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

{{--Set Page Title--}}
@section('title', 'Manage Company Payrolls')

{{--Include any Internal JS Code--}}
@section('internal-js')
    <script>
        $(document).ready(function () {
            $('#example').dataTable();
            $('#example1').dataTable();
        });
    </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.finance-header')
@endsection

{{--Set Page Heading--}}
@section('heading')
    Manage Company Payrolls
@endsection
@section('done-by', '')

{{--Page Content Goes here--}}
@section('content')
    <div class="tab">
        <button class="tablinks" onclick="openCity(event, 'general')" id="defaultOpen">Payroll Manager</button>
        @if(app('UserReads')->log == 1)
            <button class="tablinks" onclick="openCity(event, 'log')" >LOG</button>
        @endif
    </div>
    <div class="tabcontent" id="general">
        <h3 class="error">Manage Company Payrolls</h3>
        <table id="example" class="display" style="width: 100%; border-collapse: collapse;">
            <thead>
            <tr style="background-color: #a1b5d3">
                <th>No</th>
                <th>Payroll Period</th>
                <th>Gross Amount</th>
                <th>Current Balance</th>
                <th>< 30 Days</th>
                <th>31 to 60 Days</th>
                <th>61 to 90 Days</th>
                <th>91 to 180 Days</th>
                <th>181 to 365 Days</th>
                <th>> 365 Days</th>
                <th>View Account</th>
            </tr>
            </thead>
            <tbody>
            @foreach($lists as $list)
                <tr>
                    <td class="ar"></td>
                    <td><a href="{{url('payroll-file/'.$list->month.'/'.$list->year)}}" class="inner" style="color: red; font-weight: bold" target="_blank">{!! strtoupper($list->month."/".$list->year) !!}</a></td>
                    <td><b>{!! number_format($list->gross_salary,2) !!}</b></td>
                    <td>
                        @if($list->currentCompanyPayrollBalance($list->id)['currentBalance'] > 0)
                            <b class="error">{!! number_format($list->currentCompanyPayrollBalance($list->id)['currentBalance'],2) !!}</b>
                        @else
                            <b class="success">{!! number_format($list->currentCompanyPayrollBalance($list->id)['currentBalance'],2) !!}</b>
                        @endif
                    </td>
                    <td><b>{!! number_format($list->currentCompanyPayrollBalance($list->id)['lessThanThirty'],2) !!}</b></td>
                    <td><b>{!! number_format($list->currentCompanyPayrollBalance($list->id)['thirtyAndSixty'],2) !!}</b></td>
                    <td><b>{!! number_format($list->currentCompanyPayrollBalance($list->id)['sixtyAndNinety'],2) !!}</b></td>
                    <td><b>{!! number_format($list->currentCompanyPayrollBalance($list->id)['ninetyAndOneEighty'],2) !!}</b></td>
                    <td><b>{!! number_format($list->currentCompanyPayrollBalance($list->id)['oneEightyAndThreeSixtyFive'],2) !!}</b></td>
                    <td><b class="error">{!! number_format($list->currentCompanyPayrollBalance($list->id)['moreThanThreeSixtyFive'],2) !!}</b></td>
                    <td><a href="{{url('payroll-file/'.$list->month.'/'.$list->year)}}" class="inner" style="color: red; font-weight: bold" target="_blank"><i class="fa fa-eye error" style="font-size: 14px"></i></a></td>
                    </tr>
            @endforeach
            </tbody>
            <tfoot>
            <tr style="background-color: #a1b5d3">
                <th>No</th>
                <th>Payroll Period</th>
                <th>Gross Amount</th>
                <th>Current Balance</th>
                <th>< 30 Days</th>
                <th>31 to 60 Days</th>
                <th>61 to 90 Days</th>
                <th>91 to 180 Days</th>
                <th>181 to 365 Days</th>
                <th>> 365 Days</th>
                <th>View Account</th>
            </tr>
            </tfoot>
        </table>
    </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="example1" 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="br"></td>
                        <td class="error">{!!   $histo->narration !!}</td>
                        <td></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>
@endsection

{{--System Hints Page--}}
@section('modal_heading')
    <h1>Manage Employee Payrolls </h1>
@endsection
@section('modal_title')
    <h3><u>Dashboard Functionalities</u></h3>
    <b>
        <ol>
            <li>View all Payroll for the Company</li>
            <li>View LOGs[Audit Trail]</li>
        </ol>
    </b>
@endsection
