<?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');
?>
<script type="text/javascript" src="js/function-ajax.js" language="javascript"></script>
<?php 
//**************************Modify Section*******************************************************
if(isset($_REQUEST['mrnid']))
{
	    $condition="id='".$_REQUEST['mrnid']."'";
		$GetData=$s->GetRecord('log_dispatch', $condition);
		$GetResultData= DB_query($GetData,$db);
		$GetRowData=DB_fetch_array($GetResultData);
				
		$dis_no=$GetRowData['dis_no'];
		$dis_date=$GetRowData['dis_date'];
		$site=$GetRowData['site'];
		$store=$GetRowData['store'];
		$type=$GetRowData['type'];
	    $party_id=$GetRowData['party_id'];
		$to_site=$GetRowData['to_site'];
		$address=$GetRowData['address'];
		$contact_per=$GetRowData['contact_per'];
		$contact_no=$GetRowData['contact_no'];
		$mrn_no=$GetRowData['mrn_no'];
		$mrn_date=$GetRowData['mrn_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'];
}
?>
<style type="text/css">
.body_lightbox {
width:100%;
background-color:#e7e7e7;
position:fixed;
left:280px;
top:200px;
padding-left:5px;
padding-right:5px;
border:#666666 solid 3px;
}
</style>
<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 Dispatch 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="sitecode" 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 ($site==$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 ='".$site."'";
	$site_res=DB_query($site_sql,$db);
	$site_row=DB_fetch_array($site_res);
	if(isset($site))
	{
	?>
	    <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="storecode" name="storecode"  style="width:100%" disabled="disabled">
		<option value="0">Select</option> 
		<?php 
		while ($myrow=DB_fetch_array($resultStkLocs))
		{
				$p='';
				if($store==$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">Dis No.</td>
    <td><input type="text" value="<?php echo $dis_no;?>" style="width:150px;" readonly="true"/></td>
</tr>
<tr class="row1">
	<td  class="tabledata1">DIS Date </td>
    <td><input type="text" value="<?php echo ConvertSQLDate($dis_date);?>" style="width:150px;" name="dis_date" readonly="true" ></td>
  	<td class="tabledata1">Type</td>
    <td><select name="type" id="type"  style="width:150px;" disabled="disabled">
		<option value="0" <?php if($type=="0"){echo "selected";}?> >---Select---</option>
		<option value="G" <?php if($type=="0"){echo "selected";}?> >---Against GRN---</option>
		</select></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_id==$party_row['id']){echo "selected";}?>><?php echo $party_row['c_name'];?></option>	
	  <?php 	
	  }
      ?>
    </select></td>
</tr>
<tr class="row1">
	<td class="tabledata1">Site To</td>
    <td ><select name="site_to" id="site_to"  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($to_site==$party_row['id']){echo "selected";}?>><?php echo  $myrow['StoreName']; ?></option>
		<?php }
			?>
		</select>
	</td>
	<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>
</tr>
<tr class="row1">
	<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>
    <td  class="tabledata1">MRN No.</td>
    <td><input type="text" style="width:150px;" name="mrn_no" id="mrn_no" value="<?php echo $mrn_no;?>" readonly="true"></td>
    <td class="tabledata1">MRN Date</td>
    <td><input name="mrn_date" type="text" id="mrn_date" style="width:150px;" value="<?php echo ConvertSQLDate($mrn_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">LR 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">LR Date</td>
    <td><input type="text" name="lr_date" id="lr_date"  style="width:150px;" value="<?php echo ConvertSQLDate($lr_date);?>" readonly="true" /></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  colspan="6">   
		<hr>
			 <h1 align="center" style="text-align:center;">Dispatch Products</h1>
			<br />
		<div style="overflow:auto; width:950px; margin-left:auto; margin-right:auto; height:auto">
    <div id="itemdata">
      <table width="100%" border="1" cellpadding="3" cellspacing="0">
	  	<tr>
          <th><strong>S. No.</strong></th>
          <th></th>
          <th><strong>Item Code</strong></th>
          <th><strong>Item Name</strong></th>
          <th><strong>UOM</strong></th>
          <th><strong>Total Avl Qty</strong></th>
		   <th><strong>Dispatch Qty</strong></th>
		    <th><strong>Balance Qty</strong></th>
			<th><strong>GRN No</strong></th>
        </tr>
		<?php 
		$i=0;
		$iiicc='';
		$icc='';
		$sql_edit=DB_query("Select * from log_dispatchqty where dis_id='".$_REQUEST['mrnid']."'",$db);
		while($record_edit=DB_fetch_array($sql_edit))
		{
		
		if($i%2==0)
		{$bg="#CCCCCC";}
		else
		$bg="#C8BECB";
			?>
		<tr>	
		<td>
			<?php echo $i+1;?>
		</td>
		<td>
			<input  type="hidden"   readonly=""  id="itemdataid1_<?php echo $i; ?>"  name="itemdataid[]"  value="<?php echo $record_edit['mst_itemid']; ?>" />
		</td>
		<td>
			<?php echo $s->getField('item_master','id',$record_edit['mst_itemid'],'StockID'); ?>
		</td>
		<td>
			<?php echo $s->getField('item_master','id',$record_edit['mst_itemid'],'item_name'); ?>
		</td>
		<td>
			<?php $unit= $s->getField('item_master','id',$record_edit['mst_itemid'],'mst_unitid'); ?>
			<?php echo $s->getField('unitsofmeasure','unitid',$unit,'unitname');  ?>       	 
		</td>
		<?php
			$avl_sql = "SELECT SUM(reciveqty) AS rqty FROM log_addmrnqty where mst_itemid='".$record_edit['mst_itemid']."' AND grn_id IN (select id from log_add_mrn where store='".$store."')";
        	$Resulta=DB_query($avl_sql,$db);
	    	$myrowa =DB_fetch_array($Resulta);
			if($myrowa['rqty']==''){$myrowa['rqty']=0;}
		
			$avl_sqlb = "SELECT SUM(dispatchqty) AS dqty FROM log_dispatchqty where mst_itemid='".$record_edit['mst_itemid']."' AND dis_id IN (select id from log_dispatch where store='".$store."')";
        	$Resultb=DB_query($avl_sqlb,$db);
	    	$myrowb =DB_fetch_array($Resultb);
			if($myrowb['dqty']==''){$myrowb['dqty']=0;}
		?>
		<td>
			<input  type="text" name="avaqty[]"  id="avaqty1_<?php echo $i; ?>" size="30"   value="<?php echo $myrowa['rqty']+$record_edit['dispatchqty']-$myrowb['dqty'];?>" readonly="true"  /></td>
		<td>
			<input  type="text" name="disqty[]"  id="disqty1_<?php echo $i; ?>" size="30"  value="<?php echo $record_edit['dispatchqty'];?>" readonly="true"  />
		</td>
		<td>
			<input  type="text" name="penqty[]"  id="penqty1_<?php echo $i; ?>" size="30"   value="<?php echo $myrowa['rqty']-$myrowb['dqty']?>"  readonly="true"  />
		</td>
		<td id="grn1_<?php echo $i;?>">
			<table width="100%" border="1" cellspacing="0" cellpadding="3" style="border-collapse:collapse;">
				<tr>
					<th>GRN Id</th>
					<th>Dis Qty</th>
				</tr> 
				<?php  
				$dm1=0; 
				$avl_sqlb = "SELECT * FROM log_dispatchgrnqty where mst_itemid='".$record_edit['mst_itemid']."' AND dis_id='".$_REQUEST['mrnid']."'";
				$Resultb=DB_query($avl_sqlb,$db);
				while($myrowb =DB_fetch_array($Resultb)){
				?> 
				<tr bgcolor="#FFFFFF">
					<td><input type="text" id="ddgrn_<?php echo $i.$dm1;?>" name="ddgrn_<?php echo $i;?>[]" value="<?php echo $myrowb['grn_id'];?>" readonly="true" />
					<?php $icc.=$myrowb['grn_id'].",".$record_edit['mst_itemid'].":";?>
					</td>
					<td ><input type="text" id="dddqty_<?php echo $i.$dm1;?>" name="dddqty_<?php echo $i;?>[]" value="<?php echo $myrowb['dispatchqty'];?>" readonly="true" /></td>
				</tr>
				<?php  $dm1++;} ?>	
				<tr><td colspan="3"><input type="hidden" id="rowcal1_<?php echo $i;?>" name="rowcal1_<?php echo $i;?>" value="<?php echo $dm1;?>" /></td></tr>
			</table>
		</td>
		</tr>
		<?php $iiicc.=$s->getField('item_master','id',$record_edit['mst_itemid'],'StockID').",";?>
		<?php $i++; } ?>
		<input id="iiicode" value="<?php echo $iiicc;?>" type="text" />
		<input name="cherow" id="cherow" value="<?php echo $i;?>" type="hidden" />
		<input name="cherow1" id="cherow1" value="<?php echo $icc;?>" type="hidden" />
      </table>
    </div>
  </div>
  <div class="body_lightbox" id="lightbox" style="overflow:auto; width:600px; height:250px; display:none;"></div>
  <input type="hidden" name="hiditemcount" id="hiditemcount" value="" />
  <input type="hidden" name="" value="" id="edit_cnt" />
	</td>
</tr>
</table>
<div align="right">	 		
	<table width="100%">
		<tr>
			<td>
			 
			 <br /><br />
			 <div id="box_block"><!--style="display:none;"-->
			 <hr>
			 <h1 align="center" style="text-align:center;">Dispatch Boxes</h1>
			<br />
			<div align="left">
				<input type="button" onClick="open_box(<?php echo $_REQUEST['mrnid'];?>)" value="Get Boxes" class="search" id="upload_boxes" />
  			 </div>
			<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>Dispatch 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"></tbody>
			</table>
			<br />
			</div>
			</div>
		</td></tr>
    </table>
		    </td></tr>
		</table>
</form>
<script language="javascript" type="text/javascript">
function open_box(str1)
{
	var sitecode=document.getElementById("sitecode").value;
    var storecode=document.getElementById("storecode").value;
	if(document.getElementById("iiicode").value=='')
	{
		alert("No item details found.");
		return false;
	}
	
	
		myval=document.getElementById("cherow1").value;

	var xmlhttp;
	if (window.XMLHttpRequest)
	  {// code for IE7+, Firefox, Chrome, Opera, Safari
	  xmlhttp=new XMLHttpRequest();
	  }
	else
	  {// code for IE6, IE5
	  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	  }
	xmlhttp.onreadystatechange=function()
	  {
	  if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
		document.getElementById("dataTablerows").innerHTML=xmlhttp.responseText;
		}
	  }
	  
	  xmlhttp.open("GET","get_boxdetails2.php?myval="+myval+"&site="+sitecode+"&store="+storecode+"&str1="+str1,true);
	  xmlhttp.send();	
}	
</script>