Skip to content

Commit 397fb65

Browse files
authored
Merge pull request #48 from openimis/develop
MERGING develop into release/24.04
2 parents 6da7aaf + cf231ec commit 397fb65

File tree

7 files changed

+98
-44
lines changed

7 files changed

+98
-44
lines changed

src/actions.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ const PAYROLL_BENEFIT_CONSUMPTION_PROJECTION = () => [
4646
'id',
4747
// eslint-disable-next-line max-len
4848
'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}',
49-
'payroll {id, name, status, paymentCycle {runMonth, runYear}, paymentMethod, benefitPlanNameCode}',
49+
'payroll {id, name, status, paymentCycle {code, startDate, endDate}, paymentMethod, benefitPlanNameCode}',
5050
];
5151

5252
const BENEFIT_CONSUMPTION_SUMMARY_PROJECTION = () => [
@@ -64,7 +64,7 @@ const PAYROLL_PROJECTION = (modulesManager) => [
6464
'paymentMethod',
6565
'paymentPlan { code, id, name, benefitPlan }',
6666
`paymentPoint { ${PAYMENT_POINT_PROJECTION(modulesManager).join(' ')} }`,
67-
'paymentCycle { runYear, runMonth }',
67+
'paymentCycle { code, startDate, endDate }',
6868
// eslint-disable-next-line max-len
6969
'benefitConsumption{id, status, code, dateDue, receipt, individual {firstName, lastName}, benefitAttachment{bill{id, code, terms, amountTotal}}}',
7070
'jsonExt',

src/components/payroll/BenefitConsumptionPayrollFilter.js

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const useStyles = makeStyles((theme) => ({
2323
},
2424
}));
2525

26-
function BenefitConsumptionPayrollFilter({ filters, onChangeFilters }) {
26+
function BenefitConsumptionPayrollFilter({ filters, onChangeFilters, benefitPlan }) {
2727
const modulesManager = useModulesManager();
2828
const classes = useStyles();
2929
const { formatMessage } = useTranslations('payroll', modulesManager);
@@ -34,16 +34,6 @@ function BenefitConsumptionPayrollFilter({ filters, onChangeFilters }) {
3434

3535
const filterValue = (filterName) => filters?.[filterName]?.value ?? null;
3636

37-
const onChangeFilter = (filterName) => (value) => {
38-
debouncedOnChangeFilters([
39-
{
40-
id: filterName,
41-
value: value || null,
42-
filter: `${filterName}: ${value}`,
43-
},
44-
]);
45-
};
46-
4737
const onChangeStringFilter = (filterName, lookup = null) => (value) => {
4838
if (lookup) {
4939
debouncedOnChangeFilters([
@@ -80,25 +70,37 @@ function BenefitConsumptionPayrollFilter({ filters, onChangeFilters }) {
8070
label="benefitConsumption.payroll.benefitPlan"
8171
value={filterTextFieldValue('benefitPlanName')}
8272
onChange={onChangeStringFilter('benefitPlanName')}
73+
readOnly={benefitPlan !== null && benefitPlan !== undefined}
8374
/>
8475
</Grid>
8576
<Grid item xs={2} className={classes.item}>
86-
<NumberInput
77+
<PublishedComponent
78+
pubRef="core.DatePicker"
8779
module="payroll"
88-
label={formatMessage('benefitConsumption.payroll.runMonth')}
89-
min={0}
90-
max={12}
91-
value={filterValue('payroll_PaymentCycle_RunMonth')}
92-
onChange={onChangeFilter('payroll_PaymentCycle_RunMonth')}
80+
label={formatMessage('benefitConsumption.payroll.startDate')}
81+
value={filterValue('payroll_PaymentCycle_StartDate')}
82+
onChange={(v) => onChangeFilters([
83+
{
84+
id: 'payroll_PaymentCycle_StartDate',
85+
value: v,
86+
filter: `payroll_PaymentCycle_StartDate: "${v}"`,
87+
},
88+
])}
9389
/>
9490
</Grid>
9591
<Grid item xs={2} className={classes.item}>
96-
<NumberInput
92+
<PublishedComponent
93+
pubRef="core.DatePicker"
9794
module="payroll"
98-
label={formatMessage('benefitConsumption.payroll.runYear')}
99-
min={0}
100-
value={filterValue('payroll_PaymentCycle_RunYear')}
101-
onChange={onChangeFilter('payroll_PaymentCycle_RunYear')}
95+
label={formatMessage('benefitConsumption.payroll.endDate')}
96+
value={filterValue('payroll_PaymentCycle_EndDate')}
97+
onChange={(v) => onChangeFilters([
98+
{
99+
id: 'payroll_PaymentCycle_EndDate',
100+
value: v,
101+
filter: `payroll_PaymentCycle_EndDate: "${v}"`,
102+
},
103+
])}
102104
/>
103105
</Grid>
104106
<Grid item xs={2} className={classes.item}>
@@ -154,7 +156,7 @@ function BenefitConsumptionPayrollFilter({ filters, onChangeFilters }) {
154156
label={formatMessage('benefitConsumption.amount')}
155157
min={0}
156158
value={filterValue('benefit_Amount')}
157-
onChange={onChangeFilter('benefit_Amount')}
159+
onChange={onChangeStringFilter('benefit_Amount')}
158160
/>
159161
</Grid>
160162
<Grid item xs={2} className={classes.item}>

src/components/payroll/BenefitConsumptionPayrollSearcher.js

Lines changed: 54 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable no-param-reassign */
2-
import React, { useEffect } from 'react';
2+
import React, { useEffect, useState } from 'react';
33
import { bindActionCreators } from 'redux';
44
import { connect } from 'react-redux';
55

@@ -27,17 +27,21 @@ function BenefitConsumptionPayrollSearcher({
2727
fetchedBenefitsSummary,
2828
benefitsSummary,
2929
individualUuid,
30+
benefitPlan,
31+
groupBeneficiaries,
32+
paymentCycleUuid,
3033
}) {
3134
const modulesManager = useModulesManager();
3235
const { formatMessage, formatMessageWithValues } = useTranslations('payroll', modulesManager);
36+
const [totalNumberOfBenefits, setTotalNumberOfBenefits] = useState(0);
3337

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

3640
const headers = () => [
3741
'benefitConsumption.payroll.name',
3842
'benefitConsumption.payroll.benefitPlan',
39-
'benefitConsumption.payroll.runMonth',
40-
'benefitConsumption.payroll.runYear',
43+
'benefitConsumption.payroll.startDate',
44+
'benefitConsumption.payroll.endDate',
4145
'benefitConsumption.status',
4246
'benefitConsumption.code',
4347
'benefitConsumption.receipt',
@@ -64,8 +68,8 @@ function BenefitConsumptionPayrollSearcher({
6468
(payrollBenefitConsumption) => payrollBenefitConsumption?.payroll?.name,
6569
(payrollBenefitConsumption) => payrollBenefitConsumption?.payroll?.benefitPlanNameCode,
6670
// eslint-disable-next-line max-len
67-
(payrollBenefitConsumption) => payrollBenefitConsumption?.payroll?.paymentCycle?.runMonth,
68-
(payrollBenefitConsumption) => payrollBenefitConsumption?.payroll?.paymentCycle?.runYear,
71+
(payrollBenefitConsumption) => payrollBenefitConsumption?.payroll?.paymentCycle?.startDate,
72+
(payrollBenefitConsumption) => payrollBenefitConsumption?.payroll?.paymentCycle?.endDate,
6973
(payrollBenefitConsumption) => payrollBenefitConsumption?.benefit?.status,
7074
(payrollBenefitConsumption) => payrollBenefitConsumption?.benefit?.code,
7175
(payrollBenefitConsumption) => payrollBenefitConsumption?.benefit?.receipt,
@@ -85,8 +89,8 @@ function BenefitConsumptionPayrollSearcher({
8589
const sorts = () => [
8690
['payroll_Name', true],
8791
['payroll_benefitPlanName', false],
88-
['payroll_PaymentCycle_RunMonth', true],
89-
['payroll_PaymentCycle_RunYear', true],
92+
['payroll_PaymentCycle_StartDate', true],
93+
['payroll_PaymentCycle_EndDate', true],
9094
['benefit_Status', true],
9195
['benefit_Code', true],
9296
['benefit_Receipt', true],
@@ -103,24 +107,61 @@ function BenefitConsumptionPayrollSearcher({
103107
'isDeleted: false',
104108
},
105109
};
106-
if (individualUuid !== null && individualUuid !== undefined) {
110+
if (groupBeneficiaries !== null && groupBeneficiaries !== undefined) {
111+
// TO-DO fetching benefits for group once enrollment of group flow will be developed
112+
} else if (individualUuid !== null && individualUuid !== undefined) {
107113
filters.benefit_Individual_Id = {
108114
value: individualUuid,
109115
filter: `benefit_Individual_Id: "${individualUuid}"`,
110116
};
111117
}
118+
if (benefitPlan?.id) {
119+
filters.benefitPlanUuid = {
120+
value: benefitPlan.id,
121+
filter: `benefitPlanUuid: "${benefitPlan.id}"`,
122+
};
123+
}
124+
if (paymentCycleUuid) {
125+
filters.paymentCycleUuid = {
126+
value: paymentCycleUuid,
127+
filter: `paymentCycleUuid: "${paymentCycleUuid}"`,
128+
};
129+
}
112130
return filters;
113131
};
114132

115133
useEffect(() => {
116-
const params = [
117-
`individualId: "${individualUuid}"`,
118-
];
134+
const params = [];
135+
if (individualUuid) {
136+
params.push(
137+
`individualId: "${individualUuid}"`,
138+
);
139+
}
140+
if (benefitPlan?.id) {
141+
params.push(
142+
`benefitPlanUuid: "${benefitPlan.id}"`,
143+
);
144+
}
145+
if (paymentCycleUuid) {
146+
params.push(
147+
`paymentCycleUuid: "${paymentCycleUuid}"`,
148+
);
149+
}
119150
fetchBenefitsSummary(params);
120151
}, []);
121152

153+
useEffect(() => {
154+
if (payrollBenefitConsumptionsTotalCount > totalNumberOfBenefits) {
155+
setTotalNumberOfBenefits(payrollBenefitConsumptionsTotalCount);
156+
}
157+
}, [payrollBenefitConsumptionsTotalCount]);
158+
122159
const benefitConsumptionPayrollFilter = ({ filters, onChangeFilters }) => (
123-
<BenefitConsumptionPayrollFilter filters={filters} onChangeFilters={onChangeFilters} />
160+
<BenefitConsumptionPayrollFilter
161+
filters={filters}
162+
onChangeFilters={onChangeFilters}
163+
benefitPlan={benefitPlan}
164+
/>
124165
);
125166

126167
return (
@@ -133,7 +174,7 @@ function BenefitConsumptionPayrollSearcher({
133174
{formatMessage('payroll.summary.totalNumberOfBenefits')}
134175
</Typography>
135176
<Typography variant="body1">
136-
{payrollBenefitConsumptionsTotalCount}
177+
{totalNumberOfBenefits}
137178
</Typography>
138179
</Paper>
139180
</Grid>

src/components/payroll/PayrollHeadPanel.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class PayrollHeadPanel extends FormPanel {
7171

7272
render() {
7373
const {
74-
edited, classes, intl, readOnly, isPayrollFromFailedInvoices,
74+
edited, classes, intl, readOnly, isPayrollFromFailedInvoices, benefitPlanId,
7575
} = this.props;
7676
const payroll = { ...edited };
7777
const { appliedCustomFilters, appliedFiltersRowStructure } = this.state;
@@ -114,6 +114,7 @@ class PayrollHeadPanel extends FormPanel {
114114
onChange={(paymentPlan) => this.updateAttribute('paymentPlan', paymentPlan)}
115115
value={payroll?.paymentPlan}
116116
readOnly={readOnly}
117+
benefitPlanId={benefitPlanId}
117118
/>
118119
</Grid>
119120
<Grid item xs={3} className={classes.item}>

src/index.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { PinDrop } from '@material-ui/icons';
77
import MonetizationOnIcon from '@material-ui/icons/MonetizationOn';
88

99
import { FormattedMessage } from '@openimis/fe-core';
10-
import { RIGHT_PAYMENT_POINT_SEARCH, RIGHT_PAYROLL_SEARCH } from './constants';
10+
import { RIGHT_PAYMENT_POINT_SEARCH, RIGHT_PAYROLL_CREATE, RIGHT_PAYROLL_SEARCH } from './constants';
1111
import reducer from './reducer';
1212
import messages_en from './translations/en.json';
1313
import PaymentPointPage from './pages/payment-point/PaymentPointPage';
@@ -61,14 +61,18 @@ const DEFAULT_CONFIG = {
6161
{ key: 'payroll.PaymentPointPicker', ref: PaymentPointPicker },
6262
{ key: 'payroll.PaymentPointPicker.projection', ref: ['id', 'name', 'location'] },
6363
{ key: 'payroll.benefitConsumptionPayrollSearcher', ref: BenefitConsumptionPayrollSearcher },
64+
{ key: 'payroll.payrollCreateRight', ref: RIGHT_PAYROLL_CREATE },
6465
],
6566
'core.Router': [
6667
{ path: ROUTE_PAYMENT_POINTS, component: PaymentPointsPage },
6768
{ path: `${ROUTE_PAYMENT_POINT}/:payment_point_uuid?`, component: PaymentPointPage },
6869
{ path: ROUTE_PAYROLLS, component: PayrollsPage },
6970
{ path: ROUTE_PAYROLLS_APPROVED, component: ApprovedPayrollsPage },
7071
{ path: ROUTE_PAYROLLS_RECONCILED, component: ReconciledPayrollsPage },
71-
{ path: `${ROUTE_PAYROLL}/:payroll_uuid?/:createPayrollFromFailedInvoices?`, component: PayrollPage },
72+
{
73+
path: `${ROUTE_PAYROLL}/:payroll_uuid?/:createPayrollFromFailedInvoices?/:benefitPlanId?`,
74+
component: PayrollPage,
75+
},
7276
],
7377
'invoice.MainMenu': [
7478
{

src/pages/payroll/PayrollPage.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ function PayrollPage({
4545
clearConfirm,
4646
createPayrollFromFailedInvoices,
4747
journalize,
48+
benefitPlanId,
4849
}) {
4950
const modulesManager = useModulesManager();
5051
const classes = useStyles();
@@ -138,6 +139,9 @@ function PayrollPage({
138139
editedPayroll,
139140
formatMessageWithValues('payroll.mutation.create', mutationLabel(payroll)),
140141
);
142+
if (benefitPlanId) {
143+
back();
144+
}
141145
};
142146

143147
const actions = [];
@@ -169,6 +173,7 @@ function PayrollPage({
169173
payroll={payroll}
170174
readOnly={readOnly}
171175
isPayrollFromFailedInvoices={isPayrollFromFailedInvoices}
176+
benefitPlanId={benefitPlanId}
172177
/>
173178
</div>
174179
)
@@ -185,8 +190,9 @@ const mapDispatchToProps = (dispatch) => bindActionCreators({
185190
}, dispatch);
186191

187192
const mapStateToProps = (state, props) => ({
188-
statePayrollUuid: props?.match?.params.payroll_uuid,
193+
statePayrollUuid: props?.match?.params?.payroll_uuid === 'null' ? null : props?.match?.params.payroll_uuid,
189194
createPayrollFromFailedInvoices: props?.match?.params?.createPayrollFromFailedInvoices,
195+
benefitPlanId: props?.match?.params?.benefitPlanId,
190196
rights: state.core?.user?.i_user?.rights ?? [],
191197
confirmed: state.core.confirmed,
192198
submittingMutation: state.payroll.submittingMutation,

src/translations/en.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@
5757
"payroll.benefitConsumption.status.CANCELLED": "Cancelled",
5858
"payroll.benefitConsumption.status.DELETED": "Deleted",
5959
"payroll.benefitConsumption.status.SUSPENDED": "Suspended",
60-
"payroll.benefitConsumption.payroll.runYear": "Accounting Year",
61-
"payroll.benefitConsumption.payroll.runMonth": "Accounting Month",
60+
"payroll.benefitConsumption.payroll.startDate": "Accounting Start Date",
61+
"payroll.benefitConsumption.payroll.endDate": "Accounting End Date",
6262
"payroll.benefitConsumption.payroll.name": "Payroll Name",
6363
"payroll.benefitConsumption.payroll.benefitPlan": "Benefit Plan",
6464
"payroll.benefitConsumption.payroll.benefitPlanName": "Benefit Plan",

0 commit comments

Comments
 (0)