USA: possibilità di spostare il prodotto in altra posizione dopo l'uso

This commit is contained in:
dadaloop82
2026-03-15 18:44:53 +00:00
parent f9910c99b5
commit e2942d73f2
3 changed files with 69 additions and 2 deletions
+58 -1
View File
@@ -3206,6 +3206,8 @@ function showUseForm() {
document.getElementById('use-quantity').value = 1; document.getElementById('use-quantity').value = 1;
document.getElementById('use-location').value = 'dispensa'; document.getElementById('use-location').value = 'dispensa';
document.getElementById('use-unit-switch').style.display = 'none'; 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 // Reset location buttons
document.querySelectorAll('#page-use .loc-btn').forEach(b => b.classList.remove('active')); 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>`; return `<button type="button" class="loc-btn ${loc === firstLoc ? 'active' : ''}" onclick="selectUseLocation(this, '${loc}')">${locInfo.icon} ${locInfo.label} (${qtyLabel})</button>`;
}).join(''); }).join('');
// Show move-to section
updateUseMoveOptions();
const unit = items[0].unit || 'pz'; const unit = items[0].unit || 'pz';
const pkgSize = parseFloat(items[0].default_quantity) || 0; const pkgSize = parseFloat(items[0].default_quantity) || 0;
const pkgUnit = items[0].package_unit || ''; 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.parentElement.querySelectorAll('.loc-btn').forEach(b => b.classList.remove('active'));
btn.classList.add('active'); btn.classList.add('active');
document.getElementById('use-location').value = loc; 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() { async function submitUseAll() {
showLoading(true); showLoading(true);
try { try {
const moveTo = document.getElementById('use-move-location')?.value;
const moveFrom = document.getElementById('use-location').value;
const result = await api('inventory_use', {}, 'POST', { const result = await api('inventory_use', {}, 'POST', {
product_id: currentProduct.id, product_id: currentProduct.id,
use_all: true, use_all: true,
location: document.getElementById('use-location').value, location: moveFrom,
}); });
showLoading(false); showLoading(false);
if (result.success) { if (result.success) {
@@ -3415,6 +3465,13 @@ async function submitUse(e) {
if (result.success) { if (result.success) {
const usedText = displayUnit ? `${displayQty}${displayUnit}` : displayQty; const usedText = displayUnit ? `${displayQty}${displayUnit}` : displayQty;
showToast(`📤 Usato ${usedText} di ${currentProduct.name}`, 'success'); 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) { if (result.added_to_bring) {
setTimeout(() => showToast('🛒 Prodotto finito → aggiunto a Bring!', 'info'), 1500); setTimeout(() => showToast('🛒 Prodotto finito → aggiunto a Bring!', 'info'), 1500);
} }
BIN
View File
Binary file not shown.
+11 -1
View File
@@ -275,6 +275,16 @@
</div> </div>
</div> </div>
</div> </div>
<div class="form-group" id="use-move-group" style="display:none">
<label>📦 Sposta il resto in:</label>
<div class="location-selector" id="use-move-location-selector">
<button type="button" class="loc-btn" onclick="selectUseMoveLocation(this, 'dispensa')">🗄️ Dispensa</button>
<button type="button" class="loc-btn" onclick="selectUseMoveLocation(this, 'frigo')">🧊 Frigo</button>
<button type="button" class="loc-btn" onclick="selectUseMoveLocation(this, 'freezer')">❄️ Freezer</button>
<button type="button" class="loc-btn" onclick="selectUseMoveLocation(this, 'altro')">📦 Altro</button>
</div>
<input type="hidden" id="use-move-location" value="">
</div>
</form> </form>
</section> </section>
@@ -894,6 +904,6 @@
</div> </div>
</div> </div>
<script src="assets/js/app.js?v=20260315g"></script> <script src="assets/js/app.js?v=20260315h"></script>
</body> </body>
</html> </html>