<? 
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><?print strtoupper($brrow['braddr'])?><br><?print strtoupper($brrow[4])?><br>Phone :<?print strtoupper($brrow[5])?><br>GSTIN :<?print strtoupper($brrow['cstno'])?></td></tr>
<tr><td align=center><br><U>CREDIT 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 crnote 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[partic]'") or die(mysqli_error($db));
  $rsrowc=mysqli_fetch_array($re3c);

$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://qrcode.tec-it.com/API/QRCode?size=small&dpi=100&data=<?print $signedqr;?>" width="150px" height="150px">
    <?
    print "IRN No:".$irn;
}
print "<table bgcolor='' border=0 cellspacing=0 cellpadding=5 width=90%> <font size=2><tr><td>Credit 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['partic']?></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}>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=200><font size=2>Account Head </td><td width=300><font size=2>Details</td><td width=100 ><font size=2>Before Tax Amount</td><td width=100 ><font size=2>TAX%</td><td width=100 ><font size=2>TAX Amount</td><td width=100 ><font size=2>Total</td></b></tr></table> ";
print "<table bgcolor='ivory' border=0 cellspacing=1 cellpadding=1 width=90%>";

    $re2=mysqli_query($db,"select * from crnote where dbno='$jvno' and brcode='$brcode'") or die(mysqli_error($db));
    while($jvrow=mysqli_fetch_array($re2))
    {
        print "\n<tr><td width=20><font size=3>1 </td><td width=200><font size=3>$jvrow[dbto] </td>";
        print "<td width=1></td><td width=300 align=left><font size=3>$jvrow[narr]</td>";
        print "<td width=1></td><td width=100 align=left><font size=3>".nozero($jvrow['b4tax'])."</td><td width=100 align=left><font size=3>".nozero($jvrow['taxp'])."</td><td width=100 align=left><font size=3>".nozero($jvrow['taxamt'])."</td><td width=100 align=left><font size=3>".nozero($jvrow['cramt'])."</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><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['cramt'])."</td></tr></table>";

?>

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

<?

print "<table bgcolor='' border=0 cellspacing=3 cellpadding=1 width=100%> <font size=2><tr></tr><tr><br> <td width=10></td><td align=left>We have credited your account during this financial year on account of discount given<br>$rsrow[narr]<br>Your account has been thus credited by Rs $rsrow[cramt] </td><br><br><td width=1></tr></table>";


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


print "<table bgcolor='' border=0 cellspacing=3 cellpadding=1 width=100%> <font size=2><tr></tr><tr><br> <td width=10></td><td align=left>Authorised Signatory &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp
&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp 
&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbspChecked By</td><td width=1></tr></table><hr>";


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