feat: add loan charge to existing loan accounts (#370)
- Add Loans Module. - Add add-loan-charge component. - Add loans-routing.module.ts - Add loan-charge-template.resolver.ts Fixes: #247
This commit is contained in:
committed by
Abhay Chawla
parent
370fc9b481
commit
9944dcce93
@@ -0,0 +1,62 @@
|
||||
<div class="container">
|
||||
|
||||
<mat-card>
|
||||
|
||||
<form [formGroup]="loanChargeForm" (ngSubmit)="submit()">
|
||||
|
||||
<mat-card-content>
|
||||
|
||||
<div fxLayout="column">
|
||||
<mat-form-field>
|
||||
<mat-label>Charge</mat-label>
|
||||
<mat-select required formControlName="chargeId">
|
||||
<mat-option *ngFor="let loanCharge of loanChargeOptions" [value]="loanCharge.id">
|
||||
{{ loanCharge.name + ' (' + loanCharge.currency.name + ')' }}
|
||||
</mat-option>
|
||||
</mat-select>
|
||||
<mat-error *ngIf="loanChargeForm.controls.chargeId.hasError('required')">
|
||||
Charge is <strong>required</strong>
|
||||
</mat-error>
|
||||
</mat-form-field>
|
||||
|
||||
<mat-form-field>
|
||||
<mat-label>Amount</mat-label>
|
||||
<input type=number required matInput formControlName="amount" />
|
||||
<mat-error *ngIf="loanChargeForm.controls.amount.hasError('required')">
|
||||
Amount is <strong>required</strong>
|
||||
</mat-error>
|
||||
</mat-form-field>
|
||||
|
||||
<mat-form-field>
|
||||
<mat-label>Charge Calculation</mat-label>
|
||||
<input matInput formControlName="chargeCalculation" />
|
||||
</mat-form-field>
|
||||
|
||||
<mat-form-field>
|
||||
<mat-label>Charge Time</mat-label>
|
||||
<input matInput formControlName="chargeTime" />
|
||||
</mat-form-field>
|
||||
|
||||
<mat-form-field *ngIf="loanChargeForm.controls['dueDate']">
|
||||
<mat-label>Due On</mat-label>
|
||||
<input matInput [min]="minDate" [max]="maxDate" [matDatepicker]="dueDatePicker" required formControlName="dueDate">
|
||||
<mat-datepicker-toggle matSuffix [for]="dueDatePicker"></mat-datepicker-toggle>
|
||||
<mat-datepicker #dueDatePicker></mat-datepicker>
|
||||
<mat-error *ngIf="loanChargeForm.controls.dueDate.hasError('required')">
|
||||
Due Date is <strong>required</strong>
|
||||
</mat-error>
|
||||
</mat-form-field>
|
||||
|
||||
</div>
|
||||
|
||||
<mat-card-actions fxLayoutGap="5px" fxLayout="row" fxLayout.xs="column" fxLayoutAlign="center">
|
||||
<button type="button" mat-raised-button [routerLink]="['../']">Cancel</button>
|
||||
<button mat-raised-button color="primary" [disabled]="!loanChargeForm.valid">Submit</button>
|
||||
</mat-card-actions>
|
||||
|
||||
</mat-card-content>
|
||||
</form>
|
||||
|
||||
</mat-card>
|
||||
|
||||
</div>
|
||||
@@ -0,0 +1,3 @@
|
||||
.container{
|
||||
width: 37rem;
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { AddLoanChargeComponent } from './add-loan-charge.component';
|
||||
|
||||
describe('AddloanchargeComponent', () => {
|
||||
let component: AddLoanChargeComponent;
|
||||
let fixture: ComponentFixture<AddLoanChargeComponent>;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [ AddLoanChargeComponent ]
|
||||
})
|
||||
.compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(AddLoanChargeComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,108 @@
|
||||
/** Angular Imports */
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { FormGroup, FormBuilder, Validators, FormControl } from '@angular/forms';
|
||||
import { Router, ActivatedRoute } from '@angular/router';
|
||||
import { DatePipe } from '@angular/common';
|
||||
|
||||
/** Custom Services */
|
||||
import { LoansService } from '../loans.service';
|
||||
|
||||
/**
|
||||
* Create Add Loan Charge component.
|
||||
*/
|
||||
@Component({
|
||||
selector: 'mifosx-addloancharge',
|
||||
templateUrl: './add-loan-charge.component.html',
|
||||
styleUrls: ['./add-loan-charge.component.scss']
|
||||
})
|
||||
export class AddLoanChargeComponent implements OnInit {
|
||||
|
||||
/** Minimum Due Date allowed. */
|
||||
minDate = new Date(2000, 0, 1);
|
||||
/** Maximum Due Date allowed. */
|
||||
maxDate = new Date();
|
||||
/** Add Loan Charge form. */
|
||||
loanChargeForm: FormGroup;
|
||||
/** loan charge options. */
|
||||
loanChargeOptions: {
|
||||
id: number;
|
||||
name: string;
|
||||
amount: number;
|
||||
chargeCalculationType: {
|
||||
value: any;
|
||||
};
|
||||
chargeTimeType: {
|
||||
id: number;
|
||||
value: any;
|
||||
};
|
||||
}[];
|
||||
/** loan Id of the loan account. */
|
||||
loanId: string;
|
||||
|
||||
/**
|
||||
* Retrieves the loan charge template data from `resolve`.
|
||||
* @param {FormBuilder} formBuilder Form Builder.
|
||||
* @param {AccountingService} accountingService Accounting Service.
|
||||
* @param {ActivatedRoute} route Activated Route.
|
||||
* @param {Router} router Router for navigation.
|
||||
*/
|
||||
constructor(private formBuilder: FormBuilder,
|
||||
private route: ActivatedRoute,
|
||||
private router: Router,
|
||||
private datePipe: DatePipe,
|
||||
private loansService: LoansService) {
|
||||
this.route.data.subscribe((data: { loanChargeTemplate: any }) => {
|
||||
this.loanChargeOptions = data.loanChargeTemplate.chargeOptions;
|
||||
});
|
||||
this.loanId = this.route.snapshot.params['loanId'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the Loan Charge form.
|
||||
*/
|
||||
ngOnInit() {
|
||||
this.createLoanChargeForm();
|
||||
this.loanChargeForm.controls.chargeId.valueChanges.subscribe(chargeId => {
|
||||
const chargeDetails = this.loanChargeOptions.find(option => {
|
||||
return option.id === chargeId;
|
||||
});
|
||||
if (chargeDetails.chargeTimeType.id === 2) {
|
||||
this.loanChargeForm.addControl('dueDate', new FormControl('', Validators.required));
|
||||
} else {
|
||||
this.loanChargeForm.removeControl('dueDate');
|
||||
}
|
||||
this.loanChargeForm.patchValue({
|
||||
'amount': chargeDetails.amount,
|
||||
'chargeCalculation': chargeDetails.chargeCalculationType.value,
|
||||
'chargeTime': chargeDetails.chargeTimeType.value
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the Loan Charge form.
|
||||
*/
|
||||
createLoanChargeForm() {
|
||||
this.loanChargeForm = this.formBuilder.group({
|
||||
'chargeId': ['', Validators.required],
|
||||
'amount': ['', Validators.required],
|
||||
'chargeCalculation': [{ value: '', disabled: true }],
|
||||
'chargeTime': [{ value: '', disabled: true }]
|
||||
});
|
||||
}
|
||||
|
||||
submit() {
|
||||
const prevDueDate: Date = this.loanChargeForm.value.dueDate;
|
||||
// TODO: Update once language and date settings are setup
|
||||
const dateFormat = 'yyyy-MM-dd';
|
||||
this.loanChargeForm.patchValue({
|
||||
dueDate: this.datePipe.transform(prevDueDate, dateFormat)
|
||||
});
|
||||
const loanCharge = this.loanChargeForm.value;
|
||||
loanCharge.locale = 'en';
|
||||
loanCharge.dateFormat = dateFormat;
|
||||
this.loansService.createLoanCharge(this.loanId, 'charges', loanCharge).subscribe(res => {
|
||||
this.router.navigate(['../'], { relativeTo: this.route });
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user