	<!-- 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>Cliente </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 ">
						<%= link_to  customers_path(:filter => @filter, :current_page => @current_page), {:class=>"fr-space btn blue-hoki "} do %>
							<i class="fa fa-angle-left "></i>
							Regresar
						<% end %>
						<%= link_to  edit_customer_path(@customer), {:class=>"btn btn-primary "} do %>
							<i class="fa fa-edit"></i> Modificar
						<% 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">
							<div class="col-md-4 col-sm-12">
								<div class="portlet light bordered ">
									<div class="portlet-title">
										<div class="caption"> <i class="fa fa-cogs"></i>Información general </div>
									</div>
									<div class="portlet-body">
										<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"> <%= @customer.nick_name %> </div>
										</div>
										<div class="row static-info">
											<div class="col-md-1 name"> <i class="fa fa-envelope"></i> </div>
											<div class="col-md-8 value"> <%= @customer.email %> </div>
										</div>
										<% if  @customer.notes != '' %>
										<div class="row static-info">
											<div class="col-md-1 name"> <i class="fa fa-bookmark"></i> </div>
											<div class="col-md-8 value"> <%= @customer.notes %> </div>
										</div>
										<% end %>
										<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 @customer.credit %> <span class="label label-sm label-success"> Crédito activo </span><% else %> <span class="label label-sm label-danger"> No se le otorgó crédito </span><% end %> </div>
										</div>
										<% if @customer.credit %>
										<div class="row static-info">
											<div class="col-md-1 name"> <i class="fa fa-money"></i> </div>
											<div class="col-md-8 value">$ <%= @customer.credit_limit %> </div>
										</div>
										<div class="row static-info">
											<div class="col-md-1 name"> <i class="fa fa-calendar"></i> </div>
											<div class="col-md-8 value"> <%= @customer.time_limit %>  <% if @customer.time_limit > 1 %> días <% else %> día <% end %></div>
										</div>
										<% end %>
										<div class="row static-info">
											<div class="col-md-1 name"> <i class="fa fa-flag"></i> </div>
											<div class="col-md-8 value"> <% if @customer.status == 'active'  %> <span class="label label-sm label-success"> <i class="fa fa-check"></i> Activo </span><% else %> <span class="label label-sm label-danger"> <i class="fa fa-close"></i> Inactivo </span><% end %> </div>
										</div>
									</div>
								</div>
							</div>
							<% if !@customer.billing_information.nil? %>
							<div class="col-md-4 col-sm-12">
								<div class="portlet light bordered ">
									<div class="portlet-title">
										<div class="caption"> <i class="fa fa-dollar"></i>Información facturación </div>
									</div>
									<div class="portlet-body">
										<div class="row static-info">
											<div class="col-md-1 name"> <i class="fa fa-building"></i> </div>
											<div class="col-md-8 value"> <%= @customer.billing_information.name %> </div>
										</div>
										<div class="row static-info">
											<div class="col-md-1 name"> <i class="fa fa-key"></i> </div>
											<div class="col-md-8 value"> <%= @customer.billing_information.rfc %> </div>
										</div>
										<div class="row static-info">
											<div class="col-md-1 name"> <i class="fa fa-home"></i> </div>
											<div class="col-md-8 value"> <%= @customer.billing_information.address_complete %>
											</div>
										</div>
									</div>
								</div>
							</div>
							<% end %>
							<% if !@customer.contact.nil? %>
							<div class="col-md-4 col-sm-12">
								<div class="portlet light bordered ">
									<div class="portlet-title">
										<div class="caption"> <i class="fa fa-user"></i>Información contacto </div>
									</div>
									<div class="portlet-body">
										<div class="row static-info">
											<div class="col-md-1 name"> <i class="fa fa-user"></i> </div>
											<div class="col-md-8 value"> <%= @customer.contact.name %> <%= @customer.contact.last_name %> </div>
										</div>
										<div class="row static-info">
											<div class="col-md-1 name"> <i class="fa fa-phone"></i> </div>
											<div class="col-md-8 value"> <%= @customer.contact.phone %> </div>
										</div>
										<div class="row static-info">
											<div class="col-md-1 name"> <i class="fa fa-envelope"></i> </div>
											<div class="col-md-8 value"> <%= @customer.contact.email %> </div>
										</div>
									</div>
								</div>
							</div>
							<% end %>
							<div class="col-md-12">
								<div class="portlet light bordered">
									<div class="portlet-title">
										<div class="caption"> <i class="fa fa-money"></i>Historial del cliente <%= @customer.nick_name %></div>
									</div>
									<div class="portlet-body">
										<div class="tabbable-custom">
											<ul class="nav nav-tabs ">
												<li class="active">
													<a href="#customer_sales" data-toggle="tab" aria-expanded="true"> Ventas </a>
												</li>
												<li class="">
													<a href="#abonos" data-toggle="tab" aria-expanded="false"> Abonos </a>
												</li>
											</ul>
											<div class="tab-content">
												<div class="tab-pane active" id="customer_sales">
													<div class="pull-right-margin-bottom-10">
														<table class="table table-striped table-bordered table-hover tableadvanced">
															<thead>
																<tr>
																	<th>#</th>
																	<th>Folio</th>
																	<th>Punto de venta</th>
																	<th>Vendedor</th>
																	<th>Fecha</th>
																	<th>Tipo</th>
																	<th>Productos</th>
																	<th>Status</th>
																	<th>Total</th>
																	<th>Abonado</th>
																	<th>Restante</th>
																	<th>Acciones</th>
																</tr>
															</thead>
															<tbody>
																<% @sales.each_with_index do |sale, key| %>
																	<tr class=<%= (sale.cancelled? ? 'danger' : (sale.paid? ? 'success' : '')) %>>
																		<td><%= key +1 %></td>
																		<td><%= sale.sale_code %> </td>
																		<td> <%= sale.get_pointsale.name %> </td>
																		<td><%= sale.seller.name %> </td>
																		<td><%= l(sale.date_sale, :format => '%d/%m/%Y') %></td>
																		<td>
																			<% if sale.saletype == "credit" && sale.credit_note.blank? %>
																				Crédito
																			<% elsif sale.saletype == "credit" && sale.credit_note.present? %>
																				Crédito/vale
																			<% elsif sale.saletype == "reserved" %>
																				Apartado
																			<% else %>
																				Contado
																			<% end %>
																		</td>
																		<td><%= sale.products.count %></td>
																		<td>
																		<% case sale.status %>
																			<% when "paid"%>
																				<span class="label label-success"> PAGADA </span>
																			<% when "cancelled"%>
																				<span class="label label-danger"> CANCELADO </span>
																			<% when "parcial"%>
																				<span class="label label-warning"> ABONADA </span>
																			<% when "notpaid"%>
																				<span class="label label-default"> PENDIENTE PAGO </span>
																		<% end %>
																		</td>
																		<td><%= number_to_currency(sale.total, precision: 2) %></td>
																		<% credito = Credit.where(:sale_id => sale.id).first %>
																		<% if credito.present? %>
																		<% abonos = CreditPayment.where(:credit_id => credito.id, :status => 0).sum(:quantity) %>
																		<% if abonos.present? %>
																		<td><%= number_to_currency(abonos, precision: 2) %></td>
																		<% end %>
																		<td><%= number_to_currency(credito.rest, precision: 2) %></td>
																		<% else %>
																		<td></td>
																		<td></td>
																		<% end %>
																		<td>
																			<%= link_to sale, {:class=>"btn btn-icon-only default", :title=>"Ver venta"} do %>
																					<i class="fa fa-search"></i>
																			<% end %>
																			<% if can? :destroy, Sale %>
																				<% daysToCancel = @pos_config.days_cancel_sale %>
																					<% if (sale.date_sale + daysToCancel.days >= Date.today) && !sale.cancelled? %>
																						<%= link_to sale , method: :delete, :class => "btn btn-icon-only btn-danger", :title=>"Cancelar venta", data: { confirm: '¿Esta seguro que desea cancelar la venta?'}   do %> <i class="fa fa-ban"></i>
																						<% end %>
																					<% end %>
																			<% end %>
																		</td>
																	</tr>
																<% end %>
															</tbody>
														</table>
													</div>
												</div>
												<!-- fin contenido customer sales -->
												<!-- contenido abono -->
												<div class="tab-pane" id="abonos">
													<table class="table table-striped table-bordered table-hover tableadvanced" id="sales_table">
														<thead>
															<tr>
																<th>Folio</th>
																<th>Fecha</th>
																<th>Deuda</th>
																<th>Abono</th>
																<th>Restante</th>
																<th>Status</th>
																<th width="15%">Acciones</th>
															</tr>
														</thead>
														<tbody id="abonos" >
														<% @credit.each_with_index do |credit, key| %>
															<% abonos = CreditPayment.where(:credit_id => credit.id) %>
																<% abonos.each_with_index do |abono, key| %>
																<tr class=<%= (credit.cancelled? ? 'danger' : (credit.active? ? 'success' : '')) %>>
																	<td><%= credit.sale.sale_code %> </td>
																	<td><%= abono.date_payment %></td>
																	<td><%= number_to_currency(credit.total, precision: 2) %></td>
																	<td><%= number_to_currency(abono.quantity, precision: 2) %></td>
																	<td><%= number_to_currency(credit.rest, precision: 2) %></td>
																	<td>
																		<% case abono.status %>
																		<% when "cancelled"%>
																			<span class="label label-danger"> CANCELADO </span>
																		<% when "active"%>
																			<span class="label label-success"> ACTIVO </span>
																		<% end %>
																	</td>
																	<td class="text-center">
																	<% if !abono.cancelled? %>
																			<%= link_to cash_move_delete_payment_path(:credit_payment_id => abono.id, :credit => credit.id) , method: :delete_credit_payment, :class => "btn btn-icon-only btn-danger", :title=>"Cancelar abono", data: { confirm: '¿Esta seguro que desea cancelar el abono?'}   do %> <i class="fa fa-ban"></i>
																			<% end %>
																	<% end %>
																	</td>
																</tr>
															<% end %>
														<% end %>
														</tbody>
													</table>
												</div>
												<!-- fin contenido abono -->
											</div>
										</div>
									</div>
								</div>
							</div>
						</div>
					</div>
					<!-- END PAGE CONTENT INNER -->
				</div>
			</div>
			<!-- END PAGE CONTENT BODY -->
			<!-- END CONTENT BODY -->
		</div>
		<!-- END CONTENT -->
	</div>
	<!-- END CONTAINER -->
