<?php

require_once("config/configDB.php"); 
require "financial_year_calculation.php";
require "financial_year_calculation.php";
$accountyear    = $financialYearStart."-".$financialYearEnd;

$cashno   = stripslashes($_POST['cashno']);

$expensedate   = new DateTime(stripslashes($_POST['expensedate']));
$expensedate   = $expensedate->format('Y-m-d');
$expensetype   = stripslashes($_POST['expensetype']);
$expense   = stripslashes($_POST['expense']);
//$paymenttype   = stripslashes($_POST['paymenttype']);
//$silverAQUA   = stripslashes($_POST['silverAQUA']);
//$availableAmount   = stripslashes($_POST['availableAmount']);
$amount   = stripslashes($_POST['amount']);
$expenser   = stripslashes($_POST['expenser']);


$mode   = stripslashes($_POST['mode']);
$remark   = stripslashes($_POST['remark']);

$count=0;
$check_query	= mysqli_query($conn,"SELECT count(cashno) as counts FROM expense_entry WHERE cashno = '$cashno' and accountyear='$accountyear'"); // Check the database


while($row = mysqli_fetch_array($check_query)){
$count=$row['counts'];
}
if($count!=0){
// Already Exsist


		echo "<script> alert ('Data Inserted Success.');</script>";
		?>
<script language="javascript">window.location.href = "expenseEntryDashboard.php";</script>
<?php
		

}		
else
{

$autoinc=mysqli_query($conn,"ALTER TABLE expense_entry CHANGE id id INT(11) NOT NULL AUTO_INCREMENT ");


$sql  = "INSERT INTO expense_entry(cashno, expensedate, expensetype, expense,expenser,  amount,mode,remark, flag,accountyear) VALUES ('$cashno','$expensedate','$expensetype','$expense','$expenser','$amount','$mode','$remark', '1','$accountyear')";

mysqli_query($conn,$sql);

header("Location:expenseEntryDashboard.php");

}


?>