<?
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");

$date=$y.'-'.$m.'-'.$d;
$failon=$y1.'-'.$m1.'-'.$d1;
$transdate=$y2.'-'.$m2.'-'.$d2;
$invdate=$y3.'-'.$m3.'-'.$d3;

$jvres=mysqli_query($db,"select max(jvno) from journal2 where brcode='$brcode'");
$jvrow=mysqli_fetch_array($jvres);
$jvno=($jvrow[0]+1);

$warno=$warno12;
$tbl="spareinvwar".$brcode;
$re=mysqli_query($db,"select * from $tbl where warno='$warno12'");
if(mysqli_num_rows($re)<=0)
{
 print "<script> alert('Invalid Entry-Items could not be found'); history.back(1); </script>";
 return ;
}

if(mysqli_num_rows($re)>0)
{
 while($row=mysqli_fetch_array($re))
 {
 $sql="insert into warsparetransout values('$row[warno]','$row[partcode]', '$row[partname]', '$row[psnqty]' , '$row[telcqty]','$row[price]' , '$tobr', '$date', '$cust', '$msno', '$failon', '$hmr', '$flr', '$transp','$transdate','$sendto', '$finfo', '$cssno','$servord', '$stono', '$preqno','$invno','$invdate', '$stat', '$brcode','$notifno','$jvno')";
 mysqli_query($db,$sql)or die('Insert Error:'.mysqli_error());
 }
}

//*************** posting
 $re=mysqli_query($db,"select brname from branch where brcode='$tobr'")or die('err2'.mysqli_error());
 $rr=mysqli_fetch_row($re);
 $branch_na=$rr[0];

$sql="select sum(psnqty*price) from warsparetransout where warno='$warno' and brcode='$brcode' and psnqty>0";
$postres=mysqli_query($db,$sql) or die('post err'.mysqli_error());
$postrow=mysqli_fetch_array($postres);
$s="insert into journal2 values('$date','$jvno','Cr','Spare transfer out (WAR)','0','$postrow[0]','Spare Transfer out WAR:$warno','$brcode','Spare trans out WAR','Trans no','$warno','$warno')";
mysqli_query($db,$s)or die(mysqli_error());

mysqli_query($db,"insert into journal2 values('$date','$jvno','Dr','$branch_na','$postrow[0]','0','Spare Transfer out (WAR):$warno','$brcode','Spare trans out WAR','Trans no','$warno','$warno')")or die(mysqli_error());

log_entry($brcode,$user,$REMOTE_ADDR,"sparetrans out WAR:$warno, Journal:$jvno");

//mysqli_query($db,"delete from $tbl where warno='$warno'");
mysqli_query($db,"update $tbl set trans='y' where warno='$warno'")or die(mysqli_error());
print "<font color=green> Data has been saved</font>";
print "<script> window.open('prnwartrout.php?wwarno=$warno'); </script>";
$warno='x';
log_entry($brcode,$user,$REMOTE_ADDR,"War sparetrans out:$warno");
?>
<input type=button value='Close' onClick=parent.window.close()>

