<script type="text/javascript" src="<?= VIS_PATH_SCRIPT; ?>datatables/data-tables/DT_bootstrap.js"></script>
<? 
    global $vis_language;
    if($invoices!=-1) { 
		$total=0;$paid=0;$unpaid=0;
		for($i=0;$i<count($invoices);$i++) {
			if($invoices[$i]['invoice_status'] == 0)$unpaid +=$invoices[$i]['total'];
            else if($invoices[$i]['invoice_status'] == 1)$paid +=$invoices[$i]['total'];
			$total +=$invoices[$i]['total'];
		}?>
<table cellpadding="0" cellspacing="0" border="0" class="table table-hover b-t b-light m-b-none" id="datatable">
		<thead class="table_head">
		<tr>
			<th colspan="2"><? echo $vis_language['TXTTOTAL'].": ".$total.' '.$domain[0]['currency']; ?></th>
			<th colspan="2"><? echo $vis_language['TXTTOTALPAID'].": ".$paid.' '.$domain[0]['currency']; ?></th>
			<th colspan="3"><? echo $vis_language['TXTTOTALUNPAID'].": ".$unpaid.' '.$domain[0]['currency']; ?></th>
		</tr> 
		<tr>
			<th><? echo $vis_language['TXTINVOICE']."#"; ?></th>
			  <th><? echo $vis_language['TXTCLIENT']; ?></th>
			  <th><? echo $vis_language['TXTORGN']; ?></th>
			  <th><? echo $vis_language['TXTCREATEDATE']; ?></th>
			  <th><? echo $vis_language['TXTDUEDATE']; ?></th>
			  <th><? echo $vis_language['TXTPAIDDATE']; ?></th>
			  <th><? echo $vis_language['TXTTOTAL'].' ('.$domain[0]['currency'].')'; ?></th>
			  <th><? echo $vis_language['TXTSTATUS']; ?></th>									
		</tr>
		</thead>
            <?
				$invoice_status = array( 0 => $vis_language['TXTUNPAID'], 1 => $vis_language['TXTPAID'], 2 => $vis_language['TXTCANCELED'], 3 => $vis_language['TXTINPROCESS'] );
                  
                for($i=0;$i<count($invoices);$i++) {
					$clientContact = ($invoices[$i]['client_type']==0)?$invoices[$i]['email']:$invoices[$i]['contact_number'];
					echo '<tr>';
                        $lableCol = '';
                        if($invoices[$i]['invoice_status'] == 0)
                        {
							$lableCol = 'vh-danger-bg';
						}
						else if($invoices[$i]['invoice_status'] == 1)
						{
							$lableCol = 'label vh-green-bg';
						}
						else
						{
							$lableCol = 'label label-default';
						}
						
						// Newly added code to check paid date empty or not and show value
						if($invoices[$i]['paid_date']==0){
							$paid_date = '---';
						}else{
							  $paid_date = date(VIS_EDITDATETIMEPICKER_FORMAT,$invoices[$i]['paid_date']);
						}
                        ?>
				
               <td class="vis-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>
               <?php /*?><td class="vis-pointer"><a  onclick="$('#vis_workpanel_div').visExecution('load_area',{'vis_module':'client','vis_operation':'client_details', 'vis_client_id':<?echo $invoices[$i]['client_id']?>});" ><? echo $invoices[$i]['first_name'].' ('.$clientContact .')'; ?></a></td><? echo '<td>'.$invoices[$i]['group_name'].'</td><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="label '.$lableCol.'">'.$invoice_status[$invoices[$i]['invoice_status']].'</span></td>';
               } ?><?php */?>
               <td class="vis-pointer"><a  onclick="$('#vis_workpanel_div').visExecution('load_area',{'vis_module':'client','vis_operation':'client_details', 'vis_client_id':<?echo $invoices[$i]['client_id']?>});" ><? echo $invoices[$i]['first_name'].' ('.$clientContact .')'; ?></a></td><? echo '<td>'.$invoices[$i]['group_name'].'</td><td>'.date(VIS_EDITDATETIMEPICKER_FORMAT,$invoices[$i]['entry_date']).'</td><td>'.date(VIS_EDITDATETIMEPICKER_FORMAT,$invoices[$i]['due_date']).'</td><td>'.$paid_date.'</td><td>'.$invoices[$i]['total'].'</td><td><span class="label '.$lableCol.'">'.$invoice_status[$invoices[$i]['invoice_status']].'</span></td>';
               } ?>
               </tr>
               
</table>
		<script>
			$("#vis_export_rpt_<?= $operation['vis_operation'] ?>").show(); 
			$("#vis_export_rpt_<?= $operation['vis_operation'] ?>").html('<a href="javascript:void(0);" class="vis_button_export btn btn-primary btn-sm" data-toggle="ajaxModal" data-modal-arguments="vis_module=report&vis_operation=add_report_inqueue&vis_static_area=vis_open_new_dialog&duration=<? echo $data['duration']; ?>&from_date=<? echo strtotime($data['from_date']); ?>&to_date=<? echo strtotime($data['to_date']);?>&domain_id=<? echo $data['domain_id'];?>&vis_client_id=<? echo $data['vis_client_id'];?>&vis_criteria=<? $data['vis_criteria'];?>&report_type=20" onclick="" type="button"><? echo $vis_language['TXTEXPORT']; ?></a>');
			
			$("#vis_schedule_rpt_<?= $operation['vis_operation'] ?>").show(); 
			$("#vis_schedule_rpt_<?= $operation['vis_operation'] ?>").html('<a href="javascript:void(0);" class="vis_button_export btn btn-primary btn-sm" data-toggle="ajaxModal" data-modal-arguments="vis_module=report&vis_operation=add_schedule_report_inqueue&vis_static_area=vis_open_new_dialog&duration=<? echo $data['duration']; ?>&from_date=<? echo strtotime($data['from_date']); ?>&to_date=<? echo strtotime($data['to_date']);?>&domain_id=<? echo $data['domain_id'];?>&vis_client_id=<? echo $data['vis_client_id'];?>&vis_criteria=<? $data['vis_criteria'];?>&report_type=20" onclick="" type="button"><? echo $vis_language['TXTSCHEDULE']; ?></a>');
		</script> <?php
    }
    else  {
		 $operation['no_record']=1;
         include(VIS_PATH_TEMPLATE.'no_record_yet.php');
        ?>
             <script> $("#vis_export_rpt_<?= $operation['vis_operation'] ?>").hide();
             $("#vis_schedule_rpt_<?= $operation['vis_operation'] ?>").hide();</script>          
        <?php
    } ?>
	<script>
$(document).ready(function() {	
$('#datatable').dataTable({		
        "bPaginate" : true,
        "aaSorting":  [],
        "iDisplayLength": <?php echo SECURITY_DATA_PER_PAGE;?>,
		"sDom": '<"top"iflp<"clear">>rt<"bottom"iflp<"clear">>', 		
	    "bFilter" : false,
		"bLengthChange": false,
		"bInfo": false,
		"aoColumns": [
			{ "bSortable": true },
		  	{ "bSortable": true },	
			{ "bSortable": true },			  
		  	{ "bSortable": true },
			{ "bSortable": true },
			{ "bSortable": true },
		  	{ "bSortable": true },
            { "bSortable": true }			
		]
	});
});	
</script>
