feat: a pasted list in Montar, with the reference printed under each stamp and the skipped lines in the report (Rodada 5, C4)
One line per item, code size quantity reference. Lines with errors are listed with the line and the reason and mounted only after "Montar sem essas N linhas". A reference is drawn 3 mm high right under the stamp, with 1 cm to the next piece on that side; the list is always Interno and the Prumo report names the skipped lines. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -14,7 +14,7 @@ const MONTAR_GEAR='M128 80a48 48 0 1 0 48 48a48.05 48.05 0 0 0-48-48m0 80a32 32
|
||||
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,
|
||||
kind:null,internal:null,internalDirty:false,brands:new Map(),contactToken:0,contactTimer:null,
|
||||
freights:null,freight:null,catalog:null};
|
||||
freights:null,freight:null,catalog:null,batch:null};
|
||||
|
||||
const montarFolderReady=()=>!!FOLDER.handle&&!!FOLDER.granted;
|
||||
const montarDpi=found=>found.width/(found.widthCm/2.54);
|
||||
@@ -433,7 +433,7 @@ async function montarLayout(token){
|
||||
say('A estampa não pôde ser lida.',true);return;
|
||||
}
|
||||
const cargas=lines.flatMap((line,sourceIndex)=>Array.from({length:line.qty},(_,copyIndex)=>({
|
||||
a:{sourceIndex,giro:0,esp:false},img:line.img,copyIndex,w:line.widthCm,h:line.heightCm,travado:false})));
|
||||
a:{sourceIndex,giro:0,esp:false},img:line.ref?null:line.img,copyIndex,w:line.widthCm,h:line.heightCm,travado:false})));
|
||||
let enc;
|
||||
try{enc=encaixar(cargas,MONTAR_FILM_CM);}
|
||||
catch(e){
|
||||
@@ -523,7 +523,7 @@ 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,
|
||||
cargas.push({a:{sourceIndex,giro:0,esp:false},img:source.line.ref?null:source.line.img,copyIndex,
|
||||
w:source.line.widthCm,h:source.line.heightCm,travado:false});
|
||||
});
|
||||
const enc=encaixar(cargas,MONTAR_FILM_CM);
|
||||
@@ -563,6 +563,7 @@ function montarItems(lines,uploads){
|
||||
async function montarCreate(){
|
||||
if(MONTAR.creating)return;
|
||||
const kind=MONTAR.kind||'venda';
|
||||
if(MONTAR.batch&&kind!=='interno')return say('A lista colada vira sempre pedido Interno.');
|
||||
let customer=null,name='';
|
||||
if(kind==='interno'){
|
||||
if(!montarInternalReady())return say('Peça à Gestão para completar o cliente interno.');
|
||||
@@ -596,12 +597,13 @@ async function montarCreate(){
|
||||
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});
|
||||
scope:'montador:'+line.code+'-'+line.letter+(line.ref?'-'+line.ref:''),progress:say});
|
||||
uploads.set(line.id,id);
|
||||
}
|
||||
say('Criando o pedido…');
|
||||
if(!MONTAR.requestKey)MONTAR.requestKey=crypto.randomUUID();
|
||||
const body={request_key:MONTAR.requestKey,kind,items:montarItems(lines,uploads)};
|
||||
if(MONTAR.batch)body.batch=MONTAR.batch;
|
||||
if(kind==='venda'){
|
||||
body.customer=customer;
|
||||
if(withOrder)body.with_order=withOrder;
|
||||
@@ -630,6 +632,7 @@ function montarLine(line){
|
||||
const img=node('img',undefined,'montar-thumb');img.src=line.url;img.alt='';
|
||||
const words=node('div',undefined,'montar-linemeta');
|
||||
words.append(node('b',line.code),node('span','tamanho '+line.letter+' · '+cm(line.widthCm)+' cm','sub'));
|
||||
if(line.ref)words.append(node('span','ref '+line.ref,'sub'));
|
||||
if(line.dpi<MONTAR_DPI_WARN)words.append(badge(Math.floor(line.dpi)+' DPI','warn','Abaixo de '+MONTAR_DPI_WARN+' DPI.'));
|
||||
const step=node('div',undefined,'montar-step');
|
||||
const minus=node('button','−','montar-stepbtn');minus.type='button';minus.setAttribute('aria-label','Menos uma');
|
||||
@@ -667,6 +670,7 @@ function montarRemoveLine(line){
|
||||
function montarClear(){
|
||||
for(const line of MONTAR.lines)URL.revokeObjectURL(line.url);
|
||||
MONTAR.lines=[];
|
||||
MONTAR.batch=null;
|
||||
montarChanged();
|
||||
}
|
||||
|
||||
@@ -695,6 +699,156 @@ async function montarAdd(){
|
||||
montarChanged();
|
||||
}
|
||||
|
||||
function montarListSize(letter){
|
||||
const wanted=String(letter||'').toUpperCase();
|
||||
return MONTAR.sizes.find(size=>size.letter===wanted)||null;
|
||||
}
|
||||
function montarParseList(text){
|
||||
const rows=[];
|
||||
const lines=String(text||'').split(/\r?\n/);
|
||||
for(let index=0;index<lines.length;index++){
|
||||
const line=lines[index].trim();
|
||||
if(!line||line.startsWith('#'))continue;
|
||||
const parts=line.split(/\s+/);
|
||||
const row={line:index+1,text:line,code:'',letter:'',qty:0,ref:'',error:''};
|
||||
if(parts.length>4){row.error='mais de 4 campos';rows.push(row);continue;}
|
||||
if(parts.length<3){row.error='faltam campos';rows.push(row);continue;}
|
||||
row.code=parts[0];row.letter=parts[1];row.ref=parts[3]||'';
|
||||
if(!MONTAR_CODE.test(row.code)){row.error='código inválido';rows.push(row);continue;}
|
||||
const size=montarListSize(row.letter);
|
||||
if(!size){row.error='tamanho não existe na tabela';rows.push(row);continue;}
|
||||
row.letter=size.letter;
|
||||
const quantity=Number(parts[2]);
|
||||
if(!Number.isInteger(quantity)||quantity<1||quantity>9999){
|
||||
row.error='quantidade de 1 a 9999';rows.push(row);continue;
|
||||
}
|
||||
row.qty=quantity;
|
||||
if(row.ref.length>30){row.error='referência com mais de 30 caracteres';rows.push(row);continue;}
|
||||
rows.push(row);
|
||||
}
|
||||
return rows;
|
||||
}
|
||||
async function montarListCheck(rows){
|
||||
const cache=new Map();
|
||||
for(const row of rows){
|
||||
if(row.error)continue;
|
||||
const size=montarListSize(row.letter);
|
||||
if(!size){row.error='tamanho não existe na tabela';continue;}
|
||||
const key=row.code+'\u0000'+size.letter;
|
||||
let found;
|
||||
if(cache.has(key))found=cache.get(key);
|
||||
else{
|
||||
try{found=await montarRead(row.code,size);}
|
||||
catch(e){if(!montarFolderError(e))say(e.message,true);return null;}
|
||||
cache.set(key,found);
|
||||
}
|
||||
if(!found){row.error='código não existe em Estampas/';continue;}
|
||||
if(found.widthCm>56){row.error='estampa com mais de 56 cm';continue;}
|
||||
if(montarDpi(found)<MONTAR_DPI_REFUSE){row.error='estampa abaixo de '+MONTAR_DPI_REFUSE+' DPI';continue;}
|
||||
row.found=found;row.size=size;
|
||||
}
|
||||
return rows;
|
||||
}
|
||||
function montarListFile(row){
|
||||
return row.code+'.'+row.letter+'-'+row.ref.replace(/[^A-Za-z0-9._-]/g,'_')+'.png';
|
||||
}
|
||||
function montarComposeRef(found,row){
|
||||
return new Promise((ok,fail)=>{
|
||||
const source=montarStampImage(found.url);
|
||||
source.loading.then(image=>{
|
||||
if(!image)return fail(new Error('A estampa não pôde ser lida.'));
|
||||
const pxCm=found.width/found.widthCm;
|
||||
const gap=Math.round(0.1*pxCm),cap=Math.round(0.3*pxCm),bottom=Math.round(0.5*pxCm);
|
||||
const font=0.3*pxCm/0.72;
|
||||
const canvas=document.createElement('canvas'),ctx=canvas.getContext('2d');
|
||||
ctx.font='bold '+font+'px Arial, sans-serif';
|
||||
const textWidth=Math.ceil(ctx.measureText(row.ref).width);
|
||||
canvas.width=Math.max(1,Math.max(found.width,textWidth));
|
||||
canvas.height=Math.max(1,found.height+gap+cap+bottom);
|
||||
ctx.font='bold '+font+'px Arial, sans-serif';
|
||||
ctx.textBaseline='alphabetic';ctx.fillStyle='#000';
|
||||
ctx.drawImage(image,0,0,found.width,found.height);
|
||||
ctx.fillText(row.ref,0,found.height+gap+cap);
|
||||
canvas.toBlob(blob=>{
|
||||
if(!blob)return fail(new Error('A referência não pôde ser gerada.'));
|
||||
const file=new File([blob],montarListFile(row),{type:'image/png'});
|
||||
const url=URL.createObjectURL(file),picture=montarStampImage(url);
|
||||
ok({file,url,img:picture.img,loading:picture.loading,
|
||||
widthCm:canvas.width/pxCm,heightCm:canvas.height/pxCm});
|
||||
},'image/png');
|
||||
},fail);
|
||||
});
|
||||
}
|
||||
async function montarListBuild(valid,skipped){
|
||||
montarSetKind('interno');
|
||||
const used=new Set();
|
||||
try{
|
||||
for(const row of valid){
|
||||
const found=row.found;
|
||||
used.add(found);
|
||||
const existing=MONTAR.lines.find(line=>line.code===row.code&&line.letter===row.letter&&
|
||||
(line.ref||'')===row.ref);
|
||||
if(existing){existing.qty=Math.min(9999,existing.qty+row.qty);continue;}
|
||||
if(row.ref){
|
||||
const composed=await montarComposeRef(found,row);
|
||||
MONTAR.lines.push({id:++MONTAR.seq,code:row.code,letter:row.letter,widthCm:composed.widthCm,
|
||||
qty:row.qty,heightCm:composed.heightCm,dpi:montarDpi(found),url:composed.url,
|
||||
img:composed.img,loading:composed.loading,file:composed.file,ref:row.ref});
|
||||
}else{
|
||||
const url=URL.createObjectURL(found.file),picture=montarStampImage(url);
|
||||
MONTAR.lines.push({id:++MONTAR.seq,code:row.code,letter:row.letter,widthCm:found.widthCm,
|
||||
qty:row.qty,heightCm:montarHeight(found),dpi:montarDpi(found),url,
|
||||
img:picture.img,loading:picture.loading,file:found.file,ref:''});
|
||||
}
|
||||
}
|
||||
}finally{
|
||||
for(const found of used)URL.revokeObjectURL(found.url);
|
||||
}
|
||||
MONTAR.batch={lines:valid.length,skipped};
|
||||
montarChanged();
|
||||
}
|
||||
function montarListErrors(valid,skipped){
|
||||
const box=node('div',undefined,'montar-list-errors');
|
||||
box.append(...skipped.map(row=>node('p','Linha '+row.line+': '+row.text+' · '+row.reason)));
|
||||
const all=!valid.length;
|
||||
const label=all?'Fechar':(skipped.length===1?'Montar sem essa linha':'Montar sem essas '+skipped.length+' linhas');
|
||||
const dialog=formDialog('Linhas com erro',{
|
||||
text:all?'Nenhuma linha será montada.':'As linhas abaixo serão puladas.',
|
||||
fields:[box],label,
|
||||
onsave:async()=>{
|
||||
if(all)return;
|
||||
await montarListBuild(valid,skipped);
|
||||
}
|
||||
});
|
||||
if(all){
|
||||
const cancel=dialog.box.querySelector('.dfoot .btn.ghost.right');
|
||||
if(cancel)cancel.remove();
|
||||
}
|
||||
}
|
||||
function montarOpenPaste(){
|
||||
if(!montarKindNames().includes('interno'))
|
||||
return say('Seu perfil não monta lista colada: ela vira pedido Interno.',true);
|
||||
if(!montarFolderReady())return;
|
||||
const text=node('textarea',undefined,'montar-list-text');
|
||||
text.id='montar-list-text';text.rows=12;text.spellcheck=false;text.placeholder='NX.226 C 2 ML-4471';
|
||||
formDialog('Colar lista',{
|
||||
text:'Uma linha por item: código tamanho quantidade referência. Ex.: NX.226 C 2 ML-4471',
|
||||
fields:[field('Lista',text)],label:'Conferir lista',width:640,
|
||||
onsave:async()=>{
|
||||
const rows=montarParseList(text.value);
|
||||
if(rows.length>500){say('A lista tem mais de 500 linhas.',true);return false;}
|
||||
if(!rows.length){say('A lista está vazia.',true);return false;}
|
||||
const checked=await montarListCheck(rows);
|
||||
if(!checked)return false;
|
||||
const valid=checked.filter(row=>!row.error);
|
||||
const skipped=checked.filter(row=>row.error)
|
||||
.map(row=>({line:row.line,text:row.text,reason:row.error}));
|
||||
if(skipped.length){montarListErrors(valid,skipped);return;}
|
||||
await montarListBuild(valid,skipped);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function montarPaintSelect(){
|
||||
const select=$('montar-size'),current=select.value;
|
||||
select.replaceChildren(...MONTAR.sizes.map(size=>{
|
||||
@@ -855,6 +1009,7 @@ $('montar-add').onclick=async()=>{
|
||||
$('montar-add').disabled=true;
|
||||
try{await montarAdd();}catch(e){say(e.message,true);}finally{$('montar-add').disabled=false;}
|
||||
};
|
||||
$('montar-paste').onclick=()=>montarOpenPaste();
|
||||
$('montar-clear').onclick=()=>montarClear();
|
||||
$('montar-build').onclick=()=>montarCreate();
|
||||
for(const id of MONTAR_CUSTOMER)$(id).addEventListener('input',()=>{MONTAR.requestKey=null;montarPaintCustomer();montarPaintActions();});
|
||||
|
||||
@@ -1666,3 +1666,12 @@ dialog.viewer::backdrop{background:var(--scrim)}
|
||||
.montar-size-row{height:44px}
|
||||
.montar-ajustes-dlg{max-height:92vh}
|
||||
}
|
||||
|
||||
.montar-list-actions{display:flex;align-items:center;gap:8px}
|
||||
.montar-list-actions>.btn{height:42px;white-space:nowrap}
|
||||
.montar-list-text{min-height:210px;font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:13px;line-height:1.5}
|
||||
.montar-list-errors{display:flex;flex-direction:column;gap:6px;max-height:320px;overflow:auto;padding:10px 12px;border-radius:10px;background:var(--sf2)}
|
||||
.montar-list-errors p{margin:0;font-size:13px;color:var(--tx2);word-break:break-word}
|
||||
@media (max-width:700px){
|
||||
.montar-list-actions{grid-column:1/-1;justify-content:flex-start}
|
||||
}
|
||||
|
||||
@@ -131,7 +131,10 @@
|
||||
<label class="fld"><span>Código</span><input id="montar-code" maxlength="40" autocomplete="off" spellcheck="false" placeholder="1001"></label>
|
||||
<label class="fld"><span>Tamanho</span><select id="montar-size"></select></label>
|
||||
<label class="fld"><span>Quantidade</span><input id="montar-qty" type="number" min="1" max="9999" step="1" value="1"></label>
|
||||
<button class="btn pri" id="montar-add" type="button">Adicionar</button>
|
||||
<div class="montar-list-actions">
|
||||
<button class="btn pri" id="montar-add" type="button">Adicionar</button>
|
||||
<button class="btn" id="montar-paste" type="button">Colar lista</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="montar-preview" id="montar-preview"></div>
|
||||
</section>
|
||||
|
||||
Reference in New Issue
Block a user