Skip to content

Commit

Permalink
Merge pull request #48 from openimis/develop
Browse files Browse the repository at this point in the history
MERGING develop into release/24.04
  • Loading branch information
delcroip authored Mar 28, 2024
2 parents 6da7aaf + cf231ec commit 397fb65
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 44 deletions.
4 changes: 2 additions & 2 deletions src/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () => [
Expand All @@ -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',
Expand Down
48 changes: 25 additions & 23 deletions src/components/payroll/BenefitConsumptionPayrollFilter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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([
Expand Down Expand Up @@ -80,25 +70,37 @@ function BenefitConsumptionPayrollFilter({ filters, onChangeFilters }) {
label="benefitConsumption.payroll.benefitPlan"
value={filterTextFieldValue('benefitPlanName')}
onChange={onChangeStringFilter('benefitPlanName')}
readOnly={benefitPlan !== null && benefitPlan !== undefined}
/>
</Grid>
<Grid item xs={2} className={classes.item}>
<NumberInput
<PublishedComponent
pubRef="core.DatePicker"
module="payroll"
label={formatMessage('benefitConsumption.payroll.runMonth')}
min={0}
max={12}
value={filterValue('payroll_PaymentCycle_RunMonth')}
onChange={onChangeFilter('payroll_PaymentCycle_RunMonth')}
label={formatMessage('benefitConsumption.payroll.startDate')}
value={filterValue('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.runYear')}
min={0}
value={filterValue('payroll_PaymentCycle_RunYear')}
onChange={onChangeFilter('payroll_PaymentCycle_RunYear')}
label={formatMessage('benefitConsumption.payroll.endDate')}
value={filterValue('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 Expand Up @@ -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')}
/>
</Grid>
<Grid item xs={2} className={classes.item}>
Expand Down
67 changes: 54 additions & 13 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 @@ -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',
Expand All @@ -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,
Expand All @@ -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],
Expand All @@ -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 }) => (
<BenefitConsumptionPayrollFilter filters={filters} onChangeFilters={onChangeFilters} />
<BenefitConsumptionPayrollFilter
filters={filters}
onChangeFilters={onChangeFilters}
benefitPlan={benefitPlan}
/>
);

return (
Expand All @@ -133,7 +174,7 @@ function BenefitConsumptionPayrollSearcher({
{formatMessage('payroll.summary.totalNumberOfBenefits')}
</Typography>
<Typography variant="body1">
{payrollBenefitConsumptionsTotalCount}
{totalNumberOfBenefits}
</Typography>
</Paper>
</Grid>
Expand Down
3 changes: 2 additions & 1 deletion src/components/payroll/PayrollHeadPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -114,6 +114,7 @@ class PayrollHeadPanel extends FormPanel {
onChange={(paymentPlan) => this.updateAttribute('paymentPlan', paymentPlan)}
value={payroll?.paymentPlan}
readOnly={readOnly}
benefitPlanId={benefitPlanId}
/>
</Grid>
<Grid item xs={3} className={classes.item}>
Expand Down
8 changes: 6 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -61,14 +61,18 @@ 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 },
{ path: `${ROUTE_PAYMENT_POINT}/:payment_point_uuid?`, component: PaymentPointPage },
{ 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': [
{
Expand Down
8 changes: 7 additions & 1 deletion src/pages/payroll/PayrollPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ function PayrollPage({
clearConfirm,
createPayrollFromFailedInvoices,
journalize,
benefitPlanId,
}) {
const modulesManager = useModulesManager();
const classes = useStyles();
Expand Down Expand Up @@ -138,6 +139,9 @@ function PayrollPage({
editedPayroll,
formatMessageWithValues('payroll.mutation.create', mutationLabel(payroll)),
);
if (benefitPlanId) {
back();
}
};

const actions = [];
Expand Down Expand Up @@ -169,6 +173,7 @@ function PayrollPage({
payroll={payroll}
readOnly={readOnly}
isPayrollFromFailedInvoices={isPayrollFromFailedInvoices}
benefitPlanId={benefitPlanId}
/>
</div>
)
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 397fb65

Please sign in to comment.