vcn.component.ts 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  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-vcn",
  15. templateUrl: "./vcn.component.html"
  16. })
  17. export class VCN implements InstrumentComponent {
  18. title: string = "Valores comerciales negociables";
  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. instrument_exists: boolean;
  49. instrument_work: any = [];
  50. investmentProposalForm: FormGroup;
  51. myDpOptions: IAngularMyDpOptions = {
  52. dateRange: false,
  53. dateFormat: "dd/mm/yyyy",
  54. dayLabels: this.daysLabels,
  55. monthLabels: this.monthsLabels
  56. };
  57. submitted: boolean;
  58. myDateInit: boolean = true;
  59. model: IMyDateModel = null;
  60. vcnObject: {};
  61. format_incomes: any;
  62. ingreso_bruto: number = 0.0;
  63. ingreso_neto: number = 0.0;
  64. valor_transado: number = 0.0;
  65. precio_porcentaje: number = 0.0;
  66. rendimiento_neto: number = 0.0;
  67. total_pagar: number = 0.0;
  68. comision_bolsa: number = 0.0;
  69. comision_casa: number = 0.0;
  70. plazo: number = 0;
  71. interes_acumulado: number = 0;
  72. fecha_inicio_vigencia: string;
  73. constructor(
  74. private formBuilder: FormBuilder,
  75. private router: Router,
  76. private formDataService: FormInvestmentProposalService,
  77. private catalogService: CatalogsService,
  78. private instrumentCalcService: InstrumentCalculations,
  79. public datepipe: DatePipe
  80. ) {
  81. this.instrument_work = this.formDataService.getWork();
  82. this.instrument_exists = this.instrument_work == undefined;
  83. this.general = this.formDataService.getGeneralInfo();
  84. //getIncomeFormat
  85. this.catalogService.getIncomeFormat().subscribe(res => {
  86. this.format_incomes = res;
  87. });
  88. this.investmentProposalForm = this.formBuilder.group({
  89. valor_nominal: [
  90. this.instrument_exists ? "" : this.instrument_work.valor_nominal,
  91. [
  92. Validators.required,
  93. Validators.pattern(/^[+]?([0-9]+(?:[\.][0-9]*)?|\.[0-9]+)$/)
  94. ]
  95. ],
  96. otros_costos: [
  97. this.instrument_exists ? "" : this.instrument_work.otros_costos,
  98. [Validators.pattern(/^[+]?([0-9]+(?:[\.][0-9]*)?|\.[0-9]+)$/)]
  99. ],
  100. plazo: [
  101. this.instrument_exists ? "" : this.instrument_work.plazo,
  102. [Validators.required]
  103. ],
  104. renta_porcentaje: [
  105. this.instrument_exists ? "" : this.instrument_work.renta_porcentaje,
  106. [Validators.required]
  107. ],
  108. comision_casa_porcentaje: [
  109. this.instrument_exists
  110. ? ""
  111. : this.instrument_work.comision_casa_porcentaje,
  112. [
  113. Validators.required,
  114. Validators.pattern(/^[+]?([0-9]+(?:[\.][0-9]*)?|\.[0-9]+)$/)
  115. ]
  116. ],
  117. comision_bolsa_porcentaje: [
  118. this.instrument_exists
  119. ? ""
  120. : this.instrument_work.comision_bolsa_porcentaje,
  121. [
  122. Validators.required,
  123. Validators.pattern(/^[+]?([0-9]+(?:[\.][0-9]*)?|\.[0-9]+)$/)
  124. ]
  125. ],
  126. rendimiento_bruto: [
  127. this.instrument_exists ? "" : this.instrument_work.rendimiento_bruto,
  128. [
  129. Validators.required,
  130. Validators.pattern(/^[+]?([0-9]+(?:[\.][0-9]*)?|\.[0-9]+)$/)
  131. ]
  132. ],
  133. /*formato_ingreso: [
  134. this.instrument_exists ? "" : this.instrument_work.formato_ingreso,
  135. [Validators.required]
  136. ],*/
  137. fecha_liquidacion: [
  138. this.instrument_exists
  139. ? ""
  140. : {
  141. isRange: false,
  142. singleDate: {
  143. jsDate: parse(
  144. this.instrument_work.fecha_liquidacion,
  145. "dd/MM/yyyy",
  146. new Date()
  147. ),
  148. formatted: this.instrument_work.fecha_liquidacion
  149. }
  150. },
  151. Validators.required
  152. ],
  153. fecha_vencimiento: [
  154. this.instrument_exists
  155. ? ""
  156. : {
  157. isRange: false,
  158. singleDate: {
  159. jsDate: parse(
  160. this.instrument_work.fecha_vencimiento,
  161. "dd/MM/yyyy",
  162. new Date()
  163. ),
  164. formatted: this.instrument_work.fecha_vencimiento
  165. }
  166. },
  167. Validators.required
  168. ],
  169. fecha_operacion: [
  170. this.instrument_exists
  171. ? ""
  172. : {
  173. isRange: false,
  174. singleDate: {
  175. jsDate: parse(
  176. this.instrument_work.fecha_operacion,
  177. "dd/MM/yyyy",
  178. new Date()
  179. ),
  180. formatted: this.instrument_work.fecha_operacion
  181. }
  182. },
  183. Validators.required
  184. ],
  185. fecha_ultima_cupon: [
  186. this.instrument_exists
  187. ? ""
  188. : {
  189. isRange: false,
  190. singleDate: {
  191. jsDate: parse(
  192. this.instrument_work.fecha_ultima_cupon,
  193. "dd/MM/yyyy",
  194. new Date()
  195. ),
  196. formatted: this.instrument_work.fecha_ultima_cupon
  197. }
  198. }
  199. ]
  200. });
  201. }
  202. get f() {
  203. return this.investmentProposalForm.controls;
  204. }
  205. save(form: any): boolean {
  206. if (!form.valid) {
  207. return false;
  208. }
  209. this.formDataService.setWork(this.vcnObject);
  210. return true;
  211. }
  212. getCalculations(form: any, saveForm: boolean) {
  213. this.submitted = true;
  214. if (!form.valid) {
  215. return false;
  216. }
  217. Swal.fire({
  218. allowOutsideClick: false,
  219. icon: "info",
  220. text: "Espere por favor..."
  221. });
  222. Swal.showLoading();
  223. this.instrumentCalcService
  224. .vcnCalc(
  225. "PBUR", // Codigo del instrumento
  226. {
  227. id_tipo_base: this.general.base_anual,
  228. id_periodicidad: this.general.periodicidad,
  229. id_formato_ingreso: this.general.formato_ingreso
  230. },
  231. {
  232. valor_par: false,
  233. valor_nominal: +this.f.valor_nominal.value,
  234. comision_casa_porcentaje: this.f.comision_casa_porcentaje.value,
  235. comision_bolsa_porcentaje: this.f.comision_bolsa_porcentaje.value,
  236. rendimiento_bruto: this.f.rendimiento_bruto.value,
  237. otros_costos: this.f.otros_costos.value,
  238. plazo: this.f.plazo.value,
  239. renta_porcentaje: this.f.renta_porcentaje.value,
  240. //id_formato_ingreso: this.f.formato_ingreso.value,
  241. fecha_operacion: this.f.fecha_operacion.value.singleDate.formatted,
  242. fecha_liquidacion: this.f.fecha_liquidacion.value.singleDate
  243. .formatted,
  244. fecha_ultima_cupon: this.f.fecha_ultima_cupon.value.singleDate
  245. .formatted,
  246. fecha_vencimiento: this.f.fecha_vencimiento.value.singleDate.formatted
  247. }
  248. )
  249. .subscribe(
  250. ans => {
  251. this.ingreso_bruto = ans["result"]["ingreso_bruto"];
  252. this.ingreso_neto = ans["result"]["ingreso_neto"];
  253. this.valor_transado = ans["result"]["valor_transado"];
  254. this.precio_porcentaje = ans["result"]["precio_porcentaje"];
  255. this.rendimiento_neto = ans["result"]["rendimiento_neto"];
  256. this.total_pagar = ans["result"]["total_pagar"];
  257. this.comision_bolsa = ans["result"]["comision_bolsa"];
  258. this.comision_casa = ans["result"]["comision_casa"];
  259. this.plazo = ans["result"]["plazo"];
  260. this.interes_acumulado = ans["result"]["interes_acumulado"];
  261. this.fecha_inicio_vigencia = ans["result"]["fecha_inicio_vigencia"];
  262. this.vcnObject = {
  263. valor_nominal: this.investmentProposalForm.value.valor_nominal,
  264. renta_porcentaje: this.investmentProposalForm.value
  265. .renta_porcentaje,
  266. comision_casa_porcentaje: this.investmentProposalForm.value
  267. .comision_casa_porcentaje,
  268. comision_bolsa_porcentaje: this.investmentProposalForm.value
  269. .comision_bolsa_porcentaje,
  270. comision_casa: ans["result"]["comision_casa"],
  271. comision_bolsa: ans["result"]["comision_bolsa"],
  272. rendimiento_bruto: this.investmentProposalForm.value
  273. .rendimiento_bruto,
  274. otros_costos: this.investmentProposalForm.value.otros_costos,
  275. ingreso_bruto: ans["result"]["ingreso_bruto"],
  276. ingreso_neto: ans["result"]["ingreso_neto"],
  277. valor_transado: ans["result"]["valor_transado"],
  278. precio_porcentaje: ans["result"]["precio_porcentaje"],
  279. rendimiento_neto: ans["result"]["rendimiento_neto"],
  280. total_pagar: ans["result"]["total_pagar"],
  281. interes_acumulado: ans["result"]["interes_acumulado"],
  282. fecha_inicio_vigencia: ans["result"]["fecha_inicio_vigencia"],
  283. plazo: this.investmentProposalForm.value.plazo,
  284. //id_formato_ingreso: this.investmentProposalForm.value.id_formato_ingreso,
  285. fecha_operacion: this.investmentProposalForm.value.fecha_operacion
  286. .singleDate.formatted,
  287. fecha_liquidacion:
  288. this.investmentProposalForm.value.fecha_liquidacion.singleDate
  289. .formatted || "",
  290. fecha_ultima_cupon:
  291. this.investmentProposalForm.value.fecha_ultima_cupon != undefined
  292. ? this.investmentProposalForm.value.fecha_ultima_cupon
  293. .singleDate.formatted
  294. : "",
  295. fecha_vencimiento:
  296. this.investmentProposalForm.value.fecha_vencimiento != undefined
  297. ? this.investmentProposalForm.value.fecha_vencimiento.singleDate
  298. .formatted
  299. : ""
  300. };
  301. this.formDataService.setWork(this.vcnObject);
  302. Swal.close();
  303. if (saveForm == true) {
  304. if (this.investmentID != undefined) {
  305. this.router.navigate(["/investment-proposal/complement-info"], {
  306. queryParams: { id: this.investmentID }
  307. });
  308. } else {
  309. this.router.navigate(["/investment-proposal/complement-info"]);
  310. }
  311. }
  312. },
  313. err => {
  314. Swal.fire({
  315. icon: "error",
  316. title: "Error en el servidor",
  317. text: "No su pudo obtener la informacion"
  318. });
  319. return false;
  320. }
  321. );
  322. }
  323. goToPrevious() {
  324. this.submitted = true;
  325. if (this.investmentID != undefined) {
  326. this.router.navigate(["/investment-proposal/general-info"], {
  327. queryParams: { id: this.investmentID }
  328. });
  329. } else {
  330. this.router.navigate(["/investment-proposal/general-info"]);
  331. }
  332. }
  333. goToNext(form: any) {
  334. this.getCalculations(form, true);
  335. }
  336. }