feat : inventory adjustments.

This commit is contained in:
elforjani3
2021-01-11 09:42:01 +02:00
parent 097b9fdb3a
commit 9c00da3613
23 changed files with 1031 additions and 20 deletions

View File

@@ -0,0 +1,86 @@
import ApiService from 'services/ApiService';
import t from 'store/types';
export const submitInventoryAdjustment = ({ form }) => {
return (dispatch) =>
new Promise((resolve, reject) => {
ApiService.post('inventory_adjustments', form).then((response) => {
resolve(response);
}),
caches((error) => {
const { response } = error;
const { data } = response;
reject(data?.errors);
});
});
};
export const deleteInventoryAdjustment = ({ id }) => {
return (dispatch) =>
new Promise((resolve, reject) => {
ApiService.delete(`inventory_adjustments/${id}`)
.then((response) => {
dispatch({
type: t.INVENTORY_ADJUSTMENT_DELETE,
payload: { id },
});
resolve(response);
})
.catch((error) => {
reject(error.response.data.errors || []);
});
});
};
export const fetchInventoryAdjustmentsTable = ({ query } = {}) => {
return (dispatch, getState) =>
new Promise((resolve, reject) => {
const pageQuery = getState().inventoryAdjustments.tableQuery;
dispatch({
type: t.INVENTORY_ADJUSTMENTS_LOADING,
payload: {
loading: true,
},
});
ApiService.get('inventory_adjustments', {
params: { ...pageQuery, ...query },
})
.then((response) => {
dispatch({
type: t.INVENTORY_ADJUSTMENTS_PAGE_SET,
payload: {
inventory_adjustments: response.data,
pagination: response.data.pagination,
customViewId:
response.data?.filter_meta?.view?.custom_view_id || -1,
},
});
dispatch({
type: t.INVENTORY_ADJUSTMENT_ITEMS_SET,
payload: {
inventory_adjustment: response.data,
},
});
dispatch({
type: t.INVENTORY_ADJUSTMENTS_PAGINATION_SET,
payload: {
pagination: response.data.pagination,
customViewId:
response.data?.filter_meta?.view?.custom_view_id || -1,
},
});
dispatch({
type: t.INVENTORY_ADJUSTMENTS_LOADING,
payload: {
loading: false,
},
});
resolve(response);
})
.catch((error) => {
reject(error);
});
});
};

View File

@@ -0,0 +1,73 @@
import { createReducer } from '@reduxjs/toolkit';
import {
viewPaginationSetReducer,
createTableQueryReducers,
} from 'store/journalNumber.reducer';
import t from 'store/types';
const initialState = {
items: {},
views: {},
loading: false,
currentViewId: -1,
tableQuery: {
page_size: 12,
page: 1,
},
paginationMeta: {
total: 0,
},
};
export default createReducer(initialState, {
[t.INVENTORY_ADJUSTMENTS_LOADING]: (state, action) => {
const { loading } = action.payload;
state.loading = loading;
},
[t.INVENTORY_ADJUSTMENT_DELETE]: (state, action) => {
const { id } = action.payload;
if (typeof state.items[id] !== 'undefined') {
delete state.items[id];
}
},
[t.INVENTORY_ADJUSTMENTS_PAGE_SET]: (state, action) => {
const { customViewId, inventory_adjustments, pagination } = action.payload;
const viewId = customViewId || -1;
const view = state.views[viewId] || {};
state.views[viewId] = {
...view,
pages: {
...(state.views?.[viewId]?.pages || {}),
[pagination.page]: {
ids: inventory_adjustments.map((i) => i.id),
},
},
};
},
//useless
[t.INVENTORY_ADJUSTMENT_ITEMS_SET]: (state, action) => {
const { inventory_adjustment } = action.payload;
const _inventory_adjustment = {};
inventory_adjustment.forEach((_inventory) => {
_inventory_adjustment[_inventory.id] = {
..._inventory,
};
});
state.items = {
...state.items,
..._inventory_adjustment,
};
},
[t.INVENTORY_ADJUSTMENTS_SET_CURRENT_VIEW]: (state, action) => {
state.currentViewId = action.currentViewId;
},
...viewPaginationSetReducer(t.INVENTORY_ADJUSTMENTS_PAGINATION_SET),
...createTableQueryReducers('INVENTORY_ADJUSTMENTS'),
});

View File

@@ -0,0 +1,7 @@
import { createSelector } from '@reduxjs/toolkit';
import {
pickItemsFromIds,
paginationLocationQuery,
defaultPaginationMeta,
} from 'store/selectors';

View File

@@ -0,0 +1,14 @@
export default {
INVENTORY_ADJUSTMENT_ITEMS_SET: 'INVENTORY_ADJUSTMENT_ITEMS_SET',
INVENTORY_ADJUSTMENT_DELETE: 'INVENTORY_ADJUSTMENT_DELETE',
INVENTORY_ADJUSTMENTS_LOADING: 'INVENTORY_ADJUSTMENTS_LOADING',
INVENTORY_ADJUSTMENTS_PAGE_SET: 'INVENTORY_ADJUSTMENTS_PAGE_SET',
INVENTORY_ADJUSTMENTS_PAGINATION_SET: 'INVENTORY_ADJUSTMENTS_PAGINATION_SET',
INVENTORY_ADJUSTMENTS_TABLE_QUERIES_ADD:
'INVENTORY_ADJUSTMENTS_TABLE_QUERIES_ADD',
INVENTORY_ADJUSTMENTS_SET_CURRENT_VIEW:
'INVENTORY_ADJUSTMENTS_SET_CURRENT_VIEW',
};

View File

@@ -27,6 +27,7 @@ import paymentReceives from './PaymentReceive/paymentReceive.reducer';
import paymentMades from './PaymentMades/paymentMade.reducer';
import organizations from './organizations/organizations.reducers';
import subscriptions from './subscription/subscription.reducer';
import inventoryAdjustments from './inventoryAdjustments/inventoryAdjustment.reducer';
export default combineReducers({
authentication,
@@ -56,4 +57,5 @@ export default combineReducers({
vendors,
paymentReceives,
paymentMades,
inventoryAdjustments,
});

View File

@@ -26,6 +26,7 @@ import paymentReceives from './PaymentReceive/paymentReceive.type';
import paymentMades from './PaymentMades/paymentMade.type';
import organizations from './organizations/organizations.types';
import subscription from './subscription/subscription.types';
import inventoryAdjustments from './inventoryAdjustments/inventoryAdjustment.type';
export default {
...authentication,
@@ -56,4 +57,5 @@ export default {
...paymentMades,
...organizations,
...subscription,
...inventoryAdjustments
};