<?php


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

function validation_input($data) {
    $data = trim($data);
    $data = stripslashes($data);
    $data = htmlspecialchars($data);
    return $data;
}
if ($_SERVER["REQUEST_METHOD"] == "POST") {

    $edit_id            = validation_input($_POST['edit_id']);
    $invoice            = validation_input($_POST['invoice']);
    $invoicedate_temp   = new DateTime(stripslashes($_POST['invoicedate']));
    $invoicedate 		= $invoicedate_temp->format('Y-m-d');
    $payamount          = validation_input($_POST['payamount']);
    $supplierid          = validation_input($_POST['supplierid']);
    $pay_type          = validation_input($_POST['paymenttype']);
    
     $createdate  	= date("Y-m-d");
	  $createdby      = $_SESSION['username'];
    $userID         = $_SESSION['user_id'];
     
    if($pay_type == 'cash') {
        $paymentreference  = '';
    } else {
        $paymentreference  = validation_input($_POST['paymentreference']);
    }
   
   $deldt2=mysqli_query($conn,"update  supplier_payment set status='DELETED'  where   id='$edit_id' and status=''");	
   
   $autoinc=mysqli_query($conn,"ALTER TABLE supplier_payment CHANGE id id INT(11) NOT NULL AUTO_INCREMENT ");

     $sql_header  = "INSERT INTO supplier_payment ( invoice, invoicedate,supplierid,purchaseid,purchase_type,process, amount, pay_type,paymentreference, status,accountyear,isdelete,createdby,userID,createdate) VALUES ('".$invoice."', '".$invoicedate."', '".$supplierid."','0','Accounts','', '".$payamount."','".$pay_type."', '".$paymentreference."' ,'','".$accountyear."', '1','".$createdby."','".$userID."','".$createdate."')";
    
    mysqli_query($conn,$sql_header);
	
	
        
    header("Location:accOverDashboard.php");

}



?>      