<?php
$dfrom=$_GET['dfrom'];
$dto=$_GET['dto'];

include '../includes/connection.php';
session_start();

$id_user=$_SESSION['id'];
$branch=$_SESSION['branch_id'];


                                   // Create connection
if(strlen($dfrom)>0 && strlen($dto)==0){
    if($_SESSION['branch_id'] == 0 && $_SESSION['business_id']!=0){   
    $sql= mysqli_query($con,"SELECT *,(SELECT branch_name from branches where branch_id=stock_values.branch_id) as branch_name from stock_values where business_id='$business' && DATE_FORMAT(date, '%Y-%m-%d')>='$dfrom'");                              
    }else{
     $sql= mysqli_query($con,"SELECT * from stock_values WHERE branch_id='$branch' && DATE_FORMAT(date, '%Y-%m-%d')>='$dfrom' ");   
    }
}else{
    if($_SESSION['branch_id'] == 0 && $_SESSION['business_id']!=0){   
    $sql= mysqli_query($con,"SELECT *,(SELECT branch_name from branches where branch_id=stock_values.branch_id) as branch_name from stock_values where business_id='$business' && DATE_FORMAT(date, '%Y-%m-%d')>='$dfrom' && DATE_FORMAT(date, '%Y-%m-%d')<='$dto'");                              
    }else{
     $sql= mysqli_query($con,"SELECT * from stock_values WHERE branch_id='$branch' && DATE_FORMAT(date, '%Y-%m-%d')='$dfrom' && DATE_FORMAT(date, '%Y-%m-%d')<='$dto' ");   
    }

}

                                        $n=0;
              while($row = mysqli_fetch_assoc($sql)) {
                
                       $n++; 
                    ?>
                                            <tr class="odd gradeX">
                                                <td><?php echo $n; ?></td>
                                                <?php
                                                    
                                                if($_SESSION['branch_id'] == 0 ){
                                                   ?>
                                                   <td><?php echo $row['branch_name']; ?></td>
                                                   <?php
                                                    } 
                                                   ?>
                                                <td><?php echo $row['date']; ?></td>
                                                <td><?php echo number_format($row['stock_value'],3,'.',', '); ?></td>

                                                <td><?php echo $row['recorded_on']; ?></
                                                
                                                
                                                
                                            </tr>
               <?php                             
    }






?>