<tr onclick="  row_id  = this.rowIndex ">
	<%
		inventoryTtem = entry.inventory_item
		productItem = inventoryTtem&.product_item || ''
		isDisable = entry.id.present? || @materialID.present?
		productItemArr = []
		itemObj = nil
		locationArr =  WkLocation.order(:name).pluck(:name, :id)
		locationId = entry.location_id.present? ? entry.location_id : (locationArr.present? ? locationArr[0][1] : '')
		productArr = WkInventoryItem.getProduct.collect {|t| [t.name , t.id] }
		productId = productItem.present? ? productItem&.product_id : (productArr.present? ? productArr[0][1] : '')
		WkInventoryItem.getProductItem(productId, locationId).each do |item|
			name = item.product_item.brand.name + '-' + item.product_item.product_model.name + '-' + (item.currency.to_s() + ' ' +  item.selling_price.to_s()) +' - '+ (item.serial_number.to_s() + item.running_sn.to_s())
			productItemArr << [name , item.id]
		end
		inventory_id = entry&.inventory_item&.id.present? ? entry&.inventory_item.id : (productItemArr.present? ? productItemArr[0][1] : '')
		itemObj = WkInventoryItem.getProductDetails(inventory_id.to_i)&.first if inventory_id.present?
		wkexpense_helper = Object.new.extend(WkexpenseHelper)
		costPrice = inventoryTtem.blank? ? itemObj&.cost_price : inventoryTtem.cost_price
		sellPrice = entry.selling_price.blank? ? itemObj&.selling_price : entry.selling_price
		overhead = inventoryTtem.blank? ? itemObj&.over_head_price : inventoryTtem.over_head_price
		total_quantity = entry.total_quantity.blank? ? itemObj&.available_quantity : entry.total_quantity
	%>
	<% if @materialID.present? %>
		<td class="lbl-txt-align" headers="item_id">
			<%= hidden_field_tag("item_id_#{row_index}", entry.id ) %>
		</td>

		<td class="lbl-txt-align" headers="item_index">
			<label id="item_index_<%= row_index.to_s %>"><%= row_index %></label>
		</td>

		<td class="lbl-txt-align" headers="location_id">
			<%= hidden_field_tag("location_id_#{row_index}", entry.location_id, id: "hidden" ) %>
			<%= select_tag("location_id_#{row_index.to_s}", options_for_select(locationArr, selected: (entry.blank? ? locationArr : entry.location_id) ), onchange: "locationChanged(this.id, #{User.current.id}); ", disabled: isDisable, style: "width: 80px;", required: true) %>
		</td>

		<td class="lbl-txt-align" headers="product_id">
			<%= hidden_field_tag("product_id_#{row_index}", productId, id: "hidden" ) %>
			<%= select_tag("product_id_#{row_index.to_s}", options_for_select(productArr, selected: productId), onchange: "productChanged(this.id, 'product_item_id_#{row_index.to_s}', #{User.current.id}, true, false, null, 'location_id_#{row_index.to_s}');setUOMValue(this.id)", disabled: isDisable, style: "width: 80px;") %>
		</td>

		<td class="lbl-txt-align" headers="product_item_id">
			<%= hidden_field_tag("product_item_id_#{row_index}", entry.inventory_item_id, id: "hidden" ) %>
			<%= select_tag("product_item_id_#{row_index.to_s}", options_for_select(productItemArr, selected: entry.blank? ? productItemArr : entry.inventory_item_id), onchange: "deliveryitemChanged(this.id);", disabled: isDisable, required: true, style: "width: 300px;", required: true) %>
		</td>

		<td headers="serial_number">
			<%= hidden_field_tag("serial_number_#{row_index}", entry.serial_number || itemObj&.serial_number, id: "hidden" ) %>
			<%= text_field_tag "serial_number_#{row_index}",  entry.serial_number || itemObj&.serial_number, required: false, disabled: isDisable, style: "width: 140px;margin-top: 17px;" %>
			<p style="text-align: center;color: grey;"><%= l(:label_fixed) %></p>
		</td>

		<td headers="serial_number">
			<%= hidden_field_tag("running_sn_#{row_index}", entry.running_sn || itemObj&.running_sn, id: "hidden" ) %>
			<%= text_field_tag "running_sn_#{row_index}",  entry.running_sn || itemObj&.running_sn, required: false, disabled: isDisable, style: "width: 140px;margin-top: 17px;" %>
			<p style="text-align: center;color: grey;"><%= l(:label_running) %></p>
		</td>

		<td class="lbl-txt-align" headers="notes">
			<%= hidden_field_tag("notes_#{row_index}", entry.notes || itemObj&.notes, id: "hidden" ) %>
			<%= text_field_tag "notes_#{row_index}",  entry.notes || itemObj&.notes, required: false, disabled: isDisable, style: "width: 150px;" %>
		</td>

		<td class="lbl-txt-align" headers="currency">
			<%= hidden_field_tag("currency_#{row_index}", entry.currency, id: "hidden" ) %>
			<%= select_tag("currency_#{row_index}",options_for_select(wkexpense_helper.options_for_currency, selected: entry.blank? ? Setting.plugin_redmine_wktime['wktime_currency'] : entry.currency), disabled: isDisable, style: "width: 100%;") %>
		</td>

		<td headers="cost_price">
			<label id="cost_price_<%= row_index.to_s %>"><%= costPrice.blank? ? "" : ("%.2f" % costPrice) %></label>
		</td>

		<td class="lbl-txt-align" headers="selling_price">
			<%= hidden_field_tag("selling_price_#{row_index}", sellPrice.blank? ? "" : ("%.2f" % sellPrice), id: "hidden" ) %>
			<%= text_field_tag "selling_price_#{row_index}", sellPrice.blank? ? "" : ("%.2f" % sellPrice), maxlength: 14, size: "#{controller.textfield_size}", disabled: isDisable %>
		</td>

		<td headers="over_head_price">
			<label id="over_head_price_<%= row_index.to_s %>"><%= overhead.blank? ? "" : ("%.2f" % overhead) %></label>
		</td>

		<td class="lbl-txt-align" headers="total_quantity">
			<%= hidden_field_tag("total_quantity_#{row_index}", total_quantity.blank? ? "" : ("%.2f" % total_quantity), id: "hidden" ) %>
			<%= text_field_tag "total_quantity_#{row_index}", total_quantity.blank? ? "" : ("%.2f" % total_quantity), maxlength: 14, size: "3", disabled: isDisable, required: true %>
		</td>

		<td class="lbl-txt-align" headers="uom_id">
			<%= select_tag("uom_id_#{row_index.to_s}", generic_options_for_select(WkMesureUnit, nil, 'short_desc', 'short_desc', 'id', inventoryTtem.blank? ? itemObj&.uom_id : inventoryTtem.uom_id, false), disabled: isDisable, style: "width: 80px;") %>
		</td>

		<td class="lbl-txt-align" headers="project_id">
			<%= hidden_field_tag("project_id_#{row_index}", entry.project_id, id: "hidden" ) %>
			<%= select_tag("project_id_#{row_index.to_s}", options_for_select(getProjects, selected: entry.project_id), disabled: isDisable, style: "width: 80px;") %>
		</td>
		<td></td>
	<% else %>
		<td class="lbl-txt-align" headers="item_id">
			<%= hidden_field_tag("item_id_#{row_index}", entry.id ) %>
		</td>

		<td class="lbl-txt-align" headers="item_index">
			<label id="item_index_<%= row_index.to_s %>"><%= row_index %></label>
		</td>

		<td class="lbl-txt-align" headers="location_id">
			<%= select_tag("location_id_#{row_index.to_s}", options_for_select(locationArr, selected: (entry.blank? ? locationArr : entry.location_id) ), onchange: "locationChanged(this.id, #{User.current.id}); ", disabled: isDisable, style: "width: 80px;", required: true) %>
		</td>

		<td class="lbl-txt-align" headers="product_id">
			<%= select_tag("product_id_#{row_index.to_s}", options_for_select(productArr, selected: productId), onchange: "productChanged(this.id, 'product_item_id_#{row_index.to_s}', #{User.current.id}, true, false, null, 'location_id_#{row_index.to_s}');setUOMValue(this.id)", disabled: isDisable, style: "width: 80px;") %>
		</td>

		<td class="lbl-txt-align" headers="product_item_id">
			<%= select_tag("product_item_id_#{row_index.to_s}", options_for_select(productItemArr, selected: entry.blank? ? productItemArr : entry.inventory_item_id), onchange: "deliveryitemChanged(this.id);", disabled: isDisable, required: true, style: "width: 300px;", required: true) %>
		</td>

		<td headers="serial_number">
			<%= text_field_tag "serial_number_#{row_index}",  entry.serial_number || itemObj&.serial_number, required: false, disabled: isDisable, style: "width: 140px;margin-top: 17px;" %>
			<p style="text-align: center;color: grey;"><%= l(:label_fixed) %></p>
		</td>

		<td headers="serial_number">
			<%= text_field_tag "running_sn_#{row_index}",  entry.running_sn || itemObj&.running_sn, required: false, disabled: isDisable, style: "width: 140px;margin-top: 17px;" %>
			<p style="text-align: center;color: grey;"><%= l(:label_running) %></p>
		</td>

		<td class="lbl-txt-align" headers="notes">
			<%= text_field_tag "notes_#{row_index}",  entry.notes || itemObj&.notes, required: false, disabled: isDisable, style: "width: 150px;" %>
		</td>

		<td class="lbl-txt-align" headers="currency">
			<%= select_tag("currency_#{row_index}",options_for_select(wkexpense_helper.options_for_currency, selected: entry.blank? ? Setting.plugin_redmine_wktime['wktime_currency'] : entry.currency), disabled: isDisable, style: "width: 100%;") %>
		</td>

		<td headers="cost_price">
			<label id="cost_price_<%= row_index.to_s %>"><%= costPrice.blank? ? "" : ("%.2f" % costPrice) %></label>
		</td>

		<td class="lbl-txt-align" headers="selling_price">
			<%= text_field_tag "selling_price_#{row_index}", sellPrice.blank? ? "" : ("%.2f" % sellPrice), maxlength: 14, size: "#{controller.textfield_size}", disabled: isDisable %>
		</td>

		<td headers="over_head_price">
			<label id="over_head_price_<%= row_index.to_s %>"><%= overhead.blank? ? "" : ("%.2f" % overhead) %></label>
		</td>

		<td class="lbl-txt-align" headers="total_quantity">
			<%= text_field_tag "total_quantity_#{row_index}", total_quantity.blank? ? "" : ("%.2f" % total_quantity), maxlength: 14, size: "3", disabled: isDisable, required: true %>
		</td>

		<td class="lbl-txt-align" headers="uom_id">
			<%= select_tag("uom_id_#{row_index.to_s}", generic_options_for_select(WkMesureUnit, nil, 'short_desc', 'short_desc', 'id', inventoryTtem.blank? ? itemObj&.uom_id : inventoryTtem.uom_id, false), disabled: isDisable, style: "width: 80px;") %>
		</td>

		<td class="lbl-txt-align" headers="project_id">
			<%= select_tag("project_id_#{row_index.to_s}", options_for_select(getProjects, selected: entry.project_id), disabled: isDisable, style: "width: 80px;") %>
		</td>

		<td>
			<% unless isDisable || !controller.hasDeletePermission %>
				<%= link_to image_tag('delete.png'), "javascript:deleteRow('deliveryTable', 'totalrow');", id: row_index, data: {confirm: l(:text_are_you_sure)}, title: l(:button_delete) %>
			<% end %>
		</td>
		<%= hidden_field_tag("org_currency_#{row_index}", entry.id ) %>
		<%= hidden_field_tag("org_selling_price_#{row_index}", entry.id ) %>
	<% end %>
</tr>