mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 05:10:31 +00:00
feat: Calculate the total pending when matching.
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
import { useFormikContext } from 'formik';
|
||||
import { MatchingTransactionFormValues } from './types';
|
||||
import { useMatchingTransactionBoot } from './MatchingTransactionBoot';
|
||||
|
||||
export const transformToReq = (values: MatchingTransactionFormValues) => {
|
||||
const matchedTransactions = Object.entries(values.matched)
|
||||
@@ -11,3 +13,22 @@ export const transformToReq = (values: MatchingTransactionFormValues) => {
|
||||
|
||||
return { matchedTransactions };
|
||||
};
|
||||
|
||||
export const useGetPendingAmountMatched = () => {
|
||||
const { values } = useFormikContext<MatchingTransactionFormValues>();
|
||||
const { perfectMatches, possibleMatches } = useMatchingTransactionBoot();
|
||||
|
||||
const matchedItems = [...perfectMatches, ...possibleMatches].filter(
|
||||
(match) => {
|
||||
const key = `${match.transactionType}-${match.transactionId}`;
|
||||
return values.matched[key];
|
||||
},
|
||||
);
|
||||
const totalMatchedAmount = matchedItems.reduce(
|
||||
(total, item) => total + parseFloat(item.amount),
|
||||
0,
|
||||
);
|
||||
const pendingAmount = 0 - totalMatchedAmount;
|
||||
|
||||
return pendingAmount;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user