Skip to content

Commit

Permalink
fix: Recurring Deposit accounts issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Jose Alberto Hernandez authored and alberto-art3ch committed Jun 10, 2024
1 parent 9b51ec4 commit b23efd3
Show file tree
Hide file tree
Showing 23 changed files with 402 additions and 121 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ export class FixedDepositsAccountActionsResolver implements Resolve<Object> {
return this.savingsService.getSavingsChargeTemplateResource(fixedDepositAccountId);
case 'Close':
return this.fixedDepositsService.getFixedDepositsAccountClosureTemplate(fixedDepositAccountId);
case 'Withdrawal':
return this.fixedDepositsService.getFixedDepositsAccountTransactionTemplate(fixedDepositAccountId);
default:
return undefined;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
<mifosx-add-charge-fixed-deposits-account *ngIf="actions['Add Charge']"></mifosx-add-charge-fixed-deposits-account>
<mifosx-premature-close-fixed-deposits-account *ngIf="actions['Premature Close']"></mifosx-premature-close-fixed-deposits-account>
<mifosx-close-fixed-deposits-account *ngIf="actions['Close']"></mifosx-close-fixed-deposits-account>
<mifosx-fixed-deposits-cash-transaction *ngIf="actions['Withdrawal']"></mifosx-fixed-deposits-cash-transaction>
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export class FixedDepositsAccountActionsComponent {
'Add Charge': boolean
'Premature Close': boolean
'Withdrawn by Client': boolean
'Withdrawal': boolean
} = {
'Approve': false,
'Reject': false,
Expand All @@ -32,7 +33,8 @@ export class FixedDepositsAccountActionsComponent {
'Undo Activation': false,
'Add Charge': false,
'Premature Close': false,
'Withdrawn by Client': false
'Withdrawn by Client': false,
'Withdrawal': false
};

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<div class="container mat-elevation-z8">

<mat-card>

<h2 mat-title *ngIf="transactionType.withdrawal">{{'labels.menus.' + actionName | translate }} {{'labels.heading.Fixed Deposit Transactions' | translate}}</h2>

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

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

<mat-form-field (click)="dueDatePicker.open()">
<mat-label>{{'labels.inputs.Transaction Date' | translate}}</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="accountTransactionForm.controls.transactionDate.hasError('required')">
{{'labels.inputs.Transaction Date' | translate}} {{ "labels.commons.is" | translate}} <strong>{{ "labels.commons.required" | translate}}</strong>
</mat-error>
</mat-form-field>

<mifosx-input-amount [currency]="currency" [isRequired]="true"
[inputFormControl]="accountTransactionForm.controls.transactionAmount"
[inputLabel]="'Transaction Amount'">
</mifosx-input-amount>

<mat-form-field>
<mat-label>{{'labels.inputs.Payment Type' | translate}}</mat-label>
<mat-select required formControlName="paymentTypeId">
<mat-option *ngFor="let paymentType of paymentTypeOptions" [value]="paymentType.id">
{{ paymentType.name }}
</mat-option>
</mat-select>
</mat-form-field>

<div fxFlexFill>
<span fxFlex="75%" class="expandcollapsebutton m-l-10 m-t-40" (click)="addPaymentDetails()">
<mat-slide-toggle>
<div [className]="addPaymentDetailsFlag ? 'enabled' : 'disabled'">
<span class="m-l-10">{{'labels.inputs.Show Payment Details' | translate}}</span>
</div>
</mat-slide-toggle>
</span>
</div>

<mat-form-field *ngIf="addPaymentDetailsFlag">
<mat-label>{{'labels.inputs.Account Number' | translate}}</mat-label>
<input type="number" formControlName="accountNumber" matInput />
</mat-form-field>

<mat-form-field *ngIf="addPaymentDetailsFlag">
<mat-label>{{'labels.inputs.Cheque' | translate}}</mat-label>
<input type="number" formControlName="checkNumber" matInput />
</mat-form-field>

<mat-form-field *ngIf="addPaymentDetailsFlag">
<mat-label>{{'labels.inputs.Routing Code' | translate}}</mat-label>
<input formControlName="routingCode" matInput />
</mat-form-field>

<mat-form-field *ngIf="addPaymentDetailsFlag">
<mat-label>{{'labels.inputs.Receipt Number' | translate}}</mat-label>
<input formControlName="receiptNumber" matInput />
</mat-form-field>

<mat-form-field *ngIf="addPaymentDetailsFlag">
<mat-label>{{'labels.inputs.Bank' | translate}}</mat-label>
<input formControlName="bankNumber" matInput />
</mat-form-field>

<mat-form-field>
<mat-label>{{'labels.inputs.Notes' | translate}}</mat-label>
<textarea formControlName="note" matInput cdkTextareaAutosize cdkAutosizeMinRows="2"></textarea>
</mat-form-field>

<mat-card-actions fxLayoutGap="5px" fxLayout="row" fxLayout.xs="column" fxLayoutAlign="center">
<button type="button" mat-raised-button [routerLink]="['../../transactions']">{{'labels.buttons.Cancel' | translate}}</button>
<button mat-raised-button color="primary" [disabled]="!accountTransactionForm.valid">{{'labels.buttons.Submit' | translate}}</button>
</mat-card-actions>

</mat-card-content>

</form>

</mat-card>

</div>

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.expandcollapsebutton {
margin-top: -7px;
}

.container {
max-width: 37rem;
}

.right-input {
text-align: right;
}

.right-label {
padding-right: 25px !important;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { FixedDepositsCashTransactionComponent } from './fixed-deposits-cash-transaction.component';

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

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

fixture = TestBed.createComponent(FixedDepositsCashTransactionComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
import { Component, OnInit } from '@angular/core';
import { UntypedFormBuilder, UntypedFormControl, UntypedFormGroup, Validators } from '@angular/forms';
import { FixedDepositsService } from '../../fixed-deposits.service';
import { SettingsService } from 'app/settings/settings.service';
import { Dates } from 'app/core/utils/dates';
import { ActivatedRoute, Router } from '@angular/router';
import { Currency, PaymentType } from 'app/shared/models/general.model';

@Component({
selector: 'mifosx-fixed-deposits-cash-transaction',
templateUrl: './fixed-deposits-cash-transaction.component.html',
styleUrls: ['./fixed-deposits-cash-transaction.component.scss']
})
export class FixedDepositsCashTransactionComponent implements OnInit {

/** Minimum Due Date allowed. */
minDate = new Date(2000, 0, 1);
/** Maximum Due Date allowed. */
maxDate = new Date();
/** Savings account transaction form. */
accountTransactionForm: UntypedFormGroup;
/** savings account transaction payment options. */
paymentTypeOptions: PaymentType[] = [];
/** Flag to enable payment details fields. */
addPaymentDetailsFlag: Boolean = false;
/** transaction type flag to render required UI */
transactionType: { deposit: boolean, withdrawal: boolean } = { deposit: false, withdrawal: false };
/** transaction command for submit request */
transactionCommand: string;
actionName: string;
/** saving account's Id */
accountId: string;
currency: Currency;

/**
* Retrieves the Saving Account transaction template data from `resolve`.
* @param {FormBuilder} formBuilder Form Builder.
* @param {FixedDepositsService} fixedDepositsService Fixed Deposit Service.
* @param {ActivatedRoute} route Activated Route.
* @param {Dates} dateUtils Date Utils.
* @param {Router} router Router for navigation.
* @param {SettingsService} settingsService Settings Service
*/
constructor(private formBuilder: UntypedFormBuilder,
private route: ActivatedRoute,
private router: Router,
private dateUtils: Dates,
private fixedDepositsService: FixedDepositsService,
private settingsService: SettingsService) {
this.route.data.subscribe((data: { fixedDepositsAccountActionData: any }) => {
this.currency = data.fixedDepositsAccountActionData.currency;
this.paymentTypeOptions = data.fixedDepositsAccountActionData.paymentTypeOptions;
});
this.actionName = this.route.snapshot.params['name'];
this.transactionCommand = this.actionName.toLowerCase();
this.transactionType[this.transactionCommand] = true;
this.accountId = this.route.parent.snapshot.params['fixedDepositAccountId'];
}

/**
* Creates the Saving account transaction form when component loads.
*/
ngOnInit() {
this.maxDate = this.settingsService.businessDate;
this.createSavingAccountTransactionForm();
}

/**
* Method to create the Saving Account Transaction Form.
*/
createSavingAccountTransactionForm() {
this.accountTransactionForm = this.formBuilder.group({
'transactionDate': [this.settingsService.businessDate, Validators.required],
'transactionAmount': [0, Validators.required],
'paymentTypeId': [''],
'note': ['']
});
}

/**
* Method to add payment detail fields to the UI.
*/
addPaymentDetails() {
this.addPaymentDetailsFlag = !this.addPaymentDetailsFlag;
if (this.addPaymentDetailsFlag) {
this.accountTransactionForm.addControl('accountNumber', new UntypedFormControl(''));
this.accountTransactionForm.addControl('checkNumber', new UntypedFormControl(''));
this.accountTransactionForm.addControl('routingCode', new UntypedFormControl(''));
this.accountTransactionForm.addControl('receiptNumber', new UntypedFormControl(''));
this.accountTransactionForm.addControl('bankNumber', new UntypedFormControl(''));
} else {
this.accountTransactionForm.removeControl('accountNumber');
this.accountTransactionForm.removeControl('checkNumber');
this.accountTransactionForm.removeControl('routingCode');
this.accountTransactionForm.removeControl('receiptNumber');
this.accountTransactionForm.removeControl('bankNumber');
}
}

/**
* Method to submit the transaction details.
*/
submit() {
const savingAccountTransactionFormData = this.accountTransactionForm.value;
const locale = this.settingsService.language.code;
const dateFormat = this.settingsService.dateFormat;
const prevTransactionDate: Date = this.accountTransactionForm.value.transactionDate;
if (savingAccountTransactionFormData.transactionDate instanceof Date) {
savingAccountTransactionFormData.transactionDate = this.dateUtils.formatDate(prevTransactionDate, dateFormat);
}
const data = {
...savingAccountTransactionFormData,
dateFormat,
locale
};
delete data.note;
data['transactionAmount'] = data['transactionAmount'] * 1;
this.fixedDepositsService.executeFixedDepositsAccountTransactionsCommand(this.accountId, this.transactionCommand, data).subscribe(res => {
this.router.navigate(['../../transactions'], { relativeTo: this.route });
});
}

}
4 changes: 3 additions & 1 deletion src/app/deposits/fixed-deposits/fixed-deposits.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import { FixedDepositAccountInterestRateChartStepComponent } from './fixed-depos
import { FixedDepositAccountPreviewStepComponent } from './fixed-deposit-account-stepper/fixed-deposit-account-preview-step/fixed-deposit-account-preview-step.component';
import { EditFixedDepositAccountComponent } from './edit-fixed-deposit-account/edit-fixed-deposit-account.component';
import { GeneralTabComponent } from './fixed-deposit-account-view/general-tab/general-tab.component';
import { FixedDepositsCashTransactionComponent } from './fixed-deposits-account-actions/fixed-deposits-cash-transaction/fixed-deposits-cash-transaction.component';

/**
* Fixed Deposits Module
Expand Down Expand Up @@ -75,7 +76,8 @@ import { GeneralTabComponent } from './fixed-deposit-account-view/general-tab/ge
FixedDepositAccountInterestRateChartStepComponent,
FixedDepositAccountPreviewStepComponent,
EditFixedDepositAccountComponent,
GeneralTabComponent
GeneralTabComponent,
FixedDepositsCashTransactionComponent
],
imports: [
SharedModule,
Expand Down
8 changes: 8 additions & 0 deletions src/app/deposits/fixed-deposits/fixed-deposits.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ export class FixedDepositsService {
return this.http.get(`/fixeddepositaccounts/${accountId}/template`, { params: httpParams });
}

/**
* @param {string} accountId Fixed Deposits Account Id
* @returns {Observable<any>}
*/
getFixedDepositsAccountTransactionTemplate(accountId: string): Observable<any> {
return this.http.get(`/fixeddepositaccounts/${accountId}/transactions/template`);
}

/**
* @param clientId Client Id assosciated with fixed deposits account.
* @returns {Observable<any>} Fixed Deposits account template.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@

<ng-template matStepLabel>{{"labels.inputs.SETTINGS" | translate }}</ng-template>

<mifosx-recurring-deposits-account-settings-step
<mifosx-recurring-deposits-account-settings-step [isNew]="false"
[recurringDepositsAccountTemplate]="recurringDepositsAccountAndTemplate"
[recurringDepositsAccountProductTemplate]="recurringDepositsAccountProductTemplate">
</mifosx-recurring-deposits-account-settings-step>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<div class="container">

<mat-card>
<h2 mat-title *ngIf="transactionType.withdrawal">{{'labels.menus.' + actionName | translate }} {{'labels.heading.Recurring Deposit Transactions' | translate}}</h2>

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

Expand All @@ -19,15 +20,10 @@
</mat-error>
</mat-form-field>

<mat-form-field appearance="fill">
<mat-label>{{"labels.inputs.Transaction Amount" | translate}}</mat-label>
<span matTextSuffix class="m-l-10">{{ currency.code }}</span>
<span fxFlex="auto"></span>
<input type="number" matInput required class="right-input" formControlName="transactionAmount">
<mat-error *ngIf="depositRecurringDepositForm.controls.transactionAmount.hasError('required')">
{{"labels.inputs.Transaction Amount" | translate}} {{"labels.commons.is" | translate}} <strong>{{"labels.commons.required" | translate}}</strong>
</mat-error>
</mat-form-field>
<mifosx-input-amount [currency]="currency" [isRequired]="true"
[inputFormControl]="depositRecurringDepositForm.controls.transactionAmount"
[inputLabel]="'Transaction Amount'">
</mifosx-input-amount>

<mat-form-field>
<mat-label>{{"labels.inputs.Payment Type Id" | translate }}</mat-label>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ export class DepositRecurringDepositsAccountComponent implements OnInit {
depositRecurringDepositForm: UntypedFormGroup;

action: string;
actionName: string;
transactionCommand: string;
transactionType: { deposit: boolean, withdrawal: boolean } = { deposit: false, withdrawal: false };

/**
* Retrieves action details transactions template data from `resolve`
Expand All @@ -64,8 +67,10 @@ export class DepositRecurringDepositsAccountComponent implements OnInit {
this.transactionAmount = this.transactionAmount + this.outstandingChargeAmount;
}
});
const name: string = this.route.snapshot.params['name'];
this.action = name.toLowerCase();
this.actionName = this.route.snapshot.params['name'];
this.action = this.actionName.toLowerCase();
this.transactionCommand = this.action.toLowerCase();
this.transactionType[this.transactionCommand] = true;
this.accountId = this.route.parent.snapshot.params['recurringDepositAccountId'];
}

Expand All @@ -80,7 +85,7 @@ export class DepositRecurringDepositsAccountComponent implements OnInit {
createdepositRecurringDepositForm() {
this.depositRecurringDepositForm = this.formBuilder.group({
'transactionDate': [new Date(), Validators.required],
'transactionAmount': [this.transactionAmount, Validators.required],
'transactionAmount': [0.0, Validators.required],
'paymentTypeId': ['', Validators.required],
'note': ''
});
Expand Down Expand Up @@ -131,6 +136,7 @@ export class DepositRecurringDepositsAccountComponent implements OnInit {
};

delete data['note'];
data['transactionAmount'] = data['transactionAmount'] * 1;
this.recurringDepositsService.executeRecurringDepositsAccountCommand(this.accountId, this.action, data).subscribe(() => {
this.router.navigate(['../../'], { relativeTo: this.route });
});
Expand Down
Loading

0 comments on commit b23efd3

Please sign in to comment.