<div class="container-fluid">
	<div class="page-header">
	  	<ol class="breadcrumb">
		    <li class="breadcrumb-item"><a href="<%= root_path %>"><%= t("views.right_panel.button.home") %></a></li>
		    <li class="breadcrumb-item active"><%= t("views.right_panel.detail.waste_spoilage_report") %></li>
		    <span class="float-right">
		      <%= link_to 'Back', dashboard_path %>
		    </span>
	  	</ol>
	</div>
	<div class="row">
		<div class="col-md-12">
			<%= render :partial=>'shift_sale_report_filter',
			:locals=>{ 	:period_type => true, :shift_name => true,:payments => true, :report_path =>reports_waste_and_spoilage_index_path} %>
			<hr />
			<div class="text-right">
				<a href="javascript:export_to('<%=reports_waste_and_spoilage_index_path%>.xls')" class = "btn btn-info wave-effects"><%= t("views.btn.exp_to_excel") %></a>
			</div>
			<div class="margin-top-20">
				<div class="card">

					<table class="table table-striped" border="0">
						<h5 class="p-l-10 p-t-10">Report For <%= @sale_type? @sale_type : 'Waste' %></h5>


								<thead>
									<!-- <td>&nbsp;</td>
									<tr>
									    <td >
									    	<strong>Receipt No :</strong>
									    </td>
										<td></td>
										<td></td>
									    <td colspan="3" style="text-align:right"><strong>Date : </strong></td>
									</tr> -->
									<tr>
										<td><strong>Menu Category</strong></td>
								  		<td><strong>Item Name</strong></td>
								  		<td><strong>Item Code</strong></td>
								  		<td><strong>Qty</strong></td>
								  		<td><strong>Price</strong></td>
								  		<td><strong>Total Price</strong></td>
								  	</tr>
								</thead>


							<tbody>
								<% receipt_arr = Array.new %>
								<% menu_cat_arr = Array.new %>
								<% footer_arr = Array.new %>
								<% count = 0 %>
								<% waste_and_spoil_item_count = 0%>
								<% grand_total = 0%>
								<% unless @sale_data.blank? %>
								<% @sale_data.each do |sale| %>
							  	<% if !sale.item_instance_code.nil?%>
							  		<% waste_and_spoil_item_count += sale.qty.to_i %>
										<% grand_total += sale.price.to_i %>
									<% end %>
								  	<tr>
								  	<% if !menu_cat_arr.include?(sale.name) %>
											<td><%= sale.name %></td>
											<% menu_cat_arr.push(sale.name) %>
										<% else %>
											<td>&nbsp;</td>
										<% end %>
								  		<td><%= sale.product_name %></td>
								  		<td><%= sale.product_code.to_i %></td>
								  		<td><%= sale.qty.to_i %></td>
								  		<td><%= number_format(sale.unit_price, precision:precision.to_i,delimiter:delimiter) %></td>
								  		<td><%= number_format(sale.price, precision:precision.to_i,delimiter:delimiter) %></td>
								  	</tr>


							  	<% count = count + 1 %>
							  	<% if @sale_data.length == count %>
									<tr>
										<td></td>
							  			<td colspan="2" style="text-align:right"> <strong>Total Qty: </strong></td>
							  			<td>
							  				<span class="underline" style="text-align:right">
							  					<strong><%= number_format(waste_and_spoil_item_count, precision:precision.to_i,delimiter:delimiter) %></strong>
							  					<% waste_and_spoil_item_count = 0%>
							  				</span></td>
							  			<td style="text-align:right"> <strong>Grand Total: </strong></td>
							  			<td >
							  				<span class="underline" style="text-align:right">
							  					<strong><%= number_format(grand_total, precision:precision.to_i,delimiter:delimiter) %></strong>
							  				</span>
							  		 	</td>
							  		</tr>
									<% footer_arr.push(sale.sale_id) %>
								<% end %>
							<% end %>
							<% end %>
							</tbody>

					</table>
				</div>
			</div>
		</div>
	</div>
</div>
