<!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">
				<table class="table table-striped" border="0">
					<thead>
						<tr>
							<th colspan="9"> <%= 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="9"><%= t("views.right_panel.detail.shift_name") %> =  <%= @shift_from %> - <%= @shift_to %> ( <%= cashier_name %> )</th>
						</tr>
						<% end %>
						<tr>
							<th><%= t("views.right_panel.detail.dining") %></th>
							<th><%= t("views.right_panel.detail.receipt_no") %></th>
              <th><%= t :customer %></th>
							<th><%= t :cashier %></th>
							<th><%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.amount") %></th>
							<th><%= t("views.right_panel.detail.discount") %> <%= t("views.right_panel.detail.amount") %> </th>
							<% @tax_profiles.each do |tax| %>
							<th><%= tax.name %></th>
							<% end %>
							<!-- <th>Other Amount</th> -->
							<th><%= t("views.right_panel.detail.grand_total") %></th>
							<th><%= t("views.right_panel.detail.rnd_adj_sh") %></th>
							<th><%= t("views.right_panel.detail.grand_total") %> +<br/>
								<%= t("views.right_panel.detail.rnd_adj_sh") %>
							</th>
						</tr>
					</thead>
					<tbody>

						<% grand_total = 0 %>
						<% old_grand_total = 0 %>
						<% after_rounding = 0 %>
						<% total_tax = 0 %>
						<% guest_count = 0 %>
						<% total_sum = 0 %>
						<% discount_amt = 0 %>
						<% other_amt = 0 %>
						<% total_nett = 0 %>
						<% rounding_adj = 0%>
            <% gov_tax = 0 %>
            <% service_charge = 0 %>

						<% if @sale_data %>
						<% @sale_data.each do |result| %>

						<% grand_total +=  result.grand_total.to_f %>
						<% old_grand_total += result.grand_total.to_f - result.rounding_adjustment.to_f %>
						<% total_tax += result.total_tax.to_f %>
						<% total_sum += result.total_amount.to_f %>
						<% discount_amt += result.total_discount.to_f %>
						<% rounding_adj += result.rounding_adjustment.to_f %>

						<tr>
							<td>
								<%if result.type %>
									<%= result.type %> - <%= result.name %>
								<% else %>
									-
								<% end %>
							</td>
							<td><%= result.receipt_no rescue '-' %> </td>
              <td><%= result.customer_name rescue '-' %></td>
							<td><%= result.cashier_name rescue '-' %></td>
							<td><%= number_format(result.total_amount, precision: precision.to_i, delimiter: delimiter) rescue '-' %></td>
							<td><%= number_format(result.total_discount, precision: precision.to_i, delimiter: delimiter) rescue '-' %></td>
              <% @tax_profiles.each do |tax| %>
                <% if sale_tax = result.sale_taxes.find { |sale_tax| sale_tax.tax_name == tax.name } %>
              <td><%= number_format(sale_tax.tax_payable_amount, precision: precision.to_i, delimiter: delimiter) rescue '-' %> </td>
                <% else %>
              <td><%= number_format(0, precision: precision.to_i, delimiter: delimiter) rescue '-' %></td>
                <% end %>
              <% end %>
              <td><%= number_format(result.grand_total - result.rounding_adjustment, precision: precision.to_i, delimiter: delimiter) rescue '-' %></td>
							<td><%= number_format(result.rounding_adjustment.to_f, precision: precision.to_i, delimiter: delimiter) rescue '-' %></td>
							<td><%= number_format(result.grand_total, precision: precision.to_i, delimiter: delimiter) rescue '-' %></td>
						</tr>
						<% end %>
            <tr/>
						<tr style="border-top:4px double #666;">
							<td colspan="4">&nbsp;</td>
							<td><b><%= number_format(total_sum, precision: precision.to_i ,delimiter: delimiter) rescue '-' %></b></td>
							<td><b><%= number_format(discount_amt, precision: precision.to_i ,delimiter: delimiter) rescue '-' %></b></td>
              <% @tax_profiles.each do |tax| %>
                <% if sale_tax = @sale_taxes.find { |sale_tax| sale_tax.tax_name == tax.name } %>
              <td><%= number_format(sale_tax.st_amount, precision: precision.to_i, delimiter: delimiter) rescue '-' %> </td>
                <% else %>
              <td><%= number_format(0, precision: precision.to_i, delimiter: delimiter) rescue '-' %></td>
                <% end %>
              <% end %>
              <td><b><%= number_format(old_grand_total.to_f, precision: precision.to_i, delimiter: delimiter) rescue '0'  %></b></td>
							<td><b><%= number_format(rounding_adj.to_f, precision: precision.to_i, delimiter: delimiter) rescue '-' %></b></td>
							<td><b><%= number_format(grand_total.to_f, precision: precision.to_i, delimiter: delimiter) rescue '-' %></b></td>
						</tr>
					<%end%>
					</tbody>
				</table>
			</div>
		</div>
	</div>
</div>
</body>
</html>
