incomes.component.ts 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. import { Component, ViewChild, OnInit } from "@angular/core";
  2. import { MatPaginator } from "@angular/material/paginator";
  3. import { MatSort } from "@angular/material/sort";
  4. import { MatTableDataSource } from "@angular/material/table";
  5. import Swal from "sweetalert2";
  6. import { CatalogsService } from "src/app/services/catalogs.service";
  7. import { IncomesService } from "@app/services/incomes.service";
  8. import { AuthService } from "@app/services/auth2.service";
  9. import { JwtHelperService } from "@auth0/angular-jwt";
  10. import { IncomeList } from "@app/models/income-list";
  11. import { from } from "rxjs";
  12. import { FormInvestmentProposalService } from "@app/services/form-investment-proposal.service";
  13. import { Router } from "@angular/router";
  14. import { IAngularMyDpOptions, IMyDateModel } from "angular-mydatepicker";
  15. @Component({
  16. selector: "app-income-proposals",
  17. templateUrl: "./incomes.component.html",
  18. styleUrls: ["./incomes.component.scss"]
  19. })
  20. export class IncomesComponent implements OnInit {
  21. helper = new JwtHelperService();
  22. title: string = "Ingresos";
  23. // For daterange
  24. daysLabels: any = {
  25. su: "Dom",
  26. mo: "Lun",
  27. tu: "Mar",
  28. we: "Mie",
  29. th: "Jue",
  30. fr: "Vie",
  31. sa: "Sab"
  32. };
  33. monthsLabels: any = {
  34. 1: "Ene",
  35. 2: "Feb",
  36. 3: "Mar",
  37. 4: "Abr",
  38. 5: "May",
  39. 6: "Jun",
  40. 7: "Jul",
  41. 8: "Ago",
  42. 9: "Sep",
  43. 10: "Oct",
  44. 11: "Nov",
  45. 12: "Dic"
  46. };
  47. myDpOptions: IAngularMyDpOptions = {
  48. dateRange: true,
  49. dateFormat: "dd/mm/yyyy",
  50. dayLabels: this.daysLabels,
  51. monthLabels: this.monthsLabels
  52. };
  53. myDateInit: boolean = true;
  54. model: IMyDateModel = null;
  55. displayedColumns: string[] = [
  56. "codigo_inversion",
  57. "nombre_inversion",
  58. "fecha_proyeccion_pago",
  59. "tipo_instrumento",
  60. "empresa",
  61. "estado",
  62. "id_inversion",
  63. "proyeccion_ingreso"
  64. ];
  65. //displayedColumns: string[] = ['state'];
  66. listProposals: IncomeList[];
  67. dataSource = new MatTableDataSource(this.listProposals);
  68. resultsLength = 0;
  69. isLoadingResults = true;
  70. isRateLimitReached = false;
  71. userRole: any;
  72. @ViewChild(MatPaginator, { static: true }) paginator: MatPaginator;
  73. @ViewChild(MatSort, { static: true }) sort: MatSort;
  74. role_number: any;
  75. instrumentTypes: any;
  76. constructor(
  77. private catalogService: CatalogsService,
  78. private incomesService: IncomesService,
  79. private authService: AuthService,
  80. private formInvestmentProposal: FormInvestmentProposalService,
  81. private router: Router
  82. ) {
  83. const decodedToken = this.helper.decodeToken(
  84. this.authService.getJwtToken()
  85. );
  86. this.userRole = decodedToken.groups;
  87. Swal.fire({
  88. allowOutsideClick: false,
  89. icon: "info",
  90. text: "Espere por favor..."
  91. });
  92. Swal.showLoading();
  93. }
  94. ngOnInit() {
  95. this.catalogService.getInstrumentTypes().subscribe(res => {
  96. this.instrumentTypes = res;
  97. });
  98. this.incomesService.getProjectionsIncomeList().subscribe(
  99. ans => {
  100. this.listProposals = ans.result;
  101. this.dataSource.data = this.listProposals;
  102. this.dataSource.paginator = this.paginator;
  103. this.dataSource.sort = this.sort;
  104. },
  105. err => {
  106. Swal.fire({
  107. icon: "error",
  108. title: "Error en el servidor",
  109. text: err.message
  110. });
  111. }
  112. );
  113. setTimeout(() => {
  114. Swal.close();
  115. }, 1200);
  116. }
  117. filter_by_instrument(event: any) {
  118. const filterInstrument = (event.target as HTMLInputElement).value;
  119. this.dataSource.filter = filterInstrument;
  120. if (this.dataSource.paginator) {
  121. this.dataSource.paginator.firstPage();
  122. }
  123. this.dataSource.sort = this.sort;
  124. }
  125. filter_by_date(event: any) {
  126. let dateFormat = event.dateRange.formatted.split(" - ", 2);
  127. let date0 = dateFormat[0].split("/");
  128. let date1 = dateFormat[1].split("/");
  129. let dateStart = Number(date0[2] + date0[1] + date0[0]);
  130. let dateFinish = Number(date1[2] + date1[1] + date1[0]);
  131. this.dataSource.filterPredicate = (data, filter) => {
  132. if (dateFormat[0] && dateFormat[1]) {
  133. let date2 = data["fecha_proyeccion_pago"].split("/");
  134. let payment_date = Number(date2[2] + date2[1] + date2[0]);
  135. return payment_date >= dateStart && payment_date <= dateFinish;
  136. }
  137. return true;
  138. };
  139. this.dataSource.filter = "" + Math.random();
  140. if (this.dataSource.paginator) {
  141. this.dataSource.paginator.firstPage();
  142. }
  143. this.dataSource.sort = this.sort;
  144. }
  145. filter_by_income_status(event: any) {
  146. Swal.fire({
  147. allowOutsideClick: false,
  148. icon: "info",
  149. text: "Espere por favor..."
  150. });
  151. Swal.showLoading();
  152. let active = event.target.value;
  153. this.incomesService.getProjectionsIncomeList(active).subscribe(
  154. ans => {
  155. this.listProposals = ans["result"];
  156. this.dataSource.data = this.listProposals;
  157. this.dataSource.paginator = this.paginator;
  158. this.dataSource.sort = this.sort;
  159. Swal.close();
  160. },
  161. err => {
  162. Swal.fire({
  163. icon: "error",
  164. title: "Error en el servidor",
  165. text: err.message
  166. });
  167. }
  168. );
  169. }
  170. applyFilter(event: Event) {
  171. const filterValue = (event.target as HTMLSelectElement).value;
  172. this.dataSource.filter = filterValue;
  173. if (this.dataSource.paginator) {
  174. this.dataSource.paginator.firstPage();
  175. }
  176. }
  177. view_investment_proposal(id: string) {
  178. this.formInvestmentProposal.resetFormData();
  179. Swal.fire({
  180. allowOutsideClick: false,
  181. icon: "info",
  182. text: "Espere por favor..."
  183. });
  184. Swal.showLoading();
  185. setTimeout(() => {
  186. this.router.navigate([`/investment-proposal/${id}`]);
  187. }, 1000);
  188. }
  189. instrument_has_costs(id: string) {
  190. return true;
  191. }
  192. go_to_instrument_url(
  193. id: string,
  194. id_proyeccion_instrumento: string,
  195. fecha: string,
  196. id_proyeccion?: string
  197. ) {
  198. Swal.fire({
  199. allowOutsideClick: false,
  200. icon: "info",
  201. text: "Espere por favor..."
  202. });
  203. Swal.showLoading();
  204. setTimeout(() => {
  205. this.router.navigate([`/investment-income`], {
  206. queryParams: {
  207. id_inversion: id,
  208. id_proyeccion_ingreso_instrumento: id_proyeccion_instrumento,
  209. fecha_proyeccion_pago: fecha,
  210. id_proyeccion_ingreso: id_proyeccion
  211. }
  212. });
  213. }, 1000);
  214. }
  215. }