feat: Ajuste Fino Redesenho in the cart (Marcus 12/11, slice R1)

Under each art the Prumo warns about, the customer can choose Ajuste Fino
or Ajuste Fino Redesenho (vectorize or redraw, per art, +48 h, no batch
price). It is a disabled product until Gestão prices it in the Site tab;
the server charges it per chosen art, Tiny gets a DTFIMP.AJF.RED line and
two more business days, the card shows 'Redesenho · N artes' and the
designer gate applies. The preview loop is slice R2.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Cauê Faleiros
2026-11-12 11:05:17 -03:00
parent 5ca6792221
commit 38f947d632
23 changed files with 429 additions and 60 deletions

View File

@@ -4,8 +4,9 @@
scope and run top to bottom, exactly as the original did. */
// ── carrinho
let itemAtual=null;
// Ajuste Fino (front 1a): each art may be chosen under its warning, or the
// general switch chooses every art of the paying items.
// Ajuste Fino (front 1a) and Ajuste Fino Redesenho (front 1b): each art may
// be chosen under its warning, or the general switch chooses every art of the
// paying items for the basic service.
function artesDoItem(it){
if(it.partes && it.partes.length)
return it.partes.reduce((t,p)=>t+((p.production&&p.production.sources||[]).length),0);
@@ -19,17 +20,29 @@ function artesSelecionadas(aPagar=itensAPagar()){
return t+(it.ajusteSources||[]).length;
},0);
}
function redesenhosSelecionados(aPagar=itensAPagar()){
return aPagar.reduce((t,it)=>{
if(it.partes && it.partes.length)
return t+it.partes.reduce((s,p)=>s+(p.redesenhoSources||[]).length,0);
return t+(it.redesenhoSources||[]).length;
},0);
}
// While a product is open, its files are not in the cart yet; the rule must
// still see the arts the customer already checked under their warnings.
function artesEscolhidasNaTela(){
if(!modo) return 0;
return (ehFolha()?folhas:artes).filter(x=>x.ajuste).length;
}
function redesenhosEscolhidosNaTela(){
if(!modo) return 0;
return (ehFolha()?folhas:artes).filter(x=>x.redesenho).length;
}
// What the cart snapshot compares: the switch and every chosen source.
function ajusteSnapshot(){
return {tudo:!!ajusteTudo, itens:itensAPagar().map(it=>({
escolhas:it.ajusteSources||[],
partes:(it.partes||[]).map(p=>p.ajusteSources||[])
redesenhos:it.redesenhoSources||[],
partes:(it.partes||[]).map(p=>({escolhas:p.ajusteSources||[], redesenhos:p.redesenhoSources||[]}))
}))};
}
// A final cart item (after a split sheet becomes its own items) to the pairs.
@@ -42,6 +55,14 @@ function tratamentoParaItens(itens){
});
return pairs.length?pairs:false;
}
function redesenhoParaItens(itens){
if(!(TAXA_REDESENHO>0)) return false;
const pairs=[];
itens.forEach((it,itemIndex)=>{
for(const source of it.redesenhoSources||[]) pairs.push([itemIndex,source]);
});
return pairs.length?pairs:false;
}
function materializaAjuste(){
if(!ajusteTudo) return;
ajusteTudo=false;
@@ -53,8 +74,8 @@ function materializaAjuste(){
it.ajusteSources=Array.from({length:(it.production&&it.production.sources||[]).length},(_,i)=>i);
}
}
for(const x of folhas) x.ajuste=true;
for(const a of artes) a.ajuste=true;
for(const x of folhas){x.ajuste=true;x.redesenho=false;}
for(const a of artes){a.ajuste=true;a.redesenho=false;}
}
function limpaAjuste(){
ajusteTudo=false;
@@ -65,6 +86,14 @@ function limpaAjuste(){
for(const x of folhas) x.ajuste=false;
for(const a of artes) a.ajuste=false;
}
function limpaRedesenho(){
for(const it of itensAPagar()){
it.redesenhoSources=[];
for(const part of it.partes||[]) part.redesenhoSources=[];
}
for(const x of folhas) x.redesenho=false;
for(const a of artes) a.redesenho=false;
}
// Update the per-art boxes without repainting the list, which would discard
// the item the customer is still building.
function pintaAjusteCheckboxes(){
@@ -74,6 +103,12 @@ function pintaAjusteCheckboxes(){
document.querySelectorAll('[data-ajustea]').forEach(el=>{
const a=artes[+el.dataset.ajustea]; if(a)el.checked=ajusteTudo||!!a.ajuste;
});
document.querySelectorAll('[data-redesenho]').forEach(el=>{
const x=folhas[+el.dataset.redesenho]; if(x)el.checked=!!x.redesenho;
});
document.querySelectorAll('[data-redesenhoa]').forEach(el=>{
const a=artes[+el.dataset.redesenhoa]; if(a)el.checked=!!a.redesenho;
});
}
function invalidaItemAtual(){
if(!itemAtual) return;
@@ -103,7 +138,8 @@ function limpaPaineis(){
// Front 8.5: when the worst grade of the paying items is below the rule and
// Ajuste Fino is offered, it is required. The simple rule the server keeps:
// at least one art must be chosen; with none, the general switch selects all.
// at least one art must be chosen, basic or Redesenho; with none, the general
// switch selects every art for the basic service.
function mostraAvisoTratamento(texto){
const box=$('tratamentoBox'); if(!box)return;
let el=$('tratamentoAviso');
@@ -119,6 +155,7 @@ function aplicaTratamento(aPagar){
const worst=grades.length?Math.min(...grades):null;
const required=offered&&rule>0&&worst!==null&&worst<rule;
box.hidden=!offered;
if(!(TAXA_REDESENHO>0)) limpaRedesenho();
if(!offered){
check.checked=false;check.disabled=false;
ajusteTudo=false;
@@ -130,7 +167,8 @@ function aplicaTratamento(aPagar){
for(const a of artes) a.ajuste=false;
mostraAvisoTratamento('');
}else if(required){
const chosen=!!ajusteTudo || artesSelecionadas(aPagar)>0 || artesEscolhidasNaTela()>0;
const chosen=!!ajusteTudo || artesSelecionadas(aPagar)>0 || artesEscolhidasNaTela()>0 ||
redesenhosSelecionados(aPagar)>0 || redesenhosEscolhidosNaTela()>0;
if(!chosen){
ajusteTudo=true;
for(const x of folhas) x.ajuste=true;
@@ -189,7 +227,14 @@ function pintaPedido(){
const frete = entrega.tipo==='frete' && entrega.cotado ? entrega.valor : 0;
const artesAjuste = TAXA_TRATAMENTO>0 ? artesSelecionadas(aPagar) : 0;
const tratamento = artesAjuste ? Math.round(precoAjuste(artesAjuste)*artesAjuste*100)/100 : 0;
const soma = itens + frete + tratamento;
const artesRedesenho = TAXA_REDESENHO>0 ? redesenhosSelecionados(aPagar) : 0;
const redesenho = artesRedesenho ? Math.round(TAXA_REDESENHO*artesRedesenho*100)/100 : 0;
// The whole order waits 48 h when any art was sent to Redesenho, else 24 h.
const prazoTratamento=document.querySelector('#tratamentoBox .provaOp span');
if(prazoTratamento) for(const no of prazoTratamento.childNodes)
if(no.nodeType===3) no.textContent=no.textContent.replace(/aumenta em \d+ h/,
'aumenta em '+(artesRedesenho>0?48:24)+' h');
const soma = itens + frete + tratamento + redesenho;
const n = aPagar.length, noCarrinho = pedido.length + (itemAtual?1:0);
$('resLin').innerHTML =
'<div class="l"><span>'+n+(n===1?' item':' itens')+'</span><b>'+rs(itens)+'</b></div>'+
@@ -200,6 +245,8 @@ function pintaPedido(){
: entrega.cotado ? rs(frete) : 'a cotar')+'</b></div>'+
(tratamento?'<div class="l"><span>Ajuste Fino · '+artesAjuste+(artesAjuste===1?' arte':' artes')+
' · +24 h</span><b>'+rs(tratamento)+'</b></div>':'')+
(redesenho?'<div class="l"><span>Ajuste Fino Redesenho · '+artesRedesenho+
(artesRedesenho===1?' arte':' artes')+' · +48 h</span><b>'+rs(redesenho)+'</b></div>':'')+
'<div class="l"><span>Revisão e reencaixe</span>'+
'<b><span style="color:var(--verde-ml)">Grátis</span></b></div>';
$('carrTot').textContent=rs(soma);
@@ -246,6 +293,7 @@ function carrinho(){
$('carrLin').innerHTML=l;
$('atual').style.display='';
const escolhidas=lista=>lista.map((x,i)=>ajusteTudo||x.ajuste?i:null).filter(i=>i!==null);
const redesenhadas=lista=>lista.map((x,i)=>x.redesenho?i:null).filter(i=>i!==null);
const sources=(ehFolha()?folhas:artes).map(x=>ehFolha()
? {kind:'sheet',width_cm:x.med?.larg||larguraFilme(),length_cm:+(x.m*100).toFixed(4),
copies:x.rep||1,rotation_degrees:0,mirrored:false,
@@ -271,6 +319,7 @@ function carrinho(){
metros:+(f.layout.height_cm/100).toFixed(4),
production:{version:3,film_width_cm:larguraFilme(),sources:f.artes.map(fonteDaArte),...f.layout},
ajusteSources:escolhidas(f.artes),
redesenhoSources:redesenhadas(f.artes),
residueAccepted:residuosDasArtes(f.artes), ...tracoDoItem(f.artes,f.layout)}));
layout=null;
}else{
@@ -285,7 +334,8 @@ function carrinho(){
arquivos:(ehFolha()?folhas:artes).length,
production:layout?{version:3,film_width_cm:larguraFilme(),sources,...layout}:null,
partes,
...(partes?{}:{ajusteSources:escolhidas(ehFolha()?folhas:artes)}),
...(partes?{}:{ajusteSources:escolhidas(ehFolha()?folhas:artes),
redesenhoSources:redesenhadas(ehFolha()?folhas:artes)}),
qualityStatus:$('ciente').classList.contains('recusa')?'rejected':
$('ciente').classList.contains('on')?'warning':nota===0?'unverified':'ok',
qualityAcknowledged:false,
@@ -308,7 +358,7 @@ function fechaDesfazer(){ clearTimeout(desfazerTimer); desfazerAcao=null; $('des
addEventListener('dtf-page-changed',fechaDesfazer);
$('desfazerBtn').addEventListener('click',()=>{ const acao=desfazerAcao; fechaDesfazer(); if(acao) acao(); });
$('fTratamento')?.addEventListener('change',()=>{
if($('fTratamento').checked) ajusteTudo=true;
if($('fTratamento').checked){ ajusteTudo=true; limpaRedesenho(); }
else limpaAjuste();
// The art cards show the same choice, one checkbox under each warning; do
// not repaint them, or the item being built is discarded.