This commit is contained in:
elforjani3
2020-11-02 10:23:19 +02:00
29 changed files with 974 additions and 573 deletions

View File

@@ -123,11 +123,19 @@ export const fetchDueBills = ({ vendorId }) => (dispatch) => new Promise((resolv
ApiService.get(`purchases/bills/due`, { params }).then((response) => {
dispatch({
type: t.DUE_BILLS_SET,
type: t.BILLS_ITEMS_SET,
payload: {
bills: response.data.bills,
}
},
});
if ( vendorId ) {
dispatch({
type: t.BILLS_PAYABLE_BY_VENDOR_ID,
payload: {
bills: response.data.bills,
}
});
}
resolve(response);
}).catch(error => { reject(error) });
});

View File

@@ -13,7 +13,10 @@ const initialState = {
page: 1,
},
nextBillNumberChanged: false,
dueBills: {},
payable: {
byVendorId: [],
byBillPayamentId: [],
},
};
const defaultBill = {
@@ -105,23 +108,31 @@ const reducer = createReducer(initialState, {
state.nextBillNumberChanged = isChanged;
},
[t.DUE_BILLS_SET]: (state, action) => {
[t.BILLS_PAYABLE_BY_VENDOR_ID]: (state, action) => {
const { bills } = action.payload;
const _dueBills = { ...state.dueBills };
const _bills = { ...state.items };
const _data = {};
bills.forEach((bill) => {
_bills[bill.id] = { ...bill };
if (!_dueBills[bill.vendor_id]) {
_dueBills[bill.vendor_id] = []
if (!_data[bill.vendor_id]) {
_data[bill.vendor_id] = [];
}
_dueBills[bill.vendor_id].push(bill.id);
_data[bill.vendor_id].push(bill.id);
});
state.items = { ..._bills };
state.dueBills = { ..._dueBills };
state.payable.byVendorId = {
...state.payable.byVendorId,
..._data,
};
},
[t.BILLS_PAYABLE_BY_PAYMENT_ID]: (state, action) => {
const { bills, billPaymentId } = action.payload;
const _data = [];
bills.forEach((bill) => {
_data.push(bill.id);
});
state.payable.byBillPayamentId[billPaymentId] = _data;
}
});

View File

@@ -19,7 +19,10 @@ const billByIdSelector = (state, props) => state.bills.items[props.billId];
* Retrieve vendor due bills ids.
* @return {number[]}
*/
const billsDueVendorSelector = (state, props) => state.bills.dueBills[props.vendorId];
const billsPayableVendorSelector = (state, props) => state.bills.payable.byVendorId[props.vendorId];
const billsPayableByPaymentMadeSelector = (state, props) => {
return state.bills.payable.byBillPayamentId[props.paymentMadeId];
}
const billPaginationSelector = (state, props) => {
const viewId = state.bills.currentViewId;
@@ -62,16 +65,26 @@ export const getBillPaginationMetaFactory = () =>
return billPage?.paginationMeta || {};
});
/**
* Retrieve due bills of specific vendor.
*/
export const getVendorDueBillsFactory = () =>
export const getVendorPayableBillsFactory = () =>
createSelector(
billItemsSelector,
billsDueVendorSelector,
(billsItems, dueBillsIds) => {
return Array.isArray(dueBillsIds)
? pickItemsFromIds(billsItems, dueBillsIds) || []
billsPayableVendorSelector,
(billsItems, payableBillsIds) => {
return Array.isArray(payableBillsIds)
? pickItemsFromIds(billsItems, payableBillsIds) || []
: [];
},
);
export const getPayableBillsByPaymentMadeFactory = () =>
createSelector(
billItemsSelector,
billsPayableByPaymentMadeSelector,
(billsItems, payableBillsIds) => {
return Array.isArray(payableBillsIds)
? pickItemsFromIds(billsItems, payableBillsIds) || []
: [];
},
);

View File

@@ -10,5 +10,7 @@ export default {
BILLS_PAGE_SET: 'BILLS_PAGE_SET',
BILLS_ITEMS_SET: 'BILLS_ITEMS_SET',
BILL_NUMBER_CHANGED: 'BILL_NUMBER_CHANGED',
DUE_BILLS_SET: 'DUE_BILLS_SET'
BILLS_PAYABLE_BY_PAYMENT_ID: 'BILLS_PAYABLE_BY_PAYMENT_ID',
BILLS_PAYABLE_BY_VENDOR_ID: 'BILLS_PAYABLE_BY_VENDOR_ID',
};

View File

@@ -106,7 +106,20 @@ export const fetchPaymentMade = ({ id }) => {
type: t.PAYMENT_MADE_SET,
payload: {
id,
bill_payment: response.data.bill_payment,
paymentMade: response.data.bill_payment,
},
});
dispatch({
type: t.BILLS_PAYABLE_BY_PAYMENT_ID,
payload: {
billPaymentId: id,
bills: response.data.bill_payment.payable_bills,
},
});
dispatch({
type: t.BILLS_ITEMS_SET,
payload: {
bills: response.data.bill_payment.payable_bills,
},
});
resovle(response);
@@ -118,3 +131,17 @@ export const fetchPaymentMade = ({ id }) => {
});
});
};
export const fetchPaymentMadeBills = ({ paymentMadeId }) => (dispatch) => {
return new Promise((resolve, reject) => {
ApiService.get(`purchases/bill_payments/${paymentMadeId}/bills`).then((response) => {
dispatch({
type: t.BILLS_ITEMS_SET,
payload: {
bills: response.data.bills,
},
});
resolve(response);
}).catch((error) => { reject(error) });
});
}

View File

@@ -39,6 +39,17 @@ const reducer = createReducer(initialState, {
};
},
[t.PAYMENT_MADE_SET]: (state, action) => {
const { id, paymentMade } = action.payload;
const _oldPaymentMade = (state.items[id] || {});
state.items[id] = {
...defaultPaymentMade,
..._oldPaymentMade,
...paymentMade,
};
},
[t.PAYMENT_MADE_DELETE]: (state, action) => {
const { id } = action.payload;

View File

@@ -23,6 +23,9 @@ const paymentMadesIds = (state, props) => {
return state.paymentMades.items[props.paymentMadeId];
};
const paymentMadeEntries = (state, props) => props.paymentMadeEntries;
const billsItemsSelector = (state, props) => state.bills.items;
export const getPaymentMadeCurrentPageFactory = () =>
createSelector(
paymentMadesPageSelector,
@@ -54,3 +57,15 @@ export const getPaymentMadeByIdFactory = () =>
createSelector(paymentMadesIds, (payment_Made) => {
return payment_Made;
});
export const getPaymentMadeEntriesDataFactory = () =>
createSelector(
billsItemsSelector,
paymentMadeEntries,
(billsItems, paymentEntries) => {
return Array.isArray(paymentEntries) ?
paymentEntries.map((entry) => ({
...entry, ...(billsItems[entry.bill_id] || {}),
})) : [];
}
)