From be9e6ae4e5b16870d41ef3d1c8cdf5af9de1244b Mon Sep 17 00:00:00 2001 From: Luca Haid Date: Fri, 27 Feb 2026 12:36:01 +0100 Subject: [PATCH] feat: clean up and optimize FCP filter and highlighting logic --- Layout/default/Preorder/Index.php | 2 -- application/Preorder/PreorderController.php | 4 ++-- application/Preorder/PreorderModel.php | 9 +++++---- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/Layout/default/Preorder/Index.php b/Layout/default/Preorder/Index.php index c699ac63b..334e6b47c 100644 --- a/Layout/default/Preorder/Index.php +++ b/Layout/default/Preorder/Index.php @@ -2524,11 +2524,9 @@ $pagination_entity_name = "Vorbestellungen"; fcpData.sort((a, b) => { if (a.id === "") return -1; if (b.id === "") return 1; - // Sort by preorder_count descending if ((b.preorder_count || 0) !== (a.preorder_count || 0)) { return (b.preorder_count || 0) - (a.preorder_count || 0); } - // Fallback to name-based numeric/alpha sort const aN = a.id.replace(/\D/g, ""), bN = b.id.replace(/\D/g, ""); return aN && bN ? parseInt(aN, 10) - parseInt(bN, 10) : a.id.localeCompare(b.id); }); diff --git a/application/Preorder/PreorderController.php b/application/Preorder/PreorderController.php index 119d22d71..9e46475d2 100644 --- a/application/Preorder/PreorderController.php +++ b/application/Preorder/PreorderController.php @@ -1452,11 +1452,11 @@ class PreorderController extends mfBaseController { if (empty($fcps)) return []; $filter = $this->request->filter ?? []; - // We want to count preorders matching ALL other filters, but ignoring the current FCP filter if (isset($filter['fcp'])) { unset($filter['fcp']); } + $filter = $this->getPreparedFilter($filter); $statsMap = PreorderModel::countActiveGroupedByFcp($filter); $result = array_map( @@ -1466,7 +1466,7 @@ class PreorderController extends mfBaseController { "text" => $fcp->name ?? null, 'lat' => $fcp->gps_lat ?? null, 'lng' => $fcp->gps_long ?? null, - 'preorder_count' => $statsMap[$fcp->id] ?? 0 + 'preorder_count' => $statsMap[$fcp->name] ?? 0 ], $fcps ); diff --git a/application/Preorder/PreorderModel.php b/application/Preorder/PreorderModel.php index 3d8d6a087..834a08e00 100644 --- a/application/Preorder/PreorderModel.php +++ b/application/Preorder/PreorderModel.php @@ -498,19 +498,20 @@ class PreorderModel $db = FronkDB::singleton(); $where = self::getSqlFilter($filter); - $sql = "SELECT adb_hausnummer.fcp_id, COUNT(*) as cnt FROM `" . FRONKDB_DBNAME . "`.Preorder tt_preorder + $sql = "SELECT hn.rimo_fcp_name, COUNT(*) as cnt FROM `" . FRONKDB_DBNAME . "`.Preorder tt_preorder LEFT JOIN `" . FRONKDB_DBNAME . "`.Preorderstatus tt_preorderstatus ON (tt_preorder.status_id = tt_preorderstatus.id) LEFT JOIN `" . ADDRESSDB_DBNAME . "`.view_hausnummer as adb_hausnummer ON (tt_preorder.adb_hausnummer_id = adb_hausnummer.hausnummer_id) + LEFT JOIN `" . ADDRESSDB_DBNAME . "`.Hausnummer as hn ON (adb_hausnummer.hausnummer_id = hn.id) LEFT JOIN `" . ADDRESSDB_DBNAME . "`.Wohneinheit as adb_wohneinheit ON (tt_preorder.adb_wohneinheit_id = adb_wohneinheit.id) - WHERE $where AND adb_hausnummer.fcp_id IS NOT NULL - GROUP BY adb_hausnummer.fcp_id + WHERE $where AND hn.rimo_fcp_name IS NOT NULL + GROUP BY hn.rimo_fcp_name "; $res = $db->query($sql); $counts = []; if ($db->num_rows($res)) { while ($row = $db->fetch_object($res)) { - $counts[$row->fcp_id] = (int)$row->cnt; + $counts[$row->rimo_fcp_name] = (int)$row->cnt; } } return $counts;