<?php
session_start();
if($_SESSION["username"]=="")
{
 	echo "You are not Logged in Please <a href='index.html'>Sign in </a> First ";
}
else
{


?>
<!doctype html>
<!--[if lt IE 7]>      <html class="no-js lt-ie9 lt-ie8 lt-ie7" lang=""> <![endif]-->
<!--[if IE 7]>         <html class="no-js lt-ie9 lt-ie8" lang=""> <![endif]-->
<!--[if IE 8]>         <html class="no-js lt-ie9" lang=""> <![endif]-->
<!--[if gt IE 8]><!-->
<html class="no-js" lang="en">
<!--<![endif]-->

<head>
   <?php include("includes/header.php") ?>
</head>

<body>


    <!-- Left Panel -->

   <!-- /#left-panel -->

    <!-- Left Panel -->

    <!-- Right Panel -->

    <div id="right-panel" class="right-panel">

        <!-- Header-->
        
        <!-- Header-->

        

        <div class="content mt-3">
            <div class="animated fadeIn">
                <div class="row">

                    <div class="col-md-14">
                        <div class="card">
						<div class="page-title">
                        <h2><center><? echo "" . $_SESSION["userid"]; ?></center></h2>
                    </div>
                            <div class="card-header">
							
                                <strong class="card-title"><center>Total Receivable Details Report</center> </strong>
                            </div>
                            <div class="card-body">
							<?php

include 'dbc.php';


$userid=$_SESSION["userid"];
$cname=$_POST["cname"];

?>
                                <table id="bootstrap-data-table-export" class="table table-striped table-bordered">
                                    <thead>
									<?php
                                       echo "<tr>";
echo "<th > Id </th>";

echo "<th > Vendor Name </th>";

echo "<th > Bal Amount </th>";
echo "</tr>";
?>
                                    </thead>
									
                                    <tbody>
									<?php
$sql1 = "select * from vendor where user_id='$userid'";
$result1=$conn->query($sql1);
while($ppp = $result1->fetch_assoc())
{
  $ven_name=$ppp["bname"];
  $id=$ppp["id"]; 
 
   $qtyret=0;
  $netqty =0;
$tcost = 0; 
$qtysale=0;
$qtypur=0;
$qtysalest=0;
$qtydr=0;
$qtycr=0;
  $sql2 = "select * from purchase where cname='$ven_name' and user_id='$userid'";
$result2=$conn->query($sql2);
while($ppp1 = $result2->fetch_assoc())
{
  $qtysale= $qtysale + $ppp1["netamount"];   
 } 
$sql3 = "select * from cashpaid where ven_name='$ven_name' and user_id='$userid'";
$result3=$conn->query($sql3);
while($ppp3 = $result3->fetch_assoc())
{
  $qtypur= $qtypur + $ppp3["netamount"];   
 } 
  $sqldr = "select * from vdebitnote where ven_name='$ven_name' and user_id='$userid'";
$resultdr=$conn->query($sqldr);
while($pppdr = $resultdr->fetch_assoc())
{
  $qtydr= $qtydr + $pppdr["netamount"];   
 } 
 
 $sqlcr = "select * from vcreditnote where ven_name='$ven_name' and user_id='$userid'";
$resultcr=$conn->query($sqlcr);
while($pppcr = $resultcr->fetch_assoc())
{
  $qtycr= $qtycr + $pppcr["netamount"];   
 } 
$netqty = ($qtysale + $qtycr) - ($qtypur + $qtydr);
 echo "<tr>";
   echo "<td width=10%>"  .$id . "</td>" ;
   echo "<td width=25%>"  .$ven_name . "</td>" ;
   echo "<td width=10%>"  .$netqty . "</td>" ;
  
   echo "</tr>";
  
    }
  ?>
                                       
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>


                </div>
            </div><!-- .animated -->
        </div> <!-- .content -->
    </div><!-- /#right-panel -->

    <!-- Right Panel -->

   <?php include("includes/footermenu.php") ?>

</body>

</html>
<?php
}
?>