Add via to invoice

This commit is contained in:
Philipp Lang 2023-12-16 11:18:00 +01:00
parent 27cbf8bcd9
commit 58798146d4
9 changed files with 40 additions and 1 deletions

View File

@ -2,6 +2,7 @@
namespace App\Invoice\Actions; namespace App\Invoice\Actions;
use App\Invoice\BillKind;
use App\Invoice\Enums\InvoiceStatus; use App\Invoice\Enums\InvoiceStatus;
use Lorisleiva\Actions\ActionRequest; use Lorisleiva\Actions\ActionRequest;
use Lorisleiva\Actions\Concerns\AsAction; use Lorisleiva\Actions\Concerns\AsAction;
@ -19,6 +20,7 @@ class InvoiceStoreAction
{ {
return [ return [
'status' => ['required', 'string', 'max:255', Rule::in(InvoiceStatus::values())], 'status' => ['required', 'string', 'max:255', Rule::in(InvoiceStatus::values())],
'via' => ['required', 'string', 'max:255', Rule::in(BillKind::values())],
'to' => 'array', 'to' => 'array',
'to.address' => 'required|string|max:255', 'to.address' => 'required|string|max:255',
'to.location' => 'required|string|max:255', 'to.location' => 'required|string|max:255',
@ -43,6 +45,7 @@ class InvoiceStoreAction
'to.zip' => 'PLZ', 'to.zip' => 'PLZ',
'to.location' => 'Ort', 'to.location' => 'Ort',
'status' => 'Status', 'status' => 'Status',
'via' => 'Rechnungsweg',
]; ];
} }

View File

@ -2,6 +2,7 @@
namespace App\Invoice\Models; namespace App\Invoice\Models;
use App\Invoice\BillKind;
use App\Invoice\Enums\InvoiceStatus; use App\Invoice\Enums\InvoiceStatus;
use App\Member\Member; use App\Member\Member;
use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Factories\HasFactory;
@ -17,8 +18,10 @@ class Invoice extends Model
public $casts = [ public $casts = [
'to' => 'json', 'to' => 'json',
'status' => InvoiceStatus::class, 'status' => InvoiceStatus::class,
'via' => BillKind::class,
]; ];
/** @var array<int, string> */
public $dates = [ public $dates = [
'sent_at', 'sent_at',
]; ];
@ -42,6 +45,7 @@ class Invoice extends Model
], ],
'greeting' => 'Liebe Familie ' . $member->lastname, 'greeting' => 'Liebe Familie ' . $member->lastname,
'status' => InvoiceStatus::NEW, 'status' => InvoiceStatus::NEW,
'via' => $member->bill_kind,
]); ]);
} }
} }

View File

@ -27,6 +27,7 @@ class InvoiceResource extends JsonResource
'sum_human' => number_format($this->positions->sum('price') / 100, 2, ',', '') . ' €', 'sum_human' => number_format($this->positions->sum('price') / 100, 2, ',', '') . ' €',
'sent_at_human' => $this->sent_at->format('d.m.Y'), 'sent_at_human' => $this->sent_at->format('d.m.Y'),
'status' => $this->status->value, 'status' => $this->status->value,
'via' => $this->via->value,
]; ];
} }

View File

@ -2,6 +2,7 @@
namespace Database\Factories\Invoice\Models; namespace Database\Factories\Invoice\Models;
use App\Invoice\BillKind;
use App\Invoice\Enums\InvoiceStatus; use App\Invoice\Enums\InvoiceStatus;
use App\Invoice\Models\Invoice; use App\Invoice\Models\Invoice;
use Carbon\Carbon; use Carbon\Carbon;
@ -41,4 +42,9 @@ class InvoiceFactory extends Factory
{ {
return $this->state(['status' => $status->value]); return $this->state(['status' => $status->value]);
} }
public function via(BillKind $via): self
{
return $this->state(['via' => $via->value]);
}
} }

View File

@ -19,6 +19,7 @@ return new class extends Migration
$table->string('greeting'); $table->string('greeting');
$table->string('status'); $table->string('status');
$table->date('sent_at')->nullable(); $table->date('sent_at')->nullable();
$table->string('via');
$table->timestamps(); $table->timestamps();
}); });

View File

@ -2,6 +2,7 @@
namespace Tests\Feature\Invoice; namespace Tests\Feature\Invoice;
use App\Invoice\BillKind;
use App\Invoice\Enums\InvoiceStatus; use App\Invoice\Enums\InvoiceStatus;
use App\Invoice\Models\Invoice; use App\Invoice\Models\Invoice;
use App\Invoice\Models\InvoicePosition; use App\Invoice\Models\InvoicePosition;
@ -21,6 +22,7 @@ class InvoiceIndexActionTest extends TestCase
->has(InvoicePosition::factory()->price(2200), 'positions') ->has(InvoicePosition::factory()->price(2200), 'positions')
->to(ReceiverRequestFactory::new()->name('Familie Blabla')) ->to(ReceiverRequestFactory::new()->name('Familie Blabla'))
->sentAt(now()->subDay()) ->sentAt(now()->subDay())
->via(BillKind::POST)
->status(InvoiceStatus::SENT) ->status(InvoiceStatus::SENT)
->create(); ->create();
@ -29,6 +31,7 @@ class InvoiceIndexActionTest extends TestCase
->assertInertiaPath('data.data.0.sum_human', '33,00 €') ->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.sent_at_human', now()->subDay()->format('d.m.Y'))
->assertInertiaPath('data.data.0.status', 'Rechnung gestellt') ->assertInertiaPath('data.data.0.status', 'Rechnung gestellt')
->assertInertiaPath('data.data.0.via', 'Post')
->assertInertiaPath('data.meta.links.mass-store', route('invoice.mass-store')); ->assertInertiaPath('data.meta.links.mass-store', route('invoice.mass-store'));
} }
} }

View File

@ -2,8 +2,8 @@
namespace Tests\Feature\Invoice; namespace Tests\Feature\Invoice;
use App\Invoice\BillKind;
use App\Invoice\Enums\InvoiceStatus; use App\Invoice\Enums\InvoiceStatus;
use App\Member\Member;
use Worksome\RequestFactories\RequestFactory; use Worksome\RequestFactories\RequestFactory;
class InvoiceRequestFactory extends RequestFactory class InvoiceRequestFactory extends RequestFactory
@ -33,4 +33,9 @@ class InvoiceRequestFactory extends RequestFactory
$factory->create(), $factory->create(),
]]); ]]);
} }
public function via(BillKind $via): self
{
return $this->state(['via' => $via->value]);
}
} }

View File

@ -2,6 +2,7 @@
namespace Tests\Feature\Invoice; namespace Tests\Feature\Invoice;
use App\Invoice\BillKind;
use App\Invoice\Enums\InvoiceStatus; use App\Invoice\Enums\InvoiceStatus;
use App\Invoice\Models\Invoice; use App\Invoice\Models\Invoice;
use App\Member\Member; 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')) ->to(ReceiverRequestFactory::new()->name('Familie Blabla')->address('Musterstr 44')->zip('22222')->location('Solingen'))
->position(InvoicePositionRequestFactory::new()->description('Beitrag Abc')->price(3250)->member($member)) ->position(InvoicePositionRequestFactory::new()->description('Beitrag Abc')->price(3250)->member($member))
->status(InvoiceStatus::PAID) ->status(InvoiceStatus::PAID)
->via(BillKind::POST)
->state([ ->state([
'greeting' => 'Hallo Familie', 'greeting' => 'Hallo Familie',
]) ])
@ -34,6 +36,7 @@ class InvoiceStoreActionTest extends TestCase
$response->assertOk(); $response->assertOk();
$this->assertDatabaseHas('invoices', [ $this->assertDatabaseHas('invoices', [
'greeting' => 'Hallo Familie', 'greeting' => 'Hallo Familie',
'via' => BillKind::POST->value,
'status' => InvoiceStatus::PAID->value, 'status' => InvoiceStatus::PAID->value,
]); ]);
$invoice = Invoice::firstWhere('greeting', 'Hallo Familie'); $invoice = Invoice::firstWhere('greeting', 'Hallo Familie');
@ -82,6 +85,16 @@ class InvoiceStoreActionTest extends TestCase
['to.zip' => ''], ['to.zip' => ''],
['to.zip' => 'PLZ ist erforderlich.'] ['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() InvoiceRequestFactory::new()
->to(ReceiverRequestFactory::new()) ->to(ReceiverRequestFactory::new())
->position(InvoicePositionRequestFactory::new()->member(Member::factory()->defaults()->create())) ->position(InvoicePositionRequestFactory::new()->member(Member::factory()->defaults()->create()))
->via(BillKind::POST)
->state($input) ->state($input)
->create() ->create()
); );

View File

@ -2,6 +2,7 @@
namespace Tests\Feature\Invoice; namespace Tests\Feature\Invoice;
use App\Invoice\BillKind;
use App\Invoice\Models\Invoice; use App\Invoice\Models\Invoice;
use App\Member\Member; use App\Member\Member;
use App\Payment\Subscription; use App\Payment\Subscription;
@ -62,6 +63,7 @@ class MassStoreActionTest extends TestCase
'zip' => '33445', 'zip' => '33445',
'location' => 'Solingen', 'location' => 'Solingen',
], $invoice->to); ], $invoice->to);
$this->assertEquals(BillKind::EMAIL, $invoice->via);
$this->assertDatabaseHas('invoice_positions', [ $this->assertDatabaseHas('invoice_positions', [
'invoice_id' => $invoice->id, 'invoice_id' => $invoice->id,
'member_id' => $member->id, 'member_id' => $member->id,