diff --git a/app/Models/ReportTemplate.php b/app/Models/ReportTemplate.php index c8fcd22742..5c371a82df 100644 --- a/app/Models/ReportTemplate.php +++ b/app/Models/ReportTemplate.php @@ -175,17 +175,17 @@ class ReportTemplate extends Model /** * Get the value of a text field for the given field name. * - * @param string $fieldName + * @param string $fieldName + * @param string|null $fallbackValue * * @return string - * */ - public function textValue(string $fieldName): string + public function textValue(string $fieldName, string|null $fallbackValue = ''): string { // Assuming we're using the null object pattern, // return the default value if the object is not saved yet. if (is_null($this->id)) { - return ''; + return (string) $fallbackValue; } // Return the field's value if it exists diff --git a/resources/views/reports/custom.blade.php b/resources/views/reports/custom.blade.php index 22cec2b322..818a3ef591 100644 --- a/resources/views/reports/custom.blade.php +++ b/resources/views/reports/custom.blade.php @@ -395,7 +395,7 @@
- +
@@ -403,9 +403,9 @@
- + {{ strtolower(trans('general.to')) }} - +
@if ($errors->has('purchase_start') || $errors->has('purchase_end')) @@ -421,9 +421,9 @@
- + {{ strtolower(trans('general.to')) }} - +
@if ($errors->has('created_start') || $errors->has('created_end')) @@ -438,9 +438,9 @@
- + {{ strtolower(trans('general.to')) }} - +
@if ($errors->has('checkout_date_start') || $errors->has('checkout_date_end')) @@ -456,9 +456,9 @@
- + {{ strtolower(trans('general.to')) }} - +
@if ($errors->has('checkin_date_start') || $errors->has('checkin_date_end')) @@ -473,9 +473,9 @@
- + {{ strtolower(trans('general.to')) }} - +
@if ($errors->has('expected_checkin_start') || $errors->has('expected_checkin_end')) @@ -491,9 +491,9 @@
- + to - +
@if ($errors->has('asset_eol_date_start') || $errors->has('asset_eol_date_end')) @@ -508,9 +508,9 @@
- + {{ strtolower(trans('general.to')) }} - +
@if ($errors->has('last_audit_start') || $errors->has('last_audit_end')) @@ -525,9 +525,9 @@
- + {{ strtolower(trans('general.to')) }} - +
@if ($errors->has('next_audit_start') || $errors->has('next_audit_end')) diff --git a/tests/Unit/ReportTemplateTest.php b/tests/Unit/ReportTemplateTest.php index 9073b06afa..c7d5e24759 100644 --- a/tests/Unit/ReportTemplateTest.php +++ b/tests/Unit/ReportTemplateTest.php @@ -83,6 +83,7 @@ class ReportTemplateTest extends TestCase $this->assertEquals('', $template->textValue('non_existent_key')); $this->assertEquals('', (new ReportTemplate)->textValue('is_a_text_field')); + $this->assertEquals('my fallback', (new ReportTemplate)->textValue('non_existent_key', 'my fallback')); } public function testParsingRadioValue()