dap.costs.component.ts 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  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 {
  15. FormBuilder,
  16. FormGroup,
  17. FormControl,
  18. FormArray,
  19. Validators
  20. } from "@angular/forms";
  21. @Component({
  22. selector: "app-dap-costs",
  23. templateUrl: "./dap.costs.component.html"
  24. //styleUrls: ["./dap.costs.component.scss"]
  25. })
  26. export class DAPCostsComponent implements OnInit {
  27. helper = new JwtHelperService();
  28. title: string = "Costos para depósito a plazo";
  29. displayedColumns: string[] = [
  30. "codigo_inversion",
  31. "asunto",
  32. "id_tipo_mercado",
  33. "id_inversion_instrumento",
  34. "id"
  35. ];
  36. //displayedColumns: string[] = ['state'];
  37. listProposals: InvestmentProposal[];
  38. dataSource = new MatTableDataSource(this.listProposals);
  39. resultsLength = 0;
  40. isLoadingResults = true;
  41. isRateLimitReached = false;
  42. userRole: any;
  43. @ViewChild(MatPaginator, { static: true }) paginator: MatPaginator;
  44. @ViewChild(MatSort, { static: true }) sort: MatSort;
  45. role_number: any;
  46. investmentProposalID: string;
  47. form: FormArray;
  48. investmentProposalForm: FormGroup;
  49. proyecciones: any;
  50. proyeccionesProps = [];
  51. dataRetrieved: boolean = false;
  52. array1;
  53. array2;
  54. array3;
  55. investment: any;
  56. instrument_work: any;
  57. instrument_exists: boolean;
  58. constructor(
  59. private catalogService: CatalogsService,
  60. private investmentsService: InvestmentsService,
  61. private authService: AuthService,
  62. private formInvestmentProposal: FormInvestmentProposalService,
  63. private router: Router,
  64. private route: ActivatedRoute,
  65. private formBuilder: FormBuilder
  66. ) {
  67. const decodedToken = this.helper.decodeToken(
  68. this.authService.getJwtToken()
  69. );
  70. this.userRole = decodedToken.groups;
  71. Swal.fire({
  72. allowOutsideClick: false,
  73. icon: "info",
  74. text: "Espere por favor..."
  75. });
  76. Swal.showLoading();
  77. }
  78. ngOnInit() {
  79. Swal.close();
  80. const formDataObj = {};
  81. this.route.params.subscribe(params => {
  82. this.investmentProposalID = params["id"];
  83. });
  84. if (this.investmentProposalID == undefined)
  85. this.investmentProposalID = this.route.snapshot.queryParamMap.get("id");
  86. if (this.investmentProposalID != undefined) {
  87. this.investmentsService
  88. .getProposalInvestment(this.investmentProposalID)
  89. .subscribe(
  90. res => {
  91. this.investment = res["result"];
  92. this.instrument_work =
  93. res["result"]["id_inversion_instrumento"]["instrumento"];
  94. this.instrument_exists = true;
  95. this.investmentProposalForm = this.formBuilder.group({
  96. monto_inversion: [
  97. !this.instrument_exists
  98. ? ""
  99. : this.instrument_work.monto_inversion,
  100. [
  101. Validators.required,
  102. Validators.pattern(/^[+]?([0-9]+(?:[\.][0-9]*)?|\.[0-9]+)$/)
  103. ]
  104. ],
  105. renta_porcentaje: [
  106. !this.instrument_exists
  107. ? ""
  108. : this.instrument_work.renta_porcentaje,
  109. [Validators.required]
  110. ],
  111. tasa_porcentaje: [
  112. !this.instrument_exists
  113. ? ""
  114. : this.instrument_work.tasa_porcentaje,
  115. [
  116. Validators.required,
  117. Validators.pattern(/^[+]?([0-9]+(?:[\.][0-9]*)?|\.[0-9]+)$/)
  118. ]
  119. ],
  120. plazo: [
  121. !this.instrument_exists ? "" : this.instrument_work.plazo,
  122. [Validators.required]
  123. ],
  124. /*formato_ingreso: [
  125. !this.instrument_exists ? "" : this.instrument_work.formato_ingreso,
  126. [Validators.required]
  127. ],*/
  128. fecha_vencimiento: [
  129. !this.instrument_exists
  130. ? ""
  131. : this.instrument_work.fecha_vencimiento,
  132. Validators.required
  133. ],
  134. fecha_operacion: [
  135. !this.instrument_exists
  136. ? ""
  137. : this.instrument_work.fecha_operacion,
  138. Validators.required
  139. ]
  140. });
  141. },
  142. err => {}
  143. );
  144. this.investmentsService
  145. .getProposalInvestment(this.investmentProposalID)
  146. .subscribe(
  147. res => {
  148. this.proyecciones =
  149. res["result"]["id_inversion_instrumento"]["instrumento"][
  150. "proyecciones"
  151. ];
  152. this.form = new FormArray(this.buildForm(this.proyecciones));
  153. this.dataRetrieved = true;
  154. this.dataRetrieved = true;
  155. },
  156. err => {
  157. Swal.fire({
  158. icon: "error",
  159. title: "Error en el servidor",
  160. text: err.message
  161. });
  162. }
  163. );
  164. }
  165. setTimeout(() => {
  166. Swal.close();
  167. }, 1200);
  168. }
  169. submitInstrumentChanges() {}
  170. submitProjectionChanges() {
  171. let objProjection = { proyecciones: this.form.value };
  172. Swal.fire({
  173. allowOutsideClick: false,
  174. icon: "info",
  175. text: "Espere por favor..."
  176. });
  177. Swal.showLoading();
  178. this.investmentsService
  179. .updateInstrumentProjection(this.investmentProposalID, objProjection)
  180. .subscribe(
  181. success => {
  182. if (success) {
  183. Swal.fire({
  184. allowOutsideClick: false,
  185. icon: "success",
  186. showCancelButton: false,
  187. title: "Exito",
  188. confirmButtonText: "La información ha sido actualizada"
  189. }).then(result => {
  190. Swal.close();
  191. //window.location.reload();
  192. });
  193. }
  194. },
  195. err => {
  196. Swal.fire({
  197. icon: "error",
  198. title: "Error al guardar",
  199. text: err.message
  200. });
  201. }
  202. );
  203. }
  204. buildForm(items: any[]): FormGroup[] {
  205. return items.map(x => this.buildItem(x));
  206. }
  207. //return a formGroup
  208. buildItem(item: any): FormGroup {
  209. return new FormGroup({
  210. id_proyeccion_ingreso: new FormControl(item.id_proyeccion_ingreso),
  211. posicion: new FormControl(item.posicion),
  212. plazo: new FormControl(item.plazo),
  213. fecha_pago: new FormControl(item.fecha_pago),
  214. ingreso_bruto: new FormControl(item.ingreso_bruto),
  215. renta: new FormControl(item.renta),
  216. ingreso_neto: new FormControl(item.ingreso_neto),
  217. id_deposito_plazo: new FormControl(item.id_deposito_plazo)
  218. });
  219. }
  220. applyFilter(event: Event) {
  221. const filterValue = (event.target as HTMLInputElement).value;
  222. this.dataSource.filter = filterValue;
  223. if (this.dataSource.paginator) {
  224. this.dataSource.paginator.firstPage();
  225. }
  226. }
  227. view_investment_proposal(id: string) {
  228. this.formInvestmentProposal.resetFormData();
  229. Swal.fire({
  230. allowOutsideClick: false,
  231. icon: "info",
  232. text: "Espere por favor..."
  233. });
  234. Swal.showLoading();
  235. setTimeout(() => {
  236. this.router.navigate([`/investment-proposal/${id}`]);
  237. }, 1000);
  238. }
  239. modify_investment_proposal(id: string) {
  240. this.formInvestmentProposal.resetFormData();
  241. Swal.fire({
  242. allowOutsideClick: false,
  243. icon: "info",
  244. text: "Espere por favor..."
  245. });
  246. Swal.showLoading();
  247. setTimeout(() => {
  248. this.router.navigate(["/investment-proposal/general-info"], {
  249. queryParams: { id: id }
  250. });
  251. }, 1000);
  252. }
  253. // Verifica permisos para mostrar boton de edicion y/o envio a revision,
  254. // segun los permisos del usuario y el estado de la propuesta
  255. can_modify_or_send_to_review(status: string) {
  256. if (status == "NUEVA" && (this.userRole.length == 0 || this.userRole)) {
  257. // TO DO ver que el codigo de los tipos de usuario
  258. return true;
  259. } else {
  260. return false;
  261. }
  262. }
  263. }