mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 13:20:31 +00:00
feat: payment receive of customers invoices.
This commit is contained in:
@@ -121,26 +121,32 @@ export const fetchInvoice = ({ id }) => {
|
||||
});
|
||||
});
|
||||
};
|
||||
export const dueInvoices = ({ id }) => {
|
||||
return (dispatch) =>
|
||||
new Promise((resovle, reject) => {
|
||||
ApiService.get(`sales/invoices/due_invoices`, {
|
||||
params: { customer_id: id },
|
||||
})
|
||||
.then((response) => {
|
||||
dispatch({
|
||||
type: t.DUE_INVOICES_SET,
|
||||
payload: {
|
||||
customer_id: id,
|
||||
due_sales_invoices: response.data.due_sales_invoices,
|
||||
},
|
||||
});
|
||||
resovle(response);
|
||||
})
|
||||
.catch((error) => {
|
||||
const { response } = error;
|
||||
const { data } = response;
|
||||
reject(data?.errors);
|
||||
|
||||
export const fetchDueInvoices = ({ customerId }) => (dispatch) => new Promise((resovle, reject) => {
|
||||
ApiService.get(`sales/invoices/payable`, {
|
||||
params: { customer_id: customerId },
|
||||
})
|
||||
.then((response) => {
|
||||
dispatch({
|
||||
type: t.INVOICES_ITEMS_SET,
|
||||
payload: {
|
||||
sales_invoices: response.data.sales_invoices,
|
||||
},
|
||||
});
|
||||
if (customerId) {
|
||||
dispatch({
|
||||
type: t.INVOICES_RECEIVABLE_BY_CUSTOMER_ID,
|
||||
payload: {
|
||||
customerId,
|
||||
saleInvoices: response.data.sales_invoices,
|
||||
},
|
||||
});
|
||||
}
|
||||
resovle(response);
|
||||
})
|
||||
.catch((error) => {
|
||||
const { response } = error;
|
||||
const { data } = response;
|
||||
reject(data?.errors);
|
||||
});
|
||||
};
|
||||
});
|
||||
|
||||
@@ -13,6 +13,10 @@ const initialState = {
|
||||
page: 1,
|
||||
},
|
||||
dueInvoices: {},
|
||||
receivable: {
|
||||
byCustomerId: [],
|
||||
byPaymentReceiveId: [],
|
||||
}
|
||||
};
|
||||
|
||||
const defaultInvoice = {
|
||||
@@ -97,39 +101,19 @@ const reducer = createReducer(initialState, {
|
||||
},
|
||||
};
|
||||
},
|
||||
[t.DUE_INVOICES_SET]: (state, action) => {
|
||||
const { customer_id, due_sales_invoices } = action.payload;
|
||||
|
||||
const _dueInvoices = [];
|
||||
[t.INVOICES_RECEIVABLE_BY_PAYMENT_ID]: (state, action) => {
|
||||
const { paymentReceiveId, saleInvoices } = action.payload;
|
||||
const saleInvoicesIds = saleInvoices.map((saleInvoice) => saleInvoice.id);
|
||||
|
||||
state.dueInvoices[customer_id] = due_sales_invoices.map((due) => due.id);
|
||||
const _invoices = {};
|
||||
due_sales_invoices.forEach((invoice) => {
|
||||
_invoices[invoice.id] = {
|
||||
...invoice,
|
||||
};
|
||||
});
|
||||
|
||||
state.items = {
|
||||
...state.dueInvoices,
|
||||
...state.items.dueInvoices,
|
||||
..._invoices,
|
||||
};
|
||||
state.receivable.byPaymentReceiveId[paymentReceiveId] = saleInvoicesIds;
|
||||
},
|
||||
[t.RELOAD_INVOICES]: (state, action) => {
|
||||
const { sales_invoices } = action.payload;
|
||||
|
||||
const _sales_invoices = {};
|
||||
sales_invoices.forEach((invoice) => {
|
||||
_sales_invoices[invoice.id] = {
|
||||
...invoice,
|
||||
};
|
||||
});
|
||||
[t.INVOICES_RECEIVABLE_BY_CUSTOMER_ID]: (state, action) => {
|
||||
const { customerId, saleInvoices } = action.payload;
|
||||
const saleInvoiceIds = saleInvoices.map((saleInvoice) => saleInvoice.id);
|
||||
|
||||
state.items = {
|
||||
...state.items,
|
||||
..._sales_invoices,
|
||||
};
|
||||
state.receivable.byCustomerId[customerId] = saleInvoiceIds
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -22,6 +22,10 @@ const invoicesPageSelector = (state, props, query) => {
|
||||
|
||||
const invoicesItemsSelector = (state) => state.salesInvoices.items;
|
||||
|
||||
const invoicesReceiableCustomerSelector = (state, props) => state.salesInvoices.receivable.byCustomerId[props.customerId];
|
||||
const paymentReceivableInvoicesSelector = (state, props) => state.salesInvoices.receivable.byPaymentReceiveId[props.paymentReceiveId];
|
||||
|
||||
|
||||
export const getInvoiceTableQueryFactory = () =>
|
||||
createSelector(
|
||||
paginationLocationQuery,
|
||||
@@ -55,17 +59,39 @@ export const getInvoicePaginationMetaFactory = () =>
|
||||
return invoicePage?.paginationMeta || {};
|
||||
});
|
||||
|
||||
const dueInvoicesSelector = (state, props) => {
|
||||
return state.salesInvoices.dueInvoices[props.customer_id] || [];
|
||||
};
|
||||
// export const getCustomerReceivableInvoicesFactory = () =>
|
||||
// createSelector(
|
||||
// invoicesItemsSelector,
|
||||
// invoicesReceiableCustomerSelector,
|
||||
// (invoicesItems, invoicesIds) => {
|
||||
// return Array.isArray(invoicesIds)
|
||||
// ? (pickItemsFromIds(invoicesItems, invoicesIds) || [])
|
||||
// : [];
|
||||
// },
|
||||
// );
|
||||
|
||||
export const getdueInvoices = createSelector(
|
||||
dueInvoicesSelector,
|
||||
invoicesItemsSelector,
|
||||
(customerIds, items) => {
|
||||
|
||||
return typeof customerIds === 'object'
|
||||
? pickItemsFromIds(items, customerIds) || []
|
||||
: [];
|
||||
},
|
||||
);
|
||||
// export const getPaymentReceivableInvoicesFactory = () =>
|
||||
// createSelector(
|
||||
// invoicesItemsSelector,
|
||||
// paymentReceivableInvoicesSelector,
|
||||
// (invoicesItems, invoicesIds) => {
|
||||
// return Array.isArray(invoicesIds)
|
||||
// ? (pickItemsFromIds(invoicesItems, invoicesIds) || [])
|
||||
// : [];
|
||||
// },
|
||||
// );
|
||||
|
||||
|
||||
export const getPaymentReceiveReceivableInvoicesFactory = () =>
|
||||
createSelector(
|
||||
invoicesItemsSelector,
|
||||
invoicesReceiableCustomerSelector,
|
||||
paymentReceivableInvoicesSelector,
|
||||
(invoicesItems, customerInvoicesIds, paymentInvoicesIds) => {
|
||||
const invoicesIds = [
|
||||
...(customerInvoicesIds || []),
|
||||
...(paymentInvoicesIds || []),
|
||||
];
|
||||
return pickItemsFromIds(invoicesItems, invoicesIds);
|
||||
},
|
||||
);
|
||||
@@ -11,4 +11,7 @@ export default {
|
||||
INVOICES_ITEMS_SET: 'INVOICES_ITEMS_SET',
|
||||
DUE_INVOICES_SET: 'DUE_INVOICES_SET',
|
||||
RELOAD_INVOICES: 'RELOAD_INVOICES',
|
||||
|
||||
INVOICES_RECEIVABLE_BY_PAYMENT_ID: 'INVOICES_RECEIVABLE_BY_PAYMENT_ID',
|
||||
INVOICES_RECEIVABLE_BY_CUSTOMER_ID: 'INVOICES_RECEIVABLE_BY_CUSTOMER_ID'
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user