From 0ecd18f5fff439586f345e5d26677ab1b80c683e Mon Sep 17 00:00:00 2001 From: amazuecos Date: Mon, 5 May 2025 11:22:41 +0200 Subject: [PATCH] fix btn cancel fa --- ci4/app/Config/Routes.php | 3 +- ci4/app/Config/Validation.php | 4 + .../Controllers/Produccion/Ordentrabajo.php | 29 ++++++- .../maquinista/maquinistaFichajeAuto.js | 87 ++++++++++++------- 4 files changed, 89 insertions(+), 34 deletions(-) diff --git a/ci4/app/Config/Routes.php b/ci4/app/Config/Routes.php index 2d7aefc5..ee3d53c7 100755 --- a/ci4/app/Config/Routes.php +++ b/ci4/app/Config/Routes.php @@ -781,7 +781,8 @@ $routes->group('produccion', ['namespace' => 'App\Controllers\Produccion'], func $routes->post("update/tarea/progress", "Ordentrabajo::store_orden_trabajo_progress_date"); $routes->post("update/tarea/pliegos", "Ordentrabajo::update_orden_trabajo_pliegos"); $routes->post("update/tarea/proveedor", "Ordentrabajo::update_presupuesto_tarea_proveedor"); - $routes->post("fa/tareas/finish", 'Ordentrabajo::update_orden_trabajo_fa_tareas'); + $routes->post("fa/tareas/update", 'Ordentrabajo::update_orden_trabajo_fa_tareas'); + $routes->post("fa/tareas/reset",'Ordentrabajo::delete_orden_trabajo_fa_tareas'); $routes->post('maquinas/ots','Ordentrabajo::store_maquina_ordenes_trabajo'); $routes->post('maquinas/ots/estado','Ordentrabajo::update_maquina_ordenes_trabajo_estado'); diff --git a/ci4/app/Config/Validation.php b/ci4/app/Config/Validation.php index 02265475..13f8d14f 100755 --- a/ci4/app/Config/Validation.php +++ b/ci4/app/Config/Validation.php @@ -182,6 +182,10 @@ class Validation extends BaseConfig "rules" => "required|integer", "label" => "Máquina" ], + "estado" => [ + "rules" => "required|in_list[P,I,S,D,F,E]", + "label" => "estado" + ], "tareas" => [ "rules" => "required", "label" => "Tareas" diff --git a/ci4/app/Controllers/Produccion/Ordentrabajo.php b/ci4/app/Controllers/Produccion/Ordentrabajo.php index e2b1cee1..5c8850e9 100755 --- a/ci4/app/Controllers/Produccion/Ordentrabajo.php +++ b/ci4/app/Controllers/Produccion/Ordentrabajo.php @@ -751,6 +751,13 @@ class Ordentrabajo extends BaseController public function update_orden_trabajo_fa_tareas() { + $responseData = [ + "tiempo_total_estimado" => 0, + "tiempo_total_real" => 0, + "clicks_total" => 0, + "tirada_total" => 0, + "estado" => "P", + ]; $bodyData = $this->request->getPost(); $validated = $this->validation->run($bodyData, "orden_trabajo_fichaje_auto"); if ($validated) { @@ -759,18 +766,38 @@ class Ordentrabajo extends BaseController foreach ($validatedData['tareas'] as $key => $tareaId) { $this->produccionService->storeOrdenTrabajoTareaProgressDate( [ - 'estado' => 'F', + 'estado' => $validatedData['estado'], 'ot_tarea_id' => $tareaId ] ); $tareaEntity = $this->otTarea->find($tareaId); $tiempo_trabajado = $tareaEntity->tiempo_trabajado(); + $responseData['tiempo_total_estimado']+=$tareaEntity->tiempo_estimado; + $responseData['tiempo_total_real']+=$tiempo_trabajado; + $responseData["estado"] = $validatedData["estado"]; $tareaEntity->tiempo_real = $tiempo_trabajado / count($validatedData['tareas']); $tareaEntity->click_init = $validatedData['click_init'] / count($validatedData['tareas']); $tareaEntity->click_end = $validatedData['click_end'] / count($validatedData['tareas']); $this->otTarea->save($tareaEntity); } + $responseData['tiempo_total_estimado'] = float_seconds_to_hhmmss_string($responseData['tiempo_total_estimado']); + $responseData['tiempo_total_real'] = float_seconds_to_hhmmss_string($responseData['tiempo_total_real']); + return $this->response->setJSON(["message" => lang("App.global_alert_save_success"), "status" => true, "data" => $responseData]); + } else { + return $this->response->setJSON(["errors" => $this->validation->getErrors()])->setStatusCode(400); + } + } + public function delete_orden_trabajo_fa_tareas() + { + $bodyData = $this->request->getPost(); + $validated = $this->validation->run($bodyData, "orden_trabajo_fichaje_auto"); + if ($validated) { + $validatedData = $this->validation->getValidated(); + $this->produccionService->init($validatedData['orden_trabajo_id']); + foreach ($validatedData['tareas'] as $key => $tareaId) { + $this->produccionService->deleteOrdenTrabajoTareaProgressDates($tareaId); + } return $this->response->setJSON(["message" => lang("App.global_alert_save_success"), "status" => true, "data" => $validatedData]); } else { return $this->response->setJSON(["errors" => $this->validation->getErrors()])->setStatusCode(400); diff --git a/httpdocs/assets/js/safekat/pages/configuracion/maquinista/maquinistaFichajeAuto.js b/httpdocs/assets/js/safekat/pages/configuracion/maquinista/maquinistaFichajeAuto.js index b504e142..603c591e 100644 --- a/httpdocs/assets/js/safekat/pages/configuracion/maquinista/maquinistaFichajeAuto.js +++ b/httpdocs/assets/js/safekat/pages/configuracion/maquinista/maquinistaFichajeAuto.js @@ -23,7 +23,8 @@ class MaquinistaFichajeAuto { Notiflix.Block.circle('.section-block'); this.otInputId.trigger('focus') this.otInputId.on('change', this._handleGetOt.bind(this)) - this.btnFinishTarea.on('click', this._handleFinishTareasConfirm.bind(this)) + this.btnFinishTarea.on('click', this._handleUpdateTareasConfirm.bind(this)) + this.btnCancelTarea.on('click',this._handleResetTareasConfirm.bind(this)) } hideCard() { @@ -83,7 +84,7 @@ class MaquinistaFichajeAuto { console.log("Iniciar ", this.otId) if (this.lastOtId != this.otId) { console.log("Finalizar", this.lastOtId) - this._handleFinishTareas(this.lastOtId) + this._handleUpdateTareas(this.lastOtId,'F') } } else { console.log("Primera OT insertada") @@ -93,9 +94,7 @@ class MaquinistaFichajeAuto { this.actionLoader(false) if (response.data) { this.fillData(response.data) - response.data.tareas.forEach(tarea => { - this._handleInitTareas(tarea.id, 'I') - }); + this._handleUpdateTareas(this.otId, 'I') } } _handleGetOtError(error) { @@ -103,44 +102,31 @@ class MaquinistaFichajeAuto { this.otInputId.addClass('is-invalid') popErrorAlert(error.responseJSON.message) } - _handleInitTareas(tareaId, estado = 'I') { - let ajax = new Ajax('/produccion/ordentrabajo/update/tarea/progress', - { - ot_tarea_id: tareaId, - estado: estado - }, null, - this._handleInitTareasSuccess.bind(this), - this._handleInitTareasError.bind(this) - ); - if (tareaId) { - ajax.post(); - } - } - _handleInitTareasSuccess() { } - _handleInitTareasError() { } - _handleFinishTareas(otId) { - let ajax = new Ajax('/produccion/ordentrabajo/fa/tareas/finish', + _handleUpdateTareas(otId,estado = "F") { + let ajax = new Ajax('/produccion/ordentrabajo/fa/tareas/update', { orden_trabajo_id: otId, + estado : estado, ...this.getFormData() }, null, - this._handleFinishTareasSucess.bind(this), - this._handleFinishTareasError.bind(this) + this._handleUpdateTareasSucess.bind(this), + this._handleUpdateTareasError.bind(this) ); ajax.post() } - _handleFinishTareasConfirm(event) { + _handleUpdateTareasConfirm(event) { let otId = this.otInputId.val() console.log("Finalizar", otId); - let ajax = new Ajax('/produccion/ordentrabajo/fa/tareas/finish', + let ajax = new Ajax('/produccion/ordentrabajo/fa/tareas/update', { orden_trabajo_id: otId, + estado : 'F', ...this.getFormData() }, null, - this._handleFinishTareasConfirmSucess.bind(this), - this._handleFinishTareasConfirmError.bind(this) + this._handleUpdateTareasConfirmSucess.bind(this), + this._handleUpdateTareasConfirmError.bind(this) ); if (otId) { alertConfirmAction('Se va finalizar la tarea actual y se cancelará el modo auto.') @@ -152,7 +138,7 @@ class MaquinistaFichajeAuto { } } - _handleFinishTareasConfirmSucess(response) { + _handleUpdateTareasConfirmSucess(response) { this.hideCard() this.otInputId.val(null) this.otId = null @@ -160,9 +146,46 @@ class MaquinistaFichajeAuto { this.tareas = [] popSuccessAlert(response.message) } - _handleFinishTareasConfirmError() { } - _handleFinishTareasSucess() { } - _handleFinishTareasError() { } + _handleDeleteTareasConfirmSucess(response) { + this.hideCard() + this.otInputId.val(null) + this.otId = null + this.lastOtId = null + this.tareas = [] + popSuccessAlert(response.message) + } + _handleDeleteTareasConfirmError(error) { + popErrorAlert(error) + } + _handleResetTareasConfirm(event) { + let otId = this.otInputId.val() + console.log("Finalizar", otId); + let ajax = new Ajax('/produccion/ordentrabajo/fa/tareas/reset', + { + orden_trabajo_id: otId, + estado : 'P', + ...this.getFormData() + }, null, + this._handleDeleteTareasConfirmSucess.bind(this), + this._handleUpdateTareasConfirmError.bind(this) + ); + if (otId) { + alertConfirmAction('Se va a cancelar la tarea y se borrará el progreso') + .then((result) => { + if (result.isConfirmed) { + ajax.post(); + } + }) + } + + } + _handleUpdateTareasConfirmError() { } + _handleUpdateTareasSucess(response) { + this.item.find('#tiempo-estimado-info').text(response.data.tiempo_total_estimado) + this.item.find('#tiempo-real-info').text(response.data.tiempo_total_real) + + } + _handleUpdateTareasError() { }