|
|
@@ -1,4 +1,10 @@
|
|
|
-import { Component, OnInit } from '@angular/core';
|
|
|
+import { Component, Inject, OnInit } from '@angular/core';
|
|
|
+import { MatSnackBar } from '@angular/material/snack-bar';
|
|
|
+import { ActivatedRoute } from '@angular/router';
|
|
|
+import { lastValueFrom } from 'rxjs';
|
|
|
+import { PreventiveWorkOrder, PreventiveWorkOrderResponse } from 'src/app/interfaces/preventive-work-order.interface';
|
|
|
+import { EncService } from 'src/app/services/enc/enc.service';
|
|
|
+import { PreventiveMaintenanceService } from 'src/app/services/preventive-maintenance.service';
|
|
|
|
|
|
@Component({
|
|
|
selector: 'app-budget-analysis',
|
|
|
@@ -6,10 +12,115 @@ import { Component, OnInit } from '@angular/core';
|
|
|
styleUrls: ['./budget-analysis.component.css']
|
|
|
})
|
|
|
export class BudgetAnalysisComponent implements OnInit {
|
|
|
+ public btnSmall: boolean = false;
|
|
|
|
|
|
- constructor() { }
|
|
|
+ idOrder: number;
|
|
|
+ isLoading: boolean;
|
|
|
+ hasError: boolean;
|
|
|
+ errorStr: string;
|
|
|
+
|
|
|
+ workOrder: PreventiveWorkOrder | null;
|
|
|
+
|
|
|
+ constructor(
|
|
|
+ private _prevMaintService: PreventiveMaintenanceService,
|
|
|
+ private _encService: EncService,
|
|
|
+ private _router: ActivatedRoute,
|
|
|
+ private _snackBar: MatSnackBar,
|
|
|
+ ) {
|
|
|
+ this.idOrder = 0;
|
|
|
+ this.isLoading = true;
|
|
|
+ this.hasError = false;
|
|
|
+ this.errorStr = "";
|
|
|
+ this.workOrder = null;
|
|
|
+ this.btnSmall = window.innerWidth <= 1405;
|
|
|
+ }
|
|
|
|
|
|
ngOnInit(): void {
|
|
|
+ this._router.queryParams.subscribe(res => {
|
|
|
+ let idOrderEnc = res['data'];
|
|
|
+ if(idOrderEnc == undefined || idOrderEnc == null || idOrderEnc == ''){
|
|
|
+ this.openSnackBar('No se envió información.');
|
|
|
+ this.goBack(1);
|
|
|
+ }else{
|
|
|
+ this.getWorkOrder(idOrderEnc);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ async getWorkOrder(idOrderEnc: string){
|
|
|
+ try{
|
|
|
+ let idOrderDec = await this._encService.desencriptar(idOrderEnc);
|
|
|
+ this.idOrder = parseInt(idOrderDec);
|
|
|
+
|
|
|
+ let idUser = localStorage.getItem('idusuario');
|
|
|
+ let shortEnc = await lastValueFrom(this._encService.shortEncrypt(idUser!));
|
|
|
+ let idOrderShort = await lastValueFrom(this._encService.shortEncrypt(idOrderEnc));
|
|
|
+
|
|
|
+ let order: PreventiveWorkOrderResponse = await lastValueFrom(this._prevMaintService.getWorkOrder(
|
|
|
+ idOrderShort.response.encrypted,
|
|
|
+ shortEnc.response.encrypted,
|
|
|
+ 1
|
|
|
+ ));
|
|
|
+
|
|
|
+ this.hasError = order.error;
|
|
|
+ this.errorStr = order.msg;
|
|
|
+
|
|
|
+ if(!this.hasError){
|
|
|
+ this.workOrder = order.response;
|
|
|
+ }
|
|
|
+
|
|
|
+ this.isLoading = false;
|
|
|
+ }catch(error: any){
|
|
|
+ if(error.error == undefined){
|
|
|
+ this.errorStr = 'Ocurrió un error inesperado.';
|
|
|
+ }else if(error.error.msg == undefined){
|
|
|
+ this.errorStr = 'Ocurrió un error inesperado.';
|
|
|
+ }else{
|
|
|
+ this.errorStr = error.error.msg;
|
|
|
+ }
|
|
|
+
|
|
|
+ this.hasError = true;
|
|
|
+ this.isLoading = false;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
+ getTeams(teamsStr: string, teamsConfStr: string): any[]{
|
|
|
+ let teamsArr = JSON.parse(teamsStr);
|
|
|
+ let teamsConfObj = JSON.parse(teamsConfStr);
|
|
|
+ let teams: any[] = [];
|
|
|
+
|
|
|
+ teamsArr.forEach((team: any) => {
|
|
|
+ let id = team.ID;
|
|
|
+ let conf = parseInt(teamsConfObj[id]);
|
|
|
+ let confArr: string[] = [];
|
|
|
+
|
|
|
+ for(let i = 0; i < conf; i++){
|
|
|
+ confArr.push(`${id}-PERS-${i}`);
|
|
|
+ }
|
|
|
+
|
|
|
+ teams.push({
|
|
|
+ ID: id,
|
|
|
+ ESP: team.ESP,
|
|
|
+ NOMB: team.NOMB,
|
|
|
+ CANT: conf,
|
|
|
+ CONF: confArr
|
|
|
+ })
|
|
|
+ });
|
|
|
+
|
|
|
+ return teams;
|
|
|
+ }
|
|
|
+
|
|
|
+ public onResize():void {
|
|
|
+ this.btnSmall = window.innerWidth <= 1405;
|
|
|
+ }
|
|
|
+
|
|
|
+ goBack(steps: number){
|
|
|
+ window.history.go(steps * -1);
|
|
|
+ }
|
|
|
+
|
|
|
+ openSnackBar(msg: string){
|
|
|
+ this._snackBar.open(msg, undefined, {
|
|
|
+ duration: 2500,
|
|
|
+ })
|
|
|
+ }
|
|
|
}
|