<?php echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n"; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="<?php echo $direction; ?>" lang="<?php echo $language; ?>" xml:lang="<?php echo $language; ?>">
<head>
<title><?php echo $title; ?></title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/html2pdf.js/0.10.2/html2pdf.bundle.min.js" integrity="sha512-MpDFIChbcXl2QgipQrt1VcPHMldRILetapBl5MPCA9Y8r7qvlwx1/Mc9hNTzY+kS5kX6PdoDq41ws1HiVNLdZA==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script defer>
document.addEventListener('DOMContentLoaded', (event) => {
  
const btnGenerator = document.querySelector('#generate-pdf')

btnGenerator.addEventListener('click', () => {

const content = document.querySelector('#content')

const option = {

margin: [10, 10, 10, 10],
filename: "Relatorio.pdf",
html2pdf: {scale: 2},
jsPDF: {unit: "mm", format: "a4", orientation:"portrait"}

}

html2pdf().set(option).from(content).save();


})})

</script>
<base href="<?php echo $base; ?>" />
<link rel="stylesheet" href = "https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.6.0/css/all.min.css">
<link rel="stylesheet" type="text/css" href="view/stylesheet/gerarPdf.css" />
</head>
<body>
<?php foreach ($orders as $order) { ?>
<div id='content' style="page-break-after: always;">
<div class= 'border-box'> 
  <button id='generate-pdf' class="fa-solid fa-download" title="Exportar em PDF"></button>
  <table class="store">
  <h1><?php echo $order['store_name']; ?></h1>
    <tr>
      <td><br />
       <strong> Endereço: </strong><?php echo $order['store_address']; ?><br />
      <strong> <?php echo $text_telephone; ?> </strong><?php echo $order['store_telephone']; ?><br />
        <strong>Email: </strong><?php echo $order['store_email']; ?><br />
       <td align="right" valign="bottom"><table>
          <tr>
            <td><b><?php echo $text_date_added; ?></b></td>
            <td><?php echo $order['date_added']; ?></td>
          </tr>
          <tr>
            <td><b><?php echo $text_order_id; ?></b></td>
            <td><?php echo $order['order_id']; ?></td>
          </tr>
          <tr>
            <td><b><?php echo $text_payment_method; ?></b></td>
            <td><?php echo $order['payment_method']; ?></td>
          </tr>
          <?php if ($order['shipping_method']) { ?>
          <tr>
            <td><b><?php echo $text_shipping_method; ?></b></td>
            <td><?php echo $order['shipping_method']; ?></td>
          </tr>
          <?php } ?>
        </table></td>
      
    </tr>
    
  </table>
  </div>
  <table class="address">
    <tr class="heading">
      <td width="50%"><b><?php echo $text_to; ?></b></td>
      <td width="50%"><b><?php echo $shipping_pickup ? $text_pickup : $text_ship_to; ?></b></td>
    </tr>

    <tr>
    <?php
    if($this->config->get('listapresente_status') && $order['lista'] ){ ?>
       <td><?php echo $order['shipping_address']; ?></td>
       <td><?php echo $order['shipping_address']; ?></td>
    <?php }else{ ?>
    
        <td><?php echo $order['payment_address']; ?><br/>
            <?php echo $order['email']; ?><br/>
            <?php if($order['telephone']){
              echo $order['telephone']."<br/>";
              }
            ?>
            <?php if($order['celular']){
              echo $order['celular']."<br/>";
              }
            ?>
            <?php if ($order['payment_company_id']) { ?>
            <br/>
            <br/>
            <?php echo $text_company_id; ?> <?php echo $order['payment_company_id']; ?>
            <?php } ?>
        </td>
        <?php 
        if($this->data['shipping_pickup'] ){ ?>
          <td><?php echo $this->data['pickup_address'].','.$this->data['pickup_number'].','.$this->data['pickup_neighborhood'].','; ?> <br/>
              <?php echo $this->data['pickup_neighborhood'].','; ?> <br/>
              <?php echo $this->data['pickup_city'].','; ?> <br/>
              <?php echo $this->data['pickup_zone'].','; ?> <br/>
              <?php echo $this->data['pickup_postcode']; ?>
          </td>
        <?php }else{ ?>
          <td><?php echo $order['shipping_address']; ?></td>
        <?php } ?>
   <?php } ?>


    </tr>
  </table>
  <table class="product">
    <tr class="heading">
      <td><b><?php echo $column_product; ?></b></td>
      <td><b><?php echo $column_model; ?></b></td>
      <?php if ($futuragrade_status) { ?>
        <td><b>Espeficicações</td>
      <?php } ?>
      <td align="right"><b><?php echo $column_quantity; ?></b></td>
      <td align="right"><b><?php echo $column_price; ?></b></td>
      <td align="right"><b><?php echo $column_total; ?></b></td>
    </tr>
    <?php foreach ($order['product'] as $product) { ?>
    <tr>
      <td>
       
    <div class='product-name'>
      <?php if (isset($product['image'])) { ?>
        <img src="<?php echo $product['image']; ?>" width="40" height="40" class="border-gray visible-block">
    <?php } ?>
      <?php echo $product['name']; ?>
        <?php foreach ($product['option'] as $option) { ?>
        <br />
        &nbsp;<small> - <?php echo $option['name']; ?>: <?php echo $option['value']; ?></small>
        <?php } ?></td>
        </div>
      <td><?php echo $product['model']; ?></td>

      <?php if ($futuragrade_status) { ?>
        <td>
          <?php if (!empty($product['color_description'])){ ?>
          <?php echo 'Cor: '.$product['color_description']; ?>
          <?php } ?>
          <?php if (!empty($product['size_description'])){ ?>
          <br/>
          <?php echo 'Tamanho: '.$product['size_description']; ?>
          <?php } ?>
          <?php if (!empty($product['specification_description'])){ ?>
          <br/>
          <?php echo 'Especificação: '.$product['specification_description']; ?>
          <?php } ?>
        </td>
      <?php } ?>

      <td align="right"><?php echo $product['quantity']; ?></td>
      <td align="right"><?php echo $product['price']; ?></td>
      <td align="right"><?php echo $product['total']; ?></td>
    </tr>
    <?php } ?>
    <?php foreach ($order['voucher'] as $voucher) { ?>
    <tr>
      <td align="left"><?php echo $voucher['description']; ?></td>
      <td align="left"></td>
      <td align="right">1</td>
      <td align="right"><?php echo $voucher['amount']; ?></td>
      <td align="right"><?php echo $voucher['amount']; ?></td>
    </tr>
    <?php } ?>
    <?php foreach ($order['total'] as $total) { ?>
    <tr>
      <?php if ($futuragrade_status) { ?>
        <td align="right" colspan="5"><b><?php echo $total['title']; ?>:</b></td>
      <?php }else{ ?>
        <td align="right" colspan="4"><b><?php echo $total['title']; ?>:</b></td>
      <?php } ?>
      <td align="right"><?php echo $total['text']; ?></td>
    </tr>
    <?php } ?>
  </table>
  <?php if ($order['comment']) { ?>
  <table class="comment">
    <tr class="heading">
      <td><b><?php echo $column_comment; ?></b></td>
    </tr>
    <tr>
      <td><?php echo $order['comment']; ?></td>
    </tr>
  </table>
  <?php } ?>
</div>
<?php } ?>
</body>
</html>