@extends('backend.layouts.master')

@section('title', 'Stock List')

@push('css')

@endpush

@section('content')
	<div class="right_col" role="main">
        <div class="">
            <div class="clearfix"></div>
            <div class="row">
                <div class="col-md-12 col-sm-12 col-xs-12">
                    <div class="x_panel">
                        <div class="x_title">
                            <a href="{{ route('purchase.create')}}" calss="btn" ><h2><i class="fa fa-mail-reply"></i></h2></a>
                            <h2>Stock List</h2>
                            <ul class="nav navbar-right panel_toolbox">
                                <li><a class="collapse-" onclick="printDiv('printableArea')" ><i class="fa fa-print fa-2x"></i></a>
                                <li><a class="collapse-link"><i class="fa fa-chevron-up"></i></a>
                                </li>
                                <li class="dropdown">
                                    <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false"><i class="fa fa-wrench"></i></a>
                                    <ul class="dropdown-menu" role="menu">
                                        <li><a href="#">Settings 1</a>
                                        </li>
                                        <li><a href="#">Settings 2</a>
                                        </li>
                                    </ul>
                                </li>
                                <li><a class="close-link"><i class="fa fa-close"></i></a>
                                </li>
                            </ul>
                            <div class="clearfix"></div>
                        </div>
                        <div class="x_content">
							<div class="">
									<div class="col-sm-12">
											<div class="input-group">
												<input type="text" id="myInput" class="form-control" placeholder="Search">
												<span class="input-group-btn">
													<button type="button" class="btn btn-primary">
													<span class="ace-icon fa fa-search icon-on-right bigger-110"></span></button>
												</span>
											</div>
									</div>
								</div><br/>
							<hr/>
							<div class="table-content" id="printableArea">
								<table id="" class="table table-bordered table-condensed" role="grid" aria-describedby="dynamic-table_info">
									<thead>
										<tr class="bg-primary">
											<th>SL</th>
											<th>Product</th>
											<th>Code</th>
											<th>Category</th>
											<th>Unit</th>
											<th>Stock</th>
										</tr>
									</thead>
									<tbody>
										@php
											$total_stock = 0;
										@endphp
										@foreach($products as $key=>$pro)
											@php
												$total_stock = $total_stock + $pro->now_stock;
											@endphp
											<tr class="{{$pro->now_stock < $pro->re_order_label ? 'bg-danger' : 'bg-info'}} ">
												<td>{{$key + 1}}</td>
												<td>{{$pro->product_name}}</td>
												<td>{{$pro->code}}</td>
												<td>{{$pro->category_name}}</td>
												<td>{{$pro->unit_name}}</td>
												<td>{{$pro->now_stock}}</td>
											</tr>
										@endforeach
											<tr>
												<td colspan="4"></td>
												<td>Total =</td>
												<td>{{$total_stock}}</td>
											</tr>
									</tbody>
								</table>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
		
	</div>
@endsection

@push('js')
<script>
	$(document).ready(function(){
		// select2 section
		$('.select2').select2()	;
		/*-------search section------------*/

	})
	/*---------print section-------------*/
	function printDiv(divName) {
		 var printContents = document.getElementById(divName).innerHTML;
		 var originalContents = document.body.innerHTML;

		 document.body.innerHTML = printContents;

		 window.print();

		 document.body.innerHTML = originalContents;
		}
	</script>
@endpush									