instrument-calculations.service.ts 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. import { Injectable } from "@angular/core";
  2. import { of as observableOf, Observable, throwError } from "rxjs";
  3. import { HttpClient, HttpHeaders } from "@angular/common/http";
  4. import { retry, catchError, map, timeout } from "rxjs/operators";
  5. import { environment } from "@environments/environment";
  6. @Injectable({
  7. providedIn: "root"
  8. })
  9. export class InstrumentCalculations {
  10. time: number = 6000;
  11. constructor(private http: HttpClient) {}
  12. // Calculos para lete
  13. leteCalc(
  14. codigo_instrumento: string,
  15. info_inversion: { id_tipo_base: string },
  16. info_instrumento: {
  17. valor_nominal: number;
  18. plazo: number;
  19. comision_casa_porcentaje: number;
  20. comision_bolsa_porcentaje: number;
  21. rendimiento_bruto: number;
  22. fecha_operacion: string;
  23. fecha_liquidacion?: string;
  24. }
  25. ): Observable<boolean> {
  26. return this.http
  27. .post<any>(`${environment.productionApiUrl}/autocomplete/lete`, {
  28. codigo_instrumento,
  29. info_inversion,
  30. info_instrumento
  31. })
  32. .pipe(
  33. map(response => {
  34. return response;
  35. }),
  36. catchError(this.errorHandl)
  37. );
  38. }
  39. ceteCalc(
  40. codigo_instrumento: string,
  41. info_inversion: {
  42. id_tipo_base: string;
  43. id_periodicidad: string;
  44. id_formato_ingreso: string;
  45. },
  46. info_instrumento: {
  47. valor_nominal: number;
  48. comision_casa_porcentaje: number;
  49. comision_bolsa_porcentaje: number;
  50. plazo: number;
  51. rendimiento_bruto: number;
  52. otros_costos: number;
  53. fecha_operacion: string;
  54. fecha_liquidacion: string;
  55. fecha_ultima_cupon: string;
  56. fecha_vencimiento: string;
  57. }
  58. ): Observable<boolean> {
  59. return this.http
  60. .post<any>(`${environment.productionApiUrl}/autocomplete/cete`, {
  61. codigo_instrumento,
  62. info_inversion,
  63. info_instrumento
  64. })
  65. .pipe(
  66. map(response => {
  67. return response;
  68. }),
  69. catchError(this.errorHandl)
  70. );
  71. }
  72. // Para vcn y papel bursatil
  73. vcnCalc(
  74. codigo_instrumento: string,
  75. info_inversion: {
  76. id_tipo_base: string;
  77. id_periodicidad: string;
  78. id_formato_ingreso: string;
  79. },
  80. info_instrumento: {
  81. valor_par: boolean;
  82. valor_nominal: number;
  83. comision_casa_porcentaje: number;
  84. comision_bolsa_porcentaje: number;
  85. rendimiento_bruto: number;
  86. otros_costos: number;
  87. plazo: number;
  88. renta_porcentaje: number;
  89. fecha_operacion: string;
  90. fecha_liquidacion: string;
  91. fecha_ultima_cupon: string;
  92. fecha_vencimiento: string;
  93. }
  94. ): Observable<boolean> {
  95. return this.http
  96. .post<any>(`${environment.productionApiUrl}/autocomplete/vcn`, {
  97. codigo_instrumento,
  98. info_inversion,
  99. info_instrumento
  100. })
  101. .pipe(
  102. map(response => {
  103. return response;
  104. }),
  105. catchError(this.errorHandl)
  106. );
  107. }
  108. dapCalc(
  109. codigo_instrumento: string,
  110. info_inversion: {
  111. id_tipo_base: string;
  112. id_periodicidad: string;
  113. id_formato_ingreso: string;
  114. },
  115. info_instrumento: {
  116. monto_inversion: number;
  117. tasa_porcentaje: number;
  118. renta_porcentaje: number;
  119. plazo: number;
  120. fecha_operacion: string;
  121. fecha_vencimiento: string;
  122. }
  123. ): Observable<boolean> {
  124. return this.http
  125. .post<any>(`${environment.productionApiUrl}/autocomplete/dap`, {
  126. codigo_instrumento,
  127. info_inversion,
  128. info_instrumento
  129. })
  130. .pipe(
  131. map(response => {
  132. return response;
  133. }),
  134. catchError(this.errorHandl)
  135. );
  136. }
  137. errorHandl(error) {
  138. let errorMessage = "";
  139. if (error.error) {
  140. // Get client-side error
  141. errorMessage = error.error;
  142. } else {
  143. // Get server-side error
  144. errorMessage = `Error Code: ${error.status}\nMessage: ${error.message}`;
  145. }
  146. return throwError(errorMessage);
  147. }
  148. }