diff --git a/app/Services/PdfMaker/Design.php b/app/Services/PdfMaker/Design.php index 476440a9d7ea..1107f2003f9f 100644 --- a/app/Services/PdfMaker/Design.php +++ b/app/Services/PdfMaker/Design.php @@ -137,6 +137,10 @@ class Design extends BaseDesign $elements[] = ['element' => 'p', 'content' => $variable, 'show_empty' => false, 'properties' => ['data-ref' => 'company_details-' . substr($variable, 1)]]; } + foreach (['company1', 'company2', 'company3', 'company4'] as $field) { + $elements[] = ['element' => 'p', 'content' => $this->getCustomFieldValue($field), 'show_empty' => false, 'properties' => ['data-ref' => 'company_details-' . $field]]; + } + return $elements; } diff --git a/app/Services/PdfMaker/Designs/Utilities/DesignHelpers.php b/app/Services/PdfMaker/Designs/Utilities/DesignHelpers.php index 5877f3804c1a..c27e68fc3130 100644 --- a/app/Services/PdfMaker/Designs/Utilities/DesignHelpers.php +++ b/app/Services/PdfMaker/Designs/Utilities/DesignHelpers.php @@ -12,9 +12,7 @@ namespace App\Services\PdfMaker\Designs\Utilities; -use App\Models\Task; use App\Utils\Traits\MakesHash; -use Carbon\Carbon; use DOMDocument; use DOMXPath; use Exception; @@ -273,4 +271,35 @@ trait DesignHelpers array_splice($this->context['pdf_variables']["{$type}_columns"], $key + 1, 0, $custom_columns); } } + + public function getCustomFieldValue(string $field): string + { + // In custom_fields column we store fields like: company1-4, + // while in settings, they're stored in custom_value1-4 format. + // That's why we need this mapping. + + $fields = [ + 'company1' => 'custom_value1', + 'company2' => 'custom_value2', + 'company3' => 'custom_value3', + 'company4' => 'custom_value4', + ]; + + if (!array_key_exists($field, $fields)) { + return ''; + } + + if (!property_exists($this->client->company->custom_fields, $field)) { + return ''; + } + + $value = $this->client->company->getSetting($fields[$field]); + + return (new \App\Utils\Helpers)->formatCustomFieldValue( + $this->client->company->custom_fields, + $field, + $value, + $this->client + ); + } } diff --git a/app/Utils/Traits/MakesDates.php b/app/Utils/Traits/MakesDates.php index 5e8cc7481475..5d1fc56a8d86 100644 --- a/app/Utils/Traits/MakesDates.php +++ b/app/Utils/Traits/MakesDates.php @@ -99,10 +99,13 @@ trait MakesDates public function translateDate($date, $format, $locale) { - Carbon::setLocale($locale); - return Carbon::parse($date)->translatedFormat($format); + try { + return Carbon::parse($date)->translatedFormat($format); + } catch(\Exception $e) { + return 'Invalid date!'; + } } -} \ No newline at end of file +} diff --git a/database/migrations/2021_03_02_115919_update_designs.php b/database/migrations/2021_03_10_115919_update_designs.php similarity index 100% rename from database/migrations/2021_03_02_115919_update_designs.php rename to database/migrations/2021_03_10_115919_update_designs.php diff --git a/resources/views/pdf-designs/plain.html b/resources/views/pdf-designs/plain.html index 5dcdbd5c6773..9d6ae5c30a7c 100644 --- a/resources/views/pdf-designs/plain.html +++ b/resources/views/pdf-designs/plain.html @@ -154,8 +154,7 @@
-

$company.name

- +