diff --git a/app/runtime.py b/app/runtime.py index eac94fc..1f0190d 100644 --- a/app/runtime.py +++ b/app/runtime.py @@ -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'], diff --git a/web/kanban.css b/web/kanban.css index 116dd85..127d38b 100644 --- a/web/kanban.css +++ b/web/kanban.css @@ -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} } diff --git a/web/kanban.html b/web/kanban.html index a190898..fc2e930 100644 --- a/web/kanban.html +++ b/web/kanban.html @@ -51,7 +51,8 @@
- + + diff --git a/web/kanban.js b/web/kanban.js index ef9c20e..a082174 100644 --- a/web/kanban.js +++ b/web/kanban.js @@ -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