<%= form_tag({:controller => 'wkattendance', :action => 'update'}, :method => :post, :id => 'query_form') do %>
	<%
		lastAccrualOn = Date.civil(Date.today.year, Date.today.month, 1) -1
		accrual_on = params[:accrual_on].to_s.to_date
		accrualOnStr = accrual_on.strftime("%B") + ", " + accrual_on.strftime("%Y")
		user_name = @leave_details[0].firstname + ' ' + @leave_details[0].lastname if !@leave_details[0].blank?
		hasNext = accrual_on < lastAccrualOn
	%>
	<%if !@leave_details[0].blank?%>
	<h2><%= l(:label_leave_summary) %></h2>
	<table>
		<tr>
			<th align="left"><%=l(:field_user)%></th>
			<td><%=h user_name %></td>
		</tr>
		<tr>
			<th align="left"><%=l(:label_wk_attn_for)%></th>
			<td><%=h accrualOnStr %></td>
		</tr>
		<tr>
			<td colspan="2">
				 <%= link_to("\xc2\xab " + l(:label_previous ), {:controller => controller.controller_name, :action => 'edit', :user_id => params[:user_id], :accrual_on => ((accrual_on + 1) << 1) -1, :tab => controller.controller_name},
						  :title => l(:label_wk_prev_week_tip)) %>
			<%if hasNext%>
			  |
			  <%= link_to(l(:label_next) + " \xc2\xbb", {:controller => controller.controller_name, :action => 'edit', :user_id => params[:user_id], :accrual_on => ((accrual_on + 1) >> 1) -1, :tab => controller.controller_name},
						  :title => l(:label_next_week)) %>
			<%end%>
			</td>
		</tr>
	</table>
	<br>
	<div class="autoscroll">
	<div  style="float:left;width=100%;">
	<table class="list time-entries">
	<thead>
		<tr>
		<th class="lbl-txt-align"><%= l(:label_wk_leave) %></th>
		<th class="lbl-txt-align"><%= l(:wk_label_opening) %><br><%= "(" + l(:field_hours) + ")" %></th>
		<th class="lbl-txt-align"><%= l(:label_wk_leave_accrual) %><br><%= "(" + l(:field_hours) + ")" %></th>
		<th class="lbl-txt-align"><%= l(:wk_field_used) %><br><%= "(" + l(:field_hours) + ")" %></th>
		<th class="lbl-txt-align"><%= l(:wk_label_closing) %><br><%= "(" + l(:field_hours) + ")" %></th>
		</tr>
	</thead>
	<%
		disable = true
		wktime_helper = Object.new.extend(WktimeHelper)
		disable = false if wktime_helper.validateERPPermission('A_ATTEND') && ( params[:user_id].to_i != User.current.id || (!Setting.plugin_redmine_wktime['wktime_own_approval'].blank? &&
							Setting.plugin_redmine_wktime['wktime_own_approval'].to_i == 1 ))
	%>
	<%
		ids = ''
		newIssueIds =''
		userId = ''
	%>
	<% @leave_details.each do |entry| -%>
		<%
			if entry.id.blank?
				newIssueIds = newIssueIds +',' if newIssueIds!=''
				newIssueIds = newIssueIds + entry.issue_id.to_s
			else
				ids = ids +',' if ids!=''
				ids = ids + entry.id.to_s
			end
			userId = entry.user_id
			remaining = (entry.balance.blank? ? 0 : entry.balance) + (entry.accrual.blank? ? 0 : entry.accrual) - (entry.used.blank? ? 0 : (entry.used*@accrualMultiplier[entry.issue_id]))
		%>

	<tr class="time-entry <%= cycle("odd", "even") %>">
	<td width="220px"><b><%=h entry.issue.subject%></b></th>
		<td><%=h text_field_tag('balance_'+entry.issue_id.to_s,entry.balance.blank? ? 0 : entry.balance,:size => 10, :disabled => disable, :required => true) %>
		</td>
		<td><%=h text_field_tag('accrual_'+entry.issue_id.to_s,entry.accrual.blank? ? 0 : entry.accrual,:size => 10, :disabled => disable, :required => true) %>
		</td>
		<td><%=h text_field_tag('used_'+entry.issue_id.to_s,entry.used.blank? ? 0 : entry.used,:size => 10, :disabled => disable, :required => true) %>
		</td>
		<td><%=h remaining.round(2)%></td>
	</tr>
	<% end -%>
	</table>
	<br>
	<span style="margin-left:25.0em;"></span><%= submit_tag l(:button_save), :hidden => disable, :id => 'wkattendance_save', :disabled => disable %>
	</div>
	</div>
	<%else%>
		<th><b><%= l(:label_no_leaves_configured) %></b></th>
	<%end%>
	<%=h hidden_field_tag('user_id', userId) %>

	<%=h hidden_field_tag('accrual_on', accrual_on) %>

	<%=h hidden_field_tag('new_issue_ids', newIssueIds) %>

	<%=h hidden_field_tag('ids', ids) %>
<% end %>