
<?php $status = array('Pending', 'Confirmed', 'Cancelled', 'Wating For Online Payment') ?>
<?php $status_color = array('color:#FF9900;', 'color:#219921;', 'color:#D52229;', 'color:#FF9900;') ?>

<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="horizontal-order-list">
    <?php if (!empty($takeaway_orders)): ?>
        <?php if ($action == null): ?>
            <form id="jobAssingingForm">
                <ul class="list-group checkbox">
                    <?php foreach ($takeaway_orders as $takeaway_order): ?>
                        <?php
                        $billAddressString = '';
                        $billAddressString .= trim($takeaway_order->floor_or_apt) ? $this->lang->line('gkpos_floor_or_apt_no') . '&nbsp;:&nbsp;' . ucwords($takeaway_order->floor_or_apt) . ', ' : '';
                        $billAddressString .= trim($takeaway_order->building) ? $this->lang->line('gkpos_building') . '&nbsp;:&nbsp;' . ucwords($takeaway_order->building) . ', ' : '';
                        $billAddressString .= trim($takeaway_order->house) ? ucwords($takeaway_order->house) . '&nbsp;' : '';
                        $billAddressString .= trim($takeaway_order->street) ? ucwords($takeaway_order->street) . ', ' : '';
                        $billAddressString .= trim($takeaway_order->city) ? ucwords($takeaway_order->city) . ', ' : '';
                        $billAddressString .= trim($takeaway_order->postcode) ? ucwords($takeaway_order->postcode) : '';
                        ?>
                        <li class="list-group-item checkbox">
                            <div class="form-group">
                                <label style="font-size: 2.5em; width: 100%;" class="text-left btn btn-default btn-block">
                                    <input type="checkbox" name="orders[]" value="<?php echo $takeaway_order->id ?>"/>
                                    <span class="cr"><i class="cr-icon fa fa-check"></i></span>
                                    <span class="pull-left" style="font-size: 35%;	text-align: left"><strong>ID:<?php echo strtoupper($takeaway_order->id) ?>&nbsp;&Vert;&nbsp;Customer:<?php echo $takeaway_order->name ?>&nbsp;&Vert;&nbsp;Phone:<?php echo $takeaway_order->phone ?> &nbsp;&Vert;&nbsp; Total:<?php print to_currency($takeaway_order->grand_total) ?></strong><br/><i>Address:<?php echo $billAddressString ?></i></span>
                                </label>
                            </div>
                        </li>
                    <?php endforeach; ?>
                    <?php if (!empty($drivers)): ?>
                        <li class="list-group-item text-center">
                            <div class="form-group">
                                <h5><strong>Delivery man / Driver</strong></h5>
                                <div data-toggle="buttons">
                                    <?php foreach ($drivers as $driver): ?>
                                        <label class="btn btn-default" style="margin: 10px;">
                                            <input type="radio" name="driver" value="<?php echo $driver->id ?>">
                                            <span><?php echo '<strong>' . $driver->name . '</strong><br/>' . $driver->phone ?></span>
                                        </label>
                                    <?php endforeach; ?>
                                </div>
                            </div>
                        </li>
                        <li class="list-group-item">
                            <div><p class="btn btn-danger btn-block" style="width: 100%;height: 60px; padding: 20px 10px" onclick="assignDriver('jobAssingingForm')"><?php echo $this->lang->line('gkpos_numpad_key_enter') ?></p></div>
                        </li>
                    <?php endif; ?>
                </ul>
            </form>
        <?php else: ?>
            <table class="table table-responsive table-bg-color-white">
                <tr>
                    <th class="text-center">ID</th>
                    <th>Total</th>
                    <th>Delivery Address</th>
                    <th>Delivery Time</th>
                    <th>Driver</th>
                </tr>
                <?php foreach ($takeaway_orders as $takeaway_order): ?>
                    <?php
                    $billAddressString = $takeaway_order->street != null ? $takeaway_order->street . ', ' : '';
                    $billAddressString .= $takeaway_order->city != null ? $takeaway_order->city . ', ' : '';
                    $billAddressString .= $takeaway_order->postcode;
                    $driverInfo = get_driver_info($takeaway_order->driver);
                    ?>
                    <tr>
                        <td><?php echo strtoupper($takeaway_order->id) ?></td>
                        <td><?php echo to_currency($takeaway_order->grand_total) ?></td>
                        <td><?php echo $billAddressString ?></td>
                        <td><?php echo date('d/m/Y h:s a', strtotime($takeaway_order->delivery_time)) ?></td>
                        <td><?php echo $driverInfo->name ?></td>
                    </tr>
                <?php endforeach; ?>
            </table>
        <?php endif; ?>
    <?php else: ?>
        <div class="alert alert-dismissable alert-warning">No Delivery jobs to assign </div>
    <?php endif; ?>
</div>
<script>

    function assignDriver(jobForm) {
        var myform = document.getElementById(jobForm);
        var formdata = new FormData(myform);
        $.ajax({
            url: '<?php echo site_url('gkpos/assign_driver') ?>',
            data: formdata,
            cache: false,
            processData: false,
            contentType: false,
            type: 'POST',
            dataType: 'json',
            success: function (output) {
                if (output.success) {
                    getPage('<?php echo site_url('gkpos/manage_delivery') ?>', 'online order')
                } else {
                    alert(output.message);
                }

            }
        });
    }
</script>
<style>
    .table tr td {
        font-size: 90%!important;
    }
</style>