<?php
session_start();
include 'dbc.php';

$userid=$_SESSION['userid'];

$inv_no=$_REQUEST["inv_no"];

  $sqlcus = "select * from invoice where id='$inv_no' and user_id='$userid'";
   $result=$conn->query($sqlcus);
$ppp = $result->fetch_assoc();
    $date=$ppp["date"];
	$pname=$ppp["pname"];
	$cell=$ppp["cell"];
	$netamount=$ppp["netamount"];
	$discount=$ppp["discount"];
	$gamount=$ppp["gamount"];
	$cashrec=$ppp["cashrec"];
	$balret=$ppp["balret"];
	$disc=$ppp["disc"];
	$dno=$ppp["dno"];
	$pno=$ppp["pno"];
	 $sqlcus1 = "select * from feenote";
   $result1=$conn->query($sqlcus1);
$ppp1 = $result1->fetch_assoc();
	 $notice=$ppp1["notice"];


 	    
		
echo "<table border=0 width=100% align=center bgcolor=white>";
echo "<tr>";

echo "<td bgcolor=white align=right colspan=2><font color=black size=6pt face=Arial>" . "Sales Invoice" . "</font></td>";
echo "</tr>";
echo "<tr>";
echo "<th bgcolor=white align=left colspan=5> <hr></th>";
echo "</tr>";
echo "<tr>";

echo "<td bgcolor=white align=left >" ."<img src='logo.jpg' />" . "</td>";
echo "<td bgcolor=white align=left colspan=5><font color=black size=2pt face=Arial>" . $userid. "<br>231- B2, Johar Town, Lahore 54000, Pakistan <br>Tel: 0304-4441302-01". "</font></td>";

echo "</tr>";
echo "<td align=left colspan=3></td>" ;
   echo "<td bgcolor=white align=left ><font color=black size=2pt face=Arial>" . "Sales Tax Registration :" . "</font></td>";
  echo "<td align=left ><font color=black size=2pt face=Arial>"  ."30037559974" . "</font></td>" ;
  echo "</tr>"; 
  echo "<tr>";
   echo "<td align=left colspan=3></td>" ;
   echo "<td bgcolor=white align=left ><font color=black size=2pt face=Arial>" . "National Tax Number : " . "</font></td>";
  echo "<td align=left ><font color=black size=2pt face=Arial>"  ."3755997-4" . "</font></td>" ;
  echo "</tr>"; 
echo "<tr>";

  echo "<td align=left colspan=3><font color=black size=3pt face=Arial>" ."To" . "<br>" .$ppp["cname"] . "</font></td>" ;
  
  echo "<td bgcolor=white align=left > <font color=black size=2pt face=Arial>" . "Invoice No" . "</font></td>";
  echo "<td align=left ><font color=black size=1pt face=Arial>"  .$ppp["id"] . "</font></td>" ;
  echo "</tr>"; 
  echo "<tr>";
   
  echo "<td align=left colspan=3><font color=black size=2pt face=Arial>"  .$pname . "</font></td>" ;
 echo "<td bgcolor=white align=left ><font color=black size=2pt face=Arial>"  . "Date" . "</font></td>";
  echo "<td align=left ><font color=black size=1pt face=Arial>"  .$ppp["date"] . "</font></td>" ;
 
  echo "</tr>"; 
   echo "<tr>";
  echo "<td align=left colspan=3><font color=black size=2pt face=Arial>"  .$cell . "</font></td>" ;
   echo "<td bgcolor=white align=left ><font color=black size=2pt face=Arial>" . "Delivery Person" . "</font></td>";
  echo "<td align=left ><font color=black size=2pt face=Arial>"  .$disc . "</font></td>" ;
  echo "</tr>"; 
 echo "<tr>";
   echo "<td align=left colspan=3></td>" ;
   echo "<td bgcolor=white align=left ><font color=black size=2pt face=Arial>" . "PO No" . "</font></td>";
  echo "<td align=left ><font color=black size=2pt face=Arial>"  .$pno . "</font></td>" ;
  echo "</tr>";
   echo "<tr>";
   echo "<td align=left colspan=3></td>" ;
   echo "<td bgcolor=white align=left ><font color=black size=2pt face=Arial>" . "DO No" . "</font></td>";
  echo "<td align=left ><font color=black size=2pt face=Arial>"  .$dno . "</font></td>" ;
  echo "</tr>";
   echo "<tr>";
   
 echo "</table>";
$sql1 = "select * from invoice_details where inv_no='$inv_no' and user_id='$userid'";
   $result1=$conn->query($sql1);
echo "<table border=1 style=border:solid black width=100% align=center bgcolor=white>";
 echo "<tr>";
 echo "<th bgcolor=white align=left style=border:solid black><font color=black size=2pt face=Arial> Sr# </font></th>";
  echo "<th bgcolor=white align=left style=border:solid black><font color=black size=2pt face=Arial> Item Name </font></th>";
 echo "<th bgcolor=white align=center style=border:solid black><font color=black size=2pt face=Arial> Unit Price </font></th>";
 echo "<th bgcolor=white align=center style=border:solid black><font color=black size=2pt face=Arial> Qty </font></th>";
 echo "<th bgcolor=white align=center style=border:solid black><font color=black size=2pt face=Arial> Amount </font></th>";

 
 echo "</tr>";
  $sno=1;
  while($row = $result1->fetch_assoc())

  {
   echo "<tr>";
  
	 echo "<td height=30><font color=black size=1pt face=Arial>" .$sno . "</font></td>";
	 echo "<td height=30><font color=black size=1pt face=Arial>" . $row['item_name']. "<br>" . $row['rfid']. "</font>  </td>";
	 echo "<td  height=30 align=center><font color=black size=1pt face=Arial>" .$row['srate'] . "</font></td>";
	 echo "<td height=30 align=center><font color=black size=1pt face=Arial>" .$row['qty'] . "</font></td>";
	 echo "<td  height=30 align=center><font color=black size=1pt face=Arial>" .$row['amount'] . "</font></td>";
	
		
		
  echo "</tr>";
 
  $sno=$sno + 1;
  $treceived=$treceived + $row['amount'];
  $tqty=$tqty + $row['qty'];
  
  }
  
echo "</table>";
echo "<table border=0 width=100% align=center bgcolor=white>";

 echo "<tr>";
 echo "<td align=left colspan=5></td>" ;
 echo "<th align=right bgcolor=white ><font color=black size=2pt face=Arial> Total Amount    :    </font>  </th>";

 echo "<th align=right ><font color=black size=2pt face=Arial>" .$netamount . "</font></th>" ;
 echo "</tr>";
  echo "<tr>";
  echo "<td align=left colspan=5></td>" ;
 echo "<th align=right bgcolor=white ><font color=black size=2pt face=Arial> Discount    :    </font>  </th>";
 echo "<th align=center ><font color=black size=2pt face=Arial>" .$discount . "</font></th>" ;
 echo "</tr>";
  echo "<tr>";
  echo "<td align=left colspan=5></td>" ;
 echo "<th align=right bgcolor=white ><font color=black size=2pt face=Arial> Net Amount    :     </font> </th>";
 echo "<th align=center ><font color=black size=2pt face=Arial>" .$gamount . "</font></th>" ;
 echo "</tr>";
  echo "<tr>";
  echo "<td align=left colspan=5></td>" ;
 echo "<th align=right bgcolor=white ><font color=black size=2pt face=Arial> Cash Received    :   </font>   </th>";
 echo "<th align=center ><font color=black size=2pt face=Arial>" .$cashrec . "</font></th>" ;
 echo "</tr>";
  echo "<tr>";
  echo "<td align=left colspan=5></td>" ;
 echo "<th align=right bgcolor=white > <font color=black size=2pt face=Arial>Balance     :   </font>   </th>";
 echo "<th align=center ><font color=black size=2pt face=Arial>" .$balret . "</font></th>" ;
 echo "</tr>";
 echo "<tr>";
 echo "</tr>";
 echo "<tr>";

 echo "</tr>";
  echo "<tr>";
 echo "<td align=left bgcolor=white  colspan=5><font color=black size=1pt face=Arial>" .$notice.     "</font></td>";
 echo "</tr>";
 echo "<tr>";
 echo "<td align=left bgcolor=white  colspan=5><font color=black size=3pt face=Arial>For:" .$userid.     "</font>
 </td>";
  echo "<td align=right bgcolor=white  colspan=5><font color=black size=3pt face=Arial>Received, Checked & Found OK<br>For & on belalf of Customer</font>
 </td>";
 echo "</tr>";
 echo "<tr>";
 echo "<td align=left bgcolor=white  colspan=5><font color=black size=3pt face=Arial>Authorised Signatures & Stamps</font></td>";
 echo "<td align=right bgcolor=white  colspan=5><font color=black size=3pt face=Arial>Authorised Signatures & Stamps</font></td>";
 echo "</tr>";
 echo "</table>";
 
	 
 
?>



