<?php
require_once 'includes/database.php';
require_once 'includes/funcs.php';
session_start();
$user = $_SESSION['reusername'];
$db=new MySQLDatabase();
$db->open_connection();
if (intval($_REQUEST['dexpno']) > 0){
	$am = mysqli_real_escape_string($db->connection, $_REQUEST['am']); 
	$rmks = $_REQUEST['rmks']; 
	$expacc= $_REQUEST['expacc'];
	$bacc = $_REQUEST['bacc']; 
	$pmode = $_REQUEST['pmode']; 
	$chqno = $_REQUEST['chqno']; 
	$dexpno = $_REQUEST['dexpno']; 
	$ts = date("Y-m-d H:i:s");
    $ddate = substr($_REQUEST['ddate'],6,4)."-".substr($_REQUEST['ddate'],3,2)."-".substr($_REQUEST['ddate'] ,0,2); 
    $query = "UPDATE dexptrans SET ddate='$ddate', rmks='$rmks', amount ='$am', pmode = '$pmode', chqno = '$chqno', expacc='$expacc', bacc='$bacc', ts='$ts', us='$user' WHERE dexpno = '$dexpno';";
     if(!mysqli_query($db->connection, $query)){  echo 'nothing';  } 
}
else {
   $am = mysqli_real_escape_string($db->connection, $_REQUEST['am']); 
            $rmks = mysqli_real_escape_string($db->connection, $_REQUEST['rmks']); 
            $expacc= mysqli_real_escape_string($db->connection, $_REQUEST['expacc']);
			$bacc = mysqli_real_escape_string($db->connection, $_REQUEST['bacc']); 
			$pmode = mysqli_real_escape_string($db->connection, $_REQUEST['pmode']); 
			$chqno= mysqli_real_escape_string($db->connection, $_REQUEST['chqno']);
			$dexpno = getnewno('dexpno');
            $ts = date("Y-m-d H:i:s");
			$dd = mysqli_real_escape_string($db->connection, $_REQUEST['ddate']);
            $ddate = substr($dd,6,4)."-".substr($dd,3,2)."-".substr($dd,0,2); 
            $query = "INSERT INTO dexptrans (dexpno, ddate, amount, expacc, bacc, pmode, chqno, rmks, ts, us) VALUES ('".$dexpno."', '".$ddate."', ".$am.", '".$expacc."', '".$bacc."', '".$pmode."', '".$chqno."', '".$rmks."', '".$ts."', '".$user."');";

            if(!mysqli_query($db->connection, $query)){ echo 'nothing';  }
}
	echo "<script>window.location.replace('expvchprint.php?dno=".$dexpno."&pd=".$ddate."&am=".$am."&pm=".$pmode." - ".$chqno."&rmks=".$rmks."&dacc=".$expacc."&bacc=".$bacc."');</script>";			   
    $db->close_connection();
  
?>	