<link rel="stylesheet" href="css/new_mxerp.css">
<link rel="stylesheet" href="/css/jquery.ui.all.css">
<script src="js1/jquery-1.7.2.js"></script>
<script src="js1/jquery.ui.widget.js"></script>
<script src="js1/jquery.ui.tabs.js"></script>
<script>
$(function() {
$( "#tabs" ).tabs();
});
</script>

<?php 
//********************INCLUDE ROOT FILES*************START HERE***********20-11-2012********AMIT**********************>
include('includes/Class_Client.php');
include("Class_Party.php");
include('functions.php');
//********************INCLUDE ROOT FILES*************END HERE***********20-11-2012********AMIT**********************>


//********************GET UNDER USER ID*************START HERE***********20-11-2012********AMIT**********************>
$modid=$_REQUEST['modid'];
$frmid=$_REQUEST['frmid'];
$rurl="&modid=".$modid."&frmid=".$frmid;
//echo $_REQUEST['Id'];
$date=date('Y-m-d');
$back_days=calculateBackDate($_SESSION['ACGRoleId']);
$back_date=date('Y-m-d', strtotime('-'.$back_days.' day', strtotime($date)));		 
$s=new db_query();
$user_id = $_SESSION['ACG_DashBoard_User'];
$deptid=  $s->GetFieldValue('www_users'," id='".$_SESSION['UserID']."' " ,'mst_dpt_heirarchy');		 
$userzone=explode(",",$_SESSION['AssignedSites']) ;
$LowerDeptList=GETLowerDeptUser($_SESSION['UserID'],$deptid,$_SESSION['ACGCompanyId']);
$lowerlist=  UserDeptList($LowerDeptList);
$lowerlist[]=$_SESSION['UserID'];
if(count($lowerlist)>0)
$lowerlist=implode(",",$lowerlist) ;
else
$lowerlist="'".$_SESSION['UserID']."'";
//echo $lowerlist;
$user_ids=$lowerlist;
//********************GET UNDER USER ID*************END HERE***********20-11-2012********AMIT**********************>



//********************DELETE DISPATCH*************START HERE***********20-11-2012********AMIT**********************>
if($_REQUEST['action']=='delete' and $_REQUEST['Id']!='')
{
	$updatesop=DB_query("update salesorder set status='pending' where id='".$_REQUEST['Id']."'",$db);
$updatesopdetails=DB_query("update salesorder_details set pendingFordispatch='1', pendingQty='NULL' where masterId='".$_REQUEST['Id']."'",$db);
	$condition="SOPNo='".$_REQUEST['Id']."'";
	$s->DeleteRecord('dispatch_details',  $condition);
	$condition1="againstSOP='".$_REQUEST['Id']."'";
	$s->DeleteRecord('dispatch',  $condition1);
	$s->pageLocation("index.php?route=CRM/dispatch_list".$rurl);
}
//********************GET UNDER USER ID*************END HERE***********20-11-2012********AMIT**********************>
?>

<?php if($_REQUEST['action']==''){?>
<div class="body_contain">
<div class="tab_div">
<h1>Dispatch List</h1>

 <!--<a href="index.php?route=CRM/Tel-DispatchNote<?php echo $rurl;?>"><input type="button" name="Create" value="Add Tel New" style="background-color:#d1d4be; color:#006699; font-weight:800; padding-top:3px; padding-bottom:3px;" /></a>-->
<div class="centre" id="slidingDiv">
<form action="" method="Post">
<table width="100%" cellpadding="3" cellspacing="0">
<tr class="row1">
<td class="tabledata1">Branch Wise</td>
<td>
<?php $site_sql=DB_query("Select loccode, locationname from locations where CompanyId='".$_SESSION['ACGCompanyId']."' and loccode in('".$_SESSION['AssignedBranch']."')",$db); ?>
<select name="branch_id" style="width:150px;">
<!--	<option value="0">Select Branch</option>-->
    <?php 	while($site_row=DB_fetch_array($site_sql))
		{?>
			<option value="<?php echo $site_row['loccode'];?>"<?php echo($_REQUEST['branch_id']==$site_row['loccode']?'selected':'')?>><?php echo $site_row['locationname'];?></option>
		<?php 	
		}
    	?></select></td>
    	<td class="tabledata1">Party Wise</td>
    	<td> <?php // echo $ClassParty-> PartList($_REQUEST['CompanyName']);?>
		<select name="party_id" id="party" style="width:150px;" >
		<option value="All">ALL</option>
	 <?php echo $ClassParty-> ClientList( $_SESSION['UserID'],$_REQUEST['party_id']);?>
 
		</select>
		
</td>
</tr>
<tr class="row1">
<td class="tabledata1">User List</td>
<td colspan="3">
<?php $Exec=DB_query("SELECT id,userid FROM www_users where id in(".$lowerlist.")  order by id  desc ",$db); ?>
	<select name="userlist" style="width:150px;">
	<option value="All">ALL</option>
<?php 	while($ExecRow=DB_fetch_array($Exec))
	{ ?><option value="<?php echo $ExecRow['id']; ?>" <?php echo $_REQUEST['userlist']==$ExecRow['id']?'selected':''; ?>><?php echo   (ucfirst($ExecRow['userid'])); ?></option>
<?php }?>
 </select>

</td>
</tr>
<tr class="row1">
 <td colspan="4"><p align="center"><input type="submit" name="Search" value="Search" class="search" /></p></td>	
</tr>
</table>	
</form>
</div>
<p align="left"><input type="button" name="Add Distach Advice" value="Add Distach Advice" class="search" onclick="showrec();" /></p>

<p align="right"><a href="dispatch_reg_exp.php"></a></p>
<table width="35%" border="0" align="left" cellpadding="2" cellspacing="0">
<tr>
	<td style="background-color:#FFFF33;width:13px; border:#FF0000 solid 1px;"></td>
	<td>Partially Dispatch</td>
	<td style="background-color:#c3fffb;width:13px;border:#FF0000 solid 1px;"></td>
	<td>Fully Dispatched</td>
	
</tr>
</table>
<br /><br />
<table width="100%" border="1" cellpadding="3" cellspacing="0" style="border-collapse:collapse; border:#a8a8a8 solid 1px;"
id="showdata">
<tr>
<td class="tabledata">Branch</td>
<td class="tabledata">Dispatch No.</td>
<!--<td class="tabledata">Advice No.</td>-->
<td class="tabledata">Dispatch Date</td>
<td class="tabledata">Against SOP</td>
<td class="tabledata">Party Name</td>
<td class="tabledata">Order Qty</td>
<td class="tabledata">Dispatch Qty</td>
<td class="tabledata">Pending Qty</td>
<td class="tabledata">Created BY</td>
<td class="tabledata">View</td>

<!--<td class="tabledata">Print</td>-->
<td class="tabledata">Delete</td>
</tr>
<?php 
if($_REQUEST['Search'])
{
	if($_REQUEST['branch_id']!='000')
	{
	$filter[]="site='".$_REQUEST['branch_id']."'";
	}
	if($_REQUEST['party_id']!='All') 
	{
	$filter[]="party='".$_REQUEST['party_id']."'";
	}
	if($_REQUEST['userlist']!='All') 
	{
	$filter[]="createdBy='".$_REQUEST['userlist']."'";
	}
	
	if($filter!='')
	{
	$filter1=implode(" and " ,$filter);
        if($_SESSION['dealerid'])
         {
          $query= "Select * from  dispatch where  $filter1 and reject=0 and CompanyId='".$_SESSION['ACGCompanyId']."' and dealerid='".trim($_SESSION['dealerid'])."' GROUP BY againstSOP order by againstSOP desc";	
         }
         else
         {
            $query= "Select * from  dispatch where  $filter1 and reject=0 and CompanyId='".$_SESSION['ACGCompanyId']."' and dealerid='0' GROUP BY againstSOP order by againstSOP desc";	 
         }
	}
	else
	{
            if($_SESSION['dealerid'])
         {
	$query="Select * from  dispatch where createdBy in(".$lowerlist.") and reject=0  and dealerid='".trim($_SESSION['dealerid'])."' and CompanyId='".$_SESSION['ACGCompanyId']."' GROUP BY againstSOP order by againstSOP desc";	
         }
 else {
     $query="Select * from  dispatch where createdBy in(".$lowerlist.") and reject=0  and dealerid='0' and CompanyId='".$_SESSION['ACGCompanyId']."' GROUP BY againstSOP order by againstSOP desc";	
 }
	}
}
else
{
	if($_SESSION['dealerid'])
         {
    $query="Select * from  dispatch where createdBy in(".$lowerlist.") and reject=0   and dealerid='".trim($_SESSION['dealerid'])."' and CompanyId='".$_SESSION['ACGCompanyId']."'  order by againstSOP desc";
         }
 else {
      $query="Select * from  dispatch where createdBy in(".$lowerlist.") and reject=0   and dealerid='0' and CompanyId='".$_SESSION['ACGCompanyId']."'  order by againstSOP desc";
     }
}
//echo $query;
$sql=DB_query($query, $db);	

$i=0;
$num=DB_num_rows($sql);
if($num>0)
{
while($myrow=DB_fetch_array($sql))
{
$Ord_Qty=$s->GetFieldValue('salesorder_details',"masterId='".$myrow['againstSOP']."'",'SUM(Quantity)');
$Total_DisQty=$s->GetFieldValue('dispatch_details',"SOPNo='".$myrow['againstSOP']."'",'SUM(dispatchQty)');
$col=$Ord_Qty-$Total_DisQty;
if($col=='0')
{
$bgcolor='#c3fffb';
}
else
{
$bgcolor='#FFFF33';
}
?>
<tr bgcolor="<?php echo $bgcolor; ?>">
<td><?php echo $myrow['site'];?></td>
<td><?php echo $myrow['adviceNo'];?></td>
<td><?php echo ConvertSQLDate($myrow['dispatchDate']);?></td>
<td><?php 
 echo $s->GetFieldValue('salesorder',"id='".$myrow['againstSOP']."'",'orderNo');
//echo $myrow['SOPNo'];?></td>
<td><?php  //echo $myrow['party'];
if($myrow['dispatchmodetype']=='Direct')
echo   $s->GetFieldValue('clientmaster',"id='".$myrow['party']."'",'c_name');
else{
//echo $myrow['party'];
$vender_client= $s->GetFieldValue('accountledger',"vender_client='".$myrow['party']."' and ledgertype='client'",'vender_client');
 echo   $s->GetFieldValue('clientmaster',"id='".$myrow['party']."'",'c_name');
}
//$myrow['party'];
?></td>
<td><?php echo $Ord_Qty;?></td>
<td><?php echo $Total_DisQty;?></td>
<td><?php echo $Ord_Qty-$Total_DisQty;?></td>
<td><?php echo $s->GetFieldValue('www_users',"id='".$myrow['createdBy'] ."'",'realname') ;?></td>

<td><div align="center">
<?php if($_SESSION['frmView']==0){ ?>
<img src="images/search.gif" width="10px" alt="Not Allowed" title="Not Allowed"  height="10" />
<?php }else{ ?>
<a href="index.php?route=CRM/dispatch_list&amp;modid=<?php echo $_REQUEST['modid'];?>&amp;frmid=<?php echo $_REQUEST['frmid'];?>&amp;action=view&amp;Id=<?php echo $myrow['id'];?>"><img src="images/search.gif" width="10px"  height="10" /></a>
<?php } ?>
</div></td>




<!--<td><div align="center"><a href="#" onclick="popup('Tel-Dispatch-print.php?Id=<?php echo $myrow['againstSOP'];?>',1200,600)"><img src="images/print.png" width="20px"  height="20" /></a></div></td>-->



<td><div align="center"><?php if($myrow['dispatchDate'] >= $back_date){?>
<?php if($_SESSION['frmDelete']==0){ ?>
<img src="images/delete.gif" width="10px" alt="Not Allowed" title="Not Allowed"  height="10" />
<?php }else { ?>
<a href="index.php?route=CRM/dispatch_list&amp;modid=<?php echo $_REQUEST['modid'];?>&amp;frmid=<?php echo $_REQUEST['frmid'];?>&amp;action=delete&amp;Id=<?php echo $myrow['againstSOP'];?>" onclick="return confirm('Are you sure you want to delete?')"><img src="images/delete.gif" width="10px"  height="10" /></a>
<?php } ?>

<?php }else { ?><img src="images/delete.gif" width="10px"  height="10" /><?php } ?></div></td>
</tr>
<?php $i++;}}
else { ?>
<tr bgcolor="#FFFFFF">
<td colspan="12" style="color:#FF0000;">No Record Found </td>
</tr> <?php  }   ?>
</table>
<!--   ********************   Showing  Records Of Approved Orders  ********************   -->
<div id="showdata1" style="display:none;">
<table width="100%" border="1" cellpadding="3" cellspacing="0" >
<tr>
<td class="tabledata">SR No</td>
<!--<td class="tabledata">Advice No.</td>-->
<td class="tabledata"><strong>Date</strong></td>
	<td class="tabledata"><strong>SOP NO</strong></td>
	<td class="tabledata"><strong>Client Name</strong></td>
	<td class="tabledata"><strong>Client PO No</strong></td>
	<td class="tabledata"><strong>PO Date</strong></td>
	<td class="tabledata"><strong>Order Type</strong></td>
	<!--<td class="tabledata">Approved Qty.</td>-->
	<!--<td class="tabledata">Total Order Amt.</td>-->
	<td class="tabledata"><strong>category</strong></td>
	<td class="tabledata"><strong>Status</strong></td>
	<td class="tabledata"><strong>Delivery Date</strong></td>
	<td class="tabledata"><strong>Created By</strong></td>	
	<td class="tabledata"><strong>Modify By</strong></td>
	<td class="tabledata"><strong>Action</strong></td>
	
</tr>
<?php 
$s=new db_query();
//GET Heirarchy from users wise
$deptid=  $s->GetFieldValue('www_users'," id='".$_SESSION['UserID']."'",'mst_dpt_heirarchy');
$r=GETUpperDeptUser($_SESSION['UserID'],$deptid,$_SESSION['ACGCompanyId']);
$userlist=  UserDeptList($r);
  if(count($userlist)>0)
$userlist=implode(",",$userlist).",".$_SESSION['UserID'];
else
$userlist="'".$_SESSION['UserID']."'";

$LowerDeptList=GETLowerDeptUser($_SESSION['UserID'],$deptid,$_SESSION['ACGCompanyId']);
 $lowerlist=  UserDeptList($LowerDeptList);
   if(count($lowerlist)>0)
$lowerlist=implode(",",$lowerlist).",".$_SESSION['UserID'];
else
$lowerlist="'".$_SESSION['UserID']."'"; 
    
$user_id = $_SESSION['ACG_DashBoard_User'];



	$i=1;
	
	$x1= $s->GetFieldValue('www_users'," id='".$_SESSION['UserID'] ."'",'assigned_sites');
	$x2= GETFinalUserList($x1);
	$l=implode(",",$x2);
	if($l!='')
	{	
	$GetSales ="SELECT salesorder.*,salesorder_details.ApprovalStatus as ap
	        FROM salesorder inner join salesorder_details on salesorder.id=salesorder_details.masterId
	   	 WHERE CompanyID='".$_SESSION['ACGCompanyId']."' 	 AND  (createdBy IN(".$l.") 
		 or createdBy in('".$_SESSION['UserID']."'))   and salesorder_details.ApprovalStatus!=1     group BY salesorder.id  ASC ";
	}
	else{
	$GetSales="SELECT salesorder.*,salesorder_details.ApprovalStatus as ap
	 FROM salesorder inner join salesorder_details on salesorder.id=salesorder_details.masterId
	 WHERE createdBy in('".$_SESSION['UserID']."') and salesorder_details.ApprovalStatus!=1   group BY salesorder.id  ASC";
	}	
		$getlead=DB_query($GetSales,$db);
	
  
//echo $GetSales;
//echo "<br>==================<br>";
$x1= $s->GetFieldValue('www_users',"id='".$_SESSION['UserID'] ."'",'assigned_sites');
// echo "<br>==================<br>";
$_SESSION['Sales']=$GetSales;
$lop=0;
 	if(DB_num_rows($getlead)>0)
	{
		 while($row_quotes=DB_fetch_array($getlead))
	 	 {
	    	$d=explode(',',$x1);
	  		// $row_quotes['client'];
			if($row_quotes['SalesOrderType']=='Tel')
			{
 	    		$ClientName=$s->getField('clientmaster','id',$row_quotes['client'],'c_name');
			} 
			else
			{
		  	    //$ClientName=$Class_Client->GetClientByLedger($row_quotes['client']);
				$ClientName=$s->getField('clientmaster','id',$row_quotes['client'],'c_name');
 	 		}
			  
			  
	  
	$flag=0; $flag1=0;
	
	$dsql=DB_query("select * from salesorder_details where masterId='".$row_quotes['id']."'",$db);
	$num5=DB_num_rows($dsql);
		while($rowsql=DB_fetch_array($dsql))
		{
			if($rowsql['ApprovalStatus']=='3')	
			{
				$flag=$flag+1;	
				$flag1=1;
    		}
			elseif($rowsql['ApprovalStatus']=='2')	
			{
				$flag1=1;	
			}
		}
	
	if($flag==$num5)
	{
	$status_salesorder='Approved';	
	}
	else if($flag1==1)
	{
	$status_salesorder='Partially Approved';	
	}
	else
	{
	$status_salesorder='Pending';		
	}
    
	 ?>
	 <?php 
	 //echo $status_salesorder."<br/>";
	 if($status_salesorder=='Approved') { 
	 $bgcolor="#c3fffb";  
	  } 
	  if($status_salesorder=='Partially Approved') { 
	 $bgcolor="#CC33CC";  
	  } 
	  if($status_salesorder=='Pending') { 
	 $bgcolor="#B2B2B2";  
	  } 
	  
	  
	  ?>
    <tr bgcolor="<?php //echo $bgcolor; ?>" style="border:1px thin;">
    <td style="white-space:nowrap;" valign="top"><?php echo $i; ?></td>
  <td valign="top" ><p><?php  echo ConvertSQLDate($row_quotes['orderDate']); ?></p></td>
  <td valign="top" style="white-space:nowrap"><?php  echo $row_quotes['orderNo']; ?></td>
  <td valign="top" style="white-space:nowrap"><?php echo $ClientName; ?></td>
	<td valign="top"><?php  echo $row_quotes['PORefNo']?></td>
	<td valign="top"><?php  echo ConvertSQLDate($row_quotes['customerPODate']);?></td>
	<td valign="top"><?php echo $row_quotes['SalesOrderType']; ?></td>
	<td valign="top"><?php echo $row_quotes['cate'] ;?></td>
	
<td  valign="top"><?php if($status_salesorder=='Approved'){  echo $status_salesorder;  } else { echo $status_salesorder;  }?></td>
	
	<td valign="top"><?php echo $row_quotes['DeliveryDate']; ?></td>
	<td valign="top"><?php  echo $s->GetFieldValue('www_users',"id='".$row_quotes['createdBy']."'",'realname'); ?></td>
	<td valign="top"><?php echo $s->GetFieldValue('www_users',"id='".$row_quotes['modifyBy']."'",'realname'); ?></td>
	
	<td valign="top" ><?php 	if($_SESSION['frmEdit']!=0)	{ ?><a href="index.php?route=CRM/ConvertSaleOrder_Into_Dispatch&SID=<?php  echo $row_quotes['id'].$rurl;?>">
<input type="button" name="Create" value="Convert into Dispatch " class="search" />
</a><?php  }else{echo "Approval Pending";}?> 
   </tr>   
   <?php  
  // }
   
   
   $lop++;    } }
   else
   {?>
   	<tr>
   		<td colspan="14"><font color="#FF0000"><?php echo "No Records Found"; ?></font></td>
	</tr>
  <?php }?>
</table>

</div>




<?php }



if($_REQUEST['Id']!='' && $_REQUEST['action']=='view'){?>
<div class="body_contain">
<h1>View Dispatch Slip</h1>
<div class="insideclass">

<div style="z-index:-1000em;">
<div class="demo">
<div id="tabs">
	
<div id="tabs-1">
<div class="tab_div">

<?php 

if($_REQUEST['Id']!=''){
$disSql=DB_query("select * from dispatch where id='".$_REQUEST['Id']."'",$db);
$disRow=DB_fetch_array($disSql);
extract($disRow);
?>
<table width="100%" border="1" cellspacing="1" cellpadding="0" align="center">
	<tr class="row1">
	<td class="tabledata1">Branch</th>
	<td ><?php echo $s->GetFieldValue('locations',"loccode='".$site."'",'locationname');;
	$site_sql=DB_query("Select loccode, locationname from locations where loccode='".$result1['site']."'",$db);?></td>
	<td ><span class="tabledata1">Advice No. </span></td>
	<td ><?php  echo $adviceNo;?></td>
	<td class="tabledata1">Dispatch Date
	<td nowrap="nowrap" id="adviceId"><?php echo ConvertSQLDate($dispatchDate);  ?></td>
	</tr>
	<tr class="row1">
	<td class="tabledata1">Party </th>
	<td><?php   echo $cname= $s->GetFieldValue('clientmaster',"id='".$party."'",'c_name');?></td>
	<td><span class="tabledata1">City<span style="color:#FF0000">*</span></span></td>
	<td><span class="tabledata1">
	  <?php 
	$cityID=$s->GetFieldValue('clientmaster',"id='".$party."'",'pre_city');
	echo $city=$s->GetFieldValue('city_master',"id='".$cityID."'",'city'); 	?>
	</span></td>
	<td class="tabledata1">State<span style="color:#FF0000">*</span>
	<td><span class="tabledata1">
	<?php 
	$stateID=$s->GetFieldValue('clientmaster',"id='".$party."'",'pre_state');
	echo $city=$s->GetFieldValue('state_master',"id='".$stateID."'",'state'); 	?>
	</span></td>
	</tr>
	<tr class="row1">
	<td class="tabledata1">Address<span style="color:#FF0000">*</span></td>
	<td class="tabledata1"><?php echo $s->GetFieldValue('clientmaster',"id='".$party."'",'pre_address1'); 	?>	</td>
	<td class="tabledata1">Country<span style="color:#FF0000">*</span> </td>
	<td class="tabledata1"><?php 
	$country=$s->GetFieldValue('clientmaster',"id='".$party."'",'pre_country');
	echo $city=$s->GetFieldValue('country_master',"id='".$country."'",'country'); 	?></td>
	<td class="tabledata1">Destination </td>
	<td  class="tabledata1"><?php echo $desitination;?></td>
	</tr> 
	<tr class="row1">
	<td class="tabledata1">Form No</td>
	<td class="tabledata1"><?php echo $form_no ?></td>
	<td class="tabledata1">Dispatch Mode </td>
	<td class="tabledata1"><?php echo $s->GetFieldValue('transport_master',"id='".$dispatch_mode."'",'TransportName');?></td>
	<td class="tabledata1">Payment Terms </td>
	<td  class="tabledata1"><?php echo $s->GetFieldValue('paymentterms',"termsindicator='".$payment_term."'",'terms') ;?></td>
	</tr> 	
	<tr class="row1">
	  <td class="tabledata1">Order Type
	  <td ><?php if($order_type=='mrp_item'){ ?>
MRP Item Wise
  <?php } else { echo $order_type; }?></td>
	  <td ><span class="tabledata1">Freight Type</span></td>
	  <td ><span class="tabledata1">
	    <?php if($freight=='Paid'){echo "Paid";}
			  if($freight=='topay'){echo "topay";}
			  if($freight=='Nill'){echo "Nill";}?>
	  </span></td>
	  <td class="tabledata1">
	  <td >&nbsp;</td>		
	</tr>
	  

	
	</tr>
	<tr class="row1">
	<td colspan="6"><div id="SOPId">
	<table width="100%" cellpadding="0" cellspacing="0">
	<tr class="row1">
	<!--<td nowrap="nowrap" scope="row" >Against Single/Multiple S. O. P.</th>
	<?php
	$finalArray=explode(',',$result1['againstSOP']);
	?>
	<td width="29%" nowrap="nowrap">
	<input type="text" name="againstSOP1" value="<?php echo $result1['againstSOP']; ?>"/>
	</td>-->
	</tr>
	</table></div>	</td>
	</tr>
	<tr class="row1">
	<td colspan="7"><div id="SOPId">
	<table width="100%" cellpadding="1" cellspacing="1">
	<tr>
	<td class="tabledata1">Against Single/Multiple S.O.P.</th>
	<td><?php echo $s->GetFieldValue('salesorder',"id='".$againstSOP."'",'orderNo') ?></td>
	</tr>
	</table></div>	</td>
	</tr>
</table>

<table width="100%" border="1" cellpadding="3" cellspacing="0">
<tr class="row1">
			<td class="tabledata">Item Code</td>
			<td class="tabledata">Item Name</td>
			<td class="tabledata">Order Qty</td>
			<td class="tabledata">Approve Qty</td>
			<td class="tabledata">Dispatch Qty</td>
			
  </tr>
<?php 

$details_sql=DB_query("Select * from dispatch_details where parentId='".$id."'" ,$db);
$j=0; 
while($details_row=DB_fetch_array($details_sql))
{

$details_sql1=DB_query("Select * from salesorder_details where masterId ='".$details_row['SOPNo']."'",$db);
$detail_row1=DB_fetch_array($details_sql1);					
?>
  <tr class="row1">
		<td class="tabledata"><?php echo $s->getField('item_master','id',$details_row['item'],'StockID');?></td>
		<td class="tabledata" style="white-space:nowrap;">
		<?php 	echo $itemname=$s->getField('item_master','id',$details_row['item'],'item_name'); ?></td>	 
		<td class="tabledata"><?php echo $details_row['OrderQty'];  ?></td>
		<td class="tabledata"><?php  echo $details_row['ApprorderQty'] ; ?></td>
		<td class="tabledata"><?php  echo $details_row['dispatchQty'] ; ?></td>
		
  </tr>
		<?php $j++;} ?>
		<input type="hidden" name="count" value="<?php echo $j;?>"/>
		</tr>
</table>

<table width="100%" cellpadding="3" cellspacing="0" border="0">
	<tr class="row1">
		<td class="tabledata1">Remarks</th>
		<td class="tabledata1"  style="width:150px;"><?php echo $remarks; ?></td>
	</tr>
</table>
</div>
<p align="center"><a href="#" onclick="popup('Tel-Dispatch-print.php?Id=<?php echo $_REQUEST['Id'];?>',1200,600)">Print</a></p>
<?php } ?>
<div style="clear:both;"></div>
		</div>
	</div><!-- Tab 1 Close -->
	<!-- Tab 2 Close -->
</div>
</div></div>
</div><!-- inside div close -->
</div><!-- Main div close -->


<?php  }   ?>


<!---------------------VIEW PART OF DISPATCH-------------------END HERE------------20-11-2012-------------AMIT---------->

</div>
</div>
<script language="JavaScript" type="text/javascript">
function getOrders(str)
{
	var branch=document.getElementById("site").value;
	if (str.length==0)
	{
	document.getElementById("SOPId").innerHTML="";
	return;
	}
	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("SOPId").innerHTML=xmlhttp.responseText;
	}
	}
	xmlhttp.open("GET","showSalesOrders.php?client="+str+"&branch="+branch,true);
	xmlhttp.send();
}

function alldata(str)
{
	if(str.length==0)
	{
	document.getElementById("VIEWEDDATA").innerHTML="";
	return;
	}
	if(window.XMLHttpRequest)
	{
	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("VIEWEDDATA").innerHTML=xmlhttp.responseText;
	}
	}
	xmlhttp.open("GET","GetAllData.php?AdvoiceNo="+str,true);
	xmlhttp.send();
}

function getDispatch(str)
{
	if (str.length==0)
	{
	document.getElementById("adviceId").innerHTML="";
	return;
	}
	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("adviceId").innerHTML=xmlhttp.responseText;
	}
	}
	xmlhttp.open("GET","codeGenerator.php?dispatchSite="+str,true);
	xmlhttp.send();
}


function showrec()
{
document.getElementById("showdata1").style.display='block';
document.getElementById("showdata").style.display='none';


}



</script>


