|
|
@@ -17,6 +17,7 @@ import { MatDialog } from '@angular/material/dialog';
|
|
|
import { PreventiveOrderDetailsComponent } from '../preventive-order-details/preventive-order-details.component';
|
|
|
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';
|
|
|
|
|
|
@Component({
|
|
|
selector: 'app-unprogrammed-visits',
|
|
|
@@ -335,10 +336,10 @@ export class UnprogrammedVisitsComponent implements OnInit {
|
|
|
}
|
|
|
|
|
|
await this.startVisit(idVisit);
|
|
|
- } catch (error) {
|
|
|
+ } catch (error: any) {
|
|
|
console.error('verifyVisitStatus error', error);
|
|
|
this._resourcesService.openSnackBar(
|
|
|
- 'No fue posible verificar la visita.'
|
|
|
+ error?.error?.msg || 'No fue posible verificar la visita.'
|
|
|
);
|
|
|
}
|
|
|
}
|
|
|
@@ -392,6 +393,74 @@ export class UnprogrammedVisitsComponent implements OnInit {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ openCloseVisitDialog(visit: UnprogrammedVisit) {
|
|
|
+ const visitId = `${visit.IDVISITA ?? ''}`.trim();
|
|
|
+ if (!visitId) {
|
|
|
+ this._resourcesService.openSnackBar('No se pudo identificar la visita.');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ const dialogRef = this._dialog.open(CommnetsDialogComponent, {
|
|
|
+ width: '480px',
|
|
|
+ maxWidth: '480px',
|
|
|
+ disableClose: true,
|
|
|
+ data: {
|
|
|
+ idOrder: visitId,
|
|
|
+ status: 'Cerrar',
|
|
|
+ },
|
|
|
+ });
|
|
|
+
|
|
|
+ dialogRef.afterClosed().subscribe((res) => {
|
|
|
+ if (res != undefined && res != null && res != '') {
|
|
|
+ if (res.length < 35) {
|
|
|
+ this._resourcesService.openSnackBar(
|
|
|
+ 'Los comentarios deben tener al menos 35 caracteres.'
|
|
|
+ );
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ this.closeVisit(visitId, res);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private async closeVisit(idVisit: string, comment: string) {
|
|
|
+ try {
|
|
|
+ const idUser = localStorage.getItem('idusuario')!;
|
|
|
+ const idVisitEnc = await this._encService.encrypt(idVisit);
|
|
|
+ const idUserEnc = await this._encService.encrypt(idUser);
|
|
|
+
|
|
|
+ const formData = new FormData();
|
|
|
+ formData.append('id_user', idUserEnc);
|
|
|
+ formData.append('linea', '1');
|
|
|
+ formData.append('id_visit', idVisitEnc);
|
|
|
+ formData.append('comment', comment);
|
|
|
+
|
|
|
+ const response = await lastValueFrom(
|
|
|
+ this._prevMaintService.registerOperatorClosingComment(formData)
|
|
|
+ );
|
|
|
+
|
|
|
+ if (response?.error) {
|
|
|
+ this._resourcesService.openSnackBar(
|
|
|
+ response.msg || 'Ocurrió un error al cerrar la visita.'
|
|
|
+ );
|
|
|
+ } else {
|
|
|
+ this._resourcesService.openSnackBar(
|
|
|
+ response?.msg || 'La visita se cerró 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);
|
|
|
+ }
|
|
|
+ this.getUnprogrammedVisits();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
getRowIndex(index: number): number {
|
|
|
const pageIndex = this.paginator?.pageIndex ?? 0;
|
|
|
const pageSize = this.paginator?.pageSize ?? 10;
|