vat_wms/app/Models/StockEntry.php
2025-05-13 12:32:55 +02:00

90 lines
2.0 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
class StockEntry extends Model
{
use HasFactory;
/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'physical_item_id',
'supplier_id',
'count',
'price',
'bought',
'description',
'note',
'stock_position_id',
'country_of_origin_id',
'on_the_way',
'stock_batch_id',
'created_by',
'updated_by',
];
/**
* The attributes that should be cast.
*
* @var array<string, string>
*/
protected $casts = [
'bought' => 'date',
'on_the_way' => 'boolean',
];
/**
* Get the physical item associated with the stock entry.
*/
public function physicalItem(): BelongsTo
{
return $this->belongsTo(PhysicalItem::class, 'physical_item_id')->on('vat_warehouse');
}
/**
* Get the supplier associated with the stock entry.
*/
public function supplier(): BelongsTo
{
return $this->belongsTo(Supplier::class, 'supplier_id')->on('vat_warehouse');
}
/**
* Get the stock position associated with the stock entry.
*/
public function stockPosition(): BelongsTo
{
return $this->belongsTo(StockPosition::class);
}
/**
* Get the stock batch associated with the stock entry.
*/
public function stockBatch(): BelongsTo
{
return $this->belongsTo(StockBatch::class);
}
/**
* Get the attributes for this stock entry.
*/
public function attributes(): BelongsToMany
{
return $this->belongsToMany(
StockAttributes::class,
'stock_entry2attributes',
'stock_entry_id',
'stock_attributes_id'
)->withPivot('stock_attribute_value_id');
}
}