refactoring: bills service.

refactoring: bills payments made service.
This commit is contained in:
Ahmed Bouhuolia
2020-10-15 15:10:41 +02:00
parent 8713c77289
commit 899ea7a52d
39 changed files with 2192 additions and 1193 deletions

View File

@@ -17,6 +17,15 @@ export default class VendorRepository extends TenantRepository {
this.cache = this.tenancy.cache(tenantId);
}
/**
* Retrieve vendor details of the given id.
* @param {number} vendorId - Vendor id.
*/
findById(vendorId: number) {
const { Contact } = this.models;
return Contact.query().findById(vendorId);
}
/**
* Retrieve the bill that associated to the given vendor id.
* @param {number} vendorId - Vendor id.
@@ -49,4 +58,23 @@ export default class VendorRepository extends TenantRepository {
.whereIn('id', vendorIds)
.withGraphFetched('bills');
}
changeBalance(vendorId: number, amount: number) {
const { Contact } = this.models;
const changeMethod = (amount > 0) ? 'increment' : 'decrement';
return Contact.query()
.where('id', vendorId)
[changeMethod]('balance', Math.abs(amount));
}
changeDiffBalance(
vendorId: number,
amount: number,
oldAmount: number,
oldVendorId?: number,
) {
}
}