feat: new layout phase C, Cotações as on the canvas
Roadmap Novo Layout, phase C (canvas C1, C2): list rows with thumb, product line, total and expiry; the "Tudo revisado" empty state with one action to the quotes waiting for payment; the open quote with header, total, facts in three columns, notes, Originais and the footer actions. "Pedido pago fora do site" is now a dialog from the footer. Nothing removed; the e-mail stays in the header. Built by Bobina. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
/* Kanban DTF: the Cotações tab. The quotes list, the review panel, approval,
|
||||
a test order and an order paid outside the site. Loaded after kanban.js,
|
||||
which defines api, absorb, node, button, money, metres, say, ask, load, may,
|
||||
which defines api, absorb, node, button, dialogHost, formDialog, money, metres,
|
||||
say, ask, load, may,
|
||||
$, ago, shortAgo, svgIcon, IC, iconButton, badge, gradePill, lowestGrade,
|
||||
productLine, productName, sheetSize, buyer, docKind, cnpj, copyButton,
|
||||
paymentBadge, freightWeight, whatsappLink, artBox, itemPreview, itemNote,
|
||||
@@ -89,10 +90,10 @@ function renderQuotes(){
|
||||
const name=node('b',who.title);name.title=who.mail||who.title;
|
||||
// A quote from the last ten minutes carries a dot: someone just ordered.
|
||||
if(Date.now()-new Date(q.created_at)<600000){const dot=node('span',undefined,'newdot');dot.title='Chegou agora';name.prepend(dot);}
|
||||
first.append(name,node('span',q.approved?money(q.approved.total_cents):metres(quoteMetres(q)),'qm'));
|
||||
first.append(name);
|
||||
const second=node('span',undefined,'qline sub');
|
||||
const what=node('span');what.append(gradePill(lowestGrade(items)),' '+productLine(items)+', '+(q.draft.destination?q.draft.destination.city+'/'+q.draft.destination.state:'Retirada'));
|
||||
second.append(what,node('span',(quoteKind==='approved'?quoteExpiry(q):null)||shortAgo(q.created_at)));
|
||||
const what=node('span');what.append(gradePill(lowestGrade(items)),' '+productLine(items)+' · '+(q.draft.destination?q.draft.destination.city+'/'+q.draft.destination.state:'Retirada'));
|
||||
second.append(what);
|
||||
main.append(first,second);
|
||||
const warn=quoteWarning(q);
|
||||
if(warn){const w=node('span',undefined,'qwarn'+(warn[0]==='bad'?' bad':''));w.append(svgIcon(IC.alert,'i s'),node('span',warn[1]));main.append(w);}
|
||||
@@ -100,12 +101,25 @@ function renderQuotes(){
|
||||
// Approved by the Site is the rule; only a person's review is worth a word.
|
||||
if(pay||q.approved&&!q.auto_approved){const line=node('span',undefined,'qpay');
|
||||
if(pay)line.append(pay);if(q.approved&&!q.auto_approved)line.append(badge('Revisada pela equipe',''));main.append(line);}
|
||||
b.append(artBox(items,'qthumb'),main);
|
||||
const side=node('span',undefined,'qside');
|
||||
side.append(node('b',q.approved?money(q.approved.total_cents):metres(quoteMetres(q)),'qm'),
|
||||
node('span',(quoteKind==='approved'?quoteExpiry(q):null)||shortAgo(q.created_at),'qt'));
|
||||
b.append(artBox(items,'qthumb'),main,side);
|
||||
b.onclick=()=>{currentQuote=q;$('tab-quotes').classList.toggle('reviewing',PHONE.matches);renderQuotes();};return b;
|
||||
});
|
||||
const filtered=quoteQuery||quoteProduct||quoteLayout||quoteFlag;
|
||||
if(!list.length)list.push(node('p',filtered?'Nenhuma cotação com esses filtros.':
|
||||
quoteKind==='pending'?'Nenhuma cotação para revisar.':'Nenhuma cotação aprovada aguardando pagamento.','empty pad'));
|
||||
if(!list.length){
|
||||
if(filtered)list.push(node('p','Nenhuma cotação com esses filtros.','empty pad'));
|
||||
else if(quoteKind==='pending'){
|
||||
const waiting=board.approved_total||0;
|
||||
const action=button('Ver as '+waiting+' aguardando pagamento',async()=>{
|
||||
quoteKind='approved';quotePage=1;quoteFitting=0;currentQuote=null;
|
||||
await loadQuotes();
|
||||
},'btn');
|
||||
list.push(emptyState(IC.check,'Tudo revisado',
|
||||
'Nenhuma cotação esperando revisão. '+waiting+' estão aguardando pagamento.',action));
|
||||
}else list.push(node('p','Nenhuma cotação aprovada aguardando pagamento.','empty pad'));
|
||||
}
|
||||
$('quote-list').replaceChildren(...list);
|
||||
$('quote-pager').replaceChildren(...(quoteTotal?[pager({page:quotePage,size:quoteSize,total:quoteTotal,noun:'cotações',compact:true,fixedSize:true,
|
||||
onPage:n=>{quotePage=n;quoteFitting=0;loadQuotes().catch(e=>say(e.message,true));}})]:[]));
|
||||
@@ -114,9 +128,9 @@ function renderQuotes(){
|
||||
$('reviews').replaceChildren(...(currentQuote?[quoteHead(currentQuote),...review(currentQuote)]:[emptyState(IC.file,'Selecione uma cotação','A revisão dela abre aqui.')]));
|
||||
}
|
||||
// A page or a pane with nothing to show: a mark, a line, and what to do.
|
||||
function emptyState(d,title,text){
|
||||
function emptyState(d,title,text,action){
|
||||
const box=node('div',undefined,'emptystate'),ico=node('span',undefined,'dropico');ico.append(svgIcon(d));
|
||||
box.append(ico,node('b',title),...(text?[node('span',text)]:[]));return box;
|
||||
box.append(ico,node('b',title),...(text?[node('span',text)]:[]),...(action?[action]:[]));return box;
|
||||
}
|
||||
// The phone's head of a quote's page: back to the list, who, and WhatsApp.
|
||||
function quoteHead(quote){
|
||||
@@ -127,31 +141,42 @@ function quoteHead(quote){
|
||||
if(zap){const a=node('a',undefined,'mic');a.href=zap;a.target='_blank';a.rel='noopener noreferrer';a.setAttribute('aria-label','WhatsApp');a.append(svgIcon(IC.chat));h.append(a);}
|
||||
return h;
|
||||
}
|
||||
const QUOTE_STATUS={pending_review:['A revisar','warn'],approved:['Aprovada, aguardando pagamento','ok'],expired:['Expirada','bad'],paid:['Paga','ok']};
|
||||
const QUOTE_STATUS={pending_review:'A revisar',approved:'Aguardando pagamento',expired:'Expirada',paid:'Paga'};
|
||||
function whatsappAction(quote){
|
||||
const zap=whatsappLink(quote.draft.customer.zap);
|
||||
if(!zap)return null;
|
||||
const a=node('a','Abrir conversa','btn');
|
||||
a.href=zap;a.target='_blank';a.rel='noopener noreferrer';a.title=quote.draft.customer.zap;
|
||||
a.prepend(svgIcon(IC.chat,'i m'));
|
||||
return a;
|
||||
}
|
||||
function review(quote){
|
||||
const head=node('div',undefined,'rhead');head.dataset.quote=quote.id;
|
||||
const words=node('div',undefined,'rwords');
|
||||
const who=buyer(quote.draft), c=quote.draft.customer;
|
||||
const title=node('div',undefined,'rtitle');
|
||||
const h=node('h2',who.title);h.title=who.legal||who.title;
|
||||
const [label,tone]=QUOTE_STATUS[quote.status]||[quote.status,''];
|
||||
const status=badge(label,tone);status.prepend(node('span',undefined,'dot'));
|
||||
title.append(h,status);
|
||||
const h=node('h2',who.title);h.title=[who.legal,who.mail].filter(Boolean).join(' · ')||who.title;
|
||||
title.append(h,node('span',QUOTE_STATUS[quote.status]||quote.status,'tag'));
|
||||
const pay=paymentBadge(quote.payment);if(pay)title.append(pay);
|
||||
const meta=node('div',undefined,'rmeta');
|
||||
if(who.mail)meta.append(node('span',who.mail));
|
||||
const doc=node('span');doc.append(docKind(c.cnpj)+' '+cnpj(c.cnpj),copyButton(cnpj(c.cnpj),'Copiar '+docKind(c.cnpj)));meta.append(doc);
|
||||
const dest=quote.draft.destination,where=node('span');where.append(svgIcon(dest?IC.truck:IC.pin,'i s'),dest?'Entrega em '+dest.city+'/'+dest.state:'Retirada em Franca');meta.append(where);
|
||||
// The e-mail stays in sight: for many customers it is the only way to tell them apart.
|
||||
if(who.mail&&who.mail!==who.title)meta.append(node('span',who.mail));
|
||||
const dest=quote.draft.destination;
|
||||
meta.append(node('span',dest?'Entrega em '+dest.city+'/'+dest.state:'Retirada em Franca'));
|
||||
meta.append(node('span','Recebida '+ago(quote.created_at)),node('span','#'+quote.id.slice(0,8),'code'));
|
||||
words.append(title,meta);head.append(words);
|
||||
if(quote.approved){const total=node('div',undefined,'qbig');total.append(node('span','Total','lbl'),node('b',money(quote.approved.total_cents)));head.append(total);}
|
||||
const zap=whatsappLink(c.zap);
|
||||
if(zap){const a=node('a',quote.status==='approved'?'Abrir conversa':'WhatsApp','btn');a.href=zap;a.target='_blank';a.rel='noopener noreferrer';a.title=c.zap;a.prepend(svgIcon(IC.chat,'i m'));head.append(a);}
|
||||
const body=node('div',undefined,'rbody');
|
||||
const foot=node('div',undefined,'rfoot');
|
||||
const chat=whatsappAction(quote);
|
||||
const withChat=parts=>{
|
||||
if(chat){foot.append(node('span',undefined,'sp'),chat);parts.push(foot);}
|
||||
return parts;
|
||||
};
|
||||
if(quote.status==='pending_review'&"e.draft.items.some(item=>!LAYOUT_VERSIONS.includes(item.production?.version))){
|
||||
body.append(callout(IC.alert,'Montagem antiga.','Solicite uma nova cotação ao cliente.','bad'));
|
||||
return [head,body];
|
||||
return withChat([head,body]);
|
||||
}
|
||||
const count=quote.draft.items.length;
|
||||
if(quote.status!=='pending_review'){
|
||||
@@ -165,23 +190,24 @@ function review(quote){
|
||||
node('b',fr.total_cents?money(fr.total_cents):'grátis'),node('span','Total'),node('b',money(quote.approved.total_cents)));
|
||||
body.append(sums);
|
||||
}
|
||||
if(quote.status==='approved'&&may('enter'))body.append(registerForm(quote));
|
||||
if(quote.status==='approved'&&may('manage')){
|
||||
foot.append(discardButton(quote));
|
||||
foot.append(discardButton(quote),node('span',undefined,'sp'));
|
||||
// Tries the whole production flow without a payment.
|
||||
const test=button('Criar pedido de teste',async()=>{
|
||||
if(!await ask('Criar um pedido de teste?','Ele entra em Arte recebida sem cobrar nada e não vai para o Tiny.','Criar pedido de teste'))return;
|
||||
const order=await api('/quotes/'+quote.id+'/test-order',{});
|
||||
say('Pedido de teste #'+order.number+' criado em Arte recebida.');await load();
|
||||
},'btn right');
|
||||
},'btn');
|
||||
foot.append(test);
|
||||
if(chat)foot.append(chat);
|
||||
if(may('enter'))foot.append(button('Pedido pago fora do site',()=>registerDialog(quote),'btn pri'));
|
||||
return [head,body,foot];
|
||||
}
|
||||
return [head,body];
|
||||
return withChat([head,body]);
|
||||
}
|
||||
if(!may('manage')){
|
||||
quote.draft.items.forEach((item,index)=>body.append(quoteItem(item,null,null,index,count)));
|
||||
return [head,body];
|
||||
return withChat([head,body]);
|
||||
}
|
||||
const form=node('form',undefined,'rform');
|
||||
const edits=quote.draft.items.map((item,index)=>{const fields={};body.append(quoteItem(item,fields,null,index,count));
|
||||
@@ -190,8 +216,8 @@ function review(quote){
|
||||
const {residue_accepted_at,stroke_choice_at,...sent}=item;
|
||||
return ()=>({...sent,metres:fields.metres.value,grade:Number(fields.grade.value)});});
|
||||
const check=node('input');check.required=true;
|
||||
const submit=node('button','Aprovar cotação','btn pri lg');
|
||||
foot.append(checkbox('Arquivos, metragem e nota conferidos',check),discardButton(quote),submit);
|
||||
const submit=node('button','Aprovar cotação','btn pri');
|
||||
foot.append(checkbox('Arquivos, metragem e nota conferidos',check),...(chat?[chat]:[]),discardButton(quote),submit);
|
||||
form.append(body,foot);
|
||||
form.onsubmit=async e=>{e.preventDefault();submit.disabled=true;
|
||||
try{const approved=await api('/quotes/'+quote.id+'/approve',{items:edits.map(fn=>fn())});
|
||||
@@ -208,8 +234,7 @@ function callout(d,title,text,tone=''){
|
||||
// cart on the Site, as a customer would, and registers it here. Origin and
|
||||
// payment start unchosen: a default would become the answer to everything.
|
||||
const PAID_OUTSIDE={pix:'Pix',card:'Cartão',cash:'Dinheiro',credit:'Crédito do cliente',faturado:'Faturado'};
|
||||
function registerForm(quote){
|
||||
const form=node('form',undefined,'register');
|
||||
function registerDialog(quote){
|
||||
const group=(name,label,options)=>{
|
||||
const g=node('div',undefined,'fgroup2');g.setAttribute('role','radiogroup');g.setAttribute('aria-label',label);
|
||||
const set=node('div',undefined,'fopts');
|
||||
@@ -218,17 +243,17 @@ function registerForm(quote){
|
||||
r.type='radio';r.name=name+'-'+quote.id;r.value=value;r.required=true;r.className='vh';l.append(r,text);set.append(l);}
|
||||
g.append(node('span',label,'lbl'),set);return g;};
|
||||
const note=node('input');note.type='text';note.maxLength=300;note.placeholder='Observação (opcional)';note.setAttribute('aria-label','Observação');note.className='inp';
|
||||
const submit=node('button','Registrar pedido','btn pri');
|
||||
const row=node('div',undefined,'decide');row.append(note,submit);
|
||||
const head=node('div');head.append(node('h4','Pago fora do site?'),node('p','Registre o pedido: ele entra em Arte recebida como os outros.','nnote'));
|
||||
form.append(head,group('origin','Origem',ORIGINS),group('method','Como foi pago',PAID_OUTSIDE),row);
|
||||
form.onsubmit=async e=>{e.preventDefault();
|
||||
const pick=name=>form.querySelector('input[name="'+name+'-'+quote.id+'"]:checked')?.value;
|
||||
submit.disabled=true;
|
||||
try{const order=await api('/quotes/'+quote.id+'/register',{origin:pick('origin'),method:pick('method'),note:note.value});
|
||||
currentQuote=null;say('Pedido #'+order.number+' registrado em Arte recebida.');await load();}
|
||||
catch(error){say(error.message,true);submit.disabled=false;}};
|
||||
return form;
|
||||
// The class keeps kanban.js' auto-refresh guard: the choices stay on screen.
|
||||
const body=node('div',undefined,'register');
|
||||
body.append(group('origin','Origem',ORIGINS),group('method','Como foi pago',PAID_OUTSIDE),note);
|
||||
const pick=(form,name)=>form.querySelector('input[name="'+name+'-'+quote.id+'"]:checked')?.value;
|
||||
formDialog('Pedido pago fora do site',{host:dialogHost(),width:640,
|
||||
text:'Registre o pedido: ele entra em Arte recebida como os outros.',
|
||||
fields:[body],label:'Registrar pedido',
|
||||
onsave:async form=>{
|
||||
const order=await api('/quotes/'+quote.id+'/register',{origin:pick(form,'origin'),method:pick(form,'method'),note:note.value});
|
||||
currentQuote=null;say('Pedido #'+order.number+' registrado em Arte recebida.');await load();
|
||||
}});
|
||||
}
|
||||
const paidOutside=order=>order.payment?.provider==='manual';
|
||||
// An unpaid quote leaves the list and can no longer be paid.
|
||||
@@ -236,7 +261,7 @@ function discardButton(quote){
|
||||
return button('Descartar cotação',async()=>{
|
||||
if(!await ask('Descartar esta cotação?','Ela sai do Kanban e o cliente não consegue mais pagá-la.','Descartar cotação',{tone:'red'}))return;
|
||||
await api('/quotes/'+quote.id+'/discard',{});currentQuote=null;say('Cotação descartada.');await load();
|
||||
},'btn quiet right');
|
||||
},'btn quiet');
|
||||
}
|
||||
function quoteItem(item,fields,priced,index=0,count=1){
|
||||
const box=node('section',undefined,'ritem');box.setAttribute('aria-label','Item '+(index+1));
|
||||
@@ -244,14 +269,17 @@ function quoteItem(item,fields,priced,index=0,count=1){
|
||||
tall.append(itemPreview(item));
|
||||
const info=node('div',undefined,'iinfo');
|
||||
const spec=item.production;
|
||||
info.append(node('span',count>1?'Item '+(index+1)+' de '+count:'Item','lbl'),node('h3',productName(item)));
|
||||
const ihead=node('div',undefined,'ihead');
|
||||
ihead.append(node('h3',productName(item)));
|
||||
if(count>1)ihead.append(node('span','item '+(index+1)+' de '+count,'ilbl'));
|
||||
info.append(ihead);
|
||||
const dl=node('dl',undefined,'dl');
|
||||
const pair=(k,v)=>{if(v===null||v===undefined||v==='')return;const d=node('div');const dd=node('dd');dd.append(v);d.append(node('dt',k),dd);dl.append(d);};
|
||||
pair('Folha',sheetSize(spec));pair('Peças',spec?String(spec.placements.length):null);
|
||||
pair('Arquivos',spec?String(spec.sources.length):null);
|
||||
const g=node('span',undefined,'gradeline');g.append(gradePill(item.grade));pair('Nota da arte',g);
|
||||
pair('Metros cobrados',priced?metres(priced.billed_metres):null);
|
||||
pair('Valor do metro',priced?money(priced.unit_cents)+manualExtra(priced):null);
|
||||
const g=node('span',undefined,'gradeline');g.append(gradePill(item.grade));pair('Nota da arte',g);
|
||||
pair('Valor',priced?money(priced.total_cents):null);
|
||||
info.append(dl);
|
||||
const notes=node('div',undefined,'inotes');
|
||||
@@ -270,7 +298,9 @@ function quoteItem(item,fields,priced,index=0,count=1){
|
||||
grid.append(m,gr);info.append(grid);
|
||||
}
|
||||
const links=node('div',undefined,'links');
|
||||
const originals=node('details',undefined,'originals');originals.append(node('summary','Originais ('+item.uploads.length+')'));
|
||||
const originals=node('details',undefined,'originals'),summary=node('summary');
|
||||
summary.append(node('span','Originais ('+item.uploads.length+')'),svgIcon(IC.right,'i s'));
|
||||
originals.append(summary);
|
||||
item.uploads.forEach((uid,i)=>originals.append(downloadButton('Original '+(i+1),download(uid),'btn')));
|
||||
links.append(originals);
|
||||
info.append(links);box.append(tall,info);return box;
|
||||
|
||||
Reference in New Issue
Block a user