<script language="javascript" type="text/javascript">
function showsitename160(str)
{

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)
    {
	var data=xmlhttp.responseText.split("__");	
	document.getElementById("storedata7").innerHTML=data[0];
	  }
  }
  xmlhttp.open("GET","get_dealerclient.php?site="+str,true);
	xmlhttp.send();
}
</script>
<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div">
<h1>Purchase Enquiry Register</h1>
<form method="post" action="">
<table width="100%" border="0" cellpadding="3" cellspacing="0">
<tr class="row1">
	<td class="tabledata1">Dealer</td>
    <td>
	<?php
	if(!empty($_SESSION['dealerid']))
	  {	  	
  $ss1="Select * from dbl_dealer where company='".$_SESSION['ACGCompanyId']."' 
   and id='".$_SESSION['dealerid']."'";
 $site_sql1=DB_query($ss1,$db);
     }
  else
    {
	$ss1="Select * from dbl_dealer where company='".$_SESSION['ACGCompanyId']."'";
	$site_sql1=DB_query($ss1,$db);
	}
	?>
<select name="dealer" id="dealer"  style="width:150px;">
<option value="">Select Site</option>
<?php 
while($site_row = DB_fetch_array($site_sql1))
{
$p='';
if($site_row['id'] == $_POST['dealer'])	
$p="selected";
?>
<option value="<?php echo $site_row['id']; ?>" <?php echo $p;?>><?php echo $site_row['dealer_name']; ?></option>
<?php } ?>
</select></td>
	<td class="tabledata1">Order Type</td>
    <td><select name="ordertype" id="ordertype" style="width:150px;">
	    <option value="0">Select</option>
        <option value="exciable"<?php if($_POST['ordertype']=='exciable') { ?> selected="selected" <?php } ?>>Exciable</option>
		<option value="non exciable"<?php if($_POST['ordertype']=='non exciable') { ?> selected="selected" <?php } ?>>Non Exciable</option>
                </select>
              </td>
</tr>

<tr class="row1">
	<td class="tabledata1">From</td>
    <td><input type="text" name="from_date" style="width:150px;" value="<?php echo $_POST['from_date'];?>" class="datepicker"></td>
	<td class="tabledata1">To</td>
    <td><input type="text" name="to_date" style="width:150px;" value="<?php echo $_POST['to_date'];?>" class="datepicker"></td>
</tr>
<tr class="row1">
	<td class="tabledata1">SMC Unit</td>
    <td><select name="unit" id="unit" style="width:150px">
         <option value="0">Select</option>	
		 <?php $sql1=DB_query("select * from locations where mst_companyid='".$_SESSION['ACGCompanyId']."'",$db);
		       while($row1=DB_fetch_array($sql1))
			   {
		 ?>
		 <option value="<?php echo $row1['loccode']; ?>"><?php echo $row1['locationname']; ?></option>
		 <?php } ?>
	     </select>
	
	</td>
	<td class="tabledata1">To</td>
    <td><input type="text" name="to_date" style="width:150px;" value="<?php echo $_POST['to_date'];?>" class="datepicker"></td>
</tr>
<tr class="row1">
	<td class="tabledata1" style="text-align:center;" colspan="4">
	<input type="submit" name="view" class="search" value="View">
	</td>
</tr>
</table>
		

</form>
<?php 
if($_REQUEST['view']!='')
{
	$fromdate=$_REQUEST['from_date'];
	$todate=$_REQUEST['to_date'];
	$fromdate_brk=explode('/',$fromdate);
	$from=$fromdate_brk[2]."-".$fromdate_brk[1]."-".$fromdate_brk[0];
	$todate_brk=explode('/',$todate);
	$to=$todate_brk[2]."-".$todate_brk[1]."-".$todate_brk[0];
	$sitename=$s->getField('dbl_dealer','id',$_REQUEST['dealer'],'dealer_name');
	$filter=array();
	if($_REQUEST['dealer']!='')
	$filter[]="dbl_direct_po.dealer = '".$_REQUEST['dealer']."'";
	if($_REQUEST['ordertype']!='0')
	$filter[]="dbl_direct_po.type = '".$_REQUEST['ordertype']."'";
	if($_REQUEST['unit']!='0')
	$filter[]="dbl_direct_po.site = '".$_REQUEST['unit']."'";
	if($_REQUEST['from_date']!='' && $_REQUEST['to_date']!='')
	$filter[]="dbl_direct_po.pr_date BETWEEN '$from' and '$to'";
	
	
		
	
	if($filter!='')
	{
		$filter=implode(' and ',$filter);
	}
	if($_REQUEST['dealer']!='' && $_REQUEST['from_date']!='' && $_REQUEST['to_date']!='')
	{
	$message="Showing Records of Dealer ".$sitename."   From  ".$from." to ".$to."";
	}
	else if($_REQUEST['dealer']!='' && $_REQUEST['from_date']=='' && $_REQUEST['to_date']=='')
	{
	$message="Showing Records of Dealer ".$sitename." ";
	
	}
	else if($_REQUEST['dealer']=='' && $_REQUEST['from_date']!='' && $_REQUEST['to_date']!='')
	{
	$message="Showing Records   From  ".$from." to ".$to."";
	
	}
	if($filter!='')
	{
	
 $sql ="Select * from dbl_direct_po where $filter and CompanyId='".$_SESSION['ACGCompanyId']."' group by dbl_direct_po.id ";
	 }
	 else 
	 {	   
	  $sql ="Select * from dbl_direct_po and CompanyId='".$_SESSION['ACGCompanyId']."'  group by dbl_enquiry_form.id ";
	 }
	
	


?>
<p align="right"></p>


<div align="center" class="row1"><strong><h1><?php echo $message; ?></h1></strong> </div>
<br />
  <table width="100%" cellpadding="0" cellspacing="0" border="1">
<tr class="row1" style="height: 30px">
<td  class="tabledata" width="20"><strong>Sr No</strong></td>
<td class="tabledata" width="40"><strong>PO No</strong></td>
<td class="tabledata" width="50"><strong>PO Date</strong></td>
<td width="70" class="tabledata"><strong>Quotation No</strong></td>
<td width="80" class="tabledata"><strong>Quotation Date</strong></td>
<td width="40" class="tabledata"><strong>Part No</strong></td>
<td width="90" class="tabledata"><strong>Part Name </strong></td>
<td width="30" class="tabledata" ><strong>UOM</strong></td>
<td width="40" class="tabledata"><strong>Qty</strong></td>
<td width="30" class="tabledata"><strong>Price</strong></td>
<td width="52" class="tabledata"><strong>value</strong></td>
<td width="40" class="tabledata"><strong>Discount%</strong></td>
<td width="40" class="tabledata"><strong>Discount Amount</strong></td>
<td width="50" class="tabledata"><strong>Net Amount</strong></td>
<td class="tabledata" ><strong>Delivery Date</strong></td>
<td class="tabledata" style="width:49px;"><strong>Current Status</strong></td>
 </tr>
    <?php 
	$s2=1;
  $result=DB_query($sql,$db);
  while($myrow=DB_fetch_array($result))
  {  	
  
  ?>
<tr bgcolor="#FFFFFF">
<td class="jjrs_tablehead"><?php echo $s2;?></td>
<td class="jjrs_tablehead"><?php echo $myrow['pr_no'];?></td>
<td  class="jjrs_tablehead"><?php echo ConvertSQLDate($myrow['pr_date']);?></td>
<td class="jjrs_tablehead"><?php echo $myrow['quotation_no'];  ?></td>
<td class="jjrs_tablehead"><?php echo ConvertSQLDate($myrow['quotation_date']);  ?></td>
<td colspan="11"><table width="100%" border="1" cellpadding="0" cellspacing="0">
<?php 
$details_sql="Select * from dbl_direct_po_details where parent_id='".$myrow['id']."'";
$details_res=DB_query($details_sql,$db);
$req_qty[]='';
$numrow1=DB_num_rows($details_res);
if(DB_num_rows($details_res)>0){
while($details_row=DB_fetch_array($details_res)){?>
<tr bgcolor="99CCCC">
<td width="39"  class="jjrs_tablehead"  ><?php echo $s->getField('item_master','id',$details_row['mst_itemid'],'StockID'); ?></td>
<td width="90"  class="jjrs_tabledata1" ><?php echo $s->getField('item_master','id',$details_row['mst_itemid'],'item_name'); ?></td>
<td width="30" class="jjrs_tabledata1">
<?php   $unit=$s->getField('item_master','id',$details_row['mst_itemid'],'mst_unitid');
echo $s->getField('unitsofmeasure','unitid',$unit,'unitname'); ?> </td>
<td width="40" class="jjrs_tabledata1"><?php echo  $details_row['qty']; ?> </td>
<td width="30" class="jjrs_tabledata1"><?php echo  $details_row['rate']; ?> </td>
<td width="52" class="jjrs_tabledata1"><?php echo  $details_row['amt']; ?> </td>
<td width="57" class="jjrs_tabledata1"><?php echo  $details_row['dis_per']; ?> </td>
<td width="48" class="jjrs_tabledata1"><?php echo  $details_row['dis_price']; ?> </td>
 <td width="49" class="jjrs_tabledata1"><?php echo $details_row['net_total'];
 $req_qty[]=$details_row['net_total'];	?></td> 
 <td align="right" class="jjrs_tabledata1"><?php echo  $details_row['status']; ?> </td>

 
 </tr><?php }  } ?>
        </table></td>
    </tr>
    <?php $s2++; } if($numrow1>0) { ?>
    <tr bgcolor="#e7e7e7" style="height: 25px">
      <td class="jjrs_tabledata1"><strong></strong></td>
      <?php if($_REQUEST['dealer']=='') { ?> <td class="jjrs_tabledata1">&nbsp;</td><?php } ?>
       <td class="jjrs_tabledata1">&nbsp;</td>
       <td class="jjrs_tabledata1"><strong>&nbsp;</strong></td>
      <td class="jjrs_tabledata1"><strong></strong></td>
	  <td class="jjrs_tabledata1"><strong></strong></td>
	   <td class="jjrs_tabledata1"><strong></strong></td>
	   <td class="jjrs_tabledata1"><strong></strong></td>
	  <td class="jjrs_tabledata1"><strong></strong></td>
	   <td class="jjrs_tabledata1"><strong></strong></td>
	   <td class="jjrs_tabledata1"><strong></strong></td>
	  <td class="jjrs_tabledata1"><strong></strong></td>
	   <td class="jjrs_tabledata1"><strong></strong></td>
      <td class="jjrs_tabledata1"><strong>Total</strong></td>
      <td class="jjrs_tabledata1">&nbsp;</td>
      <td class="jjrs_tabledata1"><?php echo $b[]=array_sum($req_qty);?></td>
	  </tr>
      <?php } else { ?>
	   <tr bgcolor="#e7e7e7" style="height: 25px">
      <td class="jjrs_tabledata1" colspan="16" align="center"><strong>No Records</strong></td>
    </tr>
	  
      <?php } ?>     
    
  </table>

<?php } ?>
</div>
</div>