<div class='pdf-body'>
  <header class='document-header'>
    <h1 class='text-center'>
      <% if pointsale.img_pointsale? %>
        <%= wicked_pdf_image_tag_for_public(pointsale.img_pointsale_url, :style => "margin-top:10px") %>
      <% elsif @pos_config.ticket_img? %>
        <%= wicked_pdf_image_tag_for_public(@pos_config.ticket_img_url, :style => "margin-top:10px") %>
      <% end %>
    </h1>
    <p>
      <% if pointsale.notes.blank? %>
        <%= simple_format(@pos_config.ticket_description, class: 'text-center') %>
      <% else %>
        <%= simple_format(pointsale.notes, class: 'text-center')  %>
      <% end %>
    </p>
  </header>
  <div class="resume">
    <%= l(products_return.created_at, :format => '%d/%m/%y %I:%M %p') %> &nbsp; | &nbsp; <%= products_return.return_code %> &nbsp; | &nbsp; <%= products_return.user.first_name.upcase %>
  </div>
  <div style="margin-top:5px">
    <h3 style="text-align:center">Ticket de cambio</h3>
    Venta: <%= products_return.sale.sale_code %> <br>
  </div>
  <!-- productos devueltos -->
  <div class="products">
    <h4 style="margin-top:5px;margin-bottom:5px">PRODUCTOS CAMBIADOS</h4>
    <table cellspacing="0">
      <thead>
        <tr>
          <th style="text-align:left;font-weight:normal">Cantidad</th>
          <th style="text-align:right;font-weight:normal">Importe</th>
        </tr>
      </thead>
      <tbody style="border-top:1px solid black">
        <% products_return.products_return_ins.each do |detail| %>
          <tr>
            <td colspan="2">
              <%= truncate(detail.product.name, :length => 30, :separator => ' ', :omission => '') %> &nbsp; <%= truncate(detail.product.display_attributes_receipt, :length => 20, :separator => ' ', :omission => '') %>
            </td>
          </tr>
          <tr>
            <td>
              <%= detail.quantity.round %>
            </td>
            <td style="text-align:right">
              <%= number_to_currency(detail.amount, precision: 2) %>
            </td>
          </tr>
        <% end %>
        <tr>
          <td colspan="2" style="text-align:right;font-size:14px">Total de productos cambiados&nbsp; <strong><%= number_to_currency(products_return.returned_amount, precision: 2) %></strong></td>
        </tr>
      </tbody>
    </table>
  </div>
  <!-- productos nuevos -->
  <div class="products">
    <h4 style="margin-top:5px;margin-bottom:5px">PRODUCTOS SELECCIONADOS</h4>
    <table cellspacing="0">
      <thead>
        <tr>
          <th style="text-align:left;font-weight:normal">Cantidad</th>
          <th style="text-align:center;font-weight:normal">Precio</th>
          <th style="text-align:center;font-weight:normal">Desc.</th>
          <th style="text-align:right;font-weight:normal">Importe</th>
        </tr>
      </thead>
      <tbody style="border-top:1px solid black">
        <% products_return.products_return_outs.each do |detail| %>
          <tr>
            <td colspan="4">
              <%= truncate(detail.product.name, :length => 30, :separator => ' ', :omission => '') %> &nbsp; <%= truncate(detail.product.display_attributes_receipt, :length => 20, :separator => ' ', :omission => '') %>
            </td>
          </tr>
          <tr>
            <td>
              <%= detail.quantity.round %>
            </td>
            <td style="text-align:center">
              <%= number_to_currency(detail.product.get_price_sale(pointsale.id), precision: 2) %>
            </td>
            <td style="text-align:center">
              <%= number_to_currency(0, precision: 2) %>
            </td>
            <td style="text-align:right">
              <%= number_to_currency(detail.amount, precision: 2) %>
            </td>
          </tr>
        <% end %>
        <tr>
          <td colspan="4" style="text-align:right;font-size:14px">Total de productos seleccionados&nbsp; <strong><%= number_to_currency(products_return.new_amount, precision: 2) %></strong></td>
        </tr>
      </tbody>
    </table>
  </div>


  <!-- totales -->
  <div class="totals text-right">
    <% margin = 40 %>
    <table>
      <thead>
        <tr>
          <th></th>
          <th></th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <td width="30%" style="font-size:15px"><strong>A pagar</strong></td>
          <td width="40%" style="font-size:15px" ><strong><%= number_to_currency(products_return.difference_amount, precision: 2) %></strong></td>
        </tr>
      </tbody>
    </table>
  </div>
  <!-- pagos -->
  <div style="margin-top:<%=margin%>px; border-top:1px dotted black" class="totals text-right">
    <table cellspacing="0">
      <thead>
        <tr>
          <th></th>
          <th></th>
          <th></th>
        </tr>
      </thead>
      <tbody>
        <% marginFooter = 20 %>
        <% products_return.cash_registers_moves.each do |move| %>
          <tr class="text-center" style="text-decoration:underline;">
            <td><%= move.payment_method.method %> </td>
            <td></td>
            <td></td>
          </tr>
          <% if move.payment_method.isCash? %>
            <% marginFooter += 80 %>
            <tr class="text-left">
              <td> </td>
              <td> Recibido: </td>
              <td> <%= number_to_currency(move.received, precision: 2) %></td>
            </tr>
            <tr class="text-left">
              <td> </td>
              <td><strong> Pagó: </strong></td>
              <td><strong> <%= number_to_currency(move.quantity, precision: 2) %></strong></td>
            </tr>
            <tr class="text-left">
              <td> </td>
              <td> Cambio: </td>
              <td> <%= number_to_currency(move.change, precision: 2) %></td>
            </tr>
          <% else %>
            <% marginFooter += 60 %>
              <tr class="text-left">
                <td> </td>
                <td><strong> Pagó: </strong></td>
                <td><strong> <%= number_to_currency(move.quantity, precision: 2) %></strong></td>
              </tr>
              <tr class="text-left">
                <td> </td>
                <td> tarjeta nº: </td>
                <td> <%= move.cardnumber %></td>
              </tr>
          <% end %>
        <% end %>
      </tbody>
    </table>
  </div>
  <!-- footer -->
  <div style="margin-top:<%=marginFooter%>px">
    <% if pointsale.ticket_footer.blank? %>
      <%= simple_format(@pos_config.ticket_footer) %>
    <% else %>
      <%= simple_format(pointsale.ticket_footer) %>
    <% end %>
  </div>
</div>
