<!DOCTYPE html>
<html lang="es">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="<?= site_url('themes/vuexy/css/font-pdf.css') ?>">
    <link rel="stylesheet" href="<?= site_url('themes/vuexy/css/pdf.albaran.css') ?>">
    <style>
        @page {
            margin: 10px;
        }

        body {
            margin: 10px;
        }
    </style>

</head>

<body>
    <main class="body-class">
        <table class="logo">
            <tr>
                <td class="logo">
                    <img
                        src="data:image/jpeg;base64,[encoded data, 95788 characters]" />
                </td>
            </tr>
        </table>

        <?php
        $mostrarPrecios = $albaran->mostrar_precios == 1;
        ?>


        <table class="datos-albaran">
            <thead>
                <tr>
                    <th class="intro_num_albaran">
                        Nº ALBARÁN:
                    </th>
                    <th class="num_albaran">
                        <?= $albaran->id ?>
                    </th>
                    <th class="intro_num_albaran">
                    </th>
                    <th class="num_pedido">
                    </th>
                    <th class="intro_fecha">
                        FECHA:
                    </th>
                    <th class="text-start fecha">
                        <?= $albaran->fecha_albaran ? $albaran->fecha_albaran : date('d-m-Y') ?>
                    </th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td class="intro_cliente" colspan="6">Cliente: <?= $albaran->cliente ?></td>
                </tr>
                <tr>
                    <td class="att" colspan="6">Att: <?= $albaran->att ?></td>
                </tr>
                <tr>
                    <td class="direccion" colspan="6"><?= $albaran->direccion ?></td>
                </tr>
                <tr>
                </tr>
                <tr>
                    <td colspan="6">Cajas: <?= $albaran->cajas ?></td>
                </tr>
            </tbody>
        </table>

        <table class="table table-striped lineas">
            <thead>
                <tr class="head-lineas">
                    <th class="text-center num_unidades">Nº Unid.</th>
                    <th class="concepto">Pedido</th>
                    <th class="concepto">Título</th>
                    <th class="concepto">ISBN</th>
                    <th class="concepto">Ref. Cliente</th>
                    <?php if ($mostrarPrecios): ?>
                        <th class="precio_unidad">€/ud.</th>
                        <th class="subtotal">Subtotal</th>
                    <?php endif; ?>
                </tr>
            </thead>
            <tbody>
                <?php
                $total = 0;
                $total_precio = 0;
                foreach ($albaranLineas as $linea):
                    ?>

                    <?php
                    $total += 1;
                    $total_precio += $linea->total;
                    ?>
                    <tr>
                        <td class="text-center num_unidades">
                            <?= $linea->unidades ?>
                        </td>
                        <td class="text-center">
                            <?= $linea->pedido ?>
                        </td>
                        <td>
                            <div><?= $linea->titulo ?></div>
                        </td>
                        <td>
                            <div><?= $linea->isbn ?></div>
                        </td>
                        <td>
                            <div><?= $linea->ref_cliente ?></div>
                        </td>
                        <?php if ($mostrarPrecios): ?>
                            <td class="precio_unidad">
                                <?php if (!str_contains($linea->titulo, "IVA")): ?>
                                    <div><?= number_format($linea->precio_unidad, 4, ',', '.') ?></div>
                                <?php endif; ?>
                            </td>
                            <td class="subtotal">
                                <div><?= number_format($linea->total, 2, ',', '.') ?></div>
                            </td>
                        <?php endif; ?>
                    </tr>
                <?php endforeach; ?>

                <?php if ($total < 5): ?>
                    <?php for ($i = $total; $i < 7; $i++): ?>
                        <tr>
                            <td class="num_unidades">
                                <div></div>
                            </td>
                            <td>
                                <div></div>
                            </td>
                            <td>
                                <div></div>
                            </td>
                            <td>
                                <div></div>
                            </td>
                            <td>
                                <div></div>
                            </td>
                            <?php if ($mostrarPrecios): ?>
                                <td class="precio_unidad">
                                    <div></div>
                                </td>
                                <td class="subtotal">
                                    <div></div>
                                </td>
                            <?php endif; ?>
                        </tr>
                    <?php endfor; ?>
                <?php endif; ?>
            </tbody>
        </table>

        <table style="padding: 5px" class="total">
            <tr>
                <td class="intro_recibi">
                    RECIBÍ
                </td>
                <?php if ($mostrarPrecios): ?>
                    <td class="intro_total">
                        TOTAL
                    </td>
                    <td class="subtotal">
                        <?= ($total_precio) ?>
                    </td>
                <?php endif; ?>
            </tr>
        </table>

    </main>
</body>

</html>