mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
146 lines
4.8 KiB
PHP
Executable File
146 lines
4.8 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Controllers\Pedidos;
|
|
use App\Controllers\BaseController;
|
|
use App\Entities\Pedidos\PedidoEntity;
|
|
use App\Models\Collection;
|
|
use App\Models\Pedidos\PedidoModel;
|
|
|
|
|
|
class Pedido extends \App\Controllers\BaseResourceController
|
|
{
|
|
protected $modelName = PedidoModel::class;
|
|
protected $format = 'json';
|
|
|
|
protected static $singularObjectNameCc = 'pedido';
|
|
protected static $singularObjectName = 'Pedido';
|
|
protected static $pluralObjectName = 'Pedidos';
|
|
protected static $controllerSlug = 'pedido';
|
|
|
|
protected static $viewPath = 'themes/vuexy/form/pedidos/';
|
|
|
|
protected $indexRoute = 'pedidoList';
|
|
|
|
|
|
public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger)
|
|
{
|
|
$this->viewData['pageTitle'] = lang('Tarifaextra.moduleTitle');
|
|
// Se indica que este controlador trabaja con soft_delete
|
|
|
|
// Breadcrumbs
|
|
$this->viewData['breadcrumb'] = [
|
|
['title' => lang("App.menu_pedidos"), 'route' => "javascript:void(0);", 'active' => false],
|
|
];
|
|
|
|
parent::initController($request, $response, $logger);
|
|
|
|
}
|
|
|
|
public function index()
|
|
{
|
|
|
|
$this->viewData['usingClientSideDataTable'] = true;
|
|
|
|
$this->viewData['pageSubTitle'] = lang('Basic.global.ManageAllRecords', [lang('Tarifaextra.tarifaextra')]);
|
|
parent::index();
|
|
|
|
}
|
|
|
|
public function activos()
|
|
{
|
|
echo 'Pedidos Activos';
|
|
}
|
|
|
|
public function finalizados()
|
|
{
|
|
echo 'Pedidos Finalizados';
|
|
}
|
|
|
|
public function cancelados()
|
|
{
|
|
echo 'Pedidos Cancelados';
|
|
}
|
|
|
|
public function todos()
|
|
{
|
|
|
|
$viewData = [
|
|
'currentModule' => static::$controllerSlug,
|
|
'pageSubTitle' => lang('Basic.global.ManageAllRecords', [lang('Pedidos.pedido')]),
|
|
'presupuestoEntity' => new PedidoEntity(),
|
|
'usingServerSideDataTable' => true,
|
|
'pageTitle' => lang('Pedidos.Pedidos'),
|
|
'estadoPedidos' => 'todos',
|
|
['title' => lang("App.menu_pedidos"), 'route' => site_url('pedidos/todos'), 'active' => true]
|
|
];
|
|
|
|
return view(static::$viewPath . 'viewPedidosList', $viewData);
|
|
|
|
}
|
|
|
|
public function edit($id=null){
|
|
|
|
if ($id == null) :
|
|
return $this->redirect2listView();
|
|
endif;
|
|
$id = filter_var($id, FILTER_SANITIZE_URL);
|
|
$pedidoEntity = $this->model->find($id);
|
|
|
|
if ($pedidoEntity == false) :
|
|
$message = lang('Basic.global.notFoundWithIdErr', [mb_strtolower(lang('Pedidos.pedido')), $id]);
|
|
return $this->redirect2listView('sweet-error', $message);
|
|
endif;
|
|
|
|
$this->obtenerDatosFormulario($pedidoEntity);
|
|
|
|
$this->viewData['pedidoEntity'] = $pedidoEntity;
|
|
|
|
$this->viewData['boxTitle'] = lang('Basic.global.edit2') . ' ' . lang('Pedidos.moduleTitle') . ' ' . lang('Basic.global.edit3');
|
|
|
|
return $this->displayForm(__METHOD__, $id);
|
|
}
|
|
|
|
public function datatable(){
|
|
|
|
if ($this->request->isAJAX()) {
|
|
|
|
$reqData = $this->request->getPost();
|
|
if (!isset($reqData['draw']) || !isset($reqData['columns']) ) {
|
|
$errstr = 'No data available in response to this specific request.';
|
|
$response = $this->respond(Collection::datatable( [], 0, 0, $errstr ), 400, $errstr);
|
|
return $response;
|
|
}
|
|
$start = $reqData['start'] ?? 0;
|
|
$length = $reqData['length'] ?? 5;
|
|
$search = $reqData['search']['value'];
|
|
$requestedOrder = $reqData['order']['0']['column'] ?? 0;
|
|
$order = PedidoModel::SORTABLE_TODOS[$requestedOrder >= 0 ? $requestedOrder : 0];
|
|
$dir = $reqData['order']['0']['dir'] ?? 'asc';
|
|
|
|
$model_linea = model('\App\Models\Pedidos\PedidoLineaModel');
|
|
$resourceData = $model_linea->getResource($search)->orderBy($order, $dir)->limit($length, $start)->get()->getResultObject();
|
|
|
|
return $this->respond(Collection::datatable(
|
|
$resourceData,
|
|
$model_linea->getResource()->countAllResults(),
|
|
$model_linea->getResource($search)->countAllResults()
|
|
));
|
|
} else {
|
|
return $this->failUnauthorized('Invalid request', 403);
|
|
}
|
|
}
|
|
|
|
private function obtenerDatosFormulario(&$pedidoEntity){
|
|
|
|
$datos = $this->model->obtenerDatosForm($pedidoEntity->id);
|
|
|
|
$pedidoEntity->estadoText = lang('Pedidos.' . $pedidoEntity->estado);
|
|
|
|
if(count($datos) > 0){
|
|
$pedidoEntity->cliente = $datos[0]->cliente;
|
|
$pedidoEntity->cliente_id = $datos[0]->cliente_id;
|
|
$pedidoEntity->comercial = $datos[0]->comercial;
|
|
}
|
|
}
|
|
}
|
|
|