Skip to content

Commit

Permalink
OP-1854: use billPayment instead of paymentInvoice
Browse files Browse the repository at this point in the history
  • Loading branch information
olewandowski1 committed Apr 3, 2024
1 parent f6a6773 commit 82e1949
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 114 deletions.
44 changes: 9 additions & 35 deletions src/components/BillPaymentsFilter.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { withTheme, withStyles } from "@material-ui/core/styles";

import { withModulesManager, formatMessage, TextInput, NumberInput, PublishedComponent } from "@openimis/fe-core";
import { CONTAINS_LOOKUP, DEFUALT_DEBOUNCE_TIME, STARTS_WITH_LOOKUP } from "../constants";
import PaymentInvoiceStatusPicker from "../pickers/PaymentInvoiceStatusPicker";

const styles = (theme) => ({
form: {
Expand All @@ -18,7 +17,7 @@ const styles = (theme) => ({
},
});

const BillPaymentsFilter = ({ intl, classes, filters, onChangeFilters }) => {
const BillPaymentsFilter = ({ classes, filters, onChangeFilters }) => {
const debouncedOnChangeFilters = _debounce(onChangeFilters, DEFUALT_DEBOUNCE_TIME);

const filterValue = (filterName) => filters?.[filterName]?.value;
Expand Down Expand Up @@ -57,59 +56,42 @@ const BillPaymentsFilter = ({ intl, classes, filters, onChangeFilters }) => {

return (
<Grid container className={classes.form}>
<Grid item xs={2} className={classes.item}>
<PaymentInvoiceStatusPicker
label="paymentInvoice.reconciliationStatus.label"
withNull
nullLabel={formatMessage(intl, "invoice", "any")}
value={filterValue("reconciliationStatus")}
onChange={(value) =>
onChangeFilters([
{
id: "reconciliationStatus",
value: value,
filter: `reconciliationStatus: "${value}"`,
},
])
}
/>
</Grid>
<Grid item xs={2} className={classes.item}>
<TextInput
module="invoice"
label="paymentInvoice.codeExt"
label="billPayment.codeExt"
value={filterTextFieldValue("codeExt")}
onChange={onChangeStringFilter("codeExt", CONTAINS_LOOKUP)}
/>
</Grid>
<Grid item xs={2} className={classes.item}>
<TextInput
module="invoice"
label="paymentInvoice.label"
label="billPayment.label"
value={filterTextFieldValue("label")}
onChange={onChangeStringFilter("label", STARTS_WITH_LOOKUP)}
/>
</Grid>
<Grid item xs={2} className={classes.item}>
<TextInput
module="invoice"
label="paymentInvoice.codeTp"
label="billPayment.codeTp"
value={filterTextFieldValue("codeTp")}
onChange={onChangeStringFilter("codeTp", CONTAINS_LOOKUP)}
/>
</Grid>
<Grid item xs={2} className={classes.item}>
<TextInput
module="invoice"
label="paymentInvoice.codeReceipt"
label="billPayment.codeReceipt"
value={filterTextFieldValue("codeReceipt")}
onChange={onChangeStringFilter("codeReceipt", CONTAINS_LOOKUP)}
/>
</Grid>
<Grid item xs={2} className={classes.item}>
<NumberInput
module="invoice"
label="paymentInvoice.fees"
label="billPayment.fees"
min={0}
value={filterValue("fees")}
onChange={onChangeFilter("fees")}
Expand All @@ -118,7 +100,7 @@ const BillPaymentsFilter = ({ intl, classes, filters, onChangeFilters }) => {
<Grid item xs={2} className={classes.item}>
<NumberInput
module="invoice"
label="paymentInvoice.amountReceived"
label="billPayment.amountReceived"
min={0}
value={filterValue("amountReceived")}
onChange={onChangeFilter("amountReceived")}
Expand All @@ -128,27 +110,19 @@ const BillPaymentsFilter = ({ intl, classes, filters, onChangeFilters }) => {
<PublishedComponent
pubRef="core.DatePicker"
module="invoice"
label="paymentInvoice.datePayment"
label="billPayment.datePayment"
value={filterValue("datePayment")}
onChange={onChangeStringFilter("datePayment")}
/>
</Grid>
<Grid item xs={2} className={classes.item}>
<TextInput
module="invoice"
label="paymentInvoice.paymentOrigin"
label="billPayment.paymentOrigin"
value={filterTextFieldValue("paymentOrigin")}
onChange={onChangeStringFilter("paymentOrigin", CONTAINS_LOOKUP)}
/>
</Grid>
<Grid item xs={2} className={classes.item}>
<TextInput
module="invoice"
label="paymentInvoice.payerRef"
value={filterTextFieldValue("payerRef")}
onChange={onChangeStringFilter("payerRef", CONTAINS_LOOKUP)}
/>
</Grid>
</Grid>
);
};
Expand Down
151 changes: 72 additions & 79 deletions src/components/BillPaymentsSearcher.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import React, { useRef, useEffect, useState } from "react";
import { bindActionCreators } from "redux";
import { connect } from "react-redux";
import { injectIntl } from "react-intl";

import { IconButton, Tooltip } from "@material-ui/core";
import DeleteIcon from "@material-ui/icons/Delete";

import {
formatMessage,
formatMessageWithValues,
Expand All @@ -8,59 +14,53 @@ import {
withModulesManager,
coreConfirm,
} from "@openimis/fe-core";
import { bindActionCreators } from "redux";
import { connect } from "react-redux";
import { fetchPaymentInvoices, deletePaymentInvoice } from "../actions";
import { fetchBillPayments, deleteBillPayment } from "../actions";
import {
DEFAULT_PAGE_SIZE,
EMPTY_STRING,
RIGHT_BILL_PAYMENT_DELETE,
ROWS_PER_PAGE_OPTIONS,
} from "../constants";
import BillPaymentsFilter from "./BillPaymentsFilter";
import PaymentInvoiceStatusPicker from "../pickers/PaymentInvoiceStatusPicker"
import DeleteIcon from "@material-ui/icons/Delete";
import { IconButton, Tooltip } from "@material-ui/core";
import { ACTION_TYPE } from "../reducer";
import BillPaymentsFilter from "./BillPaymentsFilter";

const BillPaymentsSearcher = ({
intl,
modulesManager,
rights,
bill,
setConfirmedAction,
deletePaymentInvoice,
submittingMutation,
mutation,
coreConfirm,
confirmed,
fetchPaymentInvoices,
fetchingPaymentInvoices,
fetchedPaymentInvoices,
errorPaymentInvoices,
paymentInvoices,
paymentInvoicesPageInfo,
paymentInvoicesTotalCount,
fetchBillPayments,
fetchingBillPayments,
fetchedBillPayments,
errorBillPayments,
billPayments,
billPaymentsPageInfo,
billPaymentsTotalCount,
}) => {
const [queryParams, setQueryParams] = useState([]);
const [paymentInvoiceToDelete, setPaymentInvoiceToDelete] = useState(null);
const [deletedPaymentInvoiceUuids, setDeletedPaymentInvoiceUuids] = useState([]);
const [billPaymentToDelete, setBillPaymentToDelete] = useState(null);
const [deletedBillPaymentUuids, setDeletedBillPaymentUuids] = useState([]);
const prevSubmittingMutationRef = useRef();

useEffect(() => paymentInvoiceToDelete && openDeletePaymentInvoiceConfirmDialog(), [paymentInvoiceToDelete]);
useEffect(() => billPaymentToDelete && openDeleteBillPaymentConfirmDialog(), [billPaymentToDelete]);

useEffect(() => {
if (paymentInvoiceToDelete && confirmed) {
setDeletedPaymentInvoiceUuids([...deletedPaymentInvoiceUuids, paymentInvoiceToDelete.id]);
if (billPaymentToDelete && confirmed) {
setDeletedBillPaymentUuids([...deletedBillPaymentUuids, billPaymentToDelete.id]);
}
paymentInvoiceToDelete && confirmed !== null && setPaymentInvoiceToDelete(null);
billPaymentToDelete && confirmed !== null && setBillPaymentToDelete(null);
}, [confirmed]);

useEffect(() => {
if (
prevSubmittingMutationRef.current &&
!submittingMutation &&
[ACTION_TYPE.CREATE_PAYMENT_INVOICE_WITH_DETAIL, ACTION_TYPE.UPDATE_BILL_PAYMENT].includes(mutation?.actionType)
[ACTION_TYPE.CREATE_BILL_PAYMENT, ACTION_TYPE.UPDATE_BILL_PAYMENT].includes(mutation?.actionType)
) {
refetch();
}
Expand All @@ -70,28 +70,28 @@ const BillPaymentsSearcher = ({
prevSubmittingMutationRef.current = submittingMutation;
});

const deletePaymentInvoiceCallback = () =>
deletePaymentInvoice(
paymentInvoiceToDelete,
formatMessageWithValues(intl, "invoice", "paymentInvoice.delete.mutationLabel", {
paymentInvoiceLabel: paymentInvoiceToDelete?.label,
code: bill?.code,
const deleteBillPaymentCallback = () =>
deleteBillPayment(
billPaymentToDelete,
formatMessageWithValues(intl, "invoice", "billPayment.delete.mutationLabel", {
billPaymentLabel: billPaymentToDelete?.label,
billCode: bill?.code,
}),
);

const openDeletePaymentInvoiceConfirmDialog = () => {
setConfirmedAction(() => deletePaymentInvoiceCallback);
const openDeleteBillPaymentConfirmDialog = () => {
setConfirmedAction(() => deleteBillPaymentCallback);
coreConfirm(
formatMessageWithValues(intl, "invoice", "paymentInvoice.delete.confirm.title", {
paymentInvoiceLabel: paymentInvoiceToDelete?.label,
formatMessageWithValues(intl, "invoice", "billPayment.delete.confirm.title", {
billPaymentLabel: billPaymentToDelete?.label,
}),
formatMessage(intl, "invoice", "paymentInvoice.delete.confirm.message"),
formatMessage(intl, "invoice", "billPayment.delete.confirm.message"),
);
};

const onDelete = (paymentInvoice) => setPaymentInvoiceToDelete(paymentInvoice);
const onDelete = (billPayment) => setBillPaymentToDelete(billPayment);

const fetch = (params) => fetchPaymentInvoices(params);
const fetch = (params) => fetchBillPayments(params);

const refetch = () => fetch(queryParams);

Expand All @@ -114,41 +114,36 @@ const BillPaymentsSearcher = ({
};

const headers = () => [
"paymentInvoice.reconciliationStatus.label",
"paymentInvoice.codeExt",
"paymentInvoice.label",
"paymentInvoice.codeTp",
"paymentInvoice.codeReceipt",
"paymentInvoice.fees",
"paymentInvoice.amountReceived",
"paymentInvoice.datePayment",
"paymentInvoice.paymentOrigin",
"paymentInvoice.payerRef",
"billPayment.codeExt",
"billPayment.label",
"billPayment.codeTp",
"billPayment.codeReceipt",
"billPayment.fees",
"billPayment.amountReceived",
"billPayment.datePayment",
];

const itemFormatters = () => {
const formatters = [
(paymentInvoice) => <PaymentInvoiceStatusPicker value={paymentInvoice?.reconciliationStatus} readOnly />,
(paymentInvoice) => paymentInvoice.codeExt,
(paymentInvoice) => paymentInvoice.label,
(paymentInvoice) => paymentInvoice.codeTp,
(paymentInvoice) => paymentInvoice.codeReceipt,
(paymentInvoice) => paymentInvoice.fees,
(paymentInvoice) => paymentInvoice.amountReceived,
(paymentInvoice) =>
!!paymentInvoice.datePayment
? formatDateFromISO(modulesManager, intl, paymentInvoice.datePayment)
(billPayment) => billPayment.codeExt,
(billPayment) => billPayment.label,
(billPayment) => billPayment.codeTp,
(billPayment) => billPayment.codeReceipt,
(billPayment) => billPayment.fees,
(billPayment) => billPayment.amountReceived,
(billPayment) =>
!!billPayment.datePayment
? formatDateFromISO(modulesManager, intl, billPayment.datePayment)
: EMPTY_STRING,
(paymentInvoice) => paymentInvoice.paymentOrigin,
(paymentInvoice) => paymentInvoice.payerRef,
(billPayment) => billPayment.paymentOrigin,
];

if (rights.includes(RIGHT_BILL_PAYMENT_DELETE)) {
formatters.push((paymentInvoice) => (
formatters.push((billPayment) => (
<Tooltip title={formatMessage(intl, "invoice", "deleteButtonTooltip")}>
<IconButton
onClick={() => onDelete(paymentInvoice)}
disabled={deletedPaymentInvoiceUuids.includes(paymentInvoice.id)}
onClick={() => onDelete(billPayment)}
disabled={deletedBillPaymentUuids.includes(billPayment.id)}
>
<DeleteIcon />
</IconButton>
Expand All @@ -159,7 +154,6 @@ const BillPaymentsSearcher = ({
};

const sorts = () => [
["reconciliationStatus", true],
["codeExt", true],
["label", true],
["codeTp", true],
Expand All @@ -168,35 +162,34 @@ const BillPaymentsSearcher = ({
["amountReceived", true],
["datePayment", true],
["paymentOrigin", true],
["payerRef", true],
];

const defaultFilters = () => ({
subjectIds: {
value: bill?.id,
filter: `subjectIds: ["${bill?.id}"]`,
filter: `id: "${bill?.id}"`,
},
isDeleted: {
value: false,
filter: "isDeleted: false",
},
});

const isRowDisabled = (_, paymentInvoice) => deletedPaymentInvoiceUuids.includes(paymentInvoice.id);
const isRowDisabled = (_, billPayment) => deletedBillPaymentUuids.includes(billPayment.id);

return (
!!bill?.id && (
<Searcher
module="bill"
FilterPane={BillPaymentsFilter}
fetch={fetch}
items={paymentInvoices}
itemsPageInfo={paymentInvoicesPageInfo}
fetchingItems={fetchingPaymentInvoices}
fetchedItems={fetchedPaymentInvoices}
errorItems={errorPaymentInvoices}
tableTitle={formatMessageWithValues(intl, "invoice", "paymentInvoices.searcherResultsTitle", {
paymentInvoicesTotalCount,
items={billPayments}
itemsPageInfo={billPaymentsPageInfo}
fetchingItems={fetchingBillPayments}
fetchedItems={fetchedBillPayments}
errorItems={errorBillPayments}
tableTitle={formatMessageWithValues(intl, "invoice", "billPayments.searcherResultsTitle", {
billPaymentsTotalCount,
})}
filtersToQueryParams={filtersToQueryParams}
headers={headers}
Expand All @@ -214,12 +207,12 @@ const BillPaymentsSearcher = ({
};

const mapStateToProps = (state) => ({
fetchingPaymentInvoices: state.invoice.fetchingPaymentInvoices,
fetchedPaymentInvoices: state.invoice.fetchedPaymentInvoices,
errorPaymentInvoices: state.invoice.errorPaymentInvoices,
paymentInvoices: state.invoice.paymentInvoices,
paymentInvoicesPageInfo: state.invoice.paymentInvoicesPageInfo,
paymentInvoicesTotalCount: state.invoice.paymentInvoicesTotalCount,
fetchingBillPayments: state.invoice.fetchingBillPayments,
fetchedBillPayments: state.invoice.fetchedBillPayments,
errorBillPayments: state.invoice.errorBillPayments,
billPayments: state.invoice.billPayments,
billPaymentsPageInfo: state.invoice.billPaymentsPageInfo,
billPaymentsTotalCount: state.invoice.billPaymentsTotalCount,
submittingMutation: state.invoice.submittingMutation,
mutation: state.invoice.mutation,
confirmed: state.core.confirmed,
Expand All @@ -228,8 +221,8 @@ const mapStateToProps = (state) => ({
const mapDispatchToProps = (dispatch) => {
return bindActionCreators(
{
fetchPaymentInvoices,
deletePaymentInvoice,
fetchBillPayments,
deleteBillPayment,
coreConfirm
},
dispatch,
Expand Down

0 comments on commit 82e1949

Please sign in to comment.