feat: add reconcile credit note.

This commit is contained in:
elforjani13
2021-12-07 20:55:47 +02:00
parent 192bcdc696
commit 78c42acb17
18 changed files with 589 additions and 7 deletions

View File

@@ -27,6 +27,9 @@ const commonInvalidateQueries = (queryClient) => {
// Invalidate refund credit
queryClient.invalidateQueries(t.REFUND_CREDIT_NOTE);
// Invalidate reconcile.
queryClient.invalidateQueries(t.RECONCILE_CREDIT_NOTES);
// Invalidate financial reports.
queryClient.invalidateQueries(t.FINANCIAL_REPORT);
};
@@ -227,3 +230,88 @@ export function useOpenCreditNote(props) {
...props,
});
}
/**
* Retrieve reconcile credit note of the given id.
* @param {number} id
*
*/
export function useReconcileCreditNote(id, props, requestProps) {
return useRequestQuery(
[t.RECONCILE_CREDIT_NOTE, id],
{
method: 'get',
url: `sales/credit_notes/${id}/apply-to-invoices`,
...requestProps,
},
{
select: (res) => res.data.data,
defaultData: [],
...props,
},
);
}
/**
* Create Reconcile credit note.
*/
export function useCreateReconcileCreditNote(props) {
const queryClient = useQueryClient();
const apiRequest = useApiRequest();
return useMutation(
([id, values]) =>
apiRequest.post(`sales/credit_notes/${id}/apply-to-invoices`, values),
{
onSuccess: (res, [id, values]) => {
// Common invalidate queries.
commonInvalidateQueries(queryClient);
// Invalidate credit note query.
queryClient.invalidateQueries([t.CREDIT_NOTE, id]);
},
...props,
},
);
}
/**
* Retrieve reconcile credit notes.
*/
export function useReconcileCreditNotes(id, props, requestProps) {
return useRequestQuery(
[t.RECONCILE_CREDIT_NOTES, id],
{
method: 'get',
url: `sales/credit_notes/${id}/applied-invoices`,
...requestProps,
},
{
select: (res) => res.data.data,
defaultData: {},
...props,
},
);
}
/**
* Delete the given reconcile credit note.
*/
export function useDeleteReconcileCredit(props) {
const queryClient = useQueryClient();
const apiRequest = useApiRequest();
return useMutation(
(id) => apiRequest.delete(`sales/credit_notes/applied-to-invoices/${id}`),
{
onSuccess: (res, id) => {
// Common invalidate queries.
commonInvalidateQueries(queryClient);
// Invalidate vendor credit query.
queryClient.invalidateQueries([t.CREDIT_NOTE, id]);
},
...props,
},
);
}

View File

@@ -112,12 +112,16 @@ const CREDIT_NOTES = {
CREDIT_NOTE: 'CREDIT_NOTE',
CREDIT_NOTES: 'CREDIT_NOTES',
REFUND_CREDIT_NOTE: 'REFUND_CREDIT_NOTE',
RECONCILE_CREDIT_NOTE: 'RECONCILE_CREDIT_NOTE',
RECONCILE_CREDIT_NOTES: 'RECONCILE_CREDIT_NOTES',
};
const VENDOR_CREDIT_NOTES = {
VENDOR_CREDITS: 'VENDOR_CREDITS',
VENDOR_CREDIT: 'VENDOR_CREDIT',
REFUND_VENDOR_CREDIT:'REFUND_VENDOR_CREDIT'
REFUND_VENDOR_CREDIT: 'REFUND_VENDOR_CREDIT',
RECONCILE_VENDOR_CREDIT: 'RECONCILE_VENDOR_CREDIT',
RECONCILE_VENDOR_CREDITS: 'RECONCILE_VENDOR_CREDITS',
};
const SETTING = {