<?php 
include "config.php";
include "financial_year_calculation.php";
session_start();
$user=$_SESSION['log'];
$code = $_POST['code'];
$date = $_POST['date'];
$givento = $_POST['givento'];
$givenby = $_POST['givenby'];
$given_amount=$_POST['given_amount'];

$avail_cash=$_POST['avail_cash'];
$expense_name=$_POST['expense_name'];

$remark = $_POST['remark'];
$accountyear    = $financialYearStart."-".$financialYearEnd;
$year_code = substr($financialYearEnd,2);

$update = mysqli_query($connect,"update cash_expense set status='deleted',editdate=CURRENT_DATE(),edittime=CURRENT_TIME() where code ='$code'");

$code_validate = mysqli_query($connect,"select count(code) as code from cash_expense where code='$code' && status!='deleted'");
$code_count=mysqli_fetch_assoc($code_validate);
$code_val = $code_count['code'];
if($code_val==0)
{
$sql = "INSERT INTO cash_expense(date,avail_cash,expense_name, givento, givenby, given_amount, remark,  code, user, time,financialyear, editdate, edittime, status) VALUES ('$date','$avail_cash','$expense_name','$givento','$givenby','$given_amount','$remark','$code','$user',CURRENT_TIME(),'$accountyear','','','')";
echo $sql;
 $go = mysqli_query($connect,$sql);
}
  header('Location:expense_handling.php');

?>