fix bugs in sales and purchases API.

This commit is contained in:
Ahmed Bouhuolia
2020-08-04 23:00:15 +02:00
parent db28cd2aef
commit ad772cf247
31 changed files with 420 additions and 819 deletions

View File

@@ -1,5 +1,6 @@
import { Model, mixin } from 'objection';
import moment from 'moment';
import { difference } from 'lodash';
import TenantModel from '@/models/TenantModel';
import CachableQueryBuilder from '@/lib/Cachable/CachableQueryBuilder';
import CachableModel from '@/lib/Cachable/CachableModel';
@@ -29,8 +30,25 @@ export default class Bill extends mixin(TenantModel, [CachableModel]) {
/**
* Due amount of the given.
* @return {number}
*/
get dueAmount() {
return Math.max(this.balance - this.paymentAmount, 0);
return this.amount - this.paymentAmount;
}
/**
* Retrieve the not found bills ids as array.
* @param {Array} billsIds
* @return {Array}
*/
static async getNotFoundBills(billsIds) {
const storedBills = await this.tenant().query().whereIn('id', billsIds);
const storedBillsIds = storedBills.map((t) => t.id);
const notFoundBillsIds = difference(
billsIds,
storedBillsIds,
);
return notFoundBillsIds;
}
}