investment-proposals.component.ts 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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: "./investment-proposals.component.html",
  17. styleUrls: ["./investment-proposals.component.scss"]
  18. })
  19. export class InvestmentProposalsComponent implements OnInit {
  20. helper = new JwtHelperService();
  21. title: string = "Propuestas de inversión";
  22. displayedColumns: string[] = [
  23. "codigo_inversion",
  24. "asunto",
  25. "id_tipo_mercado",
  26. "id_inversion_instrumento",
  27. "id_estado_inversion",
  28. "id"
  29. ];
  30. //displayedColumns: string[] = ['state'];
  31. listProposals: InvestmentProposal[];
  32. dataSource = new MatTableDataSource(this.listProposals);
  33. resultsLength = 0;
  34. isLoadingResults = true;
  35. isRateLimitReached = false;
  36. userRole: any;
  37. @ViewChild(MatPaginator, { static: true }) paginator: MatPaginator;
  38. @ViewChild(MatSort, { static: true }) sort: MatSort;
  39. role_number: any;
  40. constructor(
  41. private catalogService: CatalogsService,
  42. private investmentsService: InvestmentsService,
  43. private authService: AuthService,
  44. private formInvestmentProposal: FormInvestmentProposalService,
  45. private router: Router
  46. ) {
  47. const decodedToken = this.helper.decodeToken(
  48. this.authService.getJwtToken()
  49. );
  50. this.catalogService.getGenericURL("empresas").subscribe(ans => {
  51. console.log(ans);
  52. console.log("--empresas");
  53. });
  54. console.log(decodedToken);
  55. this.userRole = decodedToken.groups;
  56. // console.log("User role");
  57. // console.log(this.userRole);
  58. //console.log(this.userRole.length == 0);
  59. this.dataSource.filterPredicate = (data, filter) => {
  60. const dataStr =
  61. data.id_inversion_instrumento.id_tipo_instrumento.nombre +
  62. data.id_estado_inversion.nombre +
  63. data.codigo_inversion +
  64. data.nombre_inversion +
  65. data.asunto +
  66. data.comentario +
  67. data.justificacion;
  68. return dataStr.indexOf(filter) != -1;
  69. };
  70. Swal.fire({
  71. allowOutsideClick: false,
  72. icon: "info",
  73. text: "Espere por favor..."
  74. });
  75. Swal.showLoading();
  76. }
  77. ngOnInit() {
  78. this.investmentsService.getProposalInvestmentsList().subscribe(
  79. ans => {
  80. this.listProposals = ans.result;
  81. console.log(this.listProposals);
  82. this.dataSource.data = this.listProposals;
  83. this.dataSource.paginator = this.paginator;
  84. this.dataSource.sort = this.sort;
  85. },
  86. err => {
  87. Swal.fire({
  88. icon: "error",
  89. title: "Error en el servidor",
  90. text: err.message
  91. });
  92. }
  93. );
  94. setTimeout(() => {
  95. Swal.close();
  96. }, 1200);
  97. }
  98. applyFilter(event: Event) {
  99. const filterValue = (event.target as HTMLInputElement).value;
  100. this.dataSource.filter = filterValue;
  101. if (this.dataSource.paginator) {
  102. this.dataSource.paginator.firstPage();
  103. }
  104. }
  105. view_investment_proposal(id: string) {
  106. this.formInvestmentProposal.resetFormData();
  107. Swal.fire({
  108. allowOutsideClick: false,
  109. icon: "info",
  110. text: "Espere por favor..."
  111. });
  112. Swal.showLoading();
  113. setTimeout(() => {
  114. this.router.navigate([`/investment-proposal/${id}`]);
  115. }, 1000);
  116. }
  117. modify_investment_proposal(id: string) {
  118. this.formInvestmentProposal.resetFormData();
  119. Swal.fire({
  120. allowOutsideClick: false,
  121. icon: "info",
  122. text: "Espere por favor..."
  123. });
  124. Swal.showLoading();
  125. setTimeout(() => {
  126. this.router.navigate(["/investment-proposal/general-info"], {
  127. queryParams: { id: id }
  128. });
  129. }, 1000);
  130. }
  131. create_investment_proposal() {
  132. this.formInvestmentProposal.resetFormData();
  133. Swal.fire({
  134. allowOutsideClick: false,
  135. icon: "info",
  136. text: "Espere por favor..."
  137. });
  138. Swal.showLoading();
  139. setTimeout(() => {
  140. this.router.navigate(["/investment-proposal/general-info"], {});
  141. }, 1000);
  142. }
  143. // Verifica permisos para mostrar boton de edicion y/o envio a revision,
  144. // segun los permisos del usuario y el estado de la propuesta
  145. can_modify_or_send_to_review(status: string) {
  146. if (status == "NUEVA" && (this.userRole.length == 0 || this.userRole)) {
  147. // TO DO ver que el codigo de los tipos de usuario
  148. return true;
  149. } else {
  150. return false;
  151. }
  152. }
  153. can_review(status: string) {
  154. if (status == "PENDI" && (this.userRole.length == 0 || this.userRole)) {
  155. // TO DO ver que el codigo de los tipos de usuario
  156. return true;
  157. } else {
  158. return false;
  159. }
  160. }
  161. can_write_payment_info(status: string) {
  162. if (status == "REVIS" && (this.userRole.length == 0 || this.userRole)) {
  163. // TO DO ver que el codigo de los tipos de usuario
  164. return true;
  165. } else {
  166. return false;
  167. }
  168. }
  169. sendToReview(investmentProposalID: number, investmentCode: string) {
  170. (async () => {
  171. const { value: comentario } = await Swal.fire({
  172. title: `<h3>Enviar a revisión propuesta de inversión ${investmentCode}</h3>`,
  173. icon: "info",
  174. input: "textarea",
  175. showCancelButton: true,
  176. confirmButtonText: "Enviar propuesta",
  177. cancelButtonText: "Cancelar",
  178. inputValidator: value => {
  179. if (!value) {
  180. return "Debe ingresar un comentario";
  181. }
  182. }
  183. });
  184. if (comentario) {
  185. let reviewProposal = {
  186. id_inversion: investmentProposalID,
  187. step: "next",
  188. comentario: comentario
  189. };
  190. this.investmentsService
  191. .sendReviewProposalInvestment(reviewProposal)
  192. .subscribe(
  193. success => {
  194. if (success) {
  195. Swal.fire({
  196. allowOutsideClick: false,
  197. icon: "success",
  198. showCancelButton: false,
  199. title: "Exito",
  200. confirmButtonText: "La propuesta ha sido enviada a revisión"
  201. }).then(result => {
  202. Swal.close();
  203. window.location.reload();
  204. });
  205. }
  206. },
  207. err => {
  208. Swal.fire({
  209. icon: "error",
  210. title: "Error al guardar",
  211. text: err.message
  212. });
  213. }
  214. );
  215. }
  216. })();
  217. }
  218. userType(userRole: any) {
  219. switch (+userRole) {
  220. case 0:
  221. return "Invitado";
  222. case 1:
  223. return "Usuario";
  224. case 2:
  225. return "Administrador";
  226. case 3:
  227. return "Super Admin";
  228. }
  229. }
  230. }