<?php
$actid = $activities[0]['actid'];
$owner = $activities[0]['firstname'] . ' ' . $activities[0]['lastname'];
$status = $activities[0]['activitystatus'];
$statustext = $stats[$status];
$actid_ref = $activities[0]['actid_ref'];
if($actid_ref == '0') { $actid_ref =''; }
$acttype = $activities[0]['fulltext'];
$sitename = $activities[0]['sitename'];
$actby = $activities[0]['actby'];
$reportdate = $activities[0]['reportdate'];
$opendate = $activities[0]['opendate'];
$closedate = $activities[0]['closedate'];
$reportfrom = $activities[0]['reportfrom'];
$media = $activities[0]['media'];
$mediatext = $media == '' ? $media : $medias[$media];
$action = $activities[0]['action'];
$subject = $activities[0]['subject'];
$acttypecode = $activities[0]['acttypecode'];

if(isset($invtrans[0]['purpose'])) {
	$purposecolumn = "<th>Purpose</th>";
} else {
	$purposecolumn = " ";
}

?>
<style>
p { margin:0; font-family: Arial, sans-serif; line-height:1.5;}
ul { margin:0; }
table, td, th { border:solid 1px black; border-collapse:collapse; }
td,th {padding:5px;}
</style>
<p>
<b>Activity ID : </b> <?=$actid;?><br/>
<b>Activity owner : </b> <?=$owner;?><br/>
<b>Activity status :</b> <?=$statustext;?><br/>
<b>Reference ID :</b> <?=$actid_ref;?><br/>
<b>Activity type :</b> <?=$acttype;?><br/>
<b>Site :</b> <?=$sitename;?><br/>
<?php 
if($actby == 'V') {
	echo "<b>Vendor :</b> ".$activities[0]['vendorname_2']." <br/>";
} elseif ($actby == 'P') {
	echo "<b>Product :</b> ".$activities[0]['productname']." <br/>
		<b>Serial no :</b> ".$activities[0]['productnumber']." <br/>
		<b>Software version :</b> ".$activities[0]['swversion']." <br/> 
		<b>Vendor :</b> ".$activities[0]['vendorname']." <br/>";
} elseif ($actby == 'C') {
	echo "<b>Consumables :</b> <br/>";
	foreach($consumables as $data) {
		$productname = $data['productname'];
		$catalognumber = $data['catalognumber'];
		$lotnumber = $data['lotnumber'];
		echo "- [$catalognumber] $productname Lot# $lotnumber<br/>";
	}
}
?>
<b>Report date :</b> <?=$reportdate;?><br/>
<b>Open date :</b> <?=$opendate;?><br/>
<b>Close date :</b> <?=$closedate;?><br/>
<b>Report from :</b> <?=$reportfrom;?><br/>
<b>Media :</b> <?=$mediatext;?><br/>
<b>Action By :</b> <?=$action;?><br/>
<b>Subject :</b> SUMMITCRM_<?php echo $acttypecode."_".$actid."_".$subject;?><br/>
</p>
<?php
foreach($actdetail as $actdetails) {
	$acttext = $actdetails['acttextname'];
	$acttime = $actdetails['createdate'];
	$actdetailtext = $actdetails['textvalue'];
	echo ("<br/><p><b>" . $acttext . " : " . $acttime . "</b><br/>" . $actdetailtext . "</p><br/>");
}
?>

<?php
if(count($invtrans) != 0 ) { 
?>
<b>Transaction</b>
<table>
<tr> <th>Catalog#</th> <th>Product</th> <th>Lot#</th> <th>Qty.</th> <th>Unit</th> <?= $purposecolumn; ?> </tr>
<?php
foreach($invtrans as $qdata) {
	$catalognumber = $qdata['catalognumber'];
	$productname = $qdata['productname'];
	$lotnumber = $qdata['lotnumber'];
	$qty = $qdata['qty'];
	$unit = $qdata['unit'];
	if(isset($qdata['purpose'])) {
		$purpose = $qdata['purpose'];
		$purposetext = $purpose == '' ? $purpose : $itx_purposes[$purpose];
		echo "<tr> <td>$catalognumber</td> <td>$productname</td> <td>$lotnumber</td> <td>$qty</td> <td>$unit</td> <td>$purposetext</td> </tr>";
	} else {
		echo "<tr> <td>$catalognumber</td> <td>$productname</td> <td>$lotnumber</td> <td>$qty</td> <td>$unit</td> </tr>";
	}
	
	
}
?>
</table>
<?php
}
?>