feat: add loan action (add collateral) (#842)

Fixes: #831
This commit is contained in:
Benura Abeywardena
2020-07-12 17:21:39 +05:30
committed by GitHub
parent 74c816a36c
commit ac529dbae8
10 changed files with 169 additions and 1 deletions
@@ -42,6 +42,8 @@ export class LoanActionButtonResolver implements Resolve<Object> {
return this.loansService.rescheduleLoanTemplate();
} else if (loanActionButton === 'prepay-loan') {
return this.loansService.getLoanActionTemplate(loanId, 'prepayLoan');
} else if (loanActionButton === 'add-collateral') {
return this.loansService.getLoanCollateralTemplate(loanId);
} else if (loanActionButton === 'disburse-to-savings') {
return this.loansService.getLoanActionTemplate(loanId, 'disburseToSavings');
} else if (loanActionButton === 'recovery-payment') {
+1
View File
@@ -35,6 +35,7 @@ import { LoanDatatableResolver } from './common-resolvers/loan-datatable.resolve
import { LoanActionButtonResolver } from './common-resolvers/loan-action-button.resolver';
import { LoansAccountTemplateResolver } from './common-resolvers/loans-account-template.resolver';
/** Loans Route. */
const routes: Routes = [
{
path: '',
@@ -0,0 +1,44 @@
<div class="container">
<form [formGroup]="collateralForm" (ngSubmit)="submit()">
<mat-card-content>
<div fxLayout="column">
<mat-form-field>
<mat-label>Collateral Type</mat-label>
<mat-select required formControlName="collateralTypeId">
<mat-option *ngFor="let collateral of dataObject.allowedCollateralTypes" [value]="collateral.id"> {{ collateral.name }}</mat-option>
</mat-select>
<mat-error *ngIf="collateralForm.controls.collateralTypeId.hasError('required')">
Collateral type <strong>required</strong>
</mat-error>
</mat-form-field>
<mat-form-field>
<mat-label>Value</mat-label>
<input matInput required formControlName="value">
<mat-error *ngIf="collateralForm.controls.value.hasError('required')">
Value is <strong>required</strong>
</mat-error>
</mat-form-field>
<mat-form-field>
<mat-label>Description</mat-label>
<textarea matInput formControlName="description"></textarea>
</mat-form-field>
</div>
<mat-card-actions fxLayout="row" fxLayout.xs="column" fxLayoutAlign="center" fxLayoutGap="5px">
<button type="button" mat-raised-button [routerLink]="['../']">Cancel</button>
<button mat-raised-button color="primary" [disabled]="!collateralForm.valid" *mifosxHasPermission="'CREATE_COLLATERAL'">Submit</button>
</mat-card-actions>
</mat-card-content>
</form>
</div>
@@ -0,0 +1,3 @@
.container {
max-width: 37rem;
}
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { AddCollateralComponent } from './add-collateral.component';
describe('AddCollateralComponent', () => {
let component: AddCollateralComponent;
let fixture: ComponentFixture<AddCollateralComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ AddCollateralComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(AddCollateralComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,69 @@
/** Angular Imports. */
import { Component, OnInit, Input } from '@angular/core';
import { FormGroup, FormBuilder, Validators } from '@angular/forms';
import { ActivatedRoute, Router } from '@angular/router';
/** Custom Services. */
import { LoansService } from 'app/loans/loans.service';
/**
* Add Collateral component.
*/
@Component({
selector: 'mifosx-add-collateral',
templateUrl: './add-collateral.component.html',
styleUrls: ['./add-collateral.component.scss']
})
export class AddCollateralComponent implements OnInit {
@Input() dataObject: any;
/** Collateral form. */
collateralForm: FormGroup;
/** Loan Id. */
loanId: string;
/**
* Retrieve data from `Resolver`.
* @param {FormBuilder} formBuilder Form Builder.
* @param {Router} router Router.
* @param {ActivatedRoute} route Activated Route.
* @param {LoansService} LoansService loans service.
*/
constructor(private formBuilder: FormBuilder,
private router: Router,
private route: ActivatedRoute,
private loanService: LoansService ) { }
ngOnInit() {
this.createAddCollateralForm();
}
/**
* Set Collateral form.
*/
createAddCollateralForm() {
this.collateralForm = this.formBuilder.group({
'collateralTypeId': ['', Validators.required],
'value': ['', Validators.required],
'description': ['']
});
}
/**
* Submits collateral form.
*/
submit() {
const collateralTypeId = this.collateralForm.value.collateralTypeId;
this.collateralForm.patchValue({
'collateralTypeId': collateralTypeId
});
const loanId = this.route.parent.snapshot.params['loanId'];
const collateralForm = this.collateralForm.value;
collateralForm.locale = 'en';
this.loanService.createLoanCollateral(loanId, collateralForm).subscribe((response: any) => {
this.router.navigate(['../general'], { relativeTo: this.route });
});
}
}
@@ -17,5 +17,6 @@
<mifosx-reject-loan *ngIf="actions.reject"></mifosx-reject-loan>
<mifosx-disburse [dataObject]="actionButtonData" *ngIf="actions.disburse"></mifosx-disburse>
<mifosx-withdrawn-by-client *ngIf="actions.withdrawn_by_client"></mifosx-withdrawn-by-client>
<mifosx-add-collateral [dataObject]="actionButtonData" *ngIf="actions.add_collateral"></mifosx-add-collateral>
</mat-card>
</div>
@@ -16,6 +16,7 @@ export class LoanAccountActionsComponent {
actions: { close: boolean,
undo_approval: boolean,
write_off: boolean,
add_collateral: boolean,
assign_loan_officer: boolean,
foreclosure: boolean,
prepay_loan: boolean,
@@ -33,6 +34,7 @@ export class LoanAccountActionsComponent {
close: false,
undo_approval: false,
write_off: false,
add_collateral: false,
assign_loan_officer: false,
foreclosure: false,
prepay_loan: false,
+2
View File
@@ -53,6 +53,7 @@ import { WithdrawnByClientComponent } from './loans-view/loan-account-actions/wi
import { LoansAccountViewGuarantorDetailsDialogComponent } from './custom-dialog/loans-account-view-guarantor-details-dialog/loans-account-view-guarantor-details-dialog.component';
import { LoansAccountAddCollateralDialogComponent } from './custom-dialog/loans-account-add-collateral-dialog/loans-account-add-collateral-dialog.component';
import { LoansConfirmationDialogBoxComponent } from './custom-dialog/loans-confirmation-dialog-box/loans-confirmation-dialog-box.component';
import { AddCollateralComponent } from './loans-view/loan-account-actions/add-collateral/add-collateral.component';
/**
* Loans Module
@@ -104,6 +105,7 @@ import { LoansConfirmationDialogBoxComponent } from './custom-dialog/loans-confi
RejectLoanComponent,
DisburseComponent,
WithdrawnByClientComponent,
AddCollateralComponent
],
entryComponents: [
LoansAccountAddCollateralDialogComponent,
+20 -1
View File
@@ -71,10 +71,29 @@ export class LoansService {
* Get Loan Account Details
* @param loanId Loan Id
*/
getLoanAccountDetails(loanId: string) {
getLoanAccountDetails(loanId: string): Observable<any> {
return this.http.get(`/loans/${loanId}`);
}
/**
* Get collateral template.
* @param {string} loanId Loan Id.
* @returns {Observable<any>}
*/
getLoanCollateralTemplate(loanId: string): Observable<any> {
return this.http.get(`/loans/${loanId}/collaterals/template`);
}
/**
* Create Loan Collateral.
* @param {string} loanId Loan Id.
* @param {any} collateralData Collateral Data.
* @returns {Observable<any>}
*/
createLoanCollateral(loanId: string, collateralData: any): Observable<any> {
return this.http.post(`/loans/${loanId}/collaterals`, collateralData);
}
/**
* Get Loans details with httpParams
* @param loanId Loan ID