
<?php
session_start();
require_once 'includes/database.php';

if (!isset($_SESSION['reusername'])) { echo 'Sorry You Dont Have permissions to View this Page!'; exit();}
else {$user = $_SESSION['reusername'];}

    $db=new MySQLDatabase();
    $db->open_connection();
        
 if (isset($_GET['r'])){  
    $dexpno =  $_GET['r'];    
    $query="SELECT * FROM dexptrans WHERE dexpno = '$dexpno'"; 
    $sql = mysqli_query($db->connection, $query) or die(mysqli_error($db->connection) ); 
    while ($row = mysqli_fetch_array($sql, MYSQLI_ASSOC)){
            $amount = -1*floatval($row['amount']); 
            $pmode = $row['pmode']; 
            $rmks = $row['rmks']; 
            $ts = date("Y-m-d H:i:s");
            $bacc = $row['bacc'];
            $chqno = $row['chqno']; 
            $expacc = $row['expacc'];        
            $ddate = $row['ddate'];
            $newno = $dexpno.'R';
      } 
 
    if( $revsd < 1 ){
        $query="INSERT INTO dexptrans (dexpno, ddate, expacc, pmode, chqno, bacc, rmks, amount, us, ts, revsd ) VALUES ('$newno','$ddate','$expacc','$pmode','$chqno','$bacc','$rmks','$amount','$user','$ts', 1 )"; 
        $sql = mysqli_query($db->connection, $query) or die(mysqli_error($db->connection) );   
        $query="UPDATE dexptrans SET revsd = 1 WHERE dexpno = '$dexpno'"; 
        $sql = mysqli_query($db->connection, $query) or die(mysqli_error($db->connection) );
        }
}            
?>
