feat: montador Interno and Venda, Tiny customers, brand per stamp (front 7a.3, Marcus 10/11)

Interno: the Expedição assembles the marketplace's own sales on the fixed
internal customer Gestão fills in once; no Tiny order, no paid e-mail,
marked interno, it stays in house. Venda: a Vendedor or Gestão picks the
customer from the Tiny base and the order goes to Tiny like an approved
quote, faturado (Boleto from TINY_RECEIPT_BOLETO when set), pickup or
'junto com o pedido de roupa nº X'. Números counts both at table price,
apart from cash (and the average ticket over cash orders only). Each stamp
can carry a brand and a public flag for the future catalogue.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Cauê Faleiros
2026-11-11 11:01:44 -03:00
parent e6197d6e40
commit b5a51137fb
15 changed files with 710 additions and 97 deletions

View File

@@ -1,20 +1,115 @@
/* Kanban DTF: "Montar folha" (Fase 2, front 7). The stamps are the PNG files
in Estampas/ inside the folder chosen in Integrações; the sizes are the
table Gestão edits. The packing is the Site's own engine (web/packing.js).
Montar, which creates the card, is slice 2b. Uses the globals of kanban.js
and packing.js, loaded first. */
Montar creates the card: Interno for the Expedição, Venda for a customer
picked from Tiny (front 7a.3). Uses the globals of kanban.js and packing.js,
loaded first. */
const MONTAR_CODE=/^[A-Za-z0-9_-]{1,40}$/;
// The Site's ruler (web/site-config.js): the same numbers, copied there too.
const MONTAR_DPI_REFUSE=96, MONTAR_DPI_WARN=200;
const MONTAR_FILM_CM=57, MONTAR_GAP_CM=0.5;
const MONTAR={sizes:[],lines:[],seq:0,preview:null,timer:null,dirty:false,token:0,
layout:null,layoutTimer:null,layoutToken:0,layoutPending:false,creating:false,requestKey:null};
layout:null,layoutTimer:null,layoutToken:0,layoutPending:false,creating:false,requestKey:null,
kind:null,internal:null,internalDirty:false,brands:new Map(),contactToken:0,contactTimer:null};
const montarFolderReady=()=>!!FOLDER.handle&&!!FOLDER.granted;
const montarDpi=found=>found.width/(found.widthCm/2.54);
const montarHeight=found=>found.widthCm*(found.height/found.width);
const montarSelected=()=>MONTAR.sizes.find(size=>size.letter===$('montar-size').value)||null;
// ---- Interno or Venda ------------------------------------------------------
// Marcus's answers of 2026-11-10 (front 7a.3): the Expedição only makes
// Interno orders, the Vendedor only Venda, and Gestão and the administrators
// both. An Interno order uses the fixed internal customer; a Venda one is
// picked from Tiny.
const montarKindNames=()=>ME?.role==='expedicao'?['interno']:ME?.role==='vendedor'?['venda']:['interno','venda'];
const montarInternalField=key=>String(MONTAR.internal?.[key]||'');
const montarInternalReady=()=>!!MONTAR.internal&&['name','cnpj','zap','mail'].every(key=>montarInternalField(key).trim());
function montarPaintKind(){
const kinds=montarKindNames();
if(!MONTAR.kind||!kinds.includes(MONTAR.kind))MONTAR.kind=kinds.length===1?kinds[0]:'venda';
if(MONTAR.kind==='interno'&&!montarInternalReady()&&kinds.length>1){
MONTAR.kind='venda';
for(const id of ['montar-name','montar-doc','montar-zap','montar-mail'])$(id).value='';
}
const box=$('montar-kind');
$('montar-kind-hint').textContent=kinds.length===1
?(MONTAR.kind==='interno'?'Interno, para a Expedição.':'Venda, para o Vendedor.')
:'Interno para a Expedição; Venda para um cliente do Tiny.';
box.hidden=kinds.length<2;
box.replaceChildren(...kinds.map(kind=>{
const b=node('button',kind==='interno'?'Interno':'Venda',kind===MONTAR.kind?'on':'');b.type='button';
b.setAttribute('aria-pressed',String(kind===MONTAR.kind));
b.disabled=kind==='interno'&&!montarInternalReady();
b.title=b.disabled?'Peça à Gestão para completar o cliente interno.':'';
b.onclick=()=>montarSetKind(kind);
return b;
}));
$('montar-interno-missing').hidden=montarInternalReady();
}
function montarSetKind(kind){
if(MONTAR.kind===kind)return;
MONTAR.kind=kind;
montarClearCustomer();
montarPaintKind();montarPaintCustomer();montarPaintActions();
}
function montarPaintCustomer(){
const interno=MONTAR.kind==='interno';
$('montar-customer-title').textContent=interno?'Cliente interno':'Cliente';
$('montar-customer-search').hidden=interno;
$('montar-interno-note').hidden=!interno;
$('montar-delivery').hidden=interno;
for(const [id,key] of [['montar-name','name'],['montar-doc','cnpj'],['montar-zap','zap'],['montar-mail','mail']]){
$(id).disabled=interno;
if(interno)$(id).value=montarInternalField(key);
}
}
const montarDelivery=()=>document.querySelector('input[name="montar-delivery"]:checked')?.value||'pickup';
function montarPaintDelivery(){
const withOrder=montarDelivery()==='with_order';
$('montar-with-order').disabled=!withOrder;
if(!withOrder)$('montar-with-order').value='';
}
function montarWithOrder(){
if(MONTAR.kind!=='venda'||montarDelivery()!=='with_order')return null;
const value=Math.round(Number($('montar-with-order').value));
return Number.isInteger(value)&&value>=1&&value<=999999?value:null;
}
// The brand of a stamp, recorded for the future catalogue (Marcus, 10/11):
// only Gestão edits it; everyone who assembles reads it.
async function montarStampBrand(code){
if(MONTAR.brands.has(code))return MONTAR.brands.get(code);
const stamp=await api('/stamps/'+encodeURIComponent(code));
MONTAR.brands.set(code,stamp);
return stamp;
}
function montarBrandRow(code,stamp){
const current=stamp||{brand:'',public:false};
const row=node('div',undefined,'montar-brand');
row.append(node('span','Marca','lbl'));
if(!may('manage')){
row.append(node('b',current.brand||'—'),node('span',current.public?'Pública':'Não pública','lbl'));
return row;
}
const brand=node('input',undefined,'montar-brandinput');
brand.value=current.brand||'';brand.maxLength=120;brand.autocomplete='off';brand.spellcheck=false;
brand.setAttribute('aria-label','Marca da estampa '+code);
const pub=node('label',undefined,'montar-public');
const check=node('input');check.type='checkbox';check.checked=!!current.public;
pub.append(check,'Pública');
const save=node('button','Salvar marca','btn');save.type='button';
save.onclick=async()=>{
save.disabled=true;
try{
await api('/stamps/'+encodeURIComponent(code),{brand:brand.value.trim(),public:check.checked});
MONTAR.brands.set(code,{code,brand:brand.value.trim(),public:check.checked});
say('Marca salva.');
}catch(e){say(e.message,true);}finally{save.disabled=false;}
};
row.append(brand,pub,save);
return row;
}
// Without the folder there is no Estampas/ to read: only the size table works.
function montarPaintFolder(){
const ok=montarFolderReady();
@@ -59,14 +154,16 @@ function montarDropPreview(){
if(MONTAR.preview)URL.revokeObjectURL(MONTAR.preview.url);
MONTAR.preview=null;
}
function montarPaintPreview(found){
function montarPaintPreview(found,stamp){
montarDropPreview();
MONTAR.preview=found;
const words=node('span',undefined,'montar-stampinfo');
words.append(node('b',found.code),
node('span',cm(found.widthCm)+' cm de largura · '+cm(montarHeight(found))+' cm de altura · '+Math.floor(montarDpi(found))+' DPI'));
const img=node('img');img.src=found.url;img.alt='Estampa '+found.code;
const wrap=node('div',undefined,'montar-stamp');wrap.append(img,words);
const body=node('div',undefined,'montar-stampbody');
body.append(words,montarBrandRow(found.code,stamp));
const wrap=node('div',undefined,'montar-stamp');wrap.append(img,body);
$('montar-preview').replaceChildren(wrap);
}
function montarPaintNotFound(){
@@ -88,7 +185,12 @@ async function montarPreview(){
try{found=await montarRead(code,size);}
catch(e){if(token===MONTAR.token&&!montarFolderError(e))say(e.message,true);return;}
if(token!==MONTAR.token){if(found)URL.revokeObjectURL(found.url);return;}
if(found)montarPaintPreview(found);else montarPaintNotFound();
if(found){
let stamp=null;
try{stamp=await montarStampBrand(code);}catch(e){stamp={code,brand:'',public:false};}
if(token!==MONTAR.token){URL.revokeObjectURL(found.url);return;}
montarPaintPreview(found,stamp);
}else montarPaintNotFound();
}
function montarQueuePreview(){
clearTimeout(MONTAR.timer);
@@ -198,15 +300,24 @@ function montarCustomer(){
const montarCustomerFilled=()=>MONTAR_CUSTOMER.every(id=>$(id).value.trim());
function montarClearCustomer(){
for(const id of MONTAR_CUSTOMER)$(id).value='';
$('montar-customer-q').value='';
$('montar-customer-hits').hidden=true;
document.querySelector('input[name="montar-delivery"][value="pickup"]').checked=true;
montarPaintDelivery();
MONTAR.requestKey=null;
}
// Montar is the real thing now: a sheet, its layout and the customer.
// Montar is the real thing now: a sheet, its layout and the customer, which
// Interno reads from the database and Venda from Tiny.
function montarPaintActions(){
const build=$('montar-build');
const customerReady=MONTAR.kind==='interno'?montarInternalReady():montarCustomerFilled();
const ready=!!(MONTAR.lines.length&&MONTAR.layout&&!MONTAR.layoutPending&&
montarCustomerFilled()&&!MONTAR.creating);
customerReady&&!MONTAR.creating);
build.disabled=!ready;
build.title=ready?'':(MONTAR.lines.length?'Aguarde a montagem e preencha o cliente.':'Monte a folha primeiro.');
build.title=ready?'':(!MONTAR.lines.length?'Monte a folha primeiro.'
:(MONTAR.layoutPending||!MONTAR.layout)?'Aguarde a montagem da folha.'
:MONTAR.kind==='interno'?'Peça à Gestão para completar o cliente interno.'
:'Preencha os dados do cliente.');
}
// The Site's grade for loose art (web/site-quality.js): each stamp's DPI over
// the ideal 200, from 6 to 100; the item's is the average of its stamps'.
@@ -252,13 +363,23 @@ function montarItems(lines,uploads){
}
async function montarCreate(){
if(MONTAR.creating)return;
const customer=montarCustomer();
if(!montarCustomerFilled())return say('Preencha os dados do cliente.',true);
const kind=MONTAR.kind||'venda';
let customer=null,name='';
if(kind==='interno'){
if(!montarInternalReady())return say('Peça à Gestão para completar o cliente interno.',true);
name=montarInternalField('name');
}else{
customer=montarCustomer();
if(!montarCustomerFilled())return say('Preencha os dados do cliente.',true);
name=customer.name;
}
if(kind==='venda'&&montarDelivery()==='with_order'&&!montarWithOrder())
return say('Informe o número do pedido de roupa.',true);
if(!MONTAR.lines.length)return say('Monte a folha primeiro.',true);
if(!MONTAR.layout||MONTAR.layoutPending)return say('A montagem ainda está sendo calculada.',true);
const lines=[...MONTAR.lines];
if(!await ask('Criar pedido','Criar o pedido com '+plural(lines.reduce((t,line)=>t+line.qty,0),'estampa','estampas')+
', '+metres(MONTAR.layout.altura/100)+', para '+customer.name+'?','Criar pedido'))return;
', '+metres(MONTAR.layout.altura/100)+', para '+name+'?','Criar pedido'))return;
MONTAR.creating=true;montarPaintActions();
try{
const uploads=new Map();
@@ -271,11 +392,17 @@ async function montarCreate(){
}
say('Criando o pedido…');
if(!MONTAR.requestKey)MONTAR.requestKey=crypto.randomUUID();
const order=await api('/montador/orders',{request_key:MONTAR.requestKey,
customer,items:montarItems(lines,uploads)});
const body={request_key:MONTAR.requestKey,kind,items:montarItems(lines,uploads)};
if(kind==='venda'){
body.customer=customer;
const withOrder=montarWithOrder();
if(withOrder)body.with_order=withOrder;
}
const order=await api('/montador/orders',body);
MONTAR.requestKey=null;
montarClear();
montarClearCustomer();
montarPaintCustomer();
say('Pedido #'+order.number+' criado em Arte recebida.',false,10000);
load(true).catch(()=>{});
}catch(e){say(e.message,true);}
@@ -328,7 +455,9 @@ async function montarAdd(){
try{found=await montarRead(code,size);}
catch(e){if(!montarFolderError(e))say(e.message,true);return;}
if(!found){montarPaintNotFound();return say('Código não existe em Estampas/.',true);}
montarPaintPreview(found);
let stamp=null;
try{stamp=await montarStampBrand(code);}catch(e){stamp={code,brand:'',public:false};}
montarPaintPreview(found,stamp);
if(found.widthCm>56)return say('A estampa tem '+cm(found.widthCm)+' cm de largura: o máximo é 56 cm.',true);
const dpi=montarDpi(found);
if(dpi<MONTAR_DPI_REFUSE)return say('A estampa tem só '+Math.floor(dpi)+' DPI em '+size.letter+': pequena demais.',true);
@@ -392,9 +521,76 @@ async function montarLoadSizes(repaint){
montarPaintSelect();
if(repaint||!MONTAR.dirty)montarPaintSizeEditor();
}
// The fixed internal customer, completed by Gestão in the panel next to the
// size table. Copied into the form only while it is not being edited.
function montarPaintInternalFields(){
if(!may('manage'))return;
$('montar-interno-name').value=montarInternalField('name');
$('montar-interno-doc').value=montarInternalField('cnpj');
$('montar-interno-zap').value=montarInternalField('zap');
$('montar-interno-mail').value=montarInternalField('mail');
}
async function montarLoadInternal(repaint){
MONTAR.internal=await api('/internal-customer');
const panel=$('montar-interno-panel');
panel.hidden=!may('manage');
if(may('manage')&&(repaint||!MONTAR.internalDirty))montarPaintInternalFields();
montarPaintKind();
montarPaintCustomer();
montarPaintActions();
}
async function montarSaveInternal(){
const customer={name:$('montar-interno-name').value.trim(),cnpj:$('montar-interno-doc').value.trim(),
zap:$('montar-interno-zap').value.trim(),mail:$('montar-interno-mail').value.trim()};
if(!['name','cnpj','zap','mail'].every(key=>customer[key]))return say('Preencha todos os campos do cliente interno.',true);
await api('/internal-customer',customer);
MONTAR.internalDirty=false;
say('Cliente interno salvo.');
await montarLoadInternal(true);
}
// The Venda customer comes from Tiny's contacts, by name or CPF/CNPJ.
async function montarSearchContacts(){
const token=++MONTAR.contactToken,q=$('montar-customer-q').value.trim(),hits=$('montar-customer-hits');
if(q.length<2){hits.hidden=true;hits.replaceChildren();return;}
let contacts;
try{contacts=await api('/tiny/contacts?q='+encodeURIComponent(q));}
catch(e){
if(token!==MONTAR.contactToken)return;
hits.replaceChildren(node('p',e.message,'montar-hint'));hits.hidden=false;return;
}
if(token!==MONTAR.contactToken)return;
if(!contacts.length){hits.replaceChildren(node('p','Nenhum contato no Tiny.','montar-hint'));hits.hidden=false;return;}
hits.replaceChildren(...contacts.map(contact=>{
const hit=node('button',undefined,'montar-hit');hit.type='button';hit.setAttribute('role','option');
hit.append(node('b',contact.name||contact.document||'Contato'),
node('span',[contact.document,contact.email,contact.phone].filter(Boolean).join(' · '),'sub'));
hit.onclick=()=>montarPickContact(contact);
return hit;
}));
hits.hidden=false;
}
function montarQueueContacts(){
clearTimeout(MONTAR.contactTimer);
MONTAR.contactTimer=setTimeout(()=>montarSearchContacts().catch(e=>say(e.message,true)),300);
}
function montarPickContact(contact){
$('montar-name').value=contact.name||'';
$('montar-doc').value=contact.document||'';
$('montar-zap').value=contact.phone||'';
$('montar-mail').value=contact.email||'';
$('montar-customer-q').value=contact.name||contact.document||'';
$('montar-customer-hits').hidden=true;
MONTAR.requestKey=null;
montarPaintActions();
const missing=MONTAR_CUSTOMER.find(id=>!$(id).value.trim());
if(missing)$(missing).focus();
}
async function loadMontador(){
montarPaintFolder();
try{await montarLoadSizes(false);}
// Paint the chosen kind and customer before the fetch answers: an Expedição
// never sees an editable customer field, not even for a moment.
montarPaintKind();montarPaintCustomer();
try{await Promise.all([montarLoadSizes(false),montarLoadInternal(false)]);}
catch(e){say(e.message,true);return;}
if(montarFolderReady()){
if($('montar-code').value.trim()){if(!MONTAR.preview)montarQueuePreview();}
@@ -433,3 +629,22 @@ $('montar-size-save').onclick=async()=>{
$('montar-size-save').disabled=true;
try{await montarSaveSizes();}catch(e){say(e.message,true);}finally{$('montar-size-save').disabled=false;}
};
for(const id of ['montar-interno-name','montar-interno-doc','montar-interno-zap','montar-interno-mail'])
$(id).addEventListener('input',()=>{MONTAR.internalDirty=true;});
$('montar-interno-save').onclick=async()=>{
$('montar-interno-save').disabled=true;
try{await montarSaveInternal();}catch(e){say(e.message,true);}finally{$('montar-interno-save').disabled=false;}
};
$('montar-customer-q').addEventListener('input',montarQueueContacts);
$('montar-customer-q').addEventListener('focus',()=>{if($('montar-customer-hits').children.length)$('montar-customer-hits').hidden=false;});
$('montar-with-order').addEventListener('focus',()=>{
document.querySelector('input[name="montar-delivery"][value="with_order"]').checked=true;
montarPaintDelivery();
});
$('montar-with-order').addEventListener('input',()=>{MONTAR.requestKey=null;});
for(const radio of document.querySelectorAll('input[name="montar-delivery"]'))
radio.addEventListener('change',()=>{MONTAR.requestKey=null;montarPaintDelivery();});
document.addEventListener('click',event=>{
if(!event.target.closest('.montar-customer-search'))$('montar-customer-hits').hidden=true;
});
montarPaintDelivery();

View File

@@ -181,14 +181,17 @@ async function loadStats(){
const mk=(label,value,unit)=>{const k=node('div',undefined,'mk');const b=node('b',value);if(unit)b.append(node('small',unit));k.append(node('span',label),b);return k;};
const pct=n=>data.orders?Math.round(100*n/data.orders)+'%':'';
const [reais,centavos]=money(data.cents).split(',');
// The ticket is the cash received over the cash orders only: an Interno or
// faturado order records the table price, not money received (front 7a.3).
const cashOrders=Math.max(0,Number(data.orders)-(data.price_table||[]).reduce((sum,row)=>sum+(row.orders||0),0));
const hero=node('div',undefined,'hero');
hero.append(hk('Metros vendidos',metres(data.metres).replace(' m',''),'m',plural(data.orders,'pedido pago','pedidos pagos')),
hk('Recebido, com frete',reais,','+centavos,data.orders?'ticket médio de '+money(Math.round(data.cents/data.orders)):''),
hk('Recebido, com frete',reais,','+centavos,cashOrders?'ticket médio de '+money(Math.round(data.cents/cashOrders)):''),
hk('Do pagamento ao Finalizado',duration(data.lead.median_hours),'',data.lead.orders?'mediana de '+plural(data.lead.orders,'pedido','pedidos')+', sem o tempo em Aguardando contato':'nenhum finalizado no período'));
const rw=data.rework, share=v=>v==null?'—':String(v).replace('.',',')+'%';
const minis=node('div',undefined,'minis');
minis.append(mk('Pedidos pagos',String(data.orders)),
mk('Ticket médio',data.orders?money(Math.round(data.cents/data.orders)):'—'),
mk('Ticket médio',cashOrders?money(Math.round(data.cents/cashOrders)):'—'),
mk('Com correção',String(data.corrected),pct(data.corrected)),
mk('Artes tratadas',String(data.treated.orders),pct(data.treated.orders)),
mk('Retrabalho da casa',share(rw.house.percent),'meta '+share(rw.house.goal_percent)),
@@ -211,6 +214,12 @@ async function loadStats(){
tr.append(node('td',ORIGINS[o.origin]),node('td',String(o.orders),'r'),node('td',metres(o.metres).replace(' m',''),'r'),node('td',money(o.cents),'r'),
node('td',o.finished?duration(o.median_hours):'—','r'));
if(!o.orders)tr.classList.add('off');return tr;}));
// The montador's table price, apart from the money received (front 7a.3).
const priceNames={faturado:'Faturado',interno:'Interno'};
$('stats-price-table').replaceChildren(...(data.price_table||[]).map(p=>{const tr=node('tr');
tr.append(node('td',priceNames[p.method]||p.method),node('td',String(p.orders),'r'),
node('td',metres(p.metres).replace(' m',''),'r'),node('td',money(p.cents),'r'));
if(!p.orders)tr.classList.add('off');return tr;}));
// Approved orders never paid: made, paid, expired and the abandonment rate.
const unpaid=data.unpaid;
const unpaidRows=[['Pedidos feitos',String(unpaid.made)],['Pagos',String(unpaid.paid)],

View File

@@ -1289,6 +1289,32 @@ dialog.viewer::backdrop{background:var(--scrim)}
#tab-montar .montar-size-head{font-size:12.5px;color:var(--tx3)}
#tab-montar .montar-size-row input{height:36px;padding:0 10px;border-radius:9px;border:1px solid var(--ln2);background:var(--bg);color:var(--tx)}
#tab-montar .montar-size-row input:focus{border-color:var(--acc)}
/* The Tiny typeahead opens over the sheet: the panel must not clip it. */
#tab-montar #montar-sheet{overflow:visible}
#tab-montar .montar-kindbar{display:flex;align-items:center;gap:14px;flex-wrap:wrap;padding:12px 18px}
#tab-montar .montar-kindbar .phint{margin:0}
#tab-montar .montar-customer-search{position:relative;margin-bottom:12px}
#tab-montar .montar-hits{position:absolute;z-index:30;left:0;right:0;top:calc(100% + 4px);max-height:260px;overflow:auto;border:1px solid var(--ln2);border-radius:10px;background:var(--sf);box-shadow:0 12px 32px rgba(0,0,0,.25);padding:4px}
#tab-montar .montar-hit{display:flex;flex-direction:column;gap:2px;width:100%;padding:8px 10px;border:0;border-radius:7px;background:transparent;color:var(--tx);text-align:left;cursor:pointer}
#tab-montar .montar-hit:hover{background:var(--sf3)}
#tab-montar .montar-hit b{font-size:13.5px;font-weight:650}
#tab-montar .montar-hit .sub{font-size:12.5px;color:var(--tx3)}
#tab-montar .montar-delivery{border-top:1px solid var(--ln);padding:14px 18px}
#tab-montar .montar-delivery h3{margin:0 0 10px;font-size:13px;font-weight:650;color:var(--tx2)}
#tab-montar .montar-delivery-options{display:flex;flex-wrap:wrap;gap:8px}
#tab-montar .montar-radio{display:inline-flex;align-items:center;gap:8px;height:36px;padding:0 12px;border-radius:9px;border:1px solid var(--ln2);font-size:13px;font-weight:550;color:var(--tx2);cursor:pointer}
#tab-montar .montar-radio:has(input[type="radio"]:checked){border-color:var(--acc);color:var(--tx)}
#tab-montar .montar-radio input[type="number"]{width:110px;height:28px;padding:0 8px;border-radius:7px;border:1px solid var(--ln2);background:var(--bg);color:var(--tx);font-family:inherit;font-size:13px}
#tab-montar .montar-radio input[type="number"]:disabled{opacity:.5}
#tab-montar .montar-brand{display:flex;align-items:center;gap:10px;flex-wrap:wrap;margin-top:8px}
#tab-montar .montar-brand .lbl{font-size:12px;color:var(--tx3)}
#tab-montar .montar-brand b{font-size:13.5px;font-weight:650}
#tab-montar .montar-brandinput{width:190px;height:34px;padding:0 10px;border-radius:8px;border:1px solid var(--ln2);background:var(--bg);color:var(--tx);font-family:inherit;font-size:13px}
#tab-montar .montar-brandinput:focus{border-color:var(--acc)}
#tab-montar .montar-public{display:inline-flex;align-items:center;gap:6px;font-size:12.5px;color:var(--tx2);cursor:pointer}
#tab-montar .montar-public input{accent-color:var(--acc)}
#tab-montar .montar-stampbody{display:flex;flex-direction:column;gap:4px;min-width:0}
#tab-montar .montar-interno-fields{padding:0 18px}
@media (max-width:700px){
#tab-montar .montar-add{grid-template-columns:minmax(0,1fr) minmax(0,1fr);padding:14px 14px 0}
#tab-montar .montar-add>.btn{grid-column:1/-1}
@@ -1307,4 +1333,8 @@ dialog.viewer::backdrop{background:var(--scrim)}
#tab-montar .montar-warn{padding:10px 14px}
#tab-montar .montar-layout{height:260px;padding:8px}
#tab-montar .montar-size-head,#tab-montar .montar-size-row{grid-template-columns:70px minmax(0,1fr) 36px;padding:6px 14px}
#tab-montar .montar-kindbar{padding:12px 14px}
#tab-montar .montar-delivery{padding:12px 14px}
#tab-montar .montar-interno-fields{padding:0 14px}
#tab-montar .montar-brandinput{width:100%}
}

View File

@@ -117,6 +117,13 @@
</div>
</section>
<section id="tab-montar" class="page" hidden>
<section class="panel clip" id="montar-kind-panel">
<div class="phead"><h2>Pedido</h2><span class="n" id="montar-kind-hint"></span></div>
<div class="montar-kindbar">
<div class="seg" id="montar-kind" role="group" aria-label="Tipo de pedido"></div>
<p class="phint" id="montar-interno-missing" hidden>Peça à Gestão para completar o cliente interno.</p>
</div>
</section>
<section class="panel clip" id="montar-setup">
<div class="phead"><h2>Estampas</h2><span class="n" id="montar-folder"></span></div>
<p class="phint" id="montar-nofolder" hidden>Para ler as estampas, escolha a pasta dos pedidos em Integrações neste computador.</p>
@@ -133,13 +140,26 @@
<div id="montar-lines"></div>
<div id="montar-layout" class="montar-layout" hidden><canvas id="montar-canvas"></canvas></div>
<div class="montar-customer">
<h3>Cliente</h3>
<h3 id="montar-customer-title">Cliente</h3>
<div class="montar-customer-search" id="montar-customer-search">
<label class="fld"><span>Cliente no Tiny</span><input id="montar-customer-q" type="search" maxlength="120" autocomplete="off" spellcheck="false" placeholder="Nome ou CPF/CNPJ" role="combobox" aria-expanded="false" aria-controls="montar-customer-hits"></label>
<div class="montar-hits" id="montar-customer-hits" role="listbox" aria-label="Contatos do Tiny" hidden></div>
</div>
<div class="montar-customer-fields">
<label class="fld"><span>Nome</span><input id="montar-name" maxlength="80" autocomplete="off" placeholder="Como devemos chamar"></label>
<label class="fld"><span>CPF ou CNPJ</span><input id="montar-doc" inputmode="numeric" maxlength="18" autocomplete="off" placeholder="CPF ou CNPJ"></label>
<label class="fld"><span>WhatsApp</span><input id="montar-zap" inputmode="numeric" maxlength="15" autocomplete="off" placeholder="(16) 99999-9999"></label>
<label class="fld"><span>E-mail</span><input id="montar-mail" type="email" maxlength="254" autocomplete="off" placeholder="voce@empresa.com.br"></label>
</div>
<p class="phint" id="montar-interno-note" hidden>O cliente fixo dos pedidos internos.</p>
</div>
<div class="montar-delivery" id="montar-delivery">
<h3>Envio</h3>
<div class="montar-delivery-options">
<label class="montar-radio"><input type="radio" name="montar-delivery" value="pickup" checked> Retirada</label>
<label class="montar-radio"><input type="radio" name="montar-delivery" value="with_order"> Junto com o pedido de roupa nº <input id="montar-with-order" type="number" min="1" max="999999" step="1" inputmode="numeric" disabled></label>
</div>
<p class="phint">Envio com o frete do Site chega na próxima etapa.</p>
</div>
<div class="montar-actions">
<button class="btn ghost" id="montar-clear" type="button">Limpar lista</button>
@@ -154,6 +174,19 @@
<button class="btn pri" id="montar-size-save" type="button">Salvar</button>
</div>
</section>
<section class="panel clip" id="montar-interno-panel" hidden>
<div class="phead"><h2>Cliente interno</h2><span class="n">O cliente fixo dos pedidos Internos.</span></div>
<p class="phint">Enquanto algum campo estiver vazio, o pedido Interno fica indisponível.</p>
<div class="montar-customer-fields montar-interno-fields">
<label class="fld"><span>Nome</span><input id="montar-interno-name" maxlength="80" autocomplete="off" placeholder="Nexstar · Marketplace"></label>
<label class="fld"><span>CPF ou CNPJ</span><input id="montar-interno-doc" inputmode="numeric" maxlength="18" autocomplete="off" placeholder="CPF ou CNPJ"></label>
<label class="fld"><span>WhatsApp</span><input id="montar-interno-zap" inputmode="numeric" maxlength="15" autocomplete="off" placeholder="(16) 99999-9999"></label>
<label class="fld"><span>E-mail</span><input id="montar-interno-mail" type="email" maxlength="254" autocomplete="off" placeholder="voce@empresa.com.br"></label>
</div>
<div class="montar-actions">
<button class="btn pri" id="montar-interno-save" type="button">Salvar</button>
</div>
</section>
</section>
<section id="tab-payments" class="page" hidden>
<section id="payments"></section>
@@ -174,6 +207,8 @@
<section class="panel s4"><div class="phead"><h2>Artes tratadas, por quem aprovou</h2><span class="hint tip-l" tabindex="0" data-tip="Pedidos do período em que o arquivo final aprovado não é a arte do cliente: alguém da equipe preparou."><svg class="i s" viewBox="0 0 20 20" aria-hidden="true"><path d="M2.75 10a7.25 7.25 0 1 0 14.5 0a7.25 7.25 0 1 0 -14.5 0 M10 9v4.5 M10 6.25v.75"></path></svg></span></div>
<div class="fillbox short"><div class="scrollin bylist" id="stats-treated"></div></div></section>
</div>
<section class="panel clip"><div class="phead"><h2>Preço de tabela (não é caixa)</h2><span class="hint tip-l" tabindex="0" data-tip="Pedidos Internos e faturados do período: o preço de tabela fica registrado no pedido, mas esse valor não é dinheiro recebido."><svg class="i s" viewBox="0 0 20 20" aria-hidden="true"><path d="M2.75 10a7.25 7.25 0 1 0 14.5 0a7.25 7.25 0 1 0 -14.5 0 M10 9v4.5 M10 6.25v.75"></path></svg></span></div>
<table class="table"><thead><tr><th scope="col">Forma</th><th scope="col" class="r">Pedidos</th><th scope="col" class="r">Metros</th><th scope="col" class="r">Valor</th></tr></thead><tbody id="stats-price-table"></tbody></table></section>
<div class="g12">
<section class="panel clip s6"><div class="phead"><h2>Retrabalho</h2><span class="hint" tabindex="0" data-tip="Metros refeitos sobre o filme impresso no período, só os autorizados, pela data em que foram abertos. Arte ruim aprovada pelo cliente fica fora da meta."><svg class="i s" viewBox="0 0 20 20" aria-hidden="true"><path d="M2.75 10a7.25 7.25 0 1 0 14.5 0a7.25 7.25 0 1 0 -14.5 0 M10 9v4.5 M10 6.25v.75"></path></svg></span><span class="pill warn right" id="stats-rework-pending-pill" hidden></span></div>
<table class="table"><thead><tr><th scope="col">Causa</th><th scope="col" class="r">Refeito</th><th scope="col" class="w50" id="stats-rework-film">Do impresso, contra a meta</th></tr></thead><tbody id="stats-rework"></tbody></table>

View File

@@ -1114,6 +1114,8 @@ function card(order,place){
row.append(node('span','#'+order.number,'num'),originTag(order),age);
const name=node('span',who.title,'cname');name.title=[who.legal,who.mail].filter(Boolean).join(' · ')||who.title;
const meta=node('span',undefined,'cmeta');meta.append(node('span',productLine(s.items)));
const special=specialDelivery(s);
if(special){const tag=node('span',special,'origin');tag.title=special;meta.append(tag);}
if(order.machine){const m=node('span',order.machine.name,'mach'+(mine?' mine':''));m.title=mine?'Sua máquina':'Máquina';meta.append(m);}
meta.append(node('b',metres(orderMetres(order)),'mtr'));
info.append(row,name,meta);
@@ -1141,8 +1143,10 @@ function miniCard(order){
const name=node('span',who.title,'cname');name.title=who.mail||who.title;
let text,ic=IC.check,warn=false;
const days=Math.floor((Date.now()-new Date(order.updated_at))/86400000);
const special=specialDelivery(order.snapshot);
if(order.cancelled_at){text='Cancelado';ic=IC.ban;warn=true;}
else if(order.picked_up_at)text='Retirado';
else if(special){text=special;ic=IC.box;}
else if(order.snapshot.destination){text='Entrega, '+order.snapshot.destination.city+'/'+order.snapshot.destination.state;ic=IC.truck;}
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;}
@@ -1425,7 +1429,7 @@ function renderPanel(order){
// A proof card is no sale (app/proof.py): it says whose proof it is.
if(order.proof_parent)paid.append(node('b','Prova do pedido #'+order.proof_parent.number),', sem custo, criada em '+when(order.created_at));
else paid.append(node('b',money(s.total_cents)),isTest(order)?' sem pagamento, '+when(order.created_at):
paidOutside(order)?' pago fora do site ('+PAID_OUTSIDE[order.payment.method]+'), registrado em '+when(order.created_at):' pago em '+when(order.created_at));
paidOutside(order)?' pago fora do site ('+(PAID_OUTSIDE[order.payment.method]||order.payment.method)+'), registrado em '+when(order.created_at):' pago em '+when(order.created_at));
const code=node('span',undefined,'chip');
code.append(node('span','DTF-'+order.number,'code'),copyButton(fileCode(order),'Copiar “'+fileCode(order)+'”, o começo do nome dos arquivos deste pedido'));
const theirs=node('span','Código do cliente ','tip-l');theirs.append(node('span',orderCode(order.id),'code strong'));theirs.dataset.tip='O código que aparece para o cliente';
@@ -1822,6 +1826,10 @@ function pickupDialog(order){
}
// Pickup or delivery, from the freight the customer chose.
const isPickup=order=>order.snapshot.freight?.service==='pickup';
// An internal order stays in house, and a sale can travel with the customer's
// clothing order (Fase 2, front 7a.3): the card and the panel say so instead
// of "Retirada".
const specialDelivery=s=>s.kind==='interno'?'Interno':s.with_order?'Junto com o pedido de roupa nº '+s.with_order:null;
// ---- Final files: the file each item is printed from, approved by an operator.
const finalDone=order=>order.snapshot.items.every((_,index)=>(order.final_items||[]).includes(index));
const treatmentDone=order=>order.snapshot.items.every((_,index)=>order.treated?.items?.includes(index));
@@ -2230,7 +2238,7 @@ function phoneFacts(order){
const box=node('div',undefined,'mblock mfacts');
const row=(k,v)=>{if(!v)return;const r=node('div',undefined,'mfact');r.append(node('span',k),node('b',v));box.append(r);};
row('Cliente',who.title);row('E-mail',s.customer.mail);row(docKind(s.customer.cnpj),cnpj(s.customer.cnpj));
row('Entrega',dest?dest.city+'/'+dest.state:'Retirada em Franca');
row('Entrega',specialDelivery(s)||(dest?dest.city+'/'+dest.state:'Retirada em Franca'));
row('Máquina',order.machine?.name||'Nenhuma');row('Código','DTF-'+order.number+', cliente '+orderCode(order.id));
// Choosing the machine stays where it is allowed.
if(may('print')&&ME?.role!=='operador'&&board.machines?.length){const m=machineCard(order).querySelector('select');if(m)box.append(m);}
@@ -2246,9 +2254,10 @@ function orderFacts(order){
client.append(node('span','Cliente','lbl'),title,...(who.mail?[node('span',who.mail)]:[]),doc);
const zap=whatsappLink(s.customer.zap);
if(zap){const a=node('a','Abrir conversa','btn lnk');a.href=zap;a.target='_blank';a.rel='noopener noreferrer';a.title=s.customer.zap;a.prepend(svgIcon(IC.chat,'i s'));client.append(a);}
const where=node('div',undefined,'fact');
where.append(node('span','Entrega','lbl'),node('b',dest?dest.recipient:'Retirada em Franca'),
node('span',dest?dest.street+', '+dest.number+(dest.complement?' '+dest.complement:'')+', '+dest.district+', '+dest.city+'/'+dest.state+', CEP '+dest.postal_code:'O cliente retira na fábrica'));
const where=node('div',undefined,'fact'),special=specialDelivery(s);
where.append(node('span','Entrega','lbl'),node('b',special||(dest?dest.recipient:'Retirada em Franca')),
node('span',special?(special==='Interno'?'Fica na fábrica':'Sem frete próprio'):
dest?dest.street+', '+dest.number+(dest.complement?' '+dest.complement:'')+', '+dest.district+', '+dest.city+'/'+dest.state+', CEP '+dest.postal_code:'O cliente retira na fábrica'));
if(dest&&s.freight?.total_cents)where.append(node('span',(s.freight.description||'Jadlog')+', '+money(s.freight.total_cents)+(s.freight.weight_kg?', '+freightWeight(s.freight):''),'faint'));
grid.append(client,where);
if(order.machine||board.machines?.length)grid.append(machineCard(order));
@@ -2429,7 +2438,7 @@ function historyView(order,rows,view){
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',
paidOutside(order)?ORIGINS[order.origin]+', pago fora do site ('+(PAID_OUTSIDE[order.payment.method]||order.payment.method)+'), registrado por '+order.payment.operator:ORIGINS[order.origin]||'Site',
order.created_at,paidOutside(order)?order.payment.note:''));
view.replaceChildren(list);
}
@@ -3685,7 +3694,7 @@ function hitRow(items,title,sub,meta,state,tone,open){
function orderHit(order){
const s=order.snapshot;
return hitRow(s.items,'#'+order.number+' · '+orderCode(order.id),buyer(s).title,
s.items.map(i=>SHORT[i.mode]+' · '+metres(i.billed_metres)).join(' + ')+' · '+(s.destination?'Entrega':'Retirada')+' · pago '+when(order.created_at),
s.items.map(i=>SHORT[i.mode]+' · '+metres(i.billed_metres)).join(' + ')+' · '+(specialDelivery(s)||(s.destination?'Entrega':'Retirada'))+' · pago '+when(order.created_at),
order.cancelled_at?'Cancelado':board.states[order.state],order.cancelled_at?'bad':'',()=>{
// An older finished order is not on the board yet: it joins, like "Carregar mais".
if(!board.orders.some(o=>o.id===order.id)){olderFinished.push(order);board.orders.push(order);}