<?php
session_start();
if($_SESSION['dbName']==""){
header("location:../index.php");
}
include("config.inc.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");

$PurId = $_GET['PurId'];
$temp  = $_GET['temp'];

$query_module = "select ifNull(Module_sizes, 0) as Module_sizes, ifNull(Module_Color, 0) as Module_Color
                 from module";
$result_module = mysql_query($query_module, $connection);
$row_module = mysql_fetch_array($result_module);
extract($row_module);

$query_setup  = "select project_no, costcent_no, BASE1, BASE2 from setup";
$result_setup = mysql_query($query_setup, $connection); 
$row_setup    = mysql_fetch_array($result_setup);
extract($row_setup);

echo "<html>
<head>
<title>Item Barcode</title>
</head>
<body>";
if($temp == 1){
	$purchasesdt = "temp_purchasesdt";
}
else{
	$purchasesdt = "purchasesdt";
}
$querydt  = "SELECT $purchasesdt.item_code,
       items.item_barcode2, items.item_description, format(items.Item_SellingPrice1Base1, 2) as Item_SellingPrice1Base1,
	   format(items.Item_SellingPrice5Base1, 2) as Item_SellingPrice5Base1,
       $purchasesdt.Project_code,
       $purchasesdt.Costcent_code,
       PurchaseDt_Quantity
FROM $purchasesdt
inner JOIN items ON items.item_code = $purchasesdt.item_code
WHERE purchase_id = '$PurId'";
			 //echo $querydt;
$resultdt = mysql_query($querydt, $connection);
echo "<div style='width: 250px; text-align: center'>";
while($rowdt = mysql_fetch_array($resultdt)){
	extract($rowdt);
	if($Project_code == ""){
		$Project_code = str_pad( "0", $project_no, "0", STR_PAD_LEFT );
	}
	
	if($Costcent_code == ""){
		$Costcent_code = str_pad( "0", $costcent_no, "0", STR_PAD_LEFT );
	}
	if($Module_sizes == 1 && $Module_Color == 1){
	$text=$item_barcode.$Project_code.$Costcent_code;
	}
	else{
		$text=$item_barcode;
	}
	$i = 1;
	while($i <= $PurchaseDt_Quantity){
echo "<div style='height: 20px'></div>";
echo "<div style='font-size: 14px; text-align: center; font-family: Arial;'>$item_description</div>";
echo "<img src='test_1D.php?text=$item_barcode2' height='40px'  width='180px' border=0>";
echo "<br>";
//echo "<div style='height: 10px'></div>";
echo "<div style='font-size: 12px; text-align: center; font-family: Arial;'>$item_barcode2</div>";
//echo "<div style='height: 25px'></div>";
echo "<div style='margin-top: 10px; font-size: 22px; text-align: center; font-family: Arial;'><span style='text-decoration: line-through'>$Item_SellingPrice5Base1</span> $Item_SellingPrice1Base1 $BASE1</div>";
echo "<div style='height: 15px'></div>";
	$i++;
	}
}
echo "</div>";
echo "<script>
window.print();
</script>";
echo"</body>
</html>";
?>