feat: add view loan (loan documents tab) (#1126)

Fixes: #818
This commit is contained in:
Muskan Khedia
2020-07-17 21:07:11 +05:30
committed by GitHub
parent a13510dae1
commit 48709edba0
16 changed files with 381 additions and 8 deletions
@@ -26,7 +26,7 @@ export class LoanActionButtonResolver implements Resolve<Object> {
resolve(route: ActivatedRouteSnapshot): Observable<any> {
const loanId = route.parent.paramMap.get('loanId');
const loanActionButton = route.paramMap.get('action');
if (loanActionButton === 'assign-loan-officer') {
if (loanActionButton === 'assign-loan-officer' || loanActionButton === 'change-loan-officer') {
return this.loansService.getLoanTemplate(loanId);
// } else if (loanActionButton === 'make-repayment') {
// return this.loansService.getLoanActionTemplate(loanId, 'repayment');
@@ -0,0 +1,31 @@
/** Angular Imports */
import { Injectable } from '@angular/core';
import { Resolve, ActivatedRouteSnapshot } from '@angular/router';
/** rxjs Imports */
import { Observable } from 'rxjs';
/** Custom Services */
import { LoansService } from '../loans.service';
/**
* Loans notes resolver.
*/
@Injectable()
export class LoanDocumentsResolver implements Resolve<Object> {
/**
* @param {LoansService} LoansService Loans service.
*/
constructor(private loansService: LoansService) { }
/**
* Returns the Loans data.
* @returns {Observable<any>}
*/
resolve(route: ActivatedRouteSnapshot): Observable<any> {
const loanId = route.parent.paramMap.get('loanId');
return this.loansService.getLoanDocuments(loanId);
}
}
@@ -0,0 +1,28 @@
<h1 mat-dialog-title>Load Loan Document</h1>
<div>
<form [formGroup]="uploadDocumentForm" fxLayout="column">
<mat-form-field fxFlex>
<mat-label>File Name</mat-label>
<input formControlName="name" required matInput />
<mat-error *ngIf="uploadDocumentForm.controls.name.hasError('required')">
File Name is <strong>required</strong>
</mat-error>
</mat-form-field>
<mat-form-field fxFlex>
<mat-label>Description</mat-label>
<input formControlName="description" matInput />
</mat-form-field>
<mifosx-file-upload flex="60%" (change)="onFileSelect($event)"></mifosx-file-upload>
<mat-dialog-actions align="end">
<button mat-raised-button mat-dialog-close>Cancel</button>
<button mat-raised-button color="primary" [disabled]="!uploadDocumentForm.valid"
[mat-dialog-close]="{data: {name: uploadDocumentForm.value.name, description: uploadDocumentForm.value.description, file: uploadDocumentForm.value.file} }">Confirm</button>
</mat-dialog-actions>
</form>
</div>
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { LoanAccountLoadDocumentsDialogComponent } from './loan-account-load-documents-dialog.component';
describe('LoanAccountLoadDocumentsDialogComponent', () => {
let component: LoanAccountLoadDocumentsDialogComponent;
let fixture: ComponentFixture<LoanAccountLoadDocumentsDialogComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ LoanAccountLoadDocumentsDialogComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(LoanAccountLoadDocumentsDialogComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,51 @@
import { Component, OnInit, Inject } from '@angular/core';
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material';
import { FormGroup, FormBuilder, Validators, FormControl } from '@angular/forms';
@Component({
selector: 'mifosx-loan-account-load-documents-dialog',
templateUrl: './loan-account-load-documents-dialog.component.html',
styleUrls: ['./loan-account-load-documents-dialog.component.scss']
})
export class LoanAccountLoadDocumentsDialogComponent implements OnInit {
/** Upload Document form. */
uploadDocumentForm: FormGroup;
/**
* @param {MatDialogRef} dialogRef Dialog reference element
* @param {FormBuilder} formBuilder Form Builder
* @param {any} data Dialog Data
*/
constructor(public dialogRef: MatDialogRef<LoanAccountLoadDocumentsDialogComponent>,
private formBuilder: FormBuilder,
@Inject(MAT_DIALOG_DATA) public data: any) {
}
ngOnInit() {
this.createUploadDocumentForm();
}
/**
* Creates the upload Document form.
*/
createUploadDocumentForm() {
this.uploadDocumentForm = this.formBuilder.group({
'name': ['', Validators.required],
'description': [''],
'file': ['']
});
}
/**
* Sets file form control value.
* @param {any} $event file change event.
*/
onFileSelect($event: any) {
if ($event.target.files.length > 0) {
const file = $event.target.files[0];
this.uploadDocumentForm.get('file').setValue(file);
}
}
}
+14 -3
View File
@@ -22,18 +22,19 @@ import { FloatingInterestRatesComponent } from './loans-view/floating-interest-r
import { LoanTrancheDetailsComponent } from './loans-view/loan-tranche-details/loan-tranche-details.component';
import { LoanCollateralTabComponent } from './loans-view/loan-collateral-tab/loan-collateral-tab.component';
import { CreateLoansAccountComponent } from './create-loans-account/create-loans-account.component';
import { RejectLoanComponent } from './loans-view/loan-account-actions/reject-loan/reject-loan.component';
import { LoanDocumentsTabComponent } from './loans-view/loan-documents-tab/loan-documents-tab.component';
/** Custom Resolvers */
import { LoanChargeTemplateResolver } from './common-resolvers/loan-charge-template.resolver';
import { LoanDetailsResolver } from './common-resolvers/loan-details.resolver';
import { LoanDetailsGeneralResolver } from './common-resolvers/loan-details-general.resolver';
import { LoanNotesResolver } from './common-resolvers/loan-notes-resolver';
import { LoanNotesResolver } from './common-resolvers/loan-notes.resolver';
import { LoanDetailsChargesResolver } from './common-resolvers/loan-details-charges.resolver';
import { LoanDatatablesResolver } from './common-resolvers/loan-datatables.resolver';
import { LoanDatatableResolver } from './common-resolvers/loan-datatable.resolver';
import { LoanActionButtonResolver } from './common-resolvers/loan-action-button.resolver';
import { LoansAccountTemplateResolver } from './common-resolvers/loans-account-template.resolver';
import { LoanDocumentsResolver } from './common-resolvers/loan-documents.resolver';
/** Loans Route. */
const routes: Routes = [
@@ -139,6 +140,15 @@ const routes: Routes = [
loanDetailsAssociationData: LoanDetailsChargesResolver
}
},
{
path: 'loan-documents',
component: LoanDocumentsTabComponent,
data: { title: extract('Loan Documents'), breadcrumb: 'Loan Documents', routeParamBreadcrumb: false },
resolve: {
loanDocuments: LoanDocumentsResolver,
loanDetailsData: LoanDetailsGeneralResolver
},
},
{
path: 'notes',
component: NotesTabComponent,
@@ -191,7 +201,8 @@ const routes: Routes = [
LoanDatatablesResolver,
LoanDatatableResolver,
LoanActionButtonResolver,
LoansAccountTemplateResolver
LoansAccountTemplateResolver,
LoanDocumentsResolver
]
})
@@ -0,0 +1,59 @@
<div class="tab-container mat-typography">
<div>
<div fxLayout="column" fxFlex="100%">
<div fxLayout="row" fxLayoutAlign="flex-end">
<button mat-raised-button color="primary" (click)="uploadDocument()" *ngIf="choice">
<fa-icon icon="plus"></fa-icon>&nbsp;&nbsp;Upload
</button>
</div>
</div>
</div>
<ng-container *ngIf="loanDocuments.length > 0">
<table mat-table #documentsTable [dataSource]="dataSource" matSort>
<ng-container matColumnDef="name">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Name </th>
<td mat-cell *matCellDef="let document"> {{ document.name }} </td>
</ng-container>
<ng-container matColumnDef="description">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Description </th>
<td mat-cell *matCellDef="let document"> {{ document.description }} </td>
</ng-container>
<ng-container matColumnDef="filename">
<th mat-header-cell *matHeaderCellDef mat-sort-header> File Name </th>
<td mat-cell *matCellDef="let document"> {{ document.fileName }} </td>
</ng-container>
<ng-container matColumnDef="actions">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Actions </th>
<td mat-cell *matCellDef="let document; let index">
<button class="loan-document-action-button" mat-raised-button color="primary">
<fa-icon icon="cloud-download-alt"></fa-icon>
</button>
<button class="loan-document-action-button" mat-raised-button color="primary" *ngIf="document.fileIsImage">
<i class="fa fa-eye"></i>
</button>
<button class="loan-document-action-button" mat-raised-button color="warn"
(click)="deleteDocument(document.id, index)">
<fa-icon icon="times"></fa-icon>
</button>
</td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
</table>
<mat-paginator [pageSizeOptions]="[10, 25, 50, 100]" showFirstLastButtons></mat-paginator>
</ng-container>
</div>
@@ -0,0 +1,15 @@
table {
width: 100%;
margin-top: 3%;
.account-action-button{
min-width: 26px;
padding: 0 6px;
margin: 4px;
line-height: 25px;
}
}
.tab-container {
padding: 1%;
margin: 1%;
}
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { LoanDocumentsTabComponent } from './loan-documents-tab.component';
describe('LoanDocumentsTabComponent', () => {
let component: LoanDocumentsTabComponent;
let fixture: ComponentFixture<LoanDocumentsTabComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ LoanDocumentsTabComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(LoanDocumentsTabComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,110 @@
/** Angular Imports */
import { Component, OnInit, ViewChild } from '@angular/core';
import { MatTableDataSource, MatPaginator, MatSort, MatDialog, MatTable } from '@angular/material';
import { ActivatedRoute } from '@angular/router';
/** Custom Services */
import { environment } from 'environments/environment';
import { LoansService } from 'app/loans/loans.service';
/** Dialog Components */
import { LoanAccountLoadDocumentsDialogComponent } from 'app/loans/custom-dialog/loan-account-load-documents-dialog/loan-account-load-documents-dialog.component';
import { DeleteDialogComponent } from 'app/shared/delete-dialog/delete-dialog.component';
/**
* Overdue charges tab component
*/
@Component({
selector: 'mifosx-loan-documents-tab',
templateUrl: './loan-documents-tab.component.html',
styleUrls: ['./loan-documents-tab.component.scss']
})
export class LoanDocumentsTabComponent implements OnInit {
@ViewChild('documentsTable') documentsTable: MatTable<Element>;
/** Stores the resolved loan documents data */
loanDocuments: any;
/** Stores the resolved loan details data */
loanDetailsData: any;
/** Status of the loan account */
status: any;
/** Choice */
choice: boolean;
/** Columns to be displayed in loan documents table. */
displayedColumns: string[] = ['name', 'description', 'filename', 'actions'];
/** Data source for loan documents table. */
dataSource: MatTableDataSource<any>;
/** Paginator for codes table. */
@ViewChild(MatPaginator) paginator: MatPaginator;
/** Sorter for codes table. */
@ViewChild(MatSort) sort: MatSort;
/**
* Retrieves the loans data from `resolve`.
* @param {ActivatedRoute} route Activated Route.
*/
constructor(private route: ActivatedRoute,
private loansService: LoansService,
public dialog: MatDialog) {
this.route.data.subscribe((data: { loanDocuments: any, loanDetailsData: any }) => {
this.getLoanDocumentsData(data.loanDocuments);
this.loanDetailsData = data.loanDetailsData;
});
}
ngOnInit() {
this.status = this.loanDetailsData.status.value;
if (this.status === 'Submitted and pending approval' || this.status === 'Active' || this.status === 'Approved') {
this.choice = true;
}
this.dataSource = new MatTableDataSource(this.loanDocuments);
this.dataSource.paginator = this.paginator;
this.dataSource.sort = this.sort;
}
getLoanDocumentsData(data: any) {
data.forEach((ele: any) => {
let loandocs = {};
loandocs = environment.serverUrl + '/loans/' + ele.parentEntityId + '/documents/' + ele.id + '/attachment?tenantIdentifier=' + environment.fineractPlatformTenantId;
ele.docUrl = loandocs;
if (ele.fileName) {
if (ele.fileName.toLowerCase().indexOf('.jpg') !== -1 || ele.fileName.toLowerCase().indexOf('.jpeg') !== -1 || ele.fileName.toLowerCase().indexOf('.png') !== -1) {
ele.fileIsImage = true;
}
}
if (ele.type) {
if (ele.type.toLowerCase().indexOf('image') !== -1) {
ele.fileIsImage = true;
}
}
});
this.loanDocuments = data;
}
uploadDocument() {
const uploadLoanDocumentDialogRef = this.dialog.open(LoanAccountLoadDocumentsDialogComponent);
uploadLoanDocumentDialogRef.afterClosed().subscribe((data: any) => {
if (data) {
this.loansService.loadLoanDocument(this.loanDetailsData.id, data)
.subscribe(() => {});
}
});
}
deleteDocument(documentId: any, index: any) {
const deleteDocumentDialogRef = this.dialog.open(DeleteDialogComponent, {
data: { deleteContext: `document id:${documentId}` }
});
deleteDocumentDialogRef.afterClosed().subscribe((response: any) => {
if (response.delete) {
this.loansService.deleteLoanDocument(this.loanDetailsData.id, documentId).subscribe((res: any) => {
this.loanDocuments.splice(index, 1);
this.documentsTable.renderRows();
});
}
});
}
}
@@ -97,6 +97,9 @@
Charges
</a>
</ng-container>
<a mat-tab-link [routerLink]="['./loan-documents']" routerLinkActive #loanDocuments="routerLinkActive" [active]="loanDocuments.isActive">
Loan Documents
</a>
<a mat-tab-link *mifosxHasPermission="'READ_LOANNOTE'" [routerLink]="['./notes']" routerLinkActive #notes="routerLinkActive" [active]="notes.isActive">
Notes
</a>
@@ -123,8 +123,6 @@ export class LoansViewComponent implements OnInit {
}
loanAction(button: string) {
console.log('button: ', button);
switch (button) {
case 'Recover From Guarantor':
this.recoverFromGuarantor();
+7 -2
View File
@@ -49,12 +49,14 @@ import { DisburseComponent } from './loans-view/loan-account-actions/disburse/di
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';
import { UndoDisbursalComponent } from './loans-view/loan-account-actions/undo-disbursal/undo-disbursal.component';
import { AddCollateralComponent } from './loans-view/loan-account-actions/add-collateral/add-collateral.component';
import { LoanDocumentsTabComponent } from './loans-view/loan-documents-tab/loan-documents-tab.component';
/** Dialog Components */
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';
import { LoanAccountLoadDocumentsDialogComponent } from './custom-dialog/loan-account-load-documents-dialog/loan-account-load-documents-dialog.component';
/**
* Loans Module
@@ -108,11 +110,14 @@ import { AddCollateralComponent } from './loans-view/loan-account-actions/add-co
WithdrawnByClientComponent,
AddCollateralComponent,
UndoDisbursalComponent,
LoanDocumentsTabComponent,
LoanAccountLoadDocumentsDialogComponent,
],
entryComponents: [
LoansAccountAddCollateralDialogComponent,
LoansAccountViewGuarantorDetailsDialogComponent,
LoansConfirmationDialogBoxComponent
LoansConfirmationDialogBoxComponent,
LoanAccountLoadDocumentsDialogComponent
],
providers: [DatePipe],
})
+12
View File
@@ -285,4 +285,16 @@ export class LoansService {
return this.http.post('/loans', loanAccount);
}
getLoanDocuments(loanId: any): Observable<any> {
return this.http.get(`/loans/${loanId}/documents`);
}
deleteLoanDocument(loanId: any, documentId: any): Observable<any> {
return this.http.delete(`/loans/${loanId}/documents/${documentId}`);
}
loadLoanDocument(loanId: any, data: any): Observable<any> {
return this.http.post(`/loans/${loanId}/documents`, data);
}
}