Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] timesheet entries that fall on midnight were not included #2497

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/Core/Middleware/RequestRateLimiter.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Leantime\Core\Frontcontroller;
use Leantime\Core\IncomingRequest;
use Leantime\Core\Middleware\Request;
use Leantime\Domain\Api\Services\Api;
use Symfony\Component\HttpFoundation\Response;

/**
Expand Down Expand Up @@ -55,7 +56,7 @@ public function handle(IncomingRequest $request, Closure $next): Response
//API Routes Limit
if ($request instanceof ApiRequest) {
$apiKey = "";
$key = app()->make(ApiRequest::class)->getAPIKeyUser($apiKey);
$key = app()->make(Api::class)->getAPIKeyUser($apiKey);
$limit = 10;
}

Expand Down
29 changes: 12 additions & 17 deletions app/Domain/Timesheets/Services/Timesheets.php
Original file line number Diff line number Diff line change
Expand Up @@ -316,16 +316,20 @@ public function getWeeklyTimesheets(int $projectId, CarbonInterface $fromDate, i
$currentWorkDate = dtHelper()->parseDbDateTime($timesheet['workDate']);

// Detect timezone offset

$workdateOffsetStart = ($currentWorkDate->setToUserTimezone()->secondsSinceMidnight() / 60 / 60);

// Various Entries can be in different timezones and thus would not be caught by upsert or grouping by
// default Creating new rows for each timezone adjustment
$timezonedTime = $currentWorkDate->format("H:i:s");

$groupKey = $timesheet["ticketId"] . "-" . $timesheet["kind"] . "-" . $timezonedTime;

if (!isset($timesheetGroups[$groupKey])) {
// Build an array of 7 days for the weekly timesheet. Include the start date of the current users
// timezone in UTC. That way we can compare the dates coming from the db
// timezone in UTC. That way we can compare the dates coming from the db and add the actual time entry
// to the correct date in our prepared line

$timesheetGroups[$groupKey] = array(
"kind" => $timesheet["kind"],
"clientName" => $timesheet["clientName"],
Expand Down Expand Up @@ -387,23 +391,15 @@ public function getWeeklyTimesheets(int $projectId, CarbonInterface $fromDate, i
);
}

// Check if timesheet entry falls within the day range of the weekly grouped timesheets that we are trying
// to pull up.
//
// Why would that be different you might ask?
//
// If a user adds time entries and then changes timezones (even just 1 hour) the values in the db
// will be different since it is based on start of the day 00:00:00 in the current users timezone and then
// stored as UTC timezone shoifted value in the db.
// If the value is not exact but falls within the time period we're adding a new row
//Take the date from the db and add the hours to the appropriate day in our week array
for ($i = 1; $i < 8; $i++) {
$start = $timesheetGroups[$groupKey]["day" . $i]["start"];
$end = $timesheetGroups[$groupKey]["day" . $i]["end"];
if ($currentWorkDate->gte($start) && $currentWorkDate->lte($end)) {
if ($timesheetGroups[$groupKey]["day" . $i]['actualWorkDate'] == $currentWorkDate) {

//It should be impossible for 2 entries in the db to have the same group key given the unique
// index on the date + ticketid + type.
// but just in case add up the hours. A save will merge the entries later.
$timesheetGroups[$groupKey]["day" . $i]['hours'] += $timesheet['hours'];
$timesheetGroups[$groupKey]["day" . $i]['actualWorkDate'] = $currentWorkDate;
$timesheetGroups[$groupKey]["day" . $i]['description'] = $timesheet['description'];

// No need to check further, we found what we came for
break;
}
Expand All @@ -412,8 +408,7 @@ public function getWeeklyTimesheets(int $projectId, CarbonInterface $fromDate, i
// Add to rowsum
$timesheetGroups[$groupKey]["rowSum"] += $timesheet['hours'];
}



return $timesheetGroups;
}

Expand Down
30 changes: 15 additions & 15 deletions public/dist/mix-manifest.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
{
"/js/compiled-htmx.3.1.2.min.js": "/js/compiled-htmx.3.1.2.min.js",
"/js/compiled-htmx-headSupport.3.1.2.min.js": "/js/compiled-htmx-headSupport.3.1.2.min.js",
"/css/main.3.1.2.min.css": "/css/main.3.1.2.min.css",
"/css/editor.3.1.2.min.css": "/css/editor.3.1.2.min.css",
"/css/app.3.1.2.min.css": "/css/app.3.1.2.min.css",
"/js/compiled-footer.3.1.2.min.js": "/js/compiled-footer.3.1.2.min.js",
"/js/compiled-app.3.1.2.min.js": "/js/compiled-app.3.1.2.min.js",
"/js/compiled-frameworks.3.1.2.min.js": "/js/compiled-frameworks.3.1.2.min.js",
"/js/compiled-framework-plugins.3.1.2.min.js": "/js/compiled-framework-plugins.3.1.2.min.js",
"/js/compiled-global-component.3.1.2.min.js": "/js/compiled-global-component.3.1.2.min.js",
"/js/compiled-calendar-component.3.1.2.min.js": "/js/compiled-calendar-component.3.1.2.min.js",
"/js/compiled-table-component.3.1.2.min.js": "/js/compiled-table-component.3.1.2.min.js",
"/js/compiled-editor-component.3.1.2.min.js": "/js/compiled-editor-component.3.1.2.min.js",
"/js/compiled-gantt-component.3.1.2.min.js": "/js/compiled-gantt-component.3.1.2.min.js",
"/js/compiled-chart-component.3.1.2.min.js": "/js/compiled-chart-component.3.1.2.min.js",
"/js/compiled-htmx.3.1.3.min.js": "/js/compiled-htmx.3.1.3.min.js",
"/js/compiled-htmx-headSupport.3.1.3.min.js": "/js/compiled-htmx-headSupport.3.1.3.min.js",
"/css/main.3.1.3.min.css": "/css/main.3.1.3.min.css",
"/css/editor.3.1.3.min.css": "/css/editor.3.1.3.min.css",
"/css/app.3.1.3.min.css": "/css/app.3.1.3.min.css",
"/js/compiled-footer.3.1.3.min.js": "/js/compiled-footer.3.1.3.min.js",
"/js/compiled-app.3.1.3.min.js": "/js/compiled-app.3.1.3.min.js",
"/js/compiled-frameworks.3.1.3.min.js": "/js/compiled-frameworks.3.1.3.min.js",
"/js/compiled-framework-plugins.3.1.3.min.js": "/js/compiled-framework-plugins.3.1.3.min.js",
"/js/compiled-global-component.3.1.3.min.js": "/js/compiled-global-component.3.1.3.min.js",
"/js/compiled-calendar-component.3.1.3.min.js": "/js/compiled-calendar-component.3.1.3.min.js",
"/js/compiled-table-component.3.1.3.min.js": "/js/compiled-table-component.3.1.3.min.js",
"/js/compiled-editor-component.3.1.3.min.js": "/js/compiled-editor-component.3.1.3.min.js",
"/js/compiled-gantt-component.3.1.3.min.js": "/js/compiled-gantt-component.3.1.3.min.js",
"/js/compiled-chart-component.3.1.3.min.js": "/js/compiled-chart-component.3.1.3.min.js",
"/images/03-1.png": "/images/03-1.png",
"/images/32px.png": "/images/32px.png",
"/images/40px.png": "/images/40px.png",
Expand Down
Loading