From 72cb7dd8182c0158c41e0862c70e3791532e94ce Mon Sep 17 00:00:00 2001 From: philipp lang Date: Mon, 14 Oct 2024 21:21:19 +0200 Subject: [PATCH] Add Settings for Bill --- .../Documents/CityFrankfurtMainDocument.php | 2 +- .../Documents/CitySolingenDocument.php | 2 +- app/Invoice/InvoiceDocument.php | 1 + app/Invoice/Models/Invoice.php | 2 +- .../Mails/PreventionRememberMail.php | 2 +- app/Providers/BaseServiceProvider.php | 1 - app/Setting/Data/SettingSynthesizer.php | 36 ++++ app/Setting/SettingServiceProvider.php | 6 +- app/View/Form/Text.php | 53 ++++++ config/app.php | 3 +- modules/Invoice/Components/SettingView.php | 53 ++++++ modules/Invoice/InvoiceServiceProvider.php | 31 ++++ modules/Invoice/InvoiceSettingTest.php | 72 ++++++++ {app => modules}/Invoice/InvoiceSettings.php | 2 +- resources/js/components/form/Text.vue | 154 ------------------ resources/js/views/setting/Bill.vue | 49 ------ tests/Feature/Contribution/StoreTest.php | 2 +- .../Feature/Invoice/InvoiceSendActionTest.php | 2 +- tests/Feature/Invoice/SettingTest.php | 2 +- tests/Feature/Invoice/ShowPdfTest.php | 2 +- tests/Feature/Invoice/ShowRememberpdfTest.php | 2 +- tests/Feature/Member/PreventionTest.php | 2 +- .../RequestFactories/InvoiceSettingsFake.php | 1 + 23 files changed, 265 insertions(+), 217 deletions(-) create mode 100644 app/Setting/Data/SettingSynthesizer.php create mode 100644 app/View/Form/Text.php create mode 100644 modules/Invoice/Components/SettingView.php create mode 100644 modules/Invoice/InvoiceServiceProvider.php create mode 100644 modules/Invoice/InvoiceSettingTest.php rename {app => modules}/Invoice/InvoiceSettings.php (98%) delete mode 100644 resources/js/components/form/Text.vue delete mode 100644 resources/js/views/setting/Bill.vue diff --git a/app/Contribution/Documents/CityFrankfurtMainDocument.php b/app/Contribution/Documents/CityFrankfurtMainDocument.php index 5306afb4..12e0354f 100644 --- a/app/Contribution/Documents/CityFrankfurtMainDocument.php +++ b/app/Contribution/Documents/CityFrankfurtMainDocument.php @@ -4,10 +4,10 @@ namespace App\Contribution\Documents; use App\Contribution\Data\MemberData; use App\Country; -use App\Invoice\InvoiceSettings; use Carbon\Carbon; use Illuminate\Support\Collection; use Illuminate\Support\Str; +use Modules\Invoice\InvoiceSettings; use Zoomyboy\Tex\Engine; use Zoomyboy\Tex\Template; diff --git a/app/Contribution/Documents/CitySolingenDocument.php b/app/Contribution/Documents/CitySolingenDocument.php index 0eed82ee..878d0fa3 100644 --- a/app/Contribution/Documents/CitySolingenDocument.php +++ b/app/Contribution/Documents/CitySolingenDocument.php @@ -3,10 +3,10 @@ namespace App\Contribution\Documents; use App\Contribution\Data\MemberData; -use App\Invoice\InvoiceSettings; use Carbon\Carbon; use Illuminate\Support\Collection; use Illuminate\Support\Str; +use Modules\Invoice\InvoiceSettings; use Zoomyboy\Tex\Engine; use Zoomyboy\Tex\Template; diff --git a/app/Invoice/InvoiceDocument.php b/app/Invoice/InvoiceDocument.php index c609038c..64cf7ed8 100644 --- a/app/Invoice/InvoiceDocument.php +++ b/app/Invoice/InvoiceDocument.php @@ -6,6 +6,7 @@ use App\Invoice\Models\Invoice; use App\Payment\Payment; use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Support\Str; +use Modules\Invoice\InvoiceSettings; use Zoomyboy\Tex\Document; use Zoomyboy\Tex\Engine; use Zoomyboy\Tex\Template; diff --git a/app/Invoice/Models/Invoice.php b/app/Invoice/Models/Invoice.php index 0ae41b96..0f5add8b 100644 --- a/app/Invoice/Models/Invoice.php +++ b/app/Invoice/Models/Invoice.php @@ -6,7 +6,6 @@ use App\Invoice\BillDocument; use App\Invoice\BillKind; use App\Invoice\Enums\InvoiceStatus; use App\Invoice\InvoiceDocument; -use App\Invoice\InvoiceSettings; use App\Invoice\RememberDocument; use App\Invoice\Scopes\InvoiceFilterScope; use App\Member\Member; @@ -17,6 +16,7 @@ use Illuminate\Database\Eloquent\Collection; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\HasMany; +use Modules\Invoice\InvoiceSettings; use stdClass; class Invoice extends Model diff --git a/app/Prevention/Mails/PreventionRememberMail.php b/app/Prevention/Mails/PreventionRememberMail.php index d435d1a7..a433ba1d 100644 --- a/app/Prevention/Mails/PreventionRememberMail.php +++ b/app/Prevention/Mails/PreventionRememberMail.php @@ -2,7 +2,6 @@ namespace App\Prevention\Mails; -use App\Invoice\InvoiceSettings; use App\Lib\Editor\EditorData; use App\Prevention\Contracts\Preventable; use Illuminate\Bus\Queueable; @@ -11,6 +10,7 @@ use Illuminate\Mail\Mailable; use Illuminate\Mail\Mailables\Content; use Illuminate\Mail\Mailables\Envelope; use Illuminate\Queue\SerializesModels; +use Modules\Invoice\InvoiceSettings; class PreventionRememberMail extends Mailable { diff --git a/app/Providers/BaseServiceProvider.php b/app/Providers/BaseServiceProvider.php index 4ffd4b12..153355fd 100644 --- a/app/Providers/BaseServiceProvider.php +++ b/app/Providers/BaseServiceProvider.php @@ -37,7 +37,6 @@ class BaseServiceProvider extends ServiceProvider return $condition ? $self->merge([$key => $attributes]) : $self; }); - Livewire::resolveMissingComponent(function ($name) { 'modules.dashboard.components.dashboard-component'; if (str($name)->startsWith('modules.')) { diff --git a/app/Setting/Data/SettingSynthesizer.php b/app/Setting/Data/SettingSynthesizer.php new file mode 100644 index 00000000..65fa5765 --- /dev/null +++ b/app/Setting/Data/SettingSynthesizer.php @@ -0,0 +1,36 @@ +toArray(), ['setting_class' => get_class($target)]]; + } + + public function hydrate($value, $meta) + { + return app($meta['setting_class'])->fill($value); + } + + public function get(&$target, $key) + { + return $target->{$key}; + } + + public function set(&$target, $key, $value) + { + $target->{$key} = $value; + } +} diff --git a/app/Setting/SettingServiceProvider.php b/app/Setting/SettingServiceProvider.php index b20a889a..4889a3f9 100644 --- a/app/Setting/SettingServiceProvider.php +++ b/app/Setting/SettingServiceProvider.php @@ -4,12 +4,14 @@ namespace App\Setting; use App\Fileshare\FileshareSettings; use App\Form\FormSettings; -use App\Invoice\InvoiceSettings; use App\Mailgateway\MailgatewaySettings; use Modules\Module\ModuleSettings; use App\Prevention\PreventionSettings; +use App\Setting\Data\SettingSynthesizer; use Illuminate\Routing\Router; use Illuminate\Support\ServiceProvider; +use Livewire\Livewire; +use Modules\Invoice\InvoiceSettings; class SettingServiceProvider extends ServiceProvider { @@ -38,5 +40,7 @@ class SettingServiceProvider extends ServiceProvider app(SettingFactory::class)->register(FormSettings::class); app(SettingFactory::class)->register(FileshareSettings::class); app(SettingFactory::class)->register(PreventionSettings::class); + + Livewire::propertySynthesizer(SettingSynthesizer::class); } } diff --git a/app/View/Form/Text.php b/app/View/Form/Text.php new file mode 100644 index 00000000..5f735ba3 --- /dev/null +++ b/app/View/Form/Text.php @@ -0,0 +1,53 @@ +id = str()->uuid()->toString(); + } + + public function render() + { + return <<<'HTML' + + HTML; + } +} diff --git a/config/app.php b/config/app.php index 585fa599..958990f5 100644 --- a/config/app.php +++ b/config/app.php @@ -177,9 +177,10 @@ return [ App\Setting\SettingServiceProvider::class, // App\Dashboard\DashboardServiceProvider::class, App\Providers\PluginServiceProvider::class, + App\Providers\BaseServiceProvider::class, Modules\Dashboard\DashboardServiceProvider::class, Modules\Module\ModuleServiceProvider::class, - App\Providers\BaseServiceProvider::class, + Modules\Invoice\InvoiceServiceProvider::class, ], /* diff --git a/modules/Invoice/Components/SettingView.php b/modules/Invoice/Components/SettingView.php new file mode 100644 index 00000000..bf1899c8 --- /dev/null +++ b/modules/Invoice/Components/SettingView.php @@ -0,0 +1,53 @@ +settings = app(InvoiceSettings::class); + } + + public function save(): void + { + $this->settings->save(); + $this->dispatch('success', 'Einstellungen gespeichert.'); + } + + public function render() + { + return <<<'HTML' + + + + +
+ + +

Kontaktdaten

+
Diese Kontaktdaten stehen im Absender-Bereich auf der Rechnung.
+ + + + + + + + + +
+
+ HTML; + } +} diff --git a/modules/Invoice/InvoiceServiceProvider.php b/modules/Invoice/InvoiceServiceProvider.php new file mode 100644 index 00000000..84040429 --- /dev/null +++ b/modules/Invoice/InvoiceServiceProvider.php @@ -0,0 +1,31 @@ +middleware(['web', 'auth:web'])->group(function ($router) { + $router->get('/setting/bill', ComponentsSettingView::class)->name('setting.bill'); + }); + } +} diff --git a/modules/Invoice/InvoiceSettingTest.php b/modules/Invoice/InvoiceSettingTest.php new file mode 100644 index 00000000..23fc0e0c --- /dev/null +++ b/modules/Invoice/InvoiceSettingTest.php @@ -0,0 +1,72 @@ +withoutExceptionHandling()->login()->loginNami(); + + test()->get('/setting/bill')->assertSeeLivewire(SettingView::class); +}); + +it('it displays settings', function () { + $this->withoutExceptionHandling()->login()->loginNami(); + app(InvoiceSettings::class)->fill([ + 'from_long' => 'DPSG Stamm Muster', + 'from' => 'Stamm Muster', + 'mobile' => '+49 176 55555', + 'email' => 'max@muster.de', + 'website' => 'https://example.com', + 'address' => 'Musterstr 4', + 'place' => 'Solingen', + 'zip' => '12345', + 'iban' => 'DE05', + 'bic' => 'SOLSDE', + 'rememberWeeks' => 6 + ])->save(); + + Livewire::test(SettingView::class) + ->assertSet('settings.from_long', 'DPSG Stamm Muster') + ->assertSet('settings.from', 'Stamm Muster') + ->assertSet('settings.mobile', '+49 176 55555') + ->assertSet('settings.email', 'max@muster.de') + ->assertSet('settings.website', 'https://example.com') + ->assertSet('settings.address', 'Musterstr 4') + ->assertSet('settings.place', 'Solingen') + ->assertSet('settings.zip', '12345') + ->assertSet('settings.iban', 'DE05') + ->assertSet('settings.bic', 'SOLSDE') + ->assertSet('settings.rememberWeeks', 6); +}); + +it('testItCanChangeSettings', function () { + test()->withoutExceptionHandling()->login()->loginNami(); + + Livewire::test(SettingView::class) + ->set('settings.from_long', 'DPSG Stamm Muster') + ->set('settings.from', 'Stamm Muster') + ->set('settings.mobile', '+49 176 55555') + ->set('settings.email', 'max@muster.de') + ->set('settings.website', 'https://example.com') + ->set('settings.address', 'Musterstr 4') + ->set('settings.place', 'Solingen') + ->set('settings.zip', '12345') + ->set('settings.iban', 'DE05') + ->set('settings.bic', 'SOLSDE') + ->set('settings.rememberWeeks', 10) + ->call('save') + ->assertDispatched('success', 'Einstellungen gespeichert.'); + + $settings = app(InvoiceSettings::class); + $this->assertEquals('DPSG Stamm Muster', $settings->from_long); + $this->assertEquals('DE05', $settings->iban); + $this->assertEquals('SOLSDE', $settings->bic); + $this->assertEquals(10, $settings->rememberWeeks); +}); diff --git a/app/Invoice/InvoiceSettings.php b/modules/Invoice/InvoiceSettings.php similarity index 98% rename from app/Invoice/InvoiceSettings.php rename to modules/Invoice/InvoiceSettings.php index 23a30710..648bb9ba 100644 --- a/app/Invoice/InvoiceSettings.php +++ b/modules/Invoice/InvoiceSettings.php @@ -1,6 +1,6 @@ - - - - diff --git a/resources/js/views/setting/Bill.vue b/resources/js/views/setting/Bill.vue deleted file mode 100644 index b6b71e1b..00000000 --- a/resources/js/views/setting/Bill.vue +++ /dev/null @@ -1,49 +0,0 @@ - - - diff --git a/tests/Feature/Contribution/StoreTest.php b/tests/Feature/Contribution/StoreTest.php index e2fd0808..e952523a 100644 --- a/tests/Feature/Contribution/StoreTest.php +++ b/tests/Feature/Contribution/StoreTest.php @@ -7,12 +7,12 @@ use App\Contribution\Documents\RdpNrwDocument; use App\Contribution\Documents\CitySolingenDocument; use App\Country; use App\Gender; -use App\Invoice\InvoiceSettings; use App\Member\Member; use Generator; use Illuminate\Foundation\Testing\DatabaseTransactions; use Laravel\Passport\Client; use Laravel\Passport\Passport; +use Modules\Invoice\InvoiceSettings; use PHPUnit\Framework\Attributes\DataProvider; use Tests\RequestFactories\ContributionMemberApiRequestFactory; use Tests\RequestFactories\ContributionRequestFactory; diff --git a/tests/Feature/Invoice/InvoiceSendActionTest.php b/tests/Feature/Invoice/InvoiceSendActionTest.php index 83b8dc66..3973c173 100644 --- a/tests/Feature/Invoice/InvoiceSendActionTest.php +++ b/tests/Feature/Invoice/InvoiceSendActionTest.php @@ -6,7 +6,6 @@ use App\Invoice\Actions\InvoiceSendAction; use App\Invoice\BillDocument; use App\Invoice\BillKind; use App\Invoice\Enums\InvoiceStatus; -use App\Invoice\InvoiceSettings; use App\Invoice\Mails\BillMail; use App\Invoice\Mails\RememberMail; use App\Invoice\Models\Invoice; @@ -15,6 +14,7 @@ use App\Invoice\RememberDocument; use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Support\Facades\Mail; use Illuminate\Support\Facades\Storage; +use Modules\Invoice\InvoiceSettings; use Tests\TestCase; use Zoomyboy\Tex\Tex; diff --git a/tests/Feature/Invoice/SettingTest.php b/tests/Feature/Invoice/SettingTest.php index e4ce8e3c..21bc2f18 100644 --- a/tests/Feature/Invoice/SettingTest.php +++ b/tests/Feature/Invoice/SettingTest.php @@ -2,8 +2,8 @@ namespace Tests\Feature\Invoice; -use App\Invoice\InvoiceSettings; use Illuminate\Foundation\Testing\DatabaseTransactions; +use Modules\Invoice\InvoiceSettings; use Tests\TestCase; class SettingTest extends TestCase diff --git a/tests/Feature/Invoice/ShowPdfTest.php b/tests/Feature/Invoice/ShowPdfTest.php index 0158354a..6dd08705 100644 --- a/tests/Feature/Invoice/ShowPdfTest.php +++ b/tests/Feature/Invoice/ShowPdfTest.php @@ -4,10 +4,10 @@ namespace Tests\Feature\Invoice; use App\Invoice\BillDocument; use App\Invoice\BillKind; -use App\Invoice\InvoiceSettings; use App\Invoice\Models\Invoice; use App\Invoice\Models\InvoicePosition; use Illuminate\Foundation\Testing\DatabaseTransactions; +use Modules\Invoice\InvoiceSettings; use Tests\TestCase; use Zoomyboy\Tex\Tex; diff --git a/tests/Feature/Invoice/ShowRememberpdfTest.php b/tests/Feature/Invoice/ShowRememberpdfTest.php index bf198126..73797f1c 100644 --- a/tests/Feature/Invoice/ShowRememberpdfTest.php +++ b/tests/Feature/Invoice/ShowRememberpdfTest.php @@ -3,11 +3,11 @@ namespace Tests\Feature\Invoice; use App\Invoice\BillKind; -use App\Invoice\InvoiceSettings; use App\Invoice\Models\Invoice; use App\Invoice\Models\InvoicePosition; use App\Invoice\RememberDocument; use Illuminate\Foundation\Testing\DatabaseTransactions; +use Modules\Invoice\InvoiceSettings; use Tests\TestCase; use Zoomyboy\Tex\Tex; diff --git a/tests/Feature/Member/PreventionTest.php b/tests/Feature/Member/PreventionTest.php index 6a277c67..ae59345c 100644 --- a/tests/Feature/Member/PreventionTest.php +++ b/tests/Feature/Member/PreventionTest.php @@ -8,7 +8,6 @@ use App\Form\Enums\NamiType; use App\Form\Enums\SpecialType; use App\Form\Models\Form; use App\Form\Models\Participant; -use App\Invoice\InvoiceSettings; use App\Lib\Editor\Condition; use App\Prevention\Mails\PreventionRememberMail; use App\Member\Member; @@ -17,6 +16,7 @@ use App\Prevention\PreventionSettings; use Generator; use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Support\Facades\Mail; +use Modules\Invoice\InvoiceSettings; use PHPUnit\Framework\Attributes\DataProvider; use Tests\Lib\CreatesFormFields; use Tests\RequestFactories\EditorRequestFactory; diff --git a/tests/RequestFactories/InvoiceSettingsFake.php b/tests/RequestFactories/InvoiceSettingsFake.php index a0ee76fd..6b79068c 100644 --- a/tests/RequestFactories/InvoiceSettingsFake.php +++ b/tests/RequestFactories/InvoiceSettingsFake.php @@ -19,6 +19,7 @@ class InvoiceSettingsFake extends RequestFactory 'zip' => '12345', 'iban' => 'DE444', 'bic' => 'SOLSSSSS', + 'rememberWeeks' => 6 ]; } }