star-cloud/app/Traits/HasDisplayFlowId.php
sky121113 ae4556584f [FEAT] 銷售紀錄流水號顯示剝除機台序號前綴
1. 新增 HasDisplayFlowId trait,提供 display_flow_id accessor:僅顯示時剝除 flow_id 開頭的機台序號前綴,DB 仍存完整 serial+flow_id 唯一值供去重/冪等/對帳判斷。
2. Order 與 Invoice 兩 Model 套用此 trait。
3. 訂單詳情面板 (order-detail-panel) 與發票匯出 (SalesController) 改顯示 display_flow_id,呈現乾淨易讀的機台流水號。
4. accessor 具防禦性:機台關聯為 null 或舊的未前綴資料皆原樣顯示,不誤剝。
5. 新增測試驗證 display_flow_id 正確剝除序號前綴且 DB 值維持完整。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-19 09:16:13 +08:00

29 lines
1011 B
PHP
Raw Permalink 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\Traits;
/**
* 提供「給人看的 flow_id」accessor去掉機台序號前綴顯示乾淨易讀的機台流水號。
*
* 資料庫仍儲存完整的 `serial_no . flow_id`(全域唯一值),供後台去重 / 冪等 / 對帳判斷使用;
* 此 accessor 只用於畫面與匯出顯示,不改動任何 DB 值。
*
* flow_id 格式serial_no . YYYYMMDDHHMMSSXXXX無分隔符
* 套用此 trait 的 Model 需具備 `flow_id` 欄位與 `machine`(含 serial_no關聯。
*/
trait HasDisplayFlowId
{
public function getDisplayFlowIdAttribute(): string
{
$flowId = (string) ($this->flow_id ?? '');
$serial = $this->machine?->serial_no;
// 僅在確實以該機台序號開頭時才剝除前綴;舊的未前綴資料原樣顯示(防禦)。
if ($serial !== null && $serial !== '' && str_starts_with($flowId, $serial)) {
return substr($flowId, strlen($serial));
}
return $flowId;
}
}