From 7c01b3bb6460bced36b23ab53f6ccc9672d6617d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Wed, 10 Mar 2021 16:55:49 +0100 Subject: [PATCH 1/5] Support for custom fields in company details section --- app/Services/PdfMaker/Design.php | 4 +++ .../Designs/Utilities/DesignHelpers.php | 33 +++++++++++++++++-- 2 files changed, 35 insertions(+), 2 deletions(-) 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 + ); + } } From b88533d3d2f3924105dfd41f26cc36b54b01d4d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Wed, 10 Mar 2021 16:56:17 +0100 Subject: [PATCH 2/5] Catch possible invalid format exception & return "Invalid date!" --- app/Utils/Traits/MakesDates.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) 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 +} From 9db7d2e5cae0a7436810a2fd8e4c52ae5bdf0ff6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Wed, 10 Mar 2021 16:56:41 +0100 Subject: [PATCH 3/5] Fix "Plain" design not showing company-details section --- ...update_designs.php => 2021_03_10_115919_update_designs.php} | 0 resources/views/pdf-designs/plain.html | 3 +-- 2 files changed, 1 insertion(+), 2 deletions(-) rename database/migrations/{2021_03_02_115919_update_designs.php => 2021_03_10_115919_update_designs.php} (100%) 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

- +
From 941132133c39c00066cfacf1d0e4e136af9019eb Mon Sep 17 00:00:00 2001 From: Joshua Dwire Date: Fri, 12 Mar 2021 18:46:56 -0500 Subject: [PATCH 4/5] Fix request validation for preconfigured installs --- app/Http/Requests/Setup/StoreSetupRequest.php | 57 +++++++++++-------- 1 file changed, 32 insertions(+), 25 deletions(-) diff --git a/app/Http/Requests/Setup/StoreSetupRequest.php b/app/Http/Requests/Setup/StoreSetupRequest.php index c7e0262433c2..13d37f2dab2e 100644 --- a/app/Http/Requests/Setup/StoreSetupRequest.php +++ b/app/Http/Requests/Setup/StoreSetupRequest.php @@ -27,31 +27,38 @@ class StoreSetupRequest extends Request public function rules() { - return [ - /*System*/ - 'url' => 'required', - /*Database*/ - 'db_host' => 'required', - 'db_database' => 'required', - 'db_username' => 'required', - 'db_password' => '', - /*Mail driver*/ - 'mail_driver' => 'required', - 'encryption' => 'required_unless:mail_driver,log', - 'mail_host' => 'required_unless:mail_driver,log', - 'mail_username' => 'required_unless:mail_driver,log', - 'mail_name' => 'required_unless:mail_driver,log', - 'mail_address' => 'required_unless:mail_driver,log', - 'mail_password' => 'required_unless:mail_driver,log', - /*user registration*/ - 'privacy_policy' => 'required', - 'terms_of_service' => 'required', - 'first_name' => 'required', - 'last_name' => 'required', - 'email' => 'required|email:rfc,dns', - 'password' => 'required', - ]; - } + $rules = [ + /*System*/ + 'url' => 'required', + /*Mail driver*/ + 'mail_driver' => 'required', + 'encryption' => 'required_unless:mail_driver,log', + 'mail_host' => 'required_unless:mail_driver,log', + 'mail_username' => 'required_unless:mail_driver,log', + 'mail_name' => 'required_unless:mail_driver,log', + 'mail_address' => 'required_unless:mail_driver,log', + 'mail_password' => 'required_unless:mail_driver,log', + /*user registration*/ + 'privacy_policy' => 'required', + 'terms_of_service' => 'required', + 'first_name' => 'required', + 'last_name' => 'required', + 'email' => 'required|email:rfc,dns', + 'password' => 'required', + ]; + + if ( ! config( 'ninja.preconfigured_install' ) ) { + $rules = array_merge( $rules, [ + /*Database*/ + 'db_host' => 'required', + 'db_database' => 'required', + 'db_username' => 'required', + 'db_password' => '', + ] ); + } + + return $rules; + } protected function prepareForValidation() { From f46f1205d0035e5c0c41a76c062fc995ae3d011e Mon Sep 17 00:00:00 2001 From: = Date: Sat, 13 Mar 2021 15:20:07 +1100 Subject: [PATCH 5/5] 5.1.22 --- VERSION.txt | 2 +- config/ninja.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/VERSION.txt b/VERSION.txt index 35f4a192f4da..e1661601966a 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -1 +1 @@ -5.1.21 \ No newline at end of file +5.1.22 \ No newline at end of file diff --git a/config/ninja.php b/config/ninja.php index 78f05ed8bc2d..ddf9f4b91edd 100644 --- a/config/ninja.php +++ b/config/ninja.php @@ -13,7 +13,7 @@ return [ 'require_https' => env('REQUIRE_HTTPS', true), 'app_url' => rtrim(env('APP_URL', ''), '/'), 'app_domain' => env('APP_DOMAIN', ''), - 'app_version' => '5.1.21', + 'app_version' => '5.1.22', 'minimum_client_version' => '5.0.16', 'terms_version' => '1.0.1', 'api_secret' => env('API_SECRET', false),