Build the stuff for payments.

This commit is contained in:
2025-01-16 15:34:10 +01:00
parent f120559e3b
commit dcedbc71c4
17 changed files with 670 additions and 31 deletions

View File

@@ -3,9 +3,58 @@
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Support\Facades\Date;
class Payment extends Model
{
use SoftDeletes;
public $timestamps = false;
/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'invoice_id',
'paid_amount',
'status',
'payment_method',
'payment_date',
];
/**
* The attributes that are appended with attribute getters.
*
* @var string[]
*/
protected $appends = [
'date',
'localized_state'
];
/**
* Get the payment state as translated string.
*/
public function getLocalizedStateAttribute(): string
{
return __('invoice.Payment state ' . $this->status);
}
/**
* Get the payment date as localized string.
*/
public function getDateAttribute(): string
{
return Date::createFromFormat('Y-m-d', $this->payment_date)->format('d.m.Y');
}
/**
* Get the invoice the payment belongs to.
*/
public function invoice(): BelongsTo
{
return $this->belongsTo(Invoice::class);
}
}