2023-12-13 00:35:39 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Invoice\Models;
|
|
|
|
|
2023-12-16 00:16:07 +01:00
|
|
|
use App\Invoice\Enums\InvoiceStatus;
|
|
|
|
use App\Member\Member;
|
2023-12-13 00:35:39 +01:00
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
|
|
|
|
|
|
class Invoice extends Model
|
|
|
|
{
|
|
|
|
use HasFactory;
|
|
|
|
|
|
|
|
public $guarded = [];
|
|
|
|
|
|
|
|
public $casts = [
|
|
|
|
'to' => 'json',
|
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return HasMany<InvoicePosition>
|
|
|
|
*/
|
|
|
|
public function positions(): HasMany
|
|
|
|
{
|
|
|
|
return $this->hasMany(InvoicePosition::class);
|
|
|
|
}
|
2023-12-16 00:16:07 +01:00
|
|
|
|
|
|
|
public static function createForMember(Member $member): self
|
|
|
|
{
|
|
|
|
return static::create([
|
|
|
|
'to' => [
|
|
|
|
'name' => 'Familie ' . $member->lastname,
|
|
|
|
'address' => $member->address,
|
|
|
|
'zip' => $member->zip,
|
|
|
|
'location' => $member->location,
|
|
|
|
],
|
|
|
|
'greeting' => 'Liebe Familie ' . $member->lastname,
|
|
|
|
'status' => InvoiceStatus::NEW,
|
|
|
|
]);
|
|
|
|
}
|
2023-12-13 00:35:39 +01:00
|
|
|
}
|