From 7318e4bd7c8a8c25dc59193d42016a6db9749414 Mon Sep 17 00:00:00 2001 From: imnavajas Date: Wed, 31 Jul 2024 22:54:20 +0200 Subject: [PATCH 1/4] Actualizacion automatica: 2024-07-31 22:54:20 --- .../vuexy/form/pedidos/viewPedidosList.php | 101 +++++++++++++++++- 1 file changed, 98 insertions(+), 3 deletions(-) diff --git a/ci4/app/Views/themes/vuexy/form/pedidos/viewPedidosList.php b/ci4/app/Views/themes/vuexy/form/pedidos/viewPedidosList.php index 1a169428..351031c4 100644 --- a/ci4/app/Views/themes/vuexy/form/pedidos/viewPedidosList.php +++ b/ci4/app/Views/themes/vuexy/form/pedidos/viewPedidosList.php @@ -23,7 +23,7 @@ - + @@ -57,6 +57,73 @@ `; }; +// Setup - add a text input to each footer cell +$('#tableOfPedidos thead tr').clone(true).appendTo('#tableOfPedidos thead'); +$('#tableOfPedidos 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{ + $(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 = $('#tableOfPedidos').DataTable({ processing: true, serverSide: true, @@ -66,9 +133,9 @@ lengthMenu: [ 5, 10, 25, 50, 75, 100, 250, 500, 1000, 2500 ], pageLength: 50, lengthChange: true, - "dom": 'lfBrtip', + "dom": '<"mb-3"l>Brtip', "buttons": [ - 'copy', 'csv', 'excel', 'print', { + 'colvis', 'copy', 'csv', 'excel', 'print', { extend: 'pdfHtml5', orientation: 'landscape', pageSize: 'A4' @@ -143,14 +210,37 @@ theTable.on( 'draw.dt', function () { const boolCols = []; + const dateCols = [1]; + const priceCols = [10]; for (let coln of boolCols) { theTable.column(coln, { page: 'current' }).nodes().each( function (cell, i) { cell.innerHTML = cell.innerHTML == '1' ? '' : ''; }); } + + 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) { var url = ''; url = url.replace(':id', `${$(this).attr('data-id')}` ); @@ -163,6 +253,8 @@ section('css') ?> "> + "> + endSection() ?> @@ -171,6 +263,9 @@ + + + From d4373a401f13e4e3412aa284fd3a2085bd76e4d7 Mon Sep 17 00:00:00 2001 From: imnavajas Date: Mon, 5 Aug 2024 13:36:26 +0200 Subject: [PATCH 2/4] Arreglando filtrado --- ci4/app/Controllers/Pedidos/Pedido.php | 6 ++++-- ci4/app/Controllers/Presupuestos/Buscador.php | 2 +- .../themes/vuexy/form/pedidos/viewPedidosList.php | 15 +++++++++------ 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/ci4/app/Controllers/Pedidos/Pedido.php b/ci4/app/Controllers/Pedidos/Pedido.php index bc8254dd..66849729 100755 --- a/ci4/app/Controllers/Pedidos/Pedido.php +++ b/ci4/app/Controllers/Pedidos/Pedido.php @@ -245,13 +245,15 @@ class Pedido extends \App\Controllers\BaseResourceController $estado = $reqData['estado'] ?? 'todos'; if($estado == 'todos') $estado = ''; + $searchValues = get_filter_datatables_columns($reqData); + $model_linea = model('\App\Models\Pedidos\PedidoLineaModel'); - $resourceData = $model_linea->getResource($search, $estado)->orderBy($order, $dir)->limit($length, $start)->get()->getResultObject(); + $resourceData = $model_linea->getResource($searchValues, $estado)->orderBy($order, $dir)->limit($length, $start)->get()->getResultObject(); return $this->respond(Collection::datatable( $resourceData, $model_linea->getResource("", $estado)->countAllResults(), - $model_linea->getResource($search, $estado)->countAllResults() + $model_linea->getResource($searchValues, $estado)->countAllResults() )); } else { return $this->failUnauthorized('Invalid request', 403); diff --git a/ci4/app/Controllers/Presupuestos/Buscador.php b/ci4/app/Controllers/Presupuestos/Buscador.php index 30b7b53e..edfe067d 100644 --- a/ci4/app/Controllers/Presupuestos/Buscador.php +++ b/ci4/app/Controllers/Presupuestos/Buscador.php @@ -111,7 +111,7 @@ class Buscador extends \App\Controllers\BaseResourceController return $this->respond(Collection::datatable( $resourceData, $this->model->getResource("")->countAllResults(), - $this->model->getResource($search)->countAllResults() + $this->model->getResource($searchValues)->countAllResults() )); } else { return $this->failUnauthorized('Invalid request', 403); diff --git a/ci4/app/Views/themes/vuexy/form/pedidos/viewPedidosList.php b/ci4/app/Views/themes/vuexy/form/pedidos/viewPedidosList.php index 351031c4..c172c254 100644 --- a/ci4/app/Views/themes/vuexy/form/pedidos/viewPedidosList.php +++ b/ci4/app/Views/themes/vuexy/form/pedidos/viewPedidosList.php @@ -17,7 +17,7 @@ - + @@ -125,10 +125,13 @@ $('#tableOfPedidos thead tr:eq(1) th').each(function (i) { }); theTable = $('#tableOfPedidos').DataTable({ + orderCellsTop: true, + fixedHeader: true, processing: true, serverSide: true, autoWidth: true, responsive: true, + searching: true, scrollX: true, lengthMenu: [ 5, 10, 25, 50, 75, 100, 250, 500, 1000, 2500 ], pageLength: 50, @@ -141,7 +144,7 @@ $('#tableOfPedidos thead tr:eq(1) th').each(function (i) { pageSize: 'A4' } ], - stateSave: true, + stateSave: false, order: [[0, 'asc']], language: { url: "/themes/vuexy/vendor/libs/datatables-sk/plugins/i18n/es-ES.json" @@ -158,7 +161,7 @@ $('#tableOfPedidos thead tr:eq(1) th').each(function (i) { columnDefs: [ { orderable: false, - searchable: false, + searchable: true, targets: [lastColNr] } ], @@ -209,14 +212,14 @@ $('#tableOfPedidos thead tr:eq(1) th').each(function (i) { }); theTable.on( 'draw.dt', function () { - const boolCols = []; + //const boolCols = []; const dateCols = [1]; const priceCols = [10]; - for (let coln of boolCols) { + /*for (let coln of boolCols) { theTable.column(coln, { page: 'current' }).nodes().each( function (cell, i) { cell.innerHTML = cell.innerHTML == '1' ? '' : ''; }); - } + }*/ for (let coln of dateCols) { theTable.column(coln, { page: 'current' }).nodes().each( function (cell, i) { From 4255b74f33cdfa18785fb222b489120238238702 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaime=20Jim=C3=A9nez?= Date: Mon, 5 Aug 2024 17:59:00 +0200 Subject: [PATCH 3/4] filtros columna en pedidos hecho --- ci4/app/Models/Pedidos/PedidoLineaModel.php | 44 +++++++++++++------ .../vuexy/form/pedidos/viewPedidosList.php | 42 ++++++++++++------ 2 files changed, 59 insertions(+), 27 deletions(-) diff --git a/ci4/app/Models/Pedidos/PedidoLineaModel.php b/ci4/app/Models/Pedidos/PedidoLineaModel.php index d7eb4699..06f4f29c 100644 --- a/ci4/app/Models/Pedidos/PedidoLineaModel.php +++ b/ci4/app/Models/Pedidos/PedidoLineaModel.php @@ -14,12 +14,20 @@ class PedidoLineaModel extends \App\Models\BaseModel protected $useAutoIncrement = true; const SORTABLE = [ - 0 => "t1.id", - 1 => "t1.estado", - 2 => "t1.total_precio", - 3 => "t1.total_tirada", + 0 => "t2.id", + 1 => "t2.updated_at", + 2 => "t2.fecha_entrega_real", + 3 => "t4.nombre", + 4 => "CONCAT(t5.first_name, ' ', t5.last_name)", + 5 => "t3.titulo", + 6 => "t6.nombre", + 7 => "t3.inc_rei", + 8 => "t3.paginas", + 9 => "t3.tirada", + 10 => "t3.total_aceptado", + 11 => "t2.estado" ]; - + protected $allowedFields = [ "pedido_id", "presupuesto_id", @@ -40,7 +48,7 @@ class PedidoLineaModel extends \App\Models\BaseModel public static $labelField = "id"; - public function getResource(string $search = "", $estado="") + public function getResource($search = [], $estado="") { $builder = $this->db ->table($this->table . " t1") @@ -67,14 +75,22 @@ class PedidoLineaModel extends \App\Models\BaseModel } } - // Falta implementar la busqueda por grupos - return empty($search) - ? $builder - : $builder - ->groupStart() - ->like("t1.id", $search) - ->orLike("t1.id", $search) - ->groupEnd(); + if (empty($search)) + return $builder; + else { + $builder->groupStart(); + foreach ($search as $col_search) { + if ($col_search[0] != 1 && $col_search[0] != 2) + $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/vuexy/form/pedidos/viewPedidosList.php b/ci4/app/Views/themes/vuexy/form/pedidos/viewPedidosList.php index c172c254..032d9f8b 100644 --- a/ci4/app/Views/themes/vuexy/form/pedidos/viewPedidosList.php +++ b/ci4/app/Views/themes/vuexy/form/pedidos/viewPedidosList.php @@ -17,7 +17,7 @@ - + @@ -27,7 +27,7 @@ - + @@ -62,9 +62,10 @@ $('#tableOfPedidos thead tr').clone(true).appendTo('#tableOfPedidos thead'); $('#tableOfPedidos 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') + if(i==1 || i==2){ + name = 'bs-rangepicker-range_' + i; + $(this).html(''); + var bsRangePickerRange = $('#' + name); bsRangePickerRange.daterangepicker({ ranges: { '': [moment(), moment()], @@ -106,6 +107,27 @@ $('#tableOfPedidos thead tr:eq(1) th').each(function (i) { }); } + else if (i == 11) { + // Agregar un selector en la tercera columna + $(this).html(''); + + // Agregar opciones al selector + var selector = $('select', this); + + selector.append(''); // Opción vacía + selector.append(''); + selector.append(''); + selector.append(''); + selector.append(''); + selector.append(''); + + selector.on('change', function () { + var val = $.fn.dataTable.util.escapeRegex( + $(this).val() + ); + theTable.column(i).search(val).draw(); + }); + } else{ $(this).html(''); @@ -212,15 +234,9 @@ $('#tableOfPedidos thead tr:eq(1) th').each(function (i) { }); theTable.on( 'draw.dt', function () { - //const boolCols = []; - const dateCols = [1]; + const dateCols = [1,2]; const priceCols = [10]; - /*for (let coln of boolCols) { - theTable.column(coln, { page: 'current' }).nodes().each( function (cell, i) { - cell.innerHTML = cell.innerHTML == '1' ? '' : ''; - }); - }*/ - + for (let coln of dateCols) { theTable.column(coln, { page: 'current' }).nodes().each( function (cell, i) { const datestr = cell.innerHTML; From 8ea0ab13c0f8738cc3ba5c380d1ad4f79b923355 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaime=20Jim=C3=A9nez?= Date: Mon, 5 Aug 2024 21:25:16 +0200 Subject: [PATCH 4/4] totalizadores implementados --- ci4/app/Controllers/Pedidos/Pedido.php | 18 +- ci4/app/Language/en/Pedidos.php | 2 + ci4/app/Language/es/Pedidos.php | 2 + ci4/app/Models/Collection.php | 6 +- ci4/app/Models/Pedidos/PedidoLineaModel.php | 88 ++++++++ .../vuexy/form/pedidos/viewPedidosList.php | 202 +++++++++++------- 6 files changed, 234 insertions(+), 84 deletions(-) diff --git a/ci4/app/Controllers/Pedidos/Pedido.php b/ci4/app/Controllers/Pedidos/Pedido.php index 66849729..647ff134 100755 --- a/ci4/app/Controllers/Pedidos/Pedido.php +++ b/ci4/app/Controllers/Pedidos/Pedido.php @@ -245,15 +245,31 @@ class Pedido extends \App\Controllers\BaseResourceController $estado = $reqData['estado'] ?? 'todos'; if($estado == 'todos') $estado = ''; + $showTotal = $reqData['showTotal'] ?? false; + $searchValues = get_filter_datatables_columns($reqData); $model_linea = model('\App\Models\Pedidos\PedidoLineaModel'); $resourceData = $model_linea->getResource($searchValues, $estado)->orderBy($order, $dir)->limit($length, $start)->get()->getResultObject(); + $totalTirada = $model_linea->getSumOfTirada($searchValues, $estado, $start, $length); + $total = $model_linea->getSumOfTotalAceptado($searchValues, $estado, $start, $length); + $total2 = 0; + if($showTotal){ + $total2 = $model_linea->getTotalOfTotalAceptado(); + } + if($total2 != 0){ + $total = "" . $total . " \n(" . $total2 . ")"; + } return $this->respond(Collection::datatable( $resourceData, $model_linea->getResource("", $estado)->countAllResults(), - $model_linea->getResource($searchValues, $estado)->countAllResults() + $model_linea->getResource($searchValues, $estado)->countAllResults(), + "", + [ + 'total_tirada' => $totalTirada, + 'total' => $total + ] )); } else { return $this->failUnauthorized('Invalid request', 403); diff --git a/ci4/app/Language/en/Pedidos.php b/ci4/app/Language/en/Pedidos.php index 69a30669..553a35c8 100644 --- a/ci4/app/Language/en/Pedidos.php +++ b/ci4/app/Language/en/Pedidos.php @@ -78,6 +78,8 @@ return [ 'facturas' => 'Invoices', + 'showTotal' => 'Show totals', + 'validation' => [ ], diff --git a/ci4/app/Language/es/Pedidos.php b/ci4/app/Language/es/Pedidos.php index f8556058..25de0a9c 100644 --- a/ci4/app/Language/es/Pedidos.php +++ b/ci4/app/Language/es/Pedidos.php @@ -78,6 +78,8 @@ return [ 'facturas' => 'Facturas', + 'showTotal' => 'Mostrar totales', + 'validation' => [ ], diff --git a/ci4/app/Models/Collection.php b/ci4/app/Models/Collection.php index 773ae680..af469083 100755 --- a/ci4/app/Models/Collection.php +++ b/ci4/app/Models/Collection.php @@ -15,7 +15,7 @@ class Collection * * @return array */ - public static function datatable(array $data, int $recordsTotal, int $recordsFiltered, string $error = null) + public static function datatable(array $data, int $recordsTotal, int $recordsFiltered, string $error = null, $extra_data = []) { $draw = 1; $req = service('request'); @@ -38,6 +38,10 @@ class Collection $response['error'] = $error; } + if (count($extra_data)>0) { + $response['extra'] = $extra_data; + } + return $response; } } \ No newline at end of file diff --git a/ci4/app/Models/Pedidos/PedidoLineaModel.php b/ci4/app/Models/Pedidos/PedidoLineaModel.php index 06f4f29c..52284cb4 100644 --- a/ci4/app/Models/Pedidos/PedidoLineaModel.php +++ b/ci4/app/Models/Pedidos/PedidoLineaModel.php @@ -93,6 +93,94 @@ class PedidoLineaModel extends \App\Models\BaseModel } } + public function getSumOfTirada(array $search, $estado = '', $start = 0, $length = 5) + { + + $builder = $this->db + ->table($this->table . " t1") + ->selectSum('t3.tirada', 'total_tirada'); + + $builder->join("pedidos t2", "t2.id = t1.pedido_id", "left"); + $builder->join("presupuestos t3", "t1.presupuesto_id = t3.id", "left"); + + + + // Aplica los filtros de búsqueda y estado + if (!empty($search)) { + $builder->groupStart(); + foreach ($search as $col_search) { + if ($col_search[0] != 1 && $col_search[0] != 2) + $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(); + } + + if ($estado !== '') { + $builder->where('estado', $estado); + } + + // Aplicar el orden y el límite + $builder->limit($length, $start); + + return $builder->get()->getRow()->total_tirada; + } + + public function getSumOfTotalAceptado(array $search, $estado = '', $start = 0, $length = 5) + { + + $builder = $this->db + ->table($this->table . " t1") + ->selectSum('t3.total_aceptado', 'total'); + + $builder->join("pedidos t2", "t2.id = t1.pedido_id", "left"); + $builder->join("presupuestos t3", "t1.presupuesto_id = t3.id", "left"); + + + + // Aplica los filtros de búsqueda y estado + if (!empty($search)) { + $builder->groupStart(); + foreach ($search as $col_search) { + if ($col_search[0] != 1 && $col_search[0] != 2) + $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(); + } + + if ($estado !== '') { + $builder->where('estado', $estado); + } + + // Aplicar el orden y el límite + $builder + ->limit($length, $start); + + return $builder->get()->getRow()->total; + } + + public function getTotalOfTotalAceptado() + { + + $builder = $this->db + ->table($this->table . " t1") + ->selectSum('t3.total_aceptado', 'total'); + + $builder->join("pedidos t2", "t2.id = t1.pedido_id", "left"); + $builder->join("presupuestos t3", "t1.presupuesto_id = t3.id", "left"); + + + return $builder->get()->getRow()->total; + } public function obtenerLineasPedidoSinFacturar($cliente_id) { $resultaArray = []; diff --git a/ci4/app/Views/themes/vuexy/form/pedidos/viewPedidosList.php b/ci4/app/Views/themes/vuexy/form/pedidos/viewPedidosList.php index 032d9f8b..6a395ff5 100644 --- a/ci4/app/Views/themes/vuexy/form/pedidos/viewPedidosList.php +++ b/ci4/app/Views/themes/vuexy/form/pedidos/viewPedidosList.php @@ -11,6 +11,14 @@
+
+
+ + +
+
@@ -24,8 +32,8 @@ - - + + @@ -62,91 +70,105 @@ $('#tableOfPedidos thead tr').clone(true).appendTo('#tableOfPedidos thead'); $('#tableOfPedidos thead tr:eq(1) th').each(function (i) { if (!$(this).hasClass("noFilter")) { var title = $(this).text(); - if(i==1 || i==2){ - name = 'bs-rangepicker-range_' + i; - $(this).html(''); - var bsRangePickerRange = $('#' + name); - 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 == 11) { - // Agregar un selector en la tercera columna - $(this).html(''); - - // Agregar opciones al selector - var selector = $('select', this); - - selector.append(''); // Opción vacía - selector.append(''); - selector.append(''); - selector.append(''); - selector.append(''); - selector.append(''); - - selector.on('change', function () { - var val = $.fn.dataTable.util.escapeRegex( - $(this).val() - ); - theTable.column(i).search(val).draw(); - }); + if($(this).hasClass("totalizador")){ + if(i==9){ + $(this).html('