<?php 
include "config.php";
session_start();
$user=$_SESSION['log'];
$code = $_POST['code'];
$date = $_POST['date'];
$time = $_POST['time'];
$customer = $_POST['customer'];
$total_amount = $_POST['totalamount'];
$pending_amount=$_POST['pendingamount'];
$payment_method = $_POST['paymentmethod'];
$cash = $_POST['cash']; 
$other_cash=$_POST['othercash'];
$cheque = $_POST['cheque'];
$remark = $_POST['remark'];
$financial_year = $_POST['financialyear'];
$invoice = $_POST['invoice'];
$upi_number = $_POST['upi_number'];
$update = mysqli_query($connect,"update creditdetails set status='deleted',editdate=CURRENT_DATE(),edittime=CURRENT_TIME() where code ='$code'");
$code_validate = mysqli_query($connect,"select count(code) as code from creditdetails where code='$code' && status!='deleted'");
$code_count=mysqli_fetch_assoc($code_validate);
$code_val = $code_count['code'];
if($code_val==0)
{
$sql = "INSERT INTO creditdetails(date, customer,sales_code, totalamount, pendingamount,paymentmethod,amount, otheramount,upi_number, remark, cheque, code, user, time,financialyear, editdate, edittime, status) VALUES ('$date','$customer','$invoice','$total_amount','$pending_amount','$payment_method','$cash','$other_cash','$upi_number','$remark','$cheque','$code','$user','$time','$financial_year','','','')";
echo $sql;
 $go = mysqli_query($connect,$sql);
}
 header('Location:credit.php');

?>