<?php
ob_start();
/* $Revision: 1.73 $ */
$PageSecurity = 11;

include('includes/session.inc');
$title = _('Item Maintenance');
include('includes/header.inc');
include('includes/function_lib.php');
include('includes/SQL_CommonFunctions.inc');
$date=date('d/m/Y');
?>

<script type="text/javascript">
function MinVal()
	{
		var x=document.getElementById("minlevel").value;
		if(x<3){alert("Min Value Must Be Greater than or Equal to Three.");}
	}

function MaxVal()
	{
		var x=document.getElementById("maxlevel").value;
		if(x>10){alert("Max Value Must Be Less than or Equal to Ten.");}
	}
</script>
<script type="text/javascript" src="js/dynamicRow.js"></script>
<?php
 /*If this form is called with the StockID then it is assumed that the stock item is to be modified */

if (isset($_GET['StockID']))
{
	$StockID =trim(strtoupper($_GET['StockID'])); 
} 
elseif (isset($_POST['StockID']))
{
	$StockID =trim(strtoupper($_POST['StockID']));
	
} else 
{
	$StockID = '';
}

if (isset($StockID))
 {
	 $sql = "SELECT COUNT(stockid) FROM stockmaster WHERE stockid='".$StockID."'";
	$result = DB_query($sql,$db);
	$myrow = DB_fetch_row($result);
	if ($myrow[0]==0) {
		$New=1;
	}
}

?>

<?php
echo '<a href="' . $rootpath . '/SelectProduct.php?' . SID . '">' . _('Back to Items') . '</a><br>' . "\n";

if($_REQUEST['action']=='insert'){
echo "<div class='success'>Record Inserted Successfully</div>";
}
if (isset($_FILES['ItemPicture']) AND $_FILES['ItemPicture']['name'] !='') {

	$result    = $_FILES['ItemPicture']['error'];
 	$UploadTheFile = 'Yes'; //Assume all is well to start off with
	$filename = $_SESSION['part_pics_dir'] . '/' . $StockID . '.jpg';

	 //But check for the worst
	if (strtoupper(substr(trim($_FILES['ItemPicture']['name']),strlen($_FILES['ItemPicture']['name'])-3))!='JPG'){
		prnMsg(_('Only jpg files are supported - a file extension of .jpg is expected'),'warn');
		$UploadTheFile ='No';
	} elseif ( $_FILES['ItemPicture']['size'] > ($_SESSION['MaxImageSize']*1024)) { //File Size Check
		prnMsg(_('The file size is over the maximum allowed. The maximum size allowed in KB is') . ' ' . $_SESSION['MaxImageSize'],'warn');
		$UploadTheFile ='No';
	} elseif ( $_FILES['ItemPicture']['type'] == "text/plain" ) {  //File Type Check
		prnMsg( _('Only graphics files can be uploaded'),'warn');
         	$UploadTheFile ='No';
	} elseif (file_exists($filename)){
		prnMsg(_('Attempting to overwrite an existing item image'),'warn');
		$result = unlink($filename);
		if (!$result){
			prnMsg(_('The existing image could not be removed'),'error');
			$UploadTheFile ='No';
		}
	}

	if ($UploadTheFile=='Yes'){
		$result  =  move_uploaded_file($_FILES['ItemPicture']['tmp_name'], $filename);
		$message = ($result)?_('File url') ."<a href='". $filename ."'>" .  $filename . '</a>' : _('Something is wrong with uploading a file');
	}
 /* EOR Add Image upload for New Item  - by Ori */
}

if (isset($Errors))
 {
	unset($Errors);
}
$Errors = array();
$InputError = 0;

if(isset($_POST['UpdateStockItem']))
{}
if (isset($_POST['submit']))
{} 
elseif(isset($_POST['delete']) AND strlen($_POST['delete']) >1 )
{
//the button to delete a selected record was clicked instead of the submit button

	$CancelDelete = 0;

// PREVENT DELETES IF DEPENDENT RECORDS IN 'StockMoves'

	$sql= "SELECT COUNT(*) FROM stockmoves WHERE stockid='$StockID'";
	$result = DB_query($sql,$db);
	$myrow = DB_fetch_row($result);
	if ($myrow[0]>0) {
		$CancelDelete = 1;
		prnMsg( _('Cannot delete this stock item because there are stock movements that refer to this item'),'warn');
		echo '<br>' . _('There are') . ' ' . $myrow[0] . ' ' . _('stock movements that refer to this item');

	} else {
		$sql= "SELECT COUNT(*) FROM bom WHERE component='$StockID'";
		$result = DB_query($sql,$db);
		$myrow = DB_fetch_row($result);
		if ($myrow[0]>0) {
			$CancelDelete = 1;
			prnMsg( _('Cannot delete this item record because there are bills of material that require this part as a component'),'warn');
			echo '<br>' . _('There are') . ' ' . $myrow[0] . ' ' . _('bills of material that require this part as a component');
		} else {
			$sql= "SELECT COUNT(*) FROM salesorderdetails WHERE stkcode='$StockID'";
			$result = DB_query($sql,$db);
			$myrow = DB_fetch_row($result);
			if ($myrow[0]>0) {
				$CancelDelete = 1;
				prnMsg( _('Cannot delete this item record because there are existing sales orders for this part'),'warn');
				echo '<br>' . _('There are') . ' ' . $myrow[0] . ' ' . _('sales order items against this part');
			} else {
				$sql= "SELECT COUNT(*) FROM salesanalysis WHERE stockid='$StockID'";
				$result = DB_query($sql,$db);
				$myrow = DB_fetch_row($result);
				if ($myrow[0]>0) {
					$CancelDelete = 1;
					prnMsg(_('Cannot delete this item because sales analysis records exist for it'),'warn');
					echo '<br>' . _('There are') . ' ' . $myrow[0] . ' ' . _('sales analysis records against this part');
				} else {
					$sql= "SELECT COUNT(*) FROM purchorderdetails WHERE itemcode='$StockID'";
					$result = DB_query($sql,$db);
					$myrow = DB_fetch_row($result);
					if ($myrow[0]>0) {
						$CancelDelete = 1;
						prnMsg(_('Cannot delete this item because there are existing purchase order items for it'),'warn');
						echo '<br>' . _('There are') . ' ' . $myrow[0] . ' ' . _('purchase order item record relating to this part');
					} else {
						$sql = "SELECT SUM(quantity) AS qoh FROM locstock WHERE stockid='$StockID'";
						$result = DB_query($sql,$db);
						$myrow = DB_fetch_row($result);
						if ($myrow[0]!=0) {
							$CancelDelete = 1;
							prnMsg( _('Cannot delete this item because there is currently some stock on hand'),'warn');
							echo '<br>' . _('There are') . ' ' . $myrow[0] . ' ' . _('on hand for this part');
						}
					}
				}
			}
		}

	}
	if ($CancelDelete==0) {
		$result = DB_Txn_Begin($db);

			/*Deletes LocStock records*/
			$sql ="DELETE FROM locstock WHERE stockid='$StockID'";
			$result=DB_query($sql,$db,_('Could not delete the location stock records because'),'',true);
			/*Deletes Price records*/
			$sql ="DELETE FROM prices WHERE stockid='$StockID'";
			$result=DB_query($sql,$db,_('Could not delete the prices for this stock record because'),'',true);
			/*and cascade deletes in PurchData */
			$sql ="DELETE FROM purchdata WHERE stockid='$StockID'";
			$result=DB_query($sql,$db,_('Could not delete the purchasing data because'),'',true);
			/*and cascade delete the bill of material if any */
			$sql = "DELETE FROM bom WHERE parent='$StockID'";
			$result=DB_query($sql,$db,_('Could not delete the bill of material because'),'',true);
			$sql="DELETE FROM stockmaster WHERE stockid='$StockID'";
			$result=DB_query($sql,$db, _('Could not delete the item record'),'',true);
            $result = DB_Txn_Commit($db);

		prnMsg(_('Deleted the stock master record for') . ' ' . $StockID . '....' .
		'<br>. . ' . _('and all the location stock records set up for the part') .
		'<br>. . .' . _('and any bill of material that may have been set up for the part') .
		'<br> . . . .' . _('and any purchasing data that may have been set up for the part') .
		'<br> . . . . .' . _('and any prices that may have been set up for the part'),'success');
		unset($_POST['longdescription']);
		unset($_POST['description']);
		unset($_POST['eoq']);
		unset($_POST['CategoryID']);
		unset($_POST['units']);
		unset($_POST['mbflag']);
		unset($_POST['discontinued']);
		unset($_POST['Controlled']);
		unset($_POST['Serialised']);
		unset($_POST['Perishable']);
		unset($_POST['volume']);
		unset($_POST['kgs']);
		unset($_POST['barCode']);
		unset($_POST['ReorderLevel']);
		unset($_POST['discountcategory']);
		unset($_POST['taxcatid']);
		unset($_POST['decimalplaces']);
		unset($_POST['ItemPDF']);
		unset($StockID);
		unset($_SESSION['SelectedStockItem']);
		//echo "<meta http-equiv='Refresh' content='0; url=" . $rootpath . '/SelectProduct.php?' . SID  ."'>";


	} //end if Delete Part
}

echo '<form  enctype="multipart/form-data" method="post" action="' . $_SERVER['PHP_SELF'] . '?' .SID .'">
	<table border="0" cellpadding="5" cellspacing="1" class="inborder" style="background:#dce6f2;">'. "\n"; // Nested table

//echo '<form name="ItemForm" enctype="multipart/form-data" method="post" action="' . $_SERVER['PHP_SELF'] . '?' .SID .'"><table border="2">
//	<tr><td><table>'. "\n"; // Nested table
if (!isset($StockID) or $StockID=='')
{

/*If the page was called without $StockID passed to page then assume a new stock item is to be entered show a form with a part Code field other wise the form showing the fields with the existing entries against the part will show for editing with only a hidden StockID field. New is set to flag that the page may have called itself and still be entering a new part, in which case the page needs to know not to go looking up details for an existing part*/
$New = true;
echo '<input type="hidden" name="New" value="1">'. "\n";
echo '<tr><td style="text-align:center; padding:5px 0px 5px 0px;" colspan="2" class="headingtable" ><strong>ITEM MASTER </strong></td>
</tr>';
echo '<tr class="OddTableRows"><td>' . _('Item Main Category') . ':</td><td><select name="CategoryID" onChange="putnumber1(this.value)">';
 //echo '<tr><td>' . _('Item Main Category') . ':</td><td><select name="CategoryID" onChange="putnumber1(this.value)" onChange="getnumber(this.value)">';
    
	 $sql = 'SELECT stockmaincategoryid,stockmaincategoryname FROM stockmaincategory';
	 $ErrMsg = _('The stock categories could not be retrieved because');
	 $DbgMsg = _('The SQL used to retrieve stock categories and failed was');
	 $result = DB_query($sql,$db,$ErrMsg,$DbgMsg);
     
		while ($myrow=DB_fetch_array($result))
		{
			if (!isset($_POST['CategoryID']) or $myrow['stockmaincategoryname']==$_POST['stockmaincategoryname'])
			{
			 	echo '<option selected VALUE="'. $myrow['stockmaincategoryid'] . '">'.$myrow['stockmaincategoryname'].'</option>';
			} 
		}
		
	echo '</select><a target="_blank" href="'. $rootpath . '/stockmaincategory.php?' . SID . '">' . _('Add or Modify Main Category') . '</a></td></tr>';



    echo '<tr class="EvenTableRows"><td>' . _('Item Sub Category') . ':</td><td><div id="change">';


echo '</div><a target="_blank" href="'. $rootpath . '/StockCategories.php?' . SID . '">' . _('Add or Modify Sub Category') . '</a></td></tr>';}
elseif(!isset($_POST['UpdateCategories']) and $InputError!=1) 
{ 
// Must be modifying an existing item and no changes made yet/////////////
 
	$sql = "SELECT *
			FROM stockmaster
		WHERE stockid = '$StockID'";
	  $result = DB_query($sql, $db);
	  $myrow = DB_fetch_array($result);
		//edit by vikas  $_POST['CategoryID']  = $myrow['categoryid'];
		//print_r($myrow['reguestdate']);die;
		$_POST['CategoryID']  =  $myrow['maincategoryid'];
		  $_POST['client_code']  =  $myrow['client_code'];
		$_POST['StockID']  =  $myrow['stockid'];
		$_POST['item_serial_code']  =  $myrow['item_serial_code'];
	  	$_POST['shade_name']  =  $myrow['shade_name'];
		$_POST['abcclass']  =  $myrow['abcclass'];
		
		$_POST['itemcode'] = $myrow['categoryid'];
		$_POST['CategoryID']  =  $myrow['maincategoryid'];
		$_POST['StockID']  =  $myrow['stockid'];
		$_POST['itemcode'] = $myrow['categoryid'];
    	$_POST['description'] = $myrow['description'];
 		$_POST['size'] = $myrow['size'];
 		  $_POST['units']  =  $myrow['units'];
		$_POST['mbflag']  =  $myrow['mbflag'];
		$_POST['lastcurcostdate']  =  $myrow['lastcurcostdate'];
 		$_POST['actualcost']  =  $myrow['actualcost'];
		$_POST['lastcost']  =  $myrow['lastcost'];
		$_POST['materialcost']  =  $myrow['materialcost'];
		$_POST['labourcost']  =  $myrow['labourcost'];
		$_POST['overheadcost']  =  $myrow['overheadcost'];
		$_POST['lowestlevel']  =  $myrow['lowestlevel'];
 		$_POST['discontinued']  =  $myrow['discontinued'];
		$_POST['controlled']  =  $myrow['controlled'];
		$_POST['eoq']  =  $myrow['eoq'];
		$_POST['volume']  =  $myrow['volume'];
		$_POST['kgs']  =  $myrow['kgs'];
		$_POST['barCode']  =  $myrow['barCode'];
 		$_POST['discountcategory']  =  $myrow['discountcategory'];
		$_POST['taxcatid']  =  $myrow['taxcatid'];
		$_POST['serialised']  =  $myrow['serialised'];
		$_POST['appendfile']  =  $myrow['appendfile'];
		$_POST['perishable']  =  $myrow['perishable'];
		$_POST['decimalplaces']  =  $myrow['decimalplaces'];
		$_POST['nextserialno']  =  $myrow['nextserialno'];
	  	$_POST['pansize']  =  $myrow['pansize'];
 		$_POST['shrinkfactor']  =  $myrow['shrinkfactor'];
		$_POST['netweight']  =  $myrow['netweight'];
		$_POST['length']  =  $myrow['length'];
		$_POST['breadth']  =  $myrow['breadth'];
 		$_POST['shape']  =  $myrow['shape'];
 		$_POST['materialtype']  =  $myrow['materialtype'];
		$_POST['predeliveryqc']  =  $myrow['predeliveryqc'];
		 
		$_POST['discountcategory']  =  $myrow['discountcategory'];
		$_POST['abcclass']  =  $myrow['abcclass'];
		$_POST['excisableitem']  =  $myrow['excisableitem'];
		$_POST['excise']  =  $myrow['excise'];
		$_POST['minlevel']  =  $myrow['minlevel'];
		$_POST['maxlevel']  =  $myrow['maxlevel'];
		$_POST['reorderlevel']  =  $myrow['reorderlevel'];
		$_POST['postdelqcreg']  =  $myrow['postdelqcreg'];
		$_POST['qctestdays']  =  $myrow['qctestdays'];
		$_POST['qctesthours']  =  $myrow['qctesthours'];
		$_POST['size']  =  $myrow['size'];
		$_POST['make']  =  $myrow['make'];
		$_POST['color']  =  $myrow['color'];
		$_POST['grade']  =  $myrow['grade'];
		$_POST['created_date']  =  $myrow['created_date'];


$_POST['reguestby']  =  $myrow['reguestby'];
$_POST['approvedby']  =  $myrow['approvedby'];
		  $_POST['barCode']  = $myrow['barCode'];
		  $_POST['ItemPDF']  = $myrow['appendfile'];
		  $_POST['NextSerialNo'] = $myrow['nextserialno'];
          $_POST['reguestdate'] = ConvertSQLDate($myrow['reguestdate']);
	      $_POST['approveddate']= ConvertSQLDate($myrow['approveddate']);

		
	echo '<tr class="EvenTableRows"><td>' . _('Item Sub Category') . ':</td><td>'.$_POST['CategoryID'].'</td></tr>'. "\n";
	echo '<input type="Hidden" name="StockID" value='.$StockID.'>'. "\n";
} 
else { // some changes were made to the data so don't re-set form variables to DB ie the code above
	
	echo '<tr><td>' . _('Item Code') . ':</td><td>'.$StockID.'</td></tr>';
	
	// edit by below
	echo '<tr><td>' . _('Item Sub Category') . ':</td><td>'.$StockID.'</td></tr>';
	echo "$StockID";
}
 
echo'<tr class="OddTableRows"><td>'._('Item Code').':</td><td><input type="text" id="StockID" name="StockID" value="'.$StockID.'" readonly="readonly" size="60"> </td></tr>';

if (isset($_POST['description'])) 
{
	$description = $_POST['description'];
} else {
	$description ='';
}



echo '<tr class="EvenTableRows"><td>' . _('Item description')  .':</td><td>'.$_POST['description'].'</td></tr>'."\n";

  
echo '<tr class="OddTableRows"><td>' . _('Client Code'). ':</td><td>'. htmlentities($_POST['client_code']).'</td></tr>'."\n";



echo '<tr class="EvenTableRows"><td>' . _('Shade Name'). ':</td><td>'. htmlentities($_POST['shade_name'],ENT_QUOTES,_('ISO-8859-1')) .'</td></tr>'."\n";


echo '<tr class="OddTableRows"><td>' . _('Item Serial No.'). ':</td><td>' . htmlentities($_POST['item_serial_code'],ENT_QUOTES,_('ISO-8859-1')) . '</td></tr>'."\n";


// Generate selection drop down from pdf_append directory - by emdx,
// developed with examples from http://au2.php.net/manual/en/function.opendir.php
function select_files($dir, $label = '', $select_name = 'ItemPDF', $curr_val = '', $char_length = 60) 
{
	$teller = 0;
	if (!file_exists($dir)) 
	{
		mkdir($dir);
		chmod($dir, 0777);
	}
	if ($handle = opendir($dir)) {
		$mydir = "<select name=".$select_name.">\n";
		$mydir .= '<option VALUE=0>none';
		if (isset($_POST['ItemPDF'])) {
			$curr_val = $_POST['ItemPDF'];
		} else {
			$curr_val .=  'none';
		}
		while (false !== ($file = readdir($handle)))
		{
			$files[] = $file;
		}
		closedir($handle);
		sort($files);
		foreach ($files as $val) {
			if (is_file($dir.$val)) {
				$mydir .= '<option VALUE='.$val;
				$mydir .= ($val == $curr_val) ? ' selected>' : '>';
				$mydir .= $val."\n";
				$teller++;
			}
		}
		$mydir .= "";
	}
	return $mydir;
}


if (!isset($_POST['ItemPDF']))
 {
	$_POST['ItemPDF'] = '';
}
 
// Add image upload for New Item  - by Ori
echo '<tr class="OddTableRows"><td>'. _('Image File (.jpg)') . ':</td><td><input type="file" id="ItemPicture" name="ItemPicture"></td></tr>';
// EOR Add Image upload for New Item  - by Ori

echo '<tr class="EvenTableRows"><td>' . _('Material Type').':</td><td>' . htmlentities($_POST['materialtype'],ENT_QUOTES,_('ISO-8859-1')) . '</td></tr>'."\n";

echo '<tr class="OddTableRows"><td>' . _('Size') . ':</td><td>' . $_POST['size'] . '</td></tr>';


if (!isset($_POST['eoq']) or $_POST['eoq']=='')
{
    $_POST['eoq']=0;
}

if (!isset($_POST['volume']) or $_POST['volume']=='')
{
    $_POST['volume']=0;
}
if (!isset($_POST['kgs']) or $_POST['kgs']=='')
{
    $_POST['kgs']=0;
}
if (!isset($_POST['Controlled']) or $_POST['Controlled']=='')
{
    $_POST['Controlled']=0;
}
if (!isset($_POST['Serialised']) or $_POST['Serialised']=='' || $_POST['Controlled']==0)
{
    $_POST['Serialised']=0;
}
if (!isset($_POST['decimalplaces']) or $_POST['decimalplaces']=='')
{
	$_POST['decimalplaces']=0;
}
if (!isset($_POST['discontinued']) or $_POST['discontinued']=='')
{
    $_POST['discontinued']=0;
}
if (!isset($_POST['pansize'])) 
{
	$_POST['pansize']=0;
}
if (!isset($_POST['shrinkfactor'])) 
{
	$_POST['shrinkfactor']=0;
}
if (!isset($_POST['NextSerialNo'])) 
{
	$_POST['NextSerialNo']=0;
}

echo '<tr class="EvenTableRows"><td>' . _('Issue as per FIFO') . ':</td><td> ';
if ($_POST['IapF']==0){
	echo 'Yes';
}  
if ($_POST['IapF']==1){
	echo 'No';
}  
echo ' </td></tr>';


echo '<tr class="OddTableRows"><td>' . _('ABC Class') . ':</td><td>' . $_POST['abcclass'] . '</td></tr>';

 
echo '<tr class="EvenTableRows"><td>' . _('Min Level') . ':</td><td>' . $_POST['minlevel'] . '</td></tr>';

echo '<tr class="OddTableRows"><td>' . _('Max Level') . ':</td><td>' . $_POST['maxlevel'] . '</td></tr>';

 

echo '<tr class="EvenTableRows"><td>' . _('Economic Order Quantity') . ':</td><td>' . $_POST['eoq'] . '</td></tr>';
// edit


echo '<tr class="OddTableRows"><td>' . _('Post Del Qc Reg') . ':</td><td> ';
if ($_POST['postdelqcreg']==0)
{
	echo 'Yes';
} else{
echo 'No';
}
 
echo ' </td></tr>';

echo '<tr class="EvenTableRows"><td>' . _('Pre Delivery Qc') . ':</td><td>';
 if ($_POST['predeliveryqc']==0){
echo 'Yes';
} else{
echo 'No';
}
echo  ' </td></tr>';

//
echo '<tr class="OddTableRows"><td>' . _('Packaged volume (metres cubed)') . ':</td><td>' . $_POST['volume'] . '</td></tr>';

echo '<tr class="EvenTableRows"><td>' . _('Packaged Weight (kgs)') . ':</td><td>
' . $_POST['kgs'] . '
</td></tr>';

##========Changed by moha end

echo "<tr class='OddTableRows'><td>" . _('units of Measure') . ":</td> ";
echo " <td>";
$t= $s->getField('unitsofmeasure','unitid',$_POST['units'],'unitname');
 
echo $t."</td></tr>";
echo '<tr class="EvenTableRows"><td>' . _('Assembly, Kit, Manufactured or Service/Labour') . ':</td><td>
 ';
if ($_POST['mbflag']=='A')
{
	echo 'Assembly' ;
} 

if (!isset($_POST['mbflag']) or $_POST['mbflag']=='K')
{
	echo  'Kit ';
} 
 if (!isset($_POST['mbflag']) or $_POST['mbflag']=='M'){
	echo  'Manufactured' ;
}  
if (!isset($_POST['mbflag']) or $_POST['mbflag']=='G' OR !isset($_POST['mbflag']) OR $_POST['mbflag']==''){
	echo 'Phantom' ;
}  
if (!isset($_POST['mbflag']) or $_POST['mbflag']=='B' OR !isset($_POST['mbflag']) OR $_POST['mbflag']==''){
	echo  'Purchased' ;
}  

if (isset($_POST['mbflag']) and $_POST['mbflag']=='D'){
	echo 'Service/Labour' ;
}  

echo ' </td></tr>';

echo '<tr class="OddTableRows"><td>' . _('Current or Obsolete') . ':</td><td>';
if ($_POST['discontinued']==0){
	echo 'Current';
} else {
	echo 'Obsolete';
}
 echo ' </td></tr>';

 

echo '<tr class="EvenTableRows"><td>' . _('Decimal Places for display Quantity') . ':</td><td>' . $_POST['decimalplaces'] . '</td></tr>';
 
 
echo '<tr class="OddTableRows"><td>' . _('Discount Category') . ':</td><td>'.$_POST['discountcategory'] .'</td></tr>';

echo '<tr class="EvenTableRows"><td>' . _('Tax Category') . ':</td><td>';
  $sql = 'SELECT taxcatid  , taxcatname          FROM taxcategories where taxcatid="'.$_POST['taxcatid'].'"ORDER BY taxcatname';
  $result = DB_query($sql, $db);
 
while ($myrow = DB_fetch_array($result)) {
 		echo '<option value=' . $myrow['taxcatid'] . '>' . $myrow['taxcatname'] . '</option>';
 } //end while loop

echo '  </td></tr>';

     echo'<tr class="OddTableRows">
        <td>' . _('Pan Size') . ':</td>
	    <td>' . $_POST['pansize'] . '</td>
	</tr>	
     <tr class="EvenTableRows">
        <td>' . _('Shrinkage Factor') . ':</td>
	    <td>' . $_POST['shrinkfactor'] . '</td>
	</tr>';


echo '<tr class="EvenTableRows"><td style="text-align:center; padding:5px 0px 5px 0px;" colspan="2"  class="headingtable"><strong>Item Specification :</strong></td>
	  </tr>';
  
   echo'<tr class="OddTableRows">
        <td>' . _('length') . ':</td>
	    <td>' . $_POST['length'] . '</td>
	</tr>';	
	echo'<tr class="EvenTableRows">
        <td>' . _('breadth') . ':</td>
	    <td>' . $_POST['breadth'] . '</td>
	</tr>';	
  
  echo'<tr class="OddTableRows">
        <td>' . _('shape') . ':</td>
	    <td>' . $_POST['shape'] . '</td>
	</tr>';	
   
		?>

	  <?php 
	  
	  echo '<tr><td style="text-align:center; padding:5px 0px 5px 0px;" colspan="2"  class="headingtable"><strong>Requester :</strong></td>
	  </tr>';
	    
  echo'<tr class="OddTableRows">
        <td>' . _('Request By') . ':</td>
	    <td>' . $_POST['reguestby'] . '</td>
	</tr>';	

 echo'<tr class="EvenTableRows">
        <td>' . _('Request Date') . ':</td>
	    <td>'.$_POST['requestdate'].' </td></tr>';

 echo '<tr><td style="text-align:center; padding:5px 0px 5px 0px;" colspan="2" class="headingtable"><strong>Approvals : </strong></td>
	  </tr>';
echo'<tr class="OddTableRows">
        <td>' . _('Approved By') . ':</td>
	    <td>' . $_POST['approvedby'] . '</td>
	</tr>';	
	echo'<tr class="EvenTableRows">
        <td>' . _('Approved Date') . ':</td>
	    <td>'.$_POST['date'].'</td></tr>';
	
	 

 if (function_exists('imagecreatefrompng'))
 {
	$StockImgLink = '<img src="GetStockImage.php?SID&automake=1&textcolor=FFFFFF&bgcolor=CCCCCC'.
		'&StockID='.urlencode($StockID).
		'&text='.
		'&width=64'.
		'&height=64'.
		'" >';
} else {
	if( isset($StockID) and file_exists($_SESSION['part_pics_dir'] . '/' .$StockID.'.jpg') ) {
		$StockImgLink = '<img src="' . $_SESSION['part_pics_dir'] . '/' .$StockID.'.jpg" >';
	} else {
		$StockImgLink = _('No Image');
	}
}

echo '</table></td></tr></table><div class="centre">';

if (!isset($_POST['CategoryID'])) {
	$_POST['CategoryID'] = '';
}
//echo '<table><tr><th colspan="2">' . _('') . '</th></tr>';

//echo '<table><tr><th colspan="2">' . _('Item Category Properties') . '</th></tr>';
$sql = "SELECT stkcatpropid,
				label,
				controltype,
				defaultvalue
		FROM stockcatproperties
		WHERE categoryid ='" . $_POST['CategoryID'] . "'
		AND reqatsalesorder =0
		ORDER BY stkcatpropid";

$PropertiesResult = DB_query($sql,$db);
$PropertyCounter = 0;
$PropertyWidth = array();

while ($PropertyRow=DB_fetch_array($PropertiesResult))
{

	$PropValResult = DB_query("SELECT value FROM
									stockitemproperties
									WHERE stockid='" . $StockID . "'
									AND stkcatpropid =" . $PropertyRow['stkcatpropid'],
								$db);
	$PropValRow = DB_fetch_row($PropValResult);
	$PropertyValue = $PropValRow[0];

	echo '<input type="hidden" name="PropID' . $PropertyCounter . '" value=' .$PropertyRow['stkcatpropid'] .'>';

	echo '<tr><td>' . $PropertyRow['label'] . '</td>
				<td>';
	switch ($PropertyRow['controltype']) {
	 	case 0; //textbox
	 		echo '<input type="textbox" name="PropValue' . $PropertyCounter . '" size="20" maxlength="100" value="' . $PropertyValue . '">';
	 		break;
	 	case 1; //select box
	 		$OptionValues = explode(',',$PropertyRow['defaultvalue']);
			echo '<select name="PropValue' . $PropertyCounter . '">';
			foreach ($OptionValues as $PropertyOptionValue){
				if ($PropertyOptionValue == $PropertyValue){
					echo '<option selected value="' . $PropertyOptionValue . '">' . $PropertyOptionValue . '</option>';
				} else {
					echo '<option value="' . $PropertyOptionValue . '">' . $PropertyOptionValue . '</option>';
				}
			}
			echo '</select>';
			break;
		case 2; //checkbox
			echo '<input type="checkbox" name="PropValue' . $PropertyCounter . '"';
			if ($PropertyValue==1){
				echo '"checked"';
			}
			echo '>';
			break;
	} //end switch

	echo '<input type="hidden" name="PropType' . $PropertyCounter .'" value=' . $PropertyRow['controltype'] . '>';
	echo '</td></tr>';
	$PropertyCounter++;
} //end loop round properties for the item category
echo '</table>';
//echo '</form></div>';

echo '<input type="hidden" name="PropertyCounter" value=' . $PropertyCounter . '>';
echo '</form></div>';

?>

<script language="javascript">
 var xmlHttp
 var rowcount=1;
function Manufacture()
{
	var str1 = document.getElementById("make").value;
	var str2 = document.getElementById("color").value;
	var str3 = document.getElementById("grade").value;
    xmlHttp=GetXmlHttpObject();
	 
	if(str1!="" && str2!="" && str3!="")
	{	  
		if (xmlHttp==null)
		{
		    alert ("Your browser does not support AJAX!");
		    return;
		} 
		var url="manufacture.php";
		url=url+"?makeId="+str1+"&colorId="+str2+"&gradeId="+str3+"&Rowcount="+rowcount;
		//alert(url);
		xmlHttp.onreadystatechange=AddRow;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	}
}

function AddRow() 
{ 
	if (xmlHttp.readyState==4)
	{ 
   		var old_add_value = document.getElementById("Add").innerHTML;
		var new_value = xmlHttp.responseText;
	    var final_value = old_add_value + new_value;
	    document.getElementById("Add").innerHTML=final_value;
		rowcount++;
	}
}

 
function putnumber1(str)
{ 
   
   xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null)
		  {
		    alert ("Your browser does not support AJAX!");
		    return;
		  } 
	var url="randomnumber.php";
	url=url+"?Category1="+str;
	//alert(url);
	//url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=NumberChanged1;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function NumberChanged1() 
{ 
	if (xmlHttp.readyState==4)
	{ 
	   document.getElementById("change").innerHTML=xmlHttp.responseText;
	}
}

function putnumber(str)
{ 
 	xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null)
		  {
		    alert ("Your browser does not support AJAX!");
		    return;
		  } 
	var url="stockNumber.php";
	url=url+"?itemcode="+str;
	//alert(url);
	//url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=NumberChanged2;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function NumberChanged2() 
{ 
	if (xmlHttp.readyState==4)
	{ 
	    document.getElementById("StockID").value=xmlHttp.responseText;
	}
}


function GetXmlHttpObject()
{
	var xmlHttp=null;
	try
	  {
	  // Firefox, Opera 8.0+, Safari
	  xmlHttp=new XMLHttpRequest();
	  }
	catch (e)
	  {
	  // Internet Explorer
	  try
		{
		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
	  catch (e)
		{
		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	  }
	return xmlHttp;
}
</script>


<?php
include('includes/footer.inc');
?>
