<!-- BEGIN CONTAINER -->
<div class="page-container">
	<!-- BEGIN CONTENT -->
	<div class="page-content-wrapper">
		<!-- BEGIN CONTENT BODY -->
		<!-- BEGIN PAGE HEAD-->
		<div class="page-head">
			<div class="container-fluid">
				<!-- BEGIN PAGE TITLE -->
				<div class="page-title">
					<h1>Venta </h1>
				</div>
				<!-- END PAGE TITLE -->
			</div>
		</div>
		<!-- END PAGE HEAD-->
		<!-- BEGIN PAGE CONTENT BODY -->
		<div class="page-content">
			<div class="container-fluid">
				<div class="pull-right margin-bottom-10 ">
					<% if @sale.reserved? %>
						<%= link_to  sales_reserved_path(:filter => @filter, :current_page => @current_page), {:class=>"fr-space btn blue-hoki "} do %>
							<i class="fa fa-angle-left "></i>
							Regresar
						<% end %>
					<% else %>
						<%= link_to  sales_path(:filter => @filter, :current_page => @current_page), {:class=>"fr-space btn blue-hoki "} do %>
							<i class="fa fa-angle-left "></i>
							Regresar
						<% end %>
					<% end %>

				</div>
				<!-- BEGIN PAGE BREADCRUMBS -->
				<ul class="page-breadcrumb breadcrumb">
					<%= render_breadcrumbs :tag => :li, :separator => ' <i class="fa fa-circle"></i> ' %>
				</ul>
				<!-- END PAGE BREADCRUMBS -->
				<!-- BEGIN PAGE CONTENT INNER -->
				<div class="page-content-inner margin-top-10">
					<div class="row">
						<!-- informacion de la venta -->
						<div class="col-md-3 col-sm-12">
							<div class="portlet light bordered ">
								<div class="portlet-title">
									<div class="caption"> <i class="fa fa-shopping-cart"></i>Información de la venta</div>
								</div>
								<div class="portlet-body">
									<div class="row static-info">
										<div class="col-md-1 name"> <i class="fa fa-hashtag"></i> </div>
										<div class="col-md-8 value"> <%= @sale.sale_code %> </div>
									</div>
									<div class="row static-info">
										<div class="col-md-1 name"> <i class="fa fa-smile-o"></i> </div>
										<div class="col-md-8 value"> <%= @sale.customer.nick_name %> </div>
									</div>
									<div class="row static-info">
										<div class="col-md-1 name"> <i class="fa fa-odnoklassniki"></i> </div>
										<div class="col-md-8 value"> <%= @sale.user.first_name %> </div>
									</div>
									<div class="row static-info">
										<div class="col-md-1 name"> <i class="fa fa-calendar-o"></i> </div>
										<div class="col-md-8 value"> <%= l(@sale.date_sale, :format => '%A, %d de %B de %Y') %> </div>
									</div>
									<div class="row static-info">
										<div class="col-md-1 name"> <i class="fa fa-fw fa-cubes"></i> </div>
										<div class="col-md-8 value"> <%= @sale.products.count %> producto(s)</div>
									</div>
									<div class="row static-info">
										<div class="col-md-1 name"> <i class="fa fa-credit-card"></i> </div>
										<div class="col-md-8 value">
				                        <% if @sale.saletype == "credit" && @sale.credit_note.blank? %>
				                          	<span class="label label-warning"> Venta a crédito </span>
				                        <% elsif @sale.saletype == "credit" && @sale.credit_note.present? %>
				                          	<span class="label label-warning"> Crédito/vale </span>
										<% elsif @sale.saletype == "cash" %>
											<span class="label label-success"> Venta a contado </span>
										<% elsif @sale.saletype == "reserved" %>
											<span class="label label-primary"> Apartado </span>
										<% end %>
										</div>
									</div>
									<div class="row static-info">
										<div class="col-md-1 name"> <i class="fa fa-money"></i> </div>
										<div class="col-md-8 value"> <%= number_to_currency(@sale.total, precision: 2) %> </div>
									</div>
									<div class="row static-info">
										<div class="col-md-1 name"> <i class="fa fa-info-circle"></i> </div>
										<div class="col-md-8 value">
											<% case @sale.status %>
					                          <% when "paid"%>
					                            <span class="label label-success"> <i class="fa fa-check"></i> Pagada </span>
					                          <% when "canceled"%>
					                             <span class="label label-danger"> <i class="fa fa-close"></i> Cancelada </span>
					                          <% when "parcial"%>
					                            <span class="label label-warning"> <i class="fa fa-clock-o"></i> Abonada </span>
					                          <% when "notpaid"%>
					                            <span class="label label-default"> <i class="fa fa-clock-o"></i> Pendiente de pago </span>
					                      	<% end %>
										</div>
									</div>
									<% if @sale.credit_note.present? %>
										<div class="row static-info">
											<div class="col-md-1 name"> <i class="fa fa-ticket"></i> </div>
											<div class="col-md-8 value"> Folio vale:
												<span class="label label-info"> <%= @sale.credit_note %> </span>
											</div>
										</div>
									<% end %>
								</div>
							</div>
						</div>
						<!-- detalle de los productos -->
						<div class="col-md-9 col-sm-12">
							<div class="portlet light bordered ">
								<div class="portlet-title">
									<div class="caption"> <i class="fa fa-fw fa-cubes"></i>Detalle de los productos </div>
								</div>
								<div class="portlet-body">
									<table class="table table-striped table-hover">

										<thead>
											<tr>
												<th>#</th>
									            <th>SKU</th>
									            <th>Imagen</th>
									            <th>Producto</th>
									            <th>Cantidad</th>
									            <th>Precio</th>
									            <th>IVA</th>
									            <th>Descuento</th>
									            <th>Importe</th>
											</tr>
										</thead>
										<tbody>
											<% @sale.sales_details.each_with_index do |detail, key| %>
												<tr>
													<td> <%= key + 1 %> </td>
													<td> <%= detail.product.sku %> </td>
													<td> <img src="<%= detail.product.small_img %>" width="50" height="50"/> </td>
													<td>
														<%= detail.product.name %><br>
														<%= detail.product.display_attributes %>
														<% if @returned_prods_ids.include?(detail.product_id) %>
															<i class="fa fa-fw fa-reply font-red"></i>
														<% end %>
													</td>
													<td> <%= detail.quantity.round %> </td>
													<td> <%= number_to_currency(detail.unit_price, precision: 2) %> </td>
													<td> <%= number_to_currency(detail.tax, precision: 2) %> </td>
													<td> <%= number_to_currency(detail.discount, precision: 2) %> </td>
													<td> <%= number_to_currency(detail.total, precision: 2) %> </td>
												</tr>
											<% end %>
										</tbody>
									</table>
								</div>
							</div>
						</div>
						<% if @products_return.present? %>
							<!-- si tiene devolucion, mostrar detalles -->
							<div class="col-md-offset-3 col-md-9 col-sm-12">
								<div class="portlet light bordered ">
									<div class="portlet-title">
										<div class="caption"> <i class="fa fa-fw fa-exchange"></i>Detalle de devolución </div>
									</div>
									<div class="portlet-body">
										<div class="row">
											<div class="col-md-4">
											    <div class="hidden-print" style="padding-left: 0px">
											      <ul class="list-group">
											        <li class="list-group-item list-group-item-default"> Monto devuelto
												        <span class="pull-right label label-warning">
												        	<%= number_to_currency(@products_return.returned_amount, precision: 2) %>
											        	</span>
											        </li>
											      </ul>
											    </div>
											</div>
											<div class="col-md-4">
											    <div class="hidden-print" style="padding-left: 0px">
											      <ul class="list-group">
											        <li class="list-group-item list-group-item-default"> Nuevo monto
											        	<span class="pull-right label label-warning">
											        		<%= number_to_currency(@products_return.new_amount, precision: 2) %>
											        	</span>
											        </li>
											      </ul>
											    </div>
											</div>
											<div class="col-md-4">
											    <div class="hidden-print" style="padding-left: 0px">
											      <ul class="list-group">
											        <li class="list-group-item list-group-item-default"> Diferencia
											        	<span class="pull-right label label-warning">
											        		<%= number_to_currency(@products_return.difference_amount, precision: 2) %>
											        	</span>
											        </li>
											      </ul>
											    </div>
											</div>
										</div>
										<h3>Productos devueltos</h3>
										<table class="table table-striped table-hover">
											<thead>
												<tr>
										            <th>Cantidad</th>
										            <th>Imagen</th>
										            <th>Producto</th>
										            <th>Monto</th>
										            <th>Razón</th>
										            <th>Destino</th>
												</tr>
											</thead>
											<tbody>
												<% @products_return.products_return_ins.each do |detail| %>
													<tr>
														<td> <%= detail.quantity.round %> </td>
														<td> <img src="<%= detail.product.small_img %>" width="50" height="50"/> </td>
														<td>
															<%= detail.product.name %><br>
															<%= detail.product.display_attributes %>
														</td>
														<td>
															<%= number_to_currency(detail.amount, precision: 2) %>
														</td>
														<td><%= detail.reason %></td>
														<td>
															<%= detail.is_wasted? ? 'Merma' : 'Inventario' %>
														</td>
													</tr>
												<% end %>
											</tbody>
										</table>

										<h3>Productos por cambio</h3>
										<table class="table table-striped table-hover">
											<thead>
												<tr>
										            <th>Cantidad</th>
										            <th>Imagen</th>
										            <th>Producto</th>
										            <th>Monto</th>
												</tr>
											</thead>
											<tbody>
												<% @products_return.products_return_outs.each do |detail| %>
													<tr>
														<td> <%= detail.quantity.round %> </td>
														<td>
															<img src="<%= detail.product.small_img %>" width="50" height="50"/>
														</td>
														<td>
															<%= detail.product.name %><br>
															<%= detail.product.display_attributes %>
														</td>
														<td>
															<%= number_to_currency(detail.amount, precision: 2) %>
														</td>
													</tr>
												<% end %>
											</tbody>
										</table>
									</div>
								</div>
							</div>
						<% end %>

						<!-- detalle de los pagos -->
						<div class="col-md-offset-3 col-md-9 col-sm-12">
							<div class="portlet light bordered ">
								<div class="portlet-title">
									<div class="caption"> <i class="fa fa-fw fa-usd"></i>Detalle de pago(s)</div>
								</div>
								<div class="portlet-body">
									<table class="table table-striped table-hover">
										<thead>
											<tr>
												<th>#</th>
												<th>Fecha</th>
									            <th>Metodo de pago</th>
									            <th>Monto</th>
									            <th>Info. Adicional</th>
											</tr>
										</thead>
										<tbody>
											<% @payments.each_with_index do |payment, key| %>
												<tr>
													<td> <%= key + 1 %> </td>
													<td> <%= l(payment.created_at, :format => '%d/%m/%y %I:%M %p') %> </td>
													<td> <%= payment.payment_method.method %> </td>
													<td> <%= number_to_currency(payment.quantity, precision: 2) %> </td>
													<td> <%= payment.cardnumber %> </td>
												</tr>
											<% end %>
										</tbody>
									</table>
								</div>
							</div>
						</div>
					</div>
				</div>
				<!-- END PAGE CONTENT INNER -->
			</div>
		</div>
		<!-- END PAGE CONTENT BODY -->
		<!-- END CONTENT BODY -->
	</div>
	<!-- END CONTENT -->
</div>
	<!-- END CONTAINER
