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


$userid=$_SESSION["userid"];
$today=date("Y-m-d");
$from_date=$_POST["from_date"];
$disc=$_POST["disc"];
$amount=$_POST["amount"];
$acc_name_dr=$_POST["acc_name_dr"];
$acc_name_cr=$_POST["acc_name_cr"];
$tr_no=$_POST["tr_no"];

 $sql11 = "select * from chartofaccounts where acc_name='$acc_name_dr' and user_id='$userid'";
   $appl1=mysql_query($sql11) or die("Error : " . mysql_error());
   $app=mysql_fetch_array($appl1);
   $acc_type_dr=$app["acc_type"];
  
   $sql112 = "select * from chartofaccounts where acc_name='$acc_name_cr' and user_id='$userid'";
   $appl12=mysql_query($sql112) or die("Error : " . mysql_error());
   $app2=mysql_fetch_array($appl12);
   $acc_type_cr=$app2["acc_type"];

$sql = "Insert into expense_voucher (id,date,tr_no,acc_name_dr,acc_name_cr,discription,amount,user_id) values (null,'$from_date','$tr_no','$acc_name_dr','$acc_name_cr','$disc','$amount','$userid')";
mysql_query($sql) or die("Error : " . mysql_error());

$sql1 = "Insert into acc_ledger (id,date,tr_no,acc_name,discription,acc_type,dr_amount,cr_amount,balance,user_id) values (null,'$from_date','$tr_no','$acc_name_dr','$disc','$acc_type_dr','$amount','0','0','$userid')";
mysql_query($sql1) or die("Error : " . mysql_error());

$sql13 = "Insert into acc_ledger (id,date,tr_no,acc_name,discription,acc_type,dr_amount,cr_amount,balance,user_id) values (null,'$from_date','$tr_no','$acc_name_cr','$disc','$acc_type_cr','0','$amount','0','$userid')";
mysql_query($sql13) or die("Error : " . mysql_error());
$Message = "Record saved ";
    header("Location:expense_vocher_entry.php?Message={$Message}");
	?>

<a href="expense_vocher_entry.php"> Back </a>