Fixed stats call + minor formatting

This commit is contained in:
Maximilian Giller 2021-07-26 22:57:39 +02:00
parent 18c4991c52
commit c17c6cfa02

View file

@ -465,7 +465,8 @@ function removeTagFromRecord($tag_id, $record_id)
$db->execute();
}
function getStats($user_id, $from_date, $until_date) {
function getStats($user_id, $from_date, $until_date)
{
$sum_duration = "SUM(ju_time_records.duration) AS duration";
$date = "DATE(ju_time_records.start_time) AS date";
$record_count = "COUNT(*) AS record_count";
@ -475,16 +476,18 @@ function getStats($user_id, $from_date, $until_date) {
$where3 = " ) AND ju_time_records.end_time IS NOT NULL ";
$db = new DbOperations();
$db->select("projects", ["name", "project_id", "color", "visible", $sum_duration, $date, $record_count], false);
$db->select("projects", ["ju_projects.name AS name", "ju_projects.project_id", "color", "visible", $sum_duration, $date, $record_count], false);
$db->innerJoin("time_records", "project_id");
// $db->innerJoin("tags_on_records", "record_id", "record_id", "time_records");
// $db->innerJoin("record_tags", "record_tag_id", "record_tag_id", "tags_on_records");
$db->where("user_id", Comparison::EQUAL, $user_id);
$db->where("ju_projects.user_id", Comparison::EQUAL, $user_id);
$db->addSql($where1);
$db->addValue($from_date);
$db->addSql($where2);
$db->addValue($until_date);
$db->addSql($where3);
$db->groupBy(["project_id", "date"]);
$db->groupBy(["ju_projects.project_id", "date"], false);
return $db->execute();
}