<?php // INVOICES PAID
function listAgent($c){

$stmt = $GLOBALS['con']->prepare("SELECT `agent_name` FROM `agents` WHERE `agent_number`='".$c."'")or die(mysqli_error("listAgent A: ".$GLOBALS['con']));
$stmt->execute();$cc=$stmt->get_result();$stmt->close();
$pd=mysqli_fetch_array($cc);
return ($pd['agent_name']);
}

$stmt = $GLOBALS['con']->prepare("SELECT * FROM `receipts` WHERE  `date`>='".$start."' AND `date`<='".$end."' ORDER BY abs(date) DESC")or die(mysqli_error("listClient B: ".$GLOBALS['con']));
$stmt->execute();$cc=$stmt->get_result();$stmt->close();
$num=mysqli_num_rows($cc);

?>

<table id="expenseTable" class="table table-striped table-bordered table-fixed">
<thead><tr><th class="c20">DATE PAID</th><th class="c10">INVOICE REF</th><th class="c30">PAYEE</th><th class="c10">DETAILS</th><th class="c10">NET</th><th class="c10">VAT</th><th class="c10">TOTAL</th><th class="c10">PAYMENT TYPE</th></tr></thead>
<tbody>

<?php while($data=mysqli_fetch_array($cc)){

$t=explode("|",$data['totals']);
$t[0]=str_replace(',','',$t[0]);
$t[1]=str_replace(',','',$t[1]);
$rnet=$t[0];
$rvat=$t[1];
$nTotal=$nTotal+$rnet;
$vTotal=$vTotal+$rvat;
$mTotal=$mTotal+$data['vMileage'];

if(!empty($data['vMileage'])){
$mileage=$data['vMileage'];
$fVat=$fVat+$t[1];
}
else{
$mileage="";
$pVat=$pVat+$t[1];
}
$gTotal=$gTotal+$data['amount'];
if(!empty($data['vRate'])){$rate="&pound;".number_format($data['vRate'],2);}else{$rate="";}
if(!empty($data['amount'])){$amount=number_format($data['amount'],2);}else{$amount="0.00";}
if(!empty($t[0])){$net=$rnet;}else{$net="0.00";}
if(!empty($t[1])){$vat=$rvat;}else{$vat="0.00";}
?>

<?php
$totals=explode('|',$data['totals']);
$totals[0]=str_replace(',','',$totals[0]);
$totals[1]=str_replace(',','',$totals[1]);
$total=0;
$total=number_format($totals[0]+$totals[1],2);
echo '
<tr>
<td class="c20">'.date('d-m-Y',$data['date']).'</td>
<td class="c10">'.sprintf("%06d", $data['invoice']).'</td>
<td class="c30">'.$data['payee'].'</td>

<td class="c10">'.$data['details'].'</td>
<td class="c10">'.number_format($totals[0],2).'</td>
<td class="c10">'.number_format($totals[1],2).'</td>
<td class="c10">&pound;'.$total.'</th>
<td class="c10">'.$data['method'].'</td>
</tr>
';
}
?>
</tbody>
<tfoot>
<tr class="footCell">
<?php
echo'
<th class="c20">Totals</th>
<th></th>
<th></th>
<th></th>
<th>&pound;'.number_format($nTotal,2).'</th>
<th>&pound;'.number_format($vTotal,2).'</th>
<th class="c10">&pound;'.number_format($nTotal+$vTotal,2).'</th>
<th class="c10"></th>
';
?>
</tr>
</tfoot>
</table>

<?php $table="expenseTable";?>