lete.component.ts 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  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. valor_nominal: [
  87. this.instrument_exists ? "" : this.instrument_work.valor_nominal,
  88. [
  89. Validators.required,
  90. Validators.pattern(/^[+]?([0-9]+(?:[\.][0-9]*)?|\.[0-9]+)$/)
  91. ]
  92. ],
  93. plazo: [
  94. this.instrument_exists ? "" : this.instrument_work.plazo,
  95. [Validators.required, Validators.pattern(/^[+]?([0-9]+)$/)]
  96. ],
  97. comision_casa_porcentaje: [
  98. this.instrument_exists
  99. ? ""
  100. : this.instrument_work.comision_casa_porcentaje,
  101. [
  102. Validators.required,
  103. Validators.pattern(/^[+]?([0-9]+(?:[\.][0-9]*)?|\.[0-9]+)$/)
  104. ]
  105. ],
  106. comision_bolsa_porcentaje: [
  107. this.instrument_exists
  108. ? ""
  109. : this.instrument_work.comision_bolsa_porcentaje,
  110. [
  111. Validators.required,
  112. Validators.pattern(/^[+]?([0-9]+(?:[\.][0-9]*)?|\.[0-9]+)$/)
  113. ]
  114. ],
  115. rendimiento_bruto: [
  116. this.instrument_exists ? "" : this.instrument_work.rendimiento_bruto,
  117. [
  118. Validators.required,
  119. Validators.pattern(/^[+]?([0-9]+(?:[\.][0-9]*)?|\.[0-9]+)$/)
  120. ]
  121. ],
  122. fecha_liquidacion: [
  123. this.instrument_exists
  124. ? ""
  125. : {
  126. isRange: false,
  127. singleDate: {
  128. jsDate: parse(
  129. this.instrument_work.fecha_liquidacion,
  130. "dd/MM/yyyy",
  131. new Date()
  132. ),
  133. formatted: this.instrument_work.fecha_liquidacion
  134. }
  135. },
  136. Validators.required
  137. ],
  138. fecha_operacion: [
  139. this.instrument_exists
  140. ? ""
  141. : {
  142. isRange: false,
  143. singleDate: {
  144. jsDate: parse(
  145. this.instrument_work.fecha_operacion,
  146. "dd/MM/yyyy",
  147. new Date()
  148. ),
  149. formatted: this.instrument_work.fecha_operacion
  150. }
  151. },
  152. Validators.required
  153. ],
  154. fecha_redencion: [
  155. this.instrument_exists
  156. ? ""
  157. : {
  158. isRange: false,
  159. singleDate: {
  160. jsDate: parse(
  161. this.instrument_work.fecha_redencion,
  162. "dd/MM/yyyy",
  163. new Date()
  164. ),
  165. formatted: this.instrument_work.fecha_redencion
  166. }
  167. }
  168. ]
  169. });
  170. }
  171. get f() {
  172. return this.investmentProposalForm.controls;
  173. }
  174. save(form: any): boolean {
  175. if (!form.valid) {
  176. return false;
  177. }
  178. this.formDataService.setWork(this.leteObject);
  179. return true;
  180. }
  181. getCalculations(form: any, saveForm: boolean) {
  182. this.submitted = true;
  183. if (!form.valid) {
  184. return false;
  185. }
  186. Swal.fire({
  187. allowOutsideClick: false,
  188. icon: "info",
  189. text: "Espere por favor..."
  190. });
  191. Swal.showLoading();
  192. this.instrumentCalcService
  193. .leteCalc(
  194. "LETE", // Codigo del instrumento
  195. { id_tipo_base: this.general.base_anual },
  196. {
  197. valor_nominal: +this.f.valor_nominal.value,
  198. plazo: +this.f.plazo.value,
  199. comision_casa_porcentaje: this.f.comision_casa_porcentaje.value,
  200. comision_bolsa_porcentaje: this.f.comision_bolsa_porcentaje.value,
  201. rendimiento_bruto: this.f.rendimiento_bruto.value,
  202. fecha_operacion: this.f.fecha_operacion.value.singleDate.formatted,
  203. fecha_liquidacion: this.f.fecha_liquidacion.value.singleDate.formatted
  204. }
  205. )
  206. .subscribe(
  207. ans => {
  208. this.ingreso_bruto = ans["result"]["ingreso_bruto"];
  209. this.ingreso_neto = ans["result"]["ingreso_neto"];
  210. this.valor_transado = ans["result"]["valor_transado"];
  211. this.precio_porcentaje = ans["result"]["precio_porcentaje"];
  212. this.rendimiento_neto = ans["result"]["rendimiento_neto"];
  213. this.total_pagar = ans["result"]["total_pagar"];
  214. this.comision_bolsa = ans["result"]["comision_bolsa"];
  215. this.comision_casa = ans["result"]["comision_casa"];
  216. this.fecha_vencimiento = ans["result"]["fecha_vencimiento"];
  217. Swal.close();
  218. this.leteObject = {
  219. valor_nominal: this.investmentProposalForm.value.valor_nominal,
  220. plazo: this.investmentProposalForm.value.plazo,
  221. comision_casa_porcentaje: this.investmentProposalForm.value
  222. .comision_casa_porcentaje,
  223. comision_bolsa_porcentaje: this.investmentProposalForm.value
  224. .comision_bolsa_porcentaje,
  225. rendimiento_bruto: this.investmentProposalForm.value
  226. .rendimiento_bruto,
  227. ingreso_bruto: this.ingreso_bruto,
  228. ingreso_neto: this.ingreso_neto,
  229. valor_transado: this.valor_transado,
  230. precio_porcentaje: this.precio_porcentaje,
  231. rendimiento_neto: this.rendimiento_neto,
  232. total_pagar: this.total_pagar,
  233. comision_bolsa: this.comision_bolsa,
  234. comision_casa: this.comision_casa,
  235. fecha_vencimiento: this.fecha_vencimiento,
  236. fecha_operacion: this.investmentProposalForm.value.fecha_operacion
  237. .singleDate.formatted,
  238. fecha_liquidacion:
  239. this.investmentProposalForm.value.fecha_liquidacion.singleDate
  240. .formatted || "",
  241. fecha_redencion:
  242. this.investmentProposalForm.value.fecha_redencion == undefined
  243. ? this.investmentProposalForm.value.fecha_redencion.singleDate
  244. .formatted
  245. : ""
  246. /*id_inversion_instrumento:
  247. this.instrument_work.id_inversion_instrumento == undefined
  248. ? ""
  249. : this.instrument_work.id_inversion_instrumento*/
  250. };
  251. this.formDataService.setWork(this.leteObject);
  252. Swal.close();
  253. if (saveForm == true) {
  254. if (this.investmentID != undefined) {
  255. this.router.navigate(["/investment-proposal/complement-info"], {
  256. queryParams: { id: this.investmentID }
  257. });
  258. } else {
  259. this.router.navigate(["/investment-proposal/complement-info"]);
  260. }
  261. }
  262. },
  263. err => {
  264. Swal.fire({
  265. icon: "error",
  266. title: "Error en el servidor",
  267. text: "No su pudo obtener la informacion"
  268. });
  269. return false;
  270. }
  271. );
  272. }
  273. goToPrevious() {
  274. this.submitted = true;
  275. if (this.investmentID != undefined) {
  276. this.router.navigate(["/investment-proposal/general-info"], {
  277. queryParams: { id: this.investmentID }
  278. });
  279. } else {
  280. this.router.navigate(["/investment-proposal/general-info"]);
  281. }
  282. }
  283. goToNext(form: any) {
  284. this.getCalculations(form, true);
  285. }
  286. }