Parcourir la source

Finalización de la integración de la función de gestión de empleados

Jose Brito il y a 2 ans
Parent
commit
887c0f4322

+ 49 - 32
sistema-mantenimiento-front/src/app/components/personal-management/employee/employee-form/employee-form.component.ts

@@ -879,6 +879,8 @@ export class EmployeeFormComponent implements OnInit {
 
   private async storeEmployee() {
     try{
+      this.isLoadingForm = true;
+
       if(this.formGroup.invalid){
         this._resourcesService.openSnackBar("Por favor complete todos los campos requeridos del formulario.");
         this.formGroup.markAllAsTouched();
@@ -1068,10 +1070,10 @@ export class EmployeeFormComponent implements OnInit {
         await lastValueFrom(this._employeeService.storeEmployee(formData));
 
         this._resourcesService.openSnackBar("El empleado se registró correctamente.");
+        this.isLoadingForm = false;
         this.goBack(1);
       }
     }catch(error: any){
-      this.isUploading = false;
       let msg = "";
       if(error.error == undefined){
         msg = 'Ocurrió un error insperado.';
@@ -1082,19 +1084,21 @@ export class EmployeeFormComponent implements OnInit {
       }
 
       this._resourcesService.openSnackBar(msg);
-      this.disableDelete = false;
+      this.isLoadingForm = false;
     }
   }
 
   private async updateEmployee() {
     try{
+      this.isLoadingForm = true;
+
       if(this.formGroup.invalid){
         this._resourcesService.openSnackBar("Por favor complete todos los campos requeridos del formulario.");
         this.formGroup.markAllAsTouched();
       }else{
         let formValue = this.formGroup.getRawValue();
         let formData = new FormData();
-        let subcontratist = formValue.subcontratistId == null ? '-' : formValue.subcontratistId;
+        let subcontratist = formValue.subcontratistId == null || formValue.subcontratistId == '' ? '-' : formValue.subcontratistId;
         let idUser = localStorage.getItem('idusuario')!;
         let idEmployee = await this._encService.encrypt(this.idEmployee);
 
@@ -1275,10 +1279,14 @@ export class EmployeeFormComponent implements OnInit {
 
         let attachedStr = JSON.stringify(this.attached);
         formData.append('ATTACHED', attachedStr);
-        console.log(formData);
+
+        await lastValueFrom(this._employeeService.updateEmployee(formData));
+
+        this._resourcesService.openSnackBar("El empleado se actualizó correctamente.");
+        this.isLoadingForm = false;
+        this.goBack(1);
       }
     }catch(error: any){
-      this.isUploading = false;
       let msg = "";
       if(error.error == undefined){
         msg = 'Ocurrió un error insperado.';
@@ -1289,16 +1297,8 @@ export class EmployeeFormComponent implements OnInit {
       }
 
       this._resourcesService.openSnackBar(msg);
-      this.disableDelete = false;
+      this.isLoadingForm = false;
     }
-    /*this.isLoadingForm = true;
-    await lastValueFrom(this._employeeService.updateEmployee(await this.employeeObject(), this.idEmployee)).then(
-      (responseData: ResponseData) => {
-        this._resourcesService.openSnackBar("Actualización Exitosa!");
-        this._router.navigate(["/sam/GPRS/employee"]);
-      }, (error: HttpErrorResponse) => this._resourcesService.checkErrors(error)
-    );
-    this.isLoadingForm = false;*/
   }
 
   private async getWorkteams() {
@@ -1815,27 +1815,44 @@ export class EmployeeFormComponent implements OnInit {
       this.disableDelete = true;
       this._resourcesService.openSnackBar('Eliminando archivo...');
 
-      let idUser = localStorage.getItem('idusuario')!;
-      let response = await lastValueFrom(this._gdelService.deleteTempFile({
-        'id_user': idUser,
-        'id_file': id,
-        'linea': 1,
-      }));
-
-      if(response.error){
-        this._resourcesService.openSnackBar(response.msg);
+      let file = this.attached.filter(item => item.id == id);
+      if(file.length == 0){
+        this._resourcesService.openSnackBar('El archivo que desea eliminar no existe.');
+        this.disableDelete = false;
       }else{
-        let attachedAux: TempFileInfo[] = [];
-        this.attached.forEach(file => {
-          if(file.id != id) attachedAux.push(file);
-        });
+        let isFinalFile = file[0].isFinalFile;
+        let idUser = localStorage.getItem('idusuario')!;
+        let response: any;
+
+        if(isFinalFile){
+          response = await lastValueFrom(this._gdelService.deleteFile({
+            'id_user': idUser,
+            'id_file': id,
+            'linea': 1,
+          }));
+        }else{
+          response = await lastValueFrom(this._gdelService.deleteTempFile({
+            'id_user': idUser,
+            'id_file': id,
+            'linea': 1,
+          }));
+        }
 
-        this.attached = attachedAux;
-        this.dataSource = new MatTableDataSource(this.attached);
-        this._resourcesService.openSnackBar('El archivo se eliminó correctamente.');
+        if(response.error){
+          this._resourcesService.openSnackBar(response.msg);
+        }else{
+          let attachedAux: TempFileInfo[] = [];
+          this.attached.forEach(file => {
+            if(file.id != id) attachedAux.push(file);
+          });
+  
+          this.attached = attachedAux;
+          this.dataSource = new MatTableDataSource(this.attached);
+          this._resourcesService.openSnackBar('El archivo se eliminó correctamente.');
+        }
+  
+        this.disableDelete = false;
       }
-
-      this.disableDelete = false;
     }catch(error: any){
       this.isUploading = false;
       let msg = "";

+ 1 - 9
sistema-mantenimiento-front/src/app/components/personal-management/employee/employee.component.html

@@ -98,10 +98,6 @@
               [disabled]="isLoading" [matMenuTriggerFor]="menu" #menuTrigger class="override_no_shadow">
                 <mat-icon>settings</mat-icon>
               </button>
-              <button mat-mini-fab class="teal_dark_background white_font" class="teal_dark_background white_font override_no_shadow" 
-              [disabled]="isLoading" (click)="openDialog('ACT', element)" *ngIf="btnSmall && element.STATUS == 'Eliminado'">
-                <mat-icon>restore_from_trash</mat-icon>
-              </button>
               <mat-menu #menu="matMenu">
                 <button mat-menu-item (click)="openDialog('DET', element)">
                   <mat-icon>visibility</mat-icon> Detalles
@@ -144,13 +140,9 @@
                   <mat-icon>edit</mat-icon>
                 </button>
                 <button mat-mini-fab color="warn" class="override_no_shadow ml-4" matTooltip="Eliminar Empleado"
-                (click)="openDialog('DEL', element)" [disabled]="isLoadingForm" *ngIf="element.STATUS == 'Activo'">
+                (click)="openDialog('DEL', element)" [disabled]="element.STATUS == 'Eliminado' || isLoadingForm">
                   <mat-icon>delete</mat-icon>
                 </button>
-                <button mat-mini-fab class="teal_dark_background white_font override_no_shadow ml-4" matTooltip="Activar Empleado"
-                (click)="openDialog('ACT', element)" [disabled]="isLoadingForm" *ngIf="element.STATUS == 'Eliminado'">
-                  <mat-icon>restore_from_trash</mat-icon>
-                </button>
               </div>
             </td>
           </ng-container>

+ 22 - 11
sistema-mantenimiento-front/src/app/components/personal-management/employee/employee.component.ts

@@ -156,7 +156,7 @@ export class EmployeeComponent implements OnInit {
         disableClose: true,
       }).afterClosed().subscribe((result) => {
         if (result) {
-          //this.deleteEmployee(element!.ID_EMPLOYEE);
+          this.deleteEmployee(`${element!.ID_EMPLOYEE}`);
         }
       });
     } else if (typeForm === 'ACT') {
@@ -219,16 +219,27 @@ export class EmployeeComponent implements OnInit {
   }
 
   private async deleteEmployee(employeeId: string) {
-    await lastValueFrom(this._employeeService.updateToInactiveStatus({
-      EMPLOYEE_ID: employeeId,
-      LINE_NUMBER: '01',
-      SAVED_BY_USER: this.resourcesService.getUser()
-    })).then(
-      (responseData: any) => {
-        this.getEmployees();
-        this.resourcesService.openSnackBar('¡Eliminación Exitosa!');
-      }, (error: HttpErrorResponse) => this.resourcesService.checkErrors(error)
-    );
+    try{
+      let idUser = localStorage.getItem('idusuario')!;
+      let formData = new FormData();
+    
+      formData.append('id_user', idUser);
+      formData.append('linea', '1');
+      formData.append('id_employee', employeeId);
+
+      await lastValueFrom(this._employeeService.updateToInactiveStatus(formData));
+
+      this.resourcesService.openSnackBar('El usuario se eliminó correctamente.');
+      this.getEmployees();
+    }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 async activateEmployee(employeeId: string) {

+ 4 - 4
sistema-mantenimiento-front/src/app/services/personal-management/employee.service.ts

@@ -38,8 +38,8 @@ export class EmployeeService {
       map((data: any) => data))
   }
 
-  public updateToInactiveStatus(response: UpdatedStatusEmployee) {
-    return this._httpRequestService.putQueryQA(`${this._url}/inactive-employee/${response.EMPLOYEE_ID}`, response)
+  public updateToInactiveStatus(response: any) {
+    return this._httpRequestService.postQueryQA(`${this._url}/delete`, response)
       .pipe(map((data: any) => data));
   }
 
@@ -53,8 +53,8 @@ export class EmployeeService {
       .pipe(map((data: any) => data));
   }
 
-  public updateEmployee(response: any, employeeId: string) {
-    return this._httpRequestService.postQueryQA(`${this._url}/${employeeId}`, response)
+  public updateEmployee(response: any) {
+    return this._httpRequestService.postQueryQA(`${this._url}/update`, response)
       .pipe(map((data: any) => data));
   }