Merge branch 'fix/btn-cancel-fa' into 'main'

fix btn cancel fa

See merge request jjimenez/safekat!773
This commit is contained in:
Alvaro
2025-05-05 09:23:34 +00:00
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/progress", "Ordentrabajo::store_orden_trabajo_progress_date");
$routes->post("update/tarea/pliegos", "Ordentrabajo::update_orden_trabajo_pliegos"); $routes->post("update/tarea/pliegos", "Ordentrabajo::update_orden_trabajo_pliegos");
$routes->post("update/tarea/proveedor", "Ordentrabajo::update_presupuesto_tarea_proveedor"); $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','Ordentrabajo::store_maquina_ordenes_trabajo');
$routes->post('maquinas/ots/estado','Ordentrabajo::update_maquina_ordenes_trabajo_estado'); $routes->post('maquinas/ots/estado','Ordentrabajo::update_maquina_ordenes_trabajo_estado');

View File

@ -182,6 +182,10 @@ class Validation extends BaseConfig
"rules" => "required|integer", "rules" => "required|integer",
"label" => "Máquina" "label" => "Máquina"
], ],
"estado" => [
"rules" => "required|in_list[P,I,S,D,F,E]",
"label" => "estado"
],
"tareas" => [ "tareas" => [
"rules" => "required", "rules" => "required",
"label" => "Tareas" "label" => "Tareas"

View File

@ -751,6 +751,13 @@ class Ordentrabajo extends BaseController
public function update_orden_trabajo_fa_tareas() 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(); $bodyData = $this->request->getPost();
$validated = $this->validation->run($bodyData, "orden_trabajo_fichaje_auto"); $validated = $this->validation->run($bodyData, "orden_trabajo_fichaje_auto");
if ($validated) { if ($validated) {
@ -759,18 +766,38 @@ class Ordentrabajo extends BaseController
foreach ($validatedData['tareas'] as $key => $tareaId) { foreach ($validatedData['tareas'] as $key => $tareaId) {
$this->produccionService->storeOrdenTrabajoTareaProgressDate( $this->produccionService->storeOrdenTrabajoTareaProgressDate(
[ [
'estado' => 'F', 'estado' => $validatedData['estado'],
'ot_tarea_id' => $tareaId 'ot_tarea_id' => $tareaId
] ]
); );
$tareaEntity = $this->otTarea->find($tareaId); $tareaEntity = $this->otTarea->find($tareaId);
$tiempo_trabajado = $tareaEntity->tiempo_trabajado(); $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->tiempo_real = $tiempo_trabajado / count($validatedData['tareas']);
$tareaEntity->click_init = $validatedData['click_init'] / count($validatedData['tareas']); $tareaEntity->click_init = $validatedData['click_init'] / count($validatedData['tareas']);
$tareaEntity->click_end = $validatedData['click_end'] / count($validatedData['tareas']); $tareaEntity->click_end = $validatedData['click_end'] / count($validatedData['tareas']);
$this->otTarea->save($tareaEntity); $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]); return $this->response->setJSON(["message" => lang("App.global_alert_save_success"), "status" => true, "data" => $validatedData]);
} else { } else {
return $this->response->setJSON(["errors" => $this->validation->getErrors()])->setStatusCode(400); return $this->response->setJSON(["errors" => $this->validation->getErrors()])->setStatusCode(400);

View File

@ -23,7 +23,8 @@ class MaquinistaFichajeAuto {
Notiflix.Block.circle('.section-block'); Notiflix.Block.circle('.section-block');
this.otInputId.trigger('focus') this.otInputId.trigger('focus')
this.otInputId.on('change', this._handleGetOt.bind(this)) 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() { hideCard() {
@ -83,7 +84,7 @@ class MaquinistaFichajeAuto {
console.log("Iniciar ", this.otId) console.log("Iniciar ", this.otId)
if (this.lastOtId != this.otId) { if (this.lastOtId != this.otId) {
console.log("Finalizar", this.lastOtId) console.log("Finalizar", this.lastOtId)
this._handleFinishTareas(this.lastOtId) this._handleUpdateTareas(this.lastOtId,'F')
} }
} else { } else {
console.log("Primera OT insertada") console.log("Primera OT insertada")
@ -93,9 +94,7 @@ class MaquinistaFichajeAuto {
this.actionLoader(false) this.actionLoader(false)
if (response.data) { if (response.data) {
this.fillData(response.data) this.fillData(response.data)
response.data.tareas.forEach(tarea => { this._handleUpdateTareas(this.otId, 'I')
this._handleInitTareas(tarea.id, 'I')
});
} }
} }
_handleGetOtError(error) { _handleGetOtError(error) {
@ -103,44 +102,31 @@ class MaquinistaFichajeAuto {
this.otInputId.addClass('is-invalid') this.otInputId.addClass('is-invalid')
popErrorAlert(error.responseJSON.message) 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) { _handleUpdateTareas(otId,estado = "F") {
let ajax = new Ajax('/produccion/ordentrabajo/fa/tareas/finish', let ajax = new Ajax('/produccion/ordentrabajo/fa/tareas/update',
{ {
orden_trabajo_id: otId, orden_trabajo_id: otId,
estado : estado,
...this.getFormData() ...this.getFormData()
}, null, }, null,
this._handleFinishTareasSucess.bind(this), this._handleUpdateTareasSucess.bind(this),
this._handleFinishTareasError.bind(this) this._handleUpdateTareasError.bind(this)
); );
ajax.post() ajax.post()
} }
_handleFinishTareasConfirm(event) { _handleUpdateTareasConfirm(event) {
let otId = this.otInputId.val() let otId = this.otInputId.val()
console.log("Finalizar", otId); 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, orden_trabajo_id: otId,
estado : 'F',
...this.getFormData() ...this.getFormData()
}, null, }, null,
this._handleFinishTareasConfirmSucess.bind(this), this._handleUpdateTareasConfirmSucess.bind(this),
this._handleFinishTareasConfirmError.bind(this) this._handleUpdateTareasConfirmError.bind(this)
); );
if (otId) { if (otId) {
alertConfirmAction('Se va finalizar la tarea actual y se cancelará el modo auto.') 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.hideCard()
this.otInputId.val(null) this.otInputId.val(null)
this.otId = null this.otId = null
@ -160,9 +146,46 @@ class MaquinistaFichajeAuto {
this.tareas = [] this.tareas = []
popSuccessAlert(response.message) popSuccessAlert(response.message)
} }
_handleFinishTareasConfirmError() { } _handleDeleteTareasConfirmSucess(response) {
_handleFinishTareasSucess() { } this.hideCard()
_handleFinishTareasError() { } 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() { }