<!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 col-lg-12">
			<div class="card" style="width:129%;">
				<div class="body table-responsive">
					<table class="table table-bordered">
						<thead> 
							<tr>
								<th colspan="15"> <%= t("views.right_panel.detail.from_date") %> : <%= @from.utc.getlocal.strftime("%Y-%b-%d") rescue '-' %>  - <%= t("views.right_panel.detail.to_date") %> : <%= @to.utc.getlocal.strftime("%Y-%b-%d")  rescue '-'%></th>
							</tr>
							<tr>
								<th style='text-align:center;'><%= t("views.right_panel.detail.sr") %></th>
								<th style='text-align:center;'><%= t("views.right_panel.detail.date") %></th>
								<th style='text-align:center;'><%= t("views.right_panel.detail.void_amount") %></th>
								<% if @payment_methods.include? ("MPU") %>
									<th style='text-align:center;' class='mobile'><%= t("views.right_panel.detail.mpu_sales") %></th>
								<% end %>
								<% if @payment_methods.include? ("Master") %>
									<th style='text-align:center;'><%= t("views.right_panel.detail.master_sales") %></th>
								<% end %>
								<% if @payment_methods.include? ("VISA") %>
									<th style='text-align:center;'><%= t("views.right_panel.detail.visa_sales") %></th>
								<% end %>
								<% if @payment_methods.include? ("JCB") %>
									<th style='text-align:center;'><%= t("views.right_panel.detail.jcb_sales") %></th>
								<% end %>
								<% if @payment_methods.include? ("UNIONPAY") %>
									<th style='text-align:center;'><%= t("views.right_panel.detail.unionpay_sales") %></th>
								<% end %>
								<% if @payment_methods.include? ("KBZPay") %>
									<th style='text-align:center;' class="d-none d-sm-table-cell"><%= t("views.right_panel.detail.kbzpay_sales") %></th>
								<% end %>
								<% if @payment_methods.include? ("Alipay") %>
									<th style='text-align:center;'><%= t("views.right_panel.detail.alipay_sales") %></th>
								<% end %>
								<% if @payment_methods.include? ("PAYMAL") %>
									<th style='text-align:center;'><%= t("views.right_panel.detail.paymal_sales") %></th>
								<% end %>
								<% if @payment_methods.include? ("DINGA") %>
									<th style='text-align:center;'><%= t("views.right_panel.detail.dinga_sales") %></th>
								<% end %>
								<% if @payment_methods.include? ("JunctionPay") %>
									<th style='text-align:center;'><%= t("views.right_panel.detail.junctionpay_sales") %></th>
								<% end %>
								<% if @payment_methods.include? ("Redeem") %>
									<th style='text-align:center;'><%= t("views.right_panel.detail.redeem_sales") %></th>
								<% end %>
								<th style='text-align:center;'><%= t("views.right_panel.detail.cash_sales") %></th>
								<th style='text-align:center;'><%= t("views.right_panel.detail.credit_sales") %></th>
								<th style='text-align:center;'><%= t("views.right_panel.detail.foc_sales") %></th>
								<% if @payment_methods.include? ("GiftVoucher") %>
									<th style='text-align:center;'><%= t("views.right_panel.detail.giftvoucher_sales") %></th>
								<% end %>
								<th style='text-align:center;'>(<%= t("views.right_panel.detail.discount") %>)</th>
								<!-- <th style='text-align:center;'><%= t("views.right_panel.detail.grand_total") %> + <br/> <%= t("views.right_panel.detail.rnd_adj_sh") %></th>    -->  
								<th style='text-align:center;'><%= t("views.right_panel.detail.grand_total") %></th>  
								<th style='text-align:center;'><%= t("views.right_panel.detail.rnd_adj_sh") %></th>

							</tr>
						</thead>
						<% if @print_settings.precision.to_i > 0
							precision = @print_settings.precision
						else
							precision = 0
						end
					    #check delimiter
					    if @print_settings.delimiter
					    	delimiter = ","
					    else
					    	delimiter = ""
					    end
					    %>	
					    <% unless @sale_data.empty? %>

					    <tbody>
					    	<% void   = 0 %>
					    	<% mpu    = 0 %>
					    	<% master = 0 %>
					    	<% visa   = 0 %>
					    	<% jcb    = 0 %>
					    	<% unionpay    	= 0 %>
					    	<% alipay    	= 0 %>
					    	<% paymal    	= 0 %>
					    	<% dinga    	= 0 %>
					    	<% junctionpay  = 0 %>
					    	<% giftvoucher  = 0 %>
					    	<% paypar = 0 %>
					    	<% cash   = 0 %>
					    	<% credit = 0 %>
					    	<% foc    = 0 %>
					    	<% discount = 0 %>
					    	<% kbzpay = 0 %>
					    	<% total    = 0 %>
					    	<% grand_total = 0 %> 
					    	<% old_grand_total = 0 %>  
					    	<% count = 1 %> <% rounding_adj = 0 %>
					    	<% @sale_data.each do |sale| %>
					    	<% void += sale[:void_amount] %>
					    	<% mpu += sale[:mpu_amount] %>
					    	<% master += sale[:master_amount] %>
					    	<% visa += sale[:visa_amount] %>
					    	<% jcb += sale[:jcb_amount] %>
					    	<% unionpay += sale[:unionpay_amount] %>
					    	<% alipay += sale[:alipay_amount] %>
					    	<% paymal += sale[:paymal_amount] %>
					    	<% dinga += sale[:dinga_amount] %>
					    	<% junctionpay += sale[:junctionpay_amount] %>
					    	<% giftvoucher += sale[:giftvoucher_amount] %>
					    	<% paypar += sale[:paypar_amount] %>
					    	<% cash += sale[:cash_amount]-sale[:total_change_amount] %>
					    	<% credit += sale[:credit_amount] %>   
					    	<% foc += sale[:foc_amount] %>
					    	<% discount += sale[:total_discount] %>
					    	<% kbzpay += sale[:kbzpay_amount] %>
					    	<% total += sale[:grand_total].to_f + sale[:rounding_adj].to_f  %>
					    	<% grand_total += sale[:grand_total].to_f  %>	
					    	<% old_grand_total += sale[:old_grand_total].to_f  %>	
					    	<% rounding_adj += sale[:rounding_adj].to_f %>	
					    	<tr>
					    		<td style='text-align:right;'><%= count %></td>
					    		<td><%= sale[:sale_date].strftime("#{sale[:sale_date].day.ordinalize} %b") rescue '-'  %></td>
					    		<td style='color:red;text-align:right;'><%= number_with_delimiter(sprintf("%.2f",sale[:void_amount]), delimiter => ',') rescue '-'%></td>
					    		<% if @payment_methods.include? ("MPU") %>
					    			<td style='text-align:right;'><%= number_with_delimiter(sprintf("%.2f",sale[:mpu_amount]),delimiter => ',') rescue '-'%></td>
					    		<% end %>
					    		<% if @payment_methods.include? ("Master") %>
					    			<td style='text-align:right;'><%= number_with_delimiter(sprintf("%.2f",sale[:master_amount]),delimiter => ',') rescue '-'%></td>
					    		<% end %>
					    		<% if @payment_methods.include? ("VISA") %>
					    			<td style='text-align:right;'><%= number_with_delimiter(sprintf("%.2f",sale[:visa_amount]),delimiter => ',') rescue '-'%></td>
					    		<% end %>
					    		<% if @payment_methods.include? ("JCB") %>
					    			<td style='text-align:right;'><%= number_with_delimiter(sprintf("%.2f",sale[:jcb_amount]),delimiter => ',') rescue '-'%></td>
					    		<% end %>
					    		<% if @payment_methods.include? ("UNIONPAY") %>
					    			<td style='text-align:right;'><%= number_with_delimiter(sprintf("%.2f",sale[:unionpay_amount]),delimiter => ',') rescue '-'%></td>
					    		<% end %>
					    		<% if @payment_methods.include? ("Alipay") %>
					    			<td style='text-align:right;'><%= number_with_delimiter(sprintf("%.2f",sale[:alipay_amount]),delimiter => ',') rescue '-'%></td>
					    		<% end %>
					    		<% if @payment_methods.include? ("KBZPay") %>
									<td style='text-align:right;' class="d-none d-sm-table-cell"><%= number_with_precision(sale[:kbzpay_amount], precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
								<% end %>
					    		<% if @payment_methods.include? ("PAYMAL") %>
					    			<td style='text-align:right;'><%= number_with_delimiter(sprintf("%.2f",sale[:paymal_amount]),delimiter => ',') rescue '-'%></td>
					    		<% end %>
					    		<% if @payment_methods.include? ("DINGA") %>
					    			<td style='text-align:right;'><%= number_with_delimiter(sprintf("%.2f",sale[:dinga_amount]),delimiter => ',') rescue '-'%></td>
					    		<% end %>
					    		<% if @payment_methods.include? ("JunctionPay") %>
					    			<td style='text-align:right;'><%= number_with_delimiter(sprintf("%.2f",sale[:junctionpay_amount]),delimiter => ',') rescue '-'%></td>
					    		<% end %>
					    		<% if @payment_methods.include? ("Redeem") %>
					    			<td style='text-align:right;'><%= number_with_delimiter(sprintf("%.2f",sale[:paypar_amount]),delimiter => ',') rescue '-'%></td>
					    		<% end %>
					    		<td style='text-align:right;'><%= number_with_delimiter(sprintf("%.2f",sale[:cash_amount]-sale[:total_change_amount]), delimiter: delimiter) rescue '-'%></td>
					    		<td style='text-align:right;'><%= number_with_delimiter(sprintf("%.2f",sale[:credit_amount]),delimiter => ',') rescue '-'%></td>
					    		<td style='text-align:right;'><%= number_with_delimiter(sprintf("%.2f",sale[:foc_amount]),delimiter => ',') rescue '-'%></td>    
					    		<% if @payment_methods.include? ("GiftVoucher") %>
					    			<td style='text-align:right;'><%= number_with_delimiter(sprintf("%.2f",sale[:giftvoucher_amount]),delimiter => ',') rescue '-'%></td>    
					    		<% end %>
					    		<td style='text-align:right;'>(<%= number_with_delimiter(sprintf("%.2f",sale[:total_discount]), delimiter => ',') rescue '-'%>)</td>
					    		<!-- <td style='text-align:right;'><%= number_with_delimiter(sale[:grand_total].to_f + sale[:rounding_adj].to_f ,delimiter => ',') rescue '-'%></td>   --> 
					    		<td style='text-align:right;'><%= number_with_delimiter(sprintf("%.2f",sale[:grand_total]),delimiter => ',') rescue '-'%></td>	 
					    		<td style='text-align:right;'><%= number_with_delimiter(sprintf("%.2f",sale[:rounding_adj].to_f),delimiter => ',') rescue '-'%></td>

					    	</tr>
					    	<% count = count + 1 %>
					    	<% end %>
					    	<% colspan = 7 %>
					    	<tr style="font-weight:600;">
					    		<td colspan="3" style='text-align:center;'>Total</td>	
					    		<% if @payment_methods.include? ("MPU") %>
					    			<% colspan += 1 %>
					    			<td style='text-align:right;'><%= number_with_delimiter(sprintf("%.2f",mpu),delimiter => ',') rescue '-'%></td>
					    		<% end %>
					    		<% if @payment_methods.include? ("Master") %>
					    			<% colspan += 1 %>
					    			<td style='text-align:right;'><%= number_with_delimiter(sprintf("%.2f",master),delimiter => ',') rescue '-'%></td>
					    		<% end %>
					    		<% if @payment_methods.include? ("VISA") %>
					    			<% colspan += 1 %>
					    			<td style='text-align:right;'><%= number_with_delimiter(sprintf("%.2f",visa), delimiter => ',') rescue '-'%></td>
					    		<% end %>
					    		<% if @payment_methods.include? ("JCB") %>
					    			<% colspan += 1 %>
					    			<td style='text-align:right;'><%= number_with_delimiter(sprintf("%.2f",jcb),delimiter => ',') rescue '-'%></td>
					    		<% end %>
					    		<% if @payment_methods.include? ("UNIONPAY") %>
					    			<% colspan += 1 %>
					    			<td style='text-align:right;'><%= number_with_delimiter(sprintf("%.2f",unionpay),delimiter => ',') rescue '-'%></td>
					    		<% end %>
					    		<% if @payment_methods.include? ("Alipay") %>
					    			<% colspan += 1 %>
					    			<td style='text-align:right;'><%= number_with_delimiter(sprintf("%.2f",alipay),delimiter => ',') rescue '-'%></td>
					    		<% end %>
					    		<% if @payment_methods.include? ("KBZPay") %>
					    			<% colspan += 1 %>
					    			<td style='text-align:right;'><%= number_with_delimiter(sprintf("%.2f",kbzpay),delimiter => ',') rescue '-'%></td>
					    		<% end %>
					    		<% if @payment_methods.include? ("PAYMAL") %>
					    			<% colspan += 1 %>
					    			<td style='text-align:right;'><%= number_with_delimiter(sprintf("%.2f",paymal),delimiter => ',') rescue '-'%></td>
					    		<% end %>
					    		<% if @payment_methods.include? ("DINGA") %>
					    			<% colspan += 1 %>
					    			<td style='text-align:right;'><%= number_with_delimiter(sprintf("%.2f",dinga),delimiter => ',') rescue '-'%></td>
					    		<% end %>
					    		<% if @payment_methods.include? ("JunctionPay") %>
					    			<% colspan += 1 %>
					    			<td style='text-align:right;'><%= number_with_delimiter(sprintf("%.2f",junctionpay),delimiter => ',') rescue '-'%></td>
					    		<% end %>
					    		<% if @payment_methods.include? ("Redeem") %>
					    			<% colspan += 1 %>
					    			<td style='text-align:right;'><%= number_with_delimiter(sprintf("%.2f",paypar),delimiter => ',') rescue '-'%></td>
					    		<% end %>
					    		<td style='text-align:right;'><%= number_with_delimiter(sprintf("%.2f",cash),delimiter => ',') rescue '-'%></td>
					    		<td style='text-align:right;'><%= number_with_delimiter(sprintf("%.2f",credit),delimiter => ',') rescue '-'%></td>
					    		<td style='text-align:right;'><%= number_with_delimiter(sprintf("%.2f",foc), delimiter => ',') rescue '-'%></td>  
					    		<% if @payment_methods.include? ("GiftVoucher") %> 
					    			<% colspan += 1 %> 
					    			<td style='text-align:right;'><%= number_with_delimiter(sprintf("%.2f",giftvoucher), delimiter => ',') rescue '-'%></td>  
					    		<% end %>  
					    		<td style='text-align:right;'>(<%= number_with_delimiter(discount,delimiter => ',') rescue '-'%>)</td>
					    		<!-- <td style='text-align:right;'><%= number_with_delimiter(total,delimiter => ',') rescue '-'%></td>     -->
					    		<td style='text-align:right;'><%= number_with_delimiter(sprintf("%.2f",grand_total),delimiter => ',') rescue '-'%></td> 
					    		<td style='text-align:right;'><%= number_with_delimiter(sprintf("%.2f",rounding_adj),delimiter => ',') rescue '-'%></td>   	

					    	</tr>
					    	<% total_tax = 0 %>
					    	<% net = 0 %>
					    	<% unless @tax.empty? %>
					    	<% @tax.each do |tax| 
					    		total_tax += tax.tax_amount.to_f %>
					    		<tr style="font-weight:600;">
					    			<td colspan="<%= colspan %>" style='text-align:right;'><%= tax.tax_name rescue '-'%></td>
					    			<td style='text-align:right;'><%= number_with_delimiter(sprintf("%.2f",tax.tax_amount),delimiter => ',') rescue '-'%></td>
					    			<td colspan="2">&nbsp;</td>
					    		</tr>
					    		<% end %>
					    		<% end %>

					    		<% net = grand_total %>
					    		<% net = net - rounding_adj%>
					    		<% net = net - total_tax %>
					    		<tr style="font-weight:600;">
					    			<td colspan="<%= colspan %>" style='text-align:right;'><%= t("views.right_panel.detail.net_amount") %></td>
					    			<td style='text-align:right;'><%= number_with_delimiter(sprintf("%.2f",net),delimiter => ',') rescue '-'%></td>
					    			<td colspan="2">&nbsp;</td>	
					    		</tr>
					    	</tbody>
					    	<% end %>
					    </table>
					</div>
				</div>
			</div>
		</div>

	</div>
</body>
</html>