diff --git a/ci4/app/Models/Clientes/ClientePreciosModel.php b/ci4/app/Models/Clientes/ClientePreciosModel.php
index 3bfbdb1d..eb76141d 100755
--- a/ci4/app/Models/Clientes/ClientePreciosModel.php
+++ b/ci4/app/Models/Clientes/ClientePreciosModel.php
@@ -14,14 +14,14 @@ class ClientePreciosModel extends \App\Models\BaseModel
protected $useAutoIncrement = true;
const SORTABLE = [
- 0 => "t1.tipo",
- 1 => "t1.tipo_maquina",
- 2 => "t1.tipo_impresion",
- 3 => "t1.tiempo_min",
- 4 => "t1.tiempo_max",
- 5 => "t1.precio_hora",
- 6 => "t1.margen",
-
+ 0 => "t1.id",
+ 1 => "t1.tipo",
+ 2 => "t1.tipo_maquina",
+ 3 => "t1.tipo_impresion",
+ 4 => "t1.tiempo_min",
+ 5 => "t1.tiempo_max",
+ 6 => "t1.precio_hora",
+ 7 => "t1.margen",
];
protected $allowedFields = [
@@ -277,10 +277,10 @@ class ClientePreciosModel extends \App\Models\BaseModel
else {
$builder->groupStart();
foreach ($search as $col_search) {
- if ($col_search[0] > 2)
- $builder->like(self::SORTABLE[$col_search[0]], $col_search[2]);
- else
+ if ($col_search[0] > 0 && $col_search[0] < 4)
$builder->where(self::SORTABLE[$col_search[0]], $col_search[2]);
+ else
+ $builder->like(self::SORTABLE[$col_search[0]], $col_search[2]);
}
$builder->groupEnd();
return $builder;
diff --git a/ci4/app/Views/themes/vuexy/form/clientes/cliente/_clienteFormItems.php b/ci4/app/Views/themes/vuexy/form/clientes/cliente/_clienteFormItems.php
index dc3e7967..92c184d8 100644
--- a/ci4/app/Views/themes/vuexy/form/clientes/cliente/_clienteFormItems.php
+++ b/ci4/app/Views/themes/vuexy/form/clientes/cliente/_clienteFormItems.php
@@ -584,6 +584,7 @@
+ | ID |
= lang('ClientePrecios.tipo') ?> |
= lang('ClientePrecios.tipo_maquina') ?> |
= lang('ClientePrecios.tipo_impresion') ?> |
diff --git a/ci4/app/Views/themes/vuexy/form/clientes/cliente/viewClienteForm.php b/ci4/app/Views/themes/vuexy/form/clientes/cliente/viewClienteForm.php
index a149252e..84a2ea39 100644
--- a/ci4/app/Views/themes/vuexy/form/clientes/cliente/viewClienteForm.php
+++ b/ci4/app/Views/themes/vuexy/form/clientes/cliente/viewClienteForm.php
@@ -1,6 +1,7 @@
= $this->include("themes/_commonPartialsBs/datatables") ?>
= $this->include("themes/_commonPartialsBs/select2bs5") ?>
= $this->include("themes/_commonPartialsBs/sweetalert") ?>
+= $this->include('themes/_commonPartialsBs/_confirm2delete') ?>
=$this->extend('themes/vuexy/main/defaultlayout') ?>
= $this->section("content") ?>
diff --git a/httpdocs/assets/js/safekat/components/ConfirmDeleteModal.js b/httpdocs/assets/js/safekat/components/ConfirmDeleteModal.js
new file mode 100644
index 00000000..a874abf7
--- /dev/null
+++ b/httpdocs/assets/js/safekat/components/ConfirmDeleteModal.js
@@ -0,0 +1,51 @@
+class ConfirmDeleteModal {
+ constructor(alias = "") {
+ this.modalId = 'confirm2delete';
+
+ const removeClass = alias !== "" ? `btn-remove-${alias}` : 'btn-remove';
+
+ this.modalHtml = `
+
+
+
+
+
+ Esta acción no se puede deshacer.
+
+
+
+
+
+ `;
+ }
+
+ // Método para mostrar el modal
+ show(callback) {
+ // Insertar el modal en el body del documento si no existe
+ if (!document.getElementById(this.modalId)) {
+ document.body.insertAdjacentHTML('beforeend', this.modalHtml);
+ }
+
+ // Mostrar el modal usando Bootstrap
+ const modal = new bootstrap.Modal(document.getElementById(this.modalId));
+ modal.show();
+
+ // Configurar el evento de confirmación de eliminación
+ document.getElementById('confirmDelete').addEventListener('click', () => {
+ callback(); // Llamar al callback que el usuario haya proporcionado
+ modal.hide(); // Cerrar el modal
+ });
+ }
+
+ // Método para ocultar el modal si es necesario
+ hide() {
+ const modal = new bootstrap.Modal(document.getElementById(this.modalId));
+ modal.hide();
+ }
+}
diff --git a/httpdocs/assets/js/safekat/components/table.js b/httpdocs/assets/js/safekat/components/table.js
index 83ea0bee..2f3c8eb3 100644
--- a/httpdocs/assets/js/safekat/components/table.js
+++ b/httpdocs/assets/js/safekat/components/table.js
@@ -156,19 +156,21 @@ let Table = function (
this.actionBtns = function (data) {
let btns = ``;
if (this.actions.includes('view')) {
- btns += ``;
+ btns += ``;
}
if (this.actions.includes('edit')) {
btns += ``;
}
- if (this.actions.includes('delete')) {
- btns += ``;
- }
if (this.actions.includes('cancel')) {
btns += ``;
}
+ if (this.actions.includes('delete')) {
+ btns += ``;
+ }
+
return btns;
};
+
}
diff --git a/httpdocs/assets/js/safekat/components/tableEditor.js b/httpdocs/assets/js/safekat/components/tableEditor.js
index 89b12369..c0a5c370 100644
--- a/httpdocs/assets/js/safekat/components/tableEditor.js
+++ b/httpdocs/assets/js/safekat/components/tableEditor.js
@@ -23,7 +23,7 @@ let TableEditor = function (
},
table : table,
idSrc: idSrc,
- fields: fields
+ fields: fields,
});
};
}
diff --git a/httpdocs/assets/js/safekat/pages/cliente/tarifasCliente.js b/httpdocs/assets/js/safekat/pages/cliente/tarifasCliente.js
index 5e6ad756..be539820 100644
--- a/httpdocs/assets/js/safekat/pages/cliente/tarifasCliente.js
+++ b/httpdocs/assets/js/safekat/pages/cliente/tarifasCliente.js
@@ -1,5 +1,6 @@
import Table from '../../components/table.js';
import TableEditor from '../../components/tableEditor.js';
+import Confirm2Delete from '../../components/confirm2delete.js';
import { getToken } from '../../common/common.js';
@@ -13,18 +14,51 @@ class tarifasClienteView {
this.csrf_hash = $('#mainContainer').find('input[name="' + this.csrf_token + '"]').val();
this.clienteId = window.location.href.split("/").pop();
- this.actions = ['edit', 'delete'];
+ this.actions = ['edit', 'delete', 'cancel'];
this.headerSearcher();
this.tableTarifas = null;
this.editorTarifas = null;
+ this.confirmDeleteModal = null;
}
init() {
const self = this;
+ this.#initEditor();
+
+ this.#initTable();
+
+
+ // Editar en linea la fila
+ this.tableTarifas.table.on('click', 'tbody span.edit', function (e) {
+
+ const row = $(this).closest('tr');
+
+ // Iniciar la edición en línea para todas las celdas de la fila
+ self.editorTarifas.editor.inline(
+ self.tableTarifas.table.cells(row, '*').nodes(),
+ {
+ cancelHtml: '',
+ submitHtml: '',
+ cancelTrigger: row.find('span.cancel')[0],
+ submitTrigger: row.find('span.edit')[0],
+ submit: 'allIfChanged'
+ }
+ );
+ });
+
+
+
+ }
+
+
+ #initEditor() {
+
+ const self = this;
+
const tipo_linea = [
{ label: window.language.ClientePrecios.interior, value: 'interior' },
{ label: window.language.ClientePrecios.cubierta, value: 'cubierta' },
@@ -43,120 +77,111 @@ class tarifasClienteView {
{ label: window.language.ClientePrecios.colorhq, value: 'colorhq' },
];
- const editorFields = [{
- 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',
+ const editorFields = [
+ {
+ name: "id",
+ type: "readonly"
+ }, {
+ 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: "updated_at",
+ type: 'hidden',
- }, {
- "name": "plantilla_id",
- "type": "hidden"
- }, {
- "name": "cliente_id",
- "type": "hidden"
- }, {
- "name": "deleted_at",
- "type": "hidden"
- }, {
- "name": "is_deleted",
- "type": "hidden"
- },
+ }, {
+ name: "plantilla_id",
+ type: "hidden"
+ }, {
+ name: "cliente_id",
+ type: "hidden"
+ }, {
+ name: "deleted_at",
+ type: "hidden"
+ }, {
+ name: "is_deleted",
+ type: "hidden"
+ },
];
this.editorTarifas = new TableEditor(
$('#tableOfPrecios'),
'/clienteprecios/datatable_editor',
{ [this.csrf_token]: this.csrf_hash },
+ 'id',
editorFields);
this.editorTarifas.init();
this.editorTarifas.editor.on('preSubmit', function (e, d, type) {
if (type === 'create') {
- d.data[0]['cliente_id'] = this.clienteId;
- }
- else if (type === 'edit') {
- for (v in d.data) {
- d.data[v]['cliente_id'] = this.clienteId;
- }
+ d.data[0]['cliente_id'] = self.clienteId;
}
});
this.editorTarifas.editor.on('submitSuccess', function (e, json, data, action) {
- this.tableTarifas.table.clearPipeline();
- this.tableTarifas.table.draw();
+ self.tableTarifas.table.clearPipeline();
+ self.tableTarifas.table.draw();
});
+
this.editorTarifas.editor.on('postEdit', function (e, json, data, action) {
- /*const domain = window.location.origin
- fetch(domain + "/clientes/clienteprecios/update/" + id, {
- method: "POST",
- body: JSON.stringify({
- = csrf_token() ?? "token" ?> : = csrf_token() ?> v
- }),
- headers: {
- "Content-type": "application/json; charset=UTF-8"
- }
- })*/
+ self.#borrarPlantillaTarifa(self.clienteId);
})
this.editorTarifas.editor.on('postCreate', function (e, json, data, action) {
- const domain = window.location.origin
- /*fetch(domain + "/clientes/clienteprecios/update/" + id, {
- method: "POST",
- body: JSON.stringify({
- = csrf_token() ?? "token" ?> : = csrf_token() ?> v
- }),
- headers: {
- "Content-type": "application/json; charset=UTF-8"
- }
- })*/
+ self.#borrarPlantillaTarifa(self.clienteId);
})
- this.#initTable();
- this.tableTarifas.table.on( 'click', 'tbody span.edit', function (e) {
- self.editorTarifas.editor.inline(
- self.tableTarifas.table.cells(this.parentNode.parentNode, '*').nodes(),
- {
- cancelHtml: '',
- cancelTrigger: 'span.cancel',
- submitHtml: '',
- submitTrigger: 'span.edit',
- submit: 'allIfChanged'
- }
- );
- } );
+ this.editorTarifas.editor.on('postCancel', function (e, json, data) {
+ // Restaurar botones de acción por fila
+ self.tableTarifas.table.rows().nodes().each(function (node) {
+ $(node).find('span.edit').removeClass('d-none');
+ $(node).find('span.cancel, span.submit').addClass('d-none');
+ });
+ });
}
+ #borrarPlantillaTarifa(id) {
+
+ const domain = window.location.origin
+ fetch(domain + "/clientes/clienteprecios/update/" + id, {
+ method: "POST",
+ body: JSON.stringify({
+ [self.csrf_token]: self.csrf_hash
+ }),
+ headers: {
+ "Content-type": "application/json; charset=UTF-8"
+ }
+ })
+ }
#initTable() {
const self = this;
const columns = [
+ { 'data': 'id' },
{
'data': 'tipo',
'render': function (data, type, row, meta) {
@@ -217,10 +242,11 @@ class tarifasClienteView {
this.tableTarifas.init({
- actions: ['edit', 'delete'],
+ actions: self.actions,
buttonNewWithEditor: true,
buttonsExport: true,
editor: this.editorTarifas.editor,
+ deleteModal: '#confirm2delete'
});
@@ -245,7 +271,7 @@ class tarifasClienteView {
if (!$(this).hasClass("noFilter")) {
- if (i == 0) {
+ if (i == 1) {
// Agregar un selector en la segunda columna
$(this).html('');
@@ -266,7 +292,7 @@ class tarifasClienteView {
}
- else if (i == 1) {
+ else if (i == 2) {
// Agregar un selector en la tercera columna
$(this).html('');
@@ -284,7 +310,7 @@ class tarifasClienteView {
});
}
- else if (i == 2) {
+ else if (i == 3) {
// Agregar un selector en la cuarta columna
$(this).html('');