|
|
@@ -0,0 +1,196 @@
|
|
|
+import { Component, Inject, OnInit } from '@angular/core';
|
|
|
+import { MAT_DIALOG_DATA } from '@angular/material/dialog';
|
|
|
+import { PreventiveMaintenanceService } from '../../../services/preventive-maintenance.service';
|
|
|
+import { EncService } from '../../../services/enc.service';
|
|
|
+import { FunctionsService } from '../../../services/functions.service';
|
|
|
+import { ResourcesService } from '../../../services/resources.service';
|
|
|
+import { lastValueFrom } from 'rxjs';
|
|
|
+import {
|
|
|
+ PreventiveVisitDetailsResponse,
|
|
|
+ PreventiveVisitDetails,
|
|
|
+} from '../../../interfaces/preventive-maintenance.interface';
|
|
|
+
|
|
|
+@Component({
|
|
|
+ selector: 'app-preventive-order-details',
|
|
|
+ templateUrl: './preventive-order-details.component.html',
|
|
|
+ styleUrl: './preventive-order-details.component.css',
|
|
|
+ standalone: false,
|
|
|
+})
|
|
|
+export class PreventiveOrderDetailsComponent implements OnInit {
|
|
|
+ idOrder: string;
|
|
|
+ isLoading: boolean;
|
|
|
+ hasError: boolean;
|
|
|
+ errorStr: string;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ workOrder: PreventiveVisitDetails | null;
|
|
|
+
|
|
|
+ constructor(
|
|
|
+ @Inject(MAT_DIALOG_DATA) private _data: any,
|
|
|
+ private _preventiveMaintenanceService: PreventiveMaintenanceService,
|
|
|
+ private _encService: EncService,
|
|
|
+ private _functionsService: FunctionsService,
|
|
|
+ private _resourcesService: ResourcesService,
|
|
|
+
|
|
|
+ ) {
|
|
|
+ this.idOrder = '';
|
|
|
+ this.isLoading = true;
|
|
|
+ this.hasError = false;
|
|
|
+ this.errorStr = '';
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ this.workOrder = null;
|
|
|
+ }
|
|
|
+
|
|
|
+ ngOnInit(): void {
|
|
|
+ this.getOrderDetails();
|
|
|
+ }
|
|
|
+
|
|
|
+ async getOrderDetails() {
|
|
|
+ try {
|
|
|
+ let idUser = localStorage.getItem('idusuario')!;
|
|
|
+ let order: PreventiveVisitDetailsResponse = await lastValueFrom(
|
|
|
+ this._preventiveMaintenanceService.getVisit(
|
|
|
+ this._data.idOrder,
|
|
|
+ idUser,
|
|
|
+ 1
|
|
|
+ )
|
|
|
+ );
|
|
|
+
|
|
|
+ this.hasError = order.error;
|
|
|
+ this.errorStr = order.msg;
|
|
|
+
|
|
|
+ if (!this.hasError) {
|
|
|
+ // Decrypt encrypted fields
|
|
|
+ order.response.ID_ORDEN = await this._encService.decrypt(
|
|
|
+ order.response.ID_ORDEN
|
|
|
+ );
|
|
|
+ order.response.CONTADOR = await this._encService.decrypt(
|
|
|
+ order.response.CONTADOR
|
|
|
+ );
|
|
|
+
|
|
|
+ let codeDec = await this._encService.decrypt(
|
|
|
+ order.response.CODIGO_EQUIPAMIENTO
|
|
|
+ );
|
|
|
+ order.response.TIPO_EQUIPAMIENTO = `${codeDec} - ${order.response.TIPO_EQUIPAMIENTO}`;
|
|
|
+
|
|
|
+ let idEquipmentDec = await this._encService.decrypt(
|
|
|
+ order.response.ID_EQUIPAMIENTO
|
|
|
+ );
|
|
|
+ order.response.MODELO_EQUIPAMIENTO = `${order.response.MODELO_EQUIPAMIENTO} (${idEquipmentDec})`;
|
|
|
+
|
|
|
+ // Handle MEDIDAS_OBJ if exists
|
|
|
+ if (order.response.MEDIDAS_OBJ) {
|
|
|
+ order.response.MEDIDAS_OBJ.ID_MEDIDA = await this._encService.decrypt(
|
|
|
+ order.response.MEDIDAS_OBJ.ID_MEDIDA
|
|
|
+ );
|
|
|
+ order.response.MEDIDAS_OBJ.CONTADOR = await this._encService.decrypt(
|
|
|
+ order.response.MEDIDAS_OBJ.CONTADOR
|
|
|
+ );
|
|
|
+ order.response.MEDIDAS_OBJ.ID_SERVICIO_WEB =
|
|
|
+ await this._encService.decrypt(
|
|
|
+ order.response.MEDIDAS_OBJ.ID_SERVICIO_WEB
|
|
|
+ );
|
|
|
+ order.response.MEDIDAS_OBJ.HORA_REGISTRO =
|
|
|
+ this._functionsService.orderDate(
|
|
|
+ order.response.MEDIDAS_OBJ.HORA_REGISTRO
|
|
|
+ )!;
|
|
|
+ }
|
|
|
+
|
|
|
+ // Process resources - handle both formats
|
|
|
+ if (order.response.RECURSOS_ARR) {
|
|
|
+ // Already comes as array
|
|
|
+ } else {
|
|
|
+ // Parse from RECURSOS string
|
|
|
+ order.response.RECURSOS_ARR = JSON.parse(order.response.RECURSOS || '[]');
|
|
|
+ }
|
|
|
+
|
|
|
+ // Process personal if exists
|
|
|
+ if (order.response.PERSONAL) {
|
|
|
+ let staffArr = JSON.parse(order.response.PERSONAL);
|
|
|
+ let staffArrFn: any[] = [];
|
|
|
+ for (const item of staffArr) {
|
|
|
+ staffArrFn.push({
|
|
|
+ ID: item.ID,
|
|
|
+ NAME: item.NAME,
|
|
|
+ CANT: item.CANT,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ order.response.PERSONAL_ARR = staffArrFn;
|
|
|
+ } else {
|
|
|
+ order.response.PERSONAL_ARR = [];
|
|
|
+ }
|
|
|
+
|
|
|
+ // Process documents - handle different format
|
|
|
+ if (
|
|
|
+ order.response.DOCUMENTOS_RELACIONADOS_ARR &&
|
|
|
+ order.response.DOCUMENTOS_RELACIONADOS_ARR.length > 0
|
|
|
+ ) {
|
|
|
+ // Already processed
|
|
|
+ } else {
|
|
|
+ let documentsArr = JSON.parse(
|
|
|
+ order.response.DOCUMENTOS_RELACIONADOS || '[]'
|
|
|
+ );
|
|
|
+ let documentsArrFn: any[] = [];
|
|
|
+ for (const document of documentsArr) {
|
|
|
+ if (typeof document === 'string') {
|
|
|
+ let parts = document.split('=');
|
|
|
+ documentsArrFn.push({
|
|
|
+ name: parts[2] || document,
|
|
|
+ size: '-',
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ order.response.DOCUMENTOS_RELACIONADOS_ARR = documentsArrFn;
|
|
|
+ }
|
|
|
+
|
|
|
+ // Format dates
|
|
|
+ order.response.FECREG = this._functionsService.orderDate(
|
|
|
+ order.response.FECREG
|
|
|
+ )!;
|
|
|
+
|
|
|
+ // Handle optional fields with null checks
|
|
|
+ if (order.response.FECHA_FINAL) {
|
|
|
+ order.response.FECHA_FINAL = this._functionsService.orderDate(
|
|
|
+ order.response.FECHA_FINAL
|
|
|
+ )!;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (order.response.FECMOD) {
|
|
|
+ order.response.FECMOD = this._functionsService.orderDate(
|
|
|
+ order.response.FECMOD
|
|
|
+ )!;
|
|
|
+ }
|
|
|
+
|
|
|
+ // Handle comments - parse if it's JSON array
|
|
|
+ if (order.response.COMENTARIOS && order.response.COMENTARIOS !== '[]') {
|
|
|
+ try {
|
|
|
+ let comments = JSON.parse(order.response.COMENTARIOS);
|
|
|
+ order.response.COMENTARIOS =
|
|
|
+ comments.length > 0 ? comments.join(', ') : null;
|
|
|
+ } catch {
|
|
|
+ // Keep as string if not JSON
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ order.response.COMENTARIOS = '';
|
|
|
+ }
|
|
|
+
|
|
|
+ // Set default values for missing fields
|
|
|
+ order.response.ID_RESPONSABLE = order.response.ID_RESPONSABLE || '-';
|
|
|
+ order.response.TIPO_RESPONSABLE =
|
|
|
+ order.response.TIPO_RESPONSABLE || '-';
|
|
|
+ order.response.FECHA_INICIO = order.response.FECHA_INICIO || '-';
|
|
|
+
|
|
|
+ this.workOrder = order.response;
|
|
|
+ }
|
|
|
+
|
|
|
+ this.isLoading = false;
|
|
|
+ } catch (error: any) {
|
|
|
+ this.errorStr = error?.error?.msg || 'Ocurrió un error inesperado.';
|
|
|
+ this.hasError = true;
|
|
|
+ this.isLoading = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|