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
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:
@@ -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();}
|
||||
|
||||
Reference in New Issue
Block a user