feat: the art grade becomes configurable, off by default (front 8.5)
Gestão sets in the Site tab below which grade the designer is warned and below which the designer treatment is required (only while it is offered). The decision is stored with the approved quote, so a later change never rewrites old orders; the card shows 'Nota N: conferir a arte', the Site forces the treatment box with the reason. With no rule nothing changes. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -77,6 +77,9 @@
|
||||
if(typeof folhas!=='undefined'&&folhas.length&&typeof pintaFolha==='function')pintaFolha();
|
||||
if(typeof itemAtual!=='undefined'&&itemAtual&&typeof carrinho==='function')carrinho();
|
||||
}
|
||||
// The art grade rules (front 8.5): the Site uses only the treatment rule,
|
||||
// forcing the checkbox when the cart's worst grade is below it.
|
||||
window.dtfGradeRules=session.grade_rules||{};
|
||||
// Treatment by the designer (front 5): only offered when TREATMENT_CENTS
|
||||
// is set; the server adds the same amount and the 24 h to the quote.
|
||||
TAXA_TRATAMENTO=(session.treatment_cents||0)/100;
|
||||
|
||||
@@ -148,6 +148,66 @@ function sitePriceBlock(product){
|
||||
return block;
|
||||
}
|
||||
|
||||
// ── Nota da arte (front 8.5) ────────────────────────────────────────────────
|
||||
function ensureGradePanel(){
|
||||
let panel=$('site-grade-panel');
|
||||
if(panel)return panel;
|
||||
panel=node('section',undefined,'panel clip');panel.id='site-grade-panel';
|
||||
const head=node('div',undefined,'phead');head.append(node('h2','Nota da arte'));
|
||||
panel.append(head,node('p','A menor nota dos itens do pedido decide. Sem regra, a nota não muda nada.','phint'));
|
||||
const body=node('div',undefined,'siteGradeBody');body.id='site-grade-body';panel.append(body);
|
||||
const coupons=$('site-coupons-panel');
|
||||
if(coupons)coupons.before(panel);
|
||||
else{
|
||||
const videos=$('site-videos-panel');
|
||||
if(videos)videos.before(panel);else $('tab-site').append(panel);
|
||||
}
|
||||
return panel;
|
||||
}
|
||||
|
||||
function gradeRuleRow(label, value){
|
||||
const row=node('div',undefined,'siteGradeRow');
|
||||
const on=node('input');on.type='checkbox';on.checked=value!=null;
|
||||
const word=node('span',on.checked?'Ligado':'Desligado');
|
||||
const toggle=node('label',undefined,'siteSwitch');toggle.append(on,word);
|
||||
const num=node('input');num.type='number';num.min='1';num.max='100';num.step='1';
|
||||
num.className='siteGradeNumber';num.value=value!=null?String(value):'';num.disabled=!on.checked;
|
||||
on.onchange=()=>{
|
||||
word.textContent=on.checked?'Ligado':'Desligado';
|
||||
num.disabled=!on.checked;
|
||||
if(on.checked)num.focus();
|
||||
};
|
||||
const fieldLabel=node('label',undefined,'siteGradeField');
|
||||
fieldLabel.append(node('span',label),num);
|
||||
row.append(toggle,fieldLabel);
|
||||
return {row,on,num};
|
||||
}
|
||||
|
||||
async function loadGradeRules(){
|
||||
if(!may('manage'))return;
|
||||
ensureGradePanel();
|
||||
const data=await api('/site/grade-rules');
|
||||
const aviso=gradeRuleRow('Avisar o designer abaixo de',data.aviso);
|
||||
const tratamento=gradeRuleRow('Exigir o tratamento abaixo de',data.tratamento);
|
||||
const save=button('Salvar',async()=>{
|
||||
const avisoValue=aviso.on.checked?Number(aviso.num.value):null;
|
||||
const tratamentoValue=tratamento.on.checked?Number(tratamento.num.value):null;
|
||||
for(const value of [avisoValue,tratamentoValue])
|
||||
if(value!==null&&(!Number.isInteger(value)||value<1||value>100))
|
||||
throw new Error('A nota vai de 1 a 100.');
|
||||
if(avisoValue!==null&&tratamentoValue!==null&&tratamentoValue>avisoValue)
|
||||
throw new Error('A regra do tratamento precisa ser menor ou igual à do aviso.');
|
||||
await api('/site/grade-rules',{aviso:avisoValue,tratamento:tratamentoValue});
|
||||
say('Regras da nota da arte salvas.');
|
||||
await loadGradeRules();
|
||||
},'btn pri');
|
||||
const children=[aviso.row,tratamento.row];
|
||||
if(!data.treatment_offered)
|
||||
children.push(node('p','Ative e dê preço ao Tratamento pelo designer para esta regra valer.','siteGradeWarn'));
|
||||
const foot=node('div',undefined,'siteGradeSave');foot.append(save);children.push(foot);
|
||||
$('site-grade-body').replaceChildren(...children);
|
||||
}
|
||||
|
||||
// ── Cupons (front 8.3) ──────────────────────────────────────────────────────
|
||||
// A "ficha" of the date in the browser's timezone, for datetime-local inputs.
|
||||
function couponDate(iso){
|
||||
@@ -298,6 +358,7 @@ async function loadSiteAdmin(){
|
||||
$('site-products').replaceChildren(...data.products.map(siteProductRow));
|
||||
$('site-prices').replaceChildren(...data.products.map(sitePriceBlock));
|
||||
await loadSiteCoupons();
|
||||
await loadGradeRules();
|
||||
await loadSiteVideos();
|
||||
}
|
||||
|
||||
|
||||
@@ -672,6 +672,12 @@ label.fopt{cursor:pointer;user-select:none}
|
||||
#tab-site .siteCouponActions{display:flex;gap:8px;flex-wrap:wrap}
|
||||
#tab-site .siteCouponActions .btn{height:32px;padding:0 10px;font-size:12.5px}
|
||||
#tab-site .siteCouponNote{margin:0;font-size:13px;color:var(--tx2)}
|
||||
#tab-site .siteGradeBody{display:flex;flex-direction:column;gap:14px;padding:16px 18px}
|
||||
#tab-site .siteGradeRow{display:flex;align-items:center;gap:16px;flex-wrap:wrap}
|
||||
#tab-site .siteGradeField{display:flex;align-items:center;gap:8px;font-size:13px;color:var(--tx2)}
|
||||
#tab-site .siteGradeNumber{width:80px;height:38px;padding:0 10px;border-radius:8px;border:1px solid var(--ln2);background:var(--sf);color:var(--tx);font-size:14px;font-family:inherit}
|
||||
#tab-site .siteGradeWarn{margin:0;font-size:12.5px;font-weight:600;color:var(--warn)}
|
||||
#tab-site .siteGradeSave{display:flex;gap:8px}
|
||||
#tab-site .siteHistory .table{font-size:13px}
|
||||
#tab-site .siteHistory .table th,#tab-site .siteHistory .table td{padding:8px 12px}
|
||||
.page>*{flex-shrink:0}
|
||||
|
||||
@@ -1057,6 +1057,10 @@ function cardFlags(order){
|
||||
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]);
|
||||
if(live&&proofPending(order)&&!order.proof_card)out.push(['warn','Prova',order.snapshot.proof?'O cliente pediu uma prova antes de imprimir':'Pedido acima de 10 m: prova antes do resto']);
|
||||
// The grade rule set in the Site tab flagged this order for the designer.
|
||||
if(!order.proof_parent&&s.grade_flags?.aviso!=null)
|
||||
out.push(['warn','Nota '+s.grade_flags.aviso+': conferir a arte',
|
||||
'A nota da arte ficou abaixo do limite configurado: confira antes de imprimir']);
|
||||
if(live&&s.items.some(i=>i.quality_status==='warning'))out.push(['warn','Nota '+(lowestGrade(s.items)??'baixa'),'Nota da arte baixa: o cliente aceitou a ressalva de resolução']);
|
||||
const dots=s.items.reduce((t,i)=>t+(i.residue_accepted||0),0);
|
||||
if(live&&dots)out.push(['warn','Resíduo','O cliente aceitou imprimir com '+residueNote({residue_accepted:dots})]);
|
||||
@@ -1428,6 +1432,9 @@ function renderPanel(order){
|
||||
sub.append(paid,node('span','Entrou pelo '+(ORIGINS[order.origin]||order.origin)),code,theirs);
|
||||
if(s.coupon && !order.proof_parent)
|
||||
sub.append(badge('Cupom '+s.coupon.code,'','Desconto de '+money(s.coupon.discount_cents)));
|
||||
if(s.grade_flags?.aviso!=null && !order.proof_parent)
|
||||
sub.append(badge('Nota '+s.grade_flags.aviso+': conferir a arte','warn',
|
||||
'A nota da arte ficou abaixo do limite configurado: confira antes de imprimir'));
|
||||
if(isTest(order))sub.append(badge('Teste','','Pedido de teste: sem pagamento, não vai ao Tiny'));
|
||||
if(stalled(order)&&!order.cancelled_at)sub.append(badge('Parado há '+hoursSince(order.updated_at)+' h','bad','Sem mudar de etapa desde '+when(order.updated_at)));
|
||||
const steps=node('ol',undefined,'stepper');steps.setAttribute('aria-label','Etapas');
|
||||
|
||||
@@ -30,6 +30,32 @@ function limpaPaineis(){
|
||||
if(!pedido.length){ $('carr').classList.remove('on'); }
|
||||
}
|
||||
|
||||
// Front 8.5: when the worst grade of the paying items is below the rule and
|
||||
// the treatment is offered, the designer's treatment is required.
|
||||
function mostraAvisoTratamento(texto){
|
||||
const box=$('tratamentoBox'); if(!box)return;
|
||||
let el=$('tratamentoAviso');
|
||||
if(!el){el=document.createElement('p');el.id='tratamentoAviso';el.className='avisoF';box.append(el);}
|
||||
el.textContent=texto;el.hidden=!texto;
|
||||
}
|
||||
function aplicaTratamento(aPagar){
|
||||
const box=$('tratamentoBox'), check=$('fTratamento');
|
||||
if(!box||!check)return;
|
||||
const offered=TAXA_TRATAMENTO>0;
|
||||
const rule=Number(window.dtfGradeRules?.tratamento)||0;
|
||||
const grades=aPagar.map(it=>Number(it.nota)||0);
|
||||
const worst=grades.length?Math.min(...grades):null;
|
||||
const required=offered&&rule>0&&worst!==null&&worst<rule;
|
||||
box.hidden=!offered;
|
||||
if(!offered){
|
||||
check.checked=false;check.disabled=false;mostraAvisoTratamento('');
|
||||
}else if(required){
|
||||
check.checked=true;check.disabled=true;
|
||||
mostraAvisoTratamento('Sua arte tem nota '+worst+': para imprimir com qualidade, o tratamento pelo designer é obrigatório neste pedido.');
|
||||
}else{
|
||||
check.disabled=false;mostraAvisoTratamento('');
|
||||
}
|
||||
}
|
||||
// O carrinho junta itens de produtos diferentes e cobra uma vez só.
|
||||
function pintaPedido(){
|
||||
const aPagar = itensAPagar();
|
||||
@@ -51,6 +77,7 @@ function pintaPedido(){
|
||||
aviso.hidden=false;
|
||||
}else{aviso.hidden=true;aviso.textContent='';}
|
||||
}
|
||||
aplicaTratamento(aPagar);
|
||||
$('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')+
|
||||
@@ -93,8 +120,6 @@ function pintaPedido(){
|
||||
// The proof is only for orders above 10 m (Dropstar, 2026-10-28): below it the box is gone.
|
||||
const prova=$('fProva');
|
||||
if(prova){ const longo=aPagar.reduce((t,it)=>t+(it.cob||0),0)>10; prova.closest('.cxE').hidden=!longo; if(!longo) prova.checked=false; }
|
||||
const tratamentoBox=$('tratamentoBox');
|
||||
if(tratamentoBox){tratamentoBox.hidden=!(TAXA_TRATAMENTO>0);if(tratamentoBox.hidden)$('fTratamento').checked=false;}
|
||||
$('bPagar').disabled = !cartPodeEnviar() || !entrega.cotado || !clienteOk() || !enderecoOk();
|
||||
if(pedido.length || itemAtual) $('carr').classList.add('on');
|
||||
if($('cartN')){ $('cartN').textContent=noCarrinho>99?'99+':noCarrinho; $('cartN').hidden=!noCarrinho;
|
||||
|
||||
Reference in New Issue
Block a user