feat: edit savings account transaction page (#954)

Fixes: #953
This commit is contained in:
Karan Takalkar
2020-06-30 01:23:11 +05:30
committed by GitHub
parent 99fd6ad38c
commit ce8ca77ad7
9 changed files with 302 additions and 6 deletions
@@ -0,0 +1,33 @@
/** Angular Imports */
import { Injectable } from '@angular/core';
import { Resolve, ActivatedRouteSnapshot } from '@angular/router';
/** rxjs Imports */
import { Observable } from 'rxjs';
/** Custom Services */
import { SavingsService } from '../savings.service';
/**
* Savings Account Transaction Template data resolver.
*/
@Injectable()
export class SavingsAccountTransactionTemplateResolver implements Resolve<Object> {
/**
* @param {SavingsService} SavingsService Savings service.
*/
constructor(private savingsService: SavingsService) { }
/**
* Returns the Savings Account Transaction Template data.
* @param {ActivatedRouteSnapshot} route Route Snapshot
* @returns {Observable<any>}
*/
resolve(route: ActivatedRouteSnapshot): Observable<any> {
const savingAccountId = route.parent.paramMap.get('savingAccountId');
const transactionId = route.paramMap.get('id');
return this.savingsService.getSavingsAccountTransactionTemplate(savingAccountId, transactionId);
}
}
@@ -0,0 +1,81 @@
<div class="container">
<mat-card>
<form [formGroup]="editTransactionForm" (ngSubmit)="submit()">
<mat-card-content fxLayout="column">
<mat-form-field>
<mat-label>Transaction Date</mat-label>
<input matInput [min]="minDate" [max]="maxDate" [matDatepicker]="dueDatePicker"
formControlName="transactionDate" required>
<mat-datepicker-toggle matSuffix [for]="dueDatePicker"></mat-datepicker-toggle>
<mat-datepicker #dueDatePicker></mat-datepicker>
<mat-error *ngIf="editTransactionForm.controls.transactionDate.hasError('required')">
Transaction Date is <strong>required</strong>
</mat-error>
</mat-form-field>
<mat-form-field>
<mat-label>Transaction Amount</mat-label>
<input type="number" formControlName="transactionAmount" required matInput />
<mat-error *ngIf="editTransactionForm.controls.transactionAmount.hasError('required')">
Transaction Amount is <strong>required</strong>
</mat-error>
</mat-form-field>
<mat-form-field>
<mat-label>Payment Type</mat-label>
<mat-select formControlName="paymentTypeId">
<mat-option *ngFor="let paymentType of paymentTypeOptions" [value]="paymentType.id">
{{ paymentType.name }}
</mat-option>
</mat-select>
</mat-form-field>
<div fxLayoutGap="5px" fxLayout="row" fxLayout.xs="column">
<mat-label fxFlexAlign="center">Show Payment Details</mat-label>
<button type="button" mat-mini-fab color="primary" (click)="addPaymentDetails()">
<fa-icon [icon]="!addPaymentDetailsFlag ? 'plus-circle' : 'minus-circle'" size="lg"></fa-icon>
</button>
</div>
<mat-form-field *ngIf="editTransactionForm.controls['accountNumber']">
<mat-label>Account Number</mat-label>
<input type="number" formControlName="accountNumber" matInput />
</mat-form-field>
<mat-form-field *ngIf="editTransactionForm.controls['checkNumber']">
<mat-label>Cheque</mat-label>
<input type="number" formControlName="checkNumber" matInput />
</mat-form-field>
<mat-form-field *ngIf="editTransactionForm.controls['routingCode']">
<mat-label>Routing Code</mat-label>
<input formControlName="routingCode" matInput />
</mat-form-field>
<mat-form-field *ngIf="editTransactionForm.controls['receiptNumber']">
<mat-label>Receipt Number</mat-label>
<input formControlName="receiptNumber" matInput />
</mat-form-field>
<mat-form-field *ngIf="editTransactionForm.controls['bankNumber']">
<mat-label>Bank</mat-label>
<input formControlName="bankNumber" matInput />
</mat-form-field>
<mat-card-actions fxLayoutGap="5px" fxLayout="row" fxLayout.xs="column" fxLayoutAlign="center">
<button type="button" mat-raised-button [routerLink]="['../']">Cancel</button>
<button mat-raised-button color="primary" [disabled]="!editTransactionForm.valid">Submit</button>
</mat-card-actions>
</mat-card-content>
</form>
</mat-card>
</div>
@@ -0,0 +1,3 @@
.container {
width: 37rem;
}
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { EditTransactionComponent } from './edit-transaction.component';
describe('EditTransactionComponent', () => {
let component: EditTransactionComponent;
let fixture: ComponentFixture<EditTransactionComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ EditTransactionComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(EditTransactionComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,123 @@
/** Angular Imports */
import { Component, OnInit } from '@angular/core';
import { FormGroup, FormBuilder, Validators, FormControl } from '@angular/forms';
import { Router, ActivatedRoute } from '@angular/router';
import { DatePipe } from '@angular/common';
/** Custom Services */
import { SavingsService } from 'app/savings/savings.service';
/**
* Edit Transaction component.
*/
@Component({
selector: 'mifosx-edit-transaction',
templateUrl: './edit-transaction.component.html',
styleUrls: ['./edit-transaction.component.scss']
})
export class EditTransactionComponent implements OnInit {
/** Minimum Due Date allowed. */
minDate = new Date(2000, 0, 1);
/** Maximum Due Date allowed. */
maxDate = new Date();
/** Savings account transaction form. */
editTransactionForm: FormGroup;
/** savings account transaction payment options. */
paymentTypeOptions: {
id: number,
name: string,
description: string,
isCashPayment: boolean,
position: number
}[];
/** Flag to enable payment details fields. */
addPaymentDetailsFlag: Boolean = false;
/** saving account's Id */
savingAccountId: string;
/** Transaction Template */
transactionTemplateData: any;
/**
* Retrieves the Saving Account transaction template data from `resolve`.
* @param {FormBuilder} formBuilder Form Builder.
* @param {SavingsService} savingsService Savings Service.
* @param {ActivatedRoute} route Activated Route.
* @param {DatePipe} datePipe DatePipe.
* @param {Router} router Router for navigation.
*/
constructor(private formBuilder: FormBuilder,
private route: ActivatedRoute,
private router: Router,
private datePipe: DatePipe,
private savingsService: SavingsService) {
this.route.data.subscribe((data: { savingsAccountTransactionTemplate: any }) => {
this.transactionTemplateData = data.savingsAccountTransactionTemplate;
this.paymentTypeOptions = this.transactionTemplateData.paymentTypeOptions;
});
this.savingAccountId = this.route.parent.snapshot.params['savingAccountId'];
}
/**
* Creates the Saving account transaction form when component loads.
*/
ngOnInit() {
this.createEditTransactionForm();
this.editTransactionForm.patchValue({
'transactionDate': this.transactionTemplateData.date && new Date(this.transactionTemplateData.date),
'transactionAmount': this.transactionTemplateData.amount,
'paymentTypeId': this.transactionTemplateData.paymentTypeId
});
}
/**
* Method to create the Saving Account Transaction Form.
*/
createEditTransactionForm() {
this.editTransactionForm = this.formBuilder.group({
'transactionDate': ['', Validators.required],
'transactionAmount': ['', Validators.required],
'paymentTypeId': [''],
});
}
/**
* Method to add payment detail fields to the UI.
*/
addPaymentDetails() {
this.addPaymentDetailsFlag = !this.addPaymentDetailsFlag;
if (this.addPaymentDetailsFlag) {
this.editTransactionForm.addControl('accountNumber', new FormControl(''));
this.editTransactionForm.addControl('checkNumber', new FormControl(''));
this.editTransactionForm.addControl('routingCode', new FormControl(''));
this.editTransactionForm.addControl('receiptNumber', new FormControl(''));
this.editTransactionForm.addControl('bankNumber', new FormControl(''));
} else {
this.editTransactionForm.removeControl('accountNumber');
this.editTransactionForm.removeControl('checkNumber');
this.editTransactionForm.removeControl('routingCode');
this.editTransactionForm.removeControl('receiptNumber');
this.editTransactionForm.removeControl('bankNumber');
}
}
/**
* Method to submit the transaction details.
*/
submit() {
const prevTransactionDate: Date = this.editTransactionForm.value.transactionDate;
// TODO: Update once language and date settings are setup
const dateFormat = 'dd-MM-yyyy';
this.editTransactionForm.patchValue({
transactionDate: this.datePipe.transform(prevTransactionDate, dateFormat)
});
const transactionData = this.editTransactionForm.value;
transactionData.locale = 'en';
transactionData.dateFormat = dateFormat;
this.savingsService.executeSavingsAccountTransactionsCommand(this.savingAccountId, 'modify', transactionData, this.transactionTemplateData.id)
.subscribe(res => {
this.router.navigate(['../'], { relativeTo: this.route });
});
}
}
@@ -1,9 +1,17 @@
<div fxLayoutAlign="end" class="container m-b-20"
<div fxLayoutAlign="end" class="container m-b-20" fxLayoutGap="2%"
*ngIf="!(transactionData.interestedPostedAsOn === false && (transactionData.transactionType.id === 17 || transactionData.transactionType.id === 3))">
<button mat-raised-button color="warn"
<span *mifosxHasPermission="'ADJUSTTRANSACTION_SAVINGSACCOUNT'">
<button mat-raised-button color="primary"
*ngIf="transactionData.transactionType.value == 'Transfer' || transactionData.reversed == 'true'
|| transactionData.transactionType.id==3 || transactionData.transactionType.id==17"
[routerLink]="'edit'">
<fa-icon icon="edit"></fa-icon>&nbsp;&nbsp;Edit
</button>
</span>
<button mat-raised-button color="warn"
*mifosxHasPermission="'UNDOTRANSACTION_SAVINGSACCOUNT'"
(click)="undoTransaction()">
<fa-icon icon="undo"></fa-icon>&nbsp;&nbsp;
Undo
<fa-icon icon="undo"></fa-icon>&nbsp;&nbsp;Undo
</button>
</div>
+12 -1
View File
@@ -18,6 +18,7 @@ import { ViewTransactionComponent } from './savings-account-view/transactions/vi
import { ViewChargeComponent } from './savings-account-view/view-charge/view-charge.component';
import { ViewRecieptComponent } from './savings-account-view/transactions/view-reciept/view-reciept.component';
import { ExportTransactionsComponent } from './savings-account-view/transactions-tab/export-transactions/export-transactions.component';
import { EditTransactionComponent } from './savings-account-view/transactions/edit-transaction/edit-transaction.component';
/** Custom Resolvers */
import { SavingsAccountViewResolver } from './common-resolvers/savings-account-view.resolver';
@@ -29,6 +30,7 @@ import { SavingsAccountTransactionResolver } from './common-resolvers/savings-ac
import { SavingsAccountChargeResolver } from './common-resolvers/savings-account-charge.resolver';
import { SavingsAccountActionsResolver } from './common-resolvers/savings-account-actions.resolver';
import { SavingsTransactionRecieptResolver } from './common-resolvers/savings-transaction-reciept.resolver';
import { SavingsAccountTransactionTemplateResolver } from './common-resolvers/savings-account-transaction-template.resolver';
const routes: Routes = [
@@ -125,6 +127,14 @@ const routes: Routes = [
savingsAccountTransaction: SavingsAccountTransactionResolver
}
},
{
path: 'edit',
component: EditTransactionComponent,
data: { breadcrumb: 'Edit', routeParamBreadcrumb: false },
resolve: {
savingsAccountTransactionTemplate: SavingsAccountTransactionTemplateResolver
}
},
{
path: 'reciept',
component: ViewRecieptComponent,
@@ -180,6 +190,7 @@ const routes: Routes = [
SavingsAccountTransactionResolver,
SavingsAccountChargeResolver,
SavingsAccountActionsResolver,
SavingsTransactionRecieptResolver]
SavingsTransactionRecieptResolver,
SavingsAccountTransactionTemplateResolver]
})
export class SavingsRoutingModule {}
+3 -1
View File
@@ -44,6 +44,7 @@ import { CloseSavingsAccountComponent } from './saving-account-actions/close-sav
import { ToggleWithholdTaxDialogComponent } from './savings-account-view/custom-dialogs/toggle-withhold-tax-dialog/toggle-withhold-tax-dialog.component';
import { ViewRecieptComponent } from './savings-account-view/transactions/view-reciept/view-reciept.component';
import { ExportTransactionsComponent } from './savings-account-view/transactions-tab/export-transactions/export-transactions.component';
import { EditTransactionComponent } from './savings-account-view/transactions/edit-transaction/edit-transaction.component';
/**
@@ -93,7 +94,8 @@ import { ExportTransactionsComponent } from './savings-account-view/transactions
CloseSavingsAccountComponent,
ToggleWithholdTaxDialogComponent,
ViewRecieptComponent,
ExportTransactionsComponent
ExportTransactionsComponent,
EditTransactionComponent
],
entryComponents: [
CalculateInterestDialogComponent,
+10
View File
@@ -204,6 +204,16 @@ export class SavingsService {
return this.http.get(`/savingsaccounts/${accountId}/transactions/${transactionId}`);
}
/**
* @param {string} accountId Savings Account Id
* @param {string} transactionId Transaction Id
* @returns {Observable<any>}
*/
getSavingsAccountTransactionTemplate(accountId: string, transactionId: string): Observable<any> {
const httpParams = new HttpParams().set('template', 'true');
return this.http.get(`/savingsaccounts/${accountId}/transactions/${transactionId}`, { params: httpParams });
}
/**
* @param {string} accountId Savings Account Id
* @param {string} command Command