mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 05:10:31 +00:00
35 lines
1.1 KiB
TypeScript
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()
|
|
);
|
|
};
|
|
}
|