Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Core/Translation/es_ES.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"add-user": "Añadir usuario",
"additional-text": "Texto adicional",
"address": "Dirección",
"address-changed-save-msg": "La dirección ha sido actualizada. No olvides guardar el documento para aplicar los cambios.",
"addresses": "Direcciones",
"addresses-and-contacts": "Direcciones y contactos",
"admin": "Administrador",
Expand Down
71 changes: 71 additions & 0 deletions Core/View/Tab/PurchasesDocument.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,66 @@
<script>
let waitCounter = 0;
let keyupInputName = null;
let addressChanged = false;

function showAddressChangeWarning() {
// 1. Inyectar el CSS con el pulso verde fluorescente
if (!document.getElementById('css-animacion-guardar')) {
const style = document.createElement('style');
style.id = 'css-animacion-guardar';
style.innerHTML = `
@keyframes pulse-green {
0% {
box-shadow: 0 0 0 0 rgba(0, 255, 0, 0.8);
}
70% {
box-shadow: 0 0 0 15px rgba(0, 255, 0, 0);
}
100% {
box-shadow: 0 0 0 0 rgba(0, 255, 0, 0);
}
}
.btn-animacion-no-guardado {
animation: pulse-green 1.5s infinite !important;
border: 2px solid #00ff00 !important;
position: relative;
z-index: 1;
}
.btn-animacion-no-guardado:active {
transform: scale(0.92);
animation: none !important;
}
`;
document.head.appendChild(style);
}

// 2. Lógica del Warning (Alert)
let warningDiv = document.getElementById('addressChangeWarning');
if (!warningDiv) {
const warningDivContainer = document.createElement('div');
warningDivContainer.className = 'container-fluid';

warningDiv = document.createElement('div');
warningDiv.id = 'addressChangeWarning';
warningDiv.className = 'alert alert-warning mt-2 mb-2 shadow-sm';
warningDiv.innerHTML = '<i class="fa-solid fa-circle-info fa-fw"></i> {{ trans("address-changed-save-msg") }}';

warningDivContainer.appendChild(warningDiv);
const formHeader = document.getElementById('purchasesFormHeader');
if (formHeader) {
formHeader.insertBefore(warningDivContainer, formHeader.firstChild);
}
}

// 3. Aplicar la clase al botón de guardado
const saveBtn = document.querySelector('#purchasesFormFooter .btn-primary i.fa-save')?.closest('.btn-primary');
if (saveBtn) {
// Si el botón ya tiene la clase, no hacemos nada para no reiniciar la animación
if (!saveBtn.classList.contains('btn-animacion-no-guardado')) {
saveBtn.classList.add('btn-animacion-no-guardado');
}
}
}

function changeColumn(btn) {
$(btn).addClass('active').siblings().removeClass('active');
Expand Down Expand Up @@ -74,6 +134,11 @@
animateSpinner('add');
$('#headerModal').modal('hide');

// Comprobar si el cliente ha cambiado y mostrar el warning
if (action === 'set-supplier') {
addressChanged = true;
}

document.forms['purchasesForm']['action'].value = action;
document.forms['purchasesForm']['selectedLine'].value = selectedLine;

Expand Down Expand Up @@ -120,6 +185,12 @@
if (Array.isArray(data.messages)) {
data.messages.forEach(item => alert(item.message));
}

// Mostrar la alerta de cambios en cliente
if (addressChanged) {
showAddressChangeWarning();
}

switch (document.forms['purchasesForm']['action'].value) {
case 'add-product':
case 'fast-product':
Expand Down
72 changes: 71 additions & 1 deletion Core/View/Tab/SalesDocument.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,66 @@
<script>
let waitCounter = 0;
let keyupInputName = null;
let addressChanged = false;

function showAddressChangeWarning() {
// 1. Inyectar el CSS con el pulso verde fluorescente
if (!document.getElementById('css-animacion-guardar')) {
const style = document.createElement('style');
style.id = 'css-animacion-guardar';
style.innerHTML = `
@keyframes pulse-green {
0% {
box-shadow: 0 0 0 0 rgba(0, 255, 0, 0.8);
}
70% {
box-shadow: 0 0 0 15px rgba(0, 255, 0, 0);
}
100% {
box-shadow: 0 0 0 0 rgba(0, 255, 0, 0);
}
}
.btn-animacion-no-guardado {
animation: pulse-green 1.5s infinite !important;
border: 2px solid #00ff00 !important;
position: relative;
z-index: 1;
}
.btn-animacion-no-guardado:active {
transform: scale(0.92);
animation: none !important;
}
`;
document.head.appendChild(style);
}

// 2. Lógica del Warning (Alert)
let warningDiv = document.getElementById('addressChangeWarning');
if (!warningDiv) {
const warningDivContainer = document.createElement('div');
warningDivContainer.className = 'container-fluid';

warningDiv = document.createElement('div');
warningDiv.id = 'addressChangeWarning';
warningDiv.className = 'alert alert-warning mt-2 mb-2 shadow-sm';
warningDiv.innerHTML = '<i class="fa-solid fa-circle-info fa-fw"></i> {{ trans("address-changed-save-msg") }}';

warningDivContainer.appendChild(warningDiv);
const formHeader = document.getElementById('salesFormHeader');
if (formHeader) {
formHeader.insertBefore(warningDivContainer, formHeader.firstChild);
}
}

// 3. Aplicar la clase al botón de guardado
const saveBtn = document.querySelector('#salesFormFooter .btn-primary i.fa-save')?.closest('.btn-primary');
if (saveBtn) {
// Si el botón ya tiene la clase, no hacemos nada para no reiniciar la animación
if (!saveBtn.classList.contains('btn-animacion-no-guardado')) {
saveBtn.classList.add('btn-animacion-no-guardado');
}
}
}

function changeColumn(btn) {
$(btn).addClass('active').siblings().removeClass('active');
Expand Down Expand Up @@ -72,7 +132,11 @@

function salesFormAction(action, selectedLine) {
animateSpinner('add');
$('#headerModal').modal('hide');

// Comprobar si el cliente ha cambiado y mostrar el warning
if (action === 'set-customer') {
addressChanged = true;
}

document.forms['salesForm']['action'].value = action;
document.forms['salesForm']['selectedLine'].value = selectedLine;
Expand Down Expand Up @@ -120,6 +184,12 @@
if (Array.isArray(data.messages)) {
data.messages.forEach(item => alert(item.message));
}

// Mostrar la alerta de cambios en cliente
if (addressChanged) {
showAddressChangeWarning();
}

switch (document.forms['salesForm']['action'].value) {
case 'add-product':
case 'fast-product':
Expand Down
Loading