Files
ploxion-stock/app.blade.php

39 lines
7.1 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
{{-- PL0XI0N stock 🧻 — CONSOMMABLES & COURSES de la zone (RS-7 11.09). Sur jOSLedger (cat conso/bouffe) :
stock avec seuil (± en un tap), sous le seuil → liste de courses ; « acheté » = +qté ; pack
de départ appart. Le frigo/cuisine existants restent sur jOSBouffe ; ici c'est la maison entière. --}}
<script>
(function () {
var ID = 'stock';
var PACK = [['Papier toilette', 'rouleaux', 12, 4, 'conso'], ['Sacs poubelle', 'sacs', 20, 5, 'conso'], ['Lessive', 'lavages', 20, 5, 'conso'], ['Liquide vaisselle', 'flacons', 1, 1, 'conso'], ['Éponges', 'pièces', 3, 1, 'conso'], ['Savon / gel douche', 'flacons', 1, 1, 'conso'], ['Dentifrice', 'tubes', 1, 1, 'conso'], ['Essuie-tout', 'rouleaux', 2, 1, 'conso'], ['Ampoules', 'pièces', 2, 1, 'conso'], ['Piles AA', 'pièces', 4, 2, 'conso'], ['Sel', 'kg', 1, 0.2, 'bouffe'], ['Huile', 'L', 1, 0.3, 'bouffe'], ['Pâtes', 'kg', 2, 0.5, 'bouffe'], ['Riz', 'kg', 1, 0.5, 'bouffe'], ['Café', 'paquets', 1, 1, 'bouffe'], ['Lait', 'L', 2, 1, 'bouffe'], ['Œufs', 'pièces', 6, 4, 'bouffe']];
function mount(container, ctx) {
var C = window.jOSCiv, U = C.ui; U.style(); container.classList.add('cv'); container.style.position = 'relative';
var Z = (ctx && ctx.zone && jOSZone.get(ctx.zone.id)) || jOSZone.current(); if (!Z) { container.innerHTML = '<div class="cv__empty">aucune zone — ouvre 🫧 zone</div>'; return { unmount: function () { container.innerHTML = ''; } }; }
var L = C.ledger(Z), tab = 'stock', q = '', offS = null;
function items() { return L.all().filter(function (r) { return r.cat !== 'argent' && r.cat !== 'compteur'; }); }
function row(r) { var low = r.seuil > 0 && r.qte <= r.seuil; return '<div class="cv__row ' + (low ? 'u2' : '') + '" data-id="' + r.id + '"><span class="ic">' + (r.cat === 'bouffe' ? '🥫' : '🧻') + '</span><div class="tx"><b>' + U.esc(r.nom) + '</b><small>' + (low ? 'sous le seuil ' + r.seuil : 'seuil ' + r.seuil) + (r.lieu ? ' · ' + U.esc(r.lieu) : '') + '</small></div><button class="cv__btn sm" data-d="-1">−</button><span class="nb">' + r.qte + ' ' + U.esc(r.unite || '') + '</span><button class="cv__btn sm" data-d="1">+</button></div>'; }
function render() {
var all = items(), list = all.filter(function (r) { return !q || r.nom.toLowerCase().indexOf(q) >= 0; }), bas = L.bas().filter(function (r) { return r.cat !== 'argent'; });
var h = U.zoneHd(Z, 'Stock & courses', '🧻') + '<div class="cv__tabs"><button data-tab="stock" class="' + (tab === 'stock' ? 'on' : '') + '">stock (' + all.length + ')</button><button data-tab="courses" class="' + (tab === 'courses' ? 'on' : '') + '">🛒 courses (' + bas.length + ')</button></div><div class="cv__bd">';
if (tab === 'stock') { h += '<input type="search" placeholder="chercher…" data-q value="' + U.esc(q) + '" style="width:100%;padding:9px 11px;border-radius:10px;border:1px solid var(--xr-border,#22324f);background:var(--xr-surface,#0c1320);color:inherit;font:14px system-ui;margin-bottom:8px">'; var byCat = {}; list.forEach(function (r) { (byCat[r.cat] = byCat[r.cat] || []).push(r); }); h += Object.keys(byCat).map(function (c) { return '<div class="cv__sec"><span>' + (c === 'bouffe' ? '🥫 bouffe' : '🧻 maison') + '</span></div>' + byCat[c].sort(function (a, b) { return a.nom.localeCompare(b.nom); }).map(row).join(''); }).join('') || '<div class="cv__empty">Aucun consommable.</div>'; if (all.length < 3) h += '<div style="text-align:center;margin-top:10px"><button class="cv__btn" data-pack>🏠 pack de départ appart (' + PACK.length + ' consommables)</button></div>'; }
else { h += bas.map(function (r) { var need = Math.max(1, Math.ceil((r.seuil * 2) - r.qte)); return '<div class="cv__row" data-id="' + r.id + '"><span class="ic">🛒</span><div class="tx"><b>' + U.esc(r.nom) + '</b><small>reste ' + r.qte + ' ' + U.esc(r.unite || '') + ' · prendre ~' + need + '</small></div><button class="cv__btn sm ok" data-bought="' + need + '">✓ acheté</button></div>'; }).join('') || '<div class="cv__empty">Rien à acheter : tout est au-dessus des seuils.</div>'; }
h += '</div><button class="cv__fab" data-add>+</button>'; container.innerHTML = h;
}
function form(r) { U.form(container, r ? 'Consommable' : 'Nouveau consommable', [{ k: 'nom', label: 'nom', val: r ? r.nom : '' }, { k: 'cat', label: 'type', type: 'chips', opts: [{ v: 'conso', l: '🧻 maison' }, { v: 'bouffe', l: '🥫 bouffe' }], val: r ? r.cat : 'conso' }, { k: 'qte', label: 'quantité', type: 'number', step: '0.1', val: r ? r.qte : 1 }, { k: 'unite', label: 'unité', val: r ? r.unite : 'pièces' }, { k: 'seuil', label: 'seuil (→ courses en dessous)', type: 'number', step: '0.1', val: r ? r.seuil : 1 }, { k: 'lieu', label: 'où', val: r ? r.lieu || '' : '', ph: 'placard cuisine, salle de bain…' }], function (v) { if (r) L.set(r.id, { nom: v.nom, cat: v.cat, qte: v.qte || 0, unite: v.unite, seuil: v.seuil || 0, lieu: v.lieu }); else L.add({ nom: v.nom || '?', cat: v.cat || 'conso', qte: v.qte || 0, unite: v.unite || '', seuil: v.seuil || 0, lieu: v.lieu || '' }); render(); }, r ? '<div style="margin-top:8px"><button type="button" class="cv__btn" data-del>🗑 supprimer</button></div>' : ''); var d = container.querySelector('[data-del]'); if (d && r) d.addEventListener('click', function () { L.remove(r.id); container.querySelector('.cv__form').remove(); render(); }); }
container.addEventListener('click', function (e) {
var b; if ((b = e.target.closest('[data-tab]'))) { tab = b.getAttribute('data-tab'); render(); return; }
if (e.target.closest('[data-add]')) { form(null); return; }
if (e.target.closest('[data-pack]')) { PACK.forEach(function (p) { L.add({ nom: p[0], unite: p[1], qte: p[2], seuil: p[3], cat: p[4] }); }); render(); return; }
var r = e.target.closest('[data-id]'); if (!r) return; var id = r.getAttribute('data-id');
if ((b = e.target.closest('[data-d]'))) { L.mouv(id, +b.getAttribute('data-d'), ''); render(); return; }
if ((b = e.target.closest('[data-bought]'))) { L.mouv(id, +b.getAttribute('data-bought'), 'acheté'); render(); return; }
form(L.get(id));
});
container.addEventListener('input', function (e) { if (e.target.matches('[data-q]')) { q = e.target.value.toLowerCase(); var v = e.target.value; render(); var i = container.querySelector('[data-q]'); if (i) { i.focus(); i.value = v; } } });
render(); offS = L.on(function () { render(); });
return { unmount: function () { try { offS(); } catch (e) {} container.classList.remove('cv'); container.innerHTML = ''; } };
}
function describe() { var Z = window.jOSZone && jOSZone.current(); if (!Z || !window.jOSCiv) return null; var L = jOSCiv.ledger(Z), bas = L.bas().filter(function (r) { return r.cat !== 'argent'; }); return { v: 1, id: ID, title: 'Stock', icon: '🧻', items: [{ p: 1, kind: 'stat', label: 'à acheter', value: bas.length }, { p: 2, kind: 'list', label: 'courses', items: bas.slice(0, 7).map(function (r) { return { label: r.nom, value: r.qte + ' ' + (r.unite || '') }; }) }] }; }
window.jOSApps = window.jOSApps || {}; window.jOSApps[ID] = { manifest: { id: ID, name: 'Stock & courses', icon: '🧻' }, mount: mount, describe: describe };
})();
</script>