<?php 
$s=new db_query();
global $db;
if(isset($_REQUEST['Delete']))
{
    //print_r($_REQUEST['quotationid']);
    
	for($i=0;$i<count($_REQUEST['quotationid']);$i++)
	{
            DB_query("delete from direct_po where id='".$_REQUEST['quotationid'][$i]."' ",$db);
             DB_query("delete from direct_po_details where parent_id='".$_REQUEST['quotationid'][$i]."' ",$db);
              DB_query("delete from direct_po_terms_conditions where parant_id='".$_REQUEST['quotationid'][$i]."' ",$db);
	} 
$s->pageLocation("index.php?route=DealerDistrbutions/POORDER/direct_po_index&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']);
}
?>

<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 class="tabledata1">Branch</td>
    <?php  //echo "select * from locations where loccode in ('".$_SESSION['AssignedBranch']."') and mst_companyid='".$_SESSION['ACGCompanyId']."' "; ?>
	<td>
	<select name="site"  style="width:150px;">
	<option value="0">--All--</option>	
	<?php
	$Sitesql="select * from locations where loccode in ('".$_SESSION['AssignedBranch']."') and mst_companyid='".$_SESSION['ACGCompanyId']."' ";
	$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 class="tabledata1">From Date:</td>
	<td ><input name="fromdate" type="text"  class="datepicker" value="<?php echo $_REQUEST['todate'] ?>" style="width:150px;"/></td>
        
	<td class="tabledata1">To Date:</td>
	<td><input name="todate" type="text"  class="datepicker" value="<?php echo $_REQUEST['fromdate'] ?>" style="width:150px;"/></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['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 }?>

&nbsp;<a href="index.php?route=DealerDistrbutions/POORDER/direct_purchase_order1&modid=<?php echo $_REQUEST['modid']; ?>&frmid=<?php echo $_REQUEST['frmid']; ?>"><input type="button" name="Add Direct PO" value="Add Direct PO" class="search"/></a>
</p>-->
<table width="100%" border="1" cellspacing="0" cellpadding="3">
<tr class="row1">
<td class="tabledata"><input name="quotationid" type="checkbox"   id="quotationid" onclick="LeadData()"    /></td>
		<th class="tabledata">PO No.</th>
		<th class="tabledata">Date </th>
                <th class="tabledata">Dealer</th>
		<th class="tabledata">Delivery Date</th>
		<th class="tabledata">Basic Amount</th>
		<th class="tabledata">Created By</th>
                <th class="tabledata">Action</th>
	
	</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 '".$fromdate."' and '".$todate."'";
	}
 	if($_REQUEST['site']!='0')
	{
		$filter[]="site='".$site."'";
	}
        
        if($_REQUEST['site']=='0')
	{
		$filter[]="1=1";
	}
	
if($filter!='')
{
	$filter1=implode(" and ",$filter);
   
	 
	
             $query="select * from direct_po where (TYPE='with_so' OR TYPE='direct' ) AND CompanyId='".$_SESSION['ACGCompanyId']."'and $filter1 ";
       }
        
}

else 
{
	

    
    
       $query=  "select * from direct_po where (TYPE='with_so' OR TYPE='direct' ) and  CompanyId='".$_SESSION['ACGCompanyId']."'";
   
}
//}
//echo $query;
$s=new db_query();
$getlead=DB_query($query,$db);
if(DB_num_rows($getlead)>0)
{
while($row_quotes=DB_fetch_array($getlead))
{
//$SOURL="index.php?route=DealerDistrbutions/POORDER/direct_po_edit&action=Edit&SID=".$row_quotes['id'].$rurl;
$SO_VIEW="index.php?route=DealerDistrbutions/POORDER/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.png" width="10px"  height="10" /></a>&nbsp;-->
  <?php if($_SESSION['frmView']=='1') { ?>
			<a href="<?php echo $SO_VIEW; ?>"><img src="images/search.gif" height="15" width="15" /></a>
			<?php }
			else { ?><a href="<?php echo $SO_VIEW; ?>" onclick="return false;" title="No Permission"><img src="images/search.gif" height="15" width="15" /></a><?php } ?>
   
   </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><?php echo $s->getField('dbl_dealer','id',$row_quotes['dealerid'],'dealer_name'); ?></td>
        <td><?php if($row_quotes['soid']!="0") {$odate=$s->getField('salesorder','id',$row_quotes['soid'],'orderDate'); echo ConvertSQLDate($odate); }?> </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  echo $s->getField('www_users','id',$row_quotes['createdBy'],'realname');?></td>
        <td style="padding-left:5px; padding-right:5px;"><?php if($row_quotes['sostatus']!=0){ echo "SO CREATED";} else{ ?><a href="index.php?route=CRM/frnchise_direct_order&modid=<?php echo $_REQUEST['modid']?>&frmid=<?php echo  $_REQUEST['frmid']?>&poid=<?php echo $row_quotes['id'] ?>">                
                <input type="button" value="CONVERT INTO SO" /></a></td>
        <?php } $i++; }  }
   else
   {?>
   	<tr>
   	<td colspan="8">
   	<font color="#FF0000"><?php echo "No Records Found"; ?></font></td>
   		</tr>
  <?php }?>
</table>
</form>
</div>
</div>