arraglado bug tarifas cliente

This commit is contained in:
2024-12-04 14:08:37 +01:00
parent a7cda851f0
commit d02e7e03f4
4 changed files with 42 additions and 363 deletions

View File

@ -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")

View File

@ -42,7 +42,7 @@
<div id="accordionTip1" class="accordion-collapse collapse show" data-bs-parent="#accordionPreciosLineas">
<div class="accordion-body">
<button type="button" class="btn btn-primary d-none">
<button id="applyChanges" type="button" class="btn btn-primary">
Guardar y aplicar a clientes
</button>
<table id="tableOfPlantillasPreciosLineas" class="table table-striped table-hover" style="width: 100%;">
@ -75,282 +75,6 @@
<?= $this->endSection() ?>
<?php if (str_contains($formAction, 'edit')): ?>
<?= $this->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 `
<span class="edit"><a href="javascript:void(0);"><i class="ti ti-pencil ti-sm btn-edit mx-2"
data-id="${data.id}"></i></a></span>
<a href="javascript:void(0);"><i class="ti ti-trash ti-sm btn-delete mx-2" data-id="${data.id}" data-bs-toggle="modal"
data-bs-target="#confirm2delete"></i></a>
<span class="cancel"></span>
`;
};
const tipo_linea = [
{label:'<?= lang('ClientePrecios.interior') ?>', value:'interior'},
{label:'<?= lang('ClientePrecios.cubierta') ?>', value: 'cubierta'},
{label:'<?= lang('ClientePrecios.sobrecubierta') ?>', value: 'sobrecubierta'}
];
const tipo_maquina = [
{label: '<?= lang('ClientePrecios.toner') ?>', value:'toner'},
{label: '<?= lang('ClientePrecios.inkjet') ?>', value:'inkjet'},
];
const tipo_impresion = [
{label: '<?= lang('ClientePrecios.negro') ?>', value:'negro'},
{label: '<?= lang('ClientePrecios.negrohq') ?>', value:'negrohq'},
{label: '<?= lang('ClientePrecios.color') ?>', value:'color'},
{label: '<?= lang('ClientePrecios.colorhq') ?>', value:'colorhq'},
];
var editor = new $.fn.dataTable.Editor( {
ajax: {
url: "<?= route_to('editorOfClienteplantillaprecioslineas') ?>",
headers: {
<?= csrf_token() ?? "token" ?> : <?= csrf_token() ?>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.<?= csrf_token() ?>);
const domain = window.location.origin
fetch(domain + "/clientes/clienteprecios/update/" + -1 , {
method: "POST",
body: JSON.stringify({
plantilla_id: id,
<?= csrf_token() ?? "token" ?> : <?= csrf_token() ?>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>
<t><"mt-4 mb-3"p>',
ajax : $.fn.dataTable.pipeline( {
url: '<?= route_to('dataTableOfClientesplantillaprecioslineas') ?>',
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 '<?= lang('ClientePrecios.interior') ?>';
else if(data=='cubierta')
return '<?= lang('ClientePrecios.cubierta') ?>';
else if(data=='sobrecubierta')
return '<?= lang('ClientePrecios.sobrecubierta') ?>';
}
},
{ 'data': 'tipo_maquina',
'render': function ( data, type, row, meta ) {
if(data=='toner')
return '<?= lang('ClientePrecios.toner') ?>';
else if(data=='inkjet')
return '<?= lang('ClientePrecios.inkjet') ?>';
}
},
{ 'data': 'tipo_impresion',
'render': function ( data, type, row, meta ) {
if(data=='negro')
return '<?= lang('ClientePrecios.negro') ?>';
else if(data=='negrohq')
return '<?= lang('ClientePrecios.negrohq') ?>';
else if(data=='color')
return '<?= lang('ClientePrecios.color') ?>';
else if(data=='colorhq')
return '<?= lang('ClientePrecios.colorhq') ?>';
}
},
{ '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: '<a href="javascript:void(0);"><i class="ti ti-device-floppy"></i></a>'
}
} ]
} );
// 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: '<a href="javascript:void(0);"><i class="ti ti-x"></i></a>',
cancelTrigger: 'span.cancel',
submitHtml: '<a href="javascript:void(0);"><i class="ti ti-device-floppy"></i></a>',
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)
})
}
});
*/
<?= $this->endSection() ?>
<?php endif; ?>
<?= $this->section('css') ?>
<link rel="stylesheet"
href="<?= site_url('themes/vuexy/css/datatables-editor/editor.dataTables.min.css') ?>">

View File

@ -267,9 +267,18 @@ class tarifasClienteView {
#changePlantilla() {
self = this;
const self = this;
const data = $('#plantillas').select2('data');
if (data.length > 0) {
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',
@ -288,6 +297,7 @@ class tarifasClienteView {
}
).post();
}
}
}

View File

@ -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: '<a href="javascript:void(0);"><i class="ti ti-device-floppy"></i></a>',
cancelTrigger: row.find('span.cancel')[0],
submitTrigger: row.find('span.edit')[0],
submit: 'allIfChanged'
submit: 'allIfChanged',
drawType: 'none'
}
);
});
@ -123,46 +127,13 @@ 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({
@ -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
if (!self.changedRows.includes(data.id))
self.changedRows.push(data.id);
}
});
/*