proposal-detail.component.ts 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. import {
  2. Component,
  3. OnInit,
  4. Input,
  5. ViewChild,
  6. ComponentFactoryResolver
  7. } from "@angular/core";
  8. import { Router, ActivatedRoute } from "@angular/router";
  9. import { InvestmentProposalForm } from "@app/models/investment-proposal-form";
  10. import { FormInvestmentProposalService } from "@app/services/form-investment-proposal.service";
  11. import { Instrument } from "@app/models/instrument";
  12. import { InvestmentProposalWorkflowService } from "@app/services/investment-proposal-workflow.service";
  13. import { InstrumentDirective } from "@app/components/investment-proposals/instrument/instrument.directive";
  14. import { InstrumentComponent } from "@app/components/investment-proposals/instrument/instrument.component";
  15. import { InstrumentsService } from "@app/services/instruments.service";
  16. import Swal from "sweetalert2";
  17. import { CatalogsService } from "@app/services/catalogs.service";
  18. import { InvestmentsService } from "@app/services/investments.service";
  19. @Component({
  20. selector: "app-investment-proposal-detail",
  21. templateUrl: "./proposal-detail.component.html",
  22. styleUrls: ["./proposal-detail.component.scss"]
  23. })
  24. export class InvestmentProposalDetailComponent implements OnInit {
  25. title = "Detalle de la propuesta de inversión";
  26. @Input() ads: Instrument[];
  27. @Input() formData: InvestmentProposalForm;
  28. @ViewChild(InstrumentDirective, { static: true })
  29. adHost: InstrumentDirective;
  30. isFormValid: boolean = false;
  31. general: any;
  32. instrument: any;
  33. complement: any;
  34. final: any;
  35. workType: string;
  36. form: any;
  37. currentAdIndex = -1;
  38. interval: any;
  39. indexDynamicComponent: number;
  40. investmentProposalID: string;
  41. investmentExists;
  42. state;
  43. financials;
  44. base_types;
  45. countries;
  46. companies;
  47. rates;
  48. revenues;
  49. funds;
  50. instrumentTypes;
  51. markets;
  52. emitters;
  53. periodicities;
  54. format_incomes;
  55. payment_terms;
  56. operations;
  57. gInfo: any;
  58. gInstrument: any;
  59. gComplement: any;
  60. subject: any;
  61. investmentName: any;
  62. comment: any;
  63. justification: any;
  64. constructor(
  65. private router: Router,
  66. private formDataService: FormInvestmentProposalService,
  67. private componentFactoryResolver: ComponentFactoryResolver,
  68. private instrumentService: InvestmentProposalWorkflowService,
  69. private loadInstrumentsService: InstrumentsService,
  70. private catalogService: CatalogsService,
  71. private route: ActivatedRoute,
  72. private investmentService: InvestmentsService
  73. ) {}
  74. ngOnInit() {
  75. //this.formDataService
  76. this.ads = this.loadInstrumentsService.getInstruments();
  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. if (this.investmentProposalID != undefined) {
  83. this.investmentExists = true;
  84. this.investmentService
  85. .getProposalInvestment(this.investmentProposalID)
  86. .subscribe(res => {
  87. this.state = res["result"]["id_estado_inversion"]["codigo"];
  88. this.gInfo = {
  89. asunto: res["result"]["asunto"],
  90. origenes_fondo:
  91. res["result"]["id_origen_fondo"] == null
  92. ? ""
  93. : res["result"]["id_origen_fondo"]["id_origen_fondo"],
  94. name: res["result"]["nombre_inversion"],
  95. //date: "",
  96. tipo_tasa: res["result"]["id_tipo_tasa"] || "",
  97. tipo_renta:
  98. res["result"]["id_tipo_renta"] == null
  99. ? ""
  100. : res["result"]["id_tipo_renta"]["id_tipo_renta"],
  101. periodicidad:
  102. res["result"]["id_periodicidad"] == null
  103. ? ""
  104. : res["result"]["id_periodicidad"]["id_periodicidad"],
  105. instrumentos:
  106. res["result"]["id_inversion_instrumento"]["id_tipo_instrumento"][
  107. "codigo"
  108. ],
  109. base_anual:
  110. res["result"]["id_tipo_base"] == null
  111. ? ""
  112. : res["result"]["id_tipo_base"]["id_tipo_base"],
  113. casa:
  114. res["result"]["id_entidad"] == null
  115. ? ""
  116. : res["result"]["id_entidad"]["id_entidad_financiera"],
  117. formato_ingreso:
  118. res["result"]["id_formato_ingreso"] == null
  119. ? ""
  120. : res["result"]["id_formato_ingreso"]["id_formato_ingreso"]
  121. };
  122. this.gInstrument =
  123. res["result"]["id_inversion_instrumento"]["instrumento"];
  124. this.gInstrument["id_inversion_instrumento"] =
  125. res["result"]["id_inversion_instrumento"][
  126. "id_inversion_instrumento"
  127. ];
  128. this.gComplement = {
  129. tipo_mercado:
  130. res["result"]["id_tipo_mercado"] == null
  131. ? ""
  132. : res["result"]["id_tipo_mercado"]["id_tipo_mercado"],
  133. emisores:
  134. res["result"]["id_tipo_emisor"] == null
  135. ? ""
  136. : res["result"]["id_tipo_emisor"]["id_tipo_emisor"],
  137. empresa:
  138. res["result"]["id_empresa"] == null
  139. ? ""
  140. : res["result"]["id_empresa"]["id_empresa"],
  141. pais:
  142. res["result"]["id_pais"] == null
  143. ? ""
  144. : res["result"]["id_pais"]["id_pais"],
  145. plazo:
  146. res["result"]["id_plazo"] == null
  147. ? ""
  148. : res["result"]["id_plazo"]["id_plazo"],
  149. operaciones:
  150. res["result"]["id_tipo_operacion"] == null
  151. ? ""
  152. : res["result"]["id_tipo_operacion"]["id_tipo_operacion"],
  153. comentarios: res["result"]["comentario"],
  154. justificacion: res["result"]["justificacion"]
  155. };
  156. this.formDataService.setGeneralInfo(this.gInfo);
  157. this.formDataService.setWork(this.gInstrument);
  158. this.formDataService.setComplementInfo(this.gComplement);
  159. this.general = this.formDataService.getGeneralInfo();
  160. this.instrument = this.formDataService.getWork();
  161. this.complement = this.formDataService.getComplementInfo();
  162. this.formData = this.formDataService.getFormData();
  163. this.formData.instrumentos;
  164. this.indexDynamicComponent = this.ads.findIndex(
  165. x => x.component.name == this.formData.instrumentos
  166. );
  167. if (this.indexDynamicComponent >= 0) {
  168. this.loadComponent();
  169. } else {
  170. console.log("No existe el componente");
  171. }
  172. if (this.general != undefined) {
  173. this.subject = this.general.asunto;
  174. this.investmentName = this.general.name;
  175. this.comment = this.complement.comment;
  176. this.justification = this.complement.comment;
  177. this.catalogService.getFinancialEntities().subscribe(res => {
  178. this.financials = res.find(
  179. e => e.id_entidad_financiera == this.general.casa
  180. );
  181. this.financials =
  182. this.financials != undefined ? this.financials.nombre : "-";
  183. });
  184. this.catalogService.getBaseTypes().subscribe(res => {
  185. this.base_types = res.find(
  186. e => e.id_tipo_base == this.general.base_anual
  187. );
  188. this.base_types =
  189. this.base_types != undefined
  190. ? ` ${this.base_types.tipo_base} / ${this.base_types.tipo_base_dias}`
  191. : "-";
  192. });
  193. this.catalogService.getCountries().subscribe(res => {
  194. this.countries = res.find(e => e.id_pais == this.complement.pais);
  195. this.countries =
  196. this.countries != undefined ? this.countries.nombre : "-";
  197. });
  198. this.catalogService.getCompanies().subscribe(res => {
  199. this.companies = res.find(
  200. e => e.id_empresa == this.complement.empresa
  201. );
  202. this.companies =
  203. this.companies != undefined ? this.companies.nombre : "-";
  204. });
  205. this.catalogService.getRateTypes().subscribe(res => {
  206. this.rates = res.find(
  207. e => e.id_tipo_tasa == this.general.tipo_tasa
  208. );
  209. this.rates = this.rates != undefined ? this.rates.nombre : "-";
  210. });
  211. this.catalogService.getRevenueTypes().subscribe(res => {
  212. this.revenues = res.find(
  213. e => e.id_tipo_renta == this.general.tipo_renta
  214. );
  215. this.revenues =
  216. this.revenues != undefined ? this.revenues.nombre : "-";
  217. });
  218. this.catalogService.getFundsOrigins().subscribe(res => {
  219. this.funds = res.find(
  220. e => e.id_origen_fondo == this.general.origenes_fondo
  221. );
  222. this.funds = this.funds != undefined ? this.funds.nombre : "-";
  223. });
  224. this.catalogService.getInstrumentTypes().subscribe(res => {
  225. this.instrumentTypes = res.find(
  226. e => e.codigo == this.general.instrumentos
  227. );
  228. this.instrumentTypes =
  229. this.instrumentTypes != undefined
  230. ? this.instrumentTypes.nombre
  231. : "-";
  232. });
  233. this.catalogService.getMarketTypes().subscribe(res => {
  234. this.markets = res.find(
  235. e => e.id_tipo_mercado == this.complement.tipo_mercado
  236. );
  237. this.markets =
  238. this.markets != undefined ? this.markets.nombre : "-";
  239. });
  240. this.catalogService.getEmitterTypes().subscribe(res => {
  241. this.emitters = res.find(
  242. e => e.id_tipo_emisor == this.complement.emisores
  243. );
  244. this.emitters =
  245. this.emitters != undefined ? this.emitters.nombre : "-";
  246. });
  247. this.catalogService.getPeriodicities().subscribe(res => {
  248. this.periodicities = res.find(
  249. e => e.id_periodicidad == this.general.periodicidad
  250. );
  251. this.periodicities =
  252. this.periodicities != undefined
  253. ? this.periodicities.nombre
  254. : "-";
  255. });
  256. this.catalogService.getPaymentTerms().subscribe(res => {
  257. this.payment_terms = res.find(
  258. e => e.codigo == this.complement.calificadora_riesgo
  259. );
  260. this.payment_terms =
  261. this.payment_terms != undefined
  262. ? this.payment_terms.nombre
  263. : "-";
  264. });
  265. this.catalogService.getOperationTypes().subscribe(res => {
  266. this.operations = res.find(
  267. e => e.codigo == this.complement.operaciones
  268. );
  269. this.operations =
  270. this.operations != undefined ? this.operations.nombre : "-";
  271. });
  272. //getIncomeFormat
  273. this.catalogService.getIncomeFormat().subscribe(res => {
  274. this.format_incomes = res.find(
  275. e => e.id_formato_ingreso == this.general.formato_ingreso
  276. );
  277. this.format_incomes =
  278. this.format_incomes != undefined
  279. ? this.format_incomes.nombre
  280. : "-";
  281. });
  282. }
  283. });
  284. } else {
  285. this.investmentExists = false;
  286. }
  287. }
  288. loadComponent() {
  289. this.currentAdIndex = this.indexDynamicComponent % this.ads.length;
  290. const adItem = this.ads[this.currentAdIndex];
  291. const componentFactory = this.componentFactoryResolver.resolveComponentFactory(
  292. adItem.component
  293. );
  294. const viewContainerRef = this.adHost.viewContainerRef;
  295. viewContainerRef.clear();
  296. const componentRef = viewContainerRef.createComponent(componentFactory);
  297. (<InstrumentComponent>componentRef.instance).data = adItem.data;
  298. (<InstrumentComponent>componentRef.instance).summary = true;
  299. }
  300. }