Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: the currency code of transaction tax rate entry #293

Merged
merged 1 commit into from
Dec 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 24 additions & 19 deletions packages/webapp/src/containers/Entries/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -284,26 +284,31 @@ export const useComposeRowsOnRemoveTableRow = () => {

/**
* Retrieves the aggregate tax rates from the given item entries.
* @param {string} currencyCode -
* @param {any} taxRates -
* @param {any} entries -
*/
export const aggregateItemEntriesTaxRates = R.curry((taxRates, entries) => {
const taxRatesById = keyBy(taxRates, 'id');
export const aggregateItemEntriesTaxRates = R.curry(
(currencyCode, taxRates, entries) => {
const taxRatesById = keyBy(taxRates, 'id');

// Calculate the total tax amount of invoice entries.
const filteredEntries = entries.filter((e) => e.tax_rate_id);
const groupedTaxRates = groupBy(filteredEntries, 'tax_rate_id');
// Calculate the total tax amount of invoice entries.
const filteredEntries = entries.filter((e) => e.tax_rate_id);
const groupedTaxRates = groupBy(filteredEntries, 'tax_rate_id');

return Object.keys(groupedTaxRates).map((taxRateId) => {
const taxRate = taxRatesById[taxRateId];
const taxRates = groupedTaxRates[taxRateId];
const totalTaxAmount = sumBy(taxRates, 'tax_amount');
const taxAmountFormatted = formattedAmount(totalTaxAmount, 'USD');
return Object.keys(groupedTaxRates).map((taxRateId) => {
const taxRate = taxRatesById[taxRateId];
const taxRates = groupedTaxRates[taxRateId];
const totalTaxAmount = sumBy(taxRates, 'tax_amount');
const taxAmountFormatted = formattedAmount(totalTaxAmount, currencyCode);

return {
taxRateId,
taxRate: taxRate.rate,
label: `${taxRate.name} [${taxRate.rate}%]`,
taxAmount: totalTaxAmount,
taxAmountFormatted,
};
});
});
return {
taxRateId,
taxRate: taxRate.rate,
label: `${taxRate.name} [${taxRate.rate}%]`,
taxAmount: totalTaxAmount,
taxAmountFormatted,
};
});
},
);
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,8 @@ export const useBillAggregatedTaxRates = () => {
const { taxRates } = useBillFormContext();

const aggregateTaxRates = React.useMemo(
() => aggregateItemEntriesTaxRates(taxRates),
[taxRates],
() => aggregateItemEntriesTaxRates(values.currency_code, taxRates),
[values.currency_code, taxRates],
);
// Calculate the total tax amount of bill entries.
return React.useMemo(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,8 +333,8 @@ export const useInvoiceAggregatedTaxRates = () => {
const { taxRates } = useInvoiceFormContext();

const aggregateTaxRates = React.useMemo(
() => aggregateItemEntriesTaxRates(taxRates),
[taxRates],
() => aggregateItemEntriesTaxRates(values.currency_code, taxRates),
[values.currency_code, taxRates],
);
// Calculate the total tax amount of invoice entries.
return React.useMemo(() => {
Expand Down
Loading