<?php

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

//require_once("checkLoginStatus.php"); 
$createdby      = $_SESSION['username'];

$cashno   = stripslashes($_POST['invoice']);
$collectiondate   = new DateTime(stripslashes($_POST['invoicedate']));
$collectiondate 		= $collectiondate->format('Y-m-d');
$supplierid   = stripslashes($_POST['supplierid']);

$pending   = stripslashes($_POST['tamount']);

$ramount   = stripslashes($_POST['payamount']);

$paymenttype   = stripslashes($_POST['paymenttype']);
$paymentreference   = stripslashes($_POST['payreference']);

$bank_name   = '';
$handover   = '';
$transactionno   = '';

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




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

$accountyear    = $financialYearStart."-".$financialYearEnd;

$msql2=mysqli_query($conn,"select * from supplier_master where id='".$supplierid."'");
        
		while($rw2=mysqli_fetch_array($msql2))
		{
			
		$cname=$rw2['sname'];
			
		}
		
		
		
		$count=0;
$check_query	= mysqli_query($conn,"SELECT count(cashno) as counts FROM supplier_payment_header WHERE cashno = '$cashno' 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 = "paypurchaseDashboard.php";</script>
<?php
		

}		
else
{
	
	$autoinc=mysqli_query($conn,"ALTER TABLE supplier_payment_header CHANGE id id INT(11) NOT NULL AUTO_INCREMENT ");



$sqlh  = "INSERT INTO supplier_payment_header (cashno,collectiondate,supplierID, paymenttype,paymentreference ,bank_name,handover,transactionno,remark,paidby,received_amount,saleid,payment_through,status,flag,accountyear) VALUES ('$cashno','$collectiondate','$supplierid','$paymenttype','$paymentreference','$bank_name','$handover','$transactionno','$remark','$createdby','$ramount','0','Accounts','','1','$accountyear')";

//echo $sql;
mysqli_query($conn,$sqlh);




header("Location:paypurchaseDashboard.php");
}

?>