<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 style="margin-top:10px">
      <% 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(Date.today, :format => '%d/%m/%y %I:%M %p') %> &nbsp; | &nbsp; <%= current_user.first_name.upcase %> &nbsp; | &nbsp; <%= sale.sale_code %> &nbsp;
  </div>
  <div style="margin-top:5px">
    <% if sale.reserve_debt <= 0 %>
      <strong> LIQUIDACIÓN DE APARTADO </strong><br>
    <% else %>
      <strong> ABONO A APARTADO </strong><br>
    <% end %>
    Cliente: <strong> <%= sale.customer.nick_name %> </strong><br>
    Vencimiento: <strong><%= l(sale.expiration_date, :format => '%d/%m/%y') %></strong>
  </div>

  <div style="margin-top:0px;text-align:right;display:block">
    <table style="float:right;width:50%">
      <thead>
        <tr>
          <th></th>
          <th></th>
          <th></th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <td width="30%">Saldo anterior</td>
          <td width="15%" class="text-right">$</td>
          <td width="40%"><%= number_to_currency(sale.reserve_debt + new_payments_quantity, precision: 2, :unit => "") %></td>
        </tr>
        <tr>
          <td width="30%">Abono a apartado</td>
          <td width="15%" class="text-right">$</td>
          <td width="40%"><%= number_to_currency(new_payments_quantity, precision: 2, :unit => "") %></td>
        </tr>
        <tr>
          <td width="30%">Saldo actual</td>
          <td width="15%" class="text-right">$</td>
          <td width="40%"><%= number_to_currency(sale.reserve_debt, precision: 2, :unit => "") %></td>
        </tr>
      </tbody>
    </table>
  </div>
  <div style="margin-top:120px; 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 %>
        <% 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>

