<!DOCTYPE html>
<?php //include '../includes/connection.php'; ?>
<html>
    
    <head>
        <?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';
$today=date('Y-m-d');
$dailydebtpayment=mysqli_query($con,"SELECT * from payment_logs where(NOT EXISTS (SELECT * from sales_details where order_id=payment_logs.order_id && branch_id='$branch' && business_id='$business' && date_format(date_time,'%Y-%m-%d')='$today')) && date_format(date_time,'%Y-%m-%d')='$today' && branch_id='$branch' && business_id='$business'");




                                  
                             // Create connection

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

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


                                   ?>
                                        <thead>
                                            <tr>
                                                <th>S/NO</th>
                                                
                                                    <th width="50%">
                                                    <table background="white" class="table table-bordered">
                                                    <td width="40%">Product</td>
                                                    <td width="20%">Quantity</td>
                                                    <td width="20%">Unit Price</td>
                                                    <td width="20%">Total Price</td>
                                                    
                                                    
                                                </table></th>
                                                <th  width="10%">Total </th>
                                                <th  width="10%">Paid Today</th>
                                                <th  width="10%">Total paid</th>
                                               
                                                
                                            </tr>
                                        </thead>
                                        <tbody id="fulldata">
                                        <?php
                                        $cou=0;
              while($row = mysqli_fetch_assoc($dailydebtpayment)) {
                $orderdid=$row['order_id'];
                $iddx=$row['order_id'];
                $sqld= mysqli_fetch_array(mysqli_query($con,"SELECT id, total_price, paid, (select count(id) from sales_details where order_id=sales.id)as count_orders, date_time, (select full_name from staff where staff_code=sales.staff)as staffname, (select name from users where id=(select distinct user_id from sales_details where order_id=sales.id))as usernames from sales where id='$iddx' && branch_id='$branch' && business_id='$business' "));
                       $cou++; 
                    ?>
                                            <tr class="odd gradeX">
                                                <td><?php echo $cou; echo $iddx ?></td>
                                                
                                                <td>
                                                    <?php include 'sales_details.php';  ?>
                                                </td>
                                                
                                                <td><?php echo $sqld['total_price']; ?></td>
                                                <td>
                                                <?php echo $row['amount_paid']; ?>
                                                    
                                                </td>
                                                <td>
                                                <?php echo $sqld['paid']; ?>
                                                    
                                                </td>
                                                
                                                
                                                
                                            </tr>
               <?php                             
    }
    if( $_SESSION['role']=="Super Admin"){
     $daily=mysqli_fetch_array(mysqli_query($con,"SELECT sum(amount_paid) as paid from payment_logs where(NOT EXISTS (SELECT * from sales where id=payment_logs.order_id && branch_id='$branch'  && date_format(date_time,'%Y-%m-%d')='$today')) && date_format(date_time,'%Y-%m-%d')='$today' && branch_id='$branch'"));   
    }else{
$daily=mysqli_fetch_array(mysqli_query($con,"SELECT sum(amount_paid) as paid from payment_logs where(NOT EXISTS (SELECT * from sales where id=payment_logs.order_id && branch_id='$branch'  && date_format(date_time,'%Y-%m-%d')='$today')) && date_format(date_time,'%Y-%m-%d')='$today' && branch_id='$branch'"));
    }
    
$totalpaid=$daily['paid'];
    ?><tr>
        <td colspan="3"><h4 style="text-align: center;">Previous Debts Paid Today</h4></td>
        <td><h4><?php echo number_format($totalpaid);?></h4></td>
        <td></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>