<?php

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


$createdby      = $_SESSION['username'];

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

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

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

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

$bank_name   = stripslashes($_POST['bank_name']);
$handover   = stripslashes($_POST['handover']);
$transactionno   = stripslashes($_POST['transactionno']);

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


$purchaseID   = $_POST['purchase_bill_no'];

$amount   = $_POST['amount'];
$pbillamount=$_POST['pbillamount'];

$itemcount      = count($purchaseID);

$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_headerwo 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 = "paypurchaseDashboardwo.php";</script>
<?php
		

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


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

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



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

?>