<?php 
$s=new db_query();
global $db;
if($_REQUEST['Delete'])
{
	for($i=0;$i<count($_REQUEST['quotationid']);$i++)
	{
	$cond="parent_id='".$_REQUEST['quotationid'][$i]."'";
	$row= $s->DeleteRecord('direct_po_details', $cond);
	
	$cond="id='".$_REQUEST['quotationid'][$i]."'";
	$row= $s->DeleteRecord('direct_po', $cond);
	}	
}
?>

<style type="text/css">
<!--
.style1 {font-weight: bold}
-->
</style>
<script language="javascript" >
function LeadData()
{	
	myCheckboxArray = document.myform.elements["quotationid[]"];
	var t=myCheckboxArray.length;
	if(document.getElementById('quotationid').checked==true)
	{	
	
		if(t==undefined)
	
		document.getElementById('quotationid_'+1).checked=true;		
			for (var i = 1; i <= t; i++)
	{
	document.getElementById('quotationid_'+i).checked=true;	
	}	
	}
	else
	{

	if(t==undefined)		
		document.getElementById('quotationid_'+1).checked=false;		
			
	for (var i = 1; i <= t; i++)
	{
	document.getElementById('quotationid_'+i).checked=false;	
	}
	}
	

	
}
</script>
<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div">
<h1><?php  echo $page_title;?></h1>
<div class="centre" id="slidingDiv">
<form action="" method="post"  >
<table width="100%" border="0" cellspacing="0" cellpadding="3" >
  <tr class="row1">
    <td width="13%"><strong>Branch</strong></td>
	<td width="20%">
	<select name="site"  style="width:98%;">
	<option value="0">--All--</option>	
	<?php
	$Sitesql="select * from locations where  CompanyId='".$_SESSION['ACGCompanyId']."' and loccode IN ('".$_SESSION['AssignedBranch']."') ";
	$SiteRes=DB_query($Sitesql,$db);
	while($SiteRow=DB_fetch_array($SiteRes))
	{?>
	<option value="<?php  echo $SiteRow['loccode'];?>" <?php  echo $_REQUEST['site']==$SiteRow['loccode']?'selected':''?> ><?php  echo $SiteRow['locationname'];?></option>
	<?php 
	}
	?>
	</select></td>
	<td width="13%"><strong>To</strong>:</td>
	<td width="20%"><input name="todate" type="text"  class="datepicker" style="width:98%;"/></td>
	<td width="13%"><strong>From</strong>:</td>
	<td width="20%"><input name="fromdate" type="text"  class="datepicker" style="width:98%;"/></td>

	</tr>


	<tr class="row1">
	<td colspan="6"><p align="center"><input name="Search" type="submit"  value="Search" class="search"/></p></td>
  </tr>
</table> 
</form>
</div>

<form method="post" name="myform">	
<p align="left">
<?php if($_SESSION['frmAdd']==0){ ?> 
<input type="button" name="Create" value="Add Direct PO" alt="Not Allowed" title="Not Allowed" class="search" />

<?php }else{?>
<a href="<?php echo "index.php?route=POModule/direct_purchase_order1".$rurl.'&action=AddNew'?>"><input type="button" name="Create" value="Add Direct PO" class="search" /></a>


<?php }?>

<?php if($_REQUEST['Search'])
{?>
<a href="QuotesExp.php"><input type="button" name="Export" value="Export" class="search" /></a>
<?php }?>

<?php if($_SESSION['frmDelete']==0){ ?>
  <input type="button" name="Delete" value="Delete" alt="Not Allowed" title="Not Allowed"  class="search" />
<?php }else{?>
<input type="submit" name="Delete" value="Delete" class="search" />
<?php }?>
</p>
<table width="100%" border="1" cellspacing="0" cellpadding="3">
	<tr class="row1">
			<td width="2%"><input name="quotationid" type="checkbox"   id="quotationid" onclick="LeadData()"    /></td>
		<td width="5%"><strong>Pr No</strong></td>
		<td width="5%"><strong>Pr Date</strong></td>
		<td width="10%"><strong>Party Name</strong></td>	
		<td width="13%"><strong>Quotation No</strong></td>
		<td width="13%"><strong>Quotation Date</strong></td>
		<td width="15%"><strong>Basic Amount</strong></td>
		<td width="15%"><strong>Grand Total</strong></td>
		<td width="18%"><strong>Created By</strong></td>
	
	</tr>
<?php 
if($_REQUEST['Search'])
{
	
$todate=ConvertSQLDate($_REQUEST['todate']);
$fromdate=ConvertSQLDate($_REQUEST['fromdate']);
$site=$_REQUEST['site'];
	if($_REQUEST['todate']!='' && $_REQUEST['fromdate']!='' )
	{
		$filter[]="pr_date between '".$todate."' and '".$fromdate."'";
	}
 	if($_REQUEST['site']!='0')
	{
		$filter[]="site='".$site."'";
	}
	
if($filter!='')
{
	$filter1=implode(" and ",$filter);
     $GetLead="select * from direct_po where  $filter1 ";
	 $getlead=DB_query(  "select * from direct_po where  CompanyId='".$_SESSION['ACGCompanyId']."' and $filter1 ",$db);
	}
}
else 
{
	
$i=1;
     $GetLead=  "select * from direct_po where  CompanyId='".$_SESSION['ACGCompanyId']."'    ";

    $getlead=DB_query(  "select * from direct_po where  CompanyId='".$_SESSION['ACGCompanyId']."'     order by id desc",$db);
}
//}

$s=new db_query();

if(DB_num_rows($getlead)>0)
{
	 while($row_quotes=DB_fetch_array($getlead))
	 {
	 $SOURL="index.php?route=POModule/direct_po_edit&action=Edit&SID=".$row_quotes['id'].$rurl;
$SO_VIEW="index.php?route=POModule/direct_po_view&action=View&SID=".$row_quotes['id'].$rurl;

?>
    <tr bgcolor="#dfdfdf">
     <td>
   <input name="quotationid[]" type="checkbox" id="quotationid_<?php echo $i; ?>"   value="<?php  echo $row_quotes['id']?>" />
  <a href="<?php echo $SOURL?>"><img src="images/icon_edit.gif" width="10px"  height="10" /></a>&nbsp;
   <a href="direct_purchase_print.php?id=<?php echo $row_quotes['id']?>" target=_blank><input type="button" value="Print" class="search"></a>
   </td>
  <td style="padding-left:5px; padding-right:5px;"><?php  echo $row_quotes['pr_no'];?></td>
  <td style="padding-left:5px; padding-right:5px;"><?php  echo ConvertSQLDate($row_quotes['pr_date']); ?></td>
  	<td style="padding-left:5px; padding-right:5px;"><?php	echo $company_name=$s->GetFieldValue('suppliers',"id='".$row_quotes['vender_id']."'",'vendor_name'); 	?></td>
 	<td><?php echo $row_quotes['quotation_no']; ?></td>
 	<td><?php echo ConvertSQLDate($row_quotes['quotation_date']); ?></td>
 	<td><?php echo $row_quotes['basic_amt']; ?></td>
 		<td style="padding-left:5px; padding-right:5px;"><?php  echo $row_quotes['grand_total']?></td>
		<td style="padding-left:5px; padding-right:5px;"><?php  
			$Sql1=DB_query("Select * from www_users where id='".$row_quotes['createdBy']."'",$db);
	$Res1=DB_fetch_array($Sql1);
		
	echo $Res1['userid'];
			?></td>
			
   <?php $i++; }  }
   else
   {?>
   	<tr bgcolor="#FFFFFF" align="center">
   	<td colspan="9">
   	<font color="#FF0000"><?php echo "No Records Found"; ?></font></td>
   		</tr>
  <?php }?>
</table>
</form>
</div>
</div>