<?php $_REQUEST['src']="ext2";require_once('../../functions/global.php'); 

$date=strtotime('now');

// GET CLIENTS
$stmt = $GLOBALS['con']->prepare("SELECT `clientnumber`,`clientname`,`phone1`,`email`,`pri_contact_name`,`account_handler`,`contract_number` FROM `clientdetails` WHERE `statuslive`='1' ORDER BY `clientname` DESC")or die(mysqli_error("LIST: ".$GLOBALS['con']));
$stmt->execute();$cc=$stmt->get_result();$stmt->close();
while($cl=mysqli_fetch_array($cc)){$clientData[]=$cl;}

$stmt2 = $GLOBALS['con']->prepare("SELECT `agent_number`,`agent_name`,`tel`,`email` FROM `agents` WHERE `statuslive`='1' ORDER BY `agent_name` DESC")or die(mysqli_error("LIST: ".$GLOBALS['con']));
$stmt2->execute();$ac=$stmt2->get_result();$stmt2->close();
while($al=mysqli_fetch_array($ac)){$agentData[]=$al;}



/////////// Invoices Client
foreach($clientData as $c){
$stmt = $GLOBALS['con']->prepare("SELECT * FROM `invoices` WHERE `client`='".$c['clientnumber']."' ORDER BY abs(invNo) DESC")or die("Invoices Client: ".mysqli_error($GLOBALS['con']));
$stmt->execute();$cc=$stmt->get_result();$stmt->close();
$count=mysqli_num_rows($cc);
if($count!=0){
echo $count."<br>";
}
}


/////////// Invoices Agent
foreach($agentData as $a){
$stmt = $GLOBALS['con']->prepare("SELECT * FROM `invoices` WHERE `agent`='".$a['agent_number']."' ORDER BY abs(invNo) DESC")or die("Invoices Agent: ".mysqli_error($GLOBALS['con']));
$stmt->execute();$cc=$stmt->get_result();$stmt->close();
$count=mysqli_num_rows($cc);
if($count!=0){
echo $count."<br>";
}
}
