<%= javascript_include_tag 'wkpayroll', :plugin => "redmine_wktime" %>
<%= stylesheet_link_tag 'wk-time', :plugin => "redmine_wktime" %>
<style>
.table-wrapper {
	overflow-x:scroll;
	margin-left: 260px;
}
th:first-child {
	white-space: normal !important;
	text-align: left;
	left: 5px;
	width: 260px;
	position: absolute;
}
</style>
<% if validateERPPermission('A_PAYRL') %>
	<fieldset>
		<legend><%= l(:label_filter_plural) %></legend>
		<%= form_tag({:controller => controller_name, :action => 'usrsettingsindex'}, :method => :get) do %>
			<%= hidden_field_tag 'back_url', url_for(:controller => params[:controller], :action => params[:action]) %>
			<%= hidden_field_tag('tab', 'payroll') %>
			<%= hidden_field_tag "searchlist", controller_name %>
			<%	groupid =session[:wkpayroll].try(:[], :group_id) %>
			<b><label for='status'><%= l(:field_status) %>:</label></b>
			<%= select_tag 'status', users_status_options_for_select(@status), :class => "small", :onchange => "this.form.submit(); return false;"  %>

			<% if @groups.present? %>
				<b><label for='group_id' style="padding-left: 10px;"><%= l(:label_group) %>:</label></b>
				<%= select_tag 'group_id', content_tag('option') + options_from_collection_for_select(@groups, :id, :name,  !groupid.nil? ? groupid.to_i: 0), :onchange => "this.form.submit(); return false;"  %>
			<% end %>

			<b><label for='name' style="padding-left: 10px;"><%= l(:label_user) %>:</label></b>
			<%= text_field_tag 'name', session[controller_name].try(:[], :name), :size => 30 %>
			<%= submit_tag l(:button_apply), :class => "small", :name => "list" %>
			<%= link_to l(:button_clear), {tab: 'payroll', clear: true}, class: 'icon icon-reload' %>
		<% end %>
	</fieldset>
<% end %>
	&nbsp;
	<div class="table-wrapper">
		<table class="list odd-even" id="userpayroll">
			<thead>
				<tr>
					<th><%= l(:field_user) %></th>
					<% @salary_components.each do |compoment| %>
						<th style="text-align: center;">
							<label style="padding-right: 10px;"><%= compoment.name %></label>
							<% if validateERPPermission('A_PAYRL') %>
								<a class="icon icon-edit" style="cursor: pointer;" id="<%= compoment.id %>" onClick=" bulk_edit('<%= compoment.id %>');" action="Edit"></a>
							<% end %>
						</th>
					<% end %>
					<th></th>
				</tr>
			</thead>
			<tbody>
				<% @payroll_entries.each do |entry| -%>
					<tr class="time-entry <%= cycle("odd", "even") %> <%= entry.status == 3 ? "user locked" : "" %>" >
						<th id="rowheader_<%=entry.user_id%>"><%=h entry.firstname + ' ' + entry.lastname%></th>
						<% @salary_components.each do |compoment|
							salComp = @userSalCompHash[compoment.id.to_s + "_" + entry.user_id.to_s]
							factor = salComp.present? ? salComp.factor : 0.00
							depID = salComp.dependent_id
						%>
							<%= hidden_field_tag('dep_'+ compoment.id.to_s + '_' + entry.user_id.to_s, depID) %>
							<td class="rowcontent_<%=entry.user_id%>" style="text-align: center;" id="td_<%= compoment.id.to_s + '_' + entry.user_id.to_s %>"><%= factor %></td>
						<% end %>
						<td align="center">
							<%= link_to image_tag('edit.png'), {:controller => controller.controller_name, :action => 'user_salary_settings', :user_id => entry.user_id, :tab => 'payroll'},
															   :title => l(:button_edit) %>
						</td>
					</tr>
				<% end -%>
			</tbody>
		</table>
	</div>