<?php


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


include("config.inc.php");
include("Functions_Purchase.php");


$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");

$querydflcostcent="select costcent_code from ".$_SESSION['dbLabel'].".loginstk where user_account='".$_SESSION['useraccount']."' and default_costcenter=1 ";	
	//echo$querydflcostcent;
	$resultdflcostcent=mysql_query($querydflcostcent,$connection) or die(mysql_error());
	$rowcount=mysql_num_rows($resultdflcostcent);
	if($rowcount==0 || $rowcount > 1){
		//echo"inside";
		$usercostcent="null";
	}
	else{
		$rowscostcent=mysql_fetch_array($resultdflcostcent);
			extract($rowscostcent);
			if($costcent_code != '') 
			$usercostcent="'".$costcent_code."'";
	}
$query_setup  = "select DecimalBase, DecimalBase1, DecimalBase2, Base1, Base2, COMPANY_NAME as CompanyName from setup";
$result_setup = mysql_query($query_setup, $connection); 
$row_setup    = mysql_fetch_array($result_setup);
extract($row_setup);
if($export ==1){
	$filename = "Clients_Archeive" . date('d/m/Y') . ".xls";
	header("Content-Disposition: attachment; filename=\"$filename\"");
	header("Content-Type: application/vnd.ms-excel");
}
echo "<html>
<head>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=windows-1256\" />
<title>List of Items</title>
</head>
<body>
<table width='1300' style='border-collapse:collapse'>
<tr>
<th colspan='12' style='font-size: 20px; border-bottom: solid 2px #000000'>List of 	Items</td>
</tr>
";


	
	
	$query_transactionsetup = "select Item_Code,Item_Description,Item_SellingPrice1,Item_Barcode,Item_Barcode2,item_lastcostpricebase2,subgroup.SubGroup_Name,grouping.group_name
from Items left join subgroup on items.subgroup_code = subgroup.subgroup_code
left join grouping on items.group_code = grouping.group_code";  
			  //echo  $query_transactionsetup;exit;
	$result_transactionsetup = mysql_query($query_transactionsetup, $connection); 
	
	
	echo "<table style='border-collapse: collapse'>
	<tr>
					  <td style='font-family: Arial; font-size: 14px; font-weight: bold; border-bottom: solid 1.5px #000000;' width='200'>Code</td>
					  <td style='font-family: Arial; font-size: 14px; font-weight: bold; border-bottom: solid 1.5px #000000;' width='500'>Name</td>
					  <td style='font-family: Arial; font-size: 14px; font-weight: bold; border-bottom: solid 1.5px #000000;' width='100'>Sell.Price 1</td>
					  <td style='font-family: Arial; font-size: 14px; font-weight: bold; border-bottom: solid 1.5px #000000;' width='200'>Qty Exist</td>
					  <td style='font-family: Arial; font-size: 14px; font-weight: bold; border-bottom: solid 1.5px #000000;' width='500'>Barcode 1</td>
					  <td style='font-family: Arial; font-size: 14px; font-weight: bold; border-bottom: solid 1.5px #000000;' width='100'>Barcode 2</td>
					  <td style='font-family: Arial; font-size: 14px; font-weight: bold; border-bottom: solid 1.5px #000000;' width='200'>Last Cost USD</td>
					  <td style='font-family: Arial; font-size: 14px; font-weight: bold; border-bottom: solid 1.5px #000000;' width='500'>Group</td>
					  <td style='font-family: Arial; font-size: 14px; font-weight: bold; border-bottom: solid 1.5px #000000;' width='500'>Subgroup</td>
					  <td style='font-family: Arial; font-size: 14px; font-weight: bold; border-bottom: solid 1.5px #000000;' width='500'>Supplier</td>
					  
					 
					 
					 </tr>";
					 
					 $count = 0;
					 while($row_transactionsetup    = mysql_fetch_array($result_transactionsetup)){
	                    extract($row_transactionsetup);
						$count ++;
						if($count % 2 != 0)
	{
		$style="background-color: #b9bbbc";
	}
	else
	{
		$style="background-color: #909090";
	}
	                   $qu="select QtyExistsPerCostCent('$Item_Code','',now(),null,'','','',$usercostcent)"; 
					   $result=mysql_query($qu,$connection) or die(mysql_error());	
			           $row=mysql_fetch_row($result);
				       
				       $q = "select IFNULL(GetLastValuesFunc('".$Base1."', '".$Base2."', '$Item_Code'),0) as LastcostPrice2";
	                   $res = mysql_query($q,$connection) or die(mysql_error());
					   $rw = mysql_fetch_row($res);
					   $ct+=1;
				       $stylefont='style15';
				   
						echo "<tr style='$style'>
					 <td width='fixed'>".$Item_Code."</td>
					 <td width='fixed'>".$Item_Description."</td>
					 <td width='15%'>".$Item_SellingPrice1."</td>
					 <td width='15%'>".$row[0]."</td>
					 <td width='15%'>".$Item_Barcode."</td>
					 <td width='15%'>".$Item_Barcode2."</td>
					 <td width='15%'>".$rw[0]."</td>
					 <td width='15%'>".$group_name."</td>
					 <td width='15%'>".$SubGroup_Name."</td>
					 <td width='15%'>".$Item_Group."</td>
					 
					 
					 
					 
					 </tr>";
					 }
					 echo "</table>";
					  echo "<br><br>";
					  



echo "</table>
</body>
</html>";

?>



