<?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['newjv']) > 0){
	$am = mysqli_real_escape_string($db->connection, $_REQUEST['am']); 
	$rmks = $_REQUEST['rmks']; 
	$dacc= $_REQUEST['dacc'];
	$cacc = $_REQUEST['cacc']; 
	$jvno = $_REQUEST['newjv']; 
	$ts = date("Y-m-d H:i:s");
    $jdate = substr($_REQUEST['jdate'],6,4)."-".substr($_REQUEST['jdate'],3,2)."-".substr($_REQUEST['jdate'] ,0,2); 
    $query = "UPDATE bktrans SET jdate='$jdate', rmks='$rmks', amount ='$am', dacc='$dacc', cacc='$cacc', ts='$ts', us='$user' WHERE jvno = '$jvno';";
     if(!mysqli_query($db->connection, $query)){
             echo 'nothing';  
         }else{   
          echo $docno; 
	  } 
}
else {
	$am = mysqli_real_escape_string($db->connection, $_REQUEST['am']); 
	$rmks = $_REQUEST['rmks']; 
	$dacc= $_REQUEST['dacc'];
	$cacc = $_REQUEST['cacc']; 
 	$docno = getnewno('jvno');
            $ts = date("Y-m-d H:i:s");
            $jdate = substr($_REQUEST['jdate'],6,4)."-".substr($_REQUEST['jdate'],3,2)."-".substr($_REQUEST['jdate'] ,0,2); 
            $query = "INSERT INTO bktrans (jvno, jdate, rmks, amount, dacc, cacc, ts, us) VALUES ('$docno', '$jdate', '$rmks', '$am', '$dacc', '$cacc', '$ts', '$user');";
            if(!mysqli_query($db->connection, $query)){
                echo 'nothing';  
             }else{   
                echo $docno;
                   }  
}				   
    $db->close_connection();
  
?>	