Preorder campaign rework
This commit is contained in:
@@ -927,11 +927,72 @@ class PreorderModel
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static function countHistoryStatus($filter = [], $status_code = null)
|
||||
{
|
||||
if ($status_code === null) {
|
||||
die("Please select a status code");
|
||||
public static function countActivePreorder($preorderCampaignId = null) {
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = "1=1 ";
|
||||
if ($preorderCampaignId) {
|
||||
$where .= " AND p.preordercampaign_id = $preorderCampaignId";
|
||||
}
|
||||
|
||||
$sql = "SELECT
|
||||
COALESCE(SUM(CASE
|
||||
WHEN LOWER(vh.gdaeigenschaft) IN ('multi dwelling', 'mehrparteienhaus', 'gebaeude mit 2 oder mehr wohnungen', 'gebäude mit 2 oder mehr wohnungen', 'wohngebaeude fuer gemeinschaften', 'wohngebäude für gemeinschaften', 'hotels und aehnliche gebaeude', 'hotels und ähnliche gebäude', 'wohngebäude mit 2 und mehr wohnungen')
|
||||
OR LOWER(vh.rimo_type) IN ('multi dwelling', 'mehrparteienhaus', 'gebaeude mit 2 oder mehr wohnungen', 'gebäude mit 2 oder mehr wohnungen', 'wohngebaeude fuer gemeinschaften', 'wohngebäude für gemeinschaften', 'hotels und aehnliche gebaeude', 'hotels und ähnliche gebäude', 'wohngebäude mit 2 und mehr wohnungen')
|
||||
THEN COALESCE(p.connection_count, 1)
|
||||
ELSE 0
|
||||
END), 0) AS md_count,
|
||||
COALESCE(SUM(COALESCE(p.connection_count, 1)), 0) AS total_count
|
||||
|
||||
FROM
|
||||
`".FRONKDB_DBNAME."`.Preorder p
|
||||
LEFT JOIN `".ADDRESSDB_DBNAME."`.view_hausnummer vh ON p.adb_hausnummer_id = vh.hausnummer_id
|
||||
LEFT JOIN `".FRONKDB_DBNAME."`.Preorderstatus tt_preorderstatus ON p.status_id = tt_preorderstatus.id
|
||||
WHERE p.deleted = 0 AND tt_preorderstatus.code < 899";
|
||||
|
||||
$queryStart = microtime(true);
|
||||
$res = $db->query($sql . $where);
|
||||
mfLoghandler::singleton()->debug("[Query took: ".(microtime(true) - $queryStart)." seconds] " . $sql);
|
||||
if ($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
return ['md_count' => $data->md_count, 'sd_count' => $data->total_count - $data->md_count, 'total_count' => $data->total_count];
|
||||
}
|
||||
return ['md_count' => 0, 'sd_count' => 0, 'total_count' => 0];
|
||||
}
|
||||
|
||||
public static function countTotalUnits($preorderCampaignId = null) {
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = "1=1 ";
|
||||
if ($preorderCampaignId) {
|
||||
$where .= " AND pc.id = $preorderCampaignId";
|
||||
}
|
||||
|
||||
$sql = "SELECT
|
||||
pc.id AS campaign_id,
|
||||
COALESCE(SUM(n.unit_count), 0) AS total_unit_count,
|
||||
COALESCE(SUM(n.unit_count_sd), 0) AS total_unit_count_sd,
|
||||
COALESCE(SUM(n.unit_count_md), 0) AS total_unit_count_md
|
||||
FROM Preordercampaign pc
|
||||
LEFT JOIN `".FRONKDB_DBNAME."`.PreordercampaignSalescluster pcs ON pc.id = pcs.preordercampaign_id
|
||||
LEFT JOIN `".ADDRESSDB_DBNAME."`.Netzgebiet n ON pcs.salescluster_id = n.id
|
||||
WHERE $where
|
||||
GROUP BY pc.id";
|
||||
|
||||
$queryStart = microtime(true);
|
||||
$res = $db->query($sql);
|
||||
mfLoghandler::singleton()->debug("[Query took: ".(microtime(true) - $queryStart)." seconds] " . $sql);
|
||||
if ($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
return ['total_unit_count' => $data->total_unit_count, 'total_unit_count_sd' => $data->total_unit_count_sd, 'total_unit_count_md' => $data->total_unit_count_md];
|
||||
}
|
||||
return ['total_unit_count' => 0, 'total_unit_count_sd' => 0, 'total_unit_count_md' => 0];
|
||||
}
|
||||
|
||||
public static function countHistoryStatus($filter = [], $status_code = null) {
|
||||
if ($status_code === null) {
|
||||
die("Please select a status code");
|
||||
}
|
||||
|
||||
if (!is_array($filter)) return false;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user