{extends file="$layouts_admin"}

{block name="content"}


    <div class="row">
        <div class="col-md-12">
            <h3 class="ibilling-page-header">Delivery Challans</h3>
        </div>
    </div>
 {*
    <div class="row">
        <div class="col-md-3">
            <div class="dashboard-stat2 ">
                <div class="display">
                    <div class="number">
                        <h3 class="font-green-meadow">
                            <span class="amount" data-a-sign="{$config['currency_code']} ">{$invoice_paid_amount}</span>
                        </h3>
                        <small>{$_L['Paid']}</small>
                    </div>
                    <div class="icon">
                        <i class="fa fa-calendar-check-o"></i>
                    </div>
                </div>
                <div class="progress-info">
                    <div class="progress">
                                            <span style="width: {$p['Paid']['percentage']}%;" class="progress-bar progress-bar-primary bg-green-meadow">
                                                <span class="sr-only">{$p['Paid']['percentage']}%</span>
                                            </span>
                    </div>
                    <div class="status">
                        <div class="status-title"> {$_L['Percentage']} </div>
                        <div class="status-number"> {$p['Paid']['percentage']}% </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-md-3">
            <div class="dashboard-stat2 ">
                <div class="display">
                    <div class="number">
                        <h3 class="font-red">
                            <span class="amount" data-a-sign="{$config['currency_code']} ">{$invoice_un_paid_amount}</span>
                        </h3>
                        <small>{$_L['Unpaid']}</small>
                    </div>
                    <div class="icon">
                        <i class="fa fa-calendar-check-o"></i>
                    </div>
                </div>
                <div class="progress-info">
                    <div class="progress">
                                            <span style="width: {$p['Unpaid']['percentage']}%;" class="progress-bar progress-bar-primary bg-red">
                                                <span class="sr-only">{$p['Unpaid']['percentage']}%</span>
                                            </span>
                    </div>
                    <div class="status">
                        <div class="status-title"> {$_L['Percentage']} </div>
                        <div class="status-number"> {$p['Unpaid']['percentage']}% </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-md-3">
            <div class="dashboard-stat2 ">
                <div class="display">
                    <div class="number">
                        <h3 class="font-blue">
                            <span class="amount" data-a-sign="{$config['currency_code']} ">{$invoice_partially_paid_amount}</span>
                        </h3>
                        <small>{$_L['Partially Paid']}</small>
                    </div>
                    <div class="icon">
                        <i class="fa fa-calendar-check-o"></i>
                    </div>
                </div>
                <div class="progress-info">
                    <div class="progress">
                                            <span style="width: {$p['Partially Paid']['percentage']}%;" class="progress-bar progress-bar-primary green-sharp">
                                                <span class="sr-only">{$p['Partially Paid']['percentage']}%</span>
                                            </span>
                    </div>
                    <div class="status">
                        <div class="status-title"> {$_L['Percentage']} </div>
                        <div class="status-number"> {$p['Partially Paid']['percentage']}% </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-md-3">
            <div class="dashboard-stat2 ">
                <div class="display">
                    <div class="number">
                        <h3 class="font-blue-hoki">
                            <span class="amount" data-a-sign="{$config['currency_code']} ">{$invoice_cancelled_amount}</span>
                        </h3>
                        <small>{$_L['Cancelled']}</small>
                    </div>
                    <div class="icon">
                        <i class="fa fa-calendar-check-o"></i>
                    </div>
                </div>
                <div class="progress-info">
                    <div class="progress">
                                            <span style="width: {$p['Cancelled']['percentage']}%;" class="progress-bar progress-bar-primary bg-blue-hoki">
                                                <span class="sr-only">{$p['Cancelled']['percentage']}%</span>
                                            </span>
                    </div>
                    <div class="status">
                        <div class="status-title"> {$_L['Percentage']} </div>
                        <div class="status-number"> {$p['Cancelled']['percentage']}% </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    *}

    <div class="row">
        <div class="col-md-12">
                            {if $view_type == 'filter'}
                      {*  <form class="form-horizontal" method="post" action="">
                            <div class="form-group">
                                <div class="col-md-12">
                                    <div class="input-group">
                                        <div class="input-group-addon">
                                            <span class="fa fa-search"></span>
                                        </div>
                                        <input type="text" name="name" id="foo_filter" class="form-control" placeholder="{$_L['Search']}..."/>

                                    </div>
                                </div>

                            </div>
                        </form> *}
                    {/if}


                <form class="form-horizontal" method="post" action="{$_url}crmdelivery/deliverychallan-list">
                            <div class="row">
                                <div class="col-md-2">
                                    
                                    
                                        

                                    
                                    
                                        
                                       
                                </div>
                                 <div class="col-md-6">
                                     Choose Date
                               <input type="date" id="today_date" name="today_date" value={$today} class="form-control"/>
                               </div>
                                <div class="col-md-4">
                                   <br/>
                                        <button type="submit"  class="btn btn-primary ">Submit </button>
                                </div>
                                

                            </div>
                        </form>
                        <br/>
         <form action="{$_url}crmdelivery/deliverychallan-deleteall" method="post">
            <div class="ibox float-e-margins">
            
                <div class="ibox-title">
                
                    {*{if $view_type == 'filter'}*}
                        {*<h5>{$_L['Total']} : {$total_invoice}</h5>*}
                    {*{else}*}
                        {*<h5>{$paginator['found']} {$_L['Records']}. {if $paginator['found'] > 0}{$_L['Page']} {$paginator['page']} {$_L['of']} {$paginator['lastpage']}.{/if}</h5>*}
                    {*{/if}*}

                    Delivery Orders
                   

                    <div class="ibox-tools">
                        {*{if $view_type neq 'filter'}*}
                            {*<a href="{$_url}invoices/list/filter/" class="btn btn-primary btn-xs"><i class="fa fa-search"></i> {$_L['Filter']}</a>*}
                        {*{else}*}
                            {*<a href="{$_url}invoices/list/" class="btn btn-primary btn-xs"><i class="fa fa-arrow-left"></i> {$_L['Back']}</a>*}
                        {*{/if}*}
                        {*<a href="{$_url}invoices/list-recurring/" class="btn btn-success btn-xs"><i class="fa fa-repeat"></i> {$_L['Manage Recurring Invoices']}</a>*}
                        <input type="checkbox"  value="Check All" class="did" name="checkAll" id="checkAll"/> <label id="lblcheck" class="btn-info">Select All</label>

                        <button id="hrefSelect" onclick="return confirm('This action cannot be undone.Are you sure?')" class="btn btn-danger btn-xs"><i class="fa fa-trash"></i> Delete Delivery Chellans</a> </button>

                        {* <a href="{$_url}crmdelivery/deliverychallan-deleteall/" id="hrefSelect" onclick="return confirm('This action cannot be undone.Are you sure?')" class="btn btn-danger btn-xs"><i class="fa fa-trash"></i> Delete Delivery Chellans</a> *}

                        <a href="{$_url}crmdelivery/deliverychallan-add/" class="btn btn-primary btn-xs"><i class="fa fa-plus"></i> Add Delivery Chellan</a>
                        <a href="{$_url}crmdelivery/driver-manual-assign"  class="btn btn-inverse  btn-sm"><i class="fa fa-car"></i> Manual Assign </a>

                        <a href="{$_url}crmdelivery/driver-assign"  class="btn btn-inverse  btn-sm"><i class="fa fa-car"></i> Smart Assign Driver </a>
                      {*  <a href="{$_url}reports/invoices/" class="btn btn-primary btn-xs"><i class="fa fa-bar-chart"></i> {$_L['View Reports']}</a> *}

                    </div>
                </div>
                <div class="ibox-content">





                    <table class="table table-bordered table-hover sys_table footable" {if $view_type == 'filter'} data-filter="#foo_filter" data-page-size="50" {/if}>
                        <thead>
                        <tr>
                            <th></th>
                            <th>#</th>
                            <th>Customer</th>
                            <th>Delivery Date</th>
                            <th>Assigned Driver</th>
                            <th>
                                {$_L['Status']}
                            </th>
                            <th class="text-right" width="140px;">{$_L['Manage']}</th>
                        </tr>
                        </thead>
                        <tbody>

                        {foreach $dn as $ds}
                            <tr>
                            <td><input type="checkbox" class="did" name="did[]" value="{$ds['id']}" ></td>
                                <td  data-value="{$ds['id']}"><a href="{$_url}crmdelivery/view/{$ds['id']}/">{$ds['cn']}</a> </td>
                                <td>
                                    {if isset($contacts[$ds['userid']])}
                                        <a href="{$_url}crmdelivery/view/{$ds['id']}/">
                                            {$ds['account']}
                                            {if $contacts[$ds['userid']]->company != ''}
                                              <br>  {$contacts[$ds['userid']]->company}
                                            {/if}

                                        </a>
                                    {/if}
                                </td>
                                <td>{$ds['c2']|date_format:"%d-%m-%Y"}</td>
                                <td> {$ds['fullname']}</td>
                                <td>
                                                {if $ds['delivery_status'] eq 'Unassigned'}
                                                <span class="label label-danger">{$ds['delivery_status']}</span>
                                                {elseif $ds['delivery_status'] eq 'Assigned'}
                                                    <span class="label label-info">{$ds['delivery_status']}</span>
                                                {elseif $ds['delivery_status'] eq 'Acknowledged'}
                                                    <span class="label label-primary">{$ds['delivery_status']}</span>
                                                {elseif $ds['delivery_status'] eq 'Started'}
                                                    <span class="label label-warning">{$ds['delivery_status']}</span>
                                                {elseif $ds['delivery_status'] eq 'Inprogress'}
                                                    <span class="label label-default">{$ds['delivery_status']}</span>
                                                {elseif $ds['delivery_status'] eq 'Successful'}
                                                    <span class="label label-success">{$ds['delivery_status']}</span>
                                                {else}
                                                    <span class="label label-danger">{$ds['delivery_status']}</span>
                                                {/if}
                                </td>
                               
                           
                                <td class="text-right">

                                    {*<a href="{$_url}invoices/view/{$ds['id']}/" class="btn btn-primary btn-xs"><i class="fa fa-check"></i> {$_L['View']}</a>*}
                                    {*<a href="{$_url}invoices/edit/{$ds['id']}/" class="btn btn-info btn-xs"><i class="fa fa-pencil"></i> {$_L['Edit']}</a>*}
                                    {*<a href="#" class="btn btn-danger btn-xs cdelete" id="iid{$ds['id']}"><i class="fa fa-trash"></i> {$_L['Delete']}</a>*}

                                    <a href="{$_url}crmdelivery/view/{$ds['id']}/" class="btn btn-primary btn-xs" data-toggle="tooltip" data-placement="top" title="{$_L['View']}"><i class="fa fa-file-text-o"></i></a>

                                    {if $ds['delivery_status'] eq 'Unassigned' || $ds['delivery_status'] eq 'Assigned'}
                                        <a href="{$_url}crmdelivery/edit/{$ds['id']}/" class="btn btn-info btn-xs" data-toggle="tooltip" data-placement="top" title="{$_L['Edit']}"><i class="fa fa-pencil"></i></a>

                        

                                        {* <a href="#" class="btn btn-danger btn-xs cdelete" id="iid{$ds['id']}" data-toggle="tooltip" data-placement="top" title="{$_L['Delete']}"><i class="fa fa-trash"></i></a> *}
                                    {/if}


                                </td>
                            </tr>
                        {/foreach}

                        </tbody>

                        {if $view_type == 'filter'}
                            <tfoot>
                            <tr>
                                <td colspan="8">
                                    <ul class="pagination">
                                    </ul>
                                </td>
                            </tr>
                            </tfoot>
                        {/if}

                    </table>
                    {$paginator['contents']}
                </div>
            </div>
            </form>
        </div>
    </div>
{/block}
{block name="script"}
<script>

        $(function() {
            $('.did').prop('checked', false);
            $('#checkAll').prop('checked', false);
            document.getElementById('lblcheck').innerHTML = 'Select All';


            $(document).on('click', '#checkAll', function() {
                
                
                if ($(this).val() == 'Check All') {
                    
                    $('.did').prop('checked', true);
                    $('#checkAll').prop('checked', true);
                    $(this).val('Uncheck All');
                    document.getElementById('lblcheck').innerHTML = 'Unselect All';
                    document.getElementById('hrefSelect').innerHTML = 'Delete Selected Delivery Chellans';

                } else {
                    $('.did').prop('checked', false);
                     $('#checkAll').prop('checked', false);   
                    $(this).val('Check All');
                    document.getElementById('lblcheck').innerHTML = 'Select All';
                    document.getElementById('hrefSelect').innerHTML = 'Delete Delivery Chellans';


                }
            });
        
        });
</script>
{/block}