payment-info.component.ts 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. import { Component, OnInit } from "@angular/core";
  2. import { FormInvestmentProposalService } from "@app/services/form-investment-proposal.service";
  3. import { FormBuilder, FormGroup, Validators } from "@angular/forms";
  4. import { CatalogsService } from "@app/services/catalogs.service";
  5. import { IAngularMyDpOptions, IMyDateModel } from "angular-mydatepicker";
  6. import { formatDate, DatePipe } from "@angular/common";
  7. import { parse } from "date-fns";
  8. import { Router, ActivatedRoute } from "@angular/router";
  9. import { InvestmentsService } from "@app/services/investments.service";
  10. import Swal from "sweetalert2";
  11. @Component({
  12. selector: "app-payment-info",
  13. templateUrl: "./payment-info.component.html"
  14. })
  15. export class PaymentInfoComponent implements OnInit {
  16. title: string = "Formulario de información para el pago";
  17. form: any;
  18. // For daterange
  19. daysLabels: any = {
  20. su: "Dom",
  21. mo: "Lun",
  22. tu: "Mar",
  23. we: "Mie",
  24. th: "Jue",
  25. fr: "Vie",
  26. sa: "Sab"
  27. };
  28. monthsLabels: any = {
  29. 1: "Ene",
  30. 2: "Feb",
  31. 3: "Mar",
  32. 4: "Abr",
  33. 5: "May",
  34. 6: "Jun",
  35. 7: "Jul",
  36. 8: "Ago",
  37. 9: "Sep",
  38. 10: "Oct",
  39. 11: "Nov",
  40. 12: "Dic"
  41. };
  42. myDpOptions: IAngularMyDpOptions = {
  43. dateRange: false,
  44. dateFormat: "dd/mm/yyyy",
  45. dayLabels: this.daysLabels,
  46. monthLabels: this.monthsLabels
  47. };
  48. myDateInit: boolean = true;
  49. investmentProposalForm: FormGroup;
  50. submitted: boolean = false;
  51. role_number: any;
  52. markets: any;
  53. emitters: any;
  54. periodicities: any;
  55. rate_agencies: any;
  56. scores: any;
  57. investmentProposalID: string;
  58. countries: any;
  59. companies: any;
  60. format_incomes: any;
  61. operations: any;
  62. payment_terms: any;
  63. payment_types: any;
  64. inversionCode: any;
  65. constructor(
  66. private router: Router,
  67. private route: ActivatedRoute,
  68. private formBuilder: FormBuilder,
  69. private formDataService: FormInvestmentProposalService,
  70. private catalogService: CatalogsService,
  71. private investmentsService: InvestmentsService
  72. ) {}
  73. ngOnInit() {
  74. this.route.params.subscribe(params => {
  75. this.investmentProposalID = params["id"];
  76. });
  77. if (this.investmentProposalID == undefined)
  78. this.investmentProposalID = this.route.snapshot.queryParamMap.get("id");
  79. this.investmentsService
  80. .getProposalInvestment(this.investmentProposalID)
  81. .subscribe(
  82. res => {
  83. console.log("results");
  84. console.log(res);
  85. console.log("-------");
  86. this.inversionCode = res["result"]["codigo_inversion"];
  87. },
  88. err => {
  89. Swal.fire({
  90. icon: "error",
  91. title: "Error en el servidor",
  92. text: err.message
  93. });
  94. }
  95. );
  96. this.catalogService.getPaymentTypes().subscribe(res => {
  97. this.payment_types = res;
  98. });
  99. this.catalogService.getCountries().subscribe(res => {
  100. this.countries = res;
  101. });
  102. this.investmentProposalForm = this.formBuilder.group({
  103. monto: [
  104. "",
  105. [
  106. Validators.required,
  107. Validators.pattern(/^[+]?([0-9]+(?:[\.][0-9]*)?|\.[0-9]+)$/)
  108. ]
  109. ],
  110. payment_types: ["", [Validators.required]],
  111. cuenta_bancaria: [""],
  112. fecha_pago: ["", Validators.required],
  113. fecha_vencimiento: ["", Validators.required]
  114. });
  115. }
  116. get f() {
  117. return this.investmentProposalForm.controls;
  118. }
  119. save(form: any): boolean {
  120. //if (!form.valid) {
  121. //return false;
  122. //}
  123. console.log(this.investmentProposalForm.value);
  124. this.formDataService.setComplementInfo(this.investmentProposalForm.value);
  125. return true;
  126. }
  127. goToPrevious(form: any) {
  128. this.submitted = true;
  129. if (this.investmentProposalID != undefined) {
  130. this.router.navigate(["/investment-proposal/instrument-work"], {
  131. queryParams: { id: this.investmentProposalID }
  132. });
  133. } else {
  134. this.router.navigate(["/investment-proposal/instrument-work"]);
  135. }
  136. }
  137. goToNext(form: any) {
  138. this.submitted = true;
  139. if (this.save(form)) {
  140. if (this.investmentProposalID != undefined) {
  141. this.router.navigate(["/investment-proposal/result"], {
  142. queryParams: { id: this.investmentProposalID }
  143. });
  144. } else {
  145. this.router.navigate(["/investment-proposal/result"]);
  146. }
  147. }
  148. }
  149. }