From d719ac60bdd32edb2a80f21294e270bdd328e2cb Mon Sep 17 00:00:00 2001 From: elforjani13 <39470382+elforjani13@users.noreply.github.com> Date: Thu, 23 Dec 2021 17:27:28 +0200 Subject: [PATCH] feat: add ability credit & vendor & item transactions. --- src/common/itemPaymentTranactionsOption.js | 53 +++++++++++-- .../Drawers/BillDrawer/BillDrawerDetails.js | 20 +++-- .../BillPaymentTransactions/components.js | 32 +++++--- .../Drawers/BillDrawer/components.js | 4 +- .../CreditNoteDetail.js | 8 +- .../CreditNoteDetailActionsBar.js | 72 ++++++++++------- .../components.js | 20 +++-- .../components.js | 24 ++++-- .../InvoiceDetailDrawer/InvoiceDetail.js | 20 +++-- .../InvoicePaymentTransactions/components.js | 32 +++++--- .../BillPaymentTransactions/components.js | 32 +++++--- .../EstimatePaymentTransactions/components.js | 32 +++++--- .../InvoicePaymentTransactions/components.js | 33 +++++--- .../ReceiptPaymentTransactions/components.js | 32 +++++--- .../ItemPaymentTransactions/utils.js | 9 ++- .../components.js | 20 +++-- .../components.js | 20 +++-- .../VendorCreditDetail.js | 28 ++++--- .../VendorCreditDetailActionsBar.js | 71 +++++++++-------- .../VendorsCreditNoteActionsBar.js | 20 +++-- .../VendorsCreditNoteEmptyStatus.js | 28 ++++--- .../CreditNotesLanding/components.js | 79 +++++++++++-------- .../CreditNotesActionsBar.js | 20 +++-- .../CreditNotesEmptyStatus.js | 28 ++++--- .../CreditNotesLanding/components.js | 70 +++++++++------- src/lang/en/index.json | 2 +- 26 files changed, 519 insertions(+), 290 deletions(-) diff --git a/src/common/itemPaymentTranactionsOption.js b/src/common/itemPaymentTranactionsOption.js index 1df2bb456..0811c5183 100644 --- a/src/common/itemPaymentTranactionsOption.js +++ b/src/common/itemPaymentTranactionsOption.js @@ -1,8 +1,51 @@ import intl from 'react-intl-universal'; +import { + AbilitySubject, + SaleEstimateAction, + SaleReceiptAction, + SaleInvoiceAction, + BillAction, +} from '../common/abilityOption'; +import { useAbilitiesFilter } from '../hooks'; -export default [ - { name: 'invoices', label: intl.get('invoices') }, - { name: 'estimates', label: intl.get('estimates') }, - { name: 'receipts', label: intl.get('receipts') }, - { name: 'bills', label: intl.get('bills') }, +export const getItemPaymentTransactions = () => [ + { + name: 'invoices', + label: intl.get('invoices'), + permission: { + subject: AbilitySubject.Invoice, + ability: SaleInvoiceAction.View, + }, + }, + { + name: 'estimates', + label: intl.get('estimates'), + permission: { + subject: AbilitySubject.Estimate, + ability: SaleEstimateAction.View, + }, + }, + { + name: 'receipts', + label: intl.get('receipts'), + permission: { + subject: AbilitySubject.Receipt, + ability: SaleReceiptAction.View, + }, + }, + { + name: 'bills', + label: intl.get('bills'), + permission: { + subject: AbilitySubject.Bill, + ability: BillAction.View, + }, + }, ]; + +export const useGetItemPaymentTransactionsMenu = () => { + const itemTransactionMenu = getItemPaymentTransactions(); + const abilitiesFilter = useAbilitiesFilter(); + + return abilitiesFilter(itemTransactionMenu); +}; diff --git a/src/containers/Drawers/BillDrawer/BillDrawerDetails.js b/src/containers/Drawers/BillDrawer/BillDrawerDetails.js index 5042ed12a..62ddb5aa6 100644 --- a/src/containers/Drawers/BillDrawer/BillDrawerDetails.js +++ b/src/containers/Drawers/BillDrawer/BillDrawerDetails.js @@ -3,8 +3,11 @@ import { Tab } from '@blueprintjs/core'; import intl from 'react-intl-universal'; import styled from 'styled-components'; -import { DrawerMainTabs } from 'components'; - +import { Can, DrawerMainTabs } from 'components'; +import { + PaymentMadeAction, + AbilitySubject, +} from '../../../common/abilityOption'; import BillDetailTab from './BillDetailTab'; import LocatedLandedCostTable from './LocatedLandedCostTable'; import BillGLEntriesTable from './BillGLEntriesTable'; @@ -30,12 +33,13 @@ function BillDetailsTabs() { id={'journal_entries'} panel={} /> - - } - /> + {/* */} + } + /> + {/* */} - } - text={intl.get('invoice_transactions.action.edit_transaction')} - onClick={safeCallback(onEdit, original)} - /> - } - /> + + } + text={intl.get('invoice_transactions.action.edit_transaction')} + onClick={safeCallback(onEdit, original)} + /> + + + } + /> + ); } diff --git a/src/containers/Drawers/BillDrawer/components.js b/src/containers/Drawers/BillDrawer/components.js index 184a120f0..daf163214 100644 --- a/src/containers/Drawers/BillDrawer/components.js +++ b/src/containers/Drawers/BillDrawer/components.js @@ -3,7 +3,9 @@ import intl from 'react-intl-universal'; import styled from 'styled-components'; import { Intent, MenuItem, Menu } from '@blueprintjs/core'; import { safeCallback } from 'utils'; -import { Icon } from 'components'; +import { Can, Icon } from 'components'; +import { BillAction, AbilitySubject } from '../../../common/abilityOption'; + /** * Actions menu. */ diff --git a/src/containers/Drawers/CreditNoteDetailDrawer/CreditNoteDetail.js b/src/containers/Drawers/CreditNoteDetailDrawer/CreditNoteDetail.js index a7d169efe..968644e2f 100644 --- a/src/containers/Drawers/CreditNoteDetailDrawer/CreditNoteDetail.js +++ b/src/containers/Drawers/CreditNoteDetailDrawer/CreditNoteDetail.js @@ -3,12 +3,16 @@ import { Tab } from '@blueprintjs/core'; import styled from 'styled-components'; import intl from 'react-intl-universal'; -import { DrawerMainTabs } from 'components'; +import { Can, DrawerMainTabs } from 'components'; import CreditNoteDetailActionsBar from './CreditNoteDetailActionsBar'; import CreditNoteDetailPanel from './CreditNoteDetailPanel'; import RefundCreditNoteTransactionsTable from './RefundCreditNoteTransactions/RefundCreditNoteTransactionsTable'; import ReconcileCreditNoteTransactionsTable from './ReconcileCreditNoteTransactions/ReconcileCreditNoteTransactionsTable'; import { CreditNoteGLEntriesTable } from './JournalEntriesTransactions/JournalEntriesTransactionsTable'; +import { + CreditNoteAction, + AbilitySubject, +} from '../../../common/abilityOption'; /** * Credit Note view detail. @@ -40,6 +44,7 @@ function CreditNoteDetailsTabs() { id={'journal_entries'} panel={} /> + {/* */} } /> + {/* */} ); } diff --git a/src/containers/Drawers/CreditNoteDetailDrawer/CreditNoteDetailActionsBar.js b/src/containers/Drawers/CreditNoteDetailDrawer/CreditNoteDetailActionsBar.js index 112a8f556..08cf85250 100644 --- a/src/containers/Drawers/CreditNoteDetailDrawer/CreditNoteDetailActionsBar.js +++ b/src/containers/Drawers/CreditNoteDetailDrawer/CreditNoteDetailActionsBar.js @@ -14,7 +14,17 @@ import withDialogActions from 'containers/Dialog/withDialogActions'; import withAlertsActions from 'containers/Alert/withAlertActions'; import withDrawerActions from 'containers/Drawer/withDrawerActions'; -import { DrawerActionsBar, Icon, FormattedMessage as T, If } from 'components'; +import { + DrawerActionsBar, + Can, + Icon, + FormattedMessage as T, + If, +} from 'components'; +import { + CreditNoteAction, + AbilitySubject, +} from '../../../common/abilityOption'; import { compose } from 'utils'; import { CreditNoteMenuItem } from './utils'; @@ -58,37 +68,45 @@ function CreditNoteDetailActionsBar({ return ( - + + - + + } /> diff --git a/src/containers/Purchases/CreditNotes/CreditNotesLanding/components.js b/src/containers/Purchases/CreditNotes/CreditNotesLanding/components.js index a5e696e0e..c6cb48162 100644 --- a/src/containers/Purchases/CreditNotes/CreditNotesLanding/components.js +++ b/src/containers/Purchases/CreditNotes/CreditNotesLanding/components.js @@ -10,8 +10,13 @@ import { Choose, If, Icon, + Can, } from 'components'; import { safeCallback } from 'utils'; +import { + VendorCreditAction, + AbilitySubject, +} from '../../../../common/abilityOption'; /** * Actions menu. @@ -27,39 +32,51 @@ export function ActionsMenu({ text={intl.get('view_details')} onClick={safeCallback(onViewDetails, original)} /> - - } - text={intl.get('vendor_credits.action.edit_vendor_credit')} - onClick={safeCallback(onEdit, original)} - /> - + + } - text={intl.get('vendor_credits.action.refund_vendor_credit')} - onClick={safeCallback(onRefund, original)} + icon={} + text={intl.get('vendor_credits.action.edit_vendor_credit')} + onClick={safeCallback(onEdit, original)} /> - - + + } + text={intl.get('vendor_credits.action.mark_as_open')} + onClick={safeCallback(onOpen, original)} + /> + + + + + } + text={intl.get('vendor_credits.action.refund_vendor_credit')} + onClick={safeCallback(onRefund, original)} + /> + + + + + } + text={intl.get('vendor_credits.action.reconcile_with_bills')} + onClick={safeCallback(onReconcile, original)} + /> + + + } - text={intl.get('vendor_credits.action.mark_as_open')} - onClick={safeCallback(onOpen, original)} + text={intl.get('vendor_credits.action.delete_vendor_credit')} + intent={Intent.DANGER} + onClick={safeCallback(onDelete, original)} + icon={} /> - - - } - text={intl.get('vendor_credits.action.reconcile_with_bills')} - onClick={safeCallback(onReconcile, original)} - /> - - } - /> + ); } @@ -83,8 +100,8 @@ export function StatusAccessor(creditNote) { - - + + diff --git a/src/containers/Sales/CreditNotes/CreditNotesLanding/CreditNotesActionsBar.js b/src/containers/Sales/CreditNotes/CreditNotesLanding/CreditNotesActionsBar.js index cb1b864c6..1504cb10f 100644 --- a/src/containers/Sales/CreditNotes/CreditNotesLanding/CreditNotesActionsBar.js +++ b/src/containers/Sales/CreditNotes/CreditNotesLanding/CreditNotesActionsBar.js @@ -10,6 +10,7 @@ import { import { useHistory } from 'react-router-dom'; import { Icon, + Can, FormattedMessage as T, DashboardActionViewsList, AdvancedFilterPopover, @@ -19,7 +20,10 @@ import { import DashboardActionsBar from '../../../../components/Dashboard/DashboardActionsBar'; import { useCreditNoteListContext } from './CreditNotesListProvider'; - +import { + CreditNoteAction, + AbilitySubject, +} from '../../../../common/abilityOption'; import withCreditNotes from './withCreditNotes'; import withCreditNotesActions from './withCreditNotesActions'; import withSettings from '../../../Settings/withSettings'; @@ -78,12 +82,14 @@ function CreditNotesActionsBar({ onChange={handleTabChange} /> - + + - + + } /> diff --git a/src/containers/Sales/CreditNotes/CreditNotesLanding/components.js b/src/containers/Sales/CreditNotes/CreditNotesLanding/components.js index 067f7c590..2e0dca0ff 100644 --- a/src/containers/Sales/CreditNotes/CreditNotesLanding/components.js +++ b/src/containers/Sales/CreditNotes/CreditNotesLanding/components.js @@ -10,8 +10,13 @@ import { Choose, If, Icon, + Can, } from 'components'; import { safeCallback } from 'utils'; +import { + CreditNoteAction, + AbilitySubject, +} from '../../../../common/abilityOption'; export function ActionsMenu({ payload: { onEdit, onDelete, onRefund, onOpen, onReconcile, onViewDetails }, @@ -24,37 +29,48 @@ export function ActionsMenu({ text={intl.get('view_details')} onClick={safeCallback(onViewDetails, original)} /> - - } - text={intl.get('credit_note.action.edit_credit_note')} - onClick={safeCallback(onEdit, original)} - /> - + + } - text={intl.get('credit_note.action.make_as_open')} - onClick={safeCallback(onOpen, original)} + icon={} + text={intl.get('credit_note.action.edit_credit_note')} + onClick={safeCallback(onEdit, original)} /> - - + + } + text={intl.get('credit_note.action.make_as_open')} + onClick={safeCallback(onOpen, original)} + /> + + + + + + } + text={intl.get('credit_note.action.refund_credit_note')} + onClick={safeCallback(onRefund, original)} + /> + + + + + } + onClick={safeCallback(onReconcile, original)} + /> + + + } - text={intl.get('credit_note.action.refund_credit_note')} - onClick={safeCallback(onRefund, original)} + text={intl.get('credit_note.action.delete_credit_note')} + intent={Intent.DANGER} + onClick={safeCallback(onDelete, original)} + icon={} /> - } - onClick={safeCallback(onReconcile, original)} - /> - - } - /> + ); } diff --git a/src/lang/en/index.json b/src/lang/en/index.json index d311ecfb5..bb10562dc 100644 --- a/src/lang/en/index.json +++ b/src/lang/en/index.json @@ -1145,7 +1145,7 @@ "Landed": "Landed", "This options allows you to be able to add additional cost eg. freight then allocate cost to the items in your bills.": "This options allows you to be able to add additional cost eg. freight then allocate cost to the items in your bills.", "Once your delete this located landed cost, you won't be able to restore it later, Are your sure you want to delete this transaction?": "Once your delete this located landed cost, you won't be able to restore it later, Are your sure you want to delete this transaction?", - "journal_entries": "Journal entries", + "journal_entries": "Journal Entries", "contact": "Contact", "invoice_details": "Invoice details", "receipt_details": "Receipt details",