<?php $__env->startSection('title','Dashboard'); ?>
<?php $__env->startSection('crumbs','<b>Dashboard</b> · <span>Operations command centre</span>'); ?>
<?php $__env->startSection('content'); ?>
<?php if(count($alerts)): ?>
<div class="card"><div class="card-b" style="padding:12px 18px">
<?php $__currentLoopData = $alerts; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as [$tone,$msg]): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?><div class="alert <?php echo e($tone); ?>"><?php echo e($tone==='bad' ? '✕' : ($tone==='warn' ? '⚠' : 'ℹ')); ?> &nbsp;<?php echo e($msg); ?></div><?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
</div></div>
<?php endif; ?>

<div class="grid g4" style="margin-bottom:14px">
  <div class="kpi"><div class="lb">Production today</div><div class="vl"><?php echo e(qty($k['prod_today'])); ?> t</div><div class="sb"><?php echo e(qty($k['prod_month'])); ?> t this month (approved)</div></div>
  <div class="kpi y"><div class="lb">Dispatched today</div><div class="vl"><?php echo e(qty($k['dispatch_today'])); ?> t</div><div class="sb">Across all quarries & customers</div></div>
  <div class="kpi g"><div class="lb">Revenue this month</div><div class="vl"><?php echo e(cmoney($k['revenue_month'],0)); ?></div><div class="sb">Invoiced (excl. draft/cancelled)</div></div>
  <div class="kpi red"><div class="lb">Receivables outstanding</div><div class="vl"><?php echo e(cmoney($k['ar_out'],0)); ?></div><div class="sb">Payables: <?php echo e(cmoney($k['ap_out'],0)); ?></div></div>
</div>
<div class="grid g4" style="margin-bottom:18px">
  <div class="kpi b"><div class="lb">Attendance today</div><div class="vl"><?php echo e($present); ?> / <?php echo e($empTotal); ?></div><div class="sb">Present of active staff</div></div>
  <div class="kpi d"><div class="lb">Fleet available</div><div class="vl"><?php echo e($eqAvail); ?> / <?php echo e($eqTotal); ?></div><div class="sb">Machines ready for work</div></div>
  <div class="kpi y"><div class="lb">Fuel cost (month)</div><div class="vl"><?php echo e(cmoney($k['fuel_month'],0)); ?></div><div class="sb">All equipment</div></div>
  <div class="kpi g"><div class="lb">Net payroll (month)</div><div class="vl"><?php echo e(cmoney($k['payroll_month'],0)); ?></div><div class="sb">Last computed run</div></div>
</div>

<div class="grid g2">
  <div class="card"><div class="card-h"><h2>Production — last 14 days (tonnes)</h2></div><div class="card-b">
    <?php $mx = max(1, max($labels14)); ?>
    <div class="bars"><?php $__currentLoopData = $labels14; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $d=>$v): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?><div class="bar" style="height:<?php echo e(round($v/$mx*100)); ?>%" title="<?php echo e($d); ?>: <?php echo e(qty($v)); ?> t"><i><?php echo e($v>0? round($v):''); ?></i></div><?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?></div>
    <div class="bars-x"><?php $__currentLoopData = $labels14; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $d=>$v): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?><span><?php echo e(date('d/m',strtotime($d))); ?></span><?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?></div>
  </div></div>
  <div class="card"><div class="card-h"><h2>Revenue — last 6 months</h2></div><div class="card-b">
    <?php $mx2 = max(1, $sales6->max() ?? 1); ?>
    <div class="bars"><?php for($i=5;$i>=0;$i--): ?> <?php $m = date('Y-m', strtotime("-$i months")); $v = (float)($sales6[$m] ?? 0); ?><div class="bar" style="height:<?php echo e(round($v/$mx2*100)); ?>%;background:linear-gradient(180deg,#34c179,#1e9e5a)" title="<?php echo e($m); ?>: <?php echo e(cmoney($v,0)); ?>"><i><?php echo e($v>0? round($v/1000).'k':''); ?></i></div><?php endfor; ?></div>
    <div class="bars-x"><?php for($i=5;$i>=0;$i--): ?><span><?php echo e(date('M', strtotime("-$i months"))); ?></span><?php endfor; ?></div>
  </div></div>
</div>

<div class="grid g2">
  <div class="card"><div class="card-h"><h2>Dispatch by product (this month)</h2><div class="sp"><a class="btn btn-sm btn-ghost" href="<?php echo e(route('reports.show','dispatch-register')); ?>">Full report</a></div></div>
    <div class="card-b"><?php $mx3 = max(1, $byProduct->max('t') ?? 1); ?>
    <?php $__empty_1 = true; $__currentLoopData = $byProduct; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $bp): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?><div class="hbar-row"><span><?php echo e($bp->product->name ?? '—'); ?></span><div class="hbar"><i style="width:<?php echo e(round($bp->t/$mx3*100)); ?>%"></i></div><b class="r"><?php echo e(qty($bp->t)); ?></b></div>
    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?><p class="muted">No dispatches this month yet.</p><?php endif; ?>
  </div></div>
  <div class="card"><div class="card-h"><h2>Stockpiles (lowest first)</h2><div class="sp"><a class="btn btn-sm btn-ghost" href="<?php echo e(crud_url('stockpiles','index')); ?>">All piles</a></div></div>
    <div class="card-b" style="padding:0"><div class="twrap" style="border:none;border-radius:0"><table class="tbl"><thead><tr><th>Pile</th><th>Product</th><th class="r">Stock (t)</th></tr></thead>
    <tbody><?php $__empty_1 = true; $__currentLoopData = $stockpiles; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $s): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?><tr><td><b><?php echo e($s->code); ?></b><br><span class="small muted"><?php echo e($s->quarry->name ?? ''); ?></span></td><td><?php echo e($s->product->name ?? ''); ?></td><td class="r"><b><?php echo e(qty($s->current_qty)); ?></b></td></tr><?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?><tr><td colspan="3" class="muted">No stockpiles.</td></tr><?php endif; ?></tbody></table></div></div></div>
</div>

<div class="grid g2">
  <div class="card"><div class="card-h"><h2>Low stock alerts</h2><div class="sp"><a class="btn btn-sm btn-ghost" href="<?php echo e(route('reports.show','below-reorder')); ?>">Report</a></div></div>
    <div class="card-b" style="padding:0"><div class="twrap" style="border:none;border-radius:0"><table class="tbl"><thead><tr><th>Item</th><th class="r">On hand</th><th class="r">Reorder</th></tr></thead>
    <tbody><?php $__empty_1 = true; $__currentLoopData = $lowStock; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $i): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?><tr><td><b><?php echo e($i->code); ?></b> <?php echo e($i->name); ?></td><td class="r"><?php echo e(qty($i->current_qty)); ?></td><td class="r"><?php echo e(qty($i->reorder_level)); ?></td></tr><?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?><tr><td colspan="3" class="muted">All stocked up. ✓</td></tr><?php endif; ?></tbody></table></div></div></div>
  <div class="card"><div class="card-h"><h2>Overdue invoices</h2><div class="sp"><a class="btn btn-sm btn-ghost" href="<?php echo e(route('reports.show','ar-aging')); ?>">AR aging</a></div></div>
    <div class="card-b" style="padding:0"><div class="twrap" style="border:none;border-radius:0"><table class="tbl"><thead><tr><th>Invoice</th><th>Customer</th><th class="r">Due</th></tr></thead>
    <tbody><?php $__empty_1 = true; $__currentLoopData = $overdue; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $o): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?><tr><td><a href="<?php echo e(route('sales-invoices.show',$o)); ?>"><b><?php echo e($o->invoice_no); ?></b></a><br><span class="small muted"><?php echo e(fdate($o->due_date)); ?></span></td><td><?php echo e($o->customer->name ?? ''); ?></td><td class="r"><b><?php echo e(money($o->balance_due)); ?></b></td></tr><?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?><tr><td colspan="3" class="muted">Nothing overdue. ✓</td></tr><?php endif; ?></tbody></table></div></div></div>
</div>

<div class="grid g2">
  <div class="card"><div class="card-h"><h2>Expiring equipment documents</h2></div>
    <div class="card-b" style="padding:0"><div class="twrap" style="border:none;border-radius:0"><table class="tbl"><thead><tr><th>Equipment</th><th>Type</th><th>Expiry</th></tr></thead>
    <tbody><?php $__empty_1 = true; $__currentLoopData = $expiring; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $e): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?><tr><td><?php echo e($e->equipment->display_name ?? ''); ?></td><td><span class="bdg b-info"><?php echo e($e->doc_type); ?></span></td><td><?php echo e(fdate($e->expiry_date)); ?></td></tr><?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?><tr><td colspan="3" class="muted">No expiries in 30 days. ✓</td></tr><?php endif; ?></tbody></table></div></div></div>
  <div class="card"><div class="card-h"><h2>Open work orders (critical first)</h2><div class="sp"><a class="btn btn-sm btn-ghost" href="<?php echo e(route('maintenance-work-orders.index')); ?>">Workshop</a></div></div>
    <div class="card-b" style="padding:0"><div class="twrap" style="border:none;border-radius:0"><table class="tbl"><thead><tr><th>WO</th><th>Equipment</th><th>Priority</th><th>Status</th></tr></thead>
    <tbody><?php $__empty_1 = true; $__currentLoopData = $openWOs; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $w): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?><tr><td><a href="<?php echo e(route('maintenance-work-orders.show',$w)); ?>"><b><?php echo e($w->wo_no); ?></b></a></td><td><?php echo e($w->equipment->display_name ?? ''); ?></td><td><span class="bdg b-<?php echo e(statusClass($w->priority)); ?>"><?php echo e($w->priority); ?></span></td><td><span class="bdg b-<?php echo e(statusClass($w->status)); ?>"><?php echo e($w->status); ?></span></td></tr><?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?><tr><td colspan="4" class="muted">Workshop clear. ✓</td></tr><?php endif; ?></tbody></table></div></div></div>
</div>

<div class="grid g2">
  <div class="card"><div class="card-h"><h2>Latest invoices</h2></div>
    <div class="card-b" style="padding:0"><div class="twrap" style="border:none;border-radius:0"><table class="tbl"><thead><tr><th>Invoice</th><th>Customer</th><th class="r">Total</th><th>Status</th></tr></thead>
    <tbody><?php $__empty_1 = true; $__currentLoopData = $recentInvoices; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $i): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?><tr><td><a href="<?php echo e(route('sales-invoices.show',$i)); ?>"><b><?php echo e($i->invoice_no); ?></b></a></td><td><?php echo e($i->customer->name ?? ''); ?></td><td class="r"><?php echo e(money($i->grand_total)); ?></td><td><span class="bdg b-<?php echo e(statusClass($i->status)); ?>"><?php echo e($i->status); ?></span></td></tr><?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?><tr><td colspan="4" class="muted">No invoices yet.</td></tr><?php endif; ?></tbody></table></div></div></div>
  <div class="card"><div class="card-h"><h2>Latest dispatches</h2></div>
    <div class="card-b" style="padding:0"><div class="twrap" style="border:none;border-radius:0"><table class="tbl"><thead><tr><th>DN</th><th>Customer</th><th>Vehicle</th><th>Status</th></tr></thead>
    <tbody><?php $__empty_1 = true; $__currentLoopData = $recentDeliveries; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $d): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?><tr><td><a href="<?php echo e(route('delivery-notes.show',$d)); ?>"><b><?php echo e($d->dn_no); ?></b></a></td><td><?php echo e($d->customer->name ?? ''); ?></td><td><?php echo e($d->vehicle_no); ?></td><td><span class="bdg b-<?php echo e(statusClass($d->status)); ?>"><?php echo e($d->status); ?></span></td></tr><?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?><tr><td colspan="4" class="muted">No dispatches yet.</td></tr><?php endif; ?></tbody></table></div></div></div>
</div>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH /home/user/nowills-sqc-erp/resources/views/dashboard/index.blade.php ENDPATH**/ ?>