<?
session_start();
if(strlen($brcode)<=0)
{
 print "<script> alert('Session timed out'); parent.document.location='../index.html'; </script>";
 return;
}

include("../opendb.php");
include("../test.php");
$re=mysqli_query($db,"select * from veh_purchreturn where brcode='AUT009' order by ret_num");
while($warrow=mysqli_fetch_array($re))
{

$jvno=$warrow[jvno];
$dt=$warrow[date];
$amt2=$warrow[amt2];
$invno=$warrow[ret_num];
$da=$warrow[da];
$amt2=$warrow[amt2];
$ledger=$warrow[retto];
$tax=$warrow[tax];
$netamt=$warrow[netamt];



mysqli_query($db,"delete from journal2 where jvno='$warrow[jvno]' and brcode='$warrow[brcode]'")or die('del jv error'.mysqli_error());
//$s1="insert into journal2 values('$invdate','$jvno','Cr','Spare transfer out (WAR)','0','$postrow[0]','Spare Transfer out WAR:$warno','$warrow[brcode]','Spare trans out WAR','Trans no','$warno','$warno')";
//print $s1.'<br>';
//mysqli_query($db,$s1);
//$s2="insert into journal2 values('$invdate','$jvno','Dr','$branch_na','$postrow[0]','0','Spare Transfer out (WAR):$warno','$warrow[brcode]','Spare trans out WAR','Trans no','$warno','$warno')";
//print $s2.'<br>';
//mysqli_query($db,$s2);

$s1="insert into journal2 values('$dt','$jvno','Dr','$ledger','$netamt', '0','Purchase Return: $invno','$brcode','P Ret','DA','$da','$invno')";
mysqli_query($db,$s1) or die("J V Write error 1:".mysqli_error());
print $s1.'<br>';
 $s2="insert into journal2 values('$dt','$jvno','Cr','Input tax 13.5 (Pur Ret)', '0','$tax','Purchase Return: $invno','$brcode','P Ret','DA','$da','$invno')";
mysqli_query($db,$s2) or die("J V Write error 2:".mysqli_error());
print $s2.'<br>';
 $s3="insert into journal2 values('$dt','$jvno','Cr','Purchase ret 13.5(vehicle)','0','$amt2','Purchase Return: $invno','$brcode','P Ret','DA','$da','$invno')";
mysqli_query($db,$s3) or die("J V Write error 3:".mysqli_error());
print $s3.'<br>';
}


?>
