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

session_start();
if($HTTP_SESSION_VARS['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($HTTP_SESSION_VARS['dbName'],$connection) or die("Could not find DB");


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


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

$queryproject=" select distinct project.project_code, project_name ".
              " from project left join ".$HTTP_SESSION_VARS['dbLabel'].".loginstk on project.project_code like concat(ifnull(loginstk.project_code,project.project_code),'%') ".
			  " where user_account='".$HTTP_SESSION_VARS['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 ".$HTTP_SESSION_VARS['dbLabel'].".loginstk on costcent.costcent_code like concat(ifnull(loginstk.costcent_code,costcent.costcent_code),'%') ".
			   " where user_account='".$HTTP_SESSION_VARS['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 ".$HTTP_SESSION_VARS['dbLabel'].".loginstk ".
		 "                                          where user_account='".$HTTP_SESSION_VARS['useraccount']."' ".
		 "                                          and (loginstk.warehouse_code is not null and loginstk.warehouse_code != '') ) ".
		 " order by warehouse.warehouse_code";
$resultwh = mysql_query($querywh,$connection) or die(mysql_error());
$whexist  = mysql_num_rows($resultwh);


$querygroup=" select distinct group_code,group_name ".
			" from grouping where group_code in (select group_code from ".$HTTP_SESSION_VARS['dbLabel'].".loginstk where user_account='".$HTTP_SESSION_VARS['useraccount']."') ".
			" order by group_code";
$resultgroup = mysql_query($querygroup,$connection) or die(mysql_error());
$groupexist  = mysql_num_rows($resultgroup);

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


if (empty($curr))  $curr = $Base1;

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

//Sending HTTP headers
$workbook->send('Exp_PreProductionAnalysis.xls');
 
//Creating a worksheet
$worksheet=&$workbook->addWorksheet('PreProduction Report Analysis');
$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'  ));  
  
$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
  )); 
$boldcenterFormat =& $workbook->addFormat(array('size'=>9,
  'align'=>'center'  ,
  'valign'=>'top'  ,
  'bold'=>1
  ));    
  
$seloptionFormat =& $workbook->addFormat(array('size'=>9,
  'align'=> 'left'  ,
  'valign'=> 'top'  ,
  'bold'=> 1
  ));
$seloptionFormat->setTextWrap();
$boldcenterFormat->setTextWrap();

$SelectedOptions = "Filter by: \n";
if ($fromdate != '')    $SelectedOptions .= "-> Date From: ". $fromdate . "  To: ". $todate ."\n";	
if ($curr != '')        $SelectedOptions .= "-> Currency: ". $curr ."\n";	
if ($fromitemRM != '')  $SelectedOptions .= "-> Item From: ". $fromitemRM . "  To: ". $toitemRM ."\n";


if (!empty($fromdate))  $fromdate = explodeword($fromdate);
if (!empty($todate))    $todate = explodeword($todate);  

$fromitemRM    = GetSQLValueString($fromitemRM, 'text');
$toitemRM      = GetSQLValueString($toitemRM, 'text');
$fromdate  	   = GetSQLValueString($fromdate, 'date');
$todate        = GetSQLValueString($todate, 'date');     
$fromproject   = GetSQLValueString($fromproject, 'text');
$toproject     = GetSQLValueString($toproject, 'text');
$fromcostcent  = GetSQLValueString($fromcostcent, 'text');
$tocostcent    = GetSQLValueString($tocostcent, 'text');
$fromwarehouse = GetSQLValueString($fromwarehouse, 'text');
   

if (empty($showdetail)) $showdetail = 0;
if (empty($showcost))   $showcost = 0;

	
//Display Report Header
$worksheet->write(1,0,$CompanyName, $TitleFormat);
$worksheet->write(1,3,"Variance Analysis Report", $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);  


$query = '';

$QueryRestrictPrj = " Inner join ( select distinct project_code from ".$HTTP_SESSION_VARS['dbLabel'].".loginstk ".
					" 			   where loginstk.user_account='".$HTTP_SESSION_VARS['useraccount']."' ".
					"              and (project_code is not null and project_code != '') ".
					"			 ) Q4  ";
					
$QueryRestrictCst = " Inner join ( select distinct costcent_code from ".$HTTP_SESSION_VARS['dbLabel'].".loginstk ".
					"			   where loginstk.user_account='".$HTTP_SESSION_VARS['useraccount']."' ".
					"              and (costcent_code is not null and costcent_code != '') ".
					"			 ) Q5  ";
					
					


$query = " Select PreProduction.Production_ID as ProductionID, PreProduction.Production_Reference as ProductionReference, Date_Format(PreProduction.Production_Date,'%d/%m/%Y') As ProductionDate, ".
		 " PreProduction.Item_code As ItemCode, Item_Description as ItemDescription, PreProduction.Warehouse_Code as WarehouseCode, Warehouse_Name as WarehouseName, ".
		 " ifNull(PreProduction.Production_Quantity,1) as ProductionQuantity,  PreProduction.Production_IdealQty as ProductionIdealQty, ".
		 " PreProduction.project_code, Date_Format(Preproduction.Production_Delivery_Date,'%d/%m/%Y') As ProductionDeliveryDate,".
		 " ifNull(Production.Preproduction_ID,0), Production.Production_Reference, Date_Format(Production.Production_Date,'%d/%m/%Y'),".
		 " ifNull(Production.Production_Quantity,1), DATEDIFF(ifNull(Production.Production_Date,Now()),Preproduction.Production_Delivery_Date) ".
		 " From PreProduction".
		 " Inner Join Items on PreProduction.Item_code = Items.Item_code ".
		 " Left Join Production on Production.Preproduction_ID = Preproduction.Production_Id".
		 " Left Join Warehouse on PreProduction.Warehouse_Code = Warehouse.Warehouse_Code ";
		 
if ($projectexist >	0 && $FI_RepRestrictProject == 1)
	$query= $query.$QueryRestrictPrj." on PreProduction.project_code like concat(Q4.project_code,'%') ";
							 
if ($costcentexist > 0 && $FI_RepRestrictCostcenter == 1)
	$query= $query.$QueryRestrictCst." on PreProduction.Costcenter_Code like concat(Q5.costcent_code,'%') ";		 
		 

$query = $query.  " Where Items.Item_Code Between ifNull(".$fromitem.", Items.Item_Code) and ifNull(". $toitem.", Items.Item_Code) ".
				  " And ifNull(PreProduction.Project_Code,'-1') between ifNull(".$fromproject.",ifNull(PreProduction.Project_Code,'-1')) and ifNull(". $toproject.",ifNull(PreProduction.Project_Code,'-1')) ".
				  " And ifNull(PreProduction.Costcenter_Code,'-1') between ifNull(".$fromcostcent.",ifNull(PreProduction.Costcenter_Code,'-1')) and ifNull(". $tocostcent.",ifNull(PreProduction.Costcenter_Code,'-1')) ".
				  " And ifNull(PreProduction.Warehouse_Code,'-1') = ifNull(". $fromwarehouse .", ifNull(PreProduction.Warehouse_Code,'-1')) ";

if($fromdate!='null' && $todate!='null')				  
$query = $query.  " And PreProduction.Production_Date between ". $fromdate." and ". $todate." ";
				  
				  
					  
if ($whexist > 0 && $FI_RepRestrictWarehouse == 1)
	$query = $query." And Production.warehouse_code In (select distinct warehouse_code from ".$HTTP_SESSION_VARS['dbLabel'].".loginstk where user_account='".$HTTP_SESSION_VARS['useraccount']."')  ";  
if ($groupexist > 0)
	$query = $query." And Items.group_code In (select distinct group_code from ".$HTTP_SESSION_VARS['dbLabel'].".loginstk where user_account='".$HTTP_SESSION_VARS['useraccount']."')  ";  


//Pending preproductions	
if ($status == 2) 
$query= $query." AND Production.Preproduction_ID IS NULL";

//Produced preproductions	
if ($status == 3) 
$query= $query." AND Production.Preproduction_ID IS NOT NULL"; 

//Order By Date
if ($orderBy == 1) 
$query= $query." ORDER BY PreProduction.Production_Date";
//Order By Delivery Date
if ($orderBy == 2) 
$query= $query." ORDER BY Preproduction.Production_Delivery_Date";
//Order By Reference
if ($orderBy == 3) 
$query= $query." ORDER BY PreProduction.Production_Reference";
//OrderBby item code
if ($orderBy == 4) 
$query= $query." ORDER BY PreProduction.Item_code";
//Order By item Desc
if ($orderBy == 5) 
$query= $query." ORDER BY Item_Description ";
		 
	
if ($whexist > 0 && $FI_RepRestrictWarehouse == 1)
	$query = $query." And ProductionFG.warehouse_code In (select distinct warehouse_code from ".$HTTP_SESSION_VARS['dbLabel'].".loginstk where user_account='".$HTTP_SESSION_VARS['useraccount']."')  ";  
if ($groupexist > 0)
	$query = $query." And Items.group_code In (select distinct group_code from ".$HTTP_SESSION_VARS['dbLabel'].".loginstk where user_account='".$HTTP_SESSION_VARS['useraccount']."')  ";  
 
 
//echo $query;
//exit;



$ArrayTotalByMaster = Array();
$ArrayItemRM = Array();
$ArrayData   = Array();

$MasterItemCode = '';
$TotalItemUsgStdRM = 0;


$result=mysql_query($query,$connection) or die(mysql_error());
while($rows=mysql_fetch_row($result)){

	
	$ItemRMFound = 0;
	$CountRM = count ($ArrayItemRM['Code']); 
	for ($j=0; $j<$CountRM; $j++){
		if ($ArrayItemRM['Code'][$j] == $rows[0])
			$ItemRMFound = 1;
	}
							
	if ($ItemRMFound == 0) { 
		$ArrayItemRM['Code'][$CountRM] = $rows[0];
		$ArrayItemRM['Name'][$CountRM] = $rows[1];
		$ArrayItemRM['Unit'][$CountRM] = $rows[3];
	
		$TotalItemUsgStdRM = 0;
	}
	
	$ItemQtyStdRM   = $rows[2];
	$ItemQtyActFG   = $rows[8];
	$ItemQtyActRM   = $rows[9];
	$ItemUsgStdRM   = $rows[10];
	
	$TotalItemUsgStdRM = $TotalItemUsgStdRM + $ItemUsgStdRM;
	
	
	
	$CountFG = count ($ArrayData[$rows[0]]['ItemCodeFG']); 
	
	$ArrayData[$rows[0]]['ItemCodeFG'][$CountFG]   = $rows[5];
	$ArrayData[$rows[0]]['ItemQtyStdRM'][$CountFG] = $ItemQtyStdRM;
	$ArrayData[$rows[0]]['ItemQtyActFG'][$CountFG] = $ItemQtyActFG;
	$ArrayData[$rows[0]]['ItemQtyActRM'][$CountFG] = $ItemQtyActRM;
	$ArrayData[$rows[0]]['ItemUsgStdRM'][$CountFG] = $ItemUsgStdRM;
	$ArrayData[$rows[0]]['TotalItemUsgStdRM'][$CountFG] = $TotalItemUsgStdRM;
	

}

array_multisort($ArrayItemRM);

$RowNum    = 10;
$ColumnNum = 0;

$CountItemRM = count($ArrayItemRM['Code']);
for ($i=0; $i<$CountItemRM; $i++){

	unset($ArrayTotalByMaster);
	
	$StyleClass = $boldcenterFormat;
	CreateTableHeader($worksheet, $ArrayItemRM['Name'][$i], $ArrayItemRM['Unit'][$i], $StyleClass, $RowNum, $ColumnNum);
	
	$RowNum += 1;
	$ColumnNum = 0;

	$CountData = count($ArrayData[$ArrayItemRM['Code'][$i]]['ItemCodeFG']);
	for ($j=0; $j<$CountData; $j++){
	
		$ItemQtyStdRM 	   = $ArrayData[$ArrayItemRM['Code'][$i]]['ItemQtyStdRM'][$j];
		$ItemQtyActFG 	   = $ArrayData[$ArrayItemRM['Code'][$i]]['ItemQtyActFG'][$j];
		$ItemUsgStdRM 	   = $ArrayData[$ArrayItemRM['Code'][$i]]['ItemUsgStdRM'][$j];
		$ItemQtyActRM 	   = $ArrayData[$ArrayItemRM['Code'][$i]]['ItemQtyActRM'][$j];
		$TotalItemUsgStdRM = $ArrayData[$ArrayItemRM['Code'][$i]]['TotalItemUsgStdRM'][$CountData-1];
		$ItemQtyStdFG	   = ($ItemQtyActRM/$TotalItemUsgStdRM)*$ItemQtyActFG;
		$ItemUsgActRM	   = $ItemQtyStdRM*$ItemQtyStdFG;
		$ItemVarianceFG	   = $ItemQtyActFG - $ItemQtyStdFG;
		$ItemVarianceRM    = ($ItemVarianceFG*$ItemQtyStdRM)/1000;
		$ItemEfficiency	   = $ItemUsgStdRM - $ItemUsgActRM;
		
		$worksheet->setColumn ($ColumnNum, $ColumnNum, 20);
		$worksheet->write($RowNum,$ColumnNum,$ArrayData[$ArrayItemRM['Code'][$i]]['ItemCodeFG'][$j], $regularleftFormat);
		$ColumnNum += 1;
		$worksheet->setColumn ($ColumnNum, $ColumnNum, 15);
		$worksheet->write($RowNum,$ColumnNum,format_currency($ItemQtyStdRM, $ListOfProductionMaskQty), $regularrightFormat);
		$ColumnNum += 1;
		$worksheet->setColumn ($ColumnNum, $ColumnNum, 15);
		$worksheet->write($RowNum,$ColumnNum,format_currency($ItemQtyActFG, $ListOfProductionMaskQty), $regularrightFormat);
		$ColumnNum += 1;
		$worksheet->setColumn ($ColumnNum, $ColumnNum, 15);
		$worksheet->write($RowNum,$ColumnNum,format_currency($ItemUsgStdRM, $ListOfProductionMaskQty), $regularrightFormat);
		$ColumnNum += 1;
		$worksheet->setColumn ($ColumnNum, $ColumnNum, 15);
		$worksheet->write($RowNum,$ColumnNum,format_currency($ItemQtyStdFG, $ListOfProductionMaskQty), $regularrightFormat);
		$ColumnNum += 1;
		$worksheet->setColumn ($ColumnNum, $ColumnNum, 15);
		$worksheet->write($RowNum,$ColumnNum,format_currency($ItemUsgActRM, $ListOfProductionMaskQty), $regularrightFormat);
		$ColumnNum += 1;
		$worksheet->setColumn ($ColumnNum, $ColumnNum, 15);
		$worksheet->write($RowNum,$ColumnNum,format_currency($ItemVarianceFG, $ListOfProductionMaskQty), $regularrightFormat);
		$ColumnNum += 1;
		$worksheet->setColumn ($ColumnNum, $ColumnNum, 15);
		$worksheet->write($RowNum,$ColumnNum,format_currency($ItemVarianceRM, $ListOfProductionMaskQty), $regularrightFormat);
		$ColumnNum += 1;
		$worksheet->setColumn ($ColumnNum, $ColumnNum, 15);
		$worksheet->write($RowNum,$ColumnNum,format_currency($ItemEfficiency, $ListOfProductionMaskQty), $regularrightFormat);
		$ColumnNum += 1;
	
		
		$ArrayTotalByMaster['TotalUsgStdRM']   = $ArrayTotalByMaster['TotalUsgStdRM'] + $ItemUsgStdRM;
		$ArrayTotalByMaster['TotalQtyStdFG']   = $ArrayTotalByMaster['TotalQtyStdFG'] + $ItemQtyStdFG;
		$ArrayTotalByMaster['TotalUsgActRM']   = $ArrayTotalByMaster['TotalUsgActRM'] + $ItemUsgActRM;
		$ArrayTotalByMaster['TotalVarianceFG'] = $ArrayTotalByMaster['TotalVarianceFG'] + $ItemVarianceFG;
		$ArrayTotalByMaster['TotalVarianceRM'] = $ArrayTotalByMaster['TotalVarianceRM'] + $ItemVarianceRM;
		
		$RowNum += 1;
		$ColumnNum = 0;
	}
	
	$worksheet->write($RowNum,$ColumnNum,"TOTAL", $boldleftFormat);
	$ColumnNum += 3;
	$worksheet->write($RowNum,$ColumnNum,format_currency($ArrayTotalByMaster['TotalUsgStdRM'], $ListOfProductionMaskQty), $boldrightFormat);
	$ColumnNum += 1;
	$worksheet->write($RowNum,$ColumnNum,format_currency($ArrayTotalByMaster['TotalQtyStdFG'], $ListOfProductionMaskQty), $boldrightFormat);
	$ColumnNum += 1;
	$worksheet->write($RowNum,$ColumnNum,format_currency($ArrayTotalByMaster['TotalUsgActRM'], $ListOfProductionMaskQty), $boldrightFormat);
	$ColumnNum += 1;
	$worksheet->write($RowNum,$ColumnNum,format_currency($ArrayTotalByMaster['TotalVarianceFG'], $ListOfProductionMaskQty), $boldrightFormat);
	$ColumnNum += 1;
	$worksheet->write($RowNum,$ColumnNum,format_currency($ArrayTotalByMaster['TotalVarianceRM'], $ListOfProductionMaskQty), $boldrightFormat);
	$ColumnNum += 1;
		
	$RowNum += 2;
	$ColumnNum = 0;
		
	$worksheet->write($RowNum,$ColumnNum,"ACTUAL USAGE OF ".$ArrayItemRM['Name'][$i], $boldleftFormat);
	$ColumnNum += 3;
	$worksheet->write($RowNum,$ColumnNum,format_currency($ItemQtyActRM, $ListOfProductionMaskQty), $boldrightFormat);
	$ColumnNum += 1;
		
	$RowNum += 3;
	$ColumnNum = 0;
	

}




function format_currency($amount, $DecimalBase) { 

    if (Round(abs($amount), $DecimalBase) == 0)
		return number_format(abs($amount), $DecimalBase); 
	else if($amount < 0) 
        return "(".number_format(abs($amount),$DecimalBase).")"; 
    else 
		return number_format($amount, $DecimalBase); 
} 

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;
}

function CreateTableHeader($worksheet, $PItemCodeRM, $PItemUnitRM, $PStyleClass, $PRowNum, $PColumnNum) {
	
	$worksheet->write($PRowNum, $PColumnNum, $PItemCodeRM, $PStyleClass);
	$PColumnNum += 1;
	$worksheet->write($PRowNum, $PColumnNum, "Std ".$PItemCodeRM." Content Per Unit [".$PItemUnitRM."]", $PStyleClass);
	$PColumnNum += 1;
	$worksheet->write($PRowNum, $PColumnNum, "Actual Output [Units]", $PStyleClass);
	$PColumnNum += 1;
	$worksheet->write($PRowNum, $PColumnNum, "Std ".$PItemCodeRM." Usg [".$PItemUnitRM."]", $PStyleClass);
	$PColumnNum += 1;
	$worksheet->write($PRowNum, $PColumnNum, "Std Output [Units]", $PStyleClass);
	$PColumnNum += 1;
	$worksheet->write($PRowNum, $PColumnNum, "Actual ".$PItemCodeRM." usg based on Units of Prod [".$PItemUnitRM."]", $PStyleClass);
	$PColumnNum += 1;
	$worksheet->write($PRowNum, $PColumnNum, "Production Variance [Units]", $PStyleClass);
	$PColumnNum += 1;
	$worksheet->write($PRowNum, $PColumnNum, $PItemCodeRM." Usg Variance [".$PItemUnitRM."]", $PStyleClass);
	$PColumnNum += 1;
	$worksheet->write($PRowNum, $PColumnNum, "Efficiency", $PStyleClass);
	$PColumnNum += 1;

}



$workbook->close();

?>