<?
session_start();
include("../opendb.php");
include("../test.php");

?>
<style>
th{font-size:13}
</style>
<style>
 td,body{font-family:'arial narrow';font-size:16;letter-spacing:1}
</style>

<?
$res1=mysqli_query($db,"select * from saleorder_spare where orderno='$orderno' and brcode='$brcode' order by partcode")or die('err'.mysqli_error());
$row1=mysqli_fetch_array($res1);
?>
<center>
<h3>
PSN CONSTRUCTION EQUIPMENTS PVT. LTD.,<?print $branch?> BRANCH
</H3>
<H4>
SALE ORDER - <?print $row1[orderno]?> </h4>


<table border=1 cellpadding=5 width=30%>
<tr><td>Customer </td><td><?print $row1[orderto]?></td></tr>
<tr><td>Date  </td><td><?print datetohtml($row1[date])?></td></tr>
<tr><td>MSNO</td><td><?print $row1[msno]?></td></tr>
</table>
<br>
<?
$tamt=0;
$tnet=0;
$res=mysqli_query($db,"select * from saleorder_spare where orderno='$orderno' and brcode='$brcode' order by partcode");
if(mysqli_num_rows($res)>0)
{
  $i=1;
 $t=0;
  print "<table border=1 cellpadding=5> <th>No <th>Location<th>Item Code <th>Item Name <th>Qty ";
 // print "<th>Rate<th>Amount <th>Tax <th>Cess <th>Net ";
  while($row=mysqli_fetch_array($res))
  {
    $locres=mysqli_query($db,"select location from sparelocmast where brcode='$brcode' and itemcode='$row[partcode]'");
    $locrow=mysqli_fetch_array($locres);
    print "\n<tr><td>";
    print $i++."</td><td>$locrow[0]</td><td>$row[0]</td><td>$row[1]</td><td align=right>$row[sqty]</td>";
  $rate=getPrice($row[0]);
  $amount=$rate*$row[sqty];
  $tamt+=$amount;
  $taxp=getTax($row[0]);
  $cessp=getCess($row[0]);
  $tax=$amount*$taxp/100;
  $cess=round($tax*$cessp/100,2);
  $net=$amount+$tax+$cess;
  $tnet+=$net;
 //   print "<td align=right>$rate</td><td align=right>".putComa($amount)."</td>";
 //   print "<td align=right>".putComa($tax)."</td>";
  //  print "<td align=right>".putComa($cess)."</td>";
 //   print "<td align=right>".putComa($net)."</td>";

    print "</tr>";
    $t+=$row[sqty];
  }
 print "<tr><td colspan=4 align=right>Total</td><td align=right>".putcoma($t)."</td>";
 //print "<td>&nbsp;</td><td align=right>".putcoma($tamt)."</td>";
// print "<td>&nbsp;</td><td>&nbsp;</td><td align=right>".putcoma($tnet)."</td>";

 print "</tr>";
 print "</table>";
}

function getPrice($code)
{
 $prres=mysqli_query($db,"select lstprice from spareprmast where partcode='$code' order by effectfrom desc")or die('err'.mysqli_error());
 $prrow=mysqli_fetch_array($prres);
 return $prrow[0];
}

function getTax($code)
{
 $prres1=mysqli_query($db,"select tax_sales from partmaster where partcode='$code' ")or die('err'.mysqli_error());
 $prrow=mysqli_fetch_array($prres1);
 return $prrow[0];
}

function getCess($code)
{
 $prres2=mysqli_query($db,"select cessonvat from partmaster where partcode='$code' ")or die('err'.mysqli_error());
 $prrow=mysqli_fetch_array($prres2);
 return $prrow[0];
}
?>
