mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-18 22:00:31 +00:00
feature : Puschases & Sales / fix : tasks
This commit is contained in:
128
client/src/store/PaymentMades/paymentMade.actions.js
Normal file
128
client/src/store/PaymentMades/paymentMade.actions.js
Normal file
@@ -0,0 +1,128 @@
|
||||
import ApiService from 'services/ApiService';
|
||||
import t from 'store/types';
|
||||
|
||||
export const submitPaymentMade = ({ form }) => {
|
||||
return (dispatch) =>
|
||||
new Promise((resolve, reject) => {
|
||||
ApiService.post('purchases/bill_payments', form)
|
||||
.then((response) => {
|
||||
resolve(response);
|
||||
})
|
||||
.catch((error) => {
|
||||
const { response } = error;
|
||||
const { data } = response;
|
||||
|
||||
reject(data?.errors);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
export const deletePaymentMade = ({ id }) => {
|
||||
return (dispatch) =>
|
||||
new Promise((resovle, reject) => {
|
||||
ApiService.delete(`purchases/bill_payments/${id}`)
|
||||
.then((response) => {
|
||||
dispatch({ type: t.PAYMENT_MADE_DELETE, payload: { id } });
|
||||
resovle(response);
|
||||
})
|
||||
.catch((error) => {
|
||||
reject(error.response.data.errors || []);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
export const editPaymentMade = (id, form) => {
|
||||
return (dispatch) =>
|
||||
new Promise((resolve, rejcet) => {
|
||||
ApiService.post(`purchases/bill_payments/${id}`, form)
|
||||
.then((response) => {
|
||||
resolve(response);
|
||||
})
|
||||
.catch((error) => {
|
||||
const { response } = error;
|
||||
const { data } = response;
|
||||
|
||||
rejcet(data?.errors);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
export const fetchPaymentMadesTable = ({ query = {} }) => {
|
||||
return (dispatch, getState) =>
|
||||
new Promise((resolve, rejcet) => {
|
||||
const pageQuery = getState().paymentMades.tableQuery;
|
||||
|
||||
dispatch({
|
||||
type: t.PAYMENT_MADES_TABLE_LOADING,
|
||||
payload: {
|
||||
loading: true,
|
||||
},
|
||||
});
|
||||
ApiService.get('purchases/bill_payments', {
|
||||
params: { ...pageQuery, ...query },
|
||||
})
|
||||
.then((response) => {
|
||||
dispatch({
|
||||
type: t.PAYMENT_MADES_PAGE_SET,
|
||||
payload: {
|
||||
bill_payments: response.data.bill_payments.results,
|
||||
pagination: response.data.bill_payments.pagination,
|
||||
customViewId: response.data.customViewId || -1,
|
||||
},
|
||||
});
|
||||
dispatch({
|
||||
type: t.PAYMENT_MADES_ITEMS_SET,
|
||||
payload: {
|
||||
bill_payments: response.data.bill_payments.results,
|
||||
},
|
||||
});
|
||||
dispatch({
|
||||
type: t.PAYMENT_MADES_PAGINATION_SET,
|
||||
payload: {
|
||||
pagination: response.data.bill_payments.pagination,
|
||||
customViewId: response.data.customViewId || -1,
|
||||
},
|
||||
});
|
||||
dispatch({
|
||||
type: t.PAYMENT_MADES_TABLE_LOADING,
|
||||
payload: {
|
||||
loading: false,
|
||||
},
|
||||
});
|
||||
resolve(response);
|
||||
})
|
||||
.catch((error) => {
|
||||
rejcet(error);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
export const fetchPaymentMade = ({ id }) => {
|
||||
return (dispatch) =>
|
||||
new Promise((resovle, reject) => {
|
||||
ApiService.get(`purchases/bill_payments/${id}`, {})
|
||||
.then((response) => {
|
||||
// dispatch({
|
||||
// type: t.RELOAD_INVOICES,
|
||||
// payload: {
|
||||
// sales_invoices: response.data.paymentReceive.entries.map(
|
||||
// (e) => e.invoice,
|
||||
// ),
|
||||
// },
|
||||
// });
|
||||
dispatch({
|
||||
type: t.PAYMENT_MADE_SET,
|
||||
payload: {
|
||||
id,
|
||||
bill_payment: response.data.bill_payment,
|
||||
},
|
||||
});
|
||||
resovle(response);
|
||||
})
|
||||
.catch((error) => {
|
||||
const { response } = error;
|
||||
const { data } = response;
|
||||
reject(data?.errors);
|
||||
});
|
||||
});
|
||||
};
|
||||
88
client/src/store/PaymentMades/paymentMade.reducer.js
Normal file
88
client/src/store/PaymentMades/paymentMade.reducer.js
Normal file
@@ -0,0 +1,88 @@
|
||||
import { createReducer } from '@reduxjs/toolkit';
|
||||
import { createTableQueryReducers } from 'store/queryReducers';
|
||||
import { omit } from 'lodash';
|
||||
import t from 'store/types';
|
||||
|
||||
const initialState = {
|
||||
items: {},
|
||||
views: {},
|
||||
loading: false,
|
||||
currentViewId: -1,
|
||||
tableQuery: {
|
||||
page_size: 5,
|
||||
page: 1,
|
||||
},
|
||||
};
|
||||
|
||||
const defaultPaymentMade = {
|
||||
entries: [],
|
||||
};
|
||||
|
||||
const reducer = createReducer(initialState, {
|
||||
[t.PAYMENT_MADES_TABLE_LOADING]: (state, action) => {
|
||||
const { loading } = action.payload;
|
||||
state.loading = loading;
|
||||
},
|
||||
[t.PAYMENT_MADES_ITEMS_SET]: (state, action) => {
|
||||
const { bill_payments } = action.payload;
|
||||
const _bill_payments = {};
|
||||
bill_payments.forEach((billPayment) => {
|
||||
_bill_payments[billPayment.id] = {
|
||||
...defaultPaymentMade,
|
||||
...billPayment,
|
||||
};
|
||||
});
|
||||
state.items = {
|
||||
...state.items,
|
||||
..._bill_payments,
|
||||
};
|
||||
},
|
||||
|
||||
[t.PAYMENT_MADE_DELETE]: (state, action) => {
|
||||
const { id } = action.payload;
|
||||
|
||||
if (typeof state.items[id] !== 'undefined') {
|
||||
delete state.items[id];
|
||||
}
|
||||
},
|
||||
|
||||
[t.PAYMENT_MADES_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,
|
||||
},
|
||||
};
|
||||
},
|
||||
|
||||
[t.PAYMENT_MADES_PAGE_SET]: (state, action) => {
|
||||
const { customViewId, bill_payments, pagination } = action.payload;
|
||||
|
||||
const viewId = customViewId || -1;
|
||||
const view = state.views[viewId] || {};
|
||||
|
||||
state.views[viewId] = {
|
||||
...view,
|
||||
pages: {
|
||||
...(state.views?.[viewId]?.pages || {}),
|
||||
[pagination.page]: {
|
||||
ids: bill_payments.map((i) => i.id),
|
||||
},
|
||||
},
|
||||
};
|
||||
},
|
||||
});
|
||||
export default createTableQueryReducers('bill_payments', reducer);
|
||||
56
client/src/store/PaymentMades/paymentMade.selector.js
Normal file
56
client/src/store/PaymentMades/paymentMade.selector.js
Normal file
@@ -0,0 +1,56 @@
|
||||
import { createSelector } from '@reduxjs/toolkit';
|
||||
import { pickItemsFromIds, paginationLocationQuery } from 'store/selectors';
|
||||
|
||||
|
||||
|
||||
const paymentMadeTableQuery = (state) => state.paymentMades.tableQuery;
|
||||
|
||||
const paymentMadesPageSelector = (state, props, query) => {
|
||||
const viewId = state.paymentMades.currentViewId;
|
||||
return state.paymentMades.views?.[viewId]?.pages?.[query.page];
|
||||
};
|
||||
|
||||
const paymentMadesItemsSelector = (state) => {
|
||||
return state.paymentMades.items;
|
||||
};
|
||||
|
||||
const PaymentMadePaginationSelector = (state, props) => {
|
||||
const viewId = state.paymentMades.currentViewId;
|
||||
return state.paymentMades.views?.[viewId];
|
||||
};
|
||||
|
||||
const paymentMadesIds = (state, props) => {
|
||||
return state.paymentMades.items[props.paymentMadeId];
|
||||
};
|
||||
|
||||
export const getPaymentMadeCurrentPageFactory = () =>
|
||||
createSelector(
|
||||
paymentMadesPageSelector,
|
||||
paymentMadesItemsSelector,
|
||||
(Page, Items) => {
|
||||
return typeof Page === 'object'
|
||||
? pickItemsFromIds(Items, Page.ids) || []
|
||||
: [];
|
||||
},
|
||||
);
|
||||
|
||||
export const getPaymentMadeTableQuery = createSelector(
|
||||
paginationLocationQuery,
|
||||
paymentMadeTableQuery,
|
||||
(locationQuery, tableQuery) => {
|
||||
return {
|
||||
...locationQuery,
|
||||
...tableQuery,
|
||||
};
|
||||
},
|
||||
);
|
||||
|
||||
export const getPaymentMadePaginationMetaFactory = () =>
|
||||
createSelector(PaymentMadePaginationSelector, (Page) => {
|
||||
return Page?.paginationMeta || {};
|
||||
});
|
||||
|
||||
export const getPaymentMadeByIdFactory = () =>
|
||||
createSelector(paymentMadesIds, (payment_Made) => {
|
||||
return payment_Made;
|
||||
});
|
||||
11
client/src/store/PaymentMades/paymentMade.type.js
Normal file
11
client/src/store/PaymentMades/paymentMade.type.js
Normal file
@@ -0,0 +1,11 @@
|
||||
export default {
|
||||
PAYMENT_MADE_LIST_SET: 'PAYMENT_MADE_LIST_SET',
|
||||
PAYMENT_MADE_DELETE: 'PAYMENT_MADE_DELETE',
|
||||
PAYMENT_MADE_SET: 'PAYMENT_MADE_SET',
|
||||
PAYMENT_MADE_SET_CURRENT_VIEW: 'PAYMENT_MADE_SET_CURRENT_VIEW',
|
||||
PAYMENT_MADE_TABLE_QUERIES_ADD: 'PAYMENT_MADE_TABLE_QUERIES_ADD',
|
||||
PAYMENT_MADES_TABLE_LOADING: 'PAYMENT_MADES_TABLE_LOADING',
|
||||
PAYMENT_MADES_PAGE_SET: 'PAYMENT_MADES_PAGE_SET',
|
||||
PAYMENT_MADES_ITEMS_SET: 'PAYMENT_MADES_ITEMS_SET',
|
||||
PAYMENT_MADES_PAGINATION_SET: 'PAYMENT_MADES_PAGINATION_SET',
|
||||
};
|
||||
Reference in New Issue
Block a user