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

{{--Set Page Title--}}
@section('title', 'Manage Client KYC Fields')

{{--Include any Internal JS Code--}}
@section('internal-js')
    <script>

        $(document).ready(function () {
            $('#example7').dataTable();


            $('#summary-url').on('click', function (){
                window.history.pushState({}, null, '?type=summary');
            });
            $('#log-url').on('click', function (){
                window.history.pushState({}, null, '?type=log');
            });

            $('#cancel').click(function (){
                if(confirm('Are you sure to Cancel Updating Client KYC Fields?')){
                    window.location = '/settings';
                }
                return false;
            });

        });

        function updateFields(id){
            var route_link = '/setup-client-kyc-fields/'+id;

            if(confirm('Are you sure to Update Client KYC Mandatory Fields for Clients')){
                var datas = $('#update-client-kyc-fields').serializeArray();

                $.ajax({
                    method: "POST",
                    url: route_link,
                    data: datas,
                    success: function (res){
                        //alert(res);
                        if(res == 'success'){
                            window.location = '/setup-client-kyc-fields?type=summary&update=true';
                        }else if(res == 'error'){
                            window.location = '/setup-client-kyc-fields?type=summary&update=false';
                        } else{
                            alert('System Encountered an Error. Please Contact System Admin');
                            window.location = '/setup-client-kyc-fields?type=summary&error=system';
                        }
                    }
                });
            }
            return false
        }

    </script>
@endsection

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

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

{{--Set Page Heading--}}

@section('heading', 'Manage Clients\' KYC Mandatory Fields:')

@section('done-by', '')


{{--Page Content Goes here--}}
@section('content')
    @isset($_GET['update'])
        <div class="error-section">
            <span onclick="this.parentElement.style.display='none'" class="topright" style="color: white ;margin-top: -4px;font-weight: bold; margin-right: 5px">&times</span>
            @if($_GET['update'] == 'true')
                <div class="yesFound"> Client KYC Fields Updated Successfully.</div><br>
            @elseif($_GET['update'] == 'false')
                <div class="notFound">System is unable to Update Client KYC Fields Entered. Please Contact System Admin for Assistance</div><br>
            @endif
        </div>
    @endisset

    @if(isset($list))
        <div class="tab">
            <button class="tablinks" onclick="openCity(event, 'list')" @if(isset($_GET['type']) && $_GET['type'] == 'summary')id="defaultOpen" @else id="summary-url"@endif>General</button>

            <button class="tablinks" onclick="openCity(event, 'log')" @if(isset($_GET['type']) && $_GET['type'] == 'log')id="defaultOpen" @else id="log-url"@endif>LOG
                <span class="
                 @if(count($history) > 0)
                    countItems
                 @else
                    zeroItems
                 @endif">
               &nbsp;{{count($history)}}&nbsp;
            </span>
            </button>
        </div>

        <div class="tabcontent" id="list">
            <span onclick="this.parentElement.style.display='none'" class="topright" style="margin-left: 20px">&times</span>
            <h3 ><span class="error" style="margin-right: 20px">Client KYC Fields Listing</span>
                <button onclick="updateFields('{{$list->id}}')" style="margin-left: 20px; cursor: pointer;height: 25px">Update KYC Fields</button>
            </h3>
            <div class="guestDetails_inputDivider"></div>

            {!! Form::open(['route'=>['ClientKYCField.update', 'id'=>$list->id], 'method'=>'POST', 'id'=>'update-client-kyc-fields']) !!}
            <div class="guestDetails_input">
                <div class="guestDetails_inputLabel">
                    {!! Form::label('name', 'Client Name') !!}
                </div>
                <div class="guestDetails_input">
                    {!!  $list->name == 1 ? 'Deactivate Here &#9755;' : 'Activate Here &#9755;'!!}
                    {!! Form::checkbox('name', '1', $list->name == 1 ? 'checked' : '') !!}
                </div>
            </div>
            <div class="guestDetails_input">
                <div class="guestDetails_inputLabel">
                    {!! Form::label('phone', 'Phone Number') !!}
                </div>
                <div class="guestDetails_input">
                    {!!  $list->phone == 1 ? 'Deactivate Here &#9755;' : 'Activate Here &#9755;'!!}
                    {!! Form::checkbox('phone', '1', $list->phone == 1 ? 'checked' : '') !!}
                </div>
            </div>

            <div class="guestDetails_input">
                <div class="guestDetails_inputLabel">
                    {!! Form::label('email', 'Email') !!}
                </div>
                <div class="guestDetails_input">
                    {!!  $list->email == 1 ? 'Deactivate Here &#9755;' : 'Activate Here &#9755;'!!}
                    {!! Form::checkbox('email', '1', $list->email == 1 ? 'checked' : '') !!}
                </div>
            </div>

            <div class="guestDetails_input">
                <div class="guestDetails_inputLabel">
                    {!! Form::label('id-no', 'ID NO.') !!}
                </div>
                <div class="guestDetails_input">
                    {!!  $list->id_no == 1 ? 'Deactivate Here &#9755;' : 'Activate Here &#9755;'!!}
                    {!! Form::checkbox('id-no', '1', $list->id_no == 1 ? 'checked' : '') !!}
                </div>
            </div>

            <div class="guestDetails_input">
                <div class="guestDetails_inputLabel">
                    {!! Form::label('pin', 'PIN No.') !!}
                </div>
                <div class="guestDetails_input">
                    {!!  $list->pin == 1 ? 'Deactivate Here &#9755;' : 'Activate Here &#9755;'!!}
                    {!! Form::checkbox('pin', '1', $list->pin == 1 ? 'checked' : '') !!}
                </div>
            </div>

            <div class="guestDetails_input">
                <div class="guestDetails_inputLabel">
                    {!! Form::label('dob', 'D.O.B') !!}
                </div>
                <div class="guestDetails_input">
                    {!!  $list->dob == 1 ? 'Deactivate Here &#9755;' : 'Activate Here &#9755;'!!}
                    {!! Form::checkbox('dob', '1', $list->dob == 1 ? 'checked' : '') !!}
                </div>
            </div>

            <div class="guestDetails_inputDivider1"></div>
            <div class="guestDetails_input">
                <div class="guestDetails_inputLabel">
                    {!! Form::label('address', 'Address') !!}
                </div>
                <div class="guestDetails_input">
                    {!!  $list->address == 1 ? 'Deactivate Here &#9755;' : 'Activate Here &#9755;'!!}
                    {!! Form::checkbox('address', '1', $list->address == 1 ? 'checked' : '') !!}
                </div>
            </div>

            <div class="guestDetails_input">
                <div class="guestDetails_inputLabel">
                    {!! Form::label('box', 'P.O BOX') !!}
                </div>
                <div class="guestDetails_input">
                    {!!  $list->box == 1 ? 'Deactivate Here &#9755;' : 'Activate Here &#9755;'!!}
                    {!! Form::checkbox('box', '1', $list->box == 1 ? 'checked' : '') !!}
                </div>
            </div>

            <div class="guestDetails_input">
                <div class="guestDetails_inputLabel">
                    {!! Form::label('occp', 'Occupation') !!}
                </div>
                <div class="guestDetails_input">
                    {!!  $list->occp == 1 ? 'Deactivate Here &#9755;' : 'Activate Here &#9755;'!!}
                    {!! Form::checkbox('occp', '1', $list->occp == 1 ? 'checked' : '') !!}
                </div>
            </div>

            <div class="guestDetails_input">
                <div class="guestDetails_inputLabel">
                    {!! Form::label('office-tel', 'Office Tel') !!}
                </div>
                <div class="guestDetails_input">
                    {!!  $list->office_tel == 1 ? 'Deactivate Here &#9755;' : 'Activate Here &#9755;'!!}
                    {!! Form::checkbox('office-tel', '1', $list->office_tel == 1 ? 'checked' : '') !!}
                </div>
            </div>

            <div class="guestDetails_input">
                <div class="guestDetails_inputLabel">
                    {!! Form::label('alt-email', 'Alt Email') !!}
                </div>
                <div class="guestDetails_input">
                    {!!  $list->alt_email == 1 ? 'Deactivate Here &#9755;' : 'Activate Here &#9755;'!!}
                    {!! Form::checkbox('alt-email', '1', $list->alt_email == 1 ? 'checked' : '') !!}
                </div>
            </div>
            <div class="guestDetails_inputDivider"></div>
            <div class="inputDivider fields" >
                <div class="fields">
                    <button type="button" name="cancel"  id="cancel" style="background-color: #e14e34; color: white; height: 35px;width: 60px; border: none; border-radius: 4px; cursor: pointer;">Cancel</button></a>
                    <button type="button" name="save" style="background-color: royalblue; color: white; height: 35px;width: 110px; border: none; border-radius: 4px; cursor: pointer; float: right" id="save" onclick="updateFields('{{$list->id}}')" >Save Changes</button>

                </div>
            </div>

            {!! Form::close() !!}



        </div>

        <div class="tabcontent" id="log">
            <span onclick="this.parentElement.style.display='none'" class="topright">&times</span>
            <h3 class="error">Audit Trails [LOGs]</h3>
            <table id="example7" class="display" style="width:100%; border-collapse: collapse">
                <thead>
                <tr style="background-color: #a1b5d3">
                    <th style="text-align: left">No</th>
                    <th style="text-align: left">Log Narration.</th>
                    <th style="text-align: left">User</th>
                    <th style="text-align: left">Date & Time</th>
                </tr>
                </thead>
                <tbody>

                @if(isset($history))
                    @foreach($history as $histo)
                        <tr>
                            <td style="width: 50px" class="mr"></td>
                            <td class="error">{!! $histo->narration !!}</td>
                            <td>{{\App\Models\User::where('id', $histo->created_by)->first()->lastName}}</td>
                            <td>{{$histo->created_at->format('d/m/Y') .' at '. $histo->created_at->format('h:i:s a')}}</td>
                        </tr>
                    @endforeach
                @endif
                </tbody>
                <tfoot>
                <tr style="background-color: #a1b5d3">
                    <th style="text-align: left">No</th>
                    <th style="text-align: left">Log Narration.</th>
                    <th style="text-align: left">User</th>
                    <th style="text-align: left">Date & Time</th>
                </tr>
                </tfoot>
            </table>
        </div>
    @else()
        <div class="tab">
            <button class="tablinks" onclick="openCity(event, 'log')" id="defaultOpen">LOG </button>
        </div>
        <div class="tabcontent" id="log">
            <span onclick="this.parentElement.style.display='none'" class="topright">&times</span>
            <h3 class="error">Audit Trails [LOGs]</h3>
            <table id="example7" class="display" style="width:100%; border-collapse: collapse">
                <thead>
                <tr style="background-color: #a1b5d3">
                    <th style="text-align: left">No</th>
                    <th style="text-align: left">Log Narration.</th>
                    <th style="text-align: left">User</th>
                    <th style="text-align: left">Date & Time</th>
                </tr>
                </thead>
                <tbody>

                @if(isset($history))
                    @foreach($history as $histo)
                        <tr>
                            <td style="width: 50px" class="mr"></td>
                            <td class="error">{!! $histo->narration !!}</td>
                            <td>{{\App\Models\User::where('id', $histo->created_by)->first()->lastName}}</td>
                            <td>{{$histo->created_at->format('d/m/Y') .' at '. $histo->created_at->format('h:i:s a')}}</td>
                        </tr>
                    @endforeach
                @endif
                </tbody>
                <tfoot>
                <tr style="background-color: #a1b5d3">
                    <th style="text-align: left">No</th>
                    <th style="text-align: left">Log Narration.</th>
                    <th style="text-align: left">User</th>
                    <th style="text-align: left">Date & Time</th>
                </tr>
                </tfoot>
            </table>
        </div>
    @endif
@endsection
@section('other-js')

@endsection

{{--System Hints Page--}}

@section('modal_heading')
    <h1>Setup Client KYC Fields</h1>
@endsection
@section('modal_title')
    <h3><u>Dashboard Functionalities</u></h3>
    <ol><b>
            <li>View and Manage New Client's Mandatory Fields</li>
            <li>Activate/Deactivate Mandatory Fields </li>
            <li>View Logs</li>
        </b>
    </ol>
@endsection


