<?php 
 // echo @$_GET['msg'];
 //  session_start();
 //  if(isset($_SESSION['userId'])){ 
if(isset($_POST['debit'])){
extract($_POST);
$description2 = $description;
require 'connection.php';
$dr = $_POST['debit'];
if($dr!==""){
// Insert into Tr Voucher  table
$dated2=date("Y/m/d");

$supname="SELECT max(tvno) as tvno from trvoucher";
	$suprun=mysqli_query($connect,$supname) or die(mysqli_error($connect));
	$suprow=mysqli_fetch_array($suprun);
	$tvno= $suprow['tvno']+1;
	

 $query="INSERT INTO `trvoucher`( `dated2`,`tvno`, `accid`, `dated`, `amount`, `description`, `posted`, `status`) VALUES('$dated2','$tvno','$accid','$dated','$debit','$description2','Posted','Debit')";
	$result=mysqli_query($connect,$query) or die(mysqli_error($connect));

// Insert into Ledger From Account  table
 $query="INSERT INTO `ledger`(`dated2`,`dated`, `accid`, `comid`, `description`, `vno`, `refno`, `entrytype`, `debit`) VALUES('$dated2','$dated','$accid','5','$description2','$tvno','$tvno','Transfer','$debit')";
	$result=mysqli_query($connect,$query) or die(mysqli_error($connect));

	// Insert into Ledger To Account  table
  $query="INSERT INTO `ledger`(`dated2`,`dated`, `accid`, `comid`, `description`, `vno`, `refno`, `entrytype`, `credit`) VALUES('$dated2','$dated','$accidto','5','$description2','$tvno','$tvno','Transfer','$debit')";
	$result=mysqli_query($connect,$query) or die(mysqli_error($connect));

if($result){
	echo "Voucher Transfer Successfully";
}
}
$cr = $_POST['credit'];
if($cr!==""){

$dated2=date("Y/m/d");

$supname="SELECT max(tvno) as tvno from trvoucher";
	$suprun=mysqli_query($connect,$supname) or die(mysqli_error($connect));
	$suprow=mysqli_fetch_array($suprun);
	$tvno= $suprow['tvno']+1;
	
// Insert into Tr Voucher  table
 $query="INSERT INTO `trvoucher`(`dated2`,`tvno`, `accid`, `dated`, `amount`, `description`, `posted`, `status`) VALUES('$dated2','$tvno','$accid','$dated','$debit','$description2','Posted','Debit')";
	$result=mysqli_query($connect,$query) or die(mysqli_error($connect));

// Insert into Ledger From Account  table
 $query="INSERT INTO `ledger`(`dated2`,`dated`, `accid`, `comid`, `description`, `vno`, `refno`, `entrytype`, `credit`) VALUES('$dated2','$dated','$accid','5','$description2','$tvno','$tvno','Transfer','$credit')";
	$result=mysqli_query($connect,$query) or die(mysqli_error($connect));

	// Insert into Ledger To Account  table
  $query="INSERT INTO `ledger`(`dated2`,`dated`, `accid`, `comid`, `description`, `vno`, `refno`, `entrytype`, `debit`) VALUES('$dated2','$dated','$accidto','5','$description2','$tvno','$tvno','Transfer','$credit')";
	$result=mysqli_query($connect,$query) or die(mysqli_error($connect));

if($result){
	echo "Voucher Transfer Successfully";
}	
}
}
// }
// else
// {
// header('location: index.php');
// }
 ?>
