<div class="buttons" style="margin: 10px 0px;">
    <div onclick="getPage('<?php echo site_url('gkpos/manage_delivery') ?>', 'online order')" class="col-lg-3 col-md-3 col-sm-3 col-xs-12 btn btn-danger gradient" style="font-size: 90%;" >Unassigned Jobs</div>
    <div onclick="getPage('<?php echo site_url('gkpos/manage_delivery/assigned') ?>', 'online order')" class="col-lg-3 col-md-3 col-sm-3 col-xs-12 btn  btn-success gradient" style="font-size: 90%;">Assigned Jobs</div>
    <div onclick="getPage('<?php echo site_url('gkpos/driver_account/') ?>', 'online order')" class="col-lg-3 col-md-3 col-sm-3 col-xs-12 btn btn-info gradient" style="font-size: 90%;" >Drivers' Account</div>
    <div onclick="getPage('<?php echo site_url('gkpos/add_driver') ?>', 'online order')" class="col-lg-3 col-md-3 col-sm-3 col-xs-12 btn  btn-primary gradient" style="font-size: 90%;" >Add New Driver</div>
</div>
<div class="pages-height"></div>
<div class="modal-content" style="height: auto;max-height: 450px; overflow: auto">
    <div class="filter-driver-accounts text-center" style="padding: 20px 10px;">
        <form class="form-inline" id="driverAccountForm">
            <div class="form-group" style="width: 80%">
                <input type="text" class="form-control driver_date_filter" id="driverDateFilter" placeholder="your date to show account" value="<?php echo $date ?>" style="width: 100%">
            </div>
            <div  class="btn btn-primary" onclick="filterDriverAccount('driverAccountForm')">Submit</div>
        </form>
    </div>
    <?php if (!empty($jobs)): ?>
        <?php foreach ($jobs as $key => $aDriverjobs): ?>   
            <div class="modal-header text-center">
                <?php $driverInfo = get_single_record('gkpos_driver', array('id' => $key)) ?>
                <strong><?php echo ucwords($driverInfo->name) ?></strong>
            </div>
            <table class="table table-responsive table-bg-color-white">
                <tr>
                    <th>ID</th>
                    <th>Total</th>
                    <th>Paid</th>
                    <th class="text-right">Balance</th>
                </tr>
                <?php $balance = 0; ?>
                <?php foreach ($aDriverjobs as $ajob): ?>
                    <tr>
                        <td> 
                            <?php if ($ajob->paid_status != 1): ?>
                                <a href="javascript:void(0)" onclick="payOpener('<?php echo $ajob->id ?>')" style="color: #002166"><?php echo strtoupper($ajob->id) ?></a>
                            <?php else: ?>
                                <a href="javascript:void(0)" onclick="alert('Already Paid')" style="color: #000000"><?php echo strtoupper($ajob->id) ?></a>
                            <?php endif; ?>
                        </td>
                        <td> <?php echo to_currency($ajob->grand_total) ?></td>
                        <td> <?php echo $ajob->paid_status == 1 ? 'Yes' : 'No' ?></td>
                        <td class="text-right"> 
                            <?php
                            if ($ajob->paid_status == 2) {
                                $balance+=$ajob->grand_total;
                                echo to_currency($ajob->grand_total);
                            } else {
                                echo to_currency(0);
                            }
                            ?>
                        </td>
                    </tr>
                <?php endforeach; ?>
                <tr>
                    <th colspan="4" class="text-right"><span>Balance Total </span>&nbsp;&nbsp;<span><?php echo to_currency($balance) ?></span></th>
                </tr>
            </table>
        <?php endforeach; ?>
    <?php endif; ?>
</div>
<div id="payOpener"></div>
<script>
    $(document).ready(function () {
        $(".driver_date_filter").datepicker({
            dateFormat: "dd-mm-yy"
        });
    });
    function filterDriverAccount(formId) {
        var filter_date = $('#driverDateFilter').val();
        getPage('<?php echo site_url('gkpos/driver_account/') ?>' + filter_date, 'Driver Account')
        //alert(filter_date);
    }
    function payOpener(id) {
        $.ajax({
            url: '<?php echo site_url('gkpos/payopen_for_driver') ?>',
            type: 'POST',
            data: {
                id: id
            },
            success: function (output) {
                $('#payOpener').html(output);
                if ($('.payAndClose').length > 0) {
                    jQuery(".payAndClose").colorbox({inline: true, slideshow: false, scrolling: false, height: "auto", open: true, width: '76%', left: "12%", right: "12%"});
                    return false;
                }
            }
        });
    }
</script>
