<?php
include_once('details.php');

	$compname =  $dat['company'];
	$compaddress = $dat['email'];
	$userphone = $dat['phone'];
	$compwatermark = $dat['company']." Top-up Summary";
	
//<img src="images/logo.png" height="100px;">

$html = '
<html>
<head>
<style>
body {font-family: sans-serif;
	font-size: 10pt;
}
p {	margin: 0pt; }
table.items {
	border: 0.1mm solid #000000;
}
td { vertical-align: top; }
.items td {
	border-left: 0.1mm solid #000000;
	border-right: 0.1mm solid #000000;
}
table thead td { background-color: #EEEEEE;
	text-align: center;
	border: 0.1mm solid #000000;
	font-variant: small-caps;
}
.items td.blanktotal {
	background-color: #EEEEEE;
	border: 0.1mm solid #000000;
	background-color: #FFFFFF;
	border: 0mm none #000000;
	border-top: 0.1mm solid #000000;
	border-right: 0.1mm solid #000000;
}
.items td.totals {
	text-align: right;
	border: 0.1mm solid #000000;
}
.items td.cost {
	text-align: "." center;
}
</style>
</head>
<body>

<!--mpdf
<htmlpageheader name="myheader">
<table  width="100%" style="font-size: 11pt;"  >
<tr>
<td width="15%">
<img src="'.$photo.'" height="100px;" style="margin-right:20px">
</td>
<td width="70%" class="headerData" ><h2>'.$compname.'</h2><br> Email: '.$compaddress.' <br>Tel: '.$userphone.'<br>
<td>
</tr>
<tr> <td></td><td></td> </tr>
<tr><td></td>   <td><strong>Airtime Topup Report: Condensed Account Summary</strong></td></tr>
</table>
</htmlpageheader>

<htmlpagefooter name="myfooter">
<div style="border-top: 1px solid #000000; font-size: 9pt; text-align: center; padding-top: 3mm; ">
Page {PAGENO} of {nb}
</div>
</htmlpagefooter>

<sethtmlpageheader name="myheader" value="on" show-this-page="1" />
<sethtmlpagefooter name="myfooter" value="on" />
mpdf-->



<table class="items" width="100%" style="font-size: 9pt; border-collapse: collapse; " cellpadding="8">
<thead>
<tr>
<td width="8%"> No.</td>
<td width="32%">Group</td>
<td width="20%">Total No. of Contacts</td>
<td width="20%">Amount of Airtime Sent (Ksh.)</td>

</tr>
</thead>
<tbody>
<!-- ITEMS HERE -->
';

 $num = 0; 
 $sql = mysql_query("select * from airtime_groups where customer_id = '$session_id' order by group_id ASC ");
                                                   	
		if(mysql_num_rows($sql) > 0 ){
						
			while($dt=mysql_fetch_array($sql)){ 
			  $num++;
			  
				$gid = $dt['group_id'];					
				$getconts = mysql_query("select * from airtime_contacts where group_id = '$gid' and customer_id = '$session_id' ");
				$numtotal = mysql_num_rows($getconts);
				$getrw=mysql_fetch_array($getconts);
				$phne = $getrw['contact'];
										
				$gettotal = mysql_query("select SUM(airtime_sent) AS value_sum from airtime_sending_records inner join airtime_contacts on airtime_sending_records.recipient = airtime_contacts.contact where airtime_contacts.group_id = '$gid' ");
				$row = mysql_fetch_array($gettotal); 
				$sum = $row['value_sum'];
			  
				$html .= '
					<tr>
						<td align="center">'.$num.'</td>
						<td>'.$dt['name'].'</td>
						<td >'.$numtotal.' </td>
						<td>'.$sum.'</td>

					</tr>
				';
			}
		}
			
			$html .= '


<!-- END ITEMS HERE -->


</tbody>
</table>





</body>
</html>
';
//==============================================================
//==============================================================
//==============================================================
//==============================================================
//==============================================================
//==============================================================

define('_MPDF_PATH','/');
include("mpdf.php");

$mpdf=new mPDF('c','A4-P','','',17,20,48,25,10,10); 

$mpdf->allow_charset_conversion=true;
$mpdf->charset_in='ISO-8859-2';
$mpdf->SetProtection(array('print'));
$mpdf->SetTitle("".$compwatermark."");
$mpdf->SetAuthor("".$compwatermark."");
$mpdf->SetWatermarkText("".$compwatermark."");
$mpdf->showWatermarkText = true;
$mpdf->watermark_font = 'DejaVuSansCondensed';
$mpdf->watermarkTextAlpha = 0.1;
$mpdf->SetDisplayMode('fullpage');
$mpdf->WriteHTML($html);


$mpdf->Output();

exit;

?>