Skip to content

Commit

Permalink
CM-838: allow to fetch by payment cycle (#45)
Browse files Browse the repository at this point in the history
Co-authored-by: Jan <[email protected]>
  • Loading branch information
jdolkowski and Jan authored Mar 25, 2024
1 parent e08f8a6 commit d6f3447
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 14 deletions.
25 changes: 18 additions & 7 deletions src/components/payroll/BenefitConsumptionPayrollFilter.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,22 +84,33 @@ function BenefitConsumptionPayrollFilter({ filters, onChangeFilters, benefitPlan
/>
</Grid>
<Grid item xs={2} className={classes.item}>
<NumberInput
<PublishedComponent
pubRef="core.DatePicker"
module="payroll"
label={formatMessage('benefitConsumption.payroll.startDate')}
min={0}
max={12}
value={filterValue('payroll_PaymentCycle_StartDate')}
onChange={onChangeFilter('payroll_PaymentCycle_StartDate')}
onChange={(v) => onChangeFilters([
{
id: 'payroll_PaymentCycle_StartDate',
value: v,
filter: `payroll_PaymentCycle_StartDate: "${v}"`,
},
])}
/>
</Grid>
<Grid item xs={2} className={classes.item}>
<NumberInput
<PublishedComponent
pubRef="core.DatePicker"
module="payroll"
label={formatMessage('benefitConsumption.payroll.endDate')}
min={0}
value={filterValue('payroll_PaymentCycle_EndDate')}
onChange={onChangeFilter('payroll_PaymentCycle_EndDate')}
onChange={(v) => onChangeFilters([
{
id: 'payroll_PaymentCycle_EndDate',
value: v,
filter: `payroll_PaymentCycle_EndDate: "${v}"`,
},
])}
/>
</Grid>
<Grid item xs={2} className={classes.item}>
Expand Down
36 changes: 29 additions & 7 deletions src/components/payroll/BenefitConsumptionPayrollSearcher.js
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -29,9 +29,11 @@ function BenefitConsumptionPayrollSearcher({
individualUuid,
benefitPlan,
groupBeneficiaries,
paymentCycleUuid,
}) {
const modulesManager = useModulesManager();
const { formatMessage, formatMessageWithValues } = useTranslations('payroll', modulesManager);
const [totalNumberOfBenefits, setTotalNumberOfBenefits] = useState(0);

const fetch = (params) => fetchPayrollBenefitConsumptions(modulesManager, params);

Expand Down Expand Up @@ -113,27 +115,47 @@ function BenefitConsumptionPayrollSearcher({
filter: `benefit_Individual_Id: "${individualUuid}"`,
};
}
if (benefitPlan !== null && benefitPlan !== undefined) {
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}"`,
];
if (benefitPlan !== null && benefitPlan !== undefined) {
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);
}
}, [benefitsSummary]);

const benefitConsumptionPayrollFilter = ({ filters, onChangeFilters }) => (
<BenefitConsumptionPayrollFilter
filters={filters}
Expand All @@ -152,7 +174,7 @@ function BenefitConsumptionPayrollSearcher({
{formatMessage('payroll.summary.totalNumberOfBenefits')}
</Typography>
<Typography variant="body1">
{payrollBenefitConsumptionsTotalCount}
{totalNumberOfBenefits}
</Typography>
</Paper>
</Grid>
Expand Down

0 comments on commit d6f3447

Please sign in to comment.