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

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

{{--Include any Internal JS Code--}}
@section('internal-js')
    <script>
        $(document).ready(function () {
            $('#example').dataTable();
            $('#example7').dataTable();

            $('#search-vehicle').select2();

            $('#submit-search').on('click', function (){
                var account = $('#search-vehicle').val();
                if(account == ""){
                    alert('Please Select a General Ledger Account to Search');
                }else{
                    window.location = '/general-ledger-account/'+account+'?type=summary';
                }
            });

            /**MAXIMIZE AND MINIMIZE THE HEADER SECTION**/
            $('#minimize').on('click', function (){
                $('#main-div-section').slideUp();
                $('#maximize').show();
                $('#minimize').hide();
            });
            $('#maximize').on('click', function (){
                $('#main-div-section').slideDown();
                $('#maximize').hide();
                $('#minimize').show();
            });

            $('#summary-url').on('click', function (){
                window.history.pushState({}, null, '?type=summary');
            });
            $('#log-url').on('click', function (){
                window.history.pushState({}, null, '?type=log');
            });
            $('#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;
        }
        #example1 tr:hover {background-color: #a3aef6;}

        #example2 th, td {
            text-align: left;
            padding: 5px;
        }

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

        #example3 tr:hover {background-color: #a3aef6;}
        #example7 th, td {
            text-align: left;
            padding: 5px;
        }
        #example7 tr:hover {background-color: #a3aef6;}
    </style>
@endsection

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

{{--Set Page Heading--}}

@section('heading')
    General Ledger Account.:
    @isset($account)
        <span class="error">{!! $account->acc_name !!}</span>/{{$account->acc_no}}
    @endisset
@endsection

@section('searches')
    <div style="float: right">
        <br>
        {!! Form::open(['method'=>'POST']) !!}
        <div class="guestDetails_input">
            <div class="guestDetails_input" style="text-align: center">
                <select name="search-vehicle" id="search-vehicle" style="width: 200px">
                    <option value="">--Select Ledger Account--</option>
                    @if(isset($accounts))
                        @foreach($accounts as $row)
                            <option value="{{$row->stamp}}">{!! strtoupper($row->acc_name) !!}</option>
                        @endforeach
                    @endif
                </select>
            </div>
        </div>
        <div class="guestDetails_input">
            <div class="guestDetails_input">
                <button type="button" id="submit-search" style="width: auto; height: 22px; cursor: pointer" title="Search a Product"><i class="fa fa-search" aria-hidden="true"></i></button>
            </div>
        </div>
        {!! Form::close() !!}
    </div>
@endsection
{{--Page Content Goes here--}}
@section('content')
    <div style="float: left">
        {{--        <button onclick="printOptions('{{$account->stamp}}')" type="button" class="navButtons" style="margin-left: 0px;background-color: #f1d414; color: black"><i class="fa fa-print"></i> &nbsp;PRINT OPTIONS</button>--}}
    </div>
    <div style="text-align: right">
        <button type="button" class="navButtons" style="background-color: #2f45d7" onclick="editLedgerDetails('{{$account->id}}')"><i class="fa fa-pencil-square-o"></i> &nbsp;EDIT LEDGER</button>
        <button onclick="deleteLedger('{{$account->stamp}}')" type="button" class="navButtons" style="background-color: #f10e21"><i class="fa fa-trash"></i> &nbsp;DELETE LEDGER</button>
        <div class="guestDetails_inputDivider"></div>
    </div>
    <div style="background-color: rgba(234,236,238,0.72); border-radius: 5px; padding: 5px 6px">
        <div style="float: right;">
            <i id="minimize" class="fa fa-chevron-up" aria-hidden="true" title="Minimize" style="cursor: pointer"></i>
            <i id="maximize" class="fa fa-chevron-down" aria-hidden="true" title="Maximize" style="cursor: pointer; display: none"></i>
        </div><br>
        <div id="main-div-section">
            <div class="wrapperer" id="client-table-wrapper">
                <div class="column">
                    <table  class="table" style="width: 100%; border-collapse:collapse; margin: 5px">
                        <tr>
                            <th>Ledger Name:</th>
                            <td><b class="error">{!! strtoupper($account->acc_name) !!}</b></td>
                        </tr>
                        <tr>
                            <th>Ledger Number:</th>
                            <td><b>{!! strtoupper($account->acc_no) !!}</b></td>
                        </tr>
                        <tr>
                            <th>Date Created:</th>
                            <td><b>{{date('d-m-Y', strtotime($account->created_at))}}</b></td>
                        </tr>
                    </table>
                </div>
                <div class="column">
                    <table class="table" style="width: 100%; border-collapse:collapse; margin: 5px">
                        <tr>
                            <th>Main Account:</th>
                            <td>
                                @if($account->mainAccountDetails)
                                    <b class="error">{!! strtoupper($account->mainAccountDetails->name) !!}</b>
                                @else
                                    -
                                @endif
                            </td>
                        </tr>

                        <tr>
                            <th>Ledger Is Mapped:</th>
                            <td>
                                @if($account->mapped == 1)
                                    <b class="success">YES</b>
                                @else
                                    <b class="error">NO</b>
                                @endif
                            </td>
                        </tr>
                        <tr>
                            <th>Mapped To:</th>
                            <td><b class="error">{!! $account->mappedLedger($account->mapped_id) !!}</b></td>
                        </tr>
                    </table>

                </div>
                <div class="column">
                    <table class="table" style="width: 100%; border-collapse:collapse; margin: 5px">
                        <tr>
                            <th>Currency Name:</th>
                            <td>
                                @if($account->currencyDetails != null)
                                    <b class="error">{{$account->currencyDetails->name}}({{$account->currencyDetails->abbr}})</b>
                                @endif
                            </td>
                        </tr>
                    </table>
                    <div class="guestDetails_inputDivider"></div>
                    <table style="width: 100%; border-collapse: collapse;">
                        <tr>
                            <td>
                                <button type="button" class="navButtons" style="background-color: #d9ffff;color: black; margin-bottom: 0;font-weight: bold; min-width: 200px ;font-size: 14px">ACC BAL
                                    @if($account->currencyDetails != null)
                                        ({!! $account->currencyDetails->abbr !!})
                                    @endif
                                    :
                                    <b class="error" style="margin-left: 10px">
                                        @if($account->currencyDetails != null)
                                            {!! $account->currencyDetails->symbol !!}
                                        @endif
                                        {{number_format($account->ledgerBalance($account->id),2)}}
                                    </b>
                                </button>
                            </td>
                        </tr>
                    </table>
                </div>
            </div>
        </div>

        @if($account->reversal_reason != null)
            <div class="guestDetails_inputDivider"></div>
            <div class="policy-notes">
                <table style="border-collapse: collapse; width: 100%" >
                    <tr>
                        <td><b>REVERSAL COMMENTS: </b> {!! $account->reversal_reason !!}</td>
                        <td style="text-align: right">Reversed By:
                            @if($account->reversedBy != null)
                                <b>{{$account->reversedBy->firstName." ".$account->reversedBy->lastName}}</b>
                            @endif
                        </td>
                    </tr>
                </table>
            </div>
        @endif

    </div><br>
    <div class="tab">
        <button class="tablinks" onclick="openCity(event, 'policies')" id="defaultOpen" >Recent Transactions <span class="
        @if(!1)
            {{'countItems'}}
        @else
            {{'zeroItems'}}
        @endif
        ">&nbsp;{{0}}&nbsp;</span> </button>
    </div>

    <div class="tabcontent" id="policies">
        <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 ><span class="error" style="margin-right: 20px">Recent Transaction Listing(10 Days)</span></h3>
        <div class="guestDetails_inputDivider"></div>
    </div>
@endsection
@section('created-by')
    * General Ledger Account Created
    @if($account->user != null)
        By <b>{{$account->user->firstName." ".$account->user->lastName}}</b>
    @endif
    on <b>{{$account->created_at->format('j F Y H:i:s')}}</b>
@endsection

{{--System Hints Page--}}
@section('modal_heading')
    <h1>General Ledger Account</h1>
@endsection
@section('modal_title')
    <h3><u>Dashboard Functionalities</u></h3>
    <ol><b>
            <li>View Ledger Details</li>
            <li>Amend Ledger Details</li>
            <li>Generate Ledger Transactional Report</li>
            <li>Delete a Wrongly created Ledger</li>
        </b>
    </ol>
@endsection






