<?php $__env->startSection('title','Dashboard'); ?>
<?php $__env->startSection('content'); ?>
<div class="page-head"><div><h1>Good <?php echo e(now()->hour<12?'morning':(now()->hour<18?'afternoon':'evening')); ?>, <?php echo e(explode(' ',auth()->user()->name)[0]); ?></h1><p><?php echo e(now()->format('l, d F Y')); ?> · Live operational overview</p></div><?php if(auth()->user()->hasPermission('sales.create')): ?><a href="<?php echo e(route('sales.create')); ?>" class="btn btn-primary btn-dense"><i class="bi bi-plus-lg me-1"></i>New invoice</a><?php endif; ?></div>
<div class="row g-2 mb-2">
<?php $cards=[];
if(auth()->user()->hasPermission('sales.view'))$cards[]=['Today’s sales',$stats['today_sales'],'bi-receipt','success'];
if(auth()->user()->hasPermission('purchases.view'))$cards[]=['Today’s purchase',$stats['today_purchase'],'bi-bag','primary'];
if(auth()->user()->hasPermission('receipts.view'))$cards[]=['Collections',$stats['today_receipt'],'bi-arrow-down-left','success'];
if(auth()->user()->hasPermission('payments.view'))$cards[]=['Payments',$stats['today_payment'],'bi-arrow-up-right','danger'];
if(auth()->user()->hasPermission('accounts.view')){$cards[]=['Receivables',$stats['receivables'],'bi-people','warning'];$cards[]=['Payables',$stats['payables'],'bi-buildings','danger'];$cards[]=['Cash balance',$stats['cash_balance'],'bi-cash-stack','success'];}
if(auth()->user()->hasPermission('inventory.view_cost'))$cards[]=['Stock value',$stats['stock_value'],'bi-boxes','primary']; ?>
<?php $__currentLoopData = $cards; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as [$label,$value,$icon,$tone]): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
<div class="col-6 col-md-3 col-xxl"><div class="card-erp stat-card h-100"><div class="d-flex justify-content-between"><div><div class="label"><?php echo e($label); ?></div><div class="value"><?php echo e(number_format((float)$value,2)); ?></div><small class="text-muted">SAR</small></div><div class="icon"><i class="bi <?php echo e($icon); ?>"></i></div></div></div></div>
<?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
</div>
<div class="row g-2">
    <?php if(auth()->user()->hasPermission('sales.view')): ?><div class="col-xl-7"><div class="card-erp h-100"><div class="card-erp-header"><span>Sales · last 14 days</span><?php if(auth()->user()->hasPermission('reports.view')): ?><a href="<?php echo e(route('reports.index',['type'=>'sales'])); ?>" class="small text-accent text-decoration-none">View report</a><?php endif; ?></div><div class="card-erp-body"><div class="d-flex align-items-end gap-2" style="height:190px"><?php $max=max(1,(float)$salesTrend->max('total')); $map=$salesTrend->keyBy(fn($x)=>$x->invoice_date->format('Y-m-d')); ?> <?php for($i=13;$i>=0;$i--): ?> <?php $day=now()->subDays($i);$total=(float)optional($map->get($day->toDateString()))->total;$height=max(3,($total/$max)*155); ?> <div class="flex-fill text-center" title="SAR <?php echo e(number_format($total,2)); ?>"><div style="height:160px;display:flex;align-items:end"><div style="height:<?php echo e($height); ?>px;background:<?php echo e($i===0?'var(--accent)':'#b9d9d5'); ?>;border-radius:5px 5px 2px 2px;width:100%"></div></div><small class="text-muted" style="font-size:8px"><?php echo e($day->format('d')); ?></small></div><?php endfor; ?></div></div></div></div><?php endif; ?>
    <?php if(auth()->user()->hasPermission('vat.view')): ?><div class="col-xl-5"><div class="card-erp h-100"><div class="card-erp-header"><span>VAT position</span><span class="badge status-finalized">ZATCA PHASE 1</span></div><div class="card-erp-body"><div class="d-flex justify-content-between py-2 border-bottom"><span class="text-muted">Output VAT</span><strong>SAR <?php echo e(number_format((float)\App\Models\Sale::where('status','finalized')->sum('vat_total'),2)); ?></strong></div><div class="d-flex justify-content-between py-2 border-bottom"><span class="text-muted">Input VAT</span><strong>SAR <?php echo e(number_format((float)\App\Models\Purchase::where('status','finalized')->sum('vat_total'),2)); ?></strong></div><div class="d-flex justify-content-between align-items-center mt-3 p-3 rounded-3 bg-accent-soft"><span><small class="d-block text-muted">Net VAT payable</small><strong class="fs-5 text-accent">SAR <?php echo e(number_format((float)$stats['vat_payable'],2)); ?></strong></span><div class="text-end"><strong>15%</strong><small class="d-block text-muted">QR active</small></div></div></div></div></div><?php endif; ?>
</div>
<div class="row g-2 mt-0">
    <?php if(auth()->user()->hasPermission('sales.view')): ?><div class="col-lg-6"><div class="card-erp"><div class="card-erp-header"><span>Top selling products</span></div><div class="table-responsive"><table class="table table-dense"><thead><tr><th>Product</th><th class="text-end">Qty</th><th class="text-end">Sales</th></tr></thead><tbody><?php $__empty_1 = true; $__currentLoopData = $topProducts; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $row): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?><tr><td><strong><?php echo e($row->product?->name_en); ?></strong><small class="d-block text-muted" dir="rtl"><?php echo e($row->product?->name_ar); ?></small></td><td class="text-end"><?php echo e(number_format((float)$row->quantity,2)); ?></td><td class="text-end"><?php echo e(number_format((float)$row->total,2)); ?></td></tr><?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?><tr><td colspan="3" class="text-center text-muted py-4">Sales activity will appear here.</td></tr><?php endif; ?></tbody></table></div></div></div><?php endif; ?>
    <?php if(auth()->user()->hasPermission('inventory.view')): ?><div class="col-lg-6"><div class="card-erp"><div class="card-erp-header"><span>Low stock attention</span><a href="<?php echo e(route('current-stock.index')); ?>" class="small text-accent text-decoration-none">All stock</a></div><div class="table-responsive"><table class="table table-dense"><thead><tr><th>Product</th><th>Warehouse</th><th class="text-end">Available</th></tr></thead><tbody><?php $__empty_1 = true; $__currentLoopData = $lowStock; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $row): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?><tr><td><?php echo e($row->product?->name_en); ?></td><td><?php echo e($row->warehouse?->name_en); ?></td><td class="text-end text-danger fw-bold"><?php echo e(number_format((float)$row->qty,2)); ?></td></tr><?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?><tr><td colspan="3" class="text-center text-muted py-4">No products below reorder level.</td></tr><?php endif; ?></tbody></table></div></div></div><?php endif; ?>
</div>
<?php if(auth()->user()->hasPermission('van-sales.view')): ?><div class="card-erp"><div class="card-erp-body d-flex flex-wrap align-items-center gap-4"><div class="icon"><i class="bi bi-truck-front"></i></div><div><small class="text-muted d-block">Active vans</small><strong class="fs-5"><?php echo e($vanStats['active']); ?></strong></div><div><small class="text-muted d-block">Van sales today</small><strong class="fs-5">SAR <?php echo e(number_format((float)$vanStats['sales_today'],2)); ?></strong></div><a class="btn btn-light border btn-dense ms-auto" href="<?php echo e(route('van.index')); ?>">Open van dashboard <i class="bi bi-arrow-right ms-1"></i></a></div></div><?php endif; ?>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH C:\xampp\htdocs\saudi\resources\views/dashboard/index.blade.php ENDPATH**/ ?>