<?php
require_once('Spreadsheet/Excel/Writer.php');

session_start();
if($_SESSION['dbName']==""){
header("location:../index.php");
}


include("config.inc.php");

//Set Time Execution For the Report
ini_set('max_execution_time', $config['ReportTimeExecution']);

$connection = mysql_connect($config['dbServer'],$config['dbUser'],$config['dbPass']) or die("Could not connect to DB");
mysql_select_db($_SESSION['dbName'],$connection) or die("Could not find DB");

$querylog=" select ifNull(FI_RepRestrictProject,0) As FI_RepRestrictProject, ifNull(FI_RepRestrictCostcenter,0) As FI_RepRestrictCostcenter, ".
		  " ifNull(FI_RepRestrictWarehouse,0) As FI_RepRestrictWarehouse ".
          " from ".$_SESSION['dbLabel'].".login where user_account='".$_SESSION['useraccount']."' and Upper(Login_Schema) = Upper('".$_SESSION['dbName']."') ";
$resultlog=mysql_query($querylog) or die(mysql_error());
while($rows=mysql_fetch_array($resultlog)){
	extract($rows);
}

$querysetup="select grid_color1,grid_color2, DecimalBase, DecimalBase1, DecimalBase2, Base1, Base2, Company_Name As CompanyName from setup";
$resultsetup=mysql_query($querysetup,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($resultsetup)){
  extract($rows);
}


$queryproject=" select distinct project.project_code, project_name ".
              " from project left join ".$_SESSION['dbLabel'].".loginstk on project.project_code like concat(ifnull(loginstk.project_code,project.project_code),'%') ".
			  " where user_account='".$_SESSION['useraccount']."' ".
			  " and (loginstk.project_code is not null and loginstk.project_code != '') ".
			  " order by project.project_code";
$projectresult = mysql_query($queryproject,$connection) or die(mysql_error());
$projectexist   = mysql_num_rows($projectresult);

$querycostcent=" select distinct costcent.costcent_code, costcent_name ".
               " from costcent left join ".$_SESSION['dbLabel'].".loginstk on costcent.costcent_code like concat(ifnull(loginstk.costcent_code,costcent.costcent_code),'%') ".
			   " where user_account='".$_SESSION['useraccount']."' ".
			   " and (loginstk.costcent_code is not null and loginstk.costcent_code != '') ".
			   " order by costcent.costcent_code";
$costcentresult = mysql_query($querycostcent,$connection) or die(mysql_error());
$costcentexist  = mysql_num_rows($costcentresult);



$querywh=" select distinct warehouse.warehouse_code, warehouse_name ".
         " from warehouse where warehouse_code in (select warehouse_code from ".$_SESSION['dbLabel'].".loginstk where user_account='".$_SESSION['useraccount']."') ".
		 " order by warehouse.warehouse_code";
$resultwh = mysql_query($querywh,$connection) or die(mysql_error());
$whexist   = mysql_num_rows($resultwh);	


$now=current_server_time($connection);
$dt=split(" ",$now[0]);
$printdate=split("-",$dt[0]);

	
//Creating a workbook
$workbook = new Spreadsheet_Excel_Writer();

//Sending HTTP headers
$workbook->send('Exp_ListofTransfer.xls');
 
//Creating a worksheet
$worksheet=&$workbook->addWorksheet('List of Transfer');
$worksheet->setLandscape();
 
//set all columns same width
$columnWidth = 10;

//Title Format 
$sheetTitleFormat =& $workbook->addFormat(array('bold'=>1,
  'size'=>10));

//Column Title Format  
$columnTitleFormat =& $workbook->addFormat(array('bold'=>1,
  'top'=>1,
  'bottom'=>1 ,
  'size'=>15,
  'color'=>0x0A,
  ));
  
 
  
// Regular Format
$regularleftFormat =& $workbook->addFormat(array('size'=>9,
  'align'=>'left'  ));
$regularrightFormat =& $workbook->addFormat(array('size'=>9,
  'align'=>'right'  ));  
$regularrightFormatNum =& $workbook->addFormat(array('size'=>9,
  'align'=>'right'  ));  
$regularcenterFormat =& $workbook->addFormat(array('size'=>9,
  'align'=>'center'  ));    
  
$regularleftFormat1 =& $workbook->addFormat(array('size'=>8,
  'align'=>'left'  ));
$regularrightFormat1 =& $workbook->addFormat(array('size'=>8,
  'align'=>'right'  ));    
$regularrightFormat1Num =& $workbook->addFormat(array('size'=>8,
  'align'=>'right'  )); 
  
$TitleFormat =& $workbook->addFormat(array('size'=>11,
  'align'=>'left',
  'bold'=>1
  ));

$boldleftFormat =& $workbook->addFormat(array('size'=>9,
  'align'=>'left'  ,
  'valign'=>'top'  ,
  'bold'=>1
  ));  
$boldrightFormat =& $workbook->addFormat(array('size'=>9,
  'align'=>'right'  ,
  'bold'=>1
  )); 
$boldrightFormatNum =& $workbook->addFormat(array('size'=>9,
  'align'=>'right'  ,
  'bold'=>1
  )); 
$boldcenterFormat =& $workbook->addFormat(array('size'=>9,
  'align'=>'center'  ,
  'valign'=>'top'  ,
  'bold'=>1
  ));    
  
$grouplevel1Format =& $workbook->addFormat(array('size'=>10,
  'align'=>'left',
  'bold'=>1,
  'color'=>0x0C
  )); 
$grouplevel2Format =& $workbook->addFormat(array('size'=>10,
  'align'=>'left',
  'bold'=>0,
  'color'=>0x0A
  )); 
$grouplevel3Format =& $workbook->addFormat(array('size'=>9,
  'align'=>'left',
  'italic'=>1,
  'color'=>0x11
  ));   
$grouplevel1totalFormat =& $workbook->addFormat(array('size'=>10,
  'align'=>'right',
  'bold'=>1,
  'color'=>0x0C
  ));  
$grouplevel2totalFormat =& $workbook->addFormat(array('size'=>10,
  'align'=>'right',
  'bold'=>0,
  'color'=>0x0A
  ));  
$grouplevel3totalFormat =& $workbook->addFormat(array('size'=>9,
  'align'=>'right',
  'italic'=>1,
  'color'=>0x11
  ));   

$seloptionFormat =& $workbook->addFormat(array('size'=>9,
  'align'=> 'left'  ,
  'valign'=> 'top'  ,
  'bold'=> 1
  ));
$seloptionFormat->setTextWrap();

$regularrightFormatNum->setNumFormat('_(* #,##0.00_);_(* (#,##0.00);_(* "-"??_);_(@_)');
$regularrightFormat1Num->setNumFormat('_(* #,##0.00_);_(* (#,##0.00);_(* "-"??_);_(@_)');
$boldrightFormatNum->setNumFormat('_(* #,##0.00_);_(* (#,##0.00);_(* "-"??_);_(@_)');
$grouplevel1totalFormat->setNumFormat('_(* #,##0.00_);_(* (#,##0.00);_(* "-"??_);_(@_)');

$fromdate 		= $_GET['fromdate'];
$todate 		= $_GET['todate'];
$fromitem 		= $_GET['fromitem'];
$toitem 		= $_GET['toitem'];

$fromgroup 		= $_GET['fromgroup'];
$togroup 		= $_GET['togroup'];
$fromsubgroup 	= $_GET['fromsubgroup'];
$tosubgroup 	= $_GET['tosubgroup'];
$fromcategory 	= $_GET['fromcategory'];
$tocategory 	= $_GET['tocategory'];

$fromproject 	= $_GET['fromproject'];
$toproject 		= $_GET['toproject'];
$fromcostcent 	= $_GET['fromcostcent'];
$tocostcent 	= $_GET['tocostcent'];
$fromwh 		= $_GET['fromwh'];
$towh 			= $_GET['towh'];

$chkdetail 		= $_GET['chkdetail'];
$grpused 		= $_GET['grpused'];


if ($grpused == '21'){
	$dispgroupby = 'From Project';
	$groupby 	 = 'transferdt.Project_code1';
	$groupbyname = 'frmprjt.project_name';
} else if ($grpused == '22'){
	$dispgroupby = 'To Project';
	$groupby 	 = 'transferdt.Project_code2';
	$groupbyname = 'toprjt.project_name';
} 
else if ($grpused == '31'){
	$dispgroupby = 'From Costcenter';
	$groupby 	 = 'transferdt.Costcent_Code';
	$groupbyname = 'frmcostcent.Costcent_name';
}
else if ($grpused == '32'){
	$dispgroupby = 'To Costcenter';
	$groupby 	 = 'transferdt.ToCostcent_Code';
	$groupbyname = 'tocostcent.Costcent_name';
}
else if ($grpused == '41'){
	$dispgroupby = 'From Warehouse';
	$groupby 	 = 'transferdt.TransferDt_WarehouseFrom';
	$groupbyname = 'frmwh.warehouse_name';
}
else if ($grpused == '42'){
	$dispgroupby = 'To Warehouse';
	$groupby 	 = 'transferdt.TransferDt_WarehouseTo';
	$groupbyname = 'towh.warehouse_name';
}
else if ($grpused == '5'){
	$dispgroupby = 'Item Code';
	$groupby 	 = 'transferdt.item_code';
	$groupbyname = 'item_description';
}
else if ($grpused == '6'){
	$dispgroupby = 'Group';
	$groupby 	 = 'items.group_code';
	$groupbyname = 'group_name';
}
else if ($grpused == '7'){
	$dispgroupby = 'Subgroup';
	$groupby 	 = 'items.subgroup_code';
	$groupbyname = 'subgroup_name';
}
else if ($grpused == '8'){
	$dispgroupby = 'Category';
	$groupby 	 = 'items.category_code';
	$groupbyname = 'category_name';
}

$SelectedOptions = "Filter by: \n";
	$SelectedOptions .= "-> From/To Date: $fromdate / $todate  \n";
if ($fromitem != '')
	$SelectedOptions .= "-> From/To Item: $fromitem / $toitem \n";

if ($fromgroup != '')
	$SelectedOptions .= "-> From/To Group: $fromgroup / $togroup \n";

if ($fromsubgroup != '')
	$SelectedOptions .= "-> From/To Subgroup: $fromsubgroup / $tosubgroup \n";

if ($fromcategory != '')
	$SelectedOptions .= "-> From/To Category: $fromcategory / $tocategory \n";

if ($fromproject != '')
	$SelectedOptions .= "-> From/To Project: $fromproject / $toproject \n";

if ($fromcostcent != '')
	$SelectedOptions .= "-> From/To Costcenter: $fromcostcent / $tocostcent \n";

if ($fromwh != '')
	$SelectedOptions .= "-> From/To Warehouse: $fromwh / $towh \n";
if ($dispgroupby != '') 
	$SelectedOptions .= "-> Group by: $dispgroupby \n";
	
//Display Report Header
$worksheet->write(1,0,$CompanyName, $TitleFormat);
$worksheet->write(1,3,$ReportTitle, $TitleFormat);
               
$worksheet->write(1,7,"Printed Date:", $boldleftFormat);
$worksheet->write(1,8,$printdate[2]."/".$printdate[1]."/".$printdate[0], $regularleftFormat);
$worksheet->write(2,7,"Time:", $boldleftFormat);		
$worksheet->write(2,8,$dt[1]." ".$dt[2], $regularleftFormat);

//Displaying Selected Options	
// Merge cells from row 3, col 0 to row 3, col 0
$worksheet->setMerge(3, 0, 8, 6);
$worksheet->write(3,0,$SelectedOptions, $seloptionFormat);  

$ndate = explode("/", $fromdate);	
$fromdate = $ndate[2]."-".$ndate[1]."-".$ndate[0];
$ndate = explode("/", $todate);	
$todate = $ndate[2]."-".$ndate[1]."-".$ndate[0];


$RowNum    = 10;
$ColumnNum = 0;	   


if ($grpused == '1' || $grpused == '') {
	
	$worksheet->setColumn ($ColumnNum, $ColumnNum, 5);
	$worksheet->write($RowNum,$ColumnNum,'', $boldleftFormat);
	$ColumnNum += 1;

	$worksheet->setColumn ($ColumnNum, $ColumnNum, 10);
	$worksheet->write($RowNum,$ColumnNum,"Reference", $boldleftFormat);
	$ColumnNum += 1;
	
	$worksheet->setColumn ($ColumnNum, $ColumnNum, 12);
	$worksheet->write($RowNum,$ColumnNum,"Date", $boldleftFormat);
	$ColumnNum += 1;
	
	$worksheet->setColumn ($ColumnNum, $ColumnNum, 12);
	$worksheet->write($RowNum,$ColumnNum,"From WH", $boldleftFormat);
	$ColumnNum += 1;
	
	$worksheet->setColumn ($ColumnNum, $ColumnNum, 12);
	$worksheet->write($RowNum,$ColumnNum,"To WH", $boldleftFormat);
	$ColumnNum += 1;
	
	$worksheet->setColumn ($ColumnNum, $ColumnNum, 12);
	$worksheet->write($RowNum,$ColumnNum,"From Project", $boldleftFormat);
	$ColumnNum += 1;
	
	$worksheet->setColumn ($ColumnNum, $ColumnNum, 12);
	$worksheet->write($RowNum,$ColumnNum,"To Project", $boldleftFormat);
	$ColumnNum += 1;
	
	$worksheet->setColumn ($ColumnNum, $ColumnNum, 20);
	$worksheet->write($RowNum,$ColumnNum,"Remark", $boldleftFormat);
	$ColumnNum += 1;

}

if (($grpused != '1' && $grpused != '') || $chkdetail == 1)	{
	$ColumnNum = 0;
	$RowNum += 1;
	
	$worksheet->setColumn ($ColumnNum, $ColumnNum, 5);
	$worksheet->write($RowNum,$ColumnNum,'', $boldleftFormat);
	$ColumnNum += 1;
	
	$worksheet->setColumn ($ColumnNum, $ColumnNum, 15);
	$worksheet->write($RowNum,$ColumnNum,'Item Code', $boldleftFormat);
	$ColumnNum += 1;
	
	$worksheet->setColumn ($ColumnNum, $ColumnNum, 20);
	$worksheet->write($RowNum,$ColumnNum,'Item Description', $boldleftFormat);
	$ColumnNum += 1;
		
	$worksheet->setColumn ($ColumnNum, $ColumnNum, 15);
	$worksheet->write($RowNum,$ColumnNum,'From WH', $boldleftFormat);
	$ColumnNum += 1;
	
	$worksheet->setColumn ($ColumnNum, $ColumnNum, 15);
	$worksheet->write($RowNum,$ColumnNum,'To WH', $boldleftFormat);
	$ColumnNum += 1;
	
	$worksheet->setColumn ($ColumnNum, $ColumnNum, 10);
	$worksheet->write($RowNum,$ColumnNum,'Qty', $boldleftFormat);
	$ColumnNum += 1;
}

$querytransfer = "select Transfer_Reference, date_format(transfer.Transfer_Date, '%d-%m-%Y') as transferdate, Transfer_Remark, transferdt.item_code, item_description, ";
if ($groupby == '')
	$querytransfer .= " TransferDt_Quantity, '' as groupby, '' as groupbyname, ";
else 
	$querytransfer .= " sum(TransferDt_Quantity), $groupby as groupby, $groupbyname as groupbyname,  ";
	$querytransfer .= " frmwh.warehouse_name as fromwharehouse, towh.warehouse_name as towharehouse, frmprjt.project_name as fromproject, toprjt.project_name as toproject ";
$querytransfer .= "	from transferdt
				inner join transfer on transfer.transfer_id = transferdt.transfer_id
				inner join items on items.item_code = transferdt.item_code
				left join grouping on grouping.group_code = items.group_code
				left join subgroup on subgroup.subgroup_code = items.subgroup_code
				left join category on category.category_code = items.category_code
				left join warehouse frmwh on frmwh.warehouse_code = transferdt.TransferDt_WarehouseFrom
				left join warehouse towh on towh.warehouse_code = transferdt.TransferDt_WarehouseTo
				left join project frmprjt on frmprjt.project_code = transferdt.Project_code1
				left join project toprjt on toprjt.project_code = transferdt.Project_code2
				left join costcent frmcostcent on frmcostcent.Costcent_code = transferdt.Costcent_Code
				left join costcent tocostcent on tocostcent.Costcent_code = transferdt.ToCostcent_Code
				where if('$fromitem'='', 1=1, transferdt.item_code between '$fromitem' and '$toitem')
				and if('$fromgroup'='', 1=1, items.group_code between '$fromgroup' and '$togroup')
				and if('$fromsubgroup'='', 1=1, items.subgroup_code between '$fromsubgroup' and '$tosubgroup')
				and if('$fromcategory'='', 1=1, items.category_code between '$fromcategory' and '$tocategory')
				and date_format(transfer.Transfer_Date,'%Y-%m-%d') between '$fromdate' and '$todate' ";
			
if ($grpused == '21')
	$querytransfer .= " and (if ('$fromproject' = '', 1=1, transferdt.Project_code1 between '$fromproject' and '$toproject' ))";
else if ($grpused == '22')
	$querytransfer .= " and (if ('$fromproject' = '', 1=1, transferdt.Project_code2 between '$fromproject' and '$toproject' ))";
else 
	$querytransfer .= " and (if ('$fromproject' = '', 1=1, transferdt.Project_code1 like '%$fromproject%' or transferdt.Project_code2 like '%$toproject%' ))";

if ($grpused == '31')
	$querytransfer .= " and (if ('$fromcostcent' = '', 1=1, transferdt.Costcent_Code between '$fromcostcent' and '$tocostcent' ))";
else if ($grpused == '32')
	$querytransfer .= " and (if ('$fromcostcent' = '', 1=1, transferdt.ToCostcent_Code between '$fromcostcent' and '$tocostcent' ))";
else 
	$querytransfer .= " and (if ('$fromcostcent' = '', 1=1,  transferdt.Costcent_Code like '%$fromcostcent%' or transferdt.ToCostcent_Code like '%$tocostcent%' ))";

if ($grpused == '41')
	$querytransfer .= " and (if ('$fromwh' = '', 1=1, transferdt.TransferDt_WarehouseFrom between '$fromwh' and '$towh' ))";
else if ($grpused == '42')
	$querytransfer .= " and (if ('$fromwh' = '', 1=1, transferdt.TransferDt_WarehouseTo between '$fromwh' and '$towh' ))";
else 
	$querytransfer .= " and (if ('$fromwh' = '', 1=1,  transferdt.TransferDt_WarehouseFrom like '%$fromwh%' or transferdt.TransferDt_WarehouseTo like '%$towh%' ))";

	
if ($whexist > 0)
{
  $querytransfer= $querytransfer." and (";
  $querytransfer= $querytransfer."  (transferdt.transferdt_warehousefrom In (select distinct warehouse_code from ".$_SESSION['dbLabel'].".loginstk where user_account='".$_SESSION['useraccount']."')  )"; 
  $querytransfer= $querytransfer." or (transferdt.transferdt_warehouseto In (select distinct warehouse_code from ".$_SESSION['dbLabel'].".loginstk where user_account='".$_SESSION['useraccount']."')  )";  
  $querytransfer= $querytransfer." )";
  }		
	
	
	
if ($groupby == '')
	$querytransfer .= " order by Transfer_Reference "; 			
else	{
	$querytransfer .= " group by $groupby, transferdt.item_code, transferdt.TransferDt_WarehouseFrom "; 			
	$querytransfer .= " order by $groupby "; 	
}			

$restransfer = mysql_query($querytransfer, $connection);

$tempref = '';
$ct = 0;

$tempgrpby = '**';

$totalQty = 0;
$totalQtyByGrp = 0;


while($rw = mysql_fetch_array($restransfer)){
	if ($tempref != $rw[0] && ($grpused == '1' || $grpused == '')){
		
		$ColumnNum = 0;
		$RowNum += 1;
		
		$worksheet->write($RowNum, $ColumnNum, '', $regularleftFormat1);
		$ColumnNum += 1;
		$worksheet->write($RowNum, $ColumnNum, $rw[0], $regularleftFormat1);
		$ColumnNum += 1;
		$worksheet->write($RowNum, $ColumnNum, $rw[1], $regularleftFormat1);
		$ColumnNum += 1;
		$worksheet->write($RowNum, $ColumnNum, $rw[8], $regularleftFormat1);
		$ColumnNum += 1;
		$worksheet->write($RowNum, $ColumnNum, $rw[9], $regularleftFormat1);
		$ColumnNum += 1;
		$worksheet->write($RowNum, $ColumnNum, $rw[10], $regularleftFormat1);
		$ColumnNum += 1;
		$worksheet->write($RowNum, $ColumnNum, $rw[11], $regularleftFormat1);
		$ColumnNum += 1;
		$worksheet->write($RowNum, $ColumnNum, $rw[2], $regularleftFormat1);
		$ColumnNum += 1;
	}
	
	if (($grpused != '1' && $grpused != '') && $tempgrpby != $rw[6]){
		
		if ($ct != 0){
			$RowNum += 1;
			$ColumnNum = 4;
			$worksheet->write($RowNum, $ColumnNum, "Total Qty in $tempgrpby", $boldcenterFormat);
			$ColumnNum += 1;
			$worksheet->writeNumber($RowNum, $ColumnNum, $totalQtyByGrp, $boldcenterFormat);
			$ColumnNum += 1;
			$RowNum += 1;
			$totalQtyByGrp = 0;
		}
		
		$ColumnNum = 0;
		$RowNum += 1;
		
		$worksheet->write($RowNum,$ColumnNum,'Group by', $boldleftFormat);
		$ColumnNum += 1;
		
		$worksheet->write($RowNum, $ColumnNum, $rw[6], $boldleftFormat);
		$ColumnNum += 1;
		
		$worksheet->write($RowNum, $ColumnNum, $rw[7], $boldleftFormat);
		$ColumnNum += 1;
	} 
	
	if (($grpused != '1' && $grpused != '') || $chkdetail == 1)	{
		$ColumnNum = 1;
		$RowNum += 1;
		
		
		$worksheet->write($RowNum, $ColumnNum, $rw[3], $regularcenterFormat);
		$ColumnNum += 1;
		
		$worksheet->write($RowNum, $ColumnNum, $rw[4], $regularcenterFormat);
		$ColumnNum += 1;
		
		$worksheet->write($RowNum, $ColumnNum, $rw[8], $regularcenterFormat);
		$ColumnNum += 1;
		
		$worksheet->write($RowNum, $ColumnNum, $rw[9], $regularcenterFormat);
		$ColumnNum += 1;
		
		$worksheet->write($RowNum, $ColumnNum, $rw[5], $regularcenterFormat);
		$ColumnNum += 1;
				
		$totalQty 		= $totalQty + $rw[5];	
		$totalQtyByGrp  = $totalQtyByGrp + $rw[5];	
	}
	
	$tempref   = $rw[0];
	$tempgrpby = $rw[6];
	
	$ct++;	
}


if ($grpused != '1' && $grpused != '')	{
	$RowNum += 1;
	$ColumnNum = 4;
	$worksheet->write($RowNum, $ColumnNum,"Total Qty in ".$tempgrpby, $boldleftFormat);
	$ColumnNum += 1;
	
	$worksheet->writeNumber($RowNum, $ColumnNum, $totalQtyByGrp, $boldcenterFormat);
	$ColumnNum += 1;
}


if (($grpused != '1' && $grpused != '') || $chkdetail == 1)	{
	$RowNum += 2;
	$ColumnNum = 4;
	$worksheet->write($RowNum,1,"Total ", $boldleftFormat);
	$ColumnNum += 1;
	$worksheet->writeNumber($RowNum, $ColumnNum, $totalQty, $boldcenterFormat);
}
 

 

function current_server_time($connection){

  $string="Select date_format(NOW(),'%Y-%m-%d %h:%i %p') ";
  $result=mysql_query($string,$connection) or die(mysql_error());
  $now=mysql_fetch_row($result);

  return $now;
}

function explodeword($date)
{

	$trim = explode('/',$date);
	$trim = "$trim[2]"."-"."$trim[1]"."-"."$trim[0]";
	return $trim;
}

function GetSQLValueString($theValue, $theType) 
{
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "Null";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "Null";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "Null";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "Null";
      break;
  }
  return $theValue;
}


$workbook->close();


?>