2025-12-30 15:03:19 +08:00
|
|
|
<?php
|
|
|
|
|
|
2026-01-26 10:37:47 +08:00
|
|
|
namespace App\Modules\Inventory\Models;
|
2025-12-30 15:03:19 +08:00
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2026-01-26 10:37:47 +08:00
|
|
|
use App\Modules\Procurement\Models\PurchaseOrder; // Cross-module dependency (Procurement)
|
2025-12-30 15:03:19 +08:00
|
|
|
|
|
|
|
|
class Warehouse extends Model
|
|
|
|
|
{
|
|
|
|
|
/** @use HasFactory<\Database\Factories\WarehouseFactory> */
|
|
|
|
|
use HasFactory;
|
2026-01-19 11:47:10 +08:00
|
|
|
use \Spatie\Activitylog\Traits\LogsActivity;
|
2025-12-30 15:03:19 +08:00
|
|
|
|
|
|
|
|
protected $fillable = [
|
|
|
|
|
'code',
|
|
|
|
|
'name',
|
|
|
|
|
'address',
|
|
|
|
|
'description',
|
|
|
|
|
];
|
|
|
|
|
|
2026-01-19 11:47:10 +08:00
|
|
|
public function getActivitylogOptions(): \Spatie\Activitylog\LogOptions
|
|
|
|
|
{
|
|
|
|
|
return \Spatie\Activitylog\LogOptions::defaults()
|
|
|
|
|
->logAll()
|
|
|
|
|
->logOnlyDirty()
|
|
|
|
|
->dontSubmitEmptyLogs();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function tapActivity(\Spatie\Activitylog\Contracts\Activity $activity, string $eventName)
|
|
|
|
|
{
|
|
|
|
|
$properties = $activity->properties;
|
2026-01-19 15:32:41 +08:00
|
|
|
|
|
|
|
|
$snapshot = $properties['snapshot'] ?? [];
|
|
|
|
|
$snapshot['name'] = $this->name;
|
|
|
|
|
$properties['snapshot'] = $snapshot;
|
2026-01-19 11:47:10 +08:00
|
|
|
|
|
|
|
|
$activity->properties = $properties;
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-30 15:03:19 +08:00
|
|
|
public function inventories(): \Illuminate\Database\Eloquent\Relations\HasMany
|
|
|
|
|
{
|
|
|
|
|
return $this->hasMany(Inventory::class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function purchaseOrders(): \Illuminate\Database\Eloquent\Relations\HasMany
|
|
|
|
|
{
|
|
|
|
|
return $this->hasMany(PurchaseOrder::class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function products(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsToMany(Product::class, 'inventories')
|
|
|
|
|
->withPivot(['quantity', 'safety_stock', 'location'])
|
|
|
|
|
->withTimestamps();
|
|
|
|
|
}
|
|
|
|
|
}
|