From d356974178af7358309e67580b56f5dcd7999356 Mon Sep 17 00:00:00 2001 From: Jaime Jimenez Date: Fri, 30 Jun 2023 11:34:30 +0200 Subject: [PATCH] terminando la consulta get resource del modelo maquinaspapelimpresion --- ci4/app/Config/Routes.php | 5 + .../Maquinaspapelesimpresion.php | 102 ++++++++---- .../Maquinastarifasimpresion.php | 10 +- .../MaquinasTarifasImpresionEntity.php | 2 - .../Language/en/MaquinasPapelImpresion.php | 8 + .../Language/en/MaquinasTarifasImpresions.php | 14 +- .../Language/es/MaquinasPapelImpresion.php | 8 + .../Language/es/MaquinasTarifasImpresions.php | 14 +- .../MaquinasPapelesImpresionModel.php | 54 +++--- .../MaquinasTarifasImpresionModel.php | 7 +- .../maquinas/viewMaquinaForm.php | 155 ++++++++++++++---- 11 files changed, 269 insertions(+), 110 deletions(-) create mode 100644 ci4/app/Language/en/MaquinasPapelImpresion.php create mode 100644 ci4/app/Language/es/MaquinasPapelImpresion.php diff --git a/ci4/app/Config/Routes.php b/ci4/app/Config/Routes.php index f9025a07..ae014d01 100644 --- a/ci4/app/Config/Routes.php +++ b/ci4/app/Config/Routes.php @@ -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) { diff --git a/ci4/app/Controllers/Configuracion/Maquinaspapelesimpresion.php b/ci4/app/Controllers/Configuracion/Maquinaspapelesimpresion.php index bee06924..627285b8 100644 --- a/ci4/app/Controllers/Configuracion/Maquinaspapelesimpresion.php +++ b/ci4/app/Controllers/Configuracion/Maquinaspapelesimpresion.php @@ -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'; - } \ No newline at end of file + // 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); + } + } + +} diff --git a/ci4/app/Controllers/Configuracion/Maquinastarifasimpresion.php b/ci4/app/Controllers/Configuracion/Maquinastarifasimpresion.php index 1d8a4b33..fcd24c70 100644 --- a/ci4/app/Controllers/Configuracion/Maquinastarifasimpresion.php +++ b/ci4/app/Controllers/Configuracion/Maquinastarifasimpresion.php @@ -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); diff --git a/ci4/app/Entities/Configuracion/MaquinasTarifasImpresionEntity.php b/ci4/app/Entities/Configuracion/MaquinasTarifasImpresionEntity.php index 1425ccc2..f0a49f25 100644 --- a/ci4/app/Entities/Configuracion/MaquinasTarifasImpresionEntity.php +++ b/ci4/app/Entities/Configuracion/MaquinasTarifasImpresionEntity.php @@ -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", diff --git a/ci4/app/Language/en/MaquinasPapelImpresion.php b/ci4/app/Language/en/MaquinasPapelImpresion.php new file mode 100644 index 00000000..c5c594fa --- /dev/null +++ b/ci4/app/Language/en/MaquinasPapelImpresion.php @@ -0,0 +1,8 @@ + 'Active', + +]; \ No newline at end of file diff --git a/ci4/app/Language/en/MaquinasTarifasImpresions.php b/ci4/app/Language/en/MaquinasTarifasImpresions.php index a16e9586..0cff47a2 100644 --- a/ci4/app/Language/en/MaquinasTarifasImpresions.php +++ b/ci4/app/Language/en/MaquinasTarifasImpresions.php @@ -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.', diff --git a/ci4/app/Language/es/MaquinasPapelImpresion.php b/ci4/app/Language/es/MaquinasPapelImpresion.php new file mode 100644 index 00000000..2ef7d8ca --- /dev/null +++ b/ci4/app/Language/es/MaquinasPapelImpresion.php @@ -0,0 +1,8 @@ + 'Activo', + +]; \ No newline at end of file diff --git a/ci4/app/Language/es/MaquinasTarifasImpresions.php b/ci4/app/Language/es/MaquinasTarifasImpresions.php index 0529bb09..e7deb3eb 100644 --- a/ci4/app/Language/es/MaquinasTarifasImpresions.php +++ b/ci4/app/Language/es/MaquinasTarifasImpresions.php @@ -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.', diff --git a/ci4/app/Models/Configuracion/MaquinasPapelesImpresionModel.php b/ci4/app/Models/Configuracion/MaquinasPapelesImpresionModel.php index e9f0f099..ce4c84b8 100644 --- a/ci4/app/Models/Configuracion/MaquinasPapelesImpresionModel.php +++ b/ci4/app/Models/Configuracion/MaquinasPapelesImpresionModel.php @@ -1,7 +1,7 @@ "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 diff --git a/ci4/app/Models/Configuracion/MaquinasTarifasImpresionModel.php b/ci4/app/Models/Configuracion/MaquinasTarifasImpresionModel.php index 4be922be..37c0956b 100644 --- a/ci4/app/Models/Configuracion/MaquinasTarifasImpresionModel.php +++ b/ci4/app/Models/Configuracion/MaquinasTarifasImpresionModel.php @@ -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 diff --git a/ci4/app/Views/themes/backend/vuexy/form/configuracion/maquinas/viewMaquinaForm.php b/ci4/app/Views/themes/backend/vuexy/form/configuracion/maquinas/viewMaquinaForm.php index acb1865d..1be5e5eb 100644 --- a/ci4/app/Views/themes/backend/vuexy/form/configuracion/maquinas/viewMaquinaForm.php +++ b/ci4/app/Views/themes/backend/vuexy/form/configuracion/maquinas/viewMaquinaForm.php @@ -49,7 +49,6 @@ - @@ -68,22 +67,26 @@

-

-
+
- - - - - + + + + + + + + + @@ -102,6 +105,21 @@ 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:'', value:'interior'}, + {label:'', value: 'cubierta'}, + {label:'', value: 'sobrecubierta'} + ]; + + tipoTypes = [ + {label:'', value:'negro'}, + {label:'', value: 'negrohq'}, + {label:'', value: 'bicolor'}, + {label:'', value: 'color'} + ]; + editor = new $.fn.dataTable.Editor( { ajax: { url: "", @@ -195,26 +229,16 @@ fields: [ { name: "uso", type: "select", - options: ['', ''] + options: usoTypes }, { name: "tipo", type: "select", - options: ['', '', - '', ''] + 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 ''; + else if (data=='cubierta') + return ''; + else if (data=='sobrecubierta') + return ''; + } + }, + { 'data': 'tipo', "render": function ( data, type, row, meta ) { + if(data=='negro') + return ''; + else if (data=='negrohq') + return ''; + else if (data=='bicolor') + return ''; + else if (data=='color') + return ''; + } + }, { '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: '', + 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/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' ? '' : ''; + }); + } + }); // 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' ? '' : ''; - }); - } - - });