<?
session_start();
include_once('includes/top.php');
include_once('opendb.php');
$brcode=$_SESSION['brcode'];
$user=$_SESSION['user'];
$level=$_SESSION['level'];
if(strlen($user)<=0)
{
 print "<script> alert('You are not logged in') </script>";
 include("logout.php");
 return;
}
?>
	<link type="text/css" href="includes/style1.css" rel="stylesheet" />
<link href="css/form.css" type="text/css" rel="stylesheet" media="screen" />
<script>
function valid()
{ 
 subOK="false";
 
if(document.f1.state1.selectedIndex<1)
  {subOK="false"; alert('Invalid state');
      
    return false;  
  }




 x=confirm("Do you want to save?");
 if(x)
  subOK="true";
   if(subOK=="true")
     return true;
   else
     return false;
} 

function chkey(abc)
{
 yy=abc.value
 if(yy.length>35)
 { 
//   alert('Name exeeds the limit');
//   return;
 }

 if(yy.indexOf('  ')>-1) 
  {
    alert('Multiple space is not allowed');
    abc.value='';
  }
 if(yy.indexOf("'")>-1) 
  {
    alert("\' is not allowed");
    abc.value='';
  }
 if(yy.indexOf('"')>-1) 
  {
    alert("\" is not allowed");
    abc.value='';
  }

if(yy.indexOf("&")>-1) 
  {
    alert("& is not allowed");
    abc.value='';
  }

}
</script>

<?
?>


<center>
<form name='f1' method='post' action='<?print $PHP_SELF?>' onSubmit="handleSelectClick();return true;">
<table>
<th colspan=4>LIMIT</th>
<tr><td>LIMIT </td><td><input type="text" name="pcode" VALUE="<?print $pcode?>" style="font-size:10pt;width:34ex;"><br>

</td></tr>
<!-- <tr><td>Part Name </td>
    <td><input type=text name='pname' size=32></td></tr> -->
<th colspan=3><input type=submit value='Search' name='sea'>
</td></tr>
</table>


</form>

<?//<table cellspacing=1 cellpadding=3 class='report'>
//<tr><td>Checking with Customer Name</td></tr>    
//<th>No. <th>Name <th>total B4amount cs<th>Total bill amt cs<th>branch

$pcode=$_REQUEST['pcode'];
if(isset($_POST['sea']))
{
   /* $tbl12 = 'tcscheck1'.$brcode;
    mysqli_query($db,"CREATE TABLE $tbl12 (customer varchar(200),pan varchar(20),bef_tax double(10,2) default 0, totamt double(10,2) default 0)");
    mysqli_query($db,"delete from $tbl12");
    mysqli_query($db,"insert into $tbl12 select customer,substr(gstin,3,10),sum(aprice),sum(tot) from psn_psneicherdb.spareinvoice group by customer");
    mysqli_query($db,"insert into $tbl12 select cname,substr(gstin,3,10),sum(amt),sum(gtot) from psn_psneicherdb.jcardparts,psn_psneicherdb.jobcard where psn_psneicherdb.jobcard.invno = psn_psneicherdb.jcardparts.invno group by psn_psneicherdb.jcardparts.invno");
   // mysqli_query($db,"insert into $tbl12 select cname,substr(gstin,3,10),sum(servamt),sum(tot) from psn_psneicherdb.jcardserv,psn_psneicherdb.jobcard where psn_psneicherdb.jobcard.invno = psn_psneicherdb.jcardserv.invno group by psn_psneicherdb.jcardserv.invno");
    mysqli_query($db,"insert into $tbl12 select acname,remark,amt2,netamt from psn_psndb.veh_invoice, psn_psndb.cust_master where psn_psndb.cust_master.code = psn_psndb.veh_invoice.cust");

    mysqli_query($db,"insert into $tbl12 select customer,msno,sum(aprice),sum(tot) from psn_boschdb.spareinvoice where length(msno) > 3 group by msno");
    mysqli_query($db,"insert into $tbl12 select customer,msno,sum(aprice),sum(tot) from psn_boschdb.spareinvoice_oth where length(msno) > 3 group by msno");
    mysqli_query($db,"insert into $tbl12 select customer,msno,sum(aprice),sum(tot) from psn_boschdb.spareinvoice_oth_o where length(msno) > 3 group by msno");
    mysqli_query($db,"insert into $tbl12 select customer,msno,sum(aprice),sum(tot) from psn_boschdb.spareinvoice_oth_v where length(msno) > 3 group by msno");
   // $re=mysqli_query($db,"SELECT customer FROM $tbl12 where customer < 'AAAAAAAA' ")or die(mysqli_error());
//    while($row=mysqli_fetch_array($re))
  //  {
    //    $brre=mysqli_query($db,"select cname from psn_psneicherdb.jobcard where invno = '$row[0]' limit 1");
     //   $brrow=mysqli_fetch_row($brre);
      //  mysqli_query($db,"update $tbl12 set customer = '$brrow[0]' where customer = '$brrow[0]' ");
        //print "update $tbl12 set customer = '$brrow[0]' where customer = '$row[0]'<br>"; 
    //}
    
    $re=mysqli_query($db,"SELECT  customer,sum(bef_tax),sum(totamt) FROM $tbl12 group by customer HAVING sum(totamt)>'$pcode'")or die(mysqli_error());
    $i=1;
    while($row=mysqli_fetch_array($re))
    {
        print "\n<tr bgcolor=aliceblue><td>".$i++."</td><td>$row[0]</td><td>$row[1]</td><td>$row[2]</td>";
        print"</tr>";
    
    }
    print   "</table><br>";*/
    print "<tr><td>Checking with PAN</td></tr>";
    print "<table cellspacing=1 cellpadding=3 class='report'>";
    print "<th>No. <th>Name <th>PAN<th>B4Tax Total<th>Total Bill Amt cs<th>branch";
    
    $tbl1 = 'tcscheck'.$brcode;
    mysqli_query($db,"drop table $tbl1");
    mysqli_query($db,"CREATE TABLE $tbl1 (customer varchar(200),pan varchar(20),bef_tax double(10,2) default 0, totamt double(10,2) default 0, brcode varchar(20))");
    mysqli_query($db,"delete from $tbl1");
    mysqli_query($db,"insert into $tbl1 select customer,susbtr(gstin,3,10),sum(aprice),sum(tot),brcode from gen4psnauto_psn_psneicherdb.spareinvoice where length(gstin) > 3 group by gstin,brcode");
    mysqli_query($db,"insert into $tbl1 select cname,substr(ship_togst,3,10),sum(amt),sum(gtot),gen4psnauto_psn_psneicherdb.jcardparts.brcode from psn_psneicherdb.jcardparts,psn_psneicherdb.jobcard where psn_psneicherdb.jobcard.invno = psn_psneicherdb.jcardparts.invno group by psn_psneicherdb.jcardparts.invno,psn_psneicherdb.jcardparts.brcode");
    //mysqli_query($db,"insert into $tbl1 select cname,substr(ship_togst,3,10),sum(servamt),sum(tot) from psn_psneicherdb.jcardserv,psn_psneicherdb.jobcard where psn_psneicherdb.jobcard.invno = psn_psneicherdb.jcardserv.invno group by psn_psneicherdb.jcardserv.invno");
    mysqli_query($db,"insert into $tbl1 select acname,kgst,amt2,netamt,brcode from psn_psndb.veh_invoice, gen4psnauto_psn_psndb.cust_master where psn_psndb.cust_master.code = psn_psndb.veh_invoice.cust");
    mysqli_query($db,"insert into $tbl1 select customer,susbtr(tin,3,10),sum(aprice),sum(tot),brcode from gen4psnauto_psn_boschdb.spareinvoice where length(tin) > 3 group by tin,brcode");
    mysqli_query($db,"insert into $tbl1 select customer,susbtr(tin,3,10),sum(aprice),sum(tot),brcode from gen4psnauto_psn_boschdb.spareinvoice_oth where length(tin) > 3 group by tin,brcode");
    mysqli_query($db,"insert into $tbl1 select customer,susbtr(tin,3,10),sum(aprice),sum(tot),brcode from gen4psnauto_psn_boschdb.spareinvoice_oth_o where length(tin) > 3 group by tin,brcode");
    mysqli_query($db,"insert into $tbl1 select customer,susbtr(tin,3,10),sum(aprice),sum(tot),brcode from gen4psnauto_psn_boschdb.spareinvoice_oth_v where length(tin) > 3 group by tin,brcode");
    $re=mysqli_query($db,"SELECT  customer,pan,sum(bef_tax),sum(totamt) from $tbl1 where pan !='' group by pan HAVING sum(totamt)>'$pcode' ")or die(mysqli_error());
    $i=1;
    while($row=mysqli_fetch_array($re))
    { 
        if(strlen($row[1])>5 || $row[1]!='T REGISTER')
        {
            $mcust = $row[0];
            $brre=mysqli_query($db,"select acname from gen4psnauto_psn_psndb.cust_master where kgst ='$row[1]' limit 1");
            $brrow=mysqli_fetch_row($brre);
            if($brrow[0]>'')
                $mcust = $brrow[0];
            print "\n<tr bgcolor=aliceblue><td>".$i++."</td><td>$mcust</td><td>$row[1]</td><td>$row[2]</td><td>$row[3]</td>";
            print"</tr>";
        }
    }
    print   "<table>";
    $re=mysqli_query($db,"SELECT  customer,pan,sum(bef_tax),sum(totamt) from $tbl1 where pan !='' group by pan HAVING sum(totamt)>'$pcode' ")or die(mysqli_error());
    $ctr=1;
    
    while($row=mysqli_fetch_array($re))
    { 
        $re1=mysqli_query($db,"SELECT distinct customer from $tbl1 where pan ='$row[1]' and brcode = '$brcode' ")or die(mysqli_error());
        $i=1;
        while($row1=mysqli_fetch_array($re1))
        { 
            if($ctr==1)
            {
                print "<tr><td colspan=3>TCS Applicable to Customers in your branch</td></tr>";
                $ctr++;
            }
            print "\n<tr bgcolor=aliceblue><td>".$i++."</td><td>$row1[0]</td><td>$row[1]</td>";
        }
    }
    print   "</table><br>";
}// end if sea
function getBranch($cde)
{
 $brre=mysqli_query($db,"select brname from branch where brcode='$cde'");
 $brrow=mysqli_fetch_row($brre);
 return $brrow[0];
}
?>

<?

?>
</table>

<script>


function del(gstcode)
{
if(confirm("Do you want to delete GST "+gstcode+" ?"))
 document.location="delgstmas.php?gstcode="+gstcode;

}
</script>


