Files
safekat/ci4/app/Controllers/Configuracion/ServicioCliente.php
2024-12-10 07:35:25 +01:00

90 lines
3.5 KiB
PHP

<?php
namespace App\Controllers\Configuracion;
use App\Controllers\BaseController;
use App\Models\Configuracion\ServicioClienteModel;
use CodeIgniter\HTTP\Response;
use Hermawan\DataTables\DataTable;
use CodeIgniter\I18n\Time;
class ServicioCliente extends BaseController
{
protected ServicioClienteModel $servicioClienteModel;
protected $format = 'json';
protected array $viewData = [];
protected static $viewPath = 'themes/vuexy/form/configuracion/servicios_cliente/';
protected static $controllerSlug = "servicios";
protected $indexRoute = 'viewServicioCliente';
protected $editRoute = 'ServicioClienteEdit';
public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger)
{
parent::initController($request, $response, $logger);
$this->servicioClienteModel = model(ServicioClienteModel::class);
}
public function index()
{
$this->viewData['breadcrumb'] = [
['title' => lang("App.menu_configuration"), 'route' => "javascript:void(0);", 'active' => false],
['title' => lang("App.menu_servicios_cliente"), 'route' => site_url('configuracion/servicios'), 'active' => true]
];
return view(static::$viewPath . $this->indexRoute, $this->viewData);
}
public function viewForm(int $servicio_cliente_id)
{
$servicioCliente = $this->servicioClienteModel->find($servicio_cliente_id);
$this->viewData['breadcrumb'] = [
['title' => lang("App.menu_configuration"), 'route' => "javascript:void(0);", 'active' => false],
['title' => lang("App.menu_servicios_cliente"), 'route' => site_url('configuracion/servicios'), 'active' => false],
['title' => $servicioCliente->nombre, 'route' => site_url('configuracion/servicios/edit/' . $servicio_cliente_id), 'active' => true]
];
$this->viewData["model"] = $servicioCliente;
return view(static::$viewPath . 'ServicioClienteEdit', $this->viewData);
}
public function show(int $id)
{
$data = $this->servicioClienteModel->find($id)->withAllTarifas();
return $this->response->setJSON($data);
}
public function update_servicio_cliente(int $id)
{
$data = $this->request->getPost();
$status = $this->servicioClienteModel->update($id, [
"nombre" => $data["nombre"],
"code" => $data["code"]
]);
if (isset($data["tarifa_manipulado_id"])) {
$this->servicioClienteModel->upsertTarifaManipulado($id, $data["tarifa_manipulado_id"]);
}else if(isset($data["tarifa_acabado_id"])) {
$this->servicioClienteModel->upsertTarifaAcabado($id, $data["tarifa_acabado_id"]);
}else{
$this->servicioClienteModel->detachTarifas($id);
}
return $this->response->setJSON(["message" => lang("App.global_success"), "status" => $status]);
}
public function store()
{
// $this->servicioClienteModel->update($id,[$this->request->getPost()]);
return $this->response->setJSON([]);
}
public function datatable()
{
$query = $this->servicioClienteModel->getQueryDatatable()->orderBy("created_at", "DESC");
return DataTable::of($query)
->edit('created_at', fn($q) => $q->created_at ? Time::createFromFormat('Y-m-d H:i:s', $q->created_at)->format("d/m/Y H:i") : "")
->add("action", fn($q) => $q->id)
->toJson(true);
}
}