I have a straightforward logic with conditions written, but I am always getting inaccurate results. I am dealing with three fields: immediate limit, hold limit, and LDC. The condition I am trying to implement is that when the immediate limit and hold limit are numeric values, their sum should be less than LDC, and each individual limit should also be less than LDC. If the limit values are not numeric, they return a negative number.
Below is my code:
immediateLimitError: boolean = false;
hold1LimitError: boolean = false;
ldcLimitError: boolean = false;
sumOflimitVal: any;
changedLdc!: any;
changedImmediateLimit!: any;
changedHold1Limit!: any;
private instantiateValidation(row: any) {
this.newHoldSchedule = this.formBuilder.group({
immediatereleaseForm: [(row.hold1ReleaseAmt != null ? row.hold1ReleaseAmt : ' '), Validators.required],
ldcForm: [(row.ldcAmt != null ? row.ldcAmt : ' ')],
holdOneLimitForm: [(row.hold2ReleaseAmt != null ? row.hold2ReleaseAmt : ' '), Validators.required]
});
this.changedImmediateLimit = row.hold1ReleaseAmt;
this.changedHold1Limit = row.hold2ReleaseAmt;
this.changedLdc = row.ldcAmt;
this.newHoldSchedule.get('immediatereleaseForm')!.valueChanges.subscribe(val => {
this.changedImmediateLimit = val;
if(this.changedHold1Limit >= 0 || val >= 0 ){
if((val + this.changedHold1Limit) > this.changedLdc ||
val > this.changedLdc ||
this.changedHold1Limit > this.changedLdc){
this.immediateLimitError = true;
}
else{
this.immediateLimitError = false;
}
}
});
// More code...
}
if(this.immediateLimitError || this.hold1LimitError || this.ldcLimitError){
this.displayError('The sum of Immediate Release limit and Hold 1 Limit exceeds LDC');
event.preventDefault();
}
This code works correctly for some values but produces inaccurate results for others. I have tried debugging and adjusting the conditions without success. Any assistance would be greatly appreciated. Thank you.