<?php

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

$cashno   = stripslashes($_POST['cashno']);
$collectiondate   = new DateTime(stripslashes($_POST['collectiondate']));
$collectiondate 		= $collectiondate->format('Y-m-d');
$supplierid   = stripslashes($_POST['supplierName']);
$purchaseID   = stripslashes($_POST['purchase_bill_no']);
$pending   = stripslashes($_POST['pending']);
$paymenttype   = stripslashes($_POST['paymenttype']);
$paymentreference   = stripslashes($_POST['paymentreference']);
$amount   = stripslashes($_POST['amount']);

$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'];
			
		}
		
		$autoinc1=mysqli_query($conn,"ALTER TABLE supplier_payment CHANGE id id INT(11) NOT NULL AUTO_INCREMENT  ");
$autoinc2=mysqli_query($conn,"ALTER TABLE supplier_statement CHANGE id id INT(11) NOT NULL AUTO_INCREMENT  ");

		
		$count=0;
$check_query	= mysqli_query($conn,"SELECT count(cashno) as counts FROM supplier_payment 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
{

$sql  = "INSERT INTO supplier_payment (cashno,collectiondate,supplierID,pending, paymenttype,amount, purchaseID,paymentreference ,flag,status,accountyear) VALUES ('$cashno','$collectiondate','$supplierid','$pending','$paymenttype','$amount','$purchaseID' ,'$paymentreference','1','','$accountyear')";


mysqli_query($conn,$sql);


header("Location:paypurchaseDashboard.php");

}
?>