lete.component.ts 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. import { Component, OnInit, Input } 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. @Component({
  14. selector: "app-lete",
  15. templateUrl: "./lete.component.html"
  16. })
  17. export class LETE implements InstrumentComponent {
  18. title: string = "Letes";
  19. @Input() data: any;
  20. @Input() summary: boolean;
  21. @Input() investmentID: string;
  22. form: any;
  23. general: GeneralInfo;
  24. // For daterange
  25. daysLabels: any = {
  26. su: "Dom",
  27. mo: "Lun",
  28. tu: "Mar",
  29. we: "Mie",
  30. th: "Jue",
  31. fr: "Vie",
  32. sa: "Sab"
  33. };
  34. monthsLabels: any = {
  35. 1: "Ene",
  36. 2: "Feb",
  37. 3: "Mar",
  38. 4: "Abr",
  39. 5: "May",
  40. 6: "Jun",
  41. 7: "Jul",
  42. 8: "Ago",
  43. 9: "Sep",
  44. 10: "Oct",
  45. 11: "Nov",
  46. 12: "Dic"
  47. };
  48. investmentProposalForm: FormGroup;
  49. myDpOptions: IAngularMyDpOptions = {
  50. dateRange: false,
  51. dateFormat: "dd/mm/yyyy",
  52. dayLabels: this.daysLabels,
  53. monthLabels: this.monthsLabels
  54. };
  55. myDateInit: boolean = true;
  56. m_fecha_operacion: IMyDateModel;
  57. m_fecha_liquidacion: IMyDateModel;
  58. m_fecha_rendencion: IMyDateModel;
  59. submitted: boolean = false;
  60. instrument_exists: boolean;
  61. instrument_work: any = [];
  62. financials: any;
  63. base_types: any;
  64. ingreso_bruto: number = 0.0;
  65. ingreso_neto: number = 0.0;
  66. valor_transado: number = 0.0;
  67. precio_porcentaje: number = 0.0;
  68. rendimiento_neto: number = 0.0;
  69. total_pagar: number = 0.0;
  70. comision_bolsa: number = 0.0;
  71. comision_casa: number = 0.0;
  72. leteObject: {};
  73. fecha_vencimiento: string = "-";
  74. constructor(
  75. private formBuilder: FormBuilder,
  76. private router: Router,
  77. private formDataService: FormInvestmentProposalService,
  78. private catalogService: CatalogsService,
  79. private instrumentCalcService: InstrumentCalculations,
  80. public datepipe: DatePipe
  81. ) {
  82. this.instrument_work = this.formDataService.getWork();
  83. this.instrument_exists = this.instrument_work == undefined;
  84. this.general = this.formDataService.getGeneralInfo();
  85. this.investmentProposalForm = this.formBuilder.group({
  86. renta_porcentaje: [
  87. this.instrument_exists ? "" : this.instrument_work.renta_porcentaje,
  88. [
  89. Validators.required,
  90. Validators.pattern(/^[+]?([0-9]+(?:[\.][0-9]*)?|\.[0-9]+)$/)
  91. ]
  92. ],
  93. valor_nominal: [
  94. this.instrument_exists ? "" : this.instrument_work.valor_nominal,
  95. [
  96. Validators.required,
  97. Validators.pattern(/^[+]?([0-9]+(?:[\.][0-9]*)?|\.[0-9]+)$/)
  98. ]
  99. ],
  100. plazo: [
  101. this.instrument_exists ? "" : this.instrument_work.plazo,
  102. [Validators.required, Validators.pattern(/^[+]?([0-9]+)$/)]
  103. ],
  104. comision_casa_porcentaje: [
  105. this.instrument_exists
  106. ? ""
  107. : this.instrument_work.comision_casa_porcentaje,
  108. [
  109. Validators.required,
  110. Validators.pattern(/^[+]?([0-9]+(?:[\.][0-9]*)?|\.[0-9]+)$/)
  111. ]
  112. ],
  113. comision_bolsa_porcentaje: [
  114. this.instrument_exists
  115. ? ""
  116. : this.instrument_work.comision_bolsa_porcentaje,
  117. [
  118. Validators.required,
  119. Validators.pattern(/^[+]?([0-9]+(?:[\.][0-9]*)?|\.[0-9]+)$/)
  120. ]
  121. ],
  122. rendimiento_bruto: [
  123. this.instrument_exists ? "" : this.instrument_work.rendimiento_bruto,
  124. [
  125. Validators.required,
  126. Validators.pattern(/^[+]?([0-9]+(?:[\.][0-9]*)?|\.[0-9]+)$/)
  127. ]
  128. ],
  129. fecha_liquidacion: [
  130. this.instrument_exists
  131. ? ""
  132. : {
  133. isRange: false,
  134. singleDate: {
  135. jsDate: parse(
  136. this.instrument_work.fecha_liquidacion,
  137. "dd/MM/yyyy",
  138. new Date()
  139. ),
  140. formatted: this.instrument_work.fecha_liquidacion
  141. }
  142. },
  143. Validators.required
  144. ],
  145. fecha_operacion: [
  146. this.instrument_exists
  147. ? ""
  148. : {
  149. isRange: false,
  150. singleDate: {
  151. jsDate: parse(
  152. this.instrument_work.fecha_operacion,
  153. "dd/MM/yyyy",
  154. new Date()
  155. ),
  156. formatted: this.instrument_work.fecha_operacion
  157. }
  158. },
  159. Validators.required
  160. ],
  161. fecha_redencion: [
  162. this.instrument_exists
  163. ? ""
  164. : {
  165. isRange: false,
  166. singleDate: {
  167. jsDate: parse(
  168. this.instrument_work.fecha_redencion,
  169. "dd/MM/yyyy",
  170. new Date()
  171. ),
  172. formatted: this.instrument_work.fecha_redencion
  173. }
  174. }
  175. ]
  176. });
  177. }
  178. get f() {
  179. return this.investmentProposalForm.controls;
  180. }
  181. save(form: any): boolean {
  182. if (!form.valid) {
  183. return false;
  184. }
  185. this.formDataService.setWork(this.leteObject);
  186. return true;
  187. }
  188. getCalculations(form: any, saveForm: boolean) {
  189. this.submitted = true;
  190. if (!form.valid) {
  191. return false;
  192. }
  193. Swal.fire({
  194. allowOutsideClick: false,
  195. icon: "info",
  196. text: "Espere por favor..."
  197. });
  198. Swal.showLoading();
  199. this.instrumentCalcService
  200. .leteCalc(
  201. "LETE", // Codigo del instrumento
  202. { id_tipo_base: this.general.base_anual },
  203. {
  204. valor_nominal: +this.f.valor_nominal.value,
  205. plazo: +this.f.plazo.value,
  206. renta_porcentaje: +this.f.renta_porcentaje.value,
  207. comision_casa_porcentaje: +this.f.comision_casa_porcentaje.value,
  208. comision_bolsa_porcentaje: +this.f.comision_bolsa_porcentaje.value,
  209. rendimiento_bruto: +this.f.rendimiento_bruto.value,
  210. fecha_operacion: this.f.fecha_operacion.value.singleDate.formatted,
  211. fecha_liquidacion: this.f.fecha_liquidacion.value.singleDate.formatted
  212. }
  213. )
  214. .subscribe(
  215. ans => {
  216. this.ingreso_bruto = ans["result"]["ingreso_bruto"];
  217. this.ingreso_neto = ans["result"]["ingreso_neto"];
  218. this.valor_transado = ans["result"]["valor_transado"];
  219. this.precio_porcentaje = ans["result"]["precio_porcentaje"];
  220. this.rendimiento_neto = ans["result"]["rendimiento_neto"];
  221. this.total_pagar = ans["result"]["total_pagar"];
  222. this.comision_bolsa = ans["result"]["comision_bolsa"];
  223. this.comision_casa = ans["result"]["comision_casa"];
  224. this.fecha_vencimiento = ans["result"]["fecha_vencimiento"];
  225. Swal.close();
  226. this.leteObject = {
  227. renta_porcentaje: this.investmentProposalForm.value
  228. .renta_porcentaje,
  229. valor_nominal: this.investmentProposalForm.value.valor_nominal,
  230. plazo: this.investmentProposalForm.value.plazo,
  231. comision_casa_porcentaje: this.investmentProposalForm.value
  232. .comision_casa_porcentaje,
  233. comision_bolsa_porcentaje: this.investmentProposalForm.value
  234. .comision_bolsa_porcentaje,
  235. rendimiento_bruto: this.investmentProposalForm.value
  236. .rendimiento_bruto,
  237. ingreso_bruto: this.ingreso_bruto,
  238. ingreso_neto: this.ingreso_neto,
  239. valor_transado: this.valor_transado,
  240. precio_porcentaje: this.precio_porcentaje,
  241. rendimiento_neto: this.rendimiento_neto,
  242. total_pagar: this.total_pagar,
  243. comision_bolsa: this.comision_bolsa,
  244. comision_casa: this.comision_casa,
  245. fecha_vencimiento: this.fecha_vencimiento,
  246. fecha_operacion: this.investmentProposalForm.value.fecha_operacion
  247. .singleDate.formatted,
  248. fecha_liquidacion:
  249. this.investmentProposalForm.value.fecha_liquidacion.singleDate
  250. .formatted || "",
  251. fecha_redencion:
  252. this.investmentProposalForm.value.fecha_redencion == undefined
  253. ? this.investmentProposalForm.value.fecha_redencion.singleDate
  254. .formatted
  255. : ""
  256. /*id_inversion_instrumento:
  257. this.instrument_work.id_inversion_instrumento == undefined
  258. ? ""
  259. : this.instrument_work.id_inversion_instrumento*/
  260. };
  261. this.formDataService.setWork(this.leteObject);
  262. Swal.close();
  263. if (saveForm == true) {
  264. if (this.investmentID != undefined) {
  265. this.router.navigate(["/investment-proposal/complement-info"], {
  266. queryParams: { id: this.investmentID }
  267. });
  268. } else {
  269. this.router.navigate(["/investment-proposal/complement-info"]);
  270. }
  271. }
  272. },
  273. err => {
  274. Swal.fire({
  275. icon: "error",
  276. title: "Error en el servidor",
  277. text: "No su pudo obtener la informacion"
  278. });
  279. return false;
  280. }
  281. );
  282. }
  283. goToPrevious() {
  284. this.submitted = true;
  285. if (this.investmentID != undefined) {
  286. this.router.navigate(["/investment-proposal/general-info"], {
  287. queryParams: { id: this.investmentID }
  288. });
  289. } else {
  290. this.router.navigate(["/investment-proposal/general-info"]);
  291. }
  292. }
  293. goToNext(form: any) {
  294. this.getCalculations(form, true);
  295. }
  296. }