<%= stylesheet_link_tag 'application' , :media => "all" %>
<%= stylesheet_link_tag 'wk-time', :plugin => "redmine_wktime" %>
<% show_on_map = session[controller_name].try(:[], :show_on_map) %>
<div class="autoscroll" >
	<% headerHash = controller.getIventoryListHeader  %>
	<% ratePerHash = getRatePerHash(false) %>
	<% assetTypeHash = getAssetTypeHash(false) %>
	<table class="list time-entries" style="width:<%= !show_on_map ? "100%" : "35%" %>; float:left;">
		<thead>
			<tr>
				<%headerHash.each do |key, header|%>
					<% if action_name == 'index' && ( show_on_map && (["owner_type", "is_loggable", "project_name", "asset_name"].include? key) )%>
						<%= sort_header_tag(key, :caption => header, class: "lbl-txt-align") %>
					<% elsif action_name == 'index' && !show_on_map %>
						<%= sort_header_tag(key, :caption => header, class: "lbl-txt-align") %>
					<% elsif action_name != 'index'  %>
						<th class="lbl-txt-align"><%= header %></th>
					<%end%>
				<%end%>
				<th></th>
			</tr>
		</thead>
		<tbody>
			<% @productInventory.each do |entry| %>
				<% inventoryID = entry.id.blank? ? (entry.parent_id.blank? ? entry.inventory_item_id : entry.parent_id) : entry.id %>
				<% productItemID = entry.id.blank? ? (entry.parent_product_item_id.blank? ? entry.inv_product_item_id || entry.product_item_id : entry.parent_product_item_id) : entry.product_item_id %>
				<tr>
					<% headerHash.keys.each do |colName|%>
						<% if ((colName == "rate" || colName == "current_value") && !show_on_map) %>
							<% ratePer = entry.id.blank? ? ratePerHash[entry['rate_per']] : ratePerHash[entry.asset_property['rate_per']] %>
							<td class="lbl-txt-align"><%=h (entry.id.blank? ? entry.asset_currency : entry.asset_property.currency).to_s + " "  %><%=h entry.id.blank? ? entry[colName] : entry.asset_property[colName] %><%=h " " + ratePer.to_s %></td>
						<% elsif colName == "owner_type" %>
							<td class="lbl-txt-align"><%=h entry.id.blank? ? assetTypeHash[entry[colName]] : assetTypeHash[entry.asset_property[colName]]  %></td>
						<% elsif colName == "is_loggable" %>
							<td class="lbl-txt-align"><%=h checked_image entry.is_loggable?  %></td>
						<% elsif (colName == "product_name" && !show_on_map) %>
							<td class="lbl-txt-align"><%=h entry.id.blank? ? entry[colName] : entry.product_item.product.name  %></td>
						<% elsif (colName == "parent_name" && !show_on_map) %>
							<% appartmentName = entry["parent_name"].blank? ? entry["asset_name"] : entry[colName] %>
							<td class="lbl-txt-align"><%=h entry.id.blank? ? appartmentName : (entry.parent.blank? ? "" : entry.parent.assetName) %></td>
						<% elsif colName == "asset_name" %>
							<% bedName = entry["parent_name"].blank? ? '' : entry[colName] %>
							<td class="lbl-txt-align"><%=h entry.id.blank? ? bedName : entry.assetName  %></td>
						<% elsif (colName == "product_attribute_name" && !show_on_map) %>
							<td class="lbl-txt-align"><%=h entry.id.blank? ? entry[colName] : (entry.product_attribute.blank? ? "" : entry.product_attribute.name)  %></td>
						<% elsif (colName == "location_name" && !show_on_map) %>
							<td class="lbl-txt-align"><%=h entry.id.blank? ? entry[colName] : (entry.location.blank? ? "" : entry.location.name)  %></td>
						<% elsif colName == "project_name" %>
							<td class="lbl-txt-align"><%=h entry.id.blank? ? entry[colName] : (entry.project.blank? ? "" : entry.project.name)  %></td>
						<% elsif colName == "serial_number" && controller.getItemType == 'I' %>
							<td class="lbl-txt-align"><%= (entry['serial_number'] || '').to_s +  (entry['running_sn'] || '').to_s %></td>
						<% elsif !show_on_map %>
							<td class="lbl-txt-align"><%=h entry[colName] %></td>
						<% end %>
					<%end%>
					  <td align="center">
						  <%= link_to image_tag('edit.png'), {:controller => controller.controller_name, :action => 'edit', :inventory_item_id => inventoryID, :product_item_id => productItemID, id: inventoryID}, :title => l(:button_edit) %>
						  <% if controller.hasDeletePermission %>
							<%= link_to image_tag('delete.png'), {:controller => controller.controller_name, :action => 'destroy', :inventory_item_id => inventoryID, :product_item_id => entry.product_item_id, :tab => controller.controller_name},  :data => {:confirm => l(:text_are_you_sure)}, :method => :delete, :title => l(:button_delete) %>
						  <% end %>
					  </td>
				</tr>
			<% end %>
		</tbody>
	</table>

	<% if show_on_map && params[:controller] == 'wkasset' %>
		<%= render partial: "wkgeolocation/show_on_map", locals: { entries: @productInventory, model: "assets", height: '94%', width: '64%'} %>
	<% end %>
</div>

