|
|
@@ -19,6 +19,7 @@ import { ResourcesService } from '../../../services/resources.service';
|
|
|
import { AlertComponent } from '../../resources/dialogs/alert/alert.component';
|
|
|
import { CommnetsDialogComponent } from '../../corrective-maintenance/operations-management/commnets-dialog/commnets-dialog.component';
|
|
|
import { StatusTimelineComponent } from '../../corrective-maintenance/operations-management/status-timeline/status-timeline.component';
|
|
|
+import { StaffSelectionComponent } from '../../corrective-maintenance/operations-management/staff-selection/staff-selection.component';
|
|
|
|
|
|
@Component({
|
|
|
selector: 'app-unprogrammed-visits',
|
|
|
@@ -531,51 +532,58 @@ export class UnprogrammedVisitsComponent implements OnInit {
|
|
|
return pageIndex * pageSize + index + 1;
|
|
|
}
|
|
|
|
|
|
- // Métodos de acción implementados
|
|
|
- approveVisit(visit: UnprogrammedVisit) {
|
|
|
- const visitId = `${visit.IDVISITA ?? ''}`.trim();
|
|
|
- if (!visitId) {
|
|
|
- this._resourcesService.openSnackBar('No se pudo identificar la visita.');
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- const confirmDialogRef = this._dialog.open(AlertComponent, {
|
|
|
- width: '420px',
|
|
|
- maxWidth: '420px',
|
|
|
+ async openStaffSelectionDialog(idVisit: string) {
|
|
|
+ const idVisitStr = idVisit.replace('Visita #', '').trim();
|
|
|
+ const idVisitEnc = await this._encService.encrypt(idVisitStr);
|
|
|
+ const dialogRef = this._dialog.open(StaffSelectionComponent, {
|
|
|
disableClose: true,
|
|
|
+ width: '540px',
|
|
|
+ maxWidth: '540px',
|
|
|
data: {
|
|
|
- title: 'Confirmación',
|
|
|
- icon: 'warning',
|
|
|
- description: `¿Está seguro de aprobar la visita #${visitId}?`,
|
|
|
+ idOrder: idVisitEnc,
|
|
|
+ orderType: 'Preventivo',
|
|
|
},
|
|
|
});
|
|
|
|
|
|
- confirmDialogRef.afterClosed().subscribe((confirmed) => {
|
|
|
- if (confirmed === true) {
|
|
|
- const commentsDialogRef = this._dialog.open(CommnetsDialogComponent, {
|
|
|
- width: '480px',
|
|
|
- maxWidth: '480px',
|
|
|
- disableClose: true,
|
|
|
- data: {
|
|
|
- idOrder: visitId,
|
|
|
- status: 'Aprobar',
|
|
|
- },
|
|
|
- });
|
|
|
-
|
|
|
- commentsDialogRef.afterClosed().subscribe((comments) => {
|
|
|
- if (comments != undefined && comments != null && comments != '') {
|
|
|
- if (comments.length < 15) {
|
|
|
- this._resourcesService.openSnackBar(
|
|
|
- 'Los comentarios deben tener al menos 15 caracteres.'
|
|
|
- );
|
|
|
- return;
|
|
|
- }
|
|
|
- this.updateVisitStatus(visitId, 'VA', comments);
|
|
|
- }
|
|
|
- });
|
|
|
+ dialogRef.afterClosed().subscribe((res) => {
|
|
|
+ if (res != null && res != undefined && res != '') {
|
|
|
+ this.approveVisit(idVisitEnc, res);
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
+ // Métodos de acción implementados
|
|
|
+ private async approveVisit(idVisit: string, config: string) {
|
|
|
+ try {
|
|
|
+ const idUser = localStorage.getItem('idusuario')!;
|
|
|
+ const formData = new FormData();
|
|
|
+ formData.append('id_user', idUser);
|
|
|
+ formData.append('linea', '1');
|
|
|
+ formData.append('id_order', idVisit);
|
|
|
+ formData.append('config', config);
|
|
|
+
|
|
|
+ const response = await lastValueFrom(
|
|
|
+ this._prevMaintService.assignOperariosToPreventiveVisit(formData)
|
|
|
+ );
|
|
|
+ if (response?.error) {
|
|
|
+ this._resourcesService.openSnackBar(
|
|
|
+ response.msg || 'Ocurrió un error al aprobar la visita.'
|
|
|
+ );
|
|
|
+ } else {
|
|
|
+ this._resourcesService.openSnackBar(
|
|
|
+ response?.msg || 'La visita se aprobó correctamente.'
|
|
|
+ );
|
|
|
+ }
|
|
|
+ this.getUnprogrammedVisits();
|
|
|
+ } 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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
rejectVisit(visit: UnprogrammedVisit) {
|
|
|
const visitId = `${visit.IDVISITA ?? ''}`.trim();
|