USA: possibilità di spostare il prodotto in altra posizione dopo l'uso
This commit is contained in:
+58
-1
@@ -3206,6 +3206,8 @@ function showUseForm() {
|
||||
document.getElementById('use-quantity').value = 1;
|
||||
document.getElementById('use-location').value = 'dispensa';
|
||||
document.getElementById('use-unit-switch').style.display = 'none';
|
||||
document.getElementById('use-move-group').style.display = 'none';
|
||||
document.getElementById('use-move-location').value = '';
|
||||
|
||||
// Reset location buttons
|
||||
document.querySelectorAll('#page-use .loc-btn').forEach(b => b.classList.remove('active'));
|
||||
@@ -3262,6 +3264,9 @@ async function loadUseInventoryInfo() {
|
||||
return `<button type="button" class="loc-btn ${loc === firstLoc ? 'active' : ''}" onclick="selectUseLocation(this, '${loc}')">${locInfo.icon} ${locInfo.label} (${qtyLabel})</button>`;
|
||||
}).join('');
|
||||
|
||||
// Show move-to section
|
||||
updateUseMoveOptions();
|
||||
|
||||
const unit = items[0].unit || 'pz';
|
||||
const pkgSize = parseFloat(items[0].default_quantity) || 0;
|
||||
const pkgUnit = items[0].package_unit || '';
|
||||
@@ -3364,15 +3369,60 @@ function selectUseLocation(btn, loc) {
|
||||
btn.parentElement.querySelectorAll('.loc-btn').forEach(b => b.classList.remove('active'));
|
||||
btn.classList.add('active');
|
||||
document.getElementById('use-location').value = loc;
|
||||
// Reset move location when source changes
|
||||
updateUseMoveOptions();
|
||||
}
|
||||
|
||||
function updateUseMoveOptions() {
|
||||
const currentLoc = document.getElementById('use-location').value;
|
||||
const moveGroup = document.getElementById('use-move-group');
|
||||
const moveSelector = document.getElementById('use-move-location-selector');
|
||||
// Show move section and disable the current source location
|
||||
moveGroup.style.display = 'block';
|
||||
document.getElementById('use-move-location').value = '';
|
||||
moveSelector.querySelectorAll('.loc-btn').forEach(b => {
|
||||
b.classList.remove('active');
|
||||
const btnLoc = b.getAttribute('onclick')?.match(/'([^']+)'/)?.[1];
|
||||
b.style.display = btnLoc === currentLoc ? 'none' : '';
|
||||
});
|
||||
}
|
||||
|
||||
function selectUseMoveLocation(btn, loc) {
|
||||
const moveSelector = document.getElementById('use-move-location-selector');
|
||||
const wasActive = btn.classList.contains('active');
|
||||
moveSelector.querySelectorAll('.loc-btn').forEach(b => b.classList.remove('active'));
|
||||
if (!wasActive) {
|
||||
btn.classList.add('active');
|
||||
document.getElementById('use-move-location').value = loc;
|
||||
} else {
|
||||
document.getElementById('use-move-location').value = '';
|
||||
}
|
||||
}
|
||||
|
||||
async function moveInventoryLocation(productId, fromLoc, toLoc) {
|
||||
try {
|
||||
const data = await api('inventory_list');
|
||||
const item = (data.inventory || []).find(i => i.product_id == productId && i.location === fromLoc && parseFloat(i.quantity) > 0);
|
||||
if (!item) return;
|
||||
await api('inventory_update', {}, 'POST', {
|
||||
id: item.id,
|
||||
location: toLoc,
|
||||
product_id: productId,
|
||||
});
|
||||
} catch (e) {
|
||||
console.error('Move inventory error:', e);
|
||||
}
|
||||
}
|
||||
|
||||
async function submitUseAll() {
|
||||
showLoading(true);
|
||||
try {
|
||||
const moveTo = document.getElementById('use-move-location')?.value;
|
||||
const moveFrom = document.getElementById('use-location').value;
|
||||
const result = await api('inventory_use', {}, 'POST', {
|
||||
product_id: currentProduct.id,
|
||||
use_all: true,
|
||||
location: document.getElementById('use-location').value,
|
||||
location: moveFrom,
|
||||
});
|
||||
showLoading(false);
|
||||
if (result.success) {
|
||||
@@ -3415,6 +3465,13 @@ async function submitUse(e) {
|
||||
if (result.success) {
|
||||
const usedText = displayUnit ? `${displayQty}${displayUnit}` : displayQty;
|
||||
showToast(`📤 Usato ${usedText} di ${currentProduct.name}`, 'success');
|
||||
// Move remaining to new location if selected
|
||||
const moveTo = document.getElementById('use-move-location')?.value;
|
||||
const moveFrom = document.getElementById('use-location').value;
|
||||
if (moveTo && moveTo !== moveFrom && result.remaining > 0) {
|
||||
await moveInventoryLocation(currentProduct.id, moveFrom, moveTo);
|
||||
setTimeout(() => showToast(`📦 Spostato in ${LOCATIONS[moveTo]?.label || moveTo}`, 'info'), 1200);
|
||||
}
|
||||
if (result.added_to_bring) {
|
||||
setTimeout(() => showToast('🛒 Prodotto finito → aggiunto a Bring!', 'info'), 1500);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user