Skip to content

WEB-874 Prevent negative values in numeric fields of Group#3412

Open
JaySoni1 wants to merge 1 commit intoopenMF:devfrom
JaySoni1:WEB-874-prevent-negative-values-in-numeric-fields-of-group
Open

WEB-874 Prevent negative values in numeric fields of Group#3412
JaySoni1 wants to merge 1 commit intoopenMF:devfrom
JaySoni1:WEB-874-prevent-negative-values-in-numeric-fields-of-group

Conversation

@JaySoni1
Copy link
Contributor

@JaySoni1 JaySoni1 commented Mar 19, 2026

Changes Made :-

-Add min(0) validation to numeric fields in Savings Account Terms, Loans Account Terms, and GLIM account in GROUP .

WEB-874

Before :-

image image image image image image image

After :-

image image image image image image image

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced validation for numeric input fields in loan and savings account configuration. Users can no longer enter negative values for critical financial parameters including interest rates, grace periods, repayment terms, opening balances, tolerance limits, and overdraft settings, ensuring improved data integrity during account setup.

@coderabbitai
Copy link

coderabbitai bot commented Mar 19, 2026

Note

.coderabbit.yaml has unrecognized properties

CodeRabbit is using all valid settings from your configuration. Unrecognized properties (listed below) have been ignored and may indicate typos or deprecated fields that can be removed.

⚠️ Parsing warnings (1)
Validation error: Unrecognized key(s) in object: 'pre_merge_checks'
⚙️ Configuration instructions
  • Please see the configuration documentation for more information.
  • You can also validate your configuration using the online YAML validator.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Walkthrough

This PR adds non-negativity validation constraints to numeric form fields across the loans and savings account steppers. The changes apply min="0" HTML attributes to template inputs and add corresponding Validators.min(0) to form control definitions in components, affecting eight numeric fields in each module.

Changes

Cohort / File(s) Summary
Loans Account Terms Step
src/app/loans/loans-account-stepper/loans-account-terms-step/loans-account-terms-step.component.html, src/app/loans/loans-account-stepper/loans-account-terms-step/loans-account-terms-step.component.ts
Added min="0" HTML attributes to numeric inputs and Validators.min(0) to form controls for numberOfRepayments, repaymentEvery, interestRatePerPeriod, inArrearsTolerance, graceOnInterestCharged, graceOnPrincipalPayment, graceOnInterestPayment, and graceOnArrearsAgeing.
Savings Account Terms Step
src/app/savings/savings-account-stepper/savings-account-terms-step/savings-account-terms-step.component.html, src/app/savings/savings-account-stepper/savings-account-terms-step/savings-account-terms-step.component.ts
Added min="0" HTML attributes and Validators.min(0) to form controls for nominalAnnualInterestRate, minRequiredOpeningBalance, lockinPeriodFrequency, minRequiredBalance, minOverdraftForInterestCalculation, nominalAnnualInterestRateOverdraft, overdraftLimit, and minBalanceForInterestCalculation.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • IOhacker
  • alberto-art3ch
🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'WEB-874 Prevent negative values in numeric fields of Group' clearly and specifically summarizes the main change: adding min(0) validation constraints to numeric input fields across loans and savings account forms.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (3)
src/app/loans/loans-account-stepper/loans-account-terms-step/loans-account-terms-step.component.ts (1)

452-468: ⚠️ Potential issue | 🟠 Major

Bug: Validators.min(0) is not applied when interestRatePerPeriod is recreated.

The setAdvancedPaymentStrategyControls() method removes and recreates the interestRatePerPeriod control dynamically, but only applies Validators.required. This overwrites the Validators.min(0) defined in createloansAccountTermsForm(), making the min validation ineffective.

🐛 Proposed fix to include Validators.min(0)
       if (this.loansAccountTermsData.product.fixedLength) {
         this.loansAccountTermsForm.addControl(
           'interestRatePerPeriod',
-          new UntypedFormControl({ value: 0, disabled: true }, Validators.required)
+          new UntypedFormControl({ value: 0, disabled: true }, [Validators.required, Validators.min(0)])
         );
         this.loansAccountTermsForm.addControl(
           'fixedLength',
           new UntypedFormControl(this.loansAccountTermsData.product.fixedLength)
         );
       } else {
         this.loansAccountTermsForm.addControl(
           'interestRatePerPeriod',
-          new UntypedFormControl(this.loansAccountTermsData.interestRatePerPeriod, Validators.required)
+          new UntypedFormControl(this.loansAccountTermsData.interestRatePerPeriod, [Validators.required, Validators.min(0)])
         );
       }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@src/app/loans/loans-account-stepper/loans-account-terms-step/loans-account-terms-step.component.ts`
around lines 452 - 468, The interestRatePerPeriod control is being removed and
re-added in setAdvancedPaymentStrategyControls (inside
loans-account-terms-step.component) without reapplying Validators.min(0), which
breaks the minimum-value validation defined in createloansAccountTermsForm();
when recreating interestRatePerPeriod (both the disabled and enabled branches)
add Validators.min(0) alongside Validators.required so the minimum validation is
preserved on the new UntypedFormControl instances on loansAccountTermsForm.
src/app/loans/loans-account-stepper/loans-account-terms-step/loans-account-terms-step.component.html (2)

129-145: ⚠️ Potential issue | 🟡 Minor

Change min="0" to min="1" and update validator to match loan product pattern.

The repaymentEvery field currently allows 0 as a valid value (both in HTML min="0" and TypeScript Validators.min(0)), which is invalid business logic—a loan cannot be repaid every 0 months/days. The loan product stepper correctly enforces min="1" in both the HTML attribute and Validators.min(1) in the form control. Align this component with that pattern.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@src/app/loans/loans-account-stepper/loans-account-terms-step/loans-account-terms-step.component.html`
around lines 129 - 145, The template allows 0 for repayment interval; change the
input min attribute from min="0" to min="1" and then update the form control
validator in the loansAccountTermsForm initialization (the control named
repaymentEvery) to use Validators.min(1) and the same pattern used by the loan
product stepper so the form-level validation matches the HTML constraint and
business rule.

69-84: ⚠️ Potential issue | 🟡 Minor

Update "Number of repayments" validation to require a minimum of 1 repayment.

The field currently allows a minimum of 0 via min="0" and Validators.min(0), but a loan with 0 repayments is invalid. Since calculateLoanTerm() multiplies numberOfRepayments × repaymentEvery to set the loan term, allowing 0 would result in a 0 loan term. Change both the HTML attribute and TypeScript validator to min="1" and Validators.min(1) to enforce at least one repayment.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@src/app/loans/loans-account-stepper/loans-account-terms-step/loans-account-terms-step.component.html`
around lines 69 - 84, The Number of repayments input and its validator allow 0
which permits a 0-length loan term; update both the template input attribute min
and the form validator to require at least 1. Change the HTML input's min="0" to
min="1" for the field bound by formControlName="numberOfRepayments", and update
the TypeScript form control where Validators.min(0) is used (on
loansAccountTermsForm.controls.numberOfRepayments or where the FormControl is
constructed) to Validators.min(1); ensure calculateLoanTerm() continues to use
loansAccountTermsForm.controls.numberOfRepayments.value safely after this
change.
🧹 Nitpick comments (1)
src/app/savings/savings-account-stepper/savings-account-terms-step/savings-account-terms-step.component.html (1)

93-96: Consider adding <mat-error> for min validation feedback.

Fields like minRequiredOpeningBalance, lockinPeriodFrequency, and minRequiredBalance now have min="0" constraints but lack corresponding <mat-error> elements to display validation feedback when users attempt to enter negative values. While the HTML5 min attribute prevents negative input in most browsers, adding error messages improves accessibility and provides clearer feedback.

💡 Example: Add mat-error for minRequiredOpeningBalance
 <mat-form-field class="flex-48">
   <mat-label>{{ 'labels.inputs.Minimum Opening Balance' | translate }}</mat-label>
   <input type="number" matInput formControlName="minRequiredOpeningBalance" min="0" />
+  `@if` (savingsAccountTermsForm.controls.minRequiredOpeningBalance.hasError('min')) {
+    <mat-error>
+      {{ 'labels.inputs.Minimum Opening Balance' | translate }}
+      {{ 'labels.commons.must be' | translate }}
+      <strong>{{ 'labels.commons.non-negative' | translate }}</strong>
+    </mat-error>
+  }
 </mat-form-field>
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@src/app/savings/savings-account-stepper/savings-account-terms-step/savings-account-terms-step.component.html`
around lines 93 - 96, Add validation error UI for the numeric min constraints in
the template: for each mat-form-field that uses
formControlName="minRequiredOpeningBalance", "lockinPeriodFrequency", and
"minRequiredBalance" inside savings-account-terms-step.component.html, add a
<mat-error> that displays when the control has a min validation error (e.g.,
control.hasError('min') or control.errors?.min) and show a translated or clear
message like "Minimum value is 0"; ensure the <mat-error> is bound to the same
FormControl used by the input so users get accessible feedback when they enter
values below 0.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In
`@src/app/loans/loans-account-stepper/loans-account-terms-step/loans-account-terms-step.component.html`:
- Around line 129-145: The template allows 0 for repayment interval; change the
input min attribute from min="0" to min="1" and then update the form control
validator in the loansAccountTermsForm initialization (the control named
repaymentEvery) to use Validators.min(1) and the same pattern used by the loan
product stepper so the form-level validation matches the HTML constraint and
business rule.
- Around line 69-84: The Number of repayments input and its validator allow 0
which permits a 0-length loan term; update both the template input attribute min
and the form validator to require at least 1. Change the HTML input's min="0" to
min="1" for the field bound by formControlName="numberOfRepayments", and update
the TypeScript form control where Validators.min(0) is used (on
loansAccountTermsForm.controls.numberOfRepayments or where the FormControl is
constructed) to Validators.min(1); ensure calculateLoanTerm() continues to use
loansAccountTermsForm.controls.numberOfRepayments.value safely after this
change.

In
`@src/app/loans/loans-account-stepper/loans-account-terms-step/loans-account-terms-step.component.ts`:
- Around line 452-468: The interestRatePerPeriod control is being removed and
re-added in setAdvancedPaymentStrategyControls (inside
loans-account-terms-step.component) without reapplying Validators.min(0), which
breaks the minimum-value validation defined in createloansAccountTermsForm();
when recreating interestRatePerPeriod (both the disabled and enabled branches)
add Validators.min(0) alongside Validators.required so the minimum validation is
preserved on the new UntypedFormControl instances on loansAccountTermsForm.

---

Nitpick comments:
In
`@src/app/savings/savings-account-stepper/savings-account-terms-step/savings-account-terms-step.component.html`:
- Around line 93-96: Add validation error UI for the numeric min constraints in
the template: for each mat-form-field that uses
formControlName="minRequiredOpeningBalance", "lockinPeriodFrequency", and
"minRequiredBalance" inside savings-account-terms-step.component.html, add a
<mat-error> that displays when the control has a min validation error (e.g.,
control.hasError('min') or control.errors?.min) and show a translated or clear
message like "Minimum value is 0"; ensure the <mat-error> is bound to the same
FormControl used by the input so users get accessible feedback when they enter
values below 0.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: f62da7e5-cbab-4c93-8772-794502e5fe78

📥 Commits

Reviewing files that changed from the base of the PR and between d4fa504 and c841f82.

📒 Files selected for processing (4)
  • src/app/loans/loans-account-stepper/loans-account-terms-step/loans-account-terms-step.component.html
  • src/app/loans/loans-account-stepper/loans-account-terms-step/loans-account-terms-step.component.ts
  • src/app/savings/savings-account-stepper/savings-account-terms-step/savings-account-terms-step.component.html
  • src/app/savings/savings-account-stepper/savings-account-terms-step/savings-account-terms-step.component.ts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant