feat: Cotações shows the last payment attempt and fits the window
All checks were successful
Build and deploy / Validate source (push) Successful in 6s
Build and deploy / Integration suite on a real stack (push) Successful in 2m43s
Build and deploy / Secret scan and release gate (push) Successful in 5s
Build and deploy / Publish images (push) Successful in 53s

Each quote shows its latest payment attempt as a badge ("PIX gerado · expira
12:22", "PIX expirou sem pagamento", "Cartão recusado"), so "tried to pay" is
told apart from "never tried"; quote_view carries the PIX expiry and the
attempt's time for it. The quote stays payable for its 24 hours: a new PIX is
for the same quote.

Cotações now fills the window and never scrolls: a page holds as many quotes
as the list's height fits, measured after each render and on resize, and the
page bar sits at the bottom of the list.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Cauê Faleiros
2026-10-02 11:55:59 -03:00
parent 1fb2e5d55a
commit 5616db1345
4 changed files with 63 additions and 13 deletions

View File

@@ -78,7 +78,9 @@ def quote_view(c, row):
order = c.execute('SELECT id,number,state FROM dtf_local.orders WHERE quote_id=%s', (row['id'],)).fetchone()
# The latest payment attempt, so the payment page can tell a refused card
# (the notification updates it) from one still waiting.
attempt = c.execute('''SELECT method,status,response->>'status_detail' AS status_detail
# Its PIX expiry and time let the Kanban tell "tried to pay" from "never tried".
attempt = c.execute('''SELECT method,status,response->>'status_detail' AS status_detail,
response->>'expires_at' AS expires_at, created_at
FROM dtf_local.payment_intents WHERE quote_id=%s ORDER BY created_at DESC LIMIT 1''', (row['id'],)).fetchone()
expired = row['approved_at'] and row['approved_at'] < datetime.now(timezone.utc)-timedelta(hours=24)
return {'id': row['id'], 'created_at': row['created_at'],

View File

@@ -146,7 +146,12 @@ main{padding:0 24px 24px}
/* Quotes */
#tab-quotes{padding-top:18px}
.split{display:flex;gap:0;border:1px solid var(--line);border-radius:12px;overflow:hidden;min-height:calc(100vh - 140px)}
/* Cotações fills the window and no more: the top bar (64px), the tab's 18px
and main's 24px. Its parts scroll inside, never the page. */
.split{display:flex;gap:0;border:1px solid var(--line);border-radius:12px;overflow:hidden;height:calc(100vh - 106px);min-height:480px}
#quote-list{flex:1;min-height:0;overflow:hidden;display:flex;flex-direction:column;gap:8px}
#quote-pager:empty{display:none}
#quote-pager .pager{margin-top:0}
/* About a third of the screen: the rows carry a picture, the customer and the price. */
.split .list{width:clamp(460px,34vw,640px);flex-shrink:0;border-right:1px solid var(--line);padding:16px;display:flex;flex-direction:column;gap:12px;background:#111316}
.qitem{text-align:left;display:flex;align-items:center;gap:12px;padding:12px;border-radius:10px;border:1px solid var(--line2);background:var(--card);width:100%}
@@ -157,10 +162,10 @@ main{padding:0 24px 24px}
.chips.small{gap:6px}
.chips.small .chip{height:30px;padding:0 10px;font-size:13px}
.qitem[aria-current=true]{border-color:var(--accent);background:#1F1A15}
.pane{flex:1;min-width:0;display:flex;flex-direction:column}
.pane{flex:1;min-width:0;min-height:0;display:flex;flex-direction:column}
.pane .head{padding:18px 24px;border-bottom:1px solid var(--line);display:flex;align-items:center;gap:14px;flex-wrap:wrap}
.pane .head b{font-size:18px;overflow-wrap:anywhere}
.pane .content{flex:1;padding:20px 24px;display:flex;flex-direction:column;gap:16px}
.pane .content{flex:1;min-height:0;overflow:auto;padding:20px 24px;display:flex;flex-direction:column;gap:16px}
.pane .fields{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:14px}
.pane .fields label{display:flex;flex-direction:column;gap:6px;font-size:13.5px;font-weight:600;color:var(--muted)}
.pane .fields input[readonly]{color:var(--faint);background:var(--panel);border-color:var(--line2)}
@@ -215,6 +220,8 @@ table.log td{padding:10px 12px;border-bottom:1px solid #1E2226;vertical-align:to
.results{width:100%}
main{padding:0 16px 16px}
.split{flex-direction:column}
.split{height:auto}
#quote-list{overflow:visible}
.split .list{width:auto;border-right:0;border-bottom:1px solid var(--line)}
.facts,.pane .fields{grid-template-columns:1fr}
}

View File

@@ -51,7 +51,8 @@
<input id="quote-q" type="search" placeholder="Filtrar por e-mail, CNPJ ou WhatsApp" aria-label="Filtrar cotações por cliente" autocomplete="off">
</label>
<div class="chips small" id="quote-chips"></div>
<div id="quote-list" style="display:flex;flex-direction:column;gap:8px"></div>
<div id="quote-list"></div>
<div id="quote-pager"></div>
</div>
<div class="pane" id="reviews"></div>
</div>

View File

@@ -132,6 +132,22 @@ function buyerBlock(content,className){
if(who.mail)box.append(node('span',who.mail,'buyer-mail'));
return box;
}
// The quote's latest payment attempt as a badge; none means nobody tried yet.
function paymentBadge(p){
if(!p)return null;
const hour=v=>new Date(v).toLocaleTimeString('pt-BR',{hour:'2-digit',minute:'2-digit'});
const tried=' · tentativa '+when(p.created_at);
if(p.method==='pix'){
if(p.status==='approved')return badge('✓ PIX pago','ok');
const live=p.status==='pending'&&p.expires_at&&new Date(p.expires_at)>Date.now();
return live?badge('PIX gerado · expira '+hour(p.expires_at),'info','O cliente gerou o código'+tried)
:badge('! PIX expirou sem pagamento','warn','O código venceu e o cliente ainda pode gerar outro'+tried);
}
if(p.status==='approved')return badge('✓ Cartão aprovado','ok');
if(p.status==='rejected')return badge('! Cartão recusado','bad',(p.status_detail?'Motivo: '+p.status_detail:'Recusado')+tried);
if(p.status==='pending')return badge(p.status_detail==='pending_challenge'?'Cartão aguardando o banco':'Cartão em análise','info',tried.slice(3));
return badge('Pagamento '+p.status,'',tried.slice(3));
}
const sheetSize=p=>p?cm(p.film_width_cm)+' × '+cm(p.height_cm)+' cm':null;
const hoursSince=v=>Math.floor((Date.now()-new Date(v))/3600000);
// The freight's weight: what the package weighs and, when Jadlog charges the
@@ -547,9 +563,31 @@ function historySection(order,rows,section){
// ---- Quotes --------------------------------------------------------------
function quoteMetres(q){return (q.approved||q.draft).items.reduce((s,i)=>s+Number(i.billed_metres||i.metres),0);}
let quoteRows=[], quoteTotal=0, quotePage=1, quoteSize=20, currentQuote=null, quoteLoading=0;
let quoteRows=[], quoteTotal=0, quotePage=1, quoteSize=0, currentQuote=null, quoteLoading=0, quoteFitting=0;
// Cotações never scrolls: a page holds as many quotes as the list's height fits.
// Before the first page, a guess from the height; after it, measured rows.
function guessQuoteSize(){return Math.max(3,Math.floor(($('quote-list').clientHeight||600)/96));}
function fitQuotes(){
const list=$('quote-list'), rows=[...list.querySelectorAll('.qitem')];
if($('tab-quotes').hidden||!rows.length||quoteFitting>3)return;
const room=list.clientHeight, gap=8;
const fits=rows.filter(r=>r.offsetTop-list.offsetTop+r.offsetHeight<=room).length;
const tallest=Math.max(...rows.map(r=>r.offsetHeight));
let size=quoteSize;
if(fits<rows.length)size=Math.max(1,fits);
else if(quoteTotal>(quotePage-1)*quoteSize+rows.length||rows.length<quoteSize){
const used=rows.at(-1).offsetTop-list.offsetTop+rows.at(-1).offsetHeight;
size=rows.length+Math.max(0,Math.floor((room-used)/(tallest+gap)));
}
if(size===quoteSize)return;
const first=(quotePage-1)*quoteSize;quoteSize=size;quotePage=Math.floor(first/size)+1;quoteFitting++;
loadQuotes().catch(e=>say(e.message,true));
}
let quoteResize=null;
addEventListener('resize',()=>{clearTimeout(quoteResize);quoteResize=setTimeout(()=>{quoteFitting=0;fitQuotes();},200);});
async function loadQuotes(){
const token=++quoteLoading;
if(!quoteSize)quoteSize=guessQuoteSize();
const params=new URLSearchParams({kind:quoteKind,limit:String(quoteSize),offset:String((quotePage-1)*quoteSize)});
for(const [key,value] of [['q',quoteQuery],['product',quoteProduct],['layout',quoteLayout],['flag',quoteFlag]])if(value)params.set(key,value);
const page=absorb(await api('/quotes?'+params));
@@ -562,7 +600,7 @@ function renderQuotes(){
const kinds=[['pending','A revisar',board.pending_total],['approved','Aprovadas, aguardando pagamento',board.approved_total]];
$('quote-filters').replaceChildren(...kinds.map(([key,label,count])=>{
const b=node('button',label+' · '+count,'chip');b.type='button';b.setAttribute('aria-pressed',String(quoteKind===key));
b.onclick=()=>{quoteKind=key;quotePage=1;currentQuote=null;loadQuotes().catch(e=>say(e.message,true));};return b;}));
b.onclick=()=>{quoteKind=key;quotePage=1;quoteFitting=0;currentQuote=null;loadQuotes().catch(e=>say(e.message,true));};return b;}));
// Product, layout and warning: each chip toggles; the two of a pair exclude each other.
const toggles=[['product','textil','Têxtil'],['product','uv','UV'],['layout','folha','Folha montada'],
['layout','avulsa','Artes avulsas'],['flag','ressalva','Com ressalva']];
@@ -571,7 +609,7 @@ function renderQuotes(){
const b=node('button',label,'chip');b.type='button';b.setAttribute('aria-pressed',String(value[group]===key));
b.onclick=()=>{const next=value[group]===key?'':key;
if(group==='product')quoteProduct=next;else if(group==='layout')quoteLayout=next;else quoteFlag=next;
quotePage=1;loadQuotes().catch(e=>say(e.message,true));};return b;}));
quotePage=1;quoteFitting=0;loadQuotes().catch(e=>say(e.message,true));};return b;}));
if(!currentQuote||(!quoteRows.some(q=>q.id===currentQuote.id)&&currentQuote.status==='pending_review'))currentQuote=quoteRows[0]||null;
else currentQuote=quoteRows.find(q=>q.id===currentQuote.id)||currentQuote;
const list=quoteRows.map(q=>{
@@ -590,16 +628,17 @@ function renderQuotes(){
if(!q.approved&&q.review_reason)flags.append(badge('! '+q.review_reason,'warn','Revisão manual: '+q.review_reason));
// Approved by the Site is the rule; only a person's review is worth a line.
if(q.approved&&!q.auto_approved)flags.append(badge('Revisada pela equipe',''));
const pay=paymentBadge(q.payment);if(pay)flags.append(pay);
const main=node('div',undefined,'qmain');main.append(head,meta);if(flags.children.length)main.append(flags);
b.append(artBox(items,'qart'),main);b.onclick=()=>{currentQuote=q;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.','faint'));
if(quoteTotal)list.push(pager({page:quotePage,size:quoteSize,total:quoteTotal,noun:'cotações',compact:true,
onPage:n=>{quotePage=n;loadQuotes().catch(e=>say(e.message,true));},
onSize:n=>{quoteSize=n;quotePage=1;loadQuotes().catch(e=>say(e.message,true));}}));
$('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));}})]:[]));
requestAnimationFrame(fitQuotes);
$('reviews').replaceChildren(currentQuote?review(currentQuote):node('p','Selecione uma cotação.','note'));
}
function review(quote){
@@ -608,6 +647,7 @@ function review(quote){
const status={pending_review:['● A revisar','accent'],approved:['● Aprovada · aguardando pagamento','ok'],
expired:['Expirada','bad'],paid:['● Paga','info']}[quote.status]||[quote.status,''];
const name=node('div',undefined,'qname');name.append(buyerBlock(quote.draft),badge(...status));
const pay=paymentBadge(quote.payment);if(pay)name.append(pay);
const sub=node('div',undefined,'qsub');const c=quote.draft.customer;
const doc=node('span');doc.append('CNPJ '+cnpj(c.cnpj),copyButton(cnpj(c.cnpj),'Copiar CNPJ'));sub.append(doc);
const zap=whatsappLink(c.zap);
@@ -724,7 +764,7 @@ function integration(name,state,tone,text,actions=[]){
}
// The page bar under every list: page size, range, first/previous/page/next/last.
const PAGE_SIZES=[10,20,50,100];
function pager({page,size,total,noun,onPage,onSize,compact=false}){
function pager({page,size,total,noun,onPage,onSize,compact=false,fixedSize=false}){
const pages=Math.max(1,Math.ceil(total/size));
const bar=node('div',undefined,'pager'+(compact?' compact':''));
const sizeLabel=node('label',undefined,'pager-size');
@@ -741,7 +781,7 @@ function pager({page,size,total,noun,onPage,onSize,compact=false}){
pageLabel.append(compact?'':'Página',input,'de '+pages);
nav.append(go('«','Primeira página',1,page<=1),go('‹','Página anterior',page-1,page<=1),pageLabel,
go('›','Próxima página',page+1,page>=pages),go('»','Última página',pages,page>=pages));
bar.append(sizeLabel,node('span',(compact?'':'Mostrando ')+from+' a '+to+' de '+total+(compact?'':' '+noun),'pager-range'),nav);
bar.append(...(fixedSize?[]:[sizeLabel]),node('span',(compact?'':'Mostrando ')+from+' a '+to+' de '+total+(compact?'':' '+noun),'pager-range'),nav);
return bar;
}
function chips(container,options,current,pick){