*/ public function latestActiveMapByBagCode(int $lgIdx): array { $rows = $this->where('bp_lg_idx', $lgIdx) ->where('bp_state', 1) ->orderBy('bp_regdate', 'DESC') ->orderBy('bp_idx', 'DESC') ->findAll(); $map = []; foreach ($rows as $row) { $code = (string) ($row->bp_bag_code ?? ''); if ($code === '' || isset($map[$code])) { continue; } $map[$code] = $row; } return $map; } public function latestActiveByBagCode(int $lgIdx, string $bagCode): ?object { $bagCode = trim($bagCode); if ($bagCode === '') { return null; } return $this->where('bp_lg_idx', $lgIdx) ->where('bp_bag_code', $bagCode) ->where('bp_state', 1) ->orderBy('bp_regdate', 'DESC') ->orderBy('bp_idx', 'DESC') ->first(); } }