<?php

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


$sqlInvoiceCount = mysqli_query($conn,"SELECT count(*) as invoice FROM cash_expense_entry where status=''");
 
$rowInvoiceCount=mysqli_fetch_array($sqlInvoiceCount,MYSQLI_ASSOC);

$invoice   = $rowInvoiceCount['invoice']+1;

$cashno   = $invoice;

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

$expensedate   = new DateTime(stripslashes($_POST['expensedate']));
$expensedate   = $expensedate->format('Y-m-d');
$expensetype   = stripslashes($_POST['expensetype']);

$expenser   = stripslashes($_POST['expenser']);
$expense_details   = stripslashes($_POST['expense_details']);

$amount   = stripslashes($_POST['amount']);
$remark   = stripslashes($_POST['english_remark']);



$msql2=mysqli_query($conn,"select * from employee_master where id='".$expenser."'");
        
		while($rw2=mysqli_fetch_array($msql2))
		{
			
		$ename=$rw2['ename'];
		
			
		}


$count=0;
$check_query	= mysqli_query($conn,"SELECT count(cashno) as counts FROM cash_expense_entry WHERE cashno = '$cashno' and status='' "); // 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 cash_expense_entry CHANGE id id INT(11) NOT NULL AUTO_INCREMENT ");


$sql  = "INSERT INTO cash_expense_entry(cashno, expensedate, expensetype, expenser,empname,expense_details, amount,remark,status, flag,accountyear) VALUES ('$cashno','$expensedate','$expensetype','$expenser','$ename','$expense_details','$amount','$remark','', '1','$accountyear')";

mysqli_query($conn,$sql);

header("Location:expenseEntryDashboard.php");

}


?>