diff --git a/ci4/app/Config/Routes.php b/ci4/app/Config/Routes.php index a5859bb6..9ec4772e 100644 --- a/ci4/app/Config/Routes.php +++ b/ci4/app/Config/Routes.php @@ -243,6 +243,7 @@ $routes->group('maquinastarifasimpresion', ['namespace' => 'App\Controllers\Conf $routes->post('create', 'Maquinastarifasimpresion::create', ['as' => 'ajaxCreateMaquinasTarifaImpresion']); $routes->put('(:num)/update', 'Maquinastarifasimpresion::update/$1', ['as' => 'ajaxUpdateMaquinasTarifaImpresion']); $routes->post('(:num)/edit', 'Maquinastarifasimpresion::edit/$1', ['as' => 'updateMaquinasTarifaImpresion']); + $routes->get('delete/(:num)', 'Maquinastarifasimpresion::delete/$1', ['as' => 'deleteMaquinastarifasimpresion']); $routes->post('datatable_editor', 'Maquinastarifasimpresion::datatable_editor', ['as' => 'editorOfMaquinasTarifaImpresion']); $routes->post('datatable', 'Maquinastarifasimpresion::datatable', ['as' => 'dataTableOfMaquinasTarifasImpresion']); $routes->post('allmenuitems', 'Maquinastarifasimpresion::allItemsSelect', ['as' => 'select2ItemsOfMaquinasTarifasImpresion']); @@ -250,6 +251,14 @@ $routes->group('maquinastarifasimpresion', ['namespace' => 'App\Controllers\Conf }); $routes->resource('maquinastarifasimpresion', ['namespace' => 'App\Controllers\Configuracion', 'controller' => 'Maquinastarifasimpresion', 'except' => 'show,new,create,update']); +$routes->group('maquinascalles', ['namespace' => 'App\Controllers\Configuracion'], function ($routes) { + $routes->get('', 'Maquinascalles::index', ['as' => 'maquinasCallesList']); + $routes->get('delete/(:num)', 'Maquinascalles::delete/$1', ['as' => 'deleteMaquinascalles']); + $routes->post('datatable_editor', 'Maquinascalles::datatable_editor', ['as' => 'editorOfMaquinascalles']); + $routes->post('datatable', 'Maquinascalles::datatable', ['as' => 'dataTableOfMaquinascalles']); +}); +$routes->resource('maquinascalles', ['namespace' => 'App\Controllers\Configuracion', 'controller' => 'maquinascalles', 'except' => 'show,new,create,update']); + $routes->group('maquinaspapelesimpresion', ['namespace' => 'App\Controllers\Configuracion'], function ($routes) { $routes->post('datatable', 'Maquinaspapelesimpresion::datatable', ['as' => 'dataTableOfMaquinasPapelesImpresion']); $routes->post('datatable_2', 'Maquinaspapelesimpresion::datatable_2', ['as' => 'dataTableOfPapelesImpresionMaquinas']); diff --git a/ci4/app/Controllers/Configuracion/Maquinascalles.php b/ci4/app/Controllers/Configuracion/Maquinascalles.php new file mode 100644 index 00000000..c5816014 --- /dev/null +++ b/ci4/app/Controllers/Configuracion/Maquinascalles.php @@ -0,0 +1,201 @@ +viewData['pageTitle'] = lang('MaquinasCalles.moduleTitle'); + $this->viewData['usingSweetAlert'] = true; + + // Se indica que este controlador trabaja con soft_delete + $this->soft_delete = true; + // Se indica el flag para los ficheros borrados + $this->delete_flag = 1; + + $this->viewData = ['usingServerSideDataTable' => true]; // JJO + + parent::initController($request, $response, $logger); + } + + + + + public function datatable_editor() + { + if ($this->request->isAJAX()) { + + include(APPPATH . "ThirdParty/DatatablesEditor/DataTables.php"); + + // Build our Editor instance and process the data coming from _POST + $response = Editor::inst($db, 'maquinas_calles') + ->fields( + Field::inst('formas_min') + ->validator('Validate::numeric', array( + 'message' => lang('MaquinasCalles.validation.formas_min.integer')) + ) + ->validator('Validate::notEmpty', array( + 'message' => lang('MaquinasCalles.validation.formas_min.required')) + ), + Field::inst('formas_max') + ->validator('Validate::numeric', array( + 'message' => lang('MaquinasCalles.validation.formas_max.integer')) + ) + ->validator('Validate::notEmpty', array( + 'message' => lang('MaquinasCalles.validation.formas_max.required')) + ), + Field::inst('internas') + ->validator('Validate::numeric', array( + 'message' => lang('MaquinasCalles.validation.internas.decimal')) + ) + ->validator('Validate::notEmpty', array( + 'message' => lang('MaquinasCalles.validation.internas.required')) + ), + Field::inst('externas') + ->validator('Validate::numeric', array( + 'message' => lang('MaquinasCalles.validation.externas.decimal')) + ) + ->validator('Validate::notEmpty', array( + 'message' => lang('MaquinasCalles.validation.externas.required')) + ), + Field::inst('maquina_id'), + Field::inst('user_created_id'), + Field::inst('created_at'), + Field::inst('user_updated_id'), + Field::inst('updated_at'), + Field::inst('is_deleted'), + Field::inst('deleted_at'), + + ) + ->validator(function ($editor, $action, $data) { + if ($action === Editor::ACTION_CREATE || $action === Editor::ACTION_EDIT) { + foreach ($data['data'] as $pkey => $values) { + // Si no se quiere borrar... + if ($data['data'][$pkey]['is_deleted'] != 1) { + $process_data['formas_min'] = $data['data'][$pkey]['formas_min']; + $process_data['formas_max'] = $data['data'][$pkey]['formas_max']; + $process_data['maquina_id'] = $data['data'][$pkey]['maquina_id']; + $response = $this->model->checkIntervals($process_data, $pkey); + // No se pueden duplicar valores al crear o al editar + if (!empty($response)) { + return $response; + } + } + } + } + }) + ->on('preCreate', function ($editor, &$values) { + $session = session(); + $datetime = (new \CodeIgniter\I18n\Time("now")); + $editor + ->field('user_created_id') + ->setValue($session->id_user); + $editor + ->field('created_at') + ->setValue($datetime->format('Y-m-d H:i:s')); + }) + ->on('preEdit', function ($editor, &$values) { + $session = session(); + $datetime = (new \CodeIgniter\I18n\Time("now")); + $editor + ->field('user_updated_id') + ->setValue($session->id_user); + $editor + ->field('updated_at') + ->setValue($datetime->format('Y-m-d H:i:s')); + }) + ->debug(true) + ->process($_POST) + ->data(); + + $newTokenHash = csrf_hash(); + $csrfTokenName = csrf_token(); + + $response[$csrfTokenName] = $newTokenHash; + + echo json_encode($response); + + } else { + return $this->failUnauthorized('Invalid request', 403); + } + } + + 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 = MaquinasCallesModel::SORTABLE[$requestedOrder >= 0 ? $requestedOrder : 0]; + $dir = $reqData['order']['0']['dir'] ?? 'asc'; + + $id_M = $reqData['maquina_id'] ?? -1; + + $resourceData = $this->model->getResource("", $id_M)->orderBy($order, $dir)->limit($length, $start)->get()->getResultObject(); + + return $this->respond(Collection::datatable( + $resourceData, + $this->model->getResource()->countAllResults(), + $this->model->getResource($search, $id_M)->countAllResults() + )); + } else { + return $this->failUnauthorized('Invalid request', 403); + } + } + + + public function menuItems() + { + if ($this->request->isAJAX()) { + + $provTipoModel = new ProveedorTipoModel(); + $provModel = new ProveedorModel(); + + $tipoId = $provTipoModel->getTipoId("Encuadernacion"); + $provList = $provModel->getProvList($tipoId); + + $newTokenHash = csrf_hash(); + $csrfTokenName = csrf_token(); + + $data = [ + 'data' => $provList, + $csrfTokenName => $newTokenHash + ]; + return $this->respond($data); + } else { + return $this->failUnauthorized('Invalid request', 403); + } + } + +} + diff --git a/ci4/app/Controllers/Configuracion/Maquinastarifasimpresion.php b/ci4/app/Controllers/Configuracion/Maquinastarifasimpresion.php index 35923914..ec16d602 100644 --- a/ci4/app/Controllers/Configuracion/Maquinastarifasimpresion.php +++ b/ci4/app/Controllers/Configuracion/Maquinastarifasimpresion.php @@ -13,14 +13,7 @@ use App\Models\Configuracion\MaquinaModel; use DataTables\Editor, - DataTables\Database, - DataTables\Editor\Field, - DataTables\Editor\Format, - DataTables\Editor\Mjoin, - DataTables\Editor\Options, - DataTables\Editor\Upload, - DataTables\Editor\Validate, - DataTables\Editor\ValidateOptions; + DataTables\Editor\Field; class Maquinastarifasimpresion extends \App\Controllers\GoBaseResourceController { @@ -44,6 +37,13 @@ class Maquinastarifasimpresion extends \App\Controllers\GoBaseResourceController { $this->viewData['pageTitle'] = lang('MaquinasTarifasImpresions.moduleTitle'); $this->viewData['usingSweetAlert'] = true; + + // Se indica que este controlador trabaja con soft_delete + $this->soft_delete = true; + // Se indica el flag para los ficheros borrados + $this->delete_flag = 1; + + parent::initController($request, $response, $logger); } @@ -129,6 +129,7 @@ class Maquinastarifasimpresion extends \App\Controllers\GoBaseResourceController return $this->displayForm(__METHOD__); } // end function add() + public function edit($requestedId = null) { diff --git a/ci4/app/Controllers/Test.php b/ci4/app/Controllers/Test.php index 29368205..26d1a273 100644 --- a/ci4/app/Controllers/Test.php +++ b/ci4/app/Controllers/Test.php @@ -2,7 +2,7 @@ namespace App\Controllers; -use App\Models\Configuracion\PapelGenericoModel; +use App\Models\Configuracion\MaquinasCallesModel; class Test extends BaseController { @@ -15,9 +15,10 @@ class Test extends BaseController public function index() { - $model = new PapelGenericoModel(); + $model = new MaquinasCallesModel(); echo '
';
-        var_dump($model->getGramajeComparador('CARTULINA GRÁFICA ESTUCADA 1/C'));
+        $resourceData = $model->getResource("", 113)->get()->getResultObject();
+        var_dump($resourceData);
         echo '
'; } } diff --git a/ci4/app/Entities/Configuracion/MaquinasCallesEntity.php b/ci4/app/Entities/Configuracion/MaquinasCallesEntity.php new file mode 100644 index 00000000..5bca1d7c --- /dev/null +++ b/ci4/app/Entities/Configuracion/MaquinasCallesEntity.php @@ -0,0 +1,31 @@ + null, + "maquina_id" => null, + "formas_min" => null, + "formas_max" => null, + "internas" => 3.32, + "externas" => 1.66, + "user_created_id" => 0, + "user_updated_id" => 0, + "is_deleted" => 0, + "created_at" => null, + "updated_at" => null, + ]; + protected $casts = [ + "maquina_id" => "int", + "formas_min" => "int", + "formas_max" => "int", + "internas" => "float", + "externas" => "float", + "user_created_id" => "int", + "user_updated_id" => "int", + "is_deleted" => "int", + ]; +} diff --git a/ci4/app/Filters/LoginAuthFilter.php b/ci4/app/Filters/LoginAuthFilter.php index a8cd6ff5..9c187b01 100644 --- a/ci4/app/Filters/LoginAuthFilter.php +++ b/ci4/app/Filters/LoginAuthFilter.php @@ -145,6 +145,7 @@ class LoginAuthFilter implements FilterInterface 'GoBaseResourceController', 'Maquinaspapelesimpresion', 'Maquinastarifasimpresion', + 'Maquinascalles', 'My', 'Usuarios', 'Notification' // PARA LA DEMO ]; diff --git a/ci4/app/Language/en/MaquinasCalles.php b/ci4/app/Language/en/MaquinasCalles.php new file mode 100644 index 00000000..743baada --- /dev/null +++ b/ci4/app/Language/en/MaquinasCalles.php @@ -0,0 +1,43 @@ + 'ID', + 'moduleTitle' => 'Streets config', + 'deleteLine' => 'the selected register', + 'formas_min' => 'Shapes mín.', + 'formas_max' => 'Shapes max.', + 'internas' => 'Internal streets', + 'externas' => 'External streets', + 'validation' => [ + 'error_calle_overlap' => 'The range [Shapes mín, Shapes max] is overlapped with another one.', + 'error_calle_range' => 'The field Shapes min. must be lower than the field Shapes max.', + 'formas_min' => [ + 'integer' => 'Must be a integer number.', + 'required' => 'Required.', + + ], + + 'formas_max' => [ + 'integer' => 'Must be a integer number.', + 'required' => 'Required.', + + ], + + 'internas' => [ + 'decimal' => 'Must be a decimal number.', + 'required' => 'Required.', + + ], + + 'externas' => [ + 'decimal' => 'Must be a decimal number.', + 'required' => 'Required.', + + ], + + ], + + +]; \ No newline at end of file diff --git a/ci4/app/Language/es/MaquinasCalles.php b/ci4/app/Language/es/MaquinasCalles.php new file mode 100644 index 00000000..dbb8c939 --- /dev/null +++ b/ci4/app/Language/es/MaquinasCalles.php @@ -0,0 +1,43 @@ + 'ID', + 'moduleTitle' => 'Configuración Calles', + 'deleteLine' => 'el registro seleccionado', + 'formas_min' => 'Formas mín.', + 'formas_max' => 'Formas max.', + 'internas' => 'Calles internas', + 'externas' => 'Calles externas', + 'validation' => [ + 'error_calle_overlap' => 'El rango [Formas mín, Formas max] se solapa con otro existente para el tipo seleccionado.', + 'error_calle_range' => 'El campo Formas mín. debe ser menor que el campo Formas max.', + 'formas_min' => [ + 'integer' => 'Debe contener un número entero.', + 'required' => 'Requerido.', + + ], + + 'formas_max' => [ + 'integer' => 'Debe contener un número entero.', + 'required' => 'Requerido.', + + ], + + 'internas' => [ + 'decimal' => 'Debe contener un número decimal.', + 'required' => 'Requerido.', + + ], + + 'externas' => [ + 'decimal' => 'Debe contener un número decimal.', + 'required' => 'Requerido.', + + ], + + ], + + +]; \ No newline at end of file diff --git a/ci4/app/Models/Configuracion/MaquinasCallesModel.php b/ci4/app/Models/Configuracion/MaquinasCallesModel.php new file mode 100644 index 00000000..aca7e2d6 --- /dev/null +++ b/ci4/app/Models/Configuracion/MaquinasCallesModel.php @@ -0,0 +1,125 @@ + "t1.formas_min", + 1 => "t1.formas_max", + 2 => "t1.internas", + 3 => "t1.externas", + ]; + + protected $allowedFields = [ + "maquina_id", + "formas_min", + "formas_max", + "internas", + "externas", + "user_created_id", + "user_updated_id", + "is_deleted", + "deleted_at", + "created_at", + "updated_at"]; + protected $returnType = "App\Entities\Configuracion\MaquinasCallesEntity"; + + protected $useTimestamps = true; + protected $useSoftDeletes = false; + + protected $createdField = "created_at"; + + protected $updatedField = "updated_at"; + + public static $labelField = "maquina_id"; + + protected $validationRules = [ + "formas_min" => [ + "rules" => "required|int", + ], + "formas_max" => [ + "rules" => "required|int", + ], + "internas" => [ + "rules" => "required|decimal", + ], + "externas" => [ + "rules" => "required|decimal", + ], + ]; + + + /** + * Get resource data. + * + * @param string $search + * + * @return \CodeIgniter\Database\BaseBuilder + */ + public function getResource(string $search = "", $maquina_id=-1) + { + $builder = $this->db + ->table($this->table . " t1") + ->select( + "t1.id AS id, t1.maquina_id as maquina, t1.formas_min AS formas_min, + t1.formas_max AS formas_max, t1.internas AS internas, t1.externas AS externas," + ); + + //JJO + $builder->where('maquina_id', $maquina_id); + $builder->where("t1.is_deleted", 0); + + return empty($search) + ? $builder + : $builder + ->groupStart() + ->like("t1.formas_min", $search) + ->orLike("t1.formas_max", $search) + ->orLike("t1.internas", $search) + ->orLike("t1.externas", $search) + ->orLike("t1.formas_min", $search) + ->orLike("t1.formas_max", $search) + ->orLike("t1.internas", $search) + ->orLike("t1.externas", $search) + ->groupEnd(); + } + + public function checkIntervals($data = [], $id = null){ + + helper('general'); + + if(floatval($data["formas_min"])>= floatval($data["formas_max"])){ + return lang('MaquinasCalles.validation.error_calle_range'); + } + + + $rows = $this->db + ->table($this->table) + ->select("id, formas_min, formas_max") + ->where("is_deleted", 0) + ->where("maquina_id", $data['maquina_id']) + ->get()->getResultObject(); + + + foreach ($rows as $row) { + if (!is_null($id)){ + if($row->id == $id){ + continue; + } + } + if(check_overlap(floatval($data["formas_min"]), floatval($data["formas_max"]), + $row->formas_min, $row->formas_max)){ + return lang('MaquinasCalles.validation.error_calle_overlap'); + } + } + } +} 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 f6dfb40d..f648b335 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 @@ -63,6 +63,39 @@ + + +
+
+

+ +

+ +
+
+ + + + + + + + + + + + + +
+
+
+
+
+ + +
@@ -110,6 +143,9 @@ endSection() ?> + + + section("additionalInlineJs") ?> const lastColNr2 = $('#tableOfPapelesImpresion').find("tr:first th").length - 1; @@ -223,9 +259,9 @@ const actionBtns = function(data) { return ` - + + - `; }; @@ -432,7 +468,7 @@ editor: editor, formOptions: { submitTrigger: -1, - submitHtml: '' + submitHtml: '', } } ] } ); @@ -520,9 +556,9 @@ editor.inline( theTable.cells(this.parentNode.parentNode, '*').nodes(), { - cancelHtml: '', + cancelHtml: '', cancelTrigger: 'span.cancel', - submitHtml: '', + submitHtml: '', submitTrigger: 'span.edit', submit: 'allIfChanged' } @@ -539,37 +575,199 @@ }); // Delete row - $('#tableOfMaquinastarifasimpresion').on( 'click', 'tbody span.remove', function (e) { + $(document).on('click', '.btn-delete', function(e) { + $(".btn-remove").attr('data-id', $(this).attr('data-id')); + const row = $(this).closest('tr')[0]._DT_RowIndex; - Swal.fire({ - title: '', - text: '', - icon: 'warning', - showCancelButton: true, - confirmButtonColor: '#3085d6', - confirmButtonText: '', - cancelButtonText: '', - cancelButtonColor: '#d33' - }) - .then((result) => { - const dataId = $(this).data('id'); - const row = $(this).closest('tr'); - if (result.value) { - editor - .create( false ) - .edit( this.parentNode, false) - .set( 'deleted_at', new Date().toISOString().slice(0, 19).replace('T', ' ') ) - .set( 'is_deleted', 1 ) - .submit(); - } - }); + if($(this).closest('table').attr('id').includes('tarifas')){ + $(".btn-remove").attr('table', "tarifas"); + $(".btn-remove").attr('row_index', row); + } + else if($(this).closest('table').attr('id').includes('Calles')){ + $(".btn-remove").attr('table', "calles"); + $(".btn-remove").attr('row_index', row); + } + else{ + $(".btn-remove").attr('table', ); + } }); + + $(document).on('click', '.btn-remove', function(e) { + const dataId = $(this).attr('data-id'); + const row = $(this).attr('row_index'); + + if ($.isNumeric(dataId)) { + + if($(this).attr('table').includes('tarifas')){ + remove_tarifas(dataId, row); + } + else if ($(this).attr('table').includes('calles')){ + remove_calles(dataId, row); + } + } + }); + + function remove_calles(dataId, row){ + $.ajax({ + url: `/maquinascalles/delete/${dataId}`, + method: 'GET', + }).done((data, textStatus, jqXHR) => { + $('#confirm2delete').modal('toggle'); + theTable3.clearPipeline(); + theTable3.row($(row)).invalidate().draw(); + popSuccessAlert(data.msg ?? jqXHR.statusText); + }).fail((jqXHR, textStatus, errorThrown) => { + popErrorAlert(jqXHR.responseJSON.messages.error) + }); + }; + + function remove_tarifas(dataId, row){ + + $.ajax({ + url: `/maquinastarifasimpresion/delete/${dataId}`, + method: 'GET', + }).done((data, textStatus, jqXHR) => { + $('#confirm2delete').modal('toggle'); + theTable.clearPipeline(); + theTable.row($(row)).invalidate().draw(); + popSuccessAlert(data.msg ?? jqXHR.statusText); + }).fail((jqXHR, textStatus, errorThrown) => { + popErrorAlert(jqXHR.responseJSON.messages.error) + }); + } + + + +endSection() ?> + + + + + +section("additionalInlineJs") ?> + + var editor3 = new $.fn.dataTable.Editor( { + ajax: { + url: "", + headers: { + : v, + }, + }, + table : "#tableOfCalles", + idSrc: 'id', + fields: [ { + name: "formas_min" + }, { + name: "formas_max" + }, { + name: "internas" + }, { + name: "externas" + }, { + "name": "maquina_id", + "type": "hidden" + },{ + "name": "deleted_at", + "type": "hidden" + },{ + "name": "is_deleted", + "type": "hidden" + }, + ] + } ); + + + editor3.on( 'preSubmit', function ( e, d, type ) { + if ( type === 'create'){ + d.data[0]['maquina_id'] = id; + } + else if(type === 'edit' ) { + for (v in d.data){ + d.data[v]['maquina_id'] = id; + } + } + }); + editor3.on( 'postSubmit', function ( e, json, data, action ) { + + yeniden(json.); + }); + + + editor3.on( 'submitSuccess', function ( e, json, data, action ) { + + theTable3.clearPipeline(); + theTable3.draw(); + }); + + theTable3 = $('#tableOfCalles').DataTable({ + processing: true, + serverSide: true, + autoWidth: true, + responsive: true, + scrollX: true, + lengthMenu: [ 5], + pageLength: 10, + lengthChange: false, + searching: false, + info: false, + "dom": '<"mt-4"><"float-end"B><"float-start"l><"mt-4 mb-3"p>', + stateSave: true, + language: { + url: "//cdn.datatables.net/plug-ins/1.13.4/i18n/i18n ?>.json" + }, + ajax : $.fn.dataTable.pipeline( { + url: '', + data: { + maquina_id: id, + }, + method: 'POST', + headers: {'X-Requested-With': 'XMLHttpRequest'}, + async: true, + }), + columns : [ + { 'data': 'formas_min' }, + { 'data': 'formas_max' }, + { 'data': 'internas' }, + { 'data': 'externas' }, + { data: actionBtns, + className: 'row-edit dt-center'} + ], + buttons: [ { + className: 'btn btn-primary float-end me-sm-3 me-1', + extend: "createInline", + editor: editor3, + formOptions: { + submitTrigger: -1, + submitHtml: '' + } + } ] + }); + + // Activate an inline edit on click of a table cell + $('#tableOfCalles').on( 'click', 'tbody span.edit', function (e) { + editor3.inline( + theTable3.cells(this.parentNode.parentNode, '*').nodes(), + { + cancelHtml: '', + cancelTrigger: 'span.cancel', + submitHtml: '', + submitTrigger: 'span.edit', + submit: 'allIfChanged' + } + ); + } ); + + + + endSection() ?> + + section('css') ?>