@extends('backend.layouts.master')
@section('title','Factory Chalan List')

@push('css')
    <link  href="{{asset('backend/plugins/datepicker/datepicker.css')}}" rel="stylesheet">
@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>Factory Chalan List</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('wastage.list')}}" id="searchForm" method="Get">
                                    <div class="col-sm-3">
                                        <select class="form-control" name="show" id="show">
                                            <option value="{{$wastages->count()}}">{{$wastages->count()}}</option>
                                            <option value="10">10</option>
                                            <option value="25">25</option>
                                            <option value="50">50</option>
                                            <option value="100">100</option>
                                            <option value="250">250</option>
                                            <option value="500">500</option>
                                        </select>
                                    </div>
                                    <div class="col-sm-6"></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-condensed table-bordered table-hover" id="categorytable">
                                    <thead>
                                    <tr class="bg-primary">
                                        <th>SL</th>
                                        <th>Date</th>
                                        <th>Product</th>
                                        <th>Supplier</th>
                                        <th>Category</th>
                                        <th>Code</th>
                                        <th>PP</th>
                                        <th>Return Price</th>
                                        <th>Return Qty</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    @foreach($wastages as $i=>$pc)
                                        <tr>
                                            <td> {{$i+1}}</td>
                                            <td> {{date('d-m-Y',strtotime($pc->return_date))}}</td>
                                            <td>{{$pc->product->product_name}} </td>
                                            <td>{{$pc->supplier->name}} </td>
                                            <td>{{$pc->category->name}} </td>
                                            <td> {{$pc->code}}</td>
                                            <td>{{$pc->purchase_price}} </td>
                                            <td> {{$pc->return_price}}</td>
                                            <td> {{$pc->return_quantity}}</td>
                                        </tr>
                                    @endforeach
                                    </tbody>
                                    <tfoot>
                                    <tr>
                                        <td colspan="6">Grand Total</td>
                                        <td>{{$wastages->sum('purchase_price')}}</td>
                                        <td>{{$wastages->sum('return_price')}}</td>
                                        <td>{{$wastages->sum('return_quantity')}}</td>
                                       
                                    </tr>
                                    </tfoot>
                                </table>
                            </div>
                            <div class="text-center">
                                {{$wastages->links()}}
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!-- /page content -->
@endsection
@push('js')

    <script src="{{asset('backend/plugins/datepicker/datepicker.js')}}"></script>
    <script type="text/javascript">
        $('[data-toggle="start"]').datepicker({
            format: 'yyyy-mm-dd'
        });

        $('[data-toggle="end"]').datepicker({
            format: 'yyyy-mm-dd'
        });
    </script>
@endpush