mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-18 05:40:31 +00:00
fix bugs in sales and purchases API.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,10 +39,11 @@ export default class BillPayment extends mixin(TenantModel, [CachableModel]) {
|
||||
*/
|
||||
static get relationMappings() {
|
||||
const BillPaymentEntry = require('@/models/BillPaymentEntry');
|
||||
const Vendor = require('@/models/Vendor');
|
||||
|
||||
return {
|
||||
/**
|
||||
* Account model may belongs to account type.
|
||||
*
|
||||
*/
|
||||
entries: {
|
||||
relation: Model.BelongsToOneRelation,
|
||||
@@ -52,6 +53,17 @@ export default class BillPayment extends mixin(TenantModel, [CachableModel]) {
|
||||
to: 'bills_payments_entries.billPaymentId',
|
||||
},
|
||||
},
|
||||
/**
|
||||
*
|
||||
*/
|
||||
vendor: {
|
||||
relation: Model.BelongsToOneRelation,
|
||||
modelClass: this.relationBindKnex(Vendor.default),
|
||||
join: {
|
||||
from: 'bills_payments.vendorId',
|
||||
to: 'vendors.id',
|
||||
},
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user