diff --git a/ci4/app/Config/Routes.php b/ci4/app/Config/Routes.php index 3b7a2594..202315e1 100755 --- a/ci4/app/Config/Routes.php +++ b/ci4/app/Config/Routes.php @@ -512,10 +512,10 @@ $routes->group('clientedirecciones', ['namespace' => 'App\Controllers\Clientes'] }); $routes->resource('clientedirecciones', ['namespace' => 'App\Controllers\Clientes', 'controller' => 'Clientedirecciones', 'except' => 'show,new,create,update']); - + $routes->group('cosidotapablanda', ['namespace' => 'App\Controllers\Presupuestos'], function ($routes) { $routes->get('list/(:num)', 'Cosidotapablanda::list/$1', ['as' => 'cosidotapablandaList']); // HOMOGENIZAR CON ARGS DINAMICOS!!! - $routes->get('add/(:num)', 'Cosidotapablanda::add/$1', ['as' => 'newCosidotapablanda']); + $routes->get('add/(:num)', 'Cosidotapablanda::add/$1', ['as' => 'newCosidotapablanda']); $routes->post('add/(:num)', 'Cosidotapablanda::add/$1', ['as' => 'createCosidotapablanda']); $routes->post('create', 'Cosidotapablanda::create', ['as' => 'ajaxCreateCosidotapablanda']); $routes->put('(:num)/update', 'Cosidotapablanda::update/$1', ['as' => 'ajaxUpdateCosidotapablanda']); @@ -560,7 +560,18 @@ $routes->group( function ($routes) { $routes->get('index/(:num)', 'PrintPresupuestos::index/$1', ['as' => 'viewPresupuesto']); $routes->get('generar/(:num)', 'PrintPresupuestos::generar/$1', ['as' => 'presupuestoToPdf']); - }); + } +); + +$routes->group( + 'buscadorpresupuestos', + ['namespace' => 'App\Controllers\Presupuestos'], + function ($routes) { + $routes->get('', 'Buscador::list', ['as' => 'buscadorPresupuestosList']); + $routes->post('datatable', 'Buscador::datatable', ['as' => 'dataTableOfBuscador']); + } +); +$routes->resource('buscadorpresupuestos', ['namespace' => 'App\Controllers\Presupuestos', 'controller' => 'Buscador', 'except' => 'show,new,create,update']); /* diff --git a/ci4/app/Controllers/Presupuestos/Buscador.php b/ci4/app/Controllers/Presupuestos/Buscador.php new file mode 100644 index 00000000..19616cc8 --- /dev/null +++ b/ci4/app/Controllers/Presupuestos/Buscador.php @@ -0,0 +1,121 @@ +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 + + // Breadcrumbs (IMN) + $this->viewData['breadcrumb'] = [ + ['title' => lang("App.menu_presupuestos"), 'route' => "javascript:void(0);", 'active' => false], + ['title' => lang("App.menu_presupuesto_buscador"), 'route' => site_url('presupuestos/buscador'), 'active' => true] + ]; + + parent::initController($request, $response, $logger); + $this->model = new BuscadorModel(); + } + + + public function index() + { + $viewData = [ + 'currentModule' => static::$controllerSlug, + 'pageSubTitle' => lang('Basic.global.ManageAllRecords', [lang('Presupuestos.presupuesto')]), + 'presupuestoEntity' => new PresupuestoEntity(), + 'usingServerSideDataTable' => true + ]; + + $viewData = array_merge($this->viewData, $viewData); // merge any possible values from the parent controller class + + return view(static::$viewPath . 'viewBuscadorList', $viewData); + } + + + public function datatable() + { + if ($this->request->isAJAX()) { + $reqData = $this->request->getPost(); + + $type = $reqData['type'] ?? null; + + if (is_null($type)) { + 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; + } + $search = $reqData['search']['value']; + } + $start = $reqData['start'] ?? 0; + $length = $reqData['length'] ?? 5; + + $requestedOrder1 = $reqData['order']['0']['column'] ?? 0; + $order1 = PresupuestoModel::SORTABLE[$requestedOrder1 >= 0 ? $requestedOrder1 : 0]; + $dir1 = $reqData['order']['0']['dir'] ?? 'asc'; + $requestedOrder2 = $reqData['order']['1']['column'] ?? 0; + $order2 = PresupuestoModel::SORTABLE[$requestedOrder2 >= 0 ? $requestedOrder1 : 0]; + $dir2 = $reqData['order']['0']['dir'] ?? 'asc'; + $requestedOrder3 = $reqData['order']['2']['column'] ?? 0; + $order3 = PresupuestoModel::SORTABLE[$requestedOrder3 >= 0 ? $requestedOrder1 : 0]; + $dir3 = $reqData['order']['0']['dir'] ?? 'asc'; + + $searchValues = get_filter_datatables_columns($reqData); + + $resourceData = $this->model->getResource($searchValues)->orderBy($order1, $dir1)->orderBy($order2, $dir2) + ->orderBy($order3, $dir3)->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); + } + } + +} diff --git a/ci4/app/Language/es/App.php b/ci4/app/Language/es/App.php index aebfe7a0..2cd814c2 100755 --- a/ci4/app/Language/es/App.php +++ b/ci4/app/Language/es/App.php @@ -741,6 +741,7 @@ return [ "menu_presupuestos" => "Presupuestos", "menu_presupuesto" => "Libros", + "menu_presupuesto_buscador" => "Buscador", "menu_libros" => "Libros", "menu_libros_fresasdo_tapa_dura" => "Fresado tapa dura", "menu_libros_fresasdo_tapa_blanda" => "Fresado tapa blanda", diff --git a/ci4/app/Language/es/Presupuestos.php b/ci4/app/Language/es/Presupuestos.php index d8625da1..f4e93843 100755 --- a/ci4/app/Language/es/Presupuestos.php +++ b/ci4/app/Language/es/Presupuestos.php @@ -20,6 +20,7 @@ return [ 'id' => 'ID', 'created_at' => 'Fecha', + 'tipoPresupuesto' => 'Tipo Presupuesto', 'clienteId' => 'Cliente', 'comercial' => 'Comercial', 'titulo' => 'Título', diff --git a/ci4/app/Models/Presupuestos/BuscadorModel.php b/ci4/app/Models/Presupuestos/BuscadorModel.php new file mode 100644 index 00000000..4fb9599e --- /dev/null +++ b/ci4/app/Models/Presupuestos/BuscadorModel.php @@ -0,0 +1,163 @@ + "t1.id", + 1 => "t1.created_at", + 2 => "t7.codigo", + 3 => "t2.nombre", + 4 => "t3.first_name", + 5 => "t1.titulo", + 6 => "t5.nombre", + 7 => "t1.inc_rei", + 8 => "t1.paginas", + 9 => "t1.tirada", + 10 => "t1.total_presupuesto", + 11 => "t6.estado", + ]; + + /* protected $allowedFields = [ + "cliente_id", + "user_created_id", + "user_update_id", + "tipo_impresion_id", + "tipologia_id", + "pais_id", + "estado_id", + "inc_rei", + "causa_cancelacion", + "retractilado", + "retractilado5", + "guardas", + "faja_color", + "recoger_en_taller", + "ferro", + "ferro_digital", + "marcapaginas", + "prototipo", + "papel_formato_id", + "papel_formato_personalizado", + "papel_formato_ancho", + "papel_formato_alto", + "titulo", + "autor", + "coleccion", + "numero_edicion", + "isbn", + "referencia_cliente", + "paginas", + "tirada", + "solapas", + "solapas_ancho", + "cosido", + "sobrecubiertas", + "sobrecubiertas_ancho", + "merma", + "merma_cubierta", + "comentarios_cliente", + "comentarios_safekat", + "comentarios_pdf", + "comentarios_tarifa", + "comentarios_produccion", + "lomo", + "total_presupuesto", + "envios_recoge_cliente", + "tirada_alternativa_json_data", + "aprobado_user_id", + "aprobado_at", + "comparador_json_data", + "is_deleted", + "comp_tipo_impresion", + "comp_pos_paginas_color", + "total_coste_papel", + "total_margen_papel", + "total_margenPercent_papel", + "total_coste_impresion", + "total_margen_impresion", + "total_margenPercent_impresion", + "total_coste_servicios", + "total_margen_servicios", + "total_margenPercent_servicios", + "total_coste_envios", + "total_margen_envios", + "total_costes", + "total_margenes", + "total_antes_descuento", + "total_descuento", + "total_descuentoPercent", + "total_presupuesto", + "total_precio_unidad", + ]; + */ + protected $returnType = "App\Entities\Presupuestos\PresupuestoEntity"; + + protected $useTimestamps = true; + protected $useSoftDeletes = false; + + protected $createdField = "created_at"; + protected $updatedField = "updated_at"; + + public static $labelField = "titulo"; + + + + /** + * Get resource data. + * + * @param string $search + * + * @return \CodeIgniter\Database\BaseBuilder + */ + public function getResource($search = []) + { + $builder = $this->db + ->table($this->table . " t1") + ->select( + "t1.id AS id, t1.created_at AS fecha, t7.codigo as codigo, t2.nombre AS cliente, + CONCAT(t3.first_name, ' ', t3.last_name) AS comercial, t1.titulo AS titulo, + t5.nombre AS pais, t1.inc_rei AS inc_rei, t1.paginas AS paginas, t1.tirada AS tirada, + t1.total_presupuesto AS total_presupuesto, t1.total_presupuesto AS total_presupuesto, + t6.estado AS estado" + ); + $builder->join("clientes t2", "t1.cliente_id = t2.id", "left"); + $builder->join("auth_user t3", "t1.user_update_id = t3.id_user", "left"); + $builder->join("lg_paises t5", "t1.pais_id = t5.id", "left"); + $builder->join("presupuesto_estados t6", "t1.estado_id = t6.id", "left"); + $builder->join("tipos_presupuestos t7", "t1.tipo_impresion_id = t7.id", "left"); + + $builder->where("t1.is_deleted", 0); + + if (empty($search)) + return $builder; + else { + $builder->groupStart(); + foreach ($search as $col_search) { + if ($col_search[0] != 1) + $builder->like(self::SORTABLE[$col_search[0]], $col_search[2]); + else { + $dates = explode(" ", $col_search[2]); + $builder->where(self::SORTABLE[$col_search[0]] . ">=", $dates[0]); + $builder->where(self::SORTABLE[$col_search[0]] . "<=", $dates[1]); + } + } + $builder->groupEnd(); + return $builder; + } + + } + + + +} diff --git a/ci4/app/Views/themes/backend/vuexy/form/presupuestos/buscador/viewBuscadorList.php b/ci4/app/Views/themes/backend/vuexy/form/presupuestos/buscador/viewBuscadorList.php new file mode 100644 index 00000000..43f17ce7 --- /dev/null +++ b/ci4/app/Views/themes/backend/vuexy/form/presupuestos/buscador/viewBuscadorList.php @@ -0,0 +1,302 @@ +include('themes/_commonPartialsBs/select2bs5') ?> +include('themes/_commonPartialsBs/datatables') ?> +include('themes/_commonPartialsBs/sweetalert') ?> +include('themes/_commonPartialsBs/_confirm2delete') ?> +extend('themes/backend/vuexy/main/defaultlayout') ?> +section('content'); ?> +
+
+ +
+
+

+
+
+ + + + + + + + + + + + + + + + + + + + + + + +
+
+ +
+
+
+ +endSection() ?> + + +section('additionalInlineJs') ?> + +const lastColNr = $('#tableOfPresupuestos').find("tr:first th").length - 1; +const actionBtns = function(data) { + return ` + +
+ + +
+ `; +}; + +// Setup - add a text input to each footer cell +$('#tableOfPresupuestos thead tr').clone(true).appendTo('#tableOfPresupuestos thead'); +$('#tableOfPresupuestos thead tr:eq(1) th').each(function (i) { + if (!$(this).hasClass("noFilter")) { + var title = $(this).text(); + if(i==1){ + + $(this).html(''); + var bsRangePickerRange = $('#bs-rangepicker-range') + bsRangePickerRange.daterangepicker({ + ranges: { + '': [moment(), moment()], + '': [moment().subtract(1, 'days'), moment().subtract(1, 'days')], + '': [moment().subtract(6, 'days'), moment()], + '': [moment().subtract(29, 'days'), moment()], + '': [moment().startOf('month'), moment().endOf('month')], + '': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')] + }, + opens: 'right', + language: 'i18n ?>', + "locale": { + "customRangeLabel": "", + "format": "YYYY-MM-DD", + "separator": " ", + "applyLabel": "", + "cancelLabel": "", + + }, + "alwaysShowCalendars": true, + autoUpdateInput: false, + + }); + + bsRangePickerRange.on('apply.daterangepicker', function(ev, picker) { + $(this).val(picker.startDate.format('YYYY-MM-DD') + ' ' + picker.endDate.format('YYYY-MM-DD')); + theTable + .column(i) + .search(this.value) + .draw(); + }); + + bsRangePickerRange.on('cancel.daterangepicker', function(ev, picker) { + $(this).val(''); + theTable + .column(i) + .search(this.value) + .draw(); + }); + + } + else if (i == 2) { + // Agregar un selector en la tercera columna + $(this).html(''); + + // Agregar opciones al selector + var selector = $('select', this); + selector.append(''); // Opción vacía + // Agregar más opciones según tus necesidades + selector.append(''); + selector.append(''); + + selector.on('change', function () { + var val = $.fn.dataTable.util.escapeRegex( + $(this).val() + ); + console.log(val) + theTable.column(i).search(val ? '^' + val + '$' : '', true, false).draw(); + }); + } + else{ + $(this).html(''); + + $('input', this).on('change clear', function () { + if (theTable.column(i).search() !== this.value) { + theTable + .column(i) + .search(this.value) + .draw(); + } + }); + } + } + else { + $(this).html(''); + } +}); + + +theTable = $('#tableOfPresupuestos').DataTable({ + orderCellsTop: true, + fixedHeader: true, + processing: true, + serverSide: true, + autoWidth: true, + responsive: true, + scrollX: true, + lengthMenu: [ 5, 10, 25, 50, 75, 100, 250, 500, 1000, 2500 ], + pageLength: 50, + lengthChange: true, + "dom": '<"mb-3"l>Brtip', + "buttons": [ + 'colvis', 'copy', 'csv', 'excel', 'print', { + extend: 'pdfHtml5', + orientation: 'landscape', + pageSize: 'A4' + } + ], + stateSave: false, + order: [[1, 'asc']], + language: { + url: "//cdn.datatables.net/plug-ins/1.13.4/i18n/i18n ?>.json" + }, + ajax : $.fn.dataTable.pipeline( { + url: '', + method: 'POST', + headers: {'X-Requested-With': 'XMLHttpRequest'}, + async: true, + }), + columnDefs: [ + { + orderable: false, + searchable: false, + targets: [lastColNr] + } + ], + columns : [ + { 'data': 'id' }, + { 'data': 'fecha' }, + { 'data': 'codigo', + render: function(data, type, row, meta) { + switch(data){ + case "libroCosidoTapaBlanda": + return ''; + break; + + default: + return data; + break; + + } + }, + }, + { 'data': 'cliente' }, + { 'data': 'comercial' }, + { 'data': 'titulo' }, + { 'data': 'pais' }, + { 'data': 'inc_rei' }, + { 'data': 'paginas' }, + { 'data': 'tirada' }, + { 'data': 'total_presupuesto' }, + { 'data': 'estado' , + 'render': function ( data, type, row, meta ) { + if(data=='borrador') + return ''; + else if(data=='aceptado') + return ''; + } + }, + { 'data': actionBtns } + ] +}); + + +theTable.on( 'draw.dt', function () { + + const dateCols = [1]; + const priceCols = [9]; + + for (let coln of dateCols) { + theTable.column(coln, { page: 'current' }).nodes().each( function (cell, i) { + const datestr = cell.innerHTML; + const dateStrLen = datestr.toString().trim().length; + if (dateStrLen > 0) { + let dateTimeParts= datestr.split(/[- :]/); // regular expression split that creates array with: year, month, day, hour, minutes, seconds values + dateTimeParts[1]--; // monthIndex begins with 0 for January and ends with 11 for December so we need to decrement by one + const d = new Date(...dateTimeParts); // new Date(datestr); + cell.innerHTML = d.toLocaleDateString(); + } + }); + } + + for (let coln of priceCols) { + theTable.column(coln, { page: 'current' }).nodes().each( function (cell, i) { + cell.innerHTML = parseFloat(cell.innerHTML).toFixed(2); + + }); + } +}); + + +$(document).on('click', '.btn-edit', function(e) { + window.location.href = `/presupuestos/cosidotapablanda/edit/${$(this).attr('data-id')}/`; +}); + + +$(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: `/presupuestos/cosidotapablanda/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('css') ?> + + + +endSection() ?> + + +section('additionalExternalJs') ?> + + + + + + + + + + +endSection() ?> + diff --git a/ci4/app/Views/themes/backend/vuexy/form/presupuestos/cosidotapablanda/viewCosidotapablandaList.php b/ci4/app/Views/themes/backend/vuexy/form/presupuestos/cosidotapablanda/viewCosidotapablandaList.php index dc27270e..743bdd47 100755 --- a/ci4/app/Views/themes/backend/vuexy/form/presupuestos/cosidotapablanda/viewCosidotapablandaList.php +++ b/ci4/app/Views/themes/backend/vuexy/form/presupuestos/cosidotapablanda/viewCosidotapablandaList.php @@ -140,7 +140,7 @@ theTable = $('#tableOfPresupuestos').DataTable({ lengthMenu: [ 5, 10, 25, 50, 75, 100, 250, 500, 1000, 2500 ], pageLength: 50, lengthChange: true, - "dom": 'lBrtip', + "dom": '<"mb-3"l>Brtip', "buttons": [ 'colvis', 'copy', 'csv', 'excel', 'print', { extend: 'pdfHtml5', diff --git a/ci4/app/Views/themes/backend/vuexy/main/menu_impresion.php b/ci4/app/Views/themes/backend/vuexy/main/menu_impresion.php index d065213d..ff7bd8f1 100755 --- a/ci4/app/Views/themes/backend/vuexy/main/menu_impresion.php +++ b/ci4/app/Views/themes/backend/vuexy/main/menu_impresion.php @@ -69,6 +69,17 @@
">