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

@@ -27,6 +27,7 @@ import {
import { ServiceError } from 'exceptions';
import ItemsService from 'services/Items/ItemsService';
import ItemsEntriesService from 'services/Items/ItemsEntriesService';
import { Bill } from 'models';
const ERRORS = {
BILL_NOT_FOUND: 'BILL_NOT_FOUND',
@@ -135,7 +136,7 @@ export default class BillsService extends SalesInvoicesCost {
*
* @returns {IBill}
*/
private async billDTOToModel(tenantId: number, billDTO: IBillDTO|IBillEditDTO, oldBill?: IBill) {
private async billDTOToModel(tenantId: number, billDTO: IBillDTO | IBillEditDTO, oldBill?: IBill) {
const { ItemEntry } = this.tenancy.models(tenantId);
let invLotNumber = oldBill?.invLotNumber;
@@ -415,6 +416,27 @@ export default class BillsService extends SalesInvoicesCost {
};
}
/**
* Retrieve all due bills or for specific given vendor id.
* @param {number} tenantId -
* @param {number} vendorId -
*/
public async getDueBills(
tenantId: number,
vendorId?: number
): Promise<IBill[]> {
const { Bill } = this.tenancy.models(tenantId);
const dueBills = await Bill.query().onBuild((query) => {
query.modify('dueBills');
if (vendorId) {
query.where('vendor_id', vendorId);
}
});
return dueBills;
}
/**
* Retrieve the given bill details with associated items entries.
* @param {Integer} billId - Specific bill.

View File

@@ -407,4 +407,25 @@ export default class SaleInvoicesService extends SalesInvoicesCost {
filterMeta: dynamicFilter.getResponseMeta(),
};
}
/**
* Retrieve due sales invoices.
* @param {number} tenantId
* @param {number} customerId
*/
public async getDueInvoices(
tenantId: number,
customerId?: number,
): Promise<ISaleInvoice> {
const { SaleInvoice } = this.tenancy.models(tenantId);
const salesInvoices = await SaleInvoice.query().onBuild((query) => {
query.modify('dueInvoices');
if (customerId) {
query.where('customer_id', customerId);
}
});
return salesInvoices;
}
}