WIP: Allocate landed cost.

This commit is contained in:
a.bouhuolia
2021-07-22 18:11:17 +02:00
parent 1eacc254d8
commit 76c6cb3699
33 changed files with 1577 additions and 163 deletions

View File

@@ -103,6 +103,7 @@ export default class Bill extends TenantModel {
'remainingDays',
'overdueDays',
'isOverdue',
'unallocatedCostAmount'
];
}
@@ -178,6 +179,14 @@ export default class Bill extends TenantModel {
return this.overdueDays > 0;
}
/**
* Retrieve the unallocated cost amount.
* @return {number}
*/
get unallocatedCostAmount() {
return Math.max(this.landedCostAmount - this.allocatedCostAmount, 0);
}
getOverdueDays(asDate = moment().format('YYYY-MM-DD')) {
// Can't continue in case due date not defined.
if (!this.dueDate) {
@@ -195,6 +204,7 @@ export default class Bill extends TenantModel {
static get relationMappings() {
const Contact = require('models/Contact');
const ItemEntry = require('models/ItemEntry');
const BillLandedCost = require('models/BillLandedCost');
return {
vendor: {
@@ -220,6 +230,15 @@ export default class Bill extends TenantModel {
builder.where('reference_type', 'Bill');
},
},
locatedLandedCosts: {
relation: Model.HasManyRelation,
modelClass: BillLandedCost.default,
join: {
from: 'bills.id',
to: 'bill_located_costs.billId',
},
},
};
}