From 2e9db313fee6c5380ebe04e34567cc6c97485103 Mon Sep 17 00:00:00 2001 From: Marcel Folaron Date: Thu, 2 May 2024 10:45:00 -0400 Subject: [PATCH 1/2] [fix] timesheet entries that fall on midnight were not included --- app/Core/Middleware/RequestRateLimiter.php | 3 +- app/Domain/Timesheets/Services/Timesheets.php | 17 ++++++++++- public/dist/mix-manifest.json | 30 +++++++++---------- 3 files changed, 33 insertions(+), 17 deletions(-) diff --git a/app/Core/Middleware/RequestRateLimiter.php b/app/Core/Middleware/RequestRateLimiter.php index e475eafb0..f81c673e8 100644 --- a/app/Core/Middleware/RequestRateLimiter.php +++ b/app/Core/Middleware/RequestRateLimiter.php @@ -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; /** @@ -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; } diff --git a/app/Domain/Timesheets/Services/Timesheets.php b/app/Domain/Timesheets/Services/Timesheets.php index 47d32616f..379999830 100644 --- a/app/Domain/Timesheets/Services/Timesheets.php +++ b/app/Domain/Timesheets/Services/Timesheets.php @@ -396,7 +396,7 @@ public function getWeeklyTimesheets(int $projectId, CarbonInterface $fromDate, i // 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 - for ($i = 1; $i < 8; $i++) { + /*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)) { @@ -404,11 +404,26 @@ public function getWeeklyTimesheets(int $projectId, CarbonInterface $fromDate, i $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; + } + }*/ + + for ($i = 1; $i < 8; $i++) { + + if ($timesheetGroups[$groupKey]["day" . $i]['actualWorkDate'] == $currentWorkDate) { + + $timesheetGroups[$groupKey]["day" . $i]['hours'] += $timesheet['hours']; + $timesheetGroups[$groupKey]["day" . $i]['description'] = $timesheet['description']; + // No need to check further, we found what we came for break; } } + + + // Add to rowsum $timesheetGroups[$groupKey]["rowSum"] += $timesheet['hours']; } diff --git a/public/dist/mix-manifest.json b/public/dist/mix-manifest.json index 867c74e0c..7a09c8817 100644 --- a/public/dist/mix-manifest.json +++ b/public/dist/mix-manifest.json @@ -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", From 9f9adf0fd0a9d2fec41cc8bd02c4ce1eb62cd273 Mon Sep 17 00:00:00 2001 From: Marcel Folaron Date: Thu, 2 May 2024 10:54:29 -0400 Subject: [PATCH 2/2] clean up. --- app/Domain/Timesheets/Services/Timesheets.php | 40 +++++-------------- 1 file changed, 10 insertions(+), 30 deletions(-) diff --git a/app/Domain/Timesheets/Services/Timesheets.php b/app/Domain/Timesheets/Services/Timesheets.php index 379999830..c1147646f 100644 --- a/app/Domain/Timesheets/Services/Timesheets.php +++ b/app/Domain/Timesheets/Services/Timesheets.php @@ -316,6 +316,7 @@ 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 @@ -323,9 +324,12 @@ public function getWeeklyTimesheets(int $projectId, CarbonInterface $fromDate, i $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"], @@ -387,48 +391,24 @@ 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 - /*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)) { - $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; - } - }*/ - + //Take the date from the db and add the hours to the appropriate day in our week array for ($i = 1; $i < 8; $i++) { - 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]['description'] = $timesheet['description']; - // No need to check further, we found what we came for break; } } - - - // Add to rowsum $timesheetGroups[$groupKey]["rowSum"] += $timesheet['hours']; } - - + return $timesheetGroups; }