From e2942d73f2d7558c788d2f1641250d96cc0a516b Mon Sep 17 00:00:00 2001 From: dadaloop82 Date: Sun, 15 Mar 2026 18:44:53 +0000 Subject: [PATCH] =?UTF-8?q?USA:=20possibilit=C3=A0=20di=20spostare=20il=20?= =?UTF-8?q?prodotto=20in=20altra=20posizione=20dopo=20l'uso?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/js/app.js | 59 ++++++++++++++++++++++++++++++++++++++++++++++- data/dispensa.db | Bin 172032 -> 172032 bytes index.html | 12 +++++++++- 3 files changed, 69 insertions(+), 2 deletions(-) diff --git a/assets/js/app.js b/assets/js/app.js index 915b75f..9d4e69d 100644 --- a/assets/js/app.js +++ b/assets/js/app.js @@ -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 ``; }).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); } diff --git a/data/dispensa.db b/data/dispensa.db index eed68e5b4d4367a2fb31e4f7661d407dd9a026d5..7ad2c0fe160185165ad61bca9fa551acfa1f15bd 100644 GIT binary patch delta 677 zcmZoTz}0YoYr{5s#`BxE+xrSIpW`|*nLVJJiR;qjNdZ<&K;D^vE+($io5KP#I7Qi* z8JV0I&V#6OhI1fFpW*E0n^78~EPPE2^^;i(Dkj$#bTaWg-mEBanS1l?n&pga3=9lF zyt$*UhLNS7bGg7|j)uU=(GB%XysIYPY0zQfTn+3aC$l(XT2W?tzAjK?^Y&i+fSTWEZCT@&&QyyC>hvj%FhvPY|J~E{q2;= z4d=zD%hfXRPmh&kZ;_ zzaifnhI@R=`I7i#d2jGe=Jn&{;yK3C%wxy>i+dY)5w```7p{#{O&C3yXEV&6=qM}f zn8(S$D9)s4Y|K#(c0S{TsUI0NrGVC0SQ(l+>cXYA`GSf9M)-{Cq3}hw4IV=+9Ac?cvfx2&KGYj*)o6g?Aq{zl=%PY$B4ruTJ zo@kXue+~vlVNP*gW2gMm60l=2O}9{O^aCkl1S%^BDoeqk&Qzn(7pzW}*I0jg{tHG? Pc-R}7ZqMjtnjr)LUue6? delta 497 zcmZoTz}0YoYr{5s#xt9@+xrSIpXRzbnLVI;@{|Cp$rl2;Hpc{Ja86txz4>O8hA0aI z14F}P)`AMgrpYx0U7HmJE^}|bU9+5#jg^^^(aB+RM_mmgO9SU}-pL#dfsCsrM>I4r z@tm1_t3d~-c0R}E<(-1ea(tQ$>_CHfm}MDLGK&jR^NJH?Ihn;7(~2_F^BpE%>$$>< zET_A9d#`_x+B^on8@#W0zH?9F;^H)Cf6Z>eCdsP6_=DvzO9XQ{(-($$OzW6@CQdBc zJn>-^4}XC^FN3SK@S$xa+lK5nKZ}3j$_2cE@ImXk>W5@lAdmDEVw*}W1 zu8mxUQ;irsCkqH=IIZEnS{67hcF%0W)|Shn9kn7 QqzII7;N70l%QQm>00|A0rT_o{ diff --git a/index.html b/index.html index cef32fd..4ca0a66 100644 --- a/index.html +++ b/index.html @@ -275,6 +275,16 @@ + @@ -894,6 +904,6 @@ - +