<?php
$rab_number_tot = 0;


echo "<table class='table table-bordered table-hover' >";
    echo "<tr>";
	echo "<th  class='text-center'>" . $n_rab_date . "</th>";
    echo "<th  class='text-center'>" . $nday . "</th>";
    echo "<th  class='text-center'>" . $ntotal . "</th>";
    echo "</tr>";
include('r_dbc.php');
if ($cidx1 == "total") 
{
$sql="SELECT date_format(r.rab_date,'%d-%b-%y') as rab_datec,sum(r.rab_number) as rab_number
			FROM ccmanager r, centers c
			WHERE r.pid = '".$pidx."'
			and r.code_center = c.code_center
			and r.pid = c.pid
			and r.mid in (select mid from ccmanager_id where expenses = 1 and pid = c.pid)
			and r.rab_number > 0
			group by date_format(r.rab_date,'%d-%b-%y')
			order by r.rab_date";
}
if ($cidx1 == "totalg") 
{
$sql="SELECT date_format(r.rab_date,'%d-%b-%y') as rab_datec,sum(r.rab_number) as rab_number,'' as desc_center,'' as code_center_group
			FROM ccmanager r, centers c
			WHERE r.pid = '".$pidx."'
			and c.code_center_group = '".$cidx2."'
			and r.code_center = c.code_center
			and r.pid = c.pid
			and r.mid in (select mid from ccmanager_id where expenses = 1 and pid = c.pid)
			and r.rab_number > 0
			group by date_format(r.rab_date,'%d-%b-%y')
			order by r.rab_date";
}
if ($cidx1 == "totalc") 
{
$sql="SELECT date_format(r.rab_date,'%d-%b-%y') as rab_datec,sum(r.rab_number) as rab_number,c.desc_center,r.code_center
			FROM ccmanager r, centers c
			WHERE r.code_center = '".$cidx2."'
			and r.pid = '".$pidx."'
			and r.code_center = c.code_center
			and r.pid = c.pid
			and r.mid in (select mid from ccmanager_id where expenses = 1 and pid = c.pid)
			and r.rab_number > 0
			group by date_format(r.rab_date,'%d-%b-%y'),c.desc_center,r.code_center
			order by r.rab_date";
}
$result = mysqli_query($conn, $sql);

if (mysqli_num_rows($result) > 0) {
      while($row = mysqli_fetch_assoc($result)) {	
			$rab_datec 	= $row['rab_datec'];
			$rab_number = $row['rab_number'];
			$rab_number_tot = $rab_number_tot + $rab_number;
			$c_rab_number	= number_format($rab_number,  $totdc, $septh, $sepdc);
			$c_rab_number_tot	= number_format($rab_number_tot,  $totdc, $septh, $sepdc);
    echo "<tr>";
	echo "<td class='text-center'>" . $rab_datec . "</td>";
    echo "<td class='text-end'>" . $c_rab_number . "</td>";
    echo "<td class='text-end'>" . $c_rab_number_tot . "</td>";	
    echo "</tr>";
}
}
    echo "<tr>";
	echo "<th class='text-center'>" . $ntotal . "</td>";
    echo "<th class='text-end'>" . $c_rab_number_tot . "</td>";
    echo "<th class='text-end'></td>";	
    echo "</tr>";
echo "</table>";
mysqli_close($conn);
?>
