<!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" border="0">
						<thead>
						  	<tr>
								<th colspan="7"> <%= t("views.right_panel.detail.from_date") %> : <%= @from.strftime("%Y-%b-%d") rescue '-' %>  - <%= t("views.right_panel.detail.to_date") %> : <%= @to.strftime("%Y-%b-%d")  rescue '-'%>
								</th>
							</tr>
							<% if @shift_from %>
								<tr>
									<% if @shift_data.employee %>
									<% cashier_name = !@shift_data.nil? ? @shift_data.employee.name : '-' %>
									<% end %>
									<th colspan="7"><%= t("views.right_panel.detail.shift_name") %> =  <%= @shift_from %> - <%= @shift_to %> ( <%= cashier_name %> )</th>
								</tr>
							<% end %>
                <tr>
				        	<th><b><%= t("views.right_panel.detail.receipt_no") %></b></th>
									<th><b><%= t("views.right_panel.detail.receipt_date") %></b></th>
									<th><b><%= t("views.right_panel.detail.shift_name") %></b></th>
									<th><b><%= t :cashier %></b></th>
									<th><b><%= t("views.right_panel.detail.table") %></b></th>
					        <th><b><%= t("views.right_panel.detail.revenue") %></b></th>
								<th>&nbsp;</th>
						    </tr>
						</thead>
						<tbody>
							<% grand_total = 0 %>
						    <% @sale_data.each do |result| %>
							<% grand_total = grand_total.to_f + result.grand_total.to_f%>
                <tr style="border-top:4px double #666;">
									<td><%= result.receipt_no rescue '-' %> </td>
									<td><%=l result.receipt_date.getlocal, :format => :short rescue '-' %> </td>
									<td><%= @shift_from %> -  <%= @shift_to  %></td>
									<td><%= result.cashier_name rescue '-' %></td>
									<td><%= result.table_type %> -  <%= result.table_name  %></td>
				  		  	<td><%= number_format(result.grand_total, precision: precision, delimiter: delimiter) %></td>
								</tr>

                <tr>
									<th>&nbsp;</th>
									<th><b><%= t("views.right_panel.detail.product") %></b></th>
									<th><b><%= t("views.right_panel.detail.qty") %></b></th>
									<th><b><%= t("views.right_panel.detail.unit_price") %></b></th>
									<th><b><%= t("views.right_panel.detail.total_price") %></b></th>
								</tr>

								<% result.sale_items.each do |item|%>
									<tr>
                    <td>&nbsp;</td>
										<td>
											<% if item.price.to_i < 0.to_i %>
												<% if item.qty.to_i < 0.to_i%>
													[PROMO QTY]<%= item.product_name rescue '-' %>
												<% else %>
													[PROMO PRICE]<%= item.product_name rescue '-' %>
												<% end %>
											<% else %>
												<%= item.product_name rescue '-' %>
											<% end %>
										</td>
										<td><%= item.qty rescue '-' %></td>
										<td><%= item.unit_price rescue '-' %></td>
										<td><%= item.price rescue '-' %></td>
									</tr>
								<% end %>

								<tr><td colspan="6">&nbsp;</td></tr>

								<%survey = Survey.find_by_receipt_no(result.receipt_no)%>
								<% if !survey.nil?%>
									<tr>
									    <td>&nbsp;</td>
									    <td>&nbsp;</td>
                      <td>&nbsp;</td>
									    <td>No. of Guest</td>
									    <td><%= survey.total_customer rescue '-' %></td>
									    <td>&nbsp;</td>
									</tr>
								<% end %>

								<% if !result.total_amount.nil?%>
									<tr>
										<td>&nbsp;</td>
										<td>&nbsp;</td>
                    <td>&nbsp;</td>
										<td><%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.amount") %></td>
										<td><%= result.total_amount %></td>
										<td>&nbsp;</td>
									</tr>
								<% end %>

								<% if result.total_discount.to_f > 0 %>
									<tr>
										<td>&nbsp;</td>
										<td>&nbsp;</td>
                    <td>&nbsp;</td>
										<td><%= t("views.right_panel.detail.total") %>
											<%= t("views.right_panel.detail.discount") %>
											<%= t("views.right_panel.detail.amount") %></td>
										<td> - <%= result.total_discount %> </td>
										<td>&nbsp;</td>
									</tr>
								<% end %>

								<% if !result.total_tax.nil? %>
									<tr>
										<td>&nbsp;</td>
										<td>&nbsp;</td>
                    <td>&nbsp;</td>
										<td>Tax Amount </td>
										<td><%= result.total_tax %> </td>
										<td>&nbsp;</td>
									</tr>
								<% end %>

								<% sale_payments = result.sale_payments %>
								<% if sale_payments.length > 0%>
									<% sale_payments.each do |rec| %>
										<%if rec.payment_amount.to_f > 0 %>
											<tr>
												<td>&nbsp;</td>
												<td>&nbsp;</td>
                        <td>&nbsp;</td>
												<td>Payment <%= rec.payment_method.upcase %>( <%= rec.payment_status %> )</td>
												<td><%= rec.payment_amount %></td>
												<td>&nbsp;</td>
											</tr>

											<% if !rec.payment_reference.nil? %>
												<tr>
													<td>&nbsp;</td>
													<td>&nbsp;</td>
                          <td>&nbsp;</td>
													<td>Payment Ref.</td>
													<td><%= rec.payment_reference %></td>
													<td>&nbsp;</td>
												</tr>
											<% end %>
										<% end %>
									<% end %>
									<% if result.amount_changed != 0 && !result.amount_changed.nil? %>
										<tr>
											<td>&nbsp;</td>
											<td>&nbsp;</td>
                      <td>&nbsp;</td>
											<td><%= t("views.right_panel.detail.change") %> <%= t("views.right_panel.detail.amount") %></td>
											<td><%= result.amount_changed %></td>
											<td>&nbsp;</td>
										</tr>
									<% end %>
									<% if !result.customer_id.nil?%>
										<tr>
											<td>&nbsp;</td>
											<td>&nbsp;</td>
                      <td>&nbsp;</td>
											<td>Customer</td>
											<td><%= result.customer_name rescue '-'%>
                        <% if result.customer_company.present? %>
                        (<%= result.customer_company rescue '-' %>)
                        <% end %>
									    </td>
											<td>&nbsp;</td>
										</tr>
									<% end %>
                  <tr><td colspan="6">&nbsp;</td></tr>
								<% end %>
						    <% end %>
							<tr style="border-top:4px double #666;">
								<td>&nbsp;</td>
								<td>&nbsp;</td>
								<td>&nbsp;</td>
                <td>&nbsp;</td>
								<td><b>Total Nett</b> - <b><%= grand_total %></b></td>
								<td>&nbsp;</td>
							</tr>
						  </tbody>
						</table>
				</div>
			</div>
		</div>
	</div>
</div>
</body>
</html>
