mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-15 20:30:33 +00:00
add server to monorepo.
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
import { Service, Inject } from 'typedi';
|
||||
import BaseCreditNotes from './CreditNotes';
|
||||
import { ISaleInvoice } from '@/interfaces';
|
||||
import { CreditNoteWithInvoicesToApplyTransformer } from './CreditNoteWithInvoicesToApplyTransformer';
|
||||
import { TransformerInjectable } from '@/lib/Transformer/TransformerInjectable';
|
||||
|
||||
@Service()
|
||||
export default class GetCreditNoteAssociatedInvoicesToApply extends BaseCreditNotes {
|
||||
@Inject()
|
||||
private transformer: TransformerInjectable;
|
||||
|
||||
/**
|
||||
* Retrieve credit note associated invoices to apply.
|
||||
* @param {number} tenantId
|
||||
* @param {number} creditNoteId
|
||||
* @returns {Promise<ISaleInvoice[]>}
|
||||
*/
|
||||
public getCreditAssociatedInvoicesToApply = async (
|
||||
tenantId: number,
|
||||
creditNoteId: number
|
||||
): Promise<ISaleInvoice[]> => {
|
||||
const { SaleInvoice } = this.tenancy.models(tenantId);
|
||||
|
||||
// Retireve credit note or throw not found service error.
|
||||
const creditNote = await this.getCreditNoteOrThrowError(
|
||||
tenantId,
|
||||
creditNoteId
|
||||
);
|
||||
// Retrieves the published due invoices that associated to the given customer.
|
||||
const saleInvoices = await SaleInvoice.query()
|
||||
.where('customerId', creditNote.customerId)
|
||||
.modify('dueInvoices')
|
||||
.modify('published');
|
||||
|
||||
// Transformes the sale invoices models to POJO.
|
||||
return this.transformer.transform(
|
||||
tenantId,
|
||||
saleInvoices,
|
||||
new CreditNoteWithInvoicesToApplyTransformer()
|
||||
);
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user