diff --git a/src/actions.js b/src/actions.js index 109bd97..605effd 100644 --- a/src/actions.js +++ b/src/actions.js @@ -46,7 +46,7 @@ const PAYROLL_BENEFIT_CONSUMPTION_PROJECTION = () => [ 'id', // eslint-disable-next-line max-len 'benefit{id,isDeleted,jsonExt,dateCreated,dateUpdated,dateValidFrom,dateValidTo,id,code,individual {firstName, lastName},benefitAttachment {bill {id, code, terms, datePayed}},receipt,photo,amount,type,status,dateDue}', - 'payroll {id, name, status, paymentCycle {runMonth, runYear}, paymentMethod, benefitPlanNameCode}', + 'payroll {id, name, status, paymentCycle {code, startDate, endDate}, paymentMethod, benefitPlanNameCode}', ]; const BENEFIT_CONSUMPTION_SUMMARY_PROJECTION = () => [ @@ -64,7 +64,7 @@ const PAYROLL_PROJECTION = (modulesManager) => [ 'paymentMethod', 'paymentPlan { code, id, name, benefitPlan }', `paymentPoint { ${PAYMENT_POINT_PROJECTION(modulesManager).join(' ')} }`, - 'paymentCycle { runYear, runMonth }', + 'paymentCycle { code, startDate, endDate }', // eslint-disable-next-line max-len 'benefitConsumption{id, status, code, dateDue, receipt, individual {firstName, lastName}, benefitAttachment{bill{id, code, terms, amountTotal}}}', 'jsonExt', diff --git a/src/components/payroll/BenefitConsumptionPayrollFilter.js b/src/components/payroll/BenefitConsumptionPayrollFilter.js index b1de6f0..ee556b7 100644 --- a/src/components/payroll/BenefitConsumptionPayrollFilter.js +++ b/src/components/payroll/BenefitConsumptionPayrollFilter.js @@ -23,7 +23,7 @@ const useStyles = makeStyles((theme) => ({ }, })); -function BenefitConsumptionPayrollFilter({ filters, onChangeFilters }) { +function BenefitConsumptionPayrollFilter({ filters, onChangeFilters, benefitPlan }) { const modulesManager = useModulesManager(); const classes = useStyles(); const { formatMessage } = useTranslations('payroll', modulesManager); @@ -34,16 +34,6 @@ function BenefitConsumptionPayrollFilter({ filters, onChangeFilters }) { const filterValue = (filterName) => filters?.[filterName]?.value ?? null; - const onChangeFilter = (filterName) => (value) => { - debouncedOnChangeFilters([ - { - id: filterName, - value: value || null, - filter: `${filterName}: ${value}`, - }, - ]); - }; - const onChangeStringFilter = (filterName, lookup = null) => (value) => { if (lookup) { debouncedOnChangeFilters([ @@ -80,25 +70,37 @@ function BenefitConsumptionPayrollFilter({ filters, onChangeFilters }) { label="benefitConsumption.payroll.benefitPlan" value={filterTextFieldValue('benefitPlanName')} onChange={onChangeStringFilter('benefitPlanName')} + readOnly={benefitPlan !== null && benefitPlan !== undefined} /> - onChangeFilters([ + { + id: 'payroll_PaymentCycle_StartDate', + value: v, + filter: `payroll_PaymentCycle_StartDate: "${v}"`, + }, + ])} /> - onChangeFilters([ + { + id: 'payroll_PaymentCycle_EndDate', + value: v, + filter: `payroll_PaymentCycle_EndDate: "${v}"`, + }, + ])} /> @@ -154,7 +156,7 @@ function BenefitConsumptionPayrollFilter({ filters, onChangeFilters }) { label={formatMessage('benefitConsumption.amount')} min={0} value={filterValue('benefit_Amount')} - onChange={onChangeFilter('benefit_Amount')} + onChange={onChangeStringFilter('benefit_Amount')} /> diff --git a/src/components/payroll/BenefitConsumptionPayrollSearcher.js b/src/components/payroll/BenefitConsumptionPayrollSearcher.js index 4684538..c951f75 100644 --- a/src/components/payroll/BenefitConsumptionPayrollSearcher.js +++ b/src/components/payroll/BenefitConsumptionPayrollSearcher.js @@ -1,5 +1,5 @@ /* eslint-disable no-param-reassign */ -import React, { useEffect } from 'react'; +import React, { useEffect, useState } from 'react'; import { bindActionCreators } from 'redux'; import { connect } from 'react-redux'; @@ -27,17 +27,21 @@ function BenefitConsumptionPayrollSearcher({ fetchedBenefitsSummary, benefitsSummary, individualUuid, + benefitPlan, + groupBeneficiaries, + paymentCycleUuid, }) { const modulesManager = useModulesManager(); const { formatMessage, formatMessageWithValues } = useTranslations('payroll', modulesManager); + const [totalNumberOfBenefits, setTotalNumberOfBenefits] = useState(0); const fetch = (params) => fetchPayrollBenefitConsumptions(modulesManager, params); const headers = () => [ 'benefitConsumption.payroll.name', 'benefitConsumption.payroll.benefitPlan', - 'benefitConsumption.payroll.runMonth', - 'benefitConsumption.payroll.runYear', + 'benefitConsumption.payroll.startDate', + 'benefitConsumption.payroll.endDate', 'benefitConsumption.status', 'benefitConsumption.code', 'benefitConsumption.receipt', @@ -64,8 +68,8 @@ function BenefitConsumptionPayrollSearcher({ (payrollBenefitConsumption) => payrollBenefitConsumption?.payroll?.name, (payrollBenefitConsumption) => payrollBenefitConsumption?.payroll?.benefitPlanNameCode, // eslint-disable-next-line max-len - (payrollBenefitConsumption) => payrollBenefitConsumption?.payroll?.paymentCycle?.runMonth, - (payrollBenefitConsumption) => payrollBenefitConsumption?.payroll?.paymentCycle?.runYear, + (payrollBenefitConsumption) => payrollBenefitConsumption?.payroll?.paymentCycle?.startDate, + (payrollBenefitConsumption) => payrollBenefitConsumption?.payroll?.paymentCycle?.endDate, (payrollBenefitConsumption) => payrollBenefitConsumption?.benefit?.status, (payrollBenefitConsumption) => payrollBenefitConsumption?.benefit?.code, (payrollBenefitConsumption) => payrollBenefitConsumption?.benefit?.receipt, @@ -85,8 +89,8 @@ function BenefitConsumptionPayrollSearcher({ const sorts = () => [ ['payroll_Name', true], ['payroll_benefitPlanName', false], - ['payroll_PaymentCycle_RunMonth', true], - ['payroll_PaymentCycle_RunYear', true], + ['payroll_PaymentCycle_StartDate', true], + ['payroll_PaymentCycle_EndDate', true], ['benefit_Status', true], ['benefit_Code', true], ['benefit_Receipt', true], @@ -103,24 +107,61 @@ function BenefitConsumptionPayrollSearcher({ 'isDeleted: false', }, }; - if (individualUuid !== null && individualUuid !== undefined) { + if (groupBeneficiaries !== null && groupBeneficiaries !== undefined) { + // TO-DO fetching benefits for group once enrollment of group flow will be developed + } else if (individualUuid !== null && individualUuid !== undefined) { filters.benefit_Individual_Id = { value: individualUuid, filter: `benefit_Individual_Id: "${individualUuid}"`, }; } + if (benefitPlan?.id) { + filters.benefitPlanUuid = { + value: benefitPlan.id, + filter: `benefitPlanUuid: "${benefitPlan.id}"`, + }; + } + if (paymentCycleUuid) { + filters.paymentCycleUuid = { + value: paymentCycleUuid, + filter: `paymentCycleUuid: "${paymentCycleUuid}"`, + }; + } return filters; }; useEffect(() => { - const params = [ - `individualId: "${individualUuid}"`, - ]; + const params = []; + if (individualUuid) { + params.push( + `individualId: "${individualUuid}"`, + ); + } + if (benefitPlan?.id) { + params.push( + `benefitPlanUuid: "${benefitPlan.id}"`, + ); + } + if (paymentCycleUuid) { + params.push( + `paymentCycleUuid: "${paymentCycleUuid}"`, + ); + } fetchBenefitsSummary(params); }, []); + useEffect(() => { + if (payrollBenefitConsumptionsTotalCount > totalNumberOfBenefits) { + setTotalNumberOfBenefits(payrollBenefitConsumptionsTotalCount); + } + }, [payrollBenefitConsumptionsTotalCount]); + const benefitConsumptionPayrollFilter = ({ filters, onChangeFilters }) => ( - + ); return ( @@ -133,7 +174,7 @@ function BenefitConsumptionPayrollSearcher({ {formatMessage('payroll.summary.totalNumberOfBenefits')} - {payrollBenefitConsumptionsTotalCount} + {totalNumberOfBenefits} diff --git a/src/components/payroll/PayrollHeadPanel.js b/src/components/payroll/PayrollHeadPanel.js index 061bafe..2a5cda9 100644 --- a/src/components/payroll/PayrollHeadPanel.js +++ b/src/components/payroll/PayrollHeadPanel.js @@ -71,7 +71,7 @@ class PayrollHeadPanel extends FormPanel { render() { const { - edited, classes, intl, readOnly, isPayrollFromFailedInvoices, + edited, classes, intl, readOnly, isPayrollFromFailedInvoices, benefitPlanId, } = this.props; const payroll = { ...edited }; const { appliedCustomFilters, appliedFiltersRowStructure } = this.state; @@ -114,6 +114,7 @@ class PayrollHeadPanel extends FormPanel { onChange={(paymentPlan) => this.updateAttribute('paymentPlan', paymentPlan)} value={payroll?.paymentPlan} readOnly={readOnly} + benefitPlanId={benefitPlanId} /> diff --git a/src/index.js b/src/index.js index 36a1a50..c01fed7 100644 --- a/src/index.js +++ b/src/index.js @@ -7,7 +7,7 @@ import { PinDrop } from '@material-ui/icons'; import MonetizationOnIcon from '@material-ui/icons/MonetizationOn'; import { FormattedMessage } from '@openimis/fe-core'; -import { RIGHT_PAYMENT_POINT_SEARCH, RIGHT_PAYROLL_SEARCH } from './constants'; +import { RIGHT_PAYMENT_POINT_SEARCH, RIGHT_PAYROLL_CREATE, RIGHT_PAYROLL_SEARCH } from './constants'; import reducer from './reducer'; import messages_en from './translations/en.json'; import PaymentPointPage from './pages/payment-point/PaymentPointPage'; @@ -61,6 +61,7 @@ const DEFAULT_CONFIG = { { key: 'payroll.PaymentPointPicker', ref: PaymentPointPicker }, { key: 'payroll.PaymentPointPicker.projection', ref: ['id', 'name', 'location'] }, { key: 'payroll.benefitConsumptionPayrollSearcher', ref: BenefitConsumptionPayrollSearcher }, + { key: 'payroll.payrollCreateRight', ref: RIGHT_PAYROLL_CREATE }, ], 'core.Router': [ { path: ROUTE_PAYMENT_POINTS, component: PaymentPointsPage }, @@ -68,7 +69,10 @@ const DEFAULT_CONFIG = { { path: ROUTE_PAYROLLS, component: PayrollsPage }, { path: ROUTE_PAYROLLS_APPROVED, component: ApprovedPayrollsPage }, { path: ROUTE_PAYROLLS_RECONCILED, component: ReconciledPayrollsPage }, - { path: `${ROUTE_PAYROLL}/:payroll_uuid?/:createPayrollFromFailedInvoices?`, component: PayrollPage }, + { + path: `${ROUTE_PAYROLL}/:payroll_uuid?/:createPayrollFromFailedInvoices?/:benefitPlanId?`, + component: PayrollPage, + }, ], 'invoice.MainMenu': [ { diff --git a/src/pages/payroll/PayrollPage.js b/src/pages/payroll/PayrollPage.js index 4babd2b..08e6beb 100644 --- a/src/pages/payroll/PayrollPage.js +++ b/src/pages/payroll/PayrollPage.js @@ -45,6 +45,7 @@ function PayrollPage({ clearConfirm, createPayrollFromFailedInvoices, journalize, + benefitPlanId, }) { const modulesManager = useModulesManager(); const classes = useStyles(); @@ -138,6 +139,9 @@ function PayrollPage({ editedPayroll, formatMessageWithValues('payroll.mutation.create', mutationLabel(payroll)), ); + if (benefitPlanId) { + back(); + } }; const actions = []; @@ -169,6 +173,7 @@ function PayrollPage({ payroll={payroll} readOnly={readOnly} isPayrollFromFailedInvoices={isPayrollFromFailedInvoices} + benefitPlanId={benefitPlanId} /> ) @@ -185,8 +190,9 @@ const mapDispatchToProps = (dispatch) => bindActionCreators({ }, dispatch); const mapStateToProps = (state, props) => ({ - statePayrollUuid: props?.match?.params.payroll_uuid, + statePayrollUuid: props?.match?.params?.payroll_uuid === 'null' ? null : props?.match?.params.payroll_uuid, createPayrollFromFailedInvoices: props?.match?.params?.createPayrollFromFailedInvoices, + benefitPlanId: props?.match?.params?.benefitPlanId, rights: state.core?.user?.i_user?.rights ?? [], confirmed: state.core.confirmed, submittingMutation: state.payroll.submittingMutation, diff --git a/src/translations/en.json b/src/translations/en.json index 8508c65..32e93a9 100644 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -57,8 +57,8 @@ "payroll.benefitConsumption.status.CANCELLED": "Cancelled", "payroll.benefitConsumption.status.DELETED": "Deleted", "payroll.benefitConsumption.status.SUSPENDED": "Suspended", - "payroll.benefitConsumption.payroll.runYear": "Accounting Year", - "payroll.benefitConsumption.payroll.runMonth": "Accounting Month", + "payroll.benefitConsumption.payroll.startDate": "Accounting Start Date", + "payroll.benefitConsumption.payroll.endDate": "Accounting End Date", "payroll.benefitConsumption.payroll.name": "Payroll Name", "payroll.benefitConsumption.payroll.benefitPlan": "Benefit Plan", "payroll.benefitConsumption.payroll.benefitPlanName": "Benefit Plan",