feat: add refund transactions.

This commit is contained in:
elforjani13
2021-12-05 19:30:52 +02:00
parent ab48e6092a
commit 2a48d9be51
24 changed files with 688 additions and 17 deletions

View File

@@ -24,6 +24,9 @@ const commonInvalidateQueries = (queryClient) => {
// Invalidate settings.
queryClient.invalidateQueries([t.SETTING, t.SETTING_CREDIT_NOTES]);
// Invalidate refund credit
queryClient.invalidateQueries(t.REFUND_CREDIT_NOTE);
// Invalidate financial reports.
queryClient.invalidateQueries(t.FINANCIAL_REPORT);
};
@@ -143,3 +146,65 @@ export function useRefreshCreditNotes() {
},
};
}
/**
* Create Round creidt note
*/
export function useCreateRefundCreditNote(props) {
const queryClient = useQueryClient();
const apiRequest = useApiRequest();
return useMutation(
([id, values]) =>
apiRequest.post(`sales/credit_notes/${id}/refund`, values),
{
onSuccess: (res, [id, values]) => {
// Common invalidate queries.
commonInvalidateQueries(queryClient);
// Invalidate credit note query.
queryClient.invalidateQueries([t.CREDIT_NOTE, id]);
},
...props,
},
);
}
/**
* Delete the given refund credit note.
*/
export function useDeleteRefundCreditNote(props) {
const queryClient = useQueryClient();
const apiRequest = useApiRequest();
return useMutation(
(id) => apiRequest.delete(`sales/credit_notes/refunds/${id}`),
{
onSuccess: (res, id) => {
// Common invalidate queries.
commonInvalidateQueries(queryClient);
// Invalidate vendor credit query.
queryClient.invalidateQueries([t.CREDIT_NOTE, id]);
},
...props,
},
);
}
/**
* Retrieve refund credit note detail of the given id.
* @param {number} id
*
*/
export function useRefundCreditNote(id, props, requestProps) {
return useRequestQuery(
[t.REFUND_CREDIT_NOTE, id],
{ method: 'get', url: `sales/credit_notes/${id}/refund`, ...requestProps },
{
select: (res) => res.data.data,
defaultData: {},
...props,
},
);
}

View File

@@ -111,11 +111,13 @@ const ROLES = {
const CREDIT_NOTES = {
CREDIT_NOTE: 'CREDIT_NOTE',
CREDIT_NOTES: 'CREDIT_NOTES',
REFUND_CREDIT_NOTE: 'REFUND_CREDIT_NOTE',
};
const VENDOR_CREDIT_NOTES = {
VENDOR_CREDITS: 'VENDOR_CREDITS',
VENDOR_CREDIT: 'VENDOR_CREDIT',
REFUND_VENDOR_CREDIT:'REFUND_VENDOR_CREDIT'
};
const SETTING = {

View File

@@ -24,6 +24,9 @@ const commonInvalidateQueries = (queryClient) => {
// Invalidate settings.
queryClient.invalidateQueries([t.SETTING, t.SETTING_VENDOR_CREDITS]);
// Invalidate refund vendor credit
queryClient.invalidateQueries(t.REFUND_VENDOR_CREDIT);
// Invalidate financial reports.
queryClient.invalidateQueries(t.FINANCIAL_REPORT);
};
@@ -150,3 +153,69 @@ export function useRefreshVendorCredits() {
},
};
}
/**
* Create Round vendor creidt
*/
export function useCreateRefundVendorCredit(props) {
const queryClient = useQueryClient();
const apiRequest = useApiRequest();
return useMutation(
([id, values]) =>
apiRequest.post(`purchases/vendor-credit/${id}/refund`, values),
{
onSuccess: (res, [id, values]) => {
// Common invalidate queries.
commonInvalidateQueries(queryClient);
// Invalidate credit note query.
queryClient.invalidateQueries([t.VENDOR_CREDIT, id]);
},
...props,
},
);
}
/**
* Delete the given refund vendor credit.
*/
export function useDeleteRefundVendorCredit(props) {
const queryClient = useQueryClient();
const apiRequest = useApiRequest();
return useMutation(
(id) => apiRequest.delete(`purchases/vendor-credit/refunds/${id}`),
{
onSuccess: (res, id) => {
// Common invalidate queries.
commonInvalidateQueries(queryClient);
// Invalidate vendor credit query.
queryClient.invalidateQueries([t.CREDIT_NOTE, id]);
},
...props,
},
);
}
/**
* Retrieve refund credit note detail of the given id.
* @param {number} id
*
*/
export function useRefundVendorCredit(id, props, requestProps) {
return useRequestQuery(
[t.REFUND_VENDOR_CREDIT, id],
{
method: 'get',
url: `purchases/vendor-credit/${id}/refund`,
...requestProps,
},
{
select: (res) => res.data.data,
defaultData: {},
...props,
},
);
}