<?
session_start();
$brcode=$_SESSION['brcode'];
$user=$_SESSION['user'];
$invno = $_REQUEST['invno'];
if(strlen($brcode)<=0)
{
	print "<script> alert('Session timed out'); parent.document.location='inde.php'; </script>";
	return;
}
include("includes/top.php");
include("opendb.php");
$tbl="jobcardcheck".$brcode;
$tbl1="jobcardcheckinv".$brcode;
mysqli_query($db,"drop table $tbl1");
mysqli_query($db,"CREATE TABLE $tbl1 (partcode varchar(40),itemdesc varchar(200),qty double(10,2) default 0,tot double(10,2),qtysap double(10,2),totsap double(10,2))");
mysqli_query($db,"delete from $tbl1");
mysqli_query($db,"insert into $tbl1 (partcode,itemdesc,qtysap,totsap) select partcode,itemdesc,qty,tot from $tbl where invno = '$invno'");
mysqli_query($db,"insert into $tbl1 (partcode,itemdesc,qty,tot) select partcode,partname,qty,gtot from jcardparts where invno = '$invno' and brcode = '$brcode'");
mysqli_query($db,"insert into $tbl1 (partcode,itemdesc,qty,tot) select 'Labour',service,1,tot from jcardserv where invno = '$invno' and brcode = '$brcode'");
$sq ="select partcode,itemdesc,sum(qty),sum(tot),sum(qtysap),sum(totsap) from $tbl1 group by itemdesc";
$jres11=mysqli_query($db,$sq)or die('Err'.mysqli_error($db));
print "<br><b>Invoice No.:".$invno;
print "<table border='1'>";
print "<tr><th>Part Code</th><th>Part Name/Service</th><th>Qty (Online)</th><th>Total (Online)</th><th>Qty(SAP)</th><th>Total(SAP)</th><tr>";
$j=1;
while($jrow11=mysqli_fetch_array($jres11))
{	
	print "<tr><td>".$jrow11[0]."</td><td>".$jrow11[1]."</td><td align='right'>".$jrow11[2]."</td><td align='right'>".$jrow11[3]."</td><td align='right'>".$jrow11[4]."</td><td align='right'>".$jrow11[5]."</td><tr>";
	$totqty += $jrow11[2];
	$tottot += $jrow11[3];
	$totqtysap += $jrow11[4];
	$tottotsap += $jrow11[5];
}
print "<tr><td colspan='2' align='center'><b>TOTAL</td><td align='right'>".$totqty."</td><td align='right'>".$tottot."</td><td align='right'>".$totqtysap."</td><td align='right'>".$tottotsap."</td><td align='right'>".$jrow11[5]."</td><tr>";
print "</table>";
?>	