diff --git a/src/containers/Drawers/InvoiceDetailDrawer/InvoiceDetail.js b/src/containers/Drawers/InvoiceDetailDrawer/InvoiceDetail.js index 224e948a0..de075c2e4 100644 --- a/src/containers/Drawers/InvoiceDetailDrawer/InvoiceDetail.js +++ b/src/containers/Drawers/InvoiceDetailDrawer/InvoiceDetail.js @@ -6,6 +6,7 @@ import clsx from 'classnames'; import { DrawerMainTabs } from 'components'; import JournalEntriesTable from '../../JournalEntriesTable/JournalEntriesTable'; +import InvoicePaymentTransactionsTable from './InvoicePaymentTransactionsTable'; import InvoiceDetailTab from './InvoiceDetailTab'; import { useInvoiceDetailDrawerContext } from './InvoiceDetailDrawerProvider'; @@ -30,11 +31,11 @@ export default function InvoiceDetail() { id={'journal_entries'} panel={} /> - {/* */} + panel={} + /> ); diff --git a/src/containers/Drawers/InvoiceDetailDrawer/InvoiceDetailDrawerProvider.js b/src/containers/Drawers/InvoiceDetailDrawer/InvoiceDetailDrawerProvider.js index ccb64799b..9b59028a5 100644 --- a/src/containers/Drawers/InvoiceDetailDrawer/InvoiceDetailDrawerProvider.js +++ b/src/containers/Drawers/InvoiceDetailDrawer/InvoiceDetailDrawerProvider.js @@ -1,7 +1,11 @@ import React from 'react'; import intl from 'react-intl-universal'; import { DrawerHeaderContent, DrawerLoading } from 'components'; -import { useTransactionsByReference, useInvoice } from 'hooks/query'; +import { + useTransactionsByReference, + useInvoice, + useInvoicePaymentTransactions, +} from 'hooks/query'; const InvoiceDetailDrawerContext = React.createContext(); /** @@ -25,14 +29,30 @@ function InvoiceDetailDrawerProvider({ invoiceId, ...props }) { enabled: !!invoiceId, }); + // Fetch invoice payment transactions. + const { + data: paymentTransactions, + isFetching: isPaymentTransactionFetching, + isLoading: isPaymentTransactionLoading, + } = useInvoicePaymentTransactions(invoiceId, { + enabled: !!invoiceId, + }); + //provider. const provider = { transactions, + paymentTransactions, + isPaymentTransactionLoading, + isPaymentTransactionFetching, invoiceId, invoice, }; return ( - + + + + ); +} diff --git a/src/containers/Drawers/InvoiceDetailDrawer/utils.js b/src/containers/Drawers/InvoiceDetailDrawer/utils.js index 68c4cbc29..197b84ba7 100644 --- a/src/containers/Drawers/InvoiceDetailDrawer/utils.js +++ b/src/containers/Drawers/InvoiceDetailDrawer/utils.js @@ -8,8 +8,15 @@ import { MenuItem, Menu, } from '@blueprintjs/core'; -import { Icon, FormattedMessage as T, Choose } from 'components'; -import { FormatNumberCell } from '../../../components'; +import clsx from 'classnames'; +import { CLASSES } from '../../../common/classes'; +import { + Icon, + FormattedMessage as T, + Choose, + FormatDateCell, + FormatNumberCell, +} from '../../../components'; import { useInvoiceDetailDrawerContext } from './InvoiceDetailDrawerProvider'; /** @@ -99,3 +106,49 @@ export const BadDebtMenuItem = ({ ); }; + +/** + * Retrieve invoice payment transactions table columns. + */ +export const useInvoicePaymentTransactionsColumns = () => { + 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: 120, + className: clsx(CLASSES.FONT_BOLD), + textOverview: true, + }, + { + id: 'payment_receive_no.', + Header: intl.get('payment_no'), + accessor: 'payment_receive_no', + width: 100, + className: 'payment_receive_no', + }, + { + id: 'reference_no', + Header: intl.get('reference_no'), + accessor: 'reference_no', + width: 90, + className: 'reference_no', + clickable: true, + textOverview: true, + }, + ], + [], + ); +}; diff --git a/src/hooks/query/invoices.js b/src/hooks/query/invoices.js index aabe2fa07..9a0b5f4e3 100644 --- a/src/hooks/query/invoices.js +++ b/src/hooks/query/invoices.js @@ -269,3 +269,18 @@ export function useInvoiceSMSDetail(invoiceId, query, props) { }, ); } + +export function useInvoicePaymentTransactions(invoiceId, props) { + return useRequestQuery( + [t.SALE_INVOICE_PAYMENT_TRANSACTIONS, invoiceId], + { + method: 'get', + url: `sales/invoices/${invoiceId}/payment-transactions`, + }, + { + select: (res) => res.data.data, + defaultData: [], + ...props, + }, + ); +} diff --git a/src/hooks/query/paymentReceives.js b/src/hooks/query/paymentReceives.js index 06e7b39cb..3ff52d0f1 100644 --- a/src/hooks/query/paymentReceives.js +++ b/src/hooks/query/paymentReceives.js @@ -28,6 +28,9 @@ const commonInvalidateQueries = (client) => { // Invalidate the cashflow transactions. client.invalidateQueries(t.CASH_FLOW_TRANSACTIONS); client.invalidateQueries(t.CASHFLOW_ACCOUNT_TRANSACTIONS_INFINITY); + + // Invalidate invoices payment transactions. + client.invalidateQueries(t.SALE_INVOICE_PAYMENT_TRANSACTIONS); }; // Transform payment receives. diff --git a/src/hooks/query/types.js b/src/hooks/query/types.js index 1aebbd8e1..851d5dc91 100644 --- a/src/hooks/query/types.js +++ b/src/hooks/query/types.js @@ -30,6 +30,7 @@ const BILLS = { BILLS: 'BILLS', BILL: 'BILL', BILLS_DUE: 'BILLS_DUE', + BILLS_PAYMENT_TRANSACTIONS: 'BILLS_PAYMENT_TRANSACTIONS', }; const VENDORS = { @@ -95,6 +96,7 @@ const SALE_INVOICES = { NOTIFY_SALE_INVOICE_BY_SMS: 'NOTIFY_SALE_INVOICE_BY_SMS', BAD_DEBT: 'BAD_DEBT', CANCEL_BAD_DEBT: 'CANCEL_BAD_DEBT', + SALE_INVOICE_PAYMENT_TRANSACTIONS: 'SALE_INVOICE_PAYMENT_TRANSACTIONS', }; const USERS = { diff --git a/src/lang/ar/index.json b/src/lang/ar/index.json index 913afc98d..bcbb5a384 100644 --- a/src/lang/ar/index.json +++ b/src/lang/ar/index.json @@ -1480,5 +1480,6 @@ "sms_notification.payment_details.type": "شكر علي عملية الدفع", "sms_notification.receipt_details.type": "تفاصيل إيصال البيع", "personal": "المحمول", - "list.create":"إضافة {value}" + "list.create":"إضافة {value}", + "payment_transactions":"معاملات الدفع" } \ No newline at end of file diff --git a/src/lang/en/index.json b/src/lang/en/index.json index 3a1f34b77..5cd4fcf36 100644 --- a/src/lang/en/index.json +++ b/src/lang/en/index.json @@ -1467,5 +1467,6 @@ "sms_notification.payment_details.type": "Payment receive thank you.", "sms_notification.receipt_details.type": "Sale receipt details", "personal": "Personal", - "list.create":"Create {value}" + "list.create":"Create {value}", + "payment_transactions":"Payment transactions" } \ No newline at end of file