fondos.component.ts 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  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-fondos",
  18. templateUrl: "./fondos.component.html"
  19. })
  20. export class FINV implements InstrumentComponent {
  21. title: string = "Fondos de inversión";
  22. @Input() data: any;
  23. @Input() summary: boolean;
  24. @Input() investmentID: string;
  25. displayedColumns: string[] = [
  26. "posicion",
  27. "plazo",
  28. "fecha_pago",
  29. "ingreso_bruto",
  30. "ingreso_neto",
  31. "dividendo_porcentaje",
  32. "rendimiento_porcentaje",
  33. "rendimiento"
  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_operacion: 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. fondosObject: {};
  82. dataSource = new MatTableDataSource(this.proyecciones);
  83. dataSource2 = new MatTableDataSource(this.proyecciones);
  84. hasProjections: boolean;
  85. fecha_vencimiento: any;
  86. operation_result: boolean = false;
  87. operation_results_work: any = [];
  88. instrument_work_summary: any = [];
  89. cuota_participacion: any;
  90. valor_participacion_porcentaje: any;
  91. dias_liquidacion: any;
  92. dias_vencimiento: any;
  93. valor_nominal: any;
  94. valor_transado: any;
  95. comision_casa_porcentaje: any;
  96. comision_casa: any;
  97. comision_bolsa_porcentaje: any;
  98. comision_bolsa: any;
  99. rendimiento_porcentaje: any;
  100. dividendo_porcentaje: any;
  101. fecha_operacion: any;
  102. fecha_liquidacion: any;
  103. consolidado_proyeccion: any;
  104. monto_pagar: any;
  105. constructor(
  106. private formBuilder: FormBuilder,
  107. private router: Router,
  108. private formDataService: FormInvestmentProposalService,
  109. private catalogService: CatalogsService,
  110. private instrumentCalcService: InstrumentCalculations,
  111. public datepipe: DatePipe
  112. ) {
  113. this.instrument_work = this.formDataService.getWork();
  114. this.instrument_exists = this.instrument_work == undefined;
  115. this.general = this.formDataService.getGeneralInfo();
  116. if (
  117. this.instrument_work != undefined &&
  118. this.instrument_work.proyecciones != ""
  119. ) {
  120. this.hasProjections = true;
  121. this.consolidado_proyeccion = this.instrument_work.proyecciones.pop();
  122. this.operation_results_work = this.instrument_work["resultado_operacion"];
  123. if (this.instrument_work["instrumento"] != undefined) {
  124. this.instrument_work = this.instrument_work["instrumento"];
  125. }
  126. this.instrument_work_summary = this.instrument_work;
  127. this.dataSource2.data = this.instrument_work.proyecciones;
  128. this.dataSource2.paginator = this.paginator;
  129. this.dataSource2.sort = this.sort;
  130. } else {
  131. this.hasProjections = false;
  132. }
  133. if (
  134. this.operation_results_work != undefined &&
  135. this.operation_results_work != ""
  136. ) {
  137. this.operation_result = true;
  138. }
  139. this.investmentProposalForm = this.formBuilder.group({
  140. cuota_participacion: [
  141. this.instrument_exists ? "" : this.instrument_work.cuota_participacion,
  142. [
  143. Validators.required,
  144. Validators.pattern(/^[+]?([0-9]+(?:[\.][0-9]*)?|\.[0-9]+)$/)
  145. ]
  146. ],
  147. valor_participacion_porcentaje: [
  148. this.instrument_exists
  149. ? ""
  150. : this.instrument_work.valor_participacion_porcentaje,
  151. [
  152. Validators.required,
  153. Validators.pattern(/^[+]?([0-9]+(?:[\.][0-9]*)?|\.[0-9]+)$/)
  154. ]
  155. ],
  156. comision_casa_porcentaje: [
  157. this.instrument_exists
  158. ? ""
  159. : this.instrument_work.comision_casa_porcentaje,
  160. [
  161. Validators.required,
  162. Validators.pattern(/^[+]?([0-9]+(?:[\.][0-9]*)?|\.[0-9]+)$/)
  163. ]
  164. ],
  165. comision_bolsa_porcentaje: [
  166. this.instrument_exists
  167. ? ""
  168. : this.instrument_work.comision_bolsa_porcentaje,
  169. [
  170. Validators.required,
  171. Validators.pattern(/^[+]?([0-9]+(?:[\.][0-9]*)?|\.[0-9]+)$/)
  172. ]
  173. ],
  174. dividendo_porcentaje: [
  175. this.instrument_exists ? "" : this.instrument_work.dividendo_porcentaje,
  176. [
  177. Validators.required,
  178. Validators.pattern(/^[+]?([0-9]+(?:[\.][0-9]*)?|\.[0-9]+)$/)
  179. ]
  180. ],
  181. rendimiento_porcentaje: [
  182. this.instrument_exists
  183. ? ""
  184. : this.instrument_work.rendimiento_porcentaje,
  185. [
  186. Validators.required,
  187. Validators.pattern(/^[+]?([0-9]+(?:[\.][0-9]*)?|\.[0-9]+)$/)
  188. ]
  189. ],
  190. dias_liquidacion: [
  191. this.instrument_exists ? "" : this.instrument_work.dias_liquidacion,
  192. [
  193. Validators.required,
  194. Validators.pattern(/^[+]?([0-9]+(?:[\.][0-9]*)?|\.[0-9]+)$/)
  195. ]
  196. ],
  197. dias_vencimiento: [
  198. this.instrument_exists ? "" : this.instrument_work.dias_vencimiento,
  199. [
  200. Validators.required,
  201. Validators.pattern(/^[+]?([0-9]+(?:[\.][0-9]*)?|\.[0-9]+)$/)
  202. ]
  203. ],
  204. fecha_operacion: [
  205. this.instrument_exists
  206. ? ""
  207. : {
  208. isRange: false,
  209. singleDate: {
  210. jsDate: parse(
  211. this.instrument_work.fecha_operacion,
  212. "dd/MM/yyyy",
  213. new Date()
  214. ),
  215. formatted: this.instrument_work.fecha_operacion
  216. }
  217. },
  218. Validators.required
  219. ]
  220. });
  221. }
  222. get f() {
  223. return this.investmentProposalForm.controls;
  224. }
  225. save(form: any): boolean {
  226. if (!form.valid) {
  227. return false;
  228. }
  229. this.formDataService.setWork(this.fondosObject);
  230. return true;
  231. }
  232. getCalculations(form: any, saveForm: boolean) {
  233. this.submitted = true;
  234. if (!form.valid) {
  235. return false;
  236. }
  237. Swal.fire({
  238. allowOutsideClick: false,
  239. icon: "info",
  240. text: "Espere por favor..."
  241. });
  242. Swal.showLoading();
  243. this.instrumentCalcService
  244. .fondosCalc(
  245. "FINV", // Codigo del instrumento
  246. {
  247. id_tipo_base: +this.general.base_anual,
  248. id_formato_ingreso: +this.general.formato_ingreso,
  249. id_periodicidad: +this.general.periodicidad
  250. },
  251. {
  252. cuota_participacion: +this.f.cuota_participacion.value,
  253. valor_participacion_porcentaje: +this.f.valor_participacion_porcentaje
  254. .value,
  255. comision_bolsa_porcentaje: +this.f.comision_bolsa_porcentaje.value,
  256. comision_casa_porcentaje: +this.f.comision_casa_porcentaje.value,
  257. dividendo_porcentaje: +this.f.dividendo_porcentaje.value,
  258. rendimiento_porcentaje: +this.f.rendimiento_porcentaje.value,
  259. dias_liquidacion: this.f.dias_liquidacion.value,
  260. dias_vencimiento: this.f.dias_vencimiento.value,
  261. fecha_operacion: this.f.fecha_operacion.value.singleDate.formatted
  262. }
  263. )
  264. .subscribe(
  265. ans => {
  266. this.cuota_participacion =
  267. ans["result"]["instrumento"]["cuota_participacion"];
  268. this.valor_participacion_porcentaje =
  269. ans["result"]["instrumento"]["valor_participacion_porcentaje"];
  270. this.dias_liquidacion =
  271. ans["result"]["instrumento"]["dias_liquidacion"];
  272. this.dias_vencimiento =
  273. ans["result"]["instrumento"]["dias_vencimiento"];
  274. this.valor_nominal = ans["result"]["instrumento"]["valor_nominal"];
  275. this.valor_transado = ans["result"]["instrumento"]["valor_transado"];
  276. this.monto_pagar = ans["result"]["instrumento"]["monto_pagar"];
  277. this.comision_casa_porcentaje =
  278. ans["result"]["instrumento"]["comision_casa_porcentaje"];
  279. this.comision_casa = ans["result"]["instrumento"]["comision_casa"];
  280. this.comision_bolsa_porcentaje =
  281. ans["result"]["instrumento"]["comision_bolsa_porcentaje"];
  282. this.comision_bolsa = ans["result"]["instrumento"]["comision_bolsa"];
  283. this.rendimiento_porcentaje =
  284. ans["result"]["instrumento"]["rendimiento_porcentaje"];
  285. this.dividendo_porcentaje =
  286. ans["result"]["instrumento"]["dividendo_porcentaje"];
  287. this.fecha_operacion =
  288. ans["result"]["instrumento"]["fecha_operacion"];
  289. this.fecha_liquidacion =
  290. ans["result"]["instrumento"]["fecha_liquidacion"];
  291. this.fecha_vencimiento =
  292. ans["result"]["instrumento"]["fecha_vencimiento"];
  293. // Proyecciones
  294. this.proyecciones = ans["result"]["proyecciones"];
  295. if (this.proyecciones != undefined && this.proyecciones.length > 0) {
  296. this.hasProjections = true;
  297. this.consolidado_proyeccion = this.proyecciones.pop();
  298. this.proyecciones;
  299. }
  300. this.operation_result = true;
  301. this.dataSource.data = this.proyecciones;
  302. this.dataSource2.data = this.proyecciones;
  303. this.dataSource.paginator = this.paginator;
  304. this.dataSource.sort = this.sort;
  305. this.fondosObject = {
  306. cuota_participacion: this.investmentProposalForm.value
  307. .cuota_participacion,
  308. valor_participacion_porcentaje: this.investmentProposalForm.value
  309. .valor_participacion_porcentaje,
  310. comision_bolsa_porcentaje: this.investmentProposalForm.value
  311. .comision_bolsa_porcentaje,
  312. comision_casa_porcentaje: this.investmentProposalForm.value
  313. .comision_casa_porcentaje,
  314. dividendo_porcentaje: this.investmentProposalForm.value
  315. .dividendo_porcentaje,
  316. rendimiento_porcentaje: this.investmentProposalForm.value
  317. .rendimiento_porcentaje,
  318. dias_liquidacion: this.investmentProposalForm.value
  319. .dias_liquidacion,
  320. dias_vencimiento: this.investmentProposalForm.value
  321. .dias_vencimiento,
  322. fecha_operacion: this.f.fecha_operacion.value.singleDate.formatted,
  323. valor_nominal: this.valor_nominal,
  324. valor_transado: this.valor_transado,
  325. monto_pagar: this.monto_pagar,
  326. comision_casa: this.comision_casa,
  327. comision_bolsa: this.comision_bolsa,
  328. fecha_liquidacion: this.fecha_liquidacion,
  329. fecha_vencimiento: this.fecha_vencimiento,
  330. // Proyecciones
  331. proyecciones: this.proyecciones
  332. };
  333. this.formDataService.setWork(this.fondosObject);
  334. Swal.close();
  335. if (saveForm == true) {
  336. if (this.investmentID != undefined) {
  337. this.router.navigate(["/investment-proposal/complement-info"], {
  338. queryParams: { id: this.investmentID }
  339. });
  340. } else {
  341. this.router.navigate(["/investment-proposal/complement-info"]);
  342. }
  343. }
  344. },
  345. err => {
  346. Swal.fire({
  347. icon: "error",
  348. title: "Error en el servidor",
  349. text: "No su pudo obtener la informacion"
  350. });
  351. return false;
  352. }
  353. );
  354. }
  355. goToPrevious() {
  356. this.submitted = true;
  357. if (this.investmentID != undefined) {
  358. this.router.navigate(["/investment-proposal/general-info"], {
  359. queryParams: { id: this.investmentID }
  360. });
  361. } else {
  362. this.router.navigate(["/investment-proposal/general-info"]);
  363. }
  364. }
  365. goToNext(form: any) {
  366. this.getCalculations(form, true);
  367. }
  368. }