diff --git a/ci4/app/Models/Clientes/ClientePreciosModel.php b/ci4/app/Models/Clientes/ClientePreciosModel.php index adeef70b..953eec5b 100755 --- a/ci4/app/Models/Clientes/ClientePreciosModel.php +++ b/ci4/app/Models/Clientes/ClientePreciosModel.php @@ -153,7 +153,7 @@ class ClientePreciosModel extends \App\Models\BaseModel // Se cargan los valores de la plantilla $plantillaModel = model('App\Models\Clientes\ClientePlantillaPreciosLineasModel'); - $values = $plantillaModel->getResource($plantilla_id)->get()->getResultObject(); + $values = $plantillaModel->getResource([],$plantilla_id)->get()->getResultObject(); foreach ($values as $value) { $this->db ->table($this->table . " t1") diff --git a/ci4/app/Views/themes/vuexy/form/clientes/plantillaprecios/viewClienteplantillapreciosForm.php b/ci4/app/Views/themes/vuexy/form/clientes/plantillaprecios/viewClienteplantillapreciosForm.php index 17d94304..1c161027 100644 --- a/ci4/app/Views/themes/vuexy/form/clientes/plantillaprecios/viewClienteplantillapreciosForm.php +++ b/ci4/app/Views/themes/vuexy/form/clientes/plantillaprecios/viewClienteplantillapreciosForm.php @@ -42,7 +42,7 @@
- @@ -75,282 +75,6 @@ endSection() ?> - - section('additionalInlineJs') ?> - /* - const lastColNr_lineas = $('#tableOfPlantillasPreciosLineas').find("tr:first th").length - 1; - - const url = window.location.href; - const url_parts = url.split('/'); - - let id = -1; - if(url_parts[url_parts.length-2] == 'edit'){ - id = url_parts[url_parts.length-1]; - } - - const actionBtns_lineas = function(data) { - return ` - - - - `; - }; - - - const tipo_linea = [ - {label:'', value:'interior'}, - {label:'', value: 'cubierta'}, - {label:'', value: 'sobrecubierta'} - ]; - - const tipo_maquina = [ - {label: '', value:'toner'}, - {label: '', value:'inkjet'}, - ]; - - const tipo_impresion = [ - {label: '', value:'negro'}, - {label: '', value:'negrohq'}, - {label: '', value:'color'}, - {label: '', value:'colorhq'}, - ]; - - var editor = new $.fn.dataTable.Editor( { - ajax: { - url: "", - headers: { - : v, - }, - }, - table : "#tableOfPlantillasPreciosLineas", - idSrc: 'id', - fields: [ { - name: "tipo", - type: "select", - options: tipo_linea - }, { - name: "tipo_maquina", - type: "select", - options: tipo_maquina - }, { - name: "tipo_impresion", - type: "select", - options: tipo_impresion - }, { - name: "tiempo_min" - }, { - name: "tiempo_max" - }, { - name: "precio_hora" - }, { - name: "margen" - }, { - name: "user_updated_id", - type:'hidden', - - }, { - name: "updated_at", - type:'hidden', - - }, { - "name": "plantilla_id", - "type": "hidden" - },{ - "name": "deleted_at", - "type": "hidden" - },{ - "name": "is_deleted", - "type": "hidden" - }, - ] - } ); - - editor.on( 'preSubmit', function ( e, d, type ) { - if ( type === 'create'){ - d.data[0]['plantilla_id'] = id; - } - else if(type === 'edit' ) { - for (v in d.data){ - d.data[v]['plantilla_id'] = id; - } - } - }); - - - editor.on( 'postSubmit', function ( e, json, data, action ) { - - yeniden(json.); - - const domain = window.location.origin - fetch(domain + "/clientes/clienteprecios/update/" + -1 , { - method: "POST", - body: JSON.stringify({ - plantilla_id: id, - : v - }), - headers: { - "Content-type": "application/json; charset=UTF-8" - } - }) - }); - - editor.on( 'submitSuccess', function ( e, json, data, action ) { - - theTable.clearPipeline(); - theTable.draw(); - }); - - - var theTable = $('#tableOfPlantillasPreciosLineas').DataTable( { - serverSide: true, - processing: true, - autoWidth: true, - responsive: true, - lengthMenu: [ 10, 25, 50, 100], - order: [[ 0, "asc" ], [ 1, "asc" ], [ 2, "asc" ], [ 3, "asc" ]], - pageLength: 50, - lengthChange: true, - searching: false, - paging: true, - info: false, - dom: '<"mt-4"><"float-end"B><"float-start"l> - <"mt-4 mb-3"p>', - ajax : $.fn.dataTable.pipeline( { - url: '', - data: { - plantilla_id: id, - }, - method: 'POST', - headers: {'X-Requested-With': 'XMLHttpRequest'}, - async: true, - }), - columns: [ - { 'data': 'tipo' , - 'render': function ( data, type, row, meta ) { - if(data=='interior') - return ''; - else if(data=='cubierta') - return ''; - else if(data=='sobrecubierta') - return ''; - } - }, - { 'data': 'tipo_maquina', - 'render': function ( data, type, row, meta ) { - if(data=='toner') - return ''; - else if(data=='inkjet') - return ''; - } - }, - { 'data': 'tipo_impresion', - 'render': function ( data, type, row, meta ) { - if(data=='negro') - return ''; - else if(data=='negrohq') - return ''; - else if(data=='color') - return ''; - else if(data=='colorhq') - return ''; - } - }, - { 'data': 'tiempo_min' }, - { 'data': 'tiempo_max' }, - { 'data': 'precio_hora' }, - { 'data': 'margen' }, - { 'data': 'user_updated_id', - 'render': function ( data, type, row, meta ) { - return row.user_updated - } - }, - { 'data': 'updated_at' }, - { - data: actionBtns_lineas, - className: 'row-edit dt-center' - } - ], - columnDefs: [ - { - orderable: false, - searchable: false, - targets: [lastColNr_lineas] - }, - {"orderData": [ 0, 1 ], "targets": 0 }, - - ], - language: { - url: "/themes/vuexy/vendor/libs/datatables-sk/plugins/i18n/es-ES.json" - }, - buttons: [ - { - extend: 'collection', - text: 'Exportar', - buttons:[ - 'copy', 'csv', 'excel', 'print', { - extend: 'pdfHtml5', - orientation: 'landscape', - pageSize: 'A4' - } - ] - }, - { - className: 'btn btn-primary me-sm-3 me-1', - extend: "createInline", - editor: editor, - formOptions: { - submitTrigger: -1, - submitHtml: '' - } - } ] - } ); - - - - // Activate an inline edit on click of a table cell - $('#tableOfPlantillasPreciosLineas').on( 'click', 'tbody span.edit', function (e) { - editor.inline( - theTable.cells(this.parentNode.parentNode, '*').nodes(), - { - cancelHtml: '', - cancelTrigger: 'span.cancel', - submitHtml: '', - submitTrigger: 'span.edit', - submit: 'allIfChanged' - } - ); - } ); - - - // Delete row - $(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: `/clientes/clienteplantillaprecioslineas/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') ?> diff --git a/httpdocs/assets/js/safekat/pages/cliente/tarifasCliente.js b/httpdocs/assets/js/safekat/pages/cliente/tarifasCliente.js index d973be42..6006e064 100644 --- a/httpdocs/assets/js/safekat/pages/cliente/tarifasCliente.js +++ b/httpdocs/assets/js/safekat/pages/cliente/tarifasCliente.js @@ -267,26 +267,36 @@ class tarifasClienteView { #changePlantilla() { - self = this; + const self = this; const data = $('#plantillas').select2('data'); if (data.length > 0) { - const id = data[0].id; - new Ajax( - '/clienteprecios/changeplantilla', - { - 'cliente_id': self.clienteId, - 'plantilla_id': id, - [this.csrf_token]: this.csrf_hash - }, - {}, - () => { - self.tableTarifas.table.clearPipeline(); - self.tableTarifas.table.draw(); - }, - (error) => { - console.log(error); - } - ).post(); + if (data[0].id == 0) { + self.#borrarPlantillaTarifa(self.clienteId); + self.tableTarifas.table.clearPipeline(); + self.tableTarifas.table.draw(); + + } + else { + + + const id = data[0].id; + new Ajax( + '/clienteprecios/changeplantilla', + { + 'cliente_id': self.clienteId, + 'plantilla_id': id, + [this.csrf_token]: this.csrf_hash + }, + {}, + () => { + self.tableTarifas.table.clearPipeline(); + self.tableTarifas.table.draw(); + }, + (error) => { + console.log(error); + } + ).post(); + } } diff --git a/httpdocs/assets/js/safekat/pages/plantillasTarifasCliente/edit.js b/httpdocs/assets/js/safekat/pages/plantillasTarifasCliente/edit.js index 03156c92..cbd17b78 100644 --- a/httpdocs/assets/js/safekat/pages/plantillasTarifasCliente/edit.js +++ b/httpdocs/assets/js/safekat/pages/plantillasTarifasCliente/edit.js @@ -15,6 +15,8 @@ class PlantillasTarifasClienteForm { this.csrf_token = getToken(); this.csrf_hash = $('#mainContainer').find('input[name="' + this.csrf_token + '"]').val(); + this.btnApply = $('#btnApply'); + this.tablePlantilla = null; this.deleteModal = null; @@ -22,6 +24,7 @@ class PlantillasTarifasClienteForm { this.ajaxEditor = null; this.changedRows = []; + this.deletedRows = []; } init() { @@ -50,7 +53,8 @@ class PlantillasTarifasClienteForm { submitHtml: '', cancelTrigger: row.find('span.cancel')[0], submitTrigger: row.find('span.edit')[0], - submit: 'allIfChanged' + submit: 'allIfChanged', + drawType: 'none' } ); }); @@ -123,47 +127,14 @@ class PlantillasTarifasClienteForm { this.ajaxEditor.init(); - this.localEditor.editor.on('postEdit', function (e, json, data) { - /*console.log(self.tablePlantilla.table.row(0).data()); - self.tablePlantilla.table.rows().every( function ( rowIdx ) { - var rowData = this.data(); - if(rowData.id == data.id){ - self.tablePlantilla.table.row(rowIdx).data({ - id: data.id, - tipo: 'interior', // 'interior', 'cubierta', etc. - tipo_maquina: 'toner', // 'toner', 'inkjet' - tipo_impresion: 'negro', // 'negro', 'color', etc. - tiempo_min: 0, - tiempo_max: 1, - precio_hora: 1, - margen: 100, - user_updated: 'yo', - updated_at: '200000' - }).draw(false); - } - }) - //self.tablePlantilla.table.row(0).data(data2).draw(false); - - /*self.tablePlantilla.table.row(0).data({ - id: 1, - tipo: 'interior', // 'interior', 'cubierta', etc. - tipo_maquina: 'toner', // 'toner', 'inkjet' - tipo_impresion: 'negro', // 'negro', 'color', etc. - tiempo_min: 0, - tiempo_max: 1, - precio_hora: 1, - margen: 100, - user_updated: 'yo', - updated_at: '200000' - }).draw(false);*/ let row = self.tablePlantilla.table.row('#' + data.id); + if (row.length) { - console.log('Data:', data) + let rowData = row.data(); - console.log('Datos de la fila:', rowData); - + // Actualizar los datos de la fila self.tablePlantilla.table.row('#' + data.id).data({ id: data.id, @@ -174,41 +145,15 @@ class PlantillasTarifasClienteForm { tiempo_max: data.tiempo_max, precio_hora: data.precio_hora, margen: "150", - user_updated_id: data.user_updated_id, + user_updated_id: data.user_updated, user_updated: data.user_updated, updated_at: data.updated_at - }).draw(true); // Usar invalidate() si es necesario - rowData = row.data(); - console.log('Datos de la fila actualizados:', rowData); - } else { - console.warn('No se encontrĂ³ la fila con ID row_' + data.id); - } - /* - if (row.length > 0) { - self.tablePlantilla.table.row(row[0]).data({ - id: data.id, - tipo: data.tipo, // 'interior', 'cubierta', etc. - tipo_maquina: data.tipo_maquina, // 'toner', 'inkjet' - tipo_impresion: data.tipo_impresion, // 'negro', 'color', etc. - tiempo_min: data.tiempo_min, - tiempo_max: data.tiempo_max, - precio_hora: data.precio_hora, - margen: data.margen, - user_updated: data.user_updated, - updated_at: data.updated_at - }).invalidate().draw(false); - - console.log('---'); - console.log(self.tablePlantilla.table.row(row[0]).data()) - }*/ + }); - - - // check if this id exists + // check if this id exists if (!self.changedRows.includes(data.id)) self.changedRows.push(data.id); - - + } }); /*