committed by
Jivjyot Singh
parent
b0b4a926eb
commit
51d622a9ff
@@ -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
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -146,6 +146,22 @@ export class OrganizationService {
|
||||
return this.http.delete(`/paymenttypes/${paymentTypeId}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} paymentTypeId Payment type ID of payment type.
|
||||
* @returns {Observable<any>} Payment type.
|
||||
*/
|
||||
getPaymentType(paymentTypeId: string): Observable<any> {
|
||||
return this.http.get(`/paymenttypes/${paymentTypeId}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} paymentTypeId Payment type ID of Payment Type to be edited.
|
||||
* @returns {Observable<any>}
|
||||
*/
|
||||
updatePaymentType(paymentTypeId: string, paymentType: any): Observable<any> {
|
||||
return this.http.put(`/paymenttypes/${paymentTypeId}`, paymentType);
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {Observable<any>} Password Preferences Template data
|
||||
*/
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
+25
@@ -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<EditPaymentTypeComponent>;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [ EditPaymentTypeComponent ]
|
||||
})
|
||||
.compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(EditPaymentTypeComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -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 });
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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<Object> {
|
||||
|
||||
/**
|
||||
* @param {OrganizationService} organizationService Organization service.
|
||||
*/
|
||||
constructor(private organizationService: OrganizationService) {}
|
||||
|
||||
/**
|
||||
* Returns the payment type data.
|
||||
* @returns {Observable<any>}
|
||||
*/
|
||||
resolve(route: ActivatedRouteSnapshot): Observable<any> {
|
||||
const paymentTypeId = route.paramMap.get('id');
|
||||
return this.organizationService.getPaymentType(paymentTypeId);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -48,7 +48,7 @@
|
||||
<ng-container matColumnDef="actions">
|
||||
<th mat-header-cell *matHeaderCellDef> Actions </th>
|
||||
<td mat-cell *matCellDef="let paymentType">
|
||||
<button mat-button color="primary">
|
||||
<button mat-button [routerLink]="[paymentType.id, 'edit']" color="primary">
|
||||
<fa-icon icon="edit"></fa-icon> Edit
|
||||
</button>
|
||||
<button mat-button (click)="deletePaymentType(paymentType.id)" color="warn">
|
||||
|
||||
Reference in New Issue
Block a user