diff --git a/ci4/app/Config/Routes.php b/ci4/app/Config/Routes.php index 14aa7581..6f8aa601 100644 --- a/ci4/app/Config/Routes.php +++ b/ci4/app/Config/Routes.php @@ -276,6 +276,7 @@ $routes->group('papelesimpresion', ['namespace' => 'App\Controllers\Configuracio $routes->post('datatable', 'Papelesimpresion::datatable', ['as' => 'dataTableOfPapelesImpresion']); $routes->post('allmenuitems', 'Papelesimpresion::allItemsSelect', ['as' => 'select2ItemsOfPapelesImpresion']); $routes->post('menuitems', 'Papelesimpresion::menuItems', ['as' => 'menuItemsOfPapelesImpresion']); + $routes->post('duplicate/(:num)','Papelesimpresion::duplicate/$1',['as' => 'duplicatePapelImpresion']); }); $routes->resource('papelesimpresion', ['namespace' => 'App\Controllers\Configuracion', 'controller' => 'Papelesimpresion', 'except' => 'show,new,create,update']); diff --git a/ci4/app/Config/Services.php b/ci4/app/Config/Services.php index 3f76f76e..df2d881e 100755 --- a/ci4/app/Config/Services.php +++ b/ci4/app/Config/Services.php @@ -3,6 +3,7 @@ namespace Config; use App\Services\FTPService; +use App\Services\PapelImpresionService; use CodeIgniter\Config\BaseService; use App\Services\ProductionService; use App\Services\TarifaMaquinaService; @@ -38,4 +39,8 @@ class Services extends BaseService public static function tarifa_maquina(){ return new TarifaMaquinaService(); } + public static function papel_impresion() + { + return new PapelImpresionService(); + } } diff --git a/ci4/app/Config/Validation.php b/ci4/app/Config/Validation.php index d07aade1..c097a621 100755 --- a/ci4/app/Config/Validation.php +++ b/ci4/app/Config/Validation.php @@ -43,6 +43,14 @@ class Validation extends BaseConfig // Rules // -------------------------------------------------------------------- + /** + * PapelImpresion duplicate validation + * + * @var array + */ + public array $papel_impresion_duplicate = [ + "name" => "required|string" + ]; /**======================================================================== * TARIFA MAQUINA ACABADO *========================================================================**/ diff --git a/ci4/app/Controllers/Configuracion/Papelesimpresion.php b/ci4/app/Controllers/Configuracion/Papelesimpresion.php index fb3a0363..e5beef97 100755 --- a/ci4/app/Controllers/Configuracion/Papelesimpresion.php +++ b/ci4/app/Controllers/Configuracion/Papelesimpresion.php @@ -22,6 +22,7 @@ use use App\Models\Collection; +use CodeIgniter\Validation\Validation; @@ -35,7 +36,6 @@ use App\Models\Configuracion\PapelImpresionTipologiaModel; use App\Models\Configuracion\MaquinasPapelesImpresionModel; use App\Models\Configuracion\MaquinaModel; - class Papelesimpresion extends \App\Controllers\BaseResourceController { @@ -52,6 +52,7 @@ class Papelesimpresion extends \App\Controllers\BaseResourceController protected static $viewPath = 'themes/vuexy/form/configuracion/papel/'; protected $indexRoute = 'papelImpresionList'; + protected Validation $validation; public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger) { @@ -66,6 +67,7 @@ class Papelesimpresion extends \App\Controllers\BaseResourceController $this->delete_flag = 1; $this->tpModel = new PapelImpresionTipologiaModel(); + $this->validation = service("validation"); // Breadcrumbs $this->viewData['breadcrumb'] = [ @@ -443,4 +445,27 @@ class Papelesimpresion extends \App\Controllers\BaseResourceController $ma_pa_model->updateRows($active_values); } } + /** + * Duplica el papel impresion y sus relaciones + * + * @param int $papel_impresion_id + * @return Response + */ + public function duplicate( int $papel_impresion_id) + { + $bodyData = $this->request->getPost(); + $validated = $this->validation->run($bodyData, "papel_impresion_duplicate"); + if($validated){ + $papelImpresionEntity = $this->model->find($papel_impresion_id); + $papelImpresionService = service('papel_impresion'); + $duplicated = $papelImpresionService + ->setPapelImpresionEntity($papelImpresionEntity) + ->duplicate($bodyData["name"]); + return $this->response->setJSON(["data" => $duplicated]); + + }else{ + return $this->response->setJSON(["errors" => $this->validation->getErrors()])->setStatusCode(400); + } + + } } diff --git a/ci4/app/Entities/Configuracion/PapelImpresion.php b/ci4/app/Entities/Configuracion/PapelImpresion.php index 4d79a06e..9aaa4a2f 100755 --- a/ci4/app/Entities/Configuracion/PapelImpresion.php +++ b/ci4/app/Entities/Configuracion/PapelImpresion.php @@ -1,6 +1,9 @@ "boolean", "is_deleted" => "int", ]; + + public function tipologia() : ?PapelImpresionTipologia + { + $m = model(PapelImpresionTipologiaModel::class); + return $m->where('papel_impresion_id',$this->attributes["id"])->first(); + } + public function maquinas_impresion() : ?MaquinasPapelesImpresionEntity + { + $m = model(MaquinasPapelesImpresionModel::class); + return $m->where('papel_impresion_id',$this->attributes["id"])->first(); + } + public function margen() : ?PapelImpresionMargen + { + $m = model(PapelImpresionMargenModel::class); + return $m->where('papel_impresion_id',$this->attributes["id"])->first(); + } } diff --git a/ci4/app/Language/es/Basic.php b/ci4/app/Language/es/Basic.php index bb333f54..be74f2d1 100755 --- a/ci4/app/Language/es/Basic.php +++ b/ci4/app/Language/es/Basic.php @@ -28,6 +28,8 @@ return [ 'Profile' => 'Perfil', 'Roles' => 'Roles', 'Save' => 'Guardar', + 'Copy' => 'Copiar', + 'Duplicate' => 'Duplicar', 'Sections' => 'Secciones', 'SignOut' => 'Desconectar', 'Success' => 'Éxito', diff --git a/ci4/app/Language/es/PapelImpresion.php b/ci4/app/Language/es/PapelImpresion.php index 939442db..0b2f919c 100755 --- a/ci4/app/Language/es/PapelImpresion.php +++ b/ci4/app/Language/es/PapelImpresion.php @@ -39,6 +39,7 @@ return [ 'activo' => 'Activo?', 'useInClient' => 'Usar en presup. cliente', 'userUpdateId' => 'ID usuario actualización', + 'namePlaceholderDuplicated' => 'Inserte el nombre del papel que se va a duplicar', 'consumo_tintas_rotativas' => 'Consumo tintas', 'maquinas_papel' => 'Máquinas seleccionadas', diff --git a/ci4/app/Services/PapelImpresionService.php b/ci4/app/Services/PapelImpresionService.php new file mode 100644 index 00000000..b476f511 --- /dev/null +++ b/ci4/app/Services/PapelImpresionService.php @@ -0,0 +1,66 @@ +papelImpresionModel = model(PapelImpresionModel::class); + $this->papelImpresionModel = model(PapelImpresionModel::class); + $this->papelImpresionMargenModel = model(PapelImpresionMargenModel::class); + $this->papelImpresionTipologiaModel = model(PapelImpresionTipologiaModel::class); + $this->papelImpresionMaquinaModel = model(MaquinasPapelesImpresionModel::class); + } + public function setPapelImpresionEntity(PapelImpresion $papelImpresionEntity) : self + { + $this->papelImpresion = $papelImpresionEntity; + return $this; + } + public function duplicate(string $newName) : PapelImpresion + { + $papelImpresionRow = $this->papelImpresion?->toArray(); + $papelImpresionMargen = $this->papelImpresion->margen()?->toArray(); + $papelImpresionTipologia = $this->papelImpresion->tipologia()?->toArray(); + $papelImpresionMaquina = $this->papelImpresion->maquinas_impresion()?->toArray(); + + $papelImpresionRow['nombre'] = $newName; + if($this->papelImpresion){ + $papelImpresionDuplicatedId = $this->papelImpresionModel->insert($papelImpresionRow); + } + if($papelImpresionMargen){ + $papelImpresionMargen['papel_impresion_id'] = $papelImpresionDuplicatedId; + $this->papelImpresionMargenModel->insert($papelImpresionMargen); + } + if($papelImpresionTipologia){ + $this->papelImpresionTipologiaModel->insert($papelImpresionTipologia); + $papelImpresionTipologia['papel_impresion_id'] = $papelImpresionDuplicatedId; + } + if($papelImpresionMaquina){ + $papelImpresionMaquina['papel_impresion_id'] = $papelImpresionDuplicatedId; + $this->papelImpresionMaquinaModel->insert($papelImpresionMaquina); + } + $papelImpresionDuplicated = $this->papelImpresionModel->find($papelImpresionDuplicatedId); + return $papelImpresionDuplicated; + + } +} \ No newline at end of file diff --git a/ci4/app/Views/themes/vuexy/form/configuracion/papel/viewPapelImpresionForm.php b/ci4/app/Views/themes/vuexy/form/configuracion/papel/viewPapelImpresionForm.php index 77ddfcd7..074deae0 100644 --- a/ci4/app/Views/themes/vuexy/form/configuracion/papel/viewPapelImpresionForm.php +++ b/ci4/app/Views/themes/vuexy/form/configuracion/papel/viewPapelImpresionForm.php @@ -6,28 +6,28 @@ section("content") ?>
-
-
-

-
-
- - - getErrors()) ? $validation->listErrors("bootstrap_style") : "" ?> - +
+
+

+
+ + + + getErrors()) ? $validation->listErrors("bootstrap_style") : "" ?> +
" - /> - "btn btn-secondary"]) ?> + class="btn btn-primary float-start me-sm-3 me-1" + name="save" + value="" /> + + "btn btn-secondary"]) ?>
- +
- +

@@ -38,7 +38,7 @@
- + @@ -49,18 +49,18 @@ - + -
+

- rotativa == true || $papelImpresion->inkjet == true)): ?> + rotativa == true || $papelImpresion->inkjet == true)): ?>
- +

- - + +
- -
-

- -

-
-
- - - - - - - - - - - - - - - -
+ +
+

+ +

+
+
+ + + + + + + + + + + + + + + +
+
+
+
+ +
+ - -
-
+
-endSection() ?> + endSection() ?> - - - -section("additionalInlineJs") ?> + section('additionalExternalJs') ?> + + endSection() ?> + + + + section("additionalInlineJs") ?> var theTable; @@ -150,134 +177,134 @@ const url_parts = url.split('/'); let id = -1; if(url_parts[url_parts.length-2] == 'edit'){ - id = url_parts[url_parts.length-1]; + id = url_parts[url_parts.length-1]; } $('#papelGenericoId').select2({ - - allowClear: false, - ajax: { - url: '', - type: 'post', - dataType: 'json', - data: function (params) { - return { - id: 'id', - text: 'nombre', - searchTerm: params.term, - : v - }; - }, - delay: 60, - processResults: function (response) { + allowClear: false, + ajax: { + url: '', + type: 'post', + dataType: 'json', - yeniden(response.); + data: function (params) { + return { + id: 'id', + text: 'nombre', + searchTerm: params.term, + : v + }; + }, + delay: 60, + processResults: function (response) { - return { - results: response.menu - }; - }, + yeniden(response.); - cache: true - } + return { + results: response.menu + }; + }, + + cache: true + } }); // Delete row $(document).on('click', '.btn-delete', function(e) { - $(".btn-remove").attr('data-id', $(this).attr('data-id')); - if($(this).closest('table').attr('id').includes('margenes')){ - $(".btn-remove").attr('table', "margenes"); - } - else if($(this).closest('table').attr('id').includes('tipologias')){ - $(".btn-remove").attr('table', "tipologias"); - } - else{ - $(".btn-remove").attr('table', ); - } + $(".btn-remove").attr('data-id', $(this).attr('data-id')); + if($(this).closest('table').attr('id').includes('margenes')){ + $(".btn-remove").attr('table', "margenes"); + } + else if($(this).closest('table').attr('id').includes('tipologias')){ + $(".btn-remove").attr('table', "tipologias"); + } + else{ + $(".btn-remove").attr('table', ); + } }); - + $(document).on('click', '.btn-remove', function(e) { - const dataId = $(this).attr('data-id'); - const row = $(this).closest('tr'); - if ($.isNumeric(dataId)) { + const dataId = $(this).attr('data-id'); + const row = $(this).closest('tr'); + if ($.isNumeric(dataId)) { - if($(this).attr('table').includes('margenes')){ - remove_margenes(dataId, row); - } - else if ($(this).attr('table').includes('tipologias')){ - remove_tipologias(dataId, row); - } - } + if($(this).attr('table').includes('margenes')){ + remove_margenes(dataId, row); + } + else if ($(this).attr('table').includes('tipologias')){ + remove_tipologias(dataId, row); + } + } }); -endSection() ?> + endSection() ?> - + - - - -section("additionalInlineJs") ?> + + + + section("additionalInlineJs") ?> - var theTable3; - const lastColNr3 = $('#tableOfPapelimpresionmargenes').find("tr:first th").length - 1; - const actionBtns3 = function(data) { + var theTable3; + const lastColNr3 = $('#tableOfPapelimpresionmargenes').find("tr:first th").length - 1; + const actionBtns3 = function(data) { return ` - - - - `; - }; + + + + `; + }; - - // Definición del editor - var editor3 = new $.fn.dataTable.Editor( { + + // Definición del editor + var editor3 = new $.fn.dataTable.Editor( { ajax: { - url: "", - headers: { - : v, - }, + url: "", + headers: { + : v, + }, + }, + table : "#tableOfPapelimpresionmargenes", + idSrc: 'id', + fields: [ + { + name: "paginas_min", + attr: { + type: "number" + } + },{ + name: "paginas_max", + attr: { + type: "number" + } + },{ + name: "margen", + attr: { + type: "number" + } + }, { + "name": "papel_impresion_id", + "type": "hidden" + }, { + "name": "deleted_at", + "type": "hidden" + }, { + "name": "is_deleted", + "type": "hidden" }, - table : "#tableOfPapelimpresionmargenes", - idSrc: 'id', - fields: [ - { - name: "paginas_min", - attr: { - type: "number" - } - },{ - name: "paginas_max", - attr: { - type: "number" - } - },{ - name: "margen", - attr: { - type: "number" - } - }, { - "name": "papel_impresion_id", - "type": "hidden" - }, { - "name": "deleted_at", - "type": "hidden" - }, { - "name": "is_deleted", - "type": "hidden" - }, ] - } ); + } ); - // Definición de la tabla - theTable3 = $('#tableOfPapelimpresionmargenes').DataTable({ + // Definición de la tabla + theTable3 = $('#tableOfPapelimpresionmargenes').DataTable({ processing: true, serverSide: true, autoWidth: true, @@ -288,504 +315,508 @@ lengthChange: false, searching: false, info: false, - "dom": '<"mt-4"><"float-end"B><"float-start"l><"mt-4 mb-3"p>', - stateSave: true, - language: { - url: "/themes/vuexy/vendor/libs/datatables-sk/plugins/i18n/es-ES.json" - }, - ajax : $.fn.dataTable.pipeline( { - url: '', - data: { - id_PI: id, - }, - method: 'POST', - headers: {'X-Requested-With': 'XMLHttpRequest'}, - async: true, - }), - columns : [ - { 'data': 'paginas_min' }, - { 'data': 'paginas_max' }, - { 'data': 'margen' }, - { data: actionBtns3, - className: 'row-edit dt-center'} - ], - columnDefs: [ - { - orderable: false, - searchable: false, - targets: [lastColNr3] - } - ], - 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 - $(document).on('click', '.btn-edit3', function(e) { - editor3.inline( - theTable3.cells(this.parentNode.parentNode.parentNode, '*').nodes(), - { - cancelHtml: '', - cancelTrigger: 'span.cancel', - submitHtml: '', - submitTrigger: 'span.edit', - submit: 'allIfChanged' - } - ); - } ); - - - // Obtención del id para editar - editor3.on( 'preSubmit', function ( e, d, type ) { - if ( type === 'create'){ - d.data[0]['papel_impresion_id'] = id; - } - else if(type === 'edit' ) { - for (v in d.data){ - d.data[v]['papel_impresion_id'] = id; - } - } - }); - - // Refrescar token - editor3.on( 'postSubmit', function ( e, json, data, action ) { - - yeniden(json.); - }); - - // Refrescar tabla - editor3.on( 'submitSuccess', function ( e, json, data, action ) { - - theTable3.clearPipeline(); - theTable3.draw(); - }); - - - // Delete row - function remove_margenes(dataId, row){ - - $.ajax({ - url: `/configuracion/papelimpresionmargenes/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) - }); - } - - -endSection() ?> - - - - -section("additionalInlineJs") ?> - - var theTable; - const lastColNr = $('#tableOfPapelimpresiontipologias').find("tr:first th").length - 1; - const actionBtns = function(data) { - return ` - - - - `; - }; - - $('#cubierta').on('change', function() { - if($(this).is(':checked')) { - $('#useForTapaDura').prop('disabled', false); - $('#useForTapaDura').prop('checked', false); - } - else{ - $('#useForTapaDura').prop('disabled', true); - } - }); - - - // Etiquetas para las tipologias - const tipoTypes = [ - {label:'', value:'negro'}, - {label:'', value: 'color'}, - {label:'', value: 'bicolor'} - ]; - - - // Definición del editor - editor = new $.fn.dataTable.Editor( { - ajax: { - url: "", - headers: { - : v, - }, - }, - table : "#tableOfPapelimpresiontipologias", - idSrc: 'id', - fields: [ - { - name: "tipo", - type: "select", - options: tipoTypes - }, { - name: "negro", - attr: { - type: "number" - } - },{ - name: "cyan", - attr: { - type: "number" - } - },{ - name: "magenta", - attr: { - type: "number" - } - },{ - name: "amarillo", - attr: { - type: "number" - } - },{ - name: "cg", - attr: { - type: "number" - }, - def: 0, - }, - { - name: "gota_negro", - attr: { - type: "number" - } - },{ - name: "gota_color", - attr: { - type: "number" - } - }, { - "name": "papel_impresion_id", - "type": "hidden" - } - ] - } ); - - - // Definición de la tabla - theTable = $('#tableOfPapelimpresiontipologias').DataTable({ - processing: true, - serverSide: true, - autoWidth: true, - responsive: true, - scrollX: true, - lengthMenu: [ 5], - pageLength: 5, - lengthChange: false, - searching: false, - info: false, - "dom": '<"mt-4"><"float-end"B><"float-start"l><"mt-4 mb-3"p>', - stateSave: true, - language: { - url: "/themes/vuexy/vendor/libs/datatables-sk/plugins/i18n/es-ES.json" - }, - ajax : $.fn.dataTable.pipeline( { - url: '', - data: { - id_PI: id, - }, - method: 'POST', - headers: {'X-Requested-With': 'XMLHttpRequest'}, - async: true, - }), - columns : [ - { 'data': 'tipo', "render": function ( data, type, row, meta ) { - if(data=='negro') - return ''; - else if (data=='color') - return ''; - else if (data=='bicolor') - return ''; - } - }, - { 'data': 'negro' }, - { 'data': 'cyan' }, - { 'data': 'magenta' }, - { 'data': 'amarillo' }, - { 'data': 'cg' }, - { 'data': 'gota_negro' }, - { 'data': 'gota_color' }, - { data: actionBtns, - className: 'row-edit dt-center'} - ], - columnDefs: [ - { - visible: false, - targets: [5] - } - ], - buttons: [ { - className: 'btn btn-primary float-end me-sm-3 me-1', - extend: "createInline", - editor: editor, - formOptions: { - submitTrigger: -1, - submitHtml: '' - } - } ], - initComplete: function () { - inkjet) { ?> - theTable.column(5).visible(true) - - } - }); - - - // Notificar que no se pueden añadir más tipologías - editor.on( 'initCreate', function () { - if ( $('#tableOfPapelimpresiontipologias').DataTable().data().count() >= 3 ){ - editor.close(); - popErrorAlert(''); - } - }); - - - // Activate an inline edit on click of a table cell - $(document).on('click', '.btn-edit', function(e) { - editor.inline( - theTable.cells(this.parentNode.parentNode.parentNode, '*').nodes(), - { - cancelHtml: '', - cancelTrigger: 'span.cancel', - submitHtml: '', - submitTrigger: 'span.edit', - submit: 'allIfChanged' - } - ); - } ); - - - // Obtención del id para editar - editor.on( 'preSubmit', function ( e, d, type ) { - if ( type === 'create'){ - d.data[0]['papel_impresion_id'] = id; - } - else if(type === 'edit' ) { - for (v in d.data){ - d.data[v]['papel_impresion_id'] = id; - } - } - }); - - // Refrescar token - editor.on( 'postSubmit', function ( e, json, data, action ) { - - yeniden(json.); - }); - - // Refrescar tabla - editor.on( 'submitSuccess', function ( e, json, data, action ) { - - theTable.clearPipeline(); - theTable.draw(); - }); - - - // Delete row - function remove_tipologias(dataId, row){ - - $.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) - }); - } - -endSection() ?> - - - - - -section("additionalInlineJs") ?> - - // Botones última columna - const lastColNr2 = $('#tableOfMaquinas').find("tr:first th").length - 1; - const actionBtns2 = function(data) { - return ` - - `; - }; - - - // Definicion de la tabla - var theTable2 = $('#tableOfMaquinas').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: true, dom: "lftp", - ajax : $.fn.dataTable.pipeline( { - url: '', - data: function (d) { - d.papel_id = id; - d.isRotativa = $('#rotativa').is(':checked')?1:0; - d.webguard_token = ''; - }, - method: 'POST', - headers: {'X-Requested-With': 'XMLHttpRequest'}, - async: true, - }), - columns: [ - { 'data': 'active', - render: function (data, type, row) { - if (type === 'display') { - return ''; - } - return data; - }, - className: 'dt-body-center' - }, - { 'data': 'maquina'}, - { 'data': 'ancho'}, - { 'data': 'alto'}, - { 'data': 'anchoimpresion'}, - { 'data': 'altoimpresion'}, - { data: actionBtns2, - className: 'row-edit dt-center'} - ], - columnDefs: [ - { - orderable: false, - searchable: false, - targets: [lastColNr2] - } - ], - rowCallback: function (row, data) { - // Set the checked state of the checkbox in the table - $('input.editor-active', row).prop('checked', data.active == 1); - }, - language: { - url: "/themes/vuexy/vendor/libs/datatables-sk/plugins/i18n/es-ES.json" - }, - columnDefs: [ - { - searchable: false, - targets: [0,2,3,4,5] - } - ], - } ); - - - // Definición del editor - editor2 = new $.fn.dataTable.Editor( { - ajax: { - url: "", - headers: { - : v, - }, - }, - table : "#tableOfMaquinas", - idSrc: 'papel_impresion_id', - fields: [ - { - name: "active", - type: "checkbox", - separator: "|", - ipOpts: [ - { label: '', value: 1 } - ] - },{ - "name": "papel_impresion_id", - "type": "hidden" - },{ - "name": "gramaje", - "type": "hidden" - },{ - "name": "maquina_id", - "type": "hidden" - } - ] - } ); - // Postsubmit del editor - editor2.on( 'postSubmit', function ( e, json, data, action ) { - yeniden(json.); - if(json.error){ - document.getElementById("check_" + json.data.papel_impresion_id).checked = false; - popErrorAlert(json.error); - } - }); + stateSave: true, + language: { + url: "/themes/vuexy/vendor/libs/datatables-sk/plugins/i18n/es-ES.json" + }, + ajax : $.fn.dataTable.pipeline( { + url: '', + data: { + id_PI: id, + }, + method: 'POST', + headers: {'X-Requested-With': 'XMLHttpRequest'}, + async: true, + }), + columns : [ + { 'data': 'paginas_min' }, + { 'data': 'paginas_max' }, + { 'data': 'margen' }, + { data: actionBtns3, + className: 'row-edit dt-center'} + ], + columnDefs: [ + { + orderable: false, + searchable: false, + targets: [lastColNr3] + } + ], + buttons: [ { + className: 'btn btn-primary float-end me-sm-3 me-1', + extend: "createInline", + editor: editor3, + formOptions: { + submitTrigger: -1, + submitHtml: '' + } + } ] + }); - // Click sobre el botón editar máquina - $(document).on('click', '.btn-edit2', function(e) { - window.open(`/configuracion/maquinas/edit/${$(this).attr('data-id')}`); - }); + // Activate an inline edit on click of a table cell + $(document).on('click', '.btn-edit3', function(e) { + editor3.inline( + theTable3.cells(this.parentNode.parentNode.parentNode, '*').nodes(), + { + cancelHtml: '', + cancelTrigger: 'span.cancel', + submitHtml: '', + submitTrigger: 'span.edit', + submit: 'allIfChanged' + } + ); + } ); - // Cuando se clica en un checkbox hacer submit en el editor - theTable2.on( 'change', 'input.editor-active', function () { - editor2 - .edit( $(this).closest('tr'), false ) - .set( 'active', $(this).prop( 'checked' ) ? 1 : 0 ) - .submit(); - } ); + // Obtención del id para editar + editor3.on( 'preSubmit', function ( e, d, type ) { + if ( type === 'create'){ + d.data[0]['papel_impresion_id'] = id; + } + else if(type === 'edit' ) { + for (v in d.data){ + d.data[v]['papel_impresion_id'] = id; + } + } + }); - $('#rotativa').on('change', function() { - if($('#inkjet').prop('checked')){ - $('#inkjet').prop('checked', false) - } - }) + // Refrescar token + editor3.on( 'postSubmit', function ( e, json, data, action ) { - $('#inkjet').on('change', function() { - if($('#rotativa').prop('checked')){ - $('#rotativa').prop('checked', false) - } - }) + yeniden(json.); + }); - endSection() ?> + // Refrescar tabla + editor3.on( 'submitSuccess', function ( e, json, data, action ) { - + theTable3.clearPipeline(); + theTable3.draw(); + }); -section('css') ?> - - "> -endSection() ?> + // Delete row + function remove_margenes(dataId, row){ -section('additionalExternalJs') ?> - - - - - - - - -endSection() ?> + $.ajax({ + url: `/configuracion/papelimpresionmargenes/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) + }); + } + + endSection() ?> + + + + + section("additionalInlineJs") ?> + + var theTable; + const lastColNr = $('#tableOfPapelimpresiontipologias').find("tr:first th").length - 1; + const actionBtns = function(data) { + return ` + + + + `; + }; + + $('#cubierta').on('change', function() { + if($(this).is(':checked')) { + $('#useForTapaDura').prop('disabled', false); + $('#useForTapaDura').prop('checked', false); + } + else{ + $('#useForTapaDura').prop('disabled', true); + } + }); + + + // Etiquetas para las tipologias + const tipoTypes = [ + {label:'', value:'negro'}, + {label:'', value: 'color'}, + {label:'', value: 'bicolor'} + ]; + + + // Definición del editor + editor = new $.fn.dataTable.Editor( { + ajax: { + url: "", + headers: { + : v, + }, + }, + table : "#tableOfPapelimpresiontipologias", + idSrc: 'id', + fields: [ + { + name: "tipo", + type: "select", + options: tipoTypes + }, { + name: "negro", + attr: { + type: "number" + } + },{ + name: "cyan", + attr: { + type: "number" + } + },{ + name: "magenta", + attr: { + type: "number" + } + },{ + name: "amarillo", + attr: { + type: "number" + } + },{ + name: "cg", + attr: { + type: "number" + }, + def: 0, + }, + { + name: "gota_negro", + attr: { + type: "number" + } + },{ + name: "gota_color", + attr: { + type: "number" + } + }, { + "name": "papel_impresion_id", + "type": "hidden" + } + ] + } ); + + + // Definición de la tabla + theTable = $('#tableOfPapelimpresiontipologias').DataTable({ + processing: true, + serverSide: true, + autoWidth: true, + responsive: true, + scrollX: true, + lengthMenu: [ 5], + pageLength: 5, + lengthChange: false, + searching: false, + info: false, + dom: "lftp", + + + stateSave: true, + language: { + url: "/themes/vuexy/vendor/libs/datatables-sk/plugins/i18n/es-ES.json" + }, + ajax : $.fn.dataTable.pipeline( { + url: '', + data: { + id_PI: id, + }, + method: 'POST', + headers: {'X-Requested-With': 'XMLHttpRequest'}, + async: true, + }), + columns : [ + { 'data': 'tipo', "render": function ( data, type, row, meta ) { + if(data=='negro') + return ''; + else if (data=='color') + return ''; + else if (data=='bicolor') + return ''; + } + }, + { 'data': 'negro' }, + { 'data': 'cyan' }, + { 'data': 'magenta' }, + { 'data': 'amarillo' }, + { 'data': 'cg' }, + { 'data': 'gota_negro' }, + { 'data': 'gota_color' }, + { data: actionBtns, + className: 'row-edit dt-center'} + ], + columnDefs: [ + { + visible: false, + targets: [5] + } + ], + buttons: [ { + className: 'btn btn-primary float-end me-sm-3 me-1', + extend: "createInline", + editor: editor, + formOptions: { + submitTrigger: -1, + submitHtml: '' + } + } ], + initComplete: function () { + inkjet) { ?> + theTable.column(5).visible(true) + + } + }); + + + // Notificar que no se pueden añadir más tipologías + editor.on( 'initCreate', function () { + if ( $('#tableOfPapelimpresiontipologias').DataTable().data().count() >= 3 ){ + editor.close(); + popErrorAlert(''); + } + }); + + + // Activate an inline edit on click of a table cell + $(document).on('click', '.btn-edit', function(e) { + editor.inline( + theTable.cells(this.parentNode.parentNode.parentNode, '*').nodes(), + { + cancelHtml: '', + cancelTrigger: 'span.cancel', + submitHtml: '', + submitTrigger: 'span.edit', + submit: 'allIfChanged' + } + ); + } ); + + + // Obtención del id para editar + editor.on( 'preSubmit', function ( e, d, type ) { + if ( type === 'create'){ + d.data[0]['papel_impresion_id'] = id; + } + else if(type === 'edit' ) { + for (v in d.data){ + d.data[v]['papel_impresion_id'] = id; + } + } + }); + + // Refrescar token + editor.on( 'postSubmit', function ( e, json, data, action ) { + + yeniden(json.); + }); + + // Refrescar tabla + editor.on( 'submitSuccess', function ( e, json, data, action ) { + + theTable.clearPipeline(); + theTable.draw(); + }); + + + // Delete row + function remove_tipologias(dataId, row){ + + $.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) + }); + } + + endSection() ?> + + + + + + section("additionalInlineJs") ?> + + // Botones última columna + const lastColNr2 = $('#tableOfMaquinas').find("tr:first th").length - 1; + const actionBtns2 = function(data) { + return ` + + `; + }; + + + // Definicion de la tabla + var theTable2 = $('#tableOfMaquinas').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: true, + dom: "lftp", + ajax : $.fn.dataTable.pipeline( { + url: '', + data: function (d) { + d.papel_id = id; + d.isRotativa = $('#rotativa').is(':checked')?1:0; + d.webguard_token = ''; + }, + method: 'POST', + headers: {'X-Requested-With': 'XMLHttpRequest'}, + async: true, + }), + columns: [ + { 'data': 'active', + render: function (data, type, row) { + if (type === 'display') { + return ''; + } + return data; + }, + className: 'dt-body-center' + }, + { 'data': 'maquina'}, + { 'data': 'ancho'}, + { 'data': 'alto'}, + { 'data': 'anchoimpresion'}, + { 'data': 'altoimpresion'}, + { data: actionBtns2, + className: 'row-edit dt-center'} + ], + columnDefs: [ + { + orderable: false, + searchable: false, + targets: [lastColNr2] + } + ], + rowCallback: function (row, data) { + // Set the checked state of the checkbox in the table + $('input.editor-active', row).prop('checked', data.active == 1); + }, + language: { + url: "/themes/vuexy/vendor/libs/datatables-sk/plugins/i18n/es-ES.json" + }, + columnDefs: [ + { + searchable: false, + targets: [0,2,3,4,5] + } + ], + } ); + + + // Definición del editor + editor2 = new $.fn.dataTable.Editor( { + ajax: { + url: "", + headers: { + : v, + }, + }, + table : "#tableOfMaquinas", + idSrc: 'papel_impresion_id', + fields: [ + { + name: "active", + type: "checkbox", + separator: "|", + ipOpts: [ + { label: '', value: 1 } + ] + },{ + "name": "papel_impresion_id", + "type": "hidden" + },{ + "name": "gramaje", + "type": "hidden" + },{ + "name": "maquina_id", + "type": "hidden" + } + ] + } ); + + + // Postsubmit del editor + editor2.on( 'postSubmit', function ( e, json, data, action ) { + yeniden(json.); + if(json.error){ + document.getElementById("check_" + json.data.papel_impresion_id).checked = false; + popErrorAlert(json.error); + } + }); + + + // Click sobre el botón editar máquina + $(document).on('click', '.btn-edit2', function(e) { + window.open(`/configuracion/maquinas/edit/${$(this).attr('data-id')}`); + }); + + + // Cuando se clica en un checkbox hacer submit en el editor + theTable2.on( 'change', 'input.editor-active', function () { + editor2 + .edit( $(this).closest('tr'), false ) + .set( 'active', $(this).prop( 'checked' ) ? 1 : 0 ) + .submit(); + } ); + + $('#rotativa').on('change', function() { + if($('#inkjet').prop('checked')){ + $('#inkjet').prop('checked', false) + } + }) + + $('#inkjet').on('change', function() { + if($('#rotativa').prop('checked')){ + $('#rotativa').prop('checked', false) + } + }) + + endSection() ?> + + + + + section('css') ?> + + "> + endSection() ?> + + section('additionalExternalJs') ?> + + + + + + + + + + endSection() ?> \ No newline at end of file diff --git a/httpdocs/assets/js/safekat/pages/configuracion/papel_impresion/duplicate.js b/httpdocs/assets/js/safekat/pages/configuracion/papel_impresion/duplicate.js new file mode 100644 index 00000000..d900f978 --- /dev/null +++ b/httpdocs/assets/js/safekat/pages/configuracion/papel_impresion/duplicate.js @@ -0,0 +1,29 @@ +import Ajax from "../../../components/ajax.js" +import Modal from "../../../components/modal.js"; +$(() => { + let papelImpresionId = $("#papelImpresionForm").data("id"); + const uri = '/configuracion/papelesimpresion/duplicate/' + papelImpresionId; + let modalPapelDuplicate = new Modal($("#modalPapelImpresionDuplicate")) + $("#btn-papel-impresion-duplicate").on("click", (event) => { + modalPapelDuplicate.toggle(); + $("#btn-new-papel-impresion-duplicate").on("click", () => { + let name = $("#duplicated_name").val() + const ajax = new Ajax(uri, + { name: name }, + null, + (response) => { + modalPapelDuplicate.toggle(); + $("#btn-new-papel-impresion-duplicate").off(); + $("#duplicated_name").addClass("is-valid").removeClass('d-none'); + window.open('/configuracion/papelesimpresion/edit/' + response.data.id) + + }, + (error) => { + $("#duplicated_name").removeClass("is-valid").addClass("is-invalid") + } + ) + ajax.post() + + }) + }) +}) \ No newline at end of file