@extends('layouts.app')
@section('title', __('Business Reports'))
@section('content')
@php($period = __('Period').': '.$from.' - '.$to)
<div class="card mb-3">
    <div class="card-body p-4">
        @include('reports.partials.header', ['title' => __('Business Reports'), 'period' => $period])
        <form class="row g-2 align-items-end no-print">
            <div class="col-md-3"><label class="form-label">{{ __('From') }}</label><input name="from" type="date" class="form-control" value="{{ $from }}"></div>
            <div class="col-md-3"><label class="form-label">{{ __('To') }}</label><input name="to" type="date" class="form-control" value="{{ $to }}"></div>
            <div class="col-auto"><button class="btn btn-success"><i class="fa-solid fa-filter me-1"></i>{{ __('Apply') }}</button></div>
            <div class="col-auto"><button type="button" onclick="window.print()" class="btn btn-light"><i class="fa-solid fa-print me-1"></i>{{ __('Print') }}</button></div>
        </form>
    </div>
</div>

<div class="row g-3">
    @foreach([
        ['Sales', $salesTotal, 'fa-chart-column', 'text-success', __('Invoices').': '.$salesCount],
        ['Purchases', $purchaseTotal, 'fa-cart-arrow-down', 'text-warning', __('Purchases').': '.$purchaseCount],
        ['Expenses', $expenses, 'fa-money-bill-transfer', 'text-danger', __('Operating expenses')],
        ['Gross Profit', $grossProfit, 'fa-scale-balanced', $grossProfit >= 0 ? 'text-success' : 'text-danger', __('Sales minus cost of goods')],
        ['Net Profit', $netProfit, 'fa-file-invoice-dollar', $netProfit >= 0 ? 'text-success' : 'text-danger', __('After expenses')],
        ['Inventory Value', $inventoryValue, 'fa-warehouse', 'text-success', __('Low Stock Items').': '.$lowStockCount],
        ['Customer Due', $receivable, 'fa-user-clock', 'text-danger', __('Accounts Receivable')],
        ['Supplier Due', $payable, 'fa-truck-field', 'text-danger', __('Supplier Payables')],
    ] as [$label, $value, $icon, $class, $caption])
        <div class="col-md-6 col-xl-3">
            <div class="card h-100">
                <div class="card-body d-flex gap-3 align-items-start">
                    <div class="stat-icon"><i class="fa-solid {{ $icon }}"></i></div>
                    <div>
                        <small class="text-muted">{{ __($label) }}</small>
                        <h5 class="mb-1 money {{ $class }}">{{ number_format($value, 2) }} {{ $moneyCode }}</h5>
                        <small class="text-muted">{{ $caption }}</small>
                    </div>
                </div>
            </div>
        </div>
    @endforeach
</div>

<div class="card mt-3">
    <div class="card-body p-4">
        <h6 class="mb-3">{{ __('Report Center') }}</h6>
        <div class="row g-2">
            @foreach([
                ['reports.sales', 'fa-chart-column', 'Sales Report'],
                ['reports.purchases', 'fa-cart-arrow-down', 'Purchase Report'],
                ['reports.stock', 'fa-boxes-stacked', 'Stock Report'],
                ['reports.payments', 'fa-arrow-up', 'Payments Report'],
                ['reports.receipts', 'fa-arrow-down', 'Receipts Report'],
                ['reports.customer-balances', 'fa-users', 'Customer Balances'],
                ['reports.supplier-balances', 'fa-truck-field', 'Supplier Balances'],
                ['reports.chart-of-accounts', 'fa-list-check', 'Chart of Accounts'],
                ['reports.balance-sheet', 'fa-scale-balanced', 'Balance Sheet'],
                ['reports.income-statement', 'fa-file-invoice-dollar', 'Income Statement'],
            ] as [$route, $icon, $label])
                <div class="col-md-4">
                    <a class="btn btn-light w-100 text-start py-3" href="{{ route($route, in_array($route, ['reports.sales', 'reports.purchases', 'reports.payments', 'reports.receipts']) ? ['from' => $from, 'to' => $to] : []) }}"><i class="fa-solid {{ $icon }} text-success me-2"></i>{{ __($label) }}</a>
                </div>
            @endforeach
        </div>
    </div>
</div>

@if(!empty($appSettings['report_footer']))
    <p class="text-center text-muted small mt-3">{{ $appSettings['report_footer'] }}</p>
@endif
@endsection
