{{--Get the Page Format--}}
@extends('layouts.app')

{{--Set Page Title--}}
@section('title', 'Clients List')

{{--Include any Internal JS Code--}}
@section('internal-js')
    <script>
        $(document).ready(function () {
            $('#example').DataTable({
                dom: 'lBfrtip',
                buttons: [
                    { extend: 'excel', className: 'download-buttons' },
                    { extend: 'pdf', className: 'download-buttons' },
                ],
            });
            $('#example1').DataTable();


            $('#active-url').on('click', function (){
                window.history.pushState({}, null, '?type=active');
            });
            $('#unauthorized-url').on('click', function (){
                window.history.pushState({}, null, '?type=unauthorized');
            });
            $('#prospect-url').on('click', function (){
                window.history.pushState({}, null, '?type=prospect');
            });
            $('#terminated-url').on('click', function (){
                window.history.pushState({}, null, '?type=terminated');
            });
            $('#trash-url').on('click', function (){
                window.history.pushState({}, null, '?type=trash');
            });
        });
    </script>
@endsection

{{--Include any Internal CSS Code--}}
@section('internal-css')
    <style>
        #example th, td {
            text-align: left;
            padding: 5px;
        }
        #example tr:hover {background-color: #a3aef6;}

        #example1 th, td {
            text-align: left;
            padding: 5px;
        }
        #example1 tr:hover {background-color: #a3aef6;}

    </style>

@endsection

{{--Control Page Header/Links--}}
@section('headers')
    @include('headers.dash-header')
@endsection

{{--Set Page Heading--}}
@section('heading', "Client's List")
@section('done-by', )

{{--Page Content Goes here--}}
@section('content')

    <div class="tab">
        <button class="tablinks" onclick="openCity(event, 'active')" @if(isset($_GET['type']) && $_GET['type'] == 'active')id="defaultOpen" @else id="active-url"@endif>Active Clients</button>
        @if(app('CompanySetup')->verify_clients == 1)
            <button class="tablinks" onclick="openCity(event, 'unauthorized')" @if(isset($_GET['type']) && $_GET['type'] == 'unauthorized')id="defaultOpen" @else id="unauthorized-url"@endif>Unauthorized
                <span class="
               @if(count($unauthorized) > 0)
                {{'countItems'}}
               @else
                {{'zeroItems'}}
               @endif">&nbsp;{{count($unauthorized)}}&nbsp;
               </span>
            </button>
        @endif
        @if(app('UserReads')->log == 1)
            <button class="tablinks" onclick="openCity(event, 'terminated')" @if(isset($_GET['type']) && $_GET['type'] == 'terminated')id="defaultOpen" @else id="terminated-url"@endif>Terminated
                <span class="
               @if(count($disabled) > 0)
               {{'countItems'}}
               @else
               {{'zeroItems'}}
               @endif">&nbsp;{{count($disabled)}}&nbsp;
               </span>
            </button>
        @endif
        @if(app('UserReads')->trash == 1)
            <button class="tablinks" style="background-color: #FF4C39; color: white" onclick="openCity(event, 'trash')" @if(isset($_GET['type']) && $_GET['type'] == 'trash')id="defaultOpen" @else id="trash-url"@endif>Trash
                <span class="
               @if(count($trash) > 0)
                   {{'countItems'}}
                   @else
                   {{'zeroItems'}}
                   @endif">&nbsp;{{count($trash)}}&nbsp;
               </span>
            </button>
        @endif
    </div>

    <div class="tabcontent" id="active">
        <span onclick="this.parentElement.style.display='none'" class="topright" style="margin-left: 20px">&times</span>
        <h3 class="error">View Active Clients' Listing</h3>

        <table id="example" class="display" style="width:100%; border-collapse: collapse">
            <thead>
            <tr style="background-color: #a1b5d3">
                <th>No</th>
                <th>Client Name</th>
                <th>File No.</th>
                <th>Category</th>
                <th>Branch</th>
                <th>ID No</th>
                <th>Phone</th>
                <th>Email</th>
                <th>Address</th>
                <th>Date Created</th>
                <th>Created By</th>
                {{--                   <th></th>--}}
            </tr>
            </thead>
            <tbody>
            @foreach($list as $client)
                @if($client->status == 1 && $client->deleted == 0)
                    <tr>
                        <td class="ar"></td>
                        <td><a href="{{url('client/'.$client->c_id.'?type=summary')}}" class="inner" style="color: red; font-weight: bold" target="_blank">{!! ucwords(strtolower($client->nms)) !!}</a></td>
                        <td>{{strtoupper($client->fl_no)}}</td>
                        <td>
                            @if($client->category == 0)
                                {{'Individual'}}
                            @elseif($client->category == 1)
                                {{'Corporate - '. $client->sub_cat}}
                            @endif
                        </td>
                        <td>
                            @if($client->branchDetails != null)
                                {{$client->branchDetails->name}}
                            @else
                                -
                            @endif
                        </td>
                        <td>{{$client->id_no}}</td>
                        <td>{{$client->pn}}</td>
                        <td>{{$client->em}}</td>
                        <td>{{$client->address}}</td>
                        <td>{{$client->created_at->format('d/m/Y')}}</td>
                        <td>{{\App\Models\User::where('id', $client->created_by)->first()->firstName[0].". ".\App\Models\User::where('id', $client->created_by)->first()->lastName}}</td>
                        {{--<td>
                            @if(app('UserDeletes')->del_client)
                                <a href="javascript:void(0);" onclick="terminateClient('{{$client->id}}')" style="margin-left: 15px" title="Terminate Client"><img src="{{asset('images/block.png')}}"></a>
                            @endif
                        </td>--}}
                    </tr>
                @endif
            @endforeach
            </tbody>
            <tfoot>
            <tr style="background-color: #a1b5d3">
                <th>No</th>
                <th>Client Name</th>
                <th>File No.</th>
                <th>Category</th>
                <th>Branch</th>
                <th>ID No</th>
                <th>Phone</th>
                <th>Email</th>
                <th>Address</th>
                <th>Date Created</th>
                <th>Created By</th>
                {{--                   <th></th>--}}
            </tr>
            </tfoot>
        </table>
    </div>


    {{--Unauthorized Client Listing--}}
    <div class="tabcontent" id="unauthorized">
        <span onclick="this.parentElement.style.display='none'" class="topright" style="margin-left: 20px">&times</span>
        <div class="topright">
            <a class="inner" href="#" ><img src="{{asset('images/exports/pdf.png')}}"></a>
            <a class="inner" href="#" ><img src="{{asset('images/exports/excel.png')}}"></a>
        </div>
        <h3 class="error">View Unauthorized Clients' Listing</h3>

        <table id="example1" class="display" style="width:100%; border-collapse: collapse">
            <thead>
            <tr style="background-color: #a1b5d3">
                <th>No</th>
                <th>Client Name</th>
                <th>File No.</th>
                <th>Category</th>
                <th>Branch</th>
                <th>ID No</th>
                <th>Phone</th>
                <th>Email</th>
                <th>Address</th>
                <th>Date Created</th>
                <th>User</th>
            </tr>
            </thead>
            <tbody>

            @foreach($unauthorized->chunk(50) as $clients)
                @foreach($clients as $client)
                    @if($client->status == 1 && $client->deleted == 0)
                        <tr>
                            <td class="br"></td>
                            <td><a href="{{url('client/'.$client->c_id.'?type=summary')}}" class="inner" style="color: red; font-weight: bold" target="_blank">{{ucwords(strtolower($client->nms))}}</a></td>
                            <td>{{strtoupper($client->fl_no)}}</td>
                            <td>
                                @if($client->category == 0)
                                    {{'Individual'}}
                                @elseif($client->category == 1)
                                    {{'Corporate - '. $client->sub_cat}}
                                @endif
                            </td>
                            <td>{{$client->branch}}</td>
                            <td>{{$client->id_no}}</td>
                            <td>{{$client->pn}}</td>
                            <td>{{$client->em}}</td>
                            <td>{{$client->address}}</td>
                            <td>{{$client->created_at->format('d/m/Y')}}</td>
                            <td>{{\App\Models\User::where('id', $client->created_by)->first()->firstName[0].". ".\App\Models\User::where('id', $client->created_by)->first()->lastName}}</td>
                        </tr>
                    @endif
                @endforeach
            @endforeach

            </tbody>
            <tfoot>
            <tr style="background-color: #a1b5d3">
                <th>No</th>
                <th>Client Name</th>
                <th>File No.</th>
                <th>Category</th>
                <th>Branch</th>
                <th>ID No</th>
                <th>Phone</th>
                <th>Email</th>
                <th>Address</th>
                <th>Date Created</th>
                <th>User</th>
            </tr>
            </tfoot>
        </table>
    </div>

    <div class="tabcontent" id="terminated">
        <div class="topright">
            <a class="inner" href="#" ><img src="{{asset('images/exports/pdf.png')}}"></a>
            <a class="inner" href="#" ><img src="{{asset('images/exports/excel.png')}}"></a>
            <span onclick="this.parentElement.style.display='none'" class="topright" style="margin-left: 20px">&times</span>
        </div>
        <h3 class="error">View Inactive Clients' Listing</h3>

    </div>

    <div class="tabcontent" id="trash">
        <div class="topright">
            <a class="inner" href="#" ><img src="{{asset('images/exports/pdf.png')}}"></a>
            <a class="inner" href="#" ><img src="{{asset('images/exports/excel.png')}}"></a>
            <span onclick="this.parentElement.style.display='none'" class="topright" style="margin-left: 20px">&times</span>
        </div>
        <h3 class="error">Deleted Clients' List</h3>

    </div>
@endsection

{{--System Hints Page--}}
@section('modal_heading')
    <h1>Customers List</h1>
@endsection
@section('modal_title')
    <h3><u>Dashboard Functionalities</u></h3>
    <ol><b>
            <li>View Clients Details</li>
            <li>Filter and Search for specific Client</li>
            <li>View Client Logs</li>
        </b>
    </ol>
@endsection




