22 lines
12 KiB
JavaScript
22 lines
12 KiB
JavaScript
const D=window.RD_DATA||{}; const money=n=>'₹'+new Intl.NumberFormat('en-IN').format(Math.round(n||0)); const num=n=>new Intl.NumberFormat('en-IN').format(Math.round(n||0)); const mt=n=>num(n)+' MT';
|
|
const nav=[['dashboard','▦','Dashboard'],['market','◫','Market Desk'],['inventory','▤','Inventory'],['procurement','⇄','Procurement'],['sales','↗','Sales'],['customers','◎','Customers'],['suppliers','◌','Suppliers'],['logistics','▱','Logistics'],['finance','₹','Finance'],['quality','✓','Quality'],['reports','▥','Reports']];
|
|
let view='dashboard';
|
|
const el=id=>document.getElementById(id); const rows=(arr,cols)=>`<table class="table"><thead><tr>${cols.map(c=>`<th>${c[0]}</th>`).join('')}</tr></thead><tbody>${arr.map(x=>`<tr>${cols.map(c=>`<td>${c[1](x)}</td>`).join('')}</tr>`).join('')}</tbody></table>`;
|
|
const pill=(s,kind='')=>`<span class="pill ${kind}">${s}</span>`;
|
|
function totals(a,k){return a.reduce((s,x)=>s+(+x[k]||0),0)}
|
|
function dashboard(){let inv=D.inventory||[], purch=D.purchases||[], sales=D.sales||[], rec=D.receipts||[], disp=D.dispatches||[];let stock=totals(inv,'closingStockMT'), pv=totals(purch,'valueINR'), sv=totals(sales,'valueINR'); let due=(D.customers||[]).reduce((s,x)=>s+x.outstandingINR,0); return `<div class="wrap"><div class="hero"><div><span class="kicker">Neemuch · Wholesale dry-agri trade</span><h2>RamDayal Deen Dayal & Co.</h2><p>Operational control centre for procurement, inventory, market intelligence, sales, dispatch and accounts.</p></div><div class="hero-badge">${D.meta.status}</div></div><div class="cards"><div class="card metric"><label>Stock on hand</label><strong>${mt(stock)}</strong><small>${inv.length} active stock lines</small></div><div class="card metric"><label>Purchase value</label><strong>${money(pv)}</strong><small>${purch.length} purchase entries</small></div><div class="card metric"><label>Sales value</label><strong>${money(sv)}</strong><small>${sales.length} sales entries</small></div><div class="card metric"><label>Receivables</label><strong>${money(due)}</strong><small>${D.customers.length} customer accounts</small></div></div><div class="grid2 section"><div class="panel"><div class="section-head"><div><h2>Operational alerts</h2><p>Items requiring attention</p></div></div>${D.alerts.map(a=>`<div class="alert ${a.severity}"><b>${a.title}</b><span>${a.detail}</span></div>`).join('')}</div><div class="panel"><div class="section-head"><div><h2>Warehouse position</h2><p>Current capacity utilisation</p></div></div>${rows(D.warehouses,[['Warehouse',x=>x.name],['Capacity',x=>mt(x.capacityMT)],['Used',x=>x.utilisationPct+'%'],['Status',x=>pill(x.utilisationPct>85?'Watch':'Normal',x.utilisationPct>85?'amber':'')]])}</div></div><div class="grid2 section"><div class="panel"><div class="section-head"><div><h2>Top stock lines</h2><p>Highest closing quantities</p></div></div>${rows([...inv].sort((a,b)=>b.closingStockMT-a.closingStockMT).slice(0,10),[['Commodity',x=>x.commodity],['Warehouse',x=>x.warehouse],['Grade',x=>x.grade],['Stock',x=>mt(x.closingStockMT)]])}</div><div class="panel"><div class="section-head"><div><h2>Recent sales</h2><p>Latest customer orders</p></div></div>${rows([...sales].sort((a,b)=>b.date.localeCompare(a.date)||b.id.localeCompare(a.id)).slice(0,10),[['Date',x=>x.date],['Customer',x=>x.customer],['Commodity',x=>x.commodity],['Qty',x=>mt(x.qtyMT)],['Value',x=>money(x.valueINR)]])}</div></div></div>`}
|
|
function market(){let a=[...D.market].sort((x,y)=>y.observationDate.localeCompare(x.observationDate));return `<div class="wrap"><div class="section-head"><div><h2>Market Desk</h2><p>${a.length} synthetic market observations</p></div><div class="toolbar"><select class="select" onchange="filterMarket(this.value)"><option>All commodities</option>${D.commodities.map(c=>`<option>${c}</option>`).join('')}</select></div></div><div id="marketTable" class="panel">${marketRows(a.slice(0,80))}</div></div>`}
|
|
function marketRows(a){return rows(a,[['Date',x=>x.observationDate],['Market',x=>x.market],['Commodity',x=>x.commodity],['Grade',x=>x.grade],['Arrivals',x=>mt(x.arrivalQuantityMT)],['Modal',x=>money(x.modalPriceINRPerQtl)],['Desk',x=>pill('Synthetic','')]])}
|
|
function filterMarket(v){let a=[...D.market].sort((x,y)=>y.observationDate.localeCompare(x.observationDate));if(v!=='All commodities')a=a.filter(x=>x.commodity===v);el('marketTable').innerHTML=marketRows(a.slice(0,100));}
|
|
function inventory(){return `<div class="wrap"><div class="section-head"><div><h2>Inventory</h2><p>${D.inventory.length} stock lines across ${D.warehouses.length} warehouses</p></div></div><div class="cards"><div class="card metric"><label>Stock</label><strong>${mt(totals(D.inventory,'closingStockMT'))}</strong><small>current book position</small></div><div class="card metric"><label>Lots</label><strong>${D.lots.length}</strong><small>lot records</small></div><div class="card metric"><label>QC holds</label><strong>${D.lots.filter(x=>x.status==='QC Hold').length}</strong><small>requiring release</small></div><div class="card metric"><label>Warehouses</label><strong>${D.warehouses.length}</strong><small>operating locations</small></div></div><div class="panel section">${rows([...D.inventory].sort((a,b)=>b.closingStockMT-a.closingStockMT),[['SKU',x=>x.sku],['Commodity',x=>x.commodity],['Variety',x=>x.variety],['Grade',x=>x.grade],['Warehouse',x=>x.warehouse],['Closing',x=>mt(x.closingStockMT)],['Bags',x=>num(x.bags)],['Updated',x=>x.updated]])}</div></div>`}
|
|
function procurement(){return `<div class="wrap"><div class="section-head"><div><h2>Procurement</h2><p>${D.purchases.length} fictitious purchase entries</p></div></div><div class="cards"><div class="card metric"><label>Quantity purchased</label><strong>${mt(totals(D.purchases,'qtyMT'))}</strong></div><div class="card metric"><label>Purchase value</label><strong>${money(totals(D.purchases,'valueINR'))}</strong></div><div class="card metric"><label>Suppliers</label><strong>${D.suppliers.length}</strong></div><div class="card metric"><label>Receipts</label><strong>${D.receipts.length}</strong></div></div><div class="panel section">${rows([...D.purchases].sort((a,b)=>b.date.localeCompare(a.date)).slice(0,120),[['ID',x=>x.id],['Date',x=>x.date],['Supplier',x=>x.supplier],['Market',x=>x.market],['Commodity',x=>x.commodity],['Qty',x=>mt(x.qtyMT)],['Rate',x=>money(x.rateINRPerQtl)],['Value',x=>money(x.valueINR)],['Status',x=>pill(x.status,x.status==='Under QC'?'amber':'')]])}</div></div>`}
|
|
function salesView(){return `<div class="wrap"><div class="section-head"><div><h2>Sales</h2><p>${D.sales.length} fictitious customer sales entries</p></div></div><div class="cards"><div class="card metric"><label>Quantity sold</label><strong>${mt(totals(D.sales,'qtyMT'))}</strong></div><div class="card metric"><label>Sales value</label><strong>${money(totals(D.sales,'valueINR'))}</strong></div><div class="card metric"><label>Customers</label><strong>${D.customers.length}</strong></div><div class="card metric"><label>Dispatches</label><strong>${D.dispatches.length}</strong></div></div><div class="panel section">${rows([...D.sales].sort((a,b)=>b.date.localeCompare(a.date)).slice(0,120),[['ID',x=>x.id],['Date',x=>x.date],['Customer',x=>x.customer],['Commodity',x=>x.commodity],['Qty',x=>mt(x.qtyMT)],['Rate',x=>money(x.rateINRPerQtl)],['Value',x=>money(x.valueINR)],['Status',x=>pill(x.status)]])}</div></div>`}
|
|
function masters(kind){let a=D[kind];return `<div class="wrap"><div class="section-head"><div><h2>${kind[0].toUpperCase()+kind.slice(1)}</h2><p>${a.length} master records</p></div></div><div class="panel">${kind==='customers'?rows(a,[['Code',x=>x.code],['Customer',x=>x.name],['City',x=>x.city],['Segment',x=>x.segment],['Credit limit',x=>money(x.creditLimitINR)],['Outstanding',x=>money(x.outstandingINR)],['Exposure',x=>pill(x.outstandingINR>x.creditLimitINR*.8?'Watch':'Normal',x.outstandingINR>x.creditLimitINR*.8?'amber':'')]]):rows(a,[['Code',x=>x.code],['Supplier',x=>x.name],['City',x=>x.city],['Segment',x=>x.segment],['Credit days',x=>x.creditDays],['Status',x=>pill('Active')]])}</div></div>`}
|
|
function logistics(){return `<div class="wrap"><div class="section-head"><div><h2>Logistics</h2><p>${D.dispatches.length} dispatch records · ${D.vehicles.length} vehicles</p></div></div><div class="grid2"><div class="panel"><h2>Dispatch board</h2>${rows([...D.dispatches].sort((a,b)=>b.date.localeCompare(a.date)).slice(0,80),[['Date',x=>x.date],['Dispatch',x=>x.id],['Commodity',x=>x.commodity],['Qty',x=>mt(x.qtyMT)],['Vehicle',x=>x.vehicle],['Destination',x=>x.destination],['Status',x=>pill(x.status,x.status==='In Transit'?'amber':'')]])}</div><div class="panel"><h2>Fleet</h2>${rows(D.vehicles,[['Reg. no.',x=>x.regNo],['Vehicle',x=>x.model],['Ownership',x=>x.ownership],['Status',x=>pill(x.status,x.status==='Maintenance'?'amber':'')]])}</div></div></div>`}
|
|
function finance(){return `<div class="wrap"><div class="section-head"><div><h2>Finance</h2><p>Receipts, expenses and customer exposure</p></div></div><div class="cards"><div class="card metric"><label>Receipts posted</label><strong>${money(totals(D.payments,'amountINR'))}</strong></div><div class="card metric"><label>Expenses</label><strong>${money(totals(D.expenses,'amountINR'))}</strong></div><div class="card metric"><label>Receivables</label><strong>${money(D.customers.reduce((s,x)=>s+x.outstandingINR,0))}</strong></div><div class="card metric"><label>Payables snapshot</label><strong>${money(D.snapshots[D.snapshots.length-1].payableINR)}</strong></div></div><div class="grid2 section"><div class="panel"><h2>Receipts</h2>${rows(D.payments.slice(0,80),[['ID',x=>x.id],['Date',x=>x.date],['Party',x=>x.party],['Amount',x=>money(x.amountINR)],['Mode',x=>x.mode],['Status',x=>pill(x.status,x.status==='Pending'?'amber':'')]])}</div><div class="panel"><h2>Expenses</h2>${rows(D.expenses.slice(0,80),[['ID',x=>x.id],['Date',x=>x.date],['Category',x=>x.category],['Amount',x=>money(x.amountINR)],['Status',x=>pill(x.status)]])}</div></div></div>`}
|
|
function quality(){return `<div class="wrap"><div class="section-head"><div><h2>Quality & Lots</h2><p>Lot control and release status</p></div></div><div class="panel">${rows(D.lots.slice(0,140),[['Lot',x=>x.lotId],['Commodity',x=>x.commodity],['Warehouse',x=>x.warehouse],['Qty',x=>mt(x.qtyMT)],['Grade',x=>x.grade],['Status',x=>pill(x.status,x.status==='QC Hold'?'amber':'')]])}</div></div>`}
|
|
function reports(){let pv=totals(D.purchases,'valueINR'),sv=totals(D.sales,'valueINR');return `<div class="wrap"><div class="section-head"><div><h2>Reports</h2><p>Management summaries from the demonstration dataset</p></div></div><div class="grid2"><div class="panel"><h2>20-day trading trend</h2>${rows(D.snapshots,[['Date',x=>x.date],['Purchases',x=>mt(x.purchasesMT)],['Sales',x=>mt(x.salesMT)],['Stock',x=>mt(x.closingStockMT)],['Receivables',x=>money(x.receivableINR)],['Payables',x=>money(x.payableINR)]])}</div><div class="panel"><h2>Business scale</h2><div class="mini-grid"><div class="mini"><b>${D.purchases.length}</b><span>Purchase entries</span></div><div class="mini"><b>${D.sales.length}</b><span>Sales entries</span></div><div class="mini"><b>${D.receipts.length}</b><span>GRNs</span></div><div class="mini"><b>${D.dispatches.length}</b><span>Dispatches</span></div><div class="mini"><b>${D.lots.length}</b><span>Lots</span></div><div class="mini"><b>${D.market.length}</b><span>Market observations</span></div></div><p class="note">Purchase value ${money(pv)} · Sales value ${money(sv)}. All figures are synthetic.</p></div></div></div>`}
|
|
const titles=Object.fromEntries(nav.map(x=>[x[0],x[2]]));
|
|
function render(){el('content').innerHTML={dashboard,market,inventory,procurement,sales:salesView,customers:()=>masters('customers'),suppliers:()=>masters('suppliers'),logistics,finance,quality,reports}[view]();el('pageTitle').textContent=titles[view];document.querySelectorAll('.nav').forEach(b=>b.classList.toggle('active',b.dataset.view===view));}
|
|
el('nav').innerHTML=nav.map(x=>`<button class="nav ${x[0]==='dashboard'?'active':''}" data-view="${x[0]}">${x[1]} <span>${x[2]}</span></button>`).join('');document.querySelectorAll('.nav').forEach(b=>b.onclick=()=>{view=b.dataset.view;render()});render();
|