feat: add create payment type component (#543)

Fixes: #164
This commit is contained in:
Rishabh Verma
2020-01-04 20:14:58 +03:00
committed by Abhay Chawla
parent 8fc6dba1a9
commit 15ff035d13
8 changed files with 172 additions and 7 deletions
@@ -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',
+3 -1
View File
@@ -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 { }
@@ -90,6 +90,14 @@ export class OrganizationService {
return this.http.get('/paymenttypes');
}
/**
* @param {any} paymentType Payment type to be created.
* @returns {Observable<any>}
*/
createPaymentType(paymentType: any): Observable<any> {
return this.http.post('/paymenttypes', paymentType);
}
/**
* @param {string} paymentTypeId Payment type ID of payment type to be deleted.
* @returns {Observable<any>}
@@ -0,0 +1,49 @@
<div class="container">
<mat-card>
<form [formGroup]="paymentTypeForm" (ngSubmit)="submit()">
<mat-card-content>
<div fxLayout="column">
<mat-form-field>
<mat-label>Payment Type</mat-label>
<input required matInput formControlName="name">
<mat-error *ngIf="paymentTypeForm.controls.name.hasError('required')">
Payment Type is <strong>required</strong>
</mat-error>
</mat-form-field>
<mat-form-field>
<mat-label>Description</mat-label>
<textarea matInput formControlName="description"></textarea>
</mat-form-field>
<mat-checkbox labelPosition="before" formControlName="isCashPayment" class="status">
Is Cash Payment?
</mat-checkbox>
<mat-form-field>
<mat-label>Position</mat-label>
<input required matInput formControlName="position">
<mat-error *ngIf="paymentTypeForm.controls.position.hasError('required')">
Position is <strong>required</strong>
</mat-error>
</mat-form-field>
</div>
</mat-card-content>
<mat-card-actions fxLayout="row" fxLayout.xs="column" fxLayoutAlign="center" fxLayoutGap="5px">
<button type="button" mat-raised-button [routerLink]="['../']">Cancel</button>
<button mat-raised-button color="primary" [disabled]="!paymentTypeForm.valid">Submit</button>
</mat-card-actions>
</form>
</mat-card>
</div>
@@ -0,0 +1,7 @@
.container {
max-width: 37rem;
}
.status {
padding: 17.5px 0 17.5px 0;
}
@@ -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<CreatePaymentTypeComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ CreatePaymentTypeComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(CreatePaymentTypeComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -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 });
});
}
}
@@ -1,8 +1,8 @@
<div class="container m-b-20" fxLayout="row" fxLayoutAlign="end" fxLayoutGap="20px">
<button mat-raised-button color="primary">
<button mat-raised-button color="primary" [routerLink]="['create']">
<fa-icon icon="plus"></fa-icon>&nbsp;&nbsp;
Add Payment Type
Create Payment Type
</button>
</div>