Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { Component, OnInit, OnChanges, Input, SimpleChanges, Output, EventEmitter, ViewChild, ElementRef } from '@angular/core';
- import { FormGroup, Validators, FormControl } from '@angular/forms';
- import { SelectItem } from 'ng2-select';
- import { ACCOUNT_TYPE, TRANSACTION_STATUSES, TRANSACTION_MODES, SOURCE_TYPE, COMPLIANCE_REVIEW_STATUS, COMPLIANCE_REVIEW_DOCUMENT } from '../../../../consts';
- import { ModalDirective } from 'ngx-bootstrap';
- import { MessagesService } from '../../../services/messages.service';
- import { Country } from "../../../models/country.model";
- import { Currency } from "../../../models/currency.model";
- import { CompanyService } from "../../../services/company.service";
- import { MetaDataService } from "../../../services/metadata.service";
- import { noSpecialCharactersValidator } from "../../../validators/no-special-characters.validator";
- import { accountNumberValidator } from "../../../validators/account-number.validator";
- import { ibanValidator } from "../../../validators/iban.validator";
- import { TransactionService } from '../../../services/transaction.service';
- import { PrintThisDirective } from '../../print-this/print-this.directive';
- import { BtnSpinnerDirective } from '../../btn-spinner/btn-spinner.directive';
- import { Company } from '../../../models/company.model';
- import { FileWithAlias } from '../../../models/file-with-alias.model';
- import { CurrencyRatesService } from '../../../services/currency-rates.service';
- import { DebitTransactionBaseComponent } from '../../../base/debit-transaction-base-component';
- import { AuthenticationService } from '../../../services/authentication.service';
- import { Router, ActivatedRoute } from '@angular/router';
- import { CompanyBrand } from 'shared/models/company-brand.model';
- import { AppNgSelectComponent } from 'shared/components/app-ng-select/app-ng-select.component';
- import { ModalViewTransactionModal } from 'shared/models/modal-view-transaction.model';
- import { ITransactionModal } from 'shared/models/modal-transaction.model';
- import { AreaSpinnerDirective } from 'shared/components/area-spinner/area-spinner.directive';
- @Component({
- selector: 'debit-transaction-view',
- templateUrl: 'debit-transaction-view.html',
- styleUrls: ['./debit-transaction-view.component.scss']
- })
- export class DebitTransactionViewComponent extends DebitTransactionBaseComponent implements OnInit, OnChanges, ITransactionModal {
- @Input() data: ModalViewTransactionModal;
- @Input() mode: string;
- @Input() showArrows = true;
- @Output() onSave: EventEmitter<boolean> = new EventEmitter<boolean>();
- @Output() onPreviousClick = new EventEmitter<number>();
- @Output() onNextClick = new EventEmitter<number>();
- @Output() onModeChanged = new EventEmitter<string>();
- isTemplate: boolean = false;
- brand: CompanyBrand;
- form: FormGroup;
- SOURCE_TYPE = SOURCE_TYPE;
- TRANSACTION_STATUSES = TRANSACTION_STATUSES;
- // mode: string = TRANSACTION_MODES.view;
- allCountries: Country[];
- countries: Country[];
- allCurrencies: Currency[];
- targetCurrencies: Currency[];
- currencies: Currency[];
- selectedAccountType: string;
- accountTypes: any[] = [
- { id: ACCOUNT_TYPE.iban, text: "Iban" },
- { id: ACCOUNT_TYPE.accountNumber, text: "Account Number" }
- ];
- complianceReviewStatuses: { id: number, text: string }[] = [
- { id: COMPLIANCE_REVIEW_STATUS.approved, text: "Approved" },
- { id: COMPLIANCE_REVIEW_STATUS.approvedAndInfoRequired, text: "Approved & additional info required" },
- { id: COMPLIANCE_REVIEW_STATUS.infoRequired, text: "Additional info required" },
- { id: COMPLIANCE_REVIEW_STATUS.escalateToMlro, text: "Escalate to MLRO" }
- ];
- complianceReviewDocuments: { id: number, text: string }[] = [
- { id: COMPLIANCE_REVIEW_DOCUMENT.idOrPassport, text: "ID / Passport" },
- { id: COMPLIANCE_REVIEW_DOCUMENT.agreementOrInvoice, text: "Agreement/ Invoice" },
- { id: COMPLIANCE_REVIEW_DOCUMENT.businessOrPurpose, text: "Nature of business / purpose of relationship" },
- { id: COMPLIANCE_REVIEW_DOCUMENT.other, text: "Other" }
- ];
- TRANSACTION_MODES = TRANSACTION_MODES;
- COMPLIANCE_REVIEW_STATUS = COMPLIANCE_REVIEW_STATUS;
- dataType: string = 'debitTransaction';
- isShowAddRequiredInfoField = false;
- selectedFile: FileWithAlias;
- selectedFileAlias: string;
- filesForUpload: FileWithAlias[] = [];
- extensions = [];
- maxFileSize;
- transactionDocuments: any[] = [];
- isClient: boolean;
- @ViewChild('beneficiaryCountriesSelect') private beneficiaryCountrySelect: AppNgSelectComponent;
- @ViewChild('targetCurrenciesSelect') private targetCurrenciesSelect: AppNgSelectComponent;
- @ViewChild('currenciesToDebitSelect') private currenciesToDebitSelect: AppNgSelectComponent;
- @ViewChild('beneficiaryBankCountriesSelect') private beneficiaryBankCountrySelect: AppNgSelectComponent;
- @ViewChild('accountTypeSelect') private accountTypeSelect: AppNgSelectComponent;
- @ViewChild('complianceReviewStatusSelect') private complianceReviewStatusSelect: AppNgSelectComponent;
- @ViewChild('complianceReviewDocumentSelect') private complianceReviewDocumentSelect: AppNgSelectComponent;
- @ViewChild('additionalInformation') private additionalInformation: ElementRef;
- @ViewChild('viewDetailsModal') private viewDetailsModal: ModalDirective;
- @ViewChild('viewTransactionEle') private viewTransactionEle: ElementRef;
- @ViewChild('paymentConfirmationPrintDir') private paymentConfirmationPrintDir: PrintThisDirective;
- @ViewChild('printMenuSpinner') printMenuSpinner: BtnSpinnerDirective;
- @ViewChild('fileInput') fileInput: ElementRef;
- @ViewChild('saveBtnSpinner') saveBtnSpinner: BtnSpinnerDirective;
- @ViewChild('modalAreaSpinner') modalAreaSpinner: AreaSpinnerDirective;
- isAdminBased: boolean = false;
- editDisabled: boolean = false;
- isReadOnly: boolean = false;
- company: Company;
- currentTime: Date;
- constructor(private messagesService: MessagesService,
- companyService: CompanyService,
- transactionService: TransactionService,
- authService: AuthenticationService,
- private metadataService: MetaDataService,
- currencyRatesService: CurrencyRatesService,
- private router: Router,
- private route: ActivatedRoute) {
- super(authService, companyService, currencyRatesService, transactionService);
- }
- async ngOnInit() {
- this.isAdminBased = this.authService.isAdminBased();
- this.isReadOnly = this.authService.isReadOnly();
- this.isClient = this.authService.isClient();
- this.mode = TRANSACTION_MODES.view;
- this.form = new FormGroup({
- id: new FormControl('', [Validators.required]),
- companyId: new FormControl('', [Validators.required]),
- isDebit: new FormControl(false, [Validators.required]),
- source: new FormControl(''),
- beneficiaryName: new FormControl('', [Validators.required, Validators.maxLength(100), noSpecialCharactersValidator]),
- beneficiaryCountry: new FormControl('', [Validators.required]),
- beneficiaryAddress: new FormControl('', [Validators.required, Validators.maxLength(100), noSpecialCharactersValidator]),
- targetAmount: new FormControl('', [Validators.required, Validators.min(0.01)]),
- targetCurrency: new FormControl('', [Validators.required]),
- currency: new FormControl({ value: null, disabled: true }, [Validators.required]),
- accountNumber: new FormControl({ value: '', disabled: true }),
- routingNumber: new FormControl('', [Validators.maxLength(100), accountNumberValidator]),
- reason: new FormControl('', [Validators.required, noSpecialCharactersValidator]),
- beneficiaryBankName: new FormControl('', [Validators.required, Validators.maxLength(100), noSpecialCharactersValidator]),
- beneficiaryBankCountry: new FormControl('', [Validators.required]),
- beneficiaryBankAddress: new FormControl('', [Validators.required, Validators.maxLength(100), noSpecialCharactersValidator]),
- beneficiaryCompanyId: new FormControl(0),
- intermediateBank: new FormControl('', [Validators.maxLength(100), noSpecialCharactersValidator]),
- bic: new FormControl('', [Validators.required, Validators.maxLength(100), accountNumberValidator]),
- accountType: new FormControl('', [Validators.required]),
- status: new FormControl('', [Validators.required]),
- requiredAdditionalInformation: new FormControl(''),
- additionalInformation: new FormControl('', [noSpecialCharactersValidator]),
- isUrgent: new FormControl(''),
- complianceReviewStatus: new FormControl(''),
- complianceReviewDocument: new FormControl('')
- });
- this.addSub = this.form.controls['accountType'].valueChanges.subscribe((value: number) => {
- if (value && this.form.controls['accountType'].enabled) {
- this.form.controls['accountNumber'].enable();
- if (value == ACCOUNT_TYPE.iban) {
- this.form.controls['accountNumber'].setValidators([Validators.required, Validators.maxLength(100), ibanValidator]);
- }
- else {
- this.form.controls['accountNumber'].setValidators([Validators.required, Validators.maxLength(100), accountNumberValidator]);
- }
- this.form.controls['accountNumber'].updateValueAndValidity();
- }
- else {
- this.form.controls['accountNumber'].disable();
- this.form.controls['accountNumber'].clearValidators();
- }
- });
- this.addSub = this.form.controls['complianceReviewStatus'].valueChanges.subscribe((value: number | null) => {
- if(!this.isClient) {
- this.form.controls['complianceReviewStatus'].setValidators([Validators.required]);
- value === COMPLIANCE_REVIEW_STATUS.approvedAndInfoRequired || value === COMPLIANCE_REVIEW_STATUS.infoRequired ?
- this.form.controls['complianceReviewDocument'].setValidators([Validators.required]) : this.form.controls['complianceReviewDocument'].clearValidators();
- }
- });
- // added func on completeStatusTransaction
- if(this.data && this.data.status === 2) {
- this.complianceReviewStatuses = this.complianceReviewStatuses.slice(0, 2);
- }
- }
- async ngOnChanges(changes: SimpleChanges) {
- if (changes['data'] && changes['data'].isFirstChange()) {
- const fileMedata = await this.metadataService.getUploadedFileSettings().toPromise();
- this.maxFileSize = fileMedata.maxFileSize;
- this.extensions = fileMedata.supportedExtensions;
- await this.loadMetadata();
- await this.loadCompany();
- }
- if (this.data) {
- if (changes['data'] && changes['data'].currentValue && changes['data'].currentValue != changes['data'].previousValue) {
- await this.loadMetadata();
- await this.loadCompany()
- this.fillForm();
- this.filterCountries(this.company);
- if (this.isConversionPaymentsEnabled) {
- this.calculateConversion();
- }
- }
- }
- }
- async loadCompany() {
- if (!this.isAdminBased) {
- this.company = await this.companyService.getDetails().toPromise();
- } else {
- if (!this.data) {
- //this.company =[];
- } else {
- this.company = await this.companyService.getDetailsById(this.data.companyId).toPromise();
- }
- }
- }
- async loadMetadata() {
- try {
- const data = await this.metadataService.loadMetaData().toPromise();
- this.allCountries = data.countries;
- this.allCurrencies = data.currencies;
- this.filterCountries();
- this.currencies = await this.companyService.getCurrencies().toPromise();
- } catch (err) {
- console.error(err);
- }
- }
- calculateConversion() {
- super.calculateConversion(this.data);
- }
- filterCountries(company: Company = null) {
- if (!company) {
- this.countries = this.allCountries.filter(c => !c.isBlocked);
- } else if (!company.companyAdditionalCountries || !company.companyAdditionalCountries.length) {
- this.countries = this.allCountries.filter(c => !c.isBlocked);
- } else {
- const whiteListExceptionCountryIds: number[] = company.companyAdditionalCountries.filter(c => !c.isBlocked).map(c => c.countryId);
- const blackListExceptionCountryIds: number[] = company.companyAdditionalCountries.filter(c => c.isBlocked).map(c => c.countryId);
- this.countries = this.allCountries
- .filter(c =>
- (!c.isBlocked || whiteListExceptionCountryIds.includes(c.id))
- &&
- !blackListExceptionCountryIds.includes(c.id)
- );
- }
- }
- showDetails(mode: string = null) {
- this.filesForUpload = [];
- this.viewDetailsModal.config.backdrop = 'static';
- this.viewDetailsModal.show();
- }
- onViewHeaderClick() {
- this.mode = TRANSACTION_MODES.view;
- }
- onEditHeaderClick() {
- this.mode = TRANSACTION_MODES.edit;
- }
- onRefundHeaderClick() {
- this.mode = TRANSACTION_MODES.refund;
- }
- changeMode(mode: string) {
- this.mode = mode;
- }
- hideViewDetailsModal() {
- this.modalAreaSpinner && this.modalAreaSpinner.stop();
- this.clearForm();
- this.onModeChanged.emit(this.mode);
- this.viewDetailsModal.hide();
- const transactionId = Number(this.route.snapshot.params.id);
- const open = this.route.snapshot.params.open;
- if (!transactionId || !open) {
- return;
- }
- this.router.navigate([this.route.snapshot.url[0].path, this.route.snapshot.url[1].path]);
- }
- get showEdit() {
- return !this.isReadOnly && this.data && this.data.status !== TRANSACTION_STATUSES.rejected;
- }
- get canShowRefundButton() {
- const data = this.data;
- return this.isAdminBased && data && !this.transactionService.isRefunded(data) && (data.source === SOURCE_TYPE.wireIn || data.source === SOURCE_TYPE.wireOut)
- && data.status === TRANSACTION_STATUSES.approved && !this.isReadOnly;
- }
- clearForm() {
- this.form.reset();
- this.beneficiaryCountrySelect.remove(this.beneficiaryCountrySelect.activeOption);
- this.beneficiaryBankCountrySelect.remove(this.beneficiaryBankCountrySelect.activeOption);
- this.targetCurrenciesSelect.active = [];
- if (this.currenciesToDebitSelect) {
- this.currenciesToDebitSelect.active = [];
- }
- this.accountTypeSelect.remove(this.accountTypeSelect.activeOption);
- if (this.complianceReviewStatusSelect) {
- this.complianceReviewStatusSelect.remove(this.complianceReviewStatusSelect.activeOption);
- }
- if (this.complianceReviewDocumentSelect) {
- this.complianceReviewDocumentSelect.remove(this.complianceReviewDocumentSelect.activeOption);
- }
- this.editDisabled = false;
- this.clearFiles();
- }
- fillForm() {
- this.form.controls['id'].setValue(this.data.id);
- this.form.controls['isDebit'].setValue(this.data.isDebit);
- this.form.controls['source'].setValue(this.data.source);
- this.form.controls['companyId'].setValue(this.data.companyId);
- this.form.controls['beneficiaryCountry'].setValue(this.data.beneficiaryCountry);
- this.form.controls['beneficiaryAddress'].setValue(this.data.beneficiaryAddress);
- this.form.controls['beneficiaryName'].setValue(this.data.beneficiaryName);
- this.form.controls['targetAmount'].setValue(this.data.targetAmount);
- this.form.controls['targetCurrency'].setValue(this.data.targetCurrency);
- this.form.controls['currency'].setValue(this.data.currency);
- this.form.controls['accountNumber'].setValue(this.data.accountNumber);
- this.form.controls['routingNumber'].setValue(this.data.routingNumber);
- this.form.controls['reason'].setValue(this.data.reason);
- this.form.controls['beneficiaryBankName'].setValue(this.data.beneficiaryBankName);
- this.form.controls['beneficiaryBankCountry'].setValue(this.data.beneficiaryBankCountry);
- this.form.controls['beneficiaryBankAddress'].setValue(this.data.beneficiaryBankAddress);
- this.form.controls['beneficiaryCompanyId'].setValue(this.data.beneficiaryCompanyId);
- this.form.controls['intermediateBank'].setValue(this.data.intermediateBank);
- this.form.controls['bic'].setValue(this.data.bic);
- this.form.controls['status'].setValue(this.data.status);
- this.form.controls['accountType'].setValue(this.data.accountType);
- this.form.controls['complianceReviewStatus'].setValue(this.data.complianceReviewStatus);
- this.form.controls['complianceReviewDocument'].setValue(this.data.complianceReviewDocument);
- this.form.controls['requiredAdditionalInformation'].setValue(!!this.data.requiredAdditionalInformation);
- this.form.controls['isUrgent'].setValue(this.data.isUrgent)
- this.form.controls['additionalInformation'].setValue(this.data.additionalInformation);
- if (!this.data.requiredAdditionalInformation) {
- this.form.controls['additionalInformation'].disable();
- }
- this.fillTargetCurrencies();
- if (this.data.beneficiaryCountry) {
- const beneficiaryCountrySelect = this.beneficiaryCountrySelect.itemObjects
- .find((item) => item.id == ('' + this.data.beneficiaryCountry.id));
- if (beneficiaryCountrySelect) {
- this.beneficiaryCountrySelect.active = [beneficiaryCountrySelect];
- } /*else {
- const country = { id: this.data.beneficiaryCountry.id, text: this.data.beneficiaryCountry.name };
- this.beneficiaryCountrySelect.active = [country];
- }*/
- }
- if (this.data.beneficiaryBankCountry) {
- const beneficiaryBankCountry = this.beneficiaryBankCountrySelect.itemObjects
- .find((item) => item.id == ('' + this.data.beneficiaryBankCountry.id));
- if (beneficiaryBankCountry) {
- this.beneficiaryBankCountrySelect.active = [beneficiaryBankCountry];
- } else {
- const country = { id: this.data.beneficiaryBankCountry.id, text: this.data.beneficiaryBankCountry.name };
- this.beneficiaryBankCountrySelect.active = [country];
- }
- }
- setTimeout(() => {
- if (this.data.targetCurrency) {
- const targetCurrency = this.targetCurrenciesSelect.itemObjects.find((item) => item.id == this.data.targetCurrency.id);
- this.targetCurrenciesSelect.active = targetCurrency ? [targetCurrency] : [];
- }
- if (this.data.currency && this.currenciesToDebitSelect) {
- const currency = this.currenciesToDebitSelect.itemObjects.find((item) => item.id == this.data.currency.id);
- this.currenciesToDebitSelect.active = currency ? [currency] : [];
- }
- if (this.data.accountType) {
- const accountType = this.accountTypes.find((item) => item.id == this.data.accountType);
- this.accountTypeSelect.active = accountType ? [accountType] : [];
- this.selectedAccountType = this.accountTypeSelect.active[0].text;
- }
- if (this.data) {
- this.updateComplianceReviewStatusSelect();
- this.updateComplianceReviewDocumentSelect();
- }
- if (this.data.additionalInformation && this.data.additionalInformation.length) {
- this.form.controls['additionalInformation'].setValue(this.data.additionalInformation);
- }
- // added func on completeStatusTransaction or reject
- if (this.data &&
- (this.data.status === TRANSACTION_STATUSES.approved && this.data.complianceReviewStatus !== COMPLIANCE_REVIEW_STATUS.approvedAndInfoRequired )
- || this.data.status === TRANSACTION_STATUSES.rejected){
- this.complianceReviewStatusSelect.disabled = true;
- if (this.complianceReviewDocumentSelect) {
- this.complianceReviewDocumentSelect.disabled = true;
- }
- } else {
- this.complianceReviewStatusSelect.disabled = false;
- if (this.complianceReviewDocumentSelect) {
- this.complianceReviewDocumentSelect.disabled = false;
- }
- }
- if (this.data && this.data.status === TRANSACTION_STATUSES.approved &&
- this.data.complianceReviewStatus === COMPLIANCE_REVIEW_STATUS.approvedAndInfoRequired && this.additionalInformation) {
- this.additionalInformation.nativeElement.disabled = false;
- } else if (this.data && this.data.status === TRANSACTION_STATUSES.approved &&
- this.data.complianceReviewStatus !== COMPLIANCE_REVIEW_STATUS.approvedAndInfoRequired && this.additionalInformation) {
- this.additionalInformation.nativeElement.disabled = true;
- }
- }, 0);
- //this.data.status !== TRANSACTION_STATUSES.pending && this.data.status !== TRANSACTION_STATUSES.companyApproval;
- if (this.data.status !== TRANSACTION_STATUSES.pending && this.data.status !== TRANSACTION_STATUSES.toSign) {
- this.editDisabled = true;
- } else if (this.data.requiredAdditionalInformation && !this.isAdminBased) {
- // check is it needs
- this.editDisabled = true;
- } else {
- this.editDisabled = false;
- }
- this.transactionDocuments = this.data.documents;
- this.canUpdateDebitTransaction();
- this.disableEnableForm();
- }
- canUpdateDebitTransaction() {
- if (this.isClient) {
- this.editDisabled = this.data.canClientEdit ? false : true;
- }
- }
- updateComplianceReviewStatusSelect() {
- const reviewStatuses = this.complianceReviewStatuses.find(({id}) => id === this.data.complianceReviewStatus);
- if (this.complianceReviewStatusSelect) {
- this.complianceReviewStatusSelect.active = reviewStatuses ? [reviewStatuses] : [];
- }
- }
- updateComplianceReviewDocumentSelect() {
- const reviewDocuments = this.complianceReviewDocuments.find(({id}) => id === this.data.complianceReviewDocument);
- if (this.complianceReviewDocumentSelect) {
- this.complianceReviewDocumentSelect.active = reviewDocuments ? [reviewDocuments] : [];
- }
- }
- disableEnableForm() {
- this.targetCurrenciesSelect.disabled = true;
- if (this.currenciesToDebitSelect) {
- this.currenciesToDebitSelect.disabled = true;
- }
- this.beneficiaryCountrySelect.disabled = this.editDisabled;
- this.beneficiaryBankCountrySelect.disabled = this.editDisabled;
- this.accountTypeSelect.disabled = this.editDisabled;
- if (this.editDisabled) {
- this.form.disable();
- this.form.controls['requiredAdditionalInformation'].enable();
- if (this.form.controls['requiredAdditionalInformation'].value) {
- this.form.controls['additionalInformation'].enable();
- }
- }
- else {
- this.form.enable();
- }
- }
- hasError(controlName: string) {
- let control = this.form.controls[controlName];
- if (!control) {
- return false;
- }
- return !control.disabled && control.dirty && !control.valid;
- }
- onAccountTypeSelected(value: SelectItem) {
- this.form.controls['accountType'].setValue(value.id);
- this.form.controls['accountNumber'].markAsDirty();
- }
- onAccountTypeRemoved() {
- this.form.controls['accountType'].reset();
- }
- onComplianceReviewStatusSelected(value: SelectItem) {
- this.onComplianceReviewSelected(value.id, 'complianceReviewStatus');
- this.updateComplianceReviewFields();
- }
- updateComplianceReviewFields() {
- this.onComplianceReviewRemoved('complianceReviewDocument');
- if (this.complianceReviewDocumentSelect && this.complianceReviewDocumentSelect.active) {
- this.complianceReviewDocumentSelect.active = [];
- }
- this.onComplianceReviewRemoved('additionalInformation');
- if (this.data && this.data.status === TRANSACTION_STATUSES.approved) {
- this.form.controls['complianceReviewStatus'].enable();
- this.form.controls['complianceReviewDocument'].enable();
- }
- // make visibled additionalInformation textarea if transaction status - completed
- setTimeout(() => {
- if (this.data && this.data.status === TRANSACTION_STATUSES.approved && this.form.controls['complianceReviewStatus'].value === COMPLIANCE_REVIEW_STATUS.approvedAndInfoRequired
- && this.additionalInformation) {
- this.additionalInformation.nativeElement.disabled = false;
- }
- });
- }
- onComplianceReviewSelected(id: string, fieldName: string) {
- this.form.controls[fieldName].setValue(id);
- }
- onComplianceReviewRemoved(fieldName: string) {
- this.form.controls[fieldName].reset();
- }
- getComplianceReviewMessage() {
- const str = this.transactionService.getComplianceReviewMessage(this.form.controls['complianceReviewStatus'].value,
- this.form.controls['complianceReviewDocument'].value);
- this.form.controls['additionalInformation'].setValue(str);
- }
- onTargetCurrencySelected(value: Currency) {
- const selected = this.allCurrencies.find((item) => item.id == value.id);
- this.form.controls['targetCurrency'].setValue(selected);
- this.calculateConversion();
- }
- onTargetCurrencyRemoved() {
- this.form.controls['targetCurrency'].setValue(null);
- this.calculateConversion();
- }
- onCurrencyToDebitSelected(value: Currency) {
- const selected = this.currencies.find((item) => item.id == value.id);
- this.form.controls['currency'].setValue(selected);
- this.calculateConversion();
- }
- onCurrencyToDebitRemoved() {
- this.form.controls['currency'].setValue(null);
- this.calculateConversion();
- }
- onBeneficiaryCountrySelected(value: any) {
- let selected = this.countries.find((item) => item.id == value.id);
- this.form.controls['beneficiaryCountry'].setValue(selected);
- let routingNumber = this.form.controls['routingNumber'].value;
- if (selected.code === 'CA' || selected.code === 'US') {
- this.form.setControl('routingNumber', new FormControl(routingNumber, [Validators.required, accountNumberValidator]));
- }
- else {
- this.form.setControl('routingNumber', new FormControl(routingNumber, [accountNumberValidator]));
- }
- }
- onBeneficiaryCountryRemoved() {
- this.form.controls['beneficiaryCountry'].reset();
- }
- onBeneficiaryBankCountrySelected(value: any) {
- let selected = this.countries.find((item) => item.id == value.id);
- this.form.controls['beneficiaryBankCountry'].setValue(selected);
- }
- onBeneficiaryBankCountryRemoved() {
- this.form.controls['beneficiaryBankCountry'].reset();
- }
- ontToggleAdditionalInfo(event: boolean) {
- this.form.controls['requiredAdditionalInformation'].setValue(event);
- if (event) {
- this.form.controls['additionalInformation'].enable();
- }
- else {
- this.form.controls['additionalInformation'].disable();
- }
- }
- onToggleIsUrgent(isUrgent: boolean) {
- this.form.controls['isUrgent'].setValue(isUrgent);
- }
- async onSubmit(event) {
- event.preventDefault();
- if (this.form.valid) {
- this.form.enable();
- try {
- this.saveBtnSpinner.start();
- await this.transactionService.updateDebitTransaction({
- ...{ ...this.form.value, createDate: this.data.createDate },
- documents: this.transactionDocuments
- }, this.filesForUpload).toPromise();
- this.messagesService.success(`Transaction #${this.form.controls['id'].value} Updated successfully.`);
- this.afterSuccessSubmit();
- } catch (error) {
- console.error(error);
- }
- finally {
- this.saveBtnSpinner.stop();
- }
- }
- }
- afterSuccessSubmit() {
- this.hideViewDetailsModal();
- this.onSave.emit(true);
- }
- getTransactionStatusName(transactionStatus) {
- switch (transactionStatus) {
- case TRANSACTION_STATUSES.approved:
- return 'Completed';
- case TRANSACTION_STATUSES.toSign:
- return 'To Sign';
- case TRANSACTION_STATUSES.deleted:
- return 'Deleted';
- case TRANSACTION_STATUSES.pending:
- return 'Pending';
- case TRANSACTION_STATUSES.rejected:
- return 'Rejected';
- default:
- return '';
- }
- }
- async onPaymentConfirmationPrintClick() {
- try {
- this.printMenuSpinner.start();
- this.brand = await this.metadataService.getBrandInfo().toPromise();
- this.company = await this.companyService.getDetailsById(this.data.companyId).toPromise();
- this.currentTime = new Date();
- this.printMenuSpinner.stop();
- setTimeout(() => {
- this.paymentConfirmationPrintDir.print();
- });
- } catch (err) {
- console.error(err);
- } finally {
- this.printMenuSpinner.stop();
- }
- }
- onFileSelect(ev) {
- this.selectedFile = ev.target.files[0];
- ev.target.value = null;
- }
- onFileUploadClick(ev) {
- ev.preventDefault();
- if (!this.selectedFile) {
- return;
- }
- const exntension = this.selectedFile.name.split('.').pop()
- this.selectedFile.alias = this.selectedFileAlias ? (this.selectedFileAlias + '.' + exntension) : this.selectedFile.name;
- this.filesForUpload.push(this.selectedFile);
- this.clearFiles();
- }
- clearFiles() {
- this.selectedFile = null;
- this.selectedFileAlias = null;
- if (this.fileInput && this.fileInput.nativeElement) {
- this.fileInput.nativeElement.value = null;
- }
- }
- get isFileExtensionInvalid() {
- if (!this.extensions.length) {
- return false;
- }
- return this.selectedFile && this.extensions.indexOf(this.selectedFile.name.split('.').pop().toLowerCase()) === -1;
- }
- get isFileSizeInvalid() {
- if (!this.maxFileSize) {
- return false;
- }
- return this.selectedFile && this.selectedFile.size > this.maxFileSize * 1000000;
- }
- get isFileInvalid() {
- return !this.selectedFile || !this.selectedFile.name || !this.selectedFile.name.length || !this.selectedFile.size || this.isFileExtensionInvalid || this.isFileSizeInvalid;
- }
- removeFromFilesToUpload(file: FileWithAlias) {
- this.filesForUpload = this.filesForUpload.filter(f => f !== file);
- }
- removeFromTransactionDocuments(key: string) {
- this.transactionDocuments = this.transactionDocuments.filter(d => d.key !== key);
- }
- async downloadDocument(key: string) {
- if (key) {
- await this.transactionService.downloadDocument(key).toPromise();
- }
- }
- get canWorkingWithDocuments(): boolean {
- if (!this.data) {
- return false;
- }
- if (this.isAdminBased) {
- return true;
- }
- if (this.data.status === TRANSACTION_STATUSES.pending || this.data.status === TRANSACTION_STATUSES.toSign) {
- return true;
- }
- return false;
- }
- get isConversionPaymentsEnabled() {
- return this.data && this.data.currency && this.data.targetCurrency && this.data.currency.id !== this.data.targetCurrency.id;
- }
- fillTargetCurrencies() {
- if (this.isConversionPaymentsEnabled) {
- this.targetCurrencies = [
- ...this.allCurrencies.filter(c => this.company.conversionAllowedCurrencies.includes(c.id)),
- ...this.currencies
- ];
- this.form.get('currency').enable();
- } else {
- this.targetCurrencies = [...this.currencies];
- this.form.get('currency').disable();
- }
- }
- trackByDocumentId(document: any) {
- return document.key;
- }
- getPrevious() {
- this.modalAreaSpinner && this.modalAreaSpinner.start();
- this.onPreviousClick.emit(this.data.id);
- }
- getNext() {
- this.modalAreaSpinner && this.modalAreaSpinner.start();
- this.onNextClick.emit(this.data.id);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement