mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 21:00:31 +00:00
feature : Puschases & Sales / fix : tasks
This commit is contained in:
@@ -4,22 +4,13 @@ import t from 'store/types';
|
||||
export const submitInvoice = ({ form }) => {
|
||||
return (dispatch) =>
|
||||
new Promise((resolve, reject) => {
|
||||
dispatch({
|
||||
type: t.SET_DASHBOARD_REQUEST_LOADING,
|
||||
});
|
||||
ApiService.post('sales/invoices', form)
|
||||
.then((response) => {
|
||||
dispatch({
|
||||
type: t.SET_DASHBOARD_REQUEST_COMPLETED,
|
||||
});
|
||||
resolve(response);
|
||||
})
|
||||
.catch((error) => {
|
||||
const { response } = error;
|
||||
const { data } = response;
|
||||
dispatch({
|
||||
type: t.SET_DASHBOARD_REQUEST_COMPLETED,
|
||||
});
|
||||
|
||||
reject(data?.errors);
|
||||
});
|
||||
@@ -51,18 +42,12 @@ export const editInvoice = (id, form) => {
|
||||
});
|
||||
ApiService.post(`sales/invoices/${id}`, form)
|
||||
.then((response) => {
|
||||
dispatch({
|
||||
type: t.SET_DASHBOARD_REQUEST_COMPLETED,
|
||||
});
|
||||
resolve(response);
|
||||
})
|
||||
.catch((error) => {
|
||||
const { response } = error;
|
||||
const { data } = response;
|
||||
|
||||
dispatch({
|
||||
type: t.SET_DASHBOARD_REQUEST_COMPLETED,
|
||||
});
|
||||
reject(data?.errors);
|
||||
});
|
||||
});
|
||||
@@ -71,7 +56,7 @@ export const editInvoice = (id, form) => {
|
||||
export const fetchInvoicesTable = ({ query } = {}) => {
|
||||
return (dispatch, getState) =>
|
||||
new Promise((resolve, reject) => {
|
||||
const pageQuery = getState().sales_invoices.tableQuery;
|
||||
const pageQuery = getState().salesInvoices.tableQuery;
|
||||
dispatch({
|
||||
type: t.INVOICES_TABLE_LOADING,
|
||||
payload: {
|
||||
@@ -90,6 +75,7 @@ export const fetchInvoicesTable = ({ query } = {}) => {
|
||||
customViewId: response.data.customViewId || -1,
|
||||
},
|
||||
});
|
||||
|
||||
dispatch({
|
||||
type: t.INVOICES_ITEMS_SET,
|
||||
payload: {
|
||||
@@ -138,3 +124,26 @@ 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);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
@@ -12,6 +12,7 @@ const initialState = {
|
||||
page_size: 5,
|
||||
page: 1,
|
||||
},
|
||||
dueInvoices: {},
|
||||
};
|
||||
|
||||
const defaultInvoice = {
|
||||
@@ -22,13 +23,13 @@ const reducer = createReducer(initialState, {
|
||||
[t.INVOICE_SET]: (state, action) => {
|
||||
const { id, sale_invoice } = action.payload;
|
||||
const _invoice = state.items[id] || {};
|
||||
|
||||
state.items[id] = { ...defaultInvoice, ..._invoice, ...sale_invoice };
|
||||
},
|
||||
|
||||
[t.INVOICES_ITEMS_SET]: (state, action) => {
|
||||
const { sales_invoices } = action.payload;
|
||||
const _invoices = {};
|
||||
|
||||
sales_invoices.forEach((invoice) => {
|
||||
_invoices[invoice.id] = {
|
||||
...defaultInvoice,
|
||||
@@ -96,6 +97,40 @@ const reducer = createReducer(initialState, {
|
||||
},
|
||||
};
|
||||
},
|
||||
[t.DUE_INVOICES_SET]: (state, action) => {
|
||||
const { customer_id, due_sales_invoices } = action.payload;
|
||||
|
||||
const _dueInvoices = [];
|
||||
|
||||
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,
|
||||
};
|
||||
},
|
||||
[t.RELOAD_INVOICES]: (state, action) => {
|
||||
const { sales_invoices } = action.payload;
|
||||
|
||||
const _sales_invoices = {};
|
||||
sales_invoices.forEach((invoice) => {
|
||||
_sales_invoices[invoice.id] = {
|
||||
...invoice,
|
||||
};
|
||||
});
|
||||
|
||||
state.items = {
|
||||
...state.items,
|
||||
..._sales_invoices,
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
export default createTableQueryReducers('sales_invoices', reducer);
|
||||
|
||||
@@ -1,27 +1,38 @@
|
||||
import { createSelector } from '@reduxjs/toolkit';
|
||||
import { pickItemsFromIds, paginationLocationQuery } from 'store/selectors';
|
||||
|
||||
const invoiceTableQuery = (state) => state.sales_invoices.tableQuery;
|
||||
|
||||
export const getInvoiceTableQuery = createSelector(
|
||||
import {
|
||||
pickItemsFromIds,
|
||||
paginationLocationQuery,
|
||||
invoiceTableQuery,
|
||||
(locationQuery, tableQuery) => {
|
||||
return {
|
||||
...locationQuery,
|
||||
...tableQuery,
|
||||
};
|
||||
},
|
||||
);
|
||||
getItemById,
|
||||
} from 'store/selectors';
|
||||
|
||||
const invoiceTableQuery = (state) => state.salesInvoices.tableQuery;
|
||||
|
||||
const invoicesByIdSelector = (state, props) =>
|
||||
state.salesInvoices.items[props.invoiceId];
|
||||
|
||||
const invoicesPaginationSelector = (state, props) => {
|
||||
const viewId = state.salesInvoices.currentViewId;
|
||||
return state.salesInvoices.views?.[viewId];
|
||||
};
|
||||
|
||||
const invoicesPageSelector = (state, props, query) => {
|
||||
const viewId = state.sales_invoices.currentViewId;
|
||||
return state.sales_invoices.views?.[viewId]?.pages?.[query.page];
|
||||
const viewId = state.salesInvoices.currentViewId;
|
||||
return state.salesInvoices.views?.[viewId]?.pages?.[query.page];
|
||||
};
|
||||
|
||||
const invoicesItemsSelector = (state) => {
|
||||
return state.sales_invoices.items;
|
||||
};
|
||||
const invoicesItemsSelector = (state) => state.salesInvoices.items;
|
||||
|
||||
export const getInvoiceTableQueryFactory = () =>
|
||||
createSelector(
|
||||
paginationLocationQuery,
|
||||
invoiceTableQuery,
|
||||
(locationQuery, tableQuery) => {
|
||||
return {
|
||||
...locationQuery,
|
||||
...tableQuery,
|
||||
};
|
||||
},
|
||||
);
|
||||
|
||||
export const getInvoiceCurrentPageFactory = () =>
|
||||
createSelector(
|
||||
@@ -34,21 +45,27 @@ export const getInvoiceCurrentPageFactory = () =>
|
||||
},
|
||||
);
|
||||
|
||||
const invoicesByIdSelector = (state, props) => {
|
||||
return state.sales_invoices.items[props.invoiceId];
|
||||
};
|
||||
|
||||
export const getInvoiecsByIdFactory = () =>
|
||||
createSelector(invoicesByIdSelector, (invoice) => {
|
||||
return invoice;
|
||||
});
|
||||
|
||||
const invoicesPaginationSelector = (state, props) => {
|
||||
const viewId = state.sales_invoices.currentViewId;
|
||||
return state.sales_invoices.views?.[viewId];
|
||||
};
|
||||
|
||||
export const getInvoicePaginationMetaFactory = () =>
|
||||
createSelector(invoicesPaginationSelector, (invoicePage) => {
|
||||
return invoicePage?.paginationMeta || {};
|
||||
});
|
||||
|
||||
const dueInvoicesSelector = (state, props) => {
|
||||
return state.salesInvoices.dueInvoices[props.customer_id] || [];
|
||||
};
|
||||
|
||||
export const getdueInvoices = createSelector(
|
||||
dueInvoicesSelector,
|
||||
invoicesItemsSelector,
|
||||
(customerIds, items) => {
|
||||
|
||||
return typeof customerIds === 'object'
|
||||
? pickItemsFromIds(items, customerIds) || []
|
||||
: [];
|
||||
},
|
||||
);
|
||||
|
||||
@@ -9,4 +9,6 @@ export default {
|
||||
INVOICES_PAGINATION_SET: 'INVOICES_PAGINATION_SET',
|
||||
INVOICES_PAGE_SET: 'INVOICES_PAGE_SET',
|
||||
INVOICES_ITEMS_SET: 'INVOICES_ITEMS_SET',
|
||||
DUE_INVOICES_SET: 'DUE_INVOICES_SET',
|
||||
RELOAD_INVOICES: 'RELOAD_INVOICES',
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user