@extends('layouts.app')
@section('title', 'Laporan Tanda Terima')
@section('page-title', 'Laporan Rekap Tanda Terima')

@section('content')
<h5 class="font-weight-bold mb-3">Laporan Rekap Tanda Terima</h5>

<div class="card mb-3">
    <div class="card-body py-2">
        <form method="GET" class="form-inline">
            <div class="form-group mr-2 mb-2">
                <label class="mr-1 small">Dari:</label>
                <input type="date" name="date_from" value="{{ request('date_from') }}" class="form-control form-control-sm">
            </div>
            <div class="form-group mr-2 mb-2">
                <label class="mr-1 small">Sampai:</label>
                <input type="date" name="date_to" value="{{ request('date_to') }}" class="form-control form-control-sm">
            </div>
            <div class="form-group mr-2 mb-2">
                <label class="mr-1 small">Metode:</label>
                <select name="payment_method" class="form-control form-control-sm">
                    <option value="">Semua</option>
                    <option value="Tunai" @selected(request('payment_method')=='Tunai')>Tunai</option>
                    <option value="Transfer Bank" @selected(request('payment_method')=='Transfer Bank')>Transfer Bank</option>
                    <option value="QRIS" @selected(request('payment_method')=='QRIS')>QRIS</option>
                    <option value="Cek/Giro" @selected(request('payment_method')=='Cek/Giro')>Cek/Giro</option>
                </select>
            </div>
            <div class="form-group mb-2">
                <button type="submit" class="btn btn-sm btn-secondary mr-1">Filter</button>
                <a href="{{ route('reports.receipts') }}" class="btn btn-sm btn-outline-secondary mr-2">Reset</a>
                <button type="button" onclick="window.print()" class="btn btn-sm btn-outline-dark no-print">
                    <i class="fas fa-print"></i> Cetak
                </button>
            </div>
        </form>
    </div>
</div>

<div class="row mb-3">
    <div class="col-md-6">
        <div class="card text-center">
            <div class="card-body py-3">
                <div class="text-muted small">Total Tanda Terima</div>
                <div class="h4 font-weight-bold mb-0">{{ $summary->total_receipts }}</div>
            </div>
        </div>
    </div>
    <div class="col-md-6">
        <div class="card text-center">
            <div class="card-body py-3">
                <div class="text-muted small">Total Penerimaan</div>
                <div class="h5 font-weight-bold mb-0 text-success">Rp {{ number_format($summary->total_amount, 0, ',', '.') }}</div>
            </div>
        </div>
    </div>
</div>

<div class="card">
    <div class="card-body p-0">
        <div class="table-responsive">
            <table class="table table-hover align-middle mb-0">
                <thead>
                    <tr>
                        <th>No. Tanda Terima</th>
                        <th>Pelanggan</th>
                        <th>Ref. Invoice</th>
                        <th>Tanggal</th>
                        <th>Metode</th>
                        <th class="text-right">Jumlah Diterima</th>
                    </tr>
                </thead>
                <tbody>
                @forelse($receipts as $r)
                <tr>
                    <td><a href="{{ route('receipts.show', $r) }}" class="font-weight-bold">{{ $r->receipt_number }}</a></td>
                    <td>{{ $r->customer->name }}</td>
                    <td class="text-muted small">{{ $r->invoice->invoice_number }}</td>
                    <td>{{ $r->receipt_date->format('d/m/Y') }}</td>
                    <td><span class="badge badge-secondary">{{ $r->payment_method ?? '-' }}</span></td>
                    <td class="text-right font-weight-bold text-success">Rp {{ number_format($r->amount_received, 0, ',', '.') }}</td>
                </tr>
                @empty
                <tr><td colspan="6" class="text-center text-muted py-5">Tidak ada data tanda terima</td></tr>
                @endforelse
                </tbody>
                @if($receipts->count() > 0)
                <tfoot class="bg-light">
                    <tr>
                        <td colspan="5" class="text-right font-weight-bold">TOTAL HALAMAN INI</td>
                        <td class="text-right font-weight-bold text-success">
                            Rp {{ number_format($receipts->sum('amount_received'), 0, ',', '.') }}
                        </td>
                    </tr>
                </tfoot>
                @endif
            </table>
        </div>
    </div>
    @if($receipts->hasPages())
        <div class="card-footer no-print">{{ $receipts->links() }}</div>
    @endif
</div>
@endsection

