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

@@ -41,6 +41,11 @@ class StoreRequisition extends Model
->dontSubmitEmptyLogs();
}
/**
* @var array 暫存的活動紀錄屬性 (不會存入資料庫)
*/
public $activityProperties = [];
/**
* 自定義日誌屬性,解析 ID 為名稱
*/
@@ -48,22 +53,90 @@ class StoreRequisition extends Model
{
$properties = $activity->properties->toArray();
// 處置日誌事件與狀態中文化
$statusMap = [
'draft' => '草稿',
'pending' => '待審核',
'approved' => '已核准',
'rejected' => '已駁回',
'completed' => '已完成',
];
// 處理 ID 轉名稱
$idToNameFields = [
'store_warehouse_id' => 'storeWarehouse',
'supply_warehouse_id' => 'supplyWarehouse',
'created_by' => 'createdBy',
'approved_by' => 'approvedBy',
'transfer_order_id' => 'transferOrder',
];
foreach (['attributes', 'old'] as $part) {
if (isset($properties[$part])) {
// 1. 解析狀態中文並替換原始 status 欄位
if (isset($properties[$part]['status'])) {
$statusValue = $properties[$part]['status'];
$properties[$part]['status'] = $statusMap[$statusValue] ?? $statusValue;
}
// 2. 解析關連名稱
foreach ($idToNameFields as $idField => $relation) {
if (isset($properties[$part][$idField])) {
$id = $properties[$part][$idField];
if (!$id) continue;
$nameField = str_replace('_id', '_name', $idField);
if (str_contains($idField, '_by')) {
$nameField = str_replace('_by', '_user_name', $idField);
}
$name = null;
try {
if ($this->relationLoaded($relation) && $this->$relation && $this->$relation->id == $id) {
// 特別處理調撥單號
$name = ($relation === 'transferOrder') ? $this->$relation->doc_no : $this->$relation->name;
} else {
$relatedModel = $this->$relation()->getRelated();
$model = $relatedModel->find($id);
if ($model) {
$name = ($relation === 'transferOrder') ? ($model->doc_no ?? "ID: $id") : ($model->name ?? "ID: $id");
} else {
$name = "ID: $id";
}
}
} catch (\Exception $e) {
$name = "ID: $id";
}
$properties[$part][$nameField] = $name;
// 移除原生的技術 ID 欄位,讓詳情更乾淨
unset($properties[$part][$idField]);
}
}
}
}
// 基本單據資訊快照
$properties['snapshot'] = [
'doc_no' => $this->doc_no,
'store_warehouse_name' => $this->storeWarehouse?->name,
'supply_warehouse_name' => $this->supplyWarehouse?->name,
'status' => $this->status,
'status' => $statusMap[$this->status] ?? $this->status,
];
// 移除雜訊欄位
// 移除雜訊與重複欄位
if (isset($properties['attributes'])) {
unset($properties['attributes']['updated_at']);
unset($properties['attributes']['activityProperties']);
}
if (isset($properties['old'])) {
unset($properties['old']['updated_at']);
}
// 合併暫存屬性 (例如 items_diff)
if (!empty($this->activityProperties)) {
$properties = array_merge($properties, $this->activityProperties);
}
$activity->properties = collect($properties);
}