investment-proposals.component.ts 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  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_empresa",
  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. this.dataSource.filterPredicate = (data, filter) => {
  52. const dataStr =
  53. data.id_inversion_instrumento.id_tipo_instrumento.nombre.toLowerCase() +
  54. data.id_estado_inversion.nombre.toLowerCase() +
  55. data.codigo_inversion.toLowerCase() +
  56. data.nombre_inversion.toLowerCase() +
  57. data.asunto.toLowerCase() +
  58. data.id_empresa.nombre.toLowerCase() +
  59. data.comentario.toLowerCase() +
  60. data.justificacion.toLowerCase();
  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. /*
  75. if (this.userType(this.userRole, "analistas")) {
  76. this.listProposals;
  77. } else if (this.userType(this.userRole, "contabilidad")) {
  78. this.listProposals = this.listProposals.filter(proposals =>
  79. ["COMPR", "LIQUI"].includes(
  80. proposals["id_estado_inversion"]["codigo"]
  81. )
  82. );
  83. } else if (this.userType(this.userRole, "autorizadores")) {
  84. this.listProposals = this.listProposals.filter(proposals =>
  85. ["REVIS", "APROB", "FINAL"].includes(
  86. proposals["id_estado_inversion"]["codigo"]
  87. )
  88. );
  89. } else if (this.userType(this.userRole, "supervisores")) {
  90. this.listProposals = this.listProposals.filter(proposals =>
  91. ["PENDI", "REVIS", "FINAL"].includes(
  92. proposals["id_estado_inversion"]["codigo"]
  93. )
  94. );
  95. }*/
  96. this.dataSource.data = this.listProposals;
  97. this.dataSource.paginator = this.paginator;
  98. this.dataSource.sort = this.sort;
  99. },
  100. err => {
  101. Swal.fire({
  102. icon: "error",
  103. title: "Error en el servidor",
  104. text: err.message
  105. });
  106. }
  107. );
  108. setTimeout(() => {
  109. Swal.close();
  110. }, 2000);
  111. }
  112. applyFilter(event: Event) {
  113. const filterValue = (event.target as HTMLInputElement).value.toLowerCase();
  114. this.dataSource.filter = filterValue;
  115. if (this.dataSource.paginator) {
  116. this.dataSource.paginator.firstPage();
  117. }
  118. }
  119. view_investment_proposal(id: string) {
  120. this.formInvestmentProposal.resetFormData();
  121. Swal.fire({
  122. allowOutsideClick: false,
  123. icon: "info",
  124. text: "Espere por favor..."
  125. });
  126. Swal.showLoading();
  127. setTimeout(() => {
  128. this.router.navigate([`/investment-proposal/${id}`]);
  129. }, 1000);
  130. }
  131. modify_investment_proposal(id: string) {
  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. queryParams: { id: id }
  142. });
  143. }, 1000);
  144. }
  145. create_investment_proposal() {
  146. this.formInvestmentProposal.resetFormData();
  147. Swal.fire({
  148. allowOutsideClick: false,
  149. icon: "info",
  150. text: "Espere por favor..."
  151. });
  152. Swal.showLoading();
  153. setTimeout(() => {
  154. this.router.navigate(["/investment-proposal/general-info"], {});
  155. }, 1000);
  156. }
  157. can_modify(status: string) {
  158. if (
  159. status == "NUEVA" ||
  160. status == "RECHA" ||
  161. status == "APROB" ||
  162. status == "LIQUI"
  163. ) {
  164. return true;
  165. } else {
  166. return false;
  167. }
  168. }
  169. // Verifica permisos para mostrar boton de edicion y/o envio a revision,
  170. // segun los permisos del usuario y el estado de la propuesta
  171. can_modify_or_send_to_review(status: string) {
  172. if (status == "NUEVA" || status == "RECHA") {
  173. return true;
  174. } else {
  175. return false;
  176. }
  177. }
  178. can_review(status: string) {
  179. if (status == "PENDI" || status == "NOAPR") {
  180. return true;
  181. } else {
  182. return false;
  183. }
  184. }
  185. can_approve(status: string) {
  186. if (status == "REVIS") {
  187. return true;
  188. } else {
  189. return false;
  190. }
  191. }
  192. can_write_payment_info(status: string) {
  193. if (status == "APROB") {
  194. return true;
  195. } else {
  196. return false;
  197. }
  198. }
  199. can_upload_payment(status: string) {
  200. if (status == "COMPR") {
  201. return true;
  202. } else {
  203. return false;
  204. }
  205. }
  206. can_finish_proposal(status: string) {
  207. if (status == "LIQUI") {
  208. return true;
  209. } else {
  210. return false;
  211. }
  212. }
  213. sendToReview(investmentProposalID: number, investmentCode: string) {
  214. (async () => {
  215. const { value: comentario } = await Swal.fire({
  216. title: `<h3>Enviar a revisión propuesta de inversión ${investmentCode}</h3>`,
  217. icon: "info",
  218. html: `<p style="text-align:left;">Comentario:</p>`,
  219. input: "textarea",
  220. showCancelButton: true,
  221. confirmButtonText: "Enviar propuesta",
  222. cancelButtonText: "Cancelar",
  223. showLoaderOnConfirm: true,
  224. // inputValidator: value => {
  225. // if (!value) {
  226. // return "Debe ingresar un comentario";
  227. // }
  228. // }
  229. preConfirm: comentario => {
  230. let reviewProposal = {
  231. id_inversion: investmentProposalID,
  232. step: "next",
  233. comentario: comentario
  234. };
  235. this.investmentsService
  236. .sendReviewProposalInvestment(reviewProposal)
  237. .subscribe(
  238. success => {
  239. if (success) {
  240. Swal.fire({
  241. allowOutsideClick: false,
  242. icon: "success",
  243. showCancelButton: false,
  244. title: "Exito",
  245. confirmButtonText: "La propuesta ha sido enviada a revisión"
  246. }).then(result => {
  247. Swal.close();
  248. window.location.reload();
  249. });
  250. }
  251. },
  252. err => {
  253. Swal.fire({
  254. icon: "error",
  255. title: "Error al guardar",
  256. text: err.message
  257. });
  258. }
  259. );
  260. },
  261. allowOutsideClick: () => !Swal.isLoading()
  262. });
  263. })();
  264. }
  265. //Enviar a revision la propuesta de inversion
  266. finishProposal(investmentProposalID: number, investmentCode: string) {
  267. (async () => {
  268. const { value: comentario } = await Swal.fire({
  269. title: `<h3>Finalizar propuesta de inversión: ${investmentCode}</h3>`,
  270. icon: "info",
  271. input: "textarea",
  272. html: `<p style="text-align:left;">Comentario:</p>`,
  273. showCancelButton: true,
  274. confirmButtonText: "Finalizar",
  275. cancelButtonText: "Cancelar",
  276. onOpen: () => {
  277. Swal.showLoading();
  278. },
  279. preConfirm: comentario => {
  280. let reviewProposal = {
  281. id_inversion: investmentProposalID,
  282. step: "next",
  283. comentario: comentario
  284. };
  285. this.investmentsService
  286. .sendReviewProposalInvestment(reviewProposal)
  287. .subscribe(
  288. success => {
  289. if (success) {
  290. Swal.fire({
  291. allowOutsideClick: false,
  292. icon: "success",
  293. showCancelButton: false,
  294. title: "Exito",
  295. confirmButtonText: "La propuesta ha sido finalizada"
  296. }).then(result => {
  297. Swal.close();
  298. window.location.reload();
  299. });
  300. }
  301. },
  302. err => {
  303. Swal.fire({
  304. icon: "error",
  305. title: "Error al guardar",
  306. text: err.message
  307. });
  308. }
  309. );
  310. }
  311. });
  312. })();
  313. }
  314. userType(userRole: any, requiredRole: any) {
  315. if (userRole.length == 0) {
  316. return true;
  317. }
  318. return userRole.includes(requiredRole);
  319. }
  320. }