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

@@ -32,6 +32,25 @@ function limpaPaineis(){
// O carrinho junta itens de produtos diferentes e cobra uma vez só.
function pintaPedido(){
const aPagar = itensAPagar();
// Faixas progressivas (front 8.2): um preço só para todos os metros de um
// produto no pedido, a mesma regra que o servidor cobra na aprovação.
const metrosPorModo={};
for(const it of aPagar) metrosPorModo[it.modo]=(metrosPorModo[it.modo]||0)+(it.cob||0);
for(const it of aPagar){
it.unit=precoNaMetragem(it.modo, metrosPorModo[it.modo])+(it.extra||0);
it.total=Math.round(it.cob*it.unit*100)/100;
it.desc=(it.partes?it.partes.length+' folhas · ':'')+fmtM(it.cob)+' m · '+rs(it.unit)+'/m';
}
const aviso=$('cProxima');
if(aviso){
const proxima=itemAtual?proximaFaixa(itemAtual.modo, metrosPorModo[itemAtual.modo]):null;
if(proxima){
const falta=Math.max(0.1, Math.ceil((Number(proxima.from_metres)-metrosPorModo[itemAtual.modo])*10-1e-9)/10);
aviso.textContent='Faltam '+falta.toFixed(1).replace('.',',')+' m para '+rs(proxima.unit_cents/100)+' o metro.';
aviso.hidden=false;
}else{aviso.hidden=true;aviso.textContent='';}
}
$('itens').innerHTML = pedido.map((it,i)=>
'<div class="item'+(it.marcado===false?' fora':'')+'">'+
'<label class="marca"><input type="checkbox" data-sel="'+i+'"'+(it.marcado===false?'':' checked')+
@@ -52,7 +71,6 @@ function pintaPedido(){
});
}));
$('bEsvaziar').hidden = pedido.length+(itemAtual?1:0) < 2;
const aPagar = itensAPagar();
const itens = aPagar.reduce((t,it)=>t+it.total,0);
const frete = entrega.tipo==='frete' && entrega.cotado ? entrega.valor : 0;
const tratamento=$('fTratamento')?.checked&&TAXA_TRATAMENTO>0?TAXA_TRATAMENTO:0;
@@ -90,8 +108,13 @@ const fonteDaArte=x=>({kind:'artwork',width_cm:x.cm,length_cm:+(x.cm*propDe(x)).
copies:x.q,rotation_degrees:x.giro||0,mirrored:!!x.esp,
measurement:(x.src||x.semPrevia)?'file':'customer'});
function carrinho(){
const base=precoMetro(), cob=cobrarMontagem();
const cob=cobrarMontagem();
const extra=folhaManual()? TAXA_MANUAL : 0;
// A faixa é escolhida pelos metros deste produto no carrinho mais o item
// sendo montado (front 8.2), como o servidor cobra.
const metrosModo=pedido.filter(it=>it.marcado!==false && it.modo===modo)
.reduce((t,it)=>t+(it.cob||0),0)+cob;
const base=precoNaMetragem(modo, metrosModo);
const unit=base+extra, tot=cob*unit, sobra=+(cob-metros).toFixed(2);
$('carr').classList.add('on');
let l='<div class="l"><span>'+MODOS[modo].tit+'</span><b>'+rs(base)+'/m</b></div>';