pbur.component.ts 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410
  1. import { Component, OnInit, Input, ViewChild, OnChanges } 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, MatSort, MatTableDataSource } from "@angular/material";
  14. @Component({
  15. selector: "app-pbur",
  16. templateUrl: "./pbur.component.html"
  17. })
  18. export class PBUR implements InstrumentComponent {
  19. title: string = "Papel bursátil";
  20. @Input() data: any;
  21. @Input() summary: boolean;
  22. @Input() investmentID: string;
  23. form: any;
  24. general: GeneralInfo;
  25. displayedColumns: string[] = [
  26. "posicion",
  27. "plazo",
  28. "fecha_pago",
  29. "ingreso_bruto",
  30. "ingreso_neto",
  31. "costo_cedeval",
  32. "renta",
  33. "costo_transferencia",
  34. "costo_banco",
  35. "otros_costos"
  36. ];
  37. // For daterange
  38. daysLabels: any = {
  39. su: "Dom",
  40. mo: "Lun",
  41. tu: "Mar",
  42. we: "Mie",
  43. th: "Jue",
  44. fr: "Vie",
  45. sa: "Sab"
  46. };
  47. monthsLabels: any = {
  48. 1: "Ene",
  49. 2: "Feb",
  50. 3: "Mar",
  51. 4: "Abr",
  52. 5: "May",
  53. 6: "Jun",
  54. 7: "Jul",
  55. 8: "Ago",
  56. 9: "Sep",
  57. 10: "Oct",
  58. 11: "Nov",
  59. 12: "Dic"
  60. };
  61. instrument_null: boolean;
  62. instrument_work: any = [];
  63. investmentProposalForm: FormGroup;
  64. myDpOptions: IAngularMyDpOptions = {
  65. dateRange: false,
  66. dateFormat: "dd/mm/yyyy",
  67. dayLabels: this.daysLabels,
  68. monthLabels: this.monthsLabels
  69. };
  70. submitted: boolean;
  71. myDateInit: boolean = true;
  72. model: IMyDateModel = null;
  73. pburObject: {};
  74. format_incomes: any;
  75. ingreso_bruto: number = 0.0;
  76. ingreso_neto: number = 0.0;
  77. valor_transado: number = 0.0;
  78. precio_porcentaje: number = 0.0;
  79. rendimiento_neto: number = 0.0;
  80. total_pagar: number = 0.0;
  81. comision_bolsa: number = 0.0;
  82. comision_casa: number = 0.0;
  83. plazo: number = 0;
  84. interes_acumulado: number = 0;
  85. fecha_inicio_vigencia: string;
  86. proyecciones: any;
  87. hasProjections: boolean;
  88. dataSource = new MatTableDataSource(this.proyecciones);
  89. dataSource2 = new MatTableDataSource(this.proyecciones);
  90. consolidado_proyeccion = {
  91. total_ingreso_bruto: 0,
  92. total_ingreso_neto: 0,
  93. total_costo_cedeval: 0,
  94. total_renta: 0,
  95. total_costo_transferencia: 0,
  96. total_costo_banco: 0,
  97. total_otros_costos: 0
  98. };
  99. @ViewChild(MatPaginator, { static: true }) paginator: MatPaginator;
  100. @ViewChild(MatSort, { static: true }) sort: MatSort;
  101. fecha_vencimiento: any;
  102. renta_porcentaje: any;
  103. constructor(
  104. private formBuilder: FormBuilder,
  105. private router: Router,
  106. private formDataService: FormInvestmentProposalService,
  107. private catalogService: CatalogsService,
  108. private instrumentCalcService: InstrumentCalculations,
  109. public datepipe: DatePipe
  110. ) {
  111. this.instrument_work = this.formDataService.getWork();
  112. this.instrument_null = this.instrument_work == undefined;
  113. this.general = this.formDataService.getGeneralInfo();
  114. if (
  115. this.instrument_work != undefined &&
  116. this.instrument_work.valor_par == true &&
  117. this.instrument_work.proyecciones != undefined
  118. ) {
  119. this.hasProjections = true;
  120. this.dataSource2.data = this.instrument_work.proyecciones.slice(0, -1);
  121. this.dataSource2.paginator = this.paginator;
  122. this.dataSource2.sort = this.sort;
  123. this.consolidado_proyeccion = this.instrument_work.proyecciones[
  124. this.instrument_work.proyecciones.length - 1
  125. ];
  126. } else {
  127. this.hasProjections = false;
  128. }
  129. //getIncomeFormat
  130. this.catalogService.getIncomeFormat().subscribe(res => {
  131. this.format_incomes = res;
  132. });
  133. this.investmentProposalForm = this.formBuilder.group({
  134. valor_par: [
  135. this.instrument_null || this.instrument_work.valor_par == null
  136. ? false
  137. : this.instrument_work.valor_par
  138. ],
  139. valor_nominal: [
  140. this.instrument_null ? "" : this.instrument_work.valor_nominal,
  141. [
  142. Validators.required,
  143. Validators.pattern(/^[+]?([0-9]+(?:[\.][0-9]*)?|\.[0-9]+)$/)
  144. ]
  145. ],
  146. otros_costos: [
  147. this.instrument_null || this.instrument_work.otros_costos == null
  148. ? 0
  149. : this.instrument_work.otros_costos,
  150. [Validators.pattern(/^[+]?([0-9]+(?:[\.][0-9]*)?|\.[0-9]+)$/)]
  151. ],
  152. renta_porcentaje: [
  153. this.instrument_null || this.instrument_work.renta_porcentaje == null
  154. ? 10
  155. : this.instrument_work.renta_porcentaje,
  156. [Validators.required]
  157. ],
  158. comision_casa_porcentaje: [
  159. this.instrument_null
  160. ? ""
  161. : this.instrument_work.comision_casa_porcentaje,
  162. [
  163. Validators.required,
  164. Validators.pattern(/^[+]?([0-9]+(?:[\.][0-9]*)?|\.[0-9]+)$/)
  165. ]
  166. ],
  167. comision_bolsa_porcentaje: [
  168. this.instrument_null
  169. ? ""
  170. : this.instrument_work.comision_bolsa_porcentaje,
  171. [
  172. Validators.required,
  173. Validators.pattern(/^[+]?([0-9]+(?:[\.][0-9]*)?|\.[0-9]+)$/)
  174. ]
  175. ],
  176. plazo: [
  177. this.instrument_null || this.instrument_work.plazo == null
  178. ? 0
  179. : this.instrument_work.plazo,
  180. [Validators.required]
  181. ],
  182. rendimiento_bruto: [
  183. this.instrument_null ? "" : this.instrument_work.rendimiento_bruto,
  184. [
  185. Validators.required,
  186. Validators.pattern(/^[+]?([0-9]+(?:[\.][0-9]*)?|\.[0-9]+)$/)
  187. ]
  188. ],
  189. /*formato_ingreso: [
  190. this.instrument_null ? "" : this.instrument_work.formato_ingreso,
  191. [Validators.required]
  192. ],*/
  193. fecha_liquidacion: [
  194. this.instrument_null
  195. ? ""
  196. : {
  197. isRange: false,
  198. singleDate: {
  199. jsDate: parse(
  200. this.instrument_work.fecha_liquidacion,
  201. "dd/MM/yyyy",
  202. new Date()
  203. ),
  204. formatted: this.instrument_work.fecha_liquidacion
  205. }
  206. },
  207. Validators.required
  208. ],
  209. fecha_operacion: [
  210. this.instrument_null
  211. ? ""
  212. : {
  213. isRange: false,
  214. singleDate: {
  215. jsDate: parse(
  216. this.instrument_work.fecha_operacion,
  217. "dd/MM/yyyy",
  218. new Date()
  219. ),
  220. formatted: this.instrument_work.fecha_operacion
  221. }
  222. },
  223. Validators.required
  224. ],
  225. fecha_ultima_cupon: [
  226. this.instrument_null
  227. ? ""
  228. : {
  229. isRange: false,
  230. singleDate: {
  231. jsDate: parse(
  232. this.instrument_work.fecha_ultima_cupon,
  233. "dd/MM/yyyy",
  234. new Date()
  235. ),
  236. formatted: this.instrument_work.fecha_ultima_cupon
  237. }
  238. },
  239. Validators.required
  240. ]
  241. });
  242. }
  243. get f() {
  244. return this.investmentProposalForm.controls;
  245. }
  246. save(form: any): boolean {
  247. if (!form.valid) {
  248. return false;
  249. }
  250. return true;
  251. }
  252. getCalculations(form: any, saveForm: boolean) {
  253. this.submitted = true;
  254. if (!form.valid) {
  255. return false;
  256. }
  257. Swal.fire({
  258. allowOutsideClick: false,
  259. icon: "info",
  260. text: "Espere por favor..."
  261. });
  262. Swal.showLoading();
  263. this.instrumentCalcService
  264. .pburCalc(
  265. "PBUR", // Codigo del instrumento
  266. {
  267. id_tipo_base: +this.general.base_anual,
  268. id_periodicidad: +this.general.periodicidad,
  269. id_formato_ingreso: +this.general.formato_ingreso
  270. },
  271. {
  272. valor_par: this.f.valor_par.value,
  273. valor_nominal: +this.f.valor_nominal.value,
  274. plazo: this.f.plazo.value,
  275. comision_casa_porcentaje: this.f.comision_casa_porcentaje.value,
  276. comision_bolsa_porcentaje: this.f.comision_bolsa_porcentaje.value,
  277. rendimiento_bruto: this.f.rendimiento_bruto.value,
  278. otros_costos: this.f.otros_costos.value,
  279. renta_porcentaje: this.f.renta_porcentaje.value,
  280. //id_formato_ingreso: this.f.formato_ingreso.value,
  281. fecha_operacion: this.f.fecha_operacion.value.singleDate.formatted,
  282. fecha_liquidacion: this.f.fecha_liquidacion.value.singleDate
  283. .formatted,
  284. fecha_ultima_cupon: this.f.fecha_ultima_cupon.value.singleDate
  285. .formatted
  286. }
  287. )
  288. .subscribe(
  289. ans => {
  290. this.ingreso_bruto = ans["result"]["ingreso_bruto"];
  291. this.ingreso_neto = ans["result"]["ingreso_neto"];
  292. this.valor_transado = ans["result"]["valor_transado"];
  293. this.precio_porcentaje = ans["result"]["precio_porcentaje"];
  294. this.rendimiento_neto = ans["result"]["rendimiento_neto"];
  295. this.total_pagar = ans["result"]["total_pagar"];
  296. this.comision_bolsa = ans["result"]["comision_bolsa"];
  297. this.comision_casa = ans["result"]["comision_casa"];
  298. this.interes_acumulado = ans["result"]["interes_acumulado"];
  299. this.fecha_inicio_vigencia = ans["result"]["fecha_inicio_vigencia"];
  300. this.fecha_vencimiento = ans["result"]["fecha_vencimiento"];
  301. this.proyecciones = ans["result"]["proyecciones"];
  302. this.renta_porcentaje = ans["result"]["renta_porcentaje"];
  303. if (this.proyecciones != undefined && this.proyecciones.length > 0) {
  304. this.consolidado_proyeccion = this.proyecciones.slice(0, -1);
  305. this.proyecciones = ans["result"]["proyecciones"];
  306. }
  307. if (this.f.valor_par.value == true) {
  308. this.hasProjections = true;
  309. } else {
  310. this.hasProjections = false;
  311. }
  312. this.dataSource.data = this.proyecciones;
  313. this.dataSource.paginator = this.paginator;
  314. this.dataSource.sort = this.sort;
  315. this.pburObject = {
  316. valor_par: this.investmentProposalForm.value.valor_par,
  317. valor_nominal: this.investmentProposalForm.value.valor_nominal,
  318. renta_porcentaje: this.investmentProposalForm.value
  319. .renta_porcentaje,
  320. comision_casa_porcentaje: this.investmentProposalForm.value
  321. .comision_casa_porcentaje,
  322. comision_bolsa_porcentaje: this.investmentProposalForm.value
  323. .comision_bolsa_porcentaje,
  324. comision_casa: this.comision_casa,
  325. comision_bolsa: this.comision_bolsa,
  326. rendimiento_bruto: this.investmentProposalForm.value
  327. .rendimiento_bruto,
  328. otros_costos: this.investmentProposalForm.value.otros_costos,
  329. ingreso_bruto: this.ingreso_bruto,
  330. ingreso_neto: this.ingreso_neto,
  331. valor_transado: this.valor_transado,
  332. precio_porcentaje: this.precio_porcentaje,
  333. rendimiento_neto: this.rendimiento_neto,
  334. total_pagar: this.total_pagar,
  335. interes_acumulado: this.interes_acumulado,
  336. fecha_inicio_vigencia: this.fecha_inicio_vigencia,
  337. proyecciones: this.proyecciones,
  338. plazo: this.investmentProposalForm.value.plazo,
  339. //id_formato_ingreso: this.investmentProposalForm.value.id_formato_ingreso,
  340. fecha_operacion: this.investmentProposalForm.value.fecha_operacion
  341. .singleDate.formatted,
  342. fecha_liquidacion:
  343. this.investmentProposalForm.value.fecha_liquidacion.singleDate
  344. .formatted || "",
  345. fecha_ultima_cupon:
  346. this.investmentProposalForm.value.fecha_ultima_cupon != undefined
  347. ? this.investmentProposalForm.value.fecha_ultima_cupon
  348. .singleDate.formatted
  349. : "",
  350. fecha_vencimiento: this.fecha_vencimiento
  351. };
  352. this.formDataService.setWork(this.pburObject);
  353. Swal.close();
  354. if (saveForm == true) {
  355. if (this.investmentID != undefined) {
  356. this.router.navigate(["/investment-proposal/complement-info"], {
  357. queryParams: { id: this.investmentID }
  358. });
  359. } else {
  360. this.router.navigate(["/investment-proposal/complement-info"]);
  361. }
  362. }
  363. },
  364. err => {
  365. Swal.fire({
  366. icon: "error",
  367. title: "Error en el servidor",
  368. text: "No su pudo obtener la informacion"
  369. });
  370. return false;
  371. }
  372. );
  373. }
  374. goToPrevious() {
  375. this.submitted = true;
  376. if (this.investmentID != undefined) {
  377. this.router.navigate(["/investment-proposal/general-info"], {
  378. queryParams: { id: this.investmentID }
  379. });
  380. } else {
  381. this.router.navigate(["/investment-proposal/general-info"]);
  382. }
  383. }
  384. goToNext(form: any) {
  385. this.getCalculations(form, true);
  386. }
  387. }