feat: payment receive and made form.

This commit is contained in:
Ahmed Bouhuolia
2020-11-05 12:16:28 +02:00
parent 1738a333c7
commit 69e7612b62
42 changed files with 1100 additions and 750 deletions

View File

@@ -17,6 +17,7 @@ const initialState = {
byVendorId: [],
byBillPayamentId: [],
},
byBillPayamentId: {},
};
const defaultBill = {
@@ -133,6 +134,13 @@ const reducer = createReducer(initialState, {
_data.push(bill.id);
});
state.payable.byBillPayamentId[billPaymentId] = _data;
},
[t.BILLS_BY_PAYMENT_ID]: (state, action) => {
const { bills, billPaymentId } = action.payload;
const billsIds = bills.map((bill) => bill.id);
state.byBillPayamentId[billPaymentId] = billsIds;
}
});

View File

@@ -1,28 +1,21 @@
import { createSelector } from '@reduxjs/toolkit';
import { pickItemsFromIds, paginationLocationQuery } from 'store/selectors';
// Retreive bills table query.
const billTableQuery = (state) => state.bills.tableQuery;
const billPageSelector = (state, props, query) => {
const viewId = state.bills.currentViewId;
return state.bills.views?.[viewId]?.pages?.[query.page];
};
// Retreive bills items.
const billItemsSelector = (state) => state.bills.items;
/**
* Retrieve bill details.
* @return {IBill}
*/
// Retrieve bill details.
const billByIdSelector = (state, props) => state.bills.items[props.billId];
/**
* Retrieve vendor due bills ids.
* @return {number[]}
*/
// Retrieve vendor due bills ids.
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;
@@ -60,12 +53,17 @@ export const getBillByIdFactory = () =>
return bill;
});
/**
* Retrieve bills datatable pagination meta.
*/
export const getBillPaginationMetaFactory = () =>
createSelector(billPaginationSelector, (billPage) => {
return billPage?.paginationMeta || {};
});
/**
* Retrieve vendor payable bills.
*/
export const getVendorPayableBillsFactory = () =>
createSelector(
billItemsSelector,
@@ -77,28 +75,24 @@ export const getVendorPayableBillsFactory = () =>
},
);
export const getPayableBillsByPaymentMadeFactory = () =>
createSelector(
billItemsSelector,
billsPayableByPaymentMadeSelector,
(billsItems, payableBillsIds) => {
return Array.isArray(payableBillsIds)
? pickItemsFromIds(billsItems, payableBillsIds) || []
: [];
},
);
export const getPaymentMadeFormPayableBillsFactory = () =>
/**
* Retrieve vendor payable bills entries.
*/
export const getVendorPayableBillsEntriesFactory = () =>
createSelector(
billItemsSelector,
billsPayableVendorSelector,
billsPayableByPaymentMadeSelector,
(billsItems, vendorBillsIds, paymentMadeBillsIds) => {
const billsIds = [
...(vendorBillsIds || []),
...(paymentMadeBillsIds || [])
];
return pickItemsFromIds(billsItems, billsIds);
},
(billsItems, payableBillsIds) => {
const bills = Array.isArray(payableBillsIds)
? pickItemsFromIds(billsItems, payableBillsIds) || []
: [];
return bills.map((bill) => ({
...bill,
bill_id: bill.id,
total_payment_amount: bill.payment_amount,
id: null,
payment_amount: null,
}));
}
);

View File

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