añadidos entidades y modelos. Hecha lista de todos

This commit is contained in:
2024-06-11 08:53:20 +02:00
parent bc85572610
commit 2143660cf6
14 changed files with 484 additions and 31 deletions

View File

@ -588,6 +588,18 @@ $routes->group('presupuestotiradasalternativas', ['namespace' => 'App\Controller
$routes->post('datatable_2', 'Presupuestotiradasalternativas::datatable_2', ['as' => 'getTiradaData']);
});
$routes->group('pedidos', ['namespace' => 'App\Controllers\Pedidos'], function ($routes) {
$routes->get('list', 'Pedido::todos', ['as' => 'listaPresupuestos']);
$routes->get('listActivos', 'Pedido::activos', ['as' => 'listaPresupuestosActivos']);
$routes->get('listFinalizados', 'Pedido::finalizados', ['as' => 'listaFinalizados']);
$routes->get('listCancelados', 'Pedido::cancelados', ['as' => 'listaCancelados']);
$routes->post('datatable', 'Pedido::datatable', ['as' => 'dataTableOfPedidos']);
$routes->get('add', 'Pedido::add', ['as' => 'nuevoPedido']);
$routes->post('add', 'Pedido::add', ['as' => 'crearPedido']);
$routes->post('edit/(:num)', 'Pedido::edit/$1', ['as' => 'editarPedido']);
});
$routes->resource('pedidos', ['namespace' => 'App\Controllers\Pedidos', 'controller' => 'Pedido', 'except' => 'show,new,create,update']);
$routes->group(

View File

@ -2,18 +2,48 @@
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 BaseController
class Pedido extends \App\Controllers\BaseResourceController
{
function __construct()
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()
{
echo 'Pedidos';
$this->viewData['usingClientSideDataTable'] = true;
$this->viewData['pageSubTitle'] = lang('Basic.global.ManageAllRecords', [lang('Tarifaextra.tarifaextra')]);
parent::index();
}
public function activos()
@ -31,25 +61,55 @@ class Pedido extends BaseController
echo 'Pedidos Cancelados';
}
public function manuales()
public function todos()
{
echo 'Pedidos Manuales';
}
// public function delete_files()
// {
//
// }
//
// public function pedidos_maquetacion()
// {
//
// }
//
// public function pedidos_prestashop()
// {
//
// }
$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){
echo "Edit";
}
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[$requestedOrder >= 0 ? $requestedOrder : 0];
$dir = $reqData['order']['0']['dir'] ?? 'asc';
$resourceData = $this->model->getResource($search)->orderBy($order, $dir)->limit($length, $start)->get()->getResultObject();
return $this->respond(Collection::datatable(
$resourceData,
$this->model->getResource()->countAllResults(),
$this->model->getResource($search)->countAllResults()
));
} else {
return $this->failUnauthorized('Invalid request', 403);
}
}
}

View File

@ -0,0 +1,30 @@
<?php
namespace App\Entities\Pedidos;
use CodeIgniter\Entity;
class PedidoEntity extends \CodeIgniter\Entity\Entity
{
protected $attributes = [
"id" => null,
"total_precio" => null,
"total_tirada" => null,
"estado" => null,
"user_created_id" => null,
"user_updated_id" => null,
"user_validated_id" => null,
"fecha_entrega_real" => null,
"fecha_impresion" => null,
"fecha_encuadernado" => null,
"fecha_entrega_externo" => null,
"created_at" => null,
"updated_at" => null,
"validated_at" => null,
];
protected $casts = [
"total_precio" => "float",
"total_tirada" => "float",
];
}

View File

@ -0,0 +1,25 @@
<?php
namespace App\Entities\Pedidos;
use CodeIgniter\Entity;
class PedidoLineaEntity extends \CodeIgniter\Entity\Entity
{
protected $attributes = [
"id" => null,
"pedido_id" => null,
"presupuesto_id" => null,
"ubicacion_id" => null,
"user_created_id" => null,
"user_updated_id" => null,
"created_at" => null,
"updated_at" => null,
];
protected $casts = [
"pedido_id" => "int",
"presupuesto_id" => "int",
"ubicacion_id" => "int",
];
}

View File

@ -731,7 +731,7 @@ return [
"menu_pedidos_activos" => "Actives",
"menu_pedidos_finalizados" => "Finished",
"menu_pedidos_cancelados" => "Cancelled",
"menu_pedidos_manuales" => "Manual",
"menu_pedidos_todos" => "All",
"menu_presupuestos" => "Budgets",
"menu_presupuesto" => "Books",

View File

@ -0,0 +1,27 @@
<?php
return [
'id' => 'Number',
'fecha' => 'Date',
'fecha_entrega' => 'Delivery Date',
'cliente' => 'Client',
'comercial' => 'Commercial',
'titulo' => 'Title',
'ubicacion' => 'Location',
'inc_rei' => 'Inc/Rei', // This seems to be a specific term, left as is
'num_paginas' => 'Number of Pages',
'tiradas' => 'Print Runs',
'total_presupuesto' => 'Total Budget',
'estado' => 'Status',
'moduleTitle' => 'Orders',
'pedido' => 'Order',
'pedidos' => 'Orders',
'pedidosList' => 'Orders List',
'validation' => [
],
];

View File

@ -737,7 +737,7 @@ return [
"menu_pedidos_activos" => "Activos",
"menu_pedidos_finalizados" => "Finalizados",
"menu_pedidos_cancelados" => "Cancelados",
"menu_pedidos_manuales" => "Manuales",
"menu_pedidos_todos" => "Todos",
"menu_presupuestos" => "Presupuestos",
"menu_presupuesto" => "Libros",

View File

@ -0,0 +1,28 @@
<?php
return [
'id' => 'Número',
'fecha' => 'Fecha',
'fecha_entrega' => 'Fecha <br>Entrega',
'cliente' => 'Cliente',
'comercial' => 'Comercial',
'titulo' => 'Título',
'ubicacion' => 'Ubicación',
'inc_rei' => 'Inc/Rei',
'num_paginas' => 'Nº Páginas',
'tiradas' => 'Tiradas',
'total_presupuesto' => 'Total',
'estado' => 'Estado',
'moduleTitle' => 'Pedidos',
'pedido' => 'Pedido',
'pedidos' => 'Pedidos',
'pedidosList' => 'Lista de Pedidos',
'validation' => [
],
];

View File

@ -0,0 +1,42 @@
<?php
namespace App\Models\Pedidos;
class PedidoLineaModel extends \App\Models\BaseModel
{
protected $table = "pedidos_linea";
/**
* Whether primary key uses auto increment.
*
* @var bool
*/
protected $useAutoIncrement = true;
const SORTABLE = [
0 => "t1.id",
1 => "t1.estado",
2 => "t1.total_precio",
3 => "t1.total_tirada",
];
protected $allowedFields = [
"pedido_id",
"presupuesto_id",
"ubicacion_id",
"user_created_id",
"user_updated_id",
"created_at",
"updated_at",
];
protected $returnType = "App\Entities\Pedidos\PedidoLineaEntity";
protected $useTimestamps = true;
protected $useSoftDeletes = false;
protected $createdField = "created_at";
protected $updatedField = "updated_at";
public static $labelField = "id";
}

View File

@ -0,0 +1,82 @@
<?php
namespace App\Models\Pedidos;
class PedidoModel extends \App\Models\BaseModel
{
protected $table = "pedidos";
/**
* Whether primary key uses auto increment.
*
* @var bool
*/
protected $useAutoIncrement = true;
const SORTABLE_TODOS = [
0 => "t1.id",
1 => "t1.updated_at",
2 => "t1.fecha_entrega_real",
3 => "t4.nombre",
4 => "t5.first_name",
5 => "t3.titulo",
6 => "t6.ubicacion",
7 => "t3.inc_rei",
8 => "t3.paginas",
9 => "t3.tirada",
10 => "t3.total_aceptado",
11 => "t1.estado"
];
protected $allowedFields = [
"total_precio",
"total_tirada",
"estado",
"user_created_id",
"user_updated_id",
"user_validated_id",
"fecha_entrega_real",
"fecha_impresion",
"fecha_encuadernado",
"fecha_entrega_externo",
"created_at",
"updated_at",
"validated_at",
];
protected $returnType = "App\Entities\Pedidos\PedidoEntity";
protected $useTimestamps = true;
protected $useSoftDeletes = false;
protected $createdField = "created_at";
protected $updatedField = "updated_at";
public static $labelField = "id";
public function getResource(string $search = "", $tarifa_envio_id = -1)
{
$builder = $this->db
->table($this->table . " t1")
->select(
"t1.id AS id, t1.updated_at AS fecha, t1.fecha_entrega_real AS fecha_entrega,
t4.nombre AS cliente, CONCAT(t5.first_name, ' ', t5.last_name) AS comercial,
t3.titulo AS titulo, t6.nombre AS ubicacion, t3.inc_rei AS inc_rei,
t3.paginas AS paginas, t3.tirada AS tirada, t3.total_aceptado AS total_presupuesto,
t1.estado AS estado"
);
$builder->join("pedidos_linea t2", "t1.id = t2.pedido_id", "left");
$builder->join("presupuestos t3", "t2.presupuesto_id = t3.id", "left");
$builder->join("clientes t4", "t4.id = t3.cliente_id", "left");
$builder->join("users t5", "t5.id = t4.comercial_id", "left");
$builder->join("ubicaciones t6", "t6.id = t2.ubicacion_id", "left");
return empty($search)
? $builder
: $builder
->groupStart()
->like("t1.id", $search)
->orLike("t1.id", $search)
->groupEnd();
}
}

View File

@ -0,0 +1,147 @@
<?=$this->include('themes/_commonPartialsBs/datatables') ?>
<?= $this->include('themes/_commonPartialsBs/_confirm2delete') ?>
<?=$this->extend('themes/vuexy/main/defaultlayout') ?>
<?=$this->section('content'); ?>
<div class="row">
<div class="col-md-12">
<div class="card card-info">
<div class="card-header">
<h3 class="card-title"><?=lang('Pedidos.pedidosList') ?></h3>
</div><!--//.card-header -->
<div class="card-body">
<?= view('themes/_commonPartialsBs/_alertBoxes'); ?>
<table id="tableOfPedidos" class="table table-striped table-hover" style="width: 100%;">
<thead>
<tr>
<th><?= lang('Pedidos.id') ?></th>
<th><?= lang('Pedidos.fecha') ?></th>
<th><?= lang('Pedidos.fecha_entrega') ?></th>
<th><?= lang('Pedidos.cliente') ?></th>
<th><?= lang('Pedidos.comercial') ?></th>
<th><?= lang('Pedidos.titulo') ?></th>
<th><?= lang('Pedidos.ubicacion') ?></th>
<th><?= lang('Pedidos.inc_rei') ?></th>
<th><?= lang('Pedidos.num_paginas') ?></th>
<th><?= lang('Pedidos.tiradas') ?></th>
<th><?= lang('Pedidos.total_presupuesto') ?></th>
<th><?= lang('Pedidos.estado') ?></th>
<th class="text-nowrap"><?= lang('Basic.global.Action') ?></th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div><!--//.card-body -->
<div class="card-footer">
</div><!--//.card-footer -->
</div><!--//.card -->
</div><!--//.col -->
</div><!--//.row -->
<?=$this->endSection() ?>
<?=$this->section('additionalInlineJs') ?>
const lastColNr = $('#tableOfPedidos').find("tr:first th").length - 1;
const actionBtns = function(data) {
return `
<td class="text-right py-0 align-middle">
<div class="btn-group btn-group-sm">
<a href="javascript:void(0);"><i class="ti ti-pencil ti-sm btn-edit mx-2" data-id="${data.id}"></i></a>
</div>
</td>`;
};
theTable = $('#tableOfPedidos').DataTable({
processing: true,
serverSide: true,
autoWidth: true,
responsive: true,
scrollX: true,
lengthMenu: [ 5, 10, 25, 50, 75, 100, 250, 500, 1000, 2500 ],
pageLength: 50,
lengthChange: true,
"dom": 'lfBrtip',
"buttons": [
'copy', 'csv', 'excel', 'print', {
extend: 'pdfHtml5',
orientation: 'landscape',
pageSize: 'A4'
}
],
stateSave: true,
order: [[0, 'asc']],
language: {
url: "/themes/vuexy/vendor/libs/datatables-sk/plugins/i18n/es-ES.json"
},
ajax : $.fn.dataTable.pipeline( {
url: '<?= route_to('dataTableOfPedidos') ?>',
method: 'POST',
data: {
estado: "<?= $estadoPedidos ?>",
},
headers: {'X-Requested-With': 'XMLHttpRequest'},
async: true,
}),
columnDefs: [
{
orderable: false,
searchable: false,
targets: [lastColNr]
}
],
columns : [
{ 'data': 'id' },
{ 'data': 'fecha' },
{ 'data': 'fecha_entrega' },
{ 'data': 'cliente' },
{ 'data': 'comercial' },
{ 'data': 'titulo' },
{ 'data': 'ubicacion' },
{ 'data': 'inc_rei' },
{ 'data': 'num_paginas' },
{ 'data': 'tiradas' },
{ 'data': 'total_presupuesto' },
{ 'data': 'estado' },
{ 'data': actionBtns }
]
});
theTable.on( 'draw.dt', function () {
const boolCols = [];
for (let coln of boolCols) {
theTable.column(coln, { page: 'current' }).nodes().each( function (cell, i) {
cell.innerHTML = cell.innerHTML == '1' ? '<i class="ti ti-check"></i>' : '';
});
}
});
$(document).on('click', '.btn-edit', function(e) {
window.location.href = `/pedidos/edit/${$(this).attr('data-id')}`;
});
<?=$this->endSection() ?>
<?=$this->section('css') ?>
<link rel="stylesheet" href="<?= site_url("/themes/vuexy/vendor/libs/datatables-sk/plugins/buttons/buttons.bootstrap5.min.css") ?>">
<?=$this->endSection() ?>
<?= $this->section('additionalExternalJs') ?>
<script src="<?= site_url("/themes/vuexy/vendor/libs/datatables-sk/plugins/buttons/dataTables.buttons.min.js") ?>"></script>
<script src="<?= site_url("/themes/vuexy/vendor/libs/datatables-sk/plugins/buttons/buttons.bootstrap5.min.js") ?>"></script>
<script src="<?= site_url("/themes/vuexy/vendor/libs/datatables-sk/plugins/buttons/buttons.html5.min.js") ?>"></script>
<script src="<?= site_url("/themes/vuexy/vendor/libs/datatables-sk/plugins/buttons/buttons.print.min.js") ?>"></script>
<script src="<?= site_url("/themes/vuexy/vendor/libs/datatables-sk/plugins/jszip/jszip.min.js") ?>"></script>
<script src="<?= site_url("/themes/vuexy/vendor/libs/datatables-sk/plugins/pdfmake/pdfmake.min.js") ?>" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="<?= site_url("/themes/vuexy/vendor/libs/datatables-sk/plugins/pdfmake/vfs_fonts.js") ?>"></script>
<?=$this->endSection() ?>

View File

@ -117,10 +117,10 @@
</a>
</li>
<?php endif; ?>
<?php if (count(getArrayItem($temp, 'methods', 'manuales', true)) > 0): ?>
<?php if (count(getArrayItem($temp, 'methods', 'todos', true)) > 0): ?>
<li class="menu-item">
<a href="<?= site_url("pedidos/pedido/manuales") ?>" class="menu-link">
<div data-i18n="<?= lang("App.menu_pedidos_manuales") ?>"><?= lang("App.menu_pedidos_manuales") ?></div>
<a href="<?= site_url("pedidos/pedido/todos") ?>" class="menu-link">
<div data-i18n="<?= lang("App.menu_pedidos_todos") ?>"><?= lang("App.menu_pedidos_todos") ?></div>
</a>
</li>
<?php endif; ?>

View File

@ -138,10 +138,10 @@
</a>
</li>
<?php endif; ?>
<?php if (count(getArrayItem($temp, 'methods', 'manuales', true)) > 0): ?>
<?php if (count(getArrayItem($temp, 'methods', 'todos', true)) > 0): ?>
<li class="menu-item">
<a href="<?= site_url("pedidos/pedido/manuales") ?>" class="menu-link">
<div data-i18n="<?= lang("App.menu_pedidos_manuales") ?>"><?= lang("App.menu_pedidos_manuales") ?></div>
<a href="<?= site_url("pedidos/pedido/todos") ?>" class="menu-link">
<div data-i18n="<?= lang("App.menu_pedidos_todos") ?>"><?= lang("App.menu_pedidos_todos") ?></div>
</a>
</li>
<?php endif; ?>

View File

@ -27,8 +27,8 @@ if (auth()->user()->inGroup('beta')) {
</a>
</li>
<li class="menu-item">
<a href="<?= site_url("pedidos/pedido/manuales") ?>" class="menu-link">
<?= lang("App.menu_pedidos_manuales") ?>
<a href="<?= site_url("pedidos/pedido/todos") ?>" class="menu-link">
<?= lang("App.menu_pedidos_todos") ?>
</a>
</li>
</ul>