Files
safekat/ci4/app/Controllers/Produccion/Ordentrabajo.php
amazuecos 2d9b1603a3 tareas
2024-12-26 13:37:18 +01:00

91 lines
3.4 KiB
PHP
Executable File

<?php
namespace App\Controllers\Produccion;
use App\Controllers\BaseController;
use App\Models\OrdenTrabajo\OrdenTrabajoModel;
use App\Services\ProductionService;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use Hermawan\DataTables\DataTable;
use Psr\Log\LoggerInterface;
class Ordentrabajo extends BaseController
{
protected $format = 'json';
protected array $viewData = [];
protected ProductionService $produccionService;
protected OrdenTrabajoModel $otModel;
protected static $viewPath = 'themes/vuexy/form/produccion/';
protected static $controllerSlug = "orden-trabajo";
protected $indexRoute = 'viewOrdenTrabajoList';
protected $editRoute = 'viewOrdenTrabajoEdit';
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{
$this->otModel = model(OrdenTrabajoModel::class);
$this->produccionService = new ProductionService();
parent::initController($request, $response, $logger);
}
public function index()
{
// Breadcrumbs
$this->viewData['breadcrumb'] = [
['title' => lang("Produccion.ot"), 'route' => "javascript:void(0);", 'active' => false],
['title' => lang("Produccion.ots"), 'route' => site_url('produccion/ordentrabajo'), 'active' => true]
];
return view(static::$viewPath . $this->indexRoute, $this->viewData);
}
public function delete()
{
}
public function get_orden_trabajo_summary($orden_trabajo_id){
$summary = $this->produccionService->init($orden_trabajo_id)->getSummary();
return $this->response->setJSON($summary);
}
public function add()
{
}
public function edit($orden_trabajo_id)
{
// Breadcrumbs
$this->viewData['breadcrumb'] = [
['title' => lang("Produccion.ot"), 'route' => "javascript:void(0);", 'active' => false],
['title' => $this->otModel->find($orden_trabajo_id)->pedido()->presupuesto()->titulo, 'route' => site_url('produccion/ordentrabajo/edit/'.$orden_trabajo_id), 'active' => true]
];
$this->viewData["modelId"] = $orden_trabajo_id;
$this->produccionService->init($orden_trabajo_id);
$this->viewData["presupuesto"] = $this->produccionService->getPresupuesto();
$this->viewData["cliente"] = $this->produccionService->getCliente();
$this->viewData["ot"] = $this->produccionService->getOrdenTrabajo();
return view(static::$viewPath . $this->editRoute, $this->viewData);
}
public function datatable(){
$q = $this->otModel->getDatatableQuery();
// return $this->response->setJSON($q->get()->getResultArray());
return DataTable::of($q)
->add("action" ,fn($q) => $q->id)
->toJson(true);
}
public function reset_tareas(int $orden_trabajo_id)
{
$r = $this->produccionService->init($orden_trabajo_id)->resetAllTareas();
return $this->response->setJSON(["message" => "Tareas reseteadas" ,"status" => $r]);
}
public function tareas_datatable(int $orden_trabajo_id){
$q = $this->produccionService->init($orden_trabajo_id)->taskDatatableQuery($orden_trabajo_id);
// return $this->response->setJSON($q->get()->getResultArray());
return DataTable::of($q)
->add("action" ,fn($q) => $q->id)
->toJson(true);
}
}