<?php ob_start();
$PageSecurity = 5;
include('includes/SQL_CommonFunctions.inc');
$title = _('Enquiry Register');
$PageName ='Enquiry Register';	
if($_REQUEST['Cancel']!='')
{
	unset($_REQUEST);
}
?>
<h2 align="center"><strong>Enquiry Register</strong></h2>
<form action="" method="post">
<table width="40%" border="0" cellspacing="2" cellpadding="2">
 
 <tr>
    <th><strong>Item Name </strong></th>
    <td>
	<select name="itemName">
	<option value="">Select</option>
	<?php 
	$name_sql=DB_query("Select distinct item_name from item_master",$db);
	while($name_row=DB_fetch_array($name_sql)) {
	?>
	<option value="<?php echo $name_row['item_name'];?>"<?php echo ($_REQUEST['itemName']==$name_row['item_name']?'selected':'')?>><?php echo $name_row['item_name'];?></option>
	<?php } ?>
    </select>	</td>
  </tr>
  <tr>
    <th><strong>From</strong></th>
    <td><strong>
	<?php 
	if($_REQUEST['fromDate']!=''){$fromDate=$_REQUEST['fromDate'];}
	if($_REQUEST['toDate']!=''){$toDate=$_REQUEST['toDate'];}
	?>
      <input name="fromDate" type="text" size="12" class="datepicker" value="<?php echo $fromDate;?>"/>
      To</strong> 
      <input name="toDate" type="text" size="12" class="datepicker" value="<?php echo $toDate;?>"/></td>
  </tr>
  
  
</table>
<p align="center"><input type="submit" name="View" value="View" /><input type="submit" name="Cancel" value="Cancel" /></p>
</form>
<br />


<?php 
	if($_REQUEST['View']!='')
	{
		//print_r($_REQUEST);
		$filter=array();		
		$fromDate=$_REQUEST['fromDate'];
		$fromDateBrk=explode("/",$fromDate);
		$fromDate=$fromDateBrk[0];
		$fromMonth=$fromDateBrk[1];
		$fromYear=$fromDateBrk[2];
		$From=$fromYear."-".$fromMonth."-".$fromDate;
		
		$toDate=$_REQUEST['toDate'];
		$toDateBrk=explode("/",$toDate);
		$toDate=$toDateBrk[0];
		$toMonth=$toDateBrk[1];
		$toYear=$toDateBrk[2];
		$To=$toYear."-".$toMonth."-".$toDate;
		
		
		if($_REQUEST['itemName']!='')
		$filter[]="jjrs_enquiry_details.item_name ='".$_REQUEST['itemName']."'";		
		if($_REQUEST['fromDate']!='' && $_REQUEST['toDate']!='')
		$filter[]="jjrs_enquiry.created_date between '".$From."' and '".$To."'";
		if($_REQUEST['itemName']!='' && $_REQUEST['fromDate']!='' && $_REQUEST['toDate']!='')
		{		
		$message="Showing Enquiry letter Register   from '".$From."' to '".$To."' ";
		}
		
		if($filter != '')
		{
		$filter1 = implode(" and ",$filter);
		}
		
			if($_REQUEST['itemName']!='' && $_REQUEST['fromDate']!='' && $_REQUEST['toDate']!='')
			{
			$message="Showing Records of Items  '".$_REQUEST['itemName']."'   From  ".$From." to ".$To."";
			}
			else if($_REQUEST['itemName']!='' && $_REQUEST['fromDate']=='' && $_REQUEST['toDate']=='')
			{
			$message="Showing Records of Items '".$_REQUEST['itemName']."' ";
			
			}
			else if($_REQUEST['itemName']=='' && $_REQUEST['fromDate']!='' && $_REQUEST['toDate']!='')
			{
			$message="Showing Records   From  ".$From." to ".$To."";
			
			}
	$_SESSION['mess']=$message;
	
	if($filter1!='')
	{		
	  $sql="SELECT *, jjrs_enquiry.id from jjrs_enquiry INNER JOIN jjrs_enquiry_details
	 on(jjrs_enquiry.id = jjrs_enquiry_details.parent_id) where $filter1 GROUP BY jjrs_enquiry.id ";	
	 }
	 else 
	 {
	 $sql="SELECT *, jjrs_enquiry.id from jjrs_enquiry INNER JOIN jjrs_enquiry_details
	 on(jjrs_enquiry.id = jjrs_enquiry_details.parent_id) GROUP BY jjrs_enquiry.id";	
	 }
	
	 $_SESSION['sql']=$sql;
	 ?>
	 <div style="width:810px; height:auto; overflow:auto; margin-left:auto; margin-right:auto;">

	 <p align="right"><a href="enquiry_report_print.php?itemName=<?php echo  $_REQUEST['itemName']; ?>" target="_blank">Print</a></p>
	 <div align="center"><strong><?php echo $message; ?></strong> </div>
	 <br />
<table width="100%" cellpadding="0" cellspacing="0" border="1" style="border:solid 1px #666666;">
  <tr style="background-color:#CCCCCC; height: 30px">
    <td width="52" height="30" style="padding-left:5px; padding-right:5px; white-space:nowrap;">S. No. </td>
    <td width="91" style="padding-left:5px; padding-right:5px; white-space:nowrap;">Enquiry Ref No.</td>
    <td width="87" style="padding-left:5px; padding-right:5px; white-space:nowrap;">Against PR </td>
    <td width="130" style="padding-left:5px; padding-right:5px; white-space:nowrap;">Vender Name</td>
    <td width="254" style="padding-left:5px; padding-right:5px; white-space:nowrap;"><strong>Item Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</strong></td>
    <td width="249" style="padding-left:5px; padding-right:5px;"><strong>Qty&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</strong></td>
    <td width="96" style="padding-left:5px; padding-right:5px;"><strong>UOM&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</strong></td>
  </tr>
  <?php
		$result=DB_query($sql,$db);
		$i=1;
		if(DB_num_rows($result)>0)
		{
		while($myrow=DB_fetch_array($result))
		{
		?>
  <tr bgcolor="#FFFFFF">
    <td><?php echo $i;?></td>
    <td><?php echo $myrow['enquiry_ref_no']; ?></td>
    <td><?php echo $myrow['req_no'];?></td>
    <td><?php echo $myrow['vendor_name'];?></td>
    <td colspan="3" bgcolor="#99CCCC"><table width="100%" border="0">
   <?php 
	 if($_REQUEST['itemName']=='')
	  {
	 $details_sql="Select * from jjrs_enquiry_details where parent_id=".$myrow['id']."";
	}
	else
	{
	$details_sql="Select * from jjrs_enquiry_details where parent_id=".$myrow['id']." and item_name ='".$_REQUEST['itemName']."' ";
	}
	$details_res=DB_query($details_sql,$db);	
	if(DB_num_rows($details_res)>0){
	$tot_received='';
	while($details_row=DB_fetch_array($details_res)){
		
	?>
      <tr bgcolor="99CCCC">
        <td width="108"  class="jjrs_tabledata1" ><?php echo $details_row['item_name'];?></td>
        <td width="90"  class="jjrs_tabledata1" ><span class="jjrs_tabledata1" style="width:39px;"><?php echo $details_row['quantity']; $tot_received[]=$details_row['quantity']; ?></span></td>
        <td width="35"  class="jjrs_tabledata1" ><span class="jjrs_tabledata1" style="width:51px;"><?php echo  $details_row['unit']; ?></span></td>
        <td width="5"  class="jjrs_tabledata1" >&nbsp;</td>
      </tr>
      <?php } ?>
      <tr bgcolor="#FFFFFF" style="height: 25px">
        <td class="jjrs_tabledata1" style="padding-left:5px; padding-right:5px; white-space:nowrap;"><strong>Total</strong></td>
     <td class="jjrs_tabledata1" style="padding-left:5px; padding-right:5px; white-space:nowrap;"><span class="jjrs_tabledata1" style="white-space:nowrap;"><strong><?php echo $a[]=array_sum($tot_received);?></strong></span></td>
        <td style="padding-left:5px; padding-right:5px; white-space:nowrap;" class="jjrs_tabledata1">&nbsp;</td>
        <td style="padding-left:5px; padding-right:5px; white-space:nowrap;" class="jjrs_tabledata1"><strong></strong></td>
      </tr>
      <?php } ?>
      
    </table></td>
  </tr>
  <?php $i++;}
  		}
		else
		{?>
  <tr>
    <td colspan="4"><font color="#FF0000"><strong>No Record Found</strong></font></td>
  </tr>
  <?php 	
		}
  }
	?>
	
</table>
<?php if(!empty($a)) { ?>
<table width="100%" cellpadding="0" cellspacing="0" border="0" style="border:solid 1px #666666;">
  <tr style="background-color:#CCCCCC; height: 30px">
	<td width="6%" class="jjrs_tabledata1" style="padding-left:5px; padding-right:5px; white-space:nowrap;">&nbsp;</td>
	<td width="6%" class="jjrs_tabledata1" style="padding-left:5px; padding-right:5px; white-space:nowrap;">&nbsp;</td>
	<td width="8%" class="jjrs_tabledata1" style="padding-left:5px; padding-right:5px; white-space:nowrap;">&nbsp;</td>
	<td width="19%" class="jjrs_tabledata1" style="padding-left:5px; padding-right:5px; white-space:nowrap;">&nbsp;</td>
        <td width="24%" class="jjrs_tabledata1" style="padding-left:5px; padding-right:5px; white-space:nowrap;"><strong>Grand Total</strong></td>
        <td width="25%" class="jjrs_tabledata1" style="padding-left:5px; padding-right:5px; white-space:nowrap;"><span class="jjrs_tabledata1" style=" white-space:nowrap;"><?php  echo array_sum($a); ?></span></td>
        <td width="6%" class="jjrs_tabledata1" style="padding-left:5px; padding-right:5px; white-space:nowrap;">&nbsp;</td>
        <td width="6%" class="jjrs_tabledata1" style="padding-left:5px; padding-right:5px; white-space:nowrap;"></td>
  </tr>
</table>
<?php } ?>
</div>


