mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 21:30:31 +00:00
WIP/ Feature : Estimate & Receipt & Bill & Invoice
This commit is contained in:
@@ -28,9 +28,12 @@ export const submitReceipt = ({ form }) => {
|
||||
export const deleteReceipt = ({ id }) => {
|
||||
return (dispatch) =>
|
||||
new Promise((resovle, reject) => {
|
||||
ApiService.delete(`receipts/${id}`)
|
||||
ApiService.delete(`sales/receipts/${id}`)
|
||||
.then((response) => {
|
||||
dispatch({ type: t.RECEIPT_DELETE });
|
||||
dispatch({
|
||||
type: t.RECEIPT_DELETE,
|
||||
payload: { id },
|
||||
});
|
||||
resovle(response);
|
||||
})
|
||||
.catch((error) => {
|
||||
@@ -45,7 +48,7 @@ export const editReceipt = (id, form) => {
|
||||
dispatch({
|
||||
type: t.SET_DASHBOARD_REQUEST_LOADING,
|
||||
});
|
||||
ApiService.delete(`receipt/${id}`, form)
|
||||
ApiService.post(`sales/receipts/${id}`, form)
|
||||
.then((response) => {
|
||||
dispatch({
|
||||
type: t.SET_DASHBOARD_REQUEST_COMPLETED,
|
||||
@@ -66,7 +69,7 @@ export const editReceipt = (id, form) => {
|
||||
export const fetchReceipt = ({ id }) => {
|
||||
return (dispatch) =>
|
||||
new Promise((resovle, reject) => {
|
||||
ApiService.get(`receipt/${id}`)
|
||||
ApiService.get(`sales/receipts/${id}`)
|
||||
.then((response) => {
|
||||
dispatch({
|
||||
type: t.RECEIPT_SET,
|
||||
@@ -88,36 +91,35 @@ export const fetchReceipt = ({ id }) => {
|
||||
export const fetchReceiptsTable = ({ query = {} }) => {
|
||||
return (dispatch, getState) =>
|
||||
new Promise((resolve, rejcet) => {
|
||||
const pageQuery = getState().receipt.tableQuery;
|
||||
|
||||
const pageQuery = getState().sales_receipts.tableQuery;
|
||||
dispatch({
|
||||
type: t.RECEIPTS_TABLE_LOADING,
|
||||
payload: {
|
||||
loading: true,
|
||||
},
|
||||
});
|
||||
ApiService.get('receipts', {
|
||||
ApiService.get('sales/receipts', {
|
||||
params: { ...pageQuery, ...query },
|
||||
})
|
||||
.then((response) => {
|
||||
dispatch({
|
||||
type: t.RECEIPTS_PAGE_SET,
|
||||
payload: {
|
||||
receipts: response.data.receipts.results,
|
||||
pagination: response.data.receipts.pagination,
|
||||
sales_receipts: response.data.sales_receipts.results,
|
||||
pagination: response.data.sales_receipts.pagination,
|
||||
customViewId: response.data.customViewId || -1,
|
||||
},
|
||||
});
|
||||
dispatch({
|
||||
type: t.RECEIPTS_ITEMS_SET,
|
||||
payload: {
|
||||
receipts: response.data.receipts.results,
|
||||
sales_receipts: response.data.sales_receipts.results,
|
||||
},
|
||||
});
|
||||
dispatch({
|
||||
type: t.RECEIPTS_PAGINATION_SET,
|
||||
payload: {
|
||||
pagination: response.data.receipts.pagination,
|
||||
pagination: response.data.sales_receipts.pagination,
|
||||
customViewId: response.data.customViewId || -1,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
import { createReducer } from '@reduxjs/toolkit';
|
||||
import { createTableQueryReducers } from 'store/queryReducers';
|
||||
import t from 'store/types';
|
||||
|
||||
const initialState = {
|
||||
items: {},
|
||||
views: {},
|
||||
loading: false,
|
||||
tableQuery: {
|
||||
page_size: 5,
|
||||
page: 1,
|
||||
},
|
||||
currentViewId: -1,
|
||||
};
|
||||
|
||||
const defaultReceipt = {
|
||||
entries: [],
|
||||
};
|
||||
|
||||
const reducer = createReducer(initialState, {
|
||||
[t.RECEIPT_SET]: (state, action) => {
|
||||
const { id, receipt } = action.payload;
|
||||
const _receipt = state.items[id] || {};
|
||||
state.items[id] = { ...defaultReceipt, ..._receipt, ...receipt };
|
||||
},
|
||||
|
||||
[t.RECEIPTS_ITEMS_SET]: (state, action) => {
|
||||
const { sales_receipts } = action.payload;
|
||||
const _receipts = {};
|
||||
sales_receipts.forEach((receipt) => {
|
||||
_receipts[receipt.id] = {
|
||||
...defaultReceipt,
|
||||
...receipt,
|
||||
};
|
||||
});
|
||||
state.items = {
|
||||
...state.items,
|
||||
..._receipts,
|
||||
};
|
||||
},
|
||||
|
||||
[t.RECEIPTS_TABLE_LOADING]: (state, action) => {
|
||||
const { loading } = action.payload;
|
||||
state.loading = loading;
|
||||
},
|
||||
|
||||
[t.RECEIPT_DELETE]: (state, action) => {
|
||||
const { id } = action.payload;
|
||||
if (typeof state.items[id] !== 'undefined') {
|
||||
delete state.items[id];
|
||||
}
|
||||
},
|
||||
|
||||
[t.RECEIPTS_SET_CURRENT_VIEW]: (state, action) => {
|
||||
state.currentViewId = action.currentViewId;
|
||||
},
|
||||
|
||||
[t.RECEIPTS_PAGE_SET]: (state, action) => {
|
||||
const { customViewId, sales_receipts, 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_receipts.map((i) => i.id),
|
||||
},
|
||||
},
|
||||
};
|
||||
},
|
||||
|
||||
[t.RECEIPTS_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_receipts', reducer);
|
||||
|
||||
export const getReceiptById = (state, id) => {
|
||||
return state.receipts.items[id];
|
||||
};
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
import { createSelector } from '@reduxjs/toolkit';
|
||||
import { pickItemsFromIds, paginationLocationQuery } from 'store/selectors';
|
||||
|
||||
const receiptsPageSelector = (state, props, query) => {
|
||||
const viewId = state.sales_receipts.currentViewId;
|
||||
return state.sales_receipts.views?.[viewId]?.pages?.[query.page];
|
||||
};
|
||||
|
||||
const receiptItemsSelector = (state) => {
|
||||
return state.sales_receipts.items;
|
||||
};
|
||||
|
||||
export const getReceiptCurrentPageFactory = () =>
|
||||
createSelector(
|
||||
receiptsPageSelector,
|
||||
receiptItemsSelector,
|
||||
(receiptPage, receiptItems) => {
|
||||
return typeof receiptPage === 'object'
|
||||
? pickItemsFromIds(receiptItems, receiptPage.ids) || []
|
||||
: [];
|
||||
},
|
||||
);
|
||||
|
||||
const receiptTableQuery = (state) => {
|
||||
return state.sales_receipts.tableQuery;
|
||||
};
|
||||
|
||||
export const getReceiptsTableQuery = createSelector(
|
||||
paginationLocationQuery,
|
||||
receiptTableQuery,
|
||||
(locationQuery, tableQuery) => {
|
||||
return {
|
||||
...locationQuery,
|
||||
...tableQuery,
|
||||
};
|
||||
},
|
||||
);
|
||||
|
||||
const receiptByIdSelector = (state, props) => {
|
||||
return state.sales_receipts.items[props.receiptId];
|
||||
};
|
||||
|
||||
export const getReceiptByIdFactory = () =>
|
||||
createSelector(receiptByIdSelector, (receipt) => {
|
||||
return receipt;
|
||||
});
|
||||
|
||||
const receiptsPaginationSelector = (state, props) => {
|
||||
const viewId = state.sales_receipts.currentViewId;
|
||||
return state.sales_receipts.views?.[viewId];
|
||||
};
|
||||
|
||||
export const getReceiptsPaginationMetaFactory = () =>
|
||||
createSelector(receiptsPaginationSelector, (receiptPage) => {
|
||||
return receiptPage?.paginationMeta || {};
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user