<style>
	#products_table {
	  border-collapse: collapse;
	  page-break-inside:auto;
	}
	#products_table tr {
		page-break-inside:avoid; page-break-after:auto;
	}
</style>
<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>
  	</header>
	<h3 class="text-center">Corte de caja <%= pointsale.name %></h3>

	<div class="resume" style="border-bottom:1px solid black;">
		<strong>Apertura de caja:</strong>&nbsp;&nbsp;
			<%= l(cash_out.open_cash_register.created_at, :format => '%d/%m/%y %I:%M %p') %><br>
		<strong>Corte de caja:</strong>&nbsp;&nbsp;
			<%= l(cash_out.created_at, :format => '%d/%m/%y %I:%M %p') %><br>
		<strong>Caja:</strong>&nbsp;&nbsp;
			<%= cash_out.open_cash_register.cash_register.name %><br>
		<strong>Realizó:</strong>&nbsp;&nbsp;
			<%= cash_out.user.first_name %><br>
		<strong>Recibió:</strong>&nbsp;&nbsp;
			<%= cash_out.received_by.first_name %><br>
		<strong>Articulos:</strong>&nbsp;&nbsp;
			<%= cash_out.open_cash_register.products.count %>
		<% if cash_out.observations.present? %>
			<br> <strong>Observaciones:</strong>&nbsp;&nbsp;
				<%= cash_out.observations %>
		<% end %>
	</div>

	<div style="border-bottom:1px solid black; margin-top:10px">
		<table cellspacing="0" width="100%">
			<thead>
				<tr>
					<th style="text-align:left">Fondo anterior</th>
					<th style="text-align:left">Efectivo en caja</th>
					<th style="text-align:left">Retiro</th>
					<th style="text-align:center">Fondo</th>
				</tr>
			</thead>
			<tbody>
				<tr>
					<td style="text-align:left">
						<%= number_to_currency(initial_cash, precision: 2) %>
					</td>
					<td style="text-align:left">
						<%= number_to_currency(cash_out.physical_cash, precision: 2) %>
					</td>
					<td style="text-align:left">
						<%= number_to_currency(cash_out.received_cash, precision: 2) %>
					</td>
					<td style="text-align:center">
						<%= number_to_currency(cash_out.cash_fund, precision: 2) %>
					</td>
				</tr>
			</tbody>
		</table>
	</div>

	<div style="border-bottom:1px solid black; margin-top:10px">
		<table cellspacing="0" width="100%">
			<thead>
				<tr>
					<th style="text-align:left"></th>
					<th style="text-align:center"></th>
					<th style="text-align:center"></th>
				</tr>
			</thead>
			<tbody>
				<tr>
					<td style="text-align:left"><strong>Ventas a contado</strong></td>
					<td style="text-align:center"><strong>Abonos a crédito</strong></td>
					<td style="text-align:center"><strong>Apartados</strong></td>
				</tr>
				<tr>
					<td style="text-align:left">
						<%= number_to_currency(sales_total, precision: 2) %>
					</td>
					<td style="text-align:center">
						<%= number_to_currency(credit_sales, precision: 2) %>
					</td>
					<td style="text-align:center">
						<%= number_to_currency(reserved_sales, precision: 2) %>
					</td>
				</tr>
			</tbody>
		</table>
	</div>
	<div style="border-bottom:1px solid black; margin-top:10px">
		<h4 style="margin-top:5px;margin-bottom:5px">RESUMEN</h4>
		<% cash_out.cash_out_details.each do | detail | %>
			<span style="text-decoration:underline;margin-bottom:5px"><%= detail.payment_method.method.upcase %></span>
			<table cellspacing="0" width="100%">
				<thead>
					<tr>
						<th style="text-align:left">Ingresos</th>
						<th style="text-align:center">Egresos</th>
						<th style="text-align:right">Total</th>
					</tr>
				</thead>
				<tbody>
					<tr>
						<td style="text-align:left">
							<%= number_to_currency(detail.incoming, precision: 2) %>
						</td>
						<td style="text-align:center">
							<%= number_to_currency(detail.outgoing, precision: 2) %>
						</td>
						<td style="text-align:right">
							<%= number_to_currency(detail.total, precision: 2) %>
						</td>
					</tr>
				</tbody>
			</table>
		<% end %>
	</div>
	<div class="products" style="border:0px">
		<h4 style="margin-top:5px;margin-bottom:5px">SALIDA DE MERCANCÍA</h4>
		<table cellspacing="0" id="products_table">
			<thead>
				<tr>
					<th></th>
					<th></th>
					<th></th>
				</tr>
			</thead>
			<tbody>
				<% @details.each_with_index do |detail, key| %>
					<% if  @details[key -1].present?
						last_one_category = @details[key -1]['parent'].present? ? @details[key -1]['parent'] : @details[key -1]['category'] %>
					<% else
						last_one_category = ""
					%>
					<% end %>
					<% current_category = detail['parent'].present? ? detail['parent'] : detail['category']%>
					<% if last_one_category != current_category %>
						<tr style="margin-top:3px;margin-bottom:10px">
							<td colspan="3"> <strong> <%= current_category %> </strong> </td>
						</tr>
					<% end %>
					<tr>
						<td valign="bottom">
							<%= detail['quantity'] %>
						</td>
						<td style="text-align:center">
							<%= truncate(detail['product_name'], :length => 30, :separator => ' ', :omission => '') %> <br>
							<%= truncate(Product.find(detail['product_id']).display_attributes_receipt.downcase, :length => 30, :separator => ' ', :omission => '') %>
						</td>
						<td style="text-align:right"  valign="center">
							<strong><%= number_to_currency(detail['total'], precision: 2) %></strong>
						</td>
					</tr>
					<tr style="<%= 'border-bottom:1px solid black;font-size:10px' if detail["discount"] == 0%>">
						<td> </td>
						<td style="text-align:center">
							Precio de venta unitario (<%= number_to_currency(detail["price_sale"], precision: 2) %>)
						</td>
						<td style="text-align:right">
						 	<%= number_to_currency(detail["total_without_discount"], precision: 2) %>
						</td>
					</tr>
					<% if detail["discount"] != 0 %>
						<tr style="border-bottom:1px solid black;font-size:10px">
							<td> </td>
							<td style="text-align:center">Descuento acumulado:</td>
							<td style="text-align:right">
							 	- <%= number_to_currency(detail["discount"], precision: 2) %>
							</td>
						</tr>
					<% end %>
				<% end %>
			</tbody>
		</table>
	</div>
	<!-- egresos -->
	<% if expenses.present? %>
		<div class="products" style="border-bottom:1px solid black">
			<h4 style="margin-top:5px;margin-bottom:5px">EGRESOS</h4>
			<table cellspacing="0" style="border-collapse:collapse">
				<thead>
					<tr>
						<td></td>
						<td></td>
					</tr>
				</thead>
				<tbody>
					<% expenses.each do |expense| %>
						<tr>
							<td style="text-align:left">
				                <strong> <%= expense.expensesconcept.name %></strong> <br>
				                <%= expense.observations %>
							</td>
							<td style="text-align:right">
								<%= number_to_currency(expense.quantity, precision: 2) %>
							</td>
						</tr>
					<% end %>
				</tbody>
			</table>
		</div>
	<% end %>
	<div style="margin-top:5px;">
		<span style="text-decoration:underline">Nota:</span> Los productos que se muestran en el listado de salidas de mercancía, son productos de <span style="font-style:italic;"> ventas, apartados y creditos </span> que fueron registrados durante este corte.
	</div>
</div>




