<?php $__env->startSection('title', 'Manage Company Bills'); ?>


<?php $__env->startSection('internal-js'); ?>
    <script>
        $(document).ready(function () {
            $('#example').dataTable({
                dom: 'lBfrtip',
                buttons: [
                    { extend: 'excel', className: 'download-buttons'},
                    { extend: 'pdf', className: 'download-buttons'},
                ],
                footerCallback: function ( row, data, start, end, display ) {
                    var api = this.api(), data;
                    var numberRenderer = $.fn.dataTable.render.number(',', '.', 2).display;

                    // Remove the formatting to get integer data for summation
                    var intVal = function ( i ) {
                        return typeof i === 'string' ? i.replace(/[\.]/g, '.').replace(/[\,]/g, '') * 1 : typeof i === 'number' ? i : 0;
                    };

                    // Total over all pages
                    totalBillAmount = api.column( 3 ).data().reduce( function (a, b) {return intVal(a) + intVal(b);}, 0 );

                    // Total over this page
                    currentBillAmount = api.column( 3, { page: 'current'} ).data().reduce( function (a, b) {return intVal(a) + intVal(b);}, 0 );

                    // Update footer
                    $( api.column( 3 ).footer() ).html(numberRenderer(currentBillAmount) +'<br>('+ numberRenderer(totalBillAmount) +')').css('color', 'blue');

                },
            } );
            $('#example1').dataTable();
        });
        function addNewBill(){
            var route_link = '/add-new-bill';

            $('#edit_dialog_content').html('<div style="text-align: center; margin: 20px 0 20px 0;"><img src="<?php echo e(asset('images/loads/loader.gif')); ?>" border=0></div>');
            $('#edit_dialog_content').load(encodeURI(route_link));
            $('#edit_dialog_content').dialog({
                modal: true,
                width: 750,
                title: "Create New Bill for the Company",
                buttons: [
                    {
                        text: "Save Details",
                        icon: "ui-icon-check",
                        click: function(e) {
                            if(confirm('Are you sure to Save Entered Details?')){
                                e.preventDefault();
                                var datas = $('#add-new-bill').serializeArray();

                                $.ajax({
                                    method: "POST",
                                    url: route_link,
                                    data: datas,

                                    success: function (res){
                                        // alert(res);
                                        if(res == 'empty fields'){
                                            alert('Please Fill out all fields marked with a Red Asterisks*');
                                        }else if(res == 'zero amount'){
                                            alert('Entered Bill Amount should be greater than 0');
                                        }else if(res == 'bill exists'){
                                            alert('You have a Similar Bill. Please confirm that');
                                        }else if(res == 'stamp exist'){
                                            alert('There was an Internal System Error. Please Try Again');
                                        }else if(res == 'error bill master'){
                                            alert('There was an Internal System Error. Please Try Again');
                                        }else if(res == 'error' ){
                                            alert('System is Unable to perform this Request. Please try again');
                                            window.location = '/acc-bills-manager?submit=false';
                                        }else if(res == 'success'){
                                            window.location = '/acc-bills-manager?submit=true';
                                        }else{
                                            alert('System Encountered an Error. Please Contact System Admin');
                                            window.location = '/acc-bills-manager?error=system';
                                        }
                                    }
                                });
                            }
                            return false;
                        }
                    }
                ],
                open: function() {
                    $(this).parent().css({'top': 100});
                }
            });
        }
    </script>
<?php $__env->stopSection(); ?>


<?php $__env->startSection('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>

<?php $__env->stopSection(); ?>


<?php $__env->startSection('headers'); ?>
    <?php echo $__env->make('headers.finance-header', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
<?php $__env->stopSection(); ?>


<?php $__env->startSection('heading'); ?>
    Manage Company Bills
<?php $__env->stopSection(); ?>
<?php $__env->startSection('done-by', ''); ?>


<?php $__env->startSection('content'); ?>
    <?php if(isset($_GET['submit'])): ?>
        <?php if($_GET['submit'] == 'true'): ?>
            <div class="yesFound error-section">A New Bill has been Created Successfully</div><br>
        <?php endif; ?>
        <?php if($_GET['submit'] == 'false'): ?>
            <div class="notFound error-section">Error Submitting New Bill Details for Storage. Please Try again</div><br>
        <?php endif; ?>
    <?php endif; ?>
    <?php if(isset($_GET['error'])): ?>
        <?php if($_GET['error'] == 'system'): ?>
            <div class="notFound error-section">System Encountered and Error. Please Contact System Administrator for help from the Live Support </div><br>
        <?php endif; ?>
    <?php endif; ?>

    <div class="tab">
        <button class="tablinks" onclick="openCity(event, 'general')" id="defaultOpen">Bills Manager</button>
        <?php if(app('UserReads')->log == 1): ?>
            <button class="tablinks" onclick="openCity(event, 'log')" >LOG</button>
        <?php endif; ?>
    </div>
    <div class="tabcontent" id="general">
        <h3 class="error">Manage Company Bills
            <button style="margin-left: 20px; cursor: pointer;height: 25px" onclick="addNewBill()">+ Add New Bill</button>
        </h3>
        <table id="example" class="display" style="width: 100%; border-collapse: collapse;">
            <thead>
            <tr style="background-color: #a1b5d3">
                <th>No</th>
                <th>Vendor Name</th>
                <th>Branch</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>
            <?php $__currentLoopData = $lists; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $list): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                <?php if($list->currentVendorBalance($list->id) != null && $list->currentVendorBalance($list->id)['currentBalance'] > 0): ?>
                    <tr>
                        <td class="ar"></td>
                        <td><a href="<?php echo e(url('acc-vendor/'.$list->stamp)); ?>" class="inner" style="color: red; font-weight: bold" target="_blank"><?php echo strtoupper($list->name); ?></a></td>
                        <td>
                            <?php if($list->branchDetails != null): ?>
                                <?php echo $list->branchDetails->name; ?>

                            <?php else: ?>
                                <span class="error"><b>No Branch Details Found</b></span>
                            <?php endif; ?>
                        </td>
                        <td style="font-weight: bold" class="error"><?php echo number_format($list->currentVendorBalance($list->id)['currentBalance'],2); ?></td>
                        <td><b><?php echo number_format($list->currentVendorBalance($list->id)['lessThanThirty'],2); ?></b></td>
                        <td><b><?php echo number_format($list->currentVendorBalance($list->id)['thirtyAndSixty'],2); ?></b></td>
                        <td><b><?php echo number_format($list->currentVendorBalance($list->id)['sixtyAndNinety'],2); ?></b></td>
                        <td><b><?php echo number_format($list->currentVendorBalance($list->id)['ninetyAndOneEighty'],2); ?></b></td>
                        <td><b><?php echo number_format($list->currentVendorBalance($list->id)['oneEightyAndThreeSixtyFive'],2); ?></b></td>
                        <td><b class="error"><?php echo number_format($list->currentVendorBalance($list->id)['moreThanThreeSixtyFive'],2); ?></b></td>
                        <td><a href="<?php echo e(url('acc-vendor/'.$list->stamp)); ?>" class="inner" style="color: red; font-weight: bold" target="_blank"><i class="fa fa-eye error" style="font-size: 14px"></i></a></td>
                    </tr>
                <?php endif; ?>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            </tbody>
            <tfoot>
            <tr style="background-color: #a1b5d3">
                <th>No</th>
                <th>Vendor Name</th>
                <th>Branch</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>
            <?php if(isset($history)): ?>
                <?php $__currentLoopData = $history; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $histo): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <tr>
                        <td style="width: 50px" class="br"></td>
                        <td class="error"><?php echo $histo->narration; ?></td>
                        <td></td>
                        <td><?php echo e($histo->created_at->format('d/m/Y') .' at '. $histo->created_at->format('h:i:s a')); ?></td>
                    </tr>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            <?php 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>
<?php $__env->stopSection(); ?>


<?php $__env->startSection('modal_heading'); ?>
    <h1>Manage Company Bills </h1>
<?php $__env->stopSection(); ?>
<?php $__env->startSection('modal_title'); ?>
    <h3><u>Dashboard Functionalities</u></h3>
    <b>
        <ol>
            <li>View all Bills for the Company</li>
            <li>Add New Bills</li>
            <li>Delete Disapprove Bills</li>
            <li>View LOGs[Audit Trail]</li>
        </ol>
    </b>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.app', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH C:\xampp\htdocs\finewood\resources\views/finance/bills/acc-bills-manager.blade.php ENDPATH**/ ?>