<!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="row">
	<div class="col-md-12">
		<div class="margin-top-20">
			<div class="card">
				<div class="table-responsive">				
					<table class="table table-striped" id="items_table" border="0">
						<thead>
							<tr>
								<th>&nbsp;</th>
								<th><%= t("views.right_panel.header.menu_category") %></th>
								<th><%= t("views.right_panel.detail.code") %></th>
								<th><%= t("views.right_panel.detail.product") %></th>
								<th><%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.item") %></th>
								<!-- <th><%= t("views.right_panel.detail.unit_price") %></th> -->
								<th><%= t("views.right_panel.detail.total") %></th>
							</tr>	
						</thead>
						<tbody>
							<% unless @sale_data.blank? %>
								<% acc_arr = Array.new %>
								<% cate_arr = Array.new %>	
								<% grand_total = 0 %>
								<% total_qty = 0 %>
								<% total_item = {} %>
								<% total_data = {} %>
								<% @sale_data.each do |sale| 
									if !total_item.has_key?(sale.item_code)
										grand_total += sale.grand_total
										total_item[sale.item_code] = sale.total_item
										total_data[sale.item_code] = sale.grand_total
									else
										if sale.status_type == "void"
											total_item[sale.item_code] += sale.total_item
										end
										if sale.status_type == "void" || sale.status_type == "Discount" || sale.status_type == "foc" 
											total_data[sale.item_code] += sale.grand_total
											grand_total += sale.grand_total
										end 
									end 
								end %>

								<% @sale_data.each do |sale| %>
									<% if sale.status_type != "Discount" && sale.status_type != "foc" && sale.status_type != "promotion"
										total_qty += sale.total_item
									end %>
									<% if sale.status_type == "foc" && sale.price > 0
										total_qty += sale.total_item
									end %>

									<% if sale.status_type != "Discount" && sale.price.to_f >= 0 %>
										<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 %>
												<% if sale.total_item > 0 %>
													<% cate_arr = Array.new %>
												<% end %>
											<td>&nbsp;</td>
											<% end %>
											<td><%= sale.item_code rescue '-' %></td>
											<td><%= sale.product_name rescue '-' %></td>
											<td><%= total_item[sale.item_code] rescue ' ' %></td>
											<!-- <td><%= sale.unit_price rescue ' ' %></td> -->
											<td><%= total_data[sale.item_code] rescue ' ' %></td>
										</tr>
										<!-- sub total -->
									<!-- end sub total -->
									<% end %>
								<% end %>
								<tr>
									<td colspan="3"></td>
									<td><strong>Total</strong></td>
									<td><strong><%= total_qty rescue ' ' %></strong></td>
									<td><strong><%= grand_total rescue ' ' %></strong></td>
								</tr>								
							<% end %>		
						</tbody>
					</table>
				</div>
			</div>
		</div>
	</div>
</div>
</body>
</html>