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

{{--Set Page Title--}}
@section('title', 'Ledger Mappings')

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

        function mapLedger(type, name){
            var route_link = '/map-ledger-account/'+type;

            $('#edit_dialog_content').html('<div style="text-align: center; margin: 20px 0 20px 0;"><img src="{{asset('images/loads/loader.gif')}}" border=0></div>')
            .load(encodeURI(route_link))
            .dialog({
                modal: true,
                width: 500,
                title: "Map a Ledger Account to "+name,
                buttons: [
                    {
                        text: "Continue to Map",
                        icon: "ui-icon-check",
                        click: function(e) {
                            e.preventDefault();
                            var datas = $('#map-ledger-account').serializeArray();

                            $.ajax({
                                method: "POST",
                                url: route_link,
                                data: datas,
                                success: function (res){
                                    if(res == 'empty account'){
                                        alert('Please select an Account to map this Ledger');
                                    }else if(res == 'empty mappable ledger'){
                                        alert('Selected Ledger does\'t have an Identifier. Please contact System Admin');
                                    }else if(res == 'error'){
                                        alert('System is unable to perform the Requested action. Please Try Again!');
                                        location.reload();
                                    }else if(res == 'success'){
                                        window.location = '/mapped-ledgers?mapLedger=true';
                                    }else{
                                        alert('System Encountered an Error. Please Contact System Admin for Help');
                                        location.reload();
                                    }
                                }
                            });
                            return false;
                        }
                    }
                ],
                open: function() {
                    $(this).parent().css({'top': 50});
                }
            });
        }
    </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;}
        table tbody,thead, tfoot {
            display: table;
            width: 100%;
        }

    </style>
@endsection

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

{{--Set Page Heading--}}

@section('heading', 'Manage Ledger Mappings')
@section('searches', '')
@section('done-by', '')

{{--Page Content Goes here--}}
@section('content')
    <div class="tab">
        <button class="tablinks" onclick="openCity(event, 'leeds')" id="defaultOpen">Active Ledgers</button>
        @if(app('UserReads')->log == 1)
            <button class="tablinks" onclick="openCity(event, 'log')">LOG </button>
        @endif
    </div>

    <div class="tabcontent" id="leeds">
        <div class="topright">
            <span onclick="this.parentElement.style.display='none'" class="topright" style="margin-left: 20px">&times</span>
        </div>
        <h3 class="error">Available Ledger Mappings</h3>
        <table id="example" class="table-overflow display" style="width:100%; border-collapse: collapse">
            <thead>
            <tr style="background-color: #a1b5d3">
                <th>No</th>
                <th>Ledger Name</th>
                <th>Details</th>
                <th>Mapped To</th>
                <th>Date Mapped</th>
                <th>User</th>
                <th>Status</th>
                <th></th>
            </tr>
            </thead>
            <tbody>
            {{--TRADE DEBTORS(clients) - ASSET--}}
            <tr>
                <td class="ar"></td>
                <td><a href="{{url('#')}}" class="inner"><span class="error">TRADE DEBTORS(clients)</span></a></td>
                <td>TRADE DEBTORS(clients) - Premium Control - Asset</td>
                <td>{{$data['Tdebtors']['mappedName']}}</td>
                <td>{{$data['Tdebtors']['mappedAt']}}</td>
                <td>{{$data['Tdebtors']['mappedBy']}}</td>
                @if($data['Tdebtors']['mapped'] == 1)
                    <td><i class="success">Mapped</i></td>
                    <td><a href="javascript: editMapping('Tdebtors','TRADE DEBTORS(clients)' );"><b class="error"><i class="fa fa-pencil fa-md"></i></b></a></td>
                @else
                    <td><i class="error">--Pending--</i></td>
                    <td><a href="javascript: void(0);" onclick="mapLedger('Tdebtors', 'TRADE DEBTORS(clients)')" class="inner"><span class="error">Map this Ledger </span> </a></td>
                @endif

            </tr>
            {{--RETAINED EARNINGS - EQUITY --}}
            <tr>
                <td class="ar"></td>
                <td><a href="{{url('#')}}" class="inner"><span class="error">RETAINED EARNINGS</span></a></td>
                <td>RETAINED EARNINGS - EQUITY</td>
                <td>{{$data['retainedEarnings']['mappedName']}}</td>
                <td>{{$data['retainedEarnings']['mappedAt']}}</td>
                <td>{{$data['retainedEarnings']['mappedBy']}}</td>
                @if($data['retainedEarnings']['mapped'] == 1)
                    <td><i class="success">Mapped</i></td>
                    <td><a href="javascript: editMapping('retainedEarnings','RETAINED EARNINGS' );"><b class="error"><i class="fa fa-pencil fa-md"></i></b></a></td>
                @else
                    <td><i class="error">--Pending--</i></td>
                    <td><a href="javascript: void(0);" onclick="mapLedger('retainedEarnings', 'RETAINED EARNINGS')" class="inner"><span class="error">Map this Ledger</span></a></td>
                @endif
            </tr>
            {{--SALARY CONTROL--}}
            <tr>
                <td class="ar"></td>
                <td><a href="{{url('#')}}" class="inner"><span class="error">SALARY CONTROL - LIABILITY</span></a></td>
                <td>All Salary Related Dues to the Company - Liability</td>
                <td>{{$data['SalaryControl']['mappedName']}}</td>
                <td>{{$data['SalaryControl']['mappedAt']}}</td>
                <td>{{$data['SalaryControl']['mappedBy']}}</td>
                @if($data['SalaryControl']['mapped'] == 1)
                    <td><i class="success">Mapped</i></td>
                    <td><a href="javascript: editMapping('SalaryControl','SALARY CONTROL - LIABILITY' );"><b class="error"><i class="fa fa-pencil fa-md"></i></b></a></td>
                @else
                    <td><i class="error">--Pending--</i></td>
                    <td><a href="javascript: void(0);" onclick="mapLedger('SalaryControl', 'SALARY CONTROL - LIABILITY')" class="inner"><span class="error">Map this Ledger</span></a></td>
                @endif
            </tr>
            {{--STAFF CURRENT ACCOUNT--}}
            <tr>
                <td class="ar"></td>
                <td><a href="{{url('#')}}" class="inner"><span class="error">STAFF CURRENT ACCOUNT</span></a></td>
                <td>Current Staff Dues to the Company - Current Asset</td>
                <td>{{$data['staffAccount']['mappedName']}}</td>
                <td>{{$data['staffAccount']['mappedAt']}}</td>
                <td>{{$data['staffAccount']['mappedBy']}}</td>
                @if($data['staffAccount']['mapped'] == 1)
                    <td><i class="success">Mapped</i></td>
                    <td><a href="javascript: editMapping('staffAccount','STAFF CURRENT ACCOUNT' );"><b class="error"><i class="fa fa-pencil fa-md"></i></b></a></td>
                @else
                    <td><i class="error">--Pending--</i></td>
                    <td><a href="javascript: void(0);" onclick="mapLedger('staffAccount', 'STAFF CURRENT ACCOUNT')" class="inner"><span class="error">Map this Ledger</span></a></td>
                @endif
            </tr>
            {{--SALARIES AND WAGES--}}
            <tr>
                <td class="ar"></td>
                <td><a href="{{url('#')}}" class="inner"><span class="error">SALARIES AND WAGES</span></a></td>
                <td>Paid Salaries and Wages - Expense to Company</td>
                <td>{{$data['SalaryExpense']['mappedName']}}</td>
                <td>{{$data['SalaryExpense']['mappedAt']}}</td>
                <td>{{$data['SalaryExpense']['mappedBy']}}</td>
                @if($data['SalaryExpense']['mapped'] == 1)
                    <td><i class="success">Mapped</i></td>
                    <td><a href="javascript: editMapping('SalaryExpense','SALARIES AND WAGES' );"><b class="error"><i class="fa fa-pencil fa-md"></i></b></a></td>
                @else
                    <td><i class="error">--Pending--</i></td>
                    <td><a href="javascript: void(0);" onclick="mapLedger('SalaryExpense', 'SALARIES AND WAGES')" class="inner"><span class="error">Map this Ledger</span></a></td>
                @endif
            </tr>
            {{--LEAVE DAYS PROVISION--}}
            <tr>
                <td class="ar"></td>
                <td><a href="{{url('#')}}" class="inner"><span class="error">LEAVE DAYS PROVISION</span></a></td>
                <td>Leave Days Provision for Employees - Liability</td>
                <td>{{$data['LeaveDays']['mappedName']}}</td>
                <td>{{$data['LeaveDays']['mappedAt']}}</td>
                <td>{{$data['LeaveDays']['mappedBy']}}</td>
                @if($data['LeaveDays']['mapped'] == 1)
                    <td><i class="success">Mapped</i></td>
                    <td><a href="javascript: editMapping('LeaveDays','LEAVE DAYS PROVISION' );"><b class="error"><i class="fa fa-pencil fa-md"></i></b></a></td>
                @else
                    <td><i class="error">--Pending--</i></td>
                    <td><a href="javascript: void(0);" onclick="mapLedger('LeaveDays', 'LEAVE DAYS PROVISION')" class="inner"><span class="error">Map this Ledger</span></a></td>
                @endif
            </tr>
            {{--P.A.Y.E - EXPENSE TO THE COMPANY---}}
            <tr>
                <td class="ar"></td>
                <td><a href="{{url('#')}}" class="inner"><span class="error">P.A.Y.E</span></a></td>
                <td>PAYE for Employees - Expense</td>
                <td>{{$data['PAYE']['mappedName']}}</td>
                <td>{{$data['PAYE']['mappedAt']}}</td>
                <td>{{$data['PAYE']['mappedBy']}}</td>
                @if($data['PAYE']['mapped'] == 1)
                    <td><i class="success">Mapped</i></td>
                    <td><a href="javascript: editMapping('PAYE','PAYE' );"><b class="error"><i class="fa fa-pencil fa-md"></i></b></a></td>
                @else
                    <td><i class="error">--Pending--</i></td>
                    <td><a href="javascript: void(0);" onclick="mapLedger('PAYE', 'PAYE')" class="inner"><span class="error">Map this Ledger</span></a></td>
                @endif
            </tr>
            {{--NSSF - EXPENSE TO COMPANY--}}
            <tr>
                <td class="ar"></td>
                <td><a href="{{url('#')}}" class="inner"><span class="error">NSSF</span></a></td>
                <td>NSSF - Company Expenses</td>
                <td>{{$data['NSSFExpense']['mappedName']}}</td>
                <td>{{$data['NSSFExpense']['mappedAt']}}</td>
                <td>{{$data['NSSFExpense']['mappedBy']}}</td>
                @if($data['NSSFExpense']['mapped'] == 1)
                    <td><i class="success">Mapped</i></td>
                    <td><a href="javascript: editMapping('NSSFExpense','NSSF' );"><b class="error"><i class="fa fa-pencil fa-md"></i></b></a></td>
                @else
                    <td><i class="error">--Pending--</i></td>
                    <td><a href="javascript: void(0);" onclick="mapLedger('NSSFExpense', 'NSSF')" class="inner"><span class="error">Map this Ledger</span></a></td>
                @endif
            </tr>
            {{--NHIF - EXPENSE TO COMPANY--}}
            <tr>
                <td class="ar"></td>
                <td><a href="{{url('#')}}" class="inner"><span class="error">NHIF</span></a></td>
                <td>NHIF - Company Expenses</td>
                <td>{{$data['NHIFExpense']['mappedName']}}</td>
                <td>{{$data['NHIFExpense']['mappedAt']}}</td>
                <td>{{$data['NHIFExpense']['mappedBy']}}</td>
                @if($data['NHIFExpense']['mapped'] == 1)
                    <td><i class="success">Mapped</i></td>
                    <td><a href="javascript: editMapping('NHIFExpense','NHIF' );"><b class="error"><i class="fa fa-pencil fa-md"></i></b></a></td>
                @else
                    <td><i class="error">--Pending--</i></td>
                    <td><a href="javascript: void(0);" onclick="mapLedger('NHIFExpense', 'NHIF')" class="inner"><span class="error">Map this Ledger</span></a></td>
                @endif
            </tr>
            {{--PENSION - EXPENSE TO COMPANY--}}
            <tr>
                <td class="ar"></td>
                <td><a href="{{url('#')}}" class="inner"><span class="error">PENSION</span></a></td>
                <td>Pension - Company Expense</td>
                <td>{{$data['PensionExpense']['mappedName']}}</td>
                <td>{{$data['PensionExpense']['mappedAt']}}</td>
                <td>{{$data['PensionExpense']['mappedBy']}}</td>
                @if($data['PensionExpense']['mapped'] == 1)
                    <td><i class="success">Mapped</i></td>
                    <td><a href="javascript: editMapping('PensionExpense','PENSION' );"><b class="error"><i class="fa fa-pencil fa-md"></i></b></a></td>
                @else
                    <td><i class="error">--Pending--</i></td>
                    <td><a href="javascript: void(0);" onclick="mapLedger('PensionExpense', 'PENSION')" class="inner"><span class="error">Map this Ledger</span></a></td>
                @endif
            </tr>

            {{--WITHHOLDING TAX PROFESSIONAL - ASSET--}}
            <tr>
                <td class="ar"></td>
                <td><a href="{{url('#')}}" class="inner"><span class="error">WITHHOLDING TAX PROFESSIONAL</span></a></td>
                <td>Withholding Tax Professional</td>
                <td>{{$data['WTaxProfessional']['mappedName']}}</td>
                <td>{{$data['WTaxProfessional']['mappedAt']}}</td>
                <td>{{$data['WTaxProfessional']['mappedBy']}}</td>
                @if($data['WTaxProfessional']['mapped'] == 1)
                    <td><i class="success">Mapped</i></td>
                    <td><a href="javascript: editMapping('WTaxProfessional','WITHHOLDING TAX PROFESSIONAL' );"><b class="error"><i class="fa fa-pencil fa-md"></i></b></a></td>
                @else
                    <td><i class="error">--Pending--</i></td>
                    <td><a href="javascript: void(0);" onclick="mapLedger('WTaxProfessional', 'WITHHOLDING TAX PROFESSIONAL')" class="inner"><span class="error">Map this Ledger</span></a></td>
                @endif
            </tr>
            {{--WITHHOLDING TAX RENTAL - ASSET--}}
            <tr>
                <td class="ar"></td>
                <td><a href="{{url('#')}}" class="inner"><span class="error">WITHHOLDING TAX RENTAL</span></a></td>
                <td>Withholding Tax Rental</td>
                <td>{{$data['WTaxRental']['mappedName']}}</td>
                <td>{{$data['WTaxRental']['mappedAt']}}</td>
                <td>{{$data['WTaxRental']['mappedBy']}}</td>
                @if($data['WTaxRental']['mapped'] == 1)
                    <td><i class="success">Mapped</i></td>
                    <td><a href="javascript: editMapping('WTaxRental','WITHHOLDING TAX RENTAL' );"><b class="error"><i class="fa fa-pencil fa-md"></i></b></a></td>
                @else
                    <td><i class="error">--Pending--</i></td>
                    <td><a href="javascript: void(0);" onclick="mapLedger('WTaxRental', 'WITHHOLDING TAX RENTAL')" class="inner"><span class="error">Map this Ledger</span></a></td>
                @endif
            </tr>
            {{--SUNDRY CREDITORS(suppliers) - LIABILITY--}}
            <tr>
                <td class="ar"></td>
                <td><a href="{{url('#')}}" class="inner"><span class="error">SUNDRY CREDITORS(suppliers)</span></a></td>
                <td>SUNDRY CREDITORS(suppliers) - Company Liability</td>
                <td>{{$data['SundryCreditors']['mappedName']}}</td>
                <td>{{$data['SundryCreditors']['mappedAt']}}</td>
                <td>{{$data['SundryCreditors']['mappedBy']}}</td>
                @if($data['SundryCreditors']['mapped'] == 1)
                    <td><i class="success">Mapped</i></td>
                    <td><a href="javascript: editMapping('SundryCreditors','SUNDRY CREDITORS(suppliers)' );"><b class="error"><i class="fa fa-pencil fa-md"></i></b></a></td>
                @else
                    <td><i class="error">--Pending--</i></td>
                    <td><a href="javascript: void(0);" onclick="mapLedger('SundryCreditors', 'SUNDRY CREDITORS(suppliers)')" class="inner"><span class="error">Map this Ledger</span></a></td>
                @endif
            </tr>

            {{--OFFICE STATIONARIES - EXPENDITURE--}}
            <tr>
                <td class="ar"></td>
                <td><a href="{{url('#')}}" class="inner"><span class="error">OFFICE STATIONARY</span></a></td>
                <td>OFFICE STATIONARY - Company Expense</td>
                <td>{{$data['OfficeStationary']['mappedName']}}</td>
                <td>{{$data['OfficeStationary']['mappedAt']}}</td>
                <td>{{$data['OfficeStationary']['mappedBy']}}</td>
                @if($data['OfficeStationary']['mapped'] == 1)
                    <td><i class="success">Mapped</i></td>
                    <td><a href="javascript: editMapping('OfficeStationary','OFFICE STATIONARY' );"><b class="error"><i class="fa fa-pencil fa-md"></i></b></a></td>
                @else
                    <td><i class="error">--Pending--</i></td>
                    <td><a href="javascript: void(0);" onclick="mapLedger('OfficeStationary', 'OFFICE STATIONARY')" class="inner"><span class="error">Map this Ledger</span></a></td>
                @endif
            </tr>

            {{--OFFICE CONSUMABLES - EXPENDITURE--}}
            <tr>
                <td class="ar"></td>
                <td><a href="{{url('#')}}" class="inner"><span class="error">OFFICE CONSUMABLES</span></a></td>
                <td>OFFICE CONSUMABLES - Company Expense</td>
                <td>{{$data['OfficeConsumables']['mappedName']}}</td>
                <td>{{$data['OfficeConsumables']['mappedAt']}}</td>
                <td>{{$data['OfficeConsumables']['mappedBy']}}</td>
                @if($data['OfficeConsumables']['mapped'] == 1)
                    <td><i class="success">Mapped</i></td>
                    <td><a href="javascript: editMapping('OfficeConsumables','OFFICE CONSUMABLES' );"><b class="error"><i class="fa fa-pencil fa-md"></i></b></a></td>
                @else
                    <td><i class="error">--Pending--</i></td>
                    <td><a href="javascript: void(0);" onclick="mapLedger('OfficeConsumables', 'OFFICE CONSUMABLES')" class="inner"><span class="error">Map this Ledger</span></a></td>
                @endif
            </tr>
            </tbody>
            <tfoot>
            <tr style="background-color: #a1b5d3">
                <th>No</th>
                <th>Ledger Name</th>
                <th>Details</th>
                <th>Mapped To</th>
                <th>Date Mapped</th>
                <th>User</th>
                <th>Status</th>
                <th></th>
            </tr>
            </tfoot>
        </table>
    </div>
@endsection

{{--System Hints Page--}}

@section('modal_heading')
    <h1>Ledger Mappings</h1>
@endsection
@section('modal_title')
    <h3><u>Management Ledger Mappings</u></h3>
    <b>
        <ol>
            <li>View All Ledger Mappings</li>
        </ol>
    </b>

@endsection




