- {/* ----------- Save ----------- */}
-
- }
- />
-
-
- }
- onClick={handleSubmitAndNewBtnClick}
- />
- }
- onClick={handleSubmitSaveContinueEditingBtnClick}
- />
-
- }
- minimal={true}
- interactionKind={PopoverInteractionKind.CLICK}
- position={Position.BOTTOM_LEFT}
- >
+ {/* ----------- Save And Open ----------- */}
+
+
}
+ onClick={handleSubmitOpenBtnClick}
+ text={}
/>
-
-
- {/* ----------- Save As Draft ----------- */}
-
- }
- />
-
- }
- onClick={handleSubmitDraftAndNewBtnClick}
- />
- }
- onClick={handleSubmitDraftContinueEditingBtnClick}
- />
-
- }
- minimal={true}
- interactionKind={PopoverInteractionKind.CLICK}
- position={Position.BOTTOM_LEFT}
- >
+
+ }
+ onClick={handleSubmitOpenAndNewBtnClick}
+ />
+ }
+ onClick={handleSubmitOpenContinueEditingBtnClick}
+ />
+
+ }
+ minimal={true}
+ interactionKind={PopoverInteractionKind.CLICK}
+ position={Position.BOTTOM_LEFT}
+ >
+ }
+ />
+
+
+ {/* ----------- Save As Draft ----------- */}
+
}
+ className={'ml1'}
+ onClick={handleSubmitDraftBtnClick}
+ text={}
/>
-
-
+
+ }
+ onClick={handleSubmitDraftAndNewBtnClick}
+ />
+ }
+ onClick={handleSubmitDraftContinueEditingBtnClick}
+ />
+
+ }
+ minimal={true}
+ interactionKind={PopoverInteractionKind.CLICK}
+ position={Position.BOTTOM_LEFT}
+ >
+ }
+ />
+
+
+
+ {/* ----------- Save and New ----------- */}
+
+
+ }
+ />
+
+ }
+ onClick={handleSubmitOpenAndNewBtnClick}
+ />
+
+ }
+ minimal={true}
+ interactionKind={PopoverInteractionKind.CLICK}
+ position={Position.BOTTOM_LEFT}
+ >
+ }
+ />
+
+
+
{/* ----------- Clear & Reset----------- */}
:
}
+ text={vendorCredit ?
:
}
/>
{/* ----------- Cancel ----------- */}
+ );
+}
+
/**
* Retrieve vendors credit note table columns.
*/
@@ -103,8 +133,8 @@ export function useVendorsCreditNoteTableColumns() {
{
id: 'status',
Header: intl.get('status'),
- // accessor:
- width: 120, // 160
+ accessor: StatusAccessor,
+ width: 160,
className: 'status',
clickable: true,
},
diff --git a/src/containers/Purchases/CreditNotes/VendorCreditNotesAlerts.js b/src/containers/Purchases/CreditNotes/VendorCreditNotesAlerts.js
index 56320a325..9b4ecceba 100644
--- a/src/containers/Purchases/CreditNotes/VendorCreditNotesAlerts.js
+++ b/src/containers/Purchases/CreditNotes/VendorCreditNotesAlerts.js
@@ -8,6 +8,10 @@ const RefundVendorCreditDeleteAlert = React.lazy(() =>
import('../../Alerts/VendorCeditNotes/RefundVendorCreditDeleteAlert'),
);
+const OpenVendorCreditAlert = React.lazy(() =>
+ import('../../Alerts/VendorCeditNotes/VendorCreditOpenedAlert'),
+);
+
/**
* Vendor Credit notes alerts.
*/
@@ -16,6 +20,10 @@ export default [
name: 'vendor-credit-delete',
component: VendorCreditDeleteAlert,
},
+ {
+ name: 'vendor-credit-open',
+ component: OpenVendorCreditAlert,
+ },
{
name: 'refund-vendor-delete',
component: RefundVendorCreditDeleteAlert,
diff --git a/src/containers/Sales/CreditNotes/CreditNoteForm/CreditNoteFloatingActions.js b/src/containers/Sales/CreditNotes/CreditNoteForm/CreditNoteFloatingActions.js
index 727643a7b..db59adfe5 100644
--- a/src/containers/Sales/CreditNotes/CreditNoteForm/CreditNoteFloatingActions.js
+++ b/src/containers/Sales/CreditNotes/CreditNoteForm/CreditNoteFloatingActions.js
@@ -26,35 +26,40 @@ export default function CreditNoteFloatingActions() {
const { resetForm, submitForm, isSubmitting } = useFormikContext();
// Credit note form context.
- const { setSubmitPayload, isNewMode } = useCreditNoteFormContext();
+ const { setSubmitPayload, creditNote } = useCreditNoteFormContext();
- // Handle submit, save and anothe new button click.
- const handleSubmitAndNewBtnClick = (event) => {
- setSubmitPayload({ redirect: false, status: true, resetForm: true });
+ // Handle submit as open button click.
+ const handleSubmitOpenBtnClick = (event) => {
+ setSubmitPayload({ redirect: true, open: true });
submitForm();
};
- // Handle submit as save & continue editing button click.
- const handleSubmitSaveContinueEditingBtnClick = (event) => {
- setSubmitPayload({ redirect: false, status: true });
+ // Handle submit, open and anothe new button click.
+ const handleSubmitOpenAndNewBtnClick = (event) => {
+ setSubmitPayload({ redirect: false, open: true, resetForm: true });
submitForm();
};
+ // Handle submit as open & continue editing button click.
+ const handleSubmitOpenContinueEditingBtnClick = (event) => {
+ setSubmitPayload({ redirect: false, open: true });
+ submitForm();
+ };
// Handle submit as draft button click.
const handleSubmitDraftBtnClick = (event) => {
- setSubmitPayload({ redirect: true, status: false });
+ setSubmitPayload({ redirect: true, open: false });
submitForm();
};
// handle submit as draft & new button click.
const handleSubmitDraftAndNewBtnClick = (event) => {
- setSubmitPayload({ redirect: false, status: false, resetForm: true });
+ setSubmitPayload({ redirect: false, open: false, resetForm: true });
submitForm();
};
// Handle submit as draft & continue editing button click.
const handleSubmitDraftContinueEditingBtnClick = (event) => {
- setSubmitPayload({ redirect: false, status: false });
+ setSubmitPayload({ redirect: false, open: false });
submitForm();
};
@@ -63,89 +68,114 @@ export default function CreditNoteFloatingActions() {
history.goBack();
};
- // Handle submit button click.
- const handleSubmitBtnClick = (event) => {
- setSubmitPayload({ redirect: true });
- submitForm();
- };
-
const handleClearBtnClick = (event) => {
resetForm();
};
return (
- {/* ----------- Save ----------- */}
-
- }
- />
-
-
- }
- onClick={handleSubmitAndNewBtnClick}
- />
- }
- onClick={handleSubmitSaveContinueEditingBtnClick}
- />
-
- }
- minimal={true}
- interactionKind={PopoverInteractionKind.CLICK}
- position={Position.BOTTOM_LEFT}
- >
+ {/* ----------- Save And Open ----------- */}
+
+
}
+ onClick={handleSubmitOpenBtnClick}
+ text={}
/>
-
-
- {/* ----------- Save As Draft ----------- */}
-
- }
- />
-
- }
- onClick={handleSubmitDraftAndNewBtnClick}
- />
- }
- onClick={handleSubmitDraftContinueEditingBtnClick}
- />
-
- }
- minimal={true}
- interactionKind={PopoverInteractionKind.CLICK}
- position={Position.BOTTOM_LEFT}
- >
+
+ }
+ onClick={handleSubmitOpenAndNewBtnClick}
+ />
+ }
+ onClick={handleSubmitOpenContinueEditingBtnClick}
+ />
+
+ }
+ minimal={true}
+ interactionKind={PopoverInteractionKind.CLICK}
+ position={Position.BOTTOM_LEFT}
+ >
+ }
+ />
+
+
+ {/* ----------- Save As Draft ----------- */}
+
}
+ className={'ml1'}
+ onClick={handleSubmitDraftBtnClick}
+ text={}
/>
-
-
+
+ }
+ onClick={handleSubmitDraftAndNewBtnClick}
+ />
+ }
+ onClick={handleSubmitDraftContinueEditingBtnClick}
+ />
+
+ }
+ minimal={true}
+ interactionKind={PopoverInteractionKind.CLICK}
+ position={Position.BOTTOM_LEFT}
+ >
+ }
+ />
+
+
+
+ {/* ----------- Save and New ----------- */}
+
+
+ }
+ />
+
+ }
+ onClick={handleSubmitOpenAndNewBtnClick}
+ />
+
+ }
+ minimal={true}
+ interactionKind={PopoverInteractionKind.CLICK}
+ position={Position.BOTTOM_LEFT}
+ >
+ }
+ />
+
+
+
{/* ----------- Clear & Reset----------- */}
:
}
+ text={creditNote ?
:
}
/>
{/* ----------- Cancel ----------- */}
+ );
+}
+
/**
* Retrieve credit note table columns.
*/
@@ -100,8 +131,8 @@ export function useCreditNoteTableColumns() {
{
id: 'status',
Header: intl.get('status'),
- // accessor:
- width: 120, // 160
+ accessor: StatusAccessor,
+ width: 160, // 160
className: 'status',
clickable: true,
},
diff --git a/src/hooks/query/creditNote.js b/src/hooks/query/creditNote.js
index db43afc33..99e6887cc 100644
--- a/src/hooks/query/creditNote.js
+++ b/src/hooks/query/creditNote.js
@@ -208,3 +208,22 @@ export function useRefundCreditNote(id, props, requestProps) {
},
);
}
+
+/**
+ * Mark the given credit note as opened.
+ */
+export function useOpenCreditNote(props) {
+ const queryClient = useQueryClient();
+ const apiRequest = useApiRequest();
+
+ return useMutation((id) => apiRequest.post(`sales/credit_notes/${id}/open`), {
+ onSuccess: (res, id) => {
+ // Common invalidate queries.
+ commonInvalidateQueries(queryClient);
+
+ // Invalidate specific
+ queryClient.invalidateQueries([t.CREDIT_NOTE, id]);
+ },
+ ...props,
+ });
+}
diff --git a/src/hooks/query/vendorCredit.js b/src/hooks/query/vendorCredit.js
index e4d2a93a8..05df98147 100644
--- a/src/hooks/query/vendorCredit.js
+++ b/src/hooks/query/vendorCredit.js
@@ -219,3 +219,25 @@ export function useRefundVendorCredit(id, props, requestProps) {
},
);
}
+
+/**
+ * Mark the given vendor credit as opened.
+ */
+export function useOpenVendorCredit(props) {
+ const queryClient = useQueryClient();
+ const apiRequest = useApiRequest();
+
+ return useMutation(
+ (id) => apiRequest.post(`purchases/vendor-credit/${id}/open`),
+ {
+ onSuccess: (res, id) => {
+ // Common invalidate queries.
+ commonInvalidateQueries(queryClient);
+
+ // Invalidate specific.
+ queryClient.invalidateQueries([t.VENDOR_CREDIT, id]);
+ },
+ ...props,
+ },
+ );
+}
diff --git a/src/lang/en/index.json b/src/lang/en/index.json
index 4d4fae799..b0b5fe0bc 100644
--- a/src/lang/en/index.json
+++ b/src/lang/en/index.json
@@ -1562,6 +1562,10 @@
"refund_vendor_credit.column.withdrawal_account": "Withdrawal account",
"refund_vendor_credit_transactions.alert.delete_message":"The vendor credit refund has been deleted successfully.",
"refund_vendor_credit_transactions.once_your_delete_this_refund_vendor_credit":"Once your delete this refund vendor credit note, you won't be able to restore it later, Are your sure you want to delete this transaction?",
- "refund": "Refund"
+ "refund": "Refund",
+ "credit_note_opened.alert.success_message":"The credit note has been opened successfully",
+ "credit_opened.are_sure_to_open_this_credit": "Are you sure you want to open this credit note?",
+ "vendor_credit_opened.alert.success_message":"The vendor credit has been opened successfully",
+ "vendor_credit_opened.are_sure_to_open_this_credit": "Are you sure you want to open this vendor credit?"
}
From 192bcdc696946d28b628aac72c0cc9a489883eba Mon Sep 17 00:00:00 2001
From: elforjani13 <39470382+elforjani13@users.noreply.github.com>
Date: Tue, 7 Dec 2021 11:00:57 +0200
Subject: [PATCH 4/9] feat: add filterByTypes
---
.../RefundCreditNoteFloatingActions.js | 2 +-
.../RefundCreditNoteDialog/RefundCreditNoteFormFields.js | 6 ++++++
.../RefundVendorCreditFloatingActions.js | 2 +-
.../RefundVendorCreditFormFields.js | 6 ++++++
4 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/src/containers/Dialogs/RefundCreditNoteDialog/RefundCreditNoteFloatingActions.js b/src/containers/Dialogs/RefundCreditNoteDialog/RefundCreditNoteFloatingActions.js
index 13bed0a71..32cb154aa 100644
--- a/src/containers/Dialogs/RefundCreditNoteDialog/RefundCreditNoteFloatingActions.js
+++ b/src/containers/Dialogs/RefundCreditNoteDialog/RefundCreditNoteFloatingActions.js
@@ -34,7 +34,7 @@ function RefundCreditNoteFloatingActions({
+ {/*------------ Reconcile credit entries table -----------*/}
+
+ {({
+ form: { setFieldValue, values },
+ field: { value },
+ meta: { error, touched },
+ }) => (
+ {
+ setFieldValue('entries', newEntries);
+ }}
+ />
+ )}
+
+
+
+
+ }
+ value={formattedAmount(totalAmount, currency_code)}
+ />
+ }
+ value={formatted_credits_remaining}
+ />
+
+
+
+ );
+}
diff --git a/src/containers/Dialogs/ReconcileCreditNoteDialog/ReconcileCreditNoteFormFloatingActions.js b/src/containers/Dialogs/ReconcileCreditNoteDialog/ReconcileCreditNoteFormFloatingActions.js
new file mode 100644
index 000000000..e885d0325
--- /dev/null
+++ b/src/containers/Dialogs/ReconcileCreditNoteDialog/ReconcileCreditNoteFormFloatingActions.js
@@ -0,0 +1,47 @@
+import React from 'react';
+import { useFormikContext } from 'formik';
+import { Intent, Button, Classes } from '@blueprintjs/core';
+import { FormattedMessage as T } from 'components';
+
+import { useReconcileCreditNoteContext } from './ReconcileCreditNoteFormProvider';
+import withDialogActions from 'containers/Dialog/withDialogActions';
+import { compose } from 'utils';
+
+/**
+ * Reconcile credit note floating actions.
+ */
+function ReconcileCreditNoteFormFloatingActions({
+ // #withDialogActions
+ closeDialog,
+}) {
+ // Formik context.
+ const { isSubmitting } = useFormikContext();
+
+ const { dialogName } = useReconcileCreditNoteContext();
+
+ // Handle cancel button click.
+ const handleCancelBtnClick = (event) => {
+ closeDialog(dialogName);
+ };
+
+ return (
+
{/* ----------- Save And Open ----------- */}
diff --git a/src/containers/Purchases/CreditNotes/CreditNoteForm/VendorCreditNoteForm.js b/src/containers/Purchases/CreditNotes/CreditNoteForm/VendorCreditNoteForm.js
index dff4f9571..0a5639ba5 100644
--- a/src/containers/Purchases/CreditNotes/CreditNoteForm/VendorCreditNoteForm.js
+++ b/src/containers/Purchases/CreditNotes/CreditNoteForm/VendorCreditNoteForm.js
@@ -1,9 +1,9 @@
import React from 'react';
import { useHistory } from 'react-router-dom';
import { Formik, Form } from 'formik';
-import { Button, Intent } from '@blueprintjs/core';
+import { Intent } from '@blueprintjs/core';
import intl from 'react-intl-universal';
-import { sumBy, omit, isEmpty } from 'lodash';
+import { isEmpty } from 'lodash';
import classNames from 'classnames';
import { CLASSES } from 'common/classes';
import {
diff --git a/src/containers/Sales/CreditNotes/CreditNoteForm/CreditNoteForm.js b/src/containers/Sales/CreditNotes/CreditNoteForm/CreditNoteForm.js
index 5e0aca734..25a636aa0 100644
--- a/src/containers/Sales/CreditNotes/CreditNoteForm/CreditNoteForm.js
+++ b/src/containers/Sales/CreditNotes/CreditNoteForm/CreditNoteForm.js
@@ -3,7 +3,7 @@ import { useHistory } from 'react-router-dom';
import { Formik, Form } from 'formik';
import { Intent } from '@blueprintjs/core';
import intl from 'react-intl-universal';
-import { sumBy, omit, isEmpty } from 'lodash';
+import { isEmpty } from 'lodash';
import classNames from 'classnames';
import { CLASSES } from 'common/classes';
import {
diff --git a/src/containers/Sales/CreditNotes/CreditNotesLanding/CreditNotesDataTable.js b/src/containers/Sales/CreditNotes/CreditNotesLanding/CreditNotesDataTable.js
index a1721a8bb..e3c8a903e 100644
--- a/src/containers/Sales/CreditNotes/CreditNotesLanding/CreditNotesDataTable.js
+++ b/src/containers/Sales/CreditNotes/CreditNotesLanding/CreditNotesDataTable.js
@@ -105,6 +105,11 @@ function CreditNotesDataTable({
openAlert('credit-note-open', { creditNoteId: id });
};
+ // Handle reconcile credit note.
+ const handleReconcileCreditNote = ({ id }) => {
+ openDialog('reconcile-credit-note', { creditNoteId: id });
+ };
+
return (
diff --git a/src/containers/Sales/CreditNotes/CreditNotesLanding/components.js b/src/containers/Sales/CreditNotes/CreditNotesLanding/components.js
index b1ea5a384..81adb4906 100644
--- a/src/containers/Sales/CreditNotes/CreditNotesLanding/components.js
+++ b/src/containers/Sales/CreditNotes/CreditNotesLanding/components.js
@@ -14,7 +14,7 @@ import {
import { safeCallback } from 'utils';
export function ActionsMenu({
- payload: { onEdit, onDelete, onRefund, onOpen, onViewDetails },
+ payload: { onEdit, onDelete, onRefund, onOpen, onReconcile, onViewDetails },
row: { original },
}) {
return (
@@ -44,7 +44,12 @@ export function ActionsMenu({
onClick={safeCallback(onOpen, original)}
/>
-
+
}
+ // text={intl.get('credit_note.action.refund_credit_note')}
+ onClick={safeCallback(onReconcile, original)}
+ />
);
diff --git a/src/containers/Drawers/CreditNoteDetailDrawer/CreditNoteDetailDrawerProvider.js b/src/containers/Drawers/CreditNoteDetailDrawer/CreditNoteDetailDrawerProvider.js
index 6dc49e32e..8f3bd7326 100644
--- a/src/containers/Drawers/CreditNoteDetailDrawer/CreditNoteDetailDrawerProvider.js
+++ b/src/containers/Drawers/CreditNoteDetailDrawer/CreditNoteDetailDrawerProvider.js
@@ -1,6 +1,10 @@
import React from 'react';
import intl from 'react-intl-universal';
-import { useCreditNote, useRefundCreditNote } from 'hooks/query';
+import {
+ useCreditNote,
+ useRefundCreditNote,
+ useReconcileCreditNotes,
+} from 'hooks/query';
import { DrawerHeaderContent, DrawerLoading } from 'components';
const CreditNoteDetailDrawerContext = React.createContext();
@@ -26,16 +30,33 @@ function CreditNoteDetailDrawerProvider({ creditNoteId, ...props }) {
enabled: !!creditNoteId,
});
+ // Handle fetch refund credit note.
+ const {
+ data: reconcileCreditNotes,
+ isFetching: isReconcileCreditNoteFetching,
+ isLoading: isReconcileCreditNoteLoading,
+ } = useReconcileCreditNotes(creditNoteId, {
+ enabled: !!creditNoteId,
+ });
+
const provider = {
creditNote,
refundCreditNote,
+ reconcileCreditNotes,
+
isRefundCreditNoteLoading,
isRefundCreditNoteFetching,
creditNoteId,
};
return (
-