Skip to content

Commit

Permalink
feat: edit and delete financial activity mapping
Browse files Browse the repository at this point in the history
Add edit financial activity component and delete dialog component.
  • Loading branch information
abhaychawla committed Jul 28, 2018
1 parent 8ebfd61 commit ff8e878
Show file tree
Hide file tree
Showing 15 changed files with 279 additions and 38 deletions.
15 changes: 13 additions & 2 deletions src/app/accounting/accounting-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { SearchJournalEntryComponent } from './search-journal-entry/search-journ
import { FinancialActivityMappingsComponent } from './financial-activity-mappings/financial-activity-mappings.component';
import { CreateFinancialActivityMappingComponent } from './financial-activity-mappings/create-financial-activity-mapping/create-financial-activity-mapping.component';
import { ViewFinancialActivityMappingComponent } from './financial-activity-mappings/view-financial-activity-mapping/view-financial-activity-mapping.component';
import { EditFinancialActivityMappingComponent } from './financial-activity-mappings/edit-financial-activity-mapping/edit-financial-activity-mapping.component';

const routes: Routes = [
Route.withShell([
Expand Down Expand Up @@ -62,8 +63,18 @@ const routes: Routes = [
},
{
path: 'view/:id',
component: ViewFinancialActivityMappingComponent,
data: {title: extract('View Financial Activity Mapping'), routeParamBreadcrumb: 'id' }
data: { title: extract('View Financial Activity Mapping'), routeParamBreadcrumb: 'id' },
children: [
{
path: '',
component: ViewFinancialActivityMappingComponent
},
{
path: 'edit',
component: EditFinancialActivityMappingComponent,
data: { title: extract('Edit Financial Activity Mapping'), breadcrumb: 'Edit', routeParamBreadcrumb: false }
}
]
}
]
}
Expand Down
4 changes: 3 additions & 1 deletion src/app/accounting/accounting.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { SearchJournalEntryComponent } from './search-journal-entry/search-journ
import { FinancialActivityMappingsComponent } from './financial-activity-mappings/financial-activity-mappings.component';
import { CreateFinancialActivityMappingComponent } from './financial-activity-mappings/create-financial-activity-mapping/create-financial-activity-mapping.component';
import { ViewFinancialActivityMappingComponent } from './financial-activity-mappings/view-financial-activity-mapping/view-financial-activity-mapping.component';
import { EditFinancialActivityMappingComponent } from './financial-activity-mappings/edit-financial-activity-mapping/edit-financial-activity-mapping.component';

@NgModule({
imports: [
Expand All @@ -33,7 +34,8 @@ import { ViewFinancialActivityMappingComponent } from './financial-activity-mapp
SearchJournalEntryComponent,
FinancialActivityMappingsComponent,
CreateFinancialActivityMappingComponent,
ViewFinancialActivityMappingComponent
ViewFinancialActivityMappingComponent,
EditFinancialActivityMappingComponent
],
entryComponents: [
RevertTransactionComponent,
Expand Down
13 changes: 11 additions & 2 deletions src/app/accounting/accounting.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,17 @@ export class AccountingService {
return this.http.post('/financialactivityaccounts', financialActivityAccount);
}

getFinancialActivityAccount(financialActivityAccountId: number) {
return this.http.get(`/financialactivityaccounts/${financialActivityAccountId}`);
getFinancialActivityAccount(financialActivityAccountId: number, template: boolean) {
const httpParams = new HttpParams().set('template', template.toString());
return this.http.get(`/financialactivityaccounts/${financialActivityAccountId}`, { params: httpParams });
}

updateFinancialActivityAccount(financialActivityAccountId: number, financialActivityAccount: any) {
return this.http.put(`/financialactivityaccounts/${financialActivityAccountId}`, financialActivityAccount);
}

deleteFinancialActivityAccount(financialActivityAccountId: number) {
return this.http.delete(`/financialactivityaccounts/${financialActivityAccountId}`);
}

}
Original file line number Diff line number Diff line change
@@ -1,35 +1,40 @@
<mat-card class="container">
<form [formGroup]="financialActivityMappingForm" (ngSubmit)="submit()">
<div class="container">

<mat-card-content>
<mat-card>

<form [formGroup]="financialActivityMappingForm" (ngSubmit)="submit()">

<div fxLayout="column">
<mat-card-content>

<mat-form-field>
<mat-select placeholder="Financial Activity" required formControlName="financialActivityId">
<mat-option *ngFor="let financialActivity of financialActivityData" [value]="financialActivity.id">
{{ financialActivity.name }}
</mat-option>
</mat-select>
</mat-form-field>
<div fxLayout="column">

<mat-form-field>
<mat-select placeholder="Account" required formControlName="glAccountId">
<mat-option *ngFor="let glAccount of glAccountData" [value]="glAccount.id">
{{ glAccount.name + ' (' + glAccount.glCode + ')' }}
</mat-option>
</mat-select>
</mat-form-field>
<mat-form-field>
<mat-select placeholder="Financial Activity" required formControlName="financialActivityId">
<mat-option *ngFor="let financialActivity of financialActivityData" [value]="financialActivity.id">
{{ financialActivity.name }}
</mat-option>
</mat-select>
</mat-form-field>

</div>
<mat-form-field>
<mat-select placeholder="Account" required formControlName="glAccountId">
<mat-option *ngFor="let glAccount of glAccountData" [value]="glAccount.id">
{{ glAccount.name + ' (' + glAccount.glCode + ')' }}
</mat-option>
</mat-select>
</mat-form-field>

</mat-card-content>
</div>

<mat-card-actions fxLayout="row" fxLayout.xs="column" fxLayoutAlign="center" fxLayoutGap="5px">
<button type="button" mat-raised-button [routerLink]="['/accounting/financial-activity-mappings']">Cancel</button>
<button mat-raised-button color="primary">Submit</button>
</mat-card-actions>
</mat-card-content>

</form>
<mat-card-actions fxLayout="row" fxLayout.xs="column" fxLayoutAlign="center" fxLayoutGap="5px">
<button type="button" mat-raised-button [routerLink]="['/accounting/financial-activity-mappings']">Cancel</button>
<button mat-raised-button color="primary">Submit</button>
</mat-card-actions>

</mat-card>
</form>

</mat-card>

</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<div class="container">

<mat-card>

<form [formGroup]="financialActivityMappingForm" (ngSubmit)="submit()">

<mat-card-content>

<div fxLayout="column">

<mat-form-field>
<mat-select placeholder="Financial Activity" required formControlName="financialActivityId">
<mat-option *ngFor="let financialActivity of financialActivityData" [value]="financialActivity.id">
{{ financialActivity.name }}
</mat-option>
</mat-select>
</mat-form-field>

<mat-form-field>
<mat-select placeholder="Account" required formControlName="glAccountId">
<mat-option *ngFor="let glAccount of glAccountData" [value]="glAccount.id">
{{ glAccount.name + ' (' + glAccount.glCode + ')' }}
</mat-option>
</mat-select>
</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]="['/accounting/financial-activity-mappings/view', financialActivityAccountId]">Cancel</button>
<button mat-raised-button color="primary">Submit</button>
</mat-card-actions>

</form>

</mat-card>

</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.container {
max-width: 37rem;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { EditFinancialActivityMappingComponent } from './edit-financial-activity-mapping.component';

describe('EditFinancialActivityMappingComponent', () => {
let component: EditFinancialActivityMappingComponent;
let fixture: ComponentFixture<EditFinancialActivityMappingComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ EditFinancialActivityMappingComponent ]
})
.compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(EditFinancialActivityMappingComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import { Component, OnInit } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { Router, ActivatedRoute } from '@angular/router';

import { AccountingService } from '../../accounting.service';

@Component({
selector: 'mifosx-edit-financial-activity-mapping',
templateUrl: './edit-financial-activity-mapping.component.html',
styleUrls: ['./edit-financial-activity-mapping.component.scss']
})
export class EditFinancialActivityMappingComponent implements OnInit {

financialActivityMappingForm: FormGroup;
glAccountOptions: any;
glAccountData: any;
financialActivityAccountId: any;
financialActivityData: any;

constructor(private route: ActivatedRoute,
private formBuider: FormBuilder,
private accountingService: AccountingService,
private router: Router) { }

ngOnInit() {
this.financialActivityAccountId = this.route.snapshot.paramMap.get('id');
this.createFinancialActivityMappingForm();
this.setGLAccountData();
this.getFinancialActivityAccount();
}

createFinancialActivityMappingForm() {
this.financialActivityMappingForm = this.formBuider.group({
'financialActivityId': ['', Validators.required],
'glAccountId': ['', Validators.required]
});
}

getFinancialActivityAccount() {
this.accountingService.getFinancialActivityAccount(this.financialActivityAccountId, true)
.subscribe((financialActivityAccountData: any) => {
this.glAccountOptions = financialActivityAccountData.glAccountOptions;
this.financialActivityData = financialActivityAccountData.financialActivityOptions;
this.financialActivityMappingForm.get('financialActivityId').setValue(financialActivityAccountData.financialActivityData.id);
this.financialActivityMappingForm.get('glAccountId').setValue(financialActivityAccountData.glAccountData.id);
});
}

setGLAccountData() {
this.financialActivityMappingForm.get('financialActivityId').valueChanges.subscribe(financialActivityId => {
switch (financialActivityId) {
case 100:
case 101:
case 102:
case 103: this.glAccountData = this.glAccountOptions.assetAccountOptions;
break;
case 200:
case 201: this.glAccountData = this.glAccountOptions.liabilityAccountOptions;
break;
case 300: this.glAccountData = this.glAccountOptions.equityAccountOptions;
break;
}
});
}

submit() {
this.accountingService.updateFinancialActivityAccount(this.financialActivityAccountId, this.financialActivityMappingForm.value)
.subscribe((response: any) => {
this.router.navigate(['/accounting/financial-activity-mappings/view', response.resourceId]);
});
}

}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<div fxLayout="row" fxLayoutAlign="end" fxLayoutGap="2%" class="container m-b-20">
<button mat-raised-button color="primary">
<button mat-raised-button color="primary" [routerLink]="['/accounting/financial-activity-mappings/view', financialActivityAccountId, 'edit']">
<mat-icon>edit</mat-icon>&nbsp;&nbsp;Edit
</button>
<button mat-raised-button color="warn">
<button mat-raised-button color="warn" (click)="deleteFinancialActivityAccount()">
<mat-icon>delete</mat-icon>&nbsp;&nbsp;Delete
</button>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { ActivatedRoute, Router } from '@angular/router';
import { MatDialog } from '@angular/material';

import { AccountingService } from '../../accounting.service';
import { DeleteDialogComponent } from '../../../shared/delete-dialog/delete-dialog.component';

@Component({
selector: 'mifosx-view-financial-activity-mapping',
Expand All @@ -13,19 +16,34 @@ export class ViewFinancialActivityMappingComponent implements OnInit {
financialActivityAccountData: any;

constructor(private route: ActivatedRoute,
private accountingService: AccountingService) { }
private router: Router,
private accountingService: AccountingService,
public dialog: MatDialog) { }

ngOnInit() {
this.financialActivityAccountId = this.route.snapshot.paramMap.get('id');
this.getFinancialActivityAccount();
}

getFinancialActivityAccount() {
this.accountingService.getFinancialActivityAccount(this.financialActivityAccountId)
this.accountingService.getFinancialActivityAccount(this.financialActivityAccountId, false)
.subscribe((financialActivityAccountData: any) => {
this.financialActivityAccountData = financialActivityAccountData;
console.log(financialActivityAccountData);
});
}

deleteFinancialActivityAccount() {
const deleteFinancialActivityAccountDialogRef = this.dialog.open(DeleteDialogComponent, {
data: { deleteContext: `financial activity mapping ${this.financialActivityAccountId}` }
});
deleteFinancialActivityAccountDialogRef.afterClosed().subscribe((response: any) => {
if (response.delete) {
this.accountingService.deleteFinancialActivityAccount(this.financialActivityAccountId)
.subscribe(() => {
this.router.navigate(['/accounting/financial-activity-mappings']);
});
}
});
}

}
8 changes: 8 additions & 0 deletions src/app/shared/delete-dialog/delete-dialog.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<h1 mat-dialog-title>Delete</h1>
<div mat-dialog-content>
<p>Are you sure you want to delete {{ data.deleteContext }} ?</p>
</div>
<mat-dialog-actions align="end">
<button mat-button mat-dialog-close>Cancel</button>
<button mat-button [mat-dialog-close]="{ delete: true }">Confirm</button>
</mat-dialog-actions>
Empty file.
25 changes: 25 additions & 0 deletions src/app/shared/delete-dialog/delete-dialog.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { DeleteDialogComponent } from './delete-dialog.component';

describe('DeleteDialogComponent', () => {
let component: DeleteDialogComponent;
let fixture: ComponentFixture<DeleteDialogComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ DeleteDialogComponent ]
})
.compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(DeleteDialogComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
17 changes: 17 additions & 0 deletions src/app/shared/delete-dialog/delete-dialog.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Component, OnInit, Inject } from '@angular/core';
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material';

@Component({
selector: 'mifosx-delete-dialog',
templateUrl: './delete-dialog.component.html',
styleUrls: ['./delete-dialog.component.scss']
})
export class DeleteDialogComponent implements OnInit {

constructor(public dialogRef: MatDialogRef<DeleteDialogComponent>,
@Inject(MAT_DIALOG_DATA) public data: any) { }

ngOnInit() {
}

}
Loading

0 comments on commit ff8e878

Please sign in to comment.