From cd3105b32020ab5ee774643b5be7c4466e148a8b Mon Sep 17 00:00:00 2001
From: elforjani13 <39470382+elforjani13@users.noreply.github.com>
Date: Tue, 2 Nov 2021 00:23:43 +0200
Subject: [PATCH] feat: add Bad-debt & cancel bad-bebt.
---
src/components/DialogsContainer.js | 2 +-
...{BadDebtAlert.js => CancelBadDebtAlert.js} | 17 +++--
.../Dialogs/BadDebtDialog/BadDebtForm.js | 2 +-
.../Drawers/BillDrawer/BillDrawerDetails.js | 4 +-
.../InvoiceDetailDrawer/BadDebtMenuItem.js | 70 -------------------
.../InvoiceDetailDrawer/InvoiceDetail.js | 4 +-
.../InvoiceDetailActionsBar.js | 19 +++--
.../Drawers/InvoiceDetailDrawer/utils.js | 41 +++++++++++
.../InventoryItemDetails/utils.js | 2 +-
.../Sales/Invoices/InvoicesAlerts.js | 6 +-
src/hooks/query/invoices.js | 1 +
src/lang/ar/index.json | 8 ++-
src/lang/en/index.json | 10 ++-
13 files changed, 86 insertions(+), 100 deletions(-)
rename src/containers/Alerts/Invoices/{BadDebtAlert.js => CancelBadDebtAlert.js} (77%)
delete mode 100644 src/containers/Drawers/InvoiceDetailDrawer/BadDebtMenuItem.js
diff --git a/src/components/DialogsContainer.js b/src/components/DialogsContainer.js
index f1e803fff..1a31006dc 100644
--- a/src/components/DialogsContainer.js
+++ b/src/components/DialogsContainer.js
@@ -45,7 +45,7 @@ export default function DialogsContainer() {
-
+
);
}
diff --git a/src/containers/Alerts/Invoices/BadDebtAlert.js b/src/containers/Alerts/Invoices/CancelBadDebtAlert.js
similarity index 77%
rename from src/containers/Alerts/Invoices/BadDebtAlert.js
rename to src/containers/Alerts/Invoices/CancelBadDebtAlert.js
index b3d05c083..6bbe29994 100644
--- a/src/containers/Alerts/Invoices/BadDebtAlert.js
+++ b/src/containers/Alerts/Invoices/CancelBadDebtAlert.js
@@ -11,9 +11,9 @@ import withAlertActions from 'containers/Alert/withAlertActions';
import { compose } from 'utils';
/**
- * bad debt alert.
+ * Cancel bad debt alert.
*/
-function BadDebtAlert({
+function CancelBadDebtAlert({
name,
// #withAlertStoreConnect
@@ -23,7 +23,7 @@ function BadDebtAlert({
// #withAlertActions
closeAlert,
}) {
- // handle cancel alert.
+ // handle cancel alert.
const handleCancel = () => {
closeAlert(name);
};
@@ -35,7 +35,7 @@ function BadDebtAlert({
cancelBadDebtMutate(invoiceId)
.then(() => {
AppToaster.show({
- message: intl.get('the_invoice_has_been_deleted_successfully'),
+ message: intl.get('badDebt_canceled_write_off_success_message'),
intent: Intent.SUCCESS,
});
})
@@ -48,7 +48,7 @@ function BadDebtAlert({
return (
}
- confirmButtonText={}
+ confirmButtonText={}
intent={Intent.WARNING}
isOpen={isOpen}
onCancel={handleCancel}
@@ -56,10 +56,13 @@ function BadDebtAlert({
loading={isLoading}
>
-
+
);
}
-export default compose(withAlertStoreConnect(), withAlertActions)(BadDebtAlert);
+export default compose(
+ withAlertStoreConnect(),
+ withAlertActions,
+)(CancelBadDebtAlert);
diff --git a/src/containers/Dialogs/BadDebtDialog/BadDebtForm.js b/src/containers/Dialogs/BadDebtDialog/BadDebtForm.js
index 5b579db28..bd2d7696e 100644
--- a/src/containers/Dialogs/BadDebtDialog/BadDebtForm.js
+++ b/src/containers/Dialogs/BadDebtDialog/BadDebtForm.js
@@ -50,7 +50,7 @@ function BadDebtForm({
// Handle request response success.
const onSuccess = (response) => {
AppToaster.show({
- message: intl.get('badDebt_success_message'),
+ message: intl.get('badDebt_writte_off_success_message'),
intent: Intent.SUCCESS,
});
closeDialog(dialogName);
diff --git a/src/containers/Drawers/BillDrawer/BillDrawerDetails.js b/src/containers/Drawers/BillDrawer/BillDrawerDetails.js
index 4b72212da..8369fb7b8 100644
--- a/src/containers/Drawers/BillDrawer/BillDrawerDetails.js
+++ b/src/containers/Drawers/BillDrawer/BillDrawerDetails.js
@@ -38,11 +38,11 @@ export default function BillDrawerDetails() {
id={'landed_cost'}
panel={}
/>
-
+ /> */}
);
diff --git a/src/containers/Drawers/InvoiceDetailDrawer/BadDebtMenuItem.js b/src/containers/Drawers/InvoiceDetailDrawer/BadDebtMenuItem.js
deleted file mode 100644
index ea86bd2f7..000000000
--- a/src/containers/Drawers/InvoiceDetailDrawer/BadDebtMenuItem.js
+++ /dev/null
@@ -1,70 +0,0 @@
-import React from 'react';
-import {
- Button,
- NavbarGroup,
- Classes,
- NavbarDivider,
- Popover,
- PopoverInteractionKind,
- Position,
- Intent,
- MenuItem,
- Menu,
-} from '@blueprintjs/core';
-import { If, Icon, FormattedMessage as T } from 'components';
-import { useInvoiceDetailDrawerContext } from './InvoiceDetailDrawerProvider';
-
-import withDialogActions from 'containers/Dialog/withDialogActions';
-import withAlertsActions from 'containers/Alert/withAlertActions';
-
-import { compose } from 'utils';
-
-function BadDebtMenuItem({
- // #withDialogActions
- openDialog,
-
- // #withAlertsActions
- openAlert,
-}) {
- // Invoice detail drawer context.
- const { invoiceId, invoice } = useInvoiceDetailDrawerContext();
-
- const handleBadDebtInvoiceDialog = () => {
- openDialog('invoice-bad-debt', { invoiceId });
- };
-
- const handleBadDebtInvoiceAlert = () => {
- openAlert('bad-debt', { invoiceId });
- };
-
- return (
-
-
- }
- onClick={handleBadDebtInvoiceAlert}
- />
-
-
- }
- />
-
- }
- minimal={true}
- interactionKind={PopoverInteractionKind.CLICK}
- position={Position.BOTTOM_LEFT}
- canOutsideClickClose={false}
- usePortal={false}
- modifiers={{
- offset: { offset: '0, 4' },
- }}
- >
- } minimal={true} />
-
- );
-}
-export default compose(withDialogActions, withAlertsActions)(BadDebtMenuItem);
diff --git a/src/containers/Drawers/InvoiceDetailDrawer/InvoiceDetail.js b/src/containers/Drawers/InvoiceDetailDrawer/InvoiceDetail.js
index 6318900b0..224e948a0 100644
--- a/src/containers/Drawers/InvoiceDetailDrawer/InvoiceDetail.js
+++ b/src/containers/Drawers/InvoiceDetailDrawer/InvoiceDetail.js
@@ -30,11 +30,11 @@ export default function InvoiceDetail() {
id={'journal_entries'}
panel={}
/>
-
+ /> */}
);
diff --git a/src/containers/Drawers/InvoiceDetailDrawer/InvoiceDetailActionsBar.js b/src/containers/Drawers/InvoiceDetailDrawer/InvoiceDetailActionsBar.js
index dc821f2d3..b83b8a6ed 100644
--- a/src/containers/Drawers/InvoiceDetailDrawer/InvoiceDetailActionsBar.js
+++ b/src/containers/Drawers/InvoiceDetailDrawer/InvoiceDetailActionsBar.js
@@ -31,7 +31,7 @@ import {
import { compose } from 'utils';
-import BadDebtMenuItem from './BadDebtMenuItem';
+import { BadDebtMenuItem } from './utils';
/**
* Invoice details action bar.
@@ -71,12 +71,15 @@ function InvoiceDetailActionsBar({
const handleQuickPaymentInvoice = () => {
openDialog('quick-payment-receive', { invoiceId });
};
- const handleBadDebtInvoiceDialog = () => () => {
- openDialog('invoice-bad-debt', { invoiceId });
+
+ // Handle write-off invoice.
+ const handleBadDebtInvoice = () => {
+ openDialog('write-off-bad-debt', { invoiceId });
};
- const handleBadDebtInvoiceAlert = () => {
- openAlert('bad-debt', { invoiceId });
+ // Handle cancele write-off invoice.
+ const handleCancelBadDebtInvoice = () => {
+ openAlert('cancel-bad-debt', { invoiceId });
};
return (
@@ -112,7 +115,11 @@ function InvoiceDetailActionsBar({
onClick={handleDeleteInvoice}
/>
-
+
);
diff --git a/src/containers/Drawers/InvoiceDetailDrawer/utils.js b/src/containers/Drawers/InvoiceDetailDrawer/utils.js
index f2d3ae58e..426d5c4c3 100644
--- a/src/containers/Drawers/InvoiceDetailDrawer/utils.js
+++ b/src/containers/Drawers/InvoiceDetailDrawer/utils.js
@@ -1,5 +1,15 @@
import React from 'react';
import intl from 'react-intl-universal';
+
+import {
+ Button,
+ Popover,
+ PopoverInteractionKind,
+ Position,
+ MenuItem,
+ Menu,
+} from '@blueprintjs/core';
+import { If, Icon, FormattedMessage as T, Choose } from 'components';
import { FormatNumberCell } from '../../../components';
/**
@@ -48,3 +58,34 @@ export const useInvoiceReadonlyEntriesColumns = () =>
],
[],
);
+
+export const BadDebtMenuItem = ({ invoice, onDialog, onAlert }) => {
+ return (
+
+
+
+ } onClick={onDialog} />
+
+
+ }
+ />
+
+
+
+ }
+ position={Position.BOTTOM}
+ >
+ } minimal={true} />
+
+ );
+};
diff --git a/src/containers/FinancialStatements/InventoryItemDetails/utils.js b/src/containers/FinancialStatements/InventoryItemDetails/utils.js
index 35d2e29f1..5824c4d52 100644
--- a/src/containers/FinancialStatements/InventoryItemDetails/utils.js
+++ b/src/containers/FinancialStatements/InventoryItemDetails/utils.js
@@ -9,7 +9,7 @@ const columnsMapper = (data, index, column) => ({
id: column.key,
key: column.key,
Header: column.label,
- Cell: CellForceWidth,
+ // Cell: CellForceWidth,
accessor: `cells[${index}].value`,
forceWidthAccess: `cells[0].value`,
className: column.key,
diff --git a/src/containers/Sales/Invoices/InvoicesAlerts.js b/src/containers/Sales/Invoices/InvoicesAlerts.js
index cae3ac2e5..1b2e017ae 100644
--- a/src/containers/Sales/Invoices/InvoicesAlerts.js
+++ b/src/containers/Sales/Invoices/InvoicesAlerts.js
@@ -7,8 +7,8 @@ const InvoiceDeliverAlert = React.lazy(() =>
import('../../Alerts/Invoices/InvoiceDeliverAlert'),
);
-const BadDebtAlert = React.lazy(() =>
- import('../../Alerts/Invoices/BadDebtAlert'),
+const CancelBadDebtAlert = React.lazy(() =>
+ import('../../Alerts/Invoices/CancelBadDebtAlert'),
);
/**
@@ -17,5 +17,5 @@ const BadDebtAlert = React.lazy(() =>
export default [
{ name: 'invoice-delete', component: InvoiceDeleteAlert },
{ name: 'invoice-deliver', component: InvoiceDeliverAlert },
- { name: 'bad-debt', component: BadDebtAlert },
+ { name: 'cancel-bad-debt', component: CancelBadDebtAlert },
];
diff --git a/src/hooks/query/invoices.js b/src/hooks/query/invoices.js
index 22ad30b7d..67debc80c 100644
--- a/src/hooks/query/invoices.js
+++ b/src/hooks/query/invoices.js
@@ -9,6 +9,7 @@ import t from './types';
const commonInvalidateQueries = (queryClient) => {
// Invalidate invoices.
queryClient.invalidateQueries(t.SALE_INVOICES);
+ queryClient.invalidateQueries(t.SALE_INVOICE);
// Invalidate customers.
queryClient.invalidateQueries(t.CUSTOMERS);
diff --git a/src/lang/ar/index.json b/src/lang/ar/index.json
index 6fea45707..c7fda276f 100644
--- a/src/lang/ar/index.json
+++ b/src/lang/ar/index.json
@@ -1435,5 +1435,11 @@
"cash_flow_transaction.balance_in_bigcapital": "الرصيد في Bigcapital",
"badDebt.label_written_off_amount": "المبلغ المشطوب",
"badDebt.label": "الديون المعدومة",
- "badDebt_the_seller_can_charge_the_amount_of_an_invoice": "يمكن للبائع تحميل مبلغ الفاتورة على حساب مصروفات الديون المعدومة عندما يكون من المؤكد أن الفاتورة لن يتم دفعها."
+ "badDebt.label_cancel_bad_debt": "إلغاء الديون المعدومة",
+ "badDebt_the_seller_can_charge_the_amount_of_an_invoice": "يمكن للبائع تحميل مبلغ الفاتورة على حساب مصروفات الديون المعدومة عندما يكون من المؤكد أن الفاتورة لن يتم دفعها.",
+ "badDebt_writte_off_success_message":"تم شطب فاتورة البيع المقدمة بنجاح.",
+ "badDebt_canceled_write_off_success_message":"تم إلغاء شطب فاتورة البيع المقدمة بنجاح.",
+ "badDebt_are_sure_to_write_off_this_invoice": "هل أنت متأكد أنك تريد شطب هذه الفاتورة؟ "
+
+
}
\ No newline at end of file
diff --git a/src/lang/en/index.json b/src/lang/en/index.json
index 61228c973..cb07a2c6e 100644
--- a/src/lang/en/index.json
+++ b/src/lang/en/index.json
@@ -1425,10 +1425,8 @@
"badDebt.label": "Bad debt",
"badDebt.label_cancel_bad_debt": "Cancel bad debt",
"badDebt_the_seller_can_charge_the_amount_of_an_invoice": "The seller can charge the amount of an invoice to the bad debt expense account when it is certain that the invoice will not be paid.",
- "badDebt_success_message":"The given sale invoice has been writte-off successfully.",
- "are_sure_to_cancel_this_invoice": "Are you sure you want to cancel this invoice?",
-
- "payment_transactions": "Payment transactions"
-
-
+ "badDebt_writte_off_success_message":"The given sale invoice has been writte-off successfully.",
+ "badDebt_canceled_write_off_success_message":"The given sale invoice has been canceled write-off successfully.",
+ "badDebt_are_sure_to_write_off_this_invoice": "Are you sure you want to write off this invoice?"
+
}
\ No newline at end of file