WIP/ Feature : Estimate & Receipt & Bill & Invoice

This commit is contained in:
elforjani3
2020-08-12 21:19:52 +02:00
parent 58c6b5466c
commit c86f0b29bf
66 changed files with 4288 additions and 535 deletions

View File

@@ -8,6 +8,7 @@ export const submitEstimate = ({ form }) => {
type: t.SET_DASHBOARD_REQUEST_LOADING,
});
ApiService.post('sales/estimates', form)
.then((response) => {
dispatch({
type: t.SET_DASHBOARD_REQUEST_COMPLETED,
@@ -32,7 +33,7 @@ export const editEstimate = (id, form) => {
dispatch({
type: t.SET_DASHBOARD_REQUEST_LOADING,
});
ApiService.post(`estimates/${id}`, form)
ApiService.post(`sales/estimates/${id}`, form)
.then((response) => {
dispatch({
type: t.SET_DASHBOARD_REQUEST_COMPLETED,
@@ -54,9 +55,12 @@ export const editEstimate = (id, form) => {
export const deleteEstimate = ({ id }) => {
return (dispatch) =>
new Promise((resovle, reject) => {
ApiService.delete(`estimates/${id}`)
ApiService.delete(`sales/estimates/${id}`)
.then((response) => {
dispatch({ type: t.ESTIMATE_DELETE });
dispatch({
type: t.ESTIMATE_DELETE,
payload: { id },
});
resovle(response);
})
.catch((error) => {
@@ -68,8 +72,9 @@ export const deleteEstimate = ({ id }) => {
export const fetchEstimate = ({ id }) => {
return (dispatch) =>
new Promise((resovle, reject) => {
ApiService.get(`estimate/${id}`)
ApiService.get(`sales/estimates/${id}`)
.then((response) => {
dispatch({
type: t.ESTIMATE_SET,
payload: {
@@ -90,36 +95,36 @@ export const fetchEstimate = ({ id }) => {
export const fetchEstimatesTable = ({ query = {} }) => {
return (dispatch, getState) =>
new Promise((resolve, rejcet) => {
const pageQuery = getState().estimates.tableQuery;
const pageQuery = getState().sales_estimates.tableQuery;
dispatch({
type: t.ESTIMATES_TABLE_LOADING,
payload: {
loading: true,
},
});
ApiService.get('estimates', {
ApiService.get('sales/estimates', {
params: { ...pageQuery, ...query },
})
.then((response) => {
// debugger;
dispatch({
type: t.ESTIMATES_PAGE_SET,
payload: {
estimates: response.data.estimates.results,
pagination: response.data.estimates.pagination,
sales_estimates: response.data.sales_estimates.results,
pagination: response.data.sales_estimates.pagination,
customViewId: response.data.customViewId || -1,
},
});
dispatch({
type: t.ESTIMATES_ITEMS_SET,
payload: {
estimates: response.data.estimates.results,
sales_estimates: response.data.sales_estimates.results,
},
});
dispatch({
type: t.ESTIMATES_PAGINATION_SET,
payload: {
pagination: response.data.estimates.pagination,
pagination: response.data.sales_estimates.pagination,
customViewId: response.data.customViewId || -1,
},
});

View File

@@ -8,27 +8,28 @@ const initialState = {
views: {},
loading: false,
tableQuery: {
page_size: 12,
page_size: 5,
page: 1,
},
currentViewId: -1,
};
const defaultEstimate = {
products: [],
entries: [],
};
const reducer = createReducer(initialState, {
[t.ESTIMATE_SET]: (state, action) => {
const { id, estiamate } = action.payload;
const { id, estimate } = action.payload;
const _estimate = state.items[id] || {};
state.items[id] = { ...defaultEstimate, ..._estimate, ...estiamate };
state.items[id] = { ...defaultEstimate, ..._estimate, ...estimate };
},
[t.ESTIMATES_ITEMS_SET]: (state, action) => {
const { estiamates } = action.payload;
const { sales_estimates } = action.payload;
const _estimates = {};
estiamates.forEach((estimate) => {
sales_estimates.forEach((estimate) => {
_estimates[estimate.id] = {
...defaultEstimate,
...estimate,
@@ -58,7 +59,7 @@ const reducer = createReducer(initialState, {
},
[t.ESTIMATES_PAGE_SET]: (state, action) => {
const { customViewId, estimates, pagination } = action.payload;
const { customViewId, sales_estimates, pagination } = action.payload;
const viewId = customViewId || -1;
const view = state.views[viewId] || {};
@@ -68,7 +69,7 @@ const reducer = createReducer(initialState, {
pages: {
...(state.views?.[viewId]?.pages || {}),
[pagination.page]: {
ids: estimates.map((i) => i.id),
ids: sales_estimates.map((i) => i.id),
},
},
};
@@ -98,8 +99,8 @@ const reducer = createReducer(initialState, {
},
});
export default createTableQueryReducers('estimates', reducer);
export default createTableQueryReducers('sales_estimates', reducer);
export const getEstimateById = (state, id) => {
return state.estiamates.items[id];
return state.sales_estimates.items[id];
};

View File

@@ -1,44 +1,54 @@
import { createSelector } from '@reduxjs/toolkit';
import { pickItemsFromIds, paginationLocationQuery } from 'store/selectors';
const estimateTableQuery = (state) => state.estimates.tableQuery;
const estimateTableQuery = (state) => {
return state.sales_estimates.tableQuery;
};
export const getEstimatesTableQuery = createSelector(
paginationLocationQuery,
estimateTableQuery,
(location, query) => ({
...location,
...query,
}),
(locationQuery, tableQuery) => {
return {
...locationQuery,
...tableQuery,
};
},
);
const estimatesSelector = (state, props, query) => {
const viewId = state.estimates.currentViewId;
return state.estimates.views?.[viewId]?.pages?.[query.page];
const estimatesPageSelector = (state, props, query) => {
const viewId = state.sales_estimates.currentViewId;
return state.sales_estimates.views?.[viewId]?.pages?.[query.page];
};
const EstimateItemsSelector = (state) => state.estimates.items;
const estimateItemsSelector = (state) => state.sales_estimates.items;
export const getEstimateCurrentPage = () =>
createSelector(estimatesSelector, EstimateItemsSelector, (page, items) => {
return typeof page === 'object'
? pickItemsFromIds(items, page.ids) || []
: [];
});
export const getEstimateCurrentPageFactory = () =>
createSelector(
estimatesPageSelector,
estimateItemsSelector,
(estimatePage, estimateItems) => {
return typeof estimatePage === 'object'
? pickItemsFromIds(estimateItems, estimatePage.ids) || []
: [];
},
);
const estimateByIdSelector = (state, props) => state.estimates.items;
const estimateByIdSelector = (state, props) => {
return state.sales_estimates.items[props.estimateId];
};
export const getEstimateByIdFactory = () =>
createSelector(estimateByIdSelector, (estimate) => {
return estimate;
});
const paginationSelector = (state, props) => {
const viewId = state.estimates.currentViewId;
return state.estimates.views?.[viewId];
const estimatesPaginationSelector = (state, props) => {
const viewId = state.sales_estimates.currentViewId;
return state.sales_estimates.views?.[viewId];
};
export const getEstimatesPaginationMetaFactory = () =>
createSelector(paginationSelector, (estimatePage) => {
createSelector(estimatesPaginationSelector, (estimatePage) => {
return estimatePage?.paginationMeta || {};
});