<?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'];
$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, totalamount, pendingamount,paymentmethod,amount, otheramount, remark, cheque, code, user, time,financialyear, editdate, edittime, status) VALUES ('$date','$customer','$total_amount','$pending_amount','$payment_method','$cash','$other_cash','$remark','$cheque','$code','$user','$time','$financial_year','','','')";
echo $sql;
 $go = mysqli_query($connect,$sql);
}
 header('Location:credit.php');

?>