<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title><?php echo e($invoice->invoice_number); ?></title>
    <style>
        body { font-family: DejaVu Sans, sans-serif; font-size: 11px; color: #222; margin: 24px; }
        h1 { font-size: 20px; margin: 0 0 4px; color: #0f4c5c; }
        h2 { font-size: 13px; margin: 18px 0 6px; color: #0f4c5c; }
        .meta { color: #555; margin-bottom: 12px; }
        .box { border: 1px solid #ddd; padding: 10px; margin-top: 10px; }
        table { width: 100%; border-collapse: collapse; margin-top: 10px; }
        th, td { border: 1px solid #ccc; padding: 6px; text-align: left; vertical-align: top; }
        th { background: #f0f4f5; }
        .text-right { text-align: right; }
        .totals td { border: none; padding: 3px 6px; }
        .totals tr.grand td { font-size: 13px; font-weight: bold; padding-top: 8px; }
        .footer { margin-top: 24px; font-size: 10px; color: #666; border-top: 1px solid #ddd; padding-top: 8px; }
    </style>
</head>
<body>
    <?php
        $customer = is_array($invoice->customer_snapshot) ? $invoice->customer_snapshot : (json_decode((string) $invoice->customer_snapshot, true) ?: []);
        $event = is_array($invoice->event_snapshot) ? $invoice->event_snapshot : (json_decode((string) $invoice->event_snapshot, true) ?: []);
        $spaces = is_array($invoice->spaces_snapshot) ? $invoice->spaces_snapshot : (json_decode((string) $invoice->spaces_snapshot, true) ?: []);
    ?>

    <h1>Invoice</h1>
    <div class="meta">
        <strong><?php echo e($settings['property_name'] ?? 'Venue Events Manager'); ?></strong><br>
        <?php echo e($settings['address'] ?? ''); ?>

        <?php if(!empty($settings['phone'])): ?> | Tel: <?php echo e($settings['phone']); ?> <?php endif; ?>
        <?php if(!empty($settings['email'])): ?> | <?php echo e($settings['email']); ?> <?php endif; ?>
        <?php if(!empty($settings['tax_id'])): ?> | TIN: <?php echo e($settings['tax_id']); ?> <?php endif; ?>
    </div>

    <table>
        <tr>
            <td width="50%">
                <strong>Invoice No:</strong> <?php echo e($invoice->invoice_number); ?><br>
                <?php if($invoice->quotation): ?><strong>From quotation:</strong> <?php echo e($invoice->quotation->quotation_number); ?><br><?php endif; ?>
                <strong>Date:</strong> <?php echo e($invoice->invoice_date?->format('d/m/Y')); ?><br>
                <strong>Due:</strong> <?php echo e($invoice->due_date?->format('d/m/Y') ?: '—'); ?><br>
                <strong>Status:</strong> <?php echo e($invoice->status?->label() ?? $invoice->status); ?>

            </td>
            <td width="50%">
                <strong>Bill To</strong><br>
                <?php echo e($customer['name'] ?? $invoice->customer?->name); ?><br>
                <?php echo e($customer['contact_person'] ?? $invoice->customer?->contact_person); ?><br>
                <?php echo e($customer['phone'] ?? $invoice->customer?->phone); ?><br>
                <?php echo e($customer['email'] ?? $invoice->customer?->email); ?><br>
                <?php echo e($customer['billing_address'] ?? $invoice->customer?->billing_address); ?>

            </td>
        </tr>
    </table>

    <?php if(!empty($event) || $invoice->booking): ?>
        <h2>Event</h2>
        <div class="box">
            <strong><?php echo e($event['event_name'] ?? $invoice->booking?->event_name ?? 'Event'); ?></strong><br>
            Guests: <?php echo e($event['guest_count'] ?? $invoice->guest_count); ?> |
            Start: <?php echo e($event['event_start'] ?? ($invoice->booking?->event_start?->format('d/m/Y H:i') ?? '—')); ?> |
            End: <?php echo e($event['event_end'] ?? ($invoice->booking?->event_end?->format('d/m/Y H:i') ?? '—')); ?>

        </div>
    <?php endif; ?>

    <?php if(!empty($spaces)): ?>
        <h2>Spaces</h2>
        <ul>
            <?php $__currentLoopData = $spaces; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $space): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                <li><?php echo e(is_array($space) ? ($space['name'] ?? $space['space_name'] ?? json_encode($space)) : $space); ?></li>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
        </ul>
    <?php endif; ?>

    <h2>Charges</h2>
    <table>
        <thead>
            <tr>
                <th>Description</th>
                <th class="text-right">Qty</th>
                <th>Basis</th>
                <th class="text-right">Unit Price</th>
                <th class="text-right">Tax</th>
                <th class="text-right">Line Total</th>
            </tr>
        </thead>
        <tbody>
            <?php $__empty_1 = true; $__currentLoopData = $invoice->items; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                <tr>
                    <td><?php echo e($item->description); ?></td>
                    <td class="text-right"><?php echo e(number_format((float) $item->quantity, 2)); ?></td>
                    <td><?php echo e($item->charge_basis?->label() ?? $item->charge_basis); ?></td>
                    <td class="text-right"><?php echo e(number_format((float) $item->unit_price, 2)); ?></td>
                    <td class="text-right"><?php echo e(number_format((float) $item->tax_amount, 2)); ?></td>
                    <td class="text-right"><?php echo e(number_format((float) $item->line_total, 2)); ?></td>
                </tr>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                <tr><td colspan="6">No line items</td></tr>
            <?php endif; ?>
        </tbody>
    </table>

    <table class="totals" style="width: 45%; margin-left: auto;">
        <tr><td class="text-right">Subtotal</td><td class="text-right"><?php echo e(number_format((float) $invoice->subtotal, 2)); ?></td></tr>
        <tr><td class="text-right">Discount</td><td class="text-right"><?php echo e(number_format((float) $invoice->discount_amount, 2)); ?></td></tr>
        <tr><td class="text-right">Service charge</td><td class="text-right"><?php echo e(number_format((float) $invoice->service_charge_amount, 2)); ?></td></tr>
        <tr><td class="text-right">Tax</td><td class="text-right"><?php echo e(number_format((float) $invoice->tax_amount, 2)); ?></td></tr>
        <tr class="grand"><td class="text-right">Grand Total</td><td class="text-right"><?php echo e(number_format((float) $invoice->grand_total, 2)); ?> <?php echo e($invoice->currency); ?></td></tr>
        <tr><td class="text-right">Amount paid</td><td class="text-right"><?php echo e(number_format((float) $invoice->amount_paid, 2)); ?></td></tr>
        <tr><td class="text-right"><strong>Outstanding</strong></td><td class="text-right"><strong><?php echo e(number_format((float) $invoice->outstanding_balance, 2)); ?></strong></td></tr>
    </table>

    <?php if($invoice->payment_terms || $invoice->notes || $invoice->terms_and_conditions): ?>
        <h2>Terms &amp; Notes</h2>
        <?php if($invoice->payment_terms): ?><p><strong>Payment terms:</strong> <?php echo e($invoice->payment_terms); ?></p><?php endif; ?>
        <?php if($invoice->notes): ?><p><strong>Notes:</strong> <?php echo e($invoice->notes); ?></p><?php endif; ?>
        <?php if($invoice->terms_and_conditions): ?><p><?php echo e($invoice->terms_and_conditions); ?></p><?php endif; ?>
    <?php endif; ?>

    <div class="footer">
        Generated <?php echo e(now()->format('d/m/Y H:i')); ?> — <?php echo e($invoice->invoice_number); ?>

    </div>
</body>
</html>
<?php /**PATH C:\xampp\htdocs\hotelplus\consol\resources\views/pdf/invoice.blade.php ENDPATH**/ ?>