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

@@ -102,6 +102,9 @@
// same amount and the 24 h to the quote.
TAXA_TRATAMENTO=(session.treatment_cents||0)/100;
FAIXAS.tratamento=session.treatment_bands||[];
// Ajuste Fino Redesenho (front 1b): one price per art, no band, only
// offered when the server prices it above zero.
TAXA_REDESENHO=(session.redesign_cents||0)/100;
const tratamentoBox=document.getElementById('tratamentoBox');
if(tratamentoBox){
tratamentoBox.hidden=!(TAXA_TRATAMENTO>0);
@@ -199,6 +202,11 @@
rows.push(linha('Ajuste Fino'+(arts?' · '+arts+(arts===1?' arte':' artes'):'')+' · +24 h',
rs(quote.treatment.cents/100)));
}
if(quote.redesign?.cents){
const arts=Number(quote.redesign.arts)||0;
rows.push(linha('Ajuste Fino Redesenho'+(arts?' · '+arts+(arts===1?' arte':' artes'):'')+' · +48 h',
rs(quote.redesign.cents/100)));
}
if(approved.coupon)
rows.push(linha('Cupom '+approved.coupon.code, '− '+rs(approved.coupon.discount_cents/100)));
rows.push(linha('Total', rs(approved.total_cents/100), 'tot'));
@@ -500,6 +508,9 @@
// Ajuste Fino: true for every art, or the [item, source] pairs chosen.
const treatment=tratamentoParaItens(sheets);
if (treatment) content.treatment = treatment;
// Ajuste Fino Redesenho: the [item, source] pairs chosen, one per art.
const redesign=redesenhoParaItens(sheets);
if (redesign) content.redesign = redesign;
if (cartSnapshot()!==initialCart) throw new Error('O carrinho mudou durante o envio. Confira os itens e envie de novo.');
// Browser timings for Números (item 0.12); they never affect the price.
const T=window.dtfTimings, timings={};

View File

@@ -67,7 +67,9 @@ function sitePriceBlock(product){
starts.setAttribute('aria-label','Quando o novo preço de '+product.title+' começa');
startsLabel.append(starts);
// Faixas progressivas (front 8.2): a nova tabela começa vazia; as faixas
// viajam com este preço. Ajuste Fino conta as faixas em artes, os produtos em metros.
// viajam com este preço. Ajuste Fino conta as faixas em artes, os produtos em
// metros. O Redesenho tem um preço único por arte, nunca faixas (front 1b).
const permiteFaixas=product.id!=='redesenho';
const bandUnit=product.unit==='arte'?'artes':'m';
const bandRows=node('div',undefined,'siteBandRows');
const addBand=node('button','Adicionar faixa','btn ghost');addBand.type='button';
@@ -105,11 +107,11 @@ function sitePriceBlock(product){
if(whenDate&&Number.isNaN(whenDate.getTime()))throw new Error('Data inválida.');
await api('/site/products/'+product.id+'/prices',
{unit_cents:cents,starts_at:whenDate?whenDate.toISOString():null,
bands:formBands()});
bands:permiteFaixas?formBands():[]});
say(whenDate?'Preço salvo para '+when(whenDate)+'.':'Preço salvo. Vale a partir de agora.');
await loadSiteAdmin();
},'btn pri');
form.append(priceLabel,startsLabel,save,bands);
form.append(priceLabel,startsLabel,save,...(permiteFaixas?[bands]:[]));
const scheduled=node('div',undefined,'siteScheduled');
if(product.scheduled.length){

View File

@@ -1069,6 +1069,11 @@ function cardFlags(order){
out.push(['warn','Ajuste Fino · '+n+(n===1?' arte':' artes'),
'O designer faz o Ajuste Fino antes de imprimir; prazo +24 h']);
}
if(order.snapshot.redesign){
const n=Number(order.snapshot.redesign.arts)||1;
out.push(['warn','Redesenho · '+n+(n===1?' arte':' artes'),
'O designer redesenha ou vetoriza a arte antes de imprimir; prazo +48 h']);
}
if(order.proof_parent)out.push(['warn','Prova do #'+order.proof_parent.number,'Card da prova do pedido #'+order.proof_parent.number]);
if(live&&waitingProof(order)&&order.state!=='tra')out.push(['warn','Aguardando prova','Entra na fila com Prova OK no card #'+order.proof_card.number]);
if(live&&proofRejected(order))out.push(['bad','Prova reprovada',order.proof_card.proof_reason+' · '+order.proof_card.proof_decided_by]);
@@ -1614,10 +1619,11 @@ function contractionList(order){
return box;
}
function approveParts(order,main=true){
if(order.snapshot.treatment){
const approve=button('Enviar arte do Ajuste Fino',()=>treatDialog(order),'btn lg'+(main?' pri':''));
if(designerPaid(order)){
const label=order.snapshot.redesign?'Ajuste Fino Redesenho':'Ajuste Fino';
const approve=button('Enviar arte do '+label,()=>treatDialog(order),'btn lg'+(main?' pri':''));
approve.dataset.treat='';
return {text:'Ajuste Fino pago: o designer precisa enviar o PNG do Ajuste Fino de cada item antes da fila.',
return {text:label+' pago: o designer precisa enviar o PNG do '+label+' de cada item antes da fila.',
files:null,approve,extra:[]};
}
const ready=readyFinals(order), all=ready.every(Boolean), many=ready.length>1;
@@ -1708,9 +1714,10 @@ function nextBox(order){
return composeNext(title,body,main,more);
}
if(st==='rec'||st==='cor'){
if(st==='rec'&&order.snapshot.treatment&&!treatmentDone(order)&&finalDone(order)){
title='Enviar a arte do Ajuste Fino';
note('O Ajuste Fino foi pago. Envie o PNG ajustado de cada item antes de colocar o pedido na fila.');
if(st==='rec'&&designerPaid(order)&&!treatmentDone(order)&&finalDone(order)){
title='Enviar a arte do '+(order.snapshot.redesign?'Ajuste Fino Redesenho':'Ajuste Fino');
note((order.snapshot.redesign?'O Ajuste Fino Redesenho foi pago.':'O Ajuste Fino foi pago.')+
' Envie o PNG ajustado de cada item antes de colocar o pedido na fila.');
if(may('produce'))main.push(button('Tratar a arte',()=>treatDialog(order),'btn pri lg'));
return composeNext(title,body,main,more);
}
@@ -1857,6 +1864,7 @@ const specialDelivery=s=>s.kind==='interno'?'Interno':s.with_order?'Junto com o
// ---- Final files: the file each item is printed from, approved by an operator.
const finalDone=order=>order.snapshot.items.every((_,index)=>(order.final_items||[]).includes(index));
const treatmentDone=order=>order.snapshot.items.every((_,index)=>order.treated?.items?.includes(index));
const designerPaid=order=>!!(order.snapshot.treatment||order.snapshot.redesign);
const FINAL_SOURCE={correction:'correção do cliente',generated:'arquivo gerado',original:'original'};
const FINAL_TITLE={correction:'Correção do cliente',generated:'Gerado pelo sistema',original:'Original do cliente'};
// What the system generated for an item: one PNG, or the parts of a film
@@ -2190,7 +2198,7 @@ function treatDialog(order){
if(file)return {file};
const kept=(order.finals||[]).filter(f=>f.item_index===index).map(f=>f.upload_id);
const treated=order.treated?.items?.includes(index);
return {ids:order.snapshot.treatment&&!treated?[]:
return {ids:designerPaid(order)&&!treated?[]:
kept.length?kept:ready[index]?ready[index].files.map(f=>f.upload_id):[]};
});
if(!plan.some(p=>p.file))throw new Error('Escolha o arquivo tratado.');

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.

View File

@@ -68,6 +68,8 @@ const FAIXAS={};
let TAXA_MANUAL=0;
// Ajuste Fino, per art, set by the server (TREATMENT_CENTS).
let TAXA_TRATAMENTO=0;
// Ajuste Fino Redesenho, one price per art, no band (REDESIGN_CENTS).
let TAXA_REDESENHO=0;
// Ajuste Fino for every art of the cart: the general switch, or true when
// the grade rule requires it. Individual choices live on the art objects.
let ajusteTudo=false;

View File

@@ -483,8 +483,9 @@ function avisosDaFolha(a,nome,i,aceito,aceitavel=false){
'usou e envie de novo. '+(varios?'Os círculos vermelhos na prévia mostram onde estão.':'O círculo vermelho na prévia mostra onde está.')+
(aceitavel?' Se '+(varios?'os pontos são':'o ponto é')+' da própria arte, marque abaixo.</p>'+aceite:'</p>');
}
// Ajuste Fino (front 1a): under a Prumo warning, the customer may hand this
// art to the designer. One choice per art; the cart has the general switch.
// Ajuste Fino (front 1a) and Ajuste Fino Redesenho (front 1b): under a Prumo
// warning, the customer may hand this art to the designer. One service per
// art, chosen radio-like; the cart has the general switch for the basic one.
function temAvisoFolha(x){
const a=x.an;
if(!a || a.grande) return false;
@@ -498,11 +499,25 @@ function temAvisoArte(a){
(typeof mista==='function' && mista(tracoDaArte(a))));
}
function ajusteLinha(i,attr){
if(!(TAXA_TRATAMENTO>0)) return '';
const marcado=ajusteTudo || (attr==='data-ajuste' ? folhas[i].ajuste : artes[i].ajuste);
return '<label class="aceiteRes ajusteArte"><input type="checkbox" '+attr+'="'+i+'"'+
(marcado?' checked':'')+'>'+
'<span>Quer que um designer resolva? <b>Ajuste Fino</b> — '+rs(TAXA_TRATAMENTO)+'</span></label>';
const folha=attr==='data-ajuste';
const x=folha?folhas[i]:artes[i];
const basico=TAXA_TRATAMENTO>0, redesenhado=TAXA_REDESENHO>0;
if(!basico && !redesenhado) return '';
let linha='';
if(basico){
const marcado=ajusteTudo || !!x.ajuste;
linha+='<label class="aceiteRes ajusteArte"><input type="checkbox" '+attr+'="'+i+'"'+
(marcado?' checked':'')+'>'+
'<span>Quer que um designer resolva? <b>Ajuste Fino</b> — '+rs(TAXA_TRATAMENTO)+'</span></label>';
}
if(redesenhado){
const attrRedesenhado=folha?'data-redesenho':'data-redesenhoa';
linha+='<label class="aceiteRes ajusteArte"><input type="checkbox" '+attrRedesenhado+'="'+i+'"'+
(x.redesenho?' checked':'')+'>'+
'<span>Precisa redesenhar ou vetorizar? <b>Ajuste Fino Redesenho</b> — '+rs(TAXA_REDESENHO)+
' (com prévia, +48 h)</span></label>';
}
return linha;
}
function detalhesDaFolha(a,i,aberto){
const linhas = a.grande
@@ -612,7 +627,16 @@ function pintaFolha(){
}));
$('lista').querySelectorAll('[data-ajuste]').forEach(el=>el.addEventListener('change',()=>{
if(ajusteTudo) materializaAjuste();
folhas[+el.dataset.ajuste].ajuste=el.checked;
const x=folhas[+el.dataset.ajuste];
x.ajuste=el.checked;
if(el.checked) x.redesenho=false;
pintaFolha(); pintaPedido();
}));
$('lista').querySelectorAll('[data-redesenho]').forEach(el=>el.addEventListener('change',()=>{
if(ajusteTudo) materializaAjuste();
const x=folhas[+el.dataset.redesenho];
x.redesenho=el.checked;
if(el.checked) x.ajuste=false;
pintaFolha(); pintaPedido();
}));
$('lista').querySelectorAll('[data-det]').forEach(d=>d.addEventListener('toggle',()=>{
@@ -745,7 +769,16 @@ function pintaArtes(){
artes[+el.dataset.residuoa].residuoAceito=el.checked; pintaArtes();}));
$('lista').querySelectorAll('[data-ajustea]').forEach(el=>el.addEventListener('change',()=>{
if(ajusteTudo) materializaAjuste();
artes[+el.dataset.ajustea].ajuste=el.checked;
const a=artes[+el.dataset.ajustea];
a.ajuste=el.checked;
if(el.checked) a.redesenho=false;
pintaArtes(); pintaPedido();
}));
$('lista').querySelectorAll('[data-redesenhoa]').forEach(el=>el.addEventListener('change',()=>{
if(ajusteTudo) materializaAjuste();
const a=artes[+el.dataset.redesenhoa];
a.redesenho=el.checked;
if(el.checked) a.ajuste=false;
pintaArtes(); pintaPedido();
}));
$('lista').querySelectorAll('[data-cm]').forEach(i=>i.addEventListener('change',()=>{artes[+i.dataset.cm].cm=+i.value||0;pintaArtes();}));