<% wkexpense_helper = Object.new.extend(WkexpenseHelper) %>
<% wkasset_helper = Object.new.extend(WkassetHelper) %>
<% wktime_helper = Object.new.extend(WktimeHelper) %>
<%
	Issue.class_eval do
		has_one :wk_issue, :dependent => :destroy, :class_name => 'WkIssue'
		has_many :assignees, :dependent => :destroy, :class_name => 'WkIssueAssignee'
		accepts_nested_attributes_for :assignees
		accepts_nested_attributes_for :wk_issue
		def erpmineissues
			self.wk_issue ||= WkIssue.new(:issue => self, :project => self.project)
		end	
	end

	Project.class_eval do
		has_many :account_projects, :dependent => :destroy, :class_name => 'WkAccountProject'
		#has_many :parents, through: :account_projects
	end

	TimeEntry.class_eval do
	  has_one :spent_for, as: :spent, class_name: 'WkSpentFor', :dependent => :destroy
	  has_one :invoice_item, through: :spent_for
	  
	  accepts_nested_attributes_for :spent_for
	end

%>
<% 	projectObj = Project.where(:id => @issue.project_id)
	usersArr = projectObj.map(&:assignable_users).reduce(:&) 
	memberArr = Array.new
	unless usersArr.blank?
		usersArr.each do | user |
			memberArr <<  [(user.firstname + " " + user.lastname), user.id.to_s]
		end
	end
%>

<% if(Setting.plugin_redmine_wktime['label_no_additional_details_for_issue'].blank? && Setting.plugin_redmine_wktime['label_no_additional_details_for_issue'].to_i == 0) %>
	<fieldset class="box tabular">
	<legend><%= l(:label_additional_details) %></legend>
	<% if wktime_helper.showBilling %>
		<table style="padding-left:130px;">
			<%= labelled_fields_for :erpmineissues, @issue.erpmineissues do |issue_fields| %>
				<tr>
				<td style="padding-left:40px;"><%= issue_fields.select :currency, wkexpense_helper.options_for_currency %></td>
				<td style="padding-left:40px;"><%= issue_fields.text_field :rate %> </td>
				<td style="padding-left:40px;"><%= issue_fields.select :rate_per, wkasset_helper.getRatePerHash(false).invert %></td>
				</tr>
			<% end %>
		</table>
	<% end %>	
		<table style="padding-left:35px;">
		<tr>
				<th align="left" ><%= l(:label_additional_assignee) %></th>
				<td align="left">
					<%=h select_tag('wk_issue_assignee', options_for_select((memberArr.blank? ? [] : memberArr), :selected => @issue.assignees.map { |a| a.user_id }), :size => 5, :multiple=> true) %>
				</td>
			</tr>
		</table>
		
	</fieldset>
<% end %>