<?
session_start();
$brcode=$_SESSION['brcode'];
$user=$_SESSION['user'];
if(strlen($brcode)<=0)
{
 print "<script> alert('Session timed out'); parent.document.location='../index.html'; </script>";
 return;
}
include("../opendb.php");
include("../test.php");
if(isset($_POST['show']))
{
?>
<style>
td,th,body{font-size:14;font-family:'arial narrow';letter-spacing:1}
</style>
<center>
<?
$d1=$_REQUEST['d1'];
$m1=$_REQUEST['m1'];
$y1=$_REQUEST['y1'];


$d2=$_REQUEST['d2'];
$m2=$_REQUEST['m2'];
$y2=$_REQUEST['y2'];
 $dfrom=$y1.'-'.$m1.'-'.$d1;
 $dto=$y2.'-'.$m2.'-'.$d2;

$ordby=$_REQUEST['ordby'];

$brres=mysqli_query($db,"select * from branch where brcode='$brcode'");
$brrow=mysqli_fetch_array($brres);
?>
<table>
<TR><TD COLSPAN=2 ALIGN=CENTER><b> PSN AUTOMOTIVE P LTD </b><BR>
	 <?print $brrow[braddr].",".$brrow[brcity].",<br><u> PH - ".$brrow[brphone]?></u>
TIN: <?print $brrow[tin]?>, GST: <?print $brrow[cstno]?>&nbsp;
</td></tr>
<tr><td COLSPAN=2 ALIGN=CENTER>
<?print "<h4><br>SPARE INVOICE REPORT </H4>";

print " from ".datetohtml($dfrom).' to '.datetohtml($dto);
?>
</td></tr>
</table>

<?
        $grand_gtot1=0;
        $grand_ttx=0;
        $grand_tcess=0;
        $grand_ttot=0;
        $grand_ttrnd=0;
        $grand_rndtot=0;

	
      
     $ttxsgst=0;
    $tcess=0;
    $ttot=0;
    $ttrnd=0;
    
    
    $gtota5=0;
    $ttxgst5=0;
    $gtota12=0;
    $ttxgst12=0;
     $gtota18=0;
    $ttxgst18=0;
    
     $gtota28=0;
    $ttxgst28=0;
    $tthand=0;
    
  
 $tbl="spareinvdw".$brcode.$user;
mysqli_query($db,"drop table $tbl");
mysqli_query($db,"CREATE TABLE $tbl (invno varchar(200),invdate date,cust varchar(400),brcode varchar(22),invtype varchar(33),28b4 double(10,2) default 0, 14sgst double(10,2) default 0, 14cgst double(12,2) default 0,28igst double(12,2) default 0,18b4 double(12,2) default 0,9sgst double(12,2) default 0,9cgst double(12,2) default 0,18igst double(12,2) default 0,12b4 double(12,2) default 0,6sgst double(12,2) default 0,6cgst double(12,2) default 0,12igst double(12,2) default 0,5b4 double(12,2) default 0,2_5sgst double(12,2) default 0,2_5cgst double(12,2) default 0,5igst double(12,2) default 0,0gst double(12,2) default 0,hand double(12,2) default 0,total double(12,2) default 0,salestype varchar(200))");
mysqli_query($db,"delete from $tbl");

//      cs start  #####################################################

$sq2="select distinct invno,invdate,customer from spareinvoice where brcode='$brcode' and invdate>='$dfrom' and invdate<='$dto'";
$re21=mysqli_query($db,$sq2)or die('Err3:'.mysqli_error($db));

while($res2=mysqli_fetch_array($re21))
{
 $cch14=mysqli_query($db,"select sum(aprice),sum(sgstamt),sum(cgstamt),sum(hand),sum(tot) from spareinvoice where brcode='$brcode' and invno='$res2[0]' and sgstp='14.00'");

   $res3=mysqli_fetch_row($cch14);
    if($res3[0]>0)

{
 $sq14="insert into $tbl(invno,invdate,cust,brcode,invtype,28b4,14sgst,14cgst,hand,total,salestype) values('$res2[invno]','$res2[invdate]','$res2[customer]','$brcode','CS','$res3[0]','$res3[1]','$res3[2]','$res3[3]','$res3[4]','spare')";
   mysqli_query($db,$sq14) or die('saleinv28cg err'.mysqli_error($db));
}
$sqqq="select sum(aprice),sum(sgstamt),sum(cgstamt),sum(hand),sum(tot) from spareinvoice where brcode='$brcode' and invno='$res2[0]' and sgstp='9.00'";
//print $sqqq;

$cch9=mysqli_query($db,"select sum(aprice),sum(sgstamt),sum(cgstamt),sum(hand),sum(tot) from spareinvoice where brcode='$brcode' and invno='$res2[0]' and sgstp='9.00'");
$nn=mysqli_num_rows($cch9);
//print $nn;
 
 
   $res3=mysqli_fetch_row($cch9);
   if($res3[0]>0)

{
 $sq9="insert into $tbl(invno,invdate,cust,brcode,invtype,18b4,9sgst,9cgst,hand,total,salestype) values('$res2[invno]','$res2[invdate]','$res2[customer]','$brcode','CS','$res3[0]','$res3[1]','$res3[2]','$res3[3]','$res3[4]','spare')";
 //print $sq9;
   mysqli_query($db,$sq9) or die('saleinv18sg err'.mysqli_error($db));
}

$cch6=mysqli_query($db,"select sum(aprice),sum(sgstamt),sum(cgstamt),sum(hand),sum(tot) from spareinvoice where brcode='$brcode' and invno='$res2[0]' and sgstp='6.00'");
 
 
   $res3=mysqli_fetch_row($cch6);
    if($res3[0]>0)

{
 $sq6="insert into $tbl(invno,invdate,cust,brcode,invtype,12b4,6sgst,6cgst,hand,total,salestype) values('$res2[invno]','$res2[invdate]','$res2[customer]','$brcode','CS','$res3[0]','$res3[1]','$res3[2]','$res3[3]','$res3[4]','spare')";
   mysqli_query($db,$sq6) or die('saleinv err'.mysqli_error($db));
}

$cch5=mysqli_query($db,"select sum(aprice),sum(sgstamt),sum(cgstamt),sum(hand),sum(tot) from spareinvoice where brcode='$brcode' and invno='$res2[0]' and sgstp='2.50'");
 
   $res3=mysqli_fetch_row($cch5);
    if($res3[0]>0)

{
 $sq5="insert into $tbl(invno,invdate,cust,brcode,invtype,5b4,2_5sgst,2_5cgst,hand,total,salestype) values('$res2[invno]','$res2[invdate]','$res2[customer]','$brcode','CS','$res3[0]','$res3[1]','$res3[2]','$res3[3]','$res3[4]','spare')";
   mysqli_query($db,$sq5) or die('saleinv err'.mysqli_error($db));
}

$cch0=mysqli_query($db,"select sum(aprice),sum(hand),sum(tot) from spareinvoice where brcode='$brcode' and invno='$res2[0]' and sgstp='0.00' and cgstp='0.00' and igstp='0.00' ");

   $res3=mysqli_fetch_row($cch0);
    if($res3[0]>0)

{
 $sq0="insert into $tbl(invno,invdate,cust,brcode,invtype,0gst,hand,total,salestype) values('$res2[invno]','$res2[invdate]','$res2[customer]','$brcode','CS','$res3[0]','$res3[1]','$res3[2]','spare')";
   mysqli_query($db,$sq0) or die('saleinv err'.mysqli_error($db));
}

$cch28i=mysqli_query($db,"select sum(aprice),sum(igstamt),sum(hand),sum(tot) from spareinvoice where brcode='$brcode' and invno='$res2[0]' and igstp='28.00'");
 
   $res3=mysqli_fetch_row($cch28i);
    if($res3[0]>0)

{
 $sq="insert into $tbl(invno,invdate,cust,brcode,invtype,28b4,28igst,hand,total,salestype) values('$res2[invno]','$res2[invdate]','$res2[customer]','$brcode','CS','$res3[0]','$res3[1]','$res3[2]','$res3[3]','spare')";
   mysqli_query($db,$sq) or die('saleinv err'.mysqli_error($db));
}

$cch18i=mysqli_query($db,"select sum(aprice),sum(igstamt),sum(hand),sum(tot) from spareinvoice where brcode='$brcode' and invno='$res2[0]' and igstp='18.00'");
 
   $res3=mysqli_fetch_row($cch18i);
    if($res3[0]>0)

{
 $sq="insert into $tbl(invno,invdate,cust,brcode,invtype,18b4,18igst,hand,total,salestype) values('$res2[invno]','$res2[invdate]','$res2[customer]','$brcode','CS','$res3[0]','$res3[1]','$res3[2]','$res3[3]','spare')";
   mysqli_query($db,$sq) or die('saleinv err'.mysqli_error($db));
}

$cch18i=mysqli_query($db,"select sum(aprice),sum(igstamt),sum(hand),sum(tot) from spareinvoice where brcode='$brcode' and invno='$res2[0]' and igstp='12.00'");
 
   $res3=mysqli_fetch_row($cch18i);
    if($res3[0]>0)

{
 $sq="insert into $tbl(invno,invdate,cust,brcode,invtype,12b4,12igst,hand,total,salestype) values('$res2[invno]','$res2[invdate]','$res2[customer]','$brcode','CS','$res3[0]','$res3[1]','$res3[2]','$res3[3]','spare')";
   mysqli_query($db,$sq) or die('saleinv err'.mysqli_error($db));
}


$cch5i=mysqli_query($db,"select sum(aprice),sum(igstamt),sum(hand),sum(tot) from spareinvoice where brcode='$brcode' and invno='$res2[0]' and igstp='5.00'");
 
   $res3=mysqli_fetch_row($cch5i);
    if($res3[0]>0)

{
 $sq="insert into $tbl(invno,invdate,cust,brcode,invtype,5b4,5igst,hand,total,salestype) values('$res2[invno]','$res2[invdate]','$res2[customer]','$brcode','CS','$res3[0]','$res3[1]','$res3[2]','$res3[3]','spare')";
   mysqli_query($db,$sq) or die('saleinv err'.mysqli_error($db));
}
}

// ###############  cs end #####################################################



//    ################## jobcard start   #####################################

$sq2="select distinct invno,date,cname from jobcard where brcode='$brcode' and date>='$dfrom' and date<='$dto'";
//print $sq2;
$re21=mysqli_query($db,$sq2)or die('Err3:'.mysqli_error($db));

while($res2=mysqli_fetch_array($re21))
{
    $ttt="select sum(amt),sum(sgstamt),sum(cgstamt),sum(hnd),sum(gtot) from jcardparts where brcode='$brcode' and invno='$res2[0]' and sgstp='14.00'";
    //print $ttt;
 $cch14=mysqli_query($db,"select sum(amt),sum(sgstamt),sum(cgstamt),sum(hnd),sum(gtot) from jcardparts where brcode='$brcode' and invno='$res2[0]' and sgstp='14.00'");

   $res3=mysqli_fetch_row($cch14);
    if($res3[0]>0)

{
 $sq14="insert into $tbl(invno,invdate,cust,brcode,invtype,28b4,14sgst,14cgst,hand,total,salestype) values('$res2[invno]','$res2[date]','$res2[cname]','$brcode','JC','$res3[0]','$res3[1]','$res3[2]','$res3[3]','$res3[4]','spare')";
   mysqli_query($db,$sq14) or die('saleinv28cg err'.mysqli_error($db));
}
$sqqq="select sum(amt),sum(sgstamt),sum(cgstamt),sum(hnd),sum(gtot) from jcardparts where brcode='$brcode' and invno='$res2[0]' and sgstp='9.00'";
//print $sqqq;

$cch9=mysqli_query($db,"select sum(amt),sum(sgstamt),sum(cgstamt),sum(hnd),sum(gtot) from jcardparts where brcode='$brcode' and invno='$res2[0]' and sgstp='9.00'");
$nn=mysqli_num_rows($cch9);
//print $nn;
 
 
   $res3=mysqli_fetch_row($cch9);
   if($res3[0]>0)

{
    
 $sq9="insert into $tbl(invno,invdate,cust,brcode,invtype,18b4,9sgst,9cgst,hand,total,salestype) values('$res2[invno]','$res2[date]','$res2[cname]','$brcode','JC','$res3[0]','$res3[1]','$res3[2]','$res3[3]','$res3[4]','spare')";
 //print $sq9;
   mysqli_query($db,$sq9) or die('saleinv18sg err'.mysqli_error($db));
}

$cch6=mysqli_query($db,"select sum(amt),sum(sgstamt),sum(cgstamt),sum(hnd),sum(gtot) from jcardparts where brcode='$brcode' and invno='$res2[0]' and sgstp='6.00'");
 
 
   $res3=mysqli_fetch_row($cch6);
    if($res3[0]>0)

{
 $sq6="insert into $tbl(invno,invdate,cust,brcode,invtype,12b4,6sgst,6cgst,hand,total,salestype) values('$res2[invno]','$res2[date]','$res2[cname]','$brcode','JC','$res3[0]','$res3[1]','$res3[2]','$res3[3]','$res3[4]','spare')";
   mysqli_query($db,$sq6) or die('saleinv err'.mysqli_error($db));
}

$cch5=mysqli_query($db,"select sum(amt),sum(sgstamt),sum(cgstamt),sum(hnd),sum(gtot) from jcardparts where brcode='$brcode' and invno='$res2[0]' and sgstp='2.50'");
 
   $res3=mysqli_fetch_row($cch5);
    if($res3[0]>0)

{
 $sq5="insert into $tbl(invno,invdate,cust,brcode,invtype,5b4,2_5sgst,2_5cgst,hand,total,salestype) values('$res2[invno]','$res2[date]','$res2[cname]','$brcode','JC','$res3[0]','$res3[1]','$res3[2]','$res3[3]','$res3[4]','spare')";
   mysqli_query($db,$sq5) or die('saleinv err'.mysqli_error($db));
}

$cch0=mysqli_query($db,"select sum(amt),sum(hnd),sum(gtot) from jcardparts where brcode='$brcode' and invno='$res2[0]' and sgstp='0.00' and cgstp='0.00' and igstp='0.00'");

   $res3=mysqli_fetch_row($cch0);
    if($res3[0]>0)

{
 $sq0="insert into $tbl(invno,invdate,cust,brcode,invtype,0gst,hand,total,salestype) values('$res2[invno]','$res2[date]','$res2[cname]','$brcode','JC','$res3[0]','$res3[1]','$res3[2]','spare')";
   mysqli_query($db,$sq0) or die('saleinv err'.mysqli_error($db));
}

$cch28i=mysqli_query($db,"select sum(amt),sum(igstamt),sum(hnd),sum(gtot) from jcardparts where brcode='$brcode' and invno='$res2[0]' and igstp='28.00'");
 
   $res3=mysqli_fetch_row($cch28i);
    if($res3[0]>0)

{
 $sq28i="insert into $tbl(invno,invdate,cust,brcode,invtype,28b4,28igst,hand,total,salestype) values('$res2[invno]','$res2[date]','$res2[cname]','$brcode','JC','$res3[0]','$res3[1]','$res3[2]','$res3[3]','spare')";
   mysqli_query($db,$sq28i) or die('saleinv err'.mysqli_error($db));
}

$cch18i=mysqli_query($db,"select sum(amt),sum(igstamt),sum(hnd),sum(gtot) from jcardparts where brcode='$brcode' and invno='$res2[0]' and igstp='18.00'");
 
   $res3=mysqli_fetch_row($cch18i);
    if($res3[0]>0)

{
 $sq18i="insert into $tbl(invno,invdate,cust,brcode,invtype,18b4,18igst,hand,total,salestype) values('$res2[invno]','$res2[date]','$res2[cname]','$brcode','JC','$res3[0]','$res3[1]','$res3[2]','$res3[3]','spare')";
   mysqli_query($db,$sq18i) or die('saleinv err'.mysqli_error($db));
}

$cch18i=mysqli_query($db,"select sum(aprice),sum(igstamt),sum(hnd),sum(gtot) from jcardparts where brcode='$brcode' and invno='$res2[0]' and igstp='12.00'");
 
   $res3=mysqli_fetch_row($cch18i);
    if($res3[0]>0)

{
 $sq12i="insert into $tbl(invno,invdate,cust,brcode,invtype,12b4,12igst,hand,total,salestype) values('$res2[invno]','$res2[date]','$res2[cname]','$brcode','JC','$res3[0]','$res3[1]','$res3[2]','$res3[3]','spare')";
   mysqli_query($db,$sq12i) or die('saleinv err'.mysqli_error($db));
}


$cch5i=mysqli_query($db,"select sum(amt),sum(igstamt),sum(hnd),sum(gtot) from jcardparts where brcode='$brcode' and invno='$res2[0]' and igstp='5.00'");
 
   $res3=mysqli_fetch_row($cch5i);
    if($res3[0]>0)

{
 $sq5i="insert into $tbl(invno,invdate,cust,brcode,invtype,5b4,5igst,hand,total,salestype) values('$res2[invno]','$res2[date]','$res2[cname]','$brcode','JC','$res3[0]','$res3[1]','$res3[2]','$res3[3]','spare')";
   mysqli_query($db,$sq5i) or die('saleinv err'.mysqli_error($db));
}
//########## parts end #######################################

//##############  service  ##################################################
$cch9s=mysqli_query($db,"select sum(servamt),sum(sgstamt),sum(cgstamt),sum(tot) from jcardserv where brcode='$brcode' and invno='$res2[0]' and sgstp='9.00'");
$nn=mysqli_num_rows($cch9s);
//print $nn;
 
 
   $res3=mysqli_fetch_row($cch9s);
   if($res3[0]>0)

{
    
 $sq9s="insert into $tbl(invno,invdate,cust,brcode,invtype,18b4,9sgst,9cgst,total,salestype) values('$res2[invno]','$res2[date]','$res2[cname]','$brcode','JC','$res3[0]','$res3[1]','$res3[2]','$res3[3]','service')";
 //print $sq9;
   mysqli_query($db,$sq9s) or die('servinv18sg err'.mysqli_error($db));
}

$cch90=mysqli_query($db,"select sum(servamt),sum(tot) from jcardserv where brcode='$brcode' and invno='$res2[0]' and sgstp='0.00'");
$nn=mysqli_num_rows($cch90);
//print $nn;
 
 
   $res3=mysqli_fetch_row($cch90);
   if($res3[0]>0)

{
    
 $sq90="insert into $tbl(invno,invdate,cust,brcode,invtype,0gst,total,salestype) values('$res2[invno]','$res2[date]','$res2[cname]','$brcode','JC','$res3[0]','$res3[1]','service')";
 //print $sq9;
   mysqli_query($db,$sq9) or die('servinv0sg err'.mysqli_error($db));
}

$cch9=mysqli_query($db,"select sum(servamt),sum(igstamt),sum(tot) from jcardserv where brcode='$brcode' and invno='$res2[0]' and igstp='18.00'");
$nn=mysqli_num_rows($cch9);
//print $nn;
 
 
   $res3=mysqli_fetch_row($cch9);
   if($res3[0]>0)

{
    
 $sq9="insert into $tbl(invno,invdate,cust,brcode,invtype,18b4,18igst,total,salestype) values('$res2[invno]','$res2[date]','$res2[cname]','$brcode','JC','$res3[0]','$res3[1]','$res3[2]','service')";
 //print $sq9;
   mysqli_query($db,$sq9) or die('servinv18igsg err'.mysqli_error($db));
}

}

//   job card end  ################################################

//###########################################################################


print "<table border=1 cellspacing=1 cellpadding=4 bgcolor='lightsteelblue'>";
print "<tr><th colspan=26><h3>COUNTER SALE</th></tr>";
print "<tr><th colspan=7><h3>Invoice Details</th><th colspan=4><h3>28% TAX</th><th colspan=4><h3>18% TAX</th><th colspan=4><h3>12% TAX</th><th colspan=4><h3>5% TAX</th><th colspan=1><h3>0% TAX</th><th colspan=2><h3></th></tr>";

print " <th>Inv No <th>Invoice Date ";
print "<th>GST NO<th>Customer<th>State Code<th>Branch<th>Sales Type<th>Before Value <th>IGST <th>SGST <th>CGST <th>Before Value <th>IGST <th>SGST <th>CGST <th>Before Value <th>IGST <th>SGST <th>CGST <th>Before Value <th>IGST <th>SGST <th>CGST <th>Before Value<th>Hand<th>Total ";

    $reinvno=mysqli_query($db,"select distinct invno,invdate,cust from $tbl  where brcode='$brcode' and invtype='CS' ")or die('err'.mysqli_error($db));
    
    while($rowinvno=mysqli_fetch_array($reinvno))
{
$re=mysqli_query($db,"select sum(28b4) 28b4,sum(14sgst) 14sgst,sum(14cgst) 14cgst ,sum(28igst) 28igst,sum(18b4) 18b4,sum(9sgst) 9sgst,sum(9cgst) 9cgst ,sum(18igst) 18igst,sum(12b4) 12b4,sum(6sgst) 6sgst,sum(6cgst) 6cgst ,sum(12igst) 12igst,sum(5b4) 5b4,sum(2_5sgst) 2_5sgst,sum(2_5cgst) 2_5cgst ,sum(5igst) 5igst,sum(0gst) 0b4,sum(hand) hand,sum(total) tot from $tbl  where brcode='$brcode'   and invno='$rowinvno[0]' group by invno")or die('err'.mysqli_error($db));
    //else
//$re=mysqli_query($db,"select invno,invdate,customer,sum(aprice) aprice,sum(taxamt)txamt,sum(cessamt)cess ,sum(tot)tot, vatorcst,invtype,msno from spareinvoice  where brcode='$brcode' and invtype='$invrow[0]' and invdate>='$dfrom' and invdate<='$dto'  group by invdate,invno")or die('err'.mysqli_error($db));    
$bta5=0;
$gsta5=0;
$bta12=0;
$gsta12=0;
$bta18=0;
$gsta18=0;
$bta28=0;
$gsta28=0;
$totcs=0;
    $hand1=0;

while($row=mysqli_fetch_array($re))
{
    $cus_result=mysqli_query($db,"select tin from customer where acname = '$row[cust]'")or die  (mysqli_error($db));
	$cus_row=mysqli_fetch_row($cus_result);
	$mtin=$cus_row[0];
	//$btgstamt=$row[3];
		$totcs+= $row[tot];
	$hand1+=$row[hand];
	$tthand+=$row[hand]; 
	 
	 
    print "\n<tr bgcolor=white><td>$rowinvno[0]</td><td>".datetohtml($rowinvno[invdate]);
    print "<td>".$mtin."</td>";
    print "<td>".strtoupper($rowinvno[cust])."</td><td></td><td>$brcode</td><td>Spare</td>";
   
    print "<td align=right>".putComa($row[0])."</td><td align=right>".putComa($row[3])."</td>";
    print "<td align=right>".putcoma($row[1])."</td><td align=right>".putComa($row[2])."</td>";
    
    print "<td align=right>".putComa($row[4])."</td><td align=right>".putComa($row[7])."</td>";
    print "<td align=right>".putcoma($row[5])."</td><td align=right>".putComa($row[6])."</td>";
    
    print "<td align=right>".putComa($row[8])."</td><td align=right>".putComa($row[11])."</td>";
    print "<td align=right>".putcoma($row[9])."</td><td align=right>".putComa($row[10])."</td>";
    
    print "<td align=right>".putComa($row[12])."</td><td align=right>".putComa($row[15])."</td>";
    print "<td align=right>".putcoma($row[13])."</td><td align=right>".putComa($row[14])."</td>";
    
    print "<td align=right>".putcoma($row[16])."</td><td align=right>".putComa($row[17])."</td>";
   
   print "<td align=right>".putcoma($row[18])."</td>";
  
    
}
}
//#########################################################################


//*********** jobcard


//####################################################################


print "<table border=1 cellspacing=1 cellpadding=4 bgcolor='lightsteelblue'>";
print "<tr><th colspan=26><h3>JOBCARD SALE</th></tr>";
print "<tr><th colspan=7><h3>Invoice Details</th><th colspan=4><h3>28% TAX</th><th colspan=4><h3>18% TAX</th><th colspan=4><h3>12% TAX</th><th colspan=4><h3>5% TAX</th><th colspan=1><h3>0% TAX</th><th colspan=2><h3></th></tr>";

print " <th>Inv No <th>Invoice Date ";
print "<th>GST NO<th>Customer<th>State Code<th>Branch<th>Sales Type<th>Before Value <th>IGST <th>SGST <th>CGST <th>Before Value <th>IGST <th>SGST <th>CGST <th>Before Value <th>IGST <th>SGST <th>CGST <th>Before Value <th>IGST <th>SGST <th>CGST <th>Before Value<th>Hand<th>Total ";

    $reinvno=mysqli_query($db,"select distinct invno,invdate,cust from $tbl  where brcode='$brcode' and invtype='JC' ")or die('err'.mysqli_error($db));
    
    while($rowinvno=mysqli_fetch_array($reinvno))
{
$re=mysqli_query($db,"select sum(28b4) 28b4,sum(14sgst) 14sgst,sum(14cgst) 14cgst ,sum(28igst) 28igst,sum(18b4) 18b4,sum(9sgst) 9sgst,sum(9cgst) 9cgst ,sum(18igst) 18igst,sum(12b4) 12b4,sum(6sgst) 6sgst,sum(6cgst) 6cgst ,sum(12igst) 12igst,sum(5b4) 5b4,sum(2_5sgst) 2_5sgst,sum(2_5cgst) 2_5cgst ,sum(5igst) 5igst,sum(0gst) 0b4,sum(hand) hand,sum(total) tot from $tbl  where brcode='$brcode'   and invno='$rowinvno[0]' and salestype='spare' group by invno")or die('err'.mysqli_error($db));
   
$bta5=0;
$gsta5=0;
$bta12=0;
$gsta12=0;
$bta18=0;
$gsta18=0;
$bta28=0;
$gsta28=0;
$totcs=0;
    $hand1=0;

while($row=mysqli_fetch_array($re))
{
    $cus_result=mysqli_query($db,"select tin from customer where acname = '$row[cust]'")or die  (mysqli_error($db));
	$cus_row=mysqli_fetch_row($cus_result);
	$mtin=$cus_row[0];
	//$btgstamt=$row[3];
		$totcs+= $row[tot];
	$hand1+=$row[hand];
	$tthand+=$row[hand]; 
	 
	 
    print "\n<tr bgcolor=white><td>$rowinvno[0]</td><td>".datetohtml($rowinvno[invdate]);
    print "<td>".$mtin."</td>";
    print "<td>".strtoupper($rowinvno[cust])."</td><td></td><td>$brcode</td><td>Spare</td>";
   
    print "<td align=right>".putComa($row[0])."</td><td align=right>".putComa($row[3])."</td>";
    print "<td align=right>".putcoma($row[1])."</td><td align=right>".putComa($row[2])."</td>";
    
    print "<td align=right>".putComa($row[4])."</td><td align=right>".putComa($row[7])."</td>";
    print "<td align=right>".putcoma($row[5])."</td><td align=right>".putComa($row[6])."</td>";
    
    print "<td align=right>".putComa($row[8])."</td><td align=right>".putComa($row[11])."</td>";
    print "<td align=right>".putcoma($row[9])."</td><td align=right>".putComa($row[10])."</td>";
    
    print "<td align=right>".putComa($row[12])."</td><td align=right>".putComa($row[15])."</td>";
    print "<td align=right>".putcoma($row[13])."</td><td align=right>".putComa($row[14])."</td>";
    
    print "<td align=right>".putcoma($row[16])."</td><td align=right>".putComa($row[17])."</td>";
   
   print "<td align=right>".putcoma($row[18])."</td>";
  
    
}

//########################  service

$res1=mysqli_query($db,"select sum(28b4) 28b4,sum(14sgst) 14sgst,sum(14cgst) 14cgst ,sum(28igst) 28igst,sum(18b4) 18b4,sum(9sgst) 9sgst,sum(9cgst) 9cgst ,sum(18igst) 18igst,sum(12b4) 12b4,sum(6sgst) 6sgst,sum(6cgst) 6cgst ,sum(12igst) 12igst,sum(5b4) 5b4,sum(2_5sgst) 2_5sgst,sum(2_5cgst) 2_5cgst ,sum(5igst) 5igst,sum(0b4) 0b4,sum(hand) hand,sum(total) tot from $tbl  where brcode='$brcode'   and invno='$rowinvno[0]' and salestype='service' group by invno")or die('err'.mysqli_error($db));
   


while($row=mysqli_fetch_array($res1))
{
    $cus_result=mysqli_query($db,"select cst from customer where acname = '$row[cust]'")or die  (mysqli_error($db));
	$cus_row=mysqli_fetch_row($cus_result);
	$mtin=$cus_row[0];
	//$btgstamt=$row[3];
		$totcs+= $row[tot];
	$hand1+=$row[hand];
	$tthand+=$row[hand]; 
	 
	 
    print "\n<tr bgcolor=white><td>$rowinvno[0]</td><td>".datetohtml($rowinvno[invdate]);
    print "<td>".$mtin."</td>";
    print "<td>".strtoupper($rowinvno[cust])."</td><td></td><td>$brcode</td><td>Service</td>";
   
    print "<td align=right>".putComa($row[0])."</td><td align=right>".putComa($row[3])."</td>";
    print "<td align=right>".putcoma($row[1])."</td><td align=right>".putComa($row[2])."</td>";
    
    print "<td align=right>".putComa($row[4])."</td><td align=right>".putComa($row[7])."</td>";
    print "<td align=right>".putcoma($row[5])."</td><td align=right>".putComa($row[6])."</td>";
    
    print "<td align=right>".putComa($row[8])."</td><td align=right>".putComa($row[11])."</td>";
    print "<td align=right>".putcoma($row[9])."</td><td align=right>".putComa($row[10])."</td>";
    
    print "<td align=right>".putComa($row[12])."</td><td align=right>".putComa($row[15])."</td>";
    print "<td align=right>".putcoma($row[13])."</td><td align=right>".putComa($row[14])."</td>";
    
    print "<td align=right>".putcoma($row[16])."</td><td align=right>".putComa($row[17])."</td>";
   
   print "<td align=right>".putcoma($row[18])."</td>";
  
    
}

}


//Jobcard end
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
$t1=0;
//******************* JOBCARD IGST START


//****************************************************************************** 



return;
}// end if
?>

<link rel="stylesheet" href="../style.css" type="text/css" />
<style>
//	tr{background-color:white}
	th{background-color:steelblue;color:white}
	td{font-size:13}
.right{text-align:right};
</style>

<center>
<h3>SPARE INVOICE REPORT -2</H3>
<form action='<?Print $PHP_SELF?>' method='post'>
<table cellspacing=1 cellpadding=1 bgcolor='steelblue'>
<tr><td bgcolor='white' align=center>
<table class=noprint>
<tr><td>Date from </td><td>dd <input type=text name='d1' size=2 value='<?print date("d")?>'>
mm <input type=text name='m1' size=2 value='<?print date("m")?>'>
yy <input type=text name='y1' size=4 value='<?print date("Y")?>'></td></tr>

<tr><td align=right>to </td><td>dd <input type=text name='d2' size=2 value='<?print date("d")?>'>
mm <input type=text name='m2' size=2 value='<?print date("m")?>'>
yy <input type=text name='y2' size=4 value='<?print date("Y")?>'>
</td></tr>
<tr><td colspan=2 align=center bgcolor='lightsteelblue'><input type=submit value='Show' name='show'></td></tr>

</table>
</td></tr>
</table>
</form>


