<?php 
require 'db.php';
$data = json_decode(file_get_contents('php://input'), true);
 
// $shop_id = "8316293";
// $shop_code = "Ey3a8s7U79";

$shop_id = $data['shop_id'];
$shop_code = $data['shop_code'];

if($shop_id == '' || $shop_code == '')
{
	$returnArr = array("ResponseCode"=>"401","Result"=>"false","ResponseMsg"=>"Something Went wrong try again !");
}
else 
{ 
    $current_time = date("H:i");
    
    $sql_que = "SELECT
        shop_details.app_version,
        shop_details.latest_app_url,
        shop_details.expiry_date,
        shop_details.manager_mobile,
        shop_details.latitude,
        shop_details.longitude,
        shop_settings.shop_message,
        shop_settings.start_time,
        shop_settings.end_time,
        shop_settings.shop_status
        FROM shop_settings
        
        INNER JOIN shop_details ON
        shop_settings.shop_id = shop_details.shop_id
        
        WHERE
        shop_details.expiry_date >=CURRENT_TIMESTAMP and shop_settings.shop_id = '$shop_id' and shop_settings.shop_code = '$shop_code'";
    
    $sql_query = "SELECT
        shop_details.expiry_date,
        shop_details.manager_mobile,
        shop_details.latitude,
        shop_details.longitude,
        shop_settings.shop_message,
        shop_settings.start_time,
        shop_settings.end_time,
        shop_settings.shop_status
        FROM shop_settings
        
        INNER JOIN shop_details ON
        shop_settings.shop_id = shop_details.shop_id
        
        WHERE
        shop_details.expiry_date >=CURRENT_TIMESTAMP and TIME_TO_SEC(shop_settings.start_time) < TIME_TO_SEC('$current_time') 
        and TIME_TO_SEC(shop_settings.end_time) > TIME_TO_SEC('$current_time') 
        and shop_settings.shop_id = '$shop_id' and shop_settings.shop_code = '$shop_code'";
    
	$cur = $con->query($sql_que)->fetch_assoc();
	$curr = $con->query($sql_query)->fetch_assoc();
    
	$kp = array("Main_Data"=>$cur);
	if($curr != null)
	{
	    $returnArr = array("ResponseCode"=>"200","Result"=>"true","ResponseMsg"=>"Data Get Successfully!","ResultData"=>$kp);
	}
	else
	{
	    $returnArr = array("ResponseCode"=>"401","Result"=>"false","ResponseMsg"=>"No data","ResultData"=>$kp);
	}
	echo json_encode($returnArr);
}
?>