@extends('backend.layouts.master')
@section('title')
   Customer Management
@endsection
@section('css')

@endsection
<!-- 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>Manage Customer
                                 <a href="{{route('account.cpi')}}" class="btn btn-xs btn-primary"> Payment</a>
                                  <a href="{{route('customer.create')}}" class="btn btn-xs btn-primary">New Customer</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">
                                <div class="col-sm-2">
                                    <form action="{{route('customer.list')}}" id="searchForm" method="Get">
                                        <select class="form-control" name="show" id="show">
                                            <option value="{{$customers->count()}}">{{$customers->count()}}</option>
                                            @foreach(explode(",",setting()->pdl) as $d)
                                                <option value="{{$d}}">{{$d}}</option>
                                            @endforeach
                                        </select>
                                    </form>
                                </div>
                                <div class="col-sm-3">
                                    <div class="input-group">
                                        <input type="text" id="myInput" class="form-control" placeholder="Filter Row">
                                        <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 class="col-sm-2"></div>
                                <form action="{{route('customer.customer_search')}}" id="" method="Post">
                                    {{ method_field('Get') }}
                                    <div class="col-sm-2">
                                        <select class="form-control" name="column" id="column">
                                            <option value="name" <?php echo request()->column == 'name' ? 'selected' : ''; ?> >Customer Name</option>
                                            <option value="phone" <?php echo request()->column == 'phone' ? 'selected' : ''; ?> >Phone Number</option>
                                            <option value="email" <?php echo request()->column == 'email' ? 'selected' : ''; ?> >Email </option>
                                            <option value="address" <?php echo request()->column == 'address' ? 'selected' : ''; ?> >Address</option>
                                        </select>
                                    </div>
                                    <div class="col-sm-3">
                                        <div class="input-group">
                                            <input type="text" id="search_value" name="search_value" class="form-control" placeholder="Search" value="{{request()->search_value}}" >
                                            <span class="input-group-btn">
                                                <button type="submit" 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 " id="">
                                    <thead>
                                    <tr class="bg-primary">
                                        <th>SL</th>
                                        <th>Customer</th>
                                        <th>Phone</th>
                                        <th>Email</th>
                                        <th>Address</th>
                                        <th>Total Price</th>
                                        <th>Total Payment</th>
                                        <th>Total Due</th>
                                        <th>Status</th>
                                        <th>Action</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    @foreach($customers as $i=>$pc)
                                        <tr>
                                            <th> {{$i+1}}</th>
                                            <td> {{$pc->name}}</td>
                                            <td> {{$pc->phone}}</td>
                                            <td> {{$pc->email}}</td>
                                            <td> {{$pc->address}}</td>
                                            <td><a href="{{url('csrs').'?customer_id='.$pc->id.'&report_type=Invoice'}}" target="_blank"> {{$pc->sales->sum('grand_total_price')}}</a></td>
                                            <td><a href="{{url('csrs').'?customer_id='.$pc->id.'&report_type=Payment'}}" target="_blank"> {{$pc->sales->sum('payment')}}</a></td>
                                            <td><a href="{{url('csrs').'?customer_id='.$pc->id.'&report_type=Statement'}}" target="_blank"> {{$pc->sales->sum('due_amount')}}</a></td>
                                            <td><a href="{{route('customer.status',$pc->id)}}"><span class="label {{ $pc->status == 'Active' ? 'label-success' : 'label-warning' }}" > {{$pc->status}} </span></a></td>
                                            <td>
                                                <div class="row">
                                                    <div class="col-md-4">
                                                        <a href="{{route('customer.edit',$pc->id)}}" class=" btn-xs btn-warning"><i class="fa fa-edit"></i></a>
                                                    </div>
                                                    <div class="col-md-4">
                                                    @can('customer-delete')
                                                        <form action="{{route('customer.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> Delete</button>
                                                        </form>
                                                    @endcan
                                                    </div>
                                                </div>
                                            </td>
                                        </tr>
                                    @endforeach
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!-- /page content -->
@endsection

@section('script')

@endsection