diff --git a/ci4/.env b/ci4/.env index 40f48c5f..1b2dc97a 100755 --- a/ci4/.env +++ b/ci4/.env @@ -22,8 +22,8 @@ CI_ENVIRONMENT = development # APP #-------------------------------------------------------------------- -#app.baseURL = 'https://sk-jjo.imnavajas.es' -app.baseURL = 'https://sk-imn.imnavajas.es' +app.baseURL = 'https://sk-jjo.imnavajas.es' +#app.baseURL = 'https://sk-imn.imnavajas.es' # app.baseURL = "http://safekat.test/" # app.forceGlobalSecureRequests = false @@ -118,7 +118,7 @@ database.default.dump = security.headerName = 'X-CSRF-TOKEN' security.cookieName = 'safekat_cookie' security.expires = 7200 - security.regenerate = true + security.regenerate = false security.redirect = true security.samesite = 'Lax' diff --git a/ci4/app/Controllers/Presupuestos/Cosidotapablanda.php b/ci4/app/Controllers/Presupuestos/Cosidotapablanda.php index f90eb06b..aa72be59 100755 --- a/ci4/app/Controllers/Presupuestos/Cosidotapablanda.php +++ b/ci4/app/Controllers/Presupuestos/Cosidotapablanda.php @@ -321,14 +321,23 @@ class Cosidotapablanda extends \App\Controllers\GoBaseResourceController $start = $reqData['start'] ?? 0; $length = $reqData['length'] ?? 5; - $requestedOrder = $reqData['order']['0']['column'] ?? 0; - $order = PresupuestoModel::SORTABLE[$requestedOrder >= 0 ? $requestedOrder : 0]; - $dir = $reqData['order']['0']['dir'] ?? 'asc'; + $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'; - if (is_null($type)) { - $resourceData = $this->model->getResource($search)->orderBy($order, $dir)->limit($length, $start)->get()->getResultObject(); + + $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(); foreach ($resourceData as $item) : if (isset($item->comentarios_pdf) && strlen($item->comentarios_pdf) > 100) : $item->comentarios_pdf = character_limiter($item->comentarios_pdf, 100); diff --git a/ci4/app/Helpers/general_helper.php b/ci4/app/Helpers/general_helper.php index 798f161f..8e5ea3ed 100755 --- a/ci4/app/Helpers/general_helper.php +++ b/ci4/app/Helpers/general_helper.php @@ -641,6 +641,25 @@ function templateSelect($templates=[],$name='',$type='') { return null; } +function get_filter_datatables_columns($request){ + $columnSearch = array(); + + if ( isset( $request['columns'] ) ) { + for ( $i=0, $ien=count($request['columns']) ; $i<$ien ; $i++ ) { + $requestColumn = $request['columns'][$i]; + + $str = $requestColumn['search']['value']; + + if ( $requestColumn['searchable'] == 'true' && + $str != '' ) { + array_push($columnSearch, [$i, $requestColumn['data'], $str]); + } + } + } + + return $columnSearch; +} + // Devuelve true si los intervalos (a1,a2) (b1,b2) se solapan // https://stackoverflow.com/questions/3269434/whats-the-most-efficient-way-to-test-if-two-ranges-overlap function check_overlap($a1, $a2, $b1, $b2){ diff --git a/ci4/app/Language/en/datePicker.php b/ci4/app/Language/en/datePicker.php new file mode 100644 index 00000000..9b0fd4c8 --- /dev/null +++ b/ci4/app/Language/en/datePicker.php @@ -0,0 +1,15 @@ + 'Today', + 'ayer' => 'Yesterday', + 'ultimos7' => 'Last 7 Days', + 'ultimos30' => 'Last 30 Days', + 'esteMes' => 'This Month', + 'ultimoMes' => 'Last Month', + 'personalizar' => 'Custom', + 'aplicar' => 'Apply', + 'limpiar' => 'Clear', +]; \ No newline at end of file diff --git a/ci4/app/Language/es/datePicker.php b/ci4/app/Language/es/datePicker.php new file mode 100644 index 00000000..2b3c0b68 --- /dev/null +++ b/ci4/app/Language/es/datePicker.php @@ -0,0 +1,15 @@ + 'Hoy', + 'ayer' => 'Ayer', + 'ultimos7' => 'Últimos 7 días', + 'ultimos30' => 'Últimos 30 días', + 'esteMes' => 'Este mes', + 'ultimoMes' => 'Último mes', + 'personalizar' => 'Personalizado', + 'aplicar' => 'Aplicar', + 'limpiar' => 'Limpiar', +]; \ No newline at end of file diff --git a/ci4/app/Models/Presupuestos/PresupuestoModel.php b/ci4/app/Models/Presupuestos/PresupuestoModel.php index f8d6bfa9..d0dcc543 100755 --- a/ci4/app/Models/Presupuestos/PresupuestoModel.php +++ b/ci4/app/Models/Presupuestos/PresupuestoModel.php @@ -18,13 +18,12 @@ class PresupuestoModel extends \App\Models\GoBaseModel 2 => "t2.nombre", 3 => "t3.first_name", 4 => "t1.titulo", - 5 => "t4.nombre", - 6 => "t5.nombre", - 7 => "t1.inc_rei", - 8 => "t1.paginas", - 9 => "t1.tirada", - 10 => "t1.total_pedido", - 11 => "t6.estado", + 5 => "t5.nombre", + 6 => "t1.inc_rei", + 7 => "t1.paginas", + 8 => "t1.tirada", + 9 => "t1.total_pedido", + 10 => "t6.estado", ]; protected $allowedFields = [ @@ -307,7 +306,7 @@ class PresupuestoModel extends \App\Models\GoBaseModel * * @return \CodeIgniter\Database\BaseBuilder */ - public function getResource(string $search = "") + public function getResource($search = []) { $builder = $this->db ->table($this->table . " t1") @@ -324,36 +323,22 @@ class PresupuestoModel extends \App\Models\GoBaseModel $builder->where("t1.is_deleted", 0); - return empty($search) - ? $builder - : $builder - ->groupStart() - ->like("t1.id", $search) - ->orLike("t1.created_at", $search) - ->orLike("t2.nombre", $search) - ->orLike("t3.first_name", $search) - ->orLike("t3.last_name", $search) - ->orLike("t1.titulo", $search) - ->orLike("t4.nombre", $search) - ->orLike("t5.nombre", $search) - ->orLike("t1.inc_rei", $search) - ->orLike("t1.paginas", $search) - ->orLike("t1.tirada", $search) - ->orLike("t1.total_pedido ", $search) - ->orLike("t6.estado", $search) - ->orLike("t1.id", $search) - ->orLike("t1.created_at", $search) - ->orLike("t2.nombre", $search) - ->orLike("t3.first_name", $search) - ->orLike("t3.last_name", $search) - ->orLike("t1.titulo", $search) - ->orLike("t4.nombre", $search) - ->orLike("t5.nombre", $search) - ->orLike("t1.inc_rei", $search) - ->orLike("t1.paginas", $search) - ->orLike("t1.tirada", $search) - ->orLike("t1.total_pedido ", $search) - ->orLike("t6.estado", $search) - ->groupEnd(); + 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/cosidotapablanda/viewCosidotapablandaList.php b/ci4/app/Views/themes/backend/vuexy/form/presupuestos/cosidotapablanda/viewCosidotapablandaList.php index 5ef811b7..deef7f2f 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 @@ -25,11 +25,11 @@ - - - + + + - + @@ -48,134 +48,149 @@ section('additionalInlineJs') ?> + + - const lastColNr = $('#tableOfPresupuestos').find("tr:first th").length - 1; - const actionBtns = function(data) { - return ` - -
- - -
- `; - }; +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{ + $(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(''); + } + +}); - // Setup - add a text input to each footer cell - $('#tableOfPresupuestos thead tr') - .clone(true) - .addClass('filters') - .appendTo('#tableOfPresupuestos thead'); - - - theTable = $('#tableOfPresupuestos').DataTable({ - orderCellsTop: 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": 'lfBrtip', - "buttons": [ - 'colvis', 'copy', 'csv', 'excel', 'print', { - extend: 'pdfHtml5', - orientation: 'landscape', - pageSize: 'A4' - } - ], - stateSave: true, - 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': '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 } - ], - initComplete: function () { - var api = this.api(); - $("#tableOfPresupuestos").DataTable().columns.adjust(); - - // For each column - api - .columns() - .eq(0) - .each(function (colIdx) { - // Set the header cell to contain the input element - var cell = $('.filters th').eq( - $(api.column(colIdx).header()).index() - ); - var title = $(cell).text(); - $(cell).html(''); - - // On every keypress in this input - $( - 'input', - $('.filters th').eq($(api.column(colIdx).header()).index()) - ) - .off('keyup change') - .on('change', function (e) { - // Get the search value - $(this).attr('title', $(this).val()); - var regexr = '({search})'; //$(this).parents('th').find('select').val(); - - var cursorPosition = this.selectionStart; - // Search the column for that value - api - .column(colIdx) - .search( - this.value != '' - ? regexr.replace('{search}', '(((' + this.value + ')))') - : '', - this.value != '', - this.value == '' - ) - .draw(); - }) - .on('keyup', function (e) { - e.stopPropagation(); - - $(this).trigger('change'); - $(this) - .focus()[0] - .setSelectionRange(cursorPosition, cursorPosition); - }); - }); - }, - }); +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": 'lBrtip', + "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': '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 () { @@ -242,6 +257,8 @@ $(document).on('click', '.btn-remove', function(e) { section('css') ?> + + endSection() ?> @@ -251,8 +268,12 @@ $(document).on('click', '.btn-remove', function(e) { + + + + diff --git a/httpdocs/themes/vuexy/css/sk-datatables.css b/httpdocs/themes/vuexy/css/sk-datatables.css index b7e25e5b..291a2963 100755 --- a/httpdocs/themes/vuexy/css/sk-datatables.css +++ b/httpdocs/themes/vuexy/css/sk-datatables.css @@ -102,3 +102,9 @@ div.draw-shapes { overflow-y: hidden; white-space: nowrap; } + +.column-input-search { + min-width: 100px; + max-width: 120px; + font-size: 0.8rem !important; +} \ No newline at end of file