<? global $vis_language; 
    $paging_list='';
    for($i=0;$i<$view_info['page_count'];$i++) $paging_list.='<option value="'.$i.'" '.(($invoice_info['page']==$i)?'selected="selected"':'').'>'.($i+1).'</option>'; 
    if(VIS_BILLING_VIEW_ACCESS==0) {echo $vis_language['MSGACCSSDND']; return false;}
    ?>
<?if($invoice_count!=0) {
    $invoice_status = array( 0 => $vis_language['TXTUNPAID'], 1 => $vis_language['TXTPAID'], 2 => $vis_language['TXTCANCELED'], 3 => $vis_language['TXTINPROCESS'] );
    $is_ticket_details_tab = (isset($operation['vis_org_operation']) && $operation['vis_org_operation']=='ticket_details' || isset($operation['vis_ticket_id'])) ? 1 : 0;
    ?>
<? if($operation['vis_invoice']!=1){ ?>
<section class="padder"  id="invoice_listing">
    <section class="panel panel-default">
        <? } ?>
        <form class="form-horizontal" role="form" id="vis_invoice_list_form" name="vis_invoice_list_form" method="post">
                <div class="row wrapper clr">
                    <div class="col-sm-9 tkt_left_menu"></div>
                    <div  class="col-sm-3 text-right text-center-xs tkt_right_menu" id="paging">
                        <select name="pageing" class="form-control input-sm selectpicker pull-right paging v-middle" onchange="$(this).parents('#vis_details_list<?= ($operation['vis_ticket_id']!=0)?'_'.$operation['vis_ticket_id']:''; ?>').visExecution('load_area',{'vis_module':'billing', 'vis_org_operation':'ticket_details', 'vis_operation':'get_invoices', 'vis_page':this.value  ,'vis_client_id':'<? echo $operation['vis_client_id']; ?>','vis_ticket':1 <? if($operation['vis_ticket_id']!=0){ ?>,'vis_ticket_id':<? echo $operation['vis_ticket_id']; }?>})">
                        <? echo $paging_list;?>
                        </select>
                        <div class="text-muted pull-right label_page"><? echo $vis_language['TXTPAGE']; ?>:</div>
                    </div>
                </div>
            
            <div class="table-responsive scroll-x">
                <table class="table table-hover b-t b-light m-b-none" data-ride="datatables">
                    <thead class="table_head">
                        <tr>
                            <th><? echo $vis_language['TXTINVOICE']."#"; ?></th>
                            <th class="txt_nowrap"><? echo $vis_language['TXTCLIENT']; ?></th>
                            <th class="txt_nowrap"><? echo $vis_language['TXTCREATEDATE']; ?></th>
                            <th class="txt_nowrap"><? echo $vis_language['TXTDUEDATE']; ?></th>
                            <th class="txt_nowrap"><? echo $vis_language['TXTPAIDDATE']; ?></th>
                            <th class="txt_nowrap"><? echo $vis_language['TXTTOTAL']; ?></th>
                            <th class="txt_nowrap"><? echo $vis_language['TXTSTATUS']; ?></th>
                        </tr>
                    </thead>
                    <tbody>
                        <?
                            $total=0;
                            $paid=0;
                            $unpaid=0;
                                  for($i=0;$i<$invoice_count;$i++) {
                                  echo '<tr>';
                                  $lableCol = '';
                                  if($invoices[$i]['invoice_status'] == 0)
                                  {
                            $lableCol = 'label vh-danger-bg';
                            }
                            else if($invoices[$i]['invoice_status'] == 1)
                            {
                            $lableCol = 'label vh-green-bg';
                            }
                            else
                            {
                            $lableCol = 'label label-default';
                            }
                                  ?>
                        <td style="cursor:pointer;" onclick="$('#vis_workpanel_div').visExecution('load_module','invoices/<?echo $invoices[$i]['invoice_id']?>',{'vis_module':'billing','vis_operation':'edit_invoice', 'vis_invoice_id':<?echo $invoices[$i]['invoice_id']?>});"><? echo $invoices[$i]['invoice_hash'];?></td>
                        <td style="cursor:pointer;"><a href="#/client/client_details/<? echo $invoices[$i]['first_name'].' '.$invoices[$i]['last_name'];?>/<? echo $invoices[$i]['client_id'];?>" ><? echo $invoices[$i]['first_name'].' ('.$invoices[$i]['email'].')'; ?></a></td>
                        <? echo'<td>'.format_datetime($invoices[$i]['entry_date']).'</td><td>'.format_datetime($invoices[$i]['due_date']).'</td><td>'.format_datetime($invoices[$i]['paid_date']).'</td><td>'.$invoices[$i]['total'].'</td><td><span class="'.$lableCol.'">'.$invoice_status[$invoices[$i]['invoice_status']].'</span></td>';
                            if($invoices[$i]['invoice_status']==0) ?>
                        <?   } ?>
                        </tr>
                    </tbody>
                </table>
            </div>
            
            <footer class="wrapper panel-footer bg-white">
                <div class="row">
                    <div class="col-sm-9 tkt_left_menu"></div>
                    <div class="col-sm-3 text-right text-center-xs tkt_right_menu" id="paging">
                        <select name="pageing" class="form-control input-sm selectpicker pull-right paging v-middle" onchange="$(this).parents('#vis_details_list<?= ($ticket_id!=0)?'_'.$ticket_id:''; ?>').visExecution('load_area',{'vis_module':'billing', 'vis_operation':'get_invoices', 'vis_org_operation':'ticket_details',vis_page':this.value  ,'vis_client_id':'<? echo $operation['vis_client_id']; ?>','vis_ticket':1 <? if($operation['vis_ticket_id']!=0){ ?>,'vis_ticket_id':<? echo $operation['vis_ticket_id']; }?>})">
                        <? echo $paging_list;?>
                        </select>
                        <div class="text-muted pull-right label_page"><? echo $vis_language['TXTPAGE']; ?>:</div>
                    </div>
                </div>
            </footer>
            
        </form>
        <? if($operation['vis_invoice']!=1){ ?>
    </section>
</section>
<?  } ?> 
<? }
    else {
       include(VIS_PATH_TEMPLATE.'no_record_yet.php');
    }
    ?>
<script type="text/javascript">
    $(".selectpicker").selectpicker(); 
     $(document).ready(function() {	
     $('[data-ride="datatables"]').dataTable({		
             "bPaginate" : false,	
     		"sDom": 't', "bAutoWidth": false,
     		"aaSorting": [[ 1, "desc" ]],
     		"aoColumns": [
     		  	null,
     		  	null,
     		  	null,
     		  	null,
     		  	null,
     		  	null,
     		  	null
     		]
     	});
     });
</script>

