feat: 整合門市領料日誌、API 文件存取、修改庫存與併發編號問題、供應商商品內聯編輯及日誌 UI 優化
All checks were successful
ERP-Deploy-Demo / deploy-demo (push) Successful in 1m0s

This commit is contained in:
2026-03-02 16:42:12 +08:00
parent 7dac2d1f77
commit 0a955fb993
33 changed files with 1424 additions and 853 deletions

View File

@@ -36,21 +36,23 @@ class InventoryTransferOrder extends Model
if ($eventName === 'created') {
$activity->description = 'created';
} elseif ($eventName === 'updated') {
// 如果屬性中有 status 且變更為 completed將描述改為 posted
if (isset($properties['attributes']['status']) && $properties['attributes']['status'] === 'completed') {
$activity->description = 'posted';
$eventName = 'posted'; // 供後續快照邏輯判定
$eventName = 'posted';
} else {
$activity->description = 'updated';
}
}
// 處理倉庫 ID 轉名稱
// 處理 ID 轉名稱 (核心:支援 attributes 與 old 的自動轉換)
$idToNameFields = [
'from_warehouse_id' => 'fromWarehouse',
'to_warehouse_id' => 'toWarehouse',
'transit_warehouse_id' => 'transitWarehouse',
'created_by' => 'createdBy',
'posted_by' => 'postedBy',
'dispatched_by' => 'dispatchedBy',
'received_by' => 'receivedBy',
];
foreach (['attributes', 'old'] as $part) {
@@ -58,14 +60,20 @@ class InventoryTransferOrder extends Model
foreach ($idToNameFields as $idField => $relation) {
if (isset($properties[$part][$idField])) {
$id = $properties[$part][$idField];
$nameField = str_replace('_id', '_name', $idField);
if (!$id) continue;
$nameField = str_replace('_id', '_name', $idField);
$name = null;
if ($this->relationLoaded($relation) && $this->$relation && $this->$relation->id == $id) {
$name = $this->$relation->name;
} else {
$model = $this->$relation()->getRelated()->find($id);
$name = $model ? $model->name : "ID: $id";
try {
if ($this->relationLoaded($relation) && $this->$relation && $this->$relation->id == $id) {
$name = $this->$relation->name;
} else {
$relatedModel = $this->$relation()->getRelated();
$model = $relatedModel->find($id);
$name = $model ? ($model->name ?? $model->display_name ?? "ID: $id") : "ID: $id";
}
} catch (\Exception $e) {
$name = "ID: $id";
}
$properties[$part][$nameField] = $name;
}
@@ -73,7 +81,7 @@ class InventoryTransferOrder extends Model
}
}
// 基本單據資訊快照 (包含單號、來源、目的地)
// 基本單據資訊快照
if (in_array($eventName, ['created', 'updated', 'posted', 'deleted'])) {
$properties['snapshot'] = [
'doc_no' => $this->doc_no,
@@ -85,8 +93,6 @@ class InventoryTransferOrder extends Model
// 移除輔助欄位與雜訊
if (isset($properties['attributes'])) {
unset($properties['attributes']['from_warehouse_name']);
unset($properties['attributes']['to_warehouse_name']);
unset($properties['attributes']['activityProperties']);
unset($properties['attributes']['updated_at']);
}
@@ -94,7 +100,7 @@ class InventoryTransferOrder extends Model
unset($properties['old']['updated_at']);
}
// 合併暫存屬性 (例如 items_diff)
// 合併暫存屬性 (重要:例如 items_diff)
if (!empty($this->activityProperties)) {
$properties = array_merge($properties, $this->activityProperties);
}