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

include("../opendb.php");
include("../test.php");
$invno=$_REQUEST['invno'];
$result=mysqli_query($db,"select * from profinv where invno='$invno' and brcode='$brcode' ");
$row=mysqli_fetch_array($result);

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

?>
<style>
td,body{font-family:arial;background-color:white;font-size:12}
.first-txt {
            position: absolute;
            top: 917px;
            left: 300px;
        }
.second-txt {
            position: absolute;
            top: 947px;
            left: 300px;
        }        
.third-txt {
            position: absolute;
            top: 947px;
            left: 50px;
        }                
.fourth-txt {
            position: absolute;
            top: 900px;
            left: 410px;
        }                        
</style>
<table width=100%>
<tr><td align=center><span style={letter-spacing:5}><u>  </u></span></TD></TR>


<?
$brname=explode(',',$branch);
?>


</TABLE>


<center>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr><td colspan='3' valign='bottom' align='center' ><h2>PSN AUTOMOBILES PVT. LTD.</h1></td></tr>
    <tr><td width="20%" height="38" align='left'><img src="../images/logo.png" alt="PSN" width="148" height="81" /></td><td width="29%" valign='top' align=center><?print $brow['braddr']?> <?print $brow['brcity']?>
    <br>Email : sales@psnauto.in    Web: www.psnauto.in <br>GST NO : <?echo $brow['gst']?><br>CIN NO : U50300KL 1996PTC010842</td><td align=right width="20%" height="38"><img src="../images/eicherlogo.jpg" alt="PSN" width="182" height="51" /></td></tr>
    
    </table>

<TABLE width=100% border=0>
<tr><td width=600 align=left>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Proforma No : <font size='2'><b> <?print $invno?></b></font></td><td width=1500 align=right >Date : <?print datetohtml($row['invdate'])?></td><td width=150></td>
</table>
</center>


<table><tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;To:</td>
<?if($invno==1323){?>

<td colspan='4'>Permanent Address</td></td></tr><tr><td valign='top'>
&nbsp;&nbsp;&nbsp;<blockquote>
    
Registration Address: <br>The Managing Partner, M/S National Trades and Agencies , 833 A, CSEZ ROAD, NEAR DOORDARSAN KENDRA, KAKKANAD, Ernakulam, Kerala, 682037<br>
GSTIN :32AABFN9977G1ZZ</blockquote>
</td><td align='right'></td><td>
The Managing Partner, M/S National Trades and Agencies, NTA Chambers, Hina House, Willingdon Island, Kochi, Ernakulam
</td></td>

<?}else{?>
<?if($invno==1255 || $invno==1256){print "<td colspan='4'>Ship to (Registration Address)</td>";?></td><?}?>
</tr><tr><td valign='top'>
&nbsp;&nbsp;&nbsp;<blockquote>
<? print $row['cust'].'<br>'.str_replace('-','<br>',$row['addr']);
print "<br>GSTIN :".$row['type'];?></blockquote>
</td><td align='right'></td><td>

<?if($invno==1255 || $invno==1256){print "<td>Mr. K. S Kumar
    S/O A. Kuttappan Valutharayil House, Karanma Vallikunnam Post Alappuzha 690501</td>";?></td><?}?>
<?}?>
</tr></table>
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Hypothicated to : <?print $row['fin']?>
<center>
<TABLE width=85% border=1 >
<tr><td  align=center>&nbsp;&nbsp;&nbsp;&nbsp;<B>PROFORMA INVOICE</B> </td></TR>
</table>
</center>
<?
if($brcode=='PSN314')
{
    ?>
<TABLE align = center CELLSPACING=1 CELLPADDING=1 BGCOLOR=BLACK width=85% border=1>
<tr align=center><td>SL<br>No.</td><td>Description </td>
<td>Unit Price </td><td>Qty</td><td> Total</td></tr>
<?
$sgstp=$row['taxp']/2;
$cgstp=$row['taxp']/2;
$sgstamt=$row['tax']/2;
$cgstamt=$row['tax']/2;
$tcsaa=round($row['tcs']);
$fcessamt=$row['amt2']*$row['cessp']/100;
$fcessamt=number_format($fcessamt, 2, '.', '');
?>
<tr valign=top><td>1</td><td align=left><?print $row['config']?></td>
<td align=right><?print putcoma($row['unit'])?></td><td align=right><?print $row['qty']?></td>

<td  align=right><?print putcoma(($row['unit']*$row['qty']))?></tr>

<tr valign=top><td>2</td><td align=left>Discount</td>
<td align=right><?print putcoma($row['disc'])?></td><td align=right><?print $row['qty']?></td>

<td  align=right><?print putcoma(($row['disc']*$row['qty']))?></tr>

<tr valign=top><td>3</td><td align=left>Price After Discount</td>
<td align=right><?print putcoma($row['netamt'])?></td><td align=right><?print $row['qty']?></td>

<td  align=right><?print putcoma(($row['netamt']*$row['qty']))?></tr>

<tr valign=top><td>4</td><td align=left>TCS 1%</td>
<td align=right><?print putcoma($tcsaa)?></td><td align=right><?print $row['qty']?></td><td align=right><?print putcoma(($tcsaa*$row['qty']))?></tr>

<tr valign=top><td>5</td><td align=left>Net Vehicle Price</td>
<td align=right><?print putcoma($row['netamt']+$tcsaa)?></td><td align=right><?print $row['qty']?></td><td align=right><?print putcoma((($row['netamt']+$tcsaa)*$row['qty']))?></tr>

<tr valign=top><td>6</td><td align=left> Insurance (<?print $row['insutype']?>) 						
</td>
<td align=right><?print $row['insurenceamt']?></td><td align=right><?print $row['qty']?></td><td align=right><?print putcoma(($row['insurenceamt']*$row['qty']))?></tr>

<tr valign=top><td>7</td><td align=left> RTO (Quaterly/Yearly Tax)</td>
<td align=right><?print $row['regis_permit_amt']?></td><td align=right><?print $row['qty']?></td><td align=right><?print putcoma(($row['regis_permit_amt']*$row['qty']))?></tr>
<tr valign=top><td>8</td><td align=left> TR & Fastag </td>
<td align=right><?print $row['fastag']?></td><td align=right><?print $row['qty']?></td><td align=right><?print putcoma(($row['fastag']*$row['qty']))?></tr>

<?
$gtt=$row['netamt']+$tcsaa+$row['insurenceamt']+$row['regis_permit_amt']+$row['fastag']+$row['extwty']+$row['amc']+$row['others'];

$gtt1=$gtt*$row['qty'];
?>
<tr valign=top><td>9</td><td align=left> Extended Warranty </td>
<td align=right><?print $row['extwty']?></td><td align=right><?print $row['qty']?></td><td align=right><?print putcoma(($row['extwty']*$row['qty']))?></tr>

<tr valign=top><td>10</td><td align=left> AMC </td>
<td align=right><?print $row['amc']?></td><td align=right><?print $row['qty']?></td><td align=right><?print putcoma(($row['amc']*$row['qty']))?></tr>

<tr valign=top><td>11</td><td align=left> Others </td>
<td align=right><?print $row['others']?></td><td align=right><?print $row['qty']?></td><td align=right><?print putcoma(($row['others']*$row['qty']))?></tr>

<tr valign=top><td>12</td><td align=left> GRAND TOTAL </td>
<td align=right><?print $gtt?></td><td align=right><?print $row['qty']?></td><td align=right><?print putcoma(($gtt*$row['qty']))?></tr>

						




</tr>
</table>
<?
}
else
{
?>

<TABLE align = center CELLSPACING=1 CELLPADDING=1 BGCOLOR=BLACK width=90% border=1>
<?if($invno==3281111)
{?>
    <tr align=center><td>SL<br>No.</td><td>Description </td>
    <td>Unit Price </td><td>Qty</td><td>Gross Value</td><td>Disc / unit</td><td>Basic Price</td><td>IGST%</td><td>IGST Amt</td>
    <td>Grand Total</td></tr>
<?}
else{?>
    <tr align=center><td>SL<br>No.</td><td>Description </td>
    <td>Unit Price </td><td>Qty</td><td>Gross Value</td><td>Disc / unit</td><td>Basic Price</td><td>CGST%</td><td>CGST Amt</td><td>SGST%</td><td>SGST Amt</td><?
    if($row['cessamt']>0)
    {?>
        <td>Cess</td>
    <?}?>
<td>Grand Total</td></tr>
<?}?>
<tr valign=top><td>1</td><td><?print $row['config']?></td>
<td align=right><?print $row['unit']?></td><td align=right><?print $row['qty']?></td>
<td align=right><?print $row['unit']*$row['qty']?></td><td align='right'><?print $row['disc']?></td>
<?$cgstper = $row['taxp']/2;?>


<?if($invno==3281111){
    $net = $row['unit']-$row['disc'];?>
    <td align=right><?print $net?></td>
    <td align='right'><?print '0%'?></td>
    <?$cgstamt = 0;?>
    <td align=right><?print $cgstamt?></td>
    <td align=right><?print round($net,0)?></td><br><br></td></tr>
<?
}
else
{?>
<td align=right><?print $row['amt2']?></td>
<td align='right'><?print $cgstper.'%'?></td>
    <?$cgstamt = round($row['amt2']*($row['taxp']/2/100),2);?>
    <td align=right><?print $cgstamt?></td><td align='right'><?print $cgstper.'%'?></td><td align=right><?print $cgstamt?></td>
    <?if($row['cessamt']>0)
    {
    ?>
        <td align=right><?print $row['cessamt']?></td>
    <?}
    $net = $row['amt2']+$row['tax']+$row['cessamt']
    ?>
    <td align=right><?print round($net,0)?></td></td></tr>
<?    
}
$tcsamt=($row['amt2']+$row['tax']+$row['cessamt'])*$row['tcsamt']/100;
$tcsamt=number_format($tcsamt, 2, '.', '');
$tcsamt=round($tcsamt);
$netamount=round($net+$tcsamt,0);


$tcsamt=number_format($tcsamt, 2, '.', '');
if($tcsamt>0)
{
    if($row['cessamt']>0)
    {?>
        <tr><td>&nbsp;</td><td colspan=11 align=center>Tax Collected at Source (TCS) @<?print $row['tcsamt'];?>%</TD>        
    <?}
    else
    {
        if($invno==3281111){?>
    
            <tr><td colspan=9 align=center>Tax Collected at Source (TCS) @<?print $row['tcsamt'];?>% </TD>
            <?}else{?>
            <tr><td>&nbsp;</td><td colspan=10 align=center>Tax Collected at Source (TCS) @<?print $row['tcsamt'];?>%</TD>
    <?}}?>
    
    <td align=right><?print $tcsamt ?></td>
    </tr>
    <?
}
if($invno==3281111){?>
    <tr><td>&nbsp;</td><td>T O T A L</TD><td>&nbsp;</td><td>&nbsp;</td>
<td align=right><?print $row['unit']*$row['qty']?></td><td align='right'><?print $row['disc']?></td><td align=right><?print $net?><td align=right><?print $cgstamt?></td>
<td align=right><?print $cgstamt?></td>
<?if($row['cessamt']>0)
{
?>
    <td align=right><?print $row['cessamt']?></td>
<?}?>
<td align=right><font size=3><?print round($netamount,0) ?></td>
</tr><?}else{?>
<tr><td>&nbsp;</td><td>T O T A L</TD><td>&nbsp;</td><td>&nbsp;</td>
<td align=right><?print $row['unit']*$row['qty']?></td><td align='right'><?print $row['disc']?></td><td align=right><?print $row['amt2']?><td></td><td align=right><?print $cgstamt?></td><td></td>
<td align=right><?print $cgstamt?></td>
<?if($row['cessamt']>0)
{
?>
    <td align=right><?print $row['cessamt']?></td>
<?}?>
<td align=right><font size=3><?print round($netamount,0) ?></td>
</tr>
<?}?>
</table>


<?
$gtot=$netamount+$row['regis_permit_amt']+$row['insurenceamt']+$row['speedgvr'];
?>

<table width=100% cellspacing=4 border=0>
<?if($invno==3281111){?>   
    <tr><td align='center' colspan=8>IGST exempted under section 16(1) of IGST Act 2017</td></tr><?}?>
<tr><td>GVW :</td><td><b><? print $row['gvw'] ?></b></td><td>Insurance charges :</td><td><b><? print $row['insurenceamt'] ?></b></td><td width=160></td></tr>
<tr><td>Wheel Base :</td><td><b><? print $row['wheel'] ?></b></td><td></td><td></td><td width=160></td></tr>
<tr><td>Tyre size :</td><td><b><? print $row['tyre'] ?></b></td><td>
<? if($invno==28 || $invno ==29 || $invno ==116 || $invno == 145 || $invno== 152 || $invno== 153 || $invno== 157 || $invno== 158 || $invno== 159 || $invno== 163 || $invno== 166 || $invno== 167 || $invno== 216 || $row['segment']=='BUS'|| $invno =='326'){?>
    GPS,Registration<?}
    else if($invno== 1831){?>
    AMC 1 year or 50,000 Km
    <?}else{?>
    Tax,Registration
<?}?>
    <br> and Other expenses :</td><td><b><? print $row['regis_permit_amt'] ?></b></td><td width=160></td><td><b>Total</b></td><td><font size='3'><b><? print $gtot ?></font></td></tr>
<?//<tr><td></td><td><b></b></td><td colspan=4 align='right'><b>Cost for FASTAG (will be extra)</td><td><font size='3'><b><? if($row[fastag]>0){ print $row[fastag].'/Veh.';}else { print '&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp/Veh'; }?></font></td></tr>

</table>
<?
}
$brname=explode(',',$branch);
?>
<?
if($brcode!='Aut14111')
{
print "<table width=95%  cellspacing=1 border=0>";
print "<tr><td></td><td width='10%'><b>Remarks:</td><td>$row[remark]</b></td></tr>
<tr><td></td><td width='10%'><b>Warranty:</td><td>$row[warranty]</b></td>
</table>
<table width=95%  cellspacing=1 border=0>
<tr><td colspan='2'>&nbsp;&nbsp;Terms and Conditions	</td></tr><tr>
<tr><td width='5%'>1.</td><td> The Full payment in advance by Electronic transfer to our Bank A/c no.30728155988 of SBI,SSI Branch Ernakulam (IFSC Code.SBIN0005387) or crossed Bank draft in favour of , A/c No. 30728155988 payable at Ernakulam.</td></tr>
<tr><td width='5%'>2.</td><td> Prices prevailing at the date of delivery will be applicable.</td></tr>
<tr><td width='5%'>3.</td><td> The delivery of the vehicle will be effected within two weeks from the date of receipt of full payment for standard configuration. For builtups and non standard configurations, delivery will be effected in 4 to 6 weeks from the date of receipt of full payment.</td></tr>
<tr><td width='5%'>4.</td><td> Arranging finance for new vehicle will be the sole responsibility of the customer.</td></tr>
<tr><td>5.</td><td> Advance payment will be refunded only after deducting Rs5000/- as Cancellation Charge, if the order is cancelled by the customer.</td></tr>
<tr><td width='5%'>6.</td><td> In case of cancellation, cancellation request letter has to be forwarded along with the original order booking form and original receipt. Refund will be made with in one month with out any interest</td></tr>
<tr><td width='5%'>7.</td><td> In the case of exchange deal, Exchange price will be as per terms & conditions mentioned in the exchange vehicle agreement signed by customer and exchange vehicle in charge of the company.</td></tr>
<tr><td>8.</td><td> Price allowed for exchanging old vehicle will be valid only if customer takes delivery of new vehicle from PSN.</td></tr>
<tr><td width='5%'>9.</td><td> Vehicle once sold will not be taken back.</td></tr>
<tr><td width='5%'>10.</td><td> Subject to Force Majeure clause</td></tr>
<tr><td width='5%'>11.</td><td> Subject to jurisdiction of Courts at Ernakulam.</td></tr>
<tr><td width='5%'>12.</td><td> The customer shall not be entitled to transfer the booking effected into the name of any other person and the vehicle. would be delivered, and invoiced only in the Name &Address of the person specified in the Delivery Order of the Financier.</td></tr>
<tr><td width='5%'>13.</td><td> For registering vehicles under Company name, D&O license issued by the local Government body is required and kindly submit the same during registration process.</td></tr>
</table>

&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;</font></td></tr>";
$mflg = 0;
$mconfig = strtoupper($row['config']);
if (strpos($mconfig, '2049 ')>0 || strpos($mconfig, '2050 ')>0 || strpos($mconfig, '2059 ')>0 || strpos($mconfig, '2075 ')>0 || strpos($mconfig, '2080 ')>0 || strpos($mconfig, '2095 ')>0 || strpos($mconfig, '2110 ')>0 || strpos($mconfig, '2114 ')>0 || strpos($mconfig, '3015 ')>0)
{
    $mflg = 1;
}

print "<tr><td>
.&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;
</font><font size=2><b> </b></FONT><img class='fourth-txt' src='../images/sealblr.jpg'  width=80 height=80 ><img class='first-txt' src='../images/blrsign.jpg'  width=82 height=51 >";
if($brcode=='AUT103' &&  $mflg==1)
{?> 
    <td><img src="pro2049.png" alt="PSN" width="152" height="91" /></td>
<?}

print "<h4 class='second-txt'>
            Authorised Signatory
        </h4>";
print "<h4 class='third-txt'>
            PSN AUTOMOBILES PVT LTD
        </h4>";
//print"<tr><td colspan=> &nbsp;&nbsp;Authorised Signatory  ";
print"<tr><td> </td></tr>";
}


?>


