diff --git a/Layout/default/Preorder/Index.php b/Layout/default/Preorder/Index.php index f4de12445..c699ac63b 100644 --- a/Layout/default/Preorder/Index.php +++ b/Layout/default/Preorder/Index.php @@ -2505,7 +2505,11 @@ $pagination_entity_name = "Vorbestellungen"; fcpSelect.empty().select2({ data: [], placeholder: "Bitte Kampagne auswählen", allowClear: true }); return; } - $.get(apiUrl, { do: "getFCPsForCampaign", campaign_id: campaign_id }, (success) => { + const filterData = $(this).closest("form").serializeArray().filter(item => item.name.startsWith("filter[") && !item.name.includes("fcp")); + const params = { do: "getFCPsForCampaign", campaign_id: campaign_id }; + filterData.forEach(item => { params[item.name] = item.value; }); + + $.get(apiUrl, params, (success) => { let fcpData = []; let opts = { data: [], placeholder: "Bitte Kampagne auswählen", allowClear: true }; if (success?.status === "OK" && Array.isArray(success.result)) { diff --git a/application/Preorder/PreorderController.php b/application/Preorder/PreorderController.php index 702b9d3df..119d22d71 100644 --- a/application/Preorder/PreorderController.php +++ b/application/Preorder/PreorderController.php @@ -1451,13 +1451,14 @@ class PreorderController extends mfBaseController { $fcps = ADBRimoFcp::getAll(["netzgebiet_id" => intval($campaign->network->adb_netzgebiet_id)]) ?? []; if (empty($fcps)) return []; - $fcpIds = array_map(fn($fcp) => $fcp->id, $fcps); - $stats = ADBRimoFcp::getRimoFcpStatistics($fcpIds); - $statsMap = []; - foreach ($stats as $stat) { - $statsMap[$stat['fcp_id']] = $stat['total_active_preorders']; + $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']); } + $statsMap = PreorderModel::countActiveGroupedByFcp($filter); + $result = array_map( fn($fcp) => [ "real_id" => $fcp->id, diff --git a/application/Preorder/PreorderModel.php b/application/Preorder/PreorderModel.php index ac5b621b4..3d8d6a087 100644 --- a/application/Preorder/PreorderModel.php +++ b/application/Preorder/PreorderModel.php @@ -482,6 +482,40 @@ class PreorderModel return self::count($filter); } + public static function countActiveGroupedByFcp($filter = []) + { + if (!is_array($filter)) return false; + + if (!array_key_exists("deleted", $filter)) { + $filter["deleted"] = null; + } + + if (!array_key_exists("status_code", $filter) && !array_key_exists("status_code", $filter) + && !array_key_exists("status_id", $filter) && !array_key_exists("status_id", $filter)) { + $filter["query($sql); + $counts = []; + if ($db->num_rows($res)) { + while ($row = $db->fetch_object($res)) { + $counts[$row->fcp_id] = (int)$row->cnt; + } + } + return $counts; + } + /** * @param $filter * @param $limit