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

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

<?
        
    
  
 $tbl="sparepurdw".$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),pbillno varchar(200) default 0,purdate date )");
mysqli_query($db,"delete from $tbl");

//      spare purchase start #################################################

$sq2="select  grno,entrydate,suplier,sum(aprice) ap,sum(sgstamt) sg,sum(cgstamt) cg,sum(hand) hnd,sum(tot) tt ,pbillno,purdate from sparepurchase  where brcode='$brcode' and entrydate>='$dfrom' and entrydate<='$dto'  and sgstp='14.00'  and jvno>'0' group by grno";
$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,pbillno,purdate) values('$res2[grno]','$res2[entrydate]','$res2[suplier]','$brcode','SP','$res2[ap]','$res2[sg]','$res2[cg]','$res2[hnd]','$res2[tt]','spare','$res2[pbillno]','$res2[purdate]')";
   //print $sq14;
   mysqli_query($db,$sq14) or die('saleinv28cg13 err'.mysqli_error($db));
}


$sq2="select  grno,entrydate,suplier,sum(aprice) ap,sum(sgstamt) sg,sum(cgstamt) cg,sum(hand) hnd,sum(tot) tt ,pbillno,purdate from sparepurchase  where brcode='$brcode' and entrydate>='$dfrom' and entrydate<='$dto'  and sgstp='9.00'  and jvno>'0' group by grno";
$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,pbillno,purdate) values('$res2[grno]','$res2[entrydate]','$res2[suplier]','$brcode','SP','$res2[ap]','$res2[sg]','$res2[cg]','$res2[hnd]','$res2[tt]','spare','$res2[pbillno]','$res2[purdate]')";
   //print $sq14;
   mysqli_query($db,$sq14) or die('saleinv18cg err'.mysqli_error($db));
}


$sq2="select  grno,entrydate,suplier,sum(aprice) ap,sum(sgstamt) sg,sum(cgstamt) cg,sum(hand) hnd,sum(tot) tt ,pbillno,purdate from sparepurchase  where brcode='$brcode' and entrydate>='$dfrom' and entrydate<='$dto'  and sgstp='6.00'  and jvno>'0' group by grno";
$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,pbillno,purdate) values('$res2[grno]','$res2[entrydate]','$res2[suplier]','$brcode','SP','$res2[ap]','$res2[sg]','$res2[cg]','$res2[hnd]','$res2[tt]','spare','$res2[pbillno]','$res2[purdate]')";
   //print $sq14;
   mysqli_query($db,$sq14) or die('saleinv18cg err'.mysqli_error($db));
}

$sq2="select  grno,entrydate,suplier,sum(aprice) ap,sum(sgstamt) sg,sum(cgstamt) cg,sum(hand) hnd,sum(tot) tt ,pbillno,purdate from sparepurchase  where brcode='$brcode' and entrydate>='$dfrom' and entrydate<='$dto'  and sgstp='2.50'  and jvno>'0' group by grno";
$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,pbillno,purdate) values('$res2[grno]','$res2[entrydate]','$res2[suplier]','$brcode','SP','$res2[ap]','$res2[sg]','$res2[cg]','$res2[hnd]','$res2[tt]','spare','$res2[pbillno]','$res2[purdate]')";
 // print $sq14;
   mysqli_query($db,$sq14) or die('saleinv18cg err'.mysqli_error($db));
}

$sq2="select  grno,entrydate,suplier,sum(aprice) ap,sum(sgstamt) sg,sum(cgstamt) cg,sum(hand) hnd,sum(tot) tt ,pbillno,purdate from sparepurchase  where brcode='$brcode' and entrydate>='$dfrom' and entrydate<='$dto'  and sgstp='0.00' and cgstp='0.00' and igstp='0.00'  and jvno>'0' group by grno";
$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,pbillno,purdate) values('$res2[grno]','$res2[entrydate]','$res2[suplier]','$brcode','SP','$res2[ap]','$res2[hnd]','$res2[tt]','spare','$res2[pbillno]','$res2[purdate]')";
  // print $sq14;
   mysqli_query($db,$sq14) or die('saleinv18cg err'.mysqli_error($db));
}




$sq2="select  grno,entrydate,suplier,sum(aprice) ap,sum(igstamt) ig,sum(hand) hnd,sum(tot) tt ,pbillno,purdate from sparepurchase  where brcode='$brcode' and entrydate>='$dfrom' and entrydate<='$dto'  and igstp='28.00'  and jvno>'0' group by grno";
$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,pbillno,purdate) values('$res2[grno]','$res2[entrydate]','$res2[suplier]','$brcode','SP','$res2[ap]','$res2[ig]','$res2[hnd]','$res2[tt]','spare','$res2[pbillno]','$res2[purdate]')";
   //print $sq14;
   mysqli_query($db,$sq14) or die('saleinv18cg err'.mysqli_error($db));
}


$sq2="select  grno,entrydate,suplier,sum(aprice) ap,sum(igstamt) ig,sum(hand) hnd,sum(tot) tt ,pbillno,purdate from sparepurchase  where brcode='$brcode' and entrydate>='$dfrom' and entrydate<='$dto'  and igstp='18.00'  and jvno>'0' group by grno";
$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,pbillno,purdate) values('$res2[grno]','$res2[entrydate]','$res2[suplier]','$brcode','SP','$res2[ap]','$res2[ig]','$res2[hnd]','$res2[tt]','spare','$res2[pbillno]','$res2[purdate]')";
   mysqli_query($db,$sq14) or die('saleinv18cg err'.mysqli_error($db));
}


$sq2="select  grno,entrydate,suplier,sum(aprice) ap,sum(igstamt) ig,sum(hand) hnd,sum(tot) tt ,pbillno,purdate from sparepurchase  where brcode='$brcode' and entrydate>='$dfrom' and entrydate<='$dto'  and igstp='12.00'  and jvno>'0' group by grno";
$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,pbillno,purdate) values('$res2[grno]','$res2[entrydate]','$res2[suplier]','$brcode','SP','$res2[ap]','$res2[ig]','$res2[hnd]','$res2[tt]','spare','$res2[pbillno]','$res2[purdate]')";
  // print $sq14;
   mysqli_query($db,$sq14) or die('saleinv18cg err'.mysqli_error($db));
}



$sq2="select  grno,entrydate,suplier,sum(aprice) ap,sum(igstamt) ig,sum(hand) hnd,sum(tot) tt ,pbillno,purdate from sparepurchase  where brcode='$brcode' and entrydate>='$dfrom' and entrydate<='$dto'  and igstp='5.00'  and jvno>'0' group by grno";
$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,pbillno,purdate) values('$res2[grno]','$res2[entrydate]','$res2[suplier]','$brcode','SP','$res2[ap]','$res2[ig]','$res2[hnd]','$res2[tt]','spare','$res2[pbillno]','$res2[purdate]')";
   //print $sq14;
   mysqli_query($db,$sq14) or die('saleinv18cg err'.mysqli_error($db));
}





// ##############  spare purchase end        ###################################



//    item  purchase accessories start #################################################

$sq2="select  pno,curdate,sup,sum(net) ap,sum(taxamt)/2 sg,sum(taxamt)/2 cg,sum(others) hnd,sum(gtot) tt ,purinvoice,pdate from item_purchase_veh   where brcode='$brcode' and curdate>='$dfrom' and curdate<='$dto'  and taxp='28.00'  and jvno>'0' and taxtype='INTRA STATE' group by pno";
$re21=mysqli_query($db,$sq2)or die('Err3ac:'.mysqli_error($db));

while($res2=mysqli_fetch_array($re21))
{
 
 $sq14="insert into $tbl(invno,invdate,cust,brcode,invtype,28b4,14sgst,14cgst,hand,total,salestype,pbillno,purdate) values('$res2[pno]','$res2[curdate]','$res2[sup]','$brcode','SPACS','$res2[ap]','$res2[sg]','$res2[cg]','$res2[hnd]','$res2[tt]','spareitm','$res2[purinvoice]','$res2[pdate]')";
   //print $sq14;
   mysqli_query($db,$sq14) or die('saleinv28cg13 err'.mysqli_error($db));
}


$sq2="select  pno,curdate,sup,sum(net) ap,sum(taxamt)/2 sg,sum(taxamt)/2 cg,sum(others) hnd,sum(gtot) tt ,purinvoice,pdate from item_purchase_veh   where brcode='$brcode' and curdate>='$dfrom' and curdate<='$dto'  and taxp='18.00'  and jvno>'0' and taxtype='INTRA STATE' group by pno";
$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,pbillno,purdate) values('$res2[pno]','$res2[curdate]','$res2[sup]','$brcode','SPACS','$res2[ap]','$res2[sg]','$res2[cg]','$res2[hnd]','$res2[tt]','spareitm','$res2[purinvoice]','$res2[pdate]')";
  //print $sq14;
   mysqli_query($db,$sq14) or die('saleinv18cg err'.mysqli_error($db));
}

$sq2="select  pno,curdate,sup,sum(net) ap,sum(taxamt)/2 sg,sum(taxamt)/2 cg,sum(others) hnd,sum(gtot) tt ,purinvoice,pdate from item_purchase_veh   where brcode='$brcode' and curdate>='$dfrom' and curdate<='$dto'  and taxp='5.00'  and jvno>'0' and taxtype='INTRA STATE' group by pno";
$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,pbillno,purdate) values('$res2[pno]','$res2[curdate]','$res2[sup]','$brcode','SPACS','$res2[ap]','$res2[sg]','$res2[cg]','$res2[hnd]','$res2[tt]','spareitm','$res2[purinvoice]','$res2[pdate]')";
  //print $sq14;
   mysqli_query($db,$sq14) or die('saleinv5cg err'.mysqli_error($db));
}




// ##############  item  purchase accessories end        ###################################



//    item  purchase ret accessories start #################################################

$sq2r="select  retno,entrydate,suplier,sum(aprice) ap,sum(taxamt)/2 sg,sum(taxamt)/2 cg,sum(hand) hnd,sum(tot) tt ,pbillno,entrydate from item_purchase_ret   where brcode='$brcode' and entrydate>='$dfrom' and entrydate<='$dto'  and tax='28.00'  and jvno>'0' and taxtype='INTRA STATE' group by purno";
$re21r=mysqli_query($db,$sq2r)or die('Err3ac:'.mysqli_error($db));

while($res2=mysqli_fetch_array($re21r))
{
 
 $sq14r="insert into $tbl(invno,invdate,cust,brcode,invtype,28b4,14sgst,14cgst,hand,total,salestype,pbillno,purdate) values('$res2[retno]','$res2[entrydate]','$res2[suplier]','$brcode','SPACSR','$res2[ap]','$res2[sg]','$res2[cg]','$res2[hnd]','$res2[tt]','spareitm','$res2[pbillno]','$res2[entrydate]')";
   //print $sq14;
   mysqli_query($db,$sq14r) or die('saleinv28cg13 err'.mysqli_error($db));
}


$sq2r="select  retno,entrydate,suplier,sum(aprice) ap,sum(taxamt)/2 sg,sum(taxamt)/2 cg,sum(hand) hnd,sum(tot) tt ,pbillno,entrydate from item_purchase_ret   where brcode='$brcode' and entrydate>='$dfrom' and entrydate<='$dto'  and tax='18.00'  and jvno>'0' and taxtype='INTRA STATE' group by purno";
$re21r=mysqli_query($db,$sq2r)or die('Err3 r:'.mysqli_error($db));

while($res2=mysqli_fetch_array($re21r))
{
 
 $sq14="insert into $tbl(invno,invdate,cust,brcode,invtype,18b4,9sgst,9cgst,hand,total,salestype,pbillno,purdate) values('$res2[retno]','$res2[entrydate]','$res2[suplier]','$brcode','SPACSR','$res2[ap]','$res2[sg]','$res2[cg]','$res2[hnd]','$res2[tt]','spareitm','$res2[pbillno]','$res2[entrydate]')";
  //print $sq14;
   mysqli_query($db,$sq14) or die('saleinv18cg r err'.mysqli_error($db));
}




// ##############  item  purchase ret accessories end       


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

$sq2="select  invno,invdate,customer,sum(aprice) ap,sum(sgstamt) sg,sum(cgstamt) cg,sum(hand) hnd,sum(tot) tt from salesretnew 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','CSRET','$res2[ap]','$res2[sg]','$res2[cg]','$res2[hnd]','$res2[tt]','spare')";
  // print $sq14;
   mysqli_query($db,$sq14) or die('saleinv28cg14 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 salesretnew 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','CSRET','$res2[ap]','$res2[sg]','$res2[cg]','$res2[hnd]','$res2[tt]','spare')";
   //print $sq14;
   mysqli_query($db,$sq14) or die('saleinv28cg15 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 salesretnew 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','CSRET','$res2[ap]','$res2[sg]','$res2[cg]','$res2[hnd]','$res2[tt]','spare')";
   //print $sq14;
   mysqli_query($db,$sq14) or die('saleinv28cg1 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 salesretnew 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','CSRET','$res2[ap]','$res2[sg]','$res2[cg]','$res2[hnd]','$res2[tt]','spare')";
  // print $sq14;
   mysqli_query($db,$sq14) or die('saleinv28cg16 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 salesretnew 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','CSRET','$res2[ap]','$res2[hnd]','$res2[tt]','spare')";
  //print $sq14;
   mysqli_query($db,$sq14) or die('saleinv28cg2 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 salesretnew 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','CSRET','$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 salesretnew 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','CSRET','$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 salesretnew 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','CSRET','$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 salesretnew 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','CSRET','$res2[ap]','$res2[ig]','$res2[hnd]','$res2[hnd]','spare')";
   mysqli_query($db,$sqig1) or die('saleinv err'.mysqli_error($db));
}




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




//   Transfer In start     ##################################################

// transfer igst  old
/*
$sqig=mysqli_query($db,"select GRNNo,GRNDate,SupplyingPlantName,sum(GRAMOUNT) ap,sum(igstamt) ig,sum(GRAMOUNT+igstamt) tt,DealerInvoiceNumber from transferin  where brcode='$brcode'  and GRNDate>='$dfrom' and GRNDate<='$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,pbillno) values('$res2[GRNNo]','$res2[GRNDate]','$res2[SupplyingPlantName]','$brcode','TRIN','$res2[ap]','$res2[ig]','$res2[tt]','spare','$res2[DealerInvoiceNumber]')";
 //print $sqig1;
   mysqli_query($db,$sqig1) or die('saleinv err'.mysqli_error($db));
}

$sqig=mysqli_query($db,"select GRNNo,GRNDate,SupplyingPlantName,sum(GRAMOUNT) ap,sum(igstamt) ig,sum(GRAMOUNT+igstamt) tt,DealerInvoiceNumber from transferin  where brcode='$brcode'  and GRNDate>='$dfrom' and GRNDate<='$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,pbillno) values('$res2[GRNNo]','$res2[GRNDate]','$res2[SupplyingPlantName]','$brcode','TRIN','$res2[ap]','$res2[ig]','$res2[tt]','spare','$res2[DealerInvoiceNumber]')";
 //print $sqig1;
   mysqli_query($db,$sqig1) or die('saleinv err'.mysqli_error($db));
}

$sqig=mysqli_query($db,"select GRNNo,GRNDate,SupplyingPlantName,sum(GRAMOUNT) ap,sum(igstamt) ig,sum(GRAMOUNT+igstamt) tt,DealerInvoiceNumber from transferin  where brcode='$brcode'  and GRNDate>='$dfrom' and GRNDate<='$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,pbillno) values('$res2[GRNNo]','$res2[GRNDate]','$res2[SupplyingPlantName]','$brcode','TRIN','$res2[ap]','$res2[ig]','$res2[tt]','spare','$res2[DealerInvoiceNumber]')";
 //print $sqig1;
   mysqli_query($db,$sqig1) or die('saleinv err'.mysqli_error($db));
}


$sqig=mysqli_query($db,"select GRNNo,GRNDate,SupplyingPlantName,sum(GRAMOUNT) ap,sum(igstamt) ig,sum(GRAMOUNT+igstamt) tt,DealerInvoiceNumber from transferin  where brcode='$brcode'  and GRNDate>='$dfrom' and GRNDate<='$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,pbillno) values('$res2[GRNNo]','$res2[GRNDate]','$res2[SupplyingPlantName]','$brcode','TRIN','$res2[ap]','$res2[ig]','$res2[tt]','spare','$res2[DealerInvoiceNumber]')";
 //print $sqig1;
   mysqli_query($db,$sqig1) or die('saleinv err'.mysqli_error($db));
}
*/
//  transfer In old end #######################################



//   Transfer In igst start     ##################################################

//new

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

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



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


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

//  transfer In end #######################################



// GST expense  start  ##################################################


$sq2="select  refno,date,vendor,sum(before_tax) ap,sum(sgstamt) sg,sum(cgstamt) cg,sum(tdsamt) hnd,sum(expense_amount) tt,vendrinvno from gst_expense 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))
{
    
    if ($res2['hnd']=='')
    {
        $res2['hnd']=0;
    }
 
 $sq14="insert into $tbl(invno,invdate,cust,brcode,invtype,28b4,14sgst,14cgst,hand,total,salestype,pbillno) values('$res2[refno]','$res2[date]','$res2[vendor]','$brcode','EXP','$res2[ap]','$res2[sg]','$res2[cg]','$res2[hnd]','$res2[tt]','spare','$res2[vendrinvno]')";
   mysqli_query($db,$sq14) or die('saleinv28cg3 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,vendrinvno from gst_expense 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))
{
    if ($res2['hnd']=='')
    {
        $res2['hnd']=0;
    }
 
 $sq14="insert into $tbl(invno,invdate,cust,brcode,invtype,18b4,9sgst,9cgst,hand,total,salestype,pbillno) values('$res2[refno]','$res2[date]','$res2[vendor]','$brcode','EXP','$res2[ap]','$res2[sg]','$res2[cg]','$res2[hnd]','$res2[tt]','spare','$res2[vendrinvno]')";
   mysqli_query($db,$sq14) or die('saleinv28cg4 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,vendrinvno from gst_expense 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))
{
 
 if ($res2['hnd']=='')
    {
        $res2['hnd']=0;
    }
 $sq14="insert into $tbl(invno,invdate,cust,brcode,invtype,12b4,6sgst,6cgst,hand,total,salestype,pbillno) values('$res2[refno]','$res2[date]','$res2[vendor]','$brcode','EXP','$res2[ap]','$res2[sg]','$res2[cg]','$res2[hnd]','$res2[tt]','spare','$res2[vendrinvno]')";
   mysqli_query($db,$sq14) or die('saleinv28cg5 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,vendrinvno from gst_expense 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))
{
 if ($res2['hnd']=='')
    {
        $res2['hnd']=0;
    }
 $sq14="insert into $tbl(invno,invdate,cust,brcode,invtype,5b4,2_5sgst,2_5cgst,hand,total,salestype,pbillno) values('$res2[refno]','$res2[date]','$res2[vendor]','$brcode','EXP','$res2[ap]','$res2[sg]','$res2[cg]','$res2[hnd]','$res2[tt]','spare','$res2[vendrinvno]')";
   mysqli_query($db,$sq14) or die('saleinv28cg6 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,vendrinvno from gst_expense 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))
{
  if ($res2['hnd']=='')
    {
        $res2['hnd']=0;
    }
 $sq14="insert into $tbl(invno,invdate,cust,brcode,invtype,0gst,hand,total,salestype,pbillno) values('$res2[refno]','$res2[date]','$res2[vendor]','$brcode','EXP','$res2[ap]','$res2[hnd]','$res2[tt]','spare','$res2[vendrinvno]')";
   mysqli_query($db,$sq14) or die('saleinv28cg7 err'.mysqli_error($db));
}


$sq2="select  refno,date,vendor,sum(before_tax) ap,sum(igstamt) ig,sum(tdsamt) hnd,sum(expense_amount) tt,vendrinvno from gst_expense 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))
{
 
  if ($res2['hnd']=='')
    {
        $res2['hnd']=0;
    }
 $sq14="insert into $tbl(invno,invdate,cust,brcode,invtype,28b4,28igst,hand,total,salestype,pbillno) values('$res2[refno]','$res2[date]','$res2[vendor]','$brcode','EXP','$res2[ap]','$res2[ig]','$res2[hnd]','$res2[tt]','spare','$res2[vendrinvno]')";
   mysqli_query($db,$sq14) or die('saleinv28cg8 err'.mysqli_error($db));
}

$sq2="select  refno,date,vendor,sum(before_tax) ap,sum(igstamt) ig,sum(tdsamt) hnd,sum(expense_amount) tt,vendrinvno from gst_expense 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))
{
  if ($res2['hnd']=='')
    {
        $res2['hnd']=0;
    }
 $sq14="insert into $tbl(invno,invdate,cust,brcode,invtype,18b4,18igst,hand,total,salestype,pbillno) values('$res2[refno]','$res2[date]','$res2[vendor]','$brcode','EXP','$res2[ap]','$res2[ig]','$res2[hnd]','$res2[tt]','spare','$res2[vendrinvno]')";
   mysqli_query($db,$sq14) or die('saleinv28cg9 err'.mysqli_error($db));
}


$sq2="select  refno,date,vendor,sum(before_tax) ap,sum(igstamt) ig,sum(tdsamt) hnd,sum(expense_amount) tt,vendrinvno from gst_expense 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))
{
 
 if ($res2['hnd']=='')
    {
        $res2['hnd']=0;
    }
 $sq14="insert into $tbl(invno,invdate,cust,brcode,invtype,12b4,12igst,hand,total,salestype,pbillno) values('$res2[refno]','$res2[date]','$res2[vendor]','$brcode','EXP','$res2[ap]','$res2[ig]','$res2[hnd]','$res2[tt]','spare','$res2[vendrinvno]')";
   mysqli_query($db,$sq14) or die('saleinv28cg11 err'.mysqli_error($db));
}


$sq2="select  refno,date,vendor,sum(before_tax) ap,sum(igstamt) ig,sum(tdsamt) hnd,sum(expense_amount) tt,vendrinvno from gst_expense 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))
{
 
 if ($res2['hnd']=='')
    {
        $res2['hnd']=0;
    }
 $sq14="insert into $tbl(invno,invdate,cust,brcode,invtype,5b4,5igst,hand,total,salestype,pbillno) values('$res2[refno]','$res2[date]','$res2[vendor]','$brcode','EXP','$res2[ap]','$res2[ig]','$res2[hnd]','$res2[tt]','spare','$res2[vendrinvno]')";
   mysqli_query($db,$sq14) or die('saleinv28cg12 err'.mysqli_error($db));
}

// GST expense    end  ################################################


//   Eicher Purchase start  #################################################

// parts

$sqig=mysqli_query($db,"select GRNNo,GRNDate,vendorCode,sum(BTAmt) ap,sum(TaxAmt) ig,sum(hand) hnd,sum(InvAmt) tt,InvoiceNo from eicherpurchase  where brcode='$brcode'  and GRNDate>='$dfrom' and GRNDate<='$dto' and taxp='28.00'  group by GRNNo");
 while($res2=mysqli_fetch_array($sqig))
{
 $sqig1="insert into $tbl(invno,invdate,cust,brcode,invtype,28b4,28igst,hand,total,salestype,pbillno) values('$res2[GRNNo]','$res2[GRNDate]','$res2[vendorCode]','$brcode','EICHP','$res2[ap]','$res2[ig]','$res2[hnd]','$res2[tt]','spare','$res2[InvoiceNo]')";
 //print $sqig1;
   mysqli_query($db,$sqig1) or die('saleinv err'.mysqli_error($db));
}

$sqig=mysqli_query($db,"select GRNNo,GRNDate,vendorCode,sum(BTAmt) ap,sum(TaxAmt) ig,sum(hand) hnd,sum(InvAmt) tt,InvoiceNo from eicherpurchase  where brcode='$brcode'  and GRNDate>='$dfrom' and GRNDate<='$dto' and taxp='18.00'  group by GRNNo");
 while($res2=mysqli_fetch_array($sqig))
{
 $sqig1="insert into $tbl(invno,invdate,cust,brcode,invtype,18b4,18igst,hand,total,salestype,pbillno) values('$res2[GRNNo]','$res2[GRNDate]','$res2[vendorCode]','$brcode','EICHP','$res2[ap]','$res2[ig]','$res2[hnd]','$res2[tt]','spare','$res2[InvoiceNo]')";
 //print $sqig1;
   mysqli_query($db,$sqig1) or die('saleinv err'.mysqli_error($db));
}

$sqig=mysqli_query($db,"select GRNNo,GRNDate,vendorCode,sum(BTAmt) ap,sum(TaxAmt) ig,sum(hand) hnd,sum(InvAmt) tt,InvoiceNo from eicherpurchase  where brcode='$brcode'  and GRNDate>='$dfrom' and GRNDate<='$dto' and taxp='12.00'  group by GRNNo");
 while($res2=mysqli_fetch_array($sqig))
{
 $sqig1="insert into $tbl(invno,invdate,cust,brcode,invtype,12b4,12igst,hand,total,salestype,pbillno) values('$res2[GRNNo]','$res2[GRNDate]','$res2[vendorCode]','$brcode','EICHP','$res2[ap]','$res2[ig]','$res2[hnd]','$res2[tt]','spare','$res2[InvoiceNo]')";
 //print $sqig1;
   mysqli_query($db,$sqig1) or die('saleinv err'.mysqli_error($db));
}


$sqig=mysqli_query($db,"select GRNNo,GRNDate,vendorCode,sum(BTAmt) ap,sum(TaxAmt) ig,sum(hand) hnd,sum(InvAmt) tt,InvoiceNo from eicherpurchase  where brcode='$brcode'  and GRNDate>='$dfrom' and GRNDate<='$dto' and taxp='5.00'  group by GRNNo");
 while($res2=mysqli_fetch_array($sqig))
{
 $sqig1="insert into $tbl(invno,invdate,cust,brcode,invtype,5b4,5igst,hand,total,salestype,pbillno) values('$res2[GRNNo]','$res2[GRNDate]','$res2[vendorCode]','$brcode','EICHP','$res2[ap]','$res2[ig]','$res2[hnd]','$res2[tt]','spare','$res2[InvoiceNo]')";
 //print $sqig1;
   mysqli_query($db,$sqig1) or die('saleinv err'.mysqli_error($db));
}

//  Eicher Pur end #######################################




//   VECV   spare purchase start   ########################################

$sq2="select  grno,entrydate,suplier,sum(aprice) ap,sum(sgstamt) sg,sum(cgstamt) cg,sum(hand) hnd,sum(tot) tt ,pbillno,purdate,sum(taxamt) taxa from sparepurchasevecv  where brcode='$brcode' and entrydate>='$dfrom' and entrydate<='$dto'  and tax='28.00' and taxtype='CGST' group by grno";
$re21=mysqli_query($db,$sq2)or die('Err3:'.mysqli_error($db));

while($res2=mysqli_fetch_array($re21))
{
 $gstt=$res2['taxa']/2;
 $sq14="insert into $tbl(invno,invdate,cust,brcode,invtype,28b4,14sgst,14cgst,hand,total,salestype,pbillno,purdate) values('$res2[grno]','$res2[entrydate]','$res2[suplier]','$brcode','VECV','$res2[ap]','$gstt','$gstt','$res2[hnd]','$res2[tt]','spare','$res2[pbillno]','$res2[purdate]')";
   mysqli_query($db,$sq14) or die('saleinv28cg13 err'.mysqli_error($db));
}


$sq2="select  grno,entrydate,suplier,sum(aprice) ap,sum(sgstamt) sg,sum(cgstamt) cg,sum(hand) hnd,sum(tot) tt ,pbillno,purdate,sum(taxamt) taxa from sparepurchasevecv  where brcode='$brcode' and entrydate>='$dfrom' and entrydate<='$dto'  and tax='18.00' and taxtype='CGST' group by grno";
$re21=mysqli_query($db,$sq2)or die('Err3:'.mysqli_error($db));

while($res2=mysqli_fetch_array($re21))
{
  $gstt=$res2['taxa']/2;
 $sq14="insert into $tbl(invno,invdate,cust,brcode,invtype,18b4,9sgst,9cgst,hand,total,salestype,pbillno,purdate) values('$res2[grno]','$res2[entrydate]','$res2[suplier]','$brcode','VECV','$res2[ap]','$gstt','$gstt','$res2[hnd]','$res2[tt]','spare','$res2[pbillno]','$res2[purdate]')";
   mysqli_query($db,$sq14) or die('saleinv18cg err'.mysqli_error($db));
}


$sq2="select  grno,entrydate,suplier,sum(aprice) ap,sum(sgstamt) sg,sum(cgstamt) cg,sum(hand) hnd,sum(tot) tt ,pbillno,purdate,sum(taxamt) taxa from sparepurchasevecv  where brcode='$brcode' and entrydate>='$dfrom' and entrydate<='$dto'  and tax='12.00' and taxtype='CGST' group by grno";
$re21=mysqli_query($db,$sq2)or die('Err3:'.mysqli_error($db));

while($res2=mysqli_fetch_array($re21))
{
  $gstt=$res2['taxa']/2;
 $sq14="insert into $tbl(invno,invdate,cust,brcode,invtype,12b4,6sgst,6cgst,hand,total,salestype,pbillno,purdate) values('$res2[grno]','$res2[entrydate]','$res2[suplier]','$brcode','VECV','$res2[ap]','$gstt','$gstt','$res2[hnd]','$res2[tt]','spare','$res2[pbillno]','$res2[purdate]')";
   mysqli_query($db,$sq14) or die('saleinv18cg err'.mysqli_error($db));
}

$sq2="select  grno,entrydate,suplier,sum(aprice) ap,sum(sgstamt) sg,sum(cgstamt) cg,sum(hand) hnd,sum(tot) tt ,pbillno,purdate,sum(taxamt) taxa from sparepurchasevecv  where brcode='$brcode' and entrydate>='$dfrom' and entrydate<='$dto'  and tax='5.00' and taxtype='CGST' group by grno";
$re21=mysqli_query($db,$sq2)or die('Err3:'.mysqli_error($db));

while($res2=mysqli_fetch_array($re21))
{
  $gstt=$res2['taxa']/2;
 $sq14="insert into $tbl(invno,invdate,cust,brcode,invtype,5b4,2_5sgst,2_5cgst,hand,total,salestype,pbillno,purdate) values('$res2[grno]','$res2[entrydate]','$res2[suplier]','$brcode','VECV','$res2[ap]','$gstt','$gstt','$res2[hnd]','$res2[tt]','spare','$res2[pbillno]','$res2[purdate]')";
   mysqli_query($db,$sq14) or die('saleinv18cg err'.mysqli_error($db));
}
//###
$sq2="select  grno,entrydate,suplier,sum(aprice) ap,sum(sgstamt) sg,sum(cgstamt) cg,sum(hand) hnd,sum(tot) tt ,pbillno,purdate,sum(taxamt) taxa from sparepurchasevecv  where brcode='$brcode' and entrydate>='$dfrom' and entrydate<='$dto'  and tax='0.00'  group by grno";
$re21=mysqli_query($db,$sq2)or die('Err3:'.mysqli_error($db));

while($res2=mysqli_fetch_array($re21))
{
 $gstt=$res2['taxa'];
 $sq14="insert into $tbl(invno,invdate,cust,brcode,invtype,0gst,hand,total,salestype,pbillno,purdate) values('$res2[grno]','$res2[entrydate]','$res2[suplier]','$brcode','VECV','$res2[ap]','$res2[hnd]','$res2[tt]','spare','$res2[pbillno]','$res2[purdate]')";
   mysqli_query($db,$sq14) or die('saleinv18cg err'.mysqli_error($db));
}




$sq2="select  grno,entrydate,suplier,sum(aprice) ap,sum(igstamt) ig,sum(hand) hnd,sum(tot) tt ,pbillno,purdate,sum(taxamt) taxa from sparepurchasevecv  where brcode='$brcode' and entrydate>='$dfrom' and entrydate<='$dto'  and tax='28.00' and taxtype='IGST' group by grno";
$re21=mysqli_query($db,$sq2)or die('Err3:'.mysqli_error($db));

while($res2=mysqli_fetch_array($re21))
{
  $gstt=$res2['taxa'];
 $sq14="insert into $tbl(invno,invdate,cust,brcode,invtype,28b4,28igst,hand,total,salestype,pbillno,purdate) values('$res2[grno]','$res2[entrydate]','$res2[suplier]','$brcode','VECV','$res2[ap]','$gstt','$res2[hnd]','$res2[tt]','spare','$res2[pbillno]','$res2[purdate]')";
   mysqli_query($db,$sq14) or die('saleinv18cg err'.mysqli_error($db));
}


$sq2="select  grno,entrydate,suplier,sum(aprice) ap,sum(igstamt) ig,sum(hand) hnd,sum(tot) tt ,pbillno,purdate,sum(taxamt) taxa from sparepurchasevecv  where brcode='$brcode' and entrydate>='$dfrom' and entrydate<='$dto'  and tax='18.00' and taxtype='IGST' group by grno";
$re21=mysqli_query($db,$sq2)or die('Err3:'.mysqli_error($db));

while($res2=mysqli_fetch_array($re21))
{
 $gstt=$res2['taxa'];
 $sq14="insert into $tbl(invno,invdate,cust,brcode,invtype,18b4,18igst,hand,total,salestype,pbillno,purdate) values('$res2[grno]','$res2[entrydate]','$res2[suplier]','$brcode','VECV','$res2[ap]','$gstt','$res2[hnd]','$res2[tt]','spare','$res2[pbillno]','$res2[purdate]')";
   mysqli_query($db,$sq14) or die('saleinv18cg err'.mysqli_error($db));
}


$sq2="select  grno,entrydate,suplier,sum(aprice) ap,sum(igstamt) ig,sum(hand) hnd,sum(tot) tt ,pbillno,purdate,sum(taxamt) taxa from sparepurchasevecv  where brcode='$brcode' and entrydate>='$dfrom' and entrydate<='$dto'  and tax='12.00' and taxtype='IGST' group by grno";
$re21=mysqli_query($db,$sq2)or die('Err3:'.mysqli_error($db));

while($res2=mysqli_fetch_array($re21))
{
 $gstt=$res2['taxa'];
 $sq14="insert into $tbl(invno,invdate,cust,brcode,invtype,12b4,12igst,hand,total,salestype,pbillno,purdate) values('$res2[grno]','$res2[entrydate]','$res2[suplier]','$brcode','VECV','$res2[ap]','$gstt','$res2[hnd]','$res2[tt]','spare','$res2[pbillno]','$res2[purdate]')";
   mysqli_query($db,$sq14) or die('saleinv18cg err'.mysqli_error($db));
}



$sq2="select  grno,entrydate,suplier,sum(aprice) ap,sum(igstamt) ig,sum(hand) hnd,sum(tot) tt ,pbillno,purdate,sum(taxamt) taxa from sparepurchasevecv  where brcode='$brcode' and entrydate>='$dfrom' and entrydate<='$dto'  and tax='5.00' and taxtype='IGST' group by grno";
$re21=mysqli_query($db,$sq2)or die('Err3:'.mysqli_error($db));

while($res2=mysqli_fetch_array($re21))
{
 $gstt=$res2['taxa'];
 $sq14="insert into $tbl(invno,invdate,cust,brcode,invtype,5b4,5igst,hand,total,salestype,pbillno,purdate) values('$res2[grno]','$res2[entrydate]','$res2[suplier]','$brcode','VECV','$res2[ap]','$gstt','$res2[hnd]','$res2[tt]','spare','$res2[pbillno]','$res2[purdate]')";
   mysqli_query($db,$sq14) or die('saleinv18cg err'.mysqli_error($db));
}





// ############## VECV  spare purchase end        ##############################





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

//  Spare Purchase  print


print "<table border=1 cellspacing=1 cellpadding=4 bgcolor='lightsteelblue'>";
print "<tr><th colspan=27><h3>SPARE PURCHASE</th></tr>";
print "<tr><th colspan=9><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>GRN No <th>Entry Date ";
print "<th>GST NO<th>Suplier<th>State Code<th>Branch<th>Sales Type<th>Bill No.<th>Pbill Date<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,pbillno,purdate from $tbl  where brcode='$brcode' and invtype='SP' 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_result=mysqli_query($db,"select cst from sup_master where web = '$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><td>$rowinvno[3]</td><td>".datetohtml($rowinvno[4])."</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=9 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>";

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

//  spare purchase  print  end



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

//  Item Purchase Accessories  print


print "<table border=1 cellspacing=1 cellpadding=4 bgcolor='lightsteelblue'>";
print "<tr><th colspan=27><h3>ITEM PURCHASE (ACCESSORIES)</th></tr>";
print "<tr><th colspan=9><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>GRN No <th>Entry Date ";
print "<th>GST NO<th>Suplier<th>State Code<th>Branch<th>Sales Type<th>Bill No.<th>Pbill Date<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,pbillno,purdate from $tbl  where brcode='$brcode' and invtype='SPACS' order by invdate,invno ASC ")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_result=mysqli_query($db,"select cst,supname from sup_master where icode = '$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($cus_row[1])."</td><td></td><td>$brcode</td><td>Spare</td><td>$rowinvno[3]</td><td>".datetohtml($rowinvno[4])."</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=9 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>";

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

//  Item purchase accessories  print  end



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

//  Item Purchase Accessories ret  print


print "<table border=1 cellspacing=1 cellpadding=4 bgcolor='lightsteelblue'>";
print "<tr><th colspan=27><h3>ITEM PURCHASE RETURN (ACCESSORIES)</th></tr>";
print "<tr><th colspan=9><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>GRN No <th>Entry Date ";
print "<th>RET NO<th>Suplier<th>State Code<th>Branch<th>Sales Type<th>Bill No.<th>Pbill Date<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,pbillno,purdate from $tbl  where brcode='$brcode' and invtype='SPACSR' 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_result=mysqli_query($db,"select cst,supname from sup_master where supname = '$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($cus_row[1])."</td><td></td><td>$brcode</td><td>Spare</td><td>$rowinvno[3]</td><td>".datetohtml($rowinvno[4])."</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=9 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>";

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

//  Item purchase accessories ret print  end




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

// VECV Spare Purchase WH  print


print "<table border=1 cellspacing=1 cellpadding=4 bgcolor='lightsteelblue'>";
print "<tr><th colspan=27><h3>SPARE PURCHASE VECV</th></tr>";
print "<tr><th colspan=9><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>GRN No <th>Entry Date ";
print "<th>GST NO<th>Suplier<th>State Code<th>Branch<th>Sales Type<th>Bill No.<th>Pbill Date<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,pbillno,purdate from $tbl  where brcode='$brcode' and invtype='VECV' 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 = '$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><td>$rowinvno[3]</td><td>".datetohtml($rowinvno[4])."</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=9 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>";

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

//  VECV spare purchase WH print  end


//*********** Sales Return  print start


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


print "<table border=1 cellspacing=1 cellpadding=4 bgcolor='lightsteelblue'>";
print "<tr><th colspan=26><h3>SALES RETURN</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='CSRET' 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='CSRET' 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 = '$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>$rowinvno[3]</td>";
   
    print "<td align=right>".putComa($row[0]*-1)."</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]*-1)."</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]*-1)."</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]*-1)."</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]*-1;
$cg5+=$row[14];
$sg5+=$row[13];
$ig5+=$row[15];

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

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

$bta28+=$row[0]*-1;
$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>";
//   Sales Return    print  end  #########################################



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

//  Transfer IN  print


print "<table border=1 cellspacing=1 cellpadding=4 bgcolor='lightsteelblue'>";
print "<tr><th colspan=26><h3>INTERSTATE STOCK TRANSFER IN</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>GRN NO<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,pbillno from $tbl  where brcode='$brcode' and invtype='TRIN' 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><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>";


//###########################################################################
// Transfer in END

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

// GST exp   print  start



print "<table border=1 cellspacing=1 cellpadding=4 bgcolor='lightsteelblue'>";
print "<tr><th colspan=26><h3>GST EXPENSE </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<th>Vender invno ";
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='EXP' 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,pbillno 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 sup_master where web = '$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>".$row['pbillno']."</td>";
    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 exp   print  end



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

//  EICHER Purchase  print


print "<table border=1 cellspacing=1 cellpadding=4 bgcolor='lightsteelblue'>";
print "<tr><th colspan=26><h3>EICHER PURCHASE</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>GRN NO<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,pbillno from $tbl  where brcode='$brcode' and invtype='EICHP' 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 sup_master where web = '$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><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>";


//###########################################################################
// Transfer in 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> Inward 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>


