<?php 
error_reporting(0);
$s=new db_query();
global $db;	

$url_add= "index.php?route=purchBillVerify".$rurl;
?>
<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>
<?php
$modification = '<a href="index.php?route=purchBillVerifyEdit&modid='.$_REQUEST['modid'].'&frmid='.$_REQUEST['frmid'].'&ModfingOnly=1&id='.$row_quotes['id'].'&page='.$_REQUEST['page'].'">' . "<img src='images/icon-edit.png' height='15' width='15'>". '</a>';
			
$modification1 = '<a href="index.php?route=purchBillVerifyEdit&modid='.$_REQUEST['modid'].'&frmid='.$_REQUEST['frmid'].'&ModfingOnly=1&id='.$row_quotes['id'].'&page='.$_REQUEST['page'].'">' . "<img src='images/icon-edit.png' height='15' onclick='return false;' title='No Permission' width='15'>". '</a>';
?>
<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">	
<div align="left">
<?php if($_SESSION['frmAdd']=='1'){?>
		<a href="<?php echo $url_add;?>"><input type="button" class="search" value="Add New" /></a>
<?php }?>
</div>
<table width="100%" border="1" cellspacing="0" cellpadding="3">
	<tr class="row1">
		<td class="tabledata">
		<strong>Sr. No.</strong></td>
		<td class="tabledata"><strong>Voucher No</strong></td>
		<td class="tabledata"><strong>V.Date</strong></td>
		<td class="tabledata"><strong>MRN No</strong></td>
		<td class="tabledata"><strong>MRN Date</strong></td>		
		<td class="tabledata"><strong>Vendor</strong></td>
		<td class="tabledata"><strong>PO No</strong></td>
		<td class="tabledata"><strong>PO Date</strong></td>
		
		<td class="tabledata"><strong>PO Type</strong></td>
		<td class="tabledata"><strong>Bill No</strong></td>
		<td class="tabledata"><strong>Bill Date</strong></td>
		<td class="tabledata"><strong>Grand Total</strong></td>
		<td class="tabledata"><strong>Prepared By</strong></td>
		
		<td class="tabledata"><table width="100%" border="0" cellspacing="0" cellpadding="0">
		<tr><td class="tabledata" style="text-align:center;"  colspan="4"><strong>Action</strong></td></tr>
		<tr>
			<td class="tabledata"><strong>Edit</strong></td>
			<td class="tabledata"><strong>View</strong></td>
			<td class="tabledata"><strong>Cancel</strong></td>
			<td class="tabledata"><strong>Delete</strong></td>
		</tr>
		</table></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=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']."' order by id desc";

    $getlead=DB_query("select * from direct_po where  CompanyId='".$_SESSION['ACGCompanyId']."' order by id desc",$db);
}
//}
//Created by ANIL
$s=new db_query();
$resul1  =  DB_query("SELECT *  FROM purchase_verification",$db);
$resul1  =  DB_query("SELECT MRNNO FROM addmrn",$db); 
$resul1  =  DB_query("SELECT vendor_code FROM suppliers",$db);
$resul11 =  DB_query("SELECT *  FROM www_users",$db);
$resul1  =  DB_query("select * from purchase_verification where company_id='".$_SESSION['ACGCompanyId']."' order by id DESC",$db);
$i=0;
//$pcode = DB_query("SELECT prefix_code FROM prefix_tbl WHERE prefix_code='PV' ",$db);
if(DB_num_rows($resul1)>0)
{
	 while($row_quotes=DB_fetch_array($resul1))
	 {	 
		//echo '<pre>'; print_r($row_quotes);		
		$i++;	
	    $prdby=$s->getField('www_users','id',$row_quotes['created_by'],'realname'); 
	    $vname=$s->getField('suppliers','id',$row_quotes['vendor'],'vendor_name');
	    $mrnno=$s->getField('addmrn','id',$row_quotes['mrn_no'],'MRNNo');
	    $vnum=$row_quotes['voucher_no'];
		$vsite=$row_quotes['site'];
		$pcode=$s->getField('prefix_tbl','prefix_code','PV','prefix_code');
	    $vouchercode=$vsite."/".$pcode."/"."00".$vnum;		
		$cancelissue=$s->getField('purchase_verification','id',$row_quotes['id'],'cancel_issue');
        ?>
			<tr bgcolor="#dfdfdf">
			<td style="padding-left:5px; padding-right:5px;"><?php  echo   $i;?></td>
			<td style="padding-left:5px; padding-right:5px;"><?php  echo   $row_quotes['voucher_no']; ?></td>
            <td style="padding-left:5px; padding-right:5px;"><?php  echo ConvertSQLDate($row_quotes['voucher_date']); ?></td>  	
		    <td>
	        <?php echo  $mrnno; ?>
		    </td>
		    <td style="padding-left:5px; padding-right:5px;">
		    <?php	echo ConvertSQLDate($row_quotes['mrn_date']);	?></td>
  		    <td style="padding-left:5px; padding-right:5px;"><?php  echo $vname;?></td>
 	        <td><?php echo $row_quotes['po_no']  ;?></td>
		    <td style="padding-left:1px; padding-right:1px;"><?php echo ConvertSQLDate($row_quotes['po_date']);?></td>
			<td style="padding-left:1px; padding-right:1px;">
			<?php if($row_quotes['po_type']=='1') {echo "Import Order";} elseif($row_quotes['po_type']=='2'){echo "Domestic Order";} elseif($row_quotes['po_type']=='3'){echo "Service Order";} elseif($row_quotes['po_type']=='4'){echo "Asset Order";} ?></td>
			<td style="padding-left:1px; padding-right:1px;"><?php echo $row_quotes['bill_no'];?></td>
			<td style="padding-left:1px; padding-right:1px;"><?php echo ConvertSQLDate($row_quotes['bill_date']);?></td>
			<td style="padding-left:1px; padding-right:1px;"><?php echo $row_quotes['grandtotals'];?></td>
			<td style="padding-left:1px; padding-right:1px;"><?php echo $prdby;?></td>			
			<td style="padding-left:1px; padding-right:11px;">
			<table width="100%" border="0" cellspacing="0" cellpadding="0">
			<tr class="rowdata">
			<td>
			<?php if($_SESSION['frmEdit']=='1' && $row_quotes['approval_status']==0) { 
			echo '<a href="index.php?route=purchBillVerifyEdit&modid='.$_REQUEST['modid'].'&frmid='.$_REQUEST['frmid'].'&ModfingOnly=1&id='.$row_quotes['id'].'">' . "<img src='images/icon-edit.png' height='15' width='15'>". '</a>';}
			
	else{echo '<a href="index.php?route=purchBillVerifyEdit&modid='.$_REQUEST['modid'].'&frmid='.$_REQUEST['frmid'].'&ModfingOnly=1&id='.$row_quotes['id'].'&page='.$_REQUEST['page'].'">' . "<img src='images/icon-edit.png' height='15' onclick='return false;' title='No Permission' width='15'>". '</a>';}?>
			</td>			
			<td>
			<?php if($_SESSION['frmView']=='1') { 
			echo '<a href="index.php?route=purchBillVerifyView&modid='.$_REQUEST['modid'].'&frmid='.$_REQUEST['frmid'].'&ModfingOnly=1&id='.$row_quotes['id'].'">' . "<img src='images/search.gif' height='15' width='15'>". '</a>';}
			
	else{echo '<a href="index.php?route=purchBillVerifyView&modid='.$_REQUEST['modid'].'&frmid='.$_REQUEST['frmid'].'&ModfingOnly=1&id='.$row_quotes['id'].'&page='.$_REQUEST['page'].'">' . "<img src='images/search.gif' height='15' onclick='return false;' title='No Permission' width='15'>". '</a>';}?>
			</td>			
			<td><center>
	<?php 	
	if($_SESSION['frmDelete']=='1')
	{
	if($cancelissue==1) 
	{ 
	?>
			 <input type="button" name="reason"  value="Cancelled" onclick="javascript:popup('ditectpo_cancel_reason.php?modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&id=<?php echo $row_quotes['id'];?>',200,220)">
			 <? } 	else { ?>
			 <a onclick="popup('purch_bill_cancel.php?modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&id=<?php echo $row_quotes['id'];?>',600,200)" href="#" >Cancel</a>
			 	<?php } }else { ?><a onclick="return false;" href="#" title="No Permission">Cancel</a><?php } ?></center>	</td>
			 <td>
		<?php if($_SESSION['frmDelete']=='1'  && $row_quotes['approval_status']==0){?>
		     <a onclick="popup('purch_bill_delete.php?modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&id=<?php echo $row_quotes['id'];?>',600,200)" href="#" >
            <img src="images/Icon_Delete.png" height="15" width="15"></a>
            <?php } else{?>
		
		<a href="index.php?route=Inventory/transation/material_receipt_note_exo_index&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&mrnid=<?php echo $id;?>&action=Delete&site=<?php echo $site; ?>&store=<?php echo $StoreCode ; ?>" onclick="return false;" title="No Permission"><img src="images/Icon_Delete.png" height="15" width="15"></a>
		
		<?php }?>
			
			
			</td>
			</tr>
			</table>
			</td>
			
			
			<?php  }  }
			else
			{?>
   	<tr>
   	<td colspan="8">
   	<font color="#FF0000">
	<?php echo "No Records Found"; ?></font></td>
   		</tr>
  <?php }?>
 
</table>
</form>
</div>
</div>