diff --git a/app/Http/Requests/Client/StoreClientRequest.php b/app/Http/Requests/Client/StoreClientRequest.php index 375726397f5a..c93e2c8299a4 100644 --- a/app/Http/Requests/Client/StoreClientRequest.php +++ b/app/Http/Requests/Client/StoreClientRequest.php @@ -93,6 +93,15 @@ class StoreClientRequest extends Request $input = $this->all(); $settings = ClientSettings::defaults(); + $tmp = []; + + $tmp['settings'] = (array)$settings; + + nlog("seeetings"); + nlog($tmp['settings']); + + if (array_key_exists('settings', $input)) + nlog($input['settings']); if (array_key_exists('settings', $input) && ! empty($input['settings'])) { foreach ($input['settings'] as $key => $value) { @@ -100,10 +109,12 @@ class StoreClientRequest extends Request $value = floatval($value); } - $settings->{$key} = $value; + $tmp['settings'][$key] = $value; } } + $input['settings'] = $tmp['settings']; + $input = $this->decodePrimaryKeys($input); if (isset($input['group_settings_id'])) { @@ -115,23 +126,26 @@ class StoreClientRequest extends Request $group_settings = GroupSetting::find($input['group_settings_id']); if ($group_settings && property_exists($group_settings->settings, 'currency_id') && isset($group_settings->settings->currency_id)) { - $settings->currency_id = (string) $group_settings->settings->currency_id; + $input['settings']['currency_id'] = (string) $group_settings->settings->currency_id; } else { - $settings->currency_id = (string) auth()->user()->company()->settings->currency_id; + $input['settings']['currency_id'] = (string) auth()->user()->company()->settings->currency_id; } } elseif (! property_exists($settings, 'currency_id')) { - $settings->currency_id = (string) auth()->user()->company()->settings->currency_id; + $input['settings']['currency_id'] = (string) auth()->user()->company()->settings->currency_id; } if (isset($input['currency_code'])) { - $settings->currency_id = $this->getCurrencyCode($input['currency_code']); + $input['settings']['currency_id'] = $this->getCurrencyCode($input['currency_code']); } if (isset($input['language_code'])) { - $settings->language_id = $this->getLanguageId($input['language_code']); + $input['settings']['language_id'] = $this->getLanguageId($input['language_code']); + + if(strlen($input['settings']['language_id']) == 0) + unset($input['settings']['language_id']); } - $input['settings'] = (array)$settings; + // $input['settings'] = $settings; if (isset($input['country_code'])) { $input['country_id'] = $this->getCountryCode($input['country_code']); @@ -146,6 +160,10 @@ class StoreClientRequest extends Request unset($input['number']); } + +nlog($input); + + $this->replace($input); } diff --git a/app/Utils/Traits/MakesInvoiceValues.php b/app/Utils/Traits/MakesInvoiceValues.php index d4697a560b1e..cb1dc4980f8b 100644 --- a/app/Utils/Traits/MakesInvoiceValues.php +++ b/app/Utils/Traits/MakesInvoiceValues.php @@ -290,9 +290,9 @@ trait MakesInvoiceValues $helpers = new Helpers(); $_table_type = ltrim($table_type, '$'); // From $product -> product. - $data[$key][$table_type.'.product_key'] = is_null($item?->product_key) ? $item->item : $item->product_key; - $data[$key][$table_type.'.item'] = is_null($item?->item) ? $item->product_key : $item->item; - $data[$key][$table_type.'.service'] = is_null($item?->service) ? $item->product_key : $item->service; + $data[$key][$table_type.'.product_key'] = is_null(optional($item)->product_key) ? $item->item : $item->product_key; + $data[$key][$table_type.'.item'] = is_null(optional($item)->item) ? $item->product_key : $item->item; + $data[$key][$table_type.'.service'] = is_null(optional($item)->service) ? $item->product_key : $item->service; $data[$key][$table_type.'.notes'] = Helpers::processReservedKeywords($item->notes, $entity); $data[$key][$table_type.'.description'] = Helpers::processReservedKeywords($item->notes, $entity); @@ -354,7 +354,7 @@ trait MakesInvoiceValues $data[$key][$table_type.'.tax3'] = &$data[$key][$table_type.'.tax_rate3']; } - $data[$key]['task_id'] = $item?->task_id; + $data[$key]['task_id'] = $item->task_id; } return $data; diff --git a/composer.json b/composer.json index e4ab673883bb..518b84fc74c6 100644 --- a/composer.json +++ b/composer.json @@ -101,8 +101,7 @@ "laravel/dusk": "^6.15", "mockery/mockery": "^1.4.4", "nunomaduro/collision": "^6.1", - "phpunit/phpunit": "^9.5.10", - "spatie/laravel-ignition": "^1.0" + "phpunit/phpunit": "^9.5.10" }, "autoload": { "psr-4": { diff --git a/composer.lock b/composer.lock index 4726f19a12d5..1b6f71f137e1 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "d0d010798ad474d7d212a31f78c90029", + "content-hash": "6876460f0cb90da2bc3e8b03d6c270b9", "packages": [ { "name": "afosto/yaac", @@ -14296,302 +14296,6 @@ ], "time": "2020-09-28T06:39:44+00:00" }, - { - "name": "spatie/backtrace", - "version": "1.2.1", - "source": { - "type": "git", - "url": "https://github.com/spatie/backtrace.git", - "reference": "4ee7d41aa5268107906ea8a4d9ceccde136dbd5b" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/spatie/backtrace/zipball/4ee7d41aa5268107906ea8a4d9ceccde136dbd5b", - "reference": "4ee7d41aa5268107906ea8a4d9ceccde136dbd5b", - "shasum": "" - }, - "require": { - "php": "^7.3|^8.0" - }, - "require-dev": { - "ext-json": "*", - "phpunit/phpunit": "^9.3", - "symfony/var-dumper": "^5.1" - }, - "type": "library", - "autoload": { - "psr-4": { - "Spatie\\Backtrace\\": "src" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Freek Van de Herten", - "email": "freek@spatie.be", - "homepage": "https://spatie.be", - "role": "Developer" - } - ], - "description": "A better backtrace", - "homepage": "https://github.com/spatie/backtrace", - "keywords": [ - "Backtrace", - "spatie" - ], - "support": { - "issues": "https://github.com/spatie/backtrace/issues", - "source": "https://github.com/spatie/backtrace/tree/1.2.1" - }, - "funding": [ - { - "url": "https://github.com/sponsors/spatie", - "type": "github" - }, - { - "url": "https://spatie.be/open-source/support-us", - "type": "other" - } - ], - "time": "2021-11-09T10:57:15+00:00" - }, - { - "name": "spatie/flare-client-php", - "version": "1.2.0", - "source": { - "type": "git", - "url": "https://github.com/spatie/flare-client-php.git", - "reference": "86a380f5b1ce839af04a08f1c8f2697184cdf23f" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/spatie/flare-client-php/zipball/86a380f5b1ce839af04a08f1c8f2697184cdf23f", - "reference": "86a380f5b1ce839af04a08f1c8f2697184cdf23f", - "shasum": "" - }, - "require": { - "illuminate/pipeline": "^8.0|^9.0", - "php": "^8.0", - "spatie/backtrace": "^1.2", - "symfony/http-foundation": "^5.0|^6.0", - "symfony/mime": "^5.2|^6.0", - "symfony/process": "^5.2|^6.0", - "symfony/var-dumper": "^5.2|^6.0" - }, - "require-dev": { - "dms/phpunit-arraysubset-asserts": "^0.3.0", - "pestphp/pest": "^1.20", - "phpstan/extension-installer": "^1.1", - "phpstan/phpstan-deprecation-rules": "^1.0", - "phpstan/phpstan-phpunit": "^1.0", - "spatie/phpunit-snapshot-assertions": "^4.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-main": "1.1.x-dev" - } - }, - "autoload": { - "files": [ - "src/helpers.php" - ], - "psr-4": { - "Spatie\\FlareClient\\": "src" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "description": "Send PHP errors to Flare", - "homepage": "https://github.com/spatie/flare-client-php", - "keywords": [ - "exception", - "flare", - "reporting", - "spatie" - ], - "support": { - "issues": "https://github.com/spatie/flare-client-php/issues", - "source": "https://github.com/spatie/flare-client-php/tree/1.2.0" - }, - "funding": [ - { - "url": "https://github.com/spatie", - "type": "github" - } - ], - "time": "2022-05-16T12:13:39+00:00" - }, - { - "name": "spatie/ignition", - "version": "1.3.1", - "source": { - "type": "git", - "url": "https://github.com/spatie/ignition.git", - "reference": "997363fbcce809b1e55f571997d49017f9c623d9" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/spatie/ignition/zipball/997363fbcce809b1e55f571997d49017f9c623d9", - "reference": "997363fbcce809b1e55f571997d49017f9c623d9", - "shasum": "" - }, - "require": { - "ext-json": "*", - "ext-mbstring": "*", - "monolog/monolog": "^2.0", - "php": "^8.0", - "spatie/flare-client-php": "^1.1", - "symfony/console": "^5.4|^6.0", - "symfony/var-dumper": "^5.4|^6.0" - }, - "require-dev": { - "mockery/mockery": "^1.4", - "pestphp/pest": "^1.20", - "phpstan/extension-installer": "^1.1", - "phpstan/phpstan-deprecation-rules": "^1.0", - "phpstan/phpstan-phpunit": "^1.0", - "symfony/process": "^5.4|^6.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-main": "1.2.x-dev" - } - }, - "autoload": { - "psr-4": { - "Spatie\\Ignition\\": "src" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Spatie", - "email": "info@spatie.be", - "role": "Developer" - } - ], - "description": "A beautiful error page for PHP applications.", - "homepage": "https://flareapp.io/ignition", - "keywords": [ - "error", - "flare", - "laravel", - "page" - ], - "support": { - "docs": "https://flareapp.io/docs/ignition-for-laravel/introduction", - "forum": "https://twitter.com/flareappio", - "issues": "https://github.com/spatie/ignition/issues", - "source": "https://github.com/spatie/ignition" - }, - "funding": [ - { - "url": "https://github.com/spatie", - "type": "github" - } - ], - "time": "2022-05-16T13:16:07+00:00" - }, - { - "name": "spatie/laravel-ignition", - "version": "1.3.1", - "source": { - "type": "git", - "url": "https://github.com/spatie/laravel-ignition.git", - "reference": "fe37a0eafe6ea040804255c70e9808af13314f87" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/spatie/laravel-ignition/zipball/fe37a0eafe6ea040804255c70e9808af13314f87", - "reference": "fe37a0eafe6ea040804255c70e9808af13314f87", - "shasum": "" - }, - "require": { - "ext-curl": "*", - "ext-json": "*", - "ext-mbstring": "*", - "illuminate/support": "^8.77|^9.0", - "monolog/monolog": "^2.3", - "php": "^8.0", - "spatie/flare-client-php": "^1.0.1", - "spatie/ignition": "^1.2.4", - "symfony/console": "^5.0|^6.0", - "symfony/var-dumper": "^5.0|^6.0" - }, - "require-dev": { - "filp/whoops": "^2.14", - "livewire/livewire": "^2.8|dev-develop", - "mockery/mockery": "^1.4", - "nunomaduro/larastan": "^1.0", - "orchestra/testbench": "^6.23|^7.0", - "pestphp/pest": "^1.20", - "phpstan/extension-installer": "^1.1", - "phpstan/phpstan-deprecation-rules": "^1.0", - "phpstan/phpstan-phpunit": "^1.0", - "spatie/laravel-ray": "^1.27" - }, - "type": "library", - "extra": { - "laravel": { - "providers": [ - "Spatie\\LaravelIgnition\\IgnitionServiceProvider" - ], - "aliases": { - "Flare": "Spatie\\LaravelIgnition\\Facades\\Flare" - } - } - }, - "autoload": { - "files": [ - "src/helpers.php" - ], - "psr-4": { - "Spatie\\LaravelIgnition\\": "src" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Spatie", - "email": "info@spatie.be", - "role": "Developer" - } - ], - "description": "A beautiful error page for Laravel applications.", - "homepage": "https://flareapp.io/ignition", - "keywords": [ - "error", - "flare", - "laravel", - "page" - ], - "support": { - "docs": "https://flareapp.io/docs/ignition-for-laravel/introduction", - "forum": "https://twitter.com/flareappio", - "issues": "https://github.com/spatie/laravel-ignition/issues", - "source": "https://github.com/spatie/laravel-ignition" - }, - "funding": [ - { - "url": "https://github.com/spatie", - "type": "github" - } - ], - "time": "2022-06-17T06:28:57+00:00" - }, { "name": "swagger-api/swagger-ui", "version": "v3.52.5", diff --git a/tests/Feature/ClientApiTest.php b/tests/Feature/ClientApiTest.php index 956d3e98dcb4..6d79bbb1dc32 100644 --- a/tests/Feature/ClientApiTest.php +++ b/tests/Feature/ClientApiTest.php @@ -69,8 +69,10 @@ class ClientApiTest extends TestCase nlog($message); } + $response->assertStatus(200); $arr = $response->json(); + $this->assertFalse(array_key_exists('translations', $arr['data']['settings'])); } @@ -98,6 +100,8 @@ class ClientApiTest extends TestCase $arr = $response->json(); +nlog($arr); + $this->assertFalse(array_key_exists('language_id', $arr['data']['settings'])); } diff --git a/tests/Unit/ClientSettingsTest.php b/tests/Unit/ClientSettingsTest.php index 7464aae79a27..1923ae0c73fb 100644 --- a/tests/Unit/ClientSettingsTest.php +++ b/tests/Unit/ClientSettingsTest.php @@ -90,7 +90,7 @@ class ClientSettingsTest extends TestCase $response->assertStatus(200); $arr = $response->json(); - +nlog($arr); $this->assertEquals('1', $arr['data']['settings']['currency_id']); $this->assertEquals('1', $arr['data']['settings']['language_id']); $this->assertEquals('1', $arr['data']['settings']['payment_terms']); @@ -100,15 +100,16 @@ class ClientSettingsTest extends TestCase } public function testClientIllegalCurrency() - { + {nlog("illegal"); + $data = [ 'name' => $this->faker->firstName(), - 'id_number' => 'Coolio', + 'id_number' => 'Cooliox2', 'settings' => [ - 'currency_id' => 'a', + 'currency_id' => '2', 'language_id' => '1', 'payment_terms' => '1', - 'valid_until' => '1', + 'valid_until' => '2', 'default_task_rate' => 10, 'send_reminders' => true, ], @@ -126,6 +127,8 @@ class ClientSettingsTest extends TestCase nlog($message); } +nlog($response->json()); + $response->assertStatus(302); }