<?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'];
$advance = $_POST['advanceamount'];
$financial_year=$_POST['financialyear'];
$update = mysqli_query($connect,"update debitdetails set status='deleted',editdate=CURRENT_DATE(),edittime=CURRENT_TIME() where code ='$code'");
$code_validate = mysqli_query($connect,"select count(code) as code from debitdetails where code='$code' && status!='deleted'");
$code_count=mysqli_fetch_assoc($code_validate);
$code_val = $code_count['code'];
if($code_val==0)
{
$sql = "INSERT INTO debitdetails(date, customer, totalamount, pendingamount,paymentmethod,amount, otheramount, remark, cheque,advance, code, user, time,financialyear, editdate, edittime, status) VALUES ('$date','$customer','$total_amount','$pending_amount','$payment_method','$cash','$other_cash','$remark','$cheque','$advance','$code','$user','$time','$financial_year','','','')";
echo $sql;
 $go = mysqli_query($connect,$sql);
}
  header('Location:debit.php');

?>