| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367 |
- 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 { InstrumentCalculations } from "@app/services/instrument-calculations.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, ActivatedRoute } from "@angular/router";
- import {
- FormBuilder,
- FormGroup,
- FormControl,
- FormArray,
- Validators
- } from "@angular/forms";
- @Component({
- selector: "app-vcn-costs",
- templateUrl: "./vcn.costs.component.html"
- //styleUrls: ["./dap.costs.component.scss"]
- })
- export class VCNCostsComponent implements OnInit {
- helper = new JwtHelperService();
- title: string = "Costos para valores comerciales";
- 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;
- investmentProposalID: string;
- form: FormArray;
- investmentProposalForm: FormGroup;
- proyecciones: any;
- proyeccionesProps = [];
- dataRetrieved: boolean = false;
- array1;
- array2;
- array3;
- investment: any;
- instrument_work: any;
- instrument_exists: boolean;
- constructor(
- private catalogService: CatalogsService,
- private investmentsService: InvestmentsService,
- private authService: AuthService,
- private formInvestmentProposal: FormInvestmentProposalService,
- private router: Router,
- private route: ActivatedRoute,
- private instrumentService: InstrumentCalculations,
- private formBuilder: FormBuilder
- ) {
- const decodedToken = this.helper.decodeToken(
- this.authService.getJwtToken()
- );
- this.userRole = decodedToken.groups;
- Swal.fire({
- allowOutsideClick: false,
- icon: "info",
- text: "Espere por favor..."
- });
- Swal.showLoading();
- }
- ngOnInit() {
- Swal.close();
- const formDataObj = {};
- this.route.params.subscribe(params => {
- this.investmentProposalID = params["id"];
- });
- if (this.investmentProposalID == undefined)
- this.investmentProposalID = this.route.snapshot.queryParamMap.get("id");
- if (this.investmentProposalID != undefined) {
- this.investmentsService
- .getProposalInvestment(this.investmentProposalID)
- .subscribe(
- res => {
- this.investment = res["result"];
- this.instrument_work =
- res["result"]["id_inversion_instrumento"]["instrumento"];
- this.instrument_exists = true;
- this.investmentProposalForm = this.formBuilder.group({
- valor_par: [
- !this.instrument_exists ? false : this.instrument_work.valor_par
- ],
- valor_nominal: [
- !this.instrument_exists
- ? ""
- : this.instrument_work.valor_nominal,
- [
- Validators.required,
- Validators.pattern(/^[+]?([0-9]+(?:[\.][0-9]*)?|\.[0-9]+)$/)
- ]
- ],
- otros_costos: [
- !this.instrument_exists ? 0 : this.instrument_work.otros_costos,
- [Validators.pattern(/^[+]?([0-9]+(?:[\.][0-9]*)?|\.[0-9]+)$/)]
- ],
- plazo: [
- !this.instrument_exists ? "" : this.instrument_work.plazo,
- [Validators.required]
- ],
- renta_porcentaje: [
- !this.instrument_exists
- ? ""
- : this.instrument_work.renta_porcentaje,
- [Validators.required]
- ],
- comision_casa_porcentaje: [
- !this.instrument_exists
- ? ""
- : this.instrument_work.comision_casa_porcentaje,
- [
- Validators.required,
- Validators.pattern(/^[+]?([0-9]+(?:[\.][0-9]*)?|\.[0-9]+)$/)
- ]
- ],
- comision_bolsa_porcentaje: [
- !this.instrument_exists
- ? ""
- : this.instrument_work.comision_bolsa_porcentaje,
- [
- Validators.required,
- Validators.pattern(/^[+]?([0-9]+(?:[\.][0-9]*)?|\.[0-9]+)$/)
- ]
- ],
- rendimiento_bruto: [
- !this.instrument_exists
- ? ""
- : this.instrument_work.rendimiento_bruto,
- [
- Validators.required,
- Validators.pattern(/^[+]?([0-9]+(?:[\.][0-9]*)?|\.[0-9]+)$/)
- ]
- ],
- /*formato_ingreso: [
- !this.instrument_exists ? "" : this.instrument_work.formato_ingreso,
- [Validators.required]
- ],*/
- fecha_liquidacion: [
- !this.instrument_exists
- ? ""
- : this.instrument_work.fecha_liquidacion,
- [Validators.required]
- ],
- fecha_vencimiento: [
- !this.instrument_exists
- ? ""
- : this.instrument_work.fecha_vencimiento,
- [Validators.required]
- ],
- fecha_operacion: [
- !this.instrument_exists
- ? ""
- : this.instrument_work.fecha_operacion,
- [Validators.required]
- ],
- fecha_ultima_cupon: [
- !this.instrument_exists
- ? ""
- : this.instrument_work.fecha_ultima_cupon,
- [Validators.required]
- ]
- });
- },
- err => {}
- );
- this.investmentsService
- .getProposalInvestment(this.investmentProposalID)
- .subscribe(
- res => {
- this.proyecciones =
- res["result"]["id_inversion_instrumento"]["instrumento"][
- "proyecciones"
- ];
- this.form = new FormArray(this.buildForm(this.proyecciones));
- this.dataRetrieved = true;
- },
- err => {
- Swal.fire({
- icon: "error",
- title: "Error en el servidor",
- text: err.message
- });
- }
- );
- }
- setTimeout(() => {
- Swal.close();
- }, 1200);
- }
- submitInstrumentChanges() {}
- submitProjectionChanges() {
- let objProjection = { proyecciones: this.form.value };
- Swal.fire({
- allowOutsideClick: false,
- icon: "info",
- text: "Espere por favor..."
- });
- Swal.showLoading();
- this.instrumentService
- .projectionCalc(this.investmentProposalID, this.form.value)
- .subscribe(
- resp => {
- this.investmentsService
- .updateInstrumentProjection(
- this.investmentProposalID,
- objProjection
- )
- .subscribe(
- success => {
- if (success) {
- Swal.fire({
- allowOutsideClick: false,
- icon: "success",
- showCancelButton: false,
- title: "Exito",
- confirmButtonText: "La información ha sido actualizada"
- }).then(result => {
- this.proyecciones =
- result["result"]["id_inversion_instrumento"][
- "instrumento"
- ]["proyecciones"];
- this.form = new FormArray(
- this.buildForm(this.proyecciones)
- );
- Swal.close();
- //window.location.reload();
- });
- }
- },
- err => {
- Swal.fire({
- icon: "error",
- title: "Error al guardar",
- text: err.message
- });
- }
- );
- },
- err => {
- Swal.fire({
- icon: "error",
- title: "Error al guardar",
- text: err.message
- });
- }
- );
- }
- saveProjection() {
- let objProjection = { proyecciones: this.form.value };
- Swal.fire({
- allowOutsideClick: false,
- icon: "info",
- text: "Espere por favor..."
- });
- Swal.showLoading();
- this.instrumentService
- .projectionModification(this.investmentProposalID, this.form.value)
- .subscribe(
- resp => {
- this.investmentsService
- .updateInstrumentProjection(
- this.investmentProposalID,
- objProjection
- )
- .subscribe(
- success => {
- if (success) {
- Swal.fire({
- allowOutsideClick: false,
- icon: "success",
- showCancelButton: false,
- title: "Exito",
- confirmButtonText: "La información ha sido actualizada"
- }).then(result => {
- Swal.close();
- //window.location.reload();
- });
- }
- },
- err => {
- Swal.fire({
- icon: "error",
- title: "Error al guardar",
- text: err.message
- });
- }
- );
- },
- err => {
- Swal.fire({
- icon: "error",
- title: "Error al guardar",
- text: err.message
- });
- }
- );
- }
- buildForm(items: any[]): FormGroup[] {
- return items.map(x => this.buildItem(x));
- }
- //return a formGroup
- buildItem(item: any): FormGroup {
- return new FormGroup({
- id_proyeccion_ingreso: new FormControl(item.id_proyeccion_ingreso),
- posicion: new FormControl(item.posicion),
- plazo: new FormControl(item.plazo),
- fecha_pago: new FormControl(item.fecha_pago),
- ingreso_bruto: new FormControl(item.ingreso_bruto),
- costo_cedeval: new FormControl(item.costo_cedeval),
- costo_transferencia: new FormControl(item.costo_transferencia),
- costo_banco: new FormControl(item.costo_banco),
- otros_costos: new FormControl(item.otros_costos),
- renta: new FormControl(item.renta),
- ingreso_neto: new FormControl(item.ingreso_neto),
- id_valor_comercial: new FormControl(item.id_valor_comercial)
- });
- }
- }
|