@extends('layouts.app')
@section('title','Reports & VAT')
@section('content')
<div class="page-head"><div><h1>{{ $report['title'] }}</h1><p>Operational, inventory, aging, profitability, and Saudi VAT reports from posted transactions.</p></div><a class="btn btn-light border btn-dense" href="{{ route('reports.export',request()->query()) }}"><i class="bi bi-file-earmark-excel me-1"></i>Export Excel</a></div>
<div class="card-erp"><div class="card-erp-body"><form class="row g-2 align-items-end"><div class="col-lg-4"><label class="form-label">Report</label><select name="type" class="form-select">@foreach($catalog as $group=>$reports)<optgroup label="{{ $group }}">@foreach($reports as $key=>$label)<option value="{{ $key }}" @selected($type===$key)>{{ $label }}</option>@endforeach</optgroup>@endforeach</select></div><div class="col-md-3 col-lg-2"><label class="form-label">From date</label><input type="date" name="date_from" class="form-control" value="{{ $from }}"></div><div class="col-md-3 col-lg-2"><label class="form-label">To date / as of</label><input type="date" name="date_to" class="form-control" value="{{ $to }}"></div><div class="col-md-2"><button class="btn btn-dark w-100">Run report</button></div><div class="col-lg-2 text-end text-muted small">Screen limit: 50<br>Excel: all rows</div></form></div></div>
<div class="row g-2 mb-2">@foreach([['Taxable sales',$vat['taxable_sales']],['Output VAT',$vat['output_vat']],['Taxable purchases',$vat['taxable_purchases']],['Input VAT',$vat['input_vat']],['VAT difference',$vat['difference']]] as [$label,$value])<div class="col-6 col-md"><div class="card-erp stat-card"><div class="label">{{ $label }}</div><div class="value">{{ number_format((float)$value,2) }}</div><small class="text-muted">SAR</small></div></div>@endforeach</div>
<div class="d-flex flex-wrap gap-2 mb-2">@if(auth()->user()->hasPermission('accounts.view_reports'))<a href="{{ route('accounts.trial-balance') }}" class="btn btn-sm btn-light border">Trial balance</a><a href="{{ route('accounts.statement','profit-loss') }}" class="btn btn-sm btn-light border">Profit & loss</a><a href="{{ route('accounts.statement','balance-sheet') }}" class="btn btn-sm btn-light border">Balance sheet</a>@endif @if(auth()->user()->hasPermission('accounts.view'))<a href="{{ route('accounts.ledger') }}" class="btn btn-sm btn-light border">General ledger</a>@endif @if(auth()->user()->hasPermission('inventory.view'))<a href="{{ route('stock-ledger.index') }}" class="btn btn-sm btn-light border">Stock ledger</a>@endif @if(auth()->user()->hasPermission('inventory.view_reports'))<a href="{{ route('expiry-report.index') }}" class="btn btn-sm btn-light border">Batch / expiry</a>@endif</div>
<div class="card-erp"><div class="table-responsive"><table class="table table-dense"><thead><tr>@foreach($report['columns'] as $column)<th class="{{ ($column[2]??'')==='money'||($column[2]??'')==='qty'?'text-end':'' }}">{{ $column[1] }}</th>@endforeach</tr></thead><tbody>@forelse($report['rows'] as $row)<tr>@foreach($report['columns'] as $column)@php($value=$row[$column[0]]??null)<td class="{{ ($column[2]??'')==='money'||($column[2]??'')==='qty'?'text-end':'' }}">@if(($column[2]??'')==='money'){{ number_format((float)$value,2) }}@elseif(($column[2]??'')==='qty'){{ number_format((float)$value,4) }}@elseif($column[0]==='arabic')<span dir="rtl">{{ $value }}</span>@else{{ $value }}@endif</td>@endforeach</tr>@empty<tr><td colspan="{{ count($report['columns']) }}" class="text-center text-muted py-5">No posted data for the selected report and date range.</td></tr>@endforelse</tbody></table></div></div>
@endsection
