<?
session_start();
$brcode=$_SESSION['brcode'];
$user=$_SESSION['user'];
if(strlen($brcode)<=0)
{
 print "<script> alert('Session timed out'); parent.document.location='../index.php'; </script>";
 return;
}
$invno=$_REQUEST['invno'];
include("test.php");
include("opendb.php");
include("includes/function.php");
//include("calstock.php");

?>
<!DOCTYPE html>
<html><head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
<title>PSN VEHICLE INVOICE</title>
<style>
body{
  -webkit-print-color-adjust:exact;
}
.printable{ 
      page-break-before: always;
      margin-top:30px;
    }
.tbl{
border: 1px solid black;
border-bottom:0px solid white;
font-size:10px;
text-transform:uppercase;
}
.tbl td{
border: 0px solid black;
}
#tbl{
border: 1px solid black;
}
.tble{
border: 1px solid black;
border-bottom:0px solid white;
font-size:10px;
border-collapse:collapse;
text-transform:uppercase;

}
.tble  td{
height:8px;
margin-left:10px;
margin-right:10px;
padding-left:10px;
padding-right:10px;
}
.tble th{
border:1px solid black;
}
.tbl1{
border: 1px solid black;
border-bottom:0px solid white;
font-size:10px;
border-collapse:collapse;
text-align:right;
text-transform:uppercase;
}
.tbl1 td{
//border-bottom:1px solid black;
height:10px;
}
#add_td{
font-size:12px;
height:15px;
}
#add_td br{
margin:0px;
padding:0px;
}
.tot_td{
border-bottom:0px solid black;
}
.tot_td1{
border-top:0px solid black;
}
#tot_tbl td{
border:1px solid black;
border-collapse:collapse;
}
body
 {font-family:Arial;
  }
p{
 margin:0px;
 padding:0px;
 }
@media print{
            #head
            {
                background-color:white;
            }
        }
</style>
<body onload='window.print()'>
<?

$result=mysqli_query($db,"select * from gst_creditnote where refno='$invno' and brcode='$brcode'");
$res1=mysqli_fetch_array($result);

$re=mysqli_query($db,"select * from branch where brcode='$brcode'");
$brow=mysqli_fetch_array($re);

//$brcol=substr($res1[cmpcode],0,3).'_ret_veh';
//$tr = "select $brcol from branch where brcode = '$brcode'";
//$trd=mysqli_query($db,$tr);
//$trdrow=mysqli_fetch_row($trd);
 
$minno =  $invno;
        
        $amt=$res1['netamt'];
        $qty =1;
        $disc =$res1['disc'];
        $cgstp=$res1['cgstp'];
        $sgstp=$res1['sgstp'];
        $igstp=$res1['igstp'];
        $cgstamt=$res1['cgstamt'];
        $sgstamt=$res1['sgstamt'];
        $igstamt=$res1['igstamt'];
        $tcsper = $res1['tcsper'];
        $tcsamt = $res1['tcsamt'];

        if($res1['invtype']=='INTERSTATE')
        {
		    $tot=$res1['amt2'];
        }
        else
        {
           $tot=$res1['amt2'];
        }
        
        $r=mysqli_query($db,"select * from sup_master where supname ='$res1[vendor]'")or die(mysqli_error());
        $cus_row=mysqli_fetch_array($r);
        $qrqry=mysqli_query($db,"select * from tbl_einvoice where invno='$invno' and brcode='$brcode'");
$qrrow=mysqli_fetch_array($qrqry);
$signedqr=$qrrow['SignedQRCode'];
?>
	<table border='0' class='printable' width='100%'>
	  
	   <tr><td colspan=6 align=center style="font-size: 22px;"<b>PSN AUTOMOBILES PVT LTD</td></tr>
 	   <tr><td colspan=6 align=center><b>GST NO : <?echo $brow['tin']?></td></tr>
	   <tr><td colspan=6 align=center><b><?echo $brow['braddr']?></td></tr>
	   <tr><td colspan=6 align=center><b><?echo $brow['brcity']?></td></tr>
	   <tr><td colspan=6 align=center><b><?echo $brow['brphone']?></td></tr>
	   <tr><td colspan=6 align=center><b>CIN NO : U50300KL 1996PTC010842</td></tr>
	<table><tr><td align='left'  id='add_td'></td><td align='right' ></td></tr><td align='right'  width='40%'> <? if($signedqr!='')
	{ ?><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;"> <?
	}
	?></td><td><?echo $qrrow['irnno']?></td>
    </table>
	<table border='1' style='border-collapse:collapse;' width='100%'>
	    <tr><th  align='center' style='border:0px solid white;height:20px;font-size:18px;' id='head'>TAX INVOICE</th></tr>
	    
	    </table>
	<table  class='tbl' width='100%'>
	<tr><td colspan=2 align='left'><b style="font-size: 14px;">Details Of Receiver(Billed to)</b></td><td align='left' colspan=2><b style="font-size: 14px;">Details Of Consignee(Shipped to)</b></td></tr>
	<tr><td align='left'><b>Name    :</b></td><td ><b><? print $cus_row['supname']; ?></b></td><td align='left'><b>Name</b></td><td align='left'><? print $cus_row['supname']; ?></td></tr>
   	<tr><td align='left'><b>Address :</b></td><td align='left'><? echo $cus_row['addr1']; ?></td><td align='left'><b>Address</b></td><td align='left'><? echo $cus_row['addr1']; ?></td></tr>
	<tr><td align='left'><b>Pin No   :</b></td><td align='left' ><? echo $cus_row['pin1']; ?></td><td align='left'><b>Pin No</b></td><td align='left'><? echo $cus_row['pin1']; ?></td></tr>

	<tr><td align='left'><b>District   :</b></td><td align='left' ><? echo $cus_row['dist1']; ?></td><td align='left'><b>District</b></td><td align='left'><? echo $cus_row['dist1']; ?></td></tr>
	<tr><td align='left'><b>State   :</b></td><td align='left'><? echo $cus_row['state1']; ?></td><td align='left'><b>State  :</b></td><td align='left'><? echo $cus_row['state1']; ?></td></tr>
	<tr><td align='left'><b>PAN   :</b></td><td align='left'><? echo $cus_row['tin']; ?></td><td align='left'><b>PAN  :</b></td><td align='left'><? echo $cus_row['tin']; ?></td></tr>
	<tr><td align='left'><b>GSTIN/Unique ID</b></td><td align='left'><? echo $cus_row['gst']; ?></td><td align='left'><b>GSTIN/Unique ID</b></td><td align='left'><? echo $cus_row['gst']; ?></td></tr>
	</table>
	<table class='tbl' height='40' width='100%'>
<? $invdate=implode("-",array_reverse(explode("-",$res1['date']))); ?>

	<tr style="font-size: 13px;"><td  ><b>Terms of Delivery:</b></td><td ></td><td ><b></b></td><td ></td><td rowspan='3' style="border-left:1px solid black;border-collapse:collapse;border-style:dotted;width:0px"></td><td align=right><b>Invoice No : </b></td><td align=left><b><? echo $invno; ?></td><td align=right><b>Date:</b></td><td align=left><b><? echo $invdate; ?></td></tr>
	
	</table>
	<table class='tble'  border='1' FRAME=BOX BORDER=1 CELLPADDING=0 CELLSPACING=0 RULES=COLS width='100%'>
	<tr><th>SR.No<th>Account<th>HSN<th>Net Value<th>Taxable Amount<th>CGST %<th>CGST AMT<th>SGST %<th>SGST AMT<th>IGST %<th>IGST AMT<th>Grand Total</tr>
<?



$i=1;
	
	$result1=mysqli_query($db,"select * from gst_creditnote where refno='$invno' and brcode='$brcode'");
	while($row=mysqli_fetch_array($result1))
	{
        print "<tr><td width='5%'>".$i."</td><td width='20%'>".$row['expense_head']."  [ ".$row['narr']." ]"."</td><td align='right' width='10%px'>".$row['hsncode']."</td>
	<td align='right' width='10%'>".putcoma($row['before_tax'])."</td><td align='right' width='5%'>".putcoma($row['before_tax'])."</td>
	<td align='right' width='5%'>".$row['cgstp']."</td><td align='right' width='10%'>".$row['cgstamt']."</td><td align='right' width='10%'>".$row['sgstp']."</td>
	<td align='right' width='5%'>".$row['sgstamt']."</td><td align='right' width='5%'>".$row['igstp']."</td>
	<td align='right' width='5%'>".$row['igstamt']."</td><td align='right' width='10%'>".putcoma($row['expense_amount'])."</td></tr>";
	
	$cgst_tot+=$row['cgstamt'];
	$sgst_tot+=$row['sgstamt'];
	$igst_tot+=$row['igstamt'];
	$tot+=$row['expense_amount'];
	$amt+=$row['before_tax'];
	$i++;
	}
	 for($k=$i;$k<=25;$k++)
	{
	    print "<tr><td></td><td></td><td align='right' width='0'></td><td align='right' width='0'></td><td></td><td align='right' ></td>
        <td align='right' width='0'></td><td align='right' width='0'></td><td align='right' width='0'></td><td align='right' width='0'></td>
        <td align='right' width='0'></td><td align='right' width='0'></td></tr>";
	}
 
?>
    
	</table>

	<table  width=100% class='tbl1' id='tbl' border='1' style='height:50px;'>
	<tr><td align='left'  width='60%' ><b>Rupees  :  <?echo word(round($tot))?>  Only</b></td><td></td><td rowspan='2'>

           <table width='100%'  style='border:0px solid black;border-collapse:collapse;margin:0px' border=0 id='tot_tbl'>
    	     	<tr><td colspan=2 class='tot_td1' align=right>Accounts</td></tr>
 	   	<tr><td  align='right'> Total Amount Before GST</td><td width='92'><?if($p==$pg_no){ echo putcoma($amt);} ?></td></tr>
		<tr><td  align='right' height='10'>cgst Total</td><td ><? if($p==$pg_no){ echo $cgst_tot; }?></td></tr>
		<tr><td  align='right' height='10'>sgst Total</td><td ><? if($p==$pg_no){ echo $sgst_tot; }?></td></tr>
		<tr><td  align='right' height='10'>igst Total</td><td ><? if($p==$pg_no){ echo $igst_tot; }?></td></tr>          

	   <?
	   
	    $rnd=round($tot);
        $dif=round(($rnd-$tot),2);
        
	   ?>

	   	<tr><td align='right'>Round Off</td><td><? if($p==$pg_no){ echo putcoma($dif);} ?> </td></tr>
	   	
              
              <tr><td align='right' class='tot_td' style='font-size:12px'><b>Net Amount</td><td class='tot_td' style='font-size:12px'><b><? if($p==$pg_no){ echo putcoma(round($tot)); } ?></b></td></tr>
         

 </table>


	</td></tr>

	

	

	<tr><td colspan=2>
	<table border=0 style='border:0px solid white; ' width=100%><tr>
	<td style='border:0px solid white;text-align:left;text-transform:none;'>
	</td><td style='border:0px solid white; text-align:right;'> </td></tr>
	<tr><td style='border:0px solid white;text-align:left;text-transform:none;'></br>

			Authorised Signatory.</td><td style='border:0px solid white; text-align:right;'>
	</td></tr></table>


	</td>

	</tr></table>


