| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655 |
- import { Component, Inject, OnInit } from '@angular/core';
- import {
- NotificationAction,
- NotificationDetailsResponse,
- NotificationsListItem,
- } from '../../../interfaces/notification.interface';
- import {
- MAT_DIALOG_DATA,
- MatDialog,
- MatDialogRef,
- } from '@angular/material/dialog';
- import { EncService } from '../../../services/enc.service';
- import { NotificationsService } from '../../../services/notifications.service';
- import { ResourcesService } from '../../../services/resources.service';
- import { CorrectiveMaintenanceService } from '../../../services/corrective-maintenance.service';
- import { PreventiveMaintenanceService } from '../../../services/preventive-maintenance.service';
- import { GdelService } from '../../../services/gdel.service';
- import { ProcessManagementService } from '../../../services/process-management/process-management.service';
- import { lastValueFrom } from 'rxjs';
- import { CorrectiveOrderDetailsComponent } from '../../corrective-maintenance/operations-management/corrective-order-details/corrective-order-details.component';
- import { PreventiveOrderDetailsComponent } from '../../preventive-maintenance/preventive-order-details/preventive-order-details.component';
- import { AgreeOrderComponent } from './agree-order/agree-order.component';
- import { SignatureViewComponent } from './signature-view/signature-view.component';
- import { StaffSelectionComponent } from '../../corrective-maintenance/operations-management/staff-selection/staff-selection.component';
- import { CommentsViewComponent } from './comments-view/comments-view.component';
- import { ValidateApplicationsModalComponent } from './validate-applications-modal/validate-applications-modal.component';
- import { ResponseDataValidateApplications } from '../../../interfaces/process-managementv/workflow-management.interface';
- @Component({
- selector: 'app-notification-dialog',
- templateUrl: './notification-dialog.component.html',
- styleUrl: './notification-dialog.component.css',
- standalone: false,
- })
- export class NotificationDialogComponent implements OnInit {
- idNotification: string;
- isLoading: boolean;
- hasError: boolean;
- errorStr: string;
- isProcessingArchives: boolean;
- notification: NotificationsListItem | null;
- constructor(
- @Inject(MAT_DIALOG_DATA) private _data: any,
- private _encService: EncService,
- private _notificationsService: NotificationsService,
- private _dialog: MatDialog,
- private _resourcesService: ResourcesService,
- private _correctiveMaintenanceService: CorrectiveMaintenanceService,
- private _preventiveMaintenanceService: PreventiveMaintenanceService,
- private _processManagementService: ProcessManagementService,
- private _dialogRef: MatDialogRef<NotificationDialogComponent>,
- private _gdelService: GdelService
- ) {
- this.idNotification = '';
- this.isLoading = true;
- this.hasError = false;
- this.errorStr = '';
- this.isProcessingArchives = false;
- this.notification = null;
- }
- ngOnInit(): void {
- this.init();
- }
- async init() {
- this.idNotification = await this._encService.decrypt(
- this._data.idNotification
- );
- this.getNotification();
- }
- async getNotification() {
- try {
- let idUser = localStorage.getItem('idusuario')!;
- let notification: NotificationDetailsResponse = await lastValueFrom(
- this._notificationsService.getNotification(
- this._data.idNotification,
- 'S',
- idUser,
- 1
- )
- );
- this.hasError = notification.error;
- this.errorStr = notification.msg;
- if (!this.hasError) {
- let notificationActionsArr: NotificationAction[] = JSON.parse(
- notification.response.ACCIONES
- ).filter(
- (action: any) => action.BOTON && action.FUNCION && action.PARAMETROS
- );
- notification.response.ACCIONES_ARR = notificationActionsArr;
- if (notification.response.ID_ORDEN !== null) {
- notification.response.ID_ORDEN = await this._encService.decrypt(
- notification.response.ID_ORDEN
- );
- }
- this.notification = notification.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.isLoading = false;
- this.hasError = true;
- }
- }
- executeNotificationAction(func: string, params: string) {
- let paramsArr = JSON.parse(params);
- switch (func) {
- case 'openCorrectiveWorkOrderDetails':
- this.openCorrectiveWorkOrderDetails(paramsArr[0]);
- break;
- case 'validateCorrectiveWorkOrder':
- this.validateCorrectiveWorkOrder(paramsArr[0]);
- break;
- case 'openModule':
- this._dialogRef.close(`go|${paramsArr[0]}`);
- break;
- case 'attendCorrectiveWorkOrder':
- this.attendCorrectiveWorkOrder(paramsArr[0]);
- break;
- case 'reviewSignatureInCorrectiveWorkOrder':
- this.reviewSignatureInCorrectiveWorkOrder(paramsArr[0], paramsArr[1]);
- break;
- case 'reviewCommentsInCorrectiveWorkOrder':
- this.reviewCommentsInCorrectiveWorkOrder(paramsArr[0], paramsArr[1]);
- break;
- case 'revalidateCorrectiveWorkOrder':
- this.revalidateCorrectiveWorkOrder(paramsArr[0]);
- break;
- case 'getValidateApplications':
- this.getValidateApplications(paramsArr[0], paramsArr[1]);
- break;
- case 'asignStateToApplication':
- this.asignStateToApplication(
- paramsArr[0],
- paramsArr[1],
- paramsArr[2],
- paramsArr[3]
- );
- break;
- case 'openPreventiveWorkOrderDetails':
- this.openPreventiveWorkOrderDetails(paramsArr[0]);
- break;
- case 'validatePreventiveWorkOrder':
- this.validatePreventiveWorkOrder(paramsArr[0]);
- break;
- case 'revalidatePreventiveVisit':
- this.revalidatePreventiveVisit(paramsArr[0]);
- break;
- case 'attendPreventiveWorkOrder':
- this.attendPreventiveWorkOrder(paramsArr[0]);
- break;
- case 'reviewCommentsInPreventiveVisit':
- this.reviewCommentsInPreventiveWorkOrder(paramsArr[0], paramsArr[1]);
- break;
- case 'reviewSignatureInPreventiveVisit':
- this.reviewSignatureInPreventiveVisit(paramsArr[0], paramsArr[1]);
- break;
- default:
- this._resourcesService.openSnackBar(
- 'La función seleccionada no existe.'
- );
- break;
- }
- }
- //FUNCIONES POSIBLES PARA LAS NOTIFICACIONES
- async getValidateApplications(user: string, line: number) {
- if (!user || !line) {
- this._resourcesService.openSnackBar('Parámetros inválidos.');
- return;
- }
- try {
- const response: ResponseDataValidateApplications = await lastValueFrom(
- this._processManagementService.getValidateApplications(
- await this._encService.encrypt(user),
- line
- )
- );
- console.log(response);
- if (!response.error) {
- this._dialogRef.close();
- this._dialog.open(ValidateApplicationsModalComponent, {
- width: '1200px',
- maxWidth: '90vw',
- data: { applications: response.response },
- });
- } else {
- this._resourcesService.openSnackBar(response.msg);
- }
- } catch (error: any) {
- this._resourcesService.openSnackBar(
- error?.error?.msg || 'Ocurrió un error inesperado.'
- );
- }
- }
- async asignStateToApplication(
- user: string,
- line: number,
- idapplication: number,
- state: string
- ) {
- if (!user || !line || !idapplication || !state) {
- this._resourcesService.openSnackBar('Parámetros inválidos.');
- return;
- }
- try {
- await lastValueFrom(
- this._processManagementService.assignStateToApplication({
- USUARIO: await this._encService.encrypt(user),
- NUMERO_LINEA: line,
- ID_APPLICATION: idapplication,
- STATE: state,
- })
- );
- this._resourcesService.openSnackBar(
- 'Estado asignado correctamente a la solicitud.'
- );
- } catch (error: any) {
- this._resourcesService.openSnackBar(
- error?.error?.msg || 'Ocurrió un error inesperado.'
- );
- }
- }
- async processLoadArchives(params: any) {
- this.isProcessingArchives = true;
- try {
- let idUser = localStorage.getItem('idusuario')!;
- let body = {
- id_user: idUser,
- linea: '1',
- temp_files: params.temp_files,
- individual_temp_files: params.individual_temp_files,
- };
- await lastValueFrom(this._gdelService.processZipFile(body));
- this._resourcesService.openSnackBar('Archivos procesados correctamente.');
- this._dialogRef.close();
- } catch (error: any) {
- if (error.error?.msg) {
- this._resourcesService.openSnackBar(error.error.msg);
- } else {
- this._resourcesService.openSnackBar('Ocurrió un error inesperado.');
- }
- } finally {
- this.isProcessingArchives = false;
- }
- }
- openCorrectiveWorkOrderDetails(idOrder: string) {
- this._dialog.open(CorrectiveOrderDetailsComponent, {
- width: '480px',
- data: {
- idOrder: idOrder,
- },
- });
- }
- openPreventiveWorkOrderDetails(idOrder: string) {
- this._dialog.open(PreventiveOrderDetailsComponent, {
- width: '480px',
- data: {
- idOrder: idOrder,
- },
- });
- }
- private validateCorrectiveWorkOrder(idOrder: string) {
- let dialogRef = this._dialog.open(StaffSelectionComponent, {
- disableClose: true,
- width: '540px',
- maxWidth: '540px',
- data: {
- idOrder: idOrder,
- orderType: 'Correctivo',
- },
- });
- dialogRef.afterClosed().subscribe((res) => {
- if (res != null && res != undefined && res != '') {
- this.approveWorkOrder(idOrder, res);
- }
- });
- }
- private revalidateCorrectiveWorkOrder(idOrder: string) {
- let dialogRef = this._dialog.open(StaffSelectionComponent, {
- disableClose: true,
- width: '540px',
- maxWidth: '540px',
- data: {
- idOrder: idOrder,
- orderType: 'Correctivo',
- },
- });
- dialogRef.afterClosed().subscribe((res) => {
- if (res != null && res != undefined && res != '') {
- this.updateApprovedWorkOrder(idOrder, res);
- }
- });
- }
- private async approveWorkOrder(idOrder: string, config: string) {
- try {
- let idUser = localStorage.getItem('idusuario')!;
- let formData = new FormData();
- formData.append('id_user', idUser);
- formData.append('linea', '1');
- formData.append('id_order', idOrder);
- formData.append('config', config);
- await lastValueFrom(
- this._correctiveMaintenanceService.approveWorkOrder(formData)
- );
- this._resourcesService.openSnackBar(
- 'La orden de trabajo se aprobó correctamente.'
- );
- this._dialogRef.close();
- } catch (error: any) {
- if (error.error == undefined) {
- this._resourcesService.openSnackBar(
- 'Ocurrió un error inesperado (14).'
- );
- } else if (error.error.msg == undefined) {
- this._resourcesService.openSnackBar(
- 'Ocurrió un error inesperado (15).'
- );
- } else {
- this._resourcesService.openSnackBar(error.error.msg);
- }
- }
- }
- private async updateApprovedWorkOrder(idOrder: string, config: string) {
- try {
- let idUser = localStorage.getItem('idusuario')!;
- let formData = new FormData();
- formData.append('id_user', idUser);
- formData.append('linea', '1');
- formData.append('id_order', idOrder);
- formData.append('config', config);
- await lastValueFrom(
- this._correctiveMaintenanceService.updateApprovedWorkOrder(formData)
- );
- this._resourcesService.openSnackBar(
- 'La orden de trabajo se actualizó correctamente.'
- );
- this._dialogRef.close();
- } catch (error: any) {
- if (error.error == undefined) {
- this._resourcesService.openSnackBar(
- 'Ocurrió un error inesperado (14).'
- );
- } else if (error.error.msg == undefined) {
- this._resourcesService.openSnackBar(
- 'Ocurrió un error inesperado (15).'
- );
- } else {
- this._resourcesService.openSnackBar(error.error.msg);
- }
- }
- }
- attendCorrectiveWorkOrder(idOrder: string) {
- let dialogRef = this._dialog.open(AgreeOrderComponent, {
- disableClose: true,
- width: '560px',
- maxWidth: '560px',
- data: {
- idOrder: idOrder,
- },
- });
- dialogRef.afterClosed().subscribe((res) => {
- if (res != null && res != undefined && res != '') {
- this.saveAttendanceCorrectiveOrder(idOrder, res);
- }
- });
- }
- private async saveAttendanceCorrectiveOrder(
- idOrder: string,
- dataEnc: string
- ) {
- try {
- let idUser = localStorage.getItem('idusuario')!;
- let dataDec = await this._encService.decrypt(dataEnc);
- let dataArr = JSON.parse(dataDec);
- let formData = new FormData();
- formData.append('id_user', idUser);
- formData.append('linea', '1');
- formData.append('id_order', idOrder);
- formData.append('attendance', dataArr[0]);
- formData.append('data', dataArr[1]);
- await lastValueFrom(
- this._correctiveMaintenanceService.setWorkOrderAttendance(formData)
- );
- this._resourcesService.openSnackBar(
- 'La atención a la orden de trabajo se registró correctamente.'
- );
- this._dialogRef.close();
- } 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);
- }
- }
- }
- private reviewSignatureInCorrectiveWorkOrder(
- idOrder: string,
- idUserAction: string
- ) {
- this._dialog.open(SignatureViewComponent, {
- width: '420px',
- maxWidth: '420px',
- data: {
- idOrder: idOrder,
- idUserAction: idUserAction,
- orderType: 'Correctivo',
- },
- });
- }
- private reviewCommentsInCorrectiveWorkOrder(
- idOrder: string,
- idUserAction: string
- ) {
- this._dialog.open(CommentsViewComponent, {
- width: '420px',
- maxWidth: '420px',
- data: {
- idOrder: idOrder,
- idUserAction: idUserAction,
- orderType: 'Correctivo',
- },
- });
- }
- // PREVENTIVE MAINTENANCE FUNCTIONS
- private reviewCommentsInPreventiveWorkOrder(
- idOrder: string,
- idUserAction: string
- ) {
- this._dialog.open(CommentsViewComponent, {
- width: '420px',
- maxWidth: '420px',
- data: {
- idOrder: idOrder,
- idUserAction: idUserAction,
- orderType: 'Preventivo',
- },
- });
- }
- private reviewSignatureInPreventiveVisit(
- idOrder: string,
- idUserAction: string
- ) {
- this._dialog.open(SignatureViewComponent, {
- width: '420px',
- maxWidth: '420px',
- data: {
- idOrder: idOrder,
- idUserAction: idUserAction,
- orderType: 'Preventivo',
- },
- });
- }
- attendPreventiveWorkOrder(idOrder: string) {
- let dialogRef = this._dialog.open(AgreeOrderComponent, {
- disableClose: true,
- width: '560px',
- maxWidth: '560px',
- data: {
- idOrder: idOrder,
- },
- });
- dialogRef.afterClosed().subscribe((res) => {
- if (res != null && res != undefined && res != '') {
- this.saveAttendancePreventiveOrder(idOrder, res);
- }
- });
- }
- private async saveAttendancePreventiveOrder(
- idOrder: string,
- dataEnc: string
- ) {
- try {
- let idUser = localStorage.getItem('idusuario')!;
- let dataDec = await this._encService.decrypt(dataEnc);
- let dataArr = JSON.parse(dataDec);
- let formData = new FormData();
- formData.append('id_user', idUser);
- formData.append('linea', '1');
- formData.append('id_order', idOrder);
- formData.append('attendance', dataArr[0]);
- formData.append('data', dataArr[1]);
- await lastValueFrom(
- this._preventiveMaintenanceService.setVisitAttendance(formData)
- );
- this._resourcesService.openSnackBar(
- 'La atención a la visita preventiva se registró correctamente.'
- );
- this._dialogRef.close();
- } 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);
- }
- }
- }
- private validatePreventiveWorkOrder(idOrder: string) {
- let dialogRef = this._dialog.open(StaffSelectionComponent, {
- disableClose: true,
- width: '540px',
- maxWidth: '540px',
- data: {
- idOrder: idOrder,
- orderType: 'Preventivo',
- },
- });
- dialogRef.afterClosed().subscribe((res) => {
- if (res != null && res != undefined && res != '') {
- this.approvePreventiveWorkOrder(idOrder, res);
- }
- });
- }
- private revalidatePreventiveVisit(idOrder: string) {
- let dialogRef = this._dialog.open(StaffSelectionComponent, {
- disableClose: true,
- width: '540px',
- maxWidth: '540px',
- data: {
- idOrder: idOrder,
- orderType: 'Preventivo',
- },
- });
- dialogRef.afterClosed().subscribe((res) => {
- if (res != null && res != undefined && res != '') {
- this.updateApprovedPreventiveWorkOrder(idOrder, res);
- }
- });
- }
- private async approvePreventiveWorkOrder(idOrder: string, config: string) {
- try {
- let idUser = localStorage.getItem('idusuario')!;
- let formData = new FormData();
- formData.append('id_user', idUser);
- formData.append('linea', '1');
- formData.append('id_order', idOrder);
- formData.append('config', config);
- await lastValueFrom(
- this._preventiveMaintenanceService.assignOperariosToPreventiveVisit(
- formData
- )
- );
- this._resourcesService.openSnackBar(
- 'La orden de trabajo preventivo se aprobó correctamente.'
- );
- this._dialogRef.close();
- } catch (error: any) {
- if (error.error == undefined) {
- this._resourcesService.openSnackBar(
- 'Ocurrió un error inesperado (14).'
- );
- } else if (error.error.msg == undefined) {
- this._resourcesService.openSnackBar(
- 'Ocurrió un error inesperado (15).'
- );
- } else {
- this._resourcesService.openSnackBar(error.error.msg);
- }
- }
- }
- private async updateApprovedPreventiveWorkOrder(
- idOrder: string,
- config: string
- ) {
- try {
- let idUser = localStorage.getItem('idusuario')!;
- let formData = new FormData();
- formData.append('id_user', idUser);
- formData.append('linea', '1');
- formData.append('id_order', idOrder);
- formData.append('config', config);
- await lastValueFrom(
- this._preventiveMaintenanceService.assignOperariosToPreventiveVisit(
- formData
- )
- );
- this._resourcesService.openSnackBar(
- 'La orden de trabajo preventivo se actualizó correctamente.'
- );
- this._dialogRef.close();
- } catch (error: any) {
- if (error.error == undefined) {
- this._resourcesService.openSnackBar(
- 'Ocurrió un error inesperado (14).'
- );
- } else if (error.error.msg == undefined) {
- this._resourcesService.openSnackBar(
- 'Ocurrió un error inesperado (15).'
- );
- } else {
- this._resourcesService.openSnackBar(error.error.msg);
- }
- }
- }
- }
|