<?php 
$frmpermission=$px->GetFileAccess($_SESSION['modid'],$_SESSION['frmid'], $_SESSION['ACGRoleId']);
$_SESSION['frmEdit']=$frmpermission[1];
$_SESSION['frmDelete']=$frmpermission[2];
$_SESSION['frmView']=$frmpermission[3];
$_SESSION['frmcreate']=$frmpermission[0];
$current_month=date('m');
?>
<h2>Search Quotations</h2>
		<form action="" method="post">
<table><tr><td><input type="radio" name="conition" id="conition" value="month" onclick="getCondition(this.value)" <?php if($_REQUEST['conition']=='month')echo "checked";?>/><strong>Month Wise</strong></td><td><input type="radio" name="conition" id="conition" value="date" onclick="getCondition(this.value)" <?php if($_REQUEST['conition']=='date')echo "checked";?>/><strong>Period Wise</strong></td></tr></table>
<br/>
<table width="100%" border="1" align="center" style="background-color:#FFFFFF; border:solid 1px #999999">
  <tr>
    <th>Site:</th>
    <td><select name="site" id="site" style="width:120px">
<option value="000">---ALL---</option>
<?php 
if($_SESSION['AssignedSites']!='0')
	  {
	  	$site_sql=DB_query("Select loccode,locationname from locations where CompanyId='".$_SESSION['ACGCompanyId']."' and loccode in (".$_SESSION['AssignedSites'].")",$db);
	   	  
	  }
else
	 {
	$site_sql=DB_query("Select loccode, locationname from locations",$db); 
    }


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>
<th>Vendor</th>
<td>
<select name="vendor" id="vendor">
<option value="000">---ALL--</option>
<?php 
$site_sql=DB_query("Select id , vendor_code , vendor_name from suppliers",$db); 
while($vendor_row=DB_fetch_array($site_sql)){
?>
<option value="<?php echo $vendor_row['id'];?>"<?php  echo($_REQUEST['vendor']==$vendor_row['id']?'selected':'');?>><?php echo 
  str_replace(array("M/s ","M/S"),'',$vendor_row['vendor_name']).'-'.'('.$vendor_row['vendor_code'].')';?></option>
<?php } ?>
</select>
 </td>
 <?php $month_array=array('01'=>'January','02'=>'February','03'=>'March','04'=>'April','05'=>'May','06'=>'June','07'=>'July','08'=>'August','09'=>'September','10'=>'October','11'=>'November','12'=>'December');
 
 $month_disabled="disabled";
 $date_disabled="disabled";
 if($_REQUEST['conition']=='month')
 {$month_disabled="";}else
 if($_REQUEST['conition']=='date')
 {$date_disabled="";}
 
 ?>
 <th>Month</th>
 <td><select name="month" id="month" style="width:90px;" <?php echo $month_disabled;?>>
 <option value="">Select Month</option>
 <?php 
 foreach($month_array as $key=>$val)
 {?>
 <option value="<?php echo $key;?>" <?php if($_REQUEST['month']==$key)echo "selected";?>><?php echo $val;?></option>
 <?php 	
 }
 ?>
 </select></td>
 <th>From</th>
 <td><input type="text" name="from" id="from" size="12" class="datepicker" value="<?php echo $_REQUEST['from'];?>" <?php echo $date_disabled;?>/></td>
 <th>To</th>
 <td><input type="text" name="to" id="to" size="12" class="datepicker" value="<?php echo $_REQUEST['to'];?>" <?php echo $date_disabled;?>/></td>
  </tr>  
</table>
<p align="center"><input name="Search" type="submit" value="Search"></p>

</form>
  	 	<br />

<table width="100%" border="0" cellpadding="2" cellspacing="0">
<?php 
if($_REQUEST['Search'])
{
	
}
$req_sql = "select * from materialrequisitions where MONTH(prdate)=".$current_month." order by prdate DESC";
$req_result=DB_query($req_sql,$db);
while($req_row=DB_fetch_array($req_result))
{
?> 
<tr style="background-color:#B7B7B7 ">
<td><strong>Requisition No.</strong></td>
<td><strong><?php echo $req_row['Reqno'];?></strong></td>
</tr>
<tr>
	<td colspan="2">
		<table width="100%" border="1" cellpadding="2" cellspacing="0">
  <tr style="background-color:#B7B7B7 ">
    <td><strong>S.No.</strong></td>
    <td><strong>Quotation Date</strong></td><td><strong>Vernder Quotation</strong> </td>
    <td><strong>Vendor Code</strong></td>
    <td><strong>Vendor Name</strong></td>
    <td><strong>Site Name/Code </strong></td>
    
	 <td><strong>View </strong></td>
	  <td><strong>Edit</strong></td>
	   <td><strong>Delete</strong> </td>
  </tr>
  	<?php $k=1;
	$current_month=date('m');
	if($_REQUEST['Search']){
 	$site=$_REQUEST['site'];
	$vendor=$_REQUEST['vendor'];
	$month=$_REQUEST['month'];
	$from=$_REQUEST['from'];
	$to=$_REQUEST['to'];
	
	$from_brk=explode('/',$from);
	$from_date=$from_brk[2]."-".$from_brk[1]."-".$from_brk[0];
	$to_brk=explode('/',$to);
	$to_date=$to_brk[2]."-".$to_brk[1]."-".$to_brk[0];
	if($month!='' || ($from!='' && $to!='')){
	$filter='1=1';}
 	if($site!='000')
	$filter.=" and sitecode = '$site'";
	if($vendor!='000')
	$filter.=" and mst_supplierno = '$vendor'";
	if($month!=''){
	$filter.=" and MONTH(date1) = '$month'";}
	
	if($from!='' && $to!='')
	$filter.=" and date1 BETWEEN '$from_date' and '$to_date'";
	
	if($month!='' || ($from!='' && $to!=''))
	{$sql = "select * from venderquotations where $filter and mst_requisition_no='".$req_row['requisitionno']."' order by date1 DESC";}
	else
	{$sql = "select * from venderquotations where MONTH(date1)='$current_month' and mst_requisition_no='".$req_row['requisitionno']."' $filter order by date1 DESC";}
	}
	else{
	 $sql = "select * from venderquotations where MONTH(date1)=".$current_month." and mst_requisition_no='".$req_row['requisitionno']."' order by date1 DESC";
	
	 //$sql = "select * from venderquotations where mst_requisition_no not in (select requsitionno from requisitionorderdetails where item_status=0) order by id DESC";
   	$purchordersResult=DB_query("SELECT requisitionno FROM materialrequisitions WHERE STATUS=1  AND requisitionno NOT IN(SELECT mst_requisition_no FROM venderquotations )",$db);
   }
//echo $sql ;
	?>
	<?php
 
	$Quotations_Result = DB_query($sql,$db,$ErrMsg);
 	if(DB_num_rows($Quotations_Result)>0)
	{
		while ($Row_Quotes=DB_fetch_array($Quotations_Result)) 
		{
		 $QuotesId=$Row_Quotes['id'];
		 $SupplierID=$Row_Quotes['mst_supplierno'];
		  $sitecode=$Row_Quotes['sitecode'];
		   $site=$Row_Quotes['site'];
		   $date1=ConvertSQLDate($Row_Quotes['date1']);
		  	$RequisitionNo=$Row_Quotes['mst_requisition_no'];		   
		      
		 $vendor_detail="Select vendor_code,vendor_name  from suppliers where id='".$SupplierID."'";
		$result_vendor=DB_query($vendor_detail,$db);
		$myrow_vendor=DB_fetch_array($result_vendor);
		$vendor_code=$myrow_vendor['vendor_code'];
		$vendor_name=$myrow_vendor['vendor_name'];
		 
		 $vernder_quotation=$Row_Quotes['vernder_quotation'];
		 
		//$tt= $s->GetFieldValue('comprative_detail',"Vendor_Quot_No='".$QuotesId."' and status_active=1",'comprative_id');
	 $tt= $s->GetFieldValue('comprative_detail',"Vendor_Quot_No='".$QuotesId."' ",'comprative_id');
	
	 ?>
	 
  <tr bgcolor="#FFFFFF" onmouseover="this.style.backgroundColor='#fffeb3'; this.style.color='#00f';" onmouseout="this.style.backgroundColor='#FFF'; this.style.color='#000000';">
    <td><div align="center">
      <?php  echo $k++;// $QuotesId;?>
    </div></td>
	  <td><?php  echo  $date1;?></td>
    <td><?php  echo  $vernder_quotation;?></td>
     <td><?php  echo  $vendor_code;?></td>
     <td><?php  echo  $vendor_name;?></td>
    <td><?php  echo  $site.'('.$sitecode.')';?></td>
     <td>
	  <a href="index.php?route=POModule/POrder&VQuotesId=<?php echo $QuotesId.$rurl;?>" ><img src="images/search.gif" width="15" height="15"></a>
	 
	 
	 </td>
	   <td>
	   <?php 
	   if($tt>0){
	 echo "Comp List Genrated";
	 ?>
	 
	 <?php }else if($_SESSION['frmcreate']==1){?>
	   <a href="index.php?route=POModule/Edit-VenderQutations&Vid=<?php echo  $QuotesId;?>&RequisitionNo=<?php echo $RequisitionNo.$rurl; ?>&action=Edit"><img src="images/icon-edit.png"width="15" height="15"></a>
	 
	 <?php  } else { echo "No Permission"; } ?>
	 
	 
	</td> 
	     <td>
		 <?php if($tt>0){
		  echo "No Permission ";
		  ?>
		 
		  <?php } else if($_SESSION['frmcreate']==1){?>
		 <a onclick="return confirm('Are You Sure U Want To Delete This Record?')" href="index.php?route=POModule/DispVendor_Quotes<?php echo $rurl;?>&delete=1&Vid=<?php echo  $QuotesId;?>"><img src="images/Icon_Delete.png" width="15" height="15" ></a>
		  <?php  } else {echo "No Permission"; }?>
	 
		 </td>
  </tr>
<?php
 
	 
	 		
	}
	}
	else
	{?>
		<tr>
		<td colspan="6"><font color="#FF0000"><h2 align="center">No Record Found!</h2></font></td>
		</tr>
	<?php }
	?>
</table>
	</td>
</tr>
<tr height="25px"><td>&nbsp;</td></tr>
<?php }?>
</table>







<script language="javascript" type="text/javascript">
function getCondition(str)
{
	if(str=='month')
	{document.getElementById("month").disabled=false;
	document.getElementById("from").disabled=true;document.getElementById("from").value='';
	document.getElementById("to").disabled=true;document.getElementById("to").value='';}
	else if(str=='date')
	{document.getElementById("month").disabled=true;document.getElementById("month").value='';
	document.getElementById("from").disabled=false;
	document.getElementById("to").disabled=false;}
}
</script>