diff --git a/src/containers/Drawers/BillDrawer/BillDrawerDetails.js b/src/containers/Drawers/BillDrawer/BillDrawerDetails.js index 8369fb7b8..288771b42 100644 --- a/src/containers/Drawers/BillDrawer/BillDrawerDetails.js +++ b/src/containers/Drawers/BillDrawer/BillDrawerDetails.js @@ -8,6 +8,7 @@ import { DrawerMainTabs } from 'components'; import BillDetailTab from './BillDetailTab'; import LocatedLandedCostTable from './LocatedLandedCostTable'; import JournalEntriesTable from '../../JournalEntriesTable/JournalEntriesTable'; +import BillPaymentTransactionTable from './BillPaymentTransactionTable'; import { useBillDrawerContext } from './BillDrawerProvider'; import BillDrawerCls from 'style/components/Drawers/BillDrawer.module.scss'; @@ -33,16 +34,16 @@ export default function BillDrawerDetails() { id={'journal_entries'} panel={} /> + } + /> } /> - {/* */} ); diff --git a/src/containers/Drawers/BillDrawer/BillDrawerProvider.js b/src/containers/Drawers/BillDrawer/BillDrawerProvider.js index bef541bb0..4bc138362 100644 --- a/src/containers/Drawers/BillDrawer/BillDrawerProvider.js +++ b/src/containers/Drawers/BillDrawer/BillDrawerProvider.js @@ -5,6 +5,7 @@ import { useBill, useTransactionsByReference, useBillLocatedLandedCost, + useBillPaymentTransactions, } from 'hooks/query'; const BillDrawerContext = React.createContext(); @@ -33,15 +34,31 @@ function BillDrawerProvider({ billId, ...props }) { enabled: !!billId, }); + // Handle fetch bill payment transaction. + const { + isLoading: isPaymentTransactionsLoading, + isFetching: isPaymentTransactionFetching, + data: paymentTransactions, + } = useBillPaymentTransactions(billId, { + enabled: !!billId, + }); + //provider. const provider = { transactions, billId, data, bill, + paymentTransactions, + isPaymentTransactionsLoading, + isPaymentTransactionFetching, }; - const loading = isLandedCostLoading || isTransactionLoading || isBillLoading; + const loading = + isLandedCostLoading || + isTransactionLoading || + isPaymentTransactionsLoading || + isBillLoading; return ( diff --git a/src/containers/Drawers/BillDrawer/BillPaymentTransactionTable.js b/src/containers/Drawers/BillDrawer/BillPaymentTransactionTable.js new file mode 100644 index 000000000..4165231e0 --- /dev/null +++ b/src/containers/Drawers/BillDrawer/BillPaymentTransactionTable.js @@ -0,0 +1,30 @@ +import React from 'react'; +import { DataTable, Card } from 'components'; + +import { useBillPaymentTransactionsColumns } from './utils'; +import { useBillDrawerContext } from './BillDrawerProvider'; + +/** + * Bill payment transactions datatable. + */ +export default function BillPaymentTransactionTable() { + const columns = useBillPaymentTransactionsColumns(); + + const { + paymentTransactions, + isPaymentTransactionsLoading, + isPaymentTransactionFetching, + } = useBillDrawerContext(); + + return ( + + + + ); +} diff --git a/src/containers/Drawers/BillDrawer/utils.js b/src/containers/Drawers/BillDrawer/utils.js index fea0879cd..5d075f3b7 100644 --- a/src/containers/Drawers/BillDrawer/utils.js +++ b/src/containers/Drawers/BillDrawer/utils.js @@ -1,51 +1,99 @@ import React from 'react'; import intl from 'react-intl-universal'; -import { FormatNumberCell } from '../../../components'; +import clsx from 'classnames'; +import { CLASSES } from '../../../common/classes'; +import { FormatNumberCell, FormatDateCell } from '../../../components'; /** * Retrieve bill readonly details entries table columns. */ export const useBillReadonlyEntriesTableColumns = () => -React.useMemo( - () => [ - { - Header: intl.get('product_and_service'), - accessor: 'item.name', - width: 150, - className: 'item', - disableSortBy: true - }, - { - Header: intl.get('description'), - accessor: 'description', - className: 'description', - disableSortBy: true - }, - { - Header: intl.get('quantity'), - accessor: 'quantity', - Cell: FormatNumberCell, - width: 100, - align: 'right', - disableSortBy: true - }, - { - Header: intl.get('rate'), - accessor: 'rate', - Cell: FormatNumberCell, - width: 100, - align: 'right', - disableSortBy: true - }, - { - Header: intl.get('amount'), - accessor: 'amount', - Cell: FormatNumberCell, - width: 100, - align: 'right', - disableSortBy: true - }, - ], - [], -); \ No newline at end of file + React.useMemo( + () => [ + { + Header: intl.get('product_and_service'), + accessor: 'item.name', + width: 150, + className: 'item', + disableSortBy: true, + }, + { + Header: intl.get('description'), + accessor: 'description', + className: 'description', + disableSortBy: true, + }, + { + Header: intl.get('quantity'), + accessor: 'quantity', + Cell: FormatNumberCell, + width: 100, + align: 'right', + disableSortBy: true, + }, + { + Header: intl.get('rate'), + accessor: 'rate', + Cell: FormatNumberCell, + width: 100, + align: 'right', + disableSortBy: true, + }, + { + Header: intl.get('amount'), + accessor: 'amount', + Cell: FormatNumberCell, + width: 100, + align: 'right', + disableSortBy: true, + }, + ], + [], + ); + +/** + * Retrieve bill payment transactions table columns. + */ +export const useBillPaymentTransactionsColumns = () => { + return React.useMemo( + () => [ + { + id: 'date', + Header: intl.get('payment_date'), + accessor: 'date', + Cell: FormatDateCell, + width: 110, + className: 'date', + textOverview: true, + }, + { + id: 'amount', + Header: intl.get('amount'), + accessor: 'amount', + // accessor: 'formatted_amount', + align: 'right', + width: 100, + className: clsx(CLASSES.FONT_BOLD), + textOverview: true, + }, + { + id: 'payment_number', + Header: intl.get('payment_no'), + accessor: 'payment_number', + width: 100, + className: 'payment_number', + }, + { + id: 'reference', + Header: intl.get('reference_no'), + accessor: 'reference', + width: 90, + className: 'reference', + clickable: true, + textOverview: true, + }, + ], + [], + ); +}; diff --git a/src/hooks/query/bills.js b/src/hooks/query/bills.js index d46225079..85eb70f92 100644 --- a/src/hooks/query/bills.js +++ b/src/hooks/query/bills.js @@ -178,3 +178,18 @@ export function useRefreshBills() { }, }; } + +export function useBillPaymentTransactions(id, props) { + return useRequestQuery( + [t.BILLS_PAYMENT_TRANSACTIONS, id], + { + method: 'get', + url: `purchases/bills/${id}/payment-transactions`, + }, + { + select: (res) => res.data.data, + defaultData: [], + ...props, + }, + ); +} diff --git a/src/hooks/query/paymentMades.js b/src/hooks/query/paymentMades.js index f4589b480..9cfad50d8 100644 --- a/src/hooks/query/paymentMades.js +++ b/src/hooks/query/paymentMades.js @@ -30,6 +30,9 @@ const commonInvalidateQueries = (client) => { // Invalidate the cashflow transactions. client.invalidateQueries(t.CASH_FLOW_TRANSACTIONS); client.invalidateQueries(t.CASHFLOW_ACCOUNT_TRANSACTIONS_INFINITY); + + // Invalidate bills payment transactions. + client.invalidateQueries(t.BILLS_PAYMENT_TRANSACTIONS); }; /**