Skip to content

Commit

Permalink
Merge pull request #82 from openimis/release/24.04
Browse files Browse the repository at this point in the history
MERGING release/24.04 into main
  • Loading branch information
delcroip authored Jun 26, 2024
2 parents 952f8f7 + b417f67 commit 1a6cb1c
Show file tree
Hide file tree
Showing 9 changed files with 218 additions and 146 deletions.
2 changes: 1 addition & 1 deletion src/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const PAYMENTPLAN_FULL_PROJECTION = (modulesManager) => [
"isDeleted",
];

const PAYMENTPLAN_PICKER_PROJECTION = () => ["id", "code", "name"];
const PAYMENTPLAN_PICKER_PROJECTION = () => ["id", "code", "name", "benefitPlan"];

function dateTimeToDate(date) {
return date.split("T")[0];
Expand Down
22 changes: 18 additions & 4 deletions src/components/PaymentPlanForm.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { Component, Fragment } from "react";
import React, { Component } from "react";
import {
Form,
withModulesManager,
Expand All @@ -22,6 +22,7 @@ const styles = theme => ({
paperHeader: theme.paper.header,
paperHeaderAction: theme.paper.action,
item: theme.paper.item,
lockedPage: theme.page.locked,
});

class PaymentPlanForm extends Component {
Expand All @@ -31,6 +32,7 @@ class PaymentPlanForm extends Component {
paymentPlan: {},
jsonExtValid: true,
requiredValid: false,
clientMutationId: null,
};
}

Expand All @@ -48,6 +50,9 @@ class PaymentPlanForm extends Component {
}
if (prevProps.submittingMutation && !this.props.submittingMutation) {
this.props.journalize(this.props.mutation);
this.setState((state, props) => ({
clientMutationId: props.mutation.clientMutationId,
}));
}
}

Expand Down Expand Up @@ -96,9 +101,17 @@ class PaymentPlanForm extends Component {
setRequiredValid = (valid) => this.setState({ requiredValid: !!valid });

render() {
const { intl, back, paymentPlanId, title, save, isReplacing = false } = this.props;
const {
intl,
back,
paymentPlanId,
save,
isReplacing = false,
classes,
} = this.props;
const shouldBeLocked = Boolean(this.state.clientMutationId);
return (
<Fragment>
<div className={shouldBeLocked ? classes.lockedPage : null}>
<Helmet title={formatMessageWithValues(this.props.intl, "paymentPlan", "paymentPlan.page.title", this.titleParams())} />
<Form
module="paymentPlan"
Expand All @@ -117,8 +130,9 @@ class PaymentPlanForm extends Component {
paymentPlanId={paymentPlanId}
isReplacing={isReplacing}
openDirty={save}
readOnly={shouldBeLocked}
/>
</Fragment>
</div>
)
}
}
Expand Down
134 changes: 99 additions & 35 deletions src/components/PaymentPlanHeadPanel.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { Fragment } from "react";
import { Grid, Divider, Typography } from "@material-ui/core";
import { Grid, Divider, Typography, Button } from "@material-ui/core";
import {
withModulesManager,
formatMessage,
Expand Down Expand Up @@ -130,6 +130,7 @@ class PaymentPlanHeadPanel extends FormPanel {
isCodeValid,
isCodeValidating,
validationError,
readOnly = false,
}
= this.props;
const { benefitPlan: productOrBenefitPlan, calculation: calculationId, ...others } = this.props.edited;
Expand All @@ -138,11 +139,17 @@ class PaymentPlanHeadPanel extends FormPanel {
const paymentPlanType = paymentPlan?.benefitPlanTypeName;
const { appliedCustomFilters, appliedFiltersRowStructure } = this.state;

const isBenefitPlanType = () => paymentPlanType.replace(/\s+/g, '') === PAYMENT_PLAN_TYPE.BENEFIT_PLAN;

if (paymentPlanType) {
// probably could get rid of that if we use double JSON.parse in reducer
const objectBenefitPlan = typeof paymentPlan.productOrBenefitPlan === 'object' ?
paymentPlan.productOrBenefitPlan : JSON.parse(paymentPlan.productOrBenefitPlan || '{}');
paymentPlan.benefitPlan = objectBenefitPlan;
if (paymentPlanType === 'benefitplan' || paymentPlanType === 'benefit plan') {
paymentPlan.periodicity = 1;
this.state.data.periodicity = paymentPlan.periodicity;
}
return (
<Fragment>
<Grid container className={classes.tableTitle}>
Expand All @@ -161,20 +168,6 @@ class PaymentPlanHeadPanel extends FormPanel {
id="paymentPlan.headPanel.title"
/>
</Typography>
{paymentPlanType.replace(/\s+/g, '') === PAYMENT_PLAN_TYPE.BENEFIT_PLAN && (
<AdvancedCriteriaDialog
object={paymentPlan.benefitPlan}
objectToSave={paymentPlan}
moduleName="social_protection"
objectType="BenefitPlan"
setAppliedCustomFilters={this.setAppliedCustomFilters}
appliedCustomFilters={appliedCustomFilters}
appliedFiltersRowStructure={appliedFiltersRowStructure}
setAppliedFiltersRowStructure={this.setAppliedFiltersRowStructure}
updateAttributes={this.updateJsonExt}
getDefaultAppliedCustomFilters={this.getDefaultAppliedCustomFilters}
/>
)}
</Grid>
</Grid>
</Grid>
Expand All @@ -188,12 +181,35 @@ class PaymentPlanHeadPanel extends FormPanel {
<Divider />
</Fragment>
)}
{paymentPlan.id && (
<Button
onClick={() => {
const currentDateObject = new Date();
const currentDate = currentDateObject.toISOString();
paymentPlan.dateValidTo = currentDate;
this.updateAttribute("dateValidTo", currentDate);
}}
variant="outlined"
color="#DFEDEF"
className={classes.button}
disabled={readOnly}
style={{
border: "0px",
textAlign: "right",
display: "block",
marginLeft: "auto",
marginRight: 0
}}
>
{formatMessage(intl, "paymentPlan", "paymentPlan.deactivatePaymentPlan")}
</Button>
)}
<Grid container className={classes.item}>
<Grid item xs={GRID_ITEM_SIZE} className={classes.item}>
<PaymentPlanTypePicker
module="contributionPlan"
label="type"
readOnly={!!paymentPlan.id}
readOnly={!!paymentPlan.id || readOnly}
withNull={false}
required
value={paymentPlan?.benefitPlanTypeName?.replace(/\s+/g, '') ?? ''}
Expand All @@ -207,7 +223,7 @@ class PaymentPlanHeadPanel extends FormPanel {
label="code"
required={true}
value={!!paymentPlan.code ? paymentPlan.code : ""}
readOnly={!!paymentPlan.id}
readOnly={!!paymentPlan.id || readOnly}
itemQueryIdentifier="paymentPlanCode"
codeTakenLabel="paymentPlan.codeTaken"
shouldValidate={this.shouldValidate}
Expand All @@ -225,6 +241,7 @@ class PaymentPlanHeadPanel extends FormPanel {
<TextInput
module="contributionPlan"
label="name"
readOnly={readOnly}
required
value={!!paymentPlan.name ? paymentPlan.name : ""}
onChange={(v) => this.updateAttribute("name", v)}
Expand All @@ -237,6 +254,7 @@ class PaymentPlanHeadPanel extends FormPanel {
value={!!calculationId ? calculationId : null}
onChange={this.updateAttribute}
context={paymentPlanType}
readOnly={readOnly}
required
/>
</Grid>
Expand All @@ -246,30 +264,35 @@ class PaymentPlanHeadPanel extends FormPanel {
? "product.ProductPicker"
: "socialProtection.BenefitPlanPicker"}
withNull={true}
readOnly={readOnly}
label={formatMessage(intl, "paymentPlan", "benefitPlan")}
required
value={paymentPlan.benefitPlan !== undefined && paymentPlan.benefitPlan !== null ? (isEmptyObject(paymentPlan.benefitPlan) ? null : paymentPlan.benefitPlan) : null}
onChange={(v) => this.updateAttribute("benefitPlan", v)}
/>
</Grid>
<Grid item xs={GRID_ITEM_SIZE} className={classes.item}>
<NumberInput
module="contributionPlan"
label="periodicity"
required
/**
* @see min set to @see EMPTY_PERIODICITY_FILTER when filter unset to avoid @see NumberInput error message
*/
min={!!paymentPlan.periodicity ? MIN_PERIODICITY_VALUE : EMPTY_PERIODICITY_VALUE}
max={MAX_PERIODICITY_VALUE}
value={!!paymentPlan.periodicity ? paymentPlan.periodicity : null}
onChange={(v) => this.updateAttribute("periodicity", v)}
/>
</Grid>
{paymentPlanType !== 'benefitplan' && paymentPlanType !== 'benefit plan' && (
<Grid item xs={GRID_ITEM_SIZE} className={classes.item}>
<NumberInput
module="contributionPlan"
readOnly={readOnly}
label="periodicity"
required
/**
* @see min set to @see EMPTY_PERIODICITY_FILTER when filter unset to avoid @see NumberInput error message
*/
min={!!paymentPlan.periodicity ? MIN_PERIODICITY_VALUE : EMPTY_PERIODICITY_VALUE}
max={MAX_PERIODICITY_VALUE}
value={!!paymentPlan.periodicity ? paymentPlan.periodicity : null}
onChange={(v) => this.updateAttribute("periodicity", v)}
/>
</Grid>
)}
<Grid item xs={GRID_ITEM_SIZE} className={classes.item}>
<PublishedComponent
pubRef="core.DatePicker"
module="contributionPlan"
readOnly={readOnly}
label="dateValidFrom"
required
value={!!paymentPlan.dateValidFrom ? paymentPlan.dateValidFrom : null}
Expand All @@ -280,24 +303,30 @@ class PaymentPlanHeadPanel extends FormPanel {
<PublishedComponent
pubRef="core.DatePicker"
module="contributionPlan"
readOnly={readOnly}
label="dateValidTo"
value={!!paymentPlan.dateValidTo ? paymentPlan.dateValidTo : null}
onChange={(v) => this.updateAttribute("dateValidTo", v)}
/>
</Grid>
</Grid>
<Divider />
<Fragment>
<div className={classes.item}>
<FormattedMessage module="contributionPlan" id="calculationParams" />
</div>
<Typography>
<div className={classes.item}>
{isBenefitPlanType() ?
<FormattedMessage module="contributionPlan" id="calculationParamsBFType"/> :
<FormattedMessage module="contributionPlan" id="calculationParams"/>
}
</div>
</Typography>
<Divider />
<Grid container className={classes.item}>
<Contributions
contributionKey={CONTRIBUTIONPLAN_CALCULATION_CONTRIBUTION_KEY}
intl={intl}
className={PAYMENTPLAN_CLASSNAME}
entity={paymentPlan}
readOnly={readOnly}
requiredRights={[!!paymentPlan.id ? RIGHT_CALCULATION_UPDATE : RIGHT_CALCULATION_WRITE]}
value={!!paymentPlan.jsonExt ? paymentPlan.jsonExt : null}
onChange={this.updateAttribute}
Expand All @@ -309,6 +338,41 @@ class PaymentPlanHeadPanel extends FormPanel {
/>
</Grid>
</Fragment>
{isBenefitPlanType() && (
<>
<Divider />
<Fragment>
<Typography>
<div className={classes.item}>
<FormattedMessage module="contributionPlan" id="paymentPlan.advancedCriteria" />
</div>
</Typography>
<div className={classes.item}>
<FormattedMessage module="contributionPlan" id="paymentPlan.advancedCriteria.tip" />
</div>
<Divider />
<Grid container className={classes.item}>

<AdvancedCriteriaDialog
object={paymentPlan.benefitPlan}
objectToSave={paymentPlan}
moduleName="social_protection"
objectType="BenefitPlan"
setAppliedCustomFilters={this.setAppliedCustomFilters}
appliedCustomFilters={appliedCustomFilters}
appliedFiltersRowStructure={appliedFiltersRowStructure}
setAppliedFiltersRowStructure={this.setAppliedFiltersRowStructure}
updateAttributes={this.updateJsonExt}
getDefaultAppliedCustomFilters={this.getDefaultAppliedCustomFilters}
edited={this.props.edited}
readOnly={readOnly}
/>

</Grid>
</Fragment>
<Divider />
</>
)}
</Fragment>
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/PaymentPlanSearcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class PaymentPlanSearcher extends Component {
value={paymentPlan.calculation}
readOnly
/> : "",
paymentPlan => {
paymentPlan => {
const objectBenefitPlan = typeof paymentPlan.benefitPlan === 'object' ?
paymentPlan.benefitPlan : JSON.parse(paymentPlan.benefitPlan || '{}');
paymentPlan.benefitPlan = objectBenefitPlan;
Expand Down
Loading

0 comments on commit 1a6cb1c

Please sign in to comment.