<!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="margin-top-20">
	<div class="card ">
		<% unless @sale_data.blank? %>

			<table class="table table-striped" border="0">
			  <thead>
				<% if !params[:from].blank?%>
			    <tr>
			        <th colspan="7"><%= t("views.right_panel.detail.from_date") %> : <%= params[:from]  rescue '-'%>	,	<%= t("views.right_panel.detail.to_date") %> : <%= params[:to]  rescue '-'%></th>
				</tr>
				<% end %>		  
				<tr>
					<th> <%= t("views.right_panel.detail.shift_name") %> </th>
				  	<th> <%= t("views.right_panel.detail.receipt_no") %></th>
				  	<th><%= t("views.right_panel.detail.order_source") %></th>
				   	<th> <%= t :cashier %> <%= t("views.right_panel.detail.name") %></th>
				  	<th> <%= t :customer %> <%= t("views.right_panel.detail.name") %></th>
				  	<th> <%= t("views.right_panel.detail.credit_amount") %> </th>
				  	<th> <%= t :credit %> <%= t :payment %> <br>
				  		<%= t("views.right_panel.detail.shift_name") %></th>
				  	<th> <%= t :credit %> <%= t("views.right_panel.detail.receipt_date") %></th>
				  	<th> <%= t :credit %> <%= t :payment %> <br> <%= t :cashier_name %></th>
				  	<th> <%= t :credit %> <%= t :payment %> <%= t("views.right_panel.detail.amount") %></th>
				</tr>
			  </thead>
			  <tbody>
			  	<% total_credit_amount = 0
			  	   total_credit_payment = 0 %>
				<% @sale_data.each do |credit| %>			
					<% total_credit_amount += credit.payment_amount
			  	   		total_credit_payment += credit.credit_payment %>
					<tr> 
					 	<% if @shift_from.nil? && @shift_to.nil? %>
							<td><%= credit.sale_date.utc.getlocal.strftime("%e %b %I:%M%p")  rescue '-'%></td>
						<% else %>
							<td><%= @shift_from  rescue '-'%> -  <%= @shift_to   rescue '-'%></td>
						<% end %>
						<td><%= credit.receipt_no rescue '-' %></td>
						<td>
							<%if credit.order_source == "cashier" || credit.order_source == "emenu" %>
                            	Cashier
                          	<% elsif credit.order_source == "quick_service" %>
                            	Quick Service
                          	<% else %>
                            	Online Order
                          	<% end %> 
						</td>
						<td><%= credit.cashier_name rescue '-' %></td>
						<td><%= credit.sale.customer.name rescue '-' %></td>
						<td><%= credit.payment_amount rescue '-' %></td>
						<td>
							<%if credit.credit_payment_shift_name == '-' %>
								<%= credit.sale_date.utc.getlocal.strftime("%e %b %I:%M%p")  rescue '-'%>
							<% else %>
								<%= credit.credit_payment_shift_name rescue '-' %>
							<% end %>
						</td>
						<td><%= credit.credit_payment_receipt_date rescue '-' %></td>
						<td><%= credit.credit_payment_cashier_name rescue '-' %></td>
						<td><%= credit.credit_payment rescue '-' %></td>
				  </tr>
				<% end %>
				<tr>
					<td colspan="5"><b>Total</b></td>
					<td colspan="4"><b><%= total_credit_amount rescue '-' %></b></td>
					<td><b><%= total_credit_payment rescue '-' %></b></td>
				</tr>
			  </tbody>
			</table>
		<% end %>
	</div>
</div>
</body>
</html>