<?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('dbl_direct_po_details', $cond);
	
	$cond="id='".$_REQUEST['quotationid'][$i]."'";
	$row= $s->DeleteRecord('dbl_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>
<style type="text/css">

a{
color: #171717;
text-decoration: none;

}
a:hover{
color: #fff;

text-decoration: none;
}

#wrapper{
width:98%;
margin:auto;
}
.box{
background: #fff;

}
.boxholder{
clear: both;
padding: 5px;
border:#737373 5px solid;
padding-bottom:15px;

}
.tab{
float:left;
height:32px;
width:125px;
margin:0 1px 0 0;
text-align: center;
background:url(images/greentab.jpg) no-repeat;
}
.tabtxt{
margin: 0;
color: #fff;
font-size: 12px;
font-weight: bold;
padding: 9px 0 0 0;d

}
</style>
<script type="text/javascript" src="js/prototype.lite.js"></script>
<script type="text/javascript" src="js/moo.fx.js"></script>
<script type="text/javascript" src="js/moo.fx.pack.js"></script>
<script type="text/javascript">
function init(){
	var stretchers = document.getElementsByClassName('box');
	var toggles = document.getElementsByClassName('tab');
	var myAccordion = new fx.Accordion(
		toggles, stretchers, {opacity: false, height: true, duration: 600}
	);
	//hash functions
	var found = false;
	toggles.each(function(h3, i){
		var div = Element.find(h3, 'nextSibling');
			if (window.location.href.indexOf(h3.title) > 0) {
				myAccordion.showThisHideOpen(div);
				found = true;
			}
		});
		if (!found) myAccordion.showThisHideOpen(stretchers[0]);
}
</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>
	<td>
	<select name="site"  style="width:150px;">
	<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 class="tabledata1">To:</td>
	<td><input name="todate" type="text"  class="datepicker" style="width:150px;"/></td>
	</tr>
	<tr class="row1">
	<td class="tabledata1">From:</td>
	<td colspan="3"><input name="fromdate" type="text"  class="datepicker" style="width:150px;"/></td>
	</tr>
	<tr class="row1">
	<td colspan="4"><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>
<div id="wrapper">
<div id="content">
<h3 class="tab" title="first" style="padding:0px;border:none;"><div class="tabtxt"><a href="#">PROCESS PO</a></div></h3>
<h3 class="tab" title="second" style="border:none; padding:0px;"><div class="tabtxt"><a href="#">DIRECT PO</a></div></h3>
<div class="boxholder">

<div class="box">
<fieldset><legend style="font-size:13px;"><strong>PROCESS PO</strong></legend>
<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">Type</th>	
                <th class="tabledata">SO No.</th>
                <th class="tabledata">SO Date</th>
                <th class="tabledata">Vendor</th>
                <th class="tabledata">Client</th>
		<th class="tabledata">Delivery Date</th>
		<th class="tabledata">Basic Amount</th>
		<th class="tabledata">Status</th>
                <th class="tabledata">Created By</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);
      $GetLead="select * from direct_po where  $filter1 ";
      if(isset($_SESSION['dealerid']))
      {
	 $query="select * from direct_po where  CompanyId='".$_SESSION['ACGCompanyId']."' and type='with_so' and dealerid='".$_SESSION['dealerid']."' and $filter1 ";
	}
        else
        {
             $query="select * from direct_po where  CompanyId='".$_SESSION['ACGCompanyId']."' and type='with_so' and dealerid='0' and $filter1 ";
        }
}
}
else 
{

    if($_SESSION['dealerid']!="")
    {
$i=1;
    $query= "select * from direct_po where  CompanyId='".$_SESSION['ACGCompanyId']."' and dealerid='".$_SESSION['dealerid']."' and type='with_so' order by id desc";
    
    }
    else
    {
       $query=  "select * from direct_po where  CompanyId='".$_SESSION['ACGCompanyId']."' and type='with_so' and dealerid='0'";
    }
}
//}
//echo $query;
$getlead=DB_query($query,$db);
$s=new db_query();

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']?>" />
  <!--<?php if($_SESSION['frmEdit']=='1') { ?>
			<a href="<?php echo $SOURL;?>"><img src="images/icon_edit.gif" height="28" width="15" /></a>
			<?php }
			else { ?><a href="<?php echo $SOURL;?>" onclick="return false;" title="No Permission"><img src="images/icon_edit.gif" height="28" width="15" /></a><?php } ?>&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 style="padding-left:5px; padding-right:5px;"><?php	if($row_quotes['type']=="with_so") echo "Against SO"; else echo "Direct PO"; ?></td>
 	<td><?php echo $s->getField('salesorder','id',$row_quotes['soid'],'orderNo'); ?></td>
        <td><?php if($row_quotes['soid']!="0") {$odate=$s->getField('salesorder','id',$row_quotes['soid'],'orderDate'); echo ConvertSQLDate($odate); }?> </td>
 	<td><?php echo $s->getField('suppliers','id',$row_quotes['vender_id'],'vendor_name'); ?></td>
        <td><?php echo $s->getField('clientmaster','id',$s->getField('salesorder','id',$row_quotes['soid'],'client'),'c_name'); ?></td>
 		<td style="padding-left:5px; padding-right:5px;"><?php  echo ConvertSQLDate($row_quotes['delivery_date']); ?></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 "status" ;?></td>
        <td style="padding-left:5px; padding-right:5px;"><?php  echo $s->getField('www_users','id',$row_quotes['createdBy'],'realname');?></td>
   <?php $i++; }  }
   else
   {?>
   	<tr>
   	<td colspan="12">
   	<font color="#FF0000"><?php echo "No Records Found"; ?></font></td>
   		</tr>
  <?php }?>
</table>

</fieldset>
</div>

<div class="box">
<fieldset><legend style="font-size:13px;"><strong>Direct PO</strong></legend>

<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">Type</th>	           
                <th class="tabledata">Vendor</th>
		<th class="tabledata">Delivery Date</th>
		<th class="tabledata">Basic Amount</th>
		<!--<th class="tabledata">Status</th>-->
                <th class="tabledata">Created By</th>
	
	</tr>
<?php 
if($_REQUEST['Search'])
{	
$todate=ConvertSQLDate($_REQUEST['todate']);
$fromdate=ConvertSQLDate($_REQUEST['fromdate']);
$site=$_REQUEST['site'];
	if($_REQUEST['todate']!='' && $_REQUEST['fromdate']!='' )
	{
		$filter2[]="pr_date between '".$fromdate."' and '".$todate."'";
	}
 	if($_REQUEST['site']!='0')
	{
		$filter2[]="site='".$site."'";
	}
        
        if($_REQUEST['site']=='0')
	{
		$filter2[]="1=1";
	}
	
if($filter2!='')
{
	$filter2=implode(" and ",$filter);
      
      if(isset($_SESSION['dealerid']))
      {
	 $query="select * from direct_po where  CompanyId='".$_SESSION['ACGCompanyId']."' and type='direct' and dealerid='".$_SESSION['dealerid']."' and $filter2";
	}
        else
        {
             $query="select * from direct_po where  CompanyId='".$_SESSION['ACGCompanyId']."' and type='direct' and dealerid='0' and $filter2 ";
        }
}
}
else 
{

    if($_SESSION['dealerid']!="")
    {
$i=1;
    $query= "select * from direct_po where  CompanyId='".$_SESSION['ACGCompanyId']."' and dealerid='".$_SESSION['dealerid']."' and type='direct' order by id desc";
    
    }
    else
    {
       $query=  "select * from direct_po where  CompanyId='".$_SESSION['ACGCompanyId']."' and type='direct' and dealerid='0'";
    }
}
//}
//echo $query;
$getlead=DB_query($query,$db);
$s=new db_query();

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 style="padding-left:5px; padding-right:5px;"><?php	if($row_quotes['type']=="with_so") echo "Against SO"; else echo "Direct PO"; ?></td>
 	
            <td><?php 
             $vendorArray=explode('--', $row_quotes['vender_id']);
             //print_r($vendorArray);
             if($vendorArray[1]=='s')
             {
                echo  $s->getField('companies','CompanyId',$vendorArray[0],'CompanyName');
             }
 else {
      $s->getField('suppliers','id',$vendorArray[0],'vendor_name');
 }
             ?></td>
 		<td style="padding-left:5px; padding-right:5px;"><?php  echo ConvertSQLDate($row_quotes['delivery_date']); ?></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 "status" ;?></td>-->
        <td style="padding-left:5px; padding-right:5px;"><?php  echo $s->getField('www_users','id',$row_quotes['createdBy'],'realname');?></td>
   <?php $i++; }  }
   else
   {?>
   	<tr>
   	<td colspan="8">
   	<font color="#FF0000"><?php echo "No Records Found"; ?></font></td>
   		</tr>
  <?php }?>
</table>
</fieldset>
</div>
    
  <script type="text/javascript">
	Element.cleanWhitespace('content');
	init();
</script>

</div>


		
	<div style="clear:both;"></div>
	</div>
</div>
</form>
</div>
</div>