*/ if (isset($_REQUEST["city"]) === FALSE) { $city = "Bangalore"; } else { $city = $_REQUEST["city"]; } try { $connection = MysqlUtils::getConnection(); if ($period === "today") { $collected_business = EmployeeAnalytics::getBusinessIdCollectedToday($connection, $city, $email_id); } elseif ($period === "weekly") { $collected_business = EmployeeAnalytics::getBusinessIdCollectedThisWeek($connection, $city, $email_id); } elseif ($period === "monthly") { $collected_business = EmployeeAnalytics::getBusinessIdCollectedThisMonth($connection, $city, $email_id); } else { $collected_business = EmployeeAnalytics::getBusinessIdCollectedToday($connection, $city, $email_id); } $user_profile = UserProfile::getProfile($connection, $email_id); $user_collected_business = new UserCollectedBusiness($collected_business); $user_collected_business = $user_collected_business->get(); echo json_encode(array("status" => "success", "user_profile" => $user_profile, "count" => count($user_collected_business), "collected_business" => $user_collected_business)); } catch (DatabaseConnectionException $e) { $failure_json = array("status" => "error", "error" => "Database Unavailable"); echo json_encode($failure_json); return; } catch (QueryFailedException $e) { $failure_json = array("status" => "error", "error" => "Unable to get pending pincode requests"); echo json_encode($failure_json); return; } mysqli_close($connection);
if ($is_admin == TRUE) { $success_json = array("status" => "success"); echo json_encode($success_json); exit; } error_log('check ' . $json); $business_id = $json_data["business_id"]; $city = $json_data["city"]; $pincode = $json_data["pincode"]; $email_id = $json_data["email_id"]; $duration = $json_data["duration"]; $iso_date = new \DateTime($json_data["date"]); $date = $iso_date->format("Y-m-d"); $date_time = $iso_date->format("Y-m-d H:i:s"); try { $connection = MysqlUtils::getConnection(); $result = EmployeeAnalytics::recordTimeSpentOnABusiness($connection, $email_id, $business_id, $city, $date, $duration); $result = PincodeAnalytics::addNewBusiness($connection, $business_id, $pincode, $city, $date_time); $success_json = array("status" => "success"); echo json_encode($success_json); } catch (DatabaseConnectionException $e) { $failure_json = array("status" => "error", "error" => "Database Unavailable"); echo json_encode($failure_json); return; } catch (QueryFailedException $e) { error_log(mysqli_error($connection)); $failure_json = array("status" => "error", "error" => "Query execution failed"); echo json_encode($failure_json); return; } mysqli_close($connection);
$city = $_REQUEST["city"]; if (empty($city) === TRUE || empty($period) === TRUE) { $error_json = array("status" => "error", "error" => "Empty Input Parameters"); echo json_decode($error_json); return; } try { $connection = MysqlUtils::getConnection(); if ($period === "today") { $analytics = EmployeeAnalytics::getTodayAnalytics($connection, $city); } elseif ($period === "weekly") { $analytics = EmployeeAnalytics::getWeeklyAnalytics($connection, $city); } elseif ($period === "monthly") { $analytics = EmployeeAnalytics::getMonthlyAnalytics($connection, $city); } else { $analytics = EmployeeAnalytics::getTodayAnalytics($connection, $city); } //No business collected by any employee if (empty($analytics) === TRUE) { $output_json = array("status" => "success", "count" => 0, "date" => getFormattedDate($period), "total_business_collected" => 0); echo json_encode($output_json); return; } $total_business_collected = calculateTotalBusinessCollected($analytics); //Add formatted duration to each analytic record foreach ($analytics as $index => $analytic_data) { $duration = $analytic_data["duration"]; $analytic_data["formatted_duration"] = formatDuration($duration); $analytics[$index] = $analytic_data; } echo json_encode(array("status" => "success", "count" => count($analytics), "date" => getFormattedDate($period), "analytics" => $analytics, "total_business_collected" => $total_business_collected));