<?php
ob_start(); session_start(); 
include_once('../dbcon.php');
include_once('../session.php');

  require_once('OLEwriter.php');
  require_once('BIFFwriter.php');
  require_once('Worksheet.php');
  require_once('Workbook.php');
  
	
	$gid = $_GET['id'];
	$gname = $_GET['nm'];

   function HeaderingExcel($filename) {
      header("Content-type: application/vnd.ms-excel");
      header("Content-Disposition: attachment; filename=$filename" );
      header("Expires: 0");
      header("Cache-Control: must-revalidate, post-check=0,pre-check=0");
      header("Pragma: public");
      }
	  
	  // HTTP headers
HeaderingExcel('Group_Report.xls');// Creating a workbook
$workbook = new excel("-");
// Creating the first worksheet
$worksheet1 =& $workbook->add_worksheet('Group Toupup');
$worksheet1->freeze_panes(1, 0);
  $worksheet1->set_column(0, 0, 25);
  $worksheet1->set_column(1, 1, 20);
  $worksheet1->set_column(1, 2, 20);
  $worksheet1->set_column(1, 3, 20);
  $worksheet1->set_column(1, 4, 20);
   $worksheet1->set_column(1, 5, 20);
  $worksheet1->set_column(1, 6, 20);
  
   $worksheet1->write_string(0,0,"Trans ID");
   $worksheet1->write_string(0,1,"Trans Time");
   $worksheet1->write_string(0,2,"Trans Amount");
   $worksheet1->write_string(0,3,"First Name");
   $worksheet1->write_string(0,4,"Middle Name");
    $worksheet1->write_string(0,5,"Last Name");
   $worksheet1->write_string(0,6,"Contacts");


/////////////////
	$mpname = $_GET['mpesa_account_name'];
	  echo	$from_date = !empty($_GET['from_date']) ? $_GET['from_date'] : date('d/m/Y');
  echo    $to_date = !empty($_GET['to_date']) ? $_GET['to_date'] : date('d/m/Y');
	
 	$qryreport = mysql_query("select * from api_topups where BillRefNumber = '$mpname' and DATE(TransTime) between '" . strToDate($from_date) . "' and '" . strToDate($to_date) . "'  ");
	
	$sqlrows=mysql_num_rows($qryreport);
	$j=0;
	
	WHILE ($reportdisp=mysql_fetch_array($qryreport)) {
	$j=$j+1;
				
			$TransID = $reportdisp['TransID'];
			$TransTime = $reportdisp['TransTime'];
			$TransAmount = $reportdisp['TransAmount'];
			$FirstName = $reportdisp['FirstName'];
			$MiddleName = $reportdisp['MiddleName'];
			$LastName = $reportdisp['LastName'];
		    $MSISDN  = $reportdisp['MSISDN'];
		    
			 $worksheet1->write_string($j,0,"$TransID");
			 $worksheet1->write_string($j,1,"$TransTime");
			 $worksheet1->write_string($j,2,"$TransAmount");
			 $worksheet1->write_string($j,3,"$FirstName");
			 $worksheet1->write_string($j,4,"$MiddleName");
			 	 $worksheet1->write_string($j,5,"LastName");
			 $worksheet1->write_string($j,6,"$MSISDN");
	}
	
	
	
/////////////////

$workbook->close();





?>