<?php
session_start();

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

include("config.inc.php");

$connection = mysql_connect($config['dbServer'], $config['dbUser'], $config['dbPass'], true, 65536) or die("Could not connect to DB");

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


$pid            = $_POST['pid'];
if ($pid == "") {
    $pid = $_GET["pid"];
}
if ($qty == "") {
    $qty = $_GET["qty"];
}
if ($weight == "") {
    $weight = $_GET["weight"];
}
$query_setup  = "select BASE1, BASE2, Company_name from setup";
$result_setup = mysql_query($query_setup);
$row_setup    = mysql_fetch_array($result_setup);
extract($row_setup);

$query_barcode  = "select item_code as item_code, productionhd_date, item_codePacked, Item_qtyPacked, ProductionFG_ExpireDate, productionfg_BatchNo from Productionfg where productionhd_id = '$pid'";
$result_barcode = mysql_query($query_barcode, $connection);
$row_barcode    = mysql_fetch_array($result_barcode);
extract($row_barcode);

echo "<div style='width: 250px; text-align: center'>";
echo "<h2>" . $Company_name . "</h2>";
$i = 1;
//while ($i <= $qty) {

echo "<table cellpadding='0' cellspacing='0' border='0'  width='500px;'>
         <col width=300><col width=200>";
echo "<tr><td><b>Product Code:</b></td><td>&nbsp; $item_code </td></tr>";
echo "<tr><td><b>Packed Date:</b></td><td>&nbsp; $productionhd_date </td></tr>";
echo "<tr><td><b>Weight</b></td><td>&nbsp; $weight </td></tr>";
echo "<tr><td><b>Expiry Date:</b></td><td>&nbsp; $ProductionFG_ExpireDate </td></tr>";
echo "<tr><td><b>Batch No:</b></td><td>&nbsp; $productionfg_BatchNo </td></tr>";
echo "<tr><td><b> $Item_qtyPacked PK</b></td><td><img src='test_1D.php?text=$item_code' height='40px' width='180px' border=0></td>";
echo "</table>";
//  $i++;
//}
echo "</div>";

echo "<script>
window.onload = function() {
     printPreview('$qty');
   
  }

  function printPreview(nbofcopy){
      var count = 0;
      while(count<nbofcopy){
        window.print();
          count++;
      }
  }
</script>";
