<?php

$response = array();
$response["emp"] = array();
$response["present"]= array();
$response["leaves"]= array();
require_once __DIR__ . '/db_config.php';


if (isset($_POST["companyname"]) ) {
    
    $companyname = $_POST['companyname'];
    $date=$_POST['date'];

    $deleted="no";
    $con = mysqli_connect(DB_SERVER, DB_USER, DB_PASSWORD,DB_DATABASE) or die(mysql_error());
    
  
    $query="SELECT s.emailid,s.employeename,mobilenumber,designation,a.attendenceteam as attendanceteam,a.attendancesubgroup,a.attendancegroup  FROM signupdetails s LEFT JOIN attendanceuser a ON
a.emailid=s.emailid AND a.companyname=s.companyname WHERE s.companyname = '$companyname' and s.deleted='$deleted'";
    $result = mysqli_query($con,$query);

    if(!empty($result) && mysqli_num_rows($result) > 0){
	   $response["emp"] = mysqli_fetch_all($result,MYSQLI_ASSOC);
    }
    
    $query ="SELECT emailid,checkintime,checkouttime,checkinlocation,checkoutlocation FROM attendance WHERE  companyname = '$companyname' and date='$date'";
    $result = mysqli_query($con,$query);
    if(!empty($result) && mysqli_num_rows($result) > 0){
	   $response["present"] = mysqli_fetch_all($result,MYSQLI_ASSOC);
    }
    
    $query ="SELECT employeemailid,leavetype,leavefrom,leaveto,permissionfrom,permissionto,permissioninminutes,reasonforleaveorpermission as applyreason,status,rejectedreason FROM leavetable WHERE ( companyname = '$companyname' and deleted='$deleted' and ((leavefrom<='$date' and leaveto>='$date') OR permissiondate='$date'))";
    if(!empty($result) && mysqli_num_rows($result) > 0){
	   $response["leaves"] = mysqli_fetch_all($result,MYSQLI_ASSOC);
    }
    
    mysqli_close($con);
}
echo json_encode($response);

?>