|
|
@@ -4,11 +4,13 @@ import { PreventiveMaintenanceService } from '../../../services/preventive-maint
|
|
|
import { EncService } from '../../../services/enc.service';
|
|
|
import { FunctionsService } from '../../../services/functions.service';
|
|
|
import { ResourcesService } from '../../../services/resources.service';
|
|
|
+import { SystemAdminService } from '../../../services/system-admin.service';
|
|
|
import { lastValueFrom } from 'rxjs';
|
|
|
import {
|
|
|
PreventiveVisitDetailsResponse,
|
|
|
PreventiveVisitDetails,
|
|
|
} from '../../../interfaces/preventive-maintenance.interface';
|
|
|
+import { PriorityInterface } from '../../system-admin/system-params/system-params.component';
|
|
|
|
|
|
@Component({
|
|
|
selector: 'app-preventive-order-details',
|
|
|
@@ -22,8 +24,7 @@ export class PreventiveOrderDetailsComponent implements OnInit {
|
|
|
hasError: boolean;
|
|
|
errorStr: string;
|
|
|
|
|
|
-
|
|
|
-
|
|
|
+ orderPriorities: PriorityInterface[];
|
|
|
workOrder: PreventiveVisitDetails | null;
|
|
|
|
|
|
constructor(
|
|
|
@@ -32,6 +33,7 @@ export class PreventiveOrderDetailsComponent implements OnInit {
|
|
|
private _encService: EncService,
|
|
|
private _functionsService: FunctionsService,
|
|
|
private _resourcesService: ResourcesService,
|
|
|
+ private _sysAdminService: SystemAdminService,
|
|
|
|
|
|
) {
|
|
|
this.idOrder = '';
|
|
|
@@ -39,13 +41,43 @@ export class PreventiveOrderDetailsComponent implements OnInit {
|
|
|
this.hasError = false;
|
|
|
this.errorStr = '';
|
|
|
|
|
|
-
|
|
|
-
|
|
|
+ this.orderPriorities = [];
|
|
|
this.workOrder = null;
|
|
|
}
|
|
|
|
|
|
ngOnInit(): void {
|
|
|
- this.getOrderDetails();
|
|
|
+ this.getOrderPriorities();
|
|
|
+ }
|
|
|
+
|
|
|
+ async getOrderPriorities() {
|
|
|
+ try {
|
|
|
+ let idUser = localStorage.getItem('idusuario')!;
|
|
|
+ let priorities = await lastValueFrom(this._sysAdminService.getOrderPriorities(idUser, 1));
|
|
|
+
|
|
|
+ this.hasError = priorities.error;
|
|
|
+ this.errorStr = priorities.msg;
|
|
|
+
|
|
|
+ if (this.hasError) {
|
|
|
+ this.isLoading = false;
|
|
|
+ } else {
|
|
|
+ let orderPriorities: PriorityInterface[] = [];
|
|
|
+ for (const priority of priorities.response.order_priorities as PriorityInterface[]) {
|
|
|
+ let valEnc = await this._encService.encrypt(priority.value);
|
|
|
+
|
|
|
+ priority.label = `${priority.label} (${priority.value})`;
|
|
|
+ priority.value = valEnc;
|
|
|
+
|
|
|
+ orderPriorities.push(priority);
|
|
|
+ }
|
|
|
+
|
|
|
+ this.orderPriorities = orderPriorities;
|
|
|
+ this.getOrderDetails();
|
|
|
+ }
|
|
|
+ } catch (error: any) {
|
|
|
+ this.errorStr = error?.error?.msg || 'Ocurrió un error inesperado.';
|
|
|
+ this.hasError = true;
|
|
|
+ this.isLoading = false;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
async getOrderDetails() {
|
|
|
@@ -99,6 +131,15 @@ export class PreventiveOrderDetailsComponent implements OnInit {
|
|
|
)!;
|
|
|
}
|
|
|
|
|
|
+ // Process priority
|
|
|
+ let priorityDec = await this._encService.decrypt(order.response.PRIORIDAD);
|
|
|
+ for (const priority of this.orderPriorities) {
|
|
|
+ let valDec = await this._encService.decrypt(priority.value);
|
|
|
+ if (valDec == priorityDec) {
|
|
|
+ order.response.PRIORIDAD_OBJ = priority;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
// Process resources - handle both formats
|
|
|
if (order.response.RECURSOS_ARR) {
|
|
|
// Already comes as array
|