Skip to content

Commit

Permalink
Merge pull request #42 from openimis/feature/OM-134
Browse files Browse the repository at this point in the history
OM-134: clear and format bill searcher, add bill route to the moldova…
  • Loading branch information
wzglinieckisoldevelo authored Mar 7, 2024
2 parents 35a654e + 90fd282 commit d920091
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 91 deletions.
170 changes: 81 additions & 89 deletions src/components/BillSearcher.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import React, { useState, useCallback, useEffect, useRef } from "react";
import { bindActionCreators } from "redux";
import { connect } from "react-redux";
import { injectIntl } from "react-intl";

import { IconButton, Tooltip, Button, Dialog, DialogActions, DialogTitle } from "@material-ui/core";
import EditIcon from "@material-ui/icons/Edit";
import DeleteIcon from "@material-ui/icons/Delete";

import {
withModulesManager,
formatMessage,
Expand All @@ -10,10 +17,8 @@ import {
journalize,
withHistory,
historyPush,
downloadExport
downloadExport,
} from "@openimis/fe-core";
import { bindActionCreators } from "redux";
import { connect } from "react-redux";
import { fetchBills, deleteBill, fetchBillsExport } from "../actions";
import {
DEFAULT_PAGE_SIZE,
Expand All @@ -26,12 +31,6 @@ import {
import BillFilter from "./BillFilter";
import InvoiceStatusPicker from "../pickers/InvoiceStatusPicker";
import { getSubjectAndThirdpartyTypePicker } from "../util/subject-and-thirdparty-picker";
import { IconButton, Tooltip, Button,
Dialog,
DialogActions,
DialogTitle,} from "@material-ui/core";
import EditIcon from "@material-ui/icons/Edit";
import DeleteIcon from "@material-ui/icons/Delete";

const BillSearcher = ({
intl,
Expand All @@ -53,15 +52,13 @@ const BillSearcher = ({
billsPageInfo,
billsTotalCount,
billsExport,
billsExportPageInfo,
billsExportTotalCount,
errorBillsExport,
actions,
actionsContributionKey
actionsContributionKey,
}) => {
const [billToDelete, setBillToDelete] = useState(null);
const [deletedBillUuids, setDeletedBillUuids] = useState([]);
const [failedExport, setFailedExport] = useState(false)
const [failedExport, setFailedExport] = useState(false);
const prevSubmittingMutationRef = useRef();

useEffect(() => billToDelete && openConfirmDialog(), [billToDelete]);
Expand All @@ -75,14 +72,14 @@ const BillSearcher = ({
}, [confirmed]);

useEffect(() => {
setFailedExport(true)
}, [errorBillsExport])
setFailedExport(true);
}, [errorBillsExport]);

useEffect(() => {
if (billsExport) {
downloadExport(billsExport, 'bill_export.csv')();
downloadExport(billsExport, "bill_export.csv")();
}
}, [billsExport])
}, [billsExport]);

useEffect(() => {
prevSubmittingMutationRef.current && !submittingMutation && journalize(mutation);
Expand Down Expand Up @@ -112,7 +109,7 @@ const BillSearcher = ({
formatMessage(intl, "bill", "delete.confirm.message"),
),
[billToDelete],
);
);

const fetch = (params) => fetchBills(params);

Expand All @@ -136,8 +133,7 @@ const BillSearcher = ({
(bill) => getSubjectAndThirdpartyTypePicker(modulesManager, bill.subjectTypeName, bill.subject),
(bill) => getSubjectAndThirdpartyTypePicker(modulesManager, bill.thirdpartyTypeName, bill.thirdparty),
(bill) => bill.code,
(bill) =>
!!bill.dateBill ? formatDateFromISO(modulesManager, intl, bill.dateBill) : EMPTY_STRING,
(bill) => (!!bill.dateBill ? formatDateFromISO(modulesManager, intl, bill.dateBill) : EMPTY_STRING),
(bill) => bill.amountTotal,
(bill) => <InvoiceStatusPicker value={bill?.status} readOnly />,
];
Expand Down Expand Up @@ -198,74 +194,73 @@ const BillSearcher = ({
},
});

const exportFields = () => ({
'id': 'ID',
'userCreated.username': "User",
'amount_total': "AmountTotal",
"subjectTypeName": "Subject",
'thirdpartyTypeName': "SenderType",
'thirdparty': ""
})

return (
<div>
<Searcher
module="bill"
FilterPane={BillFilter}
fetch={fetch}
items={bills}
itemsPageInfo={billsPageInfo}
fetchingItems={fetchingBills}
fetchedItems={fetchedBills}
errorItems={errorBills}
tableTitle={formatMessageWithValues(intl, "bill", "bills.searcherResultsTitle", {
billsTotalCount,
})}
headers={headers}
itemFormatters={itemFormatters}
sorts={sorts}
rowsPerPageOptions={ROWS_PER_PAGE_OPTIONS}
defaultPageSize={DEFAULT_PAGE_SIZE}
defaultOrderBy="code"
rowIdentifier={rowIdentifier}
onDoubleClick={onDoubleClick}
defaultFilters={defaultFilters()}
rowDisabled={isRowDisabled}
rowLocked={isRowDisabled}
actions={actions}
actionsContributionKey={actionsContributionKey}
withSelection="multiple"
selectionMessage={"bill.selection.count"}
exportable={true}
exportFetch={fetchBillsExport}
exportFields={[
'id', 'userCreated.username', 'amount_total', 'subjectType', 'subjectId', 'thirdpartyType',
'thirdpartyId', 'code', 'status', 'dateBill'
]}
exportFieldsColumns={{
'id': 'ID',
'userCreated.username': "User",
'amount_total': "AmountTotal",
"subjectType": "Subject Type",
"subject": "subject",
'thirdpartyType': "SenderType",
'thirdparty': "Sender",
'code': 'code',
'dateBill': 'Date Bill',
'status': 'Status',
}}
/>
<Searcher
module="bill"
FilterPane={BillFilter}
fetch={fetch}
items={bills}
itemsPageInfo={billsPageInfo}
fetchingItems={fetchingBills}
fetchedItems={fetchedBills}
errorItems={errorBills}
tableTitle={formatMessageWithValues(intl, "bill", "bills.searcherResultsTitle", {
billsTotalCount,
})}
headers={headers}
itemFormatters={itemFormatters}
sorts={sorts}
rowsPerPageOptions={ROWS_PER_PAGE_OPTIONS}
defaultPageSize={DEFAULT_PAGE_SIZE}
defaultOrderBy="code"
rowIdentifier={rowIdentifier}
onDoubleClick={onDoubleClick}
defaultFilters={defaultFilters()}
rowDisabled={isRowDisabled}
rowLocked={isRowDisabled}
actions={actions}
actionsContributionKey={actionsContributionKey}
withSelection="multiple"
selectionMessage={"bill.selection.count"}
exportable={true}
exportFetch={fetchBillsExport}
exportFields={[
"id",
"userCreated.username",
"amount_total",
"subjectType",
"subjectId",
"thirdpartyType",
"thirdpartyId",
"code",
"status",
"dateBill",
]}
exportFieldsColumns={{
"id": "ID",
"userCreated.username": "User",
"amount_total": "AmountTotal",
"subjectType": "Subject Type",
"subject": "subject",
"thirdpartyType": "SenderType",
"thirdparty": "Sender",
"code": "code",
"dateBill": "Date Bill",
"status": "Status",
}}
/>

{failedExport && (
<Dialog fullWidth maxWidth="sm">
<DialogTitle>{errorBillsExport}</DialogTitle>
<DialogActions>
<Button onClick={setFailedExport(false)} variant="contained">
{formatMessage(intl, "invoice", "ok")}
</Button>
</DialogActions>
</Dialog>
)}
{failedExport && (
<Dialog fullWidth maxWidth="sm">
<DialogTitle>{errorBillsExport}</DialogTitle>
<DialogActions>
<Button onClick={setFailedExport(false)} variant="contained">
{formatMessage(intl, "invoice", "ok")}
</Button>
</DialogActions>
</Dialog>
)}
</div>
);
};
Expand All @@ -280,7 +275,6 @@ const mapStateToProps = (state) => ({
confirmed: state.core.confirmed,
submittingMutation: state.invoice.submittingMutation,
mutation: state.invoice.mutation,

fetchingBillsExport: state.invoice.fetchingBillsExport,
fetchedBillsExport: state.invoice.fetchedBillsExport,
billsExport: state.invoice.billsExport,
Expand All @@ -302,6 +296,4 @@ const mapDispatchToProps = (dispatch) => {
);
};

export default withHistory(
withModulesManager(injectIntl(connect(mapStateToProps, mapDispatchToProps)(BillSearcher))),
);
export default withHistory(withModulesManager(injectIntl(connect(mapStateToProps, mapDispatchToProps)(BillSearcher))));
16 changes: 14 additions & 2 deletions src/menus/LegalAndFinanceMainMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,22 @@ const LegalAndFinanceMainMenu = (props) => {
const { modulesManager, rights, intl } = props;
const isWorker = modulesManager.getConf("fe-core", "isWorker", false);

if (isWorker) return null;

const entries = [];

if (isWorker) {
if (rights.includes(RIGHT_BILL_SEARCH || RIGHT_BILL_AMEND)) {
entries.push({
text: formatMessage(intl, "invoice", "menu.bills"),
icon: <DoubleArrowFlipped />,
route: "/bills",
});
}

if (!entries.length) return null;

return <MainMenuContribution {...props} header={formatMessage(intl, "invoice", "mainMenu")} entries={entries} />;
}

if (rights.filter((r) => r >= RIGHT_INVOICE_SEARCH && r <= RIGHT_INVOICE_AMEND).length) {
// RIGHT_SEARCH is shared by HF & HQ staff)
entries.push({
Expand Down

0 comments on commit d920091

Please sign in to comment.