vat_wms/app/Models/StockBatch.php
2025-06-02 07:36:24 +02:00

80 lines
1.6 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
class StockBatch extends Model
{
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'stock_batch';
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'user_id',
'supplier_id',
'tracking_number',
'arrival_date',
];
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
'arrival_date' => 'datetime',
'created_at' => 'datetime',
'updated_at' => 'datetime',
];
/**
* Get the user that owns the stock batch.
*/
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
/**
* Get the supplier for the stock batch.
*/
public function supplier(): BelongsTo
{
return $this->belongsTo(Supplier::class);
}
public function stockEntries(): HasMany
{
return $this->hasMany(StockEntry::class);
}
public function files()
{
return $this->hasMany(StockBatchFile::class)->select([
'id',
'filename',
'file_type',
'stock_batch_id',
'user_id',
'created_at',
'updated_at',
]);
}
public function statusHistory(): HasMany
{
return $this->hasMany(StockBatchStatusHistory::class, 'stock_batch_id');
}
}