terminando la consulta get resource del modelo maquinaspapelimpresion

This commit is contained in:
Jaime Jimenez
2023-06-30 11:34:30 +02:00
parent 38dd7cdadf
commit d356974178
11 changed files with 269 additions and 110 deletions

View File

@ -252,6 +252,11 @@ $routes->group('maquinastarifasimpresion', ['namespace' => 'App\Controllers\Conf
});
$routes->resource('maquinastarifasimpresion', ['namespace' => 'App\Controllers\Configuracion', 'controller' => 'Maquinastarifasimpresion', 'except' => 'show,new,create,update']);
$routes->group('maquinaspapelesimpresion', ['namespace' => 'App\Controllers\Configuracion'], function ($routes) {
$routes->post('datatable', 'Maquinaspapelesimpresion::datatable', ['as' => 'dataTableOfMaquinasPapelesImpresion']);
});
$routes->resource('maquinastarifasimpresion', ['namespace' => 'App\Controllers\Configuracion', 'controller' => 'Maquinastarifasimpresion', 'except' => 'show,new,create,update']);
$routes->group('profile', ['namespace' => 'App\Controllers'], function ($routes) {

View File

@ -5,9 +5,9 @@ use App\Controllers\GoBaseResourceController;
use App\Models\Collection;
use App\Entities\Configuracion\MaquinasTarifasImpresionEntity;
use App\Entities\Configuracion\MaquinasPapelesImpresionEntity;
use App\Models\Configuracion\MaquinasTarifasImpresionModel;
use App\Models\Configuracion\MaquinasPapelesImpresionModel;
use App\Models\Configuracion\MaquinaModel;
@ -22,38 +22,74 @@ use
DataTables\Editor\Validate,
DataTables\Editor\ValidateOptions;
class Maquinaspapelesimpresion extends \App\Controllers\GoBaseResourceController {
class Maquinaspapelesimpresion extends \App\Controllers\GoBaseResourceController {
protected $modelName = MaquinasPapelesImpresionModel::class;
protected $format = 'json';
protected static $singularObjectName = 'Maquinas Papel Impresion';
protected static $singularObjectNameCc = 'maquinasPapelImpresion';
protected static $pluralObjectName = 'Maquinas Papeles Impresion';
protected static $pluralObjectNameCc = 'maquinasPapelesImpresion';
protected static $controllerSlug = 'maquinaspapelesimpresion';
protected static $viewPath = 'themes/backend/vuexy/form/configuracion/maquinas/';
protected $indexRoute = '';
public function datatable_maquinas() {
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'] ?? 1;
$order = MaquinasTarifasImpresionModel::SORTABLE[$requestedOrder > 0 ? $requestedOrder : 1];
$dir = $reqData['order']['0']['dir'] ?? 'asc';
// el primer dato representa el uso y el segundo el tipo
$tarifas = $reqData['tarifas'] ?? null;
// Para saber si el papel que se tiene que mostrar es para rotativa
$isRotativa= $reqData['isRotativa'] ?? false;
$resourceData = $this->model->getResource("", $tarifas, $isRotativa)->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);
public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger) {
$this->viewData['pageTitle'] = '';
$this->viewData['usingSweetAlert'] = true;
parent::initController($request, $response, $logger);
}
public function index() {
$viewData = [
'currentModule' => static::$controllerSlug,
'pageSubTitle' => '',
'maquinasTarifasImpresion' => new Maquinaspapelesimpresion(),
'usingServerSideDataTable' => true,
];
}
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'] ?? 1;
$order = MaquinasPapelesImpresionModel::SORTABLE[$requestedOrder >= 0 ? $requestedOrder : 1];
$dir = $reqData['order']['0']['dir'] ?? 'asc';
}
// el primer dato representa el uso y el segundo el tipo
//$tarifas = $reqData['tarifas'] ?? [];
// Para saber si el papel que se tiene que mostrar es para rotativa
$isRotativa= $reqData['isRotativa'] ?? 0;
$resourceData = $this->model->getResource("", $isRotativa)->orderBy($order, $dir)->limit($length, $start)->get()->getResultObject();
return $this->respond(Collection::datatable(
$resourceData,
$this->model->getResource()->countAllResults(),
$this->model->getResource($search, $isRotativa)->countAllResults()
));
} else {
return $this->failUnauthorized('Invalid request', 403);
}
}
}

View File

@ -235,10 +235,6 @@ if ($this->request->getPost('predeterminado') == null ) {
->validator( 'Validate::notEmpty',array(
'message' => lang('MaquinasTarifasImpresions.validation.tipo.required') )
),
Field::inst( 'predeterminado' )
->validator( 'Validate::notEmpty',array(
'message' => lang('MaquinasTarifasImpresions.validation.tipo.required') )
),
Field::inst( 'maquina_id' ),
Field::inst( 'user_created_id' ),
Field::inst( 'created_at' ),
@ -254,6 +250,10 @@ if ($this->request->getPost('predeterminado') == null ) {
// Si no se quiere borrar...
if($data['data'][$pkey]['is_deleted'] != 1)
{
// Cubierta y sobrecubierta sólo pueden ser en color
if($values['uso'] != 'interior' && $values['tipo'] != 'color'){
return lang('MaquinasTarifasImpresions.validation.cubierta_sobrecubierta_color');
}
$builder = $this->model->select('*')
->where(array(
@ -338,7 +338,7 @@ if ($this->request->getPost('predeterminado') == null ) {
return $this->respond(Collection::datatable(
$resourceData,
$this->model->getResource()->countAllResults(),
$this->model->getResource($search)->countAllResults()
$this->model->getResource($search, $id_M)->countAllResults()
));
} else {
return $this->failUnauthorized('Invalid request', 403);

View File

@ -11,7 +11,6 @@ class MaquinasTarifasImpresionEntity extends \CodeIgniter\Entity\Entity
"tipo" => null,
"precio" => null,
"uso" => null,
"predeterminado" => false,
"user_created_id" => 0,
"user_updated_id" => 0,
"is_deleted" => 0,
@ -21,7 +20,6 @@ class MaquinasTarifasImpresionEntity extends \CodeIgniter\Entity\Entity
protected $casts = [
"maquina_id" => "int",
"precio" => "float",
"predeterminado" => "boolean",
"user_created_id" => "int",
"user_updated_id" => "int",
"is_deleted" => "int",

View File

@ -0,0 +1,8 @@
<?php
return [
'activo' => 'Active',
];

View File

@ -20,14 +20,16 @@ return [
'userCreatedId' => 'User Created ID',
'userUpdatedId' => 'User Updated ID',
'uso' => 'Use',
'interior' => 'inside',
'portada' => 'cover',
'negro' => 'black',
'color' => 'color',
'negrohq' => 'blackhq',
'bicolor' => 'bicolor',
'interior' => 'Inside',
'cubierta' => 'Cover',
'sobrecubierta' => 'Dust jacket',
'negro' => 'Black',
'color' => 'Color',
'negrohq' => 'Black HQ',
'bicolor' => 'Bicolor',
'validation' => [
'duplicated_uso_tipo' => "Duplicate line (the combination 'use' and 'type' already exists)",
'cubierta_sobrecubierta_color' => "Cover and dust jacket only allow 'color' type",
'tipo' => [
'in_list' => 'The {field} field must be one of: {param}.',
'required' => 'Required field.',

View File

@ -0,0 +1,8 @@
<?php
return [
'activo' => 'Activo',
];

View File

@ -20,14 +20,16 @@ return [
'userCreatedId' => 'User Created ID',
'userUpdatedId' => 'User Updated ID',
'uso' => 'Uso',
'interior' => 'interior',
'portada' => 'portada',
'negro' => 'negro',
'color' => 'color',
'negrohq' => 'negrohq',
'bicolor' => 'bicolor',
'interior' => 'Interior',
'cubierta' => 'Cubierta',
'sobrecubierta' => 'Sobrecubierta',
'negro' => 'Negro',
'color' => 'Color',
'negrohq' => 'Negro HQ',
'bicolor' => 'Bicolor',
'validation' => [
'duplicated_uso_tipo' => "Línea duplicada (la combinación 'uso' y 'tipo' ya existe)",
'cubierta_sobrecubierta_color' => "Cubierta y sobrecubierta solo permiten tipo 'color'",
'tipo' => [
'in_list' => 'El campo {field} debe contener uno de: {param}.',
'required' => 'Campo obligatorio.',

View File

@ -1,7 +1,7 @@
<?php
namespace App\Models\Configuracion;
class MaquinasTarifasImpresionModel extends \App\Models\GoBaseModel
class MaquinasPapelesImpresionModel extends \App\Models\GoBaseModel
{
protected $table = "lg_maquina_papel_impresion";
@ -13,9 +13,15 @@ class MaquinasTarifasImpresionModel extends \App\Models\GoBaseModel
protected $useAutoIncrement = true;
const SORTABLE = [
1 => "t1.maquina_id",
2 => "t1.papel_impresion_id",
3 => "t1.active",
0 => "t1.active",
1 => "t4.nombre",
2 => "t3.nombre",
3 => "t3.gramaje",
4 => "t3.bn",
5 => "t3.color",
6 => "t3.cubierta",
7 => "t3.sobrecubierta",
8 => "t3.rotativa",
];
protected $allowedFields = ["maquina_id", "papel_impresion_id", "active"];
@ -29,20 +35,34 @@ class MaquinasTarifasImpresionModel extends \App\Models\GoBaseModel
*
* @return \CodeIgniter\Database\BaseBuilder
*/
public function getResource(string $search = "", $tarifas = null, $isRotativa = false)
public function getResource(string $search = "", $isRotativa = 0)
{
$builder = $this->db
->table($this->table . " t1")
->select(
"t1.maquina_id AS maquina_id, t1.papel_impresion_id AS papel_impresion_id, t1.active AS active, t2.nombre AS maquina, t3.nombre AS papel_impresion"
"t1.maquina_id AS maquina_id, t1.papel_impresion_id AS papel_impresion_id, t1.active AS active, t2.nombre AS maquina,
t3.nombre AS papel_impresion, t3.gramaje AS gramaje, , t3.bn AS bn, t3.color AS color, t3.cubierta AS cubierta, , t3.sobrecubierta AS sobrecubierta,
t3.rotativa AS rotativa, t4.nombre as papel_generico"
);
$builder->join("lg_maquinas t2", "t1.maquina_id = t2.id", "left");
$builder->join("lg_papel_impresion t3", "t3.papel_impresion_id = t3.id", "left");
$builder->join("lg_maquinas t2", "t1.maquina_id = t2.id", "left");
$builder->join("lg_papel_impresion t3", "t1.papel_impresion_id = t3.id", "left");
$builder->join("lg_papel_generico t4", "t3.papel_generico_id = t4.id", "left");
$builder->where("t2.is_deleted", 0);
$builder->where("t3.is_deleted", 0);
$builder->where("t4.is_deleted", 0);
$builder->where("t3.isActivo", 1);
$builder->where("t3.rotativa", $isRotativa);
$isFirst = false;
$where_str = "";
if (!is_null($tarifas)){
// Si hay tarifas...
/*if (!empty($tarifas)){
foreach ($tarifas as $tarifa){
if (!$isFirst)
$where_str += ' OR ';
@ -55,17 +75,13 @@ class MaquinasTarifasImpresionModel extends \App\Models\GoBaseModel
}
$builder->where($where_str);
}
if($isRotativa){
$builder->where("t3.rotativa", 1);
}
else{
$builder->where("t3.rotativa", 0);
}
}*/
// si no hay tarifas no hay que devolver nada
/*else{
return "";
}*/
$builder->where("t2.is_deleted", 0);
$builder->where("t3.is_deleted", 0);
return empty($search)
? $builder

View File

@ -18,11 +18,10 @@ class MaquinasTarifasImpresionModel extends \App\Models\GoBaseModel
3 => "t1.tipo",
4 => "t1.precio",
5 => "t1.uso",
6 => "t1.predeterminado",
7 => "t2.nombre",
6 => "t2.nombre",
];
protected $allowedFields = ["maquina_id", "tipo", "precio", "uso", "predeterminado"];
protected $allowedFields = ["maquina_id", "tipo", "precio", "uso"];
protected $returnType = "App\Entities\Configuracion\MaquinasTarifasImpresionEntity";
protected $useTimestamps = true;
@ -96,7 +95,7 @@ class MaquinasTarifasImpresionModel extends \App\Models\GoBaseModel
$builder = $this->db
->table($this->table . " t1")
->select(
"t1.id AS id, t1.tipo AS tipo, t1.precio AS precio, t1.uso AS uso, t1.predeterminado AS predeterminado, t2.nombre AS maquina"
"t1.id AS id, t1.tipo AS tipo, t1.precio AS precio, t1.uso AS uso, t2.nombre AS maquina"
);
//JJO

View File

@ -49,7 +49,6 @@
<th><?= lang('MaquinasTarifasImpresions.uso') ?></th>
<th><?= lang('MaquinasTarifasImpresions.tipo') ?></th>
<th><?= lang('MaquinasTarifasImpresions.precio') ?></th>
<th><?= lang('MaquinasTarifasImpresions.predeterminado') ?></th>
<th class="text-nowrap"><?= lang('Basic.global.Action') ?></th>
</tr>
</thead>
@ -68,22 +67,26 @@
<div class="accordion mt-3" id="accordianPapelesImpresion">
<div class="card accordion-item active">
<h2 class="accordion-header" id="headingOne">
<button type="button" class="accordion-button" data-bs-toggle="collapse" data-bs-target="#accordionTip1" aria-expanded="false" aria-controls="accordionTip1">
<button type="button" class="accordion-button" data-bs-toggle="collapse" data-bs-target="#accordionTip2" aria-expanded="false" aria-controls="accordionTip2">
<p><?= lang("MaquinasTarifasImpresions.moduleTitle") ?></p>
</button>
</h2>
<div id="accordionTip1" class="accordion-collapse collapse show" data-bs-parent="#accordianPapelesImpresion">
<div id="accordionTip2" class="accordion-collapse collapse show" data-bs-parent="#accordianPapelesImpresion">
<div class="accordion-body">
<table id="tableOfPapelesImpresion" class="table table-striped table-hover" style="width: 100%;">
<thead>
<tr>
<th><?= lang('MaquinasTarifasImpresions.uso') ?></th>
<th><?= lang('MaquinasTarifasImpresions.tipo') ?></th>
<th><?= lang('MaquinasTarifasImpresions.precio') ?></th>
<th><?= lang('MaquinasTarifasImpresions.predeterminado') ?></th>
<th class="text-nowrap"><?= lang('Basic.global.Action') ?></th>
<th><?= lang('MaquinasPapelImpresion.activo') ?></th>
<th><?= lang('PapelGenerico.papelGenerico') ?></th>
<th><?= lang('PapelImpresion.nombre') ?></th>
<th><?= lang('PapelImpresion.gramaje') ?></th>
<th><?= lang('PapelImpresion.bn') ?></th>
<th><?= lang('PapelImpresion.color') ?></th>
<th><?= lang('PapelImpresion.cubierta') ?></th>
<th><?= lang('PapelImpresion.sobrecubierta') ?></th>
<th><?= lang('PapelImpresion.rotativa') ?></th>
</tr>
</thead>
<tbody>
@ -102,6 +105,21 @@
<?= $this->section("additionalInlineJs") ?>
function watch(j) {
return new Proxy(JSON.parse ('{"watch":' + j + '}'), {
set: function(target, property, value) {
target[property] = value;
$('#tableOfPapelesImpresion').DataTable().ajax.reload(null,false);
theTable2.clearPipeline();
theTable2.draw();
}
});
}
isRotativa = watch(0);
$(document).ready(function () {
if($(this).is(':checked')){
@ -113,6 +131,8 @@
if($(this).is(':checked')){
$("#datosRotativa").show();
isRotativa.watch = 1;
}else{
document.getElementById("precioTintaNegro").value = null;
document.getElementById("precioTintaColor").value = null;
@ -120,6 +140,7 @@
document.getElementById("precioHoraCorte").value = null;
document.getElementById("metrosxminuto").value = null;
$("#datosRotativa").hide();
isRotativa.watch = 0;
}
});
@ -183,6 +204,19 @@
};
usoTypes = [
{label:'<?= lang('MaquinasTarifasImpresions.interior') ?>', value:'interior'},
{label:'<?= lang('MaquinasTarifasImpresions.cubierta') ?>', value: 'cubierta'},
{label:'<?= lang('MaquinasTarifasImpresions.sobrecubierta') ?>', value: 'sobrecubierta'}
];
tipoTypes = [
{label:'<?= lang('MaquinasTarifasImpresions.negro') ?>', value:'negro'},
{label:'<?= lang('MaquinasTarifasImpresions.negrohq') ?>', value: 'negrohq'},
{label:'<?= lang('MaquinasTarifasImpresions.bicolor') ?>', value: 'bicolor'},
{label:'<?= lang('MaquinasTarifasImpresions.color') ?>', value: 'color'}
];
editor = new $.fn.dataTable.Editor( {
ajax: {
url: "<?= route_to('editorOfMaquinasTarifaImpresion') ?>",
@ -195,26 +229,16 @@
fields: [ {
name: "uso",
type: "select",
options: ['<?= lang('MaquinasTarifasImpresions.interior') ?>', '<?= lang('MaquinasTarifasImpresions.portada') ?>']
options: usoTypes
}, {
name: "tipo",
type: "select",
options: ['<?= lang('MaquinasTarifasImpresions.negro') ?>', '<?= lang('MaquinasTarifasImpresions.color') ?>',
'<?= lang('MaquinasTarifasImpresions.negrohq') ?>', '<?= lang('MaquinasTarifasImpresions.bicolor') ?>']
options: tipoTypes
}, {
name: "precio",
attr: {
type: "number"
}
}, {
name: "predeterminado",
type: "checkbox",
separator: "",
options: [
{ label: "", value: 1 }
],
unselectedValue: 0
}, {
"name": "maquina_id",
"type": "hidden"
@ -228,6 +252,7 @@
]
} );
editor.on( 'preSubmit', function ( e, d, type ) {
if ( type === 'create'){
d.data[0]['maquina_id'] = id;
@ -257,11 +282,11 @@
processing: true,
autoWidth: true,
responsive: true,
lengthMenu: [ 5, 10, 25],
order: [[ 0, "asc" ]],
lengthMenu: [ 5, 10, 25, 50],
order: [[ 1, "asc" ]],
pageLength: 10,
lengthChange: true,
searching: false,
searching: true,
paging: true,
info: false,
dom: "Bltp",
@ -275,14 +300,32 @@
async: true,
}),
columns: [
{ 'data': 'uso' },
{ 'data': 'tipo' },
{ 'data': 'uso', "render": function ( data, type, row, meta ) {
if(data=='interior')
return '<?= lang('MaquinasTarifasImpresions.interior') ?>';
else if (data=='cubierta')
return '<?= lang('MaquinasTarifasImpresions.cubierta') ?>';
else if (data=='sobrecubierta')
return '<?= lang('MaquinasTarifasImpresions.sobrecubierta') ?>';
}
},
{ 'data': 'tipo', "render": function ( data, type, row, meta ) {
if(data=='negro')
return '<?= lang('MaquinasTarifasImpresions.negro') ?>';
else if (data=='negrohq')
return '<?= lang('MaquinasTarifasImpresions.negrohq') ?>';
else if (data=='bicolor')
return '<?= lang('MaquinasTarifasImpresions.bicolor') ?>';
else if (data=='color')
return '<?= lang('MaquinasTarifasImpresions.color') ?>';
}
},
{ 'data': 'precio' },
{ 'data': 'predeterminado' },
{
data: actionBtns,
className: 'row-edit dt-center'
}
],
columnDefs: [
{
@ -307,6 +350,49 @@
} ]
} );
var theTable2 = $('#tableOfPapelesImpresion').DataTable( {
serverSide: true,
processing: true,
autoWidth: true,
responsive: true,
lengthMenu: [ 5, 10, 25],
order: [[ 1, "asc" ]],
pageLength: 10,
lengthChange: true,
searching: true,
paging: true,
info: false,
dom: "lftp",
ajax : $.fn.dataTable.pipeline( {
url: '<?= route_to('dataTableOfMaquinasPapelesImpresion') ?>',
data: function (d) {
d.id_maquina = id;
d.isRotativa = isRotativa.watch;
},
/*{
id_maquina: id,
//tarifas: [{'uso':'interior', 'tipo':'negro'}],
isRotativa: isRotativa.watch,
},*/
method: 'POST',
headers: {'X-Requested-With': 'XMLHttpRequest'},
async: true,
}),
columns: [
{ 'data': 'active'},
{ 'data': 'papel_generico'},
{ 'data': 'papel_impresion'},
{ 'data': 'gramaje'},
{ 'data': 'bn'},
{ 'data': 'color'},
{ 'data': 'cubierta'},
{ 'data': 'sobrecubierta'},
{ 'data': 'rotativa'}
],
language: {
url: "//cdn.datatables.net/plug-ins/1.13.4/i18n/<?= config('Basics')->i18n ?>.json"
}
} );
// Activate an inline edit on click of a table cell
@ -323,6 +409,14 @@
);
} );
theTable2.on( 'draw.dt', function () {
const boolCols = [4, 5, 6, 7, 8];
for (let coln of boolCols) {
theTable2.column(coln, { page: 'current' }).nodes().each( function (cell, i) {
cell.innerHTML = cell.innerHTML == '1' ? '<i class="ti ti-check"></i>' : '';
});
}
});
// Delete row
$('#tableOfMaquinastarifasimpresion').on( 'click', 'tbody span.remove', function (e) {
@ -352,15 +446,6 @@
});
});
theTable.on( 'draw.dt', function () {
const boolCols = [3];
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>' : '';
});
}
});