Parcourir la source

Merge branch 'master' of http://209.50.56.224/git/ITTEC/SistemaMantenimiento

JeanBenitez il y a 1 an
Parent
commit
83cd589674

+ 2 - 2
sistema-mantenimiento-front/src/app/components/preventive-maintenance/work-orders/new-work-order/new-instruction/new-instruction.component.html

@@ -14,7 +14,7 @@
     <mat-form-field style="width: calc(50% - 4px);" appearance="outline">
       <mat-label>Fecha de inicio</mat-label>
       <input matInput [matDatepicker]="startDatePicker" [(ngModel)]="startDate" (ngModelChange)="verifyDateTime('start')" required 
-      [max]="endDate == null ? undefined : endDate">
+      [max]="endDate == null ? undefined : endDate" [min]="minDate">
       <button class="hidden" id="clearStartDate" (click)="clearStartDate($event)"></button>
       <mat-datepicker-toggle matIconSuffix [for]="startDatePicker">
         <mat-icon matDatepickerToggleIcon>arrow_drop_down</mat-icon>
@@ -39,7 +39,7 @@
     <mat-form-field style="width: calc(50% - 4px);" appearance="outline">
       <mat-label>Fecha de término</mat-label>
       <input matInput [matDatepicker]="endDatePicker" [(ngModel)]="endDate" (ngModelChange)="verifyDateTime('end')" required 
-      [min]="startDate == null ? undefined : startDate">
+      [min]="startDate == null ? undefined : startDate" [max]="maxDate">
       <button class="hidden" id="clearEndDate" (click)="clearEndDate($event)"></button>
       <mat-datepicker-toggle matIconSuffix [for]="endDatePicker">
         <mat-icon matDatepickerToggleIcon>arrow_drop_down</mat-icon>

+ 9 - 0
sistema-mantenimiento-front/src/app/components/preventive-maintenance/work-orders/new-work-order/new-instruction/new-instruction.component.ts

@@ -18,6 +18,9 @@ export class NewInstructionComponent implements OnInit {
   startHour: string | null;
   endHour: string | null;
 
+  minDate: Date | null;
+  maxDate: Date | null;
+
   instructionControl = new FormControl('', [Validators.required, Validators.minLength(20)]);
 
   constructor(
@@ -33,10 +36,16 @@ export class NewInstructionComponent implements OnInit {
     this.endDate = null;
     this.startHour = null;
     this.endHour = null;
+
+    this.minDate = null;
+    this.maxDate = null;
   }
 
   ngOnInit(): void {
+    this.minDate = this._data.startDate;
+    this.maxDate = this._data.endDate;
     this.isNew = this._data.action == 'new';
+
     if(!this.isNew){
       let startDateTimeArr = this._data.instruction.INICIO.split(' ');
       let startDateArr = startDateTimeArr[0].split('-');

+ 4 - 4
sistema-mantenimiento-front/src/app/components/preventive-maintenance/work-orders/new-work-order/new-work-order.component.css

@@ -76,18 +76,17 @@
 .instruction-title{
   font-weight: 500;
   margin-right: 8px;
-  width: 40%;
+  width: 35%;
   box-sizing: border-box;
   text-overflow: ellipsis;
   overflow: hidden;
   /*white-space: nowrap;*/
   max-lines: 2;
-  width: calc(100% - 928px);
 }
 
 .instruction-duration{
   margin-right: 8px;
-  width: 35%;
+  width: calc(65% - 88px);
   box-sizing: border-box;
   text-overflow: ellipsis;
   overflow: hidden;
@@ -97,7 +96,7 @@
 }
 
 .instruction-actions{
-  width: 25%;
+  width: 88px;
   display: flex;
   flex-direction: row;
   align-items: center;
@@ -143,6 +142,7 @@
   display: flex;
   flex-direction: row;
   align-items: center;
+  justify-content: space-between;
   box-sizing: border-box;
   cursor: move;
   background: white;

+ 65 - 156
sistema-mantenimiento-front/src/app/components/preventive-maintenance/work-orders/new-work-order/new-work-order.component.ts

@@ -398,9 +398,9 @@ export class NewWorkOrderComponent implements OnInit {
         let resCont = 0;
 
         //PENDIENTE INCLUIR STOCK
-        this.orderFormGroup.controls['toolsControl'].setValue(['SH']);
+        /*this.orderFormGroup.controls['toolsControl'].setValue(['SH']);
         this.orderFormGroup.controls['sparePartsControl'].setValue(['SH']);
-        this.toolsChange(['SH'], ['SH']);
+        this.toolsChange(['SH'], ['SH']);*/
 
         if(order.response.DOCUMENTOS != null){
           let attached = JSON.parse(order.response.DOCUMENTOS!);
@@ -456,7 +456,7 @@ export class NewWorkOrderComponent implements OnInit {
           this.getActivatorsByType(activatorTypeInd, activator);
         } 
 
-        this.getEmployees();
+        this._getToolsAndSpare();
       }
     }catch(error: any){
       if(error.error == undefined){
@@ -472,156 +472,6 @@ export class NewWorkOrderComponent implements OnInit {
     }
   }
 
-  async getEmployees(){
-    try{
-      let idUser = localStorage.getItem('idusuario')!;
-      let employees: EmployeesListResponse = await lastValueFrom(this._employeeService.getConsultOfEmployees(idUser, 1));
-
-      this.hasError = employees.error;
-      this.errorStr = employees.msg;
-
-      if(this.hasError){
-        this.isLoading = false;
-      }else{
-        let employeesSelected: string[] = [];
-        if(this.workOrder != null){
-          let staffArr = JSON.parse(this.workOrder.OPERARIOS);
-          let employeesFilt = staffArr.filter((item: any) => item.TYPE == 'EM');
-          for(const employee of employeesFilt){
-            let idDec = await this._encService.decrypt(employee.ID);
-            employeesSelected.push(idDec);
-          }
-        }
-        
-        let staffVal = this.orderFormGroup.controls['staffControl'].value;
-        for(const employee of employees.response){
-          let idEmployeeDec = await this._encService.decrypt(employee.ID_EMPLOYEE);
-          if(employeesSelected.includes(idEmployeeDec)){
-            staffVal.push(`${employee.ID_EMPLOYEE}-EM`);
-          }
-
-          employee.NAME = `${employee.NAME} (${idEmployeeDec})`;
-          if(employee.STATUS == 'Activo'){
-            this.employees.push(employee);
-          }
-        }
-        
-        this.orderFormGroup.controls['staffControl'].setValue(staffVal);
-        this.getSubcontratists();
-      }
-    }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);
-      }
-
-      this.hasError = true;
-      this.isLoading = false;
-    }
-  }
-
-  async getSubcontratists(){
-    try{
-      let idUser = localStorage.getItem('idusuario')!;
-      let subcontratists: SubcontratistsResponse = await lastValueFrom(this._subcontratistService.getConsultOfSubcontratists(idUser, 1));
-
-      this.hasError = subcontratists.error;
-      this.errorStr = subcontratists.msg;
-
-      if(this.hasError){
-        this.isLoading = false;
-      }else{
-        let subcontratistsSelected: string[] = [];
-        if(this.workOrder != null){
-          let staffArr = JSON.parse(this.workOrder.OPERARIOS);
-          let subcontratistsFilt = staffArr.filter((item: any) => item.TYPE == 'SU');
-          for(const subcontratist of subcontratistsFilt){
-            let idDec = await this._encService.decrypt(subcontratist.ID);
-            subcontratistsSelected.push(idDec);
-          }
-        }
-
-        let staffVal = this.orderFormGroup.controls['staffControl'].value;
-        for(const subcontratist of subcontratists.response){
-          let idSubcontratistDec = await this._encService.decrypt(subcontratist.ID_SUBCONTRATIST);
-          if(subcontratistsSelected.includes(idSubcontratistDec)){
-            staffVal.push(`${subcontratist.ID_SUBCONTRATIST}-SU`);
-          }
-
-          subcontratist.NAME = `${subcontratist.NAME} (${idSubcontratistDec})`;
-          if(subcontratist.STATUS == 'Activo'){
-            this.subcontratists.push(subcontratist);
-          }
-        }
-
-        this.orderFormGroup.controls['staffControl'].setValue(staffVal);
-        this.getWorkTeams();
-      }
-    }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);
-      }
-
-      this.hasError = true;
-      this.isLoading = false;
-    }
-  }
-
-  async getWorkTeams(){
-    try{
-      let idUser = localStorage.getItem('idusuario')!;
-      let workTeams = await lastValueFrom(this._workTeamsService.getConsultOfWorkteams(idUser, 1));
-
-      this.hasError = workTeams.error;
-      this.errorStr = workTeams.msg;
-
-      if(this.hasError){
-        this.isLoading = false;
-      }else{
-        let workTeamsSelected: number[] = [];
-        if(this.workOrder != null){
-          let staffArr = JSON.parse(this.workOrder.OPERARIOS);
-          let workTeamsFilt = staffArr.filter((item: any) => item.TYPE == 'EQ');
-          for(const workTeam of workTeamsFilt){
-            let idDec = await this._encService.decrypt(workTeam.ID);
-            workTeamsSelected.push(parseInt(idDec));
-          }
-        }
-        
-        let staffVal = this.orderFormGroup.controls['staffControl'].value;
-        for(const workTeam of workTeams.response){
-          let idWorkTeamDec = await this._encService.decrypt(workTeam.WORKTEAM_ID);
-
-          workTeam.NAME = `${workTeam.NAME} (${idWorkTeamDec})`;
-          if(workTeam.STATUS == 'Activo'){
-            this.workTeams.push(workTeam);
-          }
-        }
-
-        this.orderFormGroup.controls['staffControl'].setValue(staffVal);
-        this.getSpecialties();
-      }
-    }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);
-      }
-
-      this.hasError = true;
-      this.isLoading = false;
-    }
-  }
-
   async getSpecialties(){
     try{
       let idUser = localStorage.getItem('idusuario')!;
@@ -631,6 +481,15 @@ export class NewWorkOrderComponent implements OnInit {
       this.errorStr = specialties.msg;
 
       if(!this.hasError){
+        let specialtiesSelected: string[] = [];
+        if(this.workOrder != null){
+          let staffArr: any[] = JSON.parse(this.workOrder.OPERARIOS);
+          for(const item of staffArr){
+            let idDec = await this._encService.decrypt(item.ID);
+            specialtiesSelected.push(idDec);
+          }
+        }
+
         let specialtiesArr: SpecialtiesListItem[] = [];
         for(const specialty of specialties.response){
           let codeDec = await this._encService.decrypt(specialty.CODIGO_ESPECIALIDAD);
@@ -638,6 +497,11 @@ export class NewWorkOrderComponent implements OnInit {
           
           if(specialty.ESTADO == 'Activo'){
             specialtiesArr.push(specialty);
+
+            let specialtiesVal = this.orderFormGroup.controls['staffControl'].value;
+            if(specialtiesSelected.includes(codeDec)){
+              specialtiesVal.push(specialty.CODIGO_ESPECIALIDAD);
+            }
           }
         }
 
@@ -662,6 +526,34 @@ export class NewWorkOrderComponent implements OnInit {
 
   initTables(){
     setTimeout(() => {
+      let equipment = this.orderFormGroup.controls['equipmentControl'].value;
+      if(equipment != null && equipment != undefined && equipment != ''){
+        this.changeEquipmentTable(equipment);
+      }
+
+      let specialties = this.orderFormGroup.controls['staffControl'].value;
+      this.updateSpecialty(specialties);
+      setTimeout(async () => {
+        if(this.workOrder != null){
+          let specialtiesArr = JSON.parse(this.workOrder.OPERARIOS);
+          for(const specialty of specialtiesArr){
+            specialty.ID = await this._encService.decrypt(specialty.ID);
+          }
+
+          for(const item of specialties){
+            let input = this._document.getElementById(`cant-req-${item}`) as HTMLInputElement;
+            let itemDec = await this._encService.decrypt(item);
+            let specialtyFilt = specialtiesArr.filter((item1: any) => item1.ID == itemDec);
+
+            if(specialtyFilt.length > 0){
+              input.value = specialtyFilt[0].CANT;
+            }else{
+              input.value = '1';
+            }
+          }
+        }
+      }, 100);
+      
       let toolsKeys = Object.keys(this.toolsConf);
       toolsKeys.forEach(key => {
         if(key != 'SH'){
@@ -1630,12 +1522,16 @@ export class NewWorkOrderComponent implements OnInit {
 
   addStep(type: string, id: string | null){
     let ins = this.instructions.filter(item => item.ID == id);
+    let startDate = this.orderFormGroup.controls['startDateControl'].value;
+    let endDate = this.orderFormGroup.controls['endDateControl'].value;
     
     let dialogRef = this._dialog.open(NewInstructionComponent, {
       width: '560px',
       data: {
         action: type,
         instruction: ins.length > 0 ? ins[0] : null,
+        startDate: startDate,
+        endDate: endDate,
       }
     }); 
 
@@ -1962,12 +1858,25 @@ export class NewWorkOrderComponent implements OnInit {
     await lastValueFrom(this._inventoryManagementService.getToolsAndSpare(USER, LINE)).then(
       (responseData: ResponseDataGetToolsAndSpare) => {
         if (!responseData.error) {
-          this.tools = responseData.response.HERRAMIENTAS
-          this.spareParts = responseData.response.REFACCIONES
+          this.tools = responseData.response.HERRAMIENTAS;
+          this.spareParts = responseData.response.REFACCIONES;
+
+          this.getSpecialties();
         } else {
           this._resourcesService.openSnackBar(`${responseData.msg}`);
         }
-      }, (httpErrorResponse: HttpErrorResponse) => this._resourcesService.checkErrors(httpErrorResponse)
+      }, (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;
+      }
     )
   }