<?php // INVOICES PAID

$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);
echo $num." Rows<br>";
?>

<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></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];
if($rvat=="" || $rvat=="0" || $rvat=="0.00"){}
else{
$rtotal=($t[0]+$t[1]);
$nTotal=$nTotal+$rnet;
$vTotal=$vTotal+$rvat;
$mTotal=$mTotal+$data['vMileage'];
if($rvat=="" || $rvat=="0.00"){}
else{
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
if($data['items']!=""){$desc=$data['details'];}
$rnet=number_format($t[0],2);
$rvat=number_format($t[1],2);
$rtotal=number_format($rtotal,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">'.$desc.'</td>
<td class="c10">&pound;'.$rnet.'</td>
<td class="c10">&pound;'.$rvat.'</td>
<td class="c10">&pound;'.$rtotal.'</td>
</tr>
';
}}}
?>
</tbody>
<tfoot>
<tr class="footCell">
<?php
$nt=number_format($nTotal,2);
$vt=number_format($vTotal,2);

$nx=str_replace(',','',$nt);
$vx=str_replace(',','',$vt);
echo'
<th class="c20">Totals</th>
<th></th>
<th></th>
<th></th>
<th class="c10">&pound;'.$nt.'</th>
<th class="c10">&pound;'.$vt.'</th>
<th class="c10">&pound;'.number_format($nx+$vx,2).'</th>
';
?>
</tr>
</tfoot>
</table>

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