Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cameroon implementation age management #80

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 65 additions & 13 deletions src/components/PolicyForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class PolicyForm extends Component {
);
this.setState(() => ({
policy: this._newPolicy(),
dob: this.props.family.headInsuree.dob,
}));
}

Expand Down Expand Up @@ -123,22 +124,42 @@ class PolicyForm extends Component {
policy = this._renewPolicy(policy);
}
policy.ext = !!policy.jsonExt ? JSON.parse(policy.jsonExt) : {};
this.setState(
{
policy,
policy_uuid: policy.uuid,
lockNew: false,
newPolicy: !this.props.renew,
renew: false,
}

);
if ( this.state.policy && this.state.policy.product && this.state.policy.product.ageMaximal != undefined) {
let years = Math.abs(this.state.policy.product.ageMaximal - this.verifyAge(this.state.dob))
this.setState(
{
policy,
policy_uuid: policy.uuid,
lockNew: false,
newPolicy: !this.props.renew,
renew: false
},
e => { if (policy.stage === POLICY_STAGE_RENEW) { this.props.fetchPolicyValues(policy, years) } }
);
}else{
this.setState(
{
policy,
policy_uuid: policy.uuid,
lockNew: false,
newPolicy: !this.props.renew,
renew: false,
},
e => { if (policy.stage === POLICY_STAGE_RENEW) { this.props.fetchPolicyValues(policy, years) } }

);
}
} else if (
!_.isEqual(prevState.policy.product, this.state.policy.product) ||
!_.isEqual(prevState.policy.enrollDate, this.state.policy.enrollDate)
) {
if (!this.props.readOnly && !!this.state.policy.product) {
this.props.fetchPolicyValues(this.state.policy);
if (this.state.policy && this.state.policy.product && this.state.policy.product.ageMaximal != undefined) {
let years = Math.abs(this.state.policy.product.ageMaximal - this.verifyAge(this.state.dob))
this.props.fetchPolicyValues(this.state?.policy, years)
}else{
this.props.fetchPolicyValues(this.state?.policy)
}
}
} else if (
!!prevProps.fetchingPolicyValues &&
Expand All @@ -165,12 +186,13 @@ class PolicyForm extends Component {
this.props.journalize(this.props.mutation);
this.setState({ reset: this.state.reset + 1 });
} else if (!prevProps.renew && !!this.props.renew) {
let years = Math.abs(this.state.policy.product.ageMaximal - this.verifyAge(this.state.dob))
this.setState(
(state, props) => ({
renew: this.props.renew,
policy: this._renewPolicy(state.policy),
}),
(e) => this.props.fetchPolicyValues(this.state.policy)
(e) => this.props.fetchPolicyValues(this.state.policy, years)
);
}
}
Expand Down Expand Up @@ -211,12 +233,30 @@ class PolicyForm extends Component {
}));
};

verifyAge = (age) =>{
let birthDate = new Date(age)
let today = new Date()
let daysMs = today - birthDate
let days = Math.round(daysMs / (1000 * 60 * 60 * 24));
let Age = Math.round(days/365,25)
return Age
}

canSave = () => {
if (!this.state.policy.family) return false;
if (!this.state.policy.product) return false;
if (!this.state.policy.enrollDate) return false;
if (!this.state.policy.startDate) return false;
if (!this.state.policy.expiryDate) return false;
if (this.state.policy.product.ageMaximal != null && this.state.policy.product.ageMinimal != null) {
if (Age < this.state.policy.product.ageMinimal || Age > this.state.policy.product.ageMaximal) {
return false;
}
} else if (this.state.policy.product.ageMinimal == null && this.state.policy.product.ageMaximal != null && Age >= this.state.policy.product.ageMaximal) {
return false;
} else if (this.state.policy.product.ageMaximal == null && this.state.policy.product.ageMinimal != null && Age <= this.state.policy.product.ageMinimal) {
return false;
}
if (!this.state.policy.value) return false;
if (!this.state.policy.officer) return false;
return true;
Expand All @@ -225,10 +265,22 @@ class PolicyForm extends Component {
_save = (policy) => {
this.setState(
{ lockNew: !policy.uuid }, // avoid duplicates
(e) => this.props.save(policy)
(e) => this.props.save(policy),
);
this.dispatchExpiryDate(policy)
};

dispatchExpiryDate = (policy) =>{
this.props.coreAlert(
formatMessage(this.props.intl, "policy", "policy.dispatchExpiryDate.title"),
formatMessageWithValues(this.props.intl, "policy", "dispatchExpiryDate.message",
{
label: policy.expiryDate,
})
)

}

render() {
const {
rights,
Expand Down
4 changes: 3 additions & 1 deletion src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -134,5 +134,7 @@
"policy.PolicyRenewalsReport.sorting.null": "Any",
"policy.PolicyRenewalsReport.sorting.D": "By renewal date",
"policy.PolicyRenewalsReport.sorting.R": "By receipt number",
"policy.PolicyRenewalsReport.sorting.O": "By enrollment officer"
"policy.PolicyRenewalsReport.sorting.O": "By enrollment officer",
"policy.dispatchExpiryDate.message": "Your policy has been registered with this expiry date: {label}",
"policy.dispatchExpiryDate.title": "Policy expiry date "
}