star-cloud/app/Models/Warehouse/Warehouse.php
sky121113 39a246d3c5 [FEAT] 倉儲管理模組標準化與庫存矩陣功能實作
1. 實作「目前庫存」矩陣化視圖:將商品作為行、倉庫作為列,支援跨倉庫水位分析與自動加總。
2. 優化矩陣 UI:實作固定欄位 (Sticky Columns) 以應對多倉庫場景,並修正深色模式下的背景色對齊問題。
3. 強化倉儲操作驗證:實作調撥與補貨單的 Alpine.js 前端欄位驗證與 AJAX 提交邏輯,提升操作流暢度。
4. 優化機台地址定位:實作結構化地址解析與 Nominatim API 對接,提升經緯度自動獲取的準確性。
5. 標準化 UI 組件:更新 Breadcrumbs、刪除確認彈窗與搜尋下拉選單,確保全站視覺一致性。
6. 完善多語系支援:補全倉儲管理、機台設定與 UI 提示的繁體中文翻譯。
7. 增加 Product Model 的 stocks() 關聯,支援高效率的庫存矩陣查詢。
2026-04-23 17:34:22 +08:00

91 lines
1.7 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace App\Models\Warehouse;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use App\Traits\TenantScoped;
class Warehouse extends Model
{
use HasFactory, SoftDeletes, TenantScoped;
protected $fillable = [
'company_id',
'name',
'type',
'address',
'manager_user_id',
'is_active',
];
protected $casts = [
'is_active' => 'boolean',
];
/**
* Scope僅篩選啟用的倉庫
*/
public function scopeActive($query)
{
return $query->where('is_active', true);
}
/**
* Scope僅篩選總倉
*/
public function scopeMain($query)
{
return $query->where('type', 'main');
}
/**
* Scope僅篩選分倉
*/
public function scopeBranch($query)
{
return $query->where('type', 'branch');
}
/**
* 倉庫負責人
*/
public function manager()
{
return $this->belongsTo(\App\Models\System\User::class, 'manager_user_id');
}
/**
* 倉庫庫存(各商品)
*/
public function stocks()
{
return $this->hasMany(WarehouseStock::class);
}
/**
* 庫存異動紀錄
*/
public function movements()
{
return $this->hasMany(StockMovement::class);
}
/**
* 入庫單
*/
public function stockInOrders()
{
return $this->hasMany(StockInOrder::class);
}
/**
* 所屬公司
*/
public function company()
{
return $this->belongsTo(\App\Models\System\Company::class);
}
}