<?php 
session_start();
include 'dbc.php';

date_default_timezone_set("Asia/Karachi");

$userid=$_SESSION["userid"];

$ven_name=$_POST["ven_name"];
$date=$_POST["date"];
$acc_name_dr=$_POST["acc_name_dr"];
$month_name=$_POST["month_name"];
$username=$_POST["username"];
$amount=$_POST["amount"];
$remarks=$_POST["remarks"];
$sqlpur = "SELECT * FROM vendor where ven_name = '$ven_name' and user_id = '$userid'";
$resultpur=$conn->query($sqlpur);
$rowpur = $resultpur->fetch_assoc();
$venid=$rowpur['id'] ;

$sql = "Insert into payment (id,date,month_name,ven_name,username,user_id,netamount,venid,remarks) values (null,'$date','$month_name','$ven_name','$username','$userid','$amount','$venid','$remarks')";
$conn->query($sql);
$last_id = $conn->insert_id;
$sql1 = "Insert into ven_ledger (id,date,month_name,tr_no,ven_name,discription,acc_type,dr_amount,cr_amount,user_id) values (null,'$date','$month_name','$last_id','$ven_name','$remarks','$username','$amount','0','$userid')";
$conn->query($sql1);
$sqlc = "SELECT * FROM chartofaccounts where acc_name = '$acc_name_dr' and  user_id='$userid'";
$resultc=$conn->query($sqlc);
$rowc = $resultc->fetch_assoc();
$acc_symb=$rowc['acc_symb'] ;
$acc_type=$rowc['acc_type'] ;
$sql101 = "Insert into acc_ledger (id,date,month_name,tr_no,acc_name,discription,acc_type,dr_amount,cr_amount,balance,user_id,acc_symb) values (null,'$date','$month_name','$last_id','$acc_name_dr','$remarks','$acc_type','0','$amount','0','$userid','$acc_symb')";
$conn->query($sql101);
header("location:Add_Payment.php");

?>
