diff --git a/src/app/organization/organization-routing.module.ts b/src/app/organization/organization-routing.module.ts index dbd4abae6..64dd1169f 100644 --- a/src/app/organization/organization-routing.module.ts +++ b/src/app/organization/organization-routing.module.ts @@ -22,6 +22,7 @@ import { ViewAdhocQueryComponent } from './adhoc-query/view-adhoc-query/view-adh import { TellersComponent } from './tellers/tellers.component'; import { ViewTellerComponent } from './tellers/view-teller/view-teller.component'; import { PaymentTypesComponent } from './payment-types/payment-types.component'; +import { EditPaymentTypeComponent } from './payment-types/edit-payment-type/edit-payment-type.component'; import { PasswordPreferencesComponent } from './password-preferences/password-preferences.component'; import { EntityDataTableChecksComponent } from './entity-data-table-checks/entity-data-table-checks.component'; import { WorkingDaysComponent } from './working-days/working-days.component'; @@ -40,6 +41,7 @@ import { AdhocQueryResolver } from './adhoc-query/adhoc-query.resolver'; import { TellersResolver } from './tellers/tellers.resolver'; import { TellerResolver } from './tellers/teller.resolver'; import { PaymentTypesResolver } from './payment-types/payment-types.resolver'; +import { PaymentTypeResolver } from './payment-types/payment-type.resolver'; import { PasswordPreferencesTemplateResolver } from './password-preferences/password-preferences-template.resolver'; import { EntityDataTableChecksResolver } from './entity-data-table-checks/entity-data-table-checks.resolver'; import { WorkingDaysResolver } from './working-days/working-days.resolver'; @@ -186,6 +188,20 @@ const routes: Routes = [ path: 'create', component: CreatePaymentTypeComponent, data: { title: extract('Create Payment Type'), breadcrumb: 'Create Payment Type'} + }, + { + path: ':id', + data: { routeParamBreadcrumb: 'id', addBreadcrumbLink: false }, + children: [ + { + path: 'edit', + component: EditPaymentTypeComponent, + data: { title: extract('Edit Payment Type'), breadcrumb: 'Edit', routeParamBreadcrumb: false }, + resolve: { + paymentType: PaymentTypeResolver + } + } + ] } ] }, @@ -238,6 +254,7 @@ const routes: Routes = [ TellersResolver, TellerResolver, PaymentTypesResolver, + PaymentTypeResolver, PasswordPreferencesTemplateResolver, EntityDataTableChecksResolver, WorkingDaysResolver diff --git a/src/app/organization/organization.module.ts b/src/app/organization/organization.module.ts index a72a8ed95..63c640389 100644 --- a/src/app/organization/organization.module.ts +++ b/src/app/organization/organization.module.ts @@ -18,6 +18,7 @@ import { ViewAdhocQueryComponent } from './adhoc-query/view-adhoc-query/view-adh import { TellersComponent } from './tellers/tellers.component'; import { ViewTellerComponent } from './tellers/view-teller/view-teller.component'; import { PaymentTypesComponent } from './payment-types/payment-types.component'; +import { EditPaymentTypeComponent } from './payment-types/edit-payment-type/edit-payment-type.component'; import { PasswordPreferencesComponent } from './password-preferences/password-preferences.component'; import { EntityDataTableChecksComponent } from './entity-data-table-checks/entity-data-table-checks.component'; import { WorkingDaysComponent } from './working-days/working-days.component'; @@ -49,6 +50,7 @@ import { ViewEmployeeComponent } from './employees/view-employee/view-employee.c TellersComponent, ViewTellerComponent, PaymentTypesComponent, + EditPaymentTypeComponent, PasswordPreferencesComponent, EntityDataTableChecksComponent, WorkingDaysComponent, diff --git a/src/app/organization/organization.service.ts b/src/app/organization/organization.service.ts index d975c910d..17c1cf26d 100644 --- a/src/app/organization/organization.service.ts +++ b/src/app/organization/organization.service.ts @@ -146,6 +146,22 @@ export class OrganizationService { return this.http.delete(`/paymenttypes/${paymentTypeId}`); } + /** + * @param {string} paymentTypeId Payment type ID of payment type. + * @returns {Observable} Payment type. + */ + getPaymentType(paymentTypeId: string): Observable { + return this.http.get(`/paymenttypes/${paymentTypeId}`); + } + + /** + * @param {string} paymentTypeId Payment type ID of Payment Type to be edited. + * @returns {Observable} + */ + updatePaymentType(paymentTypeId: string, paymentType: any): Observable { + return this.http.put(`/paymenttypes/${paymentTypeId}`, paymentType); + } + /** * @returns {Observable} Password Preferences Template data */ diff --git a/src/app/organization/payment-types/edit-payment-type/edit-payment-type.component.html b/src/app/organization/payment-types/edit-payment-type/edit-payment-type.component.html new file mode 100644 index 000000000..65f6d7a41 --- /dev/null +++ b/src/app/organization/payment-types/edit-payment-type/edit-payment-type.component.html @@ -0,0 +1,49 @@ +
+ + + +
+ + + +
+ + + Payment Type + + + Payment Type is required + + + + + Description + + + + + Is Cash Payment? + + + + Position + + + Position is required + + + +
+ +
+ + + + + + +
+ +
+ +
diff --git a/src/app/organization/payment-types/edit-payment-type/edit-payment-type.component.scss b/src/app/organization/payment-types/edit-payment-type/edit-payment-type.component.scss new file mode 100644 index 000000000..345d8f51c --- /dev/null +++ b/src/app/organization/payment-types/edit-payment-type/edit-payment-type.component.scss @@ -0,0 +1,7 @@ +.container { + max-width: 37rem; +} + +.status { + padding: 17.5px 0 17.5px 0; +} diff --git a/src/app/organization/payment-types/edit-payment-type/edit-payment-type.component.spec.ts b/src/app/organization/payment-types/edit-payment-type/edit-payment-type.component.spec.ts new file mode 100644 index 000000000..19b5e34ca --- /dev/null +++ b/src/app/organization/payment-types/edit-payment-type/edit-payment-type.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { EditPaymentTypeComponent } from './edit-payment-type.component'; + +describe('EditPaymentTypeComponent', () => { + let component: EditPaymentTypeComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ EditPaymentTypeComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(EditPaymentTypeComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/organization/payment-types/edit-payment-type/edit-payment-type.component.ts b/src/app/organization/payment-types/edit-payment-type/edit-payment-type.component.ts new file mode 100644 index 000000000..b0b71a613 --- /dev/null +++ b/src/app/organization/payment-types/edit-payment-type/edit-payment-type.component.ts @@ -0,0 +1,70 @@ +/** Angular Imports */ +import { Component, OnInit } from '@angular/core'; +import { FormGroup, FormBuilder, Validators } from '@angular/forms'; +import { Router, ActivatedRoute } from '@angular/router'; + +/** Custom Services */ +import { OrganizationService } from 'app/organization/organization.service'; + +/** + * Edit Payment Type component. + */ +@Component({ + selector: 'mifosx-edit-payment-type', + templateUrl: './edit-payment-type.component.html', + styleUrls: ['./edit-payment-type.component.scss'] +}) +export class EditPaymentTypeComponent implements OnInit { + + /** Payment Type form. */ + paymentTypeForm: FormGroup; + /** Payment Type Data. */ + paymentTypeData: any; + + /** + * Retrieves the payment type data from `resolve`. + * @param {FormBuilder} formBuilder Form Builder. + * @param {OrganizationService} organizationService Organization Service. + * @param {ActivatedRoute} route Activated Route. + * @param {Router} router Router for navigation. + */ + constructor(private formBuilder: FormBuilder, + private organizationService: OrganizationService, + private router: Router, + private route: ActivatedRoute) { + this.route.data.subscribe(( data: { paymentType: any }) => { + this.paymentTypeData = data.paymentType; + }); + } + + /** + * Creates and sets the payment type form. + */ + ngOnInit() { + this.createPaymentTypeForm(); + } + + /** + * Creates the payment type form. + */ + createPaymentTypeForm() { + this.paymentTypeForm = this.formBuilder.group({ + 'name': [this.paymentTypeData.name, Validators.required], + 'description': [this.paymentTypeData.description], + 'isCashPayment': [this.paymentTypeData.isCashPayment], + 'position': [this.paymentTypeData.position, Validators.required], + }); + } + + /** + * Submits the payment type form and updates payment type. + * if successful redirects to payment types. + */ + submit() { + const paymentType = this.paymentTypeForm.value; + this.organizationService.updatePaymentType(this.paymentTypeData.id, paymentType).subscribe(response => { + this.router.navigate(['../../'], { relativeTo: this.route }); + }); + } + +} diff --git a/src/app/organization/payment-types/payment-type.resolver.ts b/src/app/organization/payment-types/payment-type.resolver.ts new file mode 100644 index 000000000..d30645e3f --- /dev/null +++ b/src/app/organization/payment-types/payment-type.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 { OrganizationService } from 'app/organization/organization.service'; + +/** + * Payment Type data resolver. + */ +@Injectable() +export class PaymentTypeResolver implements Resolve { + + /** + * @param {OrganizationService} organizationService Organization service. + */ + constructor(private organizationService: OrganizationService) {} + + /** + * Returns the payment type data. + * @returns {Observable} + */ + resolve(route: ActivatedRouteSnapshot): Observable { + const paymentTypeId = route.paramMap.get('id'); + return this.organizationService.getPaymentType(paymentTypeId); + } + +} diff --git a/src/app/organization/payment-types/payment-types.component.html b/src/app/organization/payment-types/payment-types.component.html index dcb27bae3..5f95f3d27 100644 --- a/src/app/organization/payment-types/payment-types.component.html +++ b/src/app/organization/payment-types/payment-types.component.html @@ -48,7 +48,7 @@ Actions -