<?php
date_default_timezone_set('Asia/Kolkata');
require_once("config/configDB.php"); 
require "userPermission.php";

$salary_no   = "";
$given_date    = $_POST['given_date'];
$ecode   = $_POST['ecode'];
$employee_name    = $_POST['employee_name'];
$fromDate   = $_POST['fromDate'];
$toDate    = $_POST['toDate'];
$advance   = $_POST['advance'];
$collected_amt    = $_POST['collected_amt'];
$remaining_amt   = $_POST['remaining_amt'];
$total_shift    = $_POST['total_shift'];
$total_ot   = $_POST['total_ot'];
$salary_amount    = $_POST['salary_amount'];
$pending_salary    = $_POST['pending_salary'];

$total_salary   = $_POST['total_salary'];
$paidamount    = $_POST['paidamount'];

$deducted_amt    = $_POST['deducted_amt'];
$cash_hand    = $_POST['cash_hand'];

$givenby    = $_POST['givenby'];


$paytype   = $_POST['paytype'];
$refno    = $_POST['refno'];
$remarks    = $_POST['remarks'];

$createdate  	= date("Y-m-d");
    $createdby      = $_SESSION['username'];
    $userID         = $_SESSION['user_id'];
	
	require "financial_year_calculation.php";
$accountyear    = $financialYearStart."-".$financialYearEnd;

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

$invoice1   = sprintf('%03d',$rowInvoiceCount['invoice']+1);

$acyear="ADVC/".$syr."-".$eyr."/";

$invoice= $acyear.$invoice1;



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

$sql  = "INSERT INTO employee_payment (salary_no, given_date, ecode, employee_name, fromdate, todate, advance_amount, collected_amt, remaining_amt, total_shift, total_ot, salary_amount, pending_salary, total_salary, paidamount,deducted_amt,cash_hand, givenby, paytype, refno,remarks,adv_no,status, createddate, userId, isdelete) VALUES ('$salary_no', '$given_date', '$ecode', '$employee_name', '$fromDate', '$toDate', '$advance', '$collected_amt', '$remaining_amt', '$total_shift', '$total_ot', '$salary_amount', '$pending_salary', '$total_salary', '$paidamount','$deducted_amt','$cash_hand', '$givenby', '$paytype', '$refno','$remarks','$invoice','', '$createdate', '$userID', '1');";

//print_r($sql);die;

mysqli_query($conn,$sql);



$sql_eid=mysqli_query($conn,"select * from employee_master where  ecode='$ecode'");
while($erow=mysqli_fetch_array($sql_eid))
{
$employee_id=$erow['id'];

}

$sql_advanceheader  = "INSERT INTO employee_advance_collection (advance_no, advance_date, employee_id,employeename,advance_amount,advance_collection_amount,paytype,remarks,status, create_date, flag,accountyear) VALUES ('$invoice','$given_date','$employee_id','$employee_name','$advance','$deducted_amt','$paytype','$remarks','','$create_date', '1','$accountyear')";

mysqli_query( $conn, $sql_advanceheader ); 			



$conn->close();

// productID, customerID, driver_name, given_date, prodct_cash, hsn_code, givenby, batta_amount, sale_rate



header("Location:EmployeePaymentDashboard.php");


?>