@extends('backend.layouts.master')
@section('title', 'Stock List')
@push('css')
    <style>
        .thumbnail {
            height: 79px;
            overflow: hidden;
            font-size: 10px;
        }
    </style>
@endpush
@section('content')
  <div class="container body">
    <div class="main_container">
      <!-- page content -->
      <div class="right_col" role="main">
        <div class="">
          <div class="clearfix"></div>
          <div class="row">
            <!--Button Example-->
            <div class="col-md-12 col-sm-12 col-xs-12">
              <div class="x_panel">
                <div class="x_title">
                  <h2>Stock List </h2> &nbsp &nbsp
                      <a href="{{ route('purchase.create')}}" class="btn btn-default" > Re-Order Product</a>
                      
                  <ul class="nav navbar-right panel_toolbox">
                    <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="" role="tabpanel" data-example-id="togglable-tabs">
                      <ul id="myTab" class="nav nav-tabs bar_tabs" role="tablist">
                        <li role="presentation" class="active"><a href="#tab_content1" id="home-tab" role="tab" data-toggle="tab" aria-expanded="true">Product Label</a></li>
                        <li role="presentation" class=""><a href="#tab_content2" role="tab" id="profile-tab" data-toggle="tab" aria-expanded="false">All Stock Label </a></li>
                        <li role="presentation" class=""><a href="#tab_content3" role="tab" id="profile-tab2" data-toggle="tab" aria-expanded="false">Stock Label Single</a></li>
                      </ul>
                      <div id="myTabContent" class="tab-content">
                        <div role="tabpanel" class="tab-pane fade active in" id="tab_content1" aria-labelledby="home-tab">
                        <a href="#" onclick="printDiv('printArea')">	<i class="ace-icon bigger-120 fa-2x fa fa-print text-center"></i>	</a>
                        <br>
                            <div class="row" id="printArea">
                                @foreach($products as $p)
                                <div class="col-sm-2">
                                    <div class="thumbnail" id="thumbnail">
                                      <img src="data:image/png;base64,{{DNS1D::getBarcodePNG($p->code, 'C93')}}" alt="barcode" style=""  />
                                      <div class="caption">
                                        <span>Code: {{$p->code}}</span><br>
                                        <span>Grade: {{$p->category->name}} ,Rate: {{$p->sale_price}}</span>
                                      </div>
                                    </div>
                                </div>
                                @endforeach
                            </div>
                        </div>
                        <div role="tabpanel" class="tab-pane fade" id="tab_content2" aria-labelledby="profile-tab">
                        <a href="#" onclick="printDiv('printArea2')">	<i class="ace-icon bigger-120 fa-2x fa fa-print"></i>	</a>
                        <hr/>
                            <div class="row" id="printArea2">
                                @foreach($stocks as $st)
                                <div class="col-sm-2">
                                    <div class="thumbnail" id="thumbnail">
                                      <img src="data:image/png;base64,{{DNS1D::getBarcodePNG($st->code, 'C93')}}" alt="barcode" style=""  />
                                      <div class="caption">
                                        <span>Code: {{$st->code}}</span><br>
                                        <span>Grade: {{$st->category_name}} ,Rate: {{$st->rate}}</span>
                                      </div>
                                    </div>
                                </div>
                                @endforeach
                            </div>
                        </div>
                        <div role="tabpanel" class="tab-pane fade" id="tab_content3" aria-labelledby="profile-tab">
                            <table id="example" class="table table-bordered datatable" style="width:100%">
                              <thead>
                                <tr class="bg-primary">
                                  <th>SL</th>
                                  <th>Product</th>
                                  <th>Code</th>
                                  <th>Category</th>
                                  <th>Unit</th>
                                  <th>Stock</th>
                                  <th>Action</th>
                                </tr>
                              </thead>
                              <tbody>
                                  @php
                                    $total_stock = 0;
                                  @endphp
                                  @foreach($stocks as $key=>$pro)
                                    @php
                                      $total_stock = $total_stock + $pro->product_stock;
                                    @endphp
                                    <tr class="{{$pro->product_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->product_stock}}</td>
                                      <td>
                                          <a href="{{ route('pos.barcode_generate',$pro->id)}}" class="btn btn-xs btn-default glyphicon glyphicon-barcode" title="Generate Barcode and Print" ></a>
                                          <a href="{{ route('pos.qrcode_generate',$pro->id)}}" class="btn btn-xs btn-default glyphicon glyphicon-qrcode" title="Generate QRcode and Print"></a>
                                          </td>
                                        </tr>
                                    @endforeach
                              </tbody>
                            </table>
                        </div>
                      </div>
                    </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
      <!-- /page content -->
    </div>
  </div>
@endsection
@push('js')
    <script>
    /*---------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
    
 