<?php
$PageSecurity = 2;
$title = _('Bank Receipt Register');
include('includes/SQL_CommonFunctions.inc');
$PrefixID = $_GET['PrefixID'];
echo $PrefixID;
?><head>
<h2 align="center"><?php echo $title;?></h2>
<p align="center">&nbsp;</p>
<form action="" method="post">
<table width="100%" border="0" cellspacing="2" cellpadding="5">
<tr>
    <td><table width="40%" border="0" cellspacing="1" cellpadding="2" align="center">
      <tr>
        <th><strong>SITE</strong></tH>
        <td colspan="3">
		<select name="site" id="site">
		<option value="">---Select Site---</option>
		<?php 
		$site_sql = "Select loccode, locationname from locations";
		$site_result = DB_query($site_sql, $db);
		while($site_row	= DB_fetch_array($site_result))
		{ 
			$p='';
			if($site_row['loccode']==$_POST['site'])
			$p="selected";
		?>
		<option value="<?php echo $site_row['loccode'];?>" <?php echo $p;?>><?php echo $site_row['locationname'];?></option>		
		<?php 
		}
		?>
		</select>
		</td>
      <tr>
        <tH><strong>FROM</strong></tH>
        <td><input type="text" name="fromdate" value="<?php echo $_POST['fromdate']; ?>" id="fromdate" class="datepicker" size="12"></td>
        <th><strong>TO</strong></th>
        <td><input type="text" name="todate" value="<?php echo $_POST['todate']; ?>" id="todate" class="datepicker" size="12"></td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td><table width="40%" border="0" cellspacing="1" cellpadding="2" align="center">
      <tr>
        <th><strong>BANK</strong></th>
        <td><select name="bank" id="bank">
		<option value="">---Select---</option>
		<?php 
		echo $query = "SELECT A.GroupId,B.AccountName,B.AccountsID from accountgroupmaster A ,accountledger B where A.GroupId=19 and B.UnderGroup=A.GroupId and B.AccountName!='Cash In Hand' ";
		$result = DB_query($query,$db);
		while($row = DB_fetch_array($result))
		{ 
		    $p='';
			if($row['AccountsID']==$_POST['bank'])
			$p="selected";
		?>
		<option value="<?php echo $row['AccountsID'];?>" <?php echo $p;?>><?php echo $row['AccountName'];?></option>
		<?php } ?>
		</select></td>
      </tr>
    </table>
      <p>&nbsp;</p>
      <p align="center"> 
      <input type="submit" name="add" value="Add In Schedule">
					  <input type="submit" name="view" value="View">
					  <input type="submit" name="print" value="Print">
    <input type="submit" name="cancel" value="Cancel"></p></td>
</tr>
</table>
</form>
<hr>
<form action="" method="post">
  <table width="100%" border="0" cellspacing="2" cellpadding="2">
    <tr>
      <th scope="col"><strong>VOUCHER DATE </strong></th>
      <th scope="col"><strong>VOUCHER NO.</strong></th>
      <th scope="col"><strong>SUB LEDGER/PARTY </strong></th>
      <th scope="col"><strong>AMOUNT(INR)</strong></th>
      <th scope="col"><strong>CHEQUE NO. </strong></th>
      <th scope="col"><strong>BANK</strong></th>
      <th scope="col"><strong>NARRATION</strong></th>
    </tr>
	 <?php if($_REQUEST['view']){
$fordate = $_POST['fromdate'];
$todate = $_POST['todate'];
$fromdate = explode("/", $fordate);
$daydate = $fromdate['0'];
$Monthdate = $fromdate['1'];
$yeardate = $fromdate['2'];
$fdate = $yeardate."-".$Monthdate."-".$daydate;
					   
$tredate   = explode("/", $todate);
$dayda     = $tredate['0'];
$Monthda   = $tredate['1'];
$yearda    = $tredate['2'];
$toyrdate  = $yearda."-".$Monthda."-".$dayda;
	
	$filter=array();
$sql = "select * from cashbankvoucher_master A, cashbankvoucher B where A.voucherMasterId = B.TransId ";

	if($_GET['PrefixID'])
	$filter[]="A.PreFix='".$PrefixID."' ";
	if(isset($_POST['site']) && $_POST['site'] != '')
  	$filter[]="A.BranchID='".$_POST['site']."'";
 	if(isset($_POST['fromdate']) && $_POST['fromdate'] != '' && isset($_POST['todate']) && $_POST['todate'] != '')
 	$filter[]="A.VDate between '".$fdate."' and '".$toyrdate."' ";
 	if(isset($_REQUEST['bank']) && $_REQUEST['bank'] != '')
 	$filter[]="A.CaseBankId = '".$_POST['bank']."'";

if($filter!=''){
	$sql=$sql." and ".implode(" and ",$filter);
 	}	
echo $sql;
//echo "<pre>";
//print_r($_REQUEST);

$res = DB_query($sql,$db);
while($myrow = DB_fetch_array($res))
{ ?>
	  <tr bgcolor="#FFFFFF">
	  <td><?php echo ConvertSQLDate($myrow['VDate']);?></td>
      <td><?php echo $myrow['VoucherNo'];?></td>
      <td><?php 
	  	$ledger_sql = "select AccountName from accountledger where AccountsID='".$myrow['ledger_id']."'";
		$ledger_res = DB_query($ledger_sql,$db);
		$ledger_row = DB_fetch_array($ledger_res);
		$sub_sql = "select SubLedgerName from mastersubledger where LedgerId='".$myrow['sub_ledger_id']."' ";
		$sub_res = DB_query($sub_sql, $db);
		$sub_ledger = DB_fetch_array($sub_res);
		echo $ledger_row['AccountName']." - ".$sub_ledger['SubLedgerName'];
	  ?></td>
      <td><?php echo $myrow['Amount'];?></td>
      <td><?php echo $myrow['cheque_no'];?></td>
	  <td><?php 
	  $bank_sql = "select AccountName from accountledger where AccountsID='".$myrow['CaseBankId']."'";
	  $bank_result = DB_query($bank_sql,$db);
	  $bank_row = DB_fetch_array($bank_result);
	  echo $bank_row['AccountName'];
	  ?></td>
	  <td><?php echo $myrow['narration'];?></td>
	  </tr>
<?php }  }?>
  </table>
</form>
<p align="center">&nbsp;</p>
</head>