<?php 
 // echo @$_GET['msg'];
 //  session_start();
 //  if(isset($_SESSION['userId'])){
 $amt=0; 
  	for($count = 0; $count<count($_POST['hidden_accid']); $count++)
{
	
 	$amt=$amt+ $_POST['hidden_amt'][$count];

}

if($amt!=0){


  	for($count = 0; $count<count($_POST['hidden_accid']); $count++)
{
	
 	$dated= $_POST['hidden_dated'][$count];
 	$accid= $_POST['hidden_accid'][$count];
 	$accidto= $_POST['hidden_accid2'][$count];
 	$description= $_POST['hidden_desc'][$count];
 	$fno= $_POST['hidden_fno'][$count];
 	$debit= $_POST['hidden_amt'][$count];
 	$tvno= $_POST['hidden_trvno'][$count];

if($accidto=="" or $accidto==0){
	echo "F.F.A ID not found !";
	die();
}
else{
if($debit>0){


$description2 = $tvno.' F'.$fno.' '.$description.' BALANCE TR';

require 'connection.php';
// if($dr!==""){
// Insert into Tr Voucher  table
 $query="INSERT INTO `trvoucher`(`tvno`, `accid`, `dated`, `amount`, `description`, `posted`, `status`) VALUES('$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`(`dated`, `accid`, `comid`, `description`, `vno`, `refno`, `entrytype`, `credit`) VALUES('$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`(`dated`, `accid`, `comid`, `description`, `vno`, `refno`, `entrytype`, `debit`) VALUES('$dated','$accidto','5','$description2','$tvno','$tvno','Transfer','$debit')";
	$result=mysqli_query($connect,$query) or die(mysqli_error($connect));

}

if($debit<0){
$debit = $debit*(-1);

$description2 = $tvno.' F'.$fno.' '.$description.' BALANCE TR';
require 'connection.php';
// if($dr!==""){
// Insert into Tr Voucher  table
 $query="INSERT INTO `trvoucher`(`tvno`, `accid`, `dated`, `amount`, `description`, `posted`, `status`) VALUES('$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`(`dated`, `accid`, `comid`, `description`, `vno`, `refno`, `entrytype`, `debit`) VALUES('$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`(`dated`, `accid`, `comid`, `description`, `vno`, `refno`, `entrytype`, `credit`) VALUES('$dated','$accidto','5','$description2','$tvno','$tvno','Transfer','$debit')";
	$result=mysqli_query($connect,$query) or die(mysqli_error($connect));
}
}
}
if($result){
	echo "Voucher Transfer Successfully";
}	
}
else{
echo "No data found !";
}


// }
// else
// {
// header('location: index.php');
// }
 ?>
