Files
dtf-system/web/site-compra.js
Cauê Faleiros 911892351f
All checks were successful
Build and deploy / Validate source (push) Successful in 59s
Build and deploy / Integration suite on a real stack (push) Successful in 8m58s
Build and deploy / Secret scan and release gate (push) Successful in 10s
Build and deploy / Publish images (push) Successful in 1m45s
feat: the 8 mm between a ready sheet's copies stay on the film but are no longer billed (Marcus, 2026-12-03)
Marcus on 26/11 had the gaps count in the billed metres; on 2026-12-03,
after customers of Lais and Kedma refused orders billed 10 and 20 cm more,
"por hora pode tirar a cobrança". A ready sheet is now billed on the sum of
its sheets and copies (pricing.billable_metres: the layout's height less
unbilled_gaps_cm, at most 8 mm between each two pieces); `metres` stays the
film laid out, which the print file, the parts and the folders follow, and
the print file's billed-length guard allows the gap film. Loose art keeps
its packing. The Site bills folhaCobradaM, the copies line reads
"5 × 45,9 cm = 229,3 cm" and the buy box explains that length. The Lais
case, 5 sheets of 100 cm, bills 5,00 m instead of 5,10 m.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 11:24:13 -03:00

100 lines
4.6 KiB
JavaScript

/* Site DTF — the product page's buy box: the grade, price per metre, billed length,
total and the add-to-cart button, beside the live sheet. It shows the item
the other site-*.js files already priced (itemAtual) and never computes a
price of its own, so the box and the cart always agree. */
(function(){
const vals=$('compraVals'), add=$('bAdd');
const nomeCurto=n=>{ n=n||''; return n.length>24 ? n.slice(0,23)+'…' : n; };
// C2 · o cliente escolhe entre Agrupado (linhas) e Misturado (pela forma).
function pintaEncaixe(it){
const box=$('cEncaixe'); if(!box) return;
const alt=encaixeAlt;
if(!it || !alt || ehFolha(it.modo) ||
Math.abs(alt.linhas-alt.forma)<1e-9){
box.hidden=true; box.innerHTML=''; return;
}
const efetivo = modoEncaixeEmUso();
const maior=Math.max(alt.linhas,alt.forma), menor=Math.min(alt.linhas,alt.forma);
const nCm=Math.round((maior-menor)*100);
const y=nCm/100*(it.unit||0);
const vence=alt.forma<=alt.linhas ? 'Misturado' : 'Agrupado';
const bt=(m,rot,sub)=>'<button type="button" class="cEncBt'+
(efetivo===m?' on':'')+'" data-enc="'+m+'" aria-pressed="'+(efetivo===m)+'">'+
'<b>'+rot+'</b><small>'+sub+'</small></button>';
box.hidden=false;
box.innerHTML='<div class="cEncBts" role="group" aria-label="Modo de encaixe">'+
bt('linhas','Agrupado','Mais fácil de cortar · '+fmtM(alt.linhas)+' m')+
bt('forma','Misturado','Menos filme · '+fmtM(alt.forma)+' m')+
'</div>'+
'<p class="cEncDif">'+vence+' usa '+nCm+' cm a menos ('+rs(y)+' a menos).</p>';
}
// C1 · o que ainda cabe na metragem já cobrada, sem aumentar o filme.
function pintaVao(it){
const box=$('cVao'); if(!box) return;
const lista=encaixeVao;
if(!it || ehFolha(it.modo) || !lista.length){
box.hidden=true; box.innerHTML=''; return;
}
const bts=lista.map(v=>{
const i=artes.indexOf(v.a);
return i<0?'':'<button type="button" class="cVaoBt" data-vao="'+i+'" data-k="'+v.k+'">+'+
v.k+' '+escapeHTML(nomeCurto(v.a.f.name))+'</button>';
}).join('');
if(!bts){ box.hidden=true; box.innerHTML=''; return; }
box.hidden=false;
box.innerHTML='<p class="cVaoT">Sem custo: cabem mais cópias nesta metragem.</p>'+
'<div class="cVaoBts">'+bts+'</div>';
}
function pintaCompra(){
const it=itemAtual;
if(!modo || !artes.length) modoEncaixe='auto';
vals.hidden=!it;
add.disabled=!it || !itemPodeEnviar(it);
pintaEncaixe(it); pintaVao(it);
if(!it) return;
$('cMetroLbl').textContent = it.extra ? 'Metro · com '+rs(it.extra)+' de arquivo manual' : 'Metro';
$('cMetro').textContent=rs(it.unit);
$('cMetragem').textContent=fmtM(it.cob)+' m';
// Partes de até 10 m (Marcus, 18/11/2026): o FlexiPRINT não abre mais que isso.
const partes=ehFolha(it.modo) ? Math.ceil(it.metros/10) : 1;
$('cPartes').textContent = partes>1 ? ' Sai em '+partes+' partes de até 10 m.' : '';
// A ready sheet is billed without the gaps between its copies (03/12/2026).
const base=it.cobravel??it.metros;
const sobraCm=Math.round((it.cob-base)*100);
// A metragem cobrada explicada como vantagem (Marcus, 27/11/2026): a cada
// 10 cm, e até 8 mm a mais ficam por nossa conta.
const exata=n1(base*100)+' cm';
const aMais=Math.round((base-it.cob)*1000);
$('cObs').textContent =
it.cob===MINIMO_M && base<MINIMO_M
? (ehFolha(it.modo) ? 'Pedido mínimo de 1 m.'
: 'Pedido mínimo de 1 m: ainda cabem '+sobraCm+' cm de artes sem custo.')
: it.cob<base-1e-6
? 'A folha tem '+exata+': cobramos a cada 10 cm e '+
(aMais>1?'os '+aMais+' mm a mais ficam':aMais===1?'o 1 mm a mais fica':'o que passou fica')+' por nossa conta.'
: it.cob>base+1e-6
? 'A folha tem '+exata+'. Cobramos a cada 10 cm, então fica '+fmtM(it.cob)+' m. '+
'Se passar até 8 mm de uma faixa, esse pedaço fica por nossa conta.'
: '';
$('cTotal').textContent=rs(it.total);
}
$('cEncaixe')?.addEventListener('click',e=>{
const b=e.target.closest('[data-enc]'); if(!b) return;
modoEncaixe=b.dataset.enc;
pintaCompra();
previaAoVivo();
});
$('cVao')?.addEventListener('click',e=>{
const b=e.target.closest('[data-vao]'); if(!b) return;
const a=artes[+b.dataset.vao]; if(!a) return;
a.q=Math.min(200,(a.q||1)+(+b.dataset.k||0));
encaixeVao=[];
const box=$('cVao'); box.hidden=true; box.innerHTML='';
pintaArtes();
});
add.addEventListener('click',()=>adicionaAoCarrinho());
addEventListener('dtf-cart-changed',pintaCompra);
window.pintaCompra=pintaCompra;
pintaCompra();
})();