<?php

require_once("config/configDB.php"); 
require "financial_year_calculation.php";

if ($_SERVER["REQUEST_METHOD"] == "POST") {

$advance_no    = stripslashes($_POST['advance_no']);
$advance_date       = new DateTime(stripslashes($_POST['advance_date']));
$advance_date 		= $advance_date->format('Y-m-d');
$employee_id   = stripslashes($_POST['employee_id']);
$advance_amount         = $_POST['advance_amount'];
$advance_collection_amount  = $_POST['advance_collection_amount'];
$transaction_mode         = $_POST['transaction_mode'];
$remarks         = stripslashes($_POST['remarks']);

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

$accountyear    = $financialYearStart."-".$financialYearEnd;
$create_date  	= date("Y-m-d H:i:s"); 


$msql2=mysqli_query($conn,"select * from employee_master where id='".$employee_id."'");
        
		while($rw2=mysqli_fetch_array($msql2))
		{
			
		$employeename=$rw2['ename'];
		
			
		}
		
		
		
		$autoinc=mysqli_query($conn,"ALTER TABLE employee_advance_collection CHANGE id id INT(11) NOT NULL AUTO_INCREMENT ");


		
		
$count=0;
$check_query	= mysqli_query($conn,"SELECT count(advance_no) as counts FROM employee_advance_collection WHERE advance_no = '$advance_no' and accountyear='$accountyear' 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 = "employeeAdvance_collection_Dashboard.php";</script>
<?php
		

}		
else
{

$sql_advanceheader  = "INSERT INTO employee_advance_collection (advance_no, advance_date, employee_id,employeename,advance_amount,advance_collection_amount,transaction_mode,remarks,status, create_date, flag,accountyear) VALUES ('$advance_no','$advance_date','$employee_id','$employeename','$advance_amount','$advance_collection_amount','$transaction_mode','$remarks','','$create_date', '1','$accountyear')";

mysqli_query( $conn, $sql_advanceheader ); 			




header("Location:employeeAdvance_collection_Dashboard.php");

}

}
?>