|
|
@@ -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 = "";
|