investments.component.ts 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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 { AuthService } from "@app/services/auth2.service";
  9. import { JwtHelperService } from "@auth0/angular-jwt";
  10. import { InvestmentProposal } from "@app/models/investment-proposal";
  11. import { from } from "rxjs";
  12. import { FormInvestmentProposalService } from "@app/services/form-investment-proposal.service";
  13. import { Router } from "@angular/router";
  14. @Component({
  15. selector: "app-investment-proposals",
  16. templateUrl: "./investments.component.html",
  17. styleUrls: ["./investments.component.scss"]
  18. })
  19. export class InvestmentsComponent implements OnInit {
  20. helper = new JwtHelperService();
  21. title: string = "Inversiones activas";
  22. displayedColumns: string[] = [
  23. "codigo_inversion",
  24. "asunto",
  25. "id_tipo_mercado",
  26. "id_inversion_instrumento",
  27. "id"
  28. ];
  29. //displayedColumns: string[] = ['state'];
  30. listProposals: InvestmentProposal[];
  31. dataSource = new MatTableDataSource(this.listProposals);
  32. resultsLength = 0;
  33. isLoadingResults = true;
  34. isRateLimitReached = false;
  35. userRole: any;
  36. @ViewChild(MatPaginator, { static: true }) paginator: MatPaginator;
  37. @ViewChild(MatSort, { static: true }) sort: MatSort;
  38. role_number: any;
  39. constructor(
  40. private catalogService: CatalogsService,
  41. private investmentsService: InvestmentsService,
  42. private authService: AuthService,
  43. private formInvestmentProposal: FormInvestmentProposalService,
  44. private router: Router
  45. ) {
  46. const decodedToken = this.helper.decodeToken(
  47. this.authService.getJwtToken()
  48. );
  49. this.userRole = decodedToken.groups;
  50. // console.log("User role");
  51. // console.log(this.userRole);
  52. //console.log(this.userRole.length == 0);
  53. this.dataSource.filterPredicate = (data, filter) => {
  54. const dataStr =
  55. data.id_inversion_instrumento.id_tipo_instrumento.nombre +
  56. data.codigo_inversion +
  57. data.nombre_inversion +
  58. data.asunto +
  59. data.comentario +
  60. data.justificacion;
  61. return dataStr.indexOf(filter) != -1;
  62. };
  63. Swal.fire({
  64. allowOutsideClick: false,
  65. icon: "info",
  66. text: "Espere por favor..."
  67. });
  68. Swal.showLoading();
  69. }
  70. ngOnInit() {
  71. this.investmentsService.getProposalInvestmentsList().subscribe(
  72. ans => {
  73. this.listProposals = ans.result;
  74. this.listProposals = this.listProposals.filter(
  75. proposals =>
  76. proposals["id_estado_inversion"] != null &&
  77. proposals["id_estado_inversion"]["codigo"] == "FINAL"
  78. );
  79. console.log(this.listProposals);
  80. this.dataSource.data = this.listProposals;
  81. this.dataSource.paginator = this.paginator;
  82. this.dataSource.sort = this.sort;
  83. },
  84. err => {
  85. Swal.fire({
  86. icon: "error",
  87. title: "Error en el servidor",
  88. text: err.message
  89. });
  90. }
  91. );
  92. setTimeout(() => {
  93. Swal.close();
  94. }, 1200);
  95. }
  96. applyFilter(event: Event) {
  97. const filterValue = (event.target as HTMLInputElement).value;
  98. this.dataSource.filter = filterValue;
  99. if (this.dataSource.paginator) {
  100. this.dataSource.paginator.firstPage();
  101. }
  102. }
  103. view_investment_proposal(id: string) {
  104. this.formInvestmentProposal.resetFormData();
  105. Swal.fire({
  106. allowOutsideClick: false,
  107. icon: "info",
  108. text: "Espere por favor..."
  109. });
  110. Swal.showLoading();
  111. setTimeout(() => {
  112. this.router.navigate([`/investment-proposal/${id}`]);
  113. }, 1000);
  114. }
  115. instrument_has_costs(instrument: any) {
  116. switch (instrument.id_tipo_instrumento.codigo) {
  117. case "VCN":
  118. case "PBUR":
  119. if (instrument.id_inversion_instrumento.valor_par == true) {
  120. return true;
  121. } else {
  122. return false;
  123. }
  124. break;
  125. case "CETE":
  126. case "DAP":
  127. return true;
  128. break;
  129. default:
  130. return false;
  131. }
  132. }
  133. go_to_instrument_url(id: string, code: string, route: string) {
  134. Swal.fire({
  135. allowOutsideClick: false,
  136. icon: "info",
  137. text: "Espere por favor..."
  138. });
  139. Swal.showLoading();
  140. setTimeout(() => {
  141. this.router.navigate([
  142. `/investment-${route}/${code.toLowerCase()}/${id}`
  143. ]);
  144. }, 1000);
  145. }
  146. }