Files
safekat/ci4/app/Controllers/Configuracion/ConfigErrores.php
2025-04-21 12:55:45 +02:00

81 lines
3.1 KiB
PHP
Executable File

<?php
namespace App\Controllers\Configuracion;
use App\Controllers\BaseResourceController;
use App\Models\Collection;
use App\Models\Presupuestos\ErrorPresupuesto as ErrorPresupuestoModel;
use CodeIgniter\HTTP\Response;
use Hermawan\DataTables\DataTable;
class ConfigErrores extends BaseResourceController
{
protected ErrorPresupuestoModel $errorPresupuestoModel;
protected $format = 'json';
protected array $viewData = [];
protected static $viewPath = 'themes/vuexy/form/configuracion/error_presupuesto/';
protected static $controllerSlug = "errores-presupuesto";
protected $indexRoute = 'viewErrorPresupuestoList';
public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger)
{
parent::initController($request, $response, $logger);
$this->errorPresupuestoModel = model(ErrorPresupuestoModel::class);
}
public function index()
{
$this->viewData['breadcrumb'] = [
['title' => lang("App.menu_configuration"), 'route' => "javascript:void(0);", 'active' => false],
['title' => lang("App.menu_error_presupuesto"), 'route' => site_url('configuracion/errores-presupuesto'), 'active' => true]
];
return view(static::$viewPath . $this->indexRoute, $this->viewData);
}
public function viewForm(int $error_presupuesto_id)
{
$this->viewData['breadcrumb'] = [
['title' => lang("App.menu_configuration"), 'route' => "javascript:void(0);", 'active' => false],
['title' => lang("App.menu_error_presupuesto"), 'route' => site_url('configuracion/errores-presupuesto'), 'active' => true]
];
$this->viewData["error_presupuesto_id"] = $error_presupuesto_id;
$this->errorPresupuestoModel->update($error_presupuesto_id, [
"last_user_id" => auth()->user()->id,
"visto" => true,
]);
return view(static::$viewPath . 'viewErrorPresupuestoForm', $this->viewData);
}
public function store()
{
$data = [];
$variableCreated = $this->errorPresupuestoModel->store($data);
return $this->response->setJSON($variableCreated);
}
public function get_error_presupuesto(int $error_presupuesto_id)
{
$data = $this->errorPresupuestoModel->getErrorPresupuestoForm($error_presupuesto_id);
if (isset($data[0])) {
return $this->response->setJSON(["data" => $data[0]]);
} else {
return $this->response->setJSON(["data" => []]);
}
}
public function update_error_presupuesto(int $error_presupuesto_id)
{
$bodyData = $this->request->getPost();
$this->errorPresupuestoModel->updateComment($error_presupuesto_id, $bodyData["comments"]);
return $this->response->setJSON(["message" => "Comentario actualizado", "status" => true]);
}
public function datatable()
{
$query = $this->errorPresupuestoModel->getQueryDatatable()->orderBy("created_at", "DESC");
return DataTable::of($query)
->add("action", fn($q) => $q->id)
->toJson(true);
}
}