import { Injectable } from "@angular/core"; import { of as observableOf, Observable, throwError } from "rxjs"; import { HttpClient, HttpHeaders } from "@angular/common/http"; import { retry, catchError, map, timeout } from "rxjs/operators"; import { environment } from "@environments/environment"; @Injectable({ providedIn: "root" }) export class InstrumentCalculations { time: number = 6000; constructor(private http: HttpClient) {} // Calculos para lete leteCalc( codigo_instrumento: string, info_inversion: { id_tipo_base: string }, info_instrumento: { valor_nominal: number; plazo: number; comision_casa_porcentaje: number; comision_bolsa_porcentaje: number; rendimiento_bruto: number; fecha_operacion: string; fecha_liquidacion?: string; } ): Observable { return this.http .post(`${environment.productionApiUrl}/autocomplete`, { codigo_instrumento, info_inversion, info_instrumento }) .pipe( map(response => { return response; }), catchError(this.errorHandl) ); } ceteCalc( codigo_instrumento: string, info_inversion: { id_tipo_base: number; id_periodicidad: number; id_formato_ingreso: number; }, info_instrumento: { valor_nominal: number; comision_casa_porcentaje: number; comision_bolsa_porcentaje: number; plazo: number; rendimiento_bruto: number; otros_costos: number; fecha_operacion: string; fecha_liquidacion: string; fecha_ultima_cupon: string; //fecha_vencimiento: string; } ): Observable { return this.http .post(`${environment.productionApiUrl}/autocomplete`, { codigo_instrumento, info_inversion, info_instrumento }) .pipe( map(response => { return response; }), catchError(this.errorHandl) ); } // Para familia de bonos (bonos, eurobonos, certificados) bonosCalc( codigo_instrumento: string, info_inversion: { id_tipo_base: number; id_periodicidad: number; id_formato_ingreso: number; }, info_instrumento: { costo_cedeval: number; comision_casa_porcentaje_compra: number; comision_bolsa_porcentaje_compra: number; cupon_porcentaje_compra: number; valor_nominal_compra: number; costo_transferencia: number; precio_vencimiento_compra: number; precio_compra: number; fecha_ultima_cupon_compra: string; fecha_liquidacion_compra: string; fecha_vencimiento_compra: string; comision_casa_porcentaje_venta: number; comision_bolsa_porcentaje_venta: number; cupon_porcentaje_venta: number; valor_nominal_venta: number; precio_vencimiento_venta: number; precio_venta: number; fecha_ultima_cupon_venta: string; fecha_liquidacion_venta: string; fecha_vencimiento_venta: string; } ): Observable { return this.http .post(`${environment.productionApiUrl}/autocomplete`, { codigo_instrumento, info_inversion, info_instrumento }) .pipe( map(response => { return response; }), catchError(this.errorHandl) ); } titularizacionCalc( codigo_instrumento: string, info_inversion: { id_tipo_base: number; id_periodicidad: number; id_formato_ingreso: number; }, info_instrumento: { comision_casa_porcentaje_compra: number; comision_bolsa_porcentaje_compra: number; cupon_porcentaje_compra: number; valor_nominal_compra: number; costo_transferencia: number; precio_vencimiento_compra: number; precio_compra: number; fecha_ultima_cupon_compra: string; fecha_liquidacion_compra: string; fecha_vencimiento_compra: string; comision_casa_porcentaje_venta: number; comision_bolsa_porcentaje_venta: number; cupon_porcentaje_venta: number; valor_nominal_venta: number; precio_vencimiento_venta: number; precio_venta: number; fecha_ultima_cupon_venta: string; fecha_liquidacion_venta: string; fecha_vencimiento_venta: string; fecha_emision: string; costo_cedeval: number; amortizacion_porcentajes: any; } ): Observable { return this.http .post(`${environment.productionApiUrl}/autocomplete`, { codigo_instrumento, info_inversion, info_instrumento }) .pipe( map(response => { return response; }), catchError(this.errorHandl) ); } // Fondos de inversion fondosCalc( codigo_instrumento: string, info_inversion: { id_tipo_base: number; id_periodicidad: number; id_formato_ingreso: number; }, info_instrumento: { cuota_participacion: number; valor_participacion: number; comision_bolsa_porcentaje: number; comision_casa_porcentaje: number; dividendo_porcentaje: number; rendimiento_porcentaje: number; dias_liquidacion: number; dias_vencimiento: number; fecha_operacion: string; } ): Observable { return this.http .post(`${environment.productionApiUrl}/autocomplete`, { codigo_instrumento, info_inversion, info_instrumento }) .pipe( map(response => { return response; }), catchError(this.errorHandl) ); } // Para vcn vcnCalc( codigo_instrumento: string, info_inversion: { id_tipo_base: number; id_periodicidad: number; id_formato_ingreso: number; }, info_instrumento: { valor_par: boolean; valor_nominal: number; comision_casa_porcentaje: number; comision_bolsa_porcentaje: number; rendimiento_bruto: number; otros_costos: number; renta_porcentaje: number; fecha_operacion: string; fecha_liquidacion: string; fecha_ultima_cupon: string; fecha_vencimiento: string; } ): Observable { return this.http .post(`${environment.productionApiUrl}/autocomplete`, { codigo_instrumento, info_inversion, info_instrumento }) .pipe( map(response => { return response; }), catchError(this.errorHandl) ); } // Para pbur pburCalc( codigo_instrumento: string, info_inversion: { id_tipo_base: number; id_periodicidad: number; id_formato_ingreso: number; }, info_instrumento: { valor_par: boolean; valor_nominal: number; comision_casa_porcentaje: number; comision_bolsa_porcentaje: number; rendimiento_bruto: number; otros_costos: number; plazo: number; renta_porcentaje: number; fecha_operacion: string; fecha_liquidacion: string; fecha_ultima_cupon: string; } ): Observable { return this.http .post(`${environment.productionApiUrl}/autocomplete`, { codigo_instrumento, info_inversion, info_instrumento }) .pipe( map(response => { return response; }), catchError(this.errorHandl) ); } dapCalc( codigo_instrumento: string, info_inversion: { id_tipo_base: number; id_periodicidad: number; id_formato_ingreso: number; }, info_instrumento: { monto_inversion: number; tasa_porcentaje: number; renta_porcentaje: number; plazo: number; fecha_operacion: string; //fecha_vencimiento: string; } ): Observable { return this.http .post(`${environment.productionApiUrl}/autocomplete`, { codigo_instrumento, info_inversion, info_instrumento }) .pipe( map(response => { return response; }), catchError(this.errorHandl) ); } projectionCalc(id: string, proyecciones: any): Observable { return this.http .put(`${environment.productionApiUrl}/autocomplete/${id}`, { proyecciones }) .pipe( map(response => { return response; }), catchError(this.errorHandl) ); } projectionModification(id: string, proyecciones: any): Observable { return this.http .put( `${environment.productionApiUrl}/proyeccion/${id}`, proyecciones ) .pipe( map(response => { return response; }), catchError(this.errorHandl) ); } errorHandl(error) { let errorMessage = ""; if (error.error) { // Get client-side error errorMessage = error.error; } else { // Get server-side error errorMessage = `Error Code: ${error.status}\nMessage: ${error.message}`; } return throwError(errorMessage); } }