feat: the proof card, machine pull and print file corrections (Dropstar, 05/11)

The proof card owns its final PNG, keeps its parent locked until the seller
answers, enters the queue first, and shares one machine with the parent.
The board no longer assigns a machine at payment; the puller records it.
A stalled print file times out with a card warning and a retry, finished
orders sort by completion, and finals are stored as PNG. The original
download carries the order number (items 0.1, 0.4 to 0.7 and 0.9).
This commit is contained in:
Cauê Faleiros
2026-11-06 10:41:20 -03:00
parent 0fc01315c7
commit d69e326125
20 changed files with 584 additions and 220 deletions

View File

@@ -262,6 +262,9 @@ main{padding:0}
.card.open,.mini.open{border-color:var(--ink);box-shadow:0 0 0 1px var(--ink)}
.card.off{opacity:.7}
.card[draggable=true]{cursor:grab}
.card:focus-visible,.mini:focus-visible{outline:2px solid var(--acc);outline-offset:2px}
.card-open{display:inline-flex;align-items:center;justify-content:center;gap:5px;align-self:flex-start;min-height:28px;padding:4px 8px;border:1px solid var(--ln2);border-radius:7px;background:var(--sf3);color:var(--tx);font:inherit;font-size:11px;font-weight:600;cursor:pointer}
.card-open:hover,.card-open:focus-visible{border-color:var(--acc);color:var(--acc)}
.ctop{display:grid;grid-template-columns:56px minmax(0,1fr);gap:12px;align-items:center}
.thumb{width:56px;height:56px;border-radius:8px;padding:4px;border:0;box-shadow:inset 0 0 0 1px var(--ln);background:repeating-conic-gradient(var(--chka) 0 25%,var(--chkb) 0 50%) 0 0/8px 8px}
.thumb img{transition:transform .5s cubic-bezier(.2,.8,.2,1)}
@@ -418,6 +421,9 @@ main{padding:0}
.inote.bad,.inote.bad .i{color:var(--bad)}
.inotes .callout{margin:2px 0}
.links{display:flex;gap:8px;margin-top:18px;flex-wrap:wrap}
.originals{position:relative;border:1px solid var(--ln);border-radius:8px;padding:8px 12px}
.originals summary{cursor:pointer;font-weight:600}
.originals .btn{margin:8px 8px 0 0}
.facts3{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));border:1px solid var(--ln);border-radius:12px;overflow:hidden}
.fact{padding:14px 16px;display:flex;flex-direction:column;gap:3px;min-width:0;border-right:1px solid var(--ln)}
.fact:last-child{border-right:0}

View File

@@ -229,8 +229,8 @@ async function api(path,body){
const r=await fetch('/api/operator'+path,{headers:{'Content-Type':'application/json'},...(body===undefined?{}:{method:'POST',body:JSON.stringify(body)})});
const d=await r.json();if(!r.ok){const error=new Error(typeof d.detail==='string'?d.detail:'Confira os campos ('+r.status+').');error.status=r.status;throw error;}return d;
}
function download(uid){return async()=>{
const result=await api('/uploads/'+uid+'/download');
function download(uid,orderId){return async()=>{
const result=await api('/uploads/'+uid+'/download'+(orderId?'?order_id='+encodeURIComponent(orderId):''));
const link=node('a');link.href=result.url;link.referrerPolicy='no-referrer';link.download=result.name;link.click();
};}
// ---- Automatic folder ------------------------------------------------------
@@ -670,6 +670,7 @@ function printState(order){
if((order.corrections||[]).length)return {text:'Correção recebida',tone:'warn'};
const rows=order.print_files||[], items=order.snapshot.items.length;
const ready=rows.filter(r=>r.status==='ready').length;
if(rows.some(r=>r.status==='failed'||r.timed_out))return {text:'Falhou ao gerar',tone:'warn'};
if(rows.some(r=>r.status==='pending'||r.status==='rendering'))return {text:'Gerando arquivo…',tone:''};
if(ready===items)return {text:'Falta aprovar o final',tone:'warn'};
if(rows.some(r=>r.status==='manual'||r.status==='failed'))
@@ -849,9 +850,10 @@ function renderBoard(){
const filtered=Object.entries(boardFilter).some(([key,value])=>value&&key!=='product')||!!boardFilter.product;
$('kan').replaceChildren(...Object.entries(board.states).map(([state,title])=>{
const column=node('section',undefined,'col');column.dataset.state=state;column.setAttribute('aria-label',title);
// A queue: the order paid first is on top, the newest at the bottom, however
// the list was put together (older finished ones, one opened from the search).
const orders=board.orders.filter(o=>o.state===state&&matches(o)).sort((a,b)=>queueKey(a)-queueKey(b)||a.number-b.number);
// Working columns are queues; Finalizado shows the most recently ready order first.
const orders=board.orders.filter(o=>o.state===state&&matches(o)).sort((a,b)=>state==='fin'
? new Date(b.finished_at||b.updated_at)-new Date(a.finished_at||a.updated_at)||b.id.localeCompare(a.id)
: queueKey(a)-queueKey(b)||a.number-b.number);
const head=node('header',undefined,'colhead');
head.append(svgIcon(GLYPH[state],'sg'+(state==='cor'?' cor':'')));
const text=node('span',undefined,'coltx');text.append(node('h2',title));
@@ -1024,8 +1026,9 @@ function productLine(items){
// A card drags forward when this profile makes that move, or up and down
// when it sets the column's order; a card of another operator's machine does not.
function draggable(c,order){
c.draggable=!order.cancelled_at&&mayAct(order)&&(mayReorder(order.state)||board.transitions[order.state].some(s=>s!=='cor'&&mayMove(order.state,s)));
c.draggable=!order.cancelled_at&&!waitingProof(order)&&mayAct(order)&&(mayReorder(order.state)||board.transitions[order.state].some(s=>s!=='cor'&&mayMove(order.state,s)));
c.onclick=()=>openPanel(order.id);
c.onkeydown=e=>{if(e.target===c&&(e.key==='Enter'||e.key===' ')){e.preventDefault();openPanel(order.id);}};
c.ondragstart=e=>{
dragging=order;
e.dataTransfer.setData('text/plain',order.id);
@@ -1040,8 +1043,8 @@ function draggable(c,order){
function card(order,place){
const s=order.snapshot, mine=isMine(order)&&order.state!=='fin'&&!order.cancelled_at;
const [step,tone]=nextStep(order,place);
const c=node('button',undefined,'card'+(mine?' mine':'')+(tone==='live'?' live':'')+(order.id===openOrder?' open':'')+(order.cancelled_at?' off':''));
c.type='button';c.dataset.card=order.id;
const c=node('div',undefined,'card'+(mine?' mine':'')+(tone==='live'?' live':'')+(order.id===openOrder?' open':'')+(order.cancelled_at?' off':''));
c.tabIndex=0;c.setAttribute('role','button');c.dataset.card=order.id;
const who=buyer(s);
c.setAttribute('aria-label','Pedido #'+order.number+', '+who.title+': '+step);
const top=node('span',undefined,'ctop'), info=node('span',undefined,'cinfo');
@@ -1065,7 +1068,7 @@ function card(order,place){
next.append(node('span',step,'stx'));
foot.append(next);
const flag=flagNode(cardFlags(order));if(flag)foot.append(flag);
c.append(foot);
c.append(foot,cardOpenAction(order));
draggable(c,order);
return c;
}
@@ -1073,7 +1076,7 @@ function card(order,place){
// nothing else. A pickup waiting more than two days is said in warning.
const PICKUP_WARN_DAYS=2;
function miniCard(order){
const c=node('button',undefined,'mini'+(order.id===openOrder?' open':''));c.type='button';c.dataset.card=order.id;
const c=node('div',undefined,'mini'+(order.id===openOrder?' open':''));c.tabIndex=0;c.setAttribute('role','button');c.dataset.card=order.id;
const who=buyer(order.snapshot);
const row=node('span',undefined,'crow');row.append(node('span','#'+order.number,'num'),node('span',metres(orderMetres(order)),'age'));
const name=node('span',who.title,'cname');name.title=who.mail||who.title;
@@ -1085,7 +1088,7 @@ function miniCard(order){
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;}
const done=node('span',undefined,'done'+(warn?' warn':''));done.append(svgIcon(ic,'i s'),text);
c.append(row,name,done);
c.append(row,name,done,cardOpenAction(order));
c.setAttribute('aria-label','Pedido #'+order.number+', '+who.title+': '+text);
draggable(c,order);
return c;
@@ -1120,9 +1123,10 @@ async function reorder(order,column,y){
await load();
}
async function loadOlderFinished(){
const shown=board.orders.filter(o=>o.state==='fin').sort((a,b)=>a.created_at<b.created_at?-1:1);
const shown=board.orders.filter(o=>o.state==='fin').sort((a,b)=>
new Date(a.finished_at||a.updated_at)-new Date(b.finished_at||b.updated_at)||a.id.localeCompare(b.id));
const oldest=shown[0];const params=new URLSearchParams({limit:'50'});
if(oldest){params.set('before_created_at',oldest.created_at);params.set('before_id',oldest.id);}
if(oldest){params.set('before_finished_at',oldest.finished_at||oldest.updated_at);params.set('before_id',oldest.id);}
const page=absorb(await api('/orders/finished?'+params));
const known=new Set(board.orders.map(o=>o.id));
const fresh=page.orders.filter(o=>!known.has(o.id));
@@ -1398,7 +1402,7 @@ function moreMenu(order,buttonClass='btn sq ghost'){
if(!order.cancelled_at){
// Undo a mistaken move: one stage back, internal reason, no customer message.
const previous=board.back?.[order.state];
if(previous&&mayMove(order.state,previous)&&mayAct(order))item(IC.back,'Voltar para '+board.states[previous],()=>backDialog(order,previous)).dataset.back=previous;
if(previous&&!waitingProof(order)&&mayMove(order.state,previous)&&mayAct(order))item(IC.back,'Voltar para '+board.states[previous],()=>backDialog(order,previous)).dataset.back=previous;
if(order.state!=='fin'&&!waitingContact(order)&&may('produce'))
item(IC.phone,'Aguardando contato',()=>contactDialog(order)).dataset.contact='';
if(!isTest(order)&&may('rework'))item(IC.rework,'Abrir retrabalho',()=>reworkForm(order));
@@ -1432,8 +1436,6 @@ function contactNotice(order,canClear){
box.append(ico,p);
const zap=whatsappLink(order.snapshot.customer.zap);
if(zap){const a=node('a','Abrir conversa','btn');a.href=zap;a.target='_blank';a.rel='noopener noreferrer';a.prepend(svgIcon(IC.chat,'i s'));box.append(a);}
if(canClear)box.append(button('Contato feito',async()=>{
await api('/orders/'+order.id+'/contact',{waiting:false});say('Contato registrado: a marca saiu do pedido #'+order.number+'.');await load();},'btn'));
return box;
}
// In correction, the customer has to be told: a message ready to send on
@@ -1518,6 +1520,11 @@ function nextBox(order){
const note=text=>body.push(node('p',text,'nnote'));
const can=to=>mayMove(st,to)&&mayAct(order);
const moveBtn=(to,label,className='btn pri lg')=>{const b=button(label||'Mover para '+board.states[to],()=>move(order,to),className);b.dataset.move=to;return b;};
if(waitingProof(order)){
title='Aguardando prova do #'+order.proof_card.number;
note('O pedido segue para Arte conferida após Prova OK no card da prova. Você pode abrir o arquivo para consultar.');
return composeNext(title,body,main,more);
}
// A proof card in Revisão waits for its answer (Dropstar, 2026-11-03).
if(order.proof_parent&&st==='rev'){
title='Responder a prova';
@@ -1551,6 +1558,14 @@ function nextBox(order){
const p=node('p',undefined,'nnote');p.append(node('b','Prova reprovada: '),order.proof_card.proof_reason);body.push(p);
if(may('produce'))more.push(button('Nova prova',async()=>{await api('/orders/'+order.id+'/proof-card',{});await load();say('Nova prova criada.');},'btn lg'));
}
if(st==='rec'&&order.proof_parent){
title=finalDone(order)?'Conferir a prova':'Gerando a prova';
note(finalDone(order)?'Abra o PNG gerado pelo Prumo e confirme a contração.':'O Prumo prepara até 15 cm por classe e aprova o PNG final automaticamente.');
if(finalDone(order)&&may('produce'))main.push(checkButton(order,'btn pri lg'));
if((order.print_files||[]).some(r=>r.status==='failed'||r.status==='manual'||r.timed_out)&&may('produce'))
more.push(button('Gerar de novo',async()=>{await api('/orders/'+order.id+'/print-files',{});await load();},'btn lg'));
return composeNext(title,body,main,more);
}
if(st==='rec'||st==='cor'){
if(!finalDone(order)&&trans.includes('tra')){
if(st==='rec')title='Aprovar o arquivo final';
@@ -1694,7 +1709,7 @@ function readyFinals(order){
const fixes=order.corrections||[];
return order.snapshot.items.map((item,index)=>{
const fix=fixes.find(f=>f.item_index===index);
if(fix)return fix.expired?null:{files:[{upload_id:fix.upload_id,name:fix.name}],name:fix.name,source:'correction',label:'Correção do cliente ('+fix.name+')'};
if(fix)return fix.expired||!fix.name.toLowerCase().endsWith('.png')?null:{files:[{upload_id:fix.upload_id,name:fix.name}],name:fix.name,source:'correction',label:'Correção do cliente ('+fix.name+')'};
const made=fixes.length?null:(order.print_files||[]).find(r=>r.item_index===index&&r.status==='ready');
if(!made)return null;
const original=made.detail?.source==='original', files=generatedFiles(made);
@@ -1720,7 +1735,8 @@ function finalDialog(order,ready,{replace=false}={}){
slot.append(node('span',label,'lbl'));
const input=node('input');input.multiple=true;input.required=true;input.dataset.finalItem=index;
input.setAttribute('aria-label','Arquivo final, '+label);
const drop=dropField(input,{hint:'PNG, PDF ou TIFF, do tamanho da impressão.'});
input.accept='.png,image/png';
const drop=dropField(input,{hint:'PNG transparente a 300 DPI, do tamanho da impressão.'});
const file=ready[index];
if(file){
const use=node('input');use.checked=true;use.dataset.useGenerated=index;input.required=false;drop.hidden=true;
@@ -1740,6 +1756,7 @@ function finalDialog(order,ready,{replace=false}={}){
const generated=input.generated?.();
if(generated){refs.push(...generated.map(upload_id=>({item_index:index,upload_id})));continue;}
for(const file of input.files){
if(!file.name.toLowerCase().endsWith('.png'))throw Error('O arquivo final precisa ser PNG transparente a 300 DPI. Converta PDF/TIFF antes de enviar.');
const uid=await dtfUpload(file,{api,startPath:'/orders/'+order.id+'/uploads',scope:'operator:'+order.id+':'+order.version,progress:text=>say(text)});
refs.push({item_index:index,upload_id:uid});
}
@@ -1762,12 +1779,20 @@ const FOLDER_PATH_KEY='folder-path';
function checkButton(order,className='btn'){
const b=button('Abrir e conferir',()=>openCheck(order),className);b.prepend(svgIcon(IC.eye||IC.file,'i m'));return b;
}
function cardOpenAction(order){
const action=button('Abrir arquivo',()=>openCheck(order),'card-open');
action.prepend(svgIcon(IC.eye||IC.file,'i s'));
return action;
}
async function openCheck(order){
const {files}=await api('/orders/'+order.id+'/view');
if(!files.length){say('Ainda não há arquivo para abrir.',true);return;}
openViewer(files,{title:'#'+order.number,onClose:()=>{
const now=board.orders.find(o=>o.id===order.id)||order;
if(now.state==='rec'&&!now.cancelled_at&&may('produce')&&mayMove('rec','tra'))isOk(now);}});
if(now.state==='rec'&&!now.cancelled_at&&!waitingProof(now)&&may('produce')&&mayMove('rec','tra')){
if(openOrder!==order.id)openPanel(order.id);
isOk(now);
}}});
}
// "Está OK?" (Dropstar, 2026-10-29): the class of each item, prefilled with
// the measure, and the art either goes on to Arte conferida, its final
@@ -1908,6 +1933,7 @@ function itemNote(text,tone=''){
}
function itemCard(order,item,index){
const row=(order.print_files||[]).find(r=>r.item_index===index), spec=item.production;
const printStatus=row?.timed_out?'failed':row?.status;
const box=node('section',undefined,'item');box.setAttribute('aria-label','Item '+(index+1));
const info=node('div',undefined,'iinfo');
const count=order.snapshot.items.length;
@@ -1924,19 +1950,22 @@ function itemCard(order,item,index){
info.append(dl);
const notes=node('div',undefined,'inotes');
if(item.quality_status==='warning')notes.append(itemNote('O cliente aceitou a ressalva de resolução.','warn'));
if(item.residue_accepted)notes.append(itemNote('Resíduo aceito pelo cliente: '+residueNote(item)+'.','warn'));
if(item.residue_accepted)notes.append(itemNote('Resíduo: '+item.residue_accepted+' pontos, aceito pelo cliente'+
(item.residue_accepted_at?' às '+when(item.residue_accepted_at):'')+'.','warn'));
if(item.stroke_choice)notes.append(itemNote('Traços finos e áreas chapadas no mesmo arquivo: '+
(item.stroke_choice==='client_c3'?'o cliente escolheu proteger as áreas chapadas (C3); o traço fino pode sumir em tecido escuro.'
:'o cliente foi avisado e quis imprimir assim mesmo (C1).'),'warn'));
:'o cliente foi avisado e quis imprimir assim mesmo (C1).')+
(item.stroke_choice_at?' Aceito às '+when(item.stroke_choice_at)+'.':''),'warn'));
if(mirroredItem(item))notes.append(itemNote(MIRROR_NOTE+'.','bad'));
// After a customer correction, that file is the artwork: the generated
// print file, or the reason it could not be made, no longer applies.
const fix=(order.corrections||[]).find(f=>f.item_index===index);
if(fix)notes.append(itemNote('Correção do cliente recebida: '+fix.name,'ok'));
else if(!row)notes.append(itemNote('Arquivo de impressão ainda não gerado.'));
else if(row.status==='manual'||row.status==='failed'){
else if(printStatus==='manual'||printStatus==='failed'){
const call=node('div',undefined,'callout warn'),ico=node('span',undefined,'cico');ico.append(svgIcon(IC.alert,'i m'));
const p=node('p');p.append(node('b',row.status==='failed'?'Falhou ao gerar. ':'Preparar à mão. '),row.detail?.reason||'Monte a folha a partir do original.');
const p=node('p');p.append(node('b',printStatus==='failed'?'Falhou ao gerar'+(row.finished_at||row.timeout_at?' às '+when(row.finished_at||row.timeout_at):'')+'. ':'Preparar à mão. '),
row.timed_out?'Tempo limite excedido. Gere de novo.':row.detail?.reason||'Monte a folha a partir do original.');
call.append(ico,p);notes.append(call);
}else{
const original=row.status==='ready'&&row.detail?.source==='original';
@@ -1956,10 +1985,11 @@ function itemCard(order,item,index){
const made=generatedFiles(row);
made.forEach((f,k)=>links.append(dl_(made.length>1?'Parte '+(k+1)+' de '+made.length:/\.pdf$/i.test(f.name)?'PDF':'PNG',f.upload_id)));
}
item.uploads.forEach((uid,i)=>links.append(dl_(item.uploads.length>1?'Original '+(i+1):'Arquivo original',uid)));
if(spec?.placements){const m=button('Manifesto',()=>manifest(spec,contractionRecord(item,order.contraction?.[index])),'btn');m.prepend(svgIcon(IC.file,'i m'));links.append(m);}
const originals=node('details',undefined,'originals');originals.append(node('summary','Originais ('+item.uploads.length+')'));
item.uploads.forEach((uid,i)=>originals.append(downloadButton('Original '+(i+1),download(uid,order.id),'btn')));
links.append(originals);
if(row?.status==='ready')links.prepend(checkButton(order));
if(may('produce')&&!fix&&['rec','tra'].includes(order.state)&&(!row||row.status==='manual'||row.status==='failed')){
if(may('produce')&&!fix&&['rec','tra'].includes(order.state)&&!waitingProof(order)&&(!row||row.status==='manual'||row.status==='failed'||row.timed_out)){
const again=button('Gerar de novo',async()=>{await api('/orders/'+order.id+'/print-files',{});await load();},'btn');again.prepend(svgIcon(IC.refresh,'i m'));links.append(again);}
info.append(links);
box.append(itemPreview(item),info);return box;
@@ -1967,6 +1997,14 @@ function itemCard(order,item,index){
// Arquivos: every final, current or replaced, and the way to send a new one.
function filesView(order,revisions,view){
const out=[];
const layouts=node('div',undefined,'links');
order.snapshot.items.forEach((item,index)=>{
if(item.production?.placements){
const b=button('Manifesto · item '+(index+1),()=>manifest(item.production,contractionRecord(item,order.contraction?.[index])),'btn');
b.prepend(svgIcon(IC.file,'i m'));layouts.append(b);
}
});
if(layouts.children.length)out.push(layouts);
if(revisions.length){
const panel=node('div',undefined,'tpanel');
const table=node('table',undefined,'table');
@@ -1984,7 +2022,7 @@ function filesView(order,revisions,view){
}else out.push(node('p','Nenhum arquivo final ainda.','empty'));
// Replacing an approved final, while the art is still in Arte recebida or Correção;
// in Arte conferida, the queue, the order goes back to Arte recebida first.
if(may('produce')&&['rec','cor'].includes(order.state)&&finalDone(order)&&!order.cancelled_at){
if(may('produce')&&['rec','cor'].includes(order.state)&&finalDone(order)&&!order.cancelled_at&&!order.proof_parent){
const open=button('Enviar nova versão',async()=>finalDialog(order,readyFinals(order).map(()=>null),{replace:true}),'btn');
open.prepend(svgIcon(IC.upload,'i m'));open.classList.add('self-start');out.push(open);
}
@@ -2045,6 +2083,12 @@ function historyView(order,rows,view){
};
for(const r of [...rows].reverse())list.append(entry(r.back?'Voltou para '+stateName(r.to_state):stateName(r.to_state),
r.operator+(r.machine?', na '+r.machine:''),r.created_at,r.reason));
for(const item of order.snapshot.items){
if(item.residue_accepted_at)list.append(entry('Resíduo aceito','cliente',item.residue_accepted_at,
item.residue_accepted+' pontos'));
if(item.stroke_choice_at)list.append(entry('Traço fino aceito','cliente',item.stroke_choice_at,
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',
order.created_at,paidOutside(order)?order.payment.note:''));
@@ -2111,28 +2155,28 @@ function paintMyMachine(){
for(const id of ['my-machine','rail-machine'])$(id).onclick=()=>askMachine(true);
$('account-machine').onclick=()=>{$('account-menu').hidden=true;askMachine(true);};
// The order's machine: chosen, or the first that prints its product.
// The machine is recorded when the card is pulled into Imprimindo.
function machineCard(order){
const box=node('div',undefined,'fact');box.append(node('span','Máquina','lbl'));
const current=order.machine;
const pulled=order.machine_pulled;
const detail=pulled?'Puxada por '+pulled.by+' em '+when(pulled.at):current?'Escolhida para este pedido':'Definida quando alguém puxar o card';
// The operator's orders go to the machine that pulls them (item 12).
if(!may('print')||ME?.role==='operador'||!board.machines?.length){
box.append(node('b',current?current.name:'Nenhuma máquina cadastrada'),
node('span',current?.chosen?'Escolhida para este pedido':current?'Escolhida automaticamente':'Nenhuma máquina imprime este produto'));
if(!may('print')||ME?.role==='operador'||!board.machines?.length||waitingProof(order)||!['rec','tra','cor'].includes(order.state)){
box.append(node('b',current?current.name:'Aguardando máquina'),node('span',detail));
return box;
}
const select=node('select');select.setAttribute('aria-label','Máquina do pedido');
const auto=node('option','Automática'+(current&&!current.chosen?' ('+current.name+')':''));auto.value='';select.append(auto);
const auto=node('option','Sem máquina');auto.value='';select.append(auto);
const family=order.snapshot.items.some(i=>i.mode==='uvfile'||i.mode==='uv')?'uv':'textil';
for(const m of board.machines.filter(m=>m.active&&m.products.includes(family)||m.id===current?.id)){
const o=node('option',m.name+', '+machineLoad(m));o.value=m.id;select.append(o);
}
select.value=current?.chosen?current.id:'';
select.value=current?.id||'';
select.onchange=async()=>{try{await api('/orders/'+order.id+'/machine',{machine_id:select.value||null});
say(select.value?'Pedido enviado para '+select.selectedOptions[0].textContent+'.':'Máquina automática pelo produto.');await load();}
say(select.value?'Pedido enviado para '+select.selectedOptions[0].textContent+'.':'O pedido aguarda uma máquina.');await load();}
catch(e){say(e.message,true);}};
box.append(node('b',current?current.name:'Nenhuma'),
node('span',current?.chosen?'Escolhida para este pedido':current?'Escolhida automaticamente quando o pedido chegou':'Nenhuma máquina imprime este produto'),select);
box.append(node('b',current?current.name:'Aguardando máquina'),node('span',detail),select);
return box;
}
// "120,00 m de 300,00 m" or "120,00 m em aberto".
@@ -2804,8 +2848,9 @@ function quoteItem(item,fields,priced,index=0,count=1){
grid.append(m,gr);info.append(grid);
}
const links=node('div',undefined,'links');
item.uploads.forEach((uid,i)=>links.append(downloadButton(item.uploads.length>1?'Original '+(i+1):'Arquivo original',download(uid),'btn')));
if(spec?.placements){const b=button('Manifesto',()=>manifest(spec,contractionRecord(item)),'btn');b.prepend(svgIcon(IC.file,'i m'));links.append(b);}
const originals=node('details',undefined,'originals');originals.append(node('summary','Originais ('+item.uploads.length+')'));
item.uploads.forEach((uid,i)=>originals.append(downloadButton('Original '+(i+1),download(uid,order.id),'btn')));
links.append(originals);
info.append(links);box.append(tall,info);return box;
}