mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-20 14:50:32 +00:00
27 lines
641 B
TypeScript
27 lines
641 B
TypeScript
import { Inject, Injectable } from '@nestjs/common';
|
|
import { Bill } from '../models/Bill';
|
|
|
|
@Injectable()
|
|
export class GetDueBills {
|
|
constructor(
|
|
@Inject(Bill.name)
|
|
private billModel: typeof Bill,
|
|
) {}
|
|
|
|
/**
|
|
* Retrieve all due bills or for specific given vendor id.
|
|
* @param {number} vendorId -
|
|
*/
|
|
public async getDueBills(vendorId?: number): Promise<Bill[]> {
|
|
const dueBills = await this.billModel.query().onBuild((query) => {
|
|
query.orderBy('bill_date', 'DESC');
|
|
query.modify('dueBills');
|
|
|
|
if (vendorId) {
|
|
query.where('vendor_id', vendorId);
|
|
}
|
|
});
|
|
return dueBills;
|
|
}
|
|
}
|