Skip to content

Commit

Permalink
OLMIS-7903: part of the task
Browse files Browse the repository at this point in the history
  • Loading branch information
mdulko committed Mar 29, 2024
1 parent bc8eadc commit b6b412c
Show file tree
Hide file tree
Showing 6 changed files with 298 additions and 1 deletion.
14 changes: 14 additions & 0 deletions src/buq/Routing.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ import MohApproveFacilityDemandingForecasting from './components/MOHApproval/Moh
import MOHApprovalDistrictBuq from './components/MOHApproval/MOHApprovalDistrictBuq';
import MOHApproveRegionBuq from './components/MOHApproval/MOHApproveRegionBuq';
import MOHApprovalFacilityBuq from './components/MOHApproval/MOHApprovalFacilityBuq';
import MohForFinalApproval from './components/MOHApproval/MohForFinalApproval';
import useLocalStorage from "../react-hooks/useLocalStorage";


const Routing = ({
loadingModalService,
facilityService,
Expand Down Expand Up @@ -56,6 +58,10 @@ const Routing = ({
path: '/buq/national-approve',
breadcrumb: 'Pending Approvals'
},
{
path: '/buq/national-approval',
breadcrumb: 'Pending Approvals'
},
{
path: '/buq/national-approve/:districtId',
breadcrumb: 'District Summary'
Expand Down Expand Up @@ -147,6 +153,14 @@ const Routing = ({
orderableService={orderableService}
/>
</Route>
<Route exact path='/buq/national-approval'>
<MohForFinalApproval
loadingModalService={loadingModalService}
periodService={periodService}
orderableService={orderableService}
facilityService={facilityService}
/>
</Route>
</Switch>
</Router>
</div>
Expand Down
10 changes: 9 additions & 1 deletion src/buq/buq.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@
.state('openlmis.buq.MOHPORALGApprovals', {
label: 'buq.MOHPORALGApprovals',
url: '/national-approve',
showInNavigation: true,
showInNavigation: false,
priority: 10,
accessRights: [BUQ_RIGHTS.MOH_APPROVAL, BUQ_RIGHTS.PORALG_APPROVAL],
resolve: createResolve(false)
Expand All @@ -172,6 +172,14 @@
showInNavigation: false,
accessRights: [BUQ_RIGHTS.MOH_APPROVAL, BUQ_RIGHTS.PORALG_APPROVAL],
resolve: createResolve(false)
})
.state('openlmis.buq.MOHPORALGForFinalApproval', {
label: 'buq.MOHPORALGApprovals',
url: '/national-approval',
showInNavigation: true,
priority: 10,
accessRights: [BUQ_RIGHTS.MOH_APPROVAL, BUQ_RIGHTS.PORALG_APPROVAL],
resolve: createResolve(false)
});

}
Expand Down
14 changes: 14 additions & 0 deletions src/buq/buq.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@
'?processingPeriodId=:ppId&programId=:pId&geographicZoneId=:gzId'),
method: 'POST',
isArray: true
},
forFinalApproval: {
url: openlmisUrlFactory('/api/bottomUpQuantifications/forFinalApproval' +
'?processingPeriodId=:ppId&programId=:pId&geographicZoneId=:gzId'),
method: 'GET'
}
});

Expand All @@ -141,6 +146,7 @@
this.getMostRecentRejection = getMostRecentRejection;
this.userHasBUQProgram = userHasBUQProgram;
this.doesSupportBUQProgram = doesSupportBUQProgram;
this.forFinalApproval = forFinalApproval;

function getBuqs(facilityId) {
var queryParams = {};
Expand Down Expand Up @@ -258,6 +264,14 @@
}, payload).$promise;
}

function forFinalApproval(programId, processingPeriodId, geoZoneId) {
return resource.forFinalApproval({
pId: programId,
ppId: processingPeriodId,
gzId: geoZoneId
}).$promise;
}

function getMostRecentRejection(buqId) {
return resource.getMostRecentRejection({
id: buqId
Expand Down
1 change: 1 addition & 0 deletions src/buq/components/MOHApproval/MOHApproveRegionBuq.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ const MOHApproveRegionBuq = ({ loadingModalService }) => {
accessor: 'id',
Cell: ({ row }) => {
const { values } = row;
console.log(values);
handleSaveInLocalStorage(STORAGE_MOH_APPROVAL_PARAMS, {
forecastingPeriodId,
programId,
Expand Down
103 changes: 103 additions & 0 deletions src/buq/components/MOHApproval/MOHFinalApprovalTable.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import React, { useMemo } from "react";
import Table from "../../../react-components/table/table";
import WebTooltip from "../../../react-components/modals/web-tooltip";
import { Link } from "react-router-dom";
import ResponsiveButton from "../../../react-components/buttons/responsive-button";
import useLocalStorage from "../../../react-hooks/useLocalStorage";
import {STORAGE_MOH_APPROVAL_PARAMS} from "../../utils/constants";
import { addThousandsSeparatorsForStrings } from '../../utils/helpers';

const MOHApprovalTable = ({ data, redirectUrl, districtLvl = false }) => {
const { storedItems: { mohApprovalParams }, handleSaveInLocalStorage } = useLocalStorage();

const columns = useMemo(
() => [
{
Header: () => (
<div className="header-moh-approve-status-icon">
<div>Status</div>
<WebTooltip
shouldDisplayTooltip={true}
tooltipContent={"All facilities have reported in this period"}
>
<i className="fa fa-info-circle"></i>
</WebTooltip>
</div>
),
accessor: "status",
Cell: () => (
<div className="fa-check-container">
<i className="fa fa-check"></i>
</div>
),
},
{
Header: `${districtLvl ? "District" : "Facility Name"}`,
accessor: `${districtLvl ? "district" : "facilityName"}`,
},
{
Header: "Facility Type",
accessor: "facilityType",
},
{
Header: "Pharmaceuticals",
accessor: "pharmaceuticals",
Cell: ({ value }) => addThousandsSeparatorsForStrings(value),
},
{
Header: "Medical supplies & Equipment",
accessor: "medicalSupplies",
Cell: ({ value }) => addThousandsSeparatorsForStrings(value),
},
{
Header: "Radiology (x-rays consumables)",
accessor: "radiology",
Cell: ({ value }) => addThousandsSeparatorsForStrings(value),
},
{
Header: "Diagnostics supplies & Equipment",
accessor: "diagnosticsSupplies",
Cell: ({ value }) => addThousandsSeparatorsForStrings(value),
},
{
Header: "Dental supplies & Equipment",
accessor: "dentalSupplies",
Cell: ({ value }) => addThousandsSeparatorsForStrings(value),
},
{
Header: "Actions",
accessor: "id",
Cell: ({ row: { values } }) => {
if (districtLvl) {
handleSaveInLocalStorage(STORAGE_MOH_APPROVAL_PARAMS, {
forecastingPeriodId: mohApprovalParams?.forecastingPeriodId,
programId: mohApprovalParams?.programId,
region: mohApprovalParams?.region,
district: values.district
})
}
return (
<Link to={`${redirectUrl}/${data.facilityId}/${values.id}`}>
<ResponsiveButton className="proceed">
<span>View</span>
</ResponsiveButton>
</Link>
)
},
},
],
[]
);

return (
<Table
columns={columns}
data={data ?? []}
noItemsMessage="No reports available"
customReactTableStyle="moh-approve-buq"
customReactTableContentStyle='moh-approve-buq-content'
/>
);
};

export default MOHApprovalTable;
157 changes: 157 additions & 0 deletions src/buq/components/MOHApproval/MohForFinalApproval.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
import React, { useState, useMemo, useEffect } from 'react';
import { toast } from 'react-toastify';
import InputWithSuggestionsAndValidation from '../../../react-components/inputs/input-with-suggestions-and-validation';
import useBuqCommonFuncs from '../../../react-hooks/useBuqCommonFunctions';
import Table from '../../../react-components/table/table';
import ResponsiveButton from '../../../react-components/buttons/responsive-button';
import Checkbox from '../../../react-components/inputs/checkbox';
import ActionBar from '../../../react-components/ActionBar';
import Modal from '../../../admin-buq/components/Modal/Modal';
import ConfirmModalBody from '../../../react-components/ConfirmModalBody';
import { Link } from 'react-router-dom';
import { STORAGE_MOH_APPROVAL_PARAMS } from '../../utils/constants';
import WebTooltip from '../../../react-components/modals/web-tooltip';
import useGeographicZoneGroup from '../../../react-hooks/useGeographicZoneGroup';
import useServerService from '../../../react-hooks/useServerService';
import useLocalStorage from '../../../react-hooks/useLocalStorage';
import useCostCalculationRegion from '../../../react-hooks/useCostCalculationRegion';
import ModalErrorMessage from '../../../react-components/ModalErrorMessage';
import { addThousandsSeparatorsForStrings } from '../../utils/helpers';
import MOHApprovalTable from "./MOHApprovalTable";
import useCostCalculationDistrictOrFacility from "../../../react-hooks/useCostCalculationDistrictOrFacility";
import MOHFinalApprovalTable from "./MOHFinalApprovalTable";

const MohForFinalApproval = ({ loadingModalService, facilityService }) => {
const { forecastingPeriodsParams } = useBuqCommonFuncs();
const { geographicZoneParams } = useGeographicZoneGroup();

const [noneSelectedGroup, setNoneSelectedGroup] = useState(false);
const [noneSelectedForecastingPeriod, setNoneSelectedForecastingPeriod] =
useState(false);
const [group, setGroup] = useState();
const [forecastingPeriodId, setForecastingPeriodId] = useState();
const [data, setData] = useState([]);

const buqService = useServerService('buqService');

const { regionData, programId, fetchRegionData } = useCostCalculationRegion(
group,
forecastingPeriodId,
loadingModalService
);

useEffect(() => {
const groupValues = geographicZoneParams[0];
if (group === undefined) {
setGroup(groupValues)
}
}, [geographicZoneParams])

const fetchBuqForFinalApproval = () => {
console.log(programId, forecastingPeriodId, group);

const elo = buqService.forFinalApproval(programId, forecastingPeriodId, group.value).then(function(response) {
console.log(response);

setData(response.content);
});
};

const handleSearchButton = () => {
if (!group) {
setNoneSelectedGroup(true);
}
if (!forecastingPeriodId) {
setNoneSelectedForecastingPeriod(true);
}
if (group && forecastingPeriodId) {
fetchBuqForFinalApproval();
// fetchRegionData();
}
};

return (
<>
<h2 className="bottom-line">Consolidated Summary</h2>
<div className="approve-buq-page-container">
<div className="approve-buq-page-left">
<div className="approve-buq-select-section">
<div className="approve-buq-select">
<p className="is-required">Group</p>
<InputWithSuggestionsAndValidation
data={geographicZoneParams}
defaultValue={geographicZoneParams[0]}
displayValue="name"
placeholder="Select group"
onClick={(value) => {
setGroup(value);
setNoneSelectedGroup(false);
}}
isInvalid={noneSelectedGroup}
displayInformation={true}
/>
</div>
<div className="approve-buq-select">
<p className="is-required">Forecasting period</p>
<InputWithSuggestionsAndValidation
data={forecastingPeriodsParams}
defaultValue={forecastingPeriodsParams.at(-1)}
displayValue="name"
placeholder="Select period"
onClick={(value) => {
setForecastingPeriodId(value);
setNoneSelectedForecastingPeriod(false);
}}
isInvalid={noneSelectedForecastingPeriod}
displayInformation={true}
/>
</div>
</div>
<div className="approve-buq-button">
<button
className="primary"
type="button"
onClick={() => handleSearchButton()}
>
Search
</button>
</div>
</div>
<div className="approve-buq-page-container">
<MOHFinalApprovalTable
data={data}
redirectUrl={`/buq/national-approve/${group?.value}`}
/>
</div>
</div>
{/*<Modal*/}
{/* // isOpen={displayFinalApproveModal}*/}
{/* children={[*/}
{/* <ConfirmModalBody*/}
{/* // onConfirm={handleFinalApproveAction}*/}
{/* confirmMessage={*/}
{/* 'Are you sure you want to approve this forecasting?'*/}
{/* }*/}
{/* // onCancel={() => setDisplayFinalApproveModal(false)}*/}
{/* confirmButtonText={'Approve'}*/}
{/* />,*/}
{/* ]}*/}
{/* sourceOfFundStyle={true}*/}
{/*/>*/}
{/*<ModalErrorMessage*/}
{/* isOpen={displayFinalApproveErrorModal}*/}
{/* customMessage="At least one pending approval needs to be selected"*/}
{/* onClose={() => setDisplayFinalApproveErrorModal(false)}*/}
{/*/>*/}
{/*<ActionBar*/}
{/* onFinalApproveAction={() => setDisplayFinalApproveModal(true)}*/}
{/* finalApproveButton={true}*/}
{/* cancelButton={false}*/}
{/* totalCostInformation={false}*/}
{/* sourceOfFundButton={false}*/}
{/*/>*/}
</>
);
};

export default MohForFinalApproval;

0 comments on commit b6b412c

Please sign in to comment.