complement-info.component.ts 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. import { Component, OnInit } from "@angular/core";
  2. import { Router, ActivatedRoute } from "@angular/router";
  3. import { ComplementInfo } from "@app/models/investment-proposal-form";
  4. import { FormInvestmentProposalService } from "@app/services/form-investment-proposal.service";
  5. import { FormBuilder, FormGroup, Validators } from "@angular/forms";
  6. import { CatalogsService } from "@app/services/catalogs.service";
  7. import { IAngularMyDpOptions, IMyDateModel } from "angular-mydatepicker";
  8. import { formatDate, DatePipe } from "@angular/common";
  9. import { parse } from "date-fns";
  10. @Component({
  11. selector: "app-complement-info",
  12. templateUrl: "./complement-info.component.html"
  13. })
  14. export class ComplementInfoComponent implements OnInit {
  15. title: string = "Formulario propuesta de inversión";
  16. complementInfo: ComplementInfo;
  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. complementInfoExists: boolean;
  64. constructor(
  65. private router: Router,
  66. private route: ActivatedRoute,
  67. private formBuilder: FormBuilder,
  68. private formDataService: FormInvestmentProposalService,
  69. private catalogService: CatalogsService
  70. ) {}
  71. ngOnInit() {
  72. this.route.params.subscribe(params => {
  73. this.investmentProposalID = params["id"];
  74. console.log(params);
  75. console.log(this.investmentProposalID);
  76. });
  77. if (this.investmentProposalID == undefined)
  78. this.investmentProposalID = this.route.snapshot.queryParamMap.get("id");
  79. this.complementInfo = this.formDataService.getComplementInfo();
  80. this.complementInfoExists = this.complementInfo == undefined;
  81. this.catalogService.getCompanies().subscribe(res => {
  82. this.companies = res;
  83. });
  84. this.catalogService.getCountries().subscribe(res => {
  85. this.countries = res;
  86. });
  87. this.catalogService.getMarketTypes().subscribe(res => {
  88. this.markets = res;
  89. });
  90. this.catalogService.getEmitterTypes().subscribe(res => {
  91. this.emitters = res;
  92. });
  93. this.catalogService.getRateAgencies().subscribe(res => {
  94. this.rate_agencies = res;
  95. });
  96. this.catalogService.getScores().subscribe(res => {
  97. this.scores = res;
  98. });
  99. this.catalogService.getPaymentTerms().subscribe(res => {
  100. this.payment_terms = res;
  101. });
  102. this.catalogService.getOperationTypes().subscribe(res => {
  103. this.operations = res;
  104. });
  105. this.investmentProposalForm = this.formBuilder.group({
  106. tipo_mercado: [
  107. this.complementInfoExists ? "" : this.complementInfo.tipo_mercado,
  108. [Validators.required]
  109. ],
  110. emisores: [
  111. this.complementInfoExists ? "" : this.complementInfo.emisores,
  112. [Validators.required]
  113. ],
  114. empresa: [
  115. this.complementInfoExists ? "" : this.complementInfo.empresa,
  116. [Validators.required]
  117. ],
  118. pais: [
  119. this.complementInfoExists ? "" : this.complementInfo.pais,
  120. [Validators.required]
  121. ],
  122. plazo: [
  123. this.complementInfoExists ? "" : this.complementInfo.plazo,
  124. [Validators.required]
  125. ],
  126. operaciones: [
  127. this.complementInfoExists ? "" : this.complementInfo.operaciones,
  128. [Validators.required]
  129. ],
  130. comentarios: [
  131. this.complementInfoExists ? "" : this.complementInfo.comentarios,
  132. []
  133. ],
  134. justificacion: [
  135. this.complementInfoExists ? "" : this.complementInfo.justificacion,
  136. []
  137. ]
  138. });
  139. console.log(this.complementInfo);
  140. }
  141. get f() {
  142. return this.investmentProposalForm.controls;
  143. }
  144. save(form: any): boolean {
  145. //if (!form.valid) {
  146. //return false;
  147. //}
  148. console.log(this.investmentProposalForm.value);
  149. this.formDataService.setComplementInfo(this.investmentProposalForm.value);
  150. return true;
  151. }
  152. goToPrevious() {
  153. this.submitted = true;
  154. if (this.investmentProposalID != undefined) {
  155. this.router.navigate(["/investment-proposal/instrument-work"], {
  156. queryParams: { id: this.investmentProposalID }
  157. });
  158. } else {
  159. this.router.navigate(["/investment-proposal/instrument-work"]);
  160. }
  161. }
  162. goToNext(form: any) {
  163. this.submitted = true;
  164. if (this.save(form)) {
  165. if (this.investmentProposalID != undefined) {
  166. this.router.navigate(["/investment-proposal/result"], {
  167. queryParams: { id: this.investmentProposalID }
  168. });
  169. } else {
  170. this.router.navigate(["/investment-proposal/result"]);
  171. }
  172. }
  173. }
  174. }