dap.costs.component.ts 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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, ActivatedRoute } from "@angular/router";
  14. import { FormBuilder, FormGroup, FormControl, FormArray } from "@angular/forms";
  15. @Component({
  16. selector: "app-dap-costs",
  17. templateUrl: "./dap.costs.component.html"
  18. //styleUrls: ["./dap.costs.component.scss"]
  19. })
  20. export class DAPCostsComponent implements OnInit {
  21. helper = new JwtHelperService();
  22. title: string = "Costos para depósito a plazo";
  23. displayedColumns: string[] = [
  24. "codigo_inversion",
  25. "asunto",
  26. "id_tipo_mercado",
  27. "id_inversion_instrumento",
  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. investmentProposalID: string;
  41. form: FormArray;
  42. proyecciones: any;
  43. proyeccionesProps = [];
  44. dataRetrieved: boolean = false;
  45. array1;
  46. array2;
  47. array3;
  48. constructor(
  49. private catalogService: CatalogsService,
  50. private investmentsService: InvestmentsService,
  51. private authService: AuthService,
  52. private formInvestmentProposal: FormInvestmentProposalService,
  53. private router: Router,
  54. private route: ActivatedRoute,
  55. private formBuilder: FormBuilder
  56. ) {
  57. const decodedToken = this.helper.decodeToken(
  58. this.authService.getJwtToken()
  59. );
  60. this.userRole = decodedToken.groups;
  61. // console.log("User role");
  62. // console.log(this.userRole);
  63. //console.log(this.userRole.length == 0);
  64. Swal.fire({
  65. allowOutsideClick: false,
  66. icon: "info",
  67. text: "Espere por favor..."
  68. });
  69. Swal.showLoading();
  70. }
  71. ngOnInit() {
  72. Swal.close();
  73. const formDataObj = {};
  74. this.route.params.subscribe(params => {
  75. this.investmentProposalID = params["id"];
  76. });
  77. if (this.investmentProposalID == undefined)
  78. this.investmentProposalID = this.route.snapshot.queryParamMap.get("id");
  79. if (this.investmentProposalID != undefined) {
  80. this.investmentsService
  81. .getProposalInvestment(this.investmentProposalID)
  82. .subscribe(
  83. res => {
  84. this.proyecciones =
  85. res["result"]["id_inversion_instrumento"]["instrumento"][
  86. "proyecciones"
  87. ];
  88. this.form = new FormArray(this.buildForm(this.proyecciones));
  89. /*
  90. this.array1 = [];
  91. this.array2 = [];
  92. for (var i = 0; i < this.proyecciones.length; i++) {
  93. this.array2 = [];
  94. for (const prop2 of Object.keys(this.proyecciones[i])) {
  95. this.array3 = [];
  96. formDataObj[prop2] = new FormControl(
  97. this.proyecciones[i][prop2]
  98. );
  99. this.proyeccionesProps.push(prop2);
  100. this.array3.push(prop2);
  101. this.array2.push(this.array3);
  102. }
  103. this.array1.push(this.array2);
  104. }
  105. console.log(this.array1);
  106. this.form = new FormGroup(formDataObj);
  107. console.log(this.form);
  108. */
  109. this.dataRetrieved = true;
  110. },
  111. err => {
  112. Swal.fire({
  113. icon: "error",
  114. title: "Error en el servidor",
  115. text: err.message
  116. });
  117. }
  118. );
  119. }
  120. setTimeout(() => {
  121. Swal.close();
  122. }, 1200);
  123. }
  124. buildForm(items: any[]): FormGroup[] {
  125. return items.map(x => this.buildItem(x));
  126. }
  127. //return a formGroup
  128. buildItem(item: any): FormGroup {
  129. return new FormGroup({
  130. id_proyeccion_ingreso: new FormControl(item.id_proyeccion_ingreso),
  131. posicion: new FormControl(item.posicion),
  132. plazo: new FormControl(item.plazo),
  133. fecha_pago: new FormControl(item.fecha_pago),
  134. ingreso_bruto: new FormControl(item.ingreso_bruto),
  135. renta: new FormControl(item.renta),
  136. ingreso_neto: new FormControl(item.ingreso_neto),
  137. id_deposito_plazo: new FormControl(item.id_deposito_plazo)
  138. });
  139. }
  140. applyFilter(event: Event) {
  141. const filterValue = (event.target as HTMLInputElement).value;
  142. this.dataSource.filter = filterValue;
  143. if (this.dataSource.paginator) {
  144. this.dataSource.paginator.firstPage();
  145. }
  146. }
  147. view_investment_proposal(id: string) {
  148. this.formInvestmentProposal.resetFormData();
  149. Swal.fire({
  150. allowOutsideClick: false,
  151. icon: "info",
  152. text: "Espere por favor..."
  153. });
  154. Swal.showLoading();
  155. setTimeout(() => {
  156. this.router.navigate([`/investment-proposal/${id}`]);
  157. }, 1000);
  158. }
  159. modify_investment_proposal(id: string) {
  160. this.formInvestmentProposal.resetFormData();
  161. Swal.fire({
  162. allowOutsideClick: false,
  163. icon: "info",
  164. text: "Espere por favor..."
  165. });
  166. Swal.showLoading();
  167. setTimeout(() => {
  168. this.router.navigate(["/investment-proposal/general-info"], {
  169. queryParams: { id: id }
  170. });
  171. }, 1000);
  172. }
  173. // Verifica permisos para mostrar boton de edicion y/o envio a revision,
  174. // segun los permisos del usuario y el estado de la propuesta
  175. can_modify_or_send_to_review(status: string) {
  176. if (status == "NUEVA" && (this.userRole.length == 0 || this.userRole)) {
  177. // TO DO ver que el codigo de los tipos de usuario
  178. return true;
  179. } else {
  180. return false;
  181. }
  182. }
  183. }