feat: add convert to vendor credit.

This commit is contained in:
elforjani13
2021-12-26 13:25:07 +02:00
parent f9a7306e47
commit 93aa60124b
4 changed files with 33 additions and 3 deletions

View File

@@ -70,6 +70,11 @@ function BillsDataTable({
history.push(`/bills/${bill.id}/edit`); history.push(`/bills/${bill.id}/edit`);
}; };
// Handle convert to vendor credit.
const handleConvertToVendorCredit = ({ id }) => {
history.push(`/vendor-credits/new?from_bill_id=${id}`, { billId: id });
};
// Handle bill delete action. // Handle bill delete action.
const handleDeleteBill = (bill) => { const handleDeleteBill = (bill) => {
openAlert('bill-delete', { billId: bill.id }); openAlert('bill-delete', { billId: bill.id });
@@ -137,6 +142,7 @@ function BillsDataTable({
onQuick: handleQuickPaymentMade, onQuick: handleQuickPaymentMade,
onAllocateLandedCost: handleAllocateLandedCost, onAllocateLandedCost: handleAllocateLandedCost,
onViewDetails: handleViewDetailBill, onViewDetails: handleViewDetailBill,
onConvert: handleConvertToVendorCredit,
}} }}
/> />
</DashboardContentTable> </DashboardContentTable>

View File

@@ -34,6 +34,7 @@ export function ActionsMenu({
onOpen, onOpen,
onDelete, onDelete,
onQuick, onQuick,
onConvert,
onViewDetails, onViewDetails,
onAllocateLandedCost, onAllocateLandedCost,
}, },
@@ -53,6 +54,11 @@ export function ActionsMenu({
text={intl.get('edit_bill')} text={intl.get('edit_bill')}
onClick={safeCallback(onEdit, original)} onClick={safeCallback(onEdit, original)}
/> />
<MenuItem
icon={<Icon icon="convert_to" />}
text={intl.get('convert_to_vendor_credit')}
onClick={safeCallback(onConvert, original)}
/>
<If condition={!original.is_open}> <If condition={!original.is_open}>
<MenuItem <MenuItem

View File

@@ -3,7 +3,7 @@ import { useHistory } from 'react-router-dom';
import { Formik, Form } from 'formik'; import { Formik, Form } from 'formik';
import { Intent } from '@blueprintjs/core'; import { Intent } from '@blueprintjs/core';
import intl from 'react-intl-universal'; import intl from 'react-intl-universal';
import { isEmpty } from 'lodash'; import { isEmpty, pick } from 'lodash';
import classNames from 'classnames'; import classNames from 'classnames';
import { CLASSES } from 'common/classes'; import { CLASSES } from 'common/classes';
import { import {
@@ -50,6 +50,7 @@ function VendorCreditNoteForm({
isNewMode, isNewMode,
submitPayload, submitPayload,
vendorCredit, vendorCredit,
bill,
createVendorCreditMutate, createVendorCreditMutate,
editVendorCreditMutate, editVendorCreditMutate,
} = useVendorCreditNoteFormContext(); } = useVendorCreditNoteFormContext();
@@ -72,6 +73,9 @@ function VendorCreditNoteForm({
...(vendorcreditAutoIncrement && { ...(vendorcreditAutoIncrement && {
vendor_credit_number: vendorCreditNumber, vendor_credit_number: vendorCreditNumber,
}), }),
...transformToEditForm({
...pick(bill, ['vendor_id', 'entries']),
}),
}), }),
}), }),
[vendorCredit, base_currency], [vendorCredit, base_currency],

View File

@@ -1,6 +1,8 @@
import React from 'react'; import React from 'react';
import { useLocation } from 'react-router-dom';
import { isEmpty, pick } from 'lodash';
import DashboardInsider from 'components/Dashboard/DashboardInsider'; import DashboardInsider from 'components/Dashboard/DashboardInsider';
import { transformToEditForm } from './utils';
import { import {
useCreateVendorCredit, useCreateVendorCredit,
useEditVendorCredit, useEditVendorCredit,
@@ -8,6 +10,7 @@ import {
useItems, useItems,
useVendors, useVendors,
useSettingsVendorCredits, useSettingsVendorCredits,
useBill,
} from 'hooks/query'; } from 'hooks/query';
const VendorCreditNoteFormContext = React.createContext(); const VendorCreditNoteFormContext = React.createContext();
@@ -16,6 +19,10 @@ const VendorCreditNoteFormContext = React.createContext();
* Vendor Credit note data provider. * Vendor Credit note data provider.
*/ */
function VendorCreditNoteFormProvider({ vendorCreditId, ...props }) { function VendorCreditNoteFormProvider({ vendorCreditId, ...props }) {
const { state } = useLocation();
const billId = state?.billId;
// Handle fetching the items table based on the given query. // Handle fetching the items table based on the given query.
const { const {
data: { items }, data: { items },
@@ -39,6 +46,11 @@ function VendorCreditNoteFormProvider({ vendorCreditId, ...props }) {
enabled: !!vendorCreditId, enabled: !!vendorCreditId,
}); });
// Handle fetch bill details.
const { isLoading: isBillLoading, data: bill } = useBill(billId, {
enabled: !!billId,
});
// Form submit payload. // Form submit payload.
const [submitPayload, setSubmitPayload] = React.useState(); const [submitPayload, setSubmitPayload] = React.useState();
@@ -56,6 +68,7 @@ function VendorCreditNoteFormProvider({ vendorCreditId, ...props }) {
vendorCredit, vendorCredit,
submitPayload, submitPayload,
isNewMode, isNewMode,
bill,
isVendorCreditLoading, isVendorCreditLoading,
@@ -70,7 +83,8 @@ function VendorCreditNoteFormProvider({ vendorCreditId, ...props }) {
isVendorCreditLoading || isVendorCreditLoading ||
isItemsLoading || isItemsLoading ||
isVendorsLoading || isVendorsLoading ||
isVendorCreditLoading isVendorCreditLoading ||
isBillLoading
} }
name={'vendor-credit-form'} name={'vendor-credit-form'}
> >