<?php 
session_start();
$iduser=$_SESSION['user_idd'];
$date = new DateTime("now", new DateTimeZone('Africa/Nairobi') );
$timenow=$date->format('Y-m-d H:i:s');
$timenow2=$date->format('Y-m-d');
$month=$date->format('M');
//$finaldate='Today: '.$date->format('l d M Y - H:i:s');

 include('../include/config.php');
 if(isset($_POST["id"]))
 {
 $cat=addslashes($_POST["cat"]);
 $dat=addslashes($_POST["dat"]);
 $parti=addslashes($_POST["parti"]);
 $amt=addslashes($_POST["amt"]);
 $mod=addslashes($_POST["mod"]);
 $chequ=addslashes($_POST["chequ"]);
 $bank=addslashes($_POST["bank"]);
 $dess=addslashes($_POST["dess"]); 
 $id=addslashes($_POST["id"]); 
 
 $yrr=substr($dat, 0, 4);
 $mm=substr($dat, 5, 2);

if($mm=='01'){$mm='January';}
if($mm=='02'){$mm='February';}
if($mm=='03'){$mm='March';}
if($mm=='04'){$mm='April';}
if($mm=='05'){$mm='May';}
if($mm=='06'){$mm='June';}
if($mm=='07'){$mm='July';}
if($mm=='08'){$mm='August';}
if($mm=='09'){$mm='September';}
if($mm=='10'){$mm='October';}
if($mm=='11'){$mm='November';}
if($mm=='12'){$mm='December';}

$sql=mysqli_query($con,"UPDATE Expenses SET Particular='$parti',Cat='$cat',ExpDate='$dat',Amount='$amt',Mode='$mod',Details='$chequ',Account='$bank',Description='$dess',Year='$yrr',Month='$mm' where id='$id'");
if($sql)
{
$msgg='updated expenditure details';
$sql3=mysqli_query($con,"INSERT INTO activity(user,Action,Tim,Dat,shortmsg,Month)values('$iduser','$msgg','$timenow','$timenow2','update','$month')");
if($sql3)
{ }    
    
echo "success";
}else
{
echo "Error in updaing data";
}
 }else
 {
 $cat=addslashes($_POST["cat"]);
 $dat=addslashes($_POST["dat"]);
 $parti=addslashes($_POST["parti"]);
 $amt=addslashes($_POST["amt"]);
 $mod=addslashes($_POST["mod"]);
 $chequ=addslashes($_POST["chequ"]);
 $bank=addslashes($_POST["bank"]);
 $dess=addslashes($_POST["dess"]);

 $yrr=substr($dat, 0, 4);
 $mm=substr($dat, 5, 2);

if($mm=='01'){$mm='January';}
if($mm=='02'){$mm='February';}
if($mm=='03'){$mm='March';}
if($mm=='04'){$mm='April';}
if($mm=='05'){$mm='May';}
if($mm=='06'){$mm='June';}
if($mm=='07'){$mm='July';}
if($mm=='08'){$mm='August';}
if($mm=='09'){$mm='September';}
if($mm=='10'){$mm='October';}
if($mm=='11'){$mm='November';}
if($mm=='12'){$mm='December';}

$sql=mysqli_query($con,"INSERT INTO Expenses(Particular,Cat,ExpDate,Amount,Mode,Details,Account,Description,Year,Month,User,EntryDate) values('$parti','$cat','$dat','$amt','$mod','$chequ','$bank','$dess','$yrr','$mm','$iduser','$timenow2')");
if($sql)
{
$msgg='added expenditure details';
$sql3=mysqli_query($con,"INSERT INTO activity(user,Action,Tim,Dat,shortmsg,Month)values('$iduser','$msgg','$timenow','$timenow2','update','$month')");
if($sql3)
{ } 
echo "success";
}else
{
echo "Error in saving data";
}
 }

?>