titulos.component.ts 29 KB

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