feat: Números per machine, month by month (front 1b)
All checks were successful
Build and deploy / Validate source (push) Successful in 6s
Build and deploy / Integration suite on a real stack (push) Successful in 5m58s
Build and deploy / Secret scan and release gate (push) Successful in 6s
Build and deploy / Publish images (push) Successful in 1m4s

A new Números section, "Máquinas, mês a mês", one column per machine
and a month at a time: metres printed, metres per hour and hours
running (time shared by two orders counted once), hours stopped with
their reasons; metres per film roll, ink per 100 m by colour, powder
per 100 m; supplies, parts and total cost per metre; what the printed
orders sold, the month's contribution and since installation; and the
return in % and months to pay back once Gestão types the price.

Refills stand for consumption. Every ratio without data shows "—".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Cauê Faleiros
2026-11-09 12:50:48 -03:00
parent 29518795a5
commit 4219db8215
8 changed files with 575 additions and 4 deletions

View File

@@ -881,6 +881,16 @@ select.inp{appearance:none;-webkit-appearance:none;padding-right:32px;background
.fillbox>.mtiles,.fillbox>.scrollin{position:absolute;inset:0;overflow:auto;margin:0}
.fillbox>.mtiles{border-top:1px solid var(--ln);align-content:start}
.panel:has(> .fillbox){display:flex;flex-direction:column}
/* Máquinas, mês a mês: a fixed panel whose table scrolls both ways, the month
between its arrows and the first column pinned while it scrolls sideways. */
.mnav{display:flex;align-items:center;gap:6px;margin-left:auto}
.mnav b{font-size:13px;font-weight:600;min-width:132px;text-align:center}
.machinebox{height:420px;min-height:0;flex:none}
.machine-month{width:max-content;min-width:100%}
.machine-month tr.group td{font-weight:650;background:var(--sf2)}
.machine-month thead th:first-child,.machine-month tbody tr:not(.group) td:first-child{position:sticky;left:0;z-index:2;background:var(--sf)}
.machine-month thead th:first-child{z-index:3}
#stats-machine-panel .phint{margin-top:-1px}
.cols2.lean{align-items:stretch}
/* The board fills the window; each column scrolls on its own, its head stays. */
#tab-board:not([hidden]){display:flex;flex-direction:column;height:calc(100vh - 72px)}

View File

@@ -145,6 +145,9 @@
</div>
<section class="panel clip"><div class="phead"><h2>Pedidos sem pagamento</h2><span class="hint" tabindex="0" data-tip="Cotações aprovadas no período, pela data de aprovação. Pagas viraram pedido; expiradas passaram de 24 horas sem pagamento; aguardando ainda podem ser pagas. A taxa de abandono é expiradas sobre pagas mais expiradas."><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">Indicador</th><th scope="col" class="r">Valor</th></tr></thead><tbody id="stats-unpaid"></tbody></table></section>
<section class="panel clip" id="stats-machine-panel"><div class="phead"><h2>Máquinas, mês a mês</h2><div class="mnav" id="stats-machine-nav"></div></div>
<div class="fillbox machinebox"><div class="scrollin"><table class="table machine-month"><thead id="stats-machine-head"></thead><tbody id="stats-machine-body"></tbody></table></div></div>
<p class="phint" id="stats-machine-note"></p></section>
<section class="panel clip"><div class="phead"><h2>Velocidade do site e do Prumo</h2><span class="hint tip-l" tabindex="0" data-tip="Média e p95 do que o cliente sente, por pedido pago no período: abrir a página, subir o arquivo (segundos por MB), a conferência do Prumo, a montagem das avulsas, a geração do arquivo final por 10 m e o tempo do evento de pagamento até o card. Referências: página < 3 s; conferência < 30 s; geração < 2 min por 10 m; card em até 1 min."><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">Etapa</th><th scope="col" class="r">Média</th><th scope="col" class="r">p95</th><th scope="col" class="r">Amostras</th></tr></thead><tbody id="stats-speed"></tbody></table></section>
</section>

View File

@@ -3012,6 +3012,8 @@ $('new-machine').onclick=()=>machineForm(null);
// The period: the last 7, 30 or 90 days, or two dates picked on the calendar.
let statsDays=30, statsRange=null, statsData=null;
// The machine block has a month of its own, apart from the period above.
let machineMonth=null, machineStats=null, machineStatsMonth=null;
function duration(hours){
if(hours===null||hours===undefined)return '—';
if(hours<1)return Math.max(1,Math.round(hours*60))+' min';
@@ -3086,7 +3088,94 @@ function calendar(){
document.addEventListener('click',()=>pop.remove(),{once:true});
return pop;
}
// ---- Máquinas, mês a mês -------------------------------------------------
// This block has its own month: it does not follow the period at the top, so
// it is fetched apart and kept until the month changes.
const MACHINE_MONTHS=['Janeiro','Fevereiro','Março','Abril','Maio','Junho','Julho',
'Agosto','Setembro','Outubro','Novembro','Dezembro'];
function machineMonthShift(key,delta){
const [year,month]=key.split('-').map(Number),d=new Date(Date.UTC(year,month-1+delta,1));
return d.getUTCFullYear()+'-'+String(d.getUTCMonth()+1).padStart(2,'0');
}
function machineMonthName(key){
const [year,month]=key.split('-').map(Number);
return MACHINE_MONTHS[month-1].toLowerCase()+' de '+year;
}
function machineMonthNav(){
const data=machineStats;if(!data)return;
const current=todayIso().slice(0,7);
const prev=iconButton(IC.left,'Mês anterior',()=>changeMachineMonth(-1));
const next=iconButton(IC.right,'Próximo mês',()=>changeMachineMonth(1));
next.disabled=data.month>=current;
$('stats-machine-nav').replaceChildren(prev,node('b',machineMonthName(data.month)),next);
}
function changeMachineMonth(delta){
const current=todayIso().slice(0,7);
machineMonth=machineMonthShift(machineMonth||current,delta);
if(machineMonth>current)machineMonth=current;
loadMachineStats().catch(e=>say(e.message,true));
}
async function loadMachineStats(){
const month=machineMonth||todayIso().slice(0,7);
if(machineStats&&machineStatsMonth===month){renderMachineStats();return;}
const data=await api('/stats/machines?month='+month);
machineStats=data;machineStatsMonth=month;renderMachineStats();
}
function renderMachineStats(){
const data=machineStats;if(!data)return;
machineMonthNav();
const machines=data.machines,one=v=>v==null?'—':Number(v).toLocaleString('pt-BR',
{minimumFractionDigits:1,maximumFractionDigits:1}),unit=(v,u)=>v==null?'—':one(v)+u,
cash=v=>v==null?'—':money(v);
const head=node('tr');head.append(node('th','Indicador'));
for(const m of machines){const th=node('th',m.name,'r');th.scope='col';head.append(th);}
$('stats-machine-head').replaceChildren(head);
const stopsTitle=m=>(m.month.stops||[]).map(s=>(s.reason||'Parada')+' '+one(s.hours)+' h').join('; ');
const groups=[
['Produção',[
['Metros impressos',m=>m.month.printed_metres==null?'—':metres(m.month.printed_metres)],
['Metros por hora',m=>unit(m.month.metres_per_hour,' m/h')],
['Horas rodando',m=>unit(m.month.hours_running,' h')],
['Horas paradas',m=>unit(m.month.stopped_hours,' h'),stopsTitle]]],
['Consumo',[
['Metros por rolo de filme',m=>unit(m.month.metres_per_roll,' m')],
...['ink_c','ink_m','ink_y','ink_k','ink_w'].map(item=>
['Tinta '+{ink_c:'ciano',ink_m:'magenta',ink_y:'amarela',ink_k:'preta',ink_w:'branca'}[item]+' por 100 m',
m=>unit(m.month.ink_per_100m[item],' L')]),
['Poliamida por 100 m',m=>unit(m.month.powder_g_per_100m,' g')]]],
['Custo',[
['Insumos por metro',m=>cash(m.month.supplies_per_metre_cents)],
['Peças por metro',m=>cash(m.month.parts_per_metre_cents)],
['Total por metro',m=>cash(m.month.total_per_metre_cents)]]],
['Resultado',[
['Vendido',m=>cash(m.month.sold_cents)],
['Contribuição do mês',m=>cash(m.month.contribution_cents)],
['Contribuição desde a instalação',m=>cash(m.total.contribution_cents)]]],
['Retorno',[
['Retorno (%)',m=>m.total.roi_pct==null?'—':one(m.total.roi_pct)+'%'],
['Meses para se pagar',m=>one(m.total.payback_months)]]]];
const body=$('stats-machine-body');
if(!machines.length){body.replaceChildren(emptyRow('Nenhuma máquina com números neste mês.',1));}
else{
const rows=[];
for(const [label,items] of groups){
const group=node('tr',undefined,'group'),cell=node('td',label);cell.colSpan=machines.length+1;
group.append(cell);rows.push(group);
for(const [name,value,title] of items){
const tr=node('tr');tr.append(node('td',name));
for(const m of machines){const td=node('td',value(m),'r'),tip=title&&title(m);if(tip)td.title=tip;tr.append(td);}
rows.push(tr);
}
}
body.replaceChildren(...rows);
}
const missing=machines.some(m=>m.price_cents==null);
$('stats-machine-note').textContent='Os custos vêm dos lançamentos na ficha de cada máquina; '
+'preço e data de instalação vêm de Dados da máquina.'
+(missing?' Sem o preço de compra, o retorno fica em branco.':'');
}
async function loadStats(){
loadMachineStats().catch(e=>say(e.message,true));
const data=await api('/stats?'+(statsRange?'start='+statsRange.start+'&end='+statsRange.end:'days='+statsDays));
const editLimits=$('edit-stage-limits');
if(editLimits){editLimits.hidden=!may('manage');editLimits.onclick=()=>stageLimitsDialog();}