<?php

require_once("config/configDB.php"); 
$edit_id   = stripslashes($_POST['edit_id']);
$cashno   = stripslashes($_POST['cashno']);
$collectiondate   = new DateTime(stripslashes($_POST['collectiondate']));
$collectiondate 		= $collectiondate->format('Y-m-d');
$customerid   = stripslashes($_POST['customerName']);
$saleID   = stripslashes($_POST['sale_bill_no']);
$pending   = stripslashes($_POST['pending']);
$paymenttype   = stripslashes($_POST['paymenttype']);
$paymentreference   = stripslashes($_POST['paymentreference']);
$amount   = stripslashes($_POST['amount']);

require "financial_year_calculation.php";
$accountyear        = $financialYearStart."-".$financialYearEnd;


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



$msql2=mysqli_query($conn,"select * from customer_master where id='".$customerid."'");
        
		while($rw2=mysqli_fetch_array($msql2))
		{
			
		$cname=$rw2['cname'];
			
		}
		
		$delhdr1=mysqli_query($conn,"update  collection_customer set status='DELETED'  where id='$edit_id' and status=''");
		
		$autoinc1=mysqli_query($conn,"ALTER TABLE collection_customer CHANGE id id INT(11) NOT NULL AUTO_INCREMENT  ");
$autoinc2=mysqli_query($conn,"ALTER TABLE customer_statement CHANGE id id INT(11) NOT NULL AUTO_INCREMENT  ");

		
		$count=0;
$check_query	= mysqli_query($conn,"SELECT count(cashno) as counts FROM collection_customer 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 = "collectionDashboard.php";</script>
<?php
		

}		
else
{

$sql  = "INSERT INTO collection_customer (cashno,collectiondate,customerID,pending, paymenttype,amount, saleID,paymentreference ,flag,accountyear,status) VALUES ('$cashno','$collectiondate','$customerid','$pending','$paymenttype','$amount','$saleID' ,'$paymentreference','1','$accountyear','')";


mysqli_query($conn,$sql);




header("Location:collectionDashboard.php");

}
?>