feat: add convert to credit note in drawer.

This commit is contained in:
elforjani13
2021-12-26 16:34:05 +02:00
parent 80d86b01de
commit 2a9c1a9833
2 changed files with 23 additions and 2 deletions

View File

@@ -14,7 +14,13 @@ import withDialogActions from 'containers/Dialog/withDialogActions';
import withAlertsActions from 'containers/Alert/withAlertActions'; import withAlertsActions from 'containers/Alert/withAlertActions';
import withDrawerActions from 'containers/Drawer/withDrawerActions'; import withDrawerActions from 'containers/Drawer/withDrawerActions';
import { If, Can, Icon, DrawerActionsBar, FormattedMessage as T } from 'components'; import {
If,
Can,
Icon,
DrawerActionsBar,
FormattedMessage as T,
} from 'components';
import { import {
SaleInvoiceAction, SaleInvoiceAction,
PaymentReceiveAction, PaymentReceiveAction,
@@ -48,6 +54,14 @@ function InvoiceDetailActionsBar({
closeDrawer('invoice-detail-drawer'); closeDrawer('invoice-detail-drawer');
}; };
// Handle convert to invoice.
const handleConvertToCreitNote = () => {
history.push(`/credit-notes/new?from_invoice_id=${invoiceId}`, {
invoiceId: invoiceId,
});
closeDrawer('invoice-detail-drawer');
};
// Handle delete sale invoice. // Handle delete sale invoice.
const handleDeleteInvoice = () => { const handleDeleteInvoice = () => {
openAlert('invoice-delete', { invoiceId }); openAlert('invoice-delete', { invoiceId });
@@ -124,6 +138,7 @@ function InvoiceDetailActionsBar({
onBadDebt: handleBadDebtInvoice, onBadDebt: handleBadDebtInvoice,
onCancelBadDebt: handleCancelBadDebtInvoice, onCancelBadDebt: handleCancelBadDebtInvoice,
onNotifyViaSMS: handleNotifyViaSMS, onNotifyViaSMS: handleNotifyViaSMS,
onConvert: handleConvertToCreitNote,
}} }}
/> />
</Can> </Can>

View File

@@ -76,7 +76,7 @@ export const useInvoiceReadonlyEntriesColumns = () =>
* @returns {React.JSX} * @returns {React.JSX}
*/ */
export const BadDebtMenuItem = ({ export const BadDebtMenuItem = ({
payload: { onCancelBadDebt, onBadDebt, onNotifyViaSMS }, payload: { onCancelBadDebt, onBadDebt, onNotifyViaSMS, onConvert },
}) => { }) => {
const { invoice } = useInvoiceDetailDrawerContext(); const { invoice } = useInvoiceDetailDrawerContext();
@@ -104,6 +104,12 @@ export const BadDebtMenuItem = ({
/> />
</Choose.When> </Choose.When>
</Choose> </Choose>
<Can I={SaleInvoiceAction.Edit} a={AbilitySubject.Invoice}>
<MenuItem
onClick={onConvert}
text={<T id={'convert_to_credit_note'} />}
/>
</Can>
<Can I={SaleInvoiceAction.NotifyBySms} a={AbilitySubject.Invoice}> <Can I={SaleInvoiceAction.NotifyBySms} a={AbilitySubject.Invoice}>
<MenuItem <MenuItem
onClick={onNotifyViaSMS} onClick={onNotifyViaSMS}