<?
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 MARKETING 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>OUTWARD SUPPLY REPORT </H4>";

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

<?
       
    
  
 $tbl="spareinvdw".$brcode.$user;
mysqli_query($db,"drop table if exists $tbl");
mysqli_query($db,"CREATE TABLE if not exists $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),kfc double(12,2) default 0)");
mysqli_query($db,"delete from $tbl");

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

$sq2="select  invno,invdate,customer,sum(aprice) ap,sum(sgstamt) sg,sum(cgstamt) cg,sum(hand) hnd,sum(tot) tt ,sum(fcessa) fcess from spareinvoice where brcode='$brcode' and invdate>='$dfrom' and invdate<='$dto'  and sgstp='14.00' group by invno";
$re21=mysqli_query($db,$sq2)or die('Err3:'.mysqli_error($db));

while($res2=mysqli_fetch_array($re21))
{
 
 $sq14="insert into $tbl(invno,invdate,cust,brcode,invtype,28b4,14sgst,14cgst,hand,total,salestype,kfc) values('$res2[invno]','$res2[invdate]','$res2[customer]','$brcode','CS','$res2[ap]','$res2[sg]','$res2[cg]','$res2[hnd]','$res2[tt]','spare','$res2[fcess]')";
   mysqli_query($db,$sq14) or die('saleinv28cg err'.mysqli_error($db));
}


$sq2="select  invno,invdate,customer,sum(aprice) ap,sum(sgstamt) sg,sum(cgstamt) cg,sum(hand) hnd,sum(tot) tt,sum(fcessa) fcess from spareinvoice where brcode='$brcode' and invdate>='$dfrom' and invdate<='$dto'  and sgstp='9.00' group by invno";
$re21=mysqli_query($db,$sq2)or die('Err3:'.mysqli_error($db));

while($res2=mysqli_fetch_array($re21))
{
 
 $sq14="insert into $tbl(invno,invdate,cust,brcode,invtype,18b4,9sgst,9cgst,hand,total,salestype,kfc) values('$res2[invno]','$res2[invdate]','$res2[customer]','$brcode','CS','$res2[ap]','$res2[sg]','$res2[cg]','$res2[hnd]','$res2[tt]','spare','$res2[fcess]')";
   mysqli_query($db,$sq14) or die('saleinv18cg err'.mysqli_error($db));
}

$sq2="select  invno,invdate,customer,sum(aprice) ap,sum(sgstamt) sg,sum(cgstamt) cg,sum(hand) hnd,sum(tot) tt,sum(fcessa) fcess from spareinvoice where brcode='$brcode' and invdate>='$dfrom' and invdate<='$dto'  and sgstp='6.00' group by invno";
$re21=mysqli_query($db,$sq2)or die('Err3:'.mysqli_error($db));

while($res2=mysqli_fetch_array($re21))
{
 
 $sq14="insert into $tbl(invno,invdate,cust,brcode,invtype,12b4,6sgst,6cgst,hand,total,salestype,kfc) values('$res2[invno]','$res2[invdate]','$res2[customer]','$brcode','CS','$res2[ap]','$res2[sg]','$res2[cg]','$res2[hnd]','$res2[tt]','spare','$res2[fcess]')";
   mysqli_query($db,$sq14) or die('saleinv12cg err'.mysqli_error($db));
}

$sq2="select  invno,invdate,customer,sum(aprice) ap,sum(sgstamt) sg,sum(cgstamt) cg,sum(hand) hnd,sum(tot) tt,sum(fcessa) fcess from spareinvoice where brcode='$brcode' and invdate>='$dfrom' and invdate<='$dto'  and sgstp='2.50' group by invno";
$re21=mysqli_query($db,$sq2)or die('Err3:'.mysqli_error($db));

while($res2=mysqli_fetch_array($re21))
{
 
 $sq14="insert into $tbl(invno,invdate,cust,brcode,invtype,5b4,2_5sgst,2_5cgst,hand,total,salestype,kfc) values('$res2[invno]','$res2[invdate]','$res2[customer]','$brcode','CS','$res2[ap]','$res2[sg]','$res2[cg]','$res2[hnd]','$res2[tt]','spare','$res2[fcess]')";
   mysqli_query($db,$sq14) or die('saleinv5cg err'.mysqli_error($db));
}

$sq2="select  invno,invdate,customer,sum(aprice) ap,sum(sgstamt) sg,sum(cgstamt) cg,sum(hand) hnd,sum(tot) tt,sum(fcessa) fcess from spareinvoice where brcode='$brcode' and invdate>='$dfrom' and invdate<='$dto'  and sgstp='0.00' and cgstp='0.00' and igstp='0.00' group by invno";
$re21=mysqli_query($db,$sq2)or die('Err3:'.mysqli_error($db));

while($res2=mysqli_fetch_array($re21))
{
 
 $sq14="insert into $tbl(invno,invdate,cust,brcode,invtype,0gst,hand,total,salestype,kfc) values('$res2[invno]','$res2[invdate]','$res2[customer]','$brcode','CS','$res2[ap]','$res2[hnd]','$res2[tt]','spare','$res2[fcess]')";
   mysqli_query($db,$sq14) or die('saleinv0cg err'.mysqli_error($db));
}


$sqig=mysqli_query($db,"select invno,invdate,customer,sum(aprice) ap,sum(igstamt) ig,sum(hand) hnd,sum(tot) tt,sum(fcessa) fcess from spareinvoice where brcode='$brcode'  and invdate>='$dfrom' and invdate<='$dto' and igstp='28.00' group by invno");
 while($res2=mysqli_fetch_array($sqig))
{
 $sqig1="insert into $tbl(invno,invdate,cust,brcode,invtype,28b4,28igst,hand,total,salestype,kfc) values('$res2[invno]','$res2[invdate]','$res2[customer]','$brcode','CS','$res2[ap]','$res2[ig]','$res2[hnd]','$res2[tt]','spare','$res2[fcess]')";
   mysqli_query($db,$sqig1) or die('saleinv err'.mysqli_error($db));
}


$sqig=mysqli_query($db,"select invno,invdate,customer,sum(aprice) ap,sum(igstamt) ig,sum(hand) hnd,sum(tot) tt,sum(fcessa) fcess from spareinvoice where brcode='$brcode'  and invdate>='$dfrom' and invdate<='$dto' and igstp='18.00' group by invno");
 while($res2=mysqli_fetch_array($sqig))
{
 $sqig1="insert into $tbl(invno,invdate,cust,brcode,invtype,18b4,18igst,hand,total,salestype,kfc) values('$res2[invno]','$res2[invdate]','$res2[customer]','$brcode','CS','$res2[ap]','$res2[ig]','$res2[hnd]','$res2[tt]','spare','$res2[fcess]')";
   mysqli_query($db,$sqig1) or die('saleinv err'.mysqli_error($db));
}



$sqig=mysqli_query($db,"select invno,invdate,customer,sum(aprice) ap,sum(igstamt) ig,sum(hand) hnd,sum(tot) tt,sum(fcessa) fcess from spareinvoice where brcode='$brcode'  and invdate>='$dfrom' and invdate<='$dto' and igstp='12.00' group by invno");
 while($res2=mysqli_fetch_array($sqig))
{
 $sqig1="insert into $tbl(invno,invdate,cust,brcode,invtype,12b4,12igst,hand,total,salestype,kfc) values('$res2[invno]','$res2[invdate]','$res2[customer]','$brcode','CS','$res2[ap]','$res2[ig]','$res2[hnd]','$res2[tt]','spare','$res2[fcess]')";
   mysqli_query($db,$sqig1) or die('saleinv err'.mysqli_error($db));
}


$sqig=mysqli_query($db,"select invno,invdate,customer,sum(aprice) ap,sum(igstamt) ig,sum(hand) hnd,sum(tot) tt,sum(fcessa) fcess from spareinvoice where brcode='$brcode' and invdate>='$dfrom' and invdate<='$dto' and igstp='5.00' group by invno");
 while($res2=mysqli_fetch_array($sqig))
{
 $sqig1="insert into $tbl(invno,invdate,cust,brcode,invtype,5b4,5igst,hand,total,salestype,kfc) values('$res2[invno]','$res2[invdate]','$res2[customer]','$brcode','CS','$res2[ap]','$res2[ig]','$res2[hnd]','$res2[tt]','spare','$res2[fcess]')";
   mysqli_query($db,$sqig1) or die('saleinv err'.mysqli_error($db));
}




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



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


$sq22="select jobcard.invno,jobcard.date,cname ,sum(amt) ap,sum(sgstamt) sg,sum(cgstamt) cg,sum(hnd) hnd,sum(gtot) tt,sum(cessamt) fcess from jobcard join jcardparts on jobcard.invno=jcardparts.invno where jobcard.brcode='$brcode' and jobcard.date>='$dfrom' and jobcard.date<='$dto' and sgstp='14.00' group by jobcard.invno";

$re21=mysqli_query($db,$sq22)or die('Err3:'.mysqli_error($db));

while($res2=mysqli_fetch_array($re21))
{
if ($res2['fcess']=='')
{
$res2['fcess']=0;
}
 $sq14="insert into $tbl(invno,invdate,cust,brcode,invtype,28b4,14sgst,14cgst,hand,total,salestype,kfc) values('$res2[invno]','$res2[date]','$res2[cname]','$brcode','JC','$res2[ap]','$res2[sg]','$res2[cg]','$res2[hnd]','$res2[tt]','spare','$res2[fcess]')";
  //print $sq14;
   mysqli_query($db,$sq14) or die('jcinv28cg err'.mysqli_error($db));
}

$sq22="select jobcard.invno,jobcard.date,cname ,sum(amt) ap,sum(sgstamt) sg,sum(cgstamt) cg,sum(hnd) hnd,sum(gtot) tt,sum(cessamt) fcess from jobcard join jcardparts on jobcard.invno=jcardparts.invno where jobcard.brcode='$brcode' and jobcard.date>='$dfrom' and jobcard.date<='$dto' and sgstp='9.00' group by jobcard.invno";

$re21=mysqli_query($db,$sq22)or die('Err3:'.mysqli_error($db));

while($res2=mysqli_fetch_array($re21))
{
if ($res2['fcess']=='')
{
$res2['fcess']=0;
}
 $sq14="insert into $tbl(invno,invdate,cust,brcode,invtype,18b4,9sgst,9cgst,hand,total,salestype,kfc) values('$res2[invno]','$res2[date]','$res2[cname]','$brcode','JC','$res2[ap]','$res2[sg]','$res2[cg]','$res2[hnd]','$res2[tt]','spare','$res2[fcess]')";
   mysqli_query($db,$sq14) or die('jcinv18cg err'.mysqli_error($db));
}

$sq22="select jobcard.invno,jobcard.date,cname ,sum(amt) ap,sum(sgstamt) sg,sum(cgstamt) cg,sum(hnd) hnd,sum(gtot) tt,sum(cessamt) fcess from jobcard join jcardparts on jobcard.invno=jcardparts.invno where jobcard.brcode='$brcode' and jobcard.date>='$dfrom' and jobcard.date<='$dto' and sgstp='6.00' group by jobcard.invno";

$re21=mysqli_query($db,$sq22)or die('Err3:'.mysqli_error($db));

while($res2=mysqli_fetch_array($re21))
{

if ($res2['fcess']=='')
{
$res2['fcess']=0;
}
 $sq14="insert into $tbl(invno,invdate,cust,brcode,invtype,12b4,6sgst,6cgst,hand,total,salestype,kfc) values('$res2[invno]','$res2[date]','$res2[cname]','$brcode','JC','$res2[ap]','$res2[sg]','$res2[cg]','$res2[hnd]','$res2[tt]','spare','$res2[fcess]')";
   mysqli_query($db,$sq14) or die('jcinv12cg err'.mysqli_error($db));
}



$sq22="select jobcard.invno,jobcard.date,cname ,sum(amt) ap,sum(sgstamt) sg,sum(cgstamt) cg,sum(hnd) hnd,sum(gtot) tt,sum(cessamt) fcess from jobcard join jcardparts on jobcard.invno=jcardparts.invno where jobcard.brcode='$brcode' and jobcard.date>='$dfrom' and jobcard.date<='$dto' and sgstp='2.50' group by jobcard.invno";

$re21=mysqli_query($db,$sq22)or die('Err3:'.mysqli_error($db));

while($res2=mysqli_fetch_array($re21))
{
if ($res2['fcess']=='')
{
$res2['fcess']=0;
}
 $sq14="insert into $tbl(invno,invdate,cust,brcode,invtype,5b4,2_5sgst,2_5cgst,hand,total,salestype,kfc) values('$res2[invno]','$res2[date]','$res2[cname]','$brcode','JC','$res2[ap]','$res2[sg]','$res2[cg]','$res2[hnd]','$res2[tt]','spare','$res2[fcess]')";

   mysqli_query($db,$sq14) or die('jcinv5cg err'.mysqli_error($db));
}





$sq22="select jobcard.invno,jobcard.date,cname ,sum(amt) ap,sum(sgstamt) sg,sum(cgstamt) cg,sum(hnd) hnd,sum(gtot) tt,sum(cessamt) fcess from jobcard join jcardparts on jobcard.invno=jcardparts.invno where jobcard.brcode='$brcode' and jobcard.date>='$dfrom' and jobcard.date<='$dto' and sgstp='0.00' and cgstp='0.00' and igstp='0.00' group by jobcard.invno";

$re21=mysqli_query($db,$sq22)or die('Err3:'.mysqli_error($db));

while($res2=mysqli_fetch_array($re21))
{
if ($res2['fcess']=='')
{
$res2['fcess']=0;
}
 $sq14="insert into $tbl(invno,invdate,cust,brcode,invtype,0gst,hand,total,salestype,kfc) values('$res2[invno]','$res2[date]','$res2[cname]','$brcode','JC','$res2[ap]','$res2[hnd]','$res2[tt]','spare','$res2[fcess]')";
   mysqli_query($db,$sq14) or die('jcinv0cg err'.mysqli_error($db));
}


$sq22="select jobcard.invno,jobcard.date,cname ,sum(amt) ap,sum(igstamt) ig,sum(hnd) hnd,sum(gtot) tt,sum(cessamt) fcess from jobcard join jcardparts on jobcard.invno=jcardparts.invno where jobcard.brcode='$brcode' and jobcard.date>='$dfrom' and jobcard.date<='$dto' and  igstp='28.00' group by jobcard.invno";

$re21=mysqli_query($db,$sq22)or die('Err3:'.mysqli_error($db));

while($res2=mysqli_fetch_array($re21))
{
if ($res2['fcess']=='')
{
$res2['fcess']=0;
}
 $sq14="insert into $tbl(invno,invdate,cust,brcode,invtype,28b4,28igst,hand,total,salestype,kfc) values('$res2[invno]','$res2[date]','$res2[cname]','$brcode','JC','$res2[ap]','$res2[ig]','$res2[hnd]','$res2[tt]','spare','$res2[fcess]')";
   mysqli_query($db,$sq14) or die('jciginv28cg err'.mysqli_error($db));
}

$sq22="select jobcard.invno,jobcard.date,cname ,sum(amt) ap,sum(igstamt) ig,sum(hnd) hnd,sum(gtot) tt,sum(cessamt) fcess from jobcard join jcardparts on jobcard.invno=jcardparts.invno where jobcard.brcode='$brcode' and jobcard.date>='$dfrom' and jobcard.date<='$dto' and  igstp='18.00' group by jobcard.invno";

$re21=mysqli_query($db,$sq22)or die('Err3:'.mysqli_error($db));

while($res2=mysqli_fetch_array($re21))
{
if ($res2['fcess']=='')
{
$res2['fcess']=0;
}
 $sq14="insert into $tbl(invno,invdate,cust,brcode,invtype,18b4,18igst,hand,total,salestype,kfc) values('$res2[invno]','$res2[date]','$res2[cname]','$brcode','JC','$res2[ap]','$res2[ig]','$res2[hnd]','$res2[tt]','spare','$res2[fcess]')";
   mysqli_query($db,$sq14) or die('jciginv18cg err'.mysqli_error($db));
}


$sq22="select jobcard.invno,jobcard.date,cname ,sum(amt) ap,sum(igstamt) ig,sum(hnd) hnd,sum(gtot) tt,sum(cessamt) fcess from jobcard join jcardparts on jobcard.invno=jcardparts.invno where jobcard.brcode='$brcode' and jobcard.date>='$dfrom' and jobcard.date<='$dto' and  igstp='12.00' group by jobcard.invno";

$re21=mysqli_query($db,$sq22)or die('Err3:'.mysqli_error($db));

while($res2=mysqli_fetch_array($re21))
{
if ($res2['fcess']=='')
{
$res2['fcess']=0;
}
 $sq14="insert into $tbl(invno,invdate,cust,brcode,invtype,12b4,12igst,hand,total,salestype,kfc) values('$res2[invno]','$res2[date]','$res2[cname]','$brcode','JC','$res2[ap]','$res2[ig]','$res2[hnd]','$res2[tt]','spare','$res2[fcess]')";
   mysqli_query($db,$sq14) or die('jciginv12cg err'.mysqli_error($db));
}

$sq22="select jobcard.invno,jobcard.date,cname ,sum(amt) ap,sum(igstamt) ig,sum(hnd) hnd,sum(gtot) tt,sum(cessamt) fcess from jobcard join jcardparts on jobcard.invno=jcardparts.invno where jobcard.brcode='$brcode' and jobcard.date>='$dfrom' and jobcard.date<='$dto' and  igstp='5.00' group by jobcard.invno";

$re21=mysqli_query($db,$sq22)or die('Err3:'.mysqli_error($db));

while($res2=mysqli_fetch_array($re21))
{
if ($res2['fcess']=='')
{
$res2['fcess']=0;
}
 $sq14="insert into $tbl(invno,invdate,cust,brcode,invtype,5b4,5igst,hand,total,salestype,kfc) values('$res2[invno]','$res2[date]','$res2[cname]','$brcode','JC','$res2[ap]','$res2[ig]','$res2[hnd]','$res2[tt]','spare','$res2[fcess]')";
   mysqli_query($db,$sq14) or die('jciginv5cg err'.mysqli_error($db));
}




//########## parts end #######################################

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

$sq22="select jobcard.invno,jobcard.date,cname ,sum(servamt) as1,sum(sgstamt) sg,sum(cgstamt) cg,sum(tot) tt,sum(servtx) fcess from jobcard join jcardserv on jobcard.invno=jcardserv.invno where jobcard.brcode='$brcode' and jobcard.date>='$dfrom' and jobcard.date<='$dto' and  sgstp='9.00' group by jobcard.invno";

$re21=mysqli_query($db,$sq22)or die('Err3s:'.mysqli_error($db));

while($res2=mysqli_fetch_array($re21))
{
if ($res2['fcess']=='')
{
$res2['fcess']=0;
}
 $sq14="insert into $tbl(invno,invdate,cust,brcode,invtype,18b4,9sgst,9cgst,total,salestype,kfc) values('$res2[invno]','$res2[date]','$res2[cname]','$brcode','JC','$res2[as1]','$res2[sg]','$res2[cg]','$res2[tt]','Labour','$res2[fcess]')";
   mysqli_query($db,$sq14) or die('jcinvser28cg err'.mysqli_error($db));
}


$sq22="select jobcard.invno,jobcard.date,cname ,sum(servamt) as1,sum(sgstamt) sg,sum(cgstamt) cg,sum(tot) tt,sum(servtx) fcess from jobcard join jcardserv on jobcard.invno=jcardserv.invno where jobcard.brcode='$brcode' and jobcard.date>='$dfrom' and jobcard.date<='$dto' and  sgstp='0.00' and  cgstp='0.00'and  igstp='0.00' group by jobcard.invno";

$re21=mysqli_query($db,$sq22)or die('Err3:'.mysqli_error($db));

while($res2=mysqli_fetch_array($re21))
{

if ($res2['fcess']=='')
{
$res2['fcess']=0;
}
 $sq14="insert into $tbl(invno,invdate,cust,brcode,invtype,0gst,total,salestype,kfc) values('$res2[invno]','$res2[date]','$res2[cname]','$brcode','JC','$res2[as1]','$res2[tt]','Labour','$res2[fcess]')";
   mysqli_query($db,$sq14) or die('jcinvser0cg err'.mysqli_error($db));
}


$sq22="select jobcard.invno,jobcard.date,cname ,sum(servamt) as1,sum(igstamt) ig,sum(tot) tt,sum(servtx) fcess from jobcard join jcardserv on jobcard.invno=jcardserv.invno where jobcard.brcode='$brcode' and jobcard.date>='$dfrom' and jobcard.date<='$dto' and  igstp='18.00' group by jobcard.invno";

$re21=mysqli_query($db,$sq22)or die('Err3:'.mysqli_error($db));

while($res2=mysqli_fetch_array($re21))
{

if ($res2['fcess']=='')
{
$res2['fcess']=0;
}
 $sq14="insert into $tbl(invno,invdate,cust,brcode,invtype,18b4,18igst,total,salestype,kfc) values('$res2[invno]','$res2[date]','$res2[cname]','$brcode','JC','$res2[as1]','$res2[ig]','$res2[tt]','Labour','$res2[fcess]')";
   mysqli_query($db,$sq14) or die('jcinvser28cg err'.mysqli_error($db));
}



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

//   WARANTY start #########################################################

// parts

$sqig=mysqli_query($db,"select invno,invdate,sum(aprice) ap,sum(gstamt) ig,sum(tot) tt from warcouponinvoicepassey  where brcode='$brcode'  and invdate>='$dfrom' and invdate<='$dto' and gstp='28.00' and invtype in('Spare Parts','Lubricants','Local Parts','Outside Material') group by invno");
 while($res2=mysqli_fetch_array($sqig))
{
 $sqig1="insert into $tbl(invno,invdate,brcode,invtype,28b4,28igst,total,salestype) values('$res2[invno]','$res2[invdate]','$brcode','WTY','$res2[ap]','$res2[ig]','$res2[tt]','spare')";
 //print $sqig1;
   mysqli_query($db,$sqig1) or die('saleinv err'.mysqli_error($db));
}

$sqig=mysqli_query($db,"select invno,invdate,sum(aprice) ap,sum(gstamt) ig,sum(tot) tt from warcouponinvoicepassey  where brcode='$brcode'  and invdate>='$dfrom' and invdate<='$dto' and gstp='18.00'  and invtype in('Spare Parts','Lubricants','Local Parts','Outside Material') group by invno");
 while($res2=mysqli_fetch_array($sqig))
{
 $sqig1="insert into $tbl(invno,invdate,brcode,invtype,18b4,18igst,total,salestype) values('$res2[invno]','$res2[invdate]','$brcode','WTY','$res2[ap]','$res2[ig]','$res2[tt]','spare')";
   mysqli_query($db,$sqig1) or die('saleinv err'.mysqli_error($db));
}

$sqig=mysqli_query($db,"select invno,invdate,sum(aprice) ap,sum(gstamt) ig,sum(tot) tt from warcouponinvoicepassey  where brcode='$brcode'  and invdate>='$dfrom' and invdate<='$dto' and gstp='12.00'  and invtype in('Spare Parts','Lubricants','Local Parts','Outside Material') group by invno");
 while($res2=mysqli_fetch_array($sqig))
{
 $sqig1="insert into $tbl(invno,invdate,brcode,invtype,12b4,12igst,total,salestype) values('$res2[invno]','$res2[invdate]','$brcode','WTY','$res2[ap]','$res2[ig]','$res2[tt]','spare')";
   mysqli_query($db,$sqig1) or die('saleinv err'.mysqli_error($db));
}

$sqig=mysqli_query($db,"select invno,invdate,sum(aprice) ap,sum(gstamt) ig,sum(tot) tt from warcouponinvoicepassey  where brcode='$brcode'  and invdate>='$dfrom' and invdate<='$dto' and gstp='5.00'  and invtype in('Spare Parts','Lubricants','Local Parts','Outside Material') group by invno");
 while($res2=mysqli_fetch_array($sqig))
{
 $sqig1="insert into $tbl(invno,invdate,brcode,invtype,5b4,5igst,total,salestype) values('$res2[invno]','$res2[invdate]','$brcode','WTY','$res2[ap]','$res2[ig]','$res2[tt]','spare')";
   mysqli_query($db,$sqig1) or die('saleinv err'.mysqli_error($db));
}

$sqig=mysqli_query($db,"select invno,invdate,sum(aprice) ap,sum(gstamt) ig,sum(tot) tt from warcouponinvoicepassey  where brcode='$brcode'  and invdate>='$dfrom' and invdate<='$dto' and gstp='0.00'  and invtype in('Spare Parts','Lubricants','Local Parts','Outside Material') group by invno");
 while($res2=mysqli_fetch_array($sqig))
{
 $sqig1="insert into $tbl(invno,invdate,brcode,invtype,0gst,total,salestype) values('$res2[invno]','$res2[invdate]','$brcode','WTY','$res2[ap]','$res2[tt]','spare')";
   mysqli_query($db,$sqig1) or die('saleinv err'.mysqli_error($db));
}

// war service


$sqig=mysqli_query($db,"select invno,invdate,sum(aprice) ap,sum(gstamt) ig,sum(tot) tt from warcouponinvoicepassey  where brcode='$brcode'  and invdate>='$dfrom' and invdate<='$dto' and gstp='18.00' and invtype='Service' group by invno");
 while($res2=mysqli_fetch_array($sqig))
{
 $sqig1="insert into $tbl(invno,invdate,brcode,invtype,18b4,18igst,total,salestype) values('$res2[invno]','$res2[invdate]','$brcode','WTY','$res2[ap]','$res2[ig]','$res2[tt]','Labour')";
   mysqli_query($db,$sqig1) or die('saleinv err'.mysqli_error($db));
}


$sqig=mysqli_query($db,"select invno,invdate,sum(aprice) ap,sum(gstamt) ig,sum(tot) tt from warcouponinvoicepassey  where brcode='$brcode'  and invdate>='$dfrom' and invdate<='$dto' and gstp='0.00' and invtype='Service' group by invno");
 while($res2=mysqli_fetch_array($sqig))
{
 $sqig1="insert into $tbl(invno,invdate,brcode,invtype,0gst,total,salestype) values('$res2[invno]','$res2[invdate]','$brcode','WTY','$res2[ap]','$res2[tt]','Labour')";
   mysqli_query($db,$sqig1) or die('saleinv err'.mysqli_error($db));
}


//  Waranty end  #######################################################



//   Transfer out start  old    ##################################################

// parts
/*
$sqig=mysqli_query($db,"select DealerInvoiceNumber,InvoiceDate,ReceiverPlantName,sum(InvoiceValue) ap,sum(igstamt) ig,sum(InvoiceValue+igstamt) tt from transferout  where brcode='$brcode'  and InvoiceDate>='$dfrom' and InvoiceDate<='$dto' and igstp='28.00'  group by DealerInvoiceNumber");
 while($res2=mysqli_fetch_array($sqig))
{
 $sqig1="insert into $tbl(invno,invdate,cust,brcode,invtype,28b4,28igst,total,salestype) values('$res2[DealerInvoiceNumber]','$res2[InvoiceDate]','$res2[ReceiverPlantName]','$brcode','TROUT','$res2[ap]','$res2[ig]','$res2[tt]','spare')";
 //print $sqig1;
   mysqli_query($db,$sqig1) or die('saleinv err'.mysqli_error($db));
}


$sqig=mysqli_query($db,"select DealerInvoiceNumber,InvoiceDate,ReceiverPlantName,sum(InvoiceValue) ap,sum(igstamt) ig,sum(InvoiceValue+igstamt) tt from transferout  where brcode='$brcode'  and InvoiceDate>='$dfrom' and InvoiceDate<='$dto' and igstp='18.00'  group by DealerInvoiceNumber");
 while($res2=mysqli_fetch_array($sqig))
{
 $sqig1="insert into $tbl(invno,invdate,cust,brcode,invtype,18b4,18igst,total,salestype) values('$res2[DealerInvoiceNumber]','$res2[InvoiceDate]','$res2[ReceiverPlantName]','$brcode','TROUT','$res2[ap]','$res2[ig]','$res2[tt]','spare')";
 //print $sqig1;
   mysqli_query($db,$sqig1) or die('saleinv err'.mysqli_error($db));
}

$sqig=mysqli_query($db,"select DealerInvoiceNumber,InvoiceDate,ReceiverPlantName,sum(InvoiceValue) ap,sum(igstamt) ig,sum(InvoiceValue+igstamt) tt from transferout  where brcode='$brcode'  and InvoiceDate>='$dfrom' and InvoiceDate<='$dto' and igstp='12.00'  group by DealerInvoiceNumber");
 while($res2=mysqli_fetch_array($sqig))
{
 $sqig1="insert into $tbl(invno,invdate,cust,brcode,invtype,12b4,12igst,total,salestype) values('$res2[DealerInvoiceNumber]','$res2[InvoiceDate]','$res2[ReceiverPlantName]','$brcode','TROUT','$res2[ap]','$res2[ig]','$res2[tt]','spare')";
 //print $sqig1;
   mysqli_query($db,$sqig1) or die('saleinv err'.mysqli_error($db));
}

$sqig=mysqli_query($db,"select DealerInvoiceNumber,InvoiceDate,ReceiverPlantName,sum(InvoiceValue) ap,sum(igstamt) ig,sum(InvoiceValue+igstamt) tt from transferout  where brcode='$brcode'  and InvoiceDate>='$dfrom' and InvoiceDate<='$dto' and igstp='5.00'  group by DealerInvoiceNumber");
 while($res2=mysqli_fetch_array($sqig))
{
 $sqig1="insert into $tbl(invno,invdate,cust,brcode,invtype,5b4,5igst,total,salestype) values('$res2[DealerInvoiceNumber]','$res2[InvoiceDate]','$res2[ReceiverPlantName]','$brcode','TROUT','$res2[ap]','$res2[ig]','$res2[tt]','spare')";
 //print $sqig1;
   mysqli_query($db,$sqig1) or die('saleinv err'.mysqli_error($db));
}
*/
//  transfer out end #######################################


//   Transfer out start  igst    ##################################################

// parts

$sqig=mysqli_query($db,"select saprefno,entrydate,to_branch,sum(aprice) ap,sum(taxamt) ig,sum(gtot) tt from sparetransout  where brcode='$brcode'  and entrydate>='$dfrom' and entrydate<='$dto' and taxp='28.00'  group by saprefno");
 while($res2=mysqli_fetch_array($sqig))
{
 $sqig1="insert into $tbl(invno,invdate,cust,brcode,invtype,28b4,28igst,total,salestype) values('$res2[saprefno]','$res2[entrydate]','$res2[to_branch]','$brcode','TROUT','$res2[ap]','$res2[ig]','$res2[tt]','spare')";
 //print $sqig1;
   mysqli_query($db,$sqig1) or die('saleinv err'.mysqli_error($db));
}


$sqig=mysqli_query($db,"select saprefno,entrydate,to_branch,sum(aprice) ap,sum(taxamt) ig,sum(gtot) tt from sparetransout  where brcode='$brcode'  and entrydate>='$dfrom' and entrydate<='$dto' and taxp='18.00'  group by saprefno");
 while($res2=mysqli_fetch_array($sqig))
{
 $sqig1="insert into $tbl(invno,invdate,cust,brcode,invtype,18b4,18igst,total,salestype) values('$res2[saprefno]','$res2[entrydate]','$res2[to_branch]','$brcode','TROUT','$res2[ap]','$res2[ig]','$res2[tt]','spare')";
 //print $sqig1;
   mysqli_query($db,$sqig1) or die('saleinv err'.mysqli_error($db));
}

$sqig=mysqli_query($db,"select saprefno,entrydate,to_branch,sum(aprice) ap,sum(taxamt) ig,sum(gtot) tt from sparetransout  where brcode='$brcode'  and entrydate>='$dfrom' and entrydate<='$dto' and taxp='12.00'  group by saprefno");
 while($res2=mysqli_fetch_array($sqig))
{
 $sqig1="insert into $tbl(invno,invdate,cust,brcode,invtype,12b4,12igst,total,salestype) values('$res2[saprefno]','$res2[entrydate]','$res2[to_branch]','$brcode','TROUT','$res2[ap]','$res2[ig]','$res2[tt]','spare')";
 //print $sqig1;
   mysqli_query($db,$sqig1) or die('saleinv err'.mysqli_error($db));
}

$sqig=mysqli_query($db,"select saprefno,entrydate,to_branch,sum(aprice) ap,sum(taxamt) ig,sum(gtot) tt from sparetransout  where brcode='$brcode'  and entrydate>='$dfrom' and entrydate<='$dto' and taxp='5.00'  group by saprefno");
 while($res2=mysqli_fetch_array($sqig))
{
 $sqig1="insert into $tbl(invno,invdate,cust,brcode,invtype,5b4,5igst,total,salestype) values('$res2[saprefno]','$res2[entrydate]','$res2[to_branch]','$brcode','TROUT','$res2[ap]','$res2[ig]','$res2[tt]','spare')";
 //print $sqig1;
   mysqli_query($db,$sqig1) or die('saleinv err'.mysqli_error($db));
}
//  transfer out igst end #######################################



//      cs Other spare start #################################################

$sq2="select  invno,invdate,customer,sum(aprice) ap,sum(sgstamt) sg,sum(cgstamt) cg,sum(hand) hnd,sum(tot) tt,sum(fcessamt) fcess from spareinvoice_oth where brcode='$brcode' and invdate>='$dfrom' and invdate<='$dto'  and sgstp='14.00' group by invno";
$re21=mysqli_query($db,$sq2)or die('Err3:'.mysqli_error($db));

while($res2=mysqli_fetch_array($re21))
{
 
 $sq14="insert into $tbl(invno,invdate,cust,brcode,invtype,28b4,14sgst,14cgst,hand,total,salestype,kfc) values('$res2[invno]','$res2[invdate]','$res2[customer]','$brcode','CSOSP','$res2[ap]','$res2[sg]','$res2[cg]','$res2[hnd]','$res2[tt]','spare','$res2[fcess]')";
   mysqli_query($db,$sq14) or die('saleinv28cg err'.mysqli_error($db));
}


$sq2="select  invno,invdate,customer,sum(aprice) ap,sum(sgstamt) sg,sum(cgstamt) cg,sum(hand) hnd,sum(tot) tt,sum(fcessamt) fcess from spareinvoice_oth where brcode='$brcode' and invdate>='$dfrom' and invdate<='$dto'  and sgstp='9.00' group by invno";
$re21=mysqli_query($db,$sq2)or die('Err3:'.mysqli_error($db));

while($res2=mysqli_fetch_array($re21))
{
 
 $sq14="insert into $tbl(invno,invdate,cust,brcode,invtype,18b4,9sgst,9cgst,hand,total,salestype,kfc) values('$res2[invno]','$res2[invdate]','$res2[customer]','$brcode','CSOSP','$res2[ap]','$res2[sg]','$res2[cg]','$res2[hnd]','$res2[tt]','spare','$res2[fcess]')";
   mysqli_query($db,$sq14) or die('saleinv28cg err'.mysqli_error($db));
}

$sq2="select  invno,invdate,customer,sum(aprice) ap,sum(sgstamt) sg,sum(cgstamt) cg,sum(hand) hnd,sum(tot) tt,sum(fcessamt) fcess from spareinvoice_oth where brcode='$brcode' and invdate>='$dfrom' and invdate<='$dto'  and sgstp='6.00' group by invno";
$re21=mysqli_query($db,$sq2)or die('Err3:'.mysqli_error($db));

while($res2=mysqli_fetch_array($re21))
{
 
 $sq14="insert into $tbl(invno,invdate,cust,brcode,invtype,12b4,6sgst,6cgst,hand,total,salestype,kfc) values('$res2[invno]','$res2[invdate]','$res2[customer]','$brcode','CSOSP','$res2[ap]','$res2[sg]','$res2[cg]','$res2[hnd]','$res2[tt]','spare','$res2[fcess]')";
   mysqli_query($db,$sq14) or die('saleinv28cg err'.mysqli_error($db));
}

$sq2="select  invno,invdate,customer,sum(aprice) ap,sum(sgstamt) sg,sum(cgstamt) cg,sum(hand) hnd,sum(tot) tt,sum(fcessamt) fcess from spareinvoice_oth where brcode='$brcode' and invdate>='$dfrom' and invdate<='$dto'  and sgstp='2.50' group by invno";
$re21=mysqli_query($db,$sq2)or die('Err3:'.mysqli_error($db));

while($res2=mysqli_fetch_array($re21))
{
 
 $sq14="insert into $tbl(invno,invdate,cust,brcode,invtype,5b4,2_5sgst,2_5cgst,hand,total,salestype,kfc) values('$res2[invno]','$res2[invdate]','$res2[customer]','$brcode','CSOSP','$res2[ap]','$res2[sg]','$res2[cg]','$res2[hnd]','$res2[tt]','spare','$res2[fcess]')";
   mysqli_query($db,$sq14) or die('saleinv28cg err'.mysqli_error($db));
}

$sq2="select  invno,invdate,customer,sum(aprice) ap,sum(sgstamt) sg,sum(cgstamt) cg,sum(hand) hnd,sum(tot) tt,sum(fcessamt) fcess from spareinvoice_oth where brcode='$brcode' and invdate>='$dfrom' and invdate<='$dto'  and sgstp='0.00' and cgstp='0.00' and igstp='0.00' group by invno";
$re21=mysqli_query($db,$sq2)or die('Err3:'.mysqli_error($db));

while($res2=mysqli_fetch_array($re21))
{
 
 $sq14="insert into $tbl(invno,invdate,cust,brcode,invtype,0gst,hand,total,salestype,kfc) values('$res2[invno]','$res2[invdate]','$res2[customer]','$brcode','CSOSP','$res2[ap]','$res2[sg]','$res2[cg]','$res2[hnd]','$res2[tt]','spare','$res2[fcess]')";
   mysqli_query($db,$sq14) or die('saleinv28cg err'.mysqli_error($db));
}


$sqig=mysqli_query($db,"select invno,invdate,customer,sum(aprice) ap,sum(igstamt) ig,sum(hand) hnd,sum(tot) tt,sum(fcessamt) fcess from spareinvoice_oth where brcode='$brcode'  and invdate>='$dfrom' and invdate<='$dto' and igstp='28.00' group by invno");
 while($res2=mysqli_fetch_array($sqig))
{
 $sqig1="insert into $tbl(invno,invdate,cust,brcode,invtype,28b4,28igst,hand,total,salestype,kfc) values('$res2[invno]','$res2[invdate]','$res2[customer]','$brcode','CSOSP','$res2[ap]','$res2[ig]','$res2[hnd]','$res2[hnd]','spare','$res2[fcess]')";
   mysqli_query($db,$sqig1) or die('saleinv err'.mysqli_error($db));
}


$sqig=mysqli_query($db,"select invno,invdate,customer,sum(aprice) ap,sum(igstamt) ig,sum(hand) hnd,sum(tot) tt,sum(fcessamt) fcess from spareinvoice_oth where brcode='$brcode'  and invdate>='$dfrom' and invdate<='$dto' and igstp='18.00' group by invno");
 while($res2=mysqli_fetch_array($sqig))
{
 $sqig1="insert into $tbl(invno,invdate,cust,brcode,invtype,18b4,18igst,hand,total,salestype,kfc) values('$res2[invno]','$res2[invdate]','$res2[customer]','$brcode','CSOSP','$res2[ap]','$res2[ig]','$res2[hnd]','$res2[hnd]','spare','$res2[fcess]')";
   mysqli_query($db,$sqig1) or die('saleinv err'.mysqli_error($db));
}



$sqig=mysqli_query($db,"select invno,invdate,customer,sum(aprice) ap,sum(igstamt) ig,sum(hand) hnd,sum(tot) tt,sum(fcessamt) fcess from spareinvoice_oth where brcode='$brcode'  and invdate>='$dfrom' and invdate<='$dto' and igstp='12.00' group by invno");
 while($res2=mysqli_fetch_array($sqig))
{
 $sqig1="insert into $tbl(invno,invdate,cust,brcode,invtype,12b4,12igst,hand,total,salestype,kfc) values('$res2[invno]','$res2[invdate]','$res2[customer]','$brcode','CSOSP','$res2[ap]','$res2[ig]','$res2[hnd]','$res2[hnd]','spare','$res2[fcess]')";
   mysqli_query($db,$sqig1) or die('saleinv err'.mysqli_error($db));
}


$sqig=mysqli_query($db,"select invno,invdate,customer,sum(aprice) ap,sum(igstamt) ig,sum(hand) hnd,sum(tot) tt,sum(fcessamt) fcess from spareinvoice_oth where brcode='$brcode' and invdate>='$dfrom' and invdate<='$dto' and igstp='5.00' group by invno");
 while($res2=mysqli_fetch_array($sqig))
{
 $sqig1="insert into $tbl(invno,invdate,cust,brcode,invtype,5b4,5igst,hand,total,salestype,kfc) values('$res2[invno]','$res2[invdate]','$res2[customer]','$brcode','CSOSP','$res2[ap]','$res2[ig]','$res2[hnd]','$res2[hnd]','spare','$res2[fcess]')";
   mysqli_query($db,$sqig1) or die('saleinv err'.mysqli_error($db));
}




// ###########  cs other spare end  ############################################


//      cs Other Lab start ###################################################

$sq2="select  invno,invdate,customer,sum(aprice) ap,sum(sgstamt) sg,sum(cgstamt) cg,sum(hand) hnd,sum(tot) tt,sum(fcessamt) fcess from spareinvoice_lab where brcode='$brcode' and invdate>='$dfrom' and invdate<='$dto'  and sgstp='14.00' group by invno";
$re21=mysqli_query($db,$sq2)or die('Err3:'.mysqli_error($db));

while($res2=mysqli_fetch_array($re21))
{
 
 $sq14="insert into $tbl(invno,invdate,cust,brcode,invtype,28b4,14sgst,14cgst,hand,total,salestypekfc) values('$res2[invno]','$res2[invdate]','$res2[customer]','$brcode','CSOLAB','$res2[ap]','$res2[sg]','$res2[cg]','$res2[hnd]','$res2[tt]','spare','$res2[fcess]')";
   mysqli_query($db,$sq14) or die('saleinv28cg err'.mysqli_error($db));
}


$sq2="select  invno,invdate,customer,sum(aprice) ap,sum(sgstamt) sg,sum(cgstamt) cg,sum(hand) hnd,sum(tot) tt,sum(fcessamt) fcess from spareinvoice_lab where brcode='$brcode' and invdate>='$dfrom' and invdate<='$dto'  and sgstp='9.00' group by invno";
$re21=mysqli_query($db,$sq2)or die('Err3:'.mysqli_error($db));

while($res2=mysqli_fetch_array($re21))
{
 
 $sq14="insert into $tbl(invno,invdate,cust,brcode,invtype,18b4,9sgst,9cgst,hand,total,salestype,kfc) values('$res2[invno]','$res2[invdate]','$res2[customer]','$brcode','CSOLAB','$res2[ap]','$res2[sg]','$res2[cg]','$res2[hnd]','$res2[tt]','spare','$res2[fcess]')";
   mysqli_query($db,$sq14) or die('saleinv28cg err'.mysqli_error($db));
}

$sq2="select  invno,invdate,customer,sum(aprice) ap,sum(sgstamt) sg,sum(cgstamt) cg,sum(hand) hnd,sum(tot) tt,sum(fcessamt) fcess from spareinvoice_lab where brcode='$brcode' and invdate>='$dfrom' and invdate<='$dto'  and sgstp='6.00' group by invno";
$re21=mysqli_query($db,$sq2)or die('Err3:'.mysqli_error($db));

while($res2=mysqli_fetch_array($re21))
{
 
 $sq14="insert into $tbl(invno,invdate,cust,brcode,invtype,12b4,6sgst,6cgst,hand,total,salestype,kfc) values('$res2[invno]','$res2[invdate]','$res2[customer]','$brcode','CSOLAB','$res2[ap]','$res2[sg]','$res2[cg]','$res2[hnd]','$res2[tt]','spare','$res2[fcess]')";
   mysqli_query($db,$sq14) or die('saleinv28cg err'.mysqli_error($db));
}

$sq2="select  invno,invdate,customer,sum(aprice) ap,sum(sgstamt) sg,sum(cgstamt) cg,sum(hand) hnd,sum(tot) tt,sum(fcessamt) fcess from spareinvoice_lab where brcode='$brcode' and invdate>='$dfrom' and invdate<='$dto'  and sgstp='2.50' group by invno";
$re21=mysqli_query($db,$sq2)or die('Err3:'.mysqli_error($db));

while($res2=mysqli_fetch_array($re21))
{
 
 $sq14="insert into $tbl(invno,invdate,cust,brcode,invtype,5b4,2_5sgst,2_5cgst,hand,total,salestype,kfc) values('$res2[invno]','$res2[invdate]','$res2[customer]','$brcode','CSOLAB','$res2[ap]','$res2[sg]','$res2[cg]','$res2[hnd]','$res2[tt]','spare','$res2[fcess]')";
   mysqli_query($db,$sq14) or die('saleinv28cg err'.mysqli_error($db));
}

$sq2="select  invno,invdate,customer,sum(aprice) ap,sum(sgstamt) sg,sum(cgstamt) cg,sum(hand) hnd,sum(tot) tt,sum(fcessamt) fcess from spareinvoice_lab where brcode='$brcode' and invdate>='$dfrom' and invdate<='$dto'  and sgstp='0.00' and cgstp='0.00' and igstp='0.00' group by invno";
$re21=mysqli_query($db,$sq2)or die('Err3:'.mysqli_error($db));

while($res2=mysqli_fetch_array($re21))
{
 
 $sq14="insert into $tbl(invno,invdate,cust,brcode,invtype,0gst,hand,total,salestype,kfc) values('$res2[invno]','$res2[invdate]','$res2[customer]','$brcode','CSOLAB','$res2[ap]','$res2[sg]','$res2[cg]','$res2[hnd]','$res2[tt]','spare','$res2[fcess]')";
   mysqli_query($db,$sq14) or die('saleinv28cg err'.mysqli_error($db));
}


$sqig=mysqli_query($db,"select invno,invdate,customer,sum(aprice) ap,sum(igstamt) ig,sum(hand) hnd,sum(tot) tt,sum(fcessamt) fcess from spareinvoice_lab where brcode='$brcode'  and invdate>='$dfrom' and invdate<='$dto' and igstp='28.00' group by invno");
 while($res2=mysqli_fetch_array($sqig))
{
 $sqig1="insert into $tbl(invno,invdate,cust,brcode,invtype,28b4,28igst,hand,total,salestype,kfc) values('$res2[invno]','$res2[invdate]','$res2[customer]','$brcode','CSOLAB','$res2[ap]','$res2[ig]','$res2[hnd]','$res2[hnd]','spare','$res2[fcess]')";
   mysqli_query($db,$sqig1) or die('saleinv err'.mysqli_error($db));
}


$sqig=mysqli_query($db,"select invno,invdate,customer,sum(aprice) ap,sum(igstamt) ig,sum(hand) hnd,sum(tot) tt,sum(fcessamt) fcess from spareinvoice_lab where brcode='$brcode'  and invdate>='$dfrom' and invdate<='$dto' and igstp='18.00' group by invno");
 while($res2=mysqli_fetch_array($sqig))
{
 $sqig1="insert into $tbl(invno,invdate,cust,brcode,invtype,18b4,18igst,hand,total,salestype,kfc) values('$res2[invno]','$res2[invdate]','$res2[customer]','$brcode','CSOLAB','$res2[ap]','$res2[ig]','$res2[hnd]','$res2[hnd]','spare','$res2[fcess]')";
   mysqli_query($db,$sqig1) or die('saleinv err'.mysqli_error($db));
}



$sqig=mysqli_query($db,"select invno,invdate,customer,sum(aprice) ap,sum(igstamt) ig,sum(hand) hnd,sum(tot) tt ,sum(fcessamt) fcess from spareinvoice_lab where brcode='$brcode'  and invdate>='$dfrom' and invdate<='$dto' and igstp='12.00' group by invno");
 while($res2=mysqli_fetch_array($sqig))
{
 $sqig1="insert into $tbl(invno,invdate,cust,brcode,invtype,12b4,12igst,hand,total,salestype,kfc) values('$res2[invno]','$res2[invdate]','$res2[customer]','$brcode','CSOLAB','$res2[ap]','$res2[ig]','$res2[hnd]','$res2[hnd]','spare','$res2[fcess]')";
   mysqli_query($db,$sqig1) or die('saleinv err'.mysqli_error($db));
}


$sqig=mysqli_query($db,"select invno,invdate,customer,sum(aprice) ap,sum(igstamt) ig,sum(hand) hnd,sum(tot) tt ,sum(fcessamt) fcess from spareinvoice_lab where brcode='$brcode' and invdate>='$dfrom' and invdate<='$dto' and igstp='5.00' group by invno");
 while($res2=mysqli_fetch_array($sqig))
{
 $sqig1="insert into $tbl(invno,invdate,cust,brcode,invtype,5b4,5igst,hand,total,salestype,kfc) values('$res2[invno]','$res2[invdate]','$res2[customer]','$brcode','CSOLAB','$res2[ap]','$res2[ig]','$res2[hnd]','$res2[hnd]','spare','$res2[fcess]')";
   mysqli_query($db,$sqig1) or die('saleinv err'.mysqli_error($db));
}




// ###########  cs other Lab  end ############################################



//      pret eich  start  #####################################################

$sq2="select  invno,invdate,customer,sum(aprice) ap,sum(sgstamt) sg,sum(cgstamt) cg,sum(hand) hnd,sum(tot) tt from sparepurreteich where brcode='$brcode' and invdate>='$dfrom' and invdate<='$dto'  and sgstp='14.00' group by invno";
$re21=mysqli_query($db,$sq2)or die('Err3:'.mysqli_error($db));

while($res2=mysqli_fetch_array($re21))
{
 
 $sq14="insert into $tbl(invno,invdate,cust,brcode,invtype,28b4,14sgst,14cgst,hand,total,salestype) values('$res2[invno]','$res2[invdate]','$res2[customer]','$brcode','PRETE','$res2[ap]','$res2[sg]','$res2[cg]','$res2[hnd]','$res2[tt]','spare')";
 //print $sq14;
   mysqli_query($db,$sq14) or die('saleinv28cg err'.mysqli_error($db));
}


$sq2="select  invno,invdate,customer,sum(aprice) ap,sum(sgstamt) sg,sum(cgstamt) cg,sum(hand) hnd,sum(tot) tt from sparepurreteich where brcode='$brcode' and invdate>='$dfrom' and invdate<='$dto'  and sgstp='9.00' group by invno";
$re21=mysqli_query($db,$sq2)or die('Err3:'.mysqli_error($db));

while($res2=mysqli_fetch_array($re21))
{
 
 $sq14="insert into $tbl(invno,invdate,cust,brcode,invtype,18b4,9sgst,9cgst,hand,total,salestype) values('$res2[invno]','$res2[invdate]','$res2[customer]','$brcode','PRETE','$res2[ap]','$res2[sg]','$res2[cg]','$res2[hnd]','$res2[tt]','spare')";
   mysqli_query($db,$sq14) or die('saleinv28cg err'.mysqli_error($db));
}

$sq2="select  invno,invdate,customer,sum(aprice) ap,sum(sgstamt) sg,sum(cgstamt) cg,sum(hand) hnd,sum(tot) tt from sparepurreteich where brcode='$brcode' and invdate>='$dfrom' and invdate<='$dto'  and sgstp='6.00' group by invno";
$re21=mysqli_query($db,$sq2)or die('Err3:'.mysqli_error($db));

while($res2=mysqli_fetch_array($re21))
{
 
 $sq14="insert into $tbl(invno,invdate,cust,brcode,invtype,12b4,6sgst,6cgst,hand,total,salestype) values('$res2[invno]','$res2[invdate]','$res2[customer]','$brcode','PRETE','$res2[ap]','$res2[sg]','$res2[cg]','$res2[hnd]','$res2[tt]','spare')";
   mysqli_query($db,$sq14) or die('saleinv28cg err'.mysqli_error($db));
}

$sq2="select  invno,invdate,customer,sum(aprice) ap,sum(sgstamt) sg,sum(cgstamt) cg,sum(hand) hnd,sum(tot) tt from sparepurreteich where brcode='$brcode' and invdate>='$dfrom' and invdate<='$dto'  and sgstp='2.50' group by invno";
$re21=mysqli_query($db,$sq2)or die('Err3:'.mysqli_error($db));

while($res2=mysqli_fetch_array($re21))
{
 
 $sq14="insert into $tbl(invno,invdate,cust,brcode,invtype,5b4,2_5sgst,2_5cgst,hand,total,salestype) values('$res2[invno]','$res2[invdate]','$res2[customer]','$brcode','PRETE','$res2[ap]','$res2[sg]','$res2[cg]','$res2[hnd]','$res2[tt]','spare')";
   mysqli_query($db,$sq14) or die('saleinv28cg err'.mysqli_error($db));
}

$sq2="select  invno,invdate,customer,sum(aprice) ap,sum(sgstamt) sg,sum(cgstamt) cg,sum(hand) hnd,sum(tot) tt from sparepurreteich where brcode='$brcode' and invdate>='$dfrom' and invdate<='$dto'  and sgstp='0.00' and cgstp='0.00' and igstp='0.00' group by invno";
$re21=mysqli_query($db,$sq2)or die('Err3:'.mysqli_error($db));

while($res2=mysqli_fetch_array($re21))
{
 
 $sq14="insert into $tbl(invno,invdate,cust,brcode,invtype,0gst,hand,total,salestype) values('$res2[invno]','$res2[invdate]','$res2[customer]','$brcode','PRETE','$res2[ap]','$res2[sg]','$res2[cg]','$res2[hnd]','$res2[tt]','spare')";
   mysqli_query($db,$sq14) or die('saleinv28cg err'.mysqli_error($db));
}

/*
$sqig=mysqli_query($db,"select invno,invdate,customer,sum(aprice) ap,sum(igstamt) ig,sum(hand) hnd,sum(tot) tt from sparepurreteich where brcode='$brcode'  and invdate>='$dfrom' and invdate<='$dto' and igstp='28.00' group by invno");
 while($res2=mysqli_fetch_array($sqig))
{
 $sqig1="insert into $tbl(invno,invdate,cust,brcode,invtype,28b4,28igst,hand,total,salestype) values('$res2[invno]','$res2[invdate]','$res2[customer]','$brcode','PRETE','$res2[ap]','$res2[ig]','$res2[hnd]','$res2[hnd]','spare')";
 
 print $sqig1;
   mysqli_query($db,$sqig1) or die('saleinv err'.mysqli_error($db));
}


$sqig=mysqli_query($db,"select invno,invdate,customer,sum(aprice) ap,sum(igstamt) ig,sum(hand) hnd,sum(tot) tt from sparepurreteich where brcode='$brcode'  and invdate>='$dfrom' and invdate<='$dto' and igstp='18.00' group by invno");
 while($res2=mysqli_fetch_array($sqig))
{
 $sqig1="insert into $tbl(invno,invdate,cust,brcode,invtype,18b4,18igst,hand,total,salestype) values('$res2[invno]','$res2[invdate]','$res2[customer]','$brcode','PRETE','$res2[ap]','$res2[ig]','$res2[hnd]','$res2[hnd]','spare')";
   mysqli_query($db,$sqig1) or die('saleinv err'.mysqli_error($db));
}



$sqig=mysqli_query($db,"select invno,invdate,customer,sum(aprice) ap,sum(igstamt) ig,sum(hand) hnd,sum(tot) tt from sparepurreteich where brcode='$brcode'  and invdate>='$dfrom' and invdate<='$dto' and igstp='12.00' group by invno");
 while($res2=mysqli_fetch_array($sqig))
{
 $sqig1="insert into $tbl(invno,invdate,cust,brcode,invtype,12b4,12igst,hand,total,salestype) values('$res2[invno]','$res2[invdate]','$res2[customer]','$brcode','PRETE','$res2[ap]','$res2[ig]','$res2[hnd]','$res2[hnd]','spare')";
   mysqli_query($db,$sqig1) or die('saleinv err'.mysqli_error($db));
}


$sqig=mysqli_query($db,"select invno,invdate,customer,sum(aprice) ap,sum(igstamt) ig,sum(hand) hnd,sum(tot) tt from sparepurreteich where brcode='$brcode' and invdate>='$dfrom' and invdate<='$dto' and igstp='5.00' group by invno");
 while($res2=mysqli_fetch_array($sqig))
{
 $sqig1="insert into $tbl(invno,invdate,cust,brcode,invtype,5b4,5igst,hand,total,salestype) values('$res2[invno]','$res2[invdate]','$res2[customer]','$brcode','PRETE','$res2[ap]','$res2[ig]','$res2[hnd]','$res2[hnd]','spare')";
   mysqli_query($db,$sqig1) or die('saleinv err'.mysqli_error($db));
}

*/


$sqig=mysqli_query($db,"select invno,invdate,customer,sum(aprice) ap,sum(igstamt) ig,sum(hand) hnd,sum(tot) tt from sparepurreteich where brcode='$brcode'  and invdate>='$dfrom' and invdate<='$dto' and igstp='28.00' group by invno");
 while($res2=mysqli_fetch_array($sqig))
{
 $sqig1="insert into $tbl(invno,invdate,cust,brcode,invtype,28b4,28igst,hand,total,salestype) values('$res2[invno]','$res2[invdate]','$res2[customer]','$brcode','PRETE','$res2[ap]','$res2[ig]','$res2[hnd]','$res2[hnd]','spare')";
 
 //print $sqig1;
   mysqli_query($db,$sqig1) or die('saleinv err'.mysqli_error($db));
}


$sqig=mysqli_query($db,"select invno,invdate,customer,sum(aprice) ap,sum(igstamt) ig,sum(hand) hnd,sum(tot) tt from sparepurreteich where brcode='$brcode'  and invdate>='$dfrom' and invdate<='$dto' and igstp='18.00' group by invno");
 while($res2=mysqli_fetch_array($sqig))
{
 $sqig1="insert into $tbl(invno,invdate,cust,brcode,invtype,18b4,18igst,hand,total,salestype) values('$res2[invno]','$res2[invdate]','$res2[customer]','$brcode','PRETE','$res2[ap]','$res2[ig]','$res2[hnd]','$res2[hnd]','spare')";
   mysqli_query($db,$sqig1) or die('saleinv err'.mysqli_error($db));
}



$sqig=mysqli_query($db,"select invno,invdate,customer,sum(aprice) ap,sum(igstamt) ig,sum(hand) hnd,sum(tot) tt from sparepurreteich where brcode='$brcode'  and invdate>='$dfrom' and invdate<='$dto' and igstp='12.00' group by invno");
 while($res2=mysqli_fetch_array($sqig))
{
 $sqig1="insert into $tbl(invno,invdate,cust,brcode,invtype,12b4,12igst,hand,total,salestype) values('$res2[invno]','$res2[invdate]','$res2[customer]','$brcode','PRETE','$res2[ap]','$res2[ig]','$res2[hnd]','$res2[hnd]','spare')";
   mysqli_query($db,$sqig1) or die('saleinv err'.mysqli_error($db));
}


$sqig=mysqli_query($db,"select invno,invdate,customer,sum(aprice) ap,sum(igstamt) ig,sum(hand) hnd,sum(tot) tt from sparepurreteich where brcode='$brcode' and invdate>='$dfrom' and invdate<='$dto' and igstp='5.00' group by invno");
 while($res2=mysqli_fetch_array($sqig))
{
 $sqig1="insert into $tbl(invno,invdate,cust,brcode,invtype,5b4,5igst,hand,total,salestype) values('$res2[invno]','$res2[invdate]','$res2[customer]','$brcode','PRETE','$res2[ap]','$res2[ig]','$res2[hnd]','$res2[hnd]','spare')";
   mysqli_query($db,$sqig1) or die('saleinv err'.mysqli_error($db));
}


// ###############  pret eich end   ##########################################

// expense rev start  ##################################################


$sq2="select  refno,date,vendor,sum(before_tax) ap,sum(sgstamt) sg,sum(cgstamt) cg,sum(tdsamt) hnd,sum(expense_amount) tt from gst_expenserev where brcode='$brcode' and date>='$dfrom' and date<='$dto'  and sgstp='14.00' group by refno";
$re21=mysqli_query($db,$sq2)or die('Err3:'.mysqli_error($db));

while($res2=mysqli_fetch_array($re21))
{
 
 $sq14="insert into $tbl(invno,invdate,cust,brcode,invtype,28b4,14sgst,14cgst,hand,total,salestype) values('$res2[refno]','$res2[date]','$res2[vendor]','$brcode','EXPREV','$res2[ap]','$res2[sg]','$res2[cg]','$res2[hnd]','$res2[tt]','spare')";
   mysqli_query($db,$sq14) or die('saleinv28cg err'.mysqli_error($db));
}


$sq2="select  refno,date,vendor,sum(before_tax) ap,sum(sgstamt) sg,sum(cgstamt) cg,sum(tdsamt) hnd,sum(expense_amount) tt from gst_expenserev where brcode='$brcode' and date>='$dfrom' and date<='$dto'  and sgstp='9.00' group by refno";
$re21=mysqli_query($db,$sq2)or die('Err3:'.mysqli_error($db));

while($res2=mysqli_fetch_array($re21))
{
 
 $sq14="insert into $tbl(invno,invdate,cust,brcode,invtype,18b4,9sgst,9cgst,hand,total,salestype) values('$res2[refno]','$res2[date]','$res2[vendor]','$brcode','EXPREV','$res2[ap]','$res2[sg]','$res2[cg]','$res2[hnd]','$res2[tt]','spare')";
   mysqli_query($db,$sq14) or die('saleinv28cg err'.mysqli_error($db));
}


$sq2="select  refno,date,vendor,sum(before_tax) ap,sum(sgstamt) sg,sum(cgstamt) cg,sum(tdsamt) hnd,sum(expense_amount) tt from gst_expenserev where brcode='$brcode' and date>='$dfrom' and date<='$dto'  and sgstp='6.00' group by refno";
$re21=mysqli_query($db,$sq2)or die('Err3:'.mysqli_error($db));

while($res2=mysqli_fetch_array($re21))
{
 
 $sq14="insert into $tbl(invno,invdate,cust,brcode,invtype,12b4,6sgst,6cgst,hand,total,salestype) values('$res2[refno]','$res2[date]','$res2[vendor]','$brcode','EXPREV','$res2[ap]','$res2[sg]','$res2[cg]','$res2[hnd]','$res2[tt]','spare')";
   mysqli_query($db,$sq14) or die('saleinv28cg err'.mysqli_error($db));
}

$sq2="select  refno,date,vendor,sum(before_tax) ap,sum(sgstamt) sg,sum(cgstamt) cg,sum(tdsamt) hnd,sum(expense_amount) tt from gst_expenserev where brcode='$brcode' and date>='$dfrom' and date<='$dto'  and sgstp='2.50' group by refno";
$re21=mysqli_query($db,$sq2)or die('Err3:'.mysqli_error($db));

while($res2=mysqli_fetch_array($re21))
{
 
 $sq14="insert into $tbl(invno,invdate,cust,brcode,invtype,5b4,2_5sgst,2_5cgst,hand,total,salestype) values('$res2[refno]','$res2[date]','$res2[vendor]','$brcode','EXPREV','$res2[ap]','$res2[sg]','$res2[cg]','$res2[hnd]','$res2[tt]','spare')";
   mysqli_query($db,$sq14) or die('saleinv28cg err'.mysqli_error($db));
}


$sq2="select  refno,date,vendor,sum(before_tax) ap,sum(sgstamt) sg,sum(cgstamt) cg,sum(tdsamt) hnd,sum(expense_amount) tt from gst_expenserev where brcode='$brcode' and date>='$dfrom' and date<='$dto'  and sgstp='0.00' and cgstp='0.00' and igstp='0.00' group by refno";
$re21=mysqli_query($db,$sq2)or die('Err3:'.mysqli_error($db));

while($res2=mysqli_fetch_array($re21))
{
 
 $sq14="insert into $tbl(invno,invdate,cust,brcode,invtype,0gst,hand,total,salestype) values('$res2[refno]','$res2[date]','$res2[vendor]','$brcode','EXPREV','$res2[ap]','$res2[hnd]','$res2[tt]','spare')";
   mysqli_query($db,$sq14) or die('saleinv28cg err'.mysqli_error($db));
}


$sq2="select  refno,date,vendor,sum(before_tax) ap,sum(igstamt) ig,sum(tdsamt) hnd,sum(expense_amount) tt from gst_expenserev where brcode='$brcode' and date>='$dfrom' and date<='$dto'  and igstp='28.00' group by refno";
$re21=mysqli_query($db,$sq2)or die('Err3:'.mysqli_error($db));

while($res2=mysqli_fetch_array($re21))
{
 
 $sq14="insert into $tbl(invno,invdate,cust,brcode,invtype,28b4,28igst,hand,total,salestype) values('$res2[refno]','$res2[date]','$res2[vendor]','$brcode','EXPREV','$res2[ap]','$res2[ig]','$res2[hnd]','$res2[tt]','spare')";
   mysqli_query($db,$sq14) or die('saleinv28cg err'.mysqli_error($db));
}

$sq2="select  refno,date,vendor,sum(before_tax) ap,sum(igstamt) ig,sum(tdsamt) hnd,sum(expense_amount) tt from gst_expenserev where brcode='$brcode' and date>='$dfrom' and date<='$dto'  and igstp='18.00' group by refno";
$re21=mysqli_query($db,$sq2)or die('Err3:'.mysqli_error($db));

while($res2=mysqli_fetch_array($re21))
{
 
 $sq14="insert into $tbl(invno,invdate,cust,brcode,invtype,18b4,18igst,hand,total,salestype) values('$res2[refno]','$res2[date]','$res2[vendor]','$brcode','EXPREV','$res2[ap]','$res2[ig]','$res2[hnd]','$res2[tt]','spare')";
   mysqli_query($db,$sq14) or die('saleinv28cg err'.mysqli_error($db));
}


$sq2="select  refno,date,vendor,sum(before_tax) ap,sum(igstamt) ig,sum(tdsamt) hnd,sum(expense_amount) tt from gst_expenserev where brcode='$brcode' and date>='$dfrom' and date<='$dto'  and igstp='12.00' group by refno";
$re21=mysqli_query($db,$sq2)or die('Err3:'.mysqli_error($db));

while($res2=mysqli_fetch_array($re21))
{
 
 $sq14="insert into $tbl(invno,invdate,cust,brcode,invtype,12b4,12igst,hand,total,salestype) values('$res2[refno]','$res2[date]','$res2[vendor]','$brcode','EXPREV','$res2[ap]','$res2[ig]','$res2[hnd]','$res2[tt]','spare')";
   mysqli_query($db,$sq14) or die('saleinv28cg err'.mysqli_error($db));
}


$sq2="select  refno,date,vendor,sum(before_tax) ap,sum(igstamt) ig,sum(tdsamt) hnd,sum(expense_amount) tt from gst_expenserev where brcode='$brcode' and date>='$dfrom' and date<='$dto'  and igstp='5.00' group by refno";
$re21=mysqli_query($db,$sq2)or die('Err3:'.mysqli_error($db));

while($res2=mysqli_fetch_array($re21))
{
 
 $sq14="insert into $tbl(invno,invdate,cust,brcode,invtype,5b4,5igst,hand,total,salestype) values('$res2[refno]','$res2[date]','$res2[vendor]','$brcode','EXPREV','$res2[ap]','$res2[ig]','$res2[hnd]','$res2[tt]','spare')";
   mysqli_query($db,$sq14) or die('saleinv28cg err'.mysqli_error($db));
}

//  expense rev   end  ################################################

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


// GST Income start  ##################################################


$sq2="select  vendrinvno,date,vendor,sum(before_tax) ap,sum(sgstamt) sg,sum(cgstamt) cg,sum(expense_amount) tt from gst_income where brcode='$brcode' and date>='$dfrom' and date<='$dto'  and sgstp='14.00' group by vendrinvno";
$re21=mysqli_query($db,$sq2)or die('Err3:'.mysqli_error($db));

while($res2=mysqli_fetch_array($re21))
{
 
 $sq14="insert into $tbl(invno,invdate,cust,brcode,invtype,28b4,14sgst,14cgst,total,salestype) values('$res2[vendrinvno]','$res2[date]','$res2[vendor]','$brcode','INC','$res2[ap]','$res2[sg]','$res2[cg]','$res2[tt]','spare')";
   mysqli_query($db,$sq14) or die('saleinv28cg err'.mysqli_error($db));
}


$sq2="select  vendrinvno,date,vendor,sum(before_tax) ap,sum(sgstamt) sg,sum(cgstamt) cg,sum(expense_amount) tt from gst_income where brcode='$brcode' and date>='$dfrom' and date<='$dto'  and sgstp='9.00' group by vendrinvno";
$re21=mysqli_query($db,$sq2)or die('Err3:'.mysqli_error($db));

while($res2=mysqli_fetch_array($re21))
{
 
 $sq14="insert into $tbl(invno,invdate,cust,brcode,invtype,18b4,9sgst,9cgst,total,salestype) values('$res2[vendrinvno]','$res2[date]','$res2[vendor]','$brcode','INC','$res2[ap]','$res2[sg]','$res2[cg]','$res2[tt]','spare')";
   mysqli_query($db,$sq14) or die('saleinv28cg err'.mysqli_error($db));
}


$sq2="select  vendrinvno,date,vendor,sum(before_tax) ap,sum(sgstamt) sg,sum(cgstamt) cg,sum(expense_amount) tt from gst_income where brcode='$brcode' and date>='$dfrom' and date<='$dto'  and sgstp='6.00' group by vendrinvno";
$re21=mysqli_query($db,$sq2)or die('Err3:'.mysqli_error($db));

while($res2=mysqli_fetch_array($re21))
{
 
 $sq14="insert into $tbl(invno,invdate,cust,brcode,invtype,12b4,6sgst,6cgst,total,salestype) values('$res2[vendrinvno]','$res2[date]','$res2[vendor]','$brcode','INC','$res2[ap]','$res2[sg]','$res2[cg]','$res2[tt]','spare')";
   mysqli_query($db,$sq14) or die('saleinv28cg err'.mysqli_error($db));
}

$sq2="select  vendrinvno,date,vendor,sum(before_tax) ap,sum(sgstamt) sg,sum(cgstamt) cg,sum(expense_amount) tt from gst_income where brcode='$brcode' and date>='$dfrom' and date<='$dto'  and sgstp='2.50' group by vendrinvno";
$re21=mysqli_query($db,$sq2)or die('Err3:'.mysqli_error($db));

while($res2=mysqli_fetch_array($re21))
{
 
 $sq14="insert into $tbl(invno,invdate,cust,brcode,invtype,5b4,2_5sgst,2_5cgst,total,salestype) values('$res2[vendrinvno]','$res2[date]','$res2[vendor]','$brcode','INC','$res2[ap]','$res2[sg]','$res2[cg]','$res2[tt]','spare')";
   mysqli_query($db,$sq14) or die('saleinv28cg err'.mysqli_error($db));
}


$sq2="select  vendrinvno,date,vendor,sum(before_tax) ap,sum(sgstamt) sg,sum(cgstamt) cg,sum(expense_amount) tt from gst_income where brcode='$brcode' and date>='$dfrom' and date<='$dto'  and sgstp='0.00' and cgstp='0.00' and igstp='0.00' group by vendrinvno";
$re21=mysqli_query($db,$sq2)or die('Err3:'.mysqli_error($db));

while($res2=mysqli_fetch_array($re21))
{
 
 $sq14="insert into $tbl(invno,invdate,cust,brcode,invtype,0gst,total,salestype) values('$res2[vendrinvno]','$res2[date]','$res2[vendor]','$brcode','INC','$res2[ap]','$res2[tt]','spare')";
   mysqli_query($db,$sq14) or die('saleinv28cg err'.mysqli_error($db));
}


$sq2="select  vendrinvno,date,vendor,sum(before_tax) ap,sum(igstamt) ig,sum(expense_amount) tt from gst_income where brcode='$brcode' and date>='$dfrom' and date<='$dto'  and igstp='28.00' group by vendrinvno";
$re21=mysqli_query($db,$sq2)or die('Err3:'.mysqli_error($db));

while($res2=mysqli_fetch_array($re21))
{
 
 $sq14="insert into $tbl(invno,invdate,cust,brcode,invtype,28b4,28igst,total,salestype) values('$res2[vendrinvno]','$res2[date]','$res2[vendor]','$brcode','INC','$res2[ap]','$res2[ig]','$res2[tt]','spare')";
   mysqli_query($db,$sq14) or die('saleinv28cg err'.mysqli_error($db));
}

$sq2="select  vendrinvno,date,vendor,sum(before_tax) ap,sum(igstamt) ig,sum(expense_amount) tt from gst_income where brcode='$brcode' and date>='$dfrom' and date<='$dto'  and igstp='18.00' group by vendrinvno";
$re21=mysqli_query($db,$sq2)or die('Err3:'.mysqli_error($db));

while($res2=mysqli_fetch_array($re21))
{
 
 $sq14="insert into $tbl(invno,invdate,cust,brcode,invtype,18b4,18igst,total,salestype) values('$res2[vendrinvno]','$res2[date]','$res2[vendor]','$brcode','INC','$res2[ap]','$res2[ig]','$res2[tt]','spare')";
   mysqli_query($db,$sq14) or die('saleinv28cg err'.mysqli_error($db));
}


$sq2="select  vendrinvno,date,vendor,sum(before_tax) ap,sum(igstamt) ig,sum(expense_amount) tt from gst_income where brcode='$brcode' and date>='$dfrom' and date<='$dto'  and igstp='12.00' group by vendrinvno";
$re21=mysqli_query($db,$sq2)or die('Err3:'.mysqli_error($db));

while($res2=mysqli_fetch_array($re21))
{
 
 $sq14="insert into $tbl(invno,invdate,cust,brcode,invtype,12b4,12igst,total,salestype) values('$res2[vendrinvno]','$res2[date]','$res2[vendor]','$brcode','INC','$res2[ap]','$res2[ig]','$res2[tt]','spare')";
   mysqli_query($db,$sq14) or die('saleinv28cg err'.mysqli_error($db));
}


$sq2="select  vendrinvno,date,vendor,sum(before_tax) ap,sum(igstamt) ig,sum(expense_amount) tt from gst_income where brcode='$brcode' and date>='$dfrom' and date<='$dto'  and igstp='5.00' group by vendrinvno";
$re21=mysqli_query($db,$sq2)or die('Err3:'.mysqli_error($db));

while($res2=mysqli_fetch_array($re21))
{
 
 $sq14="insert into $tbl(invno,invdate,cust,brcode,invtype,5b4,5igst,total,salestype) values('$res2[vendrinvno]','$res2[date]','$res2[vendor]','$brcode','INC','$res2[ap]','$res2[ig]','$res2[tt]','spare')";
   mysqli_query($db,$sq14) or die('saleinv28cg err'.mysqli_error($db));
}

//  GST Income   end  ################################################



//  counter sale  print


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>Cess<th>Total ";

    $reinvno=mysqli_query($db,"select distinct invno,invdate,cust from $tbl  where brcode='$brcode' and invtype='CS' order by invno,invdate ")or die('err'.mysqli_error($db));
  $bta5=0;
$cg5=0;
$sg5=0;
$ig5=0;
$bta12=0;
$cg12=0;
$sg12=0;
$ig12=0;
$bta18=0;
$cg18=0;
$sg18=0;
$ig18=0;
$bta28=0;
$cg28=0;
$sg28=0;
$ig28=0;
$bta0=0;
$gtot=0;
    $hand1=0;  
    $totb4=0;
    $totgst=0;
    $totgtot=0;
    $tothand=0;
    $kfc=0;
    while($rowinvno=mysqli_fetch_array($reinvno))
{
    
     //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));    

$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,sum(kfc) kfc from $tbl  where brcode='$brcode'   and invno='$rowinvno[0]' group by invno")or die('err2w'.mysqli_error($db));
   

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];
	
	 
    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>";
   //28
    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>";
    //18
    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>";
    //12
    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>";
    //5
    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>";
    //0 and hand
    print "<td align=right>".putcoma($row[16])."</td><td align=right>".putComa($row[17])."</td><td align=right>".putComa($row[19])."</td>";
   //tot
   print "<td align=right>".putcoma($row[18])."</td></tr>";
   
  $bta5+=$row[12];
$cg5+=$row[14];
$sg5+=$row[13];
$ig5+=$row[15];

$bta12+=$row[8];
$cg12+=$row[10];
$sg12+=$row[9];
$ig12+=$row[11];

$bta18+=$row[4];
$cg18+=$row[6];
$sg18+=$row[5];
$ig18+=$row[7];

$bta28+=$row[0];
$cg28+=$row[2];
$sg28+=$row[1];
$ig28+=$row[3];

$bta0+=$row[16];
$gtot+=$row[18];
	$hand1+=$row[17];
	$kfc1+=$row[19];
    
}
}
    $totb4=$bta5+$bta12+$bta18+$bta28+$bta0;
    $totgst=$cg5+$sg5+$ig5+$cg12+$sg12+$ig12+$cg18+$sg18+$ig18+$cg28+$sg28+$ig28;
    $totgtot=$gtot;
    $tothand=$hand1;
    
print "<tr><td colspan=7 align =right>Total</td><td align =right>".putcoma($bta28)."</td><td align =right>".putcoma($ig28)."</td><td align =right>".putcoma($sg28)."</td><td align =right>".putcoma($cg28)."</td>  <td align =right>".putcoma($bta18)."</td><td align =right>".putcoma($ig18)."</td><td align =right>".putcoma($sg18)."</td><td align =right>".putcoma($cg18)."</td>   <td align =right>".putcoma($bta12)."</td><td align =right>".putcoma($ig12)."</td><td align =right>".putcoma($sg12)."</td><td align =right>".putcoma($cg12)."</td>  <td align =right>".putcoma($bta5)."</td><td align =right>".putcoma($ig5)."</td><td align =right>".putcoma($sg5)."</td><td align =right>".putcoma($cg5)."</td> <td align =right>".putcoma($bta0)."</td><td align =right>".putcoma($hand1)."</td><td align =right>".putcoma($kfc1)."</td><td align =right>".putcoma($gtot)."</td></td></tr><br>";

$b4cs=mysqli_query($db,"select sum(cramt) from journal2 where brcode='$brcode' and partic='Outward Supply - Sales' and j_type='Spare Invoice' and date>='$dfrom' and date<='$dto' ");
$b4cs1=mysqli_fetch_array($b4cs);

print "<tr><td colspan=7 align =right>Before Tax Total (Reg)</td><td align =right>".putcoma($totb4)."</td><td colspan=3 align =right>Before Tax Total (Ledger)</td><td align =right>".putcoma($b4cs1[0])."</td></tr>";

$taxcs=mysqli_query($db,"select sum(cramt) from journal2 where brcode='$brcode' and partic='Output Tax' and j_type='Spare Invoice' and date>='$dfrom' and date<='$dto' ");
$taxcs1=mysqli_fetch_array($taxcs);

print "<tr><td colspan=7 align =right> Tax Total (Reg)</td><td align =right>".putcoma($totgst)."</td><td colspan=3 align =right> Tax Total (Ledger)</td><td align =right>".putcoma($taxcs1[0])."</td></tr>";

$handcs=mysqli_query($db,"select sum(cramt) from journal2 where brcode='$brcode' and partic='Handling Charges' and j_type='Spare Invoice' and date>='$dfrom' and date<='$dto' ");
$handcs1=mysqli_fetch_array($handcs);

print "<tr><td colspan=7 align =right>Handling Total (Reg)</td><td align =right>".putcoma($tothand)."</td><td colspan=3 align =right> Handling Total (Ledger)</td><td align =right>".putcoma($handcs1[0])."</td></tr>";


$ttcs=mysqli_query($db,"select sum(dramt) from journal2 where brcode='$brcode' and j_type='Spare Invoice' and date>='$dfrom' and date<='$dto' ");
$ttcs1=mysqli_fetch_array($ttcs);

print "<tr><td colspan=7 align =right>Grand Total (Reg)</td><td align =right>".putcoma($totgtot)."</td><td colspan=3 align =right> Invoice Total (Ledger)</td><td align =right>".putcoma($ttcs1[0])."</td></tr>";


print "</table>";

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

//  counter sale  print  end

//*********** jobcard  print start


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


print "<table border=1 cellspacing=1 cellpadding=4 bgcolor='lightsteelblue'>";
print "<tr><th colspan=27><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=3><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>Cess<th>Total<th>INV Total ";

    $reinvno=mysqli_query($db,"select distinct invno,invdate,cust,salestype from $tbl  where brcode='$brcode' and invtype='JC' order by invno,invdate ")or die('err'.mysqli_error($db));
   
    $bta5=0;
$cg5=0;
$sg5=0;
$ig5=0;
$bta12=0;
$cg12=0;
$sg12=0;
$ig12=0;
$bta18=0;
$cg18=0;
$sg18=0;
$ig18=0;
$bta28=0;
$cg28=0;
$sg28=0;
$ig28=0;
$bta0=0;
$gtot=0;
    $hand1=0;  
    $kfc1=0;
    
    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,sum(kfc) kfc from $tbl  where brcode='$brcode'   and invno='$rowinvno[0]' and salestype='$rowinvno[3]' and invtype='JC' group by invno")or die('err1q'.mysqli_error($db));
   

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];
	
	
	$invtt=mysqli_query($db,"select sum(total) tot from $tbl  where brcode='$brcode'   and invno='$rowinvno[0]' ")or die  (mysqli_error($db));
	$invtt1=mysqli_fetch_row($invtt);
	$jctot=$invtt1[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>$rowinvno[3]</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><td align=right>".putComa($row[19])."</td>";
   
   print "<td align=right>".putcoma($row[18])."</td><td align=right>".putcoma($jctot)."</td></tr>";
 $bta5+=$row[12];
$cg5+=$row[14];
$sg5+=$row[13];
$ig5+=$row[15];

$bta12+=$row[8];
$cg12+=$row[10];
$sg12+=$row[9];
$ig12+=$row[11];

$bta18+=$row[4];
$cg18+=$row[6];
$sg18+=$row[5];
$ig18+=$row[7];

$bta28+=$row[0];
$cg28+=$row[2];
$sg28+=$row[1];
$ig28+=$row[3];

$bta0+=$row[16];
$gtot+=$row[18];
	$hand1+=$row[17]; 
	$kfc1+=$row[19]; 
    
}


}
print "<tr><td colspan=7 align =right>Total</td><td align =right>".putcoma($bta28)."</td><td align =right>".putcoma($ig28)."</td><td align =right>".putcoma($sg28)."</td><td align =right>".putcoma($cg28)."</td>  <td align =right>".putcoma($bta18)."</td><td align =right>".putcoma($ig18)."</td><td align =right>".putcoma($sg18)."</td><td align =right>".putcoma($cg18)."</td>   <td align =right>".putcoma($bta12)."</td><td align =right>".putcoma($ig12)."</td><td align =right>".putcoma($sg12)."</td><td align =right>".putcoma($cg12)."</td>  <td align =right>".putcoma($bta5)."</td><td align =right>".putcoma($ig5)."</td><td align =right>".putcoma($sg5)."</td><td align =right>".putcoma($cg5)."</td> <td align =right>".putcoma($bta0)."</td><td align =right>".putcoma($hand1)."</td><td align =right>".putcoma($kfc1)."</td><td align =right>".putcoma($gtot)."</td></td></tr>";
print"</table>";
//   jobcard   print  end



//*********** Waranty  print start


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


print "<table border=1 cellspacing=1 cellpadding=4 bgcolor='lightsteelblue'>";
print "<tr><th colspan=26><h3>WARANTY INVOICE</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,salestype from $tbl  where brcode='$brcode' and invtype='WTY' order by invno,invdate")or die('err'.mysqli_error($db));
   $bta5=0;
$cg5=0;
$sg5=0;
$ig5=0;
$bta12=0;
$cg12=0;
$sg12=0;
$ig12=0;
$bta18=0;
$cg18=0;
$sg18=0;
$ig18=0;
$bta28=0;
$cg28=0;
$sg28=0;
$ig28=0;
$bta0=0;
$gtot=0;
    $hand1=0;    
    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 invtype='WTY' and salestype='$rowinvno[3]' group by invno")or die('err1q'.mysqli_error($db));
   


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>$rowinvno[3]</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></tr>";
  
   $bta5+=$row[12];
$cg5+=$row[14];
$sg5+=$row[13];
$ig5+=$row[15];

$bta12+=$row[8];
$cg12+=$row[10];
$sg12+=$row[9];
$ig12+=$row[11];

$bta18+=$row[4];
$cg18+=$row[6];
$sg18+=$row[5];
$ig18+=$row[7];

$bta28+=$row[0];
$cg28+=$row[2];
$sg28+=$row[1];
$ig28+=$row[3];

$bta0+=$row[16];
$gtot+=$row[18];
	$hand1+=$row[17]; 
}


}
print "<tr><td colspan=7 align =right>Total</td><td align =right>".putcoma($bta28)."</td><td align =right>".putcoma($ig28)."</td><td align =right>".putcoma($sg28)."</td><td align =right>".putcoma($cg28)."</td>  <td align =right>".putcoma($bta18)."</td><td align =right>".putcoma($ig18)."</td><td align =right>".putcoma($sg18)."</td><td align =right>".putcoma($cg18)."</td>   <td align =right>".putcoma($bta12)."</td><td align =right>".putcoma($ig12)."</td><td align =right>".putcoma($sg12)."</td><td align =right>".putcoma($cg12)."</td>  <td align =right>".putcoma($bta5)."</td><td align =right>".putcoma($ig5)."</td><td align =right>".putcoma($sg5)."</td><td align =right>".putcoma($cg5)."</td> <td align =right>".putcoma($bta0)."</td><td align =right>".putcoma($hand1)."</td><td align =right>".putcoma($gtot)."</td></td></tr>";
print "</table>";
//   Waranty   print  end



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

//  Transfer Out  print


print "<table border=1 cellspacing=1 cellpadding=4 bgcolor='lightsteelblue'>";
print "<tr><th colspan=26><h3>INTERSTATE STOCK TRANSFER OUT</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='TROUT' order by invno,invdate ")or die('err'.mysqli_error($db));
   
    $bta5=0;
$cg5=0;
$sg5=0;
$ig5=0;
$bta12=0;
$cg12=0;
$sg12=0;
$ig12=0;
$bta18=0;
$cg18=0;
$sg18=0;
$ig18=0;
$bta28=0;
$cg28=0;
$sg28=0;
$ig28=0;
$bta0=0;
$gtot=0;
    $hand1=0;   
    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('err2w'.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));    


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></tr>";
  $bta5+=$row[12];
$cg5+=$row[14];
$sg5+=$row[13];
$ig5+=$row[15];

$bta12+=$row[8];
$cg12+=$row[10];
$sg12+=$row[9];
$ig12+=$row[11];

$bta18+=$row[4];
$cg18+=$row[6];
$sg18+=$row[5];
$ig18+=$row[7];

$bta28+=$row[0];
$cg28+=$row[2];
$sg28+=$row[1];
$ig28+=$row[3];

$bta0+=$row[16];
$gtot+=$row[18];
	$hand1+=$row[17];
    
}
}
print "<tr><td colspan=7 align =right>Total</td><td align =right>".putcoma($bta28)."</td><td align =right>".putcoma($ig28)."</td><td align =right>".putcoma($sg28)."</td><td align =right>".putcoma($cg28)."</td>  <td align =right>".putcoma($bta18)."</td><td align =right>".putcoma($ig18)."</td><td align =right>".putcoma($sg18)."</td><td align =right>".putcoma($cg18)."</td>   <td align =right>".putcoma($bta12)."</td><td align =right>".putcoma($ig12)."</td><td align =right>".putcoma($sg12)."</td><td align =right>".putcoma($cg12)."</td>  <td align =right>".putcoma($bta5)."</td><td align =right>".putcoma($ig5)."</td><td align =right>".putcoma($sg5)."</td><td align =right>".putcoma($cg5)."</td> <td align =right>".putcoma($bta0)."</td><td align =right>".putcoma($hand1)."</td><td align =right>".putcoma($gtot)."</td></td></tr>";
print"</table>";


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

//  Counter Sale Other Spares  print


print "<table border=1 cellspacing=1 cellpadding=4 bgcolor='lightsteelblue'>";
print "<tr><th colspan=26><h3>COUNTER SALE OTHERS (SPARE)</th></tr>";
print "<tr><th colspan=8><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>HSN Code<th>Qty<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>Cess<th>Total ";

    $reinvno=mysqli_query($db,"select distinct invno,invdate,cust from $tbl  where brcode='$brcode' and invtype='CSOSP' order by invno,invdate ")or die('err'.mysqli_error($db));
    $bta5=0;
$cg5=0;
$sg5=0;
$ig5=0;
$bta12=0;
$cg12=0;
$sg12=0;
$ig12=0;
$bta18=0;
$cg18=0;
$sg18=0;
$ig18=0;
$bta28=0;
$cg28=0;
$sg28=0;
$ig28=0;
$bta0=0;
$gtot=0;
    $hand1=0; 
    $kfc1=0;
    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,sum(kfc) kfc from $tbl  where brcode='$brcode'   and invno='$rowinvno[0]' group by invno")or die('err2w'.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));    


while($row=mysqli_fetch_array($re))
{
    $cus_result=mysqli_query($db,"select cst from customer where acname = '$rowinvno[cust]'")or die  (mysqli_error($db));
    //print "select tin from customer where acname = '$rowinvno[cust]'";
	$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>";

    $hsnpart_result=mysqli_query($db,"select partcode from spareinvoice_oth where invno = '$rowinvno[0]' and brcode = '$brcode' limit 1")or die  (mysqli_error($db));
	$hsnpart_row=mysqli_fetch_row($hsnpart_result);
	$partcode=$hsnpart_row[0];
    
    $qty_result=mysqli_query($db,"select sum(qty) from spareinvoice_oth where invno = '$rowinvno[0]' and brcode = '$brcode'")or die  (mysqli_error($db));
	$qty_row=mysqli_fetch_row($qty_result);
	$mqty=round($qty_row[0],2);
    
    $hsncode_result=mysqli_query($db,"select hsncode from partmaster where partcode = '$partcode' limit 1")or die  (mysqli_error($db));
	$hsncode_row=mysqli_fetch_row($hsncode_result);
	$mhsncode=$hsncode_row[0];
    
    print "<td>".strtoupper($rowinvno['cust'])."</td><td>$mhsncode</td><td>$mqty</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><td align=right>".putComa($row[19])."</td>";
   
   print "<td align=right>".putcoma($row[18])."</td></tr>";
  
   $bta5+=$row[12];
$cg5+=$row[14];
$sg5+=$row[13];
$ig5+=$row[15];

$bta12+=$row[8];
$cg12+=$row[10];
$sg12+=$row[9];
$ig12+=$row[11];

$bta18+=$row[4];
$cg18+=$row[6];
$sg18+=$row[5];
$ig18+=$row[7];

$bta28+=$row[0];
$cg28+=$row[2];
$sg28+=$row[1];
$ig28+=$row[3];

$bta0+=$row[16];
$gtot+=$row[18];
	$hand1+=$row[17];
		$kfc1+=$row[19]; 
}
}
print "<tr><td colspan=8 align =right>Total</td><td align =right>".putcoma($bta28)."</td><td align =right>".putcoma($ig28)."</td><td align =right>".putcoma($sg28)."</td><td align =right>".putcoma($cg28)."</td>  <td align =right>".putcoma($bta18)."</td><td align =right>".putcoma($ig18)."</td><td align =right>".putcoma($sg18)."</td><td align =right>".putcoma($cg18)."</td>   <td align =right>".putcoma($bta12)."</td><td align =right>".putcoma($ig12)."</td><td align =right>".putcoma($sg12)."</td><td align =right>".putcoma($cg12)."</td>  <td align =right>".putcoma($bta5)."</td><td align =right>".putcoma($ig5)."</td><td align =right>".putcoma($sg5)."</td><td align =right>".putcoma($cg5)."</td> <td align =right>".putcoma($bta0)."</td><td align =right>".putcoma($hand1)."</td><td align =right>".putcoma($kfc1)."</td><td align =right>".putcoma($gtot)."</td></td></tr>";
print "</table>";
//#########################################################################

//  CS OTHERS SPARE  print  end



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

//  Counter Sale SERVICE  print


print "<table border=1 cellspacing=1 cellpadding=4 bgcolor='lightsteelblue'>";
print "<tr><th colspan=26><h3>SERVICE INVOICE (OTHERS)</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>Cess<th>Total ";

    $reinvno=mysqli_query($db,"select distinct invno,invdate,cust from $tbl  where brcode='$brcode' and invtype='CSOLAB' order by invno,invdate ")or die('err'.mysqli_error($db));
     $bta5=0;
$cg5=0;
$sg5=0;
$ig5=0;
$bta12=0;
$cg12=0;
$sg12=0;
$ig12=0;
$bta18=0;
$cg18=0;
$sg18=0;
$ig18=0;
$bta28=0;
$cg28=0;
$sg28=0;
$ig28=0;
$bta0=0;
$gtot=0;
    $hand1=0;  
     $kfc1=0;
    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,sum(kfc) kfc from $tbl  where brcode='$brcode'   and invno='$rowinvno[0]' group by invno")or die('err2w'.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));    


while($row=mysqli_fetch_array($re))
{
    $cus_result=mysqli_query($db,"select cst from customer where acname = '$rowinvno[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><td align=right>".putComa($row[19])."</td>";
   
   print "<td align=right>".putcoma($row[18])."</td></tr>";

$bta5+=$row[12];
$cg5+=$row[14];
$sg5+=$row[13];
$ig5+=$row[15];

$bta12+=$row[8];
$cg12+=$row[10];
$sg12+=$row[9];
$ig12+=$row[11];

$bta18+=$row[4];
$cg18+=$row[6];
$sg18+=$row[5];
$ig18+=$row[7];

$bta28+=$row[0];
$cg28+=$row[2];
$sg28+=$row[1];
$ig28+=$row[3];

$bta0+=$row[16];
$gtot+=$row[18];
	$hand1+=$row[17];  
	$kfc1+=$row[19];  
    
}
}
print "<tr><td colspan=7 align =right>Total</td><td align =right>".putcoma($bta28)."</td><td align =right>".putcoma($ig28)."</td><td align =right>".putcoma($sg28)."</td><td align =right>".putcoma($cg28)."</td>  <td align =right>".putcoma($bta18)."</td><td align =right>".putcoma($ig18)."</td><td align =right>".putcoma($sg18)."</td><td align =right>".putcoma($cg18)."</td>   <td align =right>".putcoma($bta12)."</td><td align =right>".putcoma($ig12)."</td><td align =right>".putcoma($sg12)."</td><td align =right>".putcoma($cg12)."</td>  <td align =right>".putcoma($bta5)."</td><td align =right>".putcoma($ig5)."</td><td align =right>".putcoma($sg5)."</td><td align =right>".putcoma($cg5)."</td> <td align =right>".putcoma($bta0)."</td><td align =right>".putcoma($hand1)."</td><td align =right>".putcoma($kfc1)."</td><td align =right>".putcoma($gtot)."</td></td></tr>";
print"</table>";
//#########################################################################

//  CS OTHERS SERVICE  print  end


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

//  purret eich  print  start


print "<table border=1 cellspacing=1 cellpadding=4 bgcolor='lightsteelblue'>";
print "<tr><th colspan=26><h3>PURCHASE RETURN EICHER</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='PRETE' order by invno,invdate ")or die('err'.mysqli_error($db));
     $bta5=0;
$cg5=0;
$sg5=0;
$ig5=0;
$bta12=0;
$cg12=0;
$sg12=0;
$ig12=0;
$bta18=0;
$cg18=0;
$sg18=0;
$ig18=0;
$bta28=0;
$cg28=0;
$sg28=0;
$ig28=0;
$bta0=0;
$gtot=0;
    $hand1=0;  
    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('err2w'.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));    


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></tr>";
 $bta5+=$row[12];
$cg5+=$row[14];
$sg5+=$row[13];
$ig5+=$row[15];

$bta12+=$row[8];
$cg12+=$row[10];
$sg12+=$row[9];
$ig12+=$row[11];

$bta18+=$row[4];
$cg18+=$row[6];
$sg18+=$row[5];
$ig18+=$row[7];

$bta28+=$row[0];
$cg28+=$row[2];
$sg28+=$row[1];
$ig28+=$row[3];

$bta0+=$row[16];
$gtot+=$row[18];
	$hand1+=$row[17]; 
    
}
}
print "<tr><td colspan=7 align =right>Total</td><td align =right>".putcoma($bta28)."</td><td align =right>".putcoma($ig28)."</td><td align =right>".putcoma($sg28)."</td><td align =right>".putcoma($cg28)."</td>  <td align =right>".putcoma($bta18)."</td><td align =right>".putcoma($ig18)."</td><td align =right>".putcoma($sg18)."</td><td align =right>".putcoma($cg18)."</td>   <td align =right>".putcoma($bta12)."</td><td align =right>".putcoma($ig12)."</td><td align =right>".putcoma($sg12)."</td><td align =right>".putcoma($cg12)."</td>  <td align =right>".putcoma($bta5)."</td><td align =right>".putcoma($ig5)."</td><td align =right>".putcoma($sg5)."</td><td align =right>".putcoma($cg5)."</td> <td align =right>".putcoma($bta0)."</td><td align =right>".putcoma($hand1)."</td><td align =right>".putcoma($gtot)."</td></td></tr>";
print "</table>";

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

//  purret eich  print  end


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

//  exp rev  print  start


print "<table border=1 cellspacing=1 cellpadding=4 bgcolor='lightsteelblue'>";
print "<tr><th colspan=26><h3>GST EXPENSE REVERSE</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='EXPREV' order by invno,invdate ")or die('err'.mysqli_error($db));
     $bta5=0;
$cg5=0;
$sg5=0;
$ig5=0;
$bta12=0;
$cg12=0;
$sg12=0;
$ig12=0;
$bta18=0;
$cg18=0;
$sg18=0;
$ig18=0;
$bta28=0;
$cg28=0;
$sg28=0;
$ig28=0;
$bta0=0;
$gtot=0;
    $hand1=0;  
    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('err2w'.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));    


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></tr>";
  
$bta5+=$row[12];
$cg5+=$row[14];
$sg5+=$row[13];
$ig5+=$row[15];

$bta12+=$row[8];
$cg12+=$row[10];
$sg12+=$row[9];
$ig12+=$row[11];

$bta18+=$row[4];
$cg18+=$row[6];
$sg18+=$row[5];
$ig18+=$row[7];

$bta28+=$row[0];
$cg28+=$row[2];
$sg28+=$row[1];
$ig28+=$row[3];

$bta0+=$row[16];
$gtot+=$row[18];
	$hand1+=$row[17];    
}
}
print "<tr><td colspan=7 align =right>Total</td><td align =right>".putcoma($bta28)."</td><td align =right>".putcoma($ig28)."</td><td align =right>".putcoma($sg28)."</td><td align =right>".putcoma($cg28)."</td>  <td align =right>".putcoma($bta18)."</td><td align =right>".putcoma($ig18)."</td><td align =right>".putcoma($sg18)."</td><td align =right>".putcoma($cg18)."</td>   <td align =right>".putcoma($bta12)."</td><td align =right>".putcoma($ig12)."</td><td align =right>".putcoma($sg12)."</td><td align =right>".putcoma($cg12)."</td>  <td align =right>".putcoma($bta5)."</td><td align =right>".putcoma($ig5)."</td><td align =right>".putcoma($sg5)."</td><td align =right>".putcoma($cg5)."</td> <td align =right>".putcoma($bta0)."</td><td align =right>".putcoma($hand1)."</td><td align =right>".putcoma($gtot)."</td></td></tr>";
print "</table>";

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

//  exp rev  print  end



//  GST Income  print  start


print "<table border=1 cellspacing=1 cellpadding=4 bgcolor='lightsteelblue'>";
print "<tr><th colspan=26><h3>GST INCOME</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='INC' order by invno,invdate ")or die('err'.mysqli_error($db));
    $bta5=0;
$cg5=0;
$sg5=0;
$ig5=0;
$bta12=0;
$cg12=0;
$sg12=0;
$ig12=0;
$bta18=0;
$cg18=0;
$sg18=0;
$ig18=0;
$bta28=0;
$cg28=0;
$sg28=0;
$ig28=0;
$bta0=0;
$gtot=0;
    $hand1=0;   
    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('err2w'.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));    


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></tr>";
  
$bta5+=$row[12];
$cg5+=$row[14];
$sg5+=$row[13];
$ig5+=$row[15];

$bta12+=$row[8];
$cg12+=$row[10];
$sg12+=$row[9];
$ig12+=$row[11];

$bta18+=$row[4];
$cg18+=$row[6];
$sg18+=$row[5];
$ig18+=$row[7];

$bta28+=$row[0];
$cg28+=$row[2];
$sg28+=$row[1];
$ig28+=$row[3];

$bta0+=$row[16];
$gtot+=$row[18];
	$hand1+=$row[17];    
}
}
print "<tr><td colspan=7 align =right>Total</td><td align =right>".putcoma($bta28)."</td><td align =right>".putcoma($ig28)."</td><td align =right>".putcoma($sg28)."</td><td align =right>".putcoma($cg28)."</td>  <td align =right>".putcoma($bta18)."</td><td align =right>".putcoma($ig18)."</td><td align =right>".putcoma($sg18)."</td><td align =right>".putcoma($cg18)."</td>   <td align =right>".putcoma($bta12)."</td><td align =right>".putcoma($ig12)."</td><td align =right>".putcoma($sg12)."</td><td align =right>".putcoma($cg12)."</td>  <td align =right>".putcoma($bta5)."</td><td align =right>".putcoma($ig5)."</td><td align =right>".putcoma($sg5)."</td><td align =right>".putcoma($cg5)."</td> <td align =right>".putcoma($bta0)."</td><td align =right>".putcoma($hand1)."</td><td align =right>".putcoma($gtot)."</td></td></tr>";
print "</table>";

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

//  GST Income print  end

//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$




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> Outward Supply Register</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>


