feat: add loan button (foreclosure) (#869)

Fixes: #244
This commit is contained in:
Muskan Khedia
2020-06-13 03:19:05 +05:30
committed by GitHub
parent db248a8037
commit da609f0de4
9 changed files with 247 additions and 4 deletions
@@ -56,10 +56,10 @@ export class AssignLoanOfficerComponent implements OnInit {
}
submit() {
const assignmentDatee = this.assignOfficerForm.value.assignmentDate;
const assignmentDate = this.assignOfficerForm.value.assignmentDate;
const dateFormat = 'yyyy-MM-dd';
this.assignOfficerForm.patchValue({
assignmentDate: this.datePipe.transform(assignmentDatee, dateFormat)
assignmentDate: this.datePipe.transform(assignmentDate, dateFormat)
});
const assignForm = this.assignOfficerForm.value;
assignForm.locale = 'en';
@@ -0,0 +1,75 @@
<div class="container">
<form [formGroup]="foreclosureForm" (ngSubmit)="submit()">
<mat-card-content>
<div fxLayout="column">
<mat-form-field>
<mat-label>Transaction Date</mat-label>
<input matInput [min]="minDate" [max]="maxDate" [matDatepicker]="transactionsDatePicker" required formControlName="transactionDate">
<mat-datepicker-toggle matSuffix [for]="transactionsDatePicker"></mat-datepicker-toggle>
<mat-datepicker #transactionsDatePicker></mat-datepicker>
<mat-error *ngIf="foreclosureForm.controls.transactionDate.hasError('required')">
Transaction Date <strong>is required</strong>
</mat-error>
</mat-form-field>
<mat-form-field>
<mat-label>Principal</mat-label>
<input matInput required formControlName="outstandingPrincipalPortion">
<mat-error *ngIf="foreclosureForm.controls.outstandingPrincipalPortion.hasError('required')">
Loan Officer is <strong>required</strong>
</mat-error>
</mat-form-field>
<mat-form-field>
<mat-label>Interest</mat-label>
<input matInput required formControlName="outstandingInterestPortion">
<mat-error *ngIf="foreclosureForm.controls.outstandingInterestPortion.hasError('required')">
Loan Officer is <strong>required</strong>
</mat-error>
</mat-form-field>
<mat-form-field>
<mat-label>Fee Amount</mat-label>
<input matInput required formControlName="outstandingFeeChargesPortion">
<mat-error *ngIf="foreclosureForm.controls.outstandingFeeChargesPortion.hasError('required')">
Loan Officer is <strong>required</strong>
</mat-error>
</mat-form-field>
<mat-form-field>
<mat-label>Penalty Amount</mat-label>
<input matInput required formControlName="outstandingPenaltyChargesPortion">
<mat-error *ngIf="foreclosureForm.controls.outstandingPenaltyChargesPortion.hasError('required')">
Loan Officer is <strong>required</strong>
</mat-error>
</mat-form-field>
<mat-form-field>
<mat-label>Transaction Amount</mat-label>
<input matInput required formControlName="transactionAmount">
<mat-error *ngIf="foreclosureForm.controls.transactionAmount.hasError('required')">
Loan Officer is <strong>required</strong>
</mat-error>
</mat-form-field>
<mat-form-field>
<mat-label>Note</mat-label>
<textarea matInput formControlName="note"></textarea>
</mat-form-field>
</div>
<mat-card-actions fxLayout="row" fxLayout.xs="column" fxLayoutAlign="center" fxLayoutGap="5px">
<button type="button" mat-raised-button [routerLink]="['../general']">Cancel</button>
<button mat-raised-button color="primary" [disabled]="!foreclosureForm.valid" *mifosxHasPermission="'FORECLOSURE_LOAN'">Foreclosure</button>
</mat-card-actions>
</mat-card-content>
</form>
</div>
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ForeclosureComponent } from './foreclosure.component';
describe('ForeclosureComponent', () => {
let component: ForeclosureComponent;
let fixture: ComponentFixture<ForeclosureComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ ForeclosureComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(ForeclosureComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,124 @@
import { Component, OnInit } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { LoansService } from 'app/loans/loans.service';
import { ActivatedRoute, Router } from '@angular/router';
import { DatePipe } from '@angular/common';
@Component({
selector: 'mifosx-foreclosure',
templateUrl: './foreclosure.component.html',
styleUrls: ['./foreclosure.component.scss']
})
export class ForeclosureComponent implements OnInit {
loanId: any;
foreclosureForm: FormGroup;
/** Minimum Date allowed. */
minDate = new Date(2000, 0, 1);
/** Maximum Date allowed. */
maxDate = new Date();
foreclosuredata: any;
paymentTypes: any;
/**
* @param {FormBuilder} formBuilder Form Builder.
* @param {LoansService} systemService Loan Service.
* @param {ActivatedRoute} route Activated Route.
* @param {Router} router Router for navigation.
*/
constructor(private formBuilder: FormBuilder,
private loanService: LoansService,
private route: ActivatedRoute,
private router: Router,
private datePipe: DatePipe) {
this.loanId = this.route.parent.snapshot.params['loanId'];
}
ngOnInit() {
this.createforeclosureForm();
this.onChanges();
}
createforeclosureForm() {
this.foreclosureForm = this.formBuilder.group({
'transactionDate': [new Date(), Validators.required],
'outstandingPrincipalPortion': [{value: '', disabled: true}, Validators.required],
'outstandingInterestPortion': [{value: '', disabled: true}, Validators.required],
'outstandingFeeChargesPortion': [{value: '', disabled: true}, Validators.required],
'outstandingPenaltyChargesPortion': [{value: '', disabled: true}, Validators.required],
'transactionAmount': [{value: '', disabled: true}, Validators.required],
'interestAccruedAfterDeath': '',
'note': ''
});
}
onChanges(): void {
this.foreclosureForm.get('transactionDate').valueChanges.subscribe(val => {
this.retrieveLoanForeclosureTemplate(val);
});
}
retrieveLoanForeclosureTemplate(val: any) {
const dateFormat = 'dd MMMM yyyy';
const transactionDateFormatted = this.datePipe.transform(val, dateFormat);
const data = {
command: 'foreclosure',
dateFormat: 'dd MMMM yyyy',
locale: 'en',
transactionDate: transactionDateFormatted
};
this.loanService.getForeclosureData(this.loanId, data)
.subscribe((response: any) => {
this.foreclosuredata = response;
this.foreclosureForm.patchValue({
outstandingPrincipalPortion: this.foreclosuredata.principalPortion,
outstandingInterestPortion: this.foreclosuredata.interestPortion,
outstandingFeeChargesPortion: this.foreclosuredata.feeChargesPortion,
outstandingPenaltyChargesPortion: this.foreclosuredata.penaltyChargesPortion,
foreClosureChargesPortion: this.foreclosuredata.foreClosureChargesPortion
});
if (this.foreclosuredata.unrecognizedIncomePortion) {
this.foreclosureForm.patchValue({
interestAccruedAfterDeath: this.foreclosuredata.unrecognizedIncomePortion
});
}
this.calculateTransactionAmount();
this.paymentTypes = this.foreclosuredata.paymentTypeOptions;
});
}
calculateTransactionAmount() {
let transactionAmount = 0;
transactionAmount += parseFloat(this.foreclosuredata.principalPortion);
transactionAmount += parseFloat(this.foreclosuredata.interestPortion);
transactionAmount += parseFloat(this.foreclosuredata.feeChargesPortion);
transactionAmount += parseFloat(this.foreclosuredata.penaltyChargesPortion);
this.foreclosureForm.patchValue({
transactionAmount: transactionAmount
});
}
submit() {
const transactionDate = this.foreclosureForm.value.transactionDate;
const dateFormat = 'yyyy-MM-dd';
this.foreclosureForm.patchValue({
transactionDate: this.datePipe.transform(transactionDate, dateFormat)
});
const formData = {
transactionDate: this.foreclosureForm.value.transactionDate,
locale: 'en',
dateFormat: dateFormat,
note: this.foreclosureForm.value.note
};
this.loanService.loanForclosureData(this.loanId, formData)
.subscribe((response: any) => {
this.router.navigate([`../general`], { relativeTo: this.route });
});
}
}
@@ -3,5 +3,6 @@
<mifosx-loans-account-close *ngIf="actions.close"></mifosx-loans-account-close>
<mifosx-undo-approval *ngIf="actions.undo_approval"></mifosx-undo-approval>
<mifosx-assign-loan-officer *ngIf="actions.assign_loan_officer" [dataObject]="actionButtonData" ></mifosx-assign-loan-officer>
<mifosx-foreclosure *ngIf="actions.foreclosure"></mifosx-foreclosure>
</mat-card>
</div>
@@ -15,10 +15,12 @@ export class LoanAccountActionsComponent {
/** flag object to store possible actions and render appropriate UI to the user */
actions: { close: boolean,
undo_approval: boolean,
assign_loan_officer: boolean } = {
assign_loan_officer: boolean,
foreclosure: boolean } = {
close: false,
undo_approval: false,
assign_loan_officer: false };
assign_loan_officer: false,
foreclosure: false };
actionButtonData: any;
actionName: any;
+2
View File
@@ -26,6 +26,7 @@ import { MultiRowComponent } from './loans-view/datatable-tab/multi-row/multi-ro
import { SingleRowComponent } from './loans-view/datatable-tab/single-row/single-row.component';
import { UndoApprovalComponent } from './loans-view/loan-account-actions/undo-approval/undo-approval.component';
import { AssignLoanOfficerComponent } from './loans-view/loan-account-actions/assign-loan-officer/assign-loan-officer.component';
import { ForeclosureComponent } from './loans-view/loan-account-actions/foreclosure/foreclosure.component';
/**
* Loans Module
@@ -52,6 +53,7 @@ import { AssignLoanOfficerComponent } from './loans-view/loan-account-actions/as
SingleRowComponent,
UndoApprovalComponent,
AssignLoanOfficerComponent,
ForeclosureComponent,
],
providers: [DatePipe],
})
+14
View File
@@ -167,4 +167,18 @@ export class LoansService {
return this.http.post(`/loans/${loanId}`, data, {params: httpParams});
}
getForeclosureData(loanId: any, foreclosuredata: any) {
const httpParams = new HttpParams().set('command', foreclosuredata.command)
.set('dateFormat', foreclosuredata.dateFormat)
.set('locale', foreclosuredata.locale)
.set('transactionDate', foreclosuredata.transactionDate);
return this.http.get(`/loans/${loanId}/transactions/template`, {params: httpParams});
}
loanForclosureData(loanId: any, data: any) {
const httpParams = new HttpParams().set('command', 'foreclosure');
return this.http.post(`/loans/${loanId}/transactions`, data, {params: httpParams});
}
}