Merge main into label

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Cauê Faleiros
2026-11-11 11:32:27 -03:00
39 changed files with 920 additions and 148 deletions

View File

@@ -10,11 +10,11 @@ sessionStorage.removeItem('dtf-operator');
const FLOW=['rec','tra','imp','rev','fin'];
const FORMER_STATES={fil:'Fila de impressão'};
const stateName=s=>board.states[s]||FORMER_STATES[s]||s;
const PRODUCT={file:'DTF Têxtil · folha montada',avulsa:'DTF Têxtil · artes avulsas',uvfile:'DTF UV · folha montada',uv:'DTF UV · artes avulsas'};
const PRODUCT={file:'DTF Têxtil · folha montada',avulsa:'DTF Têxtil · artes avulsas',uvfile:'DTF UV · folha montada',uv:'DTF UV · artes avulsas',premium:'DTF Têxtil Premium · folha montada'};
// Loose art the Site split by stroke (item 17): each sheet is an item of its own.
const productName=item=>PRODUCT[item.mode]+(item.split?' · folha '+item.split.part+' de '+item.split.of+
', '+(item.stroke_class==='C3'?'chapado':'traço fino'):'');
const SHORT={file:'Têxtil folha',avulsa:'Têxtil avulsa',uvfile:'UV folha',uv:'UV avulsa'};
const SHORT={file:'Têxtil folha',avulsa:'Têxtil avulsa',uvfile:'UV folha',uv:'UV avulsa',premium:'Premium'};
const EVENTS={payment_approved:'Pagamento aprovado',production_started:'Produção iniciada',correction_needed:'Correção necessária',ready:'Pedido pronto',cancelled:'Pedido cancelado'};
// Payment outcomes are recorded by the API in English; operators read Portuguese.
function outcomeText(outcome){
@@ -427,7 +427,7 @@ async function fetchInto(dir,file){
await writeWhole(dir,file.name,r.body);
}
// The machines' hot folders (item 10): 3. Imprimindo/<máquina>/<C1|C2|C3>/.
// The machines' hot folders (item 10): 3. Imprimindo/<máquina>/<C1|C2|C3|PREMIUM>/.
// The server says what this computer writes now (claimed for it alone, two
// parts at most per machine); a written part gone from its folder was taken
// by FlexiPRINT, and is never written again; a withdrawn one, from a card that
@@ -758,7 +758,7 @@ const FILTER_TESTS={
site:o=>o.origin==='site',
dropflow:o=>o.origin==='dropflow',
atendimento:o=>o.origin==='atendimento',
textil:o=>o.snapshot.items.some(i=>i.mode==='file'||i.mode==='avulsa'),
textil:o=>o.snapshot.items.some(i=>i.mode==='file'||i.mode==='avulsa'||i.mode==='premium'),
uv:o=>o.snapshot.items.some(i=>i.mode==='uvfile'||i.mode==='uv'),
entrega:o=>!!o.snapshot.destination,
retirada:o=>!o.snapshot.destination,
@@ -1115,6 +1115,9 @@ function card(order,place){
row.append(node('span','#'+order.number,'num'),originTag(order),age);
const name=node('span',who.title,'cname');name.title=[who.legal,who.mail].filter(Boolean).join(' · ')||who.title;
const meta=node('span',undefined,'cmeta');meta.append(node('span',productLine(s.items)));
const special=specialDelivery(s);
if(special){const tag=node('span',special,'origin');tag.title=special;meta.append(tag);}
if(s.items.some(i=>i.mode==='premium'))meta.append(badge('Premium','','DTF Têxtil Premium: 8 passadas, branco no máximo'));
if(order.machine){const m=node('span',order.machine.name,'mach'+(mine?' mine':''));m.title=mine?'Sua máquina':'Máquina';meta.append(m);}
meta.append(node('b',metres(orderMetres(order)),'mtr'));
info.append(row,name,meta);
@@ -1142,8 +1145,10 @@ function miniCard(order){
const name=node('span',who.title,'cname');name.title=who.mail||who.title;
let text,ic=IC.check,warn=false;
const days=Math.floor((Date.now()-new Date(order.updated_at))/86400000);
const special=specialDelivery(order.snapshot);
if(order.cancelled_at){text='Cancelado';ic=IC.ban;warn=true;}
else if(order.picked_up_at)text='Retirado';
else if(special){text=special;ic=IC.box;}
else if(order.snapshot.destination){text='Entrega, '+order.snapshot.destination.city+'/'+order.snapshot.destination.state;ic=IC.truck;}
else if(days>=PICKUP_WARN_DAYS){text='Não retirado, '+plural(days,'dia','dias');ic=IC.bag;warn=true;}
else{text='Aguardando retirada';ic=IC.bag;}
@@ -1426,7 +1431,7 @@ function renderPanel(order){
// A proof card is no sale (app/proof.py): it says whose proof it is.
if(order.proof_parent)paid.append(node('b','Prova do pedido #'+order.proof_parent.number),', sem custo, criada em '+when(order.created_at));
else paid.append(node('b',money(s.total_cents)),isTest(order)?' sem pagamento, '+when(order.created_at):
paidOutside(order)?' pago fora do site ('+PAID_OUTSIDE[order.payment.method]+'), registrado em '+when(order.created_at):' pago em '+when(order.created_at));
paidOutside(order)?' pago fora do site ('+(PAID_OUTSIDE[order.payment.method]||order.payment.method)+'), registrado em '+when(order.created_at):' pago em '+when(order.created_at));
const code=node('span',undefined,'chip');
code.append(node('span','DTF-'+order.number,'code'),copyButton(fileCode(order),'Copiar “'+fileCode(order)+'”, o começo do nome dos arquivos deste pedido'));
const theirs=node('span','Código do cliente ','tip-l');theirs.append(node('span',orderCode(order.id),'code strong'));theirs.dataset.tip='O código que aparece para o cliente';
@@ -1437,6 +1442,7 @@ function renderPanel(order){
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(s.items.some(i=>i.mode==='premium'))sub.append(badge('Premium','','DTF Têxtil Premium: 8 passadas, branco no máximo'));
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');
const at=FLOW.indexOf(order.state);
@@ -1829,6 +1835,10 @@ function pickupDialog(order){
}
// Pickup or delivery, from the freight the customer chose.
const isPickup=order=>order.snapshot.freight?.service==='pickup';
// An internal order stays in house, and a sale can travel with the customer's
// clothing order (Fase 2, front 7a.3): the card and the panel say so instead
// of "Retirada".
const specialDelivery=s=>s.kind==='interno'?'Interno':s.with_order?'Junto com o pedido de roupa nº '+s.with_order:null;
// ---- 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));
@@ -2241,7 +2251,7 @@ function phoneFacts(order){
const box=node('div',undefined,'mblock mfacts');
const row=(k,v)=>{if(!v)return;const r=node('div',undefined,'mfact');r.append(node('span',k),node('b',v));box.append(r);};
row('Cliente',who.title);row('E-mail',s.customer.mail);row(docKind(s.customer.cnpj),cnpj(s.customer.cnpj));
row('Entrega',dest?dest.city+'/'+dest.state:'Retirada em Franca');
row('Entrega',specialDelivery(s)||(dest?dest.city+'/'+dest.state:'Retirada em Franca'));
row('Máquina',order.machine?.name||'Nenhuma');row('Código','DTF-'+order.number+', cliente '+orderCode(order.id));
// Choosing the machine stays where it is allowed.
if(may('print')&&ME?.role!=='operador'&&board.machines?.length){const m=machineCard(order).querySelector('select');if(m)box.append(m);}
@@ -2257,9 +2267,10 @@ function orderFacts(order){
client.append(node('span','Cliente','lbl'),title,...(who.mail?[node('span',who.mail)]:[]),doc);
const zap=whatsappLink(s.customer.zap);
if(zap){const a=node('a','Abrir conversa','btn lnk');a.href=zap;a.target='_blank';a.rel='noopener noreferrer';a.title=s.customer.zap;a.prepend(svgIcon(IC.chat,'i s'));client.append(a);}
const where=node('div',undefined,'fact');
where.append(node('span','Entrega','lbl'),node('b',dest?dest.recipient:'Retirada em Franca'),
node('span',dest?dest.street+', '+dest.number+(dest.complement?' '+dest.complement:'')+', '+dest.district+', '+dest.city+'/'+dest.state+', CEP '+dest.postal_code:'O cliente retira na fábrica'));
const where=node('div',undefined,'fact'),special=specialDelivery(s);
where.append(node('span','Entrega','lbl'),node('b',special||(dest?dest.recipient:'Retirada em Franca')),
node('span',special?(special==='Interno'?'Fica na fábrica':'Sem frete próprio'):
dest?dest.street+', '+dest.number+(dest.complement?' '+dest.complement:'')+', '+dest.district+', '+dest.city+'/'+dest.state+', CEP '+dest.postal_code:'O cliente retira na fábrica'));
if(dest&&s.freight?.total_cents)where.append(node('span',(s.freight.description||'Jadlog')+', '+money(s.freight.total_cents)+(s.freight.weight_kg?', '+freightWeight(s.freight):''),'faint'));
grid.append(client,where);
if(order.machine||board.machines?.length)grid.append(machineCard(order));
@@ -2440,7 +2451,7 @@ function historyView(order,rows,view){
item.stroke_choice==='client_c3'?'proteger chapado (C3)':'imprimir assim (C1)'));
}
list.append(entry('Pedido recebido',board.environment==='local'&&order.payment?.provider==='fake'?'pagamento de teste':isTest(order)?'teste, sem pagamento':
paidOutside(order)?ORIGINS[order.origin]+', pago fora do site ('+PAID_OUTSIDE[order.payment.method]+'), registrado por '+order.payment.operator:ORIGINS[order.origin]||'Site',
paidOutside(order)?ORIGINS[order.origin]+', pago fora do site ('+(PAID_OUTSIDE[order.payment.method]||order.payment.method)+'), registrado por '+order.payment.operator:ORIGINS[order.origin]||'Site',
order.created_at,paidOutside(order)?order.payment.note:''));
view.replaceChildren(list);
}
@@ -2827,7 +2838,11 @@ async function openMachineSheet(machineId){
box.append(field('Preço de compra (R$)',price),field('Data de instalação',installed));
for(const [item,[label,unit]] of Object.entries(data.catalog.supplies)){
const input=node('input');input.type='number';input.min='0';input.step='0.001';input.inputMode='decimal';
input.value=data.minimums[item]!==null&&data.minimums[item]!==undefined?Number(data.minimums[item]).toString():'';
// Dropstar's fixed minimums are the defaults: a machine with none typed
// shows and uses them until Gestão changes them.
const typed=data.minimums[item], fallback=data.default_minimums?.[item];
input.value=typed!==null&&typed!==undefined?Number(typed).toString()
:fallback!==null&&fallback!==undefined?Number(fallback).toString():'';
minimums[item]=input;
box.append(field('Mínimo de '+label.toLowerCase()+' ('+unit+')',input));
}
@@ -3699,7 +3714,7 @@ function hitRow(items,title,sub,meta,state,tone,open){
function orderHit(order){
const s=order.snapshot;
return hitRow(s.items,'#'+order.number+' · '+orderCode(order.id),buyer(s).title,
s.items.map(i=>SHORT[i.mode]+' · '+metres(i.billed_metres)).join(' + ')+' · '+(s.destination?'Entrega':'Retirada')+' · pago '+when(order.created_at),
s.items.map(i=>SHORT[i.mode]+' · '+metres(i.billed_metres)).join(' + ')+' · '+(specialDelivery(s)||(s.destination?'Entrega':'Retirada'))+' · pago '+when(order.created_at),
order.cancelled_at?'Cancelado':board.states[order.state],order.cancelled_at?'bad':'',()=>{
// An older finished order is not on the board yet: it joins, like "Carregar mais".
if(!board.orders.some(o=>o.id===order.id)){olderFinished.push(order);board.orders.push(order);}