<?php 
$PageSecurity = 2;
include('includes/DefineSuppTransClass.php');
include('includes/DefinePOClass.php');
include('includes/SQL_CommonFunctions.inc');
include('includes/session.inc');
		
		if($_GET['site1'] && $_GET['site1'] != '')
		{
		$site = $_GET['site1'];
		//echo $site; ?>
 			<div id="getstore">
			<select name="store" id="store" onChange="">
			<option value="000">Select Store</option>
			<?php
			$store_sql = "SELECT StoreCode, StoreName FROM storetype where Store_Site = '".$_REQUEST['site1']."'";
			$store_result = DB_query($store_sql,$db);
			while($store_row = DB_fetch_array($store_result))
			{ 
				$p='';
				if($store_row['StoreCode']==$_SESSION['store'])
				$p= "selected";
			
			?>
			<option value="<?php echo $store_row['StoreCode'] ; ?>" <?php echo $p;?>><?php echo $store_row['StoreName'] ; ?></option>
			<?php }
			?>
			</select></div>
			
<?php } 
		else if($_GET['site'] && $_GET['site'] != '')
		{
		$site = $_GET['site'];
		//echo $site; 
$prefix_sql=DB_query("select * from prefix_tbl where prefix_name='Material Receipt' ",$db);
$prefix_row=DB_fetch_array($prefix_sql);
$prefix=$prefix_row['prefix_code'];
		 
$sql="Select * from material_receipt where to_site='".$site."' order by receipt_voucher_code desc limit 1";
$result=DB_query($sql,$db);
$row=DB_fetch_array($result);

if(DB_num_rows($result)>0)
{
	$receipt_voucher_code=$row['receipt_voucher_code'];
	$voucher1=substr($receipt_voucher_code,0,12);
	$voucher2=substr($receipt_voucher_code,-4);
	$final=$voucher2+1;
	$strfinal=$voucher1.str_pad($final,4,"0",STR_PAD_LEFT);
	 }
	else
	{
			$strfinal=$prefix."/".$site."/0001";
			
	}		

?>		
		<div id="getstore"><table width="100%">
		 <tr><td width="38%"><strong>RECEIVE FROM </strong></td>
		 <td width="62%"><select name="from_site" id="from_site" onchange="get_voucher(this.value)">
           <option value="000">Select Site</option>
           <?php 
			//$site_sql = "select * from material_issue where to_site = '".$_GET['site']."'"; 
			$site_sql = "select distinct from_site from material_issue where to_site = '".$_GET['site']."'";
			$site_result = DB_query($site_sql,$db);
			while($site_row = DB_fetch_array($site_result))
			{ 
				$p='';
				if($site_row['from_site'] == $_POST['from_site'])
				$p= "selected";
			?>
           <option value="<?php echo $site_row['from_site']; ?>" <?php echo $p;?>><?php echo $site_row['from_site']; ?></option>
           <?php }
			?>
         </select></td>
		 </tr>
		 <tr>
            <td height="33"><strong>STORE</strong></td>
			<td><select name="store" onChange="">
			<option value="000">Select Store</option>
			<?php
			echo $store_sql = "SELECT StoreCode, StoreName FROM storetype where Store_Site = '".$_GET['site']."'";
//$store_sql = "select store from material_issue where from_site='".$_POST['from_site."' and  to_site='".$_GET['site']."' ";
			$store_result = DB_query($store_sql,$db);
			while($store_row = DB_fetch_array($store_result))
			{ 
				$p='';
				if($store_row['StoreCode'] == $_POST['store'])
				$p="selected";
			
			?>
		<option value="<?php echo $store_row['StoreCode'] ; ?>" <?php echo $p;?>><?php echo $store_row['StoreName'] ; ?></option>
			<?php }
			?>
			</select></td></tr>
			<tr>
           <td height="26"><strong> VOUCHER NO. </strong></td>
	<td><input type="text" name="receipt_voucher_code" id="receipt_voucher_code" value="<?php echo $strfinal; ?>" size="25" readonly="true">
	</td>
          </tr>
         </table></div>
		 <?php 
	 
		 } ?>
