futuros.component.ts 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755
  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. @Component({
  17. selector: "app-futuros",
  18. templateUrl: "./futuros.component.html"
  19. })
  20. export class FUTU implements InstrumentComponent {
  21. title: string = "Futuros";
  22. @Input() data: any;
  23. @Input() summary: boolean;
  24. @Input() investmentID: string;
  25. form: any;
  26. general: GeneralInfo;
  27. // For daterange
  28. daysLabels: any = {
  29. su: "Dom",
  30. mo: "Lun",
  31. tu: "Mar",
  32. we: "Mie",
  33. th: "Jue",
  34. fr: "Vie",
  35. sa: "Sab"
  36. };
  37. monthsLabels: any = {
  38. 1: "Ene",
  39. 2: "Feb",
  40. 3: "Mar",
  41. 4: "Abr",
  42. 5: "May",
  43. 6: "Jun",
  44. 7: "Jul",
  45. 8: "Ago",
  46. 9: "Sep",
  47. 10: "Oct",
  48. 11: "Nov",
  49. 12: "Dic"
  50. };
  51. investmentProposalForm: FormGroup;
  52. myDpOptions: IAngularMyDpOptions = {
  53. dateRange: false,
  54. dateFormat: "dd/mm/yyyy",
  55. dayLabels: this.daysLabels,
  56. monthLabels: this.monthsLabels
  57. };
  58. myDateInit: boolean = true;
  59. m_fecha_vencimiento_compra: IMyDateModel;
  60. m_fecha_operacion: IMyDateModel;
  61. m_fecha_rendencion: IMyDateModel;
  62. m_fecha_liquidacion_compra: IMyDateModel;
  63. submitted: boolean = false;
  64. instrument_exists: boolean;
  65. instrument_work: any = [];
  66. financials: any;
  67. base_types: any;
  68. futurosObject: {};
  69. hasProjections: boolean;
  70. tipoOperacion: any;
  71. tipoEjecucion: any;
  72. fecha_vencimiento: any;
  73. operation_result: boolean = false;
  74. operation_results_work: any = [];
  75. instrument_work_summary: any = [];
  76. fecha_operacion_compra: any;
  77. fecha_liquidacion_compra: any;
  78. precio_unitario_compra: any;
  79. comision_broker_compra: any;
  80. cantidad_contratos_compra: any;
  81. unidades_contratos_compra: any;
  82. valor_transado_compra: any;
  83. valor_pagado: any;
  84. ganancia_perdida: any;
  85. rendimiento: any;
  86. corto: any;
  87. fecha_inicio_vigencia: any;
  88. fecha_vencimiento_compra: any;
  89. fecha_operacion_venta: any;
  90. fecha_liquidacion_venta: any;
  91. precio_unitario_venta: any;
  92. comision_broker_venta: any;
  93. cantidad_contratos_venta: any;
  94. unidades_contratos_venta: any;
  95. valor_transado_venta: any;
  96. valor_recibido: any;
  97. fecha_vencimiento_venta: any;
  98. valor_nominal: any;
  99. valor_transado: any;
  100. comision_casa: any;
  101. comision_bolsa: any;
  102. fecha_liquidacion: any;
  103. operacion: any;
  104. ejecucion: any;
  105. operaciones = [
  106. { codigo: 1, nombre: "Corto" },
  107. { codigo: 0, nombre: "Largo" }
  108. ];
  109. ejecuciones = [
  110. { codigo: 1, nombre: "Completa" },
  111. { codigo: 0, nombre: "Parcial" }
  112. ];
  113. constructor(
  114. private formBuilder: FormBuilder,
  115. private router: Router,
  116. private formDataService: FormInvestmentProposalService,
  117. private catalogService: CatalogsService,
  118. private instrumentCalcService: InstrumentCalculations,
  119. public datepipe: DatePipe
  120. ) {
  121. this.instrument_work = this.formDataService.getWork();
  122. this.instrument_exists = this.instrument_work == undefined;
  123. this.general = this.formDataService.getGeneralInfo();
  124. console.log("init");
  125. console.log(this.operaciones);
  126. console.log(this.instrument_work);
  127. if (
  128. this.instrument_work != undefined &&
  129. this.instrument_work.completo == undefined
  130. ) {
  131. if (
  132. this.instrument_work.valor_pagado > 0 &&
  133. this.instrument_work.valor_recibido > 0
  134. ) {
  135. this.ejecucion = 1;
  136. } else {
  137. this.ejecucion = +this.instrument_work_summary.completo;
  138. }
  139. }
  140. this.investmentProposalForm = this.formBuilder.group({
  141. operacion: [this.instrument_exists ? "" : this.instrument_work.corto],
  142. ejecucion: [this.instrument_exists ? "" : this.ejecucion],
  143. ticker: [this.instrument_exists ? "" : this.instrument_work.ticker],
  144. precio_unitario_compra: [
  145. this.instrument_exists
  146. ? ""
  147. : this.instrument_work.precio_unitario_compra
  148. ],
  149. comision_broker_compra: [
  150. this.instrument_exists
  151. ? ""
  152. : this.instrument_work.comision_broker_compra
  153. ],
  154. cantidad_contratos_compra: [
  155. this.instrument_exists
  156. ? ""
  157. : this.instrument_work.cantidad_contratos_compra
  158. ],
  159. unidades_contratos_compra: [
  160. this.instrument_exists
  161. ? ""
  162. : this.instrument_work.unidades_contratos_compra
  163. ],
  164. fecha_operacion_compra: [
  165. this.instrument_exists
  166. ? ""
  167. : this.instrument_exists
  168. ? ""
  169. : {
  170. isRange: false,
  171. singleDate: {
  172. jsDate: parse(
  173. this.instrument_work.fecha_operacion_compra,
  174. "dd/MM/yyyy",
  175. new Date()
  176. ),
  177. formatted: this.instrument_work.fecha_operacion_compra
  178. }
  179. }
  180. ],
  181. fecha_liquidacion_compra: [
  182. this.instrument_exists
  183. ? ""
  184. : {
  185. isRange: false,
  186. singleDate: {
  187. jsDate: parse(
  188. this.instrument_work.fecha_liquidacion_compra,
  189. "dd/MM/yyyy",
  190. new Date()
  191. ),
  192. formatted: this.instrument_work.fecha_liquidacion_compra
  193. }
  194. }
  195. ],
  196. fecha_vencimiento_compra: [
  197. this.instrument_exists
  198. ? ""
  199. : {
  200. isRange: false,
  201. singleDate: {
  202. jsDate: parse(
  203. this.instrument_work.fecha_vencimiento_compra,
  204. "dd/MM/yyyy",
  205. new Date()
  206. ),
  207. formatted: this.instrument_work.fecha_vencimiento_compra
  208. }
  209. }
  210. ],
  211. precio_unitario_venta: [
  212. this.instrument_exists ? "" : this.instrument_work.precio_unitario_venta
  213. ],
  214. comision_broker_venta: [
  215. this.instrument_exists ? "" : this.instrument_work.comision_broker_venta
  216. ],
  217. cantidad_contratos_venta: [
  218. this.instrument_exists
  219. ? ""
  220. : this.instrument_work.cantidad_contratos_venta
  221. ],
  222. unidades_contratos_venta: [
  223. this.instrument_exists
  224. ? ""
  225. : this.instrument_work.unidades_contratos_venta
  226. ],
  227. fecha_operacion_venta: [
  228. this.instrument_exists
  229. ? ""
  230. : {
  231. isRange: false,
  232. singleDate: {
  233. jsDate: parse(
  234. this.instrument_work.fecha_operacion_venta,
  235. "dd/MM/yyyy",
  236. new Date()
  237. ),
  238. formatted: this.instrument_work.fecha_operacion_venta
  239. }
  240. }
  241. ],
  242. fecha_liquidacion_venta: [
  243. this.instrument_exists
  244. ? ""
  245. : {
  246. isRange: false,
  247. singleDate: {
  248. jsDate: parse(
  249. this.instrument_work.fecha_liquidacion_venta,
  250. "dd/MM/yyyy",
  251. new Date()
  252. ),
  253. formatted: this.instrument_work.fecha_liquidacion_venta
  254. }
  255. }
  256. ],
  257. fecha_vencimiento_venta: [
  258. this.instrument_exists
  259. ? ""
  260. : {
  261. isRange: false,
  262. singleDate: {
  263. jsDate: parse(
  264. this.instrument_work.fecha_vencimiento_venta,
  265. "dd/MM/yyyy",
  266. new Date()
  267. ),
  268. formatted: this.instrument_work.fecha_vencimiento_venta
  269. }
  270. }
  271. ]
  272. });
  273. if (this.instrument_work != undefined) {
  274. this.instrument_work_summary = this.instrument_work;
  275. this.operation_result = true;
  276. console.log("datos");
  277. console.log(this.instrument_work_summary);
  278. this.operacion = +this.instrument_work_summary.corto;
  279. if (this.instrument_work_summary.completo == undefined) {
  280. if (
  281. this.instrument_work_summary.valor_pagado > 0 &&
  282. this.instrument_work_summary.valor_recibido > 0
  283. ) {
  284. this.ejecucion = 1;
  285. }
  286. } else {
  287. this.ejecucion = +this.instrument_work_summary.completo;
  288. }
  289. this.toggle_operacion(this.operacion);
  290. this.toggle_ejecucion(this.ejecucion);
  291. }
  292. }
  293. toggle_operacion(input: any) {
  294. this.tipoOperacion = +input;
  295. this.setValidators();
  296. }
  297. toggle_ejecucion(input: any) {
  298. this.tipoEjecucion = +input;
  299. this.setValidators();
  300. }
  301. setValidators() {
  302. console.log("tipo de operacion");
  303. console.log(this.tipoOperacion);
  304. console.log("tipo de ejecucion");
  305. console.log(this.tipoEjecucion);
  306. const ticker = this.investmentProposalForm.get("ticker");
  307. const precio_unitario_compra = this.investmentProposalForm.get(
  308. "precio_unitario_compra"
  309. );
  310. const comision_broker_compra = this.investmentProposalForm.get(
  311. "comision_broker_compra"
  312. );
  313. const cantidad_contratos_compra = this.investmentProposalForm.get(
  314. "cantidad_contratos_compra"
  315. );
  316. const unidades_contratos_compra = this.investmentProposalForm.get(
  317. "unidades_contratos_compra"
  318. );
  319. const fecha_operacion_compra = this.investmentProposalForm.get(
  320. "fecha_operacion_compra"
  321. );
  322. const fecha_liquidacion_compra = this.investmentProposalForm.get(
  323. "fecha_liquidacion_compra"
  324. );
  325. const fecha_vencimiento_compra = this.investmentProposalForm.get(
  326. "fecha_vencimiento_compra"
  327. );
  328. const precio_unitario_venta = this.investmentProposalForm.get(
  329. "precio_unitario_venta"
  330. );
  331. const comision_broker_venta = this.investmentProposalForm.get(
  332. "comision_broker_venta"
  333. );
  334. const cantidad_contratos_venta = this.investmentProposalForm.get(
  335. "cantidad_contratos_venta"
  336. );
  337. const unidades_contratos_venta = this.investmentProposalForm.get(
  338. "unidades_contratos_venta"
  339. );
  340. const fecha_operacion_venta = this.investmentProposalForm.get(
  341. "fecha_operacion_venta"
  342. );
  343. const fecha_liquidacion_venta = this.investmentProposalForm.get(
  344. "fecha_liquidacion_venta"
  345. );
  346. const fecha_vencimiento_venta = this.investmentProposalForm.get(
  347. "fecha_vencimiento_venta"
  348. );
  349. ticker.setValidators([Validators.required]);
  350. if (this.tipoEjecucion == 1) {
  351. precio_unitario_compra.setValidators([
  352. Validators.required,
  353. Validators.pattern(/^[+]?([0-9]+(?:[\.][0-9]*)?|\.[0-9]+)$/)
  354. ]);
  355. comision_broker_compra.setValidators([
  356. Validators.required,
  357. Validators.pattern(/^[+]?([0-9]+(?:[\.][0-9]*)?|\.[0-9]+)$/)
  358. ]);
  359. cantidad_contratos_compra.setValidators([
  360. Validators.required,
  361. Validators.pattern(/^[+]?([0-9]+(?:[\.][0-9]*)?|\.[0-9]+)$/)
  362. ]);
  363. unidades_contratos_compra.setValidators([
  364. Validators.required,
  365. Validators.pattern(/^[+]?([0-9]+(?:[\.][0-9]*)?|\.[0-9]+)$/)
  366. ]);
  367. fecha_operacion_compra.setValidators([Validators.required]);
  368. fecha_liquidacion_compra.setValidators([Validators.required]);
  369. if (this.tipoOperacion == 0) {
  370. fecha_vencimiento_compra.setValidators([Validators.required]);
  371. fecha_vencimiento_venta.setValidators(null);
  372. }
  373. precio_unitario_venta.setValidators([
  374. Validators.required,
  375. Validators.pattern(/^[+]?([0-9]+(?:[\.][0-9]*)?|\.[0-9]+)$/)
  376. ]);
  377. comision_broker_venta.setValidators([
  378. Validators.required,
  379. Validators.pattern(/^[+]?([0-9]+(?:[\.][0-9]*)?|\.[0-9]+)$/)
  380. ]);
  381. cantidad_contratos_venta.setValidators([
  382. Validators.required,
  383. Validators.pattern(/^[+]?([0-9]+(?:[\.][0-9]*)?|\.[0-9]+)$/)
  384. ]);
  385. unidades_contratos_venta.setValidators([
  386. Validators.required,
  387. Validators.pattern(/^[+]?([0-9]+(?:[\.][0-9]*)?|\.[0-9]+)$/)
  388. ]);
  389. fecha_operacion_venta.setValidators([Validators.required]);
  390. fecha_liquidacion_venta.setValidators([Validators.required]);
  391. if (this.tipoOperacion == 1) {
  392. fecha_vencimiento_venta.setValidators([Validators.required]);
  393. fecha_vencimiento_compra.setValidators(null);
  394. }
  395. } else {
  396. if (this.tipoOperacion == 1) {
  397. precio_unitario_venta.setValidators([
  398. Validators.required,
  399. Validators.pattern(/^[+]?([0-9]+(?:[\.][0-9]*)?|\.[0-9]+)$/)
  400. ]);
  401. comision_broker_venta.setValidators([
  402. Validators.required,
  403. Validators.pattern(/^[+]?([0-9]+(?:[\.][0-9]*)?|\.[0-9]+)$/)
  404. ]);
  405. cantidad_contratos_venta.setValidators([
  406. Validators.required,
  407. Validators.pattern(/^[+]?([0-9]+(?:[\.][0-9]*)?|\.[0-9]+)$/)
  408. ]);
  409. unidades_contratos_venta.setValidators([
  410. Validators.required,
  411. Validators.pattern(/^[+]?([0-9]+(?:[\.][0-9]*)?|\.[0-9]+)$/)
  412. ]);
  413. fecha_operacion_venta.setValidators([Validators.required]);
  414. fecha_liquidacion_venta.setValidators([Validators.required]);
  415. fecha_vencimiento_venta.setValidators(null); //.setValidators([Validators.required]);
  416. precio_unitario_compra.setValidators(null);
  417. comision_broker_compra.setValidators(null);
  418. cantidad_contratos_compra.setValidators(null);
  419. unidades_contratos_compra.setValidators(null);
  420. fecha_operacion_compra.setValidators(null);
  421. fecha_liquidacion_compra.setValidators(null);
  422. fecha_vencimiento_compra.setValidators(null);
  423. }
  424. if (this.tipoOperacion == 0) {
  425. precio_unitario_compra.setValidators([
  426. Validators.required,
  427. Validators.pattern(/^[+]?([0-9]+(?:[\.][0-9]*)?|\.[0-9]+)$/)
  428. ]);
  429. comision_broker_compra.setValidators([
  430. Validators.required,
  431. Validators.pattern(/^[+]?([0-9]+(?:[\.][0-9]*)?|\.[0-9]+)$/)
  432. ]);
  433. cantidad_contratos_compra.setValidators([
  434. Validators.required,
  435. Validators.pattern(/^[+]?([0-9]+(?:[\.][0-9]*)?|\.[0-9]+)$/)
  436. ]);
  437. unidades_contratos_compra.setValidators([
  438. Validators.required,
  439. Validators.pattern(/^[+]?([0-9]+(?:[\.][0-9]*)?|\.[0-9]+)$/)
  440. ]);
  441. fecha_operacion_compra.setValidators([Validators.required]);
  442. fecha_liquidacion_compra.setValidators([Validators.required]);
  443. fecha_vencimiento_compra.setValidators(null); //.setValidators([Validators.required]);
  444. precio_unitario_venta.setValidators(null);
  445. comision_broker_venta.setValidators(null);
  446. cantidad_contratos_venta.setValidators(null);
  447. unidades_contratos_venta.setValidators(null);
  448. fecha_operacion_venta.setValidators(null);
  449. fecha_liquidacion_venta.setValidators(null);
  450. fecha_vencimiento_venta.setValidators(null);
  451. }
  452. }
  453. precio_unitario_compra.updateValueAndValidity();
  454. comision_broker_compra.updateValueAndValidity();
  455. cantidad_contratos_compra.updateValueAndValidity();
  456. unidades_contratos_compra.updateValueAndValidity();
  457. fecha_operacion_compra.updateValueAndValidity();
  458. fecha_liquidacion_compra.updateValueAndValidity();
  459. fecha_vencimiento_compra.updateValueAndValidity();
  460. precio_unitario_venta.updateValueAndValidity();
  461. comision_broker_venta.updateValueAndValidity();
  462. cantidad_contratos_venta.updateValueAndValidity();
  463. unidades_contratos_venta.updateValueAndValidity();
  464. fecha_operacion_venta.updateValueAndValidity();
  465. fecha_liquidacion_venta.updateValueAndValidity();
  466. fecha_vencimiento_venta.updateValueAndValidity();
  467. }
  468. save(form: any): boolean {
  469. if (!form.valid) {
  470. return false;
  471. }
  472. this.formDataService.setWork(this.futurosObject);
  473. return true;
  474. }
  475. get f() {
  476. return this.investmentProposalForm.controls;
  477. }
  478. getCalculations(form: any, saveForm: boolean) {
  479. this.submitted = true;
  480. console.log(this.investmentProposalForm);
  481. if (!form.valid) {
  482. return false;
  483. }
  484. Swal.fire({
  485. allowOutsideClick: false,
  486. icon: "info",
  487. text: "Espere por favor..."
  488. });
  489. Swal.showLoading();
  490. this.instrumentCalcService
  491. .opcionesFuturosCalc(
  492. "OPC", // Codigo del instrumento
  493. {
  494. id_tipo_base: +this.general.base_anual,
  495. id_formato_ingreso: +this.general.formato_ingreso,
  496. id_periodicidad: +this.general.periodicidad
  497. },
  498. {
  499. completo: this.tipoEjecucion,
  500. corto: this.tipoOperacion,
  501. precio_unitario_compra: this.f.precio_unitario_compra.value,
  502. comision_broker_compra: this.f.comision_broker_compra.value,
  503. cantidad_contratos_compra: this.f.cantidad_contratos_compra.value,
  504. unidades_contratos_compra: this.f.unidades_contratos_compra.value,
  505. fecha_operacion_compra:
  506. this.f.fecha_operacion_compra.value == ""
  507. ? ""
  508. : this.f.fecha_operacion_compra.value.singleDate.formatted,
  509. fecha_liquidacion_compra:
  510. this.f.fecha_liquidacion_compra.value == ""
  511. ? ""
  512. : this.f.fecha_liquidacion_compra.value.singleDate.formatted,
  513. fecha_vencimiento_compra:
  514. this.f.fecha_vencimiento_compra.value == ""
  515. ? ""
  516. : this.f.fecha_vencimiento_compra.value.singleDate.formatted,
  517. precio_unitario_venta: this.f.precio_unitario_venta.value,
  518. comision_broker_venta: this.f.comision_broker_venta.value,
  519. cantidad_contratos_venta: this.f.cantidad_contratos_venta.value,
  520. unidades_contratos_venta: this.f.unidades_contratos_venta.value,
  521. fecha_operacion_venta:
  522. this.f.fecha_operacion_venta.value == ""
  523. ? ""
  524. : this.f.fecha_operacion_venta.value.singleDate.formatted,
  525. fecha_liquidacion_venta:
  526. this.f.fecha_liquidacion_venta.value == ""
  527. ? ""
  528. : this.f.fecha_liquidacion_venta.value.singleDate.formatted,
  529. fecha_vencimiento_venta:
  530. this.f.fecha_vencimiento_venta.value == ""
  531. ? ""
  532. : this.f.fecha_vencimiento_venta.value.singleDate.formatted
  533. }
  534. )
  535. .subscribe(
  536. ans => {
  537. // Instrumento compra
  538. if (this.tipoOperacion == 0 || this.tipoEjecucion == 1) {
  539. this.fecha_operacion_compra =
  540. ans["result"]["instrumento_compra"]["fecha_operacion_compra"];
  541. this.fecha_liquidacion_compra =
  542. ans["result"]["instrumento_compra"]["fecha_liquidacion_compra"];
  543. this.precio_unitario_compra =
  544. ans["result"]["instrumento_compra"]["precio_unitario_compra"];
  545. this.comision_broker_compra =
  546. ans["result"]["instrumento_compra"]["comision_broker_compra"];
  547. this.cantidad_contratos_compra =
  548. ans["result"]["instrumento_compra"]["cantidad_contratos_compra"];
  549. this.unidades_contratos_compra =
  550. ans["result"]["instrumento_compra"]["unidades_contratos_compra"];
  551. this.valor_transado_compra =
  552. ans["result"]["instrumento_compra"]["valor_transado_compra"];
  553. this.valor_pagado =
  554. ans["result"]["instrumento_compra"]["valor_pagado"];
  555. this.ganancia_perdida =
  556. ans["result"]["instrumento_compra"]["ganancia_perdida"];
  557. this.rendimiento =
  558. ans["result"]["instrumento_compra"]["rendimiento"];
  559. }
  560. // Si es operacion largo y ejecucion completa
  561. if (this.tipoOperacion == 0) {
  562. this.corto = ans["result"]["instrumento_compra"]["corto"];
  563. this.fecha_inicio_vigencia =
  564. ans["result"]["instrumento_compra"]["fecha_inicio_vigencia"];
  565. this.fecha_vencimiento_compra =
  566. ans["result"]["instrumento_compra"]["fecha_vencimiento_compra"];
  567. }
  568. // Instrumento venta
  569. if (this.tipoOperacion == 1 || this.tipoEjecucion == 1) {
  570. this.fecha_operacion_venta =
  571. ans["result"]["instrumento_venta"]["fecha_operacion_venta"];
  572. this.fecha_liquidacion_venta =
  573. ans["result"]["instrumento_venta"]["fecha_liquidacion_venta"];
  574. this.precio_unitario_venta =
  575. ans["result"]["instrumento_venta"]["precio_unitario_venta"];
  576. this.comision_broker_venta =
  577. ans["result"]["instrumento_venta"]["comision_broker_venta"];
  578. this.cantidad_contratos_venta =
  579. ans["result"]["instrumento_venta"]["cantidad_contratos_venta"];
  580. this.unidades_contratos_venta =
  581. ans["result"]["instrumento_venta"]["unidades_contratos_venta"];
  582. this.valor_transado_venta =
  583. ans["result"]["instrumento_venta"]["valor_transado_venta"];
  584. this.valor_recibido =
  585. ans["result"]["instrumento_venta"]["valor_recibido "];
  586. }
  587. // Si es operacion corto
  588. if (this.tipoOperacion == 1) {
  589. this.corto = ans["result"]["instrumento_venta"]["corto"];
  590. this.fecha_inicio_vigencia =
  591. ans["result"]["instrumento_venta"]["fecha_inicio_vigencia"];
  592. this.fecha_vencimiento_venta =
  593. ans["result"]["instrumento_venta"]["fecha_vencimiento_venta"];
  594. }
  595. this.operation_result = true;
  596. this.futurosObject = {
  597. completo: this.tipoEjecucion,
  598. corto: this.tipoOperacion,
  599. ticker: this.investmentProposalForm.value.ticker,
  600. fecha_inicio_vigencia: this.fecha_inicio_vigencia
  601. };
  602. if (this.tipoOperacion == 0 || this.tipoEjecucion == 1) {
  603. (this.futurosObject[
  604. "precio_unitario_compra"
  605. ] = this.investmentProposalForm.value.precio_unitario_compra),
  606. (this.futurosObject[
  607. "comision_broker_compra"
  608. ] = this.investmentProposalForm.value.comision_broker_compra),
  609. (this.futurosObject[
  610. "cantidad_contratos_compra"
  611. ] = this.investmentProposalForm.value.cantidad_contratos_compra),
  612. (this.futurosObject[
  613. "unidades_contratos_compra"
  614. ] = this.investmentProposalForm.value.unidades_contratos_compra),
  615. (this.futurosObject["fecha_operacion_compra"] =
  616. this.investmentProposalForm.value.fecha_operacion_compra == ""
  617. ? ""
  618. : this.investmentProposalForm.value.fecha_operacion_compra
  619. .singleDate.formatted),
  620. (this.futurosObject["fecha_liquidacion_compra"] =
  621. this.investmentProposalForm.value.fecha_liquidacion_compra == ""
  622. ? ""
  623. : this.investmentProposalForm.value.fecha_liquidacion_compra
  624. .singleDate.formatted),
  625. (this.futurosObject[
  626. "valor_transado_compra"
  627. ] = this.valor_transado_compra),
  628. (this.futurosObject["valor_pagado"] = this.valor_pagado),
  629. (this.futurosObject["ganancia_perdida"] = this.ganancia_perdida),
  630. (this.futurosObject["rendimiento"] = this.rendimiento);
  631. }
  632. if (this.tipoOperacion == 1 || this.tipoEjecucion == 1) {
  633. (this.futurosObject[
  634. "precio_unitario_venta"
  635. ] = this.investmentProposalForm.value.precio_unitario_venta),
  636. (this.futurosObject[
  637. "comision_broker_venta"
  638. ] = this.investmentProposalForm.value.comision_broker_venta),
  639. (this.futurosObject[
  640. "cantidad_contratos_venta"
  641. ] = this.investmentProposalForm.value.cantidad_contratos_venta),
  642. (this.futurosObject[
  643. "unidades_contratos_venta"
  644. ] = this.investmentProposalForm.value.unidades_contratos_venta),
  645. (this.futurosObject["fecha_operacion_venta"] =
  646. this.investmentProposalForm.value.fecha_operacion_venta == ""
  647. ? ""
  648. : this.investmentProposalForm.value.fecha_operacion_venta
  649. .singleDate.formatted),
  650. (this.futurosObject["fecha_liquidacion_venta"] =
  651. this.investmentProposalForm.value.fecha_liquidacion_venta == ""
  652. ? ""
  653. : this.investmentProposalForm.value.fecha_liquidacion_venta
  654. .singleDate.formatted),
  655. (this.futurosObject[
  656. "valor_transado_venta"
  657. ] = this.valor_transado_venta),
  658. (this.futurosObject["valor_recibido"] = this.valor_recibido);
  659. }
  660. if (this.tipoOperacion == 0) {
  661. this.futurosObject[
  662. "fecha_vencimiento_compra"
  663. ] = this.fecha_vencimiento_compra;
  664. }
  665. if (this.tipoOperacion == 1) {
  666. this.futurosObject[
  667. "fecha_vencimiento_venta"
  668. ] = this.fecha_vencimiento_venta;
  669. }
  670. if (this.tipoEjecucion == 1) {
  671. this.futurosObject["fecha_cancelado"] = this.datepipe.transform(
  672. new Date(),
  673. "dd/MM/yyyy"
  674. ); //.toISOString().slice(0, 10);
  675. }
  676. this.formDataService.setWork(this.futurosObject);
  677. Swal.close();
  678. if (saveForm == true) {
  679. if (this.investmentID != undefined) {
  680. this.router.navigate(["/investment-proposal/complement-info"], {
  681. queryParams: { id: this.investmentID }
  682. });
  683. } else {
  684. this.router.navigate(["/investment-proposal/complement-info"]);
  685. }
  686. }
  687. },
  688. err => {
  689. Swal.fire({
  690. icon: "error",
  691. title: "Error en el servidor",
  692. text: "No su pudo obtener la informacion"
  693. });
  694. return false;
  695. }
  696. );
  697. }
  698. goToPrevious() {
  699. this.submitted = true;
  700. if (this.investmentID != undefined) {
  701. this.router.navigate(["/investment-proposal/general-info"], {
  702. queryParams: { id: this.investmentID }
  703. });
  704. } else {
  705. this.router.navigate(["/investment-proposal/general-info"]);
  706. }
  707. }
  708. goToNext(form: any) {
  709. this.getCalculations(form, true);
  710. }
  711. }