| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166 |
- import { Component, ViewChild, OnInit } from "@angular/core";
- import { MatPaginator } from "@angular/material/paginator";
- import { MatSort } from "@angular/material/sort";
- import { MatTableDataSource } from "@angular/material/table";
- import Swal from "sweetalert2";
- import { CatalogsService } from "src/app/services/catalogs.service";
- import { InvestmentsService } from "@app/services/investments.service";
- import { AuthService } from "@app/services/auth2.service";
- import { JwtHelperService } from "@auth0/angular-jwt";
- import { InvestmentProposal } from "@app/models/investment-proposal";
- import { from } from "rxjs";
- import { FormInvestmentProposalService } from "@app/services/form-investment-proposal.service";
- import { Router } from "@angular/router";
- @Component({
- selector: "app-investment-proposals",
- templateUrl: "./investments.component.html",
- styleUrls: ["./investments.component.scss"]
- })
- export class InvestmentsComponent implements OnInit {
- helper = new JwtHelperService();
- title: string = "Inversiones activas";
- displayedColumns: string[] = [
- "codigo_inversion",
- "asunto",
- "id_tipo_mercado",
- "id_inversion_instrumento",
- "id"
- ];
- //displayedColumns: string[] = ['state'];
- listProposals: InvestmentProposal[];
- dataSource = new MatTableDataSource(this.listProposals);
- resultsLength = 0;
- isLoadingResults = true;
- isRateLimitReached = false;
- userRole: any;
- @ViewChild(MatPaginator, { static: true }) paginator: MatPaginator;
- @ViewChild(MatSort, { static: true }) sort: MatSort;
- role_number: any;
- constructor(
- private catalogService: CatalogsService,
- private investmentsService: InvestmentsService,
- private authService: AuthService,
- private formInvestmentProposal: FormInvestmentProposalService,
- private router: Router
- ) {
- const decodedToken = this.helper.decodeToken(
- this.authService.getJwtToken()
- );
- this.userRole = decodedToken.groups;
- // console.log("User role");
- // console.log(this.userRole);
- //console.log(this.userRole.length == 0);
- this.dataSource.filterPredicate = (data, filter) => {
- const dataStr =
- data.id_inversion_instrumento.id_tipo_instrumento.nombre +
- data.codigo_inversion +
- data.nombre_inversion +
- data.asunto +
- data.comentario +
- data.justificacion;
- return dataStr.indexOf(filter) != -1;
- };
- Swal.fire({
- allowOutsideClick: false,
- icon: "info",
- text: "Espere por favor..."
- });
- Swal.showLoading();
- }
- ngOnInit() {
- this.investmentsService.getProposalInvestmentsList().subscribe(
- ans => {
- this.listProposals = ans.result;
- this.listProposals = this.listProposals.filter(
- proposals =>
- proposals["id_estado_inversion"] != null &&
- proposals["id_estado_inversion"]["codigo"] == "FINAL"
- );
- console.log(this.listProposals);
- this.dataSource.data = this.listProposals;
- this.dataSource.paginator = this.paginator;
- this.dataSource.sort = this.sort;
- },
- err => {
- Swal.fire({
- icon: "error",
- title: "Error en el servidor",
- text: err.message
- });
- }
- );
- setTimeout(() => {
- Swal.close();
- }, 1200);
- }
- applyFilter(event: Event) {
- const filterValue = (event.target as HTMLInputElement).value;
- this.dataSource.filter = filterValue;
- if (this.dataSource.paginator) {
- this.dataSource.paginator.firstPage();
- }
- }
- view_investment_proposal(id: string) {
- this.formInvestmentProposal.resetFormData();
- Swal.fire({
- allowOutsideClick: false,
- icon: "info",
- text: "Espere por favor..."
- });
- Swal.showLoading();
- setTimeout(() => {
- this.router.navigate([`/investment-proposal/${id}`]);
- }, 1000);
- }
- instrument_has_costs(instrument: any) {
- switch (instrument.id_tipo_instrumento.codigo) {
- case "VCN":
- case "PBUR":
- if (instrument.id_inversion_instrumento.valor_par == true) {
- return true;
- } else {
- return false;
- }
- break;
- case "CETE":
- case "DAP":
- return true;
- break;
- default:
- return false;
- }
- }
- go_to_instrument_url(id: string, code: string, route: string) {
- Swal.fire({
- allowOutsideClick: false,
- icon: "info",
- text: "Espere por favor..."
- });
- Swal.showLoading();
- setTimeout(() => {
- this.router.navigate([
- `/investment-${route}/${code.toLowerCase()}/${id}`
- ]);
- }, 1000);
- }
- }
|