<?php $__env->startSection('title', $title); ?>
<?php $__env->startSection('crumbs', '<a href="'.route('reports.index').'">Reports</a> · <b>'.$title.'</b>'); ?>
<?php $__env->startSection('content'); ?>
<?php
$dateFilters = $filters[0];
$selectFilters = $filters[1];
$colKeys = array_keys($columns);
$filterOpts = function($ff) {
  switch($ff) {
    case 'quarry_id': return \App\Models\Quarry::orderBy('name')->pluck('name','id');
    case 'project_id': return \App\Models\Project::orderBy('code')->pluck('code','id');
    case 'customer_id': return \App\Models\Customer::orderBy('name')->pluck('name','id');
    case 'supplier_id': return \App\Models\Supplier::orderBy('name')->pluck('name','id');
    case 'product_id': return \App\Models\Product::orderBy('name')->pluck('name','id');
    case 'equipment_id': return \App\Models\Equipment::orderBy('code')->pluck('code','id');
    case 'item_id': return \App\Models\StockItem::orderBy('name')->pluck('name','id');
    case 'account_id': return \App\Models\Account::orderBy('code')->get()->pluck('display_name','id');
    case 'bank_id': return \App\Models\BankAccount::orderBy('bank_name')->get()->pluck('display_name','id');
    default: return collect();
  }
};
$cellNum = function($v) { return (float) str_replace([',','GH₵',' '], '', (string) ($v ?? 0)); };
?>
<div class="card"><div class="card-h"><h2><?php echo e($title); ?></h2>
<div class="sp no-print">
<a class="btn btn-sm btn-ghost" href="<?php echo e(request()->fullUrlWithQuery(['export'=>'csv'])); ?>">⬇ CSV</a>
<a class="btn btn-sm btn-ghost" href="<?php echo e(request()->fullUrlWithQuery(['export'=>'pdf'])); ?>">📄 PDF</a>
<button class="btn btn-sm btn-ghost" data-print>🖨 Print</button>
</div></div>
<div class="card-b">
<?php if(count($dateFilters) || count($selectFilters)): ?>
<form method="GET" class="toolbar no-print rep-filters" style="margin-bottom:16px">
<?php if(in_array('from', $dateFilters)): ?><div class="fld"><label>From</label><input type="date" name="from" value="<?php echo e($from); ?>"></div><?php endif; ?>
<?php if(in_array('to', $dateFilters)): ?><div class="fld"><label>To</label><input type="date" name="to" value="<?php echo e($to); ?>"></div><?php endif; ?>
<?php $__currentLoopData = $selectFilters; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $ff): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
<div class="fld"><label><?php echo e(ucwords(str_replace('_',' ',$ff))); ?></label><select name="<?php echo e($ff); ?>"><option value="">— All —</option>
<?php $__currentLoopData = $filterOpts($ff); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $ov=>$ol): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?><option value="<?php echo e($ov); ?>" <?php if($req->get($ff)==$ov): ?> selected <?php endif; ?>><?php echo e($ol); ?></option><?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
</select></div>
<?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
<div class="fld"><label>&nbsp;</label><button class="btn btn-sm">Run</button></div>
</form>
<?php endif; ?>
<p class="muted small"><?php echo e($__company->name ?? ''); ?> · <?php if(count($dateFilters)): ?> Period <?php echo e($from); ?> → <?php echo e($to); ?> · <?php endif; ?> <?php echo e(count($rows)); ?> row(s)</p>
<div class="twrap"><table class="tbl"><thead><tr>
<?php $__currentLoopData = $columns; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $cl => $al): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?><th class="<?php echo e($al === 'r' ? 'r' : ''); ?>"><?php echo e($cl); ?></th><?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
</tr></thead><tbody>
<?php $__empty_1 = true; $__currentLoopData = $rows; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $row): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?><tr>
<?php $__currentLoopData = $colKeys; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $i => $ck): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?><td class="<?php echo e(($columns[$ck] ?? '') === 'r' ? 'r' : ''); ?>"><?php echo e($row[$i] ?? ''); ?></td><?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
</tr>
<?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?><tr><td colspan="<?php echo e(count($columns)); ?>" class="muted c">No data for the selected filters.</td></tr><?php endif; ?>
</tbody>
<?php if(count($totals) && count($rows)): ?>
<tfoot><tr>
<?php $__currentLoopData = $colKeys; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $i => $ck): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
<td class="<?php echo e(($columns[$ck] ?? '') === 'r' ? 'r' : ''); ?>"><?php if(in_array($ck, $totals)): ?><?php echo e(money(collect($rows)->sum(fn($r) => $cellNum($r[$i] ?? 0)))); ?><?php elseif($i === 0): ?> Total <?php endif; ?></td>
<?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
</tr></tfoot>
<?php endif; ?>
</table></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/reports/show.blade.php ENDPATH**/ ?>