<div class='pdf-body'>
  <header class='document-header'>
    <h1 class='text-center'>
      <% pointsale = sale.get_pointsale %>
      <% 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 sale.get_pointsale.notes.blank? %>
        <%= simple_format(@pos_config.ticket_description, class: 'text-center') %>
      <% else %>
        <%= simple_format(sale.get_pointsale.notes, class: 'text-center')  %>
      <% end %>
    </p>
  </header>
  <div class="resume">
    <%= l(sale.created_at, :format => '%d/%m/%y %I:%M %p') %> &nbsp; | &nbsp; <%= sale.sale_code %> &nbsp; | &nbsp; <%= sale.seller.name %>
  </div>
  <div style="margin-top:5px">
    <strong>VENTA AL CONTADO</strong><br>
  </div>
  <div class="products">
    <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">
        <% sale.sales_details.each_with_index do |detail, key| %>
          <tr>
            <td colspan="3">
              <%= 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.unit_price, precision: 2) %>
            </td>
            <td style="text-align:center">
              <%= number_to_currency(detail.discount, precision: 2) %>
            </td>
            <td style="text-align:right">
              <%= number_to_currency(((detail.unit_price * detail.quantity) - detail.discount), precision: 2) %>
            </td>
          </tr>
        <% end %>
      </tbody>
    </table>
  </div>
  <div class="totals text-right">
    <% margin = 60 %>
    <table>
      <thead>
        <tr>
          <th></th>
          <th></th>
          <th></th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <td width="30%">Subtotal</td>
          <td width="15%" class="text-right">$</td>
          <td width="40%"><%= number_to_currency(sale.amount - sale.discount, precision: 2, :unit => "") %></td>
        </tr>
        <% if sale.tax > 0 %>
          <% margin = margin += 20 %>
          <tr>
            <td width="30%">IVA</td>
            <td width="15%" class="text-right">$</td>
            <td width="40%"><%= number_to_currency(sale.tax, precision: 2, :unit => "") %></td>
          </tr>
        <% end %>
        <tr>
          <td width="30%" style="font-size:15px"><strong>Total</strong></td>
          <td width="15%" style="font-size:15px" class="text-right">$</td>
          <td width="40%" style="font-size:15px" ><strong><%= number_to_currency(sale.total, precision: 2, :unit => "") %></strong></td>
        </tr>
      </tbody>
    </table>
  </div>
  <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 %>
        <% sale.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>
  <div style="margin-top:<%=marginFooter%>px">
    <% if sale.get_pointsale.ticket_footer.blank? %>
      <%= simple_format(@pos_config.ticket_footer) %>
    <% else %>
      <%= simple_format(sale.get_pointsale.ticket_footer) %>
    <% end %>
  </div>
</div>
