<?php

require_once __DIR__ . '/db_config.php';

$r = array();
$r["list"] = array();

if ( isset($_POST["companyname"]) && isset($_POST["date"]) ) {
    
    $companyname = $_POST['companyname'];
    $employeemailid = $_POST['employeemailid'];
    $date  = $_POST['date'];
    
    if(isset($_POST["date2"])){
        $date2=$_POST["date2"];
    }
        
        //$companyname = "Zkitchen";

    $con = mysqli_connect(DB_SERVER, DB_USER, DB_PASSWORD,DB_DATABASE) or die(mysql_error());

    // get a product from expense
    $query ="SELECT t.timesheetdate,t.attendenceteam,t.activity,t.starttime,t.endtime,s.employeename,f.sitename 
    FROM timesheet t
    INNER JOIN signupdetails s ON s.emailid=t.employeemailid
    LEFT JOIN atmdetails f ON f.atmid=t.facility_id
    WHERE  t.companyname = '$companyname' AND t.deleted = 'no'";
        
    if(!empty($date2)){
        $query = $query." AND t.timesheetdate BETWEEN $date AND $date2 ";
    }else{
        $query = $query." AND t.timesheetdate = '$date' ";
    }    
    
    $query = $query." ORDER BY t.Id ASC ";
    
    $result=mysqli_query($con,$query);
    if(!empty($result) && mysqli_num_rows($result) > 0){
        while ($row = mysqli_fetch_array($result,MYSQLI_ASSOC)) {
            array_push($r["list"], $row);
        }
    }
}
 // echo no users JSON
            echo json_encode($r);



?>