<%= javascript_include_tag 'index', :plugin => "redmine_wktime" %>
<%= javascript_include_tag 'invoice', :plugin => "redmine_wktime" %>
<%= hidden_field_tag 'back_url', url_for(:controller => params[:controller], :action => params[:action]) %>


	<%= form_tag({:controller => controller_name, :action => 'index', :tab => controller_name}, :method => :get, :id => 'query_form') do %>
	<fieldset>
		<div style="float:right">
			<%= link_to controller.getNewHeaderLbl, url_for(:controller => controller_name, :action => 'new'), :class => 'icon icon-add' %>&nbsp;
			<%= render :partial => 'sidebar' if  controller_name == 'wkinvoice'%>
		</div>
		<%= hidden_field_tag "searchlist", controller_name %>
		<%=h hidden_field_tag('tab', controller_name) %>
		<%= hidden_field_tag "preview_billing", false %>
		<%= hidden_field_tag "timeEntryIDs" %>
		<%= hidden_field_tag "materialEntryIDs" %>
		<%= hidden_field_tag "expenseEntryIDs" %>
		<script type="text/javascript">
			accountUrl="<%= "#{url_for(:controller => "wkinvoice", :action => 'getAccountProjIds')}" %>";
		</script>

		<%	contactId =session[controller_name].try(:[], :contact_id)
			accountId =session[controller_name].try(:[], :account_id)
			rfqId = session[controller_name].try(:[], :rfq_id)
			filterSession =session[controller_name].try(:[], :polymorphic_filter)
			projid =session[controller_name].try(:[], :project_id)
			leadID =session[controller_name].try(:[], :lead_id) %>

			<%= render partial: "wkbilling/index_filters", locals: { :contact_id => contactId, :account_id => accountId, :rfq_id => rfqId, :filter_session => filterSession, :project_id => projid, :pjtChanged => controller.needChangedProject, :isapply => false, :isproject => true, :isAll => true, :blankOptionForPjt => true, :blankForActDD => true, :blankForContactDD => true, :needQuotePoDD => false, :isFilter => true, :loadSIDD => false, lead_id: leadID } %>

			<p style="float:left;"><%= render :partial => 'wkorderentity/date_range' %></p>
		<p class="buttons">
			<%= link_to_function l(:button_apply), '$("#query_form").submit(); return false;', :class => 'icon icon-checked' %>
			<%#= link_to l(:button_apply), {:controller => controller_name, :action => action_name}, :class => 'icon icon-checked' %>
			<%= link_to l(:button_clear), {:tab => controller_name, clear: true}, :class => 'icon icon-reload' %>
			<% if controller.isInvGenUnbilledLink %>
				<%= link_to l(:label_generate) + ' ' + l(:label_invoice), 'javascript:selectEntryPopup(false);', :name => 'generate', :class => 'icon icon-report' %>
				<%= link_to_function l(:label_preview_invoice), "javascript:invoiceFormSubmission(true); ", :class => 'icon icon-report' %>
			<% end %>

		</p>
	</fieldset>
	<% end %>
	<% if @invoiceEntries.present? || @invList.present?%>
	<div class="total-hours">
		<p><%= l(:label_total) %>: &nbsp;
		<%= Setting.plugin_redmine_wktime['wktime_currency']%>
		<%= html_hours("%.2f" % @totalInvAmt) %></p>
	</div>
		<%= render :partial => 'wkorderentity/order_list'%>
		<% if !@previewBilling %>
			<% other_formats_links do |f| %>
				<%= f.link_to_with_query_parameters 'CSV', {} %>
			<% end %>
		<% end %>
	<% else %>
		<p class="nodata"><%= l(:label_no_data) %></p>
	<% end %>
	<script>
		var title = "<%= l(:label_select_entries) %>";
	</script>
	<div id="billGenerate-dlg"></div>
