<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <?php use Illuminate\Support\Str; ?>
    <title><?php echo e(Str::title(str_replace('_', ' ', $document->type))); ?> - <?php echo e($document->document_number); ?></title>
    <style>
        @page { size: A4; margin: 15px; }
        html, body {
            font-family: 'DejaVu Sans', sans-serif;
            font-size: 9pt;
            margin: 0; padding: 0;
            color: #333;
        }
        body { padding: 15px; box-sizing: border-box; }
        .document-title {
            text-align: center;
            font-size: 15pt;
            font-weight: bold;
            color: #1a365d;
            margin-bottom: 15px;
            text-transform: uppercase;
        }
        .header-container { border-bottom: 1px solid #e2e8f0; padding-bottom: 15px; margin-bottom: 15px; }
        .logo-full { text-align: left; margin-bottom: 1px; }
        .logo-full img { max-width: 100px; }

        .info-row { width: 100%; border-collapse: collapse; }
        .info-row td { padding: 5px; vertical-align: top; }
        .info-left, .info-right { width: 50%; }
        .info-left { text-align: left; }
        .info-right { text-align: right; }
        .compact-info { font-size: 10pt; }

        .label, .value {
            display: inline-block;
            vertical-align: top;
            font-size: 9pt;
            font-family: 'DejaVu Sans', sans-serif;
        }
        .label {
            font-weight: normal;
            color: #1a365d;
            margin-right: 3px;
        }

        .address-value { display: inline; word-wrap: break-word; }

        .section-title {
            font-size: 10pt;
            font-weight: bold;
            color: #1a365d;
            text-transform: uppercase;
            margin-bottom: 5px;
            border-bottom: 1px solid #1a365d;
            padding-bottom: 2px;
            display: block;
        }

        .doc-info {
            display: flex;
            justify-content: space-between;
            font-size: 9pt;
            padding: 10px;
            background-color: #f8fafc;
            border: 1px solid #e2e8f0;
            border-radius: 4px;
            margin-bottom: 15px;
        }
        .doc-info div { line-height: 1.5; }

        .items-table {
            width: 100%;
            border-collapse: collapse;
            font-size: 9pt;
            margin-bottom: 15px;
        }
        .items-table th {
            background-color: #1a365d;
            color: #fff;
            padding: 8px;
            text-align: center;
        }
        .items-table td {
            border: 1px solid #e2e8f0;
            padding: 8px;
            text-align: center;
        }
        .items-table tr:nth-child(even) { background-color: #f8fafc; }

        .totals-panel table { width: auto; margin-left: auto; font-size: 9pt; }
        .totals-panel td { padding: 4px 0; }
        .total-row { border-top: 1px solid #333; font-weight: bold; }

        .signature-block { font-size: 9pt; margin-top: 15px; }

        .notes-banking-row {
            width: 100%;
            display: flex;
            justify-content: space-between;
            gap: 10px;
            margin-top: 20px;
        }
        .notes, .banking-details {
            width: 49%;
            padding: 10px;
            background-color: #f8fafc;
            border: 1px solid #e2e8f0;
            border-radius: 4px;
            font-size: 9pt;
        }

        .bottom-footer {
            width: 100%;
            font-size: 9pt;
            position: fixed;
            bottom: 15px;
            left: 15px;
            right: 15px;
        }
        .bottom-footer table { width: 100%; border-collapse: collapse; }
        .bottom-footer td { width: 50%; padding-right: 20px; }
        .text-right { text-align: right; }
    </style>
</head>
<body>
    <!-- Document title with reprint option -->
    <div class="document-title">
        <?php if(isset($isReprint) && $isReprint): ?>
            COPY - <?php echo e(Str::title(str_replace('_', ' ', $document->type))); ?>

        <?php else: ?>
            <?php echo e(Str::title(str_replace('_', ' ', $document->type))); ?>

        <?php endif; ?>
    </div>

    <div class="header-container">
        <table class="info-row compact-info">
            <tr>
                <td class="info-left">
                    <span class="section-title">Company Information</span>
                    <div class="logo-full">
                        <?php if($company && $company->logo_path): ?>
                            <img src="file://<?php echo e(public_path($company->logo_path)); ?>" alt="Company Logo">
                        <?php endif; ?>
                    </div>
                    <div><span class="label">Name:</span><span class="value"><?php echo e($company->company_name); ?></span></div>
                    <div><span class="label">Address:</span><span class="address-value"><?php echo e($company->address); ?></span></div>
                    <div><span class="label">Tel No:</span><span class="value"><?php echo e($company->phone); ?></span></div>
                    <div><span class="label">Email:</span><span class="value"><?php echo e($company->email); ?></span></div>
                    <div><span class="label">VAT No:</span><span class="value"><?php echo e($company->vat_no); ?></span></div>
                    <div><span class="label">TIN No:</span><span class="value"><?php echo e($company->tax_id); ?></span></div>
                    <div><span class="label">Currency:</span><span class="value"><?php echo e($document->currency_code); ?></span></div>
                </td>
                <td class="info-right">
                    <span class="section-title">Customer Information</span>
                    <div><span class="label">Customer Name:</span><span class="value"><?php echo e($document->customer->customer_account ?? '—'); ?></span></div>
                    <div><span class="label">Customer Address:</span><span class="address-value"><?php echo e($document->customer->address ?? '—'); ?></span></div>
                    <div><span class="label">Customer Email:</span><span class="value"><?php echo e($document->customer->email ?? '—'); ?></span></div>
                    <div><span class="label">Customer Phone:</span><span class="value"><?php echo e($document->customer->contact_1 ?? '—'); ?></span></div>
                    <div><span class="label">Customer Contact Person:</span><span class="value"><?php echo e($document->contact_person); ?></span></div>
                    <div><span class="label">Customer City:</span><span class="value"><?php echo e($document->customer->city ?? '—'); ?></span></div>
                    <div><span class="label">Customer Province:</span><span class="value"><?php echo e($document->customer->province ?? '—'); ?></span></div>
                    <div><span class="label">Customer VAT:</span><span class="value"><?php echo e($document->customer->vat); ?></span></div>
                    <div><span class="label">Customer TIN:</span><span class="value"><?php echo e($document->customer->tin); ?></span></div>
                </td>
            </tr>
        </table>
    </div>

    <div class="doc-info">
        <div>
            <div><?php echo e(Str::title(str_replace('_', ' ', $document->type))); ?> #: <strong><?php echo e($document->document_number); ?></strong></div>
            <div>Order #: <strong><?php echo e($document->order_number); ?></strong></div>
            <?php if($document->type === 'invoice'): ?>
                <div>Due Date: <strong><?php echo e($document->due_date->format('d M Y')); ?></strong></div>
            <?php endif; ?>
        </div>
        <div>
            <div>Order Date: <strong><?php echo e($document->document_date->format('d M Y')); ?></strong></div>
            <div>Delivery Date: <strong><?php echo e($document->delivery_date->format('d M Y')); ?></strong></div>
            <?php if($document->type === 'invoice'): ?>
                <div>Delivery Note #: <strong>DN-<?php echo e(substr($document->document_number, 3)); ?></strong></div>
            <?php endif; ?>
        </div>
    </div>

    <!-- Items Table -->
    <table class="items-table">
        <thead>
            <tr>
                <th>HS Code</th>
                <th>Code</th>
                <th>Description</th>
                <th>Additional Description</th>
                <th>Qty</th>
                <th>UOM</th>
                <th>Price (Incl)</th>
                <th>Disc %</th>
                <th>Tax</th>
                <th>Total (Incl)</th>
            </tr>
        </thead>
        <tbody>
            <?php $__currentLoopData = $document->lines; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $line): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                <tr>
                    <td><?php echo e($line->hs_code); ?></td>
                    <td>
                        <?php if($line->module === 'GL'): ?>
                            <?php echo e(optional($line->account)->code); ?>

                        <?php else: ?>
                            <?php echo e(optional($line->item)->code); ?>

                        <?php endif; ?>
                    </td>
                    <td>
                        <?php if($line->module === 'GL'): ?>
                            <?php echo e(optional($line->account)->account_name); ?>

                        <?php else: ?>
                            <?php echo e(optional($line->item)->description1); ?>

                        <?php endif; ?>
                    </td>
                    <td><?php echo e($line->description); ?></td>
                    <td><?php echo e($line->confirmed_quantity); ?></td>
                    <td><?php echo e(optional($line->uom)->description ?? ''); ?></td>
                    <td><?php echo e(number_format($line->price, 2)); ?></td>
                    <td><?php echo e(number_format($line->discount_percent, 2)); ?>%</td>
                    <td><?php echo e(number_format($line->line_tax, 2)); ?></td>
                    <td><?php echo e(number_format($line->line_total, 2)); ?></td>
                </tr>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
        </tbody>
    </table>

    <!-- Totals & Signature -->
    <table class="info-row compact-info" style="margin-top:20px;">
        <tr>
            <td class="info-left">
                <div class="signature-block"><strong>Received by: ______________________________</strong></div>
                <div class="signature-block"><strong>Date: ______________________________</strong></div>
                <div class="signature-block"><strong>Signed: ______________________________</strong></div>
            </td>
            <td class="info-right" style="vertical-align:top;">
                <table style="width:auto; margin-left:auto; font-size:9pt;">
                    <tr>
                        <td><strong>Exclusive Total:</strong></td>
                        <td class="text-right">
                            <?php echo e(optional($document->currency)->symbol ?? $document->currency_code); ?>

                            <?php echo e(number_format($document->exclusive_total, 2)); ?>

                        </td>
                    </tr>
                    <tr>
                        <td><strong>Tax:</strong></td>
                        <td class="text-right">
                            <?php echo e(optional($document->currency)->symbol ?? $document->currency_code); ?>

                            <?php echo e(number_format($document->tax_amount, 2)); ?>

                        </td>
                    </tr>
                    <tr>
                        <td><strong>Discount:</strong></td>
                        <td class="text-right">
                            <?php echo e(optional($document->currency)->symbol ?? $document->currency_code); ?>

                            <?php echo e(number_format($document->discount_total, 2)); ?>

                        </td>
                    </tr>
                    <tr class="total-row">
                        <td><strong>Inclusive Total:</strong></td>
                        <td class="text-right">
                            <?php echo e(optional($document->currency)->symbol ?? $document->currency_code); ?>

                            <?php echo e(number_format($document->inclusive_total, 2)); ?>

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

    <hr style="border: none; border-bottom: 1px solid #1a365d; margin-top: 10px; margin-bottom: 20px;">

    <div class="notes-banking-row">
        <div class="notes">
            <div class="section-title">Terms &amp; Conditions</div>
            <div><?php echo e($document->customer->term ?? $document->notes ?? 'No terms provided'); ?></div>
            <div class="signature-block"><strong>Sales Representative: ______________________________</strong></div>
        </div>
        <div class="banking-details">
            <div class="section-title">Banking Details</div>
            <?php $bankDetails = $company->bank_details ?? []; ?>
            <?php $__empty_1 = true; $__currentLoopData = $bankDetails; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $bank): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                <div><span class="label">Bank Name:</span> <?php echo e($bank['bank_name'] ?? ''); ?></div>
                <div><span class="label">Account Name:</span> <?php echo e($bank['account_name'] ?? ''); ?></div>
                <div><span class="label">Account Number:</span> <?php echo e($bank['account_number'] ?? ''); ?></div>
                <div><span class="label">Branch:</span> <?php echo e($bank['branch'] ?? ''); ?></div>
                <br>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                <div>No banking details available</div>
            <?php endif; ?>
        </div>
    </div>

    <div class="bottom-footer">
        <table>
            <tr>
                <td>&copy; <?php echo e(date('Y')); ?> <?php echo e($company->company_name); ?>. All rights reserved.</td>
                <td class="text-right">Printed: <?php echo e(now()->setTimezone('Africa/Harare')->format('d M Y H:i')); ?></td>
            </tr>
        </table>
    </div>
</body>
</html>
<?php /**PATH H:\systems\Quanta\demo\resources\views/documents/pdf.blade.php ENDPATH**/ ?>