complement-info.component.ts 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  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. complementInfoDontExists: boolean;
  64. companyValue: any;
  65. instrumentInfo: any;
  66. constructor(
  67. private router: Router,
  68. private route: ActivatedRoute,
  69. private formBuilder: FormBuilder,
  70. private formDataService: FormInvestmentProposalService,
  71. private catalogService: CatalogsService
  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.complementInfo = this.formDataService.getComplementInfo();
  80. this.complementInfoDontExists = this.complementInfo == undefined;
  81. this.instrumentInfo = this.formDataService.getGeneralInfo().instrumentos;
  82. console.log("instrumento");
  83. console.log(this.instrumentInfo);
  84. this.catalogService.getCatalogInfo("companies").subscribe(res => {
  85. this.companies = res;
  86. if (this.investmentProposalID != undefined) {
  87. this.companyValue = this.companies.find(
  88. e => e.id_empresa == this.complementInfo.empresa
  89. );
  90. this.companyValue =
  91. this.companyValue != undefined ? this.companyValue.nombre : "-";
  92. }
  93. });
  94. this.catalogService.getCatalogInfo("paises").subscribe(res => {
  95. this.countries = res;
  96. });
  97. this.catalogService.getCatalogInfo("tipos-mercados").subscribe(res => {
  98. this.markets = res;
  99. });
  100. this.catalogService.getCatalogInfo("tipos-emisores").subscribe(res => {
  101. this.emitters = res;
  102. });
  103. this.catalogService.getRateAgencies().subscribe(res => {
  104. this.rate_agencies = res;
  105. });
  106. this.catalogService.getScores().subscribe(res => {
  107. this.scores = res;
  108. });
  109. this.catalogService.getPaymentTerms().subscribe(res => {
  110. this.payment_terms = res;
  111. });
  112. this.catalogService.getCatalogInfo("tipos-operaciones").subscribe(res => {
  113. this.operations = res;
  114. });
  115. this.investmentProposalForm = this.formBuilder.group({
  116. tipo_mercado: [
  117. this.complementInfoDontExists ? "" : this.complementInfo.tipo_mercado,
  118. [Validators.required]
  119. ],
  120. emisores: [
  121. this.complementInfoDontExists ? "" : this.complementInfo.emisores,
  122. [Validators.required]
  123. ],
  124. empresa: [
  125. this.complementInfoDontExists ? "" : this.complementInfo.empresa,
  126. [Validators.required]
  127. ],
  128. pais: [
  129. this.complementInfoDontExists ? "" : this.complementInfo.pais,
  130. [Validators.required]
  131. ],
  132. plazo: [
  133. this.complementInfoDontExists ? "" : this.complementInfo.plazo,
  134. [Validators.required]
  135. ],
  136. operaciones: [
  137. this.complementInfoDontExists ? "" : this.complementInfo.operaciones,
  138. [Validators.required]
  139. ],
  140. comentarios: [
  141. this.complementInfoDontExists ? "" : this.complementInfo.comentarios,
  142. []
  143. ],
  144. justificacion: [
  145. this.complementInfoDontExists ? "" : this.complementInfo.justificacion,
  146. []
  147. ]
  148. });
  149. // Set default values depending of the instrument
  150. if (this.complementInfoDontExists == true) {
  151. switch (this.instrumentInfo) {
  152. case "LETE":
  153. this.investmentProposalForm.patchValue({
  154. emisores: this.investmentProposalForm.value.emisores = 985,
  155. pais: this.investmentProposalForm.value.pais = 210
  156. });
  157. case "CETE":
  158. this.investmentProposalForm.patchValue({
  159. emisores: this.investmentProposalForm.value.emisores = 985,
  160. pais: this.investmentProposalForm.value.pais = 210,
  161. operaciones: this.investmentProposalForm.value.operaciones = 2
  162. });
  163. break;
  164. case "VCN":
  165. this.investmentProposalForm.patchValue({
  166. operaciones: this.investmentProposalForm.value.operaciones = 2
  167. });
  168. break;
  169. case "PBUR":
  170. this.investmentProposalForm.patchValue({
  171. pais: this.investmentProposalForm.value.pais = 210,
  172. operaciones: this.investmentProposalForm.value.operaciones = 2
  173. });
  174. break;
  175. case "DAP":
  176. this.investmentProposalForm.patchValue({
  177. tipo_mercado: this.investmentProposalForm.value.tipo_mercado = 5,
  178. operaciones: this.investmentProposalForm.value.operaciones = 2
  179. });
  180. break;
  181. case "BONO":
  182. this.investmentProposalForm.patchValue({
  183. pais: this.investmentProposalForm.value.pais = 210,
  184. operaciones: this.investmentProposalForm.value.operaciones = 2
  185. });
  186. break;
  187. case "EURB":
  188. this.investmentProposalForm.patchValue({
  189. pais: this.investmentProposalForm.value.pais = 210,
  190. operaciones: this.investmentProposalForm.value.operaciones = 2
  191. });
  192. break;
  193. case "CINV":
  194. this.investmentProposalForm.patchValue({
  195. pais: this.investmentProposalForm.value.pais = 210,
  196. operaciones: this.investmentProposalForm.value.operaciones = 2
  197. });
  198. break;
  199. case "TIT":
  200. this.investmentProposalForm.patchValue({
  201. pais: this.investmentProposalForm.value.pais = 210,
  202. operaciones: this.investmentProposalForm.value.operaciones = 2
  203. });
  204. break;
  205. case "FINV":
  206. this.investmentProposalForm.patchValue({
  207. tipo_mercado: this.investmentProposalForm.value.tipo_mercado = 5,
  208. pais: this.investmentProposalForm.value.pais = 210,
  209. operaciones: this.investmentProposalForm.value.operaciones = 2
  210. });
  211. break;
  212. case "OPC":
  213. this.investmentProposalForm.patchValue({
  214. //tipo_mercado: this.investmentProposalForm.value.tipo_mercado = 0,
  215. pais: this.investmentProposalForm.value.pais = 233,
  216. operaciones: this.investmentProposalForm.value.operaciones = 2
  217. });
  218. break;
  219. case "FUTU":
  220. this.investmentProposalForm.patchValue({
  221. //tipo_mercado: this.investmentProposalForm.value.tipo_mercado = 0,
  222. pais: this.investmentProposalForm.value.pais = 233,
  223. operaciones: this.investmentProposalForm.value.operaciones = 2
  224. });
  225. break;
  226. case "PEMP":
  227. this.investmentProposalForm.patchValue({
  228. tipo_mercado: this.investmentProposalForm.value.tipo_mercado = 5,
  229. pais: this.investmentProposalForm.value.pais = 210,
  230. operaciones: this.investmentProposalForm.value.operaciones = 2
  231. });
  232. break;
  233. case "PPER":
  234. this.investmentProposalForm.patchValue({
  235. tipo_mercado: this.investmentProposalForm.value.tipo_mercado = 5,
  236. pais: this.investmentProposalForm.value.pais = 210,
  237. operaciones: this.investmentProposalForm.value.operaciones = 2
  238. });
  239. break;
  240. }
  241. }
  242. }
  243. get f() {
  244. return this.investmentProposalForm.controls;
  245. }
  246. save(form: any): boolean {
  247. this.submitted = true;
  248. if (!form.valid) {
  249. return false;
  250. }
  251. this.formDataService.setComplementInfo(this.investmentProposalForm.value);
  252. return true;
  253. }
  254. goToPrevious() {
  255. this.submitted = true;
  256. if (this.investmentProposalID != undefined) {
  257. this.router.navigate(["/investment-proposal/instrument-work"], {
  258. queryParams: { id: this.investmentProposalID }
  259. });
  260. } else {
  261. this.router.navigate(["/investment-proposal/instrument-work"]);
  262. }
  263. }
  264. goToNext(form: any) {
  265. if (this.save(form)) {
  266. if (this.investmentProposalID != undefined) {
  267. this.router.navigate(["/investment-proposal/result"], {
  268. queryParams: { id: this.investmentProposalID }
  269. });
  270. } else {
  271. this.router.navigate(["/investment-proposal/result"]);
  272. }
  273. }
  274. }
  275. }