<?php
require "global.ajax.php";

switch ($_GET["op"]) {

	case 'ajaxLogsHistoryList':

		$ent_id = isset($_GET["ent_id"]) ? funCheckInput($_GET["ent_id"]) : "";
		$pos_id = isset($_GET["pos_id"]) ? funCheckInput($_GET["pos_id"]) : "";
		$dateFrom = isset($_GET["fromDate"]) ? funCheckInput($_GET["fromDate"]) : "";
		$dateTo = isset($_GET["toDate"]) ? funCheckInput($_GET["toDate"]) : "";

		$fromDate = date("{$dateFrom} 07:00:00");
		$toDate = date("Y-m-d", strtotime("{$dateTo} +1 day")) . " 06:59:59";

		$wherePos = "";
		if (!empty($pos_id)) $wherePos = "AND log_pos_id = {$pos_id}";

		$whereDate = "AND DATE_FORMAT(log_datetime, '%Y-%m-%d %H:%i:%s') BETWEEN '{$fromDate}' AND '{$toDate}'";

		$sql = "SELECT
		log_id
		,(SELECT pos_name FROM tb_pos WHERE pos_id = log_pos_id) AS pos_name
		,DATE_FORMAT(log_datetime, '%d-%b-%Y %H:%i:%s') AS log_datetime
		,log_description
		,log_ip
		,log_country
		FROM tb_logs
		WHERE log_ent_id = {$ent_id} $wherePos $whereDate ORDER BY log_id DESC;";

		// exit($sql);

		$result = executePDOFetchAllAPI($sql);
		echo json_encode($result);

		break;
}
