|
|
@@ -1,28 +1,42 @@
|
|
|
import { Component, OnInit, ViewChild } from '@angular/core';
|
|
|
import { MatTableDataSource } from '@angular/material/table';
|
|
|
-import { UnprogrammedVisit, UnprogrammedVisitsResponse } from '../../../interfaces/unprogrammed-visits.interface';
|
|
|
+import {
|
|
|
+ UnprogrammedVisit,
|
|
|
+ UnprogrammedVisitsResponse,
|
|
|
+} from '../../../interfaces/unprogrammed-visits.interface';
|
|
|
import { MatPaginator } from '@angular/material/paginator';
|
|
|
import { MatSort } from '@angular/material/sort';
|
|
|
import { EncService } from '../../../services/enc.service';
|
|
|
import { PreventiveMaintenanceService } from '../../../services/preventive-maintenance.service';
|
|
|
-import { MatDialog } from '@angular/material/dialog';
|
|
|
-import { Router } from '@angular/router';
|
|
|
-import { ResourcesService } from '../../../services/resources.service';
|
|
|
import { lastValueFrom } from 'rxjs';
|
|
|
-import { VisitDetailsComponent } from './visit-details/visit-details.component';
|
|
|
+import { Router } from '@angular/router';
|
|
|
+import { PriorityInterface } from '../../system-admin/system-params/system-params.component';
|
|
|
+import { SystemAdminService } from '../../../services/system-admin.service';
|
|
|
+import { FunctionsService } from '../../../services/functions.service';
|
|
|
+import { MatDialog } from '@angular/material/dialog';
|
|
|
+import { PreventiveOrderDetailsComponent } from '../preventive-order-details/preventive-order-details.component';
|
|
|
|
|
|
@Component({
|
|
|
- selector: 'app-unprogrammed-visits',
|
|
|
- templateUrl: './unprogrammed-visits.component.html',
|
|
|
- styleUrl: './unprogrammed-visits.component.css',
|
|
|
- standalone: false
|
|
|
+ selector: 'app-unprogrammed-visits',
|
|
|
+ templateUrl: './unprogrammed-visits.component.html',
|
|
|
+ styleUrl: './unprogrammed-visits.component.css',
|
|
|
+ standalone: false,
|
|
|
})
|
|
|
export class UnprogrammedVisitsComponent implements OnInit {
|
|
|
btnSmall: boolean;
|
|
|
- txtBuscador:string;
|
|
|
+ txtBuscador: string;
|
|
|
|
|
|
dataSource?: MatTableDataSource<UnprogrammedVisit>;
|
|
|
- displayedColumns = ['ID', 'EQUIP', 'ESTA', 'ACCONES'];
|
|
|
+ displayedColumns = [
|
|
|
+ 'numeracion',
|
|
|
+ 'equipamiento',
|
|
|
+ 'descripcion',
|
|
|
+ 'estado',
|
|
|
+ 'prioridad',
|
|
|
+ 'tipoActivacion',
|
|
|
+ 'fechaRegistro',
|
|
|
+ 'acciones',
|
|
|
+ ];
|
|
|
|
|
|
@ViewChild(MatPaginator) paginator?: MatPaginator;
|
|
|
@ViewChild(MatSort) sort?: MatSort;
|
|
|
@@ -30,76 +44,150 @@ export class UnprogrammedVisitsComponent implements OnInit {
|
|
|
isLoading: boolean;
|
|
|
hasError: boolean;
|
|
|
errorStr: string;
|
|
|
- statusMap: Map<string, string>;
|
|
|
+ priorityMap: Map<string, PriorityInterface>;
|
|
|
+
|
|
|
+ private readonly activationTypeLabels: Record<string, string> = {
|
|
|
+ A: 'Automática',
|
|
|
+ M: 'Manual',
|
|
|
+ };
|
|
|
+
|
|
|
+ private readonly statusLabels: Record<string, string> = {
|
|
|
+ VA: 'Validado',
|
|
|
+ EP: 'En proceso',
|
|
|
+ CP: 'Cerrado pendiente',
|
|
|
+ CE: 'Cerrado',
|
|
|
+ P: 'Pendiente',
|
|
|
+ C: 'Cancelado',
|
|
|
+ R: 'Rechazado',
|
|
|
+ A: 'Aprobado',
|
|
|
+ F: 'Finalizado',
|
|
|
+ };
|
|
|
|
|
|
constructor(
|
|
|
private _encService: EncService,
|
|
|
private _prevMaintService: PreventiveMaintenanceService,
|
|
|
- private _dialog: MatDialog,
|
|
|
private _router: Router,
|
|
|
- private _resourcesService: ResourcesService,
|
|
|
- ) {
|
|
|
+ private _sysAdminService: SystemAdminService,
|
|
|
+ private _functionsService: FunctionsService,
|
|
|
+ private _dialog: MatDialog
|
|
|
+ ) {
|
|
|
this.btnSmall = window.innerWidth <= 1530;
|
|
|
this.txtBuscador = '';
|
|
|
this.isLoading = true;
|
|
|
this.hasError = false;
|
|
|
this.errorStr = '';
|
|
|
this.dataSource = new MatTableDataSource();
|
|
|
-
|
|
|
- this.statusMap = new Map();
|
|
|
+ this.priorityMap = new Map();
|
|
|
}
|
|
|
|
|
|
ngOnInit(): void {
|
|
|
- this.statusMap.set('P', 'Pendiente de autorización');
|
|
|
- this.statusMap.set('A', 'Autorizado');
|
|
|
- this.statusMap.set('F', 'Finalizado');
|
|
|
- this.statusMap.set('R', 'Rechazado');
|
|
|
- this.statusMap.set('C', 'Cancelado');
|
|
|
+ this.getOrderPriorities();
|
|
|
+ }
|
|
|
+
|
|
|
+ async getOrderPriorities() {
|
|
|
+ try {
|
|
|
+ let idUser = localStorage.getItem('idusuario')!;
|
|
|
+ let priorities = await lastValueFrom(
|
|
|
+ this._sysAdminService.getOrderPriorities(idUser, 1)
|
|
|
+ );
|
|
|
|
|
|
- this.getUnprogrammedVisits();
|
|
|
+ if (!priorities.error) {
|
|
|
+ this.priorityMap.clear();
|
|
|
+ const prioritiesArr = priorities.response?.order_priorities as
|
|
|
+ | PriorityInterface[]
|
|
|
+ | undefined;
|
|
|
+
|
|
|
+ if (prioritiesArr?.length) {
|
|
|
+ for (const item of prioritiesArr) {
|
|
|
+ const valueKey = `${item.value}`.trim();
|
|
|
+ const formattedPriority: PriorityInterface = {
|
|
|
+ ...item,
|
|
|
+ value: valueKey,
|
|
|
+ label: `${item.label} (${item.value})`,
|
|
|
+ };
|
|
|
+ this.priorityMap.set(valueKey, formattedPriority);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ console.error('Error loading order priorities', error);
|
|
|
+ } finally {
|
|
|
+ this.getUnprogrammedVisits();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- async getUnprogrammedVisits(){
|
|
|
- try{
|
|
|
+ async getUnprogrammedVisits() {
|
|
|
+ try {
|
|
|
this.isLoading = true;
|
|
|
this.hasError = false;
|
|
|
this.errorStr = '';
|
|
|
|
|
|
let idUser = localStorage.getItem('idusuario')!;
|
|
|
- let visits: UnprogrammedVisitsResponse = await lastValueFrom(this._prevMaintService.getUnprogrammedVisits(
|
|
|
- idUser,
|
|
|
- 1
|
|
|
- ));
|
|
|
+ let visits: UnprogrammedVisitsResponse = await lastValueFrom(
|
|
|
+ this._prevMaintService.getUnprogrammedVisits(idUser, 1)
|
|
|
+ );
|
|
|
|
|
|
this.hasError = visits.error;
|
|
|
this.errorStr = visits.msg;
|
|
|
-
|
|
|
- if(!this.hasError){
|
|
|
+ if (!this.hasError) {
|
|
|
let visitsArr: UnprogrammedVisit[] = [];
|
|
|
- for(const visit of visits.response){
|
|
|
+ for (const visit of visits.response) {
|
|
|
visit.IDVISITA = await this._encService.decrypt(visit.IDVISITA);
|
|
|
|
|
|
- let equipmentCodeDec = await this._encService.decrypt(visit.EQUIPAMIENTO);
|
|
|
+ let equipmentCodeDec = await this._encService.decrypt(
|
|
|
+ visit.EQUIPAMIENTO
|
|
|
+ );
|
|
|
visit.TIPO_EQUIPAMIENTO = `${equipmentCodeDec} - ${visit.TIPO_EQUIPAMIENTO}`;
|
|
|
|
|
|
- let equipmentIDDec = await this._encService.decrypt(visit.ID_EQUIPAMIENTO);
|
|
|
+ let equipmentIDDec = await this._encService.decrypt(
|
|
|
+ visit.ID_EQUIPAMIENTO
|
|
|
+ );
|
|
|
visit.MODELO_EQUIPAMIENTO = `${visit.MODELO_EQUIPAMIENTO} (${equipmentIDDec})`;
|
|
|
|
|
|
+ if (visit.PRIORIDAD) {
|
|
|
+ const priorityValue = await this.decryptWithFallback(
|
|
|
+ visit.PRIORIDAD
|
|
|
+ );
|
|
|
+ visit.PRIORIDAD = priorityValue;
|
|
|
+
|
|
|
+ const priorityInfo = this.priorityMap.get(priorityValue.trim());
|
|
|
+ if (priorityInfo) {
|
|
|
+ visit.PRIORIDAD_OBJ = priorityInfo;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ const activationKey = (visit.TIPO_ACTIVACION || '').toUpperCase();
|
|
|
+ visit.TIPO_ACTIVACION_LABEL =
|
|
|
+ this.activationTypeLabels[activationKey] ||
|
|
|
+ visit.TIPO_ACTIVACION ||
|
|
|
+ 'N/A';
|
|
|
+
|
|
|
+ const statusKey = (visit.ESTADO || '').toUpperCase();
|
|
|
+ visit.ESTADO_LABEL =
|
|
|
+ this.statusLabels[statusKey] || visit.ESTADO || 'N/A';
|
|
|
+
|
|
|
+ if (visit.FECREG) {
|
|
|
+ visit.FECREG_FMT = this._functionsService.orderDate(visit.FECREG);
|
|
|
+ if (!visit.FECREG_FMT) {
|
|
|
+ visit.FECREG_FMT = visit.FECREG;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
visitsArr.push(visit);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
this.dataSource = new MatTableDataSource(visitsArr);
|
|
|
this.dataSource.paginator = this.paginator!;
|
|
|
this.dataSource.sort = this.sort!;
|
|
|
}
|
|
|
|
|
|
this.isLoading = false;
|
|
|
- }catch(error: any){
|
|
|
- if(error.error == undefined){
|
|
|
+ } catch (error: any) {
|
|
|
+ if (error.error == undefined) {
|
|
|
this.errorStr = 'Ocurrió un error inesperado.';
|
|
|
- }else if(error.error.msg == undefined){
|
|
|
+ } else if (error.error.msg == undefined) {
|
|
|
this.errorStr = 'Ocurrió un error inesperado.';
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
this.errorStr = error.error.msg;
|
|
|
}
|
|
|
|
|
|
@@ -108,100 +196,66 @@ export class UnprogrammedVisitsComponent implements OnInit {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public onResize():void {
|
|
|
+ public onResize(): void {
|
|
|
this.btnSmall = window.innerWidth <= 1530;
|
|
|
}
|
|
|
|
|
|
- goBack(steps: number){
|
|
|
+ goBack(steps: number) {
|
|
|
window.history.go(steps * -1);
|
|
|
}
|
|
|
|
|
|
- applyFilter(event: any, type: string){
|
|
|
- let filterValue:string;
|
|
|
- if (type == 'INP') {
|
|
|
+ applyFilter(event: any, type: string) {
|
|
|
+ let filterValue: string;
|
|
|
+ if (type === 'INP') {
|
|
|
filterValue = (event.target as HTMLInputElement).value;
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
this.txtBuscador = event;
|
|
|
filterValue = event;
|
|
|
}
|
|
|
this.dataSource!.filter = filterValue.trim().toLowerCase();
|
|
|
|
|
|
- if(this.dataSource?.paginator){
|
|
|
+ if (this.dataSource?.paginator) {
|
|
|
this.dataSource.paginator.firstPage();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- registerVisit(){
|
|
|
- this._router.navigate(['sam/GMPR/AOTR/RVTP/register']);
|
|
|
- }
|
|
|
-
|
|
|
- openVisitDetails(id: number){
|
|
|
- this._dialog.open(VisitDetailsComponent, {
|
|
|
- width: '560px',
|
|
|
- maxWidth: '560px',
|
|
|
- data: {
|
|
|
- idVisit: id,
|
|
|
- }
|
|
|
- })
|
|
|
+ registerVisit() {
|
|
|
+ this._router.navigate(['sam/GMPR/AOTR/RVTP/register']);
|
|
|
}
|
|
|
|
|
|
- openCommentsDialog(idVisit: number, action: string){
|
|
|
- let dialogRef = this._dialog.open(CommentsDialog, {
|
|
|
- width: '380px',
|
|
|
- maxWidth: '380px',
|
|
|
- });
|
|
|
-
|
|
|
- dialogRef.afterClosed().subscribe(res => {
|
|
|
- if(res != null && res != undefined && res != ''){
|
|
|
- switch(action){
|
|
|
- case 'auth':
|
|
|
- this.updateVisitStatus(idVisit, res, 'A');
|
|
|
- break;
|
|
|
- case 'end':
|
|
|
- this.updateVisitStatus(idVisit, res, 'F');
|
|
|
- break;
|
|
|
- case 'decline':
|
|
|
- this.updateVisitStatus(idVisit, res, 'R');
|
|
|
- break;
|
|
|
- case 'cancel':
|
|
|
- this.updateVisitStatus(idVisit, res, 'C');
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
+ async openVisitDetails(idVisit: string) {
|
|
|
+ try {
|
|
|
+ const idVisitEnc = await this._encService.encrypt(idVisit);
|
|
|
+ this._dialog.open(PreventiveOrderDetailsComponent, {
|
|
|
+ width: '480px',
|
|
|
+ maxWidth: '480px',
|
|
|
+ data: {
|
|
|
+ idOrder: idVisitEnc,
|
|
|
+ },
|
|
|
+ });
|
|
|
+ } catch (error) {
|
|
|
+ console.error('Error opening visit details dialog', error);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- async updateVisitStatus(idVisit: number, comments: string, status: string){
|
|
|
- try{
|
|
|
- let idUser = localStorage.getItem('idusuario');
|
|
|
- let idVisitEnc = await this._encService.encrypt(`${idVisit}`);
|
|
|
- let formData = new FormData();
|
|
|
-
|
|
|
- formData.append('id_user', idUser!);
|
|
|
- formData.append('linea', '1');
|
|
|
- formData.append('id_visit', idVisitEnc);
|
|
|
- formData.append('comments', comments);
|
|
|
- formData.append('status', status);
|
|
|
-
|
|
|
- await lastValueFrom(this._prevMaintService.updateVisitStatus(formData));
|
|
|
+ private async decryptWithFallback(
|
|
|
+ value: string | null | undefined
|
|
|
+ ): Promise<string> {
|
|
|
+ if (!value) {
|
|
|
+ return '';
|
|
|
+ }
|
|
|
|
|
|
- this._resourcesService.openSnackBar('La visita se actualizó correctamente.');
|
|
|
- this.getUnprogrammedVisits();
|
|
|
- }catch(error: any){
|
|
|
- if(error.error == undefined){
|
|
|
- this._resourcesService.openSnackBar('Ocurrió un error inesperado.');
|
|
|
- }else if(error.error.msg == undefined){
|
|
|
- this._resourcesService.openSnackBar('Ocurrió un error inesperado.');
|
|
|
- }else{
|
|
|
- this._resourcesService.openSnackBar(error.error.msg);
|
|
|
- }
|
|
|
+ try {
|
|
|
+ const decrypted = await this._encService.decrypt(value);
|
|
|
+ return decrypted.trim();
|
|
|
+ } catch (error) {
|
|
|
+ return `${value}`.trim();
|
|
|
}
|
|
|
}
|
|
|
-}
|
|
|
|
|
|
-@Component({
|
|
|
- selector: 'comments-dialog',
|
|
|
- templateUrl: './comments-dialog.html',
|
|
|
- standalone: false
|
|
|
-})
|
|
|
-export class CommentsDialog {}
|
|
|
+ getRowIndex(index: number): number {
|
|
|
+ const pageIndex = this.paginator?.pageIndex ?? 0;
|
|
|
+ const pageSize = this.paginator?.pageSize ?? 10;
|
|
|
+ return pageIndex * pageSize + index + 1;
|
|
|
+ }
|
|
|
+}
|