diff --git a/app/api/operator.py b/app/api/operator.py index 1cbb160..1f8b820 100644 --- a/app/api/operator.py +++ b/app/api/operator.py @@ -23,6 +23,10 @@ from ..scanning import require_clean router = APIRouter() +# A quote that can still become an order: waiting for review, or approved within +# the payment window. Expired ones leave the Kanban; they can never be paid. +LIVE_QUOTE = f"(q.approved_at IS NULL OR q.approved_at > now() - interval '{int(payments.QUOTE_VALID_HOURS)} hours')" + @router.post('/api/operator/login') def operator_login(body: OperatorLogin, request: Request, response: Response): email = body.email @@ -97,16 +101,16 @@ def board(user=Depends(operator)): LEFT JOIN dtf_local.orders o ON o.quote_id=q.id WHERE o.id IS NULL AND q.approved IS NULL ORDER BY q.created_at DESC,q.id DESC LIMIT %s''', (BOARD_QUOTE_LIMIT,)).fetchall() - approved = c.execute('''SELECT q.* FROM dtf_local.quotes q + approved = c.execute(f'''SELECT q.* FROM dtf_local.quotes q LEFT JOIN dtf_local.orders o ON o.quote_id=q.id - WHERE o.id IS NULL AND q.approved IS NOT NULL + WHERE o.id IS NULL AND q.approved IS NOT NULL AND {LIVE_QUOTE} ORDER BY q.created_at DESC,q.id DESC LIMIT 20''').fetchall() pending_total = c.execute('''SELECT count(*) AS n FROM dtf_local.quotes q LEFT JOIN dtf_local.orders o ON o.quote_id=q.id WHERE o.id IS NULL AND q.approved IS NULL''').fetchone()['n'] - approved_total = c.execute('''SELECT count(*) AS n FROM dtf_local.quotes q + approved_total = c.execute(f'''SELECT count(*) AS n FROM dtf_local.quotes q LEFT JOIN dtf_local.orders o ON o.quote_id=q.id - WHERE o.id IS NULL AND q.approved IS NOT NULL''').fetchone()['n'] + WHERE o.id IS NULL AND q.approved IS NOT NULL AND {LIVE_QUOTE}''').fetchone()['n'] orders = with_print_files(c, active + list(reversed(finished))) # A paid notification that did not become an order is money received # for nothing the factory will make. The board carries the count; the @@ -257,7 +261,7 @@ def quote_page(kind: Literal['pending','approved'], before_created_at: datetime filtered by customer, product, layout and an accepted resolution warning.""" if (before_created_at is None) != (before_id is None): raise HTTPException(422, 'Both quote cursor fields are required') - clauses = ['o.id IS NULL', 'q.approved IS NULL' if kind == 'pending' else 'q.approved IS NOT NULL'] + clauses = ['o.id IS NULL', LIVE_QUOTE, 'q.approved IS NULL' if kind == 'pending' else 'q.approved IS NOT NULL'] params = [] if q and q.strip(): sql, values = customer_match('q.draft', q) @@ -302,7 +306,7 @@ def search(q: str = Query(min_length=2, max_length=100), user=Depends(operator)) ORDER BY created_at DESC LIMIT 8''', params).fetchall() rows = c.execute(f'''SELECT q.* FROM dtf_local.quotes q LEFT JOIN dtf_local.orders o ON o.quote_id=q.id - WHERE o.id IS NULL AND {quote_match} + WHERE o.id IS NULL AND {LIVE_QUOTE} AND {quote_match} ORDER BY q.created_at DESC LIMIT 8''', quote_params).fetchall() orders = with_print_files(c, orders) quotes = [quote_view(c, row) for row in rows] diff --git a/web/kanban.css b/web/kanban.css index 6a2fd8a..116dd85 100644 --- a/web/kanban.css +++ b/web/kanban.css @@ -280,7 +280,8 @@ a.zap{display:inline-flex;align-items:center;gap:4px;vertical-align:bottom} /* Quote rows */ .qitem .qmain{flex:1;min-width:0;display:flex;flex-direction:column;gap:6px} .qhead{display:flex;align-items:center;gap:8px;min-width:0} -.qmail{font-size:14.5px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis} +.qmail{min-width:0} +.qmail b{display:block;font-size:14.5px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis} .qtotal{margin-left:auto;font-size:15px;flex-shrink:0} .qtotal.muted{font-size:13px;font-weight:600} .newdot{width:7px;height:7px;flex-shrink:0;border-radius:999px;background:var(--accent)} @@ -329,3 +330,10 @@ a.zap{display:inline-flex;align-items:center;gap:4px;vertical-align:bottom} .timeline small{flex-shrink:0;color:var(--faint);font-size:13px} /* Without a picture, a long sheet's layout drawing stays a preview, not a column. */ .item .preview:not(.with-art) svg{width:auto;max-width:100%;max-height:260px;margin:0 auto} + +/* The buyer: a name over the e-mail, or the e-mail alone. */ +.buyer{display:flex;flex-direction:column;min-width:0} +.buyer b{white-space:nowrap;overflow:hidden;text-overflow:ellipsis} +.buyer-mail{font-size:12.5px;color:var(--faint);white-space:nowrap;overflow:hidden;text-overflow:ellipsis} +.card .buyer b{font-size:14px;font-weight:600} +.qname .buyer b{font-size:19px} diff --git a/web/kanban.js b/web/kanban.js index c81fbf1..ef9c20e 100644 --- a/web/kanban.js +++ b/web/kanban.js @@ -118,6 +118,20 @@ function facts(pairs){ for(const [k,v] of pairs){if(v===null||v===undefined||v==='')continue;const d=node('div');d.append(node('dt',k),node('dd',v));dl.append(d);} return dl; } +// Who is buying: a name when the order has one (the customer's, or whoever +// receives the delivery), else the e-mail. With a name, the e-mail is the +// second line, still searchable. +function buyer(content){ + const c=content.customer||{}, name=(c.name||content.destination?.recipient||'').trim(); + return {title:name||c.mail, mail:name?c.mail:''}; +} +function buyerBlock(content,className){ + const who=buyer(content); + const box=node('div',undefined,'buyer '+(className||'')); + const title=node('b',who.title);title.title=who.mail||who.title;box.append(title); + if(who.mail)box.append(node('span',who.mail,'buyer-mail')); + return box; +} 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 @@ -303,7 +317,7 @@ function card(order){ if(s.items.some(i=>i.quality_status==='warning'))flags.append(badge('! Ressalva','warn','O cliente aceitou a ressalva de resolução')); if(stalled(order))flags.append(badge('⏱ Parado '+hoursSince(order.updated_at)+' h','bad','Sem mudar de etapa desde '+when(order.updated_at))); } - c.append(artBox(s.items,'card-art'),top,node('div',s.customer.mail,'cust'),meta,place(s.destination)); + c.append(artBox(s.items,'card-art'),top,buyerBlock(s,'cust'),meta,place(s.destination)); if(flags.children.length)c.append(flags); c.onclick=()=>openPanel(order.id); c.ondragstart=e=>{ @@ -372,7 +386,7 @@ function renderPanel(order){ const facts=node('section',undefined,'facts'); const who=node('div',undefined,'fcard'); const doc=node('span',undefined,'line');doc.append('CNPJ '+cnpj(s.customer.cnpj),copyButton(cnpj(s.customer.cnpj),'Copiar CNPJ')); - who.append(node('p','Cliente','eyebrow'),node('b',s.customer.mail),doc); + who.append(node('p','Cliente','eyebrow'),buyerBlock(s),doc); const zap=whatsappLink(s.customer.zap); if(zap){const a=node('a','Abrir conversa','zapbtn');a.href=zap;a.target='_blank';a.rel='noopener noreferrer';a.title=s.customer.zap;a.prepend(icon(ICON_CHAT));who.append(a);} const where=node('div',undefined,'fcard'); @@ -566,8 +580,7 @@ function renderQuotes(){ const head=node('div',undefined,'qhead'); // 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';head.append(dot);} - const mail=node('b',q.draft.customer.mail,'qmail');mail.title=q.draft.customer.mail; - head.append(mail,node('b',q.approved?money(q.approved.total_cents):'a revisar','qtotal'+(q.approved?'':' muted'))); + head.append(buyerBlock(q.draft,'qmail'),node('b',q.approved?money(q.approved.total_cents):'a revisar','qtotal'+(q.approved?'':' muted'))); const meta=node('div',undefined,'meta'); meta.append(gradePill(lowestGrade(items)),productBadge(items),node('b',metres(quoteMetres(q)),'mtr'), place(q.draft.destination),node('span',ago(q.created_at),'age')); @@ -594,7 +607,7 @@ function review(quote){ const head=node('div',undefined,'head');const title=node('div',undefined,'qtitle'); 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(node('b',quote.draft.customer.mail),badge(...status)); + const name=node('div',undefined,'qname');name.append(buyerBlock(quote.draft),badge(...status)); 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); @@ -927,7 +940,7 @@ function hitRow(items,title,sub,meta,badge,color,open){ } function orderHit(order){ const s=order.snapshot; - return hitRow(s.items,'#'+order.number,s.customer.mail, + return hitRow(s.items,'#'+order.number,buyer(s).title, s.items.map(i=>SHORT[i.mode]+' · '+metres(i.billed_metres)).join(' + ')+' · '+(s.destination?'Entrega':'Retirada')+' · pago '+when(order.created_at), board.states[order.state],STAGE_COLORS[order.state],()=>{ // An older finished order is not on the board yet: it joins, like "Carregar mais". @@ -935,7 +948,7 @@ function orderHit(order){ showTab('board');openPanel(order.id);}); } function quoteHit(q){ - return hitRow(q.draft.items,q.approved?money(q.approved.total_cents):'Cotação '+q.id.slice(0,8),q.draft.customer.mail, + return hitRow(q.draft.items,q.approved?money(q.approved.total_cents):'Cotação '+q.id.slice(0,8),buyer(q.draft).title, q.draft.items.map(i=>SHORT[i.mode]).join(' + ')+' · '+metres(quoteMetres(q))+' · '+ago(q.created_at), q.approved?'Aguardando pagamento':'A revisar',q.approved?'':'var(--accent)',()=>{ // Opens Cotações filtered to this customer, with this quote selected.