pbur.costs.component.ts 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. import { Component, ViewChild, OnInit } from "@angular/core";
  2. import { MatPaginator } from "@angular/material/paginator";
  3. import { MatSort } from "@angular/material/sort";
  4. import { MatTableDataSource } from "@angular/material/table";
  5. import Swal from "sweetalert2";
  6. import { CatalogsService } from "src/app/services/catalogs.service";
  7. import { InvestmentsService } from "@app/services/investments.service";
  8. import { InstrumentCalculations } from "@app/services/instrument-calculations.service";
  9. import { AuthService } from "@app/services/auth2.service";
  10. import { JwtHelperService } from "@auth0/angular-jwt";
  11. import { InvestmentProposal } from "@app/models/investment-proposal";
  12. import { from } from "rxjs";
  13. import { FormInvestmentProposalService } from "@app/services/form-investment-proposal.service";
  14. import { Router, ActivatedRoute } from "@angular/router";
  15. import {
  16. FormBuilder,
  17. FormGroup,
  18. FormControl,
  19. FormArray,
  20. Validators
  21. } from "@angular/forms";
  22. @Component({
  23. selector: "app-pbur-costs",
  24. templateUrl: "./pbur.costs.component.html"
  25. //styleUrls: ["./dap.costs.component.scss"]
  26. })
  27. export class PBURCostsComponent implements OnInit {
  28. helper = new JwtHelperService();
  29. title: string = "Costos para papel bursátil";
  30. displayedColumns: string[] = [
  31. "codigo_inversion",
  32. "asunto",
  33. "id_tipo_mercado",
  34. "id_inversion_instrumento",
  35. "id"
  36. ];
  37. //displayedColumns: string[] = ['state'];
  38. listProposals: InvestmentProposal[];
  39. dataSource = new MatTableDataSource(this.listProposals);
  40. resultsLength = 0;
  41. isLoadingResults = true;
  42. isRateLimitReached = false;
  43. userRole: any;
  44. @ViewChild(MatPaginator, { static: true }) paginator: MatPaginator;
  45. @ViewChild(MatSort, { static: true }) sort: MatSort;
  46. role_number: any;
  47. investmentProposalID: string;
  48. form: FormArray;
  49. investmentProposalForm: FormGroup;
  50. proyecciones: any;
  51. proyeccionesProps = [];
  52. dataRetrieved: boolean = false;
  53. array1;
  54. array2;
  55. array3;
  56. investment: any;
  57. instrument_work: any;
  58. instrument_exists: boolean;
  59. constructor(
  60. private catalogService: CatalogsService,
  61. private investmentsService: InvestmentsService,
  62. private authService: AuthService,
  63. private formInvestmentProposal: FormInvestmentProposalService,
  64. private router: Router,
  65. private route: ActivatedRoute,
  66. private instrumentService: InstrumentCalculations,
  67. private formBuilder: FormBuilder
  68. ) {
  69. const decodedToken = this.helper.decodeToken(
  70. this.authService.getJwtToken()
  71. );
  72. this.userRole = decodedToken.groups;
  73. Swal.fire({
  74. allowOutsideClick: false,
  75. icon: "info",
  76. text: "Espere por favor..."
  77. });
  78. Swal.showLoading();
  79. }
  80. ngOnInit() {
  81. Swal.close();
  82. const formDataObj = {};
  83. this.route.params.subscribe(params => {
  84. this.investmentProposalID = params["id"];
  85. });
  86. if (this.investmentProposalID == undefined)
  87. this.investmentProposalID = this.route.snapshot.queryParamMap.get("id");
  88. if (this.investmentProposalID != undefined) {
  89. this.investmentsService
  90. .getProposalInvestment(this.investmentProposalID)
  91. .subscribe(
  92. res => {
  93. this.investment = res["result"];
  94. this.instrument_work =
  95. res["result"]["id_inversion_instrumento"]["instrumento"];
  96. this.instrument_exists = true;
  97. this.investmentProposalForm = this.formBuilder.group({
  98. valor_par: [
  99. !this.instrument_exists ? false : this.instrument_work.valor_par
  100. ],
  101. valor_nominal: [
  102. !this.instrument_exists
  103. ? ""
  104. : this.instrument_work.valor_nominal,
  105. [
  106. Validators.required,
  107. Validators.pattern(/^[+]?([0-9]+(?:[\.][0-9]*)?|\.[0-9]+)$/)
  108. ]
  109. ],
  110. otros_costos: [
  111. !this.instrument_exists ? 0 : this.instrument_work.otros_costos,
  112. [Validators.pattern(/^[+]?([0-9]+(?:[\.][0-9]*)?|\.[0-9]+)$/)]
  113. ],
  114. plazo: [
  115. !this.instrument_exists ? "" : this.instrument_work.plazo,
  116. [Validators.required]
  117. ],
  118. renta_porcentaje: [
  119. !this.instrument_exists
  120. ? ""
  121. : this.instrument_work.renta_porcentaje,
  122. [Validators.required]
  123. ],
  124. comision_casa_porcentaje: [
  125. !this.instrument_exists
  126. ? ""
  127. : this.instrument_work.comision_casa_porcentaje,
  128. [
  129. Validators.required,
  130. Validators.pattern(/^[+]?([0-9]+(?:[\.][0-9]*)?|\.[0-9]+)$/)
  131. ]
  132. ],
  133. comision_bolsa_porcentaje: [
  134. !this.instrument_exists
  135. ? ""
  136. : this.instrument_work.comision_bolsa_porcentaje,
  137. [
  138. Validators.required,
  139. Validators.pattern(/^[+]?([0-9]+(?:[\.][0-9]*)?|\.[0-9]+)$/)
  140. ]
  141. ],
  142. rendimiento_bruto: [
  143. !this.instrument_exists
  144. ? ""
  145. : this.instrument_work.rendimiento_bruto,
  146. [
  147. Validators.required,
  148. Validators.pattern(/^[+]?([0-9]+(?:[\.][0-9]*)?|\.[0-9]+)$/)
  149. ]
  150. ],
  151. /*formato_ingreso: [
  152. !this.instrument_exists ? "" : this.instrument_work.formato_ingreso,
  153. [Validators.required]
  154. ],*/
  155. fecha_liquidacion: [
  156. !this.instrument_exists
  157. ? ""
  158. : this.instrument_work.fecha_liquidacion,
  159. [Validators.required]
  160. ],
  161. fecha_vencimiento: [
  162. !this.instrument_exists
  163. ? ""
  164. : this.instrument_work.fecha_vencimiento,
  165. [Validators.required]
  166. ],
  167. fecha_operacion: [
  168. !this.instrument_exists
  169. ? ""
  170. : this.instrument_work.fecha_operacion,
  171. [Validators.required]
  172. ],
  173. fecha_ultima_cupon: [
  174. !this.instrument_exists
  175. ? ""
  176. : this.instrument_work.fecha_ultima_cupon,
  177. [Validators.required]
  178. ]
  179. });
  180. },
  181. err => {}
  182. );
  183. this.investmentsService
  184. .getProposalInvestment(this.investmentProposalID)
  185. .subscribe(
  186. res => {
  187. this.proyecciones =
  188. res["result"]["id_inversion_instrumento"]["instrumento"][
  189. "proyecciones"
  190. ];
  191. this.proyecciones.pop();
  192. this.form = new FormArray(this.buildForm(this.proyecciones));
  193. this.dataRetrieved = true;
  194. },
  195. err => {
  196. Swal.fire({
  197. icon: "error",
  198. title: "Error en el servidor",
  199. text: err.message
  200. });
  201. }
  202. );
  203. }
  204. setTimeout(() => {
  205. Swal.close();
  206. }, 1200);
  207. }
  208. recalculateProjectionChanges() {
  209. let objProjection = { proyecciones: this.form.value };
  210. Swal.fire({
  211. allowOutsideClick: false,
  212. icon: "info",
  213. text: "Espere por favor..."
  214. });
  215. Swal.showLoading();
  216. this.instrumentService
  217. .projectionCalc(this.investmentProposalID, this.form.value)
  218. .subscribe(
  219. result => {
  220. Swal.fire({
  221. allowOutsideClick: false,
  222. icon: "success",
  223. showCancelButton: false,
  224. title: "Exito"
  225. });
  226. this.proyecciones = result["result"]["proyecciones"];
  227. this.proyecciones.pop();
  228. this.form.clear();
  229. this.form = new FormArray(this.buildForm(this.proyecciones));
  230. Swal.close();
  231. //window.location.reload();
  232. },
  233. err => {
  234. Swal.fire({
  235. icon: "error",
  236. title: "Error al guardar",
  237. text: err.message
  238. });
  239. }
  240. );
  241. }
  242. saveProjection() {
  243. let objProjection = { proyecciones: this.form.value };
  244. Swal.fire({
  245. allowOutsideClick: false,
  246. icon: "info",
  247. text: "Espere por favor..."
  248. });
  249. Swal.showLoading();
  250. this.instrumentService
  251. .projectionModification(this.investmentProposalID, objProjection)
  252. .subscribe(
  253. resp => {
  254. Swal.fire({
  255. allowOutsideClick: false,
  256. icon: "success",
  257. showCancelButton: false,
  258. title: "Exito",
  259. confirmButtonText: "La información ha sido actualizada"
  260. }).then(result => {
  261. Swal.close();
  262. //window.location.reload();
  263. });
  264. },
  265. err => {
  266. Swal.fire({
  267. icon: "error",
  268. title: "Error al guardar",
  269. text: err.message
  270. });
  271. }
  272. );
  273. }
  274. buildForm(items: any[]): FormGroup[] {
  275. return items.map(x => this.buildItem(x));
  276. }
  277. //return a formGroup
  278. buildItem(item: any): FormGroup {
  279. return new FormGroup({
  280. id_proyeccion_ingreso: new FormControl(item.id_proyeccion_ingreso),
  281. posicion: new FormControl(item.posicion),
  282. plazo: new FormControl(item.plazo),
  283. fecha_pago: new FormControl(item.fecha_pago),
  284. ingreso_bruto: new FormControl(item.ingreso_bruto),
  285. costo_cedeval: new FormControl(item.costo_cedeval),
  286. costo_transferencia: new FormControl(item.costo_transferencia),
  287. costo_banco: new FormControl(item.costo_banco),
  288. otros_costos: new FormControl(item.otros_costos),
  289. renta: new FormControl(item.renta),
  290. ingreso_neto: new FormControl(item.ingreso_neto),
  291. id_valor_comercial: new FormControl(item.id_valor_comercial)
  292. });
  293. }
  294. }