@extends('backend.layouts.master')
@section('title','Product Manage')

@push('css')

@endpush
<!-- page content -->
@section('content')
    <div class="right_col" role="main">
        <div class="">
            <div class="clearfix"></div>
            @if(Session::has('success'))
                <div class="alert alert-success">
                    {{ Session::get('success') }}
                </div>
            @endif
            @if(Session::has('error'))
                <div class="alert alert-danger">
                    {{ Session::get('error') }}
                </div>
            @endif
            <div class="row">
                <div class="col-md-12 col-sm-12 col-xs-12">
                    <div class="x_panel">
                        <div class="x_title">
                            <h2>Product Management 
                                <a href="{{route('product.create')}}" class="btn btn-xs btn-primary">Create Product</a>
                            </h2> 
                            <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="">
                            <div class="row search-section">
								<form action="{{route('product.list')}}" id="searchForm" method="Get">
									<div class="col-sm-2">
										<select class="form-control" name="show" id="show">
											<option value="{{$products->count()}}">{{$products->count()}}</option>
											@foreach(explode(",",setting()->pdl) as $d)
    										<option value="{{$d}}">{{$d}}</option>
    										@endforeach
    										<option value="{{$products->total()}}">All</option>
										</select>
									</div>
									<div class="col-sm-7"></div>
									<div class="col-sm-3">
										<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>
								</form> 
							</div>
							<div class="x_content table-responsive"> 
                                <table  class="table table-bordered table-condensed" id="">
                                    <thead>
                                    <tr class="bg-primary">
                                        <th>SL</th>
                                        <th>Product</th>
                                        <th>Category</th>
                                        <th>Unit</th>
                                        <th>Code</th>
                                        <th>Square Foot</th>
                                        <th>Rate</th>
                                        <th>Sale Price</th>
                                        <th>Wage</th>
                                        <th>Order Label</th>
                                        <th>Stock</th>
                                        <th>Status</th>
                                        <th>Action</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    <?php $i=1 ?>
                                    @foreach($products as $pc)
                                        <tr class="{{$pc->re_order_label > $pc->pdetail->sum('now_stock') ? 'bg-warning' : ''}}">
                                            <th> {{$i++}}</th>
                                            <td>{{$pc->product_name}} </td>
                                            <td>{{$pc->productcategory_id != '' ? $pc->category->name : ''}} </td>
                                            <td>{{$pc->unit != '' ? $pc->unit->name : ''}} </td>
                                            <td>{{$pc->code}} </td>
                                            <td>{{$pc->square_foot}} </td>
                                            <td>{{$pc->supplier_price}}</td>
                                            <td>{{$pc->sale_price}}</td>
                                            <td>{{$pc->worker_wage}}</td>
                                            <td>{{$pc->re_order_label}}</td>
                                            <td>{{$pc->pdetail->sum('now_stock')}}</td>
                                            <td>
                                                @if($pc->status == 1)
                                                    <span class="label label-success"> Active </span>
                                                @else
                                                    <span class="label label-danger">DeActive</span>
                                                @endif
                                            </td>
                                            <td>
                                                <div class="row">
                                                    <div class="col-md-2">
                                                        <a href="{{route('product.edit',$pc->id)}}" class="btn btn-xs btn-warning"><i class="fa fa-pencil"></i></a>
                                                    </div>
                                                    @can('product-delete')
                                                    <div class="col-md-2">
                                                        <form action="{{route('product.delete' ,$pc->id)}}" method="post">
                                                            <input type="hidden" name="_method" value="DELETE">
                                                            {{ csrf_field()}}
                                                            <button type="submit" class="btn btn-xs btn-danger" onclick="return confirm('are you sure to delete?')" ><i class="fa fa-trash-o"></i></button>
                                                        </form>
                                                    </div>
                                                    @endcan
                                                </div>
                                            </td>
                                        </tr>
                                    @endforeach
                                    </tbody>
                                </table>
                            </div>
                            <div class="text-center">
                                {{$products->links()}}
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!-- /page content -->
@endsection

@push('js')

@endpush