fix: Expense amounts should not be rounded

This commit is contained in:
Ahmed Bouhuolia
2024-01-26 23:46:45 +02:00
parent 21eb88ef53
commit de5920f910
5 changed files with 46 additions and 7 deletions

View File

@@ -0,0 +1,25 @@
import { Transformer } from '@/lib/Transformer/Transformer';
import { ExpenseCategory } from '@/models';
import { formatNumber } from '@/utils';
export class ExpenseCategoryTransformer extends Transformer {
/**
* Include these attributes to expense object.
* @returns {Array}
*/
public includeAttributes = (): string[] => {
return ['amountFormatted'];
};
/**
* Retrieves the formatted amount.
* @param {ExpenseCategory} category
* @returns {string}
*/
protected amountFormatted(category: ExpenseCategory) {
return formatNumber(category.amount, {
currencyCode: this.context.currencyCode,
money: false,
});
}
}

View File

@@ -1,6 +1,7 @@
import { Transformer } from '@/lib/Transformer/Transformer';
import { formatNumber } from 'utils';
import { IExpense } from '@/interfaces';
import { ExpenseCategoryTransformer } from './ExpenseCategoryTransformer';
export class ExpenseTransfromer extends Transformer {
/**
@@ -12,7 +13,8 @@ export class ExpenseTransfromer extends Transformer {
'formattedAmount',
'formattedLandedCostAmount',
'formattedAllocatedCostAmount',
'formattedDate'
'formattedDate',
'categories',
];
};
@@ -56,5 +58,16 @@ export class ExpenseTransfromer extends Transformer {
*/
protected formattedDate = (expense: IExpense): string => {
return this.formatDate(expense.paymentDate);
}
};
/**
* Retrieves the transformed expense categories.
* @param {IExpense} expense
* @returns {}
*/
protected categories = (expense: IExpense) => {
return this.item(expense.categories, new ExpenseCategoryTransformer(), {
currencyCode: expense.currencyCode,
});
};
}