feat: interbank transfer (#2299)
This commit is contained in:
+145
-12
@@ -1,13 +1,24 @@
|
||||
/** Angular Imports */
|
||||
import { Component, OnInit, AfterViewInit } from '@angular/core';
|
||||
import { Component, OnInit, AfterViewInit, ViewChild, ElementRef } from '@angular/core';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { UntypedFormBuilder, UntypedFormGroup, Validators } from '@angular/forms';
|
||||
import {
|
||||
AbstractControl,
|
||||
FormGroup,
|
||||
UntypedFormBuilder,
|
||||
UntypedFormGroup,
|
||||
ValidationErrors,
|
||||
Validators
|
||||
} from '@angular/forms';
|
||||
|
||||
/** Custom Services */
|
||||
import { AccountTransfersService } from '../account-transfers.service';
|
||||
import { SettingsService } from 'app/settings/settings.service';
|
||||
import { ClientsService } from 'app/clients/clients.service';
|
||||
import { Dates } from 'app/core/utils/dates';
|
||||
import { MatInput } from '@angular/material/input';
|
||||
|
||||
/** Environment Configuration */
|
||||
import { environment } from 'environments/environment';
|
||||
|
||||
/**
|
||||
* Create account transfers
|
||||
@@ -26,6 +37,7 @@ export class MakeAccountTransfersComponent implements OnInit, AfterViewInit {
|
||||
maxDate = new Date(2100, 0, 1);
|
||||
/** Edit Standing Instructions form. */
|
||||
makeAccountTransferForm: UntypedFormGroup;
|
||||
//makeAccountInterbankTransferForm: FormGroup;
|
||||
/** To Office Type Data */
|
||||
toOfficeTypeData: any;
|
||||
/** To Client Type Data */
|
||||
@@ -42,6 +54,13 @@ export class MakeAccountTransfersComponent implements OnInit, AfterViewInit {
|
||||
id: any;
|
||||
/** Clients Data */
|
||||
clientsData: any;
|
||||
/** interbank transfer */
|
||||
interbank: boolean = false;
|
||||
/** Reference of phoneAccount search */
|
||||
phoneAccount = '';
|
||||
interbankTransferForm: boolean = false;
|
||||
balance: number = 0;
|
||||
isLoading: boolean = false;
|
||||
|
||||
/**
|
||||
* Retrieves the standing instructions template from `resolve`.
|
||||
@@ -77,8 +96,12 @@ export class MakeAccountTransfersComponent implements OnInit, AfterViewInit {
|
||||
this.id = this.route.snapshot.queryParams['loanId'];
|
||||
break;
|
||||
case 'fromsavings':
|
||||
case 'interbank':
|
||||
this.accountTypeId = '2';
|
||||
this.id = this.route.snapshot.queryParams['savingsId'];
|
||||
this.interbank = this.route.snapshot.queryParams['interbank'] === 'true';
|
||||
this.balance = this.router.getCurrentNavigation().extras.state.balance;
|
||||
console.log('is interbank?', this.interbank);
|
||||
break;
|
||||
default:
|
||||
this.accountTypeId = '0';
|
||||
@@ -90,7 +113,9 @@ export class MakeAccountTransfersComponent implements OnInit, AfterViewInit {
|
||||
*/
|
||||
ngOnInit() {
|
||||
this.maxDate = this.settingsService.businessDate;
|
||||
this.createMakeAccountTransferForm();
|
||||
if (!this.interbank) {
|
||||
this.createMakeAccountTransferForm();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -116,7 +141,10 @@ export class MakeAccountTransfersComponent implements OnInit, AfterViewInit {
|
||||
],
|
||||
transferAmount: [
|
||||
this.accountTransferTemplateData.transferAmount,
|
||||
Validators.required
|
||||
[
|
||||
Validators.required,
|
||||
Validators.min(0.01),
|
||||
this.amountExceedsBalanceValidator.bind(this)]
|
||||
],
|
||||
transferDate: [
|
||||
this.settingsService.businessDate,
|
||||
@@ -129,6 +157,48 @@ export class MakeAccountTransfersComponent implements OnInit, AfterViewInit {
|
||||
});
|
||||
}
|
||||
|
||||
createMakeAccountInterbankTransferForm(account: any) {
|
||||
/* --> */ this.makeAccountTransferForm = this.formBuilder.group({
|
||||
toBank: [
|
||||
{ value: account.sourceFspId, disabled: true },
|
||||
Validators.required
|
||||
],
|
||||
toClientId: [
|
||||
{ value: account.firsName + ' ' + account.lastName, disabled: true },
|
||||
Validators.required
|
||||
],
|
||||
toAccountType: [
|
||||
{ value: 'Saving Account', disabled: true },
|
||||
Validators.required
|
||||
],
|
||||
toAccountId: [
|
||||
{ value: account.partyId, disabled: true },
|
||||
Validators.required
|
||||
],
|
||||
transferAmount: [
|
||||
this.accountTransferTemplateData.transferAmount,
|
||||
[
|
||||
Validators.required,
|
||||
Validators.min(0.01),
|
||||
this.amountExceedsBalanceValidator.bind(this)]
|
||||
],
|
||||
transferDate: [
|
||||
this.settingsService.businessDate,
|
||||
Validators.required
|
||||
],
|
||||
transferDescription: [
|
||||
'',
|
||||
Validators.required
|
||||
]
|
||||
});
|
||||
this.isLoading = false;
|
||||
}
|
||||
|
||||
amountExceedsBalanceValidator(control: AbstractControl): ValidationErrors | null {
|
||||
const amount = control.value;
|
||||
return amount > this.balance ? { amountExceedsBalance: true } : null;
|
||||
}
|
||||
|
||||
/** Sets options value */
|
||||
setOptions() {
|
||||
this.toOfficeTypeData = this.accountTransferTemplateData.toOfficeOptions;
|
||||
@@ -172,14 +242,16 @@ export class MakeAccountTransfersComponent implements OnInit, AfterViewInit {
|
||||
* Subscribes to Clients search filter:
|
||||
*/
|
||||
ngAfterViewInit() {
|
||||
this.makeAccountTransferForm.controls.toClientId.valueChanges.subscribe((value: string) => {
|
||||
if (value.length >= 2) {
|
||||
this.clientsService.getFilteredClients('displayName', 'ASC', true, value).subscribe((data: any) => {
|
||||
this.clientsData = data.pageItems;
|
||||
});
|
||||
this.changeEvent();
|
||||
}
|
||||
});
|
||||
if (!this.interbank) {
|
||||
this.makeAccountTransferForm.controls.toClientId.valueChanges.subscribe((value: string) => {
|
||||
if (value.length >= 2) {
|
||||
this.clientsService.getFilteredClients('displayName', 'ASC', true, value).subscribe((data: any) => {
|
||||
this.clientsData = data.pageItems;
|
||||
});
|
||||
this.changeEvent();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -195,6 +267,11 @@ export class MakeAccountTransfersComponent implements OnInit, AfterViewInit {
|
||||
* Submits the standing instructions form
|
||||
*/
|
||||
submit() {
|
||||
this.interbank ? this.makeInterbankTransfer() : this.makeTransfer();
|
||||
}
|
||||
|
||||
makeTransfer() {
|
||||
this.isLoading = true;
|
||||
const dateFormat = this.settingsService.dateFormat;
|
||||
const locale = this.settingsService.language.code;
|
||||
const makeAccountTransferData = {
|
||||
@@ -209,7 +286,63 @@ export class MakeAccountTransfersComponent implements OnInit, AfterViewInit {
|
||||
fromOfficeId: this.accountTransferTemplateData.fromClient.officeId
|
||||
};
|
||||
this.accountTransfersService.createAccountTransfer(makeAccountTransferData).subscribe(() => {
|
||||
this.isLoading = false;
|
||||
this.router.navigate(['../../transactions'], { relativeTo: this.route });
|
||||
});
|
||||
}
|
||||
|
||||
makeInterbankTransfer() {
|
||||
this.isLoading = true;
|
||||
const payload = {
|
||||
homeTransactionId: crypto.randomUUID(),
|
||||
from: {
|
||||
fspId: environment.fineractPlatformTenantId,
|
||||
idType: 'MSISDN',
|
||||
idValue: this.accountTransferTemplateData.fromAccount.externalId.trim()
|
||||
},
|
||||
to: {
|
||||
fspId: this.makeAccountTransferForm.controls.toBank.value,
|
||||
idType: 'MSISDN',
|
||||
idValue: this.makeAccountTransferForm.controls.toAccountId.value
|
||||
},
|
||||
amountType: 'SEND',
|
||||
amount: {
|
||||
currencyCode: this.accountTransferTemplateData.currency.code,
|
||||
amount: this.makeAccountTransferForm.controls.transferAmount.value
|
||||
},
|
||||
transactionType: {
|
||||
scenario: 'TRANSFER',
|
||||
subScenario: 'DOMESTIC',
|
||||
initiator: 'PAYER',
|
||||
initiatorType: 'CUSTOMER'
|
||||
},
|
||||
note: this.makeAccountTransferForm.controls.transferDescription.value
|
||||
};
|
||||
this.accountTransfersService.sendInterbankTransfer(JSON.stringify(payload)).subscribe(
|
||||
(trnsfr) => {
|
||||
if (trnsfr.systemMessage) {
|
||||
this.isLoading = false;
|
||||
this.router.navigate(['../../transactions'], { relativeTo: this.route });
|
||||
}
|
||||
},
|
||||
(error) => {
|
||||
this.isLoading = false;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
searchAccountByNumber() {
|
||||
this.isLoading = true;
|
||||
this.accountTransfersService
|
||||
.getAccountByNumber(this.phoneAccount, this.accountTransferTemplateData.currency.code)
|
||||
.subscribe(
|
||||
(acc) => {
|
||||
this.interbankTransferForm = true;
|
||||
this.createMakeAccountInterbankTransferForm(acc);
|
||||
},
|
||||
(error) => {
|
||||
this.isLoading = false;
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user