diff --git a/app/Invoice/Actions/InvoiceStoreAction.php b/app/Invoice/Actions/InvoiceStoreAction.php index deb4a7ea..3869cb90 100644 --- a/app/Invoice/Actions/InvoiceStoreAction.php +++ b/app/Invoice/Actions/InvoiceStoreAction.php @@ -2,6 +2,7 @@ namespace App\Invoice\Actions; +use App\Invoice\BillKind; use App\Invoice\Enums\InvoiceStatus; use Lorisleiva\Actions\ActionRequest; use Lorisleiva\Actions\Concerns\AsAction; @@ -19,6 +20,7 @@ class InvoiceStoreAction { return [ 'status' => ['required', 'string', 'max:255', Rule::in(InvoiceStatus::values())], + 'via' => ['required', 'string', 'max:255', Rule::in(BillKind::values())], 'to' => 'array', 'to.address' => 'required|string|max:255', 'to.location' => 'required|string|max:255', @@ -43,6 +45,7 @@ class InvoiceStoreAction 'to.zip' => 'PLZ', 'to.location' => 'Ort', 'status' => 'Status', + 'via' => 'Rechnungsweg', ]; } diff --git a/app/Invoice/Models/Invoice.php b/app/Invoice/Models/Invoice.php index d2cc9840..4098b9a0 100644 --- a/app/Invoice/Models/Invoice.php +++ b/app/Invoice/Models/Invoice.php @@ -2,6 +2,7 @@ namespace App\Invoice\Models; +use App\Invoice\BillKind; use App\Invoice\Enums\InvoiceStatus; use App\Member\Member; use Illuminate\Database\Eloquent\Factories\HasFactory; @@ -17,8 +18,10 @@ class Invoice extends Model public $casts = [ 'to' => 'json', 'status' => InvoiceStatus::class, + 'via' => BillKind::class, ]; + /** @var array */ public $dates = [ 'sent_at', ]; @@ -42,6 +45,7 @@ class Invoice extends Model ], 'greeting' => 'Liebe Familie ' . $member->lastname, 'status' => InvoiceStatus::NEW, + 'via' => $member->bill_kind, ]); } } diff --git a/app/Invoice/Resources/InvoiceResource.php b/app/Invoice/Resources/InvoiceResource.php index 68f323f2..285fae43 100644 --- a/app/Invoice/Resources/InvoiceResource.php +++ b/app/Invoice/Resources/InvoiceResource.php @@ -27,6 +27,7 @@ class InvoiceResource extends JsonResource 'sum_human' => number_format($this->positions->sum('price') / 100, 2, ',', '') . ' €', 'sent_at_human' => $this->sent_at->format('d.m.Y'), 'status' => $this->status->value, + 'via' => $this->via->value, ]; } diff --git a/database/factories/Invoice/Models/InvoiceFactory.php b/database/factories/Invoice/Models/InvoiceFactory.php index fc98e66f..b5b93592 100644 --- a/database/factories/Invoice/Models/InvoiceFactory.php +++ b/database/factories/Invoice/Models/InvoiceFactory.php @@ -2,6 +2,7 @@ namespace Database\Factories\Invoice\Models; +use App\Invoice\BillKind; use App\Invoice\Enums\InvoiceStatus; use App\Invoice\Models\Invoice; use Carbon\Carbon; @@ -41,4 +42,9 @@ class InvoiceFactory extends Factory { return $this->state(['status' => $status->value]); } + + public function via(BillKind $via): self + { + return $this->state(['via' => $via->value]); + } } diff --git a/database/migrations/2023_12_12_015320_create_invoices_table.php b/database/migrations/2023_12_12_015320_create_invoices_table.php index 44b4334b..52814d2c 100644 --- a/database/migrations/2023_12_12_015320_create_invoices_table.php +++ b/database/migrations/2023_12_12_015320_create_invoices_table.php @@ -19,6 +19,7 @@ return new class extends Migration $table->string('greeting'); $table->string('status'); $table->date('sent_at')->nullable(); + $table->string('via'); $table->timestamps(); }); diff --git a/tests/Feature/Invoice/InvoiceIndexActionTest.php b/tests/Feature/Invoice/InvoiceIndexActionTest.php index 42099b40..96cb541f 100644 --- a/tests/Feature/Invoice/InvoiceIndexActionTest.php +++ b/tests/Feature/Invoice/InvoiceIndexActionTest.php @@ -2,6 +2,7 @@ namespace Tests\Feature\Invoice; +use App\Invoice\BillKind; use App\Invoice\Enums\InvoiceStatus; use App\Invoice\Models\Invoice; use App\Invoice\Models\InvoicePosition; @@ -21,6 +22,7 @@ class InvoiceIndexActionTest extends TestCase ->has(InvoicePosition::factory()->price(2200), 'positions') ->to(ReceiverRequestFactory::new()->name('Familie Blabla')) ->sentAt(now()->subDay()) + ->via(BillKind::POST) ->status(InvoiceStatus::SENT) ->create(); @@ -29,6 +31,7 @@ class InvoiceIndexActionTest extends TestCase ->assertInertiaPath('data.data.0.sum_human', '33,00 €') ->assertInertiaPath('data.data.0.sent_at_human', now()->subDay()->format('d.m.Y')) ->assertInertiaPath('data.data.0.status', 'Rechnung gestellt') + ->assertInertiaPath('data.data.0.via', 'Post') ->assertInertiaPath('data.meta.links.mass-store', route('invoice.mass-store')); } } diff --git a/tests/Feature/Invoice/InvoiceRequestFactory.php b/tests/Feature/Invoice/InvoiceRequestFactory.php index ddef2368..5cf3c544 100644 --- a/tests/Feature/Invoice/InvoiceRequestFactory.php +++ b/tests/Feature/Invoice/InvoiceRequestFactory.php @@ -2,8 +2,8 @@ namespace Tests\Feature\Invoice; +use App\Invoice\BillKind; use App\Invoice\Enums\InvoiceStatus; -use App\Member\Member; use Worksome\RequestFactories\RequestFactory; class InvoiceRequestFactory extends RequestFactory @@ -33,4 +33,9 @@ class InvoiceRequestFactory extends RequestFactory $factory->create(), ]]); } + + public function via(BillKind $via): self + { + return $this->state(['via' => $via->value]); + } } diff --git a/tests/Feature/Invoice/InvoiceStoreActionTest.php b/tests/Feature/Invoice/InvoiceStoreActionTest.php index 6fb255dd..ed2b592b 100644 --- a/tests/Feature/Invoice/InvoiceStoreActionTest.php +++ b/tests/Feature/Invoice/InvoiceStoreActionTest.php @@ -2,6 +2,7 @@ namespace Tests\Feature\Invoice; +use App\Invoice\BillKind; use App\Invoice\Enums\InvoiceStatus; use App\Invoice\Models\Invoice; use App\Member\Member; @@ -25,6 +26,7 @@ class InvoiceStoreActionTest extends TestCase ->to(ReceiverRequestFactory::new()->name('Familie Blabla')->address('Musterstr 44')->zip('22222')->location('Solingen')) ->position(InvoicePositionRequestFactory::new()->description('Beitrag Abc')->price(3250)->member($member)) ->status(InvoiceStatus::PAID) + ->via(BillKind::POST) ->state([ 'greeting' => 'Hallo Familie', ]) @@ -34,6 +36,7 @@ class InvoiceStoreActionTest extends TestCase $response->assertOk(); $this->assertDatabaseHas('invoices', [ 'greeting' => 'Hallo Familie', + 'via' => BillKind::POST->value, 'status' => InvoiceStatus::PAID->value, ]); $invoice = Invoice::firstWhere('greeting', 'Hallo Familie'); @@ -82,6 +85,16 @@ class InvoiceStoreActionTest extends TestCase ['to.zip' => ''], ['to.zip' => 'PLZ ist erforderlich.'] ]; + + yield [ + ['via' => ''], + ['via' => 'Rechnungsweg ist erforderlich.'] + ]; + + yield [ + ['via' => 'lala'], + ['via' => 'Der gewählte Wert für Rechnungsweg ist ungültig.'] + ]; } /** @@ -98,6 +111,7 @@ class InvoiceStoreActionTest extends TestCase InvoiceRequestFactory::new() ->to(ReceiverRequestFactory::new()) ->position(InvoicePositionRequestFactory::new()->member(Member::factory()->defaults()->create())) + ->via(BillKind::POST) ->state($input) ->create() ); diff --git a/tests/Feature/Invoice/MassStoreActionTest.php b/tests/Feature/Invoice/MassStoreActionTest.php index 838cb530..04efa52e 100644 --- a/tests/Feature/Invoice/MassStoreActionTest.php +++ b/tests/Feature/Invoice/MassStoreActionTest.php @@ -2,6 +2,7 @@ namespace Tests\Feature\Invoice; +use App\Invoice\BillKind; use App\Invoice\Models\Invoice; use App\Member\Member; use App\Payment\Subscription; @@ -62,6 +63,7 @@ class MassStoreActionTest extends TestCase 'zip' => '33445', 'location' => 'Solingen', ], $invoice->to); + $this->assertEquals(BillKind::EMAIL, $invoice->via); $this->assertDatabaseHas('invoice_positions', [ 'invoice_id' => $invoice->id, 'member_id' => $member->id,