<div class="p-l-15">
	<%= form_tag report_path, :method => :get, :id=>"frm_report", :class => "form" do %>
	<% if period_type != false %>
	<div class="row">

		<% if defined? @payment_method %>
			<div class="col-lg-2 col-md-2 col-sm-2 col-mbl-view mbl-style">
				<label class="font-14 mbl_lbl"><%= t("views.right_panel.detail.select_payments") %></label>
				<%= select_tag "payment_type", options_for_select(@payment_method, :selected => params[:payment_type]), :class => "form-control" %>
			</div>
		<% end %>
		<div class="col-lg-2 col-md-2 col-sm-2 col-mbl-view mbl-style">
			<label class="font-14 mbl_lbl"><%= t("views.right_panel.detail.select_period") %></label>
			<select name="period" id="sel_period" class="form-control">
				<option value=""><%= t("views.right_panel.detail.select_period") %></option>
				<option value="0">Today</option>
				<option value="1">Yesterday</option>
				<option value="2">This week</option>
				<option value="3">Last week</option>
				<option value="4">Last 7 days</option>
				<option value="5">This month</option>
				<option value="6">Last month</option>
				<option value="7">Last 30 days</option>
				<option value="8">This year</option>
				<option value="9">Last year</option>
			</select>
		</div>
		<% if not defined? payments %>

		  <div class="col-lg-2 col-md-2 col-sm-2 mbl-style">
			<label class="font-14 mbl_lbl"><%= t("views.right_panel.detail.select_payments") %></label>

			<select name="payment_type" id="payment_type" class="form-control">
				<%  @payments.each do |pm| %>
				<option class="<%=pm[1].downcase%>" value="<%=pm[1].downcase%>"><%=pm[0]%></option>
				<%end %>
				<%  @payment_method.each do |pm| %>
				<option value="<%=pm.payment_method%>" class="<%=pm.payment_method%>" > <%=pm.payment_method%></option>
				<%end %>
			</select>
		</div>
		<% end %>
		<div class="col-lg-2 col-md-2 col-sm-2 col-mbl-view mbl-style">
			<!-- <label class="">Select Shift Period</label> -->
			<label class="font-14 mbl_lbl"><%= t("views.right_panel.detail.from") %></label>
			<input data-behaviour='datepicker' class="form-control datepicker m-t-3" name="from" id="from" type="text" placeholder="From date" style="height: 32px;">
		</div>
		<div class="col-lg-2 col-md-2 col-sm-2 col-mbl-view mbl-style">
			<label class="font-14 mbl_lbl"><%= t("views.right_panel.detail.to") %></label>
			<input data-behaviour='datepicker' class="form-control datepicker m-t-3" name="to" id="to" type="text" placeholder="To date" style="height: 32px;">
		</div>
		<div class="col-lg-2 col-md-2 col-sm-2 mbl-style">
			<label class="font-14 mbl_lbl"><%= t("views.right_panel.detail.all_shift") %></label>
			<select class="form-control select" name="shift_name" id="shift_name" >
			</select>
		</div>
		<div class="col-lg-2 col-md-2 col-sm-2 col-xs-2 mbl-right-btn mbl-style">
			<br>
			<input type="submit" value="Generate Report" class='btn btn-primary'>
		</div>
	</div>
	<% end %>

	<% end %>
</div>

<script type="text/javascript">
	$(function(){
		$('#custom_excel').hide();

		$('#custom_excel').click(function(){
			var url = $('#custom_excel').attr('data-url');
			$('#frm_report').attr('action',url)
			$('#frm_report').submit();
		// window.location = url;
	});

		var item = $('#item').val();
		var payment_type = $('#payment_type');

		if(item == 'order'){
			$('#cashier').hide();
			$('#waiter').show();
			if(payment_type){
				$('#payment_type').hide();
			}
		}
		else if(item == 'sale'){
			$('#waiter').hide();
			$('#cashier').show();
		}
		else{
			$('#waiter').hide();
			$('#cashier').show();
			$("#item").val('sale');
		}
	});

	<% if params[:shift_name].to_i > 0%>
	shift_id = '<%= params[:shift_name] %>'
	local_date = '<%= @shift_from %> - <%= @shift_to %> '
	var shift = $('#shift_name');
	str = '<option value="'+ shift_id +'" '+ 'selected = "selected"' +'>' + local_date + '</option>';
	shift.append(str);
	<% end %>

	$('#sale_id').val("<%= params[:sale_id] %>");
	$("#from").val("<%=params[:from] rescue '-'%>");
	$("#to").val("<%=params[:to] rescue '-'%>");
	$("#sel_period").val(<%=params[:period] rescue '-'%>);
	$("#sel_sale_type").val(<%=params[:sale_type] rescue '-'%>);

	$(".<%=params[:payment_type]%>").attr('selected','selected')


 <% if params[:period_type] == 1 || params[:period_type] == "1" %>
 $("#rd_period_type_1").attr("checked","checked");
 <% else %>
 $("#rd_period_type_0").attr("checked","checked");
 <% end %>
 $(".btn-group button").removeClass("active");
 <% report_type = params[:report_type].blank? ? "0" : params[:report_type] %>
 $("#btn_report_type_<%= report_type %>").addClass("active");

 $('#item').change(function(){
 	var item = $('#item').val();
 	var payment_type = $('#payment_type');

 	if(item == 'sale'){
 		$('#waiter').hide();
 		$('#cashier').show();
 		if(payment_type){
 			$('#payment_type').show();
 		}
 	}
 	else{
 		$('#cashier').hide();
 		$('#waiter').show();
 		if(payment_type){
 			$('#payment_type').hide();
 		}
 	}
 });
</script>
