<!DOCTYPE html>
<?php include '../includes/connection.php'; ?>
<html>
    
    <head><meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <?php include("../includes/header-links.php");?>
       
        <!-- Bootstrap -->
        <link href="../bootstrap/css/bootstrap.min.css" rel="stylesheet" media="screen">
        <link href="../bootstrap/css/bootstrap-responsive.min.css" rel="stylesheet" media="screen">
        <link href="../assets/styles.css" rel="stylesheet" media="screen">
        <link href="../assets/DT_bootstrap.css" rel="stylesheet" media="screen">
        <link rel="stylesheet" href="../data-table-css/bootstrap-table.css">
    <link rel="stylesheet" href="../data-table-css/bootstrap-editable.css">
        <!--[if lte IE 8]><script language="javascript" type="text/javascript" src="vendors/flot/excanvas.min.js"></script><![endif]-->
        <!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
        <!--[if lt IE 9]>
            <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
        <![endif]-->
        <script src="../vendors/modernizr-2.6.2-respond-1.1.0.min.js"></script>
    </head>
    
    <body>
        <?php include '../includes/header.php'; ?>
        <div class="container-fluid">
            <div class="row-fluid">
                <?php include '../includes/sidebar.php'; ?>
                <!--/span-->
                <div class="span10" id="content">


                     <div class="row-fluid">
                        <!-- block -->
                        <div class="block">
                            <div class="navbar navbar-inner block-header">
                                <div class="muted pull-left">Sales Reports</div>
                                
                            </div>
                            <div class="block-content collapse in">
                             
                                    
                                    <table id="table" data-toggle="table" data-pagination="true" data-search="true" data-show-columns="true" data-show-pagination-switch="true" data-show-refresh="true" data-key-events="true" data-show-toggle="true" data-resizable="true" data-cookie="true"
                                        data-cookie-id-table="saveId" data-show-export="true" data-click-to-select="true" data-toolbar="#toolbar" data-export-options='{"fileName": "Testing_filename"}'>
<?php
include '../includes/connection.php';
$idsale=$_GET['id'];
$sale=mysqli_fetch_array(mysqli_query($con,"SELECT DATE_FORMAT(date_time,'%Y-%m-%d') as sdate from sales_details where id=$idsale"));
$today=$sale['sdate'];

if( $_SESSION['role']=="Super Admin"){ 
$sql= mysqli_query($con,"SELECT distinct product_id from sales_details where DATE_FORMAT(date_time,'%Y-%m-%d')='$today' && business_id='$business'");
}else{
$sql= mysqli_query($con,"SELECT distinct product_id from sales_details where DATE_FORMAT(date_time,'%Y-%m-%d')='$today' && branch_id='$branch'");

}

                                  
                
                                   // Create connection

//$result = +++($con, $sql);

if (mysqli_num_rows($sql) > 0) {
    // output data of each row
    


                                   ?>
                                        <thead>
                                        <tr><th colspan="4"><h3 style="text-align: center;">SALES MADE: <?php echo $today; ?>
                                        </h3></th></tr>
                                        <tr>
                                           <th>Product</th>
                                            <th>Quantity</th>
                                            <th>Price</th>
                                            <th>Total</th> 
                                        </tr>
                                            
                                            
                                        </thead>
                                        <tbody id="fulldata">
                                        <?php
                                        $cou=0;
              while($row = mysqli_fetch_assoc($sql)) {
                $product_id=$row['product_id'];
                $sql2= mysqli_query($con,"SELECT sum(quantity*selling_price) as tt, sum(quantity) as quantity,selling_price,(select product_name from products where id=sales_details.product_id) as product from sales_details where DATE_FORMAT(date_time,'%Y-%m-%d')='$today' && product_id='$product_id' ");
                $row2=mysqli_fetch_assoc($sql2);
                       $cou++; 
                    ?>

                    <tr>
                    <td><?php echo $row2['product']; ?></td>
                    <td><?php echo $row2['quantity']; ?></td>
                    <td><?php echo number_format($row2['selling_price']); ?></td>
                    <td><?php echo number_format($row2['tt']); ?></td>
                   
                    </tr>
               <?php                             
    }
    if( $_SESSION['role']=="Super Admin"){ 
    $daily=mysqli_fetch_array(mysqli_query($con,"SELECT sum(quantity*selling_price) as sold from sales_details where date_format(date_time,'%Y-%m-%d')='$today' && business_id='$business'"));
}else{
    $daily=mysqli_fetch_array(mysqli_query($con,"SELECT sum(quantity*selling_price) as sold from sales_details where date_format(date_time,'%Y-%m-%d')='$today' && branch_id='$branch'"));

}
$totalSales=$daily['sold'];

    ?><tr>
        <td colspan="3"><h4 style="text-align: center;">TOTAL SALES</h4></td>
        <td><h4><?php echo number_format($totalSales);?></h4></td>
    </tr>
    
    <?php
} else {
    echo "0 results".mysqli_error($con);
}

//mysqli_close($conn);
?>
                                            
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                        </div>
                        <!-- /block -->
                    </div>
                </div>
            </div>
            <hr>
            <?php include '../includes/footer.php'; ?>
        </div>
        <!--/.fluid-container-->

        <script src="../vendors/jquery-1.9.1.js"></script>
        <script src="../bootstrap/js/bootstrap.min.js"></script>
        <script src="../vendors/datatables/js/jquery.dataTables.min.js"></script>
        <script src="../data-table-js/bootstrap-table.js"></script>
    <script src="../data-table-js/tableExport.js"></script>
    <script src="../data-table-js/data-table-active.js"></script>
    <script src="../data-table-js/bootstrap-table-editable.js"></script>
    <script src="../data-table-js/bootstrap-editable.js"></script>
    <script src="../data-table-js/bootstrap-table-resizable.js"></script>
    <script src="../data-table-js/colResizable-1.5.source.js"></script>
    <script src="../data-table-js/bootstrap-table-export.js"></script>


        <script src="../assets/scripts.js"></script>
        <script src="../assets/DT_bootstrap.js"></script>
        <script>
        $(function() {
            
        });
        </script>
    </body>

</html>