mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-20 14:50:32 +00:00
feat: add convert to credit note.
This commit is contained in:
@@ -56,6 +56,7 @@ function CreditNoteForm({
|
|||||||
isNewMode,
|
isNewMode,
|
||||||
submitPayload,
|
submitPayload,
|
||||||
creditNote,
|
creditNote,
|
||||||
|
newCreditNote,
|
||||||
createCreditNoteMutate,
|
createCreditNoteMutate,
|
||||||
editCreditNoteMutate,
|
editCreditNoteMutate,
|
||||||
} = useCreditNoteFormContext();
|
} = useCreditNoteFormContext();
|
||||||
@@ -74,6 +75,7 @@ function CreditNoteForm({
|
|||||||
credit_note_number: creditNumber,
|
credit_note_number: creditNumber,
|
||||||
}),
|
}),
|
||||||
entries: orderingLinesIndexes(defaultCreditNote.entries),
|
entries: orderingLinesIndexes(defaultCreditNote.entries),
|
||||||
|
...newCreditNote,
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
[],
|
[],
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import {
|
|||||||
useItems,
|
useItems,
|
||||||
useCustomers,
|
useCustomers,
|
||||||
useSettingsCreditNotes,
|
useSettingsCreditNotes,
|
||||||
|
useInvoice,
|
||||||
} from 'hooks/query';
|
} from 'hooks/query';
|
||||||
|
|
||||||
const CreditNoteFormContext = React.createContext();
|
const CreditNoteFormContext = React.createContext();
|
||||||
@@ -19,6 +20,9 @@ const CreditNoteFormContext = React.createContext();
|
|||||||
* Credit note data provider.
|
* Credit note data provider.
|
||||||
*/
|
*/
|
||||||
function CreditNoteFormProvider({ creditNoteId, ...props }) {
|
function CreditNoteFormProvider({ creditNoteId, ...props }) {
|
||||||
|
const { state } = useLocation();
|
||||||
|
const invoiceId = state?.invoiceId;
|
||||||
|
|
||||||
// Handle fetch customers data table or list
|
// Handle fetch customers data table or list
|
||||||
const {
|
const {
|
||||||
data: { customers },
|
data: { customers },
|
||||||
@@ -33,13 +37,17 @@ function CreditNoteFormProvider({ creditNoteId, ...props }) {
|
|||||||
page_size: 10000,
|
page_size: 10000,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Handle fetch vendor credit details.
|
// Handle fetch credit details.
|
||||||
const { data: creditNote, isLoading: isCreditNoteLoading } = useCreditNote(
|
const { data: creditNote, isLoading: isCreditNoteLoading } = useCreditNote(
|
||||||
creditNoteId,
|
creditNoteId,
|
||||||
{
|
{
|
||||||
enabled: !!creditNoteId,
|
enabled: !!creditNoteId,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
// Handle fetch invoice detail.
|
||||||
|
const { data: invoice, isLoading: isInvoiceLoading } = useInvoice(invoiceId, {
|
||||||
|
enabled: !!invoiceId,
|
||||||
|
});
|
||||||
|
|
||||||
// Handle fetching settings.
|
// Handle fetching settings.
|
||||||
useSettingsCreditNotes();
|
useSettingsCreditNotes();
|
||||||
@@ -54,6 +62,12 @@ function CreditNoteFormProvider({ creditNoteId, ...props }) {
|
|||||||
// Determines whether the form in new mode.
|
// Determines whether the form in new mode.
|
||||||
const isNewMode = !creditNoteId;
|
const isNewMode = !creditNoteId;
|
||||||
|
|
||||||
|
const newCreditNote = !isEmpty(invoice)
|
||||||
|
? transformToEditForm({
|
||||||
|
...pick(invoice, ['customer_id', 'entries']),
|
||||||
|
})
|
||||||
|
: [];
|
||||||
|
|
||||||
// Provider payload.
|
// Provider payload.
|
||||||
const provider = {
|
const provider = {
|
||||||
items,
|
items,
|
||||||
@@ -61,6 +75,7 @@ function CreditNoteFormProvider({ creditNoteId, ...props }) {
|
|||||||
creditNote,
|
creditNote,
|
||||||
submitPayload,
|
submitPayload,
|
||||||
isNewMode,
|
isNewMode,
|
||||||
|
newCreditNote,
|
||||||
|
|
||||||
isItemsLoading,
|
isItemsLoading,
|
||||||
isCustomersLoading,
|
isCustomersLoading,
|
||||||
@@ -70,11 +85,14 @@ function CreditNoteFormProvider({ creditNoteId, ...props }) {
|
|||||||
setSubmitPayload,
|
setSubmitPayload,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const isLoading =
|
||||||
|
isItemsLoading ||
|
||||||
|
isCustomersLoading ||
|
||||||
|
isCreditNoteLoading ||
|
||||||
|
isInvoiceLoading;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DashboardInsider
|
<DashboardInsider loading={isLoading} name={'credit-note-form'}>
|
||||||
loading={isItemsLoading || isCustomersLoading || isCreditNoteLoading}
|
|
||||||
name={'credit-note-form'}
|
|
||||||
>
|
|
||||||
<CreditNoteFormContext.Provider value={provider} {...props} />
|
<CreditNoteFormContext.Provider value={provider} {...props} />
|
||||||
</DashboardInsider>
|
</DashboardInsider>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -74,6 +74,11 @@ function InvoicesDataTable({
|
|||||||
history.push(`/invoices/${invoice.id}/edit`);
|
history.push(`/invoices/${invoice.id}/edit`);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Handle convert to credit note.
|
||||||
|
const handleConvertToCreitNote = ({ id }) => {
|
||||||
|
history.push(`/credit-notes/new?from_invoice_id=${id}`, { invoiceId: id });
|
||||||
|
};
|
||||||
|
|
||||||
// handle quick payment receive.
|
// handle quick payment receive.
|
||||||
const handleQuickPaymentReceive = ({ id }) => {
|
const handleQuickPaymentReceive = ({ id }) => {
|
||||||
openDialog('quick-payment-receive', { invoiceId: id });
|
openDialog('quick-payment-receive', { invoiceId: id });
|
||||||
@@ -147,6 +152,7 @@ function InvoicesDataTable({
|
|||||||
onQuick: handleQuickPaymentReceive,
|
onQuick: handleQuickPaymentReceive,
|
||||||
onViewDetails: handleViewDetailInvoice,
|
onViewDetails: handleViewDetailInvoice,
|
||||||
onPrint: handlePrintInvoice,
|
onPrint: handlePrintInvoice,
|
||||||
|
onConvert: handleConvertToCreitNote,
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</DashboardContentTable>
|
</DashboardContentTable>
|
||||||
|
|||||||
@@ -124,7 +124,7 @@ export function ActionsMenu({
|
|||||||
onEdit,
|
onEdit,
|
||||||
onDeliver,
|
onDeliver,
|
||||||
onDelete,
|
onDelete,
|
||||||
onDrawer,
|
onConvert,
|
||||||
onQuick,
|
onQuick,
|
||||||
onViewDetails,
|
onViewDetails,
|
||||||
onPrint,
|
onPrint,
|
||||||
@@ -145,6 +145,11 @@ export function ActionsMenu({
|
|||||||
text={intl.get('edit_invoice')}
|
text={intl.get('edit_invoice')}
|
||||||
onClick={safeCallback(onEdit, original)}
|
onClick={safeCallback(onEdit, original)}
|
||||||
/>
|
/>
|
||||||
|
<MenuItem
|
||||||
|
icon={<Icon icon="convert_to" />}
|
||||||
|
text={intl.get('convert_to_credit_note')}
|
||||||
|
onClick={safeCallback(onConvert, original)}
|
||||||
|
/>
|
||||||
|
|
||||||
<If condition={!original.is_delivered}>
|
<If condition={!original.is_delivered}>
|
||||||
<MenuItem
|
<MenuItem
|
||||||
|
|||||||
@@ -646,6 +646,21 @@ export const getDashboardRoutes = () => [
|
|||||||
defaultSearchResource: RESOURCES_TYPES.CREDIT_NOTE,
|
defaultSearchResource: RESOURCES_TYPES.CREDIT_NOTE,
|
||||||
subscriptionActive: [SUBSCRIPTION_TYPE.MAIN],
|
subscriptionActive: [SUBSCRIPTION_TYPE.MAIN],
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
path: `/credit-notes/new/?from_invoice_id=/:id`,
|
||||||
|
component: lazy(() =>
|
||||||
|
import(
|
||||||
|
'../containers/Sales/CreditNotes/CreditNoteForm/CreditNoteFormPage'
|
||||||
|
),
|
||||||
|
),
|
||||||
|
name: 'credit-note-new',
|
||||||
|
breadcrumb: intl.get('credit_note.label.new_credit_note'),
|
||||||
|
backLink: true,
|
||||||
|
sidebarExpand: false,
|
||||||
|
pageTitle: intl.get('credit_note.label.new_credit_note'),
|
||||||
|
defaultSearchResource: RESOURCES_TYPES.CREDIT_NOTE,
|
||||||
|
subscriptionActive: [SUBSCRIPTION_TYPE.MAIN],
|
||||||
|
},
|
||||||
{
|
{
|
||||||
path: '/credit-notes/new',
|
path: '/credit-notes/new',
|
||||||
component: lazy(() =>
|
component: lazy(() =>
|
||||||
@@ -773,6 +788,21 @@ export const getDashboardRoutes = () => [
|
|||||||
defaultSearchResource: RESOURCES_TYPES.VENDOR_CREDIT,
|
defaultSearchResource: RESOURCES_TYPES.VENDOR_CREDIT,
|
||||||
subscriptionActive: [SUBSCRIPTION_TYPE.MAIN],
|
subscriptionActive: [SUBSCRIPTION_TYPE.MAIN],
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
path: '/vendor-credits/new/?from_bill_id=/:id',
|
||||||
|
component: lazy(() =>
|
||||||
|
import(
|
||||||
|
'containers/Purchases/CreditNotes/CreditNoteForm/VendorCreditNoteFormPage'
|
||||||
|
),
|
||||||
|
),
|
||||||
|
name: 'vendor-credits-new',
|
||||||
|
backLink: true,
|
||||||
|
sidebarExpand: false,
|
||||||
|
breadcrumb: intl.get('vendor_credits.label.new_vendor_credit'),
|
||||||
|
pageTitle: intl.get('vendor_credits.label.new_vendor_credit'),
|
||||||
|
defaultSearchResource: RESOURCES_TYPES.VENDOR_CREDIT,
|
||||||
|
subscriptionActive: [SUBSCRIPTION_TYPE.MAIN],
|
||||||
|
},
|
||||||
{
|
{
|
||||||
path: '/vendor-credits/new',
|
path: '/vendor-credits/new',
|
||||||
component: lazy(() =>
|
component: lazy(() =>
|
||||||
|
|||||||
Reference in New Issue
Block a user