complement-info.component.ts 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. import { Component, OnInit, ViewChild } 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. import { IOption } from "ng-select";
  11. @Component({
  12. selector: "app-complement-info",
  13. templateUrl: "./complement-info.component.html"
  14. })
  15. export class ComplementInfoComponent implements OnInit {
  16. title: string = "Formulario propuesta de inversión";
  17. complementInfo: ComplementInfo;
  18. form: any;
  19. // For daterange
  20. daysLabels: any = {
  21. su: "Dom",
  22. mo: "Lun",
  23. tu: "Mar",
  24. we: "Mie",
  25. th: "Jue",
  26. fr: "Vie",
  27. sa: "Sab"
  28. };
  29. monthsLabels: any = {
  30. 1: "Ene",
  31. 2: "Feb",
  32. 3: "Mar",
  33. 4: "Abr",
  34. 5: "May",
  35. 6: "Jun",
  36. 7: "Jul",
  37. 8: "Ago",
  38. 9: "Sep",
  39. 10: "Oct",
  40. 11: "Nov",
  41. 12: "Dic"
  42. };
  43. myDpOptions: IAngularMyDpOptions = {
  44. dateRange: false,
  45. dateFormat: "dd/mm/yyyy",
  46. dayLabels: this.daysLabels,
  47. monthLabels: this.monthsLabels
  48. };
  49. myDateInit: boolean = true;
  50. investmentProposalForm: FormGroup;
  51. submitted: boolean = false;
  52. role_number: any;
  53. markets: any;
  54. emitters: Array<IOption>;
  55. periodicities: any;
  56. rate_agencies: any;
  57. scores: any;
  58. investmentProposalID: string;
  59. countries: any;
  60. companies: any;
  61. format_incomes: any;
  62. operations: any;
  63. payment_terms: any;
  64. complementInfoDontExists: boolean;
  65. companyValue: any;
  66. instrumentInfo: any;
  67. @ViewChild("emisorSelect", { static: false })
  68. public emisorSelect: any;
  69. constructor(
  70. private router: Router,
  71. private route: ActivatedRoute,
  72. private formBuilder: FormBuilder,
  73. private formDataService: FormInvestmentProposalService,
  74. private catalogService: CatalogsService
  75. ) {}
  76. ngOnInit() {
  77. this.route.params.subscribe(params => {
  78. this.investmentProposalID = params["id"];
  79. });
  80. if (this.investmentProposalID == undefined)
  81. this.investmentProposalID = this.route.snapshot.queryParamMap.get("id");
  82. this.complementInfo = this.formDataService.getComplementInfo();
  83. this.complementInfoDontExists = this.complementInfo == undefined;
  84. this.instrumentInfo = this.formDataService.getGeneralInfo().instrumentos;
  85. this.catalogService.getCatalogInfo("empresas").subscribe(res => {
  86. this.companies = res;
  87. if (this.investmentProposalID != undefined) {
  88. this.companyValue = this.companies.find(
  89. e => e.id_empresa == this.complementInfo.empresa
  90. );
  91. this.companyValue =
  92. this.companyValue != undefined ? this.companyValue.nombre : "-";
  93. }
  94. });
  95. this.catalogService.getCatalogInfo("paises").subscribe(res => {
  96. this.countries = res;
  97. });
  98. this.catalogService.getCatalogInfo("tipos-mercados").subscribe(res => {
  99. this.markets = res;
  100. });
  101. this.catalogService.getCatalogInfo("tipos-emisores").subscribe(res => {
  102. this.emitters = [];
  103. for (let property in res) {
  104. this.emitters.push({
  105. label: res[property]["nombre"],
  106. value: res[property]["id_tipo_emisor"].toString()
  107. });
  108. }
  109. if (this.complementInfo.emisores.toString() != "") {
  110. this.emisorSelect.select(this.complementInfo.emisores.toString());
  111. }
  112. });
  113. this.catalogService.getRateAgencies().subscribe(res => {
  114. this.rate_agencies = res;
  115. });
  116. this.catalogService.getScores().subscribe(res => {
  117. this.scores = res;
  118. });
  119. this.catalogService.getPaymentTerms().subscribe(res => {
  120. this.payment_terms = res;
  121. });
  122. this.catalogService.getCatalogInfo("tipos-operaciones").subscribe(res => {
  123. this.operations = res;
  124. });
  125. this.investmentProposalForm = this.formBuilder.group({
  126. tipo_mercado: [
  127. this.complementInfoDontExists ? "" : this.complementInfo.tipo_mercado,
  128. [Validators.required]
  129. ],
  130. emisores: [
  131. this.complementInfoDontExists
  132. ? ""
  133. : this.complementInfo.emisores.toString(),
  134. [Validators.required]
  135. ],
  136. empresa: [
  137. this.complementInfoDontExists ? "" : this.complementInfo.empresa,
  138. [Validators.required]
  139. ],
  140. pais: [
  141. this.complementInfoDontExists ? "" : this.complementInfo.pais,
  142. [Validators.required]
  143. ],
  144. plazo: [
  145. this.complementInfoDontExists ? "" : this.complementInfo.plazo,
  146. [Validators.required]
  147. ],
  148. operaciones: [
  149. this.complementInfoDontExists ? "" : this.complementInfo.operaciones,
  150. [Validators.required]
  151. ],
  152. comentarios: [
  153. this.complementInfoDontExists ? "" : this.complementInfo.comentarios,
  154. []
  155. ],
  156. justificacion: [
  157. this.complementInfoDontExists ? "" : this.complementInfo.justificacion,
  158. []
  159. ]
  160. });
  161. // Set default values depending of the instrument
  162. if (
  163. this.complementInfoDontExists == true ||
  164. Object.values(this.complementInfo).every(x => x === null || x === "")
  165. ) {
  166. switch (this.instrumentInfo) {
  167. case "LETE":
  168. this.investmentProposalForm.patchValue({
  169. emisores: this.investmentProposalForm.value.emisores = "985",
  170. pais: this.investmentProposalForm.value.pais = 210
  171. });
  172. break;
  173. case "CETE":
  174. this.investmentProposalForm.patchValue({
  175. emisores: this.investmentProposalForm.value.emisores = "985",
  176. pais: this.investmentProposalForm.value.pais = 210,
  177. operaciones: this.investmentProposalForm.value.operaciones = 2
  178. });
  179. break;
  180. case "VCN":
  181. this.investmentProposalForm.patchValue({
  182. operaciones: this.investmentProposalForm.value.operaciones = 2
  183. });
  184. break;
  185. case "PBUR":
  186. this.investmentProposalForm.patchValue({
  187. pais: this.investmentProposalForm.value.pais = 210,
  188. operaciones: this.investmentProposalForm.value.operaciones = 2
  189. });
  190. break;
  191. case "DAP":
  192. this.investmentProposalForm.patchValue({
  193. tipo_mercado: this.investmentProposalForm.value.tipo_mercado = 5,
  194. operaciones: this.investmentProposalForm.value.operaciones = 2
  195. });
  196. break;
  197. case "BONO":
  198. this.investmentProposalForm.patchValue({
  199. pais: this.investmentProposalForm.value.pais = 210,
  200. operaciones: this.investmentProposalForm.value.operaciones = 2
  201. });
  202. break;
  203. case "EURB":
  204. this.investmentProposalForm.patchValue({
  205. pais: this.investmentProposalForm.value.pais = 210,
  206. operaciones: this.investmentProposalForm.value.operaciones = 2
  207. });
  208. break;
  209. case "CINV":
  210. this.investmentProposalForm.patchValue({
  211. pais: this.investmentProposalForm.value.pais = 210,
  212. operaciones: this.investmentProposalForm.value.operaciones = 2
  213. });
  214. break;
  215. case "TIT":
  216. this.investmentProposalForm.patchValue({
  217. pais: this.investmentProposalForm.value.pais = 210,
  218. operaciones: this.investmentProposalForm.value.operaciones = 2
  219. });
  220. break;
  221. case "FINV":
  222. this.investmentProposalForm.patchValue({
  223. tipo_mercado: this.investmentProposalForm.value.tipo_mercado = 5,
  224. pais: this.investmentProposalForm.value.pais = 210,
  225. operaciones: this.investmentProposalForm.value.operaciones = 2
  226. });
  227. break;
  228. case "OPC":
  229. this.investmentProposalForm.patchValue({
  230. //tipo_mercado: this.investmentProposalForm.value.tipo_mercado = 0,
  231. pais: this.investmentProposalForm.value.pais = 233,
  232. operaciones: this.investmentProposalForm.value.operaciones = 2
  233. });
  234. break;
  235. case "FUTU":
  236. this.investmentProposalForm.patchValue({
  237. //tipo_mercado: this.investmentProposalForm.value.tipo_mercado = 0,
  238. pais: this.investmentProposalForm.value.pais = 233,
  239. operaciones: this.investmentProposalForm.value.operaciones = 2
  240. });
  241. break;
  242. case "PEMP":
  243. this.investmentProposalForm.patchValue({
  244. tipo_mercado: this.investmentProposalForm.value.tipo_mercado = 5,
  245. pais: this.investmentProposalForm.value.pais = 210,
  246. operaciones: this.investmentProposalForm.value.operaciones = 2
  247. });
  248. break;
  249. case "PPER":
  250. this.investmentProposalForm.patchValue({
  251. tipo_mercado: this.investmentProposalForm.value.tipo_mercado = 5,
  252. pais: this.investmentProposalForm.value.pais = 210,
  253. operaciones: this.investmentProposalForm.value.operaciones = 2
  254. });
  255. break;
  256. }
  257. }
  258. }
  259. get f() {
  260. return this.investmentProposalForm.controls;
  261. }
  262. save(form: any): boolean {
  263. this.submitted = true;
  264. if (!form.valid) {
  265. return false;
  266. }
  267. this.formDataService.setComplementInfo(this.investmentProposalForm.value);
  268. return true;
  269. }
  270. goToPrevious() {
  271. this.submitted = true;
  272. if (this.investmentProposalID != undefined) {
  273. this.router.navigate(["/investment-proposal/instrument-work"], {
  274. queryParams: { id: this.investmentProposalID }
  275. });
  276. } else {
  277. this.router.navigate(["/investment-proposal/instrument-work"]);
  278. }
  279. }
  280. goToNext(form: any) {
  281. if (this.save(form)) {
  282. if (this.investmentProposalID != undefined) {
  283. this.router.navigate(["/investment-proposal/result"], {
  284. queryParams: { id: this.investmentProposalID }
  285. });
  286. } else {
  287. this.router.navigate(["/investment-proposal/result"]);
  288. }
  289. }
  290. }
  291. }