<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 class="resume">
    <!-- si es de vale o credito nadamas-->
    <% if sale.credit_note.present? %>
      <strong>VENTA A CRÉDITO / VALE</strong><br>
      Folio vale: <strong><%= sale.credit_note %></strong><br>
    <% else %>
      <strong>VENTA A CRÉDITO</strong><br>
    <% end %>
    Cliente: <strong> <%= sale.customer.nick_name %> </strong>
  </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 style="margin-top:0px;text-align:right">
    <% margin = 55 %>
    <table style="float:right;width:50%">
      <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, precision: 2, :unit => "") %></td>
        </tr>
        <% if sale.discount > 0 %>
          <% margin = margin += 20 %>
          <tr>
            <td width="30%">Descuento</td>
            <td width="15%" class="text-right">$</td>
            <td width="40%"><%= number_to_currency(sale.discount, precision: 2, :unit => "") %></td>
          </tr>
        <% end %>
        <% 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%"><strong>Total</strong></td>
          <td width="15%" class="text-right"><strong>$</strong></td>
          <td width="40%"><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">
    <div style="float:left;width:50%;margin-top:7px">
      <span>Vencimiento</span></br>
      <span><%= l(sale.created_at + sale.customer.time_limit.days, :format => '%d/%m/%y') %></span>
    </div>
    <table style="float:right;width:50%" class="text-right">
      <thead>
        <tr>
          <th></th>
          <th></th>
          <th></th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <td width="30%">Adeudo anterior</td>
          <td width="15%" class="text-right">$</td>
          <td width="40%" class="text-right">
            <%= number_to_currency(debt - sale.total, precision: 2, :unit => "") %>
          </td>
        </tr>
        <tr>
          <td width="30%"><strong>Adeudo actual</strong></td>
          <td width="15%" class="text-right"><strong>$</strong></td>
          <td width="40%" class="text-right">
            <strong><%= number_to_currency(debt, precision: 2, :unit => "") %></strong>
          </td>
        </tr>
      </tbody>
    </table>
  </div>
  <div style="margin-top:70px">
    <% if sale.get_pointsale.ticket_footer.blank? %>
      <%= simple_format(@pos_config.ticket_footer) %>
    <% else %>
      <%= simple_format(sale.get_pointsale.ticket_footer) %>
    <% end %>
  </div>
</div>
