feat: add loan action (withdrawn by client) (#1063)

Fixes: #859
This commit is contained in:
Muskan Khedia
2020-07-12 16:53:45 +05:30
committed by GitHub
parent 8bec54dfbd
commit 74c816a36c
8 changed files with 148 additions and 3 deletions
@@ -57,7 +57,7 @@ export class DisburseComponent implements OnInit {
}
/**
* Creates the create close form.
* Creates the disbursement loan form.
*/
createDisbursementLoanForm() {
this.disbursementLoanForm = this.formBuilder.group({
@@ -16,5 +16,6 @@
<mifosx-disburse-loan-account [dataObject]="actionButtonData" *ngIf="actions.disburse_to_savings"></mifosx-disburse-loan-account>
<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>
</mat-card>
</div>
@@ -28,7 +28,8 @@ export class LoanAccountActionsComponent {
recovery_payment: boolean,
view_guarantors: boolean,
create_guarantor: boolean,
disburse: boolean } = {
disburse: boolean,
withdrawn_by_client: boolean } = {
close: false,
undo_approval: false,
write_off: false,
@@ -44,7 +45,8 @@ export class LoanAccountActionsComponent {
recovery_payment: false,
view_guarantors: false,
create_guarantor: false,
disburse: false };
disburse: false,
withdrawn_by_client: false };
actionButtonData: any;
actionName: any;
@@ -0,0 +1,35 @@
<div class="container">
<form [formGroup]="withdrawnByClientLoanForm" (ngSubmit)="submit()">
<mat-card-content>
<div fxLayout="column">
<mat-form-field>
<mat-label>Withdrawn On</mat-label>
<input matInput [min]="minDate" [max]="maxDate" [matDatepicker]="withdrawnOnDatePicker" required formControlName="withdrawnOnDate">
<mat-datepicker-toggle matSuffix [for]="withdrawnOnDatePicker"></mat-datepicker-toggle>
<mat-datepicker #withdrawnOnDatePicker></mat-datepicker>
<mat-error *ngIf="withdrawnByClientLoanForm.controls.withdrawnOnDate.hasError('required')">
Withdrawn On Date <strong>is 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]="!withdrawnByClientLoanForm.valid" *mifosxHasPermission="'WITHDRAW_LOAN'">Submit</button>
</mat-card-actions>
</mat-card-content>
</form>
</div>
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { WithdrawnByClientComponent } from './withdrawn-by-client.component';
describe('WithdrawnByClientComponent', () => {
let component: WithdrawnByClientComponent;
let fixture: ComponentFixture<WithdrawnByClientComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ WithdrawnByClientComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(WithdrawnByClientComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,80 @@
/** Angular Imports */
import { Component, OnInit, Input } from '@angular/core';
import { FormGroup, FormBuilder, Validators, FormControl } from '@angular/forms';
import { ActivatedRoute, Router } from '@angular/router';
/** Custom Services */
import { LoansService } from 'app/loans/loans.service';
import { DatePipe } from '@angular/common';
/**
* Withdrawn By Applicant Loan Form
*/
@Component({
selector: 'mifosx-withdrawn-by-client',
templateUrl: './withdrawn-by-client.component.html',
styleUrls: ['./withdrawn-by-client.component.scss']
})
export class WithdrawnByClientComponent implements OnInit {
@Input() dataObject: any;
/** Loan Id */
loanId: string;
/** Minimum Date allowed. */
minDate = new Date(2000, 0, 1);
/** Maximum Date allowed. */
maxDate = new Date();
/** Withdrawn By Applicant Loan Form */
withdrawnByClientLoanForm: FormGroup;
/**
* @param {FormBuilder} formBuilder Form Builder.
* @param {LoansService} loanService Loan Service.
* @param {ActivatedRoute} route Activated Route.
* @param {Router} router Router for navigation.
* @param {DatePipe} datePipe Date Pipe.
*/
constructor(private formBuilder: FormBuilder,
private loanService: LoansService,
private route: ActivatedRoute,
private router: Router,
private datePipe: DatePipe) {
this.loanId = this.route.parent.snapshot.params['loanId'];
}
/**
* Creates the withdraw by Applicant loan form
* and initialize with the required values
*/
ngOnInit() {
this.createWithdrawnByClientLoanForm();
}
/**
* Creates the create withdraw by applicant form.
*/
createWithdrawnByClientLoanForm() {
this.withdrawnByClientLoanForm = this.formBuilder.group({
'withdrawnOnDate': [new Date(), Validators.required],
'note': ''
});
}
/** Submits the withdraw by appplicant form */
submit() {
const prevTransactionDate: Date = this.withdrawnByClientLoanForm.value.withdrawnOnDate;
// TODO: Update once language and date settings are setup
const dateFormat = 'dd-MM-yyyy';
this.withdrawnByClientLoanForm.patchValue({
withdrawnOnDate: this.datePipe.transform(prevTransactionDate, dateFormat)
});
const WithdrawnByClientLoanData = this.withdrawnByClientLoanForm.value;
WithdrawnByClientLoanData.locale = 'en';
WithdrawnByClientLoanData.dateFormat = dateFormat;
this.loanService.loanActionButtons(this.loanId, 'withdrawnByApplicant', WithdrawnByClientLoanData)
.subscribe((response: any) => {
this.router.navigate(['../general'], { relativeTo: this.route });
});
}
}
+2
View File
@@ -47,6 +47,7 @@ import { CreateGuarantorComponent } from './loans-view/loan-account-actions/crea
import { DisburseLoanAccountComponent } from './loans-view/loan-account-actions/disburse-loan-account/disburse-loan-account.component';
import { DisburseComponent } from './loans-view/loan-account-actions/disburse/disburse.component';
import { RejectLoanComponent } from './loans-view/loan-account-actions/reject-loan/reject-loan.component';
import { WithdrawnByClientComponent } from './loans-view/loan-account-actions/withdrawn-by-client/withdrawn-by-client.component';
/** Dialog Components */
import { LoansAccountViewGuarantorDetailsDialogComponent } from './custom-dialog/loans-account-view-guarantor-details-dialog/loans-account-view-guarantor-details-dialog.component';
@@ -102,6 +103,7 @@ import { LoansConfirmationDialogBoxComponent } from './custom-dialog/loans-confi
DisburseLoanAccountComponent,
RejectLoanComponent,
DisburseComponent,
WithdrawnByClientComponent,
],
entryComponents: [
LoansAccountAddCollateralDialogComponent,