fix btn cancel fa

This commit is contained in:
amazuecos
2025-05-05 11:22:41 +02:00
parent 4701329d25
commit 0ecd18f5ff
4 changed files with 89 additions and 34 deletions

View File

@ -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');

View File

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

View File

@ -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);

View File

@ -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() { }