Skip to content

Commit d49082d

Browse files
committed
Fixed localization in PDF reports
1 parent cc88f03 commit d49082d

File tree

4 files changed

+20
-40
lines changed

4 files changed

+20
-40
lines changed

app/Service/LocalizationService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public function formatInterval(CarbonInterval $interval): string
8080
if ($this->intervalFormat === IntervalFormat::Decimal) {
8181
$interval->cascade();
8282

83-
return $this->formatNumber($interval->totalHours);
83+
return $this->formatNumber($interval->totalHours).' h';
8484
} elseif ($this->intervalFormat === IntervalFormat::HoursMinutes) {
8585
$interval->cascade();
8686

resources/views/reports/time-entry-aggregate/pdf.blade.php

Lines changed: 15 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
@use('Brick\Math\BigDecimal')
22
@use('Brick\Money\Money')
3-
@use('PhpOffice\PhpSpreadsheet\Cell\DataType')
3+
@use('Illuminate\Support\Carbon')
44
@use('Carbon\CarbonInterval')
55
@inject('colorService', 'App\Service\ColorService')
66
<!DOCTYPE html>
77
<html lang="en">
88
<head>
9-
<meta charset="utf-8" />
9+
<meta charset="utf-8"/>
1010
<title>Report</title>
1111
<style>
1212
html, body, div, span, applet, object, iframe,
@@ -130,7 +130,7 @@
130130

131131
@if($debug)
132132
<link rel="preconnect" href="https://fonts.bunny.net">
133-
<link href="https://fonts.bunny.net/css?family=outfit:200,300,400,500,600,700,800" rel="stylesheet" />
133+
<link href="https://fonts.bunny.net/css?family=outfit:200,300,400,500,600,700,800" rel="stylesheet"/>
134134
@endif
135135

136136
</head>
@@ -356,7 +356,12 @@
356356
animation: false,
357357
tooltip: {},
358358
xAxis: {
359-
data: ['{!! collect($dataHistoryChart['grouped_data'])->pluck('key')->implode("', '") !!}'],
359+
data: {!!
360+
json_encode(collect($dataHistoryChart['grouped_data'])
361+
->pluck('key')
362+
->map(fn($value) => $localization->formatDate(Carbon::parse($value)))
363+
->toArray())
364+
!!},
360365
axisLabel: {
361366
fontSize: 10,
362367
fontWeight: 400,
@@ -381,26 +386,16 @@
381386
axisLabel: {
382387
show: false,
383388
inside: true,
384-
formatter: function(value, index) {
385-
let totalSeconds = value;
386-
let hours = Math.floor(totalSeconds / 3600);
387-
if (hours < 10) {
388-
hours = "0" + hours;
389-
}
390-
totalSeconds %= 3600;
391-
let minutes = Math.floor(totalSeconds / 60);
392-
if (minutes < 10) {
393-
minutes = "0" + minutes;
394-
}
395-
return hours + ":" + minutes;
396-
}
397389
}
398390
},
399391
series: [
400392
{
401393
name: "time",
402394
type: "bar",
403-
data: [{!! collect($dataHistoryChart['grouped_data'])->pluck('seconds')->implode(', ') !!}],
395+
data: {!! json_encode(collect($dataHistoryChart['grouped_data'])->map(fn($value) => (object) [
396+
'value' => $value['seconds'],
397+
'name' => ((int) $value['seconds']) === 0 ? '' : $localization->formatInterval(CarbonInterval::seconds((int) $value['seconds']))
398+
])->toArray()) !!},
404399
itemStyle: {
405400
borderColor: "#7dd3fc",
406401
color: "#7dd3fc"
@@ -413,22 +408,8 @@
413408
@endif
414409
fontSize: 10,
415410
position: "top",
416-
formatter: function(params) {
417-
let value = params.value;
418-
if (value === 0) {
419-
return "";
420-
}
421-
let totalSeconds = value;
422-
let hours = Math.floor(totalSeconds / 3600);
423-
if (hours < 10) {
424-
hours = "0" + hours;
425-
}
426-
totalSeconds %= 3600;
427-
let minutes = Math.floor(totalSeconds / 60);
428-
if (minutes < 10) {
429-
minutes = "0" + minutes;
430-
}
431-
return hours + ":" + minutes;
411+
formatter: function (params) {
412+
return params.name;
432413
}
433414
}
434415
}

resources/views/reports/time-entry-index/pdf.blade.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
@use('Brick\Math\BigDecimal')
22
@use('Brick\Money\Money')
3-
@use('PhpOffice\PhpSpreadsheet\Cell\DataType')
43
@use('Carbon\CarbonInterval')
54
@inject('interval', 'App\Service\IntervalService')
65
<!DOCTYPE html>

tests/Unit/Service/LocalizationServiceTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function test_format_interval_with_type_decimal_and_number_format_thousan
4747
$formatted = $this->localizationService->formatInterval($interval);
4848

4949
// Assert
50-
$this->assertSame('30,001.05', $formatted);
50+
$this->assertSame('30,001.05 h', $formatted);
5151
}
5252

5353
public function test_format_interval_with_type_decimal_and_number_format_thousands_space_decimal_point(): void
@@ -61,7 +61,7 @@ public function test_format_interval_with_type_decimal_and_number_format_thousan
6161
$formatted = $this->localizationService->formatInterval($interval);
6262

6363
// Assert
64-
$this->assertSame('30 001.05', $formatted);
64+
$this->assertSame('30 001.05 h', $formatted);
6565
}
6666

6767
public function test_format_interval_with_type_decimal_and_number_format_thousands_point_decimal_comma(): void
@@ -75,7 +75,7 @@ public function test_format_interval_with_type_decimal_and_number_format_thousan
7575
$formatted = $this->localizationService->formatInterval($interval);
7676

7777
// Assert
78-
$this->assertSame('30.001,05', $formatted);
78+
$this->assertSame('30.001,05 h', $formatted);
7979
}
8080

8181
public function test_format_interval_with_type_decimal_and_number_format_thousands_apostrophe_decimal_point(): void
@@ -89,7 +89,7 @@ public function test_format_interval_with_type_decimal_and_number_format_thousan
8989
$formatted = $this->localizationService->formatInterval($interval);
9090

9191
// Assert
92-
$this->assertSame('30\'001.05', $formatted);
92+
$this->assertSame('30\'001.05 h', $formatted);
9393
}
9494

9595
public function test_format_interval_with_type_hours_minutes(): void

0 commit comments

Comments
 (0)