investment-proposals.component.ts 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  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.userRole = decodedToken.groups;
  51. // console.log("User role");
  52. // console.log(this.userRole);
  53. //console.log(this.userRole.length == 0);
  54. this.dataSource.filterPredicate = (data, filter) => {
  55. const dataStr =
  56. data.id_inversion_instrumento.id_tipo_instrumento.nombre.toLowerCase() +
  57. data.id_estado_inversion.nombre.toLowerCase() +
  58. data.codigo_inversion.toLowerCase() +
  59. data.nombre_inversion.toLowerCase() +
  60. data.asunto.toLowerCase() +
  61. data.comentario.toLowerCase() +
  62. data.justificacion.toLowerCase();
  63. return dataStr.indexOf(filter) != -1;
  64. };
  65. Swal.fire({
  66. allowOutsideClick: false,
  67. icon: "info",
  68. text: "Espere por favor..."
  69. });
  70. Swal.showLoading();
  71. }
  72. ngOnInit() {
  73. this.investmentsService.getProposalInvestmentsList().subscribe(
  74. ans => {
  75. this.listProposals = ans.result;
  76. console.log(this.listProposals);
  77. this.dataSource.data = this.listProposals;
  78. this.dataSource.paginator = this.paginator;
  79. this.dataSource.sort = this.sort;
  80. },
  81. err => {
  82. Swal.fire({
  83. icon: "error",
  84. title: "Error en el servidor",
  85. text: err.message
  86. });
  87. }
  88. );
  89. setTimeout(() => {
  90. Swal.close();
  91. }, 1200);
  92. }
  93. applyFilter(event: Event) {
  94. const filterValue = (event.target as HTMLInputElement).value.toLowerCase();
  95. this.dataSource.filter = filterValue;
  96. if (this.dataSource.paginator) {
  97. this.dataSource.paginator.firstPage();
  98. }
  99. }
  100. view_investment_proposal(id: string) {
  101. this.formInvestmentProposal.resetFormData();
  102. Swal.fire({
  103. allowOutsideClick: false,
  104. icon: "info",
  105. text: "Espere por favor..."
  106. });
  107. Swal.showLoading();
  108. setTimeout(() => {
  109. this.router.navigate([`/investment-proposal/${id}`]);
  110. }, 1000);
  111. }
  112. modify_investment_proposal(id: string) {
  113. this.formInvestmentProposal.resetFormData();
  114. Swal.fire({
  115. allowOutsideClick: false,
  116. icon: "info",
  117. text: "Espere por favor..."
  118. });
  119. Swal.showLoading();
  120. setTimeout(() => {
  121. this.router.navigate(["/investment-proposal/general-info"], {
  122. queryParams: { id: id }
  123. });
  124. }, 1000);
  125. }
  126. create_investment_proposal() {
  127. this.formInvestmentProposal.resetFormData();
  128. Swal.fire({
  129. allowOutsideClick: false,
  130. icon: "info",
  131. text: "Espere por favor..."
  132. });
  133. Swal.showLoading();
  134. setTimeout(() => {
  135. this.router.navigate(["/investment-proposal/general-info"], {});
  136. }, 1000);
  137. }
  138. // Verifica permisos para mostrar boton de edicion y/o envio a revision,
  139. // segun los permisos del usuario y el estado de la propuesta
  140. can_modify_or_send_to_review(status: string) {
  141. if (status == "NUEVA" && (this.userRole.length == 0 || this.userRole)) {
  142. // TO DO ver que el codigo de los tipos de usuario
  143. return true;
  144. } else {
  145. return false;
  146. }
  147. }
  148. can_review(status: string) {
  149. if (status == "PENDI" && (this.userRole.length == 0 || this.userRole)) {
  150. // TO DO ver que el codigo de los tipos de usuario
  151. return true;
  152. } else {
  153. return false;
  154. }
  155. }
  156. can_approve(status: string) {
  157. if (status == "REVIS" && (this.userRole.length == 0 || this.userRole)) {
  158. // TO DO ver que el codigo de los tipos de usuario
  159. return true;
  160. } else {
  161. return false;
  162. }
  163. }
  164. can_write_payment_info(status: string) {
  165. if (status == "APROB" && (this.userRole.length == 0 || this.userRole)) {
  166. // TO DO ver que el codigo de los tipos de usuario
  167. return true;
  168. } else {
  169. return false;
  170. }
  171. }
  172. can_upload_payment(status: string) {
  173. if (status == "COMPR" && (this.userRole.length == 0 || this.userRole)) {
  174. // TO DO ver que el codigo de los tipos de usuario
  175. return true;
  176. } else {
  177. return false;
  178. }
  179. }
  180. can_finish_proposal(status: string) {
  181. if (status == "LIQUI" && (this.userRole.length == 0 || this.userRole)) {
  182. // TO DO ver que el codigo de los tipos de usuario
  183. return true;
  184. } else {
  185. return false;
  186. }
  187. }
  188. sendToReview(investmentProposalID: number, investmentCode: string) {
  189. (async () => {
  190. const { value: comentario } = await Swal.fire({
  191. title: `<h3>Enviar a revisión propuesta de inversión ${investmentCode}</h3>`,
  192. icon: "info",
  193. html: `<p style="text-align:left;">Comentario:</p>`,
  194. input: "textarea",
  195. showCancelButton: true,
  196. confirmButtonText: "Enviar propuesta",
  197. cancelButtonText: "Cancelar",
  198. // inputValidator: value => {
  199. // if (!value) {
  200. // return "Debe ingresar un comentario";
  201. // }
  202. // }
  203. });
  204. //if (comentario) {
  205. let reviewProposal = {
  206. id_inversion: investmentProposalID,
  207. step: "next",
  208. comentario: comentario
  209. };
  210. this.investmentsService
  211. .sendReviewProposalInvestment(reviewProposal)
  212. .subscribe(
  213. success => {
  214. if (success) {
  215. Swal.fire({
  216. allowOutsideClick: false,
  217. icon: "success",
  218. showCancelButton: false,
  219. title: "Exito",
  220. confirmButtonText: "La propuesta ha sido enviada a revisión"
  221. }).then(result => {
  222. Swal.close();
  223. window.location.reload();
  224. });
  225. }
  226. },
  227. err => {
  228. Swal.fire({
  229. icon: "error",
  230. title: "Error al guardar",
  231. text: err.message
  232. });
  233. }
  234. );
  235. //}
  236. })();
  237. }
  238. userType(userRole: any) {
  239. switch (+userRole) {
  240. case 0:
  241. return "Invitado";
  242. case 1:
  243. return "Usuario";
  244. case 2:
  245. return "Administrador";
  246. case 3:
  247. return "Super Admin";
  248. }
  249. }
  250. }