Files
bigcapital/packages/server/src/services/Purchases/BillPayments/BillPaymentTransformer.ts
2024-05-28 23:34:51 +02:00

57 lines
1.5 KiB
TypeScript

import { IBillPayment } from '@/interfaces';
import { Transformer } from '@/lib/Transformer/Transformer';
import { formatNumber } from 'utils';
import { BillPaymentEntryTransformer } from './BillPaymentEntryTransformer';
import { AttachmentTransformer } from '@/services/Attachments/AttachmentTransformer';
export class BillPaymentTransformer extends Transformer {
/**
* Include these attributes to sale invoice object.
* @returns {Array}
*/
public includeAttributes = (): string[] => {
return [
'formattedPaymentDate',
'formattedAmount',
'entries',
'attachments',
];
};
/**
* Retrieve formatted invoice date.
* @param {IBill} invoice
* @returns {String}
*/
protected formattedPaymentDate = (billPayment: IBillPayment): string => {
return this.formatDate(billPayment.paymentDate);
};
/**
* Retrieve formatted bill amount.
* @param {IBill} invoice
* @returns {string}
*/
protected formattedAmount = (billPayment: IBillPayment): string => {
return formatNumber(billPayment.amount, {
currencyCode: billPayment.currencyCode,
});
};
/**
* Retreives the bill payment entries.
*/
protected entries = (billPayment) => {
return this.item(billPayment.entries, new BillPaymentEntryTransformer());
};
/**
* Retrieves the bill attachments.
* @param {ISaleInvoice} invoice
* @returns
*/
protected attachments = (billPayment) => {
return this.item(billPayment.attachments, new AttachmentTransformer());
};
}