titulos.component.ts 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759
  1. import { Component, OnInit, Input, ViewChild } from "@angular/core";
  2. import { InstrumentComponent } from "@app/components/investment-proposals/instrument/instrument.component";
  3. import { FormBuilder, FormGroup, Validators } from "@angular/forms";
  4. import { IAngularMyDpOptions, IMyDateModel } from "angular-mydatepicker";
  5. import { formatDate, DatePipe } from "@angular/common";
  6. import { Router } from "@angular/router";
  7. import { FormInvestmentProposalService } from "@app/services/form-investment-proposal.service";
  8. import { CatalogsService } from "@app/services/catalogs.service";
  9. import { InstrumentCalculations } from "@app/services/instrument-calculations.service";
  10. import Swal from "sweetalert2";
  11. import { GeneralInfo } from "@app/models/investment-proposal-form";
  12. import { parse } from "date-fns";
  13. import { MatPaginator } from "@angular/material/paginator";
  14. import { MatSort } from "@angular/material/sort";
  15. import { MatTableDataSource } from "@angular/material/table";
  16. import { CSVRecord } from "@app/models/csv-data";
  17. import * as XLSX from "xlsx";
  18. @Component({
  19. selector: "app-titulos",
  20. templateUrl: "./titulos.component.html"
  21. })
  22. export class TIT implements InstrumentComponent {
  23. title: string = "Titularización";
  24. @Input() data: any;
  25. @Input() summary: boolean;
  26. @Input() investmentID: string;
  27. displayedColumns: string[] = [
  28. "posicion",
  29. "plazo",
  30. "fecha_pago",
  31. "cuota",
  32. "amortizacion_porcentaje",
  33. "amortizacion_capital",
  34. "ingreso_bruto",
  35. "impuesto",
  36. "ingreso_neto",
  37. "impuesto",
  38. "saldo"
  39. ];
  40. @ViewChild(MatPaginator, { static: true }) paginator: MatPaginator;
  41. @ViewChild(MatSort, { static: true }) sort: MatSort;
  42. form: any;
  43. general: GeneralInfo;
  44. // For daterange
  45. daysLabels: any = {
  46. su: "Dom",
  47. mo: "Lun",
  48. tu: "Mar",
  49. we: "Mie",
  50. th: "Jue",
  51. fr: "Vie",
  52. sa: "Sab"
  53. };
  54. monthsLabels: any = {
  55. 1: "Ene",
  56. 2: "Feb",
  57. 3: "Mar",
  58. 4: "Abr",
  59. 5: "May",
  60. 6: "Jun",
  61. 7: "Jul",
  62. 8: "Ago",
  63. 9: "Sep",
  64. 10: "Oct",
  65. 11: "Nov",
  66. 12: "Dic"
  67. };
  68. investmentProposalForm: FormGroup;
  69. myDpOptions: IAngularMyDpOptions = {
  70. dateRange: false,
  71. dateFormat: "dd/mm/yyyy",
  72. dayLabels: this.daysLabels,
  73. monthLabels: this.monthsLabels
  74. };
  75. myDateInit: boolean = true;
  76. m_fecha_vencimiento_compra: IMyDateModel;
  77. m_fecha_ultima_cupon_compra: IMyDateModel;
  78. m_fecha_rendencion: IMyDateModel;
  79. m_fecha_liquidacion_compra: IMyDateModel;
  80. submitted: boolean = false;
  81. instrument_exists: boolean;
  82. instrument_work: any = [];
  83. financials: any;
  84. base_types: any;
  85. proyecciones: any;
  86. titulosObject: {};
  87. dataSource = new MatTableDataSource(this.proyecciones);
  88. dataSource2 = new MatTableDataSource(this.proyecciones);
  89. hasProjections: boolean;
  90. fecha_vencimiento: any;
  91. comision_casa_compra: any;
  92. comision_bolsa_compra: any;
  93. fecha_siguiente_cupon_compra: any;
  94. dias_vencimiento_compra: any;
  95. dias_acumulados_compra: any;
  96. ytm_vencimiento_comision_porcentaje_compra: any;
  97. interes_acumulado_compra: any;
  98. interes_acumulado_porcentaje_compra: any;
  99. precio_sucio_porcentaje_compra: any;
  100. valor_transado_compra: any;
  101. monto_pagar: any;
  102. fecha_inicio_vigencia: any;
  103. comision_casa_venta: any;
  104. fecha_siguiente_cupon_venta: any;
  105. dias_vencimiento_venta: any;
  106. dias_acumulados_venta: any;
  107. ytm_vencimiento_comision_porcentaje_venta: any;
  108. interes_acumulado_venta: any;
  109. interes_acumulado_porcentaje_venta: any;
  110. precio_sucio_porcentaje_venta: any;
  111. valor_transado_venta: any;
  112. monto_recibir: any;
  113. dias_tenencia_total: any;
  114. ganancia_perdida_capital: any;
  115. ingresos_intereses: any;
  116. costos_totales: any;
  117. ganancia_perdida_total: any;
  118. ganancia_perdida_capital_porcentaje: any;
  119. intereses_porcentaje: any;
  120. neto_antes_impuesto_porcentaje: any;
  121. neto_despues_impuesto_porcentaje: any;
  122. total_ingresos_recibidos: any;
  123. percentages: any;
  124. amortizaciones: string[];
  125. operation_result: boolean = false;
  126. operation_results_work: any = [];
  127. instrument_work_summary: any = [];
  128. ytm_vencimiento_porcentaje_compra: any;
  129. ytm_vencimiento_porcentaje_venta: any;
  130. comision_bolsa_venta: any;
  131. consolidado_proyeccion: any;
  132. constructor(
  133. private formBuilder: FormBuilder,
  134. private router: Router,
  135. private formDataService: FormInvestmentProposalService,
  136. private catalogService: CatalogsService,
  137. private instrumentCalcService: InstrumentCalculations,
  138. public datepipe: DatePipe
  139. ) {
  140. this.instrument_work = this.formDataService.getWork();
  141. this.instrument_exists = this.instrument_work == undefined;
  142. this.general = this.formDataService.getGeneralInfo();
  143. if (
  144. this.instrument_work != undefined &&
  145. this.instrument_work.proyecciones != ""
  146. ) {
  147. this.hasProjections = true;
  148. this.consolidado_proyeccion = this.instrument_work.proyecciones.slice(
  149. 0,
  150. -1
  151. );
  152. this.operation_results_work = this.instrument_work["resultado_operacion"];
  153. if (this.instrument_work["instrumento"] != undefined) {
  154. this.instrument_work = this.instrument_work["instrumento"];
  155. }
  156. this.instrument_work_summary = this.instrument_work;
  157. this.dataSource2.data = this.instrument_work.proyecciones;
  158. this.dataSource2.paginator = this.paginator;
  159. this.dataSource2.sort = this.sort;
  160. } else {
  161. this.hasProjections = false;
  162. }
  163. if (!this.instrument_exists) {
  164. this.amortizaciones = this.instrument_work.amortizacion_porcentajes;
  165. }
  166. if (
  167. this.operation_results_work != undefined &&
  168. this.operation_results_work != ""
  169. ) {
  170. this.operation_result = true;
  171. }
  172. this.investmentProposalForm = this.formBuilder.group({
  173. costo_cedeval: [
  174. this.instrument_exists ? "" : this.instrument_work.costo_cedeval,
  175. [
  176. Validators.required,
  177. Validators.pattern(/^[+]?([0-9]+(?:[\.][0-9]*)?|\.[0-9]+)$/)
  178. ]
  179. ],
  180. costo_transferencia: [
  181. this.instrument_exists ? "" : this.instrument_work.costo_transferencia,
  182. [
  183. Validators.required,
  184. Validators.pattern(/^[+]?([0-9]+(?:[\.][0-9]*)?|\.[0-9]+)$/)
  185. ]
  186. ],
  187. precio_compra: [
  188. this.instrument_exists ? "" : this.instrument_work.precio_compra,
  189. [
  190. Validators.required,
  191. Validators.pattern(/^[+]?([0-9]+(?:[\.][0-9]*)?|\.[0-9]+)$/)
  192. ]
  193. ],
  194. valor_nominal_compra: [
  195. this.instrument_exists ? "" : this.instrument_work.valor_nominal_compra,
  196. [
  197. Validators.required,
  198. Validators.pattern(/^[+]?([0-9]+(?:[\.][0-9]*)?|\.[0-9]+)$/)
  199. ]
  200. ],
  201. precio_vencimiento_compra: [
  202. this.instrument_exists
  203. ? ""
  204. : this.instrument_work.precio_vencimiento_compra,
  205. [
  206. Validators.required,
  207. Validators.pattern(/^[+]?([0-9]+(?:[\.][0-9]*)?|\.[0-9]+)$/)
  208. ]
  209. ],
  210. cupon_porcentaje_compra: [
  211. this.instrument_exists
  212. ? ""
  213. : this.instrument_work.cupon_porcentaje_compra,
  214. [
  215. Validators.required,
  216. Validators.pattern(/^[+]?([0-9]+(?:[\.][0-9]*)?|\.[0-9]+)$/)
  217. ]
  218. ],
  219. comision_casa_porcentaje_compra: [
  220. this.instrument_exists
  221. ? ""
  222. : this.instrument_work.comision_casa_porcentaje_compra,
  223. [
  224. Validators.required,
  225. Validators.pattern(/^[+]?([0-9]+(?:[\.][0-9]*)?|\.[0-9]+)$/)
  226. ]
  227. ],
  228. comision_bolsa_porcentaje_compra: [
  229. this.instrument_exists
  230. ? ""
  231. : this.instrument_work.comision_bolsa_porcentaje_compra,
  232. [
  233. Validators.required,
  234. Validators.pattern(/^[+]?([0-9]+(?:[\.][0-9]*)?|\.[0-9]+)$/)
  235. ]
  236. ],
  237. precio_venta: [
  238. this.instrument_exists ? "" : this.instrument_work.precio_venta
  239. ],
  240. valor_nominal_venta: [
  241. this.instrument_exists ? "" : this.instrument_work.valor_nominal_venta
  242. ],
  243. precio_vencimiento_venta: [
  244. this.instrument_exists
  245. ? ""
  246. : this.instrument_work.precio_vencimiento_venta
  247. ],
  248. cupon_porcentaje_venta: [
  249. this.instrument_exists
  250. ? ""
  251. : this.instrument_work.cupon_porcentaje_venta
  252. ],
  253. comision_casa_porcentaje_venta: [
  254. this.instrument_exists
  255. ? ""
  256. : this.instrument_work.comision_casa_porcentaje_venta
  257. ],
  258. comision_bolsa_porcentaje_venta: [
  259. this.instrument_exists
  260. ? ""
  261. : this.instrument_work.comision_bolsa_porcentaje_venta
  262. ],
  263. fecha_ultima_cupon_compra: [
  264. this.instrument_exists
  265. ? ""
  266. : {
  267. isRange: false,
  268. singleDate: {
  269. jsDate: parse(
  270. this.instrument_work.fecha_ultima_cupon_compra,
  271. "dd/MM/yyyy",
  272. new Date()
  273. ),
  274. formatted: this.instrument_work.fecha_ultima_cupon_compra
  275. }
  276. },
  277. Validators.required
  278. ],
  279. fecha_liquidacion_compra: [
  280. this.instrument_exists
  281. ? ""
  282. : {
  283. isRange: false,
  284. singleDate: {
  285. jsDate: parse(
  286. this.instrument_work.fecha_liquidacion_compra,
  287. "dd/MM/yyyy",
  288. new Date()
  289. ),
  290. formatted: this.instrument_work.fecha_liquidacion_compra
  291. }
  292. },
  293. Validators.required
  294. ],
  295. fecha_vencimiento_compra: [
  296. this.instrument_exists
  297. ? ""
  298. : {
  299. isRange: false,
  300. singleDate: {
  301. jsDate: parse(
  302. this.instrument_work.fecha_vencimiento_compra,
  303. "dd/MM/yyyy",
  304. new Date()
  305. ),
  306. formatted: this.instrument_work.fecha_vencimiento_compra
  307. }
  308. },
  309. Validators.required
  310. ],
  311. fecha_ultima_cupon_venta: [
  312. this.instrument_exists
  313. ? ""
  314. : {
  315. isRange: false,
  316. singleDate: {
  317. jsDate: parse(
  318. this.instrument_work.fecha_ultima_cupon_venta,
  319. "dd/MM/yyyy",
  320. new Date()
  321. ),
  322. formatted: this.instrument_work.fecha_ultima_cupon_venta
  323. }
  324. }
  325. ],
  326. fecha_liquidacion_venta: [
  327. this.instrument_exists
  328. ? ""
  329. : {
  330. isRange: false,
  331. singleDate: {
  332. jsDate: parse(
  333. this.instrument_work.fecha_liquidacion_venta,
  334. "dd/MM/yyyy",
  335. new Date()
  336. ),
  337. formatted: this.instrument_work.fecha_liquidacion_venta
  338. }
  339. }
  340. ],
  341. fecha_vencimiento_venta: [
  342. this.instrument_exists
  343. ? ""
  344. : {
  345. isRange: false,
  346. singleDate: {
  347. jsDate: parse(
  348. this.instrument_work.fecha_vencimiento_venta,
  349. "dd/MM/yyyy",
  350. new Date()
  351. ),
  352. formatted: this.instrument_work.fecha_vencimiento_venta
  353. }
  354. }
  355. ],
  356. fecha_emision: [
  357. this.instrument_exists
  358. ? ""
  359. : {
  360. isRange: false,
  361. singleDate: {
  362. jsDate: parse(
  363. this.instrument_work.fecha_emision,
  364. "dd/MM/yyyy",
  365. new Date()
  366. ),
  367. formatted: this.instrument_work.fecha_emision
  368. }
  369. },
  370. Validators.required
  371. ]
  372. });
  373. }
  374. public records: any[] = [];
  375. @ViewChild("csvReader", null) csvReader: any;
  376. uploadListener($event: any): void {
  377. /* wire up file reader */
  378. const target: DataTransfer = $event.target;
  379. if (target.files.length !== 1) {
  380. throw new Error("Cannot use multiple files");
  381. }
  382. const reader: FileReader = new FileReader();
  383. reader.readAsBinaryString(target.files[0]);
  384. reader.onload = (e: any) => {
  385. /* create workbook */
  386. const binarystr: string = e.target.result;
  387. const wb: XLSX.WorkBook = XLSX.read(binarystr, { type: "binary" });
  388. /* selected the first sheet */
  389. const wsname: string = wb.SheetNames[0];
  390. const ws: XLSX.WorkSheet = wb.Sheets[wsname];
  391. /* save data */
  392. const data = XLSX.utils.sheet_to_json(ws, { header: 1 }); // to get 2d array pass 2nd parameter as object {header: 1}
  393. const data2 = data.toString().split(",");
  394. data2.shift();
  395. this.amortizaciones = data2;
  396. };
  397. }
  398. get f() {
  399. return this.investmentProposalForm.controls;
  400. }
  401. save(form: any): boolean {
  402. if (!form.valid) {
  403. return false;
  404. }
  405. this.formDataService.setWork(this.titulosObject);
  406. return true;
  407. }
  408. getCalculations(form: any, saveForm: boolean) {
  409. this.submitted = true;
  410. if (!form.valid) {
  411. return false;
  412. }
  413. if (this.amortizaciones == undefined && this.proyecciones == undefined) {
  414. Swal.fire({
  415. icon: "error",
  416. title: "Error de validación",
  417. text: "Debe ingresar un archivo con los porcentajes de amortización"
  418. });
  419. return false;
  420. }
  421. Swal.fire({
  422. allowOutsideClick: false,
  423. icon: "info",
  424. text: "Espere por favor..."
  425. });
  426. Swal.showLoading();
  427. this.instrumentCalcService
  428. .titularizacionCalc(
  429. "TIT", // Codigo del instrumento
  430. {
  431. id_tipo_base: +this.general.base_anual,
  432. id_formato_ingreso: +this.general.formato_ingreso,
  433. id_periodicidad: +this.general.periodicidad
  434. },
  435. {
  436. costo_transferencia: +this.f.costo_transferencia.value,
  437. valor_nominal_compra: +this.f.valor_nominal_compra.value,
  438. precio_compra: +this.f.precio_compra.value,
  439. precio_vencimiento_compra: +this.f.precio_vencimiento_compra.value,
  440. cupon_porcentaje_compra: +this.f.cupon_porcentaje_compra.value,
  441. comision_casa_porcentaje_compra: this.f
  442. .comision_casa_porcentaje_compra.value,
  443. comision_bolsa_porcentaje_compra: this.f
  444. .comision_bolsa_porcentaje_compra.value,
  445. valor_nominal_venta: +this.f.valor_nominal_venta.value,
  446. precio_venta: +this.f.precio_venta.value,
  447. precio_vencimiento_venta: +this.f.precio_vencimiento_venta.value,
  448. cupon_porcentaje_venta: +this.f.cupon_porcentaje_venta.value,
  449. comision_casa_porcentaje_venta: this.f.comision_casa_porcentaje_venta
  450. .value,
  451. comision_bolsa_porcentaje_venta: this.f
  452. .comision_bolsa_porcentaje_venta.value,
  453. fecha_vencimiento_compra: this.f.fecha_vencimiento_compra.value
  454. .singleDate.formatted,
  455. fecha_ultima_cupon_compra: this.f.fecha_ultima_cupon_compra.value
  456. .singleDate.formatted,
  457. fecha_liquidacion_compra: this.f.fecha_liquidacion_compra.value
  458. .singleDate.formatted,
  459. fecha_vencimiento_venta: this.f.fecha_vencimiento_venta.value
  460. .singleDate.formatted,
  461. fecha_ultima_cupon_venta: this.f.fecha_ultima_cupon_venta.value
  462. .singleDate.formatted,
  463. fecha_liquidacion_venta: this.f.fecha_liquidacion_venta.value
  464. .singleDate.formatted,
  465. fecha_emision: this.f.fecha_emision.value.singleDate.formatted,
  466. costo_cedeval: this.f.costo_cedeval.value,
  467. amortizacion_porcentajes: this.amortizaciones
  468. }
  469. )
  470. .subscribe(
  471. ans => {
  472. // Instrumento de compra
  473. this.comision_casa_compra =
  474. ans["result"]["instrumento_compra"]["comision_casa_compra"];
  475. this.comision_bolsa_compra =
  476. ans["result"]["instrumento_compra"]["comision_bolsa_compra"];
  477. this.fecha_siguiente_cupon_compra =
  478. ans["result"]["instrumento_compra"]["fecha_siguiente_cupon_compra"];
  479. this.dias_vencimiento_compra =
  480. ans["result"]["instrumento_compra"]["dias_vencimiento_compra"];
  481. this.dias_acumulados_compra =
  482. ans["result"]["instrumento_compra"]["dias_acumulados_compra"];
  483. this.ytm_vencimiento_comision_porcentaje_compra =
  484. ans["result"]["instrumento_compra"][
  485. "ytm_vencimiento_comision_porcentaje_compra"
  486. ];
  487. this.ytm_vencimiento_porcentaje_compra =
  488. ans["result"]["instrumento_compra"][
  489. "ytm_vencimiento_porcentaje_compra"
  490. ];
  491. this.interes_acumulado_compra =
  492. ans["result"]["instrumento_compra"]["interes_acumulado_compra"];
  493. this.interes_acumulado_porcentaje_compra =
  494. ans["result"]["instrumento_compra"][
  495. "interes_acumulado_porcentaje_compra"
  496. ];
  497. this.precio_sucio_porcentaje_compra =
  498. ans["result"]["instrumento_compra"][
  499. "precio_sucio_porcentaje_compra"
  500. ];
  501. this.valor_transado_compra =
  502. ans["result"]["instrumento_compra"]["valor_transado_compra"];
  503. this.monto_pagar = ans["result"]["instrumento_compra"]["monto_pagar"];
  504. this.fecha_inicio_vigencia =
  505. ans["result"]["instrumento_compra"]["fecha_inicio_vigencia"];
  506. // Instrumento de venta
  507. this.comision_casa_venta =
  508. ans["result"]["instrumento_venta"]["comision_casa_venta"];
  509. this.comision_bolsa_venta =
  510. ans["result"]["instrumento_venta"]["comision_bolsa_venta"];
  511. this.fecha_siguiente_cupon_venta =
  512. ans["result"]["instrumento_venta"]["fecha_siguiente_cupon_venta"];
  513. this.dias_vencimiento_venta =
  514. ans["result"]["instrumento_venta"]["dias_vencimiento_venta"];
  515. this.dias_acumulados_venta =
  516. ans["result"]["instrumento_venta"]["dias_acumulados_venta"];
  517. this.ytm_vencimiento_comision_porcentaje_venta =
  518. ans["result"]["instrumento_venta"][
  519. "ytm_vencimiento_comision_porcentaje_venta"
  520. ];
  521. this.ytm_vencimiento_porcentaje_venta =
  522. ans["result"]["instrumento_venta"][
  523. "ytm_vencimiento_porcentaje_venta"
  524. ];
  525. this.interes_acumulado_venta =
  526. ans["result"]["instrumento_venta"]["interes_acumulado_venta"];
  527. this.interes_acumulado_porcentaje_venta =
  528. ans["result"]["instrumento_venta"][
  529. "interes_acumulado_porcentaje_venta"
  530. ];
  531. this.precio_sucio_porcentaje_venta =
  532. ans["result"]["instrumento_venta"]["precio_sucio_porcentaje_venta"];
  533. this.valor_transado_venta =
  534. ans["result"]["instrumento_venta"]["valor_transado_venta"];
  535. this.monto_recibir =
  536. ans["result"]["instrumento_venta"]["monto_recibir"];
  537. // Resultado de la operacion
  538. this.operation_result = true;
  539. this.dias_tenencia_total =
  540. ans["result"]["resultado_operacion"]["dias_tenencia_total"];
  541. this.ganancia_perdida_capital =
  542. ans["result"]["resultado_operacion"]["ganancia_perdida_capital"];
  543. this.ingresos_intereses =
  544. ans["result"]["resultado_operacion"]["ingresos_intereses"];
  545. this.costos_totales =
  546. ans["result"]["resultado_operacion"]["costos_totales"];
  547. this.ganancia_perdida_total =
  548. ans["result"]["resultado_operacion"]["ganancia_perdida_total"];
  549. this.ganancia_perdida_capital_porcentaje =
  550. ans["result"]["resultado_operacion"][
  551. "ganancia_perdida_capital_porcentaje"
  552. ];
  553. this.intereses_porcentaje =
  554. ans["result"]["resultado_operacion"]["intereses_porcentaje"];
  555. this.neto_antes_impuesto_porcentaje =
  556. ans["result"]["resultado_operacion"][
  557. "neto_antes_impuesto_porcentaje"
  558. ];
  559. this.neto_despues_impuesto_porcentaje =
  560. ans["result"]["resultado_operacion"][
  561. "neto_despues_impuesto_porcentaje"
  562. ];
  563. this.total_ingresos_recibidos =
  564. ans["result"]["resultado_operacion"]["total_ingresos_recibidos"];
  565. // Proyecciones
  566. this.proyecciones = ans["result"]["proyecciones"];
  567. if (this.proyecciones != undefined && this.proyecciones.length > 0) {
  568. let proyecciones_temp = this.proyecciones;
  569. this.consolidado_proyeccion =
  570. proyecciones_temp[proyecciones_temp.length - 1];
  571. this.proyecciones = ans["result"]["proyecciones"];
  572. }
  573. this.dataSource.data = this.proyecciones.slice(0, -1);
  574. this.dataSource2.data = this.proyecciones.slice(0, -1);
  575. this.dataSource.paginator = this.paginator;
  576. this.dataSource.sort = this.sort;
  577. this.titulosObject = {
  578. costo_transferencia: this.investmentProposalForm.value
  579. .costo_transferencia,
  580. valor_nominal_compra: this.investmentProposalForm.value
  581. .valor_nominal_compra,
  582. precio_compra: this.investmentProposalForm.value.precio_compra,
  583. precio_vencimiento_compra: this.investmentProposalForm.value
  584. .precio_vencimiento_compra,
  585. cupon_porcentaje_compra: this.investmentProposalForm.value
  586. .cupon_porcentaje_compra,
  587. comision_casa_porcentaje_compra: this.investmentProposalForm.value
  588. .comision_casa_porcentaje_compra,
  589. comision_bolsa_porcentaje_compra: this.investmentProposalForm.value
  590. .comision_bolsa_porcentaje_compra,
  591. valor_nominal_venta: this.investmentProposalForm.value
  592. .valor_nominal_venta,
  593. precio_venta: this.investmentProposalForm.value.precio_venta,
  594. precio_vencimiento_venta: this.investmentProposalForm.value
  595. .precio_vencimiento_venta,
  596. cupon_porcentaje_venta: this.investmentProposalForm.value
  597. .cupon_porcentaje_venta,
  598. comision_casa_porcentaje_venta: this.investmentProposalForm.value
  599. .comision_casa_porcentaje_venta,
  600. comision_bolsa_porcentaje_venta: this.investmentProposalForm.value
  601. .comision_bolsa_porcentaje_venta,
  602. fecha_vencimiento_compra: this.f.fecha_vencimiento_compra.value
  603. .singleDate.formatted,
  604. fecha_ultima_cupon_compra: this.f.fecha_ultima_cupon_compra.value
  605. .singleDate.formatted,
  606. fecha_liquidacion_compra: this.f.fecha_liquidacion_compra.value
  607. .singleDate.formatted,
  608. fecha_vencimiento_venta: this.f.fecha_vencimiento_venta.value
  609. .singleDate.formatted,
  610. fecha_ultima_cupon_venta: this.f.fecha_ultima_cupon_venta.value
  611. .singleDate.formatted,
  612. fecha_liquidacion_venta: this.f.fecha_liquidacion_venta.value
  613. .singleDate.formatted,
  614. fecha_emision: this.f.fecha_emision.value.singleDate.formatted,
  615. // Instrumento de compra
  616. comision_casa_compra: this.comision_casa_compra,
  617. comision_bolsa_compra: this.comision_bolsa_compra,
  618. fecha_siguiente_cupon_compra: this.fecha_siguiente_cupon_compra,
  619. dias_vencimiento_compra: this.dias_vencimiento_compra,
  620. dias_acumulados_compra: this.dias_acumulados_compra,
  621. ytm_vencimiento_porcentaje_compra: this
  622. .ytm_vencimiento_porcentaje_compra,
  623. ytm_vencimiento_comision_porcentaje_compra: this
  624. .ytm_vencimiento_comision_porcentaje_compra,
  625. interes_acumulado_compra: this.interes_acumulado_compra,
  626. interes_acumulado_porcentaje_compra: this
  627. .interes_acumulado_porcentaje_compra,
  628. precio_sucio_porcentaje_compra: this.precio_sucio_porcentaje_compra,
  629. valor_transado_compra: this.valor_transado_compra,
  630. monto_pagar: this.monto_pagar,
  631. fecha_inicio_vigencia: this.fecha_inicio_vigencia,
  632. // Instrumento de venta
  633. comision_casa_venta: this.comision_casa_venta,
  634. comision_bolsa_venta: this.comision_bolsa_venta,
  635. fecha_siguiente_cupon_venta: this.fecha_siguiente_cupon_venta,
  636. dias_vencimiento_venta: this.dias_vencimiento_venta,
  637. dias_acumulados_venta: this.dias_acumulados_venta,
  638. ytm_vencimiento_porcentaje_venta: this
  639. .ytm_vencimiento_porcentaje_venta,
  640. ytm_vencimiento_comision_porcentaje_venta: this
  641. .ytm_vencimiento_comision_porcentaje_venta,
  642. interes_acumulado_venta: this.interes_acumulado_venta,
  643. interes_acumulado_porcentaje_venta: this
  644. .interes_acumulado_porcentaje_venta,
  645. precio_sucio_porcentaje_venta: this.precio_sucio_porcentaje_venta,
  646. valor_transado_venta: this.valor_transado_venta,
  647. // Resultado de la operacion
  648. /*
  649. monto_recibir: this.monto_recibir,
  650. dias_tenencia_total: this.dias_tenencia_total,
  651. ganancia_perdida_capital: this.ganancia_perdida_capital,
  652. ingresos_intereses: this.ingresos_intereses,
  653. costos_totales: this.costos_totales,
  654. ganancia_perdida_total: this.ganancia_perdida_total,
  655. ganancia_perdida_capital_porcentaje: this
  656. .ganancia_perdida_capital_porcentaje,
  657. intereses_porcentaje: this.intereses_porcentaje,
  658. neto_antes_impuesto_porcentaje: this.neto_antes_impuesto_porcentaje,
  659. neto_despues_impuesto_porcentaje: this
  660. .neto_despues_impuesto_porcentaje,
  661. total_ingresos_recibidos: this.total_ingresos_recibidos,
  662. amortizacion_porcentajes: this.amortizaciones,-**/
  663. // Proyecciones
  664. costo_cedeval: this.f.costo_cedeval.value,
  665. proyecciones: this.proyecciones
  666. };
  667. this.formDataService.setWork(this.titulosObject);
  668. Swal.close();
  669. if (saveForm == true) {
  670. if (this.investmentID != undefined) {
  671. this.router.navigate(["/investment-proposal/complement-info"], {
  672. queryParams: { id: this.investmentID }
  673. });
  674. } else {
  675. this.router.navigate(["/investment-proposal/complement-info"]);
  676. }
  677. }
  678. },
  679. err => {
  680. Swal.fire({
  681. icon: "error",
  682. title: "Error en el servidor",
  683. text: "No su pudo obtener la informacion"
  684. });
  685. return false;
  686. }
  687. );
  688. }
  689. goToPrevious() {
  690. this.submitted = true;
  691. if (this.investmentID != undefined) {
  692. this.router.navigate(["/investment-proposal/general-info"], {
  693. queryParams: { id: this.investmentID }
  694. });
  695. } else {
  696. this.router.navigate(["/investment-proposal/general-info"]);
  697. }
  698. }
  699. goToNext(form: any) {
  700. this.getCalculations(form, true);
  701. }
  702. }