dap.component.ts 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  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-dap",
  18. templateUrl: "./dap.component.html"
  19. })
  20. export class DAP implements InstrumentComponent {
  21. title: string = "Depósitos a plazo";
  22. @Input() data: any;
  23. @Input() summary: boolean;
  24. @Input() investmentID: string;
  25. form: any;
  26. general: GeneralInfo;
  27. displayedColumns: string[] = [
  28. "posicion",
  29. "plazo",
  30. "fecha_pago",
  31. "ingreso_bruto",
  32. "renta",
  33. "ingreso_neto"
  34. ];
  35. @ViewChild(MatPaginator, { static: true }) paginator: MatPaginator;
  36. @ViewChild(MatSort, { static: true }) sort: MatSort;
  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. ingreso_bruto: number = 0.0;
  74. ingreso_neto: number = 0.0;
  75. valor_transado: number = 0.0;
  76. precio_porcentaje: number = 0.0;
  77. rendimiento_neto: number = 0.0;
  78. plazo: number = 0;
  79. fecha_inicio_vigencia: string;
  80. rendimiento_bruto: number = 0;
  81. monto_inversion: number = 0;
  82. proyecciones: any;
  83. dataSource = new MatTableDataSource(this.proyecciones);
  84. dataSource2 = new MatTableDataSource(this.proyecciones);
  85. dapObject: {};
  86. renta: any;
  87. hasProjections: boolean;
  88. numero_certificado: any;
  89. fecha_vencimiento: any;
  90. consolidado_proyeccion: any;
  91. constructor(
  92. private formBuilder: FormBuilder,
  93. private router: Router,
  94. private formDataService: FormInvestmentProposalService,
  95. private catalogService: CatalogsService,
  96. private instrumentCalcService: InstrumentCalculations,
  97. public datepipe: DatePipe
  98. ) {
  99. this.instrument_work = this.formDataService.getWork();
  100. this.instrument_null = this.instrument_work == undefined;
  101. this.general = this.formDataService.getGeneralInfo();
  102. if (
  103. this.instrument_work != undefined &&
  104. (this.instrument_work.proyecciones != "" ||
  105. this.instrument_work != undefined)
  106. ) {
  107. this.hasProjections = true;
  108. this.consolidado_proyeccion = this.instrument_work.proyecciones.pop();
  109. this.dataSource2.data = this.instrument_work.proyecciones;
  110. this.dataSource2.paginator = this.paginator;
  111. this.dataSource2.sort = this.sort;
  112. } else {
  113. this.hasProjections = false;
  114. }
  115. this.investmentProposalForm = this.formBuilder.group({
  116. monto_inversion: [
  117. this.instrument_null ? "" : this.instrument_work.monto_inversion,
  118. [
  119. Validators.required,
  120. Validators.pattern(/^[+]?([0-9]+(?:[\.][0-9]*)?|\.[0-9]+)$/)
  121. ]
  122. ],
  123. renta_porcentaje: [
  124. this.instrument_null || this.instrument_work.renta_porcentaje == null
  125. ? 10
  126. : this.instrument_work.renta_porcentaje,
  127. [Validators.required]
  128. ],
  129. tasa_porcentaje: [
  130. this.instrument_null ? "" : this.instrument_work.tasa_porcentaje,
  131. [
  132. Validators.required,
  133. Validators.pattern(/^[+]?([0-9]+(?:[\.][0-9]*)?|\.[0-9]+)$/)
  134. ]
  135. ],
  136. plazo: [
  137. this.instrument_null ? "" : this.instrument_work.plazo,
  138. [Validators.required]
  139. ],
  140. numero_certificado: [
  141. this.instrument_null ? "" : this.instrument_work.numero_certificado,
  142. []
  143. ],
  144. fecha_operacion: [
  145. this.instrument_null
  146. ? ""
  147. : {
  148. isRange: false,
  149. singleDate: {
  150. jsDate: parse(
  151. this.instrument_work.fecha_operacion,
  152. "dd/MM/yyyy",
  153. new Date()
  154. ),
  155. formatted: this.instrument_work.fecha_operacion
  156. }
  157. },
  158. Validators.required
  159. ]
  160. });
  161. }
  162. get f() {
  163. return this.investmentProposalForm.controls;
  164. }
  165. save(form: any): boolean {
  166. if (!form.valid) {
  167. return false;
  168. }
  169. return true;
  170. }
  171. getCalculations(form: any, saveForm: boolean) {
  172. this.submitted = true;
  173. if (!form.valid) {
  174. return false;
  175. }
  176. Swal.fire({
  177. allowOutsideClick: false,
  178. icon: "info",
  179. text: "Espere por favor..."
  180. });
  181. Swal.showLoading();
  182. this.instrumentCalcService
  183. .dapCalc(
  184. "DAP", // Codigo del instrumento
  185. {
  186. id_tipo_base: +this.general.base_anual,
  187. id_periodicidad: +this.general.periodicidad,
  188. id_formato_ingreso: +this.general.formato_ingreso
  189. },
  190. {
  191. monto_inversion: +this.f.monto_inversion.value,
  192. tasa_porcentaje: +this.f.tasa_porcentaje.value,
  193. renta_porcentaje: +this.f.renta_porcentaje.value,
  194. plazo: +this.f.plazo.value,
  195. //id_formato_ingreso: this.f.formato_ingreso.value,
  196. fecha_operacion: this.f.fecha_operacion.value.singleDate.formatted
  197. }
  198. )
  199. .subscribe(
  200. ans => {
  201. this.monto_inversion = ans["result"]["monto_inversion"];
  202. this.ingreso_bruto = ans["result"]["ingreso_bruto"];
  203. this.ingreso_neto = ans["result"]["ingreso_neto"];
  204. this.rendimiento_bruto = ans["result"]["rendimiento_bruto"];
  205. this.rendimiento_neto = ans["result"]["rendimiento_neto"];
  206. this.plazo = ans["result"]["plazo"];
  207. this.fecha_inicio_vigencia = ans["result"]["fecha_inicio_vigencia"];
  208. this.renta = ans["result"]["renta"];
  209. this.proyecciones = ans["result"]["proyecciones"];
  210. this.numero_certificado = ans["result"]["numero_certificado"];
  211. this.fecha_vencimiento = ans["result"]["fecha_vencimiento"];
  212. if (this.proyecciones != undefined && this.proyecciones.length > 0) {
  213. this.hasProjections = true;
  214. //this.consolidado_proyeccion = this.proyecciones.pop();
  215. this.proyecciones;
  216. }
  217. this.dataSource.data = this.proyecciones;
  218. this.dataSource.paginator = this.paginator;
  219. this.dataSource.sort = this.sort;
  220. this.dapObject = {
  221. monto_inversion: this.investmentProposalForm.value.monto_inversion,
  222. renta_porcentaje: this.investmentProposalForm.value
  223. .renta_porcentaje,
  224. tasa_porcentaje: this.investmentProposalForm.value.tasa_porcentaje,
  225. plazo: +this.investmentProposalForm.value.plazo,
  226. ingreso_bruto: this.ingreso_bruto,
  227. ingreso_neto: this.ingreso_neto,
  228. rendimiento_bruto: this.rendimiento_bruto,
  229. rendimiento_neto: this.rendimiento_neto,
  230. fecha_inicio_vigencia: this.fecha_inicio_vigencia,
  231. renta: this.renta,
  232. numero_certificado: this.investmentProposalForm.value
  233. .numero_certificado,
  234. proyecciones: this.proyecciones,
  235. fecha_operacion: this.investmentProposalForm.value.fecha_operacion
  236. .singleDate.formatted,
  237. fecha_vencimiento: this.fecha_vencimiento
  238. };
  239. this.formDataService.setWork(this.dapObject);
  240. Swal.close();
  241. if (saveForm == true) {
  242. if (this.investmentID != undefined) {
  243. this.router.navigate(["/investment-proposal/complement-info"], {
  244. queryParams: { id: this.investmentID }
  245. });
  246. } else {
  247. this.router.navigate(["/investment-proposal/complement-info"]);
  248. }
  249. }
  250. },
  251. err => {
  252. Swal.fire({
  253. icon: "error",
  254. title: "Error en el servidor",
  255. text: "No su pudo obtener la informacion"
  256. });
  257. return false;
  258. }
  259. );
  260. }
  261. goToPrevious() {
  262. this.submitted = true;
  263. if (this.investmentID != undefined) {
  264. this.router.navigate(["/investment-proposal/general-info"], {
  265. queryParams: { id: this.investmentID }
  266. });
  267. } else {
  268. this.router.navigate(["/investment-proposal/general-info"]);
  269. }
  270. }
  271. goToNext(form: any) {
  272. this.getCalculations(form, true);
  273. }
  274. }