diff --git a/ci4/app/Config/Routes.php b/ci4/app/Config/Routes.php index dc4faebe..b30da853 100644 --- a/ci4/app/Config/Routes.php +++ b/ci4/app/Config/Routes.php @@ -378,6 +378,11 @@ $routes->group('tarifaencuadernacionlineas', ['namespace' => 'App\Controllers\Ta }); $routes->resource('tarifaencuadernacionlineas', ['namespace' => 'App\Controllers\Tarifas', 'controller' => 'Tarifaencuadernacionlineas', 'except' => 'show,new,create,update']); +$routes->group('tarifaencuadernaciontiradas', ['namespace' => 'App\Controllers\Tarifas'], function ($routes) { + $routes->post('datatable', 'Tarifaencuadernaciontiradas::datatable', ['as' => 'dataTableOfTarifaEncuadernacionTiradas']); + $routes->post('datatable_editor', 'Tarifaencuadernaciontiradas::datatable_editor', ['as' => 'editorOfTarifaEncuadernacionTiradas']); +}); +$routes->resource('tarifaencuadernaciontiradas', ['namespace' => 'App\Controllers\Tarifas', 'controller' => 'Tarifaencuadernaciontiradas', 'except' => 'show,new,create,update']); $routes->group('proveedores', ['namespace' => 'App\Controllers\Compras'], function ($routes) { $routes->get('', 'Proveedores::index', ['as' => 'proveedorList']); diff --git a/ci4/app/Controllers/Tarifas/Tarifaencuadernacionlineas.php b/ci4/app/Controllers/Tarifas/Tarifaencuadernacionlineas.php index 439a4176..da5d9e93 100644 --- a/ci4/app/Controllers/Tarifas/Tarifaencuadernacionlineas.php +++ b/ci4/app/Controllers/Tarifas/Tarifaencuadernacionlineas.php @@ -322,14 +322,14 @@ class Tarifaencuadernacionlineas extends \App\Controllers\GoBaseResourceControll $order = TarifaEncuadernacionLineaModel::SORTABLE[$requestedOrder >= 0 ? $requestedOrder : 0]; $dir = $reqData['order']['0']['dir'] ?? 'asc'; - $id_TM = $reqData['id_tarifaencuadernacion'] ?? -1; + $id_TE = $reqData['tirada_id'] ?? -1; - $resourceData = $this->model->getResource("", $id_TM)->orderBy($order, $dir)->limit($length, $start)->get()->getResultObject(); + $resourceData = $this->model->getResource("", $id_TE)->orderBy($order, $dir)->limit($length, $start)->get()->getResultObject(); return $this->respond(Collection::datatable( $resourceData, $this->model->getResource()->countAllResults(), - $this->model->getResource($search, $id_TM)->countAllResults() + $this->model->getResource("", $id_TE)->countAllResults() )); } else { return $this->failUnauthorized('Invalid request', 403); diff --git a/ci4/app/Controllers/Tarifas/Tarifaencuadernaciontiradas.php b/ci4/app/Controllers/Tarifas/Tarifaencuadernaciontiradas.php index 4706536f..4d5a0f6e 100644 --- a/ci4/app/Controllers/Tarifas/Tarifaencuadernaciontiradas.php +++ b/ci4/app/Controllers/Tarifas/Tarifaencuadernaciontiradas.php @@ -23,7 +23,9 @@ use class Tarifaencuadernaciontiradas extends \App\Controllers\GoBaseResourceController { - public function datatable_editor() + protected static $controllerSlug = 'tarifaencuadernaciontiradas'; + + public function datatable_editor() { if ($this->request->isAJAX()) { @@ -131,6 +133,7 @@ class Tarifaencuadernaciontiradas extends \App\Controllers\GoBaseResourceControl 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.'; @@ -141,17 +144,19 @@ class Tarifaencuadernaciontiradas extends \App\Controllers\GoBaseResourceControl $length = $reqData['length'] ?? 5; $search = $reqData['search']['value']; $requestedOrder = $reqData['order']['0']['column'] ?? 0; - $order = TarifaEncuadernacionLineaModel::SORTABLE[$requestedOrder >= 0 ? $requestedOrder : 0]; + $order = TarifaEncuadernacionTiradaModel::SORTABLE[$requestedOrder > 0 ? $requestedOrder : 1]; $dir = $reqData['order']['0']['dir'] ?? 'asc'; $id_TM = $reqData['id_tarifaencuadernacion'] ?? -1; - $resourceData = $this->model->getResource("", $id_TM)->orderBy($order, $dir)->limit($length, $start)->get()->getResultObject(); + $model = new TarifaEncuadernacionTiradaModel(); + + $resourceData = $model->getResource("", $id_TM)->orderBy($order, $dir)->limit($length, $start)->get()->getResultObject(); return $this->respond(Collection::datatable( $resourceData, - $this->model->getResource()->countAllResults(), - $this->model->getResource($search, $id_TM)->countAllResults() + $model->getResource()->countAllResults(), + $model->getResource($search, $id_TM)->countAllResults() )); } else { return $this->failUnauthorized('Invalid request', 403); diff --git a/ci4/app/Models/Tarifas/TarifaEncuadernacionTiradaModel.php b/ci4/app/Models/Tarifas/TarifaEncuadernacionTiradaModel.php index c16cd026..59b0b621 100644 --- a/ci4/app/Models/Tarifas/TarifaEncuadernacionTiradaModel.php +++ b/ci4/app/Models/Tarifas/TarifaEncuadernacionTiradaModel.php @@ -1,7 +1,7 @@ section('css') ?> - "> - -*/ ?> - - + diff --git a/ci4/app/Views/themes/backend/vuexy/form/tarifas/encuadernacion/viewTarifaEncuadernacionForm.php b/ci4/app/Views/themes/backend/vuexy/form/tarifas/encuadernacion/viewTarifaEncuadernacionForm.php index 1d65d028..7658efc9 100644 --- a/ci4/app/Views/themes/backend/vuexy/form/tarifas/encuadernacion/viewTarifaEncuadernacionForm.php +++ b/ci4/app/Views/themes/backend/vuexy/form/tarifas/encuadernacion/viewTarifaEncuadernacionForm.php @@ -1,6 +1,7 @@ include("themes/_commonPartialsBs/datatables") ?> include("themes/_commonPartialsBs/select2bs5") ?> include("themes/_commonPartialsBs/sweetalert") ?> +include('themes/_commonPartialsBs/_confirm2delete') ?> extend('themes/backend/vuexy/main/defaultlayout') ?> section("content") ?> @@ -29,84 +30,78 @@ - - - - - + endSection() ?> + + + section("additionalInlineJs") ?> - - const lastColNr = $('#tableOfTarifaencuadernacionlineas').find("tr:first th").length - 1; const url = window.location.href; const url_parts = url.split('/'); + var id = -1; if(url_parts[url_parts.length-2] == 'edit'){ id = url_parts[url_parts.length-1]; } @@ -114,16 +109,30 @@ id = -1; } + const actionBtns = function(data) { return ` - - - - `; + + + + `; }; + var selected_tirada_id = -1; + +endSection() ?> - editor = new $.fn.dataTable.Editor( { + + + + + + +section("additionalInlineJs") ?> + + const lastColNr = $('#tableOfTarifaencuadernacionlineas').find("tr:first th").length - 1; + + var editor = new $.fn.dataTable.Editor( { ajax: { url: "", headers: { @@ -155,6 +164,7 @@ ] } ); + editor.on( 'preSubmit', function ( e, d, type ) { if ( type === 'create'){ d.data[0]['tirada_encuadernacion_id'] = id; @@ -172,14 +182,14 @@ yeniden(json.); }); + editor.on( 'submitSuccess', function ( e, json, data, action ) { theTable.clearPipeline(); theTable.draw(); }); - - var theTable = $('#tableOfTarifaencuadernacionlineas').DataTable( { + var theTable = $('#tableOfTarifaencuadernacionlineas').DataTable( { serverSide: true, processing: true, autoWidth: true, @@ -195,7 +205,7 @@ ajax : $.fn.dataTable.pipeline( { url: '', data: { - id_tarifaencuadernacion: id, + tirada_id: selected_tirada_id, }, method: 'POST', headers: {'X-Requested-With': 'XMLHttpRequest'}, @@ -230,21 +240,20 @@ editor: editor, formOptions: { submitTrigger: -1, - submitHtml: '' + submitHtml: '' } } ] } ); - // Activate an inline edit on click of a table cell $('#tableOfTarifaencuadernacionlineas').on( 'click', 'tbody span.edit', function (e) { editor.inline( theTable.cells(this.parentNode.parentNode, '*').nodes(), { - cancelHtml: '', + cancelHtml: '', cancelTrigger: 'span.cancel', - submitHtml: '', + submitHtml: '', submitTrigger: 'span.edit', submit: 'allIfChanged' } @@ -253,6 +262,36 @@ // Delete row + $(document).on('click', '.btn-delete', function(e) { + $(".btn-remove").attr('data-id', $(this).attr('data-id')); + }); + + $(document).on('click', '.btn-remove', function(e) { + const dataId = $(this).attr('data-id'); + const row = $(this).closest('tr'); + if ($.isNumeric(dataId)) { + /*$.ajax({ + url: `/configuracion/papelimpresiontipologias/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) + })*/ + console.log(this.parentNode); + /*editor + .create( false ) + .edit( this.parentNode, false) + .set( 'deleted_at', new Date().toISOString().slice(0, 19).replace('T', ' ') ) + .set( 'is_deleted', 1 ) + .submit();*/ + } + }); + + /* $('#tableOfTarifaencuadernacionlineas').on( 'click', 'tbody span.remove', function (e) { Swal.fire({ @@ -278,10 +317,192 @@ } }); - }); + });*/ + + endSection() ?> + + + +section("additionalInlineJs") ?> + + const lastColNr2 = $('#tableOfTarifaencuadernaciontiradas').find("tr:first th").length - 1; + + var editor2 = new $.fn.dataTable.Editor( { + ajax: { + url: "", + headers: { + : v, + }, + }, + table : "#tableOfTarifaencuadernaciontiradas", + idSrc: 'id', + fields: [ { + name: "proveedor" + }, { + name: "tirada_min" + }, { + name: "tirada_max" + }, { + "name": "tarifa_encuadernacion_id", + "type": "hidden" + },{ + "name": "deleted_at", + "type": "hidden" + },{ + "name": "is_deleted", + "type": "hidden" + }, + ] + } ); + + + editor2.on( 'preSubmit', function ( e, d, type ) { + if ( type === 'create'){ + d.data[0]['tarifa_encuadernacion_id'] = id; + } + else if(type === 'edit' ) { + for (v in d.data){ + d.data[v]['tarifa_encuadernacion_id'] = id; + } + } + }); + + + editor2.on( 'postSubmit', function ( e, json, data, action ) { + + yeniden(json.); + }); + + + editor2.on( 'submitSuccess', function ( e, json, data, action ) { + + theTable.clearPipeline(); + theTable.draw(); + }); + + var theTable2 = $('#tableOfTarifaencuadernaciontiradas').DataTable( { + serverSide: true, + processing: true, + autoWidth: true, + responsive: true, + lengthMenu: [ 5, 10, 25], + order: [ 0, "asc" ], + pageLength: 10, + lengthChange: true, + searching: false, + paging: true, + info: false, + dom: '<"mt-4"><"float-end"B><"float-start"l><"mt-4 mb-3"p>', + ajax : $.fn.dataTable.pipeline( { + url: '', + data: { + id_tarifaencuadernacion: id, + }, + method: 'POST', + headers: {'X-Requested-With': 'XMLHttpRequest'}, + async: true, + }), + columns: [ + { + className: 'dt-body-center' + }, + { 'data': 'proveedor' }, + { 'data': 'tirada_min' }, + { 'data': 'tirada_max' }, + { + data: actionBtns, + className: 'row-edit dt-center' + } + ], + columnDefs: [ + { + orderable: false, + searchable: false, + targets: [lastColNr2] + }, + { + orderable: false, + className: 'select-checkbox', + targets: 0 + } + //], + + // {"orderData": [ 0, 1 ], "targets": 0 }, + + ], + language: { + url: "//cdn.datatables.net/plug-ins/1.13.4/i18n/i18n ?>.json" + }, + buttons: [ { + className: 'btn btn-primary float-end me-sm-3 me-1', + extend: "createInline", + editor: editor2, + formOptions: { + submitTrigger: -1, + submitHtml: '' + } + } ], + select: { + style: 'single', + selector: 'td:first-child' + } + } ); + + + // Activate an inline edit on click of a table cell + $('#tableOfTarifaencuadernaciontiradas').on( 'click', 'tbody span.edit', function (e) { + editor.inline( + theTable.cells(this.parentNode.parentNode, '*').nodes(), + { + cancelHtml: '', + cancelTrigger: 'span.cancel', + submitHtml: '', + submitTrigger: 'span.edit', + submit: 'allIfChanged' + } + ); + } ); + + + // Delete row + + /* + $('#tableOfTarifaencuadernacionlineas').on( 'click', 'tbody span.remove', function (e) { + + 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(); + + } + }); + });*/ + + +endSection() ?> + + + section('css') ?> + endSection() ?> @@ -289,6 +510,7 @@ section('additionalExternalJs') ?> +