feat: AR/AP aging summary report.

This commit is contained in:
a.bouhuolia
2021-01-09 13:37:53 +02:00
parent 09b2aa57a0
commit 40afb108e3
18 changed files with 283 additions and 100 deletions

View File

@@ -1,3 +1,4 @@
import moment from 'moment';
import { Bill } from 'models';
import TenantRepository from 'repositories/TenantRepository';
@@ -8,4 +9,30 @@ export default class BillRepository extends TenantRepository {
get model() {
return Bill.bindKnex(this.knex);
}
dueBills(asDate = moment().format('YYYY-MM-DD'), withRelations) {
const cacheKey = this.getCacheKey('dueInvoices', asDate, withRelations);
return this.cache.get(cacheKey, () => {
return this.model
.query()
.modify('dueBills')
.modify('notOverdue')
.modify('fromDate', asDate)
.withGraphFetched(withRelations);
});
}
overdueBills(asDate = moment().format('YYYY-MM-DD'), withRelations) {
const cacheKey = this.getCacheKey('overdueInvoices', asDate, withRelations);
return this.cache.get(cacheKey, () => {
return this.model
.query()
.modify('dueBills')
.modify('overdue', asDate)
.modify('fromDate', asDate)
.withGraphFetched(withRelations);
})
}
}

View File

@@ -1,3 +1,4 @@
import moment from 'moment';
import { SaleInvoice } from 'models';
import TenantRepository from 'repositories/TenantRepository';
@@ -8,4 +9,30 @@ export default class SaleInvoiceRepository extends TenantRepository {
get model() {
return SaleInvoice.bindKnex(this.knex);
}
}
dueInvoices(asDate = moment().format('YYYY-MM-DD'), withRelations) {
const cacheKey = this.getCacheKey('dueInvoices', asDate, withRelations);
return this.cache.get(cacheKey, async () => {
return this.model
.query()
.modify('dueInvoices')
.modify('notOverdue', asDate)
.modify('fromDate', asDate)
.withGraphFetched(withRelations);
});
}
overdueInvoices(asDate = moment().format('YYYY-MM-DD'), withRelations) {
const cacheKey = this.getCacheKey('overdueInvoices', asDate, withRelations);
return this.cache.get(cacheKey, () => {
return this.model
.query()
.modify('dueInvoices')
.modify('overdue', asDate)
.modify('fromDate', asDate)
.withGraphFetched(withRelations);
});
}
}