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;
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',
];
}

View File

@ -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<int, string> */
public $dates = [
'sent_at',
];
@ -42,6 +45,7 @@ class Invoice extends Model
],
'greeting' => 'Liebe Familie ' . $member->lastname,
'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, ',', '') . ' €',
'sent_at_human' => $this->sent_at->format('d.m.Y'),
'status' => $this->status->value,
'via' => $this->via->value,
];
}

View File

@ -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]);
}
}

View File

@ -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();
});

View File

@ -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'));
}
}

View File

@ -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]);
}
}

View File

@ -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()
);

View File

@ -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,