mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 05:10:31 +00:00
feat: get bank account meta summary
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import { useFormikContext } from 'formik';
|
||||
import { MatchingTransactionFormValues } from './types';
|
||||
import { useMatchingTransactionBoot } from './MatchingTransactionBoot';
|
||||
import { useCategorizeTransactionTabsBoot } from './CategorizeTransactionTabsBoot';
|
||||
import { useMemo } from 'react';
|
||||
|
||||
export const transformToReq = (values: MatchingTransactionFormValues) => {
|
||||
const matchedTransactions = Object.entries(values.matched)
|
||||
@@ -17,18 +19,38 @@ export const transformToReq = (values: MatchingTransactionFormValues) => {
|
||||
export const useGetPendingAmountMatched = () => {
|
||||
const { values } = useFormikContext<MatchingTransactionFormValues>();
|
||||
const { perfectMatches, possibleMatches } = useMatchingTransactionBoot();
|
||||
const { uncategorizedTransaction } = useCategorizeTransactionTabsBoot();
|
||||
|
||||
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 useMemo(() => {
|
||||
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 amount = uncategorizedTransaction.amount;
|
||||
const pendingAmount = amount - totalMatchedAmount;
|
||||
|
||||
return pendingAmount;
|
||||
return pendingAmount;
|
||||
}, [uncategorizedTransaction, perfectMatches, possibleMatches, values]);
|
||||
};
|
||||
|
||||
export const useAtleastOneMatchedSelected = () => {
|
||||
const { values } = useFormikContext<MatchingTransactionFormValues>();
|
||||
|
||||
return useMemo(() => {
|
||||
const matchedCount = Object.values(values.matched).filter(Boolean).length;
|
||||
return matchedCount > 0;
|
||||
}, [values]);
|
||||
};
|
||||
|
||||
export const useIsShowReconcileTransactionLink = () => {
|
||||
const pendingAmount = useGetPendingAmountMatched();
|
||||
const atleastOneSelected = useAtleastOneMatchedSelected();
|
||||
|
||||
return atleastOneSelected && pendingAmount !== 0;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user