feat: 修正庫存與撥補單邏輯並整合文件
1. 修復倉庫統計數據加總與樣式。 2. 修正可用庫存計算邏輯(排除不可銷售倉庫)。 3. 撥補單商品列表加入批號與效期顯示。 4. 修正撥補單儲存邏輯以支援精確批號轉移。 5. 整合 FEATURES.md 至 README.md。
This commit is contained in:
@@ -14,7 +14,7 @@ use Illuminate\Support\Facades\Hash;
|
||||
class UserController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
* 顯示資源列表。
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
@@ -26,7 +26,7 @@ class UserController extends Controller
|
||||
|
||||
$query = User::with(['roles:id,name,display_name']);
|
||||
|
||||
// Handle Search
|
||||
// 處理搜尋
|
||||
if ($search) {
|
||||
$query->where(function ($q) use ($search) {
|
||||
$q->where('name', 'like', "%{$search}%")
|
||||
@@ -35,14 +35,14 @@ class UserController extends Controller
|
||||
});
|
||||
}
|
||||
|
||||
// Handle Role Filter
|
||||
// 處理角色篩選
|
||||
if ($roleId && $roleId !== 'all') {
|
||||
$query->whereHas('roles', function ($q) use ($roleId) {
|
||||
$q->where('id', $roleId);
|
||||
});
|
||||
}
|
||||
|
||||
// Handle sorting
|
||||
// 處理排序
|
||||
if (in_array($sortBy, ['name', 'created_at'])) {
|
||||
$query->orderBy($sortBy, $sortOrder);
|
||||
} else {
|
||||
@@ -60,7 +60,7 @@ class UserController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
* 顯示建立新資源的表單。
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
@@ -72,7 +72,7 @@ class UserController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
* 將新建立的資源儲存到儲存體中。
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
@@ -98,7 +98,7 @@ class UserController extends Controller
|
||||
if (!empty($validated['roles'])) {
|
||||
$user->syncRoles($validated['roles']);
|
||||
|
||||
// Update the 'created' log to include roles
|
||||
// 更新 'created' 紀錄以包含角色資訊
|
||||
$activity = \Spatie\Activitylog\Models\Activity::where('subject_type', get_class($user))
|
||||
->where('subject_id', $user->id)
|
||||
->where('event', 'created')
|
||||
@@ -118,7 +118,7 @@ class UserController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
* 顯示編輯指定資源的表單。
|
||||
*/
|
||||
public function edit(string $id)
|
||||
{
|
||||
@@ -133,7 +133,7 @@ class UserController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
* 更新儲存體中的指定資源。
|
||||
*/
|
||||
public function update(Request $request, string $id)
|
||||
{
|
||||
@@ -150,7 +150,7 @@ class UserController extends Controller
|
||||
'password.confirmed' => '密碼確認不符',
|
||||
]);
|
||||
|
||||
// 1. Prepare data and detect changes
|
||||
// 1. 準備資料並偵測變更
|
||||
$userData = [
|
||||
'name' => $validated['name'],
|
||||
'email' => $validated['email'],
|
||||
@@ -163,7 +163,7 @@ class UserController extends Controller
|
||||
|
||||
$user->fill($userData);
|
||||
|
||||
// Capture dirty attributes for manual logging
|
||||
// 捕捉變更屬性以進行手動記錄
|
||||
$dirty = $user->getDirty();
|
||||
$oldAttributes = [];
|
||||
$newAttributes = [];
|
||||
@@ -173,10 +173,10 @@ class UserController extends Controller
|
||||
$newAttributes[$key] = $value;
|
||||
}
|
||||
|
||||
// Save without triggering events (prevents duplicate log)
|
||||
// 儲存但不觸發事件(防止重複記錄)
|
||||
$user->saveQuietly();
|
||||
|
||||
// 2. Handle Roles
|
||||
// 2. 處理角色
|
||||
$roleChanges = null;
|
||||
if (isset($validated['roles'])) {
|
||||
$oldRoles = $user->roles()->pluck('display_name')->join(', ');
|
||||
@@ -191,7 +191,7 @@ class UserController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
// 3. Manually Log activity (Single Consolidated Log)
|
||||
// 3. 手動記錄活動(單一整合記錄)
|
||||
if (!empty($newAttributes) || $roleChanges) {
|
||||
$properties = [
|
||||
'attributes' => $newAttributes,
|
||||
@@ -209,7 +209,7 @@ class UserController extends Controller
|
||||
->event('updated')
|
||||
->withProperties($properties)
|
||||
->tap(function (\Spatie\Activitylog\Contracts\Activity $activity) use ($user) {
|
||||
// Manually add snapshot since we aren't using the model's LogOptions due to saveQuietly
|
||||
// 手動加入快照,因為使用 saveQuietly 所以不使用模型的 LogOptions
|
||||
$activity->properties = $activity->properties->merge([
|
||||
'snapshot' => [
|
||||
'name' => $user->name,
|
||||
@@ -224,7 +224,7 @@ class UserController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
* 從儲存體中移除指定資源。
|
||||
*/
|
||||
public function destroy(string $id)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user