diff --git a/src/app/loans/common-resolvers/loan-notes-resolver.ts b/src/app/loans/common-resolvers/loan-notes-resolver.ts new file mode 100644 index 000000000..5008b80d9 --- /dev/null +++ b/src/app/loans/common-resolvers/loan-notes-resolver.ts @@ -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 LoanNotesResolver implements Resolve { + + /** + * @param {LoansService} LoansService Loans service. + */ + constructor(private loansService: LoansService) { } + + /** + * Returns the Loans data. + * @returns {Observable} + */ + resolve(route: ActivatedRouteSnapshot): Observable { + const loanId = route.parent.paramMap.get('loanId'); + return this.loansService.getLoanNotes(loanId); + } + +} diff --git a/src/app/loans/loans-routing.module.ts b/src/app/loans/loans-routing.module.ts index 943a958d7..e68435456 100644 --- a/src/app/loans/loans-routing.module.ts +++ b/src/app/loans/loans-routing.module.ts @@ -10,11 +10,13 @@ import { AddLoanChargeComponent } from './add-loan-charge/add-loan-charge.compon import { LoansViewComponent } from './loans-view/loans-view.component'; import { GeneralTabComponent } from './loans-view/general-tab/general-tab.component'; import { AccountDetailsComponent } from './loans-view/account-details/account-details.component'; +import { NotesTabComponent } from './loans-view/notes-tab/notes-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'; const routes: Routes = [ { @@ -45,6 +47,14 @@ const routes: Routes = [ loanDetailsData: LoanDetailsGeneralResolver } }, + { + path: 'notes', + component: NotesTabComponent, + data: { title: extract('Notes'), breadcrumb: 'Notes', routeParamBreadcrumb: false }, + resolve: { + loanNotes: LoanNotesResolver + } + }, { path: 'add-loan-charge', component: AddLoanChargeComponent, @@ -64,7 +74,8 @@ const routes: Routes = [ providers: [ LoanChargeTemplateResolver, LoanDetailsGeneralResolver, - LoanDetailsResolver + LoanDetailsResolver, + LoanNotesResolver ] }) diff --git a/src/app/loans/loans-view/general-tab/general-tab.component.scss b/src/app/loans/loans-view/general-tab/general-tab.component.scss index 38c0d86ff..6d8f631f5 100644 --- a/src/app/loans/loans-view/general-tab/general-tab.component.scss +++ b/src/app/loans/loans-view/general-tab/general-tab.component.scss @@ -1,22 +1,22 @@ .tab-container { + padding: 1%; + margin: 1%; + + h3{ + margin:1% auto; + } + .performance-history-container { + border: 1px solid; padding: 1%; - margin: 1%; + margin-bottom: 20px ; + } - h3{ - margin:1% auto; - } - .performance-history-container { - border: 1px solid; - padding: 1%; - margin-bottom: 20px ; - } - - table { - width: 100%; - margin-bottom: 20px; - } + table { + width: 100%; + margin-bottom: 20px; + } } span { - margin: 0.5em 0; + margin: 0.5em 0; } diff --git a/src/app/loans/loans-view/loans-view.component.html b/src/app/loans/loans-view/loans-view.component.html index 19bb41eb2..c99241bca 100644 --- a/src/app/loans/loans-view/loans-view.component.html +++ b/src/app/loans/loans-view/loans-view.component.html @@ -1,61 +1,68 @@ - - -
- -
-
-

- - Loan Product: {{loanDetailsData.loanProductName}}(#{{loanDetailsData.accountNo}}) -
- Client Name: {{loanDetailsData.clientName}}
- Group Name: {{loanDetailsData.group.name}} -

-
+ -
-

Loan Account OverView

- Current Balance: {{loanDetailsData.currency.displaySymbol}} {{loanDetailsData.summary.totalOutstanding | number}}
- Arrears By: {{loanDetailsData.summary.totalOverdue | number}} - Not Provided -
-
-
-
+ +
+ +
+ +
+

+ + Loan Product: {{loanDetailsData.loanProductName}}(#{{loanDetailsData.accountNo}}) +
+ Client Name: {{loanDetailsData.clientName}}
+ Group Name: {{loanDetailsData.group.name}} +

- - +
+

Loan Account OverView

+ Current Balance: {{loanDetailsData.currency.displaySymbol}} {{loanDetailsData.summary.totalOutstanding | number}}
+ Arrears By: {{loanDetailsData.summary.totalOverdue | number}} + Not Provided +
+
- - - +
+
+
+
- - - - - - - - + - + + + - + + + + + + + + + + + + + + + + + - - - - diff --git a/src/app/loans/loans-view/notes-tab/notes-tab.component.html b/src/app/loans/loans-view/notes-tab/notes-tab.component.html new file mode 100644 index 000000000..9b3a788bf --- /dev/null +++ b/src/app/loans/loans-view/notes-tab/notes-tab.component.html @@ -0,0 +1,32 @@ +
+

Notes

+
+
+ + + + +
+
+ + + +

{{loanNote.note}}

+

+ Created by: {{loanNote.createdByUsername}}
+ Date: {{loanNote.createdOn | date}} +

+
+ + +
+
+
+
diff --git a/src/app/loans/loans-view/notes-tab/notes-tab.component.scss b/src/app/loans/loans-view/notes-tab/notes-tab.component.scss new file mode 100644 index 000000000..b40728956 --- /dev/null +++ b/src/app/loans/loans-view/notes-tab/notes-tab.component.scss @@ -0,0 +1,4 @@ +.tab-container { + padding: 1%; + margin: 1%; +} diff --git a/src/app/loans/loans-view/notes-tab/notes-tab.component.spec.ts b/src/app/loans/loans-view/notes-tab/notes-tab.component.spec.ts new file mode 100644 index 000000000..add42af72 --- /dev/null +++ b/src/app/loans/loans-view/notes-tab/notes-tab.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { NotesTabComponent } from './notes-tab.component'; + +describe('NotesTabComponent', () => { + let component: NotesTabComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ NotesTabComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(NotesTabComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/loans/loans-view/notes-tab/notes-tab.component.ts b/src/app/loans/loans-view/notes-tab/notes-tab.component.ts new file mode 100644 index 000000000..515213386 --- /dev/null +++ b/src/app/loans/loans-view/notes-tab/notes-tab.component.ts @@ -0,0 +1,104 @@ +import { Component, OnInit, ViewChild } from '@angular/core'; +import { ActivatedRoute } from '@angular/router'; +import { MatDialog } from '@angular/material'; +import { FormGroup, FormBuilder, Validators } from '@angular/forms'; + +/** Custom Components */ +import { DeleteDialogComponent } from '../../../shared/delete-dialog/delete-dialog.component'; +import { FormDialogComponent } from 'app/shared/form-dialog/form-dialog.component'; + +/** Custom Services */ +import { LoansService } from '../../loans.service'; +import { AuthenticationService } from '../../../core/authentication/authentication.service'; + +@Component({ + selector: 'mifosx-notes-tab', + templateUrl: './notes-tab.component.html', + styleUrls: ['./notes-tab.component.scss'] +}) +export class NotesTabComponent implements OnInit { + + loanId: string; + username: string; + loanNotes: any; + noteForm: FormGroup; + @ViewChild('formRef') formRef: any; + + + constructor(private route: ActivatedRoute, + private formBuilder: FormBuilder, + private loansService: LoansService, + private authenticationService: AuthenticationService, + private dialog: MatDialog) { + const savedCredentials = this.authenticationService.getCredentials(); + this.username = savedCredentials.username; + this.loanId = this.route.parent.snapshot.params['loanId']; + this.route.data.subscribe((data: { loanNotes: any }) => { + this.loanNotes = data.loanNotes; + console.log('notes: ', this.loanNotes); + + }); + } + + ngOnInit() { + this.createNoteForm(); + } + + createNoteForm() { + this.noteForm = this.formBuilder.group({ + 'note': ['', Validators.required] + }); + } + + submit() { + this.loansService.createLoanNote(this.loanId, this.noteForm.value).subscribe((response: any) => { + this.loanNotes.push({ + id: response.resourceId, + createdByUsername: this.username, + createdOn: new Date(), + note: this.noteForm.value.note + }); + this.formRef.resetForm(); + }); + } + + editNote(noteId: string, noteContent: string, index: number) { + const editNoteDialogRef = this.dialog.open(FormDialogComponent, { + data: { formfields: [{ + controlName: 'note', + required: true, + value: noteContent, + controlType: 'input', + label: 'Note' + }], + layout: { + columns: 1, + addButtonText: 'Confirm' + }, + title: 'Edit Note' + } + }); + editNoteDialogRef.afterClosed().subscribe((response: any) => { + if (response.data) { + this.loansService.editLoanNote(this.loanId, noteId, response.data.value).subscribe(() => { + this.loanNotes[index].note = response.data.value.note; + }); + } + }); + } + + deleteNote(noteId: string, index: number) { + const deleteNoteDialogRef = this.dialog.open(DeleteDialogComponent, { + data: { deleteContext: `Note id:${noteId}` } + }); + deleteNoteDialogRef.afterClosed().subscribe((response: any) => { + if (response.delete) { + this.loansService.deleteLoanNote(this.loanId, noteId) + .subscribe(() => { + this.loanNotes.splice(index, 1); + }); + } + }); + } + +} diff --git a/src/app/loans/loans.module.ts b/src/app/loans/loans.module.ts index cb81e8bfc..381d4cbfb 100644 --- a/src/app/loans/loans.module.ts +++ b/src/app/loans/loans.module.ts @@ -13,6 +13,7 @@ import { AddLoanChargeComponent } from './add-loan-charge/add-loan-charge.compon import { LoansViewComponent } from './loans-view/loans-view.component'; import { GeneralTabComponent } from './loans-view/general-tab/general-tab.component'; import { AccountDetailsComponent } from './loans-view/account-details/account-details.component'; +import { NotesTabComponent } from './loans-view/notes-tab/notes-tab.component'; /** * Loans Module @@ -26,6 +27,7 @@ import { AccountDetailsComponent } from './loans-view/account-details/account-de LoansViewComponent, GeneralTabComponent, AccountDetailsComponent, + NotesTabComponent, ], providers: [DatePipe], }) diff --git a/src/app/loans/loans.service.ts b/src/app/loans/loans.service.ts index a979e0f9c..540be6f43 100644 --- a/src/app/loans/loans.service.ts +++ b/src/app/loans/loans.service.ts @@ -33,4 +33,41 @@ export class LoansService { return this.http.get(`/loans/${loanId}`); } + /** + * @param loanId Loan Id + * @returns The notes for particular loan + */ + getLoanNotes(loanId: string): Observable { + return this.http.get(`/loans/${loanId}/notes`); + } + + /** + * Adds a note to the particular Loan Id + * @param loanId Loan ID + * @param noteData Note Data to be added + * @returns {Observable} + */ + createLoanNote(loanId: string, noteData: any): Observable { + return this.http.post(`/loans/${loanId}/notes`, noteData); + } + + /** + * Edits the Loan Note + * @param loanId Loan ID + * @param noteId Note ID + * @param noteData Note Data + */ + editLoanNote(loanId: string, noteId: string, noteData: any) { + return this.http.put(`/loans/${loanId}/notes/${noteId}`, noteData); + } + + /** + * Deletes the particular Note + * @param loanId Loan ID + * @param noteId Note ID + */ + deleteLoanNote(loanId: string, noteId: string) { + return this.http.delete(`/loans/${loanId}/notes/${noteId}`); + } + }