mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 21:30:31 +00:00
fix issues in sales and purchases module.
This commit is contained in:
@@ -37,12 +37,55 @@ export default class Bill extends mixin(TenantModel, [CachableModel]) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the not found bills ids as array.
|
||||
* Relationship mapping.
|
||||
*/
|
||||
static get relationMappings() {
|
||||
const Vendor = require('@/models/Vendor');
|
||||
const ItemEntry = require('@/models/ItemEntry');
|
||||
|
||||
return {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
vendor: {
|
||||
relation: Model.BelongsToOneRelation,
|
||||
modelClass: this.relationBindKnex(Vendor.default),
|
||||
join: {
|
||||
from: 'bills.vendorId',
|
||||
to: 'vendors.id',
|
||||
},
|
||||
},
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
entries: {
|
||||
relation: Model.HasManyRelation,
|
||||
modelClass: this.relationBindKnex(ItemEntry.default),
|
||||
join: {
|
||||
from: 'bills.id',
|
||||
to: 'items_entries.referenceId',
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the not found bills ids as array that associated to the given vendor.
|
||||
* @param {Array} billsIds
|
||||
* @param {number} vendorId -
|
||||
* @return {Array}
|
||||
*/
|
||||
static async getNotFoundBills(billsIds) {
|
||||
const storedBills = await this.tenant().query().whereIn('id', billsIds);
|
||||
static async getNotFoundBills(billsIds, vendorId) {
|
||||
const storedBills = await this.tenant().query()
|
||||
.onBuild((builder) => {
|
||||
builder.whereIn('id', billsIds);
|
||||
|
||||
if (vendorId) {
|
||||
builder.where('vendor_id', vendorId);
|
||||
}
|
||||
});
|
||||
|
||||
const storedBillsIds = storedBills.map((t) => t.id);
|
||||
|
||||
const notFoundBillsIds = difference(
|
||||
@@ -51,4 +94,12 @@ export default class Bill extends mixin(TenantModel, [CachableModel]) {
|
||||
);
|
||||
return notFoundBillsIds;
|
||||
}
|
||||
|
||||
static changePaymentAmount(billId, amount) {
|
||||
const changeMethod = amount > 0 ? 'increment' : 'decrement';
|
||||
return this.tenant()
|
||||
.query()
|
||||
.where('id', billId)
|
||||
[changeMethod]('payment_amount', Math.abs(amount));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user