diff --git a/src/components/BillEventsTab.js b/src/components/BillEventsTab.js index 4046a6e..633e91f 100644 --- a/src/components/BillEventsTab.js +++ b/src/components/BillEventsTab.js @@ -5,9 +5,9 @@ import { BILL_EVENTS_TAB_VALUE, RIGHT_BILL_EVENT_SEARCH, RIGHT_BILL_EVENT_CREATE import BillEventsSearcher from "./BillEventsSearcher"; import CreateBillEventMessageDialog from "../dialogs/BillEventMessageDialog"; - -const BillEventsTabLabel = ({ intl, rights, onChange, tabStyle, isSelected }) => - rights?.includes(RIGHT_BILL_EVENT_SEARCH) && ( +const BillEventsTabLabel = ({ intl, rights, onChange, tabStyle, isSelected, isWorker }) => + rights?.includes(RIGHT_BILL_EVENT_SEARCH) && + !isWorker && ( /> ); - -const BillEventsTabPanel = ({ rights, value, bill }) => ( - - {rights?.includes(RIGHT_BILL_EVENT_CREATE_MESSAGE) && ( - - - - - - - - +const BillEventsTabPanel = ({ isWorker, rights, value, bill }) => + !isWorker && ( + + {rights?.includes(RIGHT_BILL_EVENT_CREATE_MESSAGE) && ( + + + + + + + + + - - )} - - -); - + )} + + + ); export { BillEventsTabLabel, BillEventsTabPanel }; diff --git a/src/components/BillFilter.js b/src/components/BillFilter.js index b14e935..ed27470 100644 --- a/src/components/BillFilter.js +++ b/src/components/BillFilter.js @@ -6,7 +6,7 @@ import { Grid } from "@material-ui/core"; import { withTheme, withStyles } from "@material-ui/core/styles"; import { withModulesManager, formatMessage, TextInput, NumberInput, PublishedComponent } from "@openimis/fe-core"; -import { CONTAINS_LOOKUP, DEFUALT_DEBOUNCE_TIME } from "../constants"; +import { CONTAINS_LOOKUP, DEFAULT, DEFUALT_DEBOUNCE_TIME } from "../constants"; import InvoiceStatusPicker from "../pickers/InvoiceStatusPicker"; import ThirdPartyTypePickerBill from "../pickers/ThirdPartyTypePickerBill"; import SubjectTypePickerBill from "../pickers/SubjectTypePickerBill"; @@ -20,7 +20,9 @@ const styles = (theme) => ({ }, }); -const BillFilter = ({ intl, classes, filters, onChangeFilters }) => { +const BillFilter = ({ intl, classes, filters, onChangeFilters, modulesManager }) => { + const isWorker = modulesManager.getConf("fe-core", "isWorker", DEFAULT.IS_WORKER); + const debouncedOnChangeFilters = _debounce(onChangeFilters, DEFUALT_DEBOUNCE_TIME); const filterValue = (filterName) => filters?.[filterName]?.value; @@ -60,24 +62,28 @@ const BillFilter = ({ intl, classes, filters, onChangeFilters }) => { return ( - - - - - - + {!isWorker && ( + <> + + + + + + + + )} { } /> - - - + {!isWorker && ( + + + + )} ); }; diff --git a/src/components/BillLineItemsFilter.js b/src/components/BillLineItemsFilter.js index 94fcf49..a049a3b 100644 --- a/src/components/BillLineItemsFilter.js +++ b/src/components/BillLineItemsFilter.js @@ -4,8 +4,8 @@ import _debounce from "lodash/debounce"; import { Grid } from "@material-ui/core"; import { withTheme, withStyles } from "@material-ui/core/styles"; -import { TextInput, NumberInput } from "@openimis/fe-core"; -import { CONTAINS_LOOKUP, DEFUALT_DEBOUNCE_TIME } from "../constants"; +import { TextInput, NumberInput, useModulesManager } from "@openimis/fe-core"; +import { CONTAINS_LOOKUP, DEFAULT, DEFUALT_DEBOUNCE_TIME } from "../constants"; const styles = (theme) => ({ form: { @@ -17,6 +17,10 @@ const styles = (theme) => ({ }); const BillLineItemsFilter = ({ classes, filters, onChangeFilters }) => { + const modulesManager = useModulesManager(); + + const isWorker = modulesManager.getConf("fe-core", "isWorker", DEFAULT.IS_WORKER); + const debouncedOnChangeFilters = _debounce(onChangeFilters, DEFUALT_DEBOUNCE_TIME); const filterValue = (filterName) => filters?.[filterName]?.value; @@ -71,14 +75,6 @@ const BillLineItemsFilter = ({ classes, filters, onChangeFilters }) => { onChange={onChangeStringFilter("description", CONTAINS_LOOKUP)} /> - - - { onChange={onChangeFilter("quantity")} /> - - - - - - - - - { onChange={onChangeFilter("amountTotal")} /> - - - + {!isWorker && ( + <> + + + + + + + + + + + + + + + + + )} ); }; diff --git a/src/components/BillLineItemsSearcher.js b/src/components/BillLineItemsSearcher.js index 4db6bd0..56a2595 100644 --- a/src/components/BillLineItemsSearcher.js +++ b/src/components/BillLineItemsSearcher.js @@ -18,53 +18,82 @@ const BillLineItemsSearcher = ({ billLineItems, billLineItemsPageInfo, billLineItemsTotalCount, + isWorker, }) => { const fetch = (params) => fetchBillLineItems(params); - const headers = () => [ - "billItem.code", - "billItem.description", - "billItem.ledgerAccount", - "billItem.quantity", - "billItem.unitPrice", - "billItem.discount", - "billItem.deduction", - "billItem.amountTotal", - "billItem.amountNet", - ]; - - const itemFormatters = () => [ - (billItem) => billItem.code, - (billItem) => billItem.description, - (billItem) => billItem.ledgerAccount, - (billItem) => billItem.quantity, - (billItem) => billItem.unitPrice, - (billItem) => billItem.discount, - (billItem) => billItem.deduction, - (billItem) => billItem.amountTotal, - (billItem) => ( - -
{billItem.amountNet}
-
- ), - ]; - - const sorts = () => [ - ["code", true], - ["description", true], - ["ledgerAccount", true], - ["quantity", true], - ["unitPrice", true], - ["discount", true], - ["deduction", true], - ["amountTotal", true], - ["amountNet", true], - ]; + const headersSetter = () => { + const headers = ["billItem.code", "billItem.description", "billItem.quantity", "billItem.amountTotal"]; + + if (!isWorker) { + const additionalHeaders = [ + "billItem.ledgerAccount", + "billItem.unitPrice", + "billItem.discount", + "billItem.deduction", + "billItem.amountNet", + ]; + + headers.push(...additionalHeaders); + } + + return headers; + }; + + const itemFormatters = () => { + const formatters = [ + (billItem) => billItem.code, + (billItem) => billItem.description, + (billItem) => billItem.quantity, + (billItem) => billItem.amountTotal, + ]; + + if (!isWorker) { + const additionalFormatters = [ + (billItem) => billItem.ledgerAccount, + (billItem) => billItem.unitPrice, + (billItem) => billItem.discount, + (billItem) => billItem.deduction, + (billItem) => ( + +
{billItem.amountNet}
+
+ ), + ]; + + formatters.push(...additionalFormatters); + } + + return formatters; + }; + + const sortsSetter = () => { + const sorts = [ + ["code", true], + ["description", true], + ["quantity", true], + ["amountTotal", true], + ]; + + if (!isWorker) { + const additionalSorts = [ + ["ledgerAccount", true], + ["unitPrice", true], + ["discount", true], + ["deduction", true], + ["amountNet", true], + ]; + + sorts.push(...additionalSorts); + } + + return sorts; + }; const defaultFilters = () => ({ bill_Id: { @@ -90,9 +119,9 @@ const BillLineItemsSearcher = ({ tableTitle={formatMessageWithValues(intl, "invoice", "billItems.searcher.resultsTitle", { billLineItemsTotalCount, })} - headers={headers} + headers={headersSetter} itemFormatters={itemFormatters} - sorts={sorts} + sorts={sortsSetter} rowsPerPageOptions={ROWS_PER_PAGE_OPTIONS} defaultPageSize={DEFAULT_PAGE_SIZE} defaultOrderBy="code" diff --git a/src/components/BillLineItemsTab.js b/src/components/BillLineItemsTab.js index d709bcf..14861fb 100644 --- a/src/components/BillLineItemsTab.js +++ b/src/components/BillLineItemsTab.js @@ -14,14 +14,9 @@ const BillLineItemsTabLabel = ({ intl, onChange, tabStyle, isSelected }) => ( /> ); -const BillLineItemsTabPanel = ({ value, bill }) => ( - - +const BillLineItemsTabPanel = ({ isWorker, value, bill }) => ( + + ); diff --git a/src/components/BillPaymentsSearcher.js b/src/components/BillPaymentsSearcher.js index 3858a69..0d3c6ad 100644 --- a/src/components/BillPaymentsSearcher.js +++ b/src/components/BillPaymentsSearcher.js @@ -15,16 +15,12 @@ import { coreConfirm, } from "@openimis/fe-core"; import { fetchBillPayments, deleteBillPayment } from "../actions"; -import { - DEFAULT_PAGE_SIZE, - EMPTY_STRING, - RIGHT_BILL_PAYMENT_DELETE, - ROWS_PER_PAGE_OPTIONS, -} from "../constants"; +import { DEFAULT_PAGE_SIZE, EMPTY_STRING, RIGHT_BILL_PAYMENT_DELETE, ROWS_PER_PAGE_OPTIONS } from "../constants"; import { ACTION_TYPE } from "../reducer"; import BillPaymentsFilter from "./BillPaymentsFilter"; const BillPaymentsSearcher = ({ + isWorker, intl, modulesManager, rights, @@ -65,7 +61,7 @@ const BillPaymentsSearcher = ({ refetch(); } }, [submittingMutation]); - + useEffect(() => { prevSubmittingMutationRef.current = submittingMutation; }); @@ -113,56 +109,82 @@ const BillPaymentsSearcher = ({ return queryParams; }; - const headers = () => [ - "billPayment.codeExt", - "billPayment.label", - "billPayment.codeTp", - "billPayment.codeReceipt", - "billPayment.fees", - "billPayment.amountReceived", - "billPayment.datePayment", - ]; + const headersSetter = () => { + const headers = [ + "billPayment.codeExt", + "billPayment.label", + "billPayment.amountReceived", + "billPayment.datePayment", + ]; + + if (!isWorker) { + const additionalHeaders = [ + "billPayment.codeTp", + "billPayment.codeReceipt", + "billPayment.fees", + "billPayment.paymentOrigin", + ]; + + headers.push(...additionalHeaders); + } + + return headers; + }; const itemFormatters = () => { const formatters = [ (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, - (billPayment) => billPayment.paymentOrigin, + billPayment.datePayment ? formatDateFromISO(modulesManager, intl, billPayment.datePayment) : EMPTY_STRING, ]; - if (rights.includes(RIGHT_BILL_PAYMENT_DELETE)) { + if (!isWorker) { + const additionalFormatters = [ + (billPayment) => billPayment.codeTp, + (billPayment) => billPayment.codeReceipt, + (billPayment) => billPayment.fees, + (billPayment) => billPayment.paymentOrigin, + ]; + + formatters.push(...additionalFormatters); + } + + if (!isWorker && rights.includes(RIGHT_BILL_PAYMENT_DELETE)) { formatters.push((billPayment) => ( - onDelete(billPayment)} - disabled={deletedBillPaymentUuids.includes(billPayment.id)} - > + onDelete(billPayment)} disabled={deletedBillPaymentUuids.includes(billPayment.id)}> )); } + return formatters; }; - const sorts = () => [ - ["codeExt", true], - ["label", true], - ["codeTp", true], - ["codeReceipt", true], - ["fees", true], - ["amountReceived", true], - ["datePayment", true], - ["paymentOrigin", true], - ]; + const sortsSetter = () => { + const sortsArray = [ + ["codeExt", true], + ["label", true], + ["amountReceived", true], + ["datePayment", true], + ]; + + if (!isWorker) { + const additionalSorts = [ + ["codeTp", true], + ["codeReceipt", true], + ["fees", true], + ["paymentOrigin", true], + ]; + + sortsArray.push(...additionalSorts); + } + + return sortsArray; + }; const defaultFilters = () => ({ subjectIds: { @@ -192,9 +214,9 @@ const BillPaymentsSearcher = ({ billPaymentsTotalCount, })} filtersToQueryParams={filtersToQueryParams} - headers={headers} + headers={headersSetter} itemFormatters={itemFormatters} - sorts={sorts} + sorts={sortsSetter} rowsPerPageOptions={ROWS_PER_PAGE_OPTIONS} defaultPageSize={DEFAULT_PAGE_SIZE} defaultOrderBy="codeExt" @@ -223,7 +245,7 @@ const mapDispatchToProps = (dispatch) => { { fetchBillPayments, deleteBillPayment, - coreConfirm + coreConfirm, }, dispatch, ); diff --git a/src/components/BillPaymentsTab.js b/src/components/BillPaymentsTab.js index f96c317..2bd68ec 100644 --- a/src/components/BillPaymentsTab.js +++ b/src/components/BillPaymentsTab.js @@ -5,7 +5,6 @@ import { BILL_PAYMENTS_TAB_VALUE, RIGHT_BILL_PAYMENT_SEARCH, RIGHT_BILL_PAYMENT_ import BillPaymentsSearcher from "./BillPaymentsSearcher"; import CreateBillPaymentDialog from "../dialogs/BillPaymentDialog"; - const BillPaymentsTabLabel = ({ intl, rights, onChange, tabStyle, isSelected }) => rights?.includes(RIGHT_BILL_PAYMENT_SEARCH) && ( ); - -const BillPaymentsTabPanel = ({ rights, value, bill, setConfirmedAction }) => ( +const BillPaymentsTabPanel = ({ isWorker, rights, value, bill, setConfirmedAction }) => ( - {rights?.includes(RIGHT_BILL_PAYMENT_CREATE) && ( + {rights?.includes(RIGHT_BILL_PAYMENT_CREATE) && !isWorker && ( @@ -31,10 +29,9 @@ const BillPaymentsTabPanel = ({ rights, value, bill, setConfirmedAction }) => ( - )} - + )} + ); - export { BillPaymentsTabLabel, BillPaymentsTabPanel }; diff --git a/src/components/BillSearcher.js b/src/components/BillSearcher.js index 121c4a7..deadfce 100644 --- a/src/components/BillSearcher.js +++ b/src/components/BillSearcher.js @@ -68,13 +68,10 @@ const BillSearcher = ({ const { economicUnit } = useSelector((state) => state.policyHolder); const economicUnitConfig = modulesManager.getConf("fe-core", "App.economicUnitConfig", DEFAULT.ECONOMIC_UNIT_CONFIG); const isAdminOrInspector = rights.includes(INSPECTOR_RIGHT) || rights.includes(ADMIN_RIGHT); + const isWorker = modulesManager.getConf("fe-core", "isWorker", DEFAULT.IS_WORKER); - const additionalExportFields = - economicUnitConfig && - economicUnit?.id && - !isAdminOrInspector - ? { subjectId: decodeId(economicUnit?.id) } - : {}; + const additionalExportFields = + economicUnitConfig && economicUnit?.id && !isAdminOrInspector ? { subjectId: decodeId(economicUnit?.id) } : {}; useEffect(() => billToDelete && openConfirmDialog(), [billToDelete]); @@ -150,14 +147,14 @@ const BillSearcher = ({ ); const headers = () => { - const headers = [ - "bill.subject", - "bill.thirdparty", - "bill.code", - "bill.dateBill", - "bill.amountTotal", - "bill.status.label", - ]; + const headers = ["bill.code", "bill.dateBill", "bill.amountTotal", "bill.status.label"]; + + if (!isWorker) { + const additionalHeaders = ["bill.subject", "bill.thirdparty"]; + + headers.unshift(...additionalHeaders); + } + if (rights.includes(RIGHT_BILL_SEARCH)) { headers.push("emptyLabel"); } @@ -166,51 +163,70 @@ const BillSearcher = ({ const itemFormatters = () => { const formatters = [ - (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.amountTotal, (bill) => , + (bill) => ( +
+ {rights.includes(RIGHT_BILL_SEARCH) && ( + + e.stopPropagation() && onDoubleClick(bill)} + disabled={deletedBillUuids.includes(bill.id)} + > + + + + )} + {rights.includes(RIGHT_BILL_DELETE) && ( + + onDelete(bill)} + disabled={bill?.status === STATUS.PAID || deletedBillUuids.includes(bill.id)} + > + + + + )} +
+ ), ]; - if (rights.includes(RIGHT_BILL_SEARCH)) { - formatters.push((bill) => ( - - e.stopPropagation() && onDoubleClick(bill)} - disabled={deletedBillUuids.includes(bill.id)} - > - - - - )); - } - if (rights.includes(RIGHT_BILL_DELETE)) { - formatters.push((bill) => ( - - onDelete(bill)} - disabled={bill?.status === STATUS.PAID || deletedBillUuids.includes(bill.id)} - > - - - - )); + + if (!isWorker) { + const additionalFormatters = [ + (bill) => getSubjectAndThirdpartyTypePicker(modulesManager, bill.subjectTypeName, bill.subject), + (bill) => getSubjectAndThirdpartyTypePicker(modulesManager, bill.thirdpartyTypeName, bill.thirdparty), + ]; + + formatters.unshift(...additionalFormatters); } + return formatters; }; const rowIdentifier = (bill) => bill.id; - const sorts = () => [ - ["subjectType", true], - ["thirdpartyType", true], - ["code", true], - ["dateBill", true], - ["amountTotal", true], - ["status", true], - ]; + const sorts = () => { + const sortsArray = [ + ["code", true], + ["dateBill", true], + ["amountTotal", true], + ["status", true], + ]; + + if (!isWorker) { + sortsArray.unshift( + ...[ + ["subjectType", true], + ["thirdpartyType", true], + ], + ); + } + + return sortsArray; + }; const billUpdatePageUrl = (bill) => modulesManager.getRef("bill.route.bill") + "/" + bill?.id; @@ -286,7 +302,7 @@ const BillSearcher = ({ rowLocked={isRowDisabled} actions={actions} actionsContributionKey={actionsContributionKey} - withSelection={economicUnitConfig && economicUnit?.id && !isAdminOrInspector ? null : "multiple"} + withSelection={economicUnitConfig && economicUnit?.id && !isAdminOrInspector ? null : "multiple"} selectionMessage={"bill.selection.count"} exportable={true} exportFetch={fetchBillsExport} diff --git a/src/components/BillTabPanel.js b/src/components/BillTabPanel.js index 39273ff..8c5d212 100644 --- a/src/components/BillTabPanel.js +++ b/src/components/BillTabPanel.js @@ -23,7 +23,7 @@ const styles = (theme) => ({ }, }); -const BillTabPanel = ({ intl, rights, classes, bill, setConfirmedAction }) => { +const BillTabPanel = ({ intl, rights, classes, bill, setConfirmedAction, isWorker = false }) => { const [activeTab, setActiveTab] = useState(BILL_LINE_ITEMS_TAB_VALUE); const isSelected = (tab) => tab === activeTab; @@ -43,6 +43,7 @@ const BillTabPanel = ({ intl, rights, classes, bill, setConfirmedAction }) => { onChange={handleChange} isSelected={isSelected} tabStyle={tabStyle} + isWorker={isWorker} /> { value={activeTab} bill={bill} setConfirmedAction={setConfirmedAction} + isWorker={isWorker} /> ); diff --git a/src/pages/BillPage.js b/src/pages/BillPage.js index 7e100bf..c756115 100644 --- a/src/pages/BillPage.js +++ b/src/pages/BillPage.js @@ -93,7 +93,7 @@ const BillPage = ({ }; const actions = [ - !!bill && + !!bill && !isWorker && getEnumValue(bill?.status) !== STATUS.PAID && { doIt: openDeleteBillConfirmDialog, icon: , @@ -116,6 +116,7 @@ const BillPage = ({ onChange={onChange} HeadPanel={isWorker && VoucherHeadPanel ? VoucherHeadPanel : BillHeadPanel} Panels={[BillTabPanel]} + isWorker={isWorker} rights={rights} actions={actions} setConfirmedAction={setConfirmedAction}