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 @@
| = lang('Pedidos.ubicacion') ?> | = lang('Pedidos.inc_rei') ?> | = lang('Pedidos.num_paginas') ?> | -= lang('Pedidos.tiradas') ?> | -= lang('Pedidos.total_presupuesto') ?> | += lang('Pedidos.tiradas') ?> | += lang('Pedidos.total_presupuesto') ?> | = lang('Pedidos.estado') ?> | = lang('Basic.global.Action') ?> | @@ -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: { - '= lang('datePicker.hoy') ?>': [moment(), moment()], - '= lang('datePicker.ayer') ?>': [moment().subtract(1, 'days'), moment().subtract(1, 'days')], - '= lang('datePicker.ultimos7') ?>': [moment().subtract(6, 'days'), moment()], - '= lang('datePicker.ultimos30') ?>': [moment().subtract(29, 'days'), moment()], - '= lang('datePicker.esteMes') ?>': [moment().startOf('month'), moment().endOf('month')], - '= lang('datePicker.ultimoMes') ?>': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')] - }, - opens: 'right', - language: '= config('Basics')->i18n ?>', - "locale": { - "customRangeLabel": "= lang('datePicker.personalizar') ?>", - "format": "YYYY-MM-DD", - "separator": " ", - "applyLabel": "= lang('datePicker.aplicar') ?>", - "cancelLabel": "= lang('datePicker.limpiar') ?>", - - }, - "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(''); + } + else if(i==10){ + $(this).html(''); + } } else{ - $(this).html(''); + if(i==1 || i==2){ + name = 'bs-rangepicker-range_' + i; + $(this).html(''); + var bsRangePickerRange = $('#' + name); + bsRangePickerRange.daterangepicker({ + ranges: { + '= lang('datePicker.hoy') ?>': [moment(), moment()], + '= lang('datePicker.ayer') ?>': [moment().subtract(1, 'days'), moment().subtract(1, 'days')], + '= lang('datePicker.ultimos7') ?>': [moment().subtract(6, 'days'), moment()], + '= lang('datePicker.ultimos30') ?>': [moment().subtract(29, 'days'), moment()], + '= lang('datePicker.esteMes') ?>': [moment().startOf('month'), moment().endOf('month')], + '= lang('datePicker.ultimoMes') ?>': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')] + }, + opens: 'right', + language: '= config('Basics')->i18n ?>', + "locale": { + "customRangeLabel": "= lang('datePicker.personalizar') ?>", + "format": "YYYY-MM-DD", + "separator": " ", + "applyLabel": "= lang('datePicker.aplicar') ?>", + "cancelLabel": "= lang('datePicker.limpiar') ?>", - $('input', this).on('change clear', function () { - if (theTable.column(i).search() !== this.value) { - theTable - .column(i) - .search(this.value) - .draw(); - } - }); - } + }, + "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(); + }); + } + 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({ + var theTable = $('#tableOfPedidos').DataTable({ + select: { + style: 'multi', + info: false + }, orderCellsTop: true, fixedHeader: true, processing: true, @@ -156,7 +178,7 @@ $('#tableOfPedidos thead tr:eq(1) th').each(function (i) { searching: true, scrollX: true, lengthMenu: [ 5, 10, 25, 50, 75, 100, 250, 500, 1000, 2500 ], - pageLength: 50, + pageLength: 100, lengthChange: true, "dom": '<"mb-3"l>Brtip', "buttons": [ @@ -174,8 +196,9 @@ $('#tableOfPedidos thead tr:eq(1) th').each(function (i) { ajax : $.fn.dataTable.pipeline( { url: '= route_to('dataTableOfPedidos') ?>', method: 'POST', - data: { - estado: "= $estadoPedidos ?>", + data: function(d, settings){ + d.estado= "= $estadoPedidos ?>"; + d.showTotal= $('#showTotal').is(':checked')? "1":"0"; }, headers: {'X-Requested-With': 'XMLHttpRequest'}, async: true, @@ -230,7 +253,11 @@ $('#tableOfPedidos thead tr:eq(1) th').each(function (i) { } }, { 'data': actionBtns } - ] + ], + drawCallback: function (settings) { + $('#total_tirada').text(settings.json.extra.total_tirada); + $('#total_aceptado').text(settings.json.extra.total); + } }); theTable.on( 'draw.dt', function () { @@ -266,6 +293,16 @@ $('#tableOfPedidos thead tr:eq(1) th').each(function (i) { window.location.href = url; }); + theTable.on('click', 'tbody tr', function (e) { + e.currentTarget.classList.toggle('selected'); + }); + + $('#showTotal').on('change', function() { + theTable.clearPipeline(); + theTable.ajax.reload(null, false); + //theTable.draw(); + }); + =$this->endSection() ?> @@ -279,6 +316,7 @@ $('#tableOfPedidos thead tr:eq(1) th').each(function (i) { = $this->section('additionalExternalJs') ?> +
|---|