<? 
session_start();
$brcode=$_SESSION['brcode'];
$user=$_SESSION['user'];
$jvno=$_REQUEST['jvno'];
if(strlen($brcode)<=0)
{
 print "<script> alert('Session timed out'); parent.document.location='../ind.php'; </script>";
 return;
}

include("opendb.php");
include("test.php");
$ad=mysqli_query($db,"select * from branch where brcode='$brcode'");
$brrow=mysqli_fetch_array($ad);
$brname=explode(',',$branch);

?>
<br>
<center>
<table width=90% >
<tr><td align=center><p style={letter-spacing:2;font-size:15}><b>PSN AUTOMOTIVE MARKETING PRIVATE LTD</TD></TR>
<TR><TD ALIGN=CENTER><font size=2>AUTHORISED DEALER FOR EICHER VEHICLES
</td></TR>
<TR><TD ALIGN=CENTER><font size=2>
Regd.Off. 2/330, CHERANALLOOR,</td></TR>
<TR><TD ALIGN=CENTER><font size=2> ERNAKULAM, PIN.682 034</td></TR>

<TR><TD ALIGN=CENTER><font size=2>Branch : <?print strtoupper($brrow['braddr'])?><br><?print strtoupper($brrow[4])?><br>Phone :<?print strtoupper($brrow[5])?></td></tr>
<tr><td align=center><br><U>DEBIT NOTE </U></TD></TR>
</table>
</center>

<br>
<left>

</left>
<table width=100%><tr><td >&nbsp&nbsp</td><td >
<?

//print $row1[1];
$re=mysqli_query($db,"select distinct jvno,j_type from journal2 where brcode='$brcode' and jvno='$jvno'  ");
$re3=mysqli_query($db,"select * from dbnote where dbno='$jvno' and brcode='$brcode'") or die(mysqli_error($db));
  $rsrow=mysqli_fetch_array($re3);

$re3c=mysqli_query($db,"select * from customer where acname='$rsrow[dbto]'") or die(mysqli_error($db));
if(mysqli_num_rows($re3c)>0)
{
  $rsrowc=mysqli_fetch_array($re3c);
  

}
else
{
    $re3c=mysqli_query($db,"select * from sup_master  where web='$rsrow[dbto]'") or die(mysqli_error($db));
   $rsrowc=mysqli_fetch_array($re3c);
  

}
//qrcode
$qrqry=mysqli_query($db,"select * from tbl_einvoice where invno='$jvno' and brcode='$brcode'");
$qrrow=mysqli_fetch_array($qrqry);
$signedqr=$qrrow['SignedQRCode'];
$irn=$qrrow['irnno'];
if(strlen($irn)>0){
    ?>
    <img src="https://chart.googleapis.com/chart?chs=200x200&cht=qr&chl=<?print $signedqr;?>&choe=UTF-8" alt="generation qr-code" style="border: solid 0px black;width:200px;height:200px;"> 
    <?
    print "IRN No:".$irn;
}
//end qrcode
print "<table bgcolor='' border=0 cellspacing=0 cellpadding=5 width=90%> <font size=2><tr><td>Debit Note  No :&nbsp;$jvno</td><td align='center'>&nbsp&nbsp&nbsp&nbspDate :&nbsp;".datetohtml($rsrow['date'])."</td> </tr></table><br>"; 
?>


<table  width=90%>
<tr><td align=left><p style={letter-spacing:2;font-size:15}><b><? print $rsrow['dbto']?></TD></TR>
<tr><td align=left><p style={letter-spacing:2;font-size:15}><b><? print $rsrowc['addr1']?></TD></TR>
<tr><td align=left><p style={letter-spacing:2;font-size:15}><b><? print $rsrowc['dist']?></TD></TR>
<tr><td align=left><p style={letter-spacing:2;font-size:15}><b><? print $rsrowc['pin']?></TD></TR>
<tr><td align=left><p style={letter-spacing:2;font-size:15}>GSTIN : <b><? print $rsrowc['cst']?></TD></TR>

</table><br>



<?

print "<table bgcolor='ivory' border=1 cellspacing=1 cellpadding=0 width=90%> <font size=2><tr><b> <td width=20><font size=2>Sr.No </td> <td width=300><font size=2>Account Head </td><td><font size=2>HSN CODE</td><td width=300><font size=2>Details</td><td width=150 ><font size=2>Amount</td><td width=150> Tax%</td><td width=150> CGST Amt</td><td width=150> SGST Amt</td><td width=150> IGST Amt</td><td width=2><td width=150>Total</td></b></tr></table> ";
print "<table bgcolor='ivory' border=1 cellspacing=1 cellpadding=1 width=90%>";

    $re2=mysqli_query($db,"select * from dbnote where dbno='$jvno' and brcode='$brcode'") or die(mysqli_error($db));
    while($jvrow=mysqli_fetch_array($re2))
    {
        if($jvrow['taxtype']=='INTRA STATE')
        {
            $cgsta=$jvrow['taxamt']/2;
            $sgsta=$jvrow['taxamt']/2;
            $igsta=0;
        }
        else
        {
          $cgsta=0;
          $sgsta=0;
          $igsta=$jvrow['taxamt'];
        }
        print "\n<tr><td width=20><font size=3>1 </td><td width=300><font size=3>$jvrow[partic] </td><td><font size=3>$jvrow[hsn] </td>";
        print "<td width=300 align=left><font size=3>$jvrow[narr]</td>";
          print "<td width=150 align=left><font size=3>$jvrow[b4tax]</td>";
       
        print "<td width=150 align=left><font size=3>$jvrow[taxp]</td>";
        print "<td width=150 align=left><font size=3>$cgsta</td>";
        print "<td width=150 align=left><font size=3>$sgsta</td>";
        print "<td width=150 align=left><font size=3>$igsta</td>";
      
        
        print "<td width=150 align=left><font size=3>".nozero($jvrow['dramt'])."</td></tr>";
        
        
  }
  
     //print "<tr><td colspan=9 bgcolor=''></td></tr>";
print "<tr><td colspan=9 ></td></tr></table>";
print "<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><hr>";
print "<table bgcolor='' border=0 cellspacing=3 cellpadding=1 width=100%> <font size=2><tr></tr><tr><br> <td width=300></td><td align=center>Grand Total:&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp<font size=3>".nozero($rsrow['dramt'])."</td></tr></table>";

?>

<font size=3>( <?print word($rsrow['dramt'])?> Only)</font>

<?
print "<table bgcolor='' border=0 cellspacing=3 cellpadding=1 width=100%> <font size=2><tr></tr><tr><br><br> <td width=400></td><td align=center>For Psn Automotive Marketing Private Ltd</td><br><br><td width=50></tr></table>";


print "<table bgcolor='' border=0 cellspacing=3 cellpadding=1 width=100%> <font size=2><tr></tr><tr><br><br> <td width=400></td><td align=center>Authorised Signatory</td><td width=50></tr></table><hr>";


?>
</td></tr></table>