<!-- 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>Existencias</h1>
				</div>
				<!-- END PAGE TITLE -->
			</div>
		</div>
		<!-- END PAGE HEAD-->
		<!-- BEGIN PAGE CONTENT BODY -->
		<div class="page-content">
			<div class="container-fluid">
				<!-- <%= link_to  root_path, {:class=>"btn blue-hoki pull-right margin-bottom-10"} do %>  <i class="fa fa-angle-left "></i> Regresar
				<% end %> -->
				<% if current_user.usertype != 'C' %>
				<a class="pull-right btn blue hidden-print margin-bottom-10" onclick="print()"> Imprimir
					<i class="fa fa-print"></i>
				</a>
				<%end%>
				<!-- 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">
					<div id="notice"><%= notice %></div>
					<div class="row">
						<div class="col-md-12">
							<div class="portlet light">
								<div class="portlet-body form">
									<div id="error_explanation"></div>
									<!-- lista de productos -->
									<h4 class="form-section"> Lista de productos</h4>
									<div class="portlet-body">
										<div class="form-horizontal">
											<div class="row">
												<div class="col-md-12">
													<div class="form-group">
														<!-- punto de venta -->
														<%= label :pointsale, "", {:class=>"col-md-1 control-label"} do %>Localización<% end %>
														<div class="col-md-3 select2-bootstrap-prepend">
															<%= select_tag "pointsale", grouped_options_for_select([
																['Puntos de venta',  Pointsale.activos.collect {|p| [ p.name, ('P-' + p.id.to_s) ] }],
																['Almacenes', Warehouse.activos.collect {|w| [ w.name, ('W-' + w.id.to_s)] }]], :selected =>@selected), class: "pointsale_id form-control select2" %>
														</div>
														<!-- categoria -->
														<%= label :category, "", {:class=>"col-md-1 control-label"} do %>Línea <% end %>
														<div class="col-md-3 select2-bootstrap-prepend">
															<%= select_tag "category", options_from_collection_for_select(Category.activos_padre, :id, :category), :include_blank => "Todas",  class: "form-control select2 clereable", :onchange => 'getSub_categories()'%>
														</div>
														<!-- sub- categoria -->
														<%= label :sub_category, "", {:class=>"col-md-1 control-label"} do %>Sublínea <% end %>
														<div class="col-md-3 select2-bootstrap-prepend">
															<%= select_tag "sub_category", options_from_collection_for_select(Category.activos.where('parent_id != 0'), :id, :category), :include_blank => "Todas",  class: "form-control select2 clereable" %>
														</div>
													</div>
												</div>
											</div>
											<div class="row">
												<div class="col-md-3 col-sm-4 col-xs-6 " >
													<div class="text-center well" id="container_total_prods" style="margin-bottom: 0px">
														<div class="font-grey-mint font-sm">Total de productos </div>
														<div class="uppercase font-hg font-blue-sharp" id="total_prods"></div>
													</div>
												</div>
												<% if current_user.usertype == 'A' %>
													<div class="col-md-3 col-sm-4 col-xs-6 ">
														<div class="text-center well" id="container_total_invested" style="margin-bottom: 0px">
															<div class="font-grey-mint font-sm">Total invertido en pesos </div>
															<div class="uppercase font-hg font-green-sharp" id="total_invested"></div>
														</div>
													</div>

													<div class="col-md-3 col-sm-4 col-xs-6 ">
														<div class="text-center well" id="container_total_invested_dlls" style="margin-bottom: 0px">
															<div class="font-grey-mint font-sm">Total invertido en dolares</div>
															<div class="uppercase font-hg font-green-sharp" id="total_invested_dlls"></div>
														</div>
													</div>
												<% end %>
											</div>
											<div class='row'>
												<div class="col-md-12">
												<h4 class="form-section" > </h4>
													<%= render 'form_stock_printable' %>
												</div>
											</div>
										</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 -->
<script type="text/javascript">
	$(document).on('page:change', function() {
		$(".clereable").select2({
			allowClear: true,
			placeholder: 'Todas'
		});
	});

	function print() {
		var search = $('input[type="search"]').val();
		var location = $('#pointsale').val();
		var category = $('#category').val();
		var sub_category = $('#sub_category').val();
		var size = parseInt($("select[name='pointsale_stock_length']").val());
		var uri = 'location=' + location;
		if (size != -1){ uri += '&size=' + size; }
		if (category) { uri += '&category=' + category; }
		if (sub_category) { uri += '&sub_category=' + sub_category; }
		if (search) { uri += '&search=' + encodeURIComponent(search); }

		window.open('/print_stock_by_pointsale.pdf?' + uri, 'New tab', '' );

	}
</script>

