
<link rel="stylesheet" href="css/new_mxerp.css">

<!----------------Work Hold By Madhav Sir On Date-------17-10-2012------------Only One Searching Is Working--------->





<script language="javascript" type="text/javascript">
function get_itemsubgroup(str)
{
	if(str=="")
  {
  document.getElementById("sub_id").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("sub_id").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","item_subcategory.php?main="+str,true);
xmlhttp.send();
}



function showItems(str)
{
	if(str=="")
  {
  document.getElementById("itemid").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("itemid").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","Get_itemcode.php?partName="+str,true);
xmlhttp.send();
}



</script>

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



<h1>Dispatch Advice  Register</h1>
<form action="" method="post">

<table width="100%" border="1" cellpadding="3" cellspacing="0" style="border-collapse:collapse; border:#666666 solid 1px;">
		<tr>
		 	<td class="tabledata" style="width:146px;">Branch</td>
			<td style="width:230px;">
				<?php 
	$site_sql=DB_query("Select loccode,locationname from locations where CompanyId='".$_SESSION['ACGCompanyId']."' and loccode in ('".$_SESSION['AssignedBranch']."')",$db);?>
	<select name="site" id="site" style="width:100%" >
<!--	<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['site']==$site_row['loccode']?'selected':'')?>><?php echo   $site_row['locationname']?></option>
	<?php 	
	}
	?>
	</select>
			</td>
			<td class="tabledata" style="width:146px;">Party</td>
			<td>
				<select style="width:100%;"  name="party" id="party"   >
		<option value="0">Select Party</option>
		<?php
		  $ClientSQL="Select * from clientmaster where CompanyId='".$_SESSION['ACGCompanyId']."'";
		$ClientRes=DB_query($ClientSQL,$db);
		while($ClientRow=DB_fetch_array($ClientRes))
		{
 		?>
		<option value="<?php echo $ClientRow['id']?>" <?php echo ($_REQUEST['party']==$ClientRow['id']?'selected':'');?>><?php echo $ClientRow['c_name']?></option>
		<?php  } ?>
 	</select>
			</td>
		</tr>
		<tr>
			<td class="tabledata">From</td>
			<td><input type="text" name="from_date" value="<? echo $_REQUEST['from_date']; ?>" style=" width:100%;" class="datepicker"/></td>
			<td class="tabledata">To</td>
			<td><input type="text" name="to_date" value="<? echo $_REQUEST['to_date']; ?>" style=" width:100%;" class="datepicker"/></td>
		</tr>
		
		
		<!--<tr>
			<td class="tabledata">Dispatch AD No.</td>
			<td>
				<select name="dispatchNo" style=" width:100%;height: 20px">
				<option value="">All</option>	
				<?php 
					$dispatchSql=DB_query("Select id,adviceNo from dispatch",$db);
					while($dipatchRow=DB_fetch_array($dispatchSql))
					{?>
						<option value="<?php echo $dipatchRow['id']?>"<?php echo ($_REQUEST['dispatchNo']==$dipatchRow['id']?'selected':'')?>><?php echo $dipatchRow['adviceNo']?></option>
					<?php 	
					}
					?>
				</select>
			</td>
		</tr>-->
		
	</table>
	
	<!--<table width="70%" border="0" cellspacing="1" cellpadding="2" align="center">
  
  
  <tr>
    <td class="tabledata">Items</td>
    <td><div id="itemid">
	<div style="overflow:auto; height:150px; width:450px; border:1px solid; " >
	<?php 
	$item_sql=DB_query("select StockID,item_name from item_master where CategoryID='FG'",$db);
	$c3=0;
	while($row3=DB_fetch_array($item_sql))
	{ 
		$c='';
		if($_REQUEST['item'][$c3]==$row3['StockID'])
		{$c="checked";}
	?>
	<input type="checkbox" name="item[<?php echo $c3;?>]" id="item_<?php echo $c3;?>" value="<?php echo $row3['StockID'];?>" <?php echo $c;?>/><?php echo $row3['StockID']." - ".$row3['item_name'];?><br />
	<?php 	
	$c3++;
	}
	?>
	</div>
		
	</div></td>
  </tr>
</table>-->
	


	<p align="center"><input type="submit" name="View" value="View" /><input type="submit" name="Cancel" value="Cancel" /></p>
</form>
<!---------------------SEARCHING----------------START HERE---------------BY AMIT SINGH--------------------------------------->

<?php 
if($_REQUEST['View']!=''){
	if($_REQUEST['site'] != '')
	{
  	$filter[]="dispatch.site='".$_REQUEST['site']."' ";
	}
	if($_REQUEST['party']!='0')
	{
	$filter[]="dispatch.party='".$_REQUEST['party']."'";
	}
	if($_REQUEST['from_date'] != '' && $_REQUEST['to_date'] != '')
	{
 	$filter[]="dispatch.dispatchDate between '".FormatDateForSQL($_REQUEST['from_date'])."' and '".FormatDateForSQL($_REQUEST['to_date'])."'";
	}
	if($filter!='')
	{
		$filter1 = implode(" and ",$filter);
	
	}
	//echo "SELECT * FROM dispatch INNER JOIN dispatch_details ON(dispatch.id=dispatch_details.parentId) where $filter1";
     $sql1 =DB_query("SELECT * FROM dispatch INNER JOIN dispatch_details ON(dispatch.id=dispatch_details.parentId) where $filter1",$db); 
	
	?>
	
<!---------------------SEARCHING----------------END HERE---------------BY AMIT SINGH--------------------------------------->

	
<table width="100%" border="0" cellspacing="0" cellpadding="0">

  <tr>
    <td><table width="100%" border="0" cellspacing="1" cellpadding="0" style="border:1px solid #ccc; background-color:#FFF">
    
    	    <tr>
    	      <td><table width="100%" border="1" cellpadding="3" cellspacing="0" style="border-collapse:collapse; border:#666666 solid 1px;">
    	        <tr>
    	          <td class="tabledata">Sr. No.</td>
    	          <td class="tabledata">Dispatch Slip No.</td>
				  <td class="tabledata">SOP No.</td>
				  <td class="tabledata">Dispatch Date.</td>
    	          <td class="tabledata">Order Qty</td>
				  <td class="tabledata">Diapatch Qty</td>
				  <td class="tabledata">Pending Qty</td>
				 <!-- <td class="tabledata">Status</td>-->
    	          <!--<td class="tabledata">Weight</td>
    	          <td class="tabledata">No. of Pkt.</td>
    	          <td class="tabledata">Pcs/Pkt.</td>-->
  	          </tr>
  	          <?php if(DB_num_rows($sql1)>0){
			  while($GetData=DB_fetch_array($sql1)) {?>
		  <tr bgcolor="#c1c1c1">
    	          <td><?php echo $t+1; ?></td>
    	          <td><?php echo $GetData['adviceNo']?></td>
    	          <td><?php echo $s->GetFieldValue('salesorder',"id='".$GetData['SOPNo']."'",'orderNo');?></td>
				  <td><?php echo ConvertSQLDate($GetData['dispatchDate']);?></td>
    	          
				  <td><?php echo $GetData['OrderQty'];?></td>
				  <td><?php echo $GetData['dispatchQty'];?></td>
				  <td><?php echo $pend=$GetData['OrderQty']-$GetData['dispatchQty'];?></td>
				  
  	          	</tr>
  	          	<?php 
  	          	$totalOrderQty=$totalOrderQty+$GetData['OrderQty'];
				$totaldpQty=$totaldpQty+$GetData['dispatchQty'];
				$totalpnQty=$totalpnQty+$pend;
  	          	$t++;} ?>
			<tr bgcolor="#c1c1c1">
    	          <td>&nbsp;</td>
    	          <td>&nbsp;</td>
				  <td>&nbsp;</td>
    	          <td align="right" style="text-align:right;">Total:</td>
    	          <td><?php echo $or=round($totalOrderQty,2);?></td>
    	          <td><?php echo $dis=round($totaldpQty,2);?></td>
    	          <td><?php echo round($totalpnQty,2);?></td>
				 
				  		  				  
  	          </tr>
			  <?php }else{ ?>
			  <tr><td colspan="6"><font color="#FF0000">No Record Found</font></td></tr>
			  <?php }?>
  	        </table></td>
   	      </tr>
    </table></td>
  </tr>
  
 <?php 
	?>
</table>
<? } ?>


</div></div>