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

				<div class="col-lg-3 col-md-3 col-sm-3 col-mbl-view mbl-style">
					<!-- <label class="font-14">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-3 col-md-3 col-sm-3 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">
					<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 margin-top-20 mbl-style mbl-right-btn"><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');
		}
	});

//Reset the form to pervious values
<% if params[:shift_name].to_i > 0%>
shift_id = '<%= params[:shift_name] %>'
local_date = '<%= @shift.shift_started_at.utc.getlocal.strftime("%e %b %I:%M%p")%> -<%= @shift.shift_closed_at ? @shift.shift_closed_at.utc.getlocal.strftime("%e %b %I:%M%p") : "-" %>'
var shift = $('#shift_name');
str = '<option value="'+ shift_id +'" '+ 'selected = "selected"' +'>' + local_date + '</option>';
shift.append(str);
<% end %>
$("#from").val("<%=params[:from]%>");
$("#to").val("<%=params[:to]%>");
$("#sel_period").val(<%=params[:period]%>);
$("#sel_sale_type").val(<%=params[:sale_type]%>);

<% 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>
