From 15ff035d1376a1950a5f4efb7740d07c11167292 Mon Sep 17 00:00:00 2001 From: Rishabh Verma Date: Sat, 4 Jan 2020 22:44:58 +0530 Subject: [PATCH] feat: add create payment type component (#543) Fixes: #164 --- .../organization-routing.module.ts | 19 ++++-- src/app/organization/organization.module.ts | 4 +- src/app/organization/organization.service.ts | 8 +++ .../create-payment-type.component.html | 49 +++++++++++++++ .../create-payment-type.component.scss | 7 +++ .../create-payment-type.component.spec.ts | 25 ++++++++ .../create-payment-type.component.ts | 63 +++++++++++++++++++ .../payment-types.component.html | 4 +- 8 files changed, 172 insertions(+), 7 deletions(-) create mode 100644 src/app/organization/payment-types/create-payment-type/create-payment-type.component.html create mode 100644 src/app/organization/payment-types/create-payment-type/create-payment-type.component.scss create mode 100644 src/app/organization/payment-types/create-payment-type/create-payment-type.component.spec.ts create mode 100644 src/app/organization/payment-types/create-payment-type/create-payment-type.component.ts diff --git a/src/app/organization/organization-routing.module.ts b/src/app/organization/organization-routing.module.ts index c7b914748..2755547d5 100644 --- a/src/app/organization/organization-routing.module.ts +++ b/src/app/organization/organization-routing.module.ts @@ -23,6 +23,7 @@ import { PasswordPreferencesComponent } from './password-preferences/password-pr import { EntityDataTableChecksComponent } from './entity-data-table-checks/entity-data-table-checks.component'; import { WorkingDaysComponent } from './working-days/working-days.component'; import { CreateOfficeComponent } from './offices/create-office/create-office.component'; +import { CreatePaymentTypeComponent } from './payment-types/create-payment-type/create-payment-type.component'; /** Custom Resolvers */ import { LoanProvisioningCriteriaResolver } from './loan-provisioning-criteria/loan-provisioning-criteria.resolver'; @@ -137,11 +138,21 @@ const routes: Routes = [ }, { path: 'payment-types', - component: PaymentTypesComponent, data: { title: extract('Payment Types'), breadcrumb: 'Payment Types' }, - resolve: { - paymentTypes: PaymentTypesResolver - } + children: [ + { + path: '', + component: PaymentTypesComponent, + resolve: { + paymentTypes: PaymentTypesResolver + } + }, + { + path: 'create', + component: CreatePaymentTypeComponent, + data: { title: extract('Create Payment Type'), breadcrumb: 'Create Payment Type'} + } + ] }, { path: 'password-preferences', diff --git a/src/app/organization/organization.module.ts b/src/app/organization/organization.module.ts index 0c4217a7d..ca488e40c 100644 --- a/src/app/organization/organization.module.ts +++ b/src/app/organization/organization.module.ts @@ -21,6 +21,7 @@ import { EntityDataTableChecksComponent } from './entity-data-table-checks/entit import { WorkingDaysComponent } from './working-days/working-days.component'; import { CreateOfficeComponent } from './offices/create-office/create-office.component'; import { CreateEmployeeComponent } from './employees/create-employee/create-employee.component'; +import { CreatePaymentTypeComponent } from './payment-types/create-payment-type/create-payment-type.component'; /** * Organization Module @@ -47,7 +48,8 @@ import { CreateEmployeeComponent } from './employees/create-employee/create-empl EntityDataTableChecksComponent, WorkingDaysComponent, CreateOfficeComponent, - CreateEmployeeComponent + CreateEmployeeComponent, + CreatePaymentTypeComponent ] }) export class OrganizationModule { } diff --git a/src/app/organization/organization.service.ts b/src/app/organization/organization.service.ts index 4e4815e65..78eb102c8 100644 --- a/src/app/organization/organization.service.ts +++ b/src/app/organization/organization.service.ts @@ -90,6 +90,14 @@ export class OrganizationService { return this.http.get('/paymenttypes'); } + /** + * @param {any} paymentType Payment type to be created. + * @returns {Observable} + */ + createPaymentType(paymentType: any): Observable { + return this.http.post('/paymenttypes', paymentType); + } + /** * @param {string} paymentTypeId Payment type ID of payment type to be deleted. * @returns {Observable} diff --git a/src/app/organization/payment-types/create-payment-type/create-payment-type.component.html b/src/app/organization/payment-types/create-payment-type/create-payment-type.component.html new file mode 100644 index 000000000..860aa9c5f --- /dev/null +++ b/src/app/organization/payment-types/create-payment-type/create-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/create-payment-type/create-payment-type.component.scss b/src/app/organization/payment-types/create-payment-type/create-payment-type.component.scss new file mode 100644 index 000000000..345d8f51c --- /dev/null +++ b/src/app/organization/payment-types/create-payment-type/create-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/create-payment-type/create-payment-type.component.spec.ts b/src/app/organization/payment-types/create-payment-type/create-payment-type.component.spec.ts new file mode 100644 index 000000000..7a42d6404 --- /dev/null +++ b/src/app/organization/payment-types/create-payment-type/create-payment-type.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { CreatePaymentTypeComponent } from './create-payment-type.component'; + +describe('CreatePaymentTypeComponent', () => { + let component: CreatePaymentTypeComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ CreatePaymentTypeComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(CreatePaymentTypeComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/organization/payment-types/create-payment-type/create-payment-type.component.ts b/src/app/organization/payment-types/create-payment-type/create-payment-type.component.ts new file mode 100644 index 000000000..e9d6060b2 --- /dev/null +++ b/src/app/organization/payment-types/create-payment-type/create-payment-type.component.ts @@ -0,0 +1,63 @@ +/** 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 '../../organization.service'; + +/** + * Create Payment Type Component. + */ +@Component({ + selector: 'mifosx-create-payment-type', + templateUrl: './create-payment-type.component.html', + styleUrls: ['./create-payment-type.component.scss'] +}) +export class CreatePaymentTypeComponent implements OnInit { + + /** Payment Type form. */ + paymentTypeForm: FormGroup; + + /** + * @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) {} + + /** + * Creates and sets the payment type form. + */ + ngOnInit() { + this.createpaymentTypeForm(); + } + + /** + * Creates the payment type form. + */ + createpaymentTypeForm() { + this.paymentTypeForm = this.formBuilder.group({ + 'name': ['', Validators.required], + 'description': [''], + 'isCashPayment': [false], + 'position': ['', Validators.required], + }); + } + + /** + * Submits the payment type form and creates payment type. + * if successful redirects to payment types + */ + submit() { + const paymentType = this.paymentTypeForm.value; + this.organizationService.createPaymentType(paymentType).subscribe(response => { + this.router.navigate(['../'], { relativeTo: this.route }); + }); + } + +} diff --git a/src/app/organization/payment-types/payment-types.component.html b/src/app/organization/payment-types/payment-types.component.html index 055f9a0c7..dcb27bae3 100644 --- a/src/app/organization/payment-types/payment-types.component.html +++ b/src/app/organization/payment-types/payment-types.component.html @@ -1,8 +1,8 @@
-