This commit is contained in:
elforjani3
2020-11-06 01:17:30 +02:00
46 changed files with 1220 additions and 799 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',
};

View File

@@ -72,7 +72,6 @@ export const fetchInvoicesTable = ({ query } = {}) => {
customViewId: response.data.customViewId || -1,
},
});
dispatch({
type: t.INVOICES_ITEMS_SET,
payload: {

View File

@@ -16,7 +16,8 @@ const initialState = {
receivable: {
byCustomerId: [],
byPaymentReceiveId: [],
}
},
byPaymentReceiveId: {},
};
const defaultInvoice = {
@@ -115,6 +116,13 @@ const reducer = createReducer(initialState, {
state.receivable.byCustomerId[customerId] = saleInvoiceIds
},
[t.INVOICES_BY_PAYMENT_ID]: (state, action) => {
const { paymentReceiveId, saleInvoices } = action.payload;
const saleInvoiceIds = saleInvoices.map((saleInvoice) => saleInvoice.id);
state.byPaymentReceiveId[paymentReceiveId] = saleInvoiceIds;
},
});
export default createTableQueryReducers('sales_invoices', reducer);

View File

@@ -19,12 +19,8 @@ const invoicesPageSelector = (state, props, query) => {
const viewId = state.salesInvoices.currentViewId;
return state.salesInvoices.views?.[viewId]?.pages?.[query.page];
};
const invoicesItemsSelector = (state) => state.salesInvoices.items;
const invoicesReceiableCustomerSelector = (state, props) => state.salesInvoices.receivable.byCustomerId[props.customerId];
const paymentReceivableInvoicesSelector = (state, props) => state.salesInvoices.receivable.byPaymentReceiveId[props.paymentReceiveId];
export const getInvoiceTableQueryFactory = () =>
createSelector(
@@ -59,39 +55,22 @@ export const getInvoicePaginationMetaFactory = () =>
return invoicePage?.paginationMeta || {};
});
// export const getCustomerReceivableInvoicesFactory = () =>
// createSelector(
// invoicesItemsSelector,
// invoicesReceiableCustomerSelector,
// (invoicesItems, invoicesIds) => {
// return Array.isArray(invoicesIds)
// ? (pickItemsFromIds(invoicesItems, invoicesIds) || [])
// : [];
// },
// );
// export const getPaymentReceivableInvoicesFactory = () =>
// createSelector(
// invoicesItemsSelector,
// paymentReceivableInvoicesSelector,
// (invoicesItems, invoicesIds) => {
// return Array.isArray(invoicesIds)
// ? (pickItemsFromIds(invoicesItems, invoicesIds) || [])
// : [];
// },
// );
export const getPaymentReceiveReceivableInvoicesFactory = () =>
export const getCustomerReceivableInvoicesEntriesFactory = () =>
createSelector(
invoicesItemsSelector,
invoicesReceiableCustomerSelector,
paymentReceivableInvoicesSelector,
(invoicesItems, customerInvoicesIds, paymentInvoicesIds) => {
(invoicesItems, customerInvoicesIds) => {
const invoicesIds = [
...(customerInvoicesIds || []),
...(paymentInvoicesIds || []),
];
return pickItemsFromIds(invoicesItems, invoicesIds);
const invoices = pickItemsFromIds(invoicesItems, invoicesIds);
return invoices.map((invoice) => ({
...invoice,
invoice_id: invoice.id,
total_payment_amount: invoice.payment_amount,
id: null,
payment_amount: 0,
}));
},
);
)

View File

@@ -13,5 +13,6 @@ export default {
RELOAD_INVOICES: 'RELOAD_INVOICES',
INVOICES_RECEIVABLE_BY_PAYMENT_ID: 'INVOICES_RECEIVABLE_BY_PAYMENT_ID',
INVOICES_RECEIVABLE_BY_CUSTOMER_ID: 'INVOICES_RECEIVABLE_BY_CUSTOMER_ID'
INVOICES_RECEIVABLE_BY_CUSTOMER_ID: 'INVOICES_RECEIVABLE_BY_CUSTOMER_ID',
INVOICES_BY_PAYMENT_ID: 'INVOICES_BY_PAYMENT_ID'
};

View File

@@ -109,17 +109,30 @@ export const fetchPaymentMade = ({ id }) => {
paymentMade: response.data.bill_payment,
},
});
dispatch({
type: t.BILLS_ITEMS_SET,
payload: {
bills: response.data.payable_bills,
},
});
dispatch({
type: t.BILLS_PAYABLE_BY_PAYMENT_ID,
payload: {
billPaymentId: id,
bills: response.data.bill_payment.payable_bills,
billPaymentId: response.data.bill_payment.id,
bills: response.data.payable_bills,
},
});
dispatch({
type: t.BILLS_ITEMS_SET,
payload: {
bills: response.data.bill_payment.payable_bills,
bills: response.data.payment_bills,
},
});
dispatch({
type: t.BILLS_BY_PAYMENT_ID,
payload: {
billPaymentId: response.data.bill_payment.id,
bills: response.data.payment_bills,
},
});
resovle(response);

View File

@@ -1,7 +1,6 @@
import { createSelector } from '@reduxjs/toolkit';
import { pickItemsFromIds, paginationLocationQuery } from 'store/selectors';
import { transformToObject } from 'utils';
const paymentMadeTableQuery = (state) => state.paymentMades.tableQuery;
@@ -10,21 +9,19 @@ const paymentMadesPageSelector = (state, props, query) => {
return state.paymentMades.views?.[viewId]?.pages?.[query.page];
};
const paymentMadesItemsSelector = (state) => {
return state.paymentMades.items;
};
const paymentMadesItemsSelector = (state) => 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];
};
const paymentMadeById = (state, props) => state.paymentMades.items[props.paymentMadeId];
const paymentMadeEntries = (state, props) => props.paymentMadeEntries;
const billsItemsSelector = (state, props) => state.bills.items;
const billsPayableByPaymentMadeSelector = (state, props) => state.bills.payable.byBillPayamentId[props.paymentMadeId];
const paymentMadeBillsSelector = (state, props) => state.bills.byBillPayamentId[props.paymentMadeId];
export const getPaymentMadeCurrentPageFactory = () =>
createSelector(
@@ -54,7 +51,7 @@ export const getPaymentMadePaginationMetaFactory = () =>
});
export const getPaymentMadeByIdFactory = () =>
createSelector(paymentMadesIds, (payment_Made) => {
createSelector(paymentMadeById, (payment_Made) => {
return payment_Made;
});
@@ -68,4 +65,37 @@ export const getPaymentMadeEntriesDataFactory = () =>
...entry, ...(billsItems[entry.bill_id] || {}),
})) : [];
}
)
);
export const getPaymentMadeEntriesFactory = () =>
createSelector(
billsItemsSelector,
billsPayableByPaymentMadeSelector,
paymentMadeBillsSelector,
paymentMadeById,
(
billsItems,
paymentPayableBillsIds,
paymentMadeBillsIds,
paymentMade,
) => {
const billsIds = [
...(paymentPayableBillsIds || []),
...(paymentMadeBillsIds || []),
];
const bills = pickItemsFromIds(billsItems, billsIds);
const billEntries = transformToObject((paymentMade?.entries || []), 'bill_id');
return bills.map((bill) => {
const paymentMadeEntry = (billEntries?.[bill.id] || {});
return {
...bill,
bill_id: bill.id,
total_payment_amount: bill.payment_amount,
id: paymentMadeEntry?.id,
payment_amount: paymentMadeEntry?.payment_amount,
};
});
},
);

View File

@@ -56,20 +56,33 @@ export const fetchPaymentReceive = ({ id }) => {
type: t.PAYMENT_RECEIVE_SET,
payload: {
id,
paymentReceive: response.data.paymentReceive,
paymentReceive: response.data.payment_receive,
},
});
dispatch({
type: t.INVOICES_ITEMS_SET,
payload: {
sales_invoices: response.data.sale_invoice.receivable_invoices,
sales_invoices: response.data.receivable_invoices,
},
});
dispatch({
type: t.INVOICES_ITEMS_SET,
payload: {
sales_invoices: response.data.payment_invoices,
},
});
dispatch({
type: t.INVOICES_RECEIVABLE_BY_PAYMENT_ID,
payload: {
paymentReceiveid: response.data.id,
saleInvoices: response.data.sale_invoice.receivable_invoices,
paymentReceiveId: response.data.payment_receive.id,
saleInvoices: response.data.receivable_invoices,
},
});
dispatch({
type: t.INVOICES_BY_PAYMENT_ID,
payload: {
paymentReceiveId: response.data.payment_receive.id,
saleInvoices: response.data.payment_invoices,
},
});
resovle(response);

View File

@@ -1,14 +1,32 @@
import { createSelector } from '@reduxjs/toolkit';
import { pickItemsFromIds, paginationLocationQuery } from 'store/selectors';
import { transformToObject } from 'utils';
const paymentReceivesPageSelector = (state, props, query) => {
const viewId = state.paymentReceives.currentViewId;
return state.paymentReceives.views?.[viewId]?.pages?.[query.page];
};
const paymentReceivesItemsSelector = (state) => {
return state.paymentReceives.items;
const paymentReceivesItemsSelector = (state) => state.paymentReceives.items;
const paymentReceiveTableQuery = (state) => state.paymentReceives.tableQuery;
const PaymentReceivePaginationSelector = (state, props) => {
const viewId = state.paymentReceives.currentViewId;
return state.paymentReceives.views?.[viewId];
};
const invoicesItemsSelector = (state) => state.salesInvoices.items;
const payemntReceiveById = (state, props) =>
state.paymentReceives.items[props.paymentReceiveId];
const invoicesReceivableByPaymentReceiveSelector = (state, props) =>
state.salesInvoices.receivable.byPaymentReceiveId[props.paymentReceiveId];
const paymentReceiveInvoicesSelector = (state, props) =>
state.salesInvoices.byPaymentReceiveId[props.paymentReceiveId];
const paymentReceiveByIdSelector = (state, props) =>
state.paymentReceives.items[props.paymentReceiveId];
export const getPaymentReceiveCurrentPageFactory = () =>
createSelector(
@@ -21,8 +39,6 @@ export const getPaymentReceiveCurrentPageFactory = () =>
},
);
const paymentReceiveTableQuery = (state) => state.paymentReceives.tableQuery;
export const getPaymentReceiveTableQuery = createSelector(
paginationLocationQuery,
paymentReceiveTableQuery,
@@ -34,48 +50,19 @@ export const getPaymentReceiveTableQuery = createSelector(
},
);
const PaymentReceivePaginationSelector = (state, props) => {
const viewId = state.paymentReceives.currentViewId;
return state.paymentReceives.views?.[viewId];
};
export const getPaymentReceivePaginationMetaFactory = () =>
createSelector(PaymentReceivePaginationSelector, (Page) => {
return Page?.paginationMeta || {};
});
const invoicesItems = (state) => {
return state.salesInvoices.items;
};
const payemntReceiveById = (state, props) => {
return state.paymentReceives.items[props.paymentReceiveId];
};
export const getPaymentReceiveByIdFactory = () =>
createSelector(payemntReceiveById, (payment_receive) => {
return payment_receive;
});
const paymentReceiveInvoicesIdss = (state, props) => {
return state.paymentReceives.items[props.paymentReceiveInvoices]
};
// const invoicesItems = (state) => {
// return state.sales_invoices.items;
// };
// export const = createSelector(
// paymentReceiveInvoicesIds,
// invoicesItems,
// (ids, items) => {},
// );
export const getPaymentReceiveInvoices = createSelector(
payemntReceiveById,
invoicesItems,
invoicesItemsSelector,
(paymentRecieve, items) => {
return typeof paymentRecieve === 'object'
? pickItemsFromIds(
@@ -85,3 +72,42 @@ export const getPaymentReceiveInvoices = createSelector(
: [];
},
);
/**
* Retrieve payment receive invoices entries.
*/
export const getPaymentReceiveEntriesFactory = () =>
createSelector(
invoicesItemsSelector,
invoicesReceivableByPaymentReceiveSelector,
paymentReceiveInvoicesSelector,
paymentReceiveByIdSelector,
(
invoicesItems,
paymentReceivableInvoicesIds,
paymentReceiveInvoicesIds,
paymentReceive,
) => {
const invoicesIds = [
...(paymentReceivableInvoicesIds || []),
...(paymentReceiveInvoicesIds || []),
];
const invoices = pickItemsFromIds(invoicesItems, invoicesIds);
const invoicesEntries = transformToObject(
paymentReceive?.entries || [],
'invoice_id',
);
return invoices.map((invoice) => {
const paymentReceiveEntry = invoicesEntries?.[invoice.id] || {};
return {
...invoice,
invoice_id: invoice.id,
total_payment_amount: invoice.payment_amount,
id: paymentReceiveEntry?.id,
payment_amount: paymentReceiveEntry?.payment_amount,
};
});
},
);