feat: retrieve all due invoices and bills or for specific customer/vendor.

This commit is contained in:
Ahmed Bouhuolia
2020-10-28 13:47:35 +02:00
parent 571716e82b
commit bc9638c9a2
6 changed files with 117 additions and 40 deletions

View File

@@ -1,4 +1,4 @@
import { Model, mixin } from 'objection';
import { Model, raw } from 'objection';
import moment from 'moment';
import TenantModel from 'models/TenantModel';
@@ -33,6 +33,10 @@ export default class SaleInvoice extends TenantModel {
*/
static get modifiers() {
return {
dueInvoices(query) {
query.where(raw('BALANCE - PAYMENT_AMOUNT > 0'));
},
filterDateRange(query, startDate, endDate, type = 'day') {
const dateFormat = 'YYYY-MM-DD HH:mm:ss';
const fromDate = moment(startDate).startOf(type).format(dateFormat);