mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 21:00:31 +00:00
refactoring: sales tables.
refacoring: purchases tables.
This commit is contained in:
@@ -1,14 +1,7 @@
|
||||
import { useQueryClient, useQuery, useMutation } from 'react-query';
|
||||
import { defaultTo } from 'lodash';
|
||||
import ApiService from 'services/ApiService';
|
||||
|
||||
// Bills transformer.
|
||||
const billsTransformer = (response) => {
|
||||
return {
|
||||
bills: response.data.bills,
|
||||
pagination: response.data.pagination,
|
||||
filterMeta: response.data.filter_meta,
|
||||
};
|
||||
};
|
||||
import { transformPagination } from 'utils';
|
||||
|
||||
/**
|
||||
* Creates a new sale invoice.
|
||||
@@ -19,6 +12,7 @@ export function useCreateBill(props) {
|
||||
return useMutation((values) => ApiService.post('purchases/bills', values), {
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries('BILLS');
|
||||
queryClient.invalidateQueries('BILL');
|
||||
},
|
||||
...props,
|
||||
});
|
||||
@@ -35,6 +29,7 @@ export function useEditBill(props) {
|
||||
{
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries('BILLS');
|
||||
queryClient.invalidateQueries('BILL');
|
||||
},
|
||||
...props,
|
||||
},
|
||||
@@ -50,6 +45,7 @@ export function useDeleteBill(props) {
|
||||
return useMutation((id) => ApiService.delete(`purchases/bills/${id}`), {
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries('BILLS');
|
||||
queryClient.invalidateQueries('BILL');
|
||||
},
|
||||
...props,
|
||||
});
|
||||
@@ -59,24 +55,32 @@ export function useDeleteBill(props) {
|
||||
* Retrieve sale invoices list with pagination meta.
|
||||
*/
|
||||
export function useBills(query, props) {
|
||||
return useQuery(
|
||||
const states = useQuery(
|
||||
['BILLS', query],
|
||||
() =>
|
||||
ApiService.get('purchases/bills', { params: query }).then(
|
||||
billsTransformer,
|
||||
),
|
||||
ApiService.get('purchases/bills', { params: query }),
|
||||
{
|
||||
initialData: {
|
||||
bills: [],
|
||||
pagination: {
|
||||
page: 1,
|
||||
page_size: 12,
|
||||
total: 0,
|
||||
},
|
||||
},
|
||||
select: (response) => ({
|
||||
bills: response.data.bills,
|
||||
pagination: transformPagination(response.data.pagination),
|
||||
filterMeta: response.data.filter_meta,
|
||||
}),
|
||||
...props,
|
||||
},
|
||||
);
|
||||
|
||||
return {
|
||||
...states,
|
||||
data: defaultTo(states.data, {
|
||||
bills: [],
|
||||
pagination: {
|
||||
page: 1,
|
||||
page_size: 12,
|
||||
total: 0,
|
||||
},
|
||||
filterMeta: {},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -84,17 +88,16 @@ export function useBills(query, props) {
|
||||
* @param {number} id - Bill id.
|
||||
*/
|
||||
export function useBill(id, props) {
|
||||
return useQuery(
|
||||
const states = useQuery(
|
||||
['BILL', id],
|
||||
async () => {
|
||||
const { data } = await ApiService.get(`/purchases/bills/${id}`);
|
||||
return data.bill;
|
||||
},
|
||||
() => ApiService.get(`/purchases/bills/${id}`),
|
||||
{
|
||||
initialData: {},
|
||||
select: (res) => res.data.bill,
|
||||
...props,
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
return defaultTo(states.data, {});
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,12 +1,7 @@
|
||||
import { useQueryClient, useQuery, useMutation } from 'react-query';
|
||||
import { defaultTo } from 'lodash';
|
||||
import ApiService from 'services/ApiService';
|
||||
|
||||
const invoicesTransformer = (response) => {
|
||||
return {
|
||||
estimates: response.data.sale_invoices,
|
||||
pagination: response.data.pagination,
|
||||
};
|
||||
};
|
||||
import { transformPagination } from 'utils';
|
||||
|
||||
/**
|
||||
* Creates a new sale estimate.
|
||||
@@ -29,7 +24,7 @@ export function useEditEstimate(props) {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation(
|
||||
(id, values) => ApiService.post(`sales/estimates/${id}`, values),
|
||||
([id, values]) => ApiService.post(`sales/estimates/${id}`, values),
|
||||
{
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries('SALE_ESTIMATES');
|
||||
@@ -39,6 +34,37 @@ export function useEditEstimate(props) {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve sale invoices list with pagination meta.
|
||||
*/
|
||||
export function useEstimates(query, props) {
|
||||
const states = useQuery(
|
||||
['SALE_ESTIMATES', query],
|
||||
() => ApiService.get('sales/estimates', { params: query }),
|
||||
{
|
||||
select: (res) => ({
|
||||
estimates: res.data.sales_estimates,
|
||||
pagination: transformPagination(res.data.pagination),
|
||||
filterMeta: res.data.filter_meta,
|
||||
}),
|
||||
...props,
|
||||
},
|
||||
);
|
||||
|
||||
return {
|
||||
...states,
|
||||
data: defaultTo(states.data, {
|
||||
estimates: [],
|
||||
pagination: {
|
||||
page: 1,
|
||||
pageSize: 12,
|
||||
total: 0,
|
||||
},
|
||||
filterMeta: {},
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes the given sale invoice.
|
||||
*/
|
||||
@@ -53,30 +79,6 @@ export function useDeleteEstimate(props) {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve sale invoices list with pagination meta.
|
||||
*/
|
||||
export function useEstimates(query, props) {
|
||||
return useQuery(
|
||||
['SALE_INVOICES', query],
|
||||
() =>
|
||||
ApiService.get('sales/estimates', { params: query }).then(
|
||||
invoicesTransformer,
|
||||
),
|
||||
{
|
||||
initialData: {
|
||||
saleEstimates: [],
|
||||
pagination: {
|
||||
page: 1,
|
||||
page_size: 12,
|
||||
total: 0,
|
||||
},
|
||||
},
|
||||
...props,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark the given estimate as delivered.
|
||||
*/
|
||||
@@ -84,7 +86,7 @@ export function useDeliverEstimate(props) {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation(
|
||||
(id) => ApiService.delete(`sales/estimates/${id}/deliver`),
|
||||
(id) => ApiService.post(`sales/estimates/${id}/deliver`),
|
||||
{
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries('SALE_ESTIMATES');
|
||||
@@ -101,7 +103,7 @@ export function useApproveEstimate(props) {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation(
|
||||
(id) => ApiService.delete(`sales/estimates/${id}/deliver`),
|
||||
(id) => ApiService.post(`sales/estimates/${id}/approve`),
|
||||
{
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries('SALE_ESTIMATES');
|
||||
@@ -118,7 +120,7 @@ export function useRejectEstimate(props) {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation(
|
||||
(id) => ApiService.delete(`sales/estimates/${id}/reject`),
|
||||
(id) => ApiService.post(`sales/estimates/${id}/reject`),
|
||||
{
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries('SALE_ESTIMATES');
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { useQuery } from 'react-query';
|
||||
import { defaultTo } from 'lodash';
|
||||
import ApiService from 'services/ApiService';
|
||||
import {
|
||||
trialBalanceSheetReducer,
|
||||
@@ -7,134 +8,154 @@ import {
|
||||
generalLedgerTableRowsReducer,
|
||||
journalTableRowsReducer,
|
||||
} from 'containers/FinancialStatements/reducers';
|
||||
|
||||
const transformBalanceSheet = (response) => {
|
||||
return {
|
||||
tableRows: balanceSheetRowsReducer(response.data.data),
|
||||
...response.data,
|
||||
};
|
||||
};
|
||||
|
||||
const transformTrialBalance = (response) => {
|
||||
return {
|
||||
tableRows: trialBalanceSheetReducer(response.data.data),
|
||||
...response.data,
|
||||
};
|
||||
};
|
||||
|
||||
const transformProfitLoss = (response) => {
|
||||
return {
|
||||
tableRows: profitLossSheetReducer(response.data.data),
|
||||
...response.data,
|
||||
};
|
||||
};
|
||||
|
||||
const transformGeneralLedger = (response) => {
|
||||
return {
|
||||
tableRows: generalLedgerTableRowsReducer(response.data.data),
|
||||
...response.data,
|
||||
};
|
||||
};
|
||||
|
||||
const transformJournal = (response) => {
|
||||
return {
|
||||
tableRows: journalTableRowsReducer(response.data.data),
|
||||
...response.data,
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Retrieve balance sheet.
|
||||
*/
|
||||
export function useBalanceSheet(query, props) {
|
||||
return useQuery(
|
||||
const states = useQuery(
|
||||
['FINANCIAL-REPORT', 'BALANCE-SHEET', query],
|
||||
() =>
|
||||
ApiService.get('/financial_statements/balance_sheet', {
|
||||
params: query,
|
||||
}).then(transformBalanceSheet),
|
||||
}),
|
||||
{
|
||||
initialData: {
|
||||
data: [],
|
||||
columns: [],
|
||||
query: {},
|
||||
tableRows: [],
|
||||
},
|
||||
...props,
|
||||
select: (res) => ({
|
||||
tableRows: balanceSheetRowsReducer(res.data.data),
|
||||
...res.data,
|
||||
}),
|
||||
...props
|
||||
},
|
||||
);
|
||||
|
||||
return {
|
||||
...states,
|
||||
data: defaultTo(states.data, {
|
||||
data: [],
|
||||
columns: [],
|
||||
query: {},
|
||||
tableRows: [],
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve trial balance sheet.
|
||||
*/
|
||||
export function useTrialBalanceSheet(query, props) {
|
||||
return useQuery(
|
||||
const states = useQuery(
|
||||
['FINANCIAL-REPORT', 'TRIAL-BALANCE-SHEET', query],
|
||||
() =>
|
||||
ApiService.get('/financial_statements/trial_balance_sheet', {
|
||||
params: query,
|
||||
}).then(transformTrialBalance),
|
||||
}),
|
||||
{
|
||||
initialData: {
|
||||
tableRows: [],
|
||||
data: [],
|
||||
query: {},
|
||||
},
|
||||
select: (res) => ({
|
||||
tableRows: trialBalanceSheetReducer(res.data.data),
|
||||
...res.data,
|
||||
}),
|
||||
...props,
|
||||
},
|
||||
);
|
||||
|
||||
return {
|
||||
...states,
|
||||
data: defaultTo(states.data, {
|
||||
tableRows: [],
|
||||
data: [],
|
||||
query: {},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve profit/loss (P&L) sheet.
|
||||
*/
|
||||
export function useProfitLossSheet(query, props) {
|
||||
return useQuery(
|
||||
const states = useQuery(
|
||||
['FINANCIAL-REPORT', 'PROFIT-LOSS-SHEET', query],
|
||||
() =>
|
||||
ApiService.get('/financial_statements/profit_loss_sheet', {
|
||||
params: query,
|
||||
}).then(transformProfitLoss),
|
||||
}),
|
||||
{
|
||||
initialData: {
|
||||
data: {},
|
||||
tableRows: [],
|
||||
columns: [],
|
||||
query: {},
|
||||
},
|
||||
select: (res) => ({
|
||||
tableRows: profitLossSheetReducer(res.data.data),
|
||||
...res.data,
|
||||
}),
|
||||
...props,
|
||||
},
|
||||
);
|
||||
return {
|
||||
...states,
|
||||
data: defaultTo(states.data, {
|
||||
data: {},
|
||||
tableRows: [],
|
||||
columns: [],
|
||||
query: {},
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve general ledger (GL) sheet.
|
||||
*/
|
||||
export function useGeneralLedgerSheet(query, props) {
|
||||
return useQuery(
|
||||
const states = useQuery(
|
||||
['FINANCIAL-REPORT', 'GENERAL-LEDGER', query],
|
||||
() =>
|
||||
ApiService.get('/financial_statements/general_ledger', {
|
||||
params: query,
|
||||
}).then(transformGeneralLedger),
|
||||
}),
|
||||
{
|
||||
initialData: {
|
||||
tableRows: [],
|
||||
data: {},
|
||||
query: {}
|
||||
},
|
||||
...props
|
||||
select: (res) => ({
|
||||
tableRows: generalLedgerTableRowsReducer(res.data.data),
|
||||
...res.data,
|
||||
}),
|
||||
...props,
|
||||
},
|
||||
);
|
||||
|
||||
return {
|
||||
...states,
|
||||
data: defaultTo(states.data, {
|
||||
tableRows: [],
|
||||
data: {},
|
||||
query: {},
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve journal sheet.
|
||||
*/
|
||||
export function useJournalSheet(query, props) {
|
||||
return useQuery(
|
||||
const states = useQuery(
|
||||
['FINANCIAL-REPORT', 'JOURNAL', query],
|
||||
() =>
|
||||
ApiService.get('/financial_statements/journal', { params: query }).then(
|
||||
transformJournal,
|
||||
),
|
||||
ApiService.get('/financial_statements/journal', { params: query }),
|
||||
{
|
||||
initialData: {
|
||||
data: {},
|
||||
tableRows: [],
|
||||
query: {},
|
||||
},
|
||||
...props
|
||||
select: (res) => ({
|
||||
tableRows: journalTableRowsReducer(res.data.data),
|
||||
...res.data,
|
||||
}),
|
||||
...props,
|
||||
},
|
||||
);
|
||||
|
||||
return {
|
||||
...states,
|
||||
data: defaultTo(states.data, {
|
||||
data: {},
|
||||
tableRows: [],
|
||||
query: {},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve AR aging summary report.
|
||||
*/
|
||||
export function useARAgingSummaryReport(query, props) {
|
||||
return useQuery(
|
||||
['FINANCIAL-REPORT', 'AR-AGING-SUMMARY', query],
|
||||
|
||||
@@ -1,20 +1,8 @@
|
||||
import { defaultTo } from 'lodash';
|
||||
import { useQueryClient, useQuery, useMutation } from 'react-query';
|
||||
import ApiService from 'services/ApiService';
|
||||
import { transformPagination } from 'utils';
|
||||
|
||||
// Invoices transformer.
|
||||
const invoicesTransformer = (response) => {
|
||||
return {
|
||||
invoices: response.data.sales_invoices,
|
||||
pagination: response.data.pagination,
|
||||
filterMeta: response.data.filter_meta,
|
||||
};
|
||||
};
|
||||
|
||||
const invoiceTransformer = (response) => {
|
||||
return {
|
||||
invoice: response.data.invoice,
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Creates a new sale invoice.
|
||||
*/
|
||||
@@ -64,24 +52,31 @@ export function useDeleteInvoice(props) {
|
||||
* Retrieve sale invoices list with pagination meta.
|
||||
*/
|
||||
export function useInvoices(query, props) {
|
||||
return useQuery(
|
||||
const states = useQuery(
|
||||
['SALE_INVOICES', query],
|
||||
() =>
|
||||
ApiService.get('sales/invoices', { params: query }).then(
|
||||
invoicesTransformer,
|
||||
),
|
||||
() => ApiService.get('sales/invoices', { params: query }),
|
||||
{
|
||||
initialData: {
|
||||
saleInvoices: [],
|
||||
pagination: {
|
||||
page: 1,
|
||||
page_size: 12,
|
||||
total: 0,
|
||||
},
|
||||
},
|
||||
select: (res) => ({
|
||||
invoices: res.data.sales_invoices,
|
||||
pagination: transformPagination(res.data.pagination),
|
||||
filterMeta: res.data.filter_meta,
|
||||
}),
|
||||
...props,
|
||||
},
|
||||
);
|
||||
|
||||
return {
|
||||
...states,
|
||||
data: defaultTo(states.data, {
|
||||
invoices: [],
|
||||
pagination: {
|
||||
page: 1,
|
||||
pageSize: 12,
|
||||
total: 0,
|
||||
},
|
||||
filterMeta: {},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -105,11 +100,16 @@ export function useDeliverInvoice(props) {
|
||||
* Retrieve the sale invoice details.
|
||||
*/
|
||||
export function useInvoice(id, props) {
|
||||
return useQuery(['SALE_INVOICE', id], () =>
|
||||
ApiService.get(`sales/invoices/${id}`).then(invoiceTransformer),
|
||||
const states = useQuery(['SALE_INVOICE', id], () =>
|
||||
ApiService.get(`sales/invoices/${id}`),
|
||||
{
|
||||
initialData: {},
|
||||
select: (res) => res.data.invoice,
|
||||
...props
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
return {
|
||||
...states,
|
||||
data: defaultTo(states.data, {}),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,25 +1,33 @@
|
||||
import { defaultTo } from 'lodash';
|
||||
import { useMutation, useQuery, useQueryClient } from 'react-query';
|
||||
import ApiService from 'services/ApiService';
|
||||
|
||||
const transformPaymentMades = (response) => {
|
||||
return {};
|
||||
};
|
||||
import { transformPagination } from 'utils';
|
||||
|
||||
/**
|
||||
* Retrieve payment mades list.
|
||||
*/
|
||||
export function usePaymentMades(query, props) {
|
||||
return useQuery(
|
||||
const states = useQuery(
|
||||
['PAYMENT_MADES', query],
|
||||
() =>
|
||||
ApiService.get('sales/payment_mades', { params: query }).then(
|
||||
transformPaymentMades,
|
||||
),
|
||||
() => ApiService.get('purchases/bill_payments', { params: query }),
|
||||
{
|
||||
initialData: [],
|
||||
select: (res) => ({
|
||||
paymentMades: res.data.bill_payments,
|
||||
pagination: transformPagination(res.data.pagination),
|
||||
filterMeta: res.data.filter_meta,
|
||||
}),
|
||||
...props,
|
||||
},
|
||||
);
|
||||
|
||||
return {
|
||||
...states,
|
||||
data: defaultTo(states.data, {
|
||||
paymentMades: [],
|
||||
pagination: {},
|
||||
filterMeta: {}
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -29,7 +37,7 @@ export function useCreatePaymentMade(props) {
|
||||
const client = useQueryClient();
|
||||
|
||||
return useMutation(
|
||||
(values) => ApiService.post('sales/payment_mades', values),
|
||||
(values) => ApiService.post('purchases/bill_payments', values),
|
||||
{
|
||||
onSuccess: () => {
|
||||
client.invalidateQueries('PAYMENT_MADES');
|
||||
@@ -46,7 +54,7 @@ export function useEditPaymentMade(props) {
|
||||
const client = useQueryClient();
|
||||
|
||||
return useMutation(
|
||||
(id, values) => ApiService.post(`sales/payment_mades/${id}`, values),
|
||||
(id, values) => ApiService.post(`purchases/bill_payments/${id}`, values),
|
||||
{
|
||||
onSuccess: () => {
|
||||
client.invalidateQueries('PAYMENT_MADES');
|
||||
@@ -63,7 +71,7 @@ export function useDeletePaymentMade(props) {
|
||||
const client = useQueryClient();
|
||||
|
||||
return useMutation(
|
||||
(id, values) => ApiService.delete(`sales/payment_mades/${id}`, values),
|
||||
(id, values) => ApiService.delete(`purchases/bill_payments/${id}`, values),
|
||||
{
|
||||
onSuccess: () => {
|
||||
client.invalidateQueries('PAYMENT_MADES');
|
||||
@@ -77,15 +85,14 @@ export function useDeletePaymentMade(props) {
|
||||
* Retrieve specific payment made.
|
||||
*/
|
||||
export function usePaymentMade(id, props) {
|
||||
return useQuery(
|
||||
const states = useQuery(
|
||||
['PAYMENT_MADE', id],
|
||||
() =>
|
||||
ApiService.get(`sales/payment_mades/${id}`).then(
|
||||
transformPaymentMades,
|
||||
),
|
||||
{
|
||||
initialData: [],
|
||||
...props,
|
||||
},
|
||||
() => ApiService.get(`purchases/bill_payments/${id}`),
|
||||
props,
|
||||
);
|
||||
|
||||
return {
|
||||
...states,
|
||||
data: defaultTo(states.data, {}),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,25 +1,37 @@
|
||||
import { useMutation, useQuery, useQueryClient } from 'react-query';
|
||||
import { defaultTo } from 'lodash';
|
||||
import ApiService from 'services/ApiService';
|
||||
|
||||
const transformPaymentReceives = (response) => {
|
||||
return {};
|
||||
};
|
||||
import { transformPagination } from 'utils';
|
||||
|
||||
/**
|
||||
* Retrieve accounts list.
|
||||
*/
|
||||
export function usePaymentReceives(query, props) {
|
||||
return useQuery(
|
||||
const states = useQuery(
|
||||
['PAYMENT_RECEIVES', query],
|
||||
() =>
|
||||
ApiService.get('sales/payment_receives', { params: query }).then(
|
||||
transformPaymentReceives,
|
||||
),
|
||||
() => ApiService.get('sales/payment_receives', { params: query }),
|
||||
{
|
||||
initialData: [],
|
||||
select: (res) => ({
|
||||
paymentReceives: res.data.payment_receives,
|
||||
pagination: transformPagination(res.data.pagination),
|
||||
filterMeta: res.data.filter_meta,
|
||||
}),
|
||||
...props,
|
||||
},
|
||||
);
|
||||
|
||||
return {
|
||||
...states,
|
||||
data: defaultTo(states.data, {
|
||||
paymentReceives: [],
|
||||
pagination: {
|
||||
page: 1,
|
||||
pageSize: 12,
|
||||
total: 0,
|
||||
},
|
||||
filterMeta: {},
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -77,15 +89,14 @@ export function useDeletePaymentReceive(props) {
|
||||
* Retrieve specific payment receive.
|
||||
*/
|
||||
export function usePaymentReceive(id, props) {
|
||||
return useQuery(
|
||||
const states = useQuery(
|
||||
['PAYMENT_RECEIVE', id],
|
||||
() =>
|
||||
ApiService.get(`sales/payment_receives/${id}`).then(
|
||||
transformPaymentReceives,
|
||||
),
|
||||
{
|
||||
initialData: [],
|
||||
...props,
|
||||
},
|
||||
() => ApiService.get(`sales/payment_receives/${id}`),
|
||||
props,
|
||||
);
|
||||
|
||||
return {
|
||||
...states,
|
||||
data: defaultTo(states.data, {}),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +1,8 @@
|
||||
import { useQueryClient, useQuery, useMutation } from 'react-query';
|
||||
import { defaultTo } from 'lodash';
|
||||
import ApiService from 'services/ApiService';
|
||||
import { transformPagination } from 'utils';
|
||||
|
||||
// Receipts transformer.
|
||||
const invoicesTransformer = (response) => {
|
||||
return {
|
||||
invoices: response.data.sales_invoices,
|
||||
pagination: response.data.pagination,
|
||||
filterMeta: response.data.filter_meta,
|
||||
};
|
||||
};
|
||||
|
||||
const receiptTransformer = (response) => {
|
||||
return response.data;
|
||||
}
|
||||
/**
|
||||
* Creates a new sale invoice.
|
||||
*/
|
||||
@@ -76,39 +66,48 @@ export function useCloseReceipt(props) {
|
||||
* Retrieve sale invoices list with pagination meta.
|
||||
*/
|
||||
export function useReceipts(query, props) {
|
||||
return useQuery(
|
||||
const states = useQuery(
|
||||
['SALE_RECEIPTS', query],
|
||||
() =>
|
||||
ApiService
|
||||
.get('sales/receipts', { params: query })
|
||||
.then(invoicesTransformer),
|
||||
() => ApiService.get('sales/receipts', { params: query }),
|
||||
{
|
||||
initialData: {
|
||||
saleReceipts: [],
|
||||
pagination: {
|
||||
page: 1,
|
||||
page_size: 12,
|
||||
total: 0,
|
||||
},
|
||||
},
|
||||
select: (response) => ({
|
||||
receipts: response.data.sale_receipts,
|
||||
pagination: transformPagination(response.data.pagination),
|
||||
filterMeta: response.data.filter_meta,
|
||||
}),
|
||||
...props,
|
||||
},
|
||||
);
|
||||
|
||||
return {
|
||||
...states,
|
||||
data: defaultTo(states.data, {
|
||||
receipts: [],
|
||||
pagination: {
|
||||
page: 1,
|
||||
page_size: 12,
|
||||
total: 0,
|
||||
},
|
||||
filterMeta: {},
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve sale invoices list with pagination meta.
|
||||
*/
|
||||
export function useReceipt(id, props) {
|
||||
return useQuery(
|
||||
const states = useQuery(
|
||||
['SALE_RECEIPT', id],
|
||||
() =>
|
||||
ApiService
|
||||
.get(`sales/receipts/${id}`)
|
||||
.then(receiptTransformer),
|
||||
() => ApiService.get(`sales/receipts/${id}`),
|
||||
{
|
||||
initialData: {},
|
||||
select: (res) => res.data.sale_receipt,
|
||||
...props,
|
||||
},
|
||||
);
|
||||
|
||||
return {
|
||||
...states,
|
||||
data: defaultTo(states.data, {}),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user