<?php
session_start();
require_once 'includes/database.php';
include 'includes/funcs.php';
$db=new MySQLDatabase();
$db->open_connection();
$user = $_SESSION['reusername'];

if(isset($_REQUEST['cname'])){	
$cname = strtoupper($_REQUEST['cname']);	
$idate = substr($_REQUEST['idate'],6,4)."-".substr($_REQUEST['idate'],3,2)."-".substr($_REQUEST['idate'] ,0,2);
$am = $_REQUEST['am'];		$ic = $_REQUEST['ic'];		$invno = $_REQUEST['i'];
$rmks = trim($_REQUEST['rmks']);
if($invno === '0'){ $invno = getnewno("invno");
					$query = "INSERT INTO othinvoices (cname, invno, idate, rmks, amount, invoicecredit, us, ts) VALUES ('".$cname."', ".$invno.", '".$idate."', '".$rmks."', ".$am.", ".$ic.", '".$user."', '".date("Y-m-d H:i:s")."');";
}
else { $query = "UPDATE othinvoices SET cname = '$cname', amount = '$am', rmks = '$rmks', idate = '$idate' WHERE invno = '$invno'"; }														
$result = mysqli_query($db->connection, $query) or die(mysqli_error($db->connection) ); 														
$db->close_connection();
echo $invno;  
}


?>