Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 33.66 KB | None | 0 0
  1. import { Component, OnInit, OnChanges, Input, SimpleChanges, Output, EventEmitter, ViewChild, ElementRef } from '@angular/core';
  2. import { FormGroup, Validators, FormControl } from '@angular/forms';
  3. import { SelectItem } from 'ng2-select';
  4.  
  5. import { ACCOUNT_TYPE, TRANSACTION_STATUSES, TRANSACTION_MODES, SOURCE_TYPE, COMPLIANCE_REVIEW_STATUS, COMPLIANCE_REVIEW_DOCUMENT } from '../../../../consts';
  6. import { ModalDirective } from 'ngx-bootstrap';
  7. import { MessagesService } from '../../../services/messages.service';
  8. import { Country } from "../../../models/country.model";
  9. import { Currency } from "../../../models/currency.model";
  10. import { CompanyService } from "../../../services/company.service";
  11. import { MetaDataService } from "../../../services/metadata.service";
  12. import { noSpecialCharactersValidator } from "../../../validators/no-special-characters.validator";
  13. import { accountNumberValidator } from "../../../validators/account-number.validator";
  14. import { ibanValidator } from "../../../validators/iban.validator";
  15. import { TransactionService } from '../../../services/transaction.service';
  16. import { PrintThisDirective } from '../../print-this/print-this.directive';
  17. import { BtnSpinnerDirective } from '../../btn-spinner/btn-spinner.directive';
  18. import { Company } from '../../../models/company.model';
  19. import { FileWithAlias } from '../../../models/file-with-alias.model';
  20. import { CurrencyRatesService } from '../../../services/currency-rates.service';
  21. import { DebitTransactionBaseComponent } from '../../../base/debit-transaction-base-component';
  22. import { AuthenticationService } from '../../../services/authentication.service';
  23. import { Router, ActivatedRoute } from '@angular/router';
  24. import { CompanyBrand } from 'shared/models/company-brand.model';
  25. import { AppNgSelectComponent } from 'shared/components/app-ng-select/app-ng-select.component';
  26. import { ModalViewTransactionModal } from 'shared/models/modal-view-transaction.model';
  27. import { ITransactionModal } from 'shared/models/modal-transaction.model';
  28. import { AreaSpinnerDirective } from 'shared/components/area-spinner/area-spinner.directive';
  29.  
  30.  
  31. @Component({
  32. selector: 'debit-transaction-view',
  33. templateUrl: 'debit-transaction-view.html',
  34. styleUrls: ['./debit-transaction-view.component.scss']
  35. })
  36.  
  37. export class DebitTransactionViewComponent extends DebitTransactionBaseComponent implements OnInit, OnChanges, ITransactionModal {
  38. @Input() data: ModalViewTransactionModal;
  39. @Input() mode: string;
  40. @Input() showArrows = true;
  41. @Output() onSave: EventEmitter<boolean> = new EventEmitter<boolean>();
  42. @Output() onPreviousClick = new EventEmitter<number>();
  43. @Output() onNextClick = new EventEmitter<number>();
  44. @Output() onModeChanged = new EventEmitter<string>();
  45. isTemplate: boolean = false;
  46.  
  47. brand: CompanyBrand;
  48.  
  49. form: FormGroup;
  50. SOURCE_TYPE = SOURCE_TYPE;
  51. TRANSACTION_STATUSES = TRANSACTION_STATUSES;
  52. // mode: string = TRANSACTION_MODES.view;
  53. allCountries: Country[];
  54. countries: Country[];
  55. allCurrencies: Currency[];
  56. targetCurrencies: Currency[];
  57. currencies: Currency[];
  58. selectedAccountType: string;
  59. accountTypes: any[] = [
  60. { id: ACCOUNT_TYPE.iban, text: "Iban" },
  61. { id: ACCOUNT_TYPE.accountNumber, text: "Account Number" }
  62. ];
  63. complianceReviewStatuses: { id: number, text: string }[] = [
  64. { id: COMPLIANCE_REVIEW_STATUS.approved, text: "Approved" },
  65. { id: COMPLIANCE_REVIEW_STATUS.approvedAndInfoRequired, text: "Approved & additional info required" },
  66. { id: COMPLIANCE_REVIEW_STATUS.infoRequired, text: "Additional info required" },
  67. { id: COMPLIANCE_REVIEW_STATUS.escalateToMlro, text: "Escalate to MLRO" }
  68. ];
  69. complianceReviewDocuments: { id: number, text: string }[] = [
  70. { id: COMPLIANCE_REVIEW_DOCUMENT.idOrPassport, text: "ID / Passport" },
  71. { id: COMPLIANCE_REVIEW_DOCUMENT.agreementOrInvoice, text: "Agreement/ Invoice" },
  72. { id: COMPLIANCE_REVIEW_DOCUMENT.businessOrPurpose, text: "Nature of business / purpose of relationship" },
  73. { id: COMPLIANCE_REVIEW_DOCUMENT.other, text: "Other" }
  74. ];
  75. TRANSACTION_MODES = TRANSACTION_MODES;
  76. COMPLIANCE_REVIEW_STATUS = COMPLIANCE_REVIEW_STATUS;
  77. dataType: string = 'debitTransaction';
  78. isShowAddRequiredInfoField = false;
  79.  
  80. selectedFile: FileWithAlias;
  81. selectedFileAlias: string;
  82. filesForUpload: FileWithAlias[] = [];
  83.  
  84. extensions = [];
  85. maxFileSize;
  86. transactionDocuments: any[] = [];
  87. isClient: boolean;
  88.  
  89. @ViewChild('beneficiaryCountriesSelect') private beneficiaryCountrySelect: AppNgSelectComponent;
  90. @ViewChild('targetCurrenciesSelect') private targetCurrenciesSelect: AppNgSelectComponent;
  91. @ViewChild('currenciesToDebitSelect') private currenciesToDebitSelect: AppNgSelectComponent;
  92. @ViewChild('beneficiaryBankCountriesSelect') private beneficiaryBankCountrySelect: AppNgSelectComponent;
  93. @ViewChild('accountTypeSelect') private accountTypeSelect: AppNgSelectComponent;
  94. @ViewChild('complianceReviewStatusSelect') private complianceReviewStatusSelect: AppNgSelectComponent;
  95. @ViewChild('complianceReviewDocumentSelect') private complianceReviewDocumentSelect: AppNgSelectComponent;
  96. @ViewChild('additionalInformation') private additionalInformation: ElementRef;
  97. @ViewChild('viewDetailsModal') private viewDetailsModal: ModalDirective;
  98. @ViewChild('viewTransactionEle') private viewTransactionEle: ElementRef;
  99. @ViewChild('paymentConfirmationPrintDir') private paymentConfirmationPrintDir: PrintThisDirective;
  100. @ViewChild('printMenuSpinner') printMenuSpinner: BtnSpinnerDirective;
  101. @ViewChild('fileInput') fileInput: ElementRef;
  102. @ViewChild('saveBtnSpinner') saveBtnSpinner: BtnSpinnerDirective;
  103. @ViewChild('modalAreaSpinner') modalAreaSpinner: AreaSpinnerDirective;
  104. isAdminBased: boolean = false;
  105. editDisabled: boolean = false;
  106. isReadOnly: boolean = false;
  107. company: Company;
  108. currentTime: Date;
  109.  
  110. constructor(private messagesService: MessagesService,
  111. companyService: CompanyService,
  112. transactionService: TransactionService,
  113. authService: AuthenticationService,
  114. private metadataService: MetaDataService,
  115. currencyRatesService: CurrencyRatesService,
  116. private router: Router,
  117. private route: ActivatedRoute) {
  118. super(authService, companyService, currencyRatesService, transactionService);
  119. }
  120.  
  121. async ngOnInit() {
  122. this.isAdminBased = this.authService.isAdminBased();
  123. this.isReadOnly = this.authService.isReadOnly();
  124. this.isClient = this.authService.isClient();
  125. this.mode = TRANSACTION_MODES.view;
  126.  
  127. this.form = new FormGroup({
  128. id: new FormControl('', [Validators.required]),
  129. companyId: new FormControl('', [Validators.required]),
  130. isDebit: new FormControl(false, [Validators.required]),
  131. source: new FormControl(''),
  132. beneficiaryName: new FormControl('', [Validators.required, Validators.maxLength(100), noSpecialCharactersValidator]),
  133. beneficiaryCountry: new FormControl('', [Validators.required]),
  134. beneficiaryAddress: new FormControl('', [Validators.required, Validators.maxLength(100), noSpecialCharactersValidator]),
  135. targetAmount: new FormControl('', [Validators.required, Validators.min(0.01)]),
  136. targetCurrency: new FormControl('', [Validators.required]),
  137. currency: new FormControl({ value: null, disabled: true }, [Validators.required]),
  138. accountNumber: new FormControl({ value: '', disabled: true }),
  139. routingNumber: new FormControl('', [Validators.maxLength(100), accountNumberValidator]),
  140. reason: new FormControl('', [Validators.required, noSpecialCharactersValidator]),
  141. beneficiaryBankName: new FormControl('', [Validators.required, Validators.maxLength(100), noSpecialCharactersValidator]),
  142. beneficiaryBankCountry: new FormControl('', [Validators.required]),
  143. beneficiaryBankAddress: new FormControl('', [Validators.required, Validators.maxLength(100), noSpecialCharactersValidator]),
  144. beneficiaryCompanyId: new FormControl(0),
  145. intermediateBank: new FormControl('', [Validators.maxLength(100), noSpecialCharactersValidator]),
  146. bic: new FormControl('', [Validators.required, Validators.maxLength(100), accountNumberValidator]),
  147. accountType: new FormControl('', [Validators.required]),
  148. status: new FormControl('', [Validators.required]),
  149. requiredAdditionalInformation: new FormControl(''),
  150. additionalInformation: new FormControl('', [noSpecialCharactersValidator]),
  151. isUrgent: new FormControl(''),
  152. complianceReviewStatus: new FormControl(''),
  153. complianceReviewDocument: new FormControl('')
  154. });
  155.  
  156. this.addSub = this.form.controls['accountType'].valueChanges.subscribe((value: number) => {
  157. if (value && this.form.controls['accountType'].enabled) {
  158. this.form.controls['accountNumber'].enable();
  159.  
  160. if (value == ACCOUNT_TYPE.iban) {
  161. this.form.controls['accountNumber'].setValidators([Validators.required, Validators.maxLength(100), ibanValidator]);
  162. }
  163. else {
  164. this.form.controls['accountNumber'].setValidators([Validators.required, Validators.maxLength(100), accountNumberValidator]);
  165. }
  166. this.form.controls['accountNumber'].updateValueAndValidity();
  167. }
  168. else {
  169. this.form.controls['accountNumber'].disable();
  170. this.form.controls['accountNumber'].clearValidators();
  171. }
  172. });
  173.  
  174. this.addSub = this.form.controls['complianceReviewStatus'].valueChanges.subscribe((value: number | null) => {
  175. if(!this.isClient) {
  176. this.form.controls['complianceReviewStatus'].setValidators([Validators.required]);
  177.  
  178. value === COMPLIANCE_REVIEW_STATUS.approvedAndInfoRequired || value === COMPLIANCE_REVIEW_STATUS.infoRequired ?
  179. this.form.controls['complianceReviewDocument'].setValidators([Validators.required]) : this.form.controls['complianceReviewDocument'].clearValidators();
  180. }
  181. });
  182.  
  183. // added func on completeStatusTransaction
  184. if(this.data && this.data.status === 2) {
  185. this.complianceReviewStatuses = this.complianceReviewStatuses.slice(0, 2);
  186. }
  187. }
  188.  
  189. async ngOnChanges(changes: SimpleChanges) {
  190. if (changes['data'] && changes['data'].isFirstChange()) {
  191.  
  192. const fileMedata = await this.metadataService.getUploadedFileSettings().toPromise();
  193. this.maxFileSize = fileMedata.maxFileSize;
  194. this.extensions = fileMedata.supportedExtensions;
  195.  
  196. await this.loadMetadata();
  197. await this.loadCompany();
  198.  
  199. }
  200.  
  201. if (this.data) {
  202. if (changes['data'] && changes['data'].currentValue && changes['data'].currentValue != changes['data'].previousValue) {
  203. await this.loadMetadata();
  204. await this.loadCompany()
  205.  
  206. this.fillForm();
  207. this.filterCountries(this.company);
  208.  
  209. if (this.isConversionPaymentsEnabled) {
  210. this.calculateConversion();
  211. }
  212. }
  213. }
  214. }
  215.  
  216. async loadCompany() {
  217. if (!this.isAdminBased) {
  218. this.company = await this.companyService.getDetails().toPromise();
  219.  
  220. } else {
  221. if (!this.data) {
  222. //this.company =[];
  223. } else {
  224. this.company = await this.companyService.getDetailsById(this.data.companyId).toPromise();
  225. }
  226. }
  227. }
  228.  
  229. async loadMetadata() {
  230.  
  231. try {
  232. const data = await this.metadataService.loadMetaData().toPromise();
  233. this.allCountries = data.countries;
  234. this.allCurrencies = data.currencies;
  235. this.filterCountries();
  236.  
  237. this.currencies = await this.companyService.getCurrencies().toPromise();
  238. } catch (err) {
  239. console.error(err);
  240. }
  241. }
  242.  
  243. calculateConversion() {
  244. super.calculateConversion(this.data);
  245. }
  246.  
  247. filterCountries(company: Company = null) {
  248. if (!company) {
  249. this.countries = this.allCountries.filter(c => !c.isBlocked);
  250. } else if (!company.companyAdditionalCountries || !company.companyAdditionalCountries.length) {
  251. this.countries = this.allCountries.filter(c => !c.isBlocked);
  252. } else {
  253. const whiteListExceptionCountryIds: number[] = company.companyAdditionalCountries.filter(c => !c.isBlocked).map(c => c.countryId);
  254. const blackListExceptionCountryIds: number[] = company.companyAdditionalCountries.filter(c => c.isBlocked).map(c => c.countryId);
  255.  
  256. this.countries = this.allCountries
  257. .filter(c =>
  258. (!c.isBlocked || whiteListExceptionCountryIds.includes(c.id))
  259. &&
  260. !blackListExceptionCountryIds.includes(c.id)
  261. );
  262. }
  263. }
  264.  
  265. showDetails(mode: string = null) {
  266.  
  267. this.filesForUpload = [];
  268.  
  269. this.viewDetailsModal.config.backdrop = 'static';
  270. this.viewDetailsModal.show();
  271. }
  272.  
  273. onViewHeaderClick() {
  274. this.mode = TRANSACTION_MODES.view;
  275. }
  276.  
  277. onEditHeaderClick() {
  278. this.mode = TRANSACTION_MODES.edit;
  279. }
  280.  
  281. onRefundHeaderClick() {
  282. this.mode = TRANSACTION_MODES.refund;
  283. }
  284.  
  285. changeMode(mode: string) {
  286. this.mode = mode;
  287. }
  288.  
  289. hideViewDetailsModal() {
  290. this.modalAreaSpinner && this.modalAreaSpinner.stop();
  291. this.clearForm();
  292. this.onModeChanged.emit(this.mode);
  293. this.viewDetailsModal.hide();
  294.  
  295. const transactionId = Number(this.route.snapshot.params.id);
  296. const open = this.route.snapshot.params.open;
  297.  
  298. if (!transactionId || !open) {
  299. return;
  300. }
  301.  
  302. this.router.navigate([this.route.snapshot.url[0].path, this.route.snapshot.url[1].path]);
  303. }
  304.  
  305. get showEdit() {
  306. return !this.isReadOnly && this.data && this.data.status !== TRANSACTION_STATUSES.rejected;
  307. }
  308.  
  309. get canShowRefundButton() {
  310. const data = this.data;
  311.  
  312. return this.isAdminBased && data && !this.transactionService.isRefunded(data) && (data.source === SOURCE_TYPE.wireIn || data.source === SOURCE_TYPE.wireOut)
  313. && data.status === TRANSACTION_STATUSES.approved && !this.isReadOnly;
  314. }
  315.  
  316. clearForm() {
  317. this.form.reset();
  318. this.beneficiaryCountrySelect.remove(this.beneficiaryCountrySelect.activeOption);
  319. this.beneficiaryBankCountrySelect.remove(this.beneficiaryBankCountrySelect.activeOption);
  320. this.targetCurrenciesSelect.active = [];
  321.  
  322. if (this.currenciesToDebitSelect) {
  323. this.currenciesToDebitSelect.active = [];
  324. }
  325.  
  326. this.accountTypeSelect.remove(this.accountTypeSelect.activeOption);
  327. if (this.complianceReviewStatusSelect) {
  328. this.complianceReviewStatusSelect.remove(this.complianceReviewStatusSelect.activeOption);
  329. }
  330.  
  331. if (this.complianceReviewDocumentSelect) {
  332. this.complianceReviewDocumentSelect.remove(this.complianceReviewDocumentSelect.activeOption);
  333. }
  334.  
  335. this.editDisabled = false;
  336. this.clearFiles();
  337. }
  338.  
  339. fillForm() {
  340. this.form.controls['id'].setValue(this.data.id);
  341. this.form.controls['isDebit'].setValue(this.data.isDebit);
  342. this.form.controls['source'].setValue(this.data.source);
  343. this.form.controls['companyId'].setValue(this.data.companyId);
  344. this.form.controls['beneficiaryCountry'].setValue(this.data.beneficiaryCountry);
  345. this.form.controls['beneficiaryAddress'].setValue(this.data.beneficiaryAddress);
  346. this.form.controls['beneficiaryName'].setValue(this.data.beneficiaryName);
  347. this.form.controls['targetAmount'].setValue(this.data.targetAmount);
  348. this.form.controls['targetCurrency'].setValue(this.data.targetCurrency);
  349. this.form.controls['currency'].setValue(this.data.currency);
  350. this.form.controls['accountNumber'].setValue(this.data.accountNumber);
  351. this.form.controls['routingNumber'].setValue(this.data.routingNumber);
  352. this.form.controls['reason'].setValue(this.data.reason);
  353. this.form.controls['beneficiaryBankName'].setValue(this.data.beneficiaryBankName);
  354. this.form.controls['beneficiaryBankCountry'].setValue(this.data.beneficiaryBankCountry);
  355. this.form.controls['beneficiaryBankAddress'].setValue(this.data.beneficiaryBankAddress);
  356. this.form.controls['beneficiaryCompanyId'].setValue(this.data.beneficiaryCompanyId);
  357. this.form.controls['intermediateBank'].setValue(this.data.intermediateBank);
  358. this.form.controls['bic'].setValue(this.data.bic);
  359. this.form.controls['status'].setValue(this.data.status);
  360. this.form.controls['accountType'].setValue(this.data.accountType);
  361. this.form.controls['complianceReviewStatus'].setValue(this.data.complianceReviewStatus);
  362. this.form.controls['complianceReviewDocument'].setValue(this.data.complianceReviewDocument);
  363.  
  364. this.form.controls['requiredAdditionalInformation'].setValue(!!this.data.requiredAdditionalInformation);
  365. this.form.controls['isUrgent'].setValue(this.data.isUrgent)
  366.  
  367. this.form.controls['additionalInformation'].setValue(this.data.additionalInformation);
  368.  
  369. if (!this.data.requiredAdditionalInformation) {
  370. this.form.controls['additionalInformation'].disable();
  371. }
  372.  
  373. this.fillTargetCurrencies();
  374.  
  375. if (this.data.beneficiaryCountry) {
  376. const beneficiaryCountrySelect = this.beneficiaryCountrySelect.itemObjects
  377. .find((item) => item.id == ('' + this.data.beneficiaryCountry.id));
  378.  
  379. if (beneficiaryCountrySelect) {
  380. this.beneficiaryCountrySelect.active = [beneficiaryCountrySelect];
  381. } /*else {
  382. const country = { id: this.data.beneficiaryCountry.id, text: this.data.beneficiaryCountry.name };
  383. this.beneficiaryCountrySelect.active = [country];
  384. }*/
  385. }
  386.  
  387. if (this.data.beneficiaryBankCountry) {
  388. const beneficiaryBankCountry = this.beneficiaryBankCountrySelect.itemObjects
  389. .find((item) => item.id == ('' + this.data.beneficiaryBankCountry.id));
  390.  
  391. if (beneficiaryBankCountry) {
  392. this.beneficiaryBankCountrySelect.active = [beneficiaryBankCountry];
  393. } else {
  394. const country = { id: this.data.beneficiaryBankCountry.id, text: this.data.beneficiaryBankCountry.name };
  395. this.beneficiaryBankCountrySelect.active = [country];
  396. }
  397. }
  398.  
  399. setTimeout(() => {
  400. if (this.data.targetCurrency) {
  401. const targetCurrency = this.targetCurrenciesSelect.itemObjects.find((item) => item.id == this.data.targetCurrency.id);
  402. this.targetCurrenciesSelect.active = targetCurrency ? [targetCurrency] : [];
  403. }
  404.  
  405. if (this.data.currency && this.currenciesToDebitSelect) {
  406. const currency = this.currenciesToDebitSelect.itemObjects.find((item) => item.id == this.data.currency.id);
  407. this.currenciesToDebitSelect.active = currency ? [currency] : [];
  408. }
  409.  
  410. if (this.data.accountType) {
  411. const accountType = this.accountTypes.find((item) => item.id == this.data.accountType);
  412.  
  413. this.accountTypeSelect.active = accountType ? [accountType] : [];
  414.  
  415. this.selectedAccountType = this.accountTypeSelect.active[0].text;
  416. }
  417.  
  418. if (this.data) {
  419. this.updateComplianceReviewStatusSelect();
  420. this.updateComplianceReviewDocumentSelect();
  421. }
  422.  
  423. if (this.data.additionalInformation && this.data.additionalInformation.length) {
  424. this.form.controls['additionalInformation'].setValue(this.data.additionalInformation);
  425. }
  426.  
  427. // added func on completeStatusTransaction or reject
  428. if (this.data &&
  429. (this.data.status === TRANSACTION_STATUSES.approved && this.data.complianceReviewStatus !== COMPLIANCE_REVIEW_STATUS.approvedAndInfoRequired )
  430. || this.data.status === TRANSACTION_STATUSES.rejected){
  431. this.complianceReviewStatusSelect.disabled = true;
  432. if (this.complianceReviewDocumentSelect) {
  433. this.complianceReviewDocumentSelect.disabled = true;
  434. }
  435. } else {
  436. this.complianceReviewStatusSelect.disabled = false;
  437. if (this.complianceReviewDocumentSelect) {
  438. this.complianceReviewDocumentSelect.disabled = false;
  439. }
  440. }
  441.  
  442. if (this.data && this.data.status === TRANSACTION_STATUSES.approved &&
  443. this.data.complianceReviewStatus === COMPLIANCE_REVIEW_STATUS.approvedAndInfoRequired && this.additionalInformation) {
  444. this.additionalInformation.nativeElement.disabled = false;
  445. } else if (this.data && this.data.status === TRANSACTION_STATUSES.approved &&
  446. this.data.complianceReviewStatus !== COMPLIANCE_REVIEW_STATUS.approvedAndInfoRequired && this.additionalInformation) {
  447. this.additionalInformation.nativeElement.disabled = true;
  448. }
  449.  
  450. }, 0);
  451.  
  452. //this.data.status !== TRANSACTION_STATUSES.pending && this.data.status !== TRANSACTION_STATUSES.companyApproval;
  453.  
  454. if (this.data.status !== TRANSACTION_STATUSES.pending && this.data.status !== TRANSACTION_STATUSES.toSign) {
  455. this.editDisabled = true;
  456. } else if (this.data.requiredAdditionalInformation && !this.isAdminBased) {
  457. // check is it needs
  458. this.editDisabled = true;
  459. } else {
  460. this.editDisabled = false;
  461. }
  462.  
  463. this.transactionDocuments = this.data.documents;
  464. this.canUpdateDebitTransaction();
  465. this.disableEnableForm();
  466. }
  467.  
  468. canUpdateDebitTransaction() {
  469. if (this.isClient) {
  470. this.editDisabled = this.data.canClientEdit ? false : true;
  471. }
  472. }
  473.  
  474. updateComplianceReviewStatusSelect() {
  475. const reviewStatuses = this.complianceReviewStatuses.find(({id}) => id === this.data.complianceReviewStatus);
  476. if (this.complianceReviewStatusSelect) {
  477. this.complianceReviewStatusSelect.active = reviewStatuses ? [reviewStatuses] : [];
  478. }
  479. }
  480.  
  481. updateComplianceReviewDocumentSelect() {
  482. const reviewDocuments = this.complianceReviewDocuments.find(({id}) => id === this.data.complianceReviewDocument);
  483. if (this.complianceReviewDocumentSelect) {
  484. this.complianceReviewDocumentSelect.active = reviewDocuments ? [reviewDocuments] : [];
  485. }
  486. }
  487.  
  488. disableEnableForm() {
  489. this.targetCurrenciesSelect.disabled = true;
  490.  
  491. if (this.currenciesToDebitSelect) {
  492. this.currenciesToDebitSelect.disabled = true;
  493. }
  494.  
  495. this.beneficiaryCountrySelect.disabled = this.editDisabled;
  496. this.beneficiaryBankCountrySelect.disabled = this.editDisabled;
  497. this.accountTypeSelect.disabled = this.editDisabled;
  498.  
  499. if (this.editDisabled) {
  500. this.form.disable();
  501.  
  502. this.form.controls['requiredAdditionalInformation'].enable();
  503.  
  504. if (this.form.controls['requiredAdditionalInformation'].value) {
  505. this.form.controls['additionalInformation'].enable();
  506. }
  507. }
  508. else {
  509. this.form.enable();
  510. }
  511. }
  512.  
  513. hasError(controlName: string) {
  514. let control = this.form.controls[controlName];
  515.  
  516. if (!control) {
  517. return false;
  518. }
  519.  
  520. return !control.disabled && control.dirty && !control.valid;
  521. }
  522.  
  523. onAccountTypeSelected(value: SelectItem) {
  524. this.form.controls['accountType'].setValue(value.id);
  525. this.form.controls['accountNumber'].markAsDirty();
  526. }
  527.  
  528. onAccountTypeRemoved() {
  529. this.form.controls['accountType'].reset();
  530. }
  531.  
  532. onComplianceReviewStatusSelected(value: SelectItem) {
  533. this.onComplianceReviewSelected(value.id, 'complianceReviewStatus');
  534. this.updateComplianceReviewFields();
  535. }
  536.  
  537. updateComplianceReviewFields() {
  538. this.onComplianceReviewRemoved('complianceReviewDocument');
  539.  
  540. if (this.complianceReviewDocumentSelect && this.complianceReviewDocumentSelect.active) {
  541. this.complianceReviewDocumentSelect.active = [];
  542. }
  543. this.onComplianceReviewRemoved('additionalInformation');
  544.  
  545. if (this.data && this.data.status === TRANSACTION_STATUSES.approved) {
  546. this.form.controls['complianceReviewStatus'].enable();
  547. this.form.controls['complianceReviewDocument'].enable();
  548. }
  549.  
  550. // make visibled additionalInformation textarea if transaction status - completed
  551. setTimeout(() => {
  552. if (this.data && this.data.status === TRANSACTION_STATUSES.approved && this.form.controls['complianceReviewStatus'].value === COMPLIANCE_REVIEW_STATUS.approvedAndInfoRequired
  553. && this.additionalInformation) {
  554. this.additionalInformation.nativeElement.disabled = false;
  555. }
  556. });
  557. }
  558.  
  559. onComplianceReviewSelected(id: string, fieldName: string) {
  560. this.form.controls[fieldName].setValue(id);
  561. }
  562.  
  563. onComplianceReviewRemoved(fieldName: string) {
  564. this.form.controls[fieldName].reset();
  565. }
  566.  
  567. getComplianceReviewMessage() {
  568. const str = this.transactionService.getComplianceReviewMessage(this.form.controls['complianceReviewStatus'].value,
  569. this.form.controls['complianceReviewDocument'].value);
  570.  
  571. this.form.controls['additionalInformation'].setValue(str);
  572. }
  573.  
  574. onTargetCurrencySelected(value: Currency) {
  575. const selected = this.allCurrencies.find((item) => item.id == value.id);
  576. this.form.controls['targetCurrency'].setValue(selected);
  577. this.calculateConversion();
  578. }
  579.  
  580. onTargetCurrencyRemoved() {
  581. this.form.controls['targetCurrency'].setValue(null);
  582. this.calculateConversion();
  583. }
  584.  
  585. onCurrencyToDebitSelected(value: Currency) {
  586. const selected = this.currencies.find((item) => item.id == value.id);
  587. this.form.controls['currency'].setValue(selected);
  588. this.calculateConversion();
  589. }
  590.  
  591. onCurrencyToDebitRemoved() {
  592. this.form.controls['currency'].setValue(null);
  593. this.calculateConversion();
  594. }
  595.  
  596. onBeneficiaryCountrySelected(value: any) {
  597. let selected = this.countries.find((item) => item.id == value.id);
  598.  
  599. this.form.controls['beneficiaryCountry'].setValue(selected);
  600.  
  601. let routingNumber = this.form.controls['routingNumber'].value;
  602.  
  603. if (selected.code === 'CA' || selected.code === 'US') {
  604. this.form.setControl('routingNumber', new FormControl(routingNumber, [Validators.required, accountNumberValidator]));
  605. }
  606. else {
  607. this.form.setControl('routingNumber', new FormControl(routingNumber, [accountNumberValidator]));
  608. }
  609. }
  610.  
  611. onBeneficiaryCountryRemoved() {
  612. this.form.controls['beneficiaryCountry'].reset();
  613. }
  614.  
  615. onBeneficiaryBankCountrySelected(value: any) {
  616. let selected = this.countries.find((item) => item.id == value.id);
  617.  
  618. this.form.controls['beneficiaryBankCountry'].setValue(selected);
  619. }
  620.  
  621. onBeneficiaryBankCountryRemoved() {
  622. this.form.controls['beneficiaryBankCountry'].reset();
  623. }
  624.  
  625. ontToggleAdditionalInfo(event: boolean) {
  626. this.form.controls['requiredAdditionalInformation'].setValue(event);
  627.  
  628. if (event) {
  629. this.form.controls['additionalInformation'].enable();
  630. }
  631. else {
  632. this.form.controls['additionalInformation'].disable();
  633. }
  634. }
  635.  
  636. onToggleIsUrgent(isUrgent: boolean) {
  637. this.form.controls['isUrgent'].setValue(isUrgent);
  638. }
  639.  
  640. async onSubmit(event) {
  641. event.preventDefault();
  642.  
  643. if (this.form.valid) {
  644. this.form.enable();
  645.  
  646. try {
  647. this.saveBtnSpinner.start();
  648.  
  649. await this.transactionService.updateDebitTransaction({
  650. ...{ ...this.form.value, createDate: this.data.createDate },
  651. documents: this.transactionDocuments
  652. }, this.filesForUpload).toPromise();
  653.  
  654. this.messagesService.success(`Transaction #${this.form.controls['id'].value} Updated successfully.`);
  655. this.afterSuccessSubmit();
  656. } catch (error) {
  657. console.error(error);
  658. }
  659. finally {
  660. this.saveBtnSpinner.stop();
  661. }
  662. }
  663. }
  664.  
  665. afterSuccessSubmit() {
  666. this.hideViewDetailsModal();
  667. this.onSave.emit(true);
  668. }
  669.  
  670. getTransactionStatusName(transactionStatus) {
  671. switch (transactionStatus) {
  672. case TRANSACTION_STATUSES.approved:
  673. return 'Completed';
  674. case TRANSACTION_STATUSES.toSign:
  675. return 'To Sign';
  676. case TRANSACTION_STATUSES.deleted:
  677. return 'Deleted';
  678. case TRANSACTION_STATUSES.pending:
  679. return 'Pending';
  680. case TRANSACTION_STATUSES.rejected:
  681. return 'Rejected';
  682. default:
  683. return '';
  684. }
  685. }
  686.  
  687. async onPaymentConfirmationPrintClick() {
  688. try {
  689. this.printMenuSpinner.start();
  690.  
  691. this.brand = await this.metadataService.getBrandInfo().toPromise();
  692. this.company = await this.companyService.getDetailsById(this.data.companyId).toPromise();
  693.  
  694. this.currentTime = new Date();
  695. this.printMenuSpinner.stop();
  696.  
  697. setTimeout(() => {
  698. this.paymentConfirmationPrintDir.print();
  699. });
  700. } catch (err) {
  701. console.error(err);
  702. } finally {
  703. this.printMenuSpinner.stop();
  704. }
  705. }
  706.  
  707. onFileSelect(ev) {
  708. this.selectedFile = ev.target.files[0];
  709. ev.target.value = null;
  710. }
  711.  
  712. onFileUploadClick(ev) {
  713. ev.preventDefault();
  714.  
  715. if (!this.selectedFile) {
  716. return;
  717. }
  718.  
  719. const exntension = this.selectedFile.name.split('.').pop()
  720. this.selectedFile.alias = this.selectedFileAlias ? (this.selectedFileAlias + '.' + exntension) : this.selectedFile.name;
  721. this.filesForUpload.push(this.selectedFile);
  722.  
  723. this.clearFiles();
  724. }
  725.  
  726. clearFiles() {
  727. this.selectedFile = null;
  728. this.selectedFileAlias = null;
  729.  
  730. if (this.fileInput && this.fileInput.nativeElement) {
  731. this.fileInput.nativeElement.value = null;
  732. }
  733. }
  734.  
  735. get isFileExtensionInvalid() {
  736. if (!this.extensions.length) {
  737. return false;
  738. }
  739.  
  740. return this.selectedFile && this.extensions.indexOf(this.selectedFile.name.split('.').pop().toLowerCase()) === -1;
  741. }
  742.  
  743. get isFileSizeInvalid() {
  744. if (!this.maxFileSize) {
  745. return false;
  746. }
  747.  
  748. return this.selectedFile && this.selectedFile.size > this.maxFileSize * 1000000;
  749. }
  750.  
  751. get isFileInvalid() {
  752. return !this.selectedFile || !this.selectedFile.name || !this.selectedFile.name.length || !this.selectedFile.size || this.isFileExtensionInvalid || this.isFileSizeInvalid;
  753. }
  754.  
  755. removeFromFilesToUpload(file: FileWithAlias) {
  756. this.filesForUpload = this.filesForUpload.filter(f => f !== file);
  757. }
  758.  
  759. removeFromTransactionDocuments(key: string) {
  760. this.transactionDocuments = this.transactionDocuments.filter(d => d.key !== key);
  761. }
  762.  
  763. async downloadDocument(key: string) {
  764. if (key) {
  765. await this.transactionService.downloadDocument(key).toPromise();
  766. }
  767. }
  768.  
  769. get canWorkingWithDocuments(): boolean {
  770. if (!this.data) {
  771. return false;
  772. }
  773.  
  774. if (this.isAdminBased) {
  775. return true;
  776. }
  777.  
  778. if (this.data.status === TRANSACTION_STATUSES.pending || this.data.status === TRANSACTION_STATUSES.toSign) {
  779. return true;
  780. }
  781.  
  782. return false;
  783. }
  784.  
  785. get isConversionPaymentsEnabled() {
  786. return this.data && this.data.currency && this.data.targetCurrency && this.data.currency.id !== this.data.targetCurrency.id;
  787. }
  788.  
  789. fillTargetCurrencies() {
  790. if (this.isConversionPaymentsEnabled) {
  791. this.targetCurrencies = [
  792. ...this.allCurrencies.filter(c => this.company.conversionAllowedCurrencies.includes(c.id)),
  793. ...this.currencies
  794. ];
  795. this.form.get('currency').enable();
  796. } else {
  797. this.targetCurrencies = [...this.currencies];
  798. this.form.get('currency').disable();
  799. }
  800. }
  801.  
  802. trackByDocumentId(document: any) {
  803. return document.key;
  804. }
  805.  
  806. getPrevious() {
  807. this.modalAreaSpinner && this.modalAreaSpinner.start();
  808. this.onPreviousClick.emit(this.data.id);
  809. }
  810.  
  811. getNext() {
  812. this.modalAreaSpinner && this.modalAreaSpinner.start();
  813. this.onNextClick.emit(this.data.id);
  814. }
  815. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement