<?php $_REQUEST['src']="ext2";require_once('../../functions/global.php');
ini_set('max_execution_time', '3000');
$record=file_get_contents('reports.txt');
$record=explode("|",$record);
if(strtotime($record[0]) < strtotime('today')){

function listOutstandingReports2($item){
$stmt = $GLOBALS['con']->prepare("SELECT `repitem` FROM `reportitems` WHERE `delivery`='0' AND `itemnumber`='".$item."' ORDER BY abs(repitem) ASC LIMIT 1")or die(mysqli_error("GET_INV_NO: ".$GLOBALS['con']));
$stmt->execute();$iv=$stmt->get_result();$stmt->close();
return mysqli_num_rows($iv);
}



$stmt = $GLOBALS['con']->prepare("SELECT `clientnumber`,`clientname` FROM `clientdetails` WHERE `statuslive`='1' ORDER BY `clientname` ASC")or die(mysqli_error($GLOBALS['con']));$stmt->execute();$client=$stmt->get_result();$stmt->close();?>

<?php while($cdata=mysqli_fetch_array($client)){
$stmt = $GLOBALS['con']->prepare("SELECT `itemnumber` FROM `itemdetails` WHERE `clientnumber`='".$cdata['clientnumber']."' AND `statuslive`='1'")or die(mysqli_error($GLOBALS['con']));
$stmt->execute();$iv=$stmt->get_result();$stmt->close();
$itemCount=0;
while($idata=mysqli_fetch_array($iv)){
$num=listOutstandingReports2($idata['itemnumber']);
if($num==0){}
else{$itemCount++;
}}
if($itemCount!=0){

$output.'<tr id="R'.$list['clientnumber'].'">
<td>'.$cdata['clientname'].'</td>
<td>'.$itemCount.'</td>
<td>

<a href="index.php?t=includes/master/&p=reports_outstanding.php&clientnumber='.$cdata['clientnumber'].'" class="btn btn-secondary float-end" data-mdb-tooltip-init data-mdb-placement="bottom" data-mdb-trigger="hover"  title="View Reports" title="View Reports"><i class="fad fa-eye"></i></a>

</td>
</tr>';
}}
$reportFile = fopen("reports.txt", "w");
fwrite($reportFile, date('d-m-Y')."|".$output);
fclose($reportFile);

}?>