- feat: Sales estimates.

- feat: Sales invoices.
- feat: Sales payment receives.
- feat: Purchases bills.
- feat: Purchases bills payments that made to the vendors.
This commit is contained in:
Ahmed Bouhuolia
2020-08-03 22:46:50 +02:00
parent 56278a25f0
commit db28cd2aef
56 changed files with 3290 additions and 1208 deletions

View File

@@ -1,4 +1,4 @@
import { mixin } from 'objection';
import { Model, mixin } from 'objection';
import TenantModel from '@/models/TenantModel';
import CachableQueryBuilder from '@/lib/Cachable/CachableQueryBuilder';
import CachableModel from '@/lib/Cachable/CachableModel';
@@ -25,4 +25,33 @@ export default class BillPayment extends mixin(TenantModel, [CachableModel]) {
static get QueryBuilder() {
return CachableQueryBuilder;
}
static changePaymentAmount(billId, amount) {
const changeMethod = amount > 0 ? 'increment' : 'decrement';
return this.tenant()
.query()
.where('id', billId)
[changeMethod]('payment_amount', Math.abs(amount));
}
/**
* Relationship mapping.
*/
static get relationMappings() {
const BillPaymentEntry = require('@/models/BillPaymentEntry');
return {
/**
* Account model may belongs to account type.
*/
entries: {
relation: Model.BelongsToOneRelation,
modelClass: this.relationBindKnex(BillPaymentEntry.default),
join: {
from: 'bills_payments.id',
to: 'bills_payments_entries.billPaymentId',
},
},
};
}
}