<?php 
ob_start();
$PageSecurity = 2;
$title = _('Purchase Bill Book List');

if($_REQUEST['DelId'])
{
  $mrnid=$s->getField('purchase_billbook','id',$_REQUEST['DelId'],'mrn_no');   
  $cond="purch_billbookid='".$_REQUEST['DelId']."'";
	$s->DeleteRecord('purchase_bill_details',$cond);
	$condition="id='".$_REQUEST['DelId']."'";
	$s->DeleteRecord('purchase_billbook',$condition);
	
	$data1['mrnstatus']='Pending';
	$cond1="id='".$mrnid."'";   
   
	$s->RecordEdit('addmrn',$data1,$cond1);	
  $s->RecordEdit('addmrn',$data1,$cond1); 
  $accout_id=$s->GetFieldValue("account_book","trans_type_id='".$_REQUEST['DelId']."' and trans_type='PURCHASE BILL'",'id');
  $accountid="id='".$accout_id."'";
  $s->DeleteRecord('account_book',$accountid);
  $condition_acc="account_bookid='".$accout_id."'";
  $s->DeleteRecord('account_book_details',$condition_acc);
	
	//$s->pageLocation("index.php?route=PurchBillBook_list".$rurl);
}
?>
<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div"> 
<h1>Purchase Bill Book</h1>
<p align="left"><a href="index.php?route=pend_mrn&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>"><input type="button" value="ADD PROCESS BILL" class="search" /></a></p>
<form method="post" action="">  
<table width="100%" cellpadding="3" cellspacing="0" border="0" align=""> 
<tr class="row1"> 
  <td width="13%" align="right"><strong>Branch:</strong></td> 
  <td width="20%"><select name="Site" id="Site"> 
      <option value="0">--Select--</option> 
      <?php 
      $SiteName=DB_query("Select * from locations where mst_companyid='".$_SESSION['ACGCompanyId']."' and loccode in('".$_SESSION['AssignedBranch']."')",$db); 
      while($SiteRow=DB_fetch_array($SiteName)) 
      { ?> 
      <option value="<?php echo $SiteRow['loccode']?>"<?php echo($_REQUEST['Site']==$SiteRow['loccode']?'selected':'');?>><?php echo $SiteRow['locationname']?></option>   
         
    <?php } ?> 
    </select> 
  </td>    
  <td width="13%" align="right"><strong>From Date:</strong></td> 
  <td width="20%"><input type="text" name="fdate" id="fdate"  class="datepicker" value="<?php echo $_REQUEST['fdate']?>"/></td> 
  <td width="13%" align="right"><strong>To Date:</strong></td> 
  <td><input type="text" name="todate" id="todate" class="datepicker"  value="<?php echo $_REQUEST['todate']?>"  /></td> 
</tr> 
<tr class="row1"> 
  <td colspan="6" style="text-align:center;"><input name="Go" type="submit" value="Search" onclick="return frmvalidate()" class="search" /></td> 
</tr> 
</table>
</form>
<form name="" method="post">
<table border="1" cellpadding="3" cellspacing="0" width="100%" style="border:1px #808080 solid;">
<tr>
	<th width="15%">Branch</th>
	<th>Vendor</th>  
	<th width="10%">MRN No.</th>
	<th width="10%">Purchase Voucher No.</th>
	<th width="10%">Bill No.</th>
	<th width="10%">Challan No.</th>
	<th width="6%">Bill Date</th>
	<th width="10%">Grand Total</th>
	<!-- <th>View</th>-->
	<th width="4%" style="text-align:center;">Edit</th>
	<th width="4%" style="text-align:center;">Delete</th>
</tr>
<?php
/*$sql = "select * from  purchase_billbook where bill_book_date between '".$_SESSION['financialYrStart']."' 
 and '".$_SESSION['financialYrEnd']."'  ";*/
 
 $sql = "select * from  purchase_billbook where created_date='".date('Y-m-d')."' and PV_Type!='Direct'";
 if(isset($_POST['Go'])) 
{ 
  $fromdate=$_REQUEST['fdate']; 
  $todate=$_REQUEST['todate']; 
  $fromdate_brk=explode('/',$fromdate); 
  $from=$fromdate_brk[2]."-".$fromdate_brk[1]."-".$fromdate_brk[0]; 
  $todate_brk=explode('/',$todate); 
  $to=$todate_brk[2]."-".$todate_brk[1]."-".$todate_brk[0]; 
  $sql="Select * from purchase_billbook  where  PV_Type!='Direct'"; 
  if($_REQUEST['Site']!="") 
  { 
    $sql .=" AND site='".$_REQUEST['Site']."'";   
       
  } 
  if($_REQUEST['fdate']!="" && $_REQUEST['todate']!="") 
  { 
      $sql .=" AND created_date BETWEEN '".$from."' and '".$to."' ";         
  }  
} 
$result=DB_query($sql, $db);
$i=0;
while($myrow=DB_fetch_array($result))
  {
    
    /* ------------------------- Check For Finance Entry ---------------------------------------------  */

    $sql_check_finance_entry="select * from account_book where trans_type_id='".$myrow['id']."' and trans_type='PURCHASE ADJ' and cancel_status='0' ";
    $result_check_finance_entry=DB_query($sql_check_finance_entry,$db);
    $count_rows=DB_num_rows($result_check_finance_entry);

    ?>
<tr bgcolor="#fff">
	<td><?php 
	$site_sql=DB_query("Select locationname from locations where loccode='".$myrow['site']."'",$db);
	$site_row=DB_fetch_array($site_sql);
	echo $site_row['locationname']?></td>
	<td><?php 
	$vendor_sql=DB_query("Select vendor_name,vendor_type from suppliers where id='".$myrow['vendor']."'",$db);
	$vendor_row=DB_fetch_array($vendor_sql);
	echo $vendor_row['vendor_name']?></td> 
	<td><?php 
	$mrn_sql=DB_query("Select MRNNo from addmrn where id='".$myrow['mrn_no']."'",$db);
	$mrn_row=DB_fetch_array($mrn_sql);
	// echo $mrn_row['MRNNo'];	  
	if($myrow['mrn_no']!=0)
	echo $mrn_row['MRNNo'];
	else echo "N/A";
	
	?></td>
	<td><?php echo $myrow['bill_book_no']?></td>  
	<td><?php echo $myrow['bill_no'];?></td>
	<td><?php echo $myrow['challan_no'];?></td>
	<td><?php echo ConvertSQLDate($myrow['bill_book_date']);?></td>
	<td style="text-align:right;"><?php echo $myrow['GrandTotal'];?></td>
  <td style="text-align:center;">
  <?php if($count_rows!=0) { if($vendor_row['vendor_type']=='International') { ?><img src="images/icon-edit.png" width="15" style="opacity:0.40;" height="15" title="No Permission" />
  <?php } else { ?>
   <img src="images/icon-edit.png" height="15" width="15" style="opacity:0.40;" title="No Permission" /><?php } } else { if($vendor_row['vendor_type']=='International') {?> <a href="index.php?route=Edit_DirectpurchBillBook&action=Edit&editId=<?php echo $myrow['id'];?>&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>"><img src="images/icon-edit.png" width="15" height="15" title="Edit" /></a>
  <?php } else { ?>
<a href="index.php?route=purchbillverify_edit&action=Edit&editId=<?php echo $myrow['id'];?>&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>"><img src="images/icon-edit.png" height="15" style="" width="15" title="Edit" /></a><?php } } ?></td>
	<td style="text-align:center;"><?php if($count_rows<0) { ?><a href="index.php?route=PurchBillBook_list&DelId=<?php echo $myrow['id'];?>&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>"><img src="images/Icon_Delete.png" width="15" height="15" onclick="return  confirm('Do you want to delete ?')" title="Delete" /></a><?php } else { ?><img src="images/Icon_Delete.png" width="15" height="15" style="opacity:0.5" title="No Permission" /><?php } ?></td>
</tr>
<?php }?>
</table>
</form>
<script>
  function frmvalidate() 
{ 
  if(document.getElementById("Site").value==0) 
  { 
      alert("Select Site"); 
      document.getElementById("Site").focus(); 
      return false; 
  } 
}
</script>

</div>
</div>