WIP / Feature Fix _bills

This commit is contained in:
elforjani3
2020-08-04 17:51:17 +02:00
parent 5d1b41da16
commit 1cb826163b
25 changed files with 1703 additions and 5 deletions

View File

@@ -0,0 +1,136 @@
import ApiService from 'services/ApiService';
import t from 'store/types';
export const fetchBillsTable = ({ query = {} }) => {
return (dispatch, getState) =>
new Promise((resolve, rejcet) => {
const pageQuery = getState().bill.tableQuery;
dispatch({
type: t.BILLS_TABLE_LOADING,
payload: {
loading: true,
},
});
ApiService.get('bills', {
params: { ...pageQuery, ...query },
})
.then((response) => {
dispatch({
type: t.BILLS_PAGE_SET,
payload: {
bills: response.data.bills.results,
pagination: response.data.bills.pagination,
customViewId: response.data.customViewId || -1,
},
});
dispatch({
type: t.BILLS_ITEMS_SET,
payload: {
bills: response.data.bills.results,
},
});
dispatch({
type: t.BILLS_PAGINATION_SET,
payload: {
pagination: response.data.bills.pagination,
customViewId: response.data.customViewId || -1,
},
});
dispatch({
type: t.BILLS_TABLE_LOADING,
payload: {
loading: false,
},
});
resolve(response);
})
.catch((error) => {
rejcet(error);
});
});
};
export const deleteBill = ({ id }) => {
return (dispatch) =>
new Promise((resovle, reject) => {
ApiService.delete(`bills/${id}`)
.then((response) => {
dispatch({ type: t.BILL_DELETE });
resovle(response);
})
.catch((error) => {
reject(error.response.data.errors || []);
});
});
};
export const submitBill = ({ form }) => {
return (dispatch) =>
new Promise((resolve, reject) => {
dispatch({
type: t.SET_DASHBOARD_REQUEST_LOADING,
});
ApiService.post('bills', form)
.then((response) => {
dispatch({
type: t.SET_DASHBOARD_REQUEST_COMPLETED,
});
resolve(response);
})
.catch((error) => {
const { response } = error;
const { data } = response;
dispatch({
type: t.SET_DASHBOARD_REQUEST_COMPLETED,
});
reject(data?.errors);
});
});
};
export const fetchBill = ({ id }) => {
return (dispatch) =>
new Promise((resovle, reject) => {
ApiService.get(`bills/${id}`)
.then((response) => {
dispatch({
type: t.BILL_SET,
payload: {
id,
bill: response.data.bill,
},
});
resovle(response);
})
.catch((error) => {
const { response } = error;
const { data } = response;
reject(data?.errors);
});
});
};
export const editBill = (id, form) => {
return (dispatch) =>
new Promise((resolve, rejcet) => {
dispatch({
type: t.SET_DASHBOARD_REQUEST_LOADING,
});
ApiService.post(`bills/${id}`, form)
.then((response) => {
dispatch({
type: t.SET_DASHBOARD_REQUEST_COMPLETED,
});
resolve(response);
})
.catch((error) => {
const { response } = error;
const { data } = response;
dispatch({
type: t.SET_DASHBOARD_REQUEST_COMPLETED,
});
rejcet(data?.errors);
});
});
};

View File

View File

@@ -0,0 +1,6 @@
import { createSelector } from '@reduxjs/toolkit';
const billByIdSelector = (state, props) => state.bills.items[props.billId];
export const getBillById = () =>
createSelector(billByIdSelector, (_bill) => _bill);

View File

@@ -0,0 +1,12 @@
export default {
BILL_DELETE: 'BILL_DELETE',
BILLS_BULK_DELETE: 'BILLS_BULK_DELETE',
BILLS_LIST_SET: 'BILLS_LIST_SET',
BILL_SET: 'BILL_SET',
BILLS_SET_CURRENT_VIEW: 'BILLS_SET_CURRENT_VIEW',
BILLS_TABLE_QUERIES_ADD: 'BILLS_TABLE_QUERIES_ADD',
BILLS_TABLE_LOADING: 'BILLS_TABLE_LOADING',
BILLS_PAGINATION_SET: 'BILLS_PAGINATION_SET',
BILLS_PAGE_SET: 'BILLS_PAGE_SET',
BILLS_ITEMS_SET: 'BILLS_ITEMS_SET',
};

View File

@@ -0,0 +1,136 @@
import ApiService from 'services/ApiService';
import t from 'store/types';
export const submitPaymentReceive = ({ form }) => {
return (dispatch) =>
new Promise((resolve, reject) => {
dispatch({
type: t.SET_DASHBOARD_REQUEST_LOADING,
});
ApiService.post('sales/payment_receives', form)
.then((response) => {
dispatch({
type: t.SET_DASHBOARD_REQUEST_COMPLETED,
});
resolve(response);
})
.catch((error) => {
const { response } = error;
const { data } = response;
dispatch({
type: t.SET_DASHBOARD_REQUEST_COMPLETED,
});
reject(data?.errors);
});
});
};
export const editPaymentReceive = (id, form) => {
return (dispatch) =>
new Promise((resolve, rejcet) => {
dispatch({
type: t.SET_DASHBOARD_REQUEST_LOADING,
});
ApiService.post(`sales/payment_receives/${id}`, form)
.then((response) => {
dispatch({
type: t.SET_DASHBOARD_REQUEST_COMPLETED,
});
resolve(response);
})
.catch((error) => {
const { response } = error;
const { data } = response;
dispatch({
type: t.SET_DASHBOARD_REQUEST_COMPLETED,
});
rejcet(data?.errors);
});
});
};
export const deletePaymentReceive = ({ id }) => {
return (dispatch) =>
new Promise((resovle, reject) => {
ApiService.delete(`payment_receives/${id}`)
.then((response) => {
dispatch({ type: t.PAYMENT_RECEIVE_DELETE });
resovle(response);
})
.catch((error) => {
reject(error.response.data.errors || []);
});
});
};
export const fetchPaymentReceive = ({ id }) => {
return (dispatch) =>
new Promise((resovle, reject) => {
ApiService.get(`payment_receives/${id}`)
.then((response) => {
dispatch({
type: t.PAYMENT_RECEIVE_SET,
payload: {
id,
payment_receive: response.data.payment_receive,
},
});
resovle(response);
})
.catch((error) => {
const { response } = error;
const { data } = response;
reject(data?.errors);
});
});
};
export const fetchPaymentReceivesTable = ({ query = {} }) => {
return (dispatch, getState) =>
new Promise((resolve, rejcet) => {
const pageQuery = getState().payment_receive.tableQuery;
dispatch({
type: t.PAYMENT_RECEIVES_TABLE_LOADING,
payload: {
loading: true,
},
});
ApiService.get('payment_receives', {
params: { ...pageQuery, ...query },
})
.then((response) => {
dispatch({
type: t.RECEIPTS_PAGE_SET,
payload: {
payment_receives: response.data.payment_receives.results,
pagination: response.data.payment_receives.pagination,
customViewId: response.data.customViewId || -1,
},
});
dispatch({
type: t.PAYMENT_RECEIVES_ITEMS_SET,
payload: {
payment_receives: response.data.payment_receives.results,
},
});
dispatch({
type: t.PAYMENT_RECEIVES_PAGINATION_SET,
payload: {
pagination: response.data.payment_receives.pagination,
customViewId: response.data.customViewId || -1,
},
});
dispatch({
type: t.PAYMENT_RECEIVES_TABLE_LOADING,
payload: {
loading: false,
},
});
resolve(response);
})
.catch((error) => {
rejcet(error);
});
});
};

View File

@@ -0,0 +1,11 @@
export default {
PAYMENT_RECEIVE_LIST_SET: 'PAYMENT_RECEIVE_LIST_SET',
PAYMENT_RECEIVE_SET: 'PAYMENT_RECEIVE_SET',
PAYMENT_RECEIVE_DELETE: 'PAYMENT_RECEIVE_DELETE',
PAYMENT_RECEIVE_SET_CURRENT_VIEW: 'PAYMENT_RECEIVE_SET_CURRENT_VIEW',
PAYMENT_RECEIVE_TABLE_QUERIES_ADD: 'PAYMENT_RECEIVE_TABLE_QUERIES_ADD',
PAYMENT_RECEIVES_TABLE_LOADING: 'PAYMENT_RECEIVES_TABLE_LOADING',
PAYMENT_RECEIVES_PAGE_SET: 'PAYMENT_RECEIVES_PAGE_SET',
PAYMENT_RECEIVES_ITEMS_SET: 'PAYMENT_RECEIVES_ITEMS_SET',
PAYMENT_RECEIVES_PAGINATION_SET: 'PAYMENT_RECEIVES_PAGINATION_SET',
};

View File

@@ -20,6 +20,8 @@ import customer from './customers/customers.type';
import estimates from './Estimate/estimates.types';
import invoices from './Invoice/invoices.types';
import receipts from './receipt/receipt.type';
import bills from './Bills/bills.type';
import paymentReceives from './PaymentReceive/paymentReceive.type';
export default {
...authentication,
@@ -43,5 +45,7 @@ export default {
...customer,
...estimates,
...invoices,
...receipts
...receipts,
...bills,
...paymentReceives,
};