| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555 |
- 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: "./investment-proposals.component.html",
- styleUrls: ["./investment-proposals.component.scss"]
- })
- export class InvestmentProposalsComponent implements OnInit {
- helper = new JwtHelperService();
- title: string = "Propuestas de inversión";
- displayedColumns: string[] = [
- "codigo_inversion",
- "asunto",
- "id_empresa",
- "id_inversion_instrumento",
- "id_estado_inversion",
- "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;
- test: string;
- userList: any;
- reviewProposal: { id_inversion: number; step: string; comentario: 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;
- this.dataSource.filterPredicate = (data, filter) => {
- const dataStr =
- data.id_inversion_instrumento.id_tipo_instrumento.nombre.toLowerCase() +
- data.id_estado_inversion.nombre.toLowerCase() +
- data.codigo_inversion.toLowerCase() +
- data.nombre_inversion.toLowerCase() +
- data.asunto.toLowerCase() +
- data.id_empresa.nombre.toLowerCase() +
- data.comentario.toLowerCase() +
- data.justificacion.toLowerCase();
- return dataStr.indexOf(filter) != -1;
- };
- Swal.fire({
- allowOutsideClick: false,
- icon: "info",
- text: "Espere por favor..."
- });
- Swal.showLoading();
- }
- ngOnInit() {
- this.investmentsService.getProposalInvestmentsList("propuestas").subscribe(
- ans => {
- this.listProposals = ans.result;
- /*
- if (this.userType(this.userRole, "analistas")) {
- this.listProposals;
- } else if (this.userType(this.userRole, "contabilidad")) {
- this.listProposals = this.listProposals.filter(proposals =>
- ["COMPR", "LIQUI"].includes(
- proposals["id_estado_inversion"]["codigo"]
- )
- );
- } else if (this.userType(this.userRole, "autorizadores")) {
- this.listProposals = this.listProposals.filter(proposals =>
- ["REVIS", "APROB", "FINAL"].includes(
- proposals["id_estado_inversion"]["codigo"]
- )
- );
- } else if (this.userType(this.userRole, "supervisores")) {
- this.listProposals = this.listProposals.filter(proposals =>
- ["PENDI", "REVIS", "FINAL"].includes(
- proposals["id_estado_inversion"]["codigo"]
- )
- );
- }*/
- this.dataSource.data = this.listProposals;
- this.dataSource.paginator = this.paginator;
- this.dataSource.sortingDataAccessor = (item, property) => {
- switch (property) {
- case "id_inversion_instrumento":
- return item.id_inversion_instrumento.id_tipo_instrumento.nombre;
- case "id_estado_inversion":
- return item.id_estado_inversion.nombre;
- case "id_empresa":
- return item.id_empresa.nombre;
- default:
- return item[property];
- }
- };
- this.dataSource.sort = this.sort;
- Swal.close();
- },
- err => {
- Swal.fire({
- icon: "error",
- title: "Error en el servidor",
- text: err.message
- });
- }
- );
- }
- applyFilter(event: Event) {
- const filterValue = (event.target as HTMLInputElement).value.toLowerCase();
- this.dataSource.filter = filterValue;
- if (this.dataSource.paginator) {
- this.dataSource.paginator.firstPage();
- }
- }
- upload_liquidation_file(id: string) {
- this.formInvestmentProposal.resetFormData();
- Swal.fire({
- allowOutsideClick: false,
- icon: "info",
- text: "Espere por favor..."
- });
- Swal.showLoading();
- setTimeout(() => {
- this.router.navigate([`/investment-proposal/${id}/upload-file`]);
- }, 1000);
- }
- 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);
- }
- modify_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/general-info"], {
- queryParams: { id: id }
- });
- }, 1000);
- }
- create_investment_proposal() {
- this.formInvestmentProposal.resetFormData();
- Swal.fire({
- allowOutsideClick: false,
- icon: "info",
- text: "Espere por favor..."
- });
- Swal.showLoading();
- setTimeout(() => {
- this.router.navigate(["/investment-proposal/general-info"], {});
- }, 1000);
- }
- can_modify(status: string) {
- if (
- status == "NUEVA" ||
- status == "RECHA" ||
- status == "APROB" ||
- status == "PGNPR" ||
- status == "LIQUI"
- ) {
- return true;
- } else {
- return false;
- }
- }
- can_upload_file(status: string, file: string) {
- if (
- (status == "APROB" ||
- status == "LIQUI" ||
- status == "COMPR" ||
- status == "PGAPR" ||
- status == "PGNPR" ||
- status == "LIQUI") &&
- file == null
- ) {
- return true;
- } else {
- return false;
- }
- }
- // Verifica permisos para mostrar boton de edicion y/o envio a revision,
- // segun los permisos del usuario y el estado de la propuesta
- can_modify_or_send_to_review(status: string) {
- if (status == "NUEVA" || status == "RECHA") {
- return true;
- } else {
- return false;
- }
- }
- can_review(status: string) {
- if (status == "PENDI" || status == "NOAPR") {
- return true;
- } else {
- return false;
- }
- }
- can_approve(status: string) {
- if (status == "REVIS") {
- return true;
- } else {
- return false;
- }
- }
- can_write_payment_info(status: string) {
- if (status == "APROB" || status == "PGNPR") {
- return true;
- } else {
- return false;
- }
- }
- can_review_payment(status: string) {
- if (status == "COMPR") {
- return true;
- } else {
- return false;
- }
- }
- can_upload_payment(status: string) {
- if (status == "PGAPR") {
- return true;
- } else {
- return false;
- }
- }
- can_finish_proposal(status: string) {
- if (status == "LIQUI") {
- return true;
- } else {
- return false;
- }
- }
- sendToReview(investmentProposalID: number, investmentCode: string) {
- this.investmentsService
- .getAvailableUsers(investmentProposalID)
- .subscribe(res => {
- this.userList = res["usuarios_next"];
- this.test = "<div>Notificar a:</div>";
- if (this.userList.length > 0) {
- for (let i = 0; i < this.userList.length; i++) {
- if (this.userList[i].default_email == true) {
- this.test += `<div class='form-check form-check-inline'><input type='checkbox' class='form-check-input' id='next-${this.userList[i].name}' name='users' value='${this.userList[i].name}' checked='true'><label class='form-check-label' for='next-${this.userList[i].name}'>${this.userList[i].name}</label></div>`;
- } else {
- this.test += `<div class='form-check form-check-inline'><input type='checkbox' class='form-check-input' id='next-${this.userList[i].name}' name='users' value='${this.userList[i].name}'><label class='form-check-label' for='next-${this.userList[i].name}'>${this.userList[i].name}</label></div>`;
- }
- }
- }
- });
- this.reviewProposal = undefined;
- (async () => {
- Swal.fire({
- title: `<h3>Enviar a revisión propuesta de inversión ${investmentCode}</h3>`,
- icon: "info",
- html: `<p style="text-align:left;">Comentario:</p>`,
- input: "textarea",
- showCancelButton: true,
- confirmButtonText: "Enviar propuesta",
- cancelButtonText: "Cancelar",
- allowEscapeKey: true,
- preConfirm: comentario => {
- this.reviewProposal = {
- id_inversion: investmentProposalID,
- step: "next",
- comentario: comentario == null ? "" : comentario
- };
- }
- }).then(result => {
- if (result.dismiss) {
- return false;
- }
- Swal.fire({
- title: `<h3>Enviar a revisión propuesta de inversión ${investmentCode}</h3>`,
- icon: "info",
- html: `${this.test}`,
- confirmButtonText: "Siguiente",
- showCancelButton: true,
- cancelButtonText: "Cancelar",
- showLoaderOnConfirm: true,
- allowEscapeKey: true,
- preConfirm: () => {
- let array = [];
- for (let i = 0; i < this.userList.length; i++) {
- let html_input: HTMLInputElement = document.getElementById(
- "next-" + this.userList[i].name
- ) as HTMLInputElement;
- if (html_input != null) {
- let html_value: string = html_input.value;
- if (html_input.checked == true) {
- array.push(html_value);
- }
- } else {
- array;
- }
- }
- this.reviewProposal["notificar"] = array.toString();
- }
- }).then(result1 => {
- if (result1.dismiss) {
- return false;
- }
- Swal.fire({
- allowOutsideClick: false,
- title: "Espere por favor...",
- icon: "info"
- });
- Swal.showLoading();
- this.investmentsService
- .sendReviewProposalInvestment(this.reviewProposal)
- .subscribe(
- success => {
- if (success) {
- Swal.fire({
- allowOutsideClick: false,
- icon: "success",
- showCancelButton: false,
- title: "Exito",
- confirmButtonText: "La propuesta ha sido enviada a revisión"
- }).then(result => {
- Swal.close();
- window.location.reload();
- });
- }
- },
- err => {
- if (err.code == 405) {
- Swal.fire({
- icon: "error",
- title: "Operacion no permitida",
- text: err.message
- }).then(result => {
- Swal.close();
- window.location.href = "#/investment-proposals";
- });
- } else {
- Swal.fire({
- icon: "error",
- title: "Error al guardar",
- text: err.message
- });
- }
- }
- );
- });
- //window.location.reload();
- });
- })();
- }
- //Enviar a revision la propuesta de inversion
- finishProposal(investmentProposalID: number, investmentCode: string) {
- this.investmentsService
- .getAvailableUsers(investmentProposalID)
- .subscribe(res => {
- this.userList = res["usuarios_next"];
- this.test = "";
- if (this.userList.length > 0) {
- for (let i = 0; i < this.userList.length; i++) {
- if (this.userList[i].default_email == true) {
- this.test += `<div class='form-check form-check-inline'><input type='checkbox' class='form-check-input' id='next-${
- this.userList[i].name
- }' name='users' value='${this.userList[i].name}' checked='${
- this.userList[i].default_email == "true" ? true : false
- }'><label class='form-check-label' for='next-${
- this.userList[i].name
- }'>${this.userList[i].name}</label></div>`;
- } else {
- this.test += `<div class='form-check form-check-inline'><input type='checkbox' class='form-check-input' id='next-${this.userList[i].name}' name='users' value='${this.userList[i].name}'><label class='form-check-label' for='next-${this.userList[i].name}'>${this.userList[i].name}</label></div>`;
- }
- }
- }
- });
- this.reviewProposal = undefined;
- (async () => {
- Swal.fire({
- title: `<h3>Finalizar propuesta de inversión: ${investmentCode}</h3>`,
- icon: "info",
- input: "textarea",
- html: `<p style="text-align:left;">Comentario:</p>`,
- showCancelButton: true,
- confirmButtonText: "Siguiente",
- cancelButtonText: "Cancelar",
- /*inputValidator: value => {
- if (!value) {
- return "Debe ingresar un comentario";
- }
- },*/
- preConfirm: comentario => {
- this.reviewProposal = {
- id_inversion: investmentProposalID,
- step: "next",
- comentario: comentario == null ? "" : comentario
- };
- },
- allowOutsideClick: () => !Swal.isLoading()
- }).then(result => {
- if (result.dismiss) {
- return false;
- }
- Swal.fire({
- title: `<h3>Finalizar propuesta de inversión ${investmentCode}</h3>`,
- icon: "info",
- html: `${this.test}`,
- confirmButtonText: "Finalizar",
- showCancelButton: true,
- cancelButtonText: "Cancelar",
- showLoaderOnConfirm: true,
- preConfirm: () => {
- let array = [];
- for (let i = 0; i < this.userList.length; i++) {
- let html_input: HTMLInputElement = document.getElementById(
- this.userList[i].name
- ) as HTMLInputElement;
- if (html_input != null) {
- let html_value: string = html_input.value;
- if (html_input.checked == true) {
- array.push(html_value);
- }
- } else {
- array;
- }
- }
- this.reviewProposal["notificar"] = array.toString();
- }
- }).then(result1 => {
- if (result1.dismiss) {
- return false;
- }
- Swal.fire({
- allowOutsideClick: false,
- title: "Espere por favor...",
- icon: "info"
- });
- Swal.showLoading();
- this.investmentsService
- .sendReviewProposalInvestment(this.reviewProposal)
- .subscribe(
- success => {
- if (success) {
- Swal.fire({
- allowOutsideClick: false,
- icon: "success",
- showCancelButton: false,
- title: "Exito",
- confirmButtonText: "La propuesta ha sido finalizada"
- }).then(result => {
- Swal.close();
- window.location.reload();
- });
- }
- },
- err => {
- if (err.code == 405) {
- Swal.fire({
- icon: "error",
- title: "Operacion no permitida",
- text: err.message
- }).then(result => {
- Swal.close();
- window.location.href = "#/investment-proposals";
- });
- } else {
- Swal.fire({
- icon: "error",
- title: "Error al guardar",
- text: err.message
- });
- }
- this.router.navigate(["/investment-proposals"]);
- }
- );
- });
- //window.location.reload();
- });
- })();
- }
- userType(userRole: any, requiredRole: any) {
- if (userRole.length == 0) {
- return true;
- }
- return userRole.includes(requiredRole);
- }
- }
|