<?
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:5px;
padding-right:0px;
}
.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 veh_invoice where invno='$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 =  $trdrow[0].substr(("00000".$invno),-5);
        
        $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];
	$mcessp = $res1[cessp];
	$mcessamt = $res1[cessamt];
        if($res1[invtype]=='INTERSTATE')
        {
		    $tot=$res1[amt2];
        }
        else
        {
           $tot=$res1[amt2];
        }
        $r=mysqli_query($db,"select * from cust_master where code='$res1[cust]'")or die(mysqli_error());
        $cus_row=mysqli_fetch_array($r);
?>
	<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[gst]?></td></tr>
<?
 $invdate=implode("-",array_reverse(explode("-",$res1[invdate]))); 
if($invdate<"03-09-2018")
$addr="35/189, P Box No 2270 Palarivattom";
else
$addr=$brow[braddr];

?>
	   <tr><td colspan=6 align=center><b><?echo $addr?></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>
	<tr><td align='left'  id='add_td'></td><td align='right' ></td></tr></table> 
    <br>
	<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'>FORM GST</th></tr>
	    <tr><th  align='center' style='border:0px solid white;height:18px;font-size:12px;' id='head'>VEHICLE INVOICE</th></tr>
	    </table>
	<table  class='tbl' width='100%'>
<?if($res1[ship_to]>'')
{?>
	<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[custname]; ?></b></td><td align='left'><b>Name</b></td><td align='left'><? print $res1[ship_to]; ?></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 $res1[ship_addr]; ?></td></tr>
	<tr><td align='left'><b>Pin No   :</b></td><td align='left' ><? echo $cus_row[pin]; ?></td><td align='left'><b>Pin No</b></td><td align='left'><? echo $res1[ship_pin]; ?></td></tr>
	<tr><td align='left'><b>District   :</b></td><td align='left' ><? echo $cus_row[dist]; ?></td><td align='left'><b>District</b></td><td align='left'><? echo $res1[ship_dist]; ?></td></tr>
	<tr><td align='left'><b>State   :</b></td><td align='left'><? echo $cus_row['stat']; ?></td><td align='left'><b>State  :</b></td><td align='left'><? echo $res1[ship_state]; ?></td></tr>
	<tr><td align='left'><b>PAN   :</b></td><td align='left'><? echo $cus_row['kgst']; ?></td><td align='left'><b>PAN  :</b></td><td align='left'><? echo $res1[ship_pan]; ?></td></tr>
	<tr><td align='left'><b>GSTIN/Unique ID</b></td><td align='left'><? echo $cus_row['tin']; ?></td><td align='left'><b>GSTIN/Unique ID</b></td><td align='left'><? echo $res1[ship_gst]; ?></td></tr>
	</table>
<?}
else
{
?>
	<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[custname]; ?></b></td><td align='left'><b>Name</b></td><td align='left'><? print $cus_row[custname]; ?></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[pin]; ?></td><td align='left'><b>Pin No</b></td><td align='left'><? echo $cus_row[pin]; ?></td></tr>

	<tr><td align='left'><b>District   :</b></td><td align='left' ><? echo $cus_row[dist]; ?></td><td align='left'><b>District</b></td><td align='left'><? echo $cus_row[dist]; ?></td></tr>
	<tr><td align='left'><b>State   :</b></td><td align='left'><? echo $cus_row['stat']; ?></td><td align='left'><b>State  :</b></td><td align='left'><? echo $cus_row['stat']; ?></td></tr>
	<tr><td align='left'><b>PAN   :</b></td><td align='left'><? echo $cus_row['kgst']; ?></td><td align='left'><b>PAN  :</b></td><td align='left'><? echo $cus_row['kgst']; ?></td></tr>
	<tr><td align='left'><b>GSTIN/Unique ID</b></td><td align='left'><? echo $cus_row['tin']; ?></td><td align='left'><b>GSTIN/Unique ID</b></td><td align='left'><? echo $cus_row['tin']; ?></td></tr>
	</table>
<?}?>
	<table class='tbl' height='40' width='100%'>


	<tr style="font-size: 15px;"><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 ><b>Invoice No : </b></td><td><b><? echo $minno; ?></td><td ><b>Date:</b></td><td><b><? echo $invdate; ?></td></tr>
	<tr><td colspan='4' style="border-bottom:0px solid black;border-collapse:collapse;"></td><td ><b></b></td><td></td><td ><b></b></td><td></td></tr>
	</table>
	<table class='tbl' style=" font-size: 12px;" width='100%'>
	<tr><td ><b>Hypothicated to:<? echo $res1['fin']; ?> </b></td>
	<tr><td></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>Description Of Goods<th>HSN<th>Quantity<th>Amount
<?
$i=1;
if($res1[taxtype]=='INTRASTATE')
	$amt12 = round($tot+$sgstamt+$cgstamt+$mcessamt,2);
else
	$amt12 = round($tot+$igstamt+$mcessamt,2);


        print "<tr><td width='5%'>".$i."</td><td width='20%'>".$res1[config]."</td><td align='right' width='5%px'>".$res1[hsncode]."</td><td align='right' width='5%'>1</td><td width='10%' align='right'>".putcoma($tot)."<br><br></td>";
	print "<tr><td></td><td><b>Color : </b>".$res1[color]."</td><td></td><td></td><td><br><br></td>";
	print "<tr><td></td><td><b>Chassis No:</b>".$res1[chasis]."</td><td></td><td></td><td><br><br></td>";
	print "<tr><td></td><td><b>Engine No:</b>".$res1[engno]."</td><td></td><td></td><td><br><br></td>";
	print "<tr><td></td><td><b>EMLDA No:</b>".$res1['da']."</td><td></td><td></td><td><br><br></td>";
	print "<tr><td></td><td><b>Less Discount</td><td></td><td></td><td align='right'>".$disc."<br><br></td>";
	print "<tr><td><br><br><br><br><br></td><td></td><td></td><td></td><td></td></tr>";
/*	 <td align='right' width='5%'>".$disc."</td><td align='right' width='5%'>".putcoma($tot)."</td><td align='right' width='5%'>".putcoma($tot)."</td><td align='right' width='5%'>".$cgstp."</td>
	<td align='right' width='5%'>".$cgstamt."</td><td align='right' width='5%'>".$sgstp."</td><td align='right' width='5%'>".$sgstamt."</td>";
	if($mcessp>0)
		print "<td align='right' width='5%'>".$mcessp."</td><td align='right' width='5%'>".$mcessamt."</td>";
	else
		print "<td align='right' width='5%'>".$igstp."</td><td align='right' width='5%'>".$igstamt."</td>";
	print "<td align='right' width='10%'>".putcoma($amt12)."</td></tr>";
	 for($k=$i;$k<=17;$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><td align='right' width='0'></td><td align='right' width='0'></td>
        <td align='right' width='0'></td>";
	}*/
?>
    	</table>
	<table class='tble' id='tbl' border='0' style='height:50px;' width='100%'>
<?
	print "<tr><td></td><td width='40%'></td><td></td><td><b>Net Amount </td><td align='right'>".putcoma($tot)."</td>";
	print "<tr><td></td><td width='40%'></td><td></td><td><b>Tax Collected at Source (TCS @ 1%):</td><td align='right'>".putcoma($tcsamt)."</td>";
	print "<tr><td></td><td width='40%'></td><td></td><td><b>CGST (".$cgstp."%)</td><td align='right'>".putcoma($cgstamt)."</td>";
	print "<tr><td></td><td width='40%'></td><td></td><td><b>SGST (".$sgstp."%)</td><td align='right'>".putcoma($cgstamt)."</td>";

?>
	</table>
	<table class='tbl1' id='tbl' border='1' style='height:50px;' width='100%'>
	<?if($tcsper>0)
	{
	}
	else
	{
		$amt = $amt12;
	}
	?>
	<tr><td align='left'  ><b>Attended by Engineer:</b></td><td align='right' ><b>Grand Total  : &nbsp&nbsp&nbsp&nbsp <? echo putcoma(round($amt)); $amt=round($amt);?></b></td></tr>
	<tr><td colspan=2>
	<table  style='height:130px;'  width='100%'>
	<tr><td style='text-align:left;text-transform:none;'>Rupees  :  <?echo word($amt)?>  Only</td><td></td></tr>
	<tr><td style='text-align:left;text-transform:none;'  > We Confirm having received above mentioned goods in good condition.</br>CUSTOMER SIGNATURE.</td>
	<td style='text-align:right;'>For PSN AUTOMOBILES PVT LTD</td></tr>
	<tr></tr>
	<tr><td align=right></td><td align=right>AUTHORISED SIGNATORY</td></tr>
	</table>
	</td></tr></table>
  


