proposal-detail.component.ts 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  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. logs: any;
  65. logsExists: boolean = false;
  66. paymentExists: boolean = false;
  67. monto: any;
  68. codigo_inversion: any;
  69. codigo: any;
  70. tipo_pago: any;
  71. cuenta_bancaria: any;
  72. fecha_vencimiento: any;
  73. fecha_pago: any;
  74. cuenta_bancaria_destino: any;
  75. emitir_nombre: any;
  76. constructor(
  77. private router: Router,
  78. private formDataService: FormInvestmentProposalService,
  79. private componentFactoryResolver: ComponentFactoryResolver,
  80. private instrumentService: InvestmentProposalWorkflowService,
  81. private loadInstrumentsService: InstrumentsService,
  82. private catalogService: CatalogsService,
  83. private route: ActivatedRoute,
  84. private investmentService: InvestmentsService
  85. ) {}
  86. ngOnInit() {
  87. //this.formDataService
  88. this.ads = this.loadInstrumentsService.getInstruments();
  89. this.route.params.subscribe(params => {
  90. this.investmentProposalID = params["id"];
  91. });
  92. if (this.investmentProposalID == undefined)
  93. this.investmentProposalID = this.route.snapshot.queryParamMap.get("id");
  94. if (this.investmentProposalID != undefined) {
  95. this.investmentExists = true;
  96. this.investmentService
  97. .getProposalInvestment(this.investmentProposalID)
  98. .subscribe(res => {
  99. this.state = res["result"]["id_estado_inversion"]["codigo"];
  100. this.gInfo = {
  101. asunto: res["result"]["asunto"],
  102. origenes_fondo:
  103. res["result"]["id_origen_fondo"] == null
  104. ? ""
  105. : res["result"]["id_origen_fondo"]["id_origen_fondo"],
  106. name: res["result"]["nombre_inversion"],
  107. //date: "",
  108. tipo_tasa: res["result"]["id_tipo_tasa"] || "",
  109. tipo_renta:
  110. res["result"]["id_tipo_renta"] == null
  111. ? ""
  112. : res["result"]["id_tipo_renta"]["id_tipo_renta"],
  113. periodicidad:
  114. res["result"]["id_periodicidad"] == null
  115. ? ""
  116. : res["result"]["id_periodicidad"]["id_periodicidad"],
  117. instrumentos:
  118. res["result"]["id_inversion_instrumento"]["id_tipo_instrumento"][
  119. "codigo"
  120. ],
  121. base_anual:
  122. res["result"]["id_tipo_base"] == null
  123. ? ""
  124. : res["result"]["id_tipo_base"]["id_tipo_base"],
  125. casa:
  126. res["result"]["id_entidad"] == null
  127. ? ""
  128. : res["result"]["id_entidad"]["id_entidad_financiera"],
  129. formato_ingreso:
  130. res["result"]["id_formato_ingreso"] == null
  131. ? ""
  132. : res["result"]["id_formato_ingreso"]["id_formato_ingreso"]
  133. };
  134. this.gInstrument =
  135. res["result"]["id_inversion_instrumento"]["instrumento"];
  136. this.gInstrument["id_inversion_instrumento"] =
  137. res["result"]["id_inversion_instrumento"][
  138. "id_inversion_instrumento"
  139. ];
  140. this.gComplement = {
  141. tipo_mercado:
  142. res["result"]["id_tipo_mercado"] == null
  143. ? ""
  144. : res["result"]["id_tipo_mercado"]["id_tipo_mercado"],
  145. emisores:
  146. res["result"]["id_tipo_emisor"] == null
  147. ? ""
  148. : res["result"]["id_tipo_emisor"]["id_tipo_emisor"],
  149. empresa:
  150. res["result"]["id_empresa"] == null
  151. ? ""
  152. : res["result"]["id_empresa"]["id_empresa"],
  153. pais:
  154. res["result"]["id_pais"] == null
  155. ? ""
  156. : res["result"]["id_pais"]["id_pais"],
  157. plazo:
  158. res["result"]["id_plazo"] == null
  159. ? ""
  160. : res["result"]["id_plazo"]["id_plazo"],
  161. operaciones:
  162. res["result"]["id_tipo_operacion"] == null
  163. ? ""
  164. : res["result"]["id_tipo_operacion"]["id_tipo_operacion"],
  165. comentarios: res["result"]["comentario"],
  166. justificacion: res["result"]["justificacion"]
  167. };
  168. this.formDataService.setGeneralInfo(this.gInfo);
  169. this.formDataService.setWork(this.gInstrument);
  170. this.formDataService.setComplementInfo(this.gComplement);
  171. this.general = this.formDataService.getGeneralInfo();
  172. this.instrument = this.formDataService.getWork();
  173. this.complement = this.formDataService.getComplementInfo();
  174. this.formData = this.formDataService.getFormData();
  175. this.formData.instrumentos;
  176. this.indexDynamicComponent = this.ads.findIndex(
  177. x => x.data.key == this.formData.instrumentos
  178. );
  179. if (this.indexDynamicComponent >= 0) {
  180. this.loadComponent();
  181. } else {
  182. console.log("No existe el componente");
  183. }
  184. if (this.general != undefined) {
  185. this.subject = this.general.asunto;
  186. this.investmentName = this.general.name;
  187. this.comment = this.complement.comentarios;
  188. this.justification = this.complement.justificacion;
  189. this.catalogService.getFinancialEntities().subscribe(res => {
  190. this.financials = res.find(
  191. e => e.id_entidad_financiera == this.general.casa
  192. );
  193. this.financials =
  194. this.financials != undefined ? this.financials.nombre : "-";
  195. });
  196. this.catalogService.getBaseTypes().subscribe(res => {
  197. this.base_types = res.find(
  198. e => e.id_tipo_base == this.general.base_anual
  199. );
  200. this.base_types =
  201. this.base_types != undefined
  202. ? `${this.base_types.tipo_base_dias} / ${this.base_types.tipo_base}`
  203. : "-";
  204. });
  205. this.catalogService.getCountries().subscribe(res => {
  206. this.countries = res.find(e => e.id_pais == this.complement.pais);
  207. this.countries =
  208. this.countries != undefined ? this.countries.nombre : "-";
  209. });
  210. this.catalogService.getCompanies().subscribe(res => {
  211. this.companies = res.find(
  212. e => e.id_empresa == this.complement.empresa
  213. );
  214. this.companies =
  215. this.companies != undefined ? this.companies.nombre : "-";
  216. });
  217. this.catalogService.getRateTypes().subscribe(res => {
  218. this.rates = res.find(
  219. e => e.id_tipo_tasa == this.general.tipo_tasa
  220. );
  221. this.rates = this.rates != undefined ? this.rates.nombre : "-";
  222. });
  223. this.catalogService.getRevenueTypes().subscribe(res => {
  224. this.revenues = res.find(
  225. e => e.id_tipo_renta == this.general.tipo_renta
  226. );
  227. this.revenues =
  228. this.revenues != undefined ? this.revenues.nombre : "-";
  229. });
  230. this.catalogService.getFundsOrigins().subscribe(res => {
  231. this.funds = res.find(
  232. e => e.id_origen_fondo == this.general.origenes_fondo
  233. );
  234. this.funds = this.funds != undefined ? this.funds.nombre : "-";
  235. });
  236. this.catalogService.getInstrumentTypes().subscribe(res => {
  237. this.instrumentTypes = res.find(
  238. e => e.codigo == this.general.instrumentos
  239. );
  240. this.instrumentTypes =
  241. this.instrumentTypes != undefined
  242. ? this.instrumentTypes.nombre
  243. : "-";
  244. });
  245. this.catalogService.getMarketTypes().subscribe(res => {
  246. this.markets = res.find(
  247. e => e.id_tipo_mercado == this.complement.tipo_mercado
  248. );
  249. this.markets =
  250. this.markets != undefined ? this.markets.nombre : "-";
  251. });
  252. this.catalogService.getEmitterTypes().subscribe(res => {
  253. this.emitters = res.find(
  254. e => e.id_tipo_emisor == this.complement.emisores
  255. );
  256. this.emitters =
  257. this.emitters != undefined ? this.emitters.nombre : "-";
  258. });
  259. this.catalogService.getPeriodicities().subscribe(res => {
  260. this.periodicities = res.find(
  261. e => e.id_periodicidad == this.general.periodicidad
  262. );
  263. this.periodicities =
  264. this.periodicities != undefined
  265. ? this.periodicities.nombre
  266. : "-";
  267. });
  268. this.catalogService.getPaymentTerms().subscribe(res => {
  269. this.payment_terms = res.find(
  270. e => e.id_plazo == this.complement.plazo
  271. );
  272. this.payment_terms =
  273. this.payment_terms != undefined
  274. ? this.payment_terms.nombre
  275. : "-";
  276. });
  277. this.catalogService.getOperationTypes().subscribe(res => {
  278. this.operations = res.find(
  279. e => e.id_tipo_operacion == this.complement.operaciones
  280. );
  281. this.operations =
  282. this.operations != undefined ? this.operations.nombre : "-";
  283. });
  284. //getIncomeFormat
  285. this.catalogService.getIncomeFormat().subscribe(res => {
  286. this.format_incomes = res.find(
  287. e => e.id_formato_ingreso == this.general.formato_ingreso
  288. );
  289. this.format_incomes =
  290. this.format_incomes != undefined
  291. ? this.format_incomes.nombre
  292. : "-";
  293. });
  294. }
  295. if (
  296. this.state == "COMPR" ||
  297. this.state == "PGAPR" ||
  298. this.state == "LIQUI" ||
  299. this.state == "FINAL"
  300. )
  301. this.investmentService
  302. .getPaymentInfoProposalInvestment(this.investmentProposalID)
  303. .subscribe(resp => {
  304. this.paymentExists = true;
  305. this.monto = resp["result"]["monto"];
  306. this.codigo = resp["result"]["codigo"];
  307. this.tipo_pago = resp["result"]["id_tipo_pago"]["nombre"];
  308. this.cuenta_bancaria =
  309. resp["result"]["id_cuenta_bancaria"]["nombre"];
  310. this.fecha_vencimiento = resp["result"]["fecha_vencimiento"];
  311. this.fecha_pago = resp["result"]["fecha_pago"] || "";
  312. if (resp["result"]["id_cuenta_bancaria_destino"] != null) {
  313. this.cuenta_bancaria_destino =
  314. resp["result"]["id_cuenta_bancaria_destino"]["nombre"];
  315. }
  316. if (resp["result"]["emitir_nombre"] != null) {
  317. this.emitir_nombre = resp["result"]["emitir_nombre"];
  318. }
  319. });
  320. });
  321. this.investmentService
  322. .getInvestmentProposalLogs(this.investmentProposalID)
  323. .subscribe(
  324. res => {
  325. this.logs = res["result"];
  326. this.logsExists = true;
  327. console.log(this.logs);
  328. },
  329. error => {}
  330. );
  331. } else {
  332. this.investmentExists = false;
  333. }
  334. Swal.close();
  335. }
  336. loadComponent() {
  337. const adItem = this.ads[this.indexDynamicComponent];
  338. const componentFactory = this.componentFactoryResolver.resolveComponentFactory(
  339. adItem.component
  340. );
  341. const viewContainerRef = this.adHost.viewContainerRef;
  342. viewContainerRef.clear();
  343. const componentRef = viewContainerRef.createComponent(componentFactory);
  344. (<InstrumentComponent>componentRef.instance).data = adItem.data;
  345. (<InstrumentComponent>componentRef.instance).summary = true;
  346. }
  347. }