|
|
@@ -1,5 +1,15 @@
|
|
|
import { Component, Inject, OnInit } from '@angular/core';
|
|
|
import { MAT_DIALOG_DATA } from '@angular/material/dialog';
|
|
|
+import { MatTableDataSource } from '@angular/material/table';
|
|
|
+import { lastValueFrom } from 'rxjs';
|
|
|
+import { AssociatedWorkOrder, AssociatedWorkOrdersResponse } from 'src/app/interfaces/associated-work-orders.interface';
|
|
|
+import { GdelService } from 'src/app/services/document-management/gdel.service';
|
|
|
+import { EncService } from 'src/app/services/enc/enc.service';
|
|
|
+import { SystemAdminService } from 'src/app/services/system-admin.service';
|
|
|
+import { PriorityInterface } from '../../system-admin/system-params/system-params.component';
|
|
|
+import { PreventiveMaintenanceService } from 'src/app/services/preventive-maintenance.service';
|
|
|
+import { PreventiveWorkOrdersActive, PreventiveWorkOrdersActiveResponse } from 'src/app/interfaces/preventive-work-orders-active.interface';
|
|
|
+import { MatSnackBar } from '@angular/material/snack-bar';
|
|
|
|
|
|
@Component({
|
|
|
selector: 'app-order-associaton',
|
|
|
@@ -7,12 +17,204 @@ import { MAT_DIALOG_DATA } from '@angular/material/dialog';
|
|
|
styleUrls: ['./order-associaton.component.css']
|
|
|
})
|
|
|
export class OrderAssociatonComponent implements OnInit {
|
|
|
+ isLoading: boolean;
|
|
|
+ hasError: boolean;
|
|
|
+ errorStr: string;
|
|
|
+ idFile: string;
|
|
|
+
|
|
|
+ displayedColumns = ['ID', 'EQUIPAMIENTO', 'ACTIVADOR', 'CLASIFICACION', 'PRIORIDAD', 'ACCIONES'];
|
|
|
+ dataSource: MatTableDataSource<AssociatedWorkOrder>;
|
|
|
+ orderPriorities: PriorityInterface[];
|
|
|
+
|
|
|
+ dataSourceOrders: MatTableDataSource<AssociatedWorkOrder>;
|
|
|
|
|
|
constructor(
|
|
|
@Inject(MAT_DIALOG_DATA) private _data: any,
|
|
|
- ) {}
|
|
|
+ private _encService: EncService,
|
|
|
+ private _gdelService: GdelService,
|
|
|
+ private _sysAdminService: SystemAdminService,
|
|
|
+ private _prevMaintService: PreventiveMaintenanceService,
|
|
|
+ private _snackBar: MatSnackBar,
|
|
|
+ ) {
|
|
|
+ this.isLoading = true;
|
|
|
+ this.hasError = false;
|
|
|
+ this.errorStr = '';
|
|
|
+ this.idFile = '';
|
|
|
+
|
|
|
+ this.dataSource = new MatTableDataSource();
|
|
|
+ this.orderPriorities = [];
|
|
|
+
|
|
|
+ this.dataSourceOrders = new MatTableDataSource();
|
|
|
+ }
|
|
|
|
|
|
ngOnInit(): void {
|
|
|
+ this.idFile = this._data.idFile;
|
|
|
+ this.getAssociatedOrders();
|
|
|
+ }
|
|
|
+
|
|
|
+ async getAssociatedOrders(){
|
|
|
+ try{
|
|
|
+ this.isLoading = true;
|
|
|
+ this.hasError = false;
|
|
|
+ this.errorStr = '';
|
|
|
+
|
|
|
+ let idUser = localStorage.getItem('idusuario');
|
|
|
+ let shortEnc = await lastValueFrom(this._encService.shortEncrypt(idUser!));
|
|
|
+ let idFileEnc = await this._encService.encrypt(this.idFile);
|
|
|
+ let idFileShort = await lastValueFrom(this._encService.shortEncrypt(idFileEnc));
|
|
|
+
|
|
|
+ let orders: AssociatedWorkOrdersResponse = await lastValueFrom(this._gdelService.getAssociatedWorkOrders(
|
|
|
+ idFileShort.response.encrypted,
|
|
|
+ shortEnc.response.encrypted,
|
|
|
+ 1
|
|
|
+ ));
|
|
|
+
|
|
|
+ this.hasError = orders.error;
|
|
|
+ this.errorStr = orders.msg;
|
|
|
+
|
|
|
+ if(this.hasError){
|
|
|
+ this.isLoading = false
|
|
|
+ }else{
|
|
|
+ this.dataSource = new MatTableDataSource(orders.response);
|
|
|
+ this.getPriorities();
|
|
|
+ }
|
|
|
+ }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;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ async getPriorities(){
|
|
|
+ try{
|
|
|
+ let idUser = localStorage.getItem('idusuario');
|
|
|
+ let shortEnc = await lastValueFrom(this._encService.shortEncrypt(idUser!));
|
|
|
+ let priorities = await lastValueFrom(this._sysAdminService.getOrderPriorities(shortEnc.response.encrypted, 1));
|
|
|
+
|
|
|
+ if(priorities.error){
|
|
|
+ this.hasError = priorities.error;
|
|
|
+ this.errorStr = priorities.msg;
|
|
|
+ this.isLoading = false;
|
|
|
+ }else{
|
|
|
+ this.orderPriorities = priorities.response.order_priorities;
|
|
|
+ this.getActiveOrders();
|
|
|
+ }
|
|
|
+ }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;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ async getActiveOrders(){
|
|
|
+ try{
|
|
|
+ let idUser = localStorage.getItem('idusuario');
|
|
|
+ let shortEnc = await lastValueFrom(this._encService.shortEncrypt(idUser!));
|
|
|
+
|
|
|
+ let activeOrders: PreventiveWorkOrdersActiveResponse = await lastValueFrom(this._prevMaintService.getActiveWorkOrders(shortEnc.response.encrypted, 1));
|
|
|
+
|
|
|
+ this.hasError = activeOrders.error;
|
|
|
+ this.errorStr = activeOrders.msg;
|
|
|
+
|
|
|
+ if(!this.hasError){
|
|
|
+ let nonAssociatedOrders: AssociatedWorkOrder[] = [];
|
|
|
+ let associatedOrders = this.dataSource.data;
|
|
|
+
|
|
|
+ activeOrders.response.forEach(order => {
|
|
|
+ let filt = associatedOrders.filter(item => order.IDORDEN == item.IDORDEN);
|
|
|
+ if(filt.length <= 0){
|
|
|
+ let nonAssociatedOrder: AssociatedWorkOrder = {
|
|
|
+ IDORDEN: order.IDORDEN,
|
|
|
+ EQUIPAMIENTO: order.EQUIPAMIENTO,
|
|
|
+ ACTIVADOR: order.ACTIVADOR,
|
|
|
+ CLASIFICACION: order.CLASIFICACION,
|
|
|
+ PRIORIDAD: order.PRIORIDAD,
|
|
|
+ TIPOACTIVADOR: order.TIPOACTIVADOR
|
|
|
+ };
|
|
|
+
|
|
|
+ nonAssociatedOrders.push(nonAssociatedOrder);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ this.dataSourceOrders = new MatTableDataSource(nonAssociatedOrders);
|
|
|
+ }
|
|
|
+
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ getPriorityStr(priorityStr: string): string{
|
|
|
+ let priorityFiltered = this.orderPriorities.filter(item => item.value == priorityStr);
|
|
|
+ if(priorityFiltered.length == 0) return "-";
|
|
|
|
|
|
+ let priority = priorityFiltered[0];
|
|
|
+ return priority.label;
|
|
|
+ }
|
|
|
+
|
|
|
+ getFontColor(priorityStr: string): string{
|
|
|
+ let priorityFiltered = this.orderPriorities.filter(item => item.value == priorityStr);
|
|
|
+ if(priorityFiltered.length == 0) return "rgb(0, 0, 0)";
|
|
|
+
|
|
|
+ let priority = priorityFiltered[0];
|
|
|
+ return priority.color;
|
|
|
+ }
|
|
|
+
|
|
|
+ async changeAssociationStatus(newStatus: string, idOrder: number){
|
|
|
+ try{
|
|
|
+ let idUser = localStorage.getItem('idusuario');
|
|
|
+ let idFileEnc = await this._encService.encrypt(this.idFile);
|
|
|
+ let idOrderEnc = await this._encService.encrypt(`${idOrder}`);
|
|
|
+ let formData = new FormData();
|
|
|
+
|
|
|
+ formData.append('id_user', idUser!);
|
|
|
+ formData.append('linea', '1');
|
|
|
+ formData.append('id_file', idFileEnc);
|
|
|
+ formData.append('action', newStatus);
|
|
|
+ formData.append('id_order', idOrderEnc);
|
|
|
+
|
|
|
+ await lastValueFrom(this._gdelService.changeAssociationStatus(formData));
|
|
|
+
|
|
|
+ this.openSnackBar('La asociación del documento se actualizó correctamente');
|
|
|
+ this.getAssociatedOrders();
|
|
|
+ }catch(error: any){
|
|
|
+ if(error.error == undefined){
|
|
|
+ this.openSnackBar('Ocurrió un error inesperado.');
|
|
|
+ }else if(error.error.msg == undefined){
|
|
|
+ this.openSnackBar('Ocurrió un error inesperado.');
|
|
|
+ }else{
|
|
|
+ this.openSnackBar(error.error.msg);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ openSnackBar(msg: string){
|
|
|
+ this._snackBar.open(msg, undefined, {
|
|
|
+ duration: 2500,
|
|
|
+ })
|
|
|
}
|
|
|
}
|