feat: Montar creates the invoiced order card (front 7a.2b)
The montador sends each stamp to storage, splits the list into items of at most 20 sources and 4000 copies, packs each one with the Site's engine and creates the order in Arte recebida: typed customer, pickup, the Site's table price, payment 'faturado', origin dropflow for Expedição and atendimento otherwise. Until Dropstar decides, these orders do not go to Tiny and the customer gets no paid e-mail. Vendedor and Expedição may now upload through the operator upload routes (can_any). Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -8,7 +8,7 @@ const MONTAR_CODE=/^[A-Za-z0-9_-]{1,40}$/;
|
||||
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};
|
||||
layout:null,layoutTimer:null,layoutToken:0,layoutPending:false,creating:false,requestKey:null};
|
||||
|
||||
const montarFolderReady=()=>!!FOLDER.handle&&!!FOLDER.granted;
|
||||
const montarDpi=found=>found.width/(found.widthCm/2.54);
|
||||
@@ -113,6 +113,7 @@ function montarPaintTotals(){
|
||||
$('montar-count').textContent=MONTAR.lines.length?plural(MONTAR.lines.length,'estampa','estampas'):'';
|
||||
$('montar-clear').disabled=!MONTAR.lines.length;
|
||||
$('montar-warning').hidden=!(MONTAR.lines.length>20||MONTAR.lines.some(line=>line.qty>200));
|
||||
montarPaintActions();
|
||||
}
|
||||
// The line's image, loaded once and kept for the packing and the preview.
|
||||
function montarStampImage(url){
|
||||
@@ -127,6 +128,7 @@ function montarChanged(){
|
||||
MONTAR.layoutToken+=1;
|
||||
MONTAR.layout=null;
|
||||
MONTAR.layoutPending=true;
|
||||
MONTAR.requestKey=null;
|
||||
montarPaintLines();
|
||||
if(!MONTAR.lines.length)montarDrawPreview(null);
|
||||
clearTimeout(MONTAR.layoutTimer);
|
||||
@@ -186,6 +188,100 @@ function montarDrawPreview(layout){
|
||||
ctx.restore();
|
||||
}
|
||||
}
|
||||
// ---- Criar o pedido -------------------------------------------------------
|
||||
// The typed customer, as the Site's own Customer model validates it.
|
||||
const MONTAR_CUSTOMER=['montar-name','montar-doc','montar-zap','montar-mail'];
|
||||
function montarCustomer(){
|
||||
return {name:$('montar-name').value.trim(),cnpj:$('montar-doc').value.trim(),
|
||||
zap:$('montar-zap').value.trim(),mail:$('montar-mail').value.trim()};
|
||||
}
|
||||
const montarCustomerFilled=()=>MONTAR_CUSTOMER.every(id=>$(id).value.trim());
|
||||
function montarClearCustomer(){
|
||||
for(const id of MONTAR_CUSTOMER)$(id).value='';
|
||||
MONTAR.requestKey=null;
|
||||
}
|
||||
// Montar is the real thing now: a sheet, its layout and the customer.
|
||||
function montarPaintActions(){
|
||||
const build=$('montar-build');
|
||||
const ready=!!(MONTAR.lines.length&&MONTAR.layout&&!MONTAR.layoutPending&&
|
||||
montarCustomerFilled()&&!MONTAR.creating);
|
||||
build.disabled=!ready;
|
||||
build.title=ready?'':(MONTAR.lines.length?'Aguarde a montagem e preencha o cliente.':'Monte a folha primeiro.');
|
||||
}
|
||||
// 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'.
|
||||
const montarGrade=dpi=>Math.max(6,Math.min(100,Math.round(dpi/200*100)));
|
||||
function montarItem(sources){
|
||||
const cargas=[];
|
||||
sources.forEach((source,sourceIndex)=>{
|
||||
for(let copyIndex=0;copyIndex<source.copies;copyIndex++)
|
||||
cargas.push({a:{sourceIndex,giro:0,esp:false},img:source.line.img,copyIndex,
|
||||
w:source.line.widthCm,h:source.line.heightCm,travado:false});
|
||||
});
|
||||
const enc=encaixar(cargas,MONTAR_FILM_CM);
|
||||
const height=+enc.altura.toFixed(4);
|
||||
const grades=sources.map(source=>montarGrade(source.line.dpi));
|
||||
const warning=sources.some(source=>source.line.dpi<MONTAR_DPI_WARN);
|
||||
return {mode:'avulsa',metres:+(height/100).toFixed(4),
|
||||
grade:Math.round(grades.reduce((sum,n)=>sum+n,0)/grades.length),
|
||||
uploads:sources.map(source=>source.uploadId),
|
||||
production:{version:3,film_width_cm:MONTAR_FILM_CM,height_cm:height,
|
||||
sources:sources.map(source=>({upload_id:source.uploadId,kind:'artwork',
|
||||
width_cm:source.line.widthCm,length_cm:+source.line.heightCm.toFixed(4),
|
||||
copies:source.copies,rotation_degrees:0,mirrored:false,measurement:'file'})),
|
||||
placements:placementsDe(enc.pos)},
|
||||
quality_status:warning?'warning':'ok',quality_acknowledged:warning,residue_accepted:0};
|
||||
}
|
||||
// 20 sources and 4000 copies per item; a stamp above 200 copies becomes
|
||||
// several sources of the same upload, 200 each; items in list order.
|
||||
function montarItems(lines,uploads){
|
||||
const pool=[];
|
||||
for(const line of lines){
|
||||
const uploadId=uploads.get(line.id);
|
||||
for(let left=line.qty;left>0;left-=200)
|
||||
pool.push({line,uploadId,copies:Math.min(200,left)});
|
||||
}
|
||||
const groups=[];let current=null;
|
||||
for(const source of pool){
|
||||
if(!current||current.sources.length>=20||current.copies+source.copies>4000){
|
||||
current={sources:[],copies:0};groups.push(current);
|
||||
}
|
||||
current.sources.push(source);current.copies+=source.copies;
|
||||
}
|
||||
return groups.map(group=>montarItem(group.sources));
|
||||
}
|
||||
async function montarCreate(){
|
||||
if(MONTAR.creating)return;
|
||||
const customer=montarCustomer();
|
||||
if(!montarCustomerFilled())return say('Preencha os dados do cliente.',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;
|
||||
MONTAR.creating=true;montarPaintActions();
|
||||
try{
|
||||
const uploads=new Map();
|
||||
for(let index=0;index<lines.length;index++){
|
||||
const line=lines[index];
|
||||
say('Enviando estampas '+(index+1)+' de '+lines.length+'…');
|
||||
const id=await dtfUpload(line.file,{api,startPath:'/montador/uploads',
|
||||
scope:'montador:'+line.code+'-'+line.letter,progress:say});
|
||||
uploads.set(line.id,id);
|
||||
}
|
||||
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)});
|
||||
MONTAR.requestKey=null;
|
||||
montarClear();
|
||||
montarClearCustomer();
|
||||
say('Pedido #'+order.number+' criado em Arte recebida.',false,10000);
|
||||
load(true).catch(()=>{});
|
||||
}catch(e){say(e.message,true);}
|
||||
finally{MONTAR.creating=false;montarPaintActions();}
|
||||
}
|
||||
|
||||
function montarLine(line){
|
||||
const row=node('div',undefined,'montar-line');
|
||||
const img=node('img',undefined,'montar-thumb');img.src=line.url;img.alt='';
|
||||
@@ -330,7 +426,8 @@ $('montar-add').onclick=async()=>{
|
||||
try{await montarAdd();}catch(e){say(e.message,true);}finally{$('montar-add').disabled=false;}
|
||||
};
|
||||
$('montar-clear').onclick=()=>montarClear();
|
||||
$('montar-build').title='Em breve';
|
||||
$('montar-build').onclick=()=>montarCreate();
|
||||
for(const id of MONTAR_CUSTOMER)$(id).addEventListener('input',()=>{MONTAR.requestKey=null;montarPaintActions();});
|
||||
$('montar-size-add').onclick=()=>{MONTAR.dirty=true;$('montar-sizes').append(montarSizeRow(null));};
|
||||
$('montar-size-save').onclick=async()=>{
|
||||
$('montar-size-save').disabled=true;
|
||||
|
||||
@@ -1261,6 +1261,10 @@ dialog.viewer::backdrop{background:var(--scrim)}
|
||||
#tab-montar .montar-dpi{display:flex;justify-content:flex-end}
|
||||
#tab-montar .montar-height{font-size:13px;color:var(--tx2);text-align:right;white-space:nowrap}
|
||||
#tab-montar #montar-lines .emptystate{padding:28px 18px}
|
||||
#tab-montar .montar-customer{border-top:1px solid var(--ln);padding:14px 18px}
|
||||
#tab-montar .montar-customer h3{margin:0 0 10px;font-size:13px;font-weight:650;color:var(--tx2)}
|
||||
#tab-montar .montar-customer-fields{display:grid;grid-template-columns:repeat(4,minmax(0,1fr));gap:12px}
|
||||
@media (max-width:1100px){#tab-montar .montar-customer-fields{grid-template-columns:repeat(2,minmax(0,1fr))}}
|
||||
#tab-montar .montar-actions{display:flex;justify-content:flex-end;gap:10px;padding:12px 18px;border-top:1px solid var(--ln)}
|
||||
#tab-montar .montar-warn{margin:0;padding:10px 18px;border-bottom:1px solid var(--ln);font-size:13px;font-weight:600;color:var(--warn)}
|
||||
#tab-montar .montar-layout{height:340px;overflow:auto;scrollbar-gutter:stable;border-top:1px solid var(--ln);background:var(--sf2);padding:12px}
|
||||
@@ -1283,6 +1287,8 @@ dialog.viewer::backdrop{background:var(--scrim)}
|
||||
#tab-montar .montar-line>.btn{grid-area:remove}
|
||||
#tab-montar .montar-actions{flex-wrap:wrap;padding:12px 14px}
|
||||
#tab-montar .montar-actions .btn{flex:1}
|
||||
#tab-montar .montar-customer{padding:12px 14px}
|
||||
#tab-montar .montar-customer-fields{grid-template-columns:minmax(0,1fr)}
|
||||
#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}
|
||||
|
||||
@@ -132,9 +132,18 @@
|
||||
<div class="phead"><h2>Folha</h2><span class="n" id="montar-count"></span><b class="montar-total" id="montar-total"></b></div>
|
||||
<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>
|
||||
<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>
|
||||
</div>
|
||||
<div class="montar-actions">
|
||||
<button class="btn ghost" id="montar-clear" type="button">Limpar lista</button>
|
||||
<button class="btn pri" id="montar-build" type="button" disabled title="Em breve">Montar</button>
|
||||
<button class="btn pri" id="montar-build" type="button" disabled>Montar</button>
|
||||
</div>
|
||||
</section>
|
||||
<section class="panel clip" id="montar-sizes-panel" hidden>
|
||||
|
||||
@@ -3511,7 +3511,7 @@ function callout(d,title,text,tone=''){
|
||||
// An order paid outside the site (Dropstar's rule D-35): the team builds the
|
||||
// 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'};
|
||||
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');
|
||||
const group=(name,label,options)=>{
|
||||
|
||||
Reference in New Issue
Block a user