<?php 
if(file_exists('../../../'.$_REQUEST['tenant'].'/config.php')){require_once('../../../'.$_REQUEST['tenant'].'/config.php');}
if(file_exists('/config.php')){require_once('/config.php');}


require_once('../../includes/master/form_functions.php');
$ret='';
$stmt = $GLOBALS['con']->prepare("SELECT `itemnumber`,`locnumber`,`desc`, `plantnumber`,`serialnumber`,`currdate`,`duedate` FROM `itemdetails` WHERE `clientnumber`=? AND `statuslive`='1' ORDER BY abs(duedate) ASC")or die(mysqli_error($GLOBALS['con']));
$stmt->bind_param('i',$_REQUEST['clientnumber']);$stmt->execute();$ic=$stmt->get_result();$stmt->close();

while($id=mysqli_fetch_array($ic)){
$stmt2 = $GLOBALS['con']->prepare("SELECT `repnumber`,`insdate` FROM `reportitems` WHERE `itemnumber`=? ORDER BY abs(repitem) DESC LIMIT 1")or die(mysqli_error($GLOBALS['con']));
$stmt2->bind_param('i',$id['itemnumber']);$stmt2->execute();$get=$stmt2->get_result();$stmt2->close();	
$rget=mysqli_fetch_array($get);
$ret.='
<tr>
<td align="center">'.$id['itemnumber'].'</a></td>
<td>'.$id['desc'].'</td>
<td>'.$id['plantnumber'].'</td>
<td>'.$id['serialnumber'].'</td>
<td>'.getItemLocation($id['itemnumber'],'postcode').'</td>
<td>'.date('d-m-Y',$rget['insdate']).'</td>
<td>'.date('d-m-Y',$id['duedate']).'</td>
</tr>';
}



$postData='
';

$pdf='<table id="coverDetails" class="table-sm" width="100%">
<thead>
<tr><td colspan="7">
<table id="repDetails" class="table-sm" width="100%">
<tbody>
<tr valign="top">
<td width="80%" valign="top"><h3>Client Schedule - '.getClientName($_REQUEST['clientnumber']).'</h3></td>
<td width="20%" align="right" valign="top" style="font-family: serif; font-size: 8pt; color: #000000; font-weight: bold;">'.getClientAddress($_REQUEST['clientnumber']).'</td>
</tr>
</tbody>
</table>
</td></tr>
<tr><th>Item No</th><th>Description</th><th>Plant Number</th><th>Serial Number</th><th>Location</th><th>Inspection date</th><th>Due Date</th></tr>
</thead>
<tbody>
'.$ret.'
</tbody>
</table>';
$orientation="L";
$default_header="";
$default_footer="yes";
$generic="yes";
$cover="";
if($_REQUEST['mode']=="split"){
$filestore='../../..'.TENANT_URL.'/output/reports/'.$_REQUEST['clientnumber'].'/'.$_REQUEST['clientnumber'].'_schedule.pdf';
include('../../includes/engines/ext.pdf.engine');
}
else{
$filestore='../../..'.TENANT_URL.'/output/reports/'.$_REQUEST['clientnumber'].'/'.$_REQUEST['clientnumber'].'_schedule.pdf';
include('../../includes/engines/ext.pdf.engine');
echo $postData;
exit();
}

?>