opciones.component.ts 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751
  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-opciones",
  18. templateUrl: "./opciones.component.html"
  19. })
  20. export class OPC implements InstrumentComponent {
  21. title: string = "Opciones";
  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. opcionesObject: {};
  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 precio_unitario_compra = this.investmentProposalForm.get(
  307. "precio_unitario_compra"
  308. );
  309. const comision_broker_compra = this.investmentProposalForm.get(
  310. "comision_broker_compra"
  311. );
  312. const cantidad_contratos_compra = this.investmentProposalForm.get(
  313. "cantidad_contratos_compra"
  314. );
  315. const unidades_contratos_compra = this.investmentProposalForm.get(
  316. "unidades_contratos_compra"
  317. );
  318. const fecha_operacion_compra = this.investmentProposalForm.get(
  319. "fecha_operacion_compra"
  320. );
  321. const fecha_liquidacion_compra = this.investmentProposalForm.get(
  322. "fecha_liquidacion_compra"
  323. );
  324. const fecha_vencimiento_compra = this.investmentProposalForm.get(
  325. "fecha_vencimiento_compra"
  326. );
  327. const precio_unitario_venta = this.investmentProposalForm.get(
  328. "precio_unitario_venta"
  329. );
  330. const comision_broker_venta = this.investmentProposalForm.get(
  331. "comision_broker_venta"
  332. );
  333. const cantidad_contratos_venta = this.investmentProposalForm.get(
  334. "cantidad_contratos_venta"
  335. );
  336. const unidades_contratos_venta = this.investmentProposalForm.get(
  337. "unidades_contratos_venta"
  338. );
  339. const fecha_operacion_venta = this.investmentProposalForm.get(
  340. "fecha_operacion_venta"
  341. );
  342. const fecha_liquidacion_venta = this.investmentProposalForm.get(
  343. "fecha_liquidacion_venta"
  344. );
  345. const fecha_vencimiento_venta = this.investmentProposalForm.get(
  346. "fecha_vencimiento_venta"
  347. );
  348. if (this.tipoEjecucion == 1) {
  349. precio_unitario_compra.setValidators([
  350. Validators.required,
  351. Validators.pattern(/^[+]?([0-9]+(?:[\.][0-9]*)?|\.[0-9]+)$/)
  352. ]);
  353. comision_broker_compra.setValidators([
  354. Validators.required,
  355. Validators.pattern(/^[+]?([0-9]+(?:[\.][0-9]*)?|\.[0-9]+)$/)
  356. ]);
  357. cantidad_contratos_compra.setValidators([
  358. Validators.required,
  359. Validators.pattern(/^[+]?([0-9]+(?:[\.][0-9]*)?|\.[0-9]+)$/)
  360. ]);
  361. unidades_contratos_compra.setValidators([
  362. Validators.required,
  363. Validators.pattern(/^[+]?([0-9]+(?:[\.][0-9]*)?|\.[0-9]+)$/)
  364. ]);
  365. fecha_operacion_compra.setValidators([Validators.required]);
  366. fecha_liquidacion_compra.setValidators([Validators.required]);
  367. if (this.tipoOperacion == 0) {
  368. fecha_vencimiento_compra.setValidators([Validators.required]);
  369. fecha_vencimiento_venta.setValidators(null);
  370. }
  371. precio_unitario_venta.setValidators([
  372. Validators.required,
  373. Validators.pattern(/^[+]?([0-9]+(?:[\.][0-9]*)?|\.[0-9]+)$/)
  374. ]);
  375. comision_broker_venta.setValidators([
  376. Validators.required,
  377. Validators.pattern(/^[+]?([0-9]+(?:[\.][0-9]*)?|\.[0-9]+)$/)
  378. ]);
  379. cantidad_contratos_venta.setValidators([
  380. Validators.required,
  381. Validators.pattern(/^[+]?([0-9]+(?:[\.][0-9]*)?|\.[0-9]+)$/)
  382. ]);
  383. unidades_contratos_venta.setValidators([
  384. Validators.required,
  385. Validators.pattern(/^[+]?([0-9]+(?:[\.][0-9]*)?|\.[0-9]+)$/)
  386. ]);
  387. fecha_operacion_venta.setValidators([Validators.required]);
  388. fecha_liquidacion_venta.setValidators([Validators.required]);
  389. if (this.tipoOperacion == 1) {
  390. fecha_vencimiento_venta.setValidators([Validators.required]);
  391. fecha_vencimiento_compra.setValidators(null);
  392. }
  393. } else {
  394. if (this.tipoOperacion == 1) {
  395. precio_unitario_venta.setValidators([
  396. Validators.required,
  397. Validators.pattern(/^[+]?([0-9]+(?:[\.][0-9]*)?|\.[0-9]+)$/)
  398. ]);
  399. comision_broker_venta.setValidators([
  400. Validators.required,
  401. Validators.pattern(/^[+]?([0-9]+(?:[\.][0-9]*)?|\.[0-9]+)$/)
  402. ]);
  403. cantidad_contratos_venta.setValidators([
  404. Validators.required,
  405. Validators.pattern(/^[+]?([0-9]+(?:[\.][0-9]*)?|\.[0-9]+)$/)
  406. ]);
  407. unidades_contratos_venta.setValidators([
  408. Validators.required,
  409. Validators.pattern(/^[+]?([0-9]+(?:[\.][0-9]*)?|\.[0-9]+)$/)
  410. ]);
  411. fecha_operacion_venta.setValidators([Validators.required]);
  412. fecha_liquidacion_venta.setValidators([Validators.required]);
  413. fecha_vencimiento_venta.setValidators(null); //.setValidators([Validators.required]);
  414. precio_unitario_compra.setValidators(null);
  415. comision_broker_compra.setValidators(null);
  416. cantidad_contratos_compra.setValidators(null);
  417. unidades_contratos_compra.setValidators(null);
  418. fecha_operacion_compra.setValidators(null);
  419. fecha_liquidacion_compra.setValidators(null);
  420. fecha_vencimiento_compra.setValidators(null);
  421. }
  422. if (this.tipoOperacion == 0) {
  423. precio_unitario_compra.setValidators([
  424. Validators.required,
  425. Validators.pattern(/^[+]?([0-9]+(?:[\.][0-9]*)?|\.[0-9]+)$/)
  426. ]);
  427. comision_broker_compra.setValidators([
  428. Validators.required,
  429. Validators.pattern(/^[+]?([0-9]+(?:[\.][0-9]*)?|\.[0-9]+)$/)
  430. ]);
  431. cantidad_contratos_compra.setValidators([
  432. Validators.required,
  433. Validators.pattern(/^[+]?([0-9]+(?:[\.][0-9]*)?|\.[0-9]+)$/)
  434. ]);
  435. unidades_contratos_compra.setValidators([
  436. Validators.required,
  437. Validators.pattern(/^[+]?([0-9]+(?:[\.][0-9]*)?|\.[0-9]+)$/)
  438. ]);
  439. fecha_operacion_compra.setValidators([Validators.required]);
  440. fecha_liquidacion_compra.setValidators([Validators.required]);
  441. fecha_vencimiento_compra.setValidators(null); //.setValidators([Validators.required]);
  442. precio_unitario_venta.setValidators(null);
  443. comision_broker_venta.setValidators(null);
  444. cantidad_contratos_venta.setValidators(null);
  445. unidades_contratos_venta.setValidators(null);
  446. fecha_operacion_venta.setValidators(null);
  447. fecha_liquidacion_venta.setValidators(null);
  448. fecha_vencimiento_venta.setValidators(null);
  449. }
  450. }
  451. precio_unitario_compra.updateValueAndValidity();
  452. comision_broker_compra.updateValueAndValidity();
  453. cantidad_contratos_compra.updateValueAndValidity();
  454. unidades_contratos_compra.updateValueAndValidity();
  455. fecha_operacion_compra.updateValueAndValidity();
  456. fecha_liquidacion_compra.updateValueAndValidity();
  457. fecha_vencimiento_compra.updateValueAndValidity();
  458. precio_unitario_venta.updateValueAndValidity();
  459. comision_broker_venta.updateValueAndValidity();
  460. cantidad_contratos_venta.updateValueAndValidity();
  461. unidades_contratos_venta.updateValueAndValidity();
  462. fecha_operacion_venta.updateValueAndValidity();
  463. fecha_liquidacion_venta.updateValueAndValidity();
  464. fecha_vencimiento_venta.updateValueAndValidity();
  465. }
  466. save(form: any): boolean {
  467. if (!form.valid) {
  468. return false;
  469. }
  470. this.formDataService.setWork(this.opcionesObject);
  471. return true;
  472. }
  473. get f() {
  474. return this.investmentProposalForm.controls;
  475. }
  476. getCalculations(form: any, saveForm: boolean) {
  477. this.submitted = true;
  478. console.log(this.investmentProposalForm);
  479. if (!form.valid) {
  480. return false;
  481. }
  482. Swal.fire({
  483. allowOutsideClick: false,
  484. icon: "info",
  485. text: "Espere por favor..."
  486. });
  487. Swal.showLoading();
  488. this.instrumentCalcService
  489. .opcionesFuturosCalc(
  490. "OPC", // Codigo del instrumento
  491. {
  492. id_tipo_base: +this.general.base_anual,
  493. id_formato_ingreso: +this.general.formato_ingreso,
  494. id_periodicidad: +this.general.periodicidad
  495. },
  496. {
  497. completo: this.tipoEjecucion,
  498. corto: this.tipoOperacion,
  499. precio_unitario_compra: this.f.precio_unitario_compra.value,
  500. comision_broker_compra: this.f.comision_broker_compra.value,
  501. cantidad_contratos_compra: this.f.cantidad_contratos_compra.value,
  502. unidades_contratos_compra: this.f.unidades_contratos_compra.value,
  503. fecha_operacion_compra:
  504. this.f.fecha_operacion_compra.value == ""
  505. ? ""
  506. : this.f.fecha_operacion_compra.value.singleDate.formatted,
  507. fecha_liquidacion_compra:
  508. this.f.fecha_liquidacion_compra.value == ""
  509. ? ""
  510. : this.f.fecha_liquidacion_compra.value.singleDate.formatted,
  511. fecha_vencimiento_compra:
  512. this.f.fecha_vencimiento_compra.value == ""
  513. ? ""
  514. : this.f.fecha_vencimiento_compra.value.singleDate.formatted,
  515. precio_unitario_venta: this.f.precio_unitario_venta.value,
  516. comision_broker_venta: this.f.comision_broker_venta.value,
  517. cantidad_contratos_venta: this.f.cantidad_contratos_venta.value,
  518. unidades_contratos_venta: this.f.unidades_contratos_venta.value,
  519. fecha_operacion_venta:
  520. this.f.fecha_operacion_venta.value == ""
  521. ? ""
  522. : this.f.fecha_operacion_venta.value.singleDate.formatted,
  523. fecha_liquidacion_venta:
  524. this.f.fecha_liquidacion_venta.value == ""
  525. ? ""
  526. : this.f.fecha_liquidacion_venta.value.singleDate.formatted,
  527. fecha_vencimiento_venta:
  528. this.f.fecha_vencimiento_venta.value == ""
  529. ? ""
  530. : this.f.fecha_vencimiento_venta.value.singleDate.formatted
  531. }
  532. )
  533. .subscribe(
  534. ans => {
  535. // Instrumento compra
  536. if (this.tipoOperacion == 0 || this.tipoEjecucion == 1) {
  537. this.fecha_operacion_compra =
  538. ans["result"]["instrumento_compra"]["fecha_operacion_compra"];
  539. this.fecha_liquidacion_compra =
  540. ans["result"]["instrumento_compra"]["fecha_liquidacion_compra"];
  541. this.precio_unitario_compra =
  542. ans["result"]["instrumento_compra"]["precio_unitario_compra"];
  543. this.comision_broker_compra =
  544. ans["result"]["instrumento_compra"]["comision_broker_compra"];
  545. this.cantidad_contratos_compra =
  546. ans["result"]["instrumento_compra"]["cantidad_contratos_compra"];
  547. this.unidades_contratos_compra =
  548. ans["result"]["instrumento_compra"]["unidades_contratos_compra"];
  549. this.valor_transado_compra =
  550. ans["result"]["instrumento_compra"]["valor_transado_compra"];
  551. this.valor_pagado =
  552. ans["result"]["instrumento_compra"]["valor_pagado"];
  553. this.ganancia_perdida =
  554. ans["result"]["instrumento_compra"]["ganancia_perdida"];
  555. this.rendimiento =
  556. ans["result"]["instrumento_compra"]["rendimiento"];
  557. }
  558. // Si es operacion largo y ejecucion completa
  559. if (this.tipoOperacion == 0) {
  560. this.corto = ans["result"]["instrumento_compra"]["corto"];
  561. this.fecha_inicio_vigencia =
  562. ans["result"]["instrumento_compra"]["fecha_inicio_vigencia"];
  563. this.fecha_vencimiento_compra =
  564. ans["result"]["instrumento_compra"]["fecha_vencimiento_compra"];
  565. }
  566. // Instrumento venta
  567. if (this.tipoOperacion == 1 || this.tipoEjecucion == 1) {
  568. this.fecha_operacion_venta =
  569. ans["result"]["instrumento_venta"]["fecha_operacion_venta"];
  570. this.fecha_liquidacion_venta =
  571. ans["result"]["instrumento_venta"]["fecha_liquidacion_venta"];
  572. this.precio_unitario_venta =
  573. ans["result"]["instrumento_venta"]["precio_unitario_venta"];
  574. this.comision_broker_venta =
  575. ans["result"]["instrumento_venta"]["comision_broker_venta"];
  576. this.cantidad_contratos_venta =
  577. ans["result"]["instrumento_venta"]["cantidad_contratos_venta"];
  578. this.unidades_contratos_venta =
  579. ans["result"]["instrumento_venta"]["unidades_contratos_venta"];
  580. this.valor_transado_venta =
  581. ans["result"]["instrumento_venta"]["valor_transado_venta"];
  582. this.valor_recibido =
  583. ans["result"]["instrumento_venta"]["valor_recibido "];
  584. }
  585. // Si es operacion corto
  586. if (this.tipoOperacion == 1) {
  587. this.corto = ans["result"]["instrumento_venta"]["corto"];
  588. this.fecha_inicio_vigencia =
  589. ans["result"]["instrumento_venta"]["fecha_inicio_vigencia"];
  590. this.fecha_vencimiento_venta =
  591. ans["result"]["instrumento_venta"]["fecha_vencimiento_venta"];
  592. }
  593. this.operation_result = true;
  594. this.opcionesObject = {
  595. completo: this.tipoEjecucion,
  596. corto: this.tipoOperacion,
  597. ticker: this.investmentProposalForm.value.ticker,
  598. fecha_inicio_vigencia: this.fecha_inicio_vigencia
  599. };
  600. if (this.tipoOperacion == 0 || this.tipoEjecucion == 1) {
  601. (this.opcionesObject[
  602. "precio_unitario_compra"
  603. ] = this.investmentProposalForm.value.precio_unitario_compra),
  604. (this.opcionesObject[
  605. "comision_broker_compra"
  606. ] = this.investmentProposalForm.value.comision_broker_compra),
  607. (this.opcionesObject[
  608. "cantidad_contratos_compra"
  609. ] = this.investmentProposalForm.value.cantidad_contratos_compra),
  610. (this.opcionesObject[
  611. "unidades_contratos_compra"
  612. ] = this.investmentProposalForm.value.unidades_contratos_compra),
  613. (this.opcionesObject["fecha_operacion_compra"] =
  614. this.investmentProposalForm.value.fecha_operacion_compra == ""
  615. ? ""
  616. : this.investmentProposalForm.value.fecha_operacion_compra
  617. .singleDate.formatted),
  618. (this.opcionesObject["fecha_liquidacion_compra"] =
  619. this.investmentProposalForm.value.fecha_liquidacion_compra == ""
  620. ? ""
  621. : this.investmentProposalForm.value.fecha_liquidacion_compra
  622. .singleDate.formatted),
  623. (this.opcionesObject[
  624. "valor_transado_compra"
  625. ] = this.valor_transado_compra),
  626. (this.opcionesObject["valor_pagado"] = this.valor_pagado),
  627. (this.opcionesObject["ganancia_perdida"] = this.ganancia_perdida),
  628. (this.opcionesObject["rendimiento"] = this.rendimiento);
  629. }
  630. if (this.tipoOperacion == 1 || this.tipoEjecucion == 1) {
  631. (this.opcionesObject[
  632. "precio_unitario_venta"
  633. ] = this.investmentProposalForm.value.precio_unitario_venta),
  634. (this.opcionesObject[
  635. "comision_broker_venta"
  636. ] = this.investmentProposalForm.value.comision_broker_venta),
  637. (this.opcionesObject[
  638. "cantidad_contratos_venta"
  639. ] = this.investmentProposalForm.value.cantidad_contratos_venta),
  640. (this.opcionesObject[
  641. "unidades_contratos_venta"
  642. ] = this.investmentProposalForm.value.unidades_contratos_venta),
  643. (this.opcionesObject["fecha_operacion_venta"] =
  644. this.investmentProposalForm.value.fecha_operacion_venta == ""
  645. ? ""
  646. : this.investmentProposalForm.value.fecha_operacion_venta
  647. .singleDate.formatted),
  648. (this.opcionesObject["fecha_liquidacion_venta"] =
  649. this.investmentProposalForm.value.fecha_liquidacion_venta == ""
  650. ? ""
  651. : this.investmentProposalForm.value.fecha_liquidacion_venta
  652. .singleDate.formatted),
  653. (this.opcionesObject[
  654. "valor_transado_venta"
  655. ] = this.valor_transado_venta),
  656. (this.opcionesObject["valor_recibido"] = this.valor_recibido);
  657. }
  658. if (this.tipoOperacion == 0) {
  659. this.opcionesObject[
  660. "fecha_vencimiento_compra"
  661. ] = this.fecha_vencimiento_compra;
  662. }
  663. if (this.tipoOperacion == 1) {
  664. this.opcionesObject[
  665. "fecha_vencimiento_venta"
  666. ] = this.fecha_vencimiento_venta;
  667. }
  668. if (this.tipoEjecucion == 1) {
  669. this.opcionesObject["fecha_cancelado"] = this.datepipe.transform(
  670. new Date(),
  671. "dd/MM/yyyy"
  672. ); //.toISOString().slice(0, 10);
  673. }
  674. this.formDataService.setWork(this.opcionesObject);
  675. Swal.close();
  676. if (saveForm == true) {
  677. if (this.investmentID != undefined) {
  678. this.router.navigate(["/investment-proposal/complement-info"], {
  679. queryParams: { id: this.investmentID }
  680. });
  681. } else {
  682. this.router.navigate(["/investment-proposal/complement-info"]);
  683. }
  684. }
  685. },
  686. err => {
  687. Swal.fire({
  688. icon: "error",
  689. title: "Error en el servidor",
  690. text: "No su pudo obtener la informacion"
  691. });
  692. return false;
  693. }
  694. );
  695. }
  696. goToPrevious() {
  697. this.submitted = true;
  698. if (this.investmentID != undefined) {
  699. this.router.navigate(["/investment-proposal/general-info"], {
  700. queryParams: { id: this.investmentID }
  701. });
  702. } else {
  703. this.router.navigate(["/investment-proposal/general-info"]);
  704. }
  705. }
  706. goToNext(form: any) {
  707. this.getCalculations(form, true);
  708. }
  709. }