<?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>Daily Sale Details Report</center> </strong>
                            </div>
                            <div class="card-body">
							<?php

include 'dbc.php';


$userid=$_SESSION["userid"];
$from_date=$_POST["from_date"];
$to_date=$_POST["to_date"];
$today=date("Y-m-d");
$class_name=$_POST["class_name"];


?>
<strong class="card-title"><center><? echo $class_name; ?></center> </strong>
                                <table id="bootstrap-data-table-export" class="table table-striped table-bordered">
                                    <thead>
									<?php
                                      echo "<tr>";
echo "<th > id </th>";
echo "<th > Discription </th>";
echo "<th > Sale Qty </th>";
echo "<th > Sale Rate </th>";
echo "<th > Cost Rate </th>";
echo "<th > Total Sale </th>";
echo "<th > Total Cost </th>";
echo "<th > Profit </th>";
echo "<th > Barcode </th>";
echo "</tr>";
$totalcost=0;
$totalsale = 0;
$totalnetqty=0;
   $totalprof = 0;
$sql = "SELECT * FROM items where type_name='$class_name' and user_id='$userid'";
$result=$conn->query($sql);
while($ppp = $result->fetch_assoc())
{
  $pname=$ppp["item_name"];
   $rfid=$ppp["rfid"];
  $id=$ppp["id"]; 
  $prate=$ppp["cost_price"]; 
  $srate=$ppp["retail_price"]; 
  $netqty =0;
$tcost = 0; 
$netqtysale =0;
$tsale=0;
$tsaleqty=0;
$tpureqty=0;
$tadjustqty=0;
$profdiff=0;
$tsaleqtyst=0;
 $sql1 = "SELECT * FROM invoice_details where item_name='$pname' and date between '$from_date' and '$to_date' and user_id='$userid'";
$result1=$conn->query($sql1);
while($row1 = $result1->fetch_assoc())
 
  {
 $tsaleqty=$tsaleqty + $row1['qty'];
 

  }

 $sql1st = "SELECT * FROM invoice_details_st where item_name='$pname' and date between '$from_date' and '$to_date' and user_id='$userid'";
$result1st=$conn->query($sql1st);
while($row1st = $result1st->fetch_assoc())
 
  {
 $tsaleqtyst=$tsaleqtyst + $row1st['qty'];
 

  }


$netqtysale = $tsaleqty + $tsaleqtyst;
$tcost = $netqtysale * $prate;
$tsale = $netqtysale * $srate;
$profdiff=$tsale - $tcost;
?>
                                    </thead>
									
                                    <tbody>
									<?php
 echo "<tr>";
   echo "<td width=10%>"  .$id . "</td>" ;
   echo "<td width=45%>"  .$pname . "</td>" ;
   
   echo "<td width=10%>"  .$tsaleqty . "</td>" ;
  
   
	echo "<td width=10%>"  .$srate . "</td>" ;
   echo "<td width=10%>"  .$prate . "</td>" ;
    echo "<td width=10%>"  .$tsale . "</td>" ;
    echo "<td width=10%>"  .$tcost . "</td>" ;
	 echo "<td width=10%>"  .$profdiff . "</td>" ;
	 echo "<td width=10%>"  .$rfid . "</td>" ;
	
   echo "</tr>";
  $totalcost = $totalcost + $tcost;
  $totalsale = $totalsale + $tsale;
   $totalprof = $totalprof + $profdiff;
   $totalnetqty = $totalnetqty + $tsaleqty;
    }
	
	echo "<tr>";
   echo "<td width=10% colspan=2 align=right>Total Qty</td>" ;
   
   echo "<td width=10% >"  .$totalnetqty . "</td>" ;
   echo "<td width=10% colspan=2 align=right>Total</td>" ;
    echo "<td width=10% >"  .$totalsale . "</td>" ;
	echo "<td width=10% >"  .$totalcost . "</td>" ;
	echo "<td width=10% >"  .$totalprof . "</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
}
?>