fix: formatted money attributes

This commit is contained in:
Ahmed Bouhuolia
2025-12-14 16:51:06 +02:00
parent 6ecfe1ff12
commit 63922c391a
9 changed files with 60 additions and 8 deletions

View File

@@ -104,6 +104,12 @@ export class BillPaymentResponseDto {
@ApiProperty({ description: 'The formatted amount', example: '100.00 USD' })
formattedAmount: string;
@ApiProperty({ description: 'The formatted total', example: '100.00 USD' })
formattedTotal: string;
@ApiProperty({ description: 'The formatted subtotal', example: '100.00 USD' })
formattedSubtotal: string;
@ApiProperty({
description: 'The date when the payment was created',
example: '2024-01-01T12:00:00Z',

View File

@@ -13,6 +13,8 @@ export class BillPaymentTransformer extends Transformer {
'formattedPaymentDate',
'formattedCreatedAt',
'formattedAmount',
'formattedTotal',
'formattedSubtotal',
'entries',
'attachments',
];
@@ -47,6 +49,29 @@ export class BillPaymentTransformer extends Transformer {
});
};
/**
* Retrieves the formatted total.
* @param {IBillPayment} billPayment
* @returns {string}
*/
protected formattedTotal = (billPayment: BillPayment): string => {
return this.formatNumber(billPayment.amount, {
currencyCode: billPayment.currencyCode,
money: true,
});
};
/**
* Retrieves the formatted subtotal.
* @param {IBillPayment} billPayment
* @returns {string}
*/
protected formattedSubtotal = (billPayment: BillPayment): string => {
return this.formatNumber(billPayment.amount, {
currencyCode: billPayment.currencyCode,
});
};
/**
* Retreives the bill payment entries.
*/

View File

@@ -94,6 +94,7 @@ export class BillTransformer extends Transformer {
protected formattedDueAmount = (bill: Bill): string => {
return this.formatNumber(bill.dueAmount, {
currencyCode: bill.currencyCode,
money: true,
});
};
@@ -169,6 +170,7 @@ export class BillTransformer extends Transformer {
protected totalFormatted = (bill: Bill): string => {
return this.formatNumber(bill.total, {
currencyCode: bill.currencyCode,
money: true,
});
};

View File

@@ -90,7 +90,7 @@ export class CreditNoteTransformer extends Transformer {
* @returns {string}
*/
protected formattedSubtotal = (credit): string => {
return this.formatNumber(credit.amount, { money: false });
return this.formatNumber(credit.amount);
};
/**
@@ -130,7 +130,7 @@ export class CreditNoteTransformer extends Transformer {
* @returns {string}
*/
protected adjustmentFormatted = (credit): string => {
return this.formatMoney(credit.adjustment, {
return this.formatNumber(credit.adjustment, {
currencyCode: credit.currencyCode,
excerptZero: true,
});
@@ -156,6 +156,7 @@ export class CreditNoteTransformer extends Transformer {
protected totalFormatted = (credit): string => {
return this.formatNumber(credit.total, {
currencyCode: credit.currencyCode,
money: true,
});
};
@@ -167,6 +168,7 @@ export class CreditNoteTransformer extends Transformer {
protected totalLocalFormatted = (credit): string => {
return this.formatNumber(credit.totalLocal, {
currencyCode: credit.currencyCode,
money: true,
});
};

View File

@@ -74,6 +74,9 @@ export class PaymentReceivedResponseDto {
@ApiProperty({ description: 'The formatted amount', example: '100.00' })
formattedAmount: string;
@ApiProperty({ description: 'The formatted total', example: '100.00 USD' })
formattedTotal: string;
@ApiProperty({ description: 'The currency code', example: 'USD' })
currencyCode: string;

View File

@@ -11,6 +11,7 @@ export class PaymentReceiveTransfromer extends Transformer {
public includeAttributes = (): string[] => {
return [
'subtotalFormatted',
'formatttedTotal',
'formattedPaymentDate',
'formattedCreatedAt',
'formattedAmount',
@@ -45,7 +46,18 @@ export class PaymentReceiveTransfromer extends Transformer {
protected subtotalFormatted = (payment: PaymentReceived): string => {
return this.formatNumber(payment.amount, {
currencyCode: payment.currencyCode,
money: false,
});
};
/**
* Retrieves the formatted total.
* @param {PaymentReceived} payment
* @returns {string}
*/
protected formatttedTotal = (payment: PaymentReceived): string => {
return this.formatNumber(payment.amount, {
currencyCode: payment.currencyCode,
money: true,
});
};
@@ -66,7 +78,7 @@ export class PaymentReceiveTransfromer extends Transformer {
* @returns {string}
*/
protected formattedExchangeRate = (payment: PaymentReceived): string => {
return this.formatNumber(payment.exchangeRate, { money: false });
return this.formatNumber(payment.exchangeRate);
};
/**

View File

@@ -17,7 +17,7 @@ export class SaleEstimateTransfromer extends Transformer {
'formattedDeliveredAtDate',
'formattedApprovedAtDate',
'formattedRejectedAtDate',
'discountAmountFormatted',
'discountPercentageFormatted',
'adjustmentFormatted',
@@ -135,7 +135,7 @@ export class SaleEstimateTransfromer extends Transformer {
* @returns {string}
*/
protected adjustmentFormatted = (estimate: SaleEstimate): string => {
return this.formatMoney(estimate.adjustment, {
return this.formatNumber(estimate.adjustment, {
currencyCode: estimate.currencyCode,
excerptZero: true,
});

View File

@@ -70,6 +70,7 @@ export class SaleInvoiceTransformer extends Transformer {
protected dueAmountFormatted = (invoice: SaleInvoice): string => {
return this.formatNumber(invoice.dueAmount, {
currencyCode: invoice.currencyCode,
money: true
});
};
@@ -113,7 +114,6 @@ export class SaleInvoiceTransformer extends Transformer {
protected subtotalFormatted = (invoice: SaleInvoice): string => {
return this.formatNumber(invoice.subtotal, {
currencyCode: this.context.organization.baseCurrency,
money: false,
});
};
@@ -170,6 +170,7 @@ export class SaleInvoiceTransformer extends Transformer {
protected totalFormatted = (invoice: SaleInvoice): string => {
return this.formatNumber(invoice.total, {
currencyCode: invoice.currencyCode,
money: true
});
};
@@ -212,7 +213,7 @@ export class SaleInvoiceTransformer extends Transformer {
* @returns {string}
*/
protected adjustmentFormatted = (invoice: SaleInvoice): string => {
return this.formatMoney(invoice.adjustment, {
return this.formatNumber(invoice.adjustment, {
currencyCode: invoice.currencyCode,
})
}

View File

@@ -203,6 +203,7 @@ export class Transformer<T = {}, ExtraContext = {}> {
protected formatMoney(money, options?) {
return formatNumber(money, {
currencyCode: this.context.organization.baseCurrency,
money: true,
...options,
});
}