<?php ob_start();
error_reporting(0);
$PageSecurity = 4;
date_default_timezone_set('Asia/Kolkata');
$PageName = 'DispatchReceiptNote';
include('includes/DefinePOClass.php');
include('includes/SQL_CommonFunctions.inc');


//**************************Modify Section*******************************************************
if(isset($_REQUEST['mrnid']))
{
	    $condition="id='".$_REQUEST['mrnid']."'";
		$GetData=$s->GetRecord('log_srn', $condition);
		$GetResultData= DB_query($GetData,$db);
		$GetRowData=DB_fetch_array($GetResultData);
						
		$srn_no=$GetRowData['srn_no'];
		$srn_date=$GetRowData['srn_date'];
		$sitecode=$GetRowData['site'];
		$storecode=$GetRowData['store'];
	    $type=$GetRowData['type'];
		$party_id=$GetRowData['party_id'];
		$from_site=$GetRowData['from_site'];
		$address=$GetRowData['address'];
		$contact_per=$GetRowData['contact_per'];
		$contact_no=$GetRowData['contact_no'];
		$dis_id=$GetRowData['dis_id'];
		$ref_no=$GetRowData['ref_no'];
		$ref_date=$GetRowData['ref_date'];
		$way_bill_no=$GetRowData['way_bill_no'];
		$way_bill_amt=$GetRowData['way_bill_amt'];
		$vehicle_no=$GetRowData['vehicle_no'];
		$lr_no=$GetRowData['lr_no'];
		$lr_date=$GetRowData['lr_date'];
		$remarks=$GetRowData['remarks'];
}
?>


<script type="text/javascript" src="js/function-ajax.js" language="javascript"></script>

<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div">
<form action="" method="post" name="myform" id="myform">
<h1 align="center"><strong>View Transfer Note</strong></h1>
<input name="usertype" id="usertype" type="hidden" value="<?php echo $dealertype; ?>" />
 
<h3 >GENERAL DETAILS</h3>
<table width="100%"  border="1" cellspacing="0" cellpadding="3">
<tr class="row1">
    <td class="tabledata1">Location </td>
    <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
	<tr>
	  <td><?php
	if($_SESSION['AssignedBranch']!='')
	  {	  	
      $ss="Select loccode, locationname from locations  where CompanyId='".$_SESSION['ACGCompanyId']."'
    and loccode in('".$_SESSION['AssignedBranch']."')";
	  	 $site_sql=DB_query($ss,$db);
	  }
	  else
	  {
		$ss="Select loccode,locationname from locations where CompanyId='".$_SESSION['ACGCompanyId']."'";
		$site_sql=DB_query($ss,$db);
	  }?>
     <select name="site" id="site" style="width:70px" disabled="disabled"    >
      <option value="0">---Select---</option>
      <?php
	while($site_row=DB_fetch_array($site_sql))
	{
	?>
      <option value="<?php echo $site_row['loccode'];?>"<?php echo ($sitecode==$site_row['loccode']?'selected':'')?>><?php echo $site_row['loccode'];?></option>
      <?php } ?>
    </select></td>
	  <td><div id="txtsite">
	    <?php
	
	$site_sql="Select locationname from locations where loccode ='".$sitecode."'";
	$site_res=DB_query($site_sql,$db);
	$site_row=DB_fetch_array($site_res);
	if(isset($sitecode))
	{
	?>
	    <input name="sitename" type="text" id="sitename"  value="<?php echo $site_row['locationname'];?>" size="20" readonly="true">
	<?php } else {?>
	<input name="sitename" type="text" id="sitename"  value="<?php echo $sitename;?>" size="20" readonly="true">
	<?php } ?>
	<input type="hidden" name="hidden_site" id="hidden_site" value="<?php echo $_REQUEST['hidden_site'];?>"/></div></td>
	</tr>
	<tr></tr>
	</table>	</td>
	<td  class="tabledata1">Warehouse</td>
    <td id="storedata">
	<table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
		<td>	
		<?php
		$sql_store = "select id, StoreCode, StoreName from storetype where CompanyId='".$_SESSION['ACGCompanyId']."' and Store_Site in ('".$_SESSION['AssignedBranch']."') order by StoreCode ASC";
		$resultStkLocs = DB_query($sql_store,$db);
		?>
		<select id="store" name="storecode"  style="width:100%" disabled="disabled">
		<option value="0">Select</option> 
		<?php 
		while ($myrow=DB_fetch_array($resultStkLocs))
		{
				$p='';
				if($storecode==$myrow['id'])
				$p="selected";
		?>
			<option Value="<?php echo $myrow['id']; ?>" <?php echo $p; ?>><?php echo $myrow['StoreName']; ?></option>
		<?php }
		?>
		</select>		</td>
        <!--<td><div id="txtid"><input type="text" name="storename" id="storename" size="20" readonly="true" value="<?php echo $storename; ?>"></div></td>-->
      </tr>
    </table></td>
	<td  class="tabledata1">SRN No. </td>
    <td><input type="text" value="<?php echo $srn_no;?>" style="width:150px;" name="srn_no" readonly="true"></td>
</tr>
<tr class="row1">
	<td  class="tabledata1">SRN Date </td>
    <td><input type="text" value="<?php echo ConvertSQLDate($gsrn_date);?>" style="width:150px;" name="drn_date" readonly="true"></td>
  	<td class="tabledata1">Party Name</td>
    <td><select name="party_id" id="party_id" style="width:100%;" disabled="disabled">
		<option value="0">Select Party</option>
      <?php 
      $party=DB_query("Select id,client_code,c_name from clientmaster",$db);
	  while($party_row=DB_fetch_array($party))
	  {?>
	  <option value="<?php echo $party_row['id'];?>" <?php if($party_row['id']==$party_id){echo "selected";}?>><?php echo $party_row['c_name'];?></option>	
	  <?php 	
	  }
      ?>
    </select>
	</td>
	<td class="tabledata1">From Site</td>
	<td>
	  <select name="from_site" id="from_site"  style="width:150px;" disabled="disabled">
        <option value="0" >---Select---</option>
        <?php
			$sql="select id, StoreCode, StoreName from locations_to";
			$result = DB_query($sql, $db);
			while($myrow = DB_fetch_array($result))
			{ 
			?>
        <option  value="<?php echo $myrow['id']; ?>" <?php if($myrow['id']==$from_site){echo "selected";}?>><?php echo  $myrow['StoreName']; ?></option>
        <?php }
			?>
      </select>
	 </td>
</tr>
<tr class="row1">
    <td class="tabledata1">Site Address</td>
    <td><textarea name="address" id="address" readonly="readonly"><?php echo $address;?></textarea></td>
	<td class="tabledata1">Contact Person</td>
    <td><input type="text" name="contact_per" id="contact_per"  style="width:150px;" value="<?php echo $contact_per;?>" readonly="true"/></td>
	<td class="tabledata1">Mobile</td>
    <td><input name="contact_no" id="contact_no" type="text" value="<?php echo $contact_no;?>" size="25" style="width:100%;" readonly="true"/></td>
</tr>
<tr class="row1">
	<td  class="tabledata1">Dispatch No.</td>
    <td id="disval">
	<?php
		$data4="<select name='dis_id' id='dis_id'  style='width:150px;' disabled='disabled'";
		$data4.="<option value='0' >---Select---</option>";
		$sql1="select id, dis_no from log_dispatch where id='".$dis_id."'";
		$result1 = DB_query($sql1, $db);
		while($myrow1 = DB_fetch_array($result1))
		{
			$data4.="<option value=".$myrow1['id'].">".$myrow1['dis_no']."</option>";
		}
		echo $data4.="</select>";
	?>
	</td>
    <td  class="tabledata1">Ref No.</td>
    <td><input type="text" style="width:150px;" name="ref_no" id="ref_no" value="<?php echo $ref_no;?>" readonly="true"></td>
    <td class="tabledata1">Ref Date</td>
    <td><input name="ref_date" type="text" id="ref_date" style="width:150px;" value="<?php echo ConvertSQLDate($ref_date);?>" readonly="true" /></td>
</tr>
<tr class="row1">
	<td class="tabledata1">Way bill No. </td>
    <td><input name="way_bill_no" type="text" id="way_bill_no" style="width:150px;"  value="<?php echo $way_bill_no;?>" readonly="true"/></td>
	<td class="tabledata1">Way Bill Amount</td>
    <td><input name="way_bill_amt" type="text" id="way_bill_amt" style="width:150px;"  value="<?php echo $way_bill_amt;?>" readonly="true"/></td>
	<td class="tabledata1">Vehicle no.</td>
    <td><input name="vehicle_no" type="text" id="vehicle_no" style="width:150px;"  value="<?php echo $vehicle_no;?>" readonly="true"/></td>
</tr>
<tr class="row1">
	<td class="tabledata1">L R No.</td>
    <td><input name="lr_no" type="text" id="lr_no" style="width:150px;"  value="<?php echo $lr_no;?>" readonly="true"/></td>
	<td class="tabledata1">L R Date</td>
    <td><input name="lr_date" type="text" id="lr_date" style="width:150px;"  value="<?php echo ConvertSQLDate($lr_date);?>" /></td>
	<td class="tabledata1">&nbsp;</td>
    <td>&nbsp;</td>
</tr>
<tr class="row1">
    <td  class="tabledata1">Remarks If Any</td>
    <td colspan="5"><textarea name="remarks"  id="remarks" style="width:830px;height:50px;" readonly="readonly"><?php echo $remarks;?></textarea></td>
  </tr>
<!--<tr class="row1">
	<td style="text-align:left;" colspan="6">
		<input type="button" onClick="open_items()" value="Add Rows" accesskey="A" class="search" />&nbsp;
		<input type="button" class="search"  onclick="deleteRowOrder('dataTable')" value="Delete" />&nbsp;
	</td>			 
</tr>-->
<tr class="row1">
	<td  colspan="6">   
		<hr>
			 <h1 align="center" style="text-align:center;">Transfer Products</h1>
			 <br />
		<table width="100%" border="1" cellspacing="0" cellpadding="0">
		<tr class="row1">	
		<td class="tabledata1" style="width:40px;"><strong>S. No.</strong></td>
		<td class="tabledata1" style="width:20px;"><strong></strong></td>
		<td class="tabledata1"><strong>CODE </strong></td>
		<td class="tabledata1"><strong>NAME</strong></td>
		<td class="tabledata1"><strong>PART NO.</strong></td>
		<td class="tabledata1"><strong>UOM</strong></td>         
		<!--<td class="tabledata1"><strong>QTY</strong></td>
		<td class="tabledata1"><strong>PENDING</strong></td>-->
		<td class="tabledata1"><strong>TRANSFER QTY</strong></td>    
		</tr>
		<tbody id='dataTable'>
		<?php
			$i=1;
			$data9='';
$sqlQty = "SELECT * From log_dispatchqty Where dis_id='".$dis_id."' group by mst_itemid";

$Qty_result = DB_query($sqlQty, $db);
while($row2=DB_fetch_array($Qty_result))
{
	$itemcode=$s->getField('item_master','id',$row2['mst_itemid'],'StockID'); 
	$itemname=$s->getField('item_master','id',$row2['mst_itemid'],'item_name');
	$part_no=$s->getField('item_master','id',$row2['mst_itemid'],'part_no'); 
	$unitid=$s->getField('item_master','id',$row2['mst_itemid'],'mst_unitid');
	$unitname=$s->getField('unitsofmeasure','unitid',$unitid,'unitname'); 

	$sqlQty1 = "SELECT dispatchqty From log_dispatchqty Where dis_id='".$dis_id."' and mst_itemid='".$row2['mst_itemid']."'";
	$Qty_result1 = DB_query($sqlQty1, $db);
	$row3=DB_fetch_array($Qty_result1);
	if(DB_num_rows($Qty_result1)==0){$row3['disqty']=0;}
	
	$sqlQty11 = "SELECT SUM(transferqty) AS tfqty From log_srnqty Where dis_id='".$dis_id."' and mst_itemid='".$row2['mst_itemid']."'";
	$Qty_result11 = DB_query($sqlQty11, $db);
	$row11=DB_fetch_array($Qty_result11);
	if(DB_num_rows($Qty_result11)==0){$row11['tfqty']=0;}
	
	$sqlQtym = "SELECT transferqty From log_srnqty Where dis_id='".$dis_id."' and mst_itemid='".$row2['mst_itemid']."'";
	$Qty_resultm = DB_query($sqlQtym, $db);
	$rowm=DB_fetch_array($Qty_resultm);
	if(DB_num_rows($Qty_resultm)==0){$rowm['tfqty']=0;}
	
	
	$pendingqty=$row3['dispatchqty']+$rowm['transferqty']-$row11['tfqty'];

$data9.='<tr class="row1">';
$data9.='<td class="tabledata">'.$i.'</td>';
$data9.='<td class="tabledata"><input type="hidden" id="mstitemid_'.$i.'" name="mst_itemid[]" value="'.$row2['mst_itemid'].'"/></td>';
$data9.='<td class="tabledata"><input type="text" name="" id="itemcode_'.$i.'" value="'.$itemcode.'" readonly="true"/></td>';
$data9.='<td class="tabledata"><input type="text" name="item_name[]" id="itemname_'.$i.'" value="'.$itemname.'" readonly="true"/></td>';
$data9.='<td class="tabledata"><input type="text" name="part_no[]" id="part_no_'.$i.'" value="'.$part_no.'" readonly="true"/></td>';
$data9.='<td class="tabledata"><input type="text" name="uom[]" id="uom_'.$i.'" value="'.$unitname.'" readonly="true"/></td>';
//$data9.='<td class="tabledata"><input name="reciveqty[]" type="text" id="reciveqty_'.$i.'" value="'.$row3['dispatchqty'].'" readonly="true"/></td>';
//$data9.='<td class="tabledata"><input name="pendingqty[]" type="text" id="pendingqty_'.$i.'" value="'.$pendingqty.'" readonly="true"/></td>';
$data9.='<td class="tabledata"><input name="dispatchqty[]" type="text" id="dispatchqty_'.$i.'" value="'.$rowm['transferqty'].'" onkeyup="checkqty('.$i.',this.value)" readonly="true"/></td>';
$data9.='</tr>';
$i++; }
echo $data9.='<input type="hidden" name="" value="'.$i.'" id="edit_cnt" />';

		?>
		</tbody>
		</table>
		</td>
</tr>
</table>
	<br /><br />
			 <!--<div align="left">
				<input type="button" onClick="open_box()" value="Upload Boxes Manualy" class="search" id="upload_boxes" />
  			 </div>-->
			 <br /><br />
			 <div id="box_block"><!--style="display:none;"-->
			 <hr>
			 <h1 align="center" style="text-align:center;">Transfer Boxes</h1>
			 <br />
			<div style="height: auto" id="ItemListDiv">
			<table width="100%" border="1" cellpadding="3" cellspacing="0" style="border-collapse:collapse; border:#666666 solid 1px;">
			  <tr>
				<td class="tabledata1" colspan="3"><h3 style="color:#000000; font-size:16px;"><strong>Transfer Note Boxes Details</strong></h3></td>
				 <td class="tabledata1" colspan="2">&nbsp;</td>
			  </tr>
			  <tr>
				<td class="tabledata">S. No.</td>
				<td class="tabledata">Package No.</td>
				<td class="tabledata">No. of Packages</td>
				<td class="tabledata">Content</td>
				<td class="tabledata">Layout</td>
				<td class="tabledata">Item</td>
			  </tr>
			   <tbody id="dataTablerows">
			   <?php
			   	$j=0;
				$data10='';
$sqlQtybox = "SELECT * From log_addmrnbox Where dis_id='".$dis_id."'";
$Qty_resultbox = DB_query($sqlQtybox, $db);
while($row2box=DB_fetch_array($Qty_resultbox))
{
$k=$j+1;
$data10.='<tr>';

$data10.='<td class="tabledata">'.$k.'<input type="hidden" name="box_id['.$j.']" id="box_id_'.$j.'" value="'.$row2box['id'].'"/></td>';
$data10.='<td class="tabledata"><input type="text" name="package_no['.$j.']" id="package_no_'.$j.'" value="'.$row2box['package_no'].'" readonly="true"/></td>';
$data10.='<td class="tabledata"><input type="text" name="no_of_package['.$j.']" id="no_of_package_'.$j.'" value="'.$row2box['no_of_package'].'" readonly="true"/></td>';
$data10.='<td class="tabledata"><input type="text" name="content['.$j.']" id="content_'.$j.'" value="'.$row2box['content'].'" readonly="true" ></td>';
$data10.='<td class="tabledata">';
$data10.='<select name="layout['.$j.']" id="layout_'.$j.'" disabled="disabled">';
$data10.='<option value="0">Select</option>';
$sql1=DB_query("select * from log_floor where CompanyId='".$_SESSION['ACGCompanyId']."'",$db);
while($sql_floor=DB_fetch_array($sql1))
{
	if($sql_floor['id']==$row2box['layout']){
	$data10.='<option value="'.$sql_floor['id'].'" selected="selected">'.$sql_floor['floor_name'].'</option>';
	}else{
	$data10.='<option value="'.$sql_floor['id'].'">'.$sql_floor['floor_name'].'</option>';
	}
}
$data10.='</select>';
$data10.='</td><td class="tabledata">';
$data10.='<select name="itemid['.$j.']" id="itemid_'.$j.'" disabled="disabled">';
	$data10.='<option value="0">Select</option>';
	$sql2=DB_query("select * from item_master where CompanyId='".$_SESSION['ACGCompanyId']."'",$db);
	while($sql_floor2=DB_fetch_array($sql2))
	{
		if($sql_floor2['id']==$row2box['itemid']){
		$data10.='<option value="'.$sql_floor2['id'].'" selected="selected">'.$sql_floor2['item_name'].'</option>';
		}else{
		$data10.='<option value="'.$sql_floor2['id'].'">'.$sql_floor2['item_name'].'</option>';
		}
	}
	$data10.='</select>';
$data10.='</td></tr>';
$j++;}
echo $data10.='<input type="hidden" name="countrow" id="countrow" value="'.$j.'" />';

			   ?>
			   </tbody>
			</table>
			<br />
			</div>
			</div>
		</td></tr>
    </table>
		    </td></tr>
			 
		</table>
		
			
		
</form>
