mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 12:50:38 +00:00
feat: integrate tax rates to bills (#260)
This commit is contained in:
16
packages/webapp/src/containers/Entries/EntriesActionBar.tsx
Normal file
16
packages/webapp/src/containers/Entries/EntriesActionBar.tsx
Normal file
@@ -0,0 +1,16 @@
|
||||
import { Box } from '@/components';
|
||||
import styled from 'styled-components';
|
||||
|
||||
export const EntriesActionsBar = styled(Box)`
|
||||
padding-bottom: 12px;
|
||||
display: flex;
|
||||
|
||||
.bp4-form-group {
|
||||
margin-bottom: 0;
|
||||
|
||||
label.bp4-label {
|
||||
opacity: 0.6;
|
||||
margin-right: 8px;
|
||||
}
|
||||
}
|
||||
`;
|
||||
@@ -1,8 +1,7 @@
|
||||
// @ts-nocheck
|
||||
import React, { useCallback } from 'react';
|
||||
import * as R from 'ramda';
|
||||
import { sumBy, isEmpty, last, keyBy } from 'lodash';
|
||||
|
||||
import { sumBy, isEmpty, last, keyBy, groupBy } from 'lodash';
|
||||
import { useItem } from '@/hooks/query';
|
||||
import {
|
||||
toSafeNumber,
|
||||
@@ -12,6 +11,7 @@ import {
|
||||
updateAutoAddNewLine,
|
||||
orderingLinesIndexes,
|
||||
updateTableRow,
|
||||
formattedAmount,
|
||||
} from '@/utils';
|
||||
import { useItemEntriesTableContext } from './ItemEntriesTableProvider';
|
||||
|
||||
@@ -116,6 +116,11 @@ export function useFetchItemRow({ landedCost, itemType, notifyNewRow }) {
|
||||
? item.purchase_description
|
||||
: item.sell_description;
|
||||
|
||||
const taxRateId =
|
||||
itemType === ITEM_TYPE.PURCHASABLE
|
||||
? item.purchase_tax_rate_id
|
||||
: item.sell_tax_rate_id;
|
||||
|
||||
// Detarmines whether the landed cost checkbox should be disabled.
|
||||
const landedCostDisabled = isLandedCostDisabled(item);
|
||||
|
||||
@@ -130,6 +135,7 @@ export function useFetchItemRow({ landedCost, itemType, notifyNewRow }) {
|
||||
landed_cost_disabled: landedCostDisabled,
|
||||
}
|
||||
: {}),
|
||||
taxRateId,
|
||||
};
|
||||
setItemRow(null);
|
||||
saveInvoke(notifyNewRow, newRow, rowIndex);
|
||||
@@ -266,3 +272,29 @@ export const useComposeRowsOnRemoveTableRow = () => {
|
||||
[minLinesNumber, defaultEntry, localValue],
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieves the aggregate tax rates from the given item entries.
|
||||
*/
|
||||
export const aggregateItemEntriesTaxRates = R.curry((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');
|
||||
|
||||
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 {
|
||||
taxRateId,
|
||||
taxRate: taxRate.rate,
|
||||
label: `${taxRate.name} [${taxRate.rate}%]`,
|
||||
taxAmount: totalTaxAmount,
|
||||
taxAmountFormatted,
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user