mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
modificado el listado de maquinas
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
<?php namespace App\Controllers\Configuracion;
|
||||
<?php
|
||||
namespace App\Controllers\Configuracion;
|
||||
|
||||
|
||||
use App\Controllers\BaseResourceController;
|
||||
@ -65,14 +66,50 @@ class Maquinas extends \App\Controllers\BaseResourceController
|
||||
return view(static::$viewPath . 'viewMaquinaList', $viewData);
|
||||
}
|
||||
|
||||
public function delete($id = null)
|
||||
{
|
||||
// Sanitizar el ID
|
||||
$id = filter_var($id, FILTER_SANITIZE_URL);
|
||||
|
||||
// Validar que el ID es válido
|
||||
if (empty($id) || !is_numeric($id)) {
|
||||
return $this->respond(['status' => 'error', 'msg' => 'ID no válida']);
|
||||
}
|
||||
|
||||
// Buscar la máquina en la base de datos
|
||||
$maquina = $this->model->find($id);
|
||||
if (!$maquina) {
|
||||
$message = lang('Basic.global.notFoundWithIdErr', [mb_strtolower(lang('Maquinas.maquina')), $id]);
|
||||
return $this->respond(['status' => 'error', 'msg' => 'ID no válida']);
|
||||
}
|
||||
|
||||
// Verificar que el usuario está autenticado
|
||||
if (!auth()->user()) {
|
||||
return $this->respond(['status' => 'error', 'msg' => 'Usuario no autenticado']);
|
||||
}
|
||||
|
||||
// Preparar los datos para actualizar
|
||||
$data = [
|
||||
'id' => $id,
|
||||
'is_deleted' => 1,
|
||||
'deleted_at' => date('Y-m-d H:i:s'),
|
||||
'user_updated_id' => auth()->user()->id,
|
||||
];
|
||||
|
||||
// Guardar los cambios
|
||||
if (!$this->model->save($data)) {
|
||||
return $this->respond(['status' => 'error', 'msg' => 'Error al eliminar']);
|
||||
}
|
||||
|
||||
// Retornar éxito
|
||||
$message = lang('Basic.global.deleteSuccess', [lang('Basic.global.record')]) . '.';
|
||||
return $this->respond(['status' => 'error', 'msg' => $message]);
|
||||
}
|
||||
|
||||
|
||||
public function add()
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
if ($this->request->getPost()) :
|
||||
if ($this->request->getPost()):
|
||||
|
||||
$nullIfEmpty = true; // !(phpversion() >= '8.1');
|
||||
|
||||
@ -84,10 +121,10 @@ class Maquinas extends \App\Controllers\BaseResourceController
|
||||
$sanitizedData['user_created_id'] = auth()->user()->id;
|
||||
|
||||
$noException = true;
|
||||
if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) :
|
||||
if ($successfulResult = $this->canValidate()): // if ($successfulResult = $this->validate($this->formValidationRules) ) :
|
||||
|
||||
|
||||
if ($this->canValidate()) :
|
||||
if ($this->canValidate()):
|
||||
try {
|
||||
$successfulResult = $this->model->skipValidation(true)->save($sanitizedData);
|
||||
} catch (\Exception $e) {
|
||||
@ -101,14 +138,14 @@ class Maquinas extends \App\Controllers\BaseResourceController
|
||||
|
||||
$thenRedirect = true; // Change this to false if you want your user to stay on the form after submission
|
||||
endif;
|
||||
if ($noException && $successfulResult) :
|
||||
if ($noException && $successfulResult):
|
||||
|
||||
$id = $this->model->db->insertID();
|
||||
|
||||
$message = lang('Basic.global.saveSuccess', [lang('Basic.global.record')]) . '.';
|
||||
|
||||
if ($thenRedirect) :
|
||||
if (!empty($this->indexRoute)) :
|
||||
if ($thenRedirect):
|
||||
if (!empty($this->indexRoute)):
|
||||
//return redirect()->to(route_to($this->indexRoute))->with('sweet-success', $message);
|
||||
return redirect()->to(site_url('configuracion/maquinas/edit/' . $id))->with('sweet-success', $message);
|
||||
else:
|
||||
@ -138,20 +175,20 @@ class Maquinas extends \App\Controllers\BaseResourceController
|
||||
{
|
||||
|
||||
|
||||
if ($requestedId == null) :
|
||||
if ($requestedId == null):
|
||||
return $this->redirect2listView();
|
||||
endif;
|
||||
$id = filter_var($requestedId, FILTER_SANITIZE_URL);
|
||||
$maquina = $this->model->find($id);
|
||||
|
||||
if ($maquina == false) :
|
||||
if ($maquina == false):
|
||||
$message = lang('Basic.global.notFoundWithIdErr', [mb_strtolower(lang('Maquinas.maquina')), $id]);
|
||||
return $this->redirect2listView('sweet-error', $message);
|
||||
endif;
|
||||
|
||||
|
||||
|
||||
if ($this->request->getPost()) :
|
||||
|
||||
if ($this->request->getPost()):
|
||||
|
||||
$nullIfEmpty = true; // !(phpversion() >= '8.1');
|
||||
|
||||
@ -171,17 +208,19 @@ class Maquinas extends \App\Controllers\BaseResourceController
|
||||
// JJO
|
||||
$sanitizedData['user_updated_id'] = auth()->user()->id;
|
||||
$noException = true;
|
||||
if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) :
|
||||
if ($successfulResult = $this->canValidate()): // if ($successfulResult = $this->validate($this->formValidationRules) ) :
|
||||
|
||||
if ($this->canValidate()) :
|
||||
if ($this->canValidate()):
|
||||
//JJO: comprobar alto y ancho impresion < alto y ancho
|
||||
if ($sanitizedData['alto'] < $sanitizedData['alto_impresion']) {
|
||||
$successfulResult = false;
|
||||
$this->viewData['errorMessage'] = lang('Maquinas.validation.alto_menor_alto_impresion');;
|
||||
$this->viewData['errorMessage'] = lang('Maquinas.validation.alto_menor_alto_impresion');
|
||||
;
|
||||
$this->session->setFlashdata('formErrors', $this->model->errors());
|
||||
} else if ($sanitizedData['ancho'] < $sanitizedData['ancho_impresion']) {
|
||||
$successfulResult = false;
|
||||
$this->viewData['errorMessage'] = lang('Maquinas.validation.ancho_menor_ancho_impresion');;
|
||||
$this->viewData['errorMessage'] = lang('Maquinas.validation.ancho_menor_ancho_impresion');
|
||||
;
|
||||
$this->session->setFlashdata('formErrors', $this->model->errors());
|
||||
} else {
|
||||
try {
|
||||
@ -202,12 +241,12 @@ class Maquinas extends \App\Controllers\BaseResourceController
|
||||
|
||||
$thenRedirect = false;
|
||||
endif;
|
||||
if ($noException && $successfulResult) :
|
||||
if ($noException && $successfulResult):
|
||||
$id = $maquina->id ?? $id;
|
||||
$message = lang('Basic.global.updateSuccess', [lang('Basic.global.record')]) . '.';
|
||||
|
||||
if ($thenRedirect) :
|
||||
if (!empty($this->indexRoute)) :
|
||||
if ($thenRedirect):
|
||||
if (!empty($this->indexRoute)):
|
||||
return redirect()->to(route_to($this->indexRoute))->with('sweet-success', $message);
|
||||
else:
|
||||
return $this->redirect2listView('sweet-success', $message);
|
||||
@ -243,22 +282,24 @@ class Maquinas extends \App\Controllers\BaseResourceController
|
||||
}
|
||||
$start = $reqData['start'] ?? 0;
|
||||
$length = $reqData['length'] ?? 5;
|
||||
$search = $reqData['search']['value'];
|
||||
$requestedOrder = $reqData['order']['0']['column'] ?? 1;
|
||||
$order = MaquinaModel::SORTABLE[$requestedOrder >= 0 ? $requestedOrder : 1];
|
||||
$dir = $reqData['order']['0']['dir'] ?? 'asc';
|
||||
$searchValues = get_filter_datatables_columns($reqData);
|
||||
$requestedOrder = $reqData['order'] ?? [];
|
||||
|
||||
$resourceData = $this->model->getResource($search)->orderBy($order, $dir)->limit($length, $start)->get()->getResultObject();
|
||||
foreach ($resourceData as $item) :
|
||||
if (isset($item->observaciones) && strlen($item->observaciones) > 100) :
|
||||
$item->observaciones = character_limiter($item->observaciones, 100);
|
||||
endif;
|
||||
endforeach;
|
||||
$resourceData = $this->model->getResource($searchValues);
|
||||
foreach ($requestedOrder as $order) {
|
||||
$column = $order['column'] ?? 0;
|
||||
$dir = $order['dir'] ?? 'asc';
|
||||
$orderColumn = MaquinaModel::SORTABLE[$column] ?? null;
|
||||
if ($orderColumn) {
|
||||
$resourceData->orderBy($orderColumn, $dir);
|
||||
}
|
||||
}
|
||||
$resourceData = $resourceData->limit($length, $start)->get()->getResultObject();
|
||||
|
||||
return $this->respond(Collection::datatable(
|
||||
$resourceData,
|
||||
$this->model->getResource()->countAllResults(),
|
||||
$this->model->getResource($search)->countAllResults()
|
||||
$this->model->getResource([])->countAllResults(),
|
||||
$this->model->getResource($searchValues)->countAllResults()
|
||||
));
|
||||
} else {
|
||||
return $this->failUnauthorized('Invalid request', 403);
|
||||
@ -319,11 +360,11 @@ class Maquinas extends \App\Controllers\BaseResourceController
|
||||
protected function getMaquinaListItems($selId = null)
|
||||
{
|
||||
$data = ['' => lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Maquinas.maquina'))])];
|
||||
if (!empty($selId)) :
|
||||
if (!empty($selId)):
|
||||
$maquinaModel = model('App\Models\Configuracion\MaquinaModel');
|
||||
|
||||
$selOption = $maquinaModel->where('id', $selId)->findColumn('nombre');
|
||||
if (!empty($selOption)) :
|
||||
if (!empty($selOption)):
|
||||
$data[$selId] = $selOption[0];
|
||||
endif;
|
||||
endif;
|
||||
|
||||
Reference in New Issue
Block a user