Build the stuff for payments.
This commit is contained in:
@@ -38,8 +38,6 @@ class Invoice extends Model
|
||||
|
||||
/**
|
||||
* Get the invoice state as translated string.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getLocalizedStateAttribute(): string
|
||||
{
|
||||
@@ -56,35 +54,57 @@ class Invoice extends Model
|
||||
|
||||
/**
|
||||
* Get the created_at attribute in local time format.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCreatedAttribute(): string
|
||||
{
|
||||
return $this->created_at->format('d.m.Y');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the user, that has created the invoice.
|
||||
*/
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the invoice's customer.
|
||||
*/
|
||||
public function customer(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Customer::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the invoice's address.
|
||||
*/
|
||||
public function address(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Address::class)->withTrashed();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the invoice's delivery address.
|
||||
*/
|
||||
public function delivery(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Address::class)->withTrashed();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the items (invoice positions) of this invoice.
|
||||
*/
|
||||
public function items(): HasMany
|
||||
{
|
||||
return $this->hasMany(Invoiceitem::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the payments for the invoice
|
||||
*/
|
||||
public function payments(): HasMany
|
||||
{
|
||||
return $this->hasMany(Payment::class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user