titulos.component.ts 29 KB

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