<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
	<meta http-equiv="Content-type" content="application/vnd.ms-excel; charset=UTF-8">
</head>
<body>
<div class="span12">
<% unless @sale_data.blank? %>

<table class="table table-striped" id="items_table" border="0">
  <thead>

	<% if !params[:from].blank?%>
    <tr>
        <th colspan="7">From Date : <%= params[:from] %>	,	To Date : <%= params[:to] %></th>
	</tr>
	<% end %>
	<% if @shift_from %>
	<tr>
		<% if @shift_data.employee %>		
			<% cashier_name = !@shift_data.nil? ? @shift_data.employee.name : '-' %>
		<% end %>			
		<th colspan="7">Shift Name =  <%= @shift_from %> - <%= @shift_to %> ( <%= cashier_name %> )</th>
    </tr>
	<% end %>
	<tr>
		<th>&nbsp;</th>
		<th>Menu Category</th>
		<th>Code</th>
		<th>Product</th>
		<th>Total Item</th>
		<th>Unit Price</th>
 	 <th>Revenue</th>
	</tr>	
  </thead>
  <tbody>
	  
	  <% acc_arr = Array.new %>
	  <% cate_arr = Array.new %>	  

	  <% sub_total = 0.0 %>
	  <% count = 0%>
	  <% total_price = 0.0 %>
	  <% cate_count = 0 %>
	  <% acc_count = 0%>
	  <% grand_total = 0%>
	  <% total_discount = 0.0 %>
	
	<% @sale_data.order("total_item desc").each do |sale| %>
	
	<tr>
		<td>&nbsp;</td>
		<% if !cate_arr.include?(sale.menu_category_id) %>	
			<td><%= sale.menu_category_name %></td>
			<% cate_arr.push(sale.menu_category_id) %>
		<% else %>
			<td>&nbsp;</td>
		<% end %>
		<td><%= sale.code rescue '-' %></td>
		<% if @item_table == 'sale' %>
			<% if sale.item_remark == 'FOC' %>
				<td><%= '[PROMO] '.to_s + sale.product_name.to_s rescue '-' %></td>
			<% elsif sale.item_remark == 'FOC ITEM' %>
				<td><%= '[DIS:QTY] '.to_s + sale.product_name.to_s rescue '-' %></td>
			<% elsif sale.item_remark == 'DISCOUNT' %>
				<td><%= '[DIS:TP] '.to_s + sale.product_name.to_s rescue '-' %></td>
			<% else %>
				<td><%= sale.product_name.to_s rescue '-' %></td>
			<% end %>
			<% if sale.item_remark == 'DISCOUNT' %>
				<td> - </td>
				<td> - </td>
				<td><%= sale.total_price.abs rescue '-' %></td>
				<% total_price += sale.total_price %>
			<% else %>
				<td><%= sale.total_item.abs rescue '-' %></td>
				<td><%= sale.unit_price rescue '-' %></td>
				<td><%= sale.grand_total.abs rescue '-' %></td>
			<% end %>
		<% else %>
			<td><%= sale.product_name.to_s rescue '-' %></td>
			<td><%= sale.total_item.abs rescue '-' %></td>
			<td><%= sale.unit_price rescue '-' %></td>
			<td><%= sale.grand_total.abs rescue '-' %></td>
		<% end %>
	</tr>
	
	<!-- sub total -->
	
	<!-- end sub total -->
	<% grand_total += sale.grand_total%>	  
	<% end %>
	<tr>
		<td colspan="5">&nbsp;</td>
		<td>Grand Total</td>
		<td><span class="double_underline"><%= grand_total + total_discount %></span></td>
	</tr>
  </tbody>
</table>
<% end %>
</div>
</body>
</html>