Fixed localization in PDF reports

This commit is contained in:
Constantin Graf
2025-05-13 18:48:37 +02:00
parent cc88f034c7
commit d49082d7f3
4 changed files with 20 additions and 40 deletions

View File

@@ -80,7 +80,7 @@ class LocalizationService
if ($this->intervalFormat === IntervalFormat::Decimal) { if ($this->intervalFormat === IntervalFormat::Decimal) {
$interval->cascade(); $interval->cascade();
return $this->formatNumber($interval->totalHours); return $this->formatNumber($interval->totalHours).' h';
} elseif ($this->intervalFormat === IntervalFormat::HoursMinutes) { } elseif ($this->intervalFormat === IntervalFormat::HoursMinutes) {
$interval->cascade(); $interval->cascade();

View File

@@ -1,12 +1,12 @@
@use('Brick\Math\BigDecimal') @use('Brick\Math\BigDecimal')
@use('Brick\Money\Money') @use('Brick\Money\Money')
@use('PhpOffice\PhpSpreadsheet\Cell\DataType') @use('Illuminate\Support\Carbon')
@use('Carbon\CarbonInterval') @use('Carbon\CarbonInterval')
@inject('colorService', 'App\Service\ColorService') @inject('colorService', 'App\Service\ColorService')
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="utf-8" /> <meta charset="utf-8"/>
<title>Report</title> <title>Report</title>
<style> <style>
html, body, div, span, applet, object, iframe, html, body, div, span, applet, object, iframe,
@@ -130,7 +130,7 @@
@if($debug) @if($debug)
<link rel="preconnect" href="https://fonts.bunny.net"> <link rel="preconnect" href="https://fonts.bunny.net">
<link href="https://fonts.bunny.net/css?family=outfit:200,300,400,500,600,700,800" rel="stylesheet" /> <link href="https://fonts.bunny.net/css?family=outfit:200,300,400,500,600,700,800" rel="stylesheet"/>
@endif @endif
</head> </head>
@@ -356,7 +356,12 @@
animation: false, animation: false,
tooltip: {}, tooltip: {},
xAxis: { xAxis: {
data: ['{!! collect($dataHistoryChart['grouped_data'])->pluck('key')->implode("', '") !!}'], data: {!!
json_encode(collect($dataHistoryChart['grouped_data'])
->pluck('key')
->map(fn($value) => $localization->formatDate(Carbon::parse($value)))
->toArray())
!!},
axisLabel: { axisLabel: {
fontSize: 10, fontSize: 10,
fontWeight: 400, fontWeight: 400,
@@ -381,26 +386,16 @@
axisLabel: { axisLabel: {
show: false, show: false,
inside: true, inside: true,
formatter: function(value, index) {
let totalSeconds = value;
let hours = Math.floor(totalSeconds / 3600);
if (hours < 10) {
hours = "0" + hours;
}
totalSeconds %= 3600;
let minutes = Math.floor(totalSeconds / 60);
if (minutes < 10) {
minutes = "0" + minutes;
}
return hours + ":" + minutes;
}
} }
}, },
series: [ series: [
{ {
name: "time", name: "time",
type: "bar", type: "bar",
data: [{!! collect($dataHistoryChart['grouped_data'])->pluck('seconds')->implode(', ') !!}], data: {!! json_encode(collect($dataHistoryChart['grouped_data'])->map(fn($value) => (object) [
'value' => $value['seconds'],
'name' => ((int) $value['seconds']) === 0 ? '' : $localization->formatInterval(CarbonInterval::seconds((int) $value['seconds']))
])->toArray()) !!},
itemStyle: { itemStyle: {
borderColor: "#7dd3fc", borderColor: "#7dd3fc",
color: "#7dd3fc" color: "#7dd3fc"
@@ -413,22 +408,8 @@
@endif @endif
fontSize: 10, fontSize: 10,
position: "top", position: "top",
formatter: function(params) { formatter: function (params) {
let value = params.value; return params.name;
if (value === 0) {
return "";
}
let totalSeconds = value;
let hours = Math.floor(totalSeconds / 3600);
if (hours < 10) {
hours = "0" + hours;
}
totalSeconds %= 3600;
let minutes = Math.floor(totalSeconds / 60);
if (minutes < 10) {
minutes = "0" + minutes;
}
return hours + ":" + minutes;
} }
} }
} }

View File

@@ -1,6 +1,5 @@
@use('Brick\Math\BigDecimal') @use('Brick\Math\BigDecimal')
@use('Brick\Money\Money') @use('Brick\Money\Money')
@use('PhpOffice\PhpSpreadsheet\Cell\DataType')
@use('Carbon\CarbonInterval') @use('Carbon\CarbonInterval')
@inject('interval', 'App\Service\IntervalService') @inject('interval', 'App\Service\IntervalService')
<!DOCTYPE html> <!DOCTYPE html>

View File

@@ -47,7 +47,7 @@ class LocalizationServiceTest extends TestCaseWithDatabase
$formatted = $this->localizationService->formatInterval($interval); $formatted = $this->localizationService->formatInterval($interval);
// Assert // Assert
$this->assertSame('30,001.05', $formatted); $this->assertSame('30,001.05 h', $formatted);
} }
public function test_format_interval_with_type_decimal_and_number_format_thousands_space_decimal_point(): void public function test_format_interval_with_type_decimal_and_number_format_thousands_space_decimal_point(): void
@@ -61,7 +61,7 @@ class LocalizationServiceTest extends TestCaseWithDatabase
$formatted = $this->localizationService->formatInterval($interval); $formatted = $this->localizationService->formatInterval($interval);
// Assert // Assert
$this->assertSame('30 001.05', $formatted); $this->assertSame('30 001.05 h', $formatted);
} }
public function test_format_interval_with_type_decimal_and_number_format_thousands_point_decimal_comma(): void public function test_format_interval_with_type_decimal_and_number_format_thousands_point_decimal_comma(): void
@@ -75,7 +75,7 @@ class LocalizationServiceTest extends TestCaseWithDatabase
$formatted = $this->localizationService->formatInterval($interval); $formatted = $this->localizationService->formatInterval($interval);
// Assert // Assert
$this->assertSame('30.001,05', $formatted); $this->assertSame('30.001,05 h', $formatted);
} }
public function test_format_interval_with_type_decimal_and_number_format_thousands_apostrophe_decimal_point(): void public function test_format_interval_with_type_decimal_and_number_format_thousands_apostrophe_decimal_point(): void
@@ -89,7 +89,7 @@ class LocalizationServiceTest extends TestCaseWithDatabase
$formatted = $this->localizationService->formatInterval($interval); $formatted = $this->localizationService->formatInterval($interval);
// Assert // Assert
$this->assertSame('30\'001.05', $formatted); $this->assertSame('30\'001.05 h', $formatted);
} }
public function test_format_interval_with_type_hours_minutes(): void public function test_format_interval_with_type_hours_minutes(): void