Files
bigcapital/packages/server/src/services/Sales/Invoices/GetInvoicePaymentsService.ts
2023-08-22 22:49:39 +02:00

35 lines
1.1 KiB
TypeScript

import { Service, Inject } from 'typedi';
import HasTenancyService from '@/services/Tenancy/TenancyService';
import { InvoicePaymentTransactionTransformer } from './InvoicePaymentTransactionTransformer';
import { TransformerInjectable } from '@/lib/Transformer/TransformerInjectable';
@Service()
export class GetInvoicePaymentsService {
@Inject()
private tenancy: HasTenancyService;
@Inject()
private transformer: TransformerInjectable;
/**
* Retrieve the invoice associated payments transactions.
* @param {number} tenantId - Tenant id.
* @param {number} invoiceId - Invoice id.
*/
public getInvoicePayments = async (tenantId: number, invoiceId: number) => {
const { PaymentReceiveEntry } = this.tenancy.models(tenantId);
const paymentsEntries = await PaymentReceiveEntry.query()
.where('invoiceId', invoiceId)
.withGraphJoined('payment.depositAccount')
.withGraphJoined('invoice')
.orderBy('payment:paymentDate', 'ASC');
return this.transformer.transform(
tenantId,
paymentsEntries,
new InvoicePaymentTransactionTransformer()
);
};
}