<link rel="stylesheet" href="css/new_mxerp.css">
<?php
$modid=$_REQUEST['modid'];
$frmid=$_REQUEST['frmid'];
$rurl="&modid=".$modid."&frmid=".$frmid;
if($_REQUEST['DelID']!='' && $_REQUEST['act']=='del')
{
  //echo "Delete from salesorder where id='".$_REQUEST['DelID']."'";
  
 	$query1=DB_query("Delete from stock_transfer where id='".$_REQUEST['DelID']."'",$db);
	 $query2=DB_query("Delete from stock_transfer_details where parentId='".$_REQUEST['DelID']."'",$db);
	 $s->pageLocation('index.php?route=stock_transfer_list&daction=Deleted'.$rurl);
}
if($_REQUEST['ViewID']=='' && $_REQUEST['act']=='') {
?>

<div class="body_contain">
<div class="tab_div">
<h1>Stock Transfer</h1>

<?php if($_SESSION['frmAdd']=='1'){?>
<div align="left"
	   style="padding-left:10px;"><a href="index.php?route=stock_transfer&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>">Add New</a> <?php }




if($_REQUEST['daction']=='Deleted')
{
   echo "<div class='error'>Record Deleted Sucessfully</div><br />";
   }



 ?>
<br /><br />
<table width="100%" border="1" cellpadding="3" cellspacing="0" style="border-collapse:collapse; border:#666666 solid 1px;">
  <tr>
    <td class="tabledata">S. NO.</td>
    <td class="tabledata">Branch</td>
    <td class="tabledata">Transfer No.</td>
    <td class="tabledata">Date</td>
    <td class="tabledata">From Branch</td>
    <td class="tabledata">From Store</td>
  	<td class="tabledata">To Branch</td>
    <td class="tabledata">To Store</td>
    <td class="tabledata">View</td>
    <!--<td class="tabledata">Edit</td>-->
    <td class="tabledata">Delete</td>
  </tr>
  <?php 
 $sql=DB_query("Select * from stock_transfer where CompanyId='".$_SESSION['ACGCompanyId']."'",$db);
$num=DB_num_rows($sql);
if($num>0)
{ $i=1;
while($myrow=DB_fetch_array($sql)){
  ?>
<tr bgcolor="#c1c1c1">
  	<td><?php echo $i;?></td>
    <td><?php 
	$sitename=$s->getField('locations','loccode',$myrow['site'],'locationname');
	echo $sitename;?></td>
    <td><?php echo $myrow['transferNo'];?></td>
    <td><?php echo ConvertSQLDate($myrow['date']);?></td>
    <td><?php 
	$sitename=$s->getField('locations','loccode',$myrow['fromSite'],'locationname');
	echo $sitename;?></td>
   	<td><?php 
	$storename=$s->getField('storetype','StoreCode',$myrow['fromStore'],'StoreName');
	echo $storename;?></td>
	<td><?php 
	$sitename=$s->getField('locations','loccode',$myrow['toSite'],'locationname');
	echo $sitename;?></td>
    	<td><?php
	$storename=$s->getField('storetype','StoreCode',$myrow['toStore'],'StoreName');
	echo $storename;?></td>
    <td><?php if($myrow['frmView']=='1'){?><a href="index.php?route=stock_transfer_list&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&ViewID=<?php echo $myrow['id'];?>&act=view">View</a><?php }else{echo "No Permission";} ?></td>
    <!--<td><a href="index.php?route=stock_transfer&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&EditID=<?php echo $myrow['id'];?>&act=edit">Edit</a></td>-->
    <td>
	<?php if($myrow['frmView']=='1'){?>
	<a href="index.php?route=stock_transfer_list&DelID=<?php echo $myrow['id']?>&act=del<?php  echo $rurl;?>" onClick="return confirm('Do You want to Delete This Record')">Delete</a>
	<?php }else{echo "No Permission";} ?>
	</td>
  </tr>
  <?php $i++;} } else {?>
  	<tr bgcolor="#c1c1c1">
	   <td  colspan="10">No Records</td></tr>
  	<?php } ?>
</table>
</div></div>


<?php }






if($_REQUEST['ViewID']!='' && $_REQUEST['act']=='view')
{
	//echo "Select * from stock_transfer where id='".$_REQUEST['ViewID']."'";
$master_sql=DB_query("Select * from stock_transfer where id='".$_REQUEST['ViewID']."'",$db);
$master_row=DB_fetch_array($master_sql);
?>

<div class="body_contain">
<div class="tab_div">

<h1>View Stock Transfer</h1>
<table width="100%" border="1" cellpadding="3" cellspacing="0" style="border-collapse:collapse; border:#666666 solid 1px;">
  <tr>
    <td class="tabledata1">Branch</td>
    <td><select name="site" id="site" style="width:100%; height:20px" onchange="transferCode(this.value)">
    <?php 
	$siteSql=DB_query("Select loccode,locationname from locations where loccode='".$master_row['site']."'",$db);
	while($siteRow=DB_fetch_array($siteSql))
	{
		$s='';	
		if($_SESSION['site']==$siteRow['loccode'])
		$s="selected";
		?>
    <option value="<?php echo $siteRow['loccode'];?>"><?php echo $siteRow['locationname'];?></option>
	<?php 	
	}
	?>
    </select></td>
    <td class="tabledata1">ST. No.</td>
    <td id="transferDiv"><input type="text" value="<?php echo $master_row['transferNo'];?>" name="transferNo" id="transferNo" style="width:100%;height:20px"></td>
  </tr>
  <tr>
    <td class="tabledata1">Date</td>
    <td><input type="text" name="date" id="date" style="width:100%;height:20px" value="<?php echo ConvertSQLDate($master_row['date']);?>"></td>
    <td class="tabledata1">Voucher Type</td>
    <td>
      <select name="voucherType" id="voucherType" style="width:100%;height:20px">
      	<option value="Stock Transfer">Stock Transfer</option>
      </select>
    </td>
  </tr>
  <tr>
    <td class="tabledata1">Form No.</td>
    <td><input type="text" name="formNo" id="formNo" value="<?php echo $master_row['formNo'];?>" style="width:100%;height:20px"></td>
    <td class="tabledata1">Received By</td>
    <td><select name="receivedBy" id="receivedBy" style="width:100%;height:20px">
    	<?php 
    	$empSql=DB_query("Select id, emp_name from empmaster where id='".$master_row['receivedBy']."';",$db);
		while($empRow=DB_fetch_array($empSql))
		{
			$s='';
			if($_SESSION['receivedBy']==$empRow['id'])
			$s="selected";
			?>
			<option value="<?php echo $empRow['id'];?>" ><?php echo $empRow['emp_name'];?></option>
		<?php 	
		}
    	?>
    </select></td>
  </tr>
  <tr>
    <td class="tabledata1">Transport Type</td>
    <td>
    	<select name="transportType" id="transportType" style="width:100%;height:20px">
    	<?php 
    	$transSql=DB_query("Select * from transport_master where id='".$master_row['transportType']."'",$db);
		while($transRow=DB_fetch_array($transSql))
		{
			$s='';
			if($_SESSION['transportType']==$transRow['id'])
			$s="selected";
			?>
			<option value="<?php echo $transRow['id'];?>"><?php echo $transRow['TransportName'];?></option>
		<?php 	
		}
    	?>
    </select>
    	</td>
    <td class="tabledata1">Vehicle No.</td>
    <td><input type="text" name="vehicleNo" id="vehicleNo" value="<?php echo $master_row['vehicleNo'];?>" style="width:100%;height:20px"></td>
  </tr>
  <tr>
    <td class="tabledata1">From Branch</td>
    <td><select name="fromSite" id="fromSite" style="width:100%;height:20px" onchange="showFromStore(this.value)">
    	<?php 
	$siteSql=DB_query("Select loccode,locationname from locations where loccode='".$master_row['fromSite']."'",$db);
	while($siteRow=DB_fetch_array($siteSql))
	{
		$s='';
		if($_SESSION['fromSite']==$siteRow['loccode'])
		$s="selected";
		?>
    <option value="<?php echo $siteRow['loccode'];?>"><?php echo $siteRow['locationname'];?></option>
	<?php 	
	}
	?>
    </select></td>
    <td class="tabledata1">From Store</td>
    <td id="fromDiv"><select name="fromStore" id="fromStore" style="width:100%;height:20px">
    	<?php 
    	$storeSql=DB_query("SELECT DISTINCT StoreCode, StoreName FROM storetype  where StoreCode='".$master_row['fromStore']."'",$db);
		while($storeRow=DB_fetch_array($storeSql))
		{
			$s='';
			if($_SESSION['fromStore']==$storeRow['StoreCode'])
			$s="selected";
			?>
			<option value="<?php echo $storeRow['StoreCode'];?>"><?php echo $storeRow['StoreName'];?></option>
		<?php 	
		}
    	?>
    </select></td>
  </tr>
  <tr>
    <td class="tabledata1">To Branch</td>
    <td><select name="toSite" id="toSite" style="width:100%;height:20px" onchange="showToStore(this.value)">
    	<?php 
	$siteSql=DB_query("Select loccode,locationname from locations where loccode='".$master_row['toSite']."'",$db);
	while($siteRow=DB_fetch_array($siteSql))
	{
			$s='';
			if($_SESSION['toSite']==$siteRow['loccode'])
			$s="selected";?>
    <option value="<?php echo $siteRow['loccode'];?>" <?php echo $s;?>><?php echo $siteRow['locationname'];?></option>
	<?php 	
	}
	?>
    </select></td>
    <td class="tabledata1">To Store</td>
    <td id="toDiv"><select name="toStore" id="toStore" style="width:100%;height:20px">
    	<?php 
    	$storeSql=DB_query("SELECT DISTINCT StoreCode, StoreName FROM storetype where StoreCode='".$master_row['toStore']."'",$db);
		while($storeRow=DB_fetch_array($storeSql))
		{
			$s='';
			if($_SESSION['toStore']==$storeRow['StoreCode'])
			$s="selected";
			?>
			<option value="<?php echo $storeRow['StoreCode'];?>" <?php echo $s;?>><?php echo $storeRow['StoreName'];?></option>
		<?php 	
		}
    	?>
    </select></td>
  </tr>
</table>
<div style="overflow:auto; width:810px ; height:auto"  >
<table width="100%" border="1" cellpadding="3" cellspacing="0" style="border-collapse:collapse; border:#666666 solid 1px;">
  <tr>
    <td class="tabledata">Part Code</td>
    <td class="tabledata" width="25%">Item Name</td>
    <td class="tabledata">UOM</td>
    <td class="tabledata">Make</td>
    <td class="tabledata">Grade</td>
    <td class="tabledata">Color</td>
    <td class="tabledata">Size</td>
    <td class="tabledata">GSM</td>
    <td class="tabledata">Stock Qty</td>
    <td class="tabledata">Transfer Qty</td>
    <td class="tabledata">Purpose</td>
  </tr>
 <?php 
 
	$detailsSql=DB_query("Select * from stock_transfer_details where parentId='".$_REQUEST['ViewID']."'",$db);
	while($detialsRow=DB_fetch_array($detailsSql))
	{	 
		$itemSql=DB_query("select item_name, unit from item_master where StockID='".$detialsRow['itemCode']."'",$db);
		$itemRow=DB_fetch_array($itemSql);
 ?>
  <tr>
    <td><?php echo $detialsRow['itemCode']?></td>
    <td><?php echo $itemRow['item_name']?></td>
    <td><?php
    	$uomSql=DB_query("Select unitname from unitsofmeasure where unitid='".$itemRow['unit']."'",$db);
		$uomRow=DB_fetch_array($uomSql);
		echo $uomRow['unitname'];
    ?></td>
    <?php 
    	$makeName=$fnLib->getField('product_manufacture','id',$detialsRow['make'],'manufacturer');
    	$gradeName=$fnLib->getField('product_grade','id',$detialsRow['grade'],'grade');
    	$colorName=$fnLib->getField('product_color','id',$detialsRow['color'],'color');
    	$sizeName=$fnLib->getField('size_master','id',$detialsRow['size'],'name');
    	$gsmName=$fnLib->getField('gsm','id',$detialsRow['gsm'],'gsm');
    ?>
    <td><input type="text" value="<?php echo $makeName;?>" style="width:100%;height:20px"/>
    </td>
    <td>
    	<input type="text" value="<?php echo $gradeName;?>"  style="width:100%;height:20px"/>
    </td>
    <td>
    	<input type="text" value="<?php echo $colorName;?>" style="width:100%;height:20px" />
    </td>
    <td>
    	<input type="text" value="<?php echo $sizeName;?>" style="width:100%;height:20px" />
    </td>
    <td>
    	<input type="text" value="<?php echo $gsmName;?>" style="width:100%;height:20px" />
    </td>
    <td></td>
    <td><input type="text" value="<?php echo $detialsRow['quantity'];?>" style="width:100%;height:20px"/></td>
    <td><input type="text" value="<?php echo $detialsRow['purpose'];?>" style="width:100%;height:20px"/></td>
  </tr>
  <?php } ?>
</table></div>

<table width="100%" border="1" cellpadding="3" cellspacing="0" style="border-collapse:collapse; border:#666666 solid 1px;">
  <tr>
  <td class="tabledata">Remarks</td>
  <td><textarea name="remarks" style="width:100%;" rows="5"><?php echo $master_row['remarks'];?></textarea></td>
  </tr>
</table>

</div></div>


<?php 
}
?>
