feat: progressive price bands per product (front 8.2)

A price may carry up to five bands, "from N m, R$ Y": the order's total
billed metres of that product chooses one price for its whole quantity,
the manual-file extra still on top. Bands start and become history with
their price row. The Site charges the same band for the cart, shows
"Faltam X m para R$ Y o metro" and lists the bands under the price
table; the Kanban's Site tab edits them.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Cauê Faleiros
2026-11-09 14:30:15 -03:00
parent c5e7a80b64
commit 2a6732eb37
16 changed files with 334 additions and 23 deletions

View File

@@ -91,6 +91,7 @@
if(session.products){
for(const [mode,product] of Object.entries(session.products)){
PRECO[mode]=product.unit_cents/100;
FAIXAS[mode]=product.bands||[];
const card=document.querySelector('button.ec[data-modo="'+mode+'"]');
if(card&&!product.enabled)card.hidden=true;
}
@@ -98,6 +99,16 @@
const product=session.products[el.dataset.preco];
el.textContent=product&&!product.enabled?'Indisponível':rs(PRECO[el.dataset.preco]);
});
// The home price table keeps the base price; the bands go under it.
const tabelaFaixas=document.getElementById('tabelaFaixas');
if(tabelaFaixas){
const linhas=Object.entries(session.products)
.filter(([,product])=>product.enabled && product.bands?.length)
.map(([mode,product])=>node('div',MODOS[mode].tit+': '+product.bands
.map(band=>'a partir de '+metrosCurto(band.from_metres)+' m: '+rs(band.unit_cents/100)).join(' · ')));
tabelaFaixas.replaceChildren(...linhas);
tabelaFaixas.hidden=!linhas.length;
}
window.dtfProducts=session.products;
if(typeof folhas!=='undefined'&&folhas.length&&typeof pintaFolha==='function')pintaFolha();
if(typeof itemAtual!=='undefined'&&itemAtual&&typeof carrinho==='function')carrinho();
@@ -129,6 +140,10 @@
if (className) el.className=className;
return el;
}
// "5" or "5,5": a band's metres as the customer reads them.
function metrosCurto(value){
return String(Number(value)).replace('.',',');
}
// What the customer is paying for, from the server's approval.
function pintaResumo(quote) {
const approved = quote ? quote.approved : null;