diff --git a/src/app/clients/clients-routing.module.ts b/src/app/clients/clients-routing.module.ts index df5ce2132..9e9c316a2 100644 --- a/src/app/clients/clients-routing.module.ts +++ b/src/app/clients/clients-routing.module.ts @@ -45,6 +45,8 @@ import { ClientActionsResolver } from './common-resolvers/client-actions.resolve import { TakeSurveyResolver } from './common-resolvers/take-survey.resolver'; import { ViewChargeComponent } from './clients-view/view-charge/view-charge.component'; import { ClientChargeViewResolver } from './common-resolvers/client-charge-view.resolver'; +import { ClientPayChargesComponent } from './clients-view/client-pay-charges/client-pay-charges.component'; +import { ClientTransactionPayResolver } from './common-resolvers/client-transaction-pay.resolver'; const routes: Routes = [ Route.withShell([{ @@ -246,7 +248,8 @@ const routes: Routes = [ ClientChargeOverviewResolver, ClientActionsResolver, TakeSurveyResolver, - ClientChargeViewResolver + ClientChargeViewResolver, + ClientTransactionPayResolver ] }) export class ClientsRoutingModule { } diff --git a/src/app/clients/clients-view/client-pay-charges/client-pay-charges.component.html b/src/app/clients/clients-view/client-pay-charges/client-pay-charges.component.html new file mode 100644 index 000000000..abfbd971e --- /dev/null +++ b/src/app/clients/clients-view/client-pay-charges/client-pay-charges.component.html @@ -0,0 +1,34 @@ +
+ +
+ +
+ + + Amount + + + Amount is required + + + + + Transaction date + + + + + Transaction date is required + + + +
+ +
+ + +
+ +
+ +
diff --git a/src/app/clients/clients-view/client-pay-charges/client-pay-charges.component.scss b/src/app/clients/clients-view/client-pay-charges/client-pay-charges.component.scss new file mode 100644 index 000000000..71a761bce --- /dev/null +++ b/src/app/clients/clients-view/client-pay-charges/client-pay-charges.component.scss @@ -0,0 +1,4 @@ +.tab-container { + padding: 1%; + margin: 1%; +} diff --git a/src/app/clients/clients-view/client-pay-charges/client-pay-charges.component.spec.ts b/src/app/clients/clients-view/client-pay-charges/client-pay-charges.component.spec.ts new file mode 100644 index 000000000..4d8f0cc64 --- /dev/null +++ b/src/app/clients/clients-view/client-pay-charges/client-pay-charges.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { ClientPayChargesComponent } from './client-pay-charges.component'; + +describe('ClientPayChargesComponent', () => { + let component: ClientPayChargesComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ ClientPayChargesComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(ClientPayChargesComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/clients/clients-view/client-pay-charges/client-pay-charges.component.ts b/src/app/clients/clients-view/client-pay-charges/client-pay-charges.component.ts new file mode 100644 index 000000000..337cb3889 --- /dev/null +++ b/src/app/clients/clients-view/client-pay-charges/client-pay-charges.component.ts @@ -0,0 +1,77 @@ +/** Angular Imports */ +import { Component, OnInit } from '@angular/core'; +import { FormBuilder, Validators } from '@angular/forms'; +import { ActivatedRoute, Router } from '@angular/router'; +import { DatePipe } from '@angular/common'; + +/** Custom Services. */ +import { ClientsService } from 'app/clients/clients.service'; + +/** + * Client Pay Charge component. + */ +@Component({ + selector: 'mifosx-client-pay-charges', + templateUrl: './client-pay-charges.component.html', + styleUrls: ['./client-pay-charges.component.scss'] +}) +export class ClientPayChargesComponent implements OnInit { + + /** Transaction Form. */ + transactionForm: any; + /** Transaction Data. */ + transactionData: any; + /** Minimum Date allowed. */ + minDate = new Date(2000, 0, 1); + + /** + * Retrieves the charge data from `resolve`. + * @param {ClientService} clientService Products Service. + * @param {FormBuilder} formBuilder Form Builder. + * @param {ActivatedRoute} route Activated Route. + * @param {Router} router Router for navigation. + */ + constructor( + private clientsService: ClientsService, + private formBuilder: FormBuilder, + private route: ActivatedRoute, + private router: Router, + private datePipe: DatePipe + ) { + this.route.data.subscribe((data: { transactionData: any }) => { + this.transactionData = data.transactionData; + }); + } + + ngOnInit() { + this.setTransactionForm(); + } + + /** + * Set Transaction Form. + */ + setTransactionForm() { + this.transactionForm = this.formBuilder.group({ + 'amount': [this.transactionData.amount, Validators.required], + 'transactionDate': [new Date(), Validators.required] + }); + } + + /** + * Submits Transaction form. + */ + submit() { + const transactionDate = this.transactionForm.value.transactionDate; + const dateFormat = 'yyyy-MM-dd'; + this.transactionForm.patchValue({ + transactionDate: this.datePipe.transform(transactionDate, dateFormat) + }); + const transactions = this.transactionForm.value; + transactions.locale = 'en'; + transactions.dateFormat = dateFormat; + this.clientsService.payClientCharge(this.transactionData.clientId, this.transactionData.id, transactions).subscribe(() => { + this.router.navigate(['../', 'general']); + }); + } + +} diff --git a/src/app/clients/clients-view/general-tab/general-tab.component.html b/src/app/clients/clients-view/general-tab/general-tab.component.html index b80a988c7..26f1fab8a 100644 --- a/src/app/clients/clients-view/general-tab/general-tab.component.html +++ b/src/app/clients/clients-view/general-tab/general-tab.component.html @@ -157,6 +157,7 @@ + diff --git a/src/app/clients/clients.module.ts b/src/app/clients/clients.module.ts index ca087d347..97fa8ad1e 100644 --- a/src/app/clients/clients.module.ts +++ b/src/app/clients/clients.module.ts @@ -43,6 +43,7 @@ import { ReactivateClientComponent } from './clients-view/client-actions/reactiv import { UndoClientRejectionComponent } from './clients-view/client-actions/undo-client-rejection/undo-client-rejection.component'; import { AddClientChargeComponent } from './clients-view/client-actions/add-client-charge/add-client-charge.component'; import { ViewChargeComponent } from './clients-view/view-charge/view-charge.component'; +import { ClientPayChargesComponent } from './clients-view/client-pay-charges/client-pay-charges.component'; /** @@ -91,7 +92,8 @@ import { ViewChargeComponent } from './clients-view/view-charge/view-charge.comp ReactivateClientComponent, UndoClientRejectionComponent, AddClientChargeComponent, - ViewChargeComponent + ViewChargeComponent, + ClientPayChargesComponent ], entryComponents: [ UploadDocumentDialogComponent, diff --git a/src/app/clients/clients.service.ts b/src/app/clients/clients.service.ts index 30d146bdf..fee005104 100644 --- a/src/app/clients/clients.service.ts +++ b/src/app/clients/clients.service.ts @@ -122,6 +122,24 @@ export class ClientsService { return this.http.delete(`/clients/${clientId}/charges/${chargeId}?associations=all`); } + /* + * @param clientId Client Id of payer. + * @param chargeId Charge Id of the charge to be paid. + */ + getClientTransactionPay(clientId: string, chargeId: string) { + return this.http.get(`/clients/${clientId}/charges/${chargeId}`); + } + + /** + * @param clientId Client Id of the payment. + * @param chargeId Charge Id of the payment. + * @param payment Client Payment data. + */ + payClientCharge(clientId: string, chargeId: string, payment: any) { + const httpParams = new HttpParams().set('command', 'paycharge'); + return this.http.post(`/clients/${clientId}/charges/${chargeId}?command=paycharge`, payment, { params: httpParams }); + } + getClientSummary(clientId: string) { const httpParams = new HttpParams().set('R_clientId', clientId) .set('genericResultSet', 'false'); diff --git a/src/app/clients/common-resolvers/client-transaction-pay.resolver.ts b/src/app/clients/common-resolvers/client-transaction-pay.resolver.ts new file mode 100644 index 000000000..c33fa0822 --- /dev/null +++ b/src/app/clients/common-resolvers/client-transaction-pay.resolver.ts @@ -0,0 +1,32 @@ +/** Angular Imports */ +import { Injectable } from '@angular/core'; +import { Resolve, ActivatedRouteSnapshot } from '@angular/router'; + +/** rxjs Imports */ +import { Observable } from 'rxjs'; + +/** Custom Services */ +import { ClientsService } from '../clients.service'; + +/** + * Client Transaction data resolver. + */ +@Injectable() +export class ClientTransactionPayResolver implements Resolve { + + /** + * @param {ClientsService} ClientsService Clients service. + */ + constructor(private clientsService: ClientsService) { } + + /** + * Returns the Client Transaction data. + * @returns {Observable} + */ + resolve(route: ActivatedRouteSnapshot): Observable { + const clientId = route.parent.parent.parent.paramMap.get('clientId'); + const chargeId = route.paramMap.get('chargeId'); + return this.clientsService.getClientTransactionPay(clientId, chargeId); + } + +}