<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Facture <?php echo e($invoice->number); ?></title>
    <style>
        body {
            font-family: Arial, sans-serif;
            font-size: 12px;
            line-height: 1.4;
            color: #333;
        }
        .header {
            border-bottom: 2px solid #007bff;
            padding-bottom: 20px;
            margin-bottom: 30px;
        }
        .company-info {
            float: left;
            width: 50%;
        }
        .invoice-info {
            float: right;
            width: 45%;
            text-align: right;
        }
        .client-info {
            margin: 30px 0;
            clear: both;
        }
        .invoice-details {
            width: 100%;
            border-collapse: collapse;
            margin: 20px 0;
        }
        .invoice-details th,
        .invoice-details td {
            border: 1px solid #ddd;
            padding: 8px;
            text-align: left;
        }
        .invoice-details th {
            background-color: #f8f9fa;
            font-weight: bold;
        }
        .text-right {
            text-align: right;
        }
        .text-center {
            text-align: center;
        }
        .total-section {
            float: right;
            width: 300px;
            margin-top: 20px;
        }
        .total-row {
            display: flex;
            justify-content: space-between;
            padding: 5px 0;
        }
        .total-row.final {
            border-top: 2px solid #333;
            font-weight: bold;
            font-size: 14px;
        }
        .notes {
            margin-top: 40px;
            clear: both;
        }
        .footer {
            margin-top: 50px;
            padding-top: 20px;
            border-top: 1px solid #ddd;
            clear: both;
            font-size: 11px;
            color: #666;
        }
        .footer-fixed {
            position: fixed;
            bottom: 0;
            left: 0;
            right: 0;
            height: 60px;
            background: white;
            border-top: 1px solid #ddd;
            padding: 10px 20px;
            font-size: 10px;
            color: #666;
            z-index: 1000;
        }
        @page {
            margin-bottom: 80px;
        }
        body {
            margin-bottom: 80px;
        }
        .clearfix::after {
            content: "";
            display: table;
            clear: both;
        }
    </style>
</head>
<body>
    <div class="header clearfix">
        <div class="company-info">
            <p>
                <strong><?php echo e($company ? $company->name : 'Mon Entreprise'); ?></strong><br>
                <?php if($company && $company->address): ?><?php echo e($company->address); ?><?php else: ?> Ville <?php endif; ?><br>
                <?php if($company && $company->phone): ?><?php echo e($company->phone); ?><?php else: ?> Téléphone <?php endif; ?><br>
                <strong>Facture N°:</strong> <?php echo e($invoice->number); ?><br>
                <strong>Date facture:</strong> <?php echo e($invoice->date->format('d/m/Y')); ?>

            </p>
        </div>
        <div class="invoice-info">
            <p>
                <strong><?php echo e($invoice->type === 'sale' ? 'Facturé à:' : 'Facturé par:'); ?></strong><br>
                <strong><?php echo e($invoice->client ? $invoice->client->name : $invoice->supplier->name); ?></strong><br>
                <?php echo e($invoice->client ? $invoice->client->address : $invoice->supplier->address); ?><br>
                <?php if($invoice->client): ?>
                    <?php if($invoice->client->ice): ?>ICE: <?php echo e($invoice->client->ice); ?><br><?php endif; ?>
                    <?php if($invoice->client->phone): ?>Tél: <?php echo e($invoice->client->phone); ?><br><?php endif; ?>
                    <?php if($invoice->client->email): ?>Email: <?php echo e($invoice->client->email); ?><?php endif; ?>
                <?php else: ?>
                    <?php if($invoice->supplier->ice): ?>ICE: <?php echo e($invoice->supplier->ice); ?><br><?php endif; ?>
                    <?php if($invoice->supplier->phone): ?>Tél: <?php echo e($invoice->supplier->phone); ?><br><?php endif; ?>
                    <?php if($invoice->supplier->email): ?>Email: <?php echo e($invoice->supplier->email); ?><?php endif; ?>
                <?php endif; ?>
            </p>
        </div>
    </div>

    <table class="invoice-details">
        <thead>
            <tr>
                <th>Produit/Service</th>
                <th>Description</th>
                <th class="text-center">Qté</th>
                <th class="text-right">Prix unitaire</th>
                <th class="text-center">TVA</th>
                <th class="text-right">Total HT</th>
                <th class="text-right">Total TTC</th>
            </tr>
        </thead>
        <tbody>
            <?php $__currentLoopData = $invoice->items; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
            <tr>
                <td><?php echo e($item->product_name); ?></td>
                <td><?php echo e($item->description); ?></td>
                <td class="text-center"><?php echo e($item->quantity); ?> <?php echo e($item->unit); ?></td>
                <td class="text-right"><?php echo e(number_format($item->unit_price, 2)); ?> MAD</td>
                <td class="text-center"><?php echo e($item->vat_rate); ?>%</td>
                <td class="text-right"><?php echo e(number_format($item->total_ht, 2)); ?> MAD</td>
                <td class="text-right"><?php echo e(number_format($item->total_ttc, 2)); ?> MAD</td>
            </tr>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
        </tbody>
    </table>

    <div class="total-section">
        <div class="total-row">
            <span>Sous-total HT:</span>
            <span><?php echo e(number_format($invoice->subtotal_ht, 2)); ?> MAD</span>
        </div>
        <div class="total-row">
            <span>TVA:</span>
            <span><?php echo e(number_format($invoice->total_vat, 2)); ?> MAD</span>
        </div>
        <div class="total-row final">
            <span>Total TTC:</span>
            <span><?php echo e(number_format($invoice->total_ttc, 2)); ?> MAD</span>
        </div>
        <?php if($invoice->paid_amount > 0): ?>
        <div class="total-row">
            <span>Montant payé:</span>
            <span><?php echo e(number_format($invoice->paid_amount, 2)); ?> MAD</span>
        </div>
        <div class="total-row">
            <span>Reste à payer:</span>
            <span><?php echo e(number_format($invoice->remaining_amount, 2)); ?> MAD</span>
        </div>
        <?php endif; ?>
    </div>

    <div class="amount-in-words" style="margin-top: 20px; clear: both; border: 1px solid #ddd; padding: 10px; background-color: #f9f9f9;">
        <strong>ARRÊTÉE LA PRÉSENTE FACTURE À LA SOMME DE :</strong><br>
        <strong><?php echo e(\App\Helpers\NumberToWords::convert($invoice->total_ttc)); ?></strong>
    </div>

    <?php if($invoice->notes || $invoice->terms): ?>
    <div class="notes">
        <?php if($invoice->notes): ?>
        <h4>Notes:</h4>
        <p><?php echo e($invoice->notes); ?></p>
        <?php endif; ?>
        
        <?php if($invoice->terms): ?>
        <h4>Conditions:</h4>
        <p><?php echo e($invoice->terms); ?></p>
        <?php endif; ?>
    </div>
    <?php endif; ?>

    <?php if($company && $company->footer_template): ?>
    <div class="footer-fixed">
        <?php echo nl2br(e($company->footer_template)); ?>

    </div>
    <?php endif; ?>
</body>
</html><?php /**PATH /Users/macbook/Documents/gstock/backend/resources/views/invoices/pdf.blade.php ENDPATH**/ ?>