Files
project/app/Models/Incoming.php
2025-02-13 17:13:20 +01:00

95 lines
2.1 KiB
PHP

<?php
namespace App\Models;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
class Incoming extends Model
{
public $timestamps = false;
/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'supplier_id',
'invoice_number',
'issue_date',
'due_date',
'invoice_type_code',
'currency_code',
'net',
'gross',
'tax',
'pay_date',
'pay_name',
'pay_bic',
'pay_iban',
];
/**
* The attributes that are appended with attribute getters.
*
* @var string[]
*/
protected $appends = [
'created',
'paid',
'due',
];
/**
* Get the pay_date attribute in local time format.
*/
public function getDueAttribute(): string
{
return (is_null($this->due_date)) ? '' : Carbon::createFromFormat('Y-m-d', $this->due_date)->format('d.m.Y');
}
/**
* Get the pay_date attribute in local time format.
*/
public function getPaidAttribute(): string
{
return (is_null($this->pay_date)) ? '' : Carbon::createFromFormat('Y-m-d', $this->pay_date)->format('d.m.Y');
}
/**
* Get the issue_date attribute in local time format.
*/
public function getCreatedAttribute(): string
{
return Carbon::createFromFormat('Y-m-d', $this->issue_date)->format('d.m.Y');
}
/**
* Get the supplier of the incoming invoice.
*/
public function supplier(): BelongsTo
{
return $this->belongsTo(Supplier::class)->withTrashed();
}
/**
* Get the items (invoice positions) of this incoming invoice.
*/
public function items(): HasMany
{
return $this->hasMany(Incomingitem::class);
}
/**
* Get the tax subtotals for the incoming invoice.
*/
public function taxes(): HasMany
{
return $this->hasMany(Incomingtax::class);
}
}