
<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']."'",$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']."' and  Site in('".$_SESSION['AssignedBranch']."') 
		and Zone in(".$_SESSION['AssignedSites'].")";
		$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']!='0' && $_REQUEST['party']!='0'){
	if($_REQUEST['site'] != '')
	{
  	$filter[]="dispatch.site='".$_REQUEST['site']."' ";
	}
	if($_REQUEST['party']!='')
	{
	$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);
        $sql1 = "SELECT * FROM dispatch INNER JOIN dispatch_details ON(dispatch.id=dispatch_details.parentId) where $filter1"; 
	}
	?>
	
<!---------------------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">
    <tr>
    <td><table width="100%" border="1" cellspacing="0" cellpadding="5" style="background-color:#666666; color:#FFFF99">
    <tr>
	  <td>InVoice Details</td>
	  <td>N/A</td>
	  <td>Party</td>
	  <td><? echo $s->GetFieldValue('clientmaster',"id='".$_REQUEST['party']."'",'c_name'); ?></td>
	  <td>From Date</td>
	  <td><? echo $_REQUEST['from_date'] ?></td>
	  <td>From Date</td>
	  <td><? echo $_REQUEST['to_date'] ?></td>
  	      </tr>
  	   </table>
	</td>
        </tr>
    	    <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">Date</td>
    	          <td class="tabledata">Dispatch Slip No.</td>
    	          <td class="tabledata">Item/Shade Name</td>
    	          
    	         <td class="tabledata">Item Description</td>
    	        
    	          
    	          
    	           <td class="tabledata">Order Qty</td>
				    <td class="tabledata">Dispatch Qty</td>
					<td class="tabledata">Pending Qty</td>
    	          <td class="tabledata">Weight</td>
    	          <td class="tabledata">No. of Pkt.</td>
    	          <td class="tabledata">Pcs/Pkt.</td>
    	         
  	          </tr><?php 
  	          $result1 = DB_query($sql1,$db);
  	          $k=1;
if(DB_num_rows($result1)>0){
$Total_Odr_qty=array();
$Grand_Dis=array();
$Grand_Pend=array();
while($row1=DB_fetch_array($result1))
{ 
 echo $Pend_Qty=$s->GetFieldValue('salesorder_details',"masterId='".$row1['againstSOP']."'",'pendingQty');
 $TotalDispatch_Qty=$row1['orderQty']-$Pend_Qty;
 $Total_Odr_qty[]=$row1['orderQty'];
 $Grand_Dis[]=$TotalDispatch_Qty;
 $Grand_Pend[]=$Pend_Qty;
?>
<tr bgcolor="#c1c1c1">
    	          <td><?php echo $t+1; ?></td>
				  <td><?php echo ConvertSQLDate($row1['dispatchDate']); ?></td>
    	          <td><?php  echo $row1['adviceNo'];?></td>
    	          <td><?php   echo $s->GetFieldValue('item_master',"id='".$row1['item']."'",'item_name'); ?></td>
    	          <td><?php   echo $s->GetFieldValue('item_master',"id='".$row1['item']."'",'item_desc'); ?></td>
    	          <td><?php echo $row1['orderQty'];?></td>
				   <td><?php echo $TotalDispatch_Qty;?></td>
				    <td><?php echo $Pend_Qty;?></td>
    	          <td><?php echo $row1['weight'];?></td>
    	          <td><?php echo $row1['boxDetails'];?></td>
    	          <td><?php echo $row1['piecePerBox'];?></td>
    	         
  	          	</tr>
  	          	<?php $t++; $k++; 
				} ?>
				<tr bgcolor="#c1c1c1">
    	          <td>&nbsp;</td>
    	          <td>&nbsp;</td>
				  <td>&nbsp;</td>
				  <td>&nbsp;</td>
				  <td align="right" style="text-align:right;">Total:</td>
    	          <td><?php echo $abc1=array_sum($Total_Odr_qty);?></td>
    	          <td><?php echo $abc2=array_sum($Grand_Dis);?></td>
    	          <td><?php echo $abc3=array_sum($Grand_Pend);?></td>
    	          <td><?php echo round($totalPacketNo,2);?></td>
    	          <td><?php echo round($totalPieces,2);?></td>
				  <td>&nbsp;</td>				  
  	          </tr>

<?php } 	 else { ?>
  	          		 <tr><td colspan="7"><font color="#FF0000">No Record Found</font></td></tr><?php } ?>
  	        </table></td></tr></table>
	
<?php } else {
if($_REQUEST['View']!='' && $_REQUEST['party']=='0')
{
	if($_REQUEST['site'] != '')
	{
  	$filter[]="dispatch.site='".$_REQUEST['site']."' ";
	}
	if($_REQUEST['from_date'] != '' && $_REQUEST['to_date'] != '')
	{
 	$filter[]="dispatch.dispatchDate between '".FormatDateForSQL($_REQUEST['from_date'])."' and '".FormatDateForSQL($_REQUEST['to_date'])."'";
	}
	/*if($_REQUEST['party'] != '')
	{
	$filter[]="dispatch.party='".$_REQUEST['party']."'";
	}*/
	if($filter!='')
	{
	$filter1 = implode(" and ",$filter);
	$k=1;
		$getparty=DB_query("SELECT DISTINCT(party) as P_name FROM dispatch WHERE site='".$_REQUEST['site']."'",$db);
		
if(DB_num_rows($getparty)>0){
		while($getpartyRow=DB_fetch_array($getparty)){
		//echo "SELECT * FROM dispatch INNER JOIN dispatch_details ON(dispatch.id=dispatch_details.parentId) where dispatch.party='".$getpartyRow['P_name']."' and  $filter1";
        $sql1 = DB_query("SELECT * FROM dispatch INNER JOIN dispatch_details ON(dispatch.id=dispatch_details.parentId) where dispatch.party='".$getpartyRow['P_name']."' and  $filter1",$db);  


?>
  <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="0" cellspacing="0" cellpadding="5">
    	        <tr>
    	          <td>Invoice No.</td>
    	          <td><?php echo 'N/A';?></td>
    	          <td>Party Name</td>
    	          <td><?php $p=DB_query("Select c_name from clientmaster where id='".$getpartyRow['P_name']."'",$db);
    	          	$pRes=DB_fetch_array($p); echo $pRes['c_name'];
    	          	?></td>
                  <td>From Date</td>
    	          <td><?php echo $_REQUEST['from_date']?></td>
				  <td>To Date</td>
    	          <td><?php echo $_REQUEST['to_date']?></td>
  	          </tr>
  	        </table></td>
        </tr>
    	    <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">Item Description</td>
    	          <td class="tabledata">Order Qty</td>
				  <td class="tabledata">Diapatch Qty</td>
				  <td class="tabledata">Pending Qty</td>
    	          <td class="tabledata">Weight</td>
    	          <td class="tabledata">No. of Pkt.</td>
    	          <td class="tabledata">Pcs/Pkt.</td>
  	          </tr>
  	          <?php while($GetData=DB_fetch_array($sql1)) {?>
		  <tr bgcolor="#c1c1c1">
    	          <td><?php echo $t+1; ?></td>
    	          <td><?php echo $GetData['adviceNo']?></td>
    	          <td><?php 
    	          $itemName=$s->getField('item_master','StockID',$details_row['ItemCode'],'item_name');
    	          echo $itemName;?></td>
    	          <td><?php echo $details_row['Quantity'];?></td>
				  <td><?php echo $details_row['Quantity'];?></td>
				  <td><?php echo $details_row['Quantity'];?></td>
    	          <td><?php echo $dispatchRow['weight'];?></td>
    	          <td><?php echo $dispatchRow['boxDetails'];?></td>
    	          <td><?php echo $dispatchRow['piecePerBox'];?></td>
  	          	</tr>
  	          	<?php 
  	          	$totalQty=$totalQty+$details_row['Quantity'];
				$totalQty=$totalQty+$details_row['Quantity'];
  	          	$totalWeight=$totalWeight+$dispatchRow['weight'];
				$totalPacketNo=$totalPacketNo+$dispatchRow['boxDetails'];
				$totalPieces=$totalPieces+$dispatchRow['piecePerBox'];
  	          	$t++;} ?>
			<tr bgcolor="#c1c1c1">
    	          <td>&nbsp;</td>
    	          <td>&nbsp;</td>
    	          <td align="right" style="text-align:right;">Total:</td>
    	          <td><?php echo round($totalQty,2);?></td>
    	          <td><?php echo round($totalWeight,2);?></td>
    	          <td><?php echo round($totalPacketNo,2);?></td>
    	          <td><?php echo round($totalPieces,2);?></td>
				  <td>&nbsp;</td>
				  <td>&nbsp;</td>				  				  
  	          </tr>
  	        </table></td>
   	      </tr>
    </table></td>
  </tr>
  <tr>
  	<td></td>
  </tr> 
  <tr>
  	<td></td>
  </tr> 
 <?php $k++;
	 } 	}
} 
	else
	{?>
	<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="0" cellspacing="0" cellpadding="5">
    	        <tr>
    	          <td>Invoice No.</td>
    	          <td></td>
    	          <td>Party Name</td>
    	          <td></td>
                  <td>Date</td>
    	          <td></td>
  	          </tr>
  	        </table></td>
        </tr>
    	    <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">Item Description</td>
    	          <td class="tabledata">Quantity</td>
    	          <td class="tabledata">Weight</td>
    	          <td class="tabledata">No. of Pkt.</td>
    	          <td class="tabledata">Pcs/Pkt.</td>
  	          </tr>
  	          <tr><td colspan="7"><font color="#FF0000">No Record Found</font></td></tr>
  	        </table></td>
   	      </tr>
    </table>
</td>
	</tr>
	<?php 
	} } }
?>
</table>



<? } ?>


</div></div>