mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 21:00:31 +00:00
WIP/ Feature : Estimate & Receipt & Bill & Invoice
This commit is contained in:
@@ -29,9 +29,12 @@ export const submitInvoice = ({ form }) => {
|
||||
export const deleteInvoice = ({ id }) => {
|
||||
return (dispatch) =>
|
||||
new Promise((resovle, reject) => {
|
||||
ApiService.delete(`invoice/${id}`)
|
||||
ApiService.delete(`sales/invoices/${id}`)
|
||||
.then((response) => {
|
||||
dispatch({ type: t.INVOICE_DELETE });
|
||||
dispatch({
|
||||
type: t.INVOICE_DELETE,
|
||||
payload: { id },
|
||||
});
|
||||
resovle(response);
|
||||
})
|
||||
.catch((error) => {
|
||||
@@ -46,7 +49,7 @@ export const editInvoice = (id, form) => {
|
||||
dispatch({
|
||||
type: t.SET_DASHBOARD_REQUEST_LOADING,
|
||||
});
|
||||
ApiService.post(`invoice/${id}`, form)
|
||||
ApiService.post(`sales/invoices/${id}`, form)
|
||||
.then((response) => {
|
||||
dispatch({
|
||||
type: t.SET_DASHBOARD_REQUEST_COMPLETED,
|
||||
@@ -64,39 +67,39 @@ export const editInvoice = (id, form) => {
|
||||
});
|
||||
});
|
||||
};
|
||||
export const fetchInvoicesTable = ({ query = {} }) => {
|
||||
return (dispatch, getState) =>
|
||||
new Promise((resolve, rejcet) => {
|
||||
const pageQuery = getState().invoices.tableQuery;
|
||||
|
||||
export const fetchInvoicesTable = ({ query } = {}) => {
|
||||
return (dispatch, getState) =>
|
||||
new Promise((resolve, reject) => {
|
||||
const pageQuery = getState().sales_invoices.tableQuery;
|
||||
dispatch({
|
||||
type: t.INVOICES_TABLE_LOADING,
|
||||
payload: {
|
||||
loading: true,
|
||||
},
|
||||
});
|
||||
ApiService.get('invoices', {
|
||||
ApiService.get('sales/invoices', {
|
||||
params: { ...pageQuery, ...query },
|
||||
})
|
||||
.then((response) => {
|
||||
dispatch({
|
||||
type: t.INVOICES_PAGE_SET,
|
||||
payload: {
|
||||
invoices: response.data.invoices.results,
|
||||
pagination: response.data.invoices.pagination,
|
||||
sales_invoices: response.data.sales_invoices.results,
|
||||
pagination: response.data.sales_invoices.pagination,
|
||||
customViewId: response.data.customViewId || -1,
|
||||
},
|
||||
});
|
||||
dispatch({
|
||||
type: t.INVOICES_ITEMS_SET,
|
||||
payload: {
|
||||
invoices: response.data.invoices.results,
|
||||
sales_invoices: response.data.sales_invoices.results,
|
||||
},
|
||||
});
|
||||
dispatch({
|
||||
type: t.INVOICES_PAGINATION_SET,
|
||||
payload: {
|
||||
pagination: response.data.invoices.pagination,
|
||||
pagination: response.data.sales_invoices.pagination,
|
||||
customViewId: response.data.customViewId || -1,
|
||||
},
|
||||
});
|
||||
@@ -109,7 +112,7 @@ export const fetchInvoicesTable = ({ query = {} }) => {
|
||||
resolve(response);
|
||||
})
|
||||
.catch((error) => {
|
||||
rejcet(error);
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
};
|
||||
@@ -117,13 +120,13 @@ export const fetchInvoicesTable = ({ query = {} }) => {
|
||||
export const fetchInvoice = ({ id }) => {
|
||||
return (dispatch) =>
|
||||
new Promise((resovle, reject) => {
|
||||
ApiService.get(`invoices/${id}`)
|
||||
ApiService.get(`sales/invoices/${id}`)
|
||||
.then((response) => {
|
||||
dispatch({
|
||||
type: t.INVOICE_SET,
|
||||
payload: {
|
||||
id,
|
||||
invoice: response.data.invoice,
|
||||
sale_invoice: response.data.sale_invoice,
|
||||
},
|
||||
});
|
||||
resovle(response);
|
||||
|
||||
@@ -7,26 +7,99 @@ const initialState = {
|
||||
items: {},
|
||||
views: {},
|
||||
loading: false,
|
||||
currentViewId: -1,
|
||||
tableQuery: {
|
||||
page_size: 12,
|
||||
page_size: 5,
|
||||
page: 1,
|
||||
},
|
||||
currentViewId: -1,
|
||||
};
|
||||
|
||||
const defaultInvoice = {
|
||||
entires: [],
|
||||
entries: [],
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
const reducer = createReducer(initialState, {
|
||||
[t.INVOICE_SET]:(state,actio)=>{
|
||||
[t.INVOICE_SET]: (state, action) => {
|
||||
const { id, sale_invoice } = action.payload;
|
||||
const _invoice = state.items[id] || {};
|
||||
|
||||
const {id,INVOICE_SET} = action.payload;
|
||||
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,
|
||||
...invoice,
|
||||
};
|
||||
});
|
||||
state.items = {
|
||||
...state.items,
|
||||
..._invoices,
|
||||
};
|
||||
},
|
||||
|
||||
[t.INVOICES_TABLE_LOADING]: (state, action) => {
|
||||
const { loading } = action.payload;
|
||||
state.loading = loading;
|
||||
},
|
||||
|
||||
[t.INVOICES_SET_CURRENT_VIEW]: (state, action) => {
|
||||
state.currentViewId = action.currentViewId;
|
||||
},
|
||||
|
||||
[t.INVOICE_DELETE]: (state, action) => {
|
||||
const { id } = action.payload;
|
||||
|
||||
if (typeof state.items[id] !== 'undefined') {
|
||||
delete state.items[id];
|
||||
}
|
||||
},
|
||||
|
||||
[t.INVOICES_PAGE_SET]: (state, action) => {
|
||||
const { customViewId, sales_invoices, pagination } = action.payload;
|
||||
|
||||
const viewId = customViewId || -1;
|
||||
const view = state.views[viewId] || {};
|
||||
|
||||
state.views[viewId] = {
|
||||
...view,
|
||||
pages: {
|
||||
...(state.views?.[viewId]?.pages || {}),
|
||||
[pagination.page]: {
|
||||
ids: sales_invoices.map((i) => i.id),
|
||||
},
|
||||
},
|
||||
};
|
||||
},
|
||||
|
||||
[t.INVOICES_PAGINATION_SET]: (state, action) => {
|
||||
const { pagination, customViewId } = action.payload;
|
||||
|
||||
const mapped = {
|
||||
pageSize: parseInt(pagination.pageSize, 10),
|
||||
page: parseInt(pagination.page, 10),
|
||||
total: parseInt(pagination.total, 10),
|
||||
};
|
||||
const paginationMeta = {
|
||||
...mapped,
|
||||
pagesCount: Math.ceil(mapped.total / mapped.pageSize),
|
||||
pageIndex: Math.max(mapped.page - 1, 0),
|
||||
};
|
||||
state.views = {
|
||||
...state.views,
|
||||
[customViewId]: {
|
||||
...(state.views?.[customViewId] || {}),
|
||||
paginationMeta,
|
||||
},
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
export default createTableQueryReducers('sales_invoices', reducer);
|
||||
|
||||
export const getInvoiceById = (state, id) => {
|
||||
return state.sales_invoices.items[id];
|
||||
};
|
||||
|
||||
@@ -1,9 +1,54 @@
|
||||
import { createSelector } from '@reduxjs/toolkit';
|
||||
import { pickItemsFromIds, paginationLocationQuery } from 'store/selectors';
|
||||
|
||||
const invoiceByIdSelector = (state, props) =>
|
||||
state.invoices.items[props.invoiceId];
|
||||
const invoiceTableQuery = (state) => state.sales_invoices.tableQuery;
|
||||
|
||||
export const getInvoiceById = () =>
|
||||
createSelector(invoiceByIdSelector, (_invoice) => {
|
||||
return _invoice;
|
||||
export const getInvoiceTableQuery = createSelector(
|
||||
paginationLocationQuery,
|
||||
invoiceTableQuery,
|
||||
(locationQuery, tableQuery) => {
|
||||
return {
|
||||
...locationQuery,
|
||||
...tableQuery,
|
||||
};
|
||||
},
|
||||
);
|
||||
|
||||
const invoicesPageSelector = (state, props, query) => {
|
||||
const viewId = state.sales_invoices.currentViewId;
|
||||
return state.sales_invoices.views?.[viewId]?.pages?.[query.page];
|
||||
};
|
||||
|
||||
const invoicesItemsSelector = (state) => {
|
||||
return state.sales_invoices.items;
|
||||
};
|
||||
|
||||
export const getInvoiceCurrentPageFactory = () =>
|
||||
createSelector(
|
||||
invoicesPageSelector,
|
||||
invoicesItemsSelector,
|
||||
(invoicePage, invoicesItems) => {
|
||||
return typeof invoicePage === 'object'
|
||||
? pickItemsFromIds(invoicesItems, invoicePage.ids) || []
|
||||
: [];
|
||||
},
|
||||
);
|
||||
|
||||
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 || {};
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user