changed logic of unit count calculation based on internal tool type

This commit is contained in:
Luca Haid
2025-06-10 09:45:57 +02:00
parent 327d6686fb
commit 28546cf4d0
8 changed files with 135 additions and 678 deletions

View File

@@ -1,215 +0,0 @@
<?php
$pagination_baseurl = $this->getUrl($Mod,"Index");
$pagination_baseurl_params = ["filter" => $filter];
$pagination_entity_name = "Vorbestellkampagnen";
?>
<?php include(realpath(dirname(__FILE__)."/../../$mfLayoutPackage")."/header.php"); ?>
<!-- start page title -->
<div class="row">
<div class="col-12">
<div class="page-title-box">
<div class="page-title-right">
<ol class="breadcrumb m-0">
<li class="breadcrumb-item"><a href="<?=self::getUrl("Dashboard")?>"><?=MFAPPNAME_SLUG?></a></li>
<li class="breadcrumb-item active">Vorbestellung</li>
</ol>
</div>
<h4 class="page-title">Vorbestellkampagnen</h4>
</div>
</div>
</div>
<!-- end page title -->
<div class="row">
<div class="col-lg-12">
<div class="card">
<div class="card-body mb-3">
<h4 class="header-title mb-3">Filter</h4>
<form method="get" action="<?=self::getUrl("Preordercampaign")?>">
<div class="row">
<div class="col-2">
<label class="form-label" for="filter_network_id">Netzgebiet</label>
<select name="filter[network_id]" id="filter_network_id" class="form-control">
<option></option>
<?php foreach($mynetworks as $fnet): ?>
<option value="<?=$fnet->id?>" <?=($filter['network_id'] == $fnet->id) ? "selected='selected'" : ""?>><?=$fnet->name?></option>
<?php endforeach; ?>
</select>
</div>
<?php if($me->is("Admin")): ?>
<div class="col-2">
<label class="form-label" for="filter_netowner">Netzbesitzer</label>
<select name="filter[netowner]" id="filter_netowner" class="form-control">
<option></option>
<?php foreach($netowners as $owner): ?>
<option value="<?=$owner->id?>" <?=($filter['netowner'] == $owner->id) ? "selected='selected'" : ""?>><?=$owner->getCompanyOrName()?></option>
<?php endforeach; ?>
</select>
</div>
<?php endif; ?>
<div class="col-1">
<label class="form-label" for="filter_name">Name</label>
<input type="text" class="form-control" name="filter[name]" id="filter_name" value="<?=$filter['name'] ?? ""?>" />
</div>
<div class="col-1">
<label class="form-label" for="filter_area">Gebiet</label>
<input type="text" class="form-control" name="filter[area]" id="filter_area" value="<?=$filter['area'] ?? ""?>" />
</div>
</div>
<div class="row mt-2">
<div class="col">
<button type="submit" class="btn btn-primary">Filter anwenden</button>
<a class="btn btn-secondary" href="<?=self::getUrl("Preordercampaign")?>">Filter zurücksetzen</a>
</div>
</div>
</form>
</div>
</div>
<?php if($me->address_id == 1 || $me->address_id == 4807): // xinon, rml ?>
<div class="card">
<div class="card-body">
<a class="btn btn-purple" href="<?=self::getUrl("PreorderDiscount", "import")?>"><i class="fas fa-tags fa-fw"></i> Gutscheincodes importieren</a>
<a class="btn btn-purple ml-1" href="<?=self::getUrl("Preorder", "statusupdateimport")?>"><i class="fas fa-retweet fa-fw"></i> Statusupdates importieren</a>
</div>
</div>
<?php endif; ?>
<div class="card">
<div class="card-body mb-3">
<div class="float-left">
<h4 class="header-title">Liste aller Vorbestellkampagnen</h4>
</div>
<div class="float-right">
<?php if($me->is("Admin")): ?>
<a class="btn btn-primary mb-2" href="<?=self::getUrl("Preordercampaign", "add")?>"><i class="fas fa-plus"></i> Neue Vorbestellkampagne anlegen</a>
<?php endif; ?>
</div>
<div class="row">
<div class="col">
<?php include(realpath(dirname(__FILE__)."/../")."/tpl/pagination.php"); ?>
<?php include(realpath(dirname(__FILE__)."/../")."/tpl/pagination-summary.php"); ?>
</div>
</div>
<table class="table table-striped table-hover">
<tr>
<th></th>
<th></th>
<th>Netzgebiete</th>
<th>Name</th>
<th>Vorbestellungen</th>
<th>Workorders</th>
<th>Start</th>
<th>Ende</th>
<th></th>
</tr>
<?php foreach($campaigns as $camp): ?>
<tr <?=(date('U') >= $camp->from && date('U') <= $camp->to) ? "class='active'" : ""?>>
<td class="text-right">
<?php if(date('U') >= $camp->from && date('U') <= $camp->to): ?>
<span class="fa-stack" title="Vorbestellkampagne aktiv">
<i class="fas fa-alarm-clock fa-stack-1x text-success" style="z-index: 20;"></i>
<i class="fas fa-circle-check" style="color: Tomato; vertical-align: top; font-size: 0.7em; padding-right:4px; padding-top:4px; z-index: 10;"></i>
</span>
<?php endif; ?>
</td>
<td class="text-right">
<a class="btn btn-sm btn-outline-primary" href="<?=self::getUrl("Preorder", "add", ["preordercampaign_id" => $camp->id])?>"><i class="fas fa-plus" title="Vorbestellung hinzufügen"></i></a>
</td>
<td><?=$camp->network->name?></td>
<td><?=$camp->name?></td>
<td>
<div class="row">
<div class="col-1 text-right" style="font-size: 1.5em" title="Bestellungen anzeigen">
<a href="<?=self::getUrl("Preorder", "Index", ["filter" => ["preordercampaign_id" => $camp->id]])?>"><i class="fas fa-list-alt"></i></a>
</div>
<div class="col">
<table class="table-sm table-borderless">
<tr class="bg-transparent" style="line-height: .6em;">
<?php if($camp->total_homes_sd): // automatic value from AdressDB ?>
<td class="text-right">EFH:</td>
<td class="text-right"><?=$camp->active_preorder_count_sd?> /</td>
<td class="text-right"><?=$camp->total_homes_sd?></td>
<td>(<?=(round(($camp->active_preorder_count_sd / $camp->total_homes_sd) * 100, 2))?> %)</td>
<?php endif; ?>
</tr>
<tr class="bg-transparent" style="line-height: .6em;">
<?php if($camp->total_homes_md): // automatic value from AdressdB ?>
<td class="text-right">MPH:</td>
<td class="text-right"><?=$camp->active_preorder_count_md?> /</td>
<td class="text-right"><?=$camp->total_homes_md?></td>
<td>(<?=(round(($camp->active_preorder_count_md / $camp->total_homes_md) * 100, 2))?> %)</td>
<?php endif; ?>
</tr>
<tr class="bg-transparent" style="line-height: .6em;">
<td class="text-right">Gesamt:</td>
<td class="text-right"><?=$camp->active_preorder_count?> /</td>
<td class="text-right">
<?php if($camp->homes_total): // manual value ?>
<?=$camp->homes_total?>
<?php elseif($camp->total_homes): // automatic value from AdressDB ?>
<?=$camp->total_homes?>
<?php endif; ?>
</td>
<td>
<?php if($camp->homes_total): // manual value ?>
(<?=(round(($camp->active_preorder_count / $camp->homes_total) * 100, 2))?> %)
<?php elseif($camp->total_homes): // automatic value from AdressDB ?>
(<?=(round(($camp->active_preorder_count / $camp->total_homes) * 100, 2))?> %)
<?php endif; ?>
</td>
</tr>
</table>
</div>
</div>
</td>
<td>
<?php if($camp->workorder_count): ?>
<?=$camp->workorder_count?>
<?php else: ?>
0
<?php endif; ?>
/ <?=$camp->active_preorder_count?>
</td>
<td><?=date('d.m.Y',$camp->from)?></td>
<td><?=date('d.m.Y',$camp->to)?></td>
<td style="text-align: left; letter-spacing: 4px; font-size: 1.1em;">
<a href="<?=self::getUrl("Preordercampaign", "downloadAddonServices", ["preordercampaign_id" => $camp->id])?>" title="Bestellte Zusatzdienste exportieren"><i class="far fa-sunset"></i></a>
<a href="<?=self::getUrl("Preordernotification", "Index", ["filter" => ["preordercampaign_id" => $camp->id]])?>" title="Email Aussendungen"><i class="far fa-envelope"></i></a>
<?php if($me->is("Admin")): ?>
<a href="<?=self::getUrl("Preordercampaign", "edit", ["id" => $camp->id])?>"><i class="far fa-edit" title="Vorbestellkampagne Bearbeiten"></i></a>
<a href="<?=self::getUrl("Preordercampaign", "admin", ["id" => $camp->id])?>"><i class="far fa-a" title="Adminfunktionen"></i></a>
<a href="<?=self::getUrl("Preordercampaign", "delete", ["id" => $camp->id])?>" class="text-danger" onclick="if(!confirm('Vorbestellkampagne wirklich löschen?')) return false;" title="Vorbestellkampagne Löschen"><i class="fas fa-trash"></i></a>
<?php endif; ?>
</td>
</tr>
<?php endforeach; ?>
</table>
<?php include(realpath(dirname(__FILE__)."/../")."/tpl/pagination-summary.php"); ?>
<?php include(realpath(dirname(__FILE__)."/../")."/tpl/pagination.php"); ?>
</div>
</div>
</div>
</div>
<?php include(realpath(dirname(__FILE__)."/../../$mfLayoutPackage")."/footer.php"); ?>

View File

@@ -1,318 +0,0 @@
<?php
$pagination_baseurl = $this->getUrl($Mod,"Index");
$pagination_baseurl_params = ["filter" => $filter];
$pagination_entity_name = "Vorbestellkampagnen";
?>
<?php include(realpath(dirname(__FILE__)."/../../$mfLayoutPackage")."/header.php"); ?>
<style>
.preorder-campaign-import {
display: flex;
gap: 8px;
justify-content: flex-start;
}
.preorder-campaign-header, .preorder-campaign-header-buttons {
display: flex;
justify-content: space-between;
}
.preorder-campaign-header-buttons {
max-width: 500px;
}
@media (max-width: 576px) {
.preorder-campaign-import, .preorder-campaign-header {
display: grid;
grid-template-columns: 1fr;
grid-gap: 8px;
}
.preorder-campaign-table-wrapper {
overflow-x: auto;
}
.preorder-campaign-header h4 {
text-align: center;
}
.preorder-campaign-header-buttons {
display:grid;
grid-template-columns: 1fr 1fr;
grid-gap: 8px;
}
.preorder-campaign-table-actions {
display: grid;
grid-gap: 4px;
grid-template-columns: auto auto auto;
}
.preorder-campaign-table-actions a {
text-align: center;
font-size: 24px;
}
.preorder-campaign-table-actions a[title="Vorbestellkampagne Löschen"] {
grid-column: 3;
}
}
</style>
<script>
$(document).ready(function () {
if (window.matchMedia('(min-width: 576px)').matches) {
return;
}
// in ul.pagination
// if .page-item.disabled.text-secondary exists
// only keep the first 2 .page-item, the last 2 .page-item and the .page-item.disabled.text-secondary and the one before and the one after that
const pagination = $("ul.pagination");
const disabled = pagination.find(".page-item.disabled.points");
if (disabled.length) {
const first = pagination.find(".page-item").first();
const firstNext = first.next();
const last = pagination.find(".page-item").last();
const lastNext = last.prev();
const prev = disabled.prev();
const next = disabled.next();
const notToDelete = [first, firstNext, last, lastNext, prev, next, disabled];
// loop through pagination.find(".page-item") and remove all but the first, last, prev, next, firstNext, lastNext
pagination.find(".page-item").each(function (index, item) {
// if (!notToDelete.includes($(item))) {
// $(item).remove();
// } fix this becaues of we need [0] of notToDelete to compare
let check = false;
notToDelete.forEach(function (n) {
if (n[0] === item) {
check = true;
}
});
if (!check) {
$(item).remove();
}
});
}
});
</script>
<!-- start page title -->
<div class="row">
<div class="col-12">
<div class="page-title-box">
<div class="page-title-right">
<ol class="breadcrumb m-0">
<li class="breadcrumb-item"><a href="<?=self::getUrl("Dashboard")?>"><?=MFAPPNAME_SLUG?></a></li>
<li class="breadcrumb-item active">Vorbestellung</li>
</ol>
</div>
<h4 class="page-title">Vorbestellkampagnen</h4>
</div>
</div>
</div>
<!-- end page title -->
<div class="row">
<div class="col-lg-12">
<div class="card">
<div class="card-body mb-3">
<h4 class="header-title mb-3">Filter</h4>
<form method="get" action="<?=self::getUrl("Preordercampaign")?>">
<div class="row">
<div class="col-sm-12 col-md-2">
<label class="form-label" for="filter_network_id">Netzgebiet</label>
<select name="filter[network_id]" id="filter_network_id" class="form-control">
<option></option>
<?php foreach($mynetworks as $fnet): ?>
<option value="<?=$fnet->id?>" <?=($filter['network_id'] == $fnet->id) ? "selected='selected'" : ""?>><?=$fnet->name?></option>
<?php endforeach; ?>
</select>
</div>
<?php if($me->is("Admin")): ?>
<div class="col-sm-12 col-md-2">
<label class="form-label" for="filter_netowner">Netzbesitzer</label>
<select name="filter[netowner]" id="filter_netowner" class="form-control">
<option></option>
<?php foreach($netowners as $owner): ?>
<option value="<?=$owner->id?>" <?=($filter['netowner'] == $owner->id) ? "selected='selected'" : ""?>><?=$owner->getCompanyOrName()?></option>
<?php endforeach; ?>
</select>
</div>
<?php endif; ?>
<div class="col-sm-12 col-md-1">
<label class="form-label" for="filter_name">Name</label>
<input type="text" class="form-control" name="filter[name]" id="filter_name" value="<?=$filter['name'] ?? ""?>" />
</div>
<div class="col-sm-12 col-md-1">
<label class="form-label" for="filter_area">Gebiet</label>
<input type="text" class="form-control" name="filter[area]" id="filter_area" value="<?=$filter['area'] ?? ""?>" />
</div>
</div>
<div class="row mt-2">
<div class="col preorder-campaign-header-buttons" style="max-width: 350px">
<button type="submit" class="btn btn-primary">Filter anwenden</button>
<a class="btn btn-secondary" href="<?=self::getUrl("Preordercampaign")?>">Filter zurücksetzen</a>
</div>
</div>
</form>
</div>
</div>
<?php if($me->address_id == 1 || $me->address_id == 4807): // xinon, rml ?>
<div class="card">
<div class="card-body preorder-campaign-import">
<a class="btn btn-purple" href="<?=self::getUrl("PreorderDiscount", "import")?>"><i class="fas fa-tags fa-fw"></i> Gutscheincodes importieren</a>
<a class="btn btn-purple ml-1" href="<?=self::getUrl("Preorder", "statusupdateimport")?>"><i class="fas fa-retweet fa-fw"></i> Statusupdates importieren</a>
</div>
</div>
<?php endif; ?>
<div class="card">
<div class="card-body mb-3">
<div class="preorder-campaign-header">
<h4 class="header-title">Liste aller Vorbestellkampagnen</h4>
<?php if ($me->is("Admin")): ?>
<a class="btn btn-primary mb-2" href="<?= self::getUrl("Preordercampaign", "add") ?>"><i class="fas fa-plus"></i> Neue
Vorbestellkampagne anlegen</a>
<?php endif; ?>
</div>
<div class="row">
<div class="col">
<?php include(realpath(dirname(__FILE__)."/../")."/tpl/pagination.php"); ?>
<?php include(realpath(dirname(__FILE__)."/../")."/tpl/pagination-summary.php"); ?>
</div>
</div>
<div class="preorder-campaign-table-wrapper">
<table class="table table-striped table-hover">
<tr>
<th></th>
<th></th>
<th>Netzgebiete</th>
<th>Name</th>
<th>Vorbestellungen</th>
<td>Workorders</td>
<th>Start</th>
<th>Ende</th>
<th></th>
</tr>
<?php foreach($campaigns as $camp): ?>
<tr <?=(date('U') >= $camp->from && date('U') <= $camp->to) ? "class='active'" : ""?>>
<td class="text-right">
<?php if(date('U') >= $camp->from && date('U') <= $camp->to): ?>
<span class="fa-stack" title="Vorbestellkampagne aktiv">
<i class="fas fa-alarm-clock fa-stack-1x text-success" style="z-index: 20;"></i>
<i class="fas fa-circle-check" style="color: Tomato; vertical-align: top; font-size: 0.7em; padding-right:4px; padding-top:4px; z-index: 10;"></i>
</span>
<?php endif; ?>
</td>
<td class="text-right">
<a class="btn btn-sm btn-outline-primary" href="<?=self::getUrl("Preorder", "add", ["preordercampaign_id" => $camp->id])?>"><i class="fas fa-plus" title="Vorbestellung hinzufügen"></i></a>
</td>
<td><?=$camp->network->name?></td>
<td><?=$camp->name?></td>
<td>
<div class="row">
<div class="col-1 text-right" style="font-size: 1.5em" title="Bestellungen anzeigen">
<a href="<?=self::getUrl("Preorder", "Index", ["filter" => ["preordercampaign_id" => $camp->id]])?>"><i class="fas fa-list-alt"></i></a>
</div>
<div class="col">
<table class="table-sm table-borderless">
<tr class="bg-transparent" style="line-height: .6em;">
<?php if($camp->total_homes_sd): // automatic value from AdressDB ?>
<td class="text-right">EFH:</td>
<td class="text-right"><?=$camp->active_preorder_count_sd?> /</td>
<td class="text-right"><?=$camp->total_homes_sd?></td>
<td>(<?=(round(($camp->active_preorder_count_sd / $camp->total_homes_sd) * 100, 2))?> %)</td>
<?php endif; ?>
</tr>
<tr class="bg-transparent" style="line-height: .6em;">
<?php if($camp->total_homes_md): // automatic value from AdressdB ?>
<td class="text-right">MPH:</td>
<td class="text-right"><?=$camp->active_preorder_count_md?> /</td>
<td class="text-right"><?=$camp->total_homes_md?></td>
<td>(<?=(round(($camp->active_preorder_count_md / $camp->total_homes_md) * 100, 2))?> %)</td>
<?php endif; ?>
</tr>
<tr class="bg-transparent" style="line-height: .6em;">
<td class="text-right">Gesamt:</td>
<td class="text-right"><?=$camp->active_preorder_count?> /</td>
<td class="text-right">
<?php if($camp->homes_total): // manual value ?>
<?=$camp->homes_total?>
<?php elseif($camp->total_homes): // automatic value from AdressDB ?>
<?=$camp->total_homes?>
<?php endif; ?>
</td>
<td>
<?php if($camp->homes_total): // manual value ?>
(<?=(round(($camp->active_preorder_count / $camp->homes_total) * 100, 2))?> %)
<?php elseif($camp->total_homes): // automatic value from AdressDB ?>
(<?=(round(($camp->active_preorder_count / $camp->total_homes) * 100, 2))?> %)
<?php endif; ?>
</td>
</tr>
</table>
</div>
</div>
</td>
<td>
<?php if($camp->workorder_count): ?>
<?=$camp->workorder_count?>
<?php else: ?>
0
<?php endif; ?>
/ <?=$camp->active_preorder_count?>
</td>
<td><?=date('d.m.Y',$camp->from)?></td>
<td><?=date('d.m.Y',$camp->to)?></td>
<td style="text-align: left; letter-spacing: 4px; font-size: 1.1em;">
<div class="preorder-campaign-table-actions">
<a href="<?=self::getUrl("Preordercampaign", "downloadAddonServices", ["preordercampaign_id" => $camp->id])?>" title="Bestellte Zusatzdienste exportieren"><i class="far fa-sunset"></i></a>
<a href="<?=self::getUrl("Preordernotification", "Index", ["filter" => ["preordercampaign_id" => $camp->id]])?>" title="Email Aussendungen"><i class="far fa-envelope"></i></a>
<?php if($me->is("Admin")): ?>
<a href="<?=self::getUrl("Preordercampaign", "edit", ["id" => $camp->id])?>"><i class="far fa-edit" title="Vorbestellkampagne Bearbeiten"></i></a>
<a href="<?=self::getUrl("Preordercampaign", "admin", ["id" => $camp->id])?>"><i class="far fa-a" title="Adminfunktionen"></i></a>
<a href="<?=self::getUrl("Preordercampaign", "delete", ["id" => $camp->id])?>" class="text-danger" onclick="if(!confirm('Vorbestellkampagne wirklich löschen?')) return false;" title="Vorbestellkampagne Löschen"><i class="fas fa-trash"></i></a>
<?php endif; ?>
</div>
</td>
</tr>
<?php endforeach; ?>
</table>
</div>
<?php include(realpath(dirname(__FILE__)."/../")."/tpl/pagination-summary.php"); ?>
<?php include(realpath(dirname(__FILE__)."/../")."/tpl/pagination.php"); ?>
</div>
</div>
</div>
</div>
<?php include(realpath(dirname(__FILE__)."/../../$mfLayoutPackage")."/footer.php"); ?>

View File

@@ -7,9 +7,6 @@ class ADBNetzgebietModel {
public $source_id;
public $rimo_id;
public $freigabe;
public $unit_count;
public $unit_count_sd;
public $unit_count_md;
public $create = null;
public $edit = null;
@@ -175,13 +172,3 @@ class ADBNetzgebietModel {
}
}
/*
* Update unit_count in Netzgebiet:
UPDATE `Netzgebiet`
LEFT JOIN (SELECT netzgebiet_id, COUNT(*) as uc FROM Wohneinheit LEFT JOIN Hausnummer ON (Wohneinheit.hausnummer_id = Hausnummer.id) GROUP BY netzgebiet_id) AS uc_table ON (uc_table.netzgebiet_id = Netzgebiet.id)
SET unit_count = uc_table.uc
WHERE uc_table.uc IS NOT NULL;
*/

View File

@@ -148,28 +148,29 @@ class DashboardController extends mfBaseController {
}
private function getTotalHomes($preordercampaign_id = [], $gemeinde_id = false) {
$total_homes = 0;
return 0;
// $i_total_calculated_homes = 0;
if($gemeinde_id) {
$sql = "SELECT COUNT(adb_wohneinheit.id) as cnt FROM `".ADDRESSDB_DBNAME."`.Wohneinheit adb_wohneinheit
LEFT JOIN `".ADDRESSDB_DBNAME."`.Hausnummer adb_hausnummer ON (adb_wohneinheit.hausnummer_id = adb_hausnummer.id)
LEFT JOIN `".ADDRESSDB_DBNAME."`.Strasse adb_strasse ON (adb_hausnummer.strasse_id = adb_strasse.id)
WHERE adb_strasse.gemeinde_id = $gemeinde_id
";
$res = $this->db()->query($sql);
if($this->db()->num_rows($res)) {
$data = $this->db()->fetch_object($res);
return $data->cnt;
}
} else {
foreach($preordercampaign_id as $campaign_id) {
$campaign = new Preordercampaign($campaign_id);
if($campaign->id) {
$total_homes += ($campaign->homes_total) ? $campaign->homes_total : $campaign->total_homes;
}
}
}
return $total_homes;
// if($gemeinde_id) {
// $sql = "SELECT COUNT(adb_wohneinheit.id) as cnt FROM `".ADDRESSDB_DBNAME."`.Wohneinheit adb_wohneinheit
// LEFT JOIN `".ADDRESSDB_DBNAME."`.Hausnummer adb_hausnummer ON (adb_wohneinheit.hausnummer_id = adb_hausnummer.id)
// LEFT JOIN `".ADDRESSDB_DBNAME."`.Strasse adb_strasse ON (adb_hausnummer.strasse_id = adb_strasse.id)
// WHERE adb_strasse.gemeinde_id = $gemeinde_id
// ";
// $res = $this->db()->query($sql);
// if($this->db()->num_rows($res)) {
// $data = $this->db()->fetch_object($res);
// return $data->cnt;
// }
// } else {
// foreach($preordercampaign_id as $campaign_id) {
// $campaign = new Preordercampaign($campaign_id);
// if($campaign->id) {
// $i_total_calculated_homes += ($campaign->homes_DEPRECATED_total) ? $campaign->homes_DEPRECATED_total : $campaign->homes_DEPRECATED_total;
// }
// }
// }
// return $i_total_calculated_homes;
}
private function getPartnerOrderCount($preordercampaign_id = [], $gemeinde_id = false) {

View File

@@ -201,6 +201,9 @@ class DashboardNewController extends mfBaseController {
$efh_connection_types = ["single-dwelling", "business"];
$mph_connection_types = ["apartment-building", "apartment", "multi-dwelling"];
$efh_connection_types = [0,1];
$mph_connection_types = [2];
$countFunction = function($params, $statusFlag = null) use ($campaign_ids, $gemeinde_ids) {
$baseParams = ["preordercampaign_id" => $campaign_ids, "gemeinde_id" => $gemeinde_ids];
$params = array_merge($baseParams, $params);
@@ -254,15 +257,15 @@ class DashboardNewController extends mfBaseController {
'baufortschritt_140' => $countFunction([">status_code" => "139", "<status_code" => "899"]),
// MAYBE OVERWORK
'order_efh' => $countFunction(["connection_type" => $efh_connection_types]),
'installationspaket_erhalten' => $countFunction(["connection_type" => $efh_connection_types], 145),
'lehrrohr_im_haus' => $countFunction(["connection_type" => $efh_connection_types], 200),
'order_efh' => $countFunction(["tool_building_type" => $efh_connection_types]),
'installationspaket_erhalten' => $countFunction(["tool_building_type" => $efh_connection_types], 145),
'lehrrohr_im_haus' => $countFunction(["tool_building_type" => $efh_connection_types], 200),
//END MAYBE OVERWORK
'inhouse_kabel_verlegt_efh' => $inhouse_kabel_verlegt_efh,
'inhouse_kabel_verlegt_efh_magenta' => $countFunction([">status_code" => "243", "<status_code" => "899", "partner_id" => 4803]),
'inhouse_kabel_verlegt_efh_salzburg' => $countFunction([">status_code" => "243", "<status_code" => "899", "partner_id" => 5668]),
'order_mph' => $countFunction(["connection_type" => $mph_connection_types]),
'inhouse_kabel_verlegt_mph' => $countFunction(["connection_type" => $mph_connection_types], 242),
'order_mph' => $countFunction(["tool_building_type" => $mph_connection_types]),
'inhouse_kabel_verlegt_mph' => $countFunction(["tool_building_type" => $mph_connection_types], 242),
'timeline' => $this->getTimeline('weekly-orders', $campaign_ids, $gemeinde_ids),
'timeline_inhouse_kabel_verlegt_efh' => $timeline_inhouse_kabel_verlegt_efh,
@@ -311,17 +314,17 @@ class DashboardNewController extends mfBaseController {
'type' => 'default',
'order_max_home_addrdb' => $order_max_homes,
'order_actual_order' => $countFunction([]),
'order_efh' => $countFunction(["connection_type" => $efh_connection_types]),
'order_efh_vorsorge' => $countFunction(["connection_type" => $efh_connection_types, "type" => "provision"]),
'order_efh_vollanschluss' => $countFunction(["connection_type" => $efh_connection_types, "type" => "order"]),
'order_mph' => $countFunction(["connection_type" => $mph_connection_types]),
'order_mph_vorsorge' => $countFunction(["connection_type" => $mph_connection_types, "type" => "provision"]),
'order_mph_vollanschluss' => $countFunction(["connection_type" => $mph_connection_types, "type" => "order"]),
'order_efh' => $countFunction(["tool_building_type" => $efh_connection_types]),
'order_efh_vorsorge' => $countFunction(["tool_building_type" => $efh_connection_types, "type" => "provision"]),
'order_efh_vollanschluss' => $countFunction(["tool_building_type" => $efh_connection_types, "type" => "order"]),
'order_mph' => $countFunction(["tool_building_type" => $mph_connection_types]),
'order_mph_vorsorge' => $countFunction(["tool_building_type" => $mph_connection_types, "type" => "provision"]),
'order_mph_vollanschluss' => $countFunction(["tool_building_type" => $mph_connection_types, "type" => "order"]),
'baufortschritt_140' => $baufortschritt_140,
'installationspaket_erhalten' => $countFunction(["connection_type" => $efh_connection_types], 145),
'lehrrohr_im_haus' => $countFunction(["connection_type" => $efh_connection_types], 200),
'inhouse_kabel_verlegt_efh' => $countFunction(["connection_type" => $efh_connection_types], 242),
'inhouse_kabel_verlegt_mph' => $countFunction(["connection_type" => $mph_connection_types], 242),
'installationspaket_erhalten' => $countFunction(["tool_building_type" => $efh_connection_types], 145),
'lehrrohr_im_haus' => $countFunction(["tool_building_type" => $efh_connection_types], 200),
'inhouse_kabel_verlegt_efh' => $countFunction(["tool_building_type" => $efh_connection_types], 242),
'inhouse_kabel_verlegt_mph' => $countFunction(["tool_building_type" => $mph_connection_types], 242),
'installationsfortschritt_245' => $countFunction([">status_code" => "244", "<status_code" => "899"]),
'ont_installiert_300' => $ont_installiert_300,
'vollanschluss_dokumentiert_350' => $countFunction(["status_code" => ["350","500"], "type" => "order"]),
@@ -390,17 +393,17 @@ class DashboardNewController extends mfBaseController {
'type' => 'default',
'order_max_home_addrdb' => $order_max_homes,
'order_actual_order' => $countFunction([]),
'order_efh' => $countFunction(["connection_type" => $efh_connection_types]),
'order_efh_vorsorge' => $countFunction(["connection_type" => $efh_connection_types, "type" => "provision"]),
'order_efh_vollanschluss' => $countFunction(["connection_type" => $efh_connection_types, "type" => "order"]),
'order_mph' => $countFunction(["connection_type" => $mph_connection_types]),
'order_mph_vorsorge' => $countFunction(["connection_type" => $mph_connection_types, "type" => "provision"]),
'order_mph_vollanschluss' => $countFunction(["connection_type" => $mph_connection_types, "type" => "order"]),
'order_efh' => $countFunction(["tool_building_type" => $efh_connection_types]),
'order_efh_vorsorge' => $countFunction(["tool_building_type" => $efh_connection_types, "type" => "provision"]),
'order_efh_vollanschluss' => $countFunction(["tool_building_type" => $efh_connection_types, "type" => "order"]),
'order_mph' => $countFunction(["tool_building_type" => $mph_connection_types]),
'order_mph_vorsorge' => $countFunction(["tool_building_type" => $mph_connection_types, "type" => "provision"]),
'order_mph_vollanschluss' => $countFunction(["tool_building_type" => $mph_connection_types, "type" => "order"]),
'baufortschritt_140' => $baufortschritt_140,
'installationspaket_erhalten' => $countFunction(["connection_type" => $efh_connection_types], 145),
'lehrrohr_im_haus' => $countFunction(["connection_type" => $efh_connection_types], 200),
'inhouse_kabel_verlegt_efh' => $countFunction(["connection_type" => $efh_connection_types], 242),
'inhouse_kabel_verlegt_mph' => $countFunction(["connection_type" => $mph_connection_types], 242),
'installationspaket_erhalten' => $countFunction(["tool_building_type" => $efh_connection_types], 145),
'lehrrohr_im_haus' => $countFunction(["tool_building_type" => $efh_connection_types], 200),
'inhouse_kabel_verlegt_efh' => $countFunction(["tool_building_type" => $efh_connection_types], 242),
'inhouse_kabel_verlegt_mph' => $countFunction(["tool_building_type" => $mph_connection_types], 242),
'installationsfortschritt_245' => $countFunction([">status_code" => "244", "<status_code" => "899"]),
'ont_installiert_300' => $ont_installiert_300,
'vollanschluss_dokumentiert_350' => $countFunction(["status_code" => ["350","500"], "type" => "order"]),

View File

@@ -495,7 +495,7 @@ class PreorderModel
$where = self::getSqlFilter($filter);
$sql = "SELECT 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 adb_hausnummer ON (tt_preorder.adb_hausnummer_id = adb_hausnummer.id)
LEFT JOIN `" . ADDRESSDB_DBNAME . "`.Wohneinheit as adb_wohneinheit ON (tt_preorder.adb_wohneinheit_id = adb_wohneinheit.id)
LEFT OUTER JOIN (SELECT adb_wohneinheit_id, count(*) cnt, MAX(rimo_status) as rimo_status, MAX(rimo_name) as rimo_name, MAX(rimo_team_name) as rimo_team_name, MAX(rimo_team_id) as rimo_team_id FROM `" . FRONKDB_DBNAME . "`.RimoWorkorder WHERE rimo_status NOT IN ('deleted', 'cancelled') GROUP BY adb_wohneinheit_id) workorder ON adb_wohneinheit.id = workorder.adb_wohneinheit_id
WHERE $where
@@ -795,6 +795,18 @@ class PreorderModel
}
}
if (array_key_exists("tool_building_type", $filter)) {
$tool_building_type = $filter['tool_building_type'];
if (is_array($tool_building_type) && count($tool_building_type)) {
$where .= " AND adb_hausnummer.tool_building_type IN ('" . implode("','", $tool_building_type) . "')";
} else {
$tool_building_type = FronkDB::singleton()->escape($filter['connection_type']);
if ($tool_building_type) {
$where .= " AND adb_hausnummer.tool_building_type like '%$tool_building_type%'";
}
}
}
if (array_key_exists("connection_count", $filter)) {
$connection_count = $filter['connection_count'];
if (intval($connection_count) === 1) {
@@ -1095,7 +1107,7 @@ class PreorderModel
$sql = "SELECT 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 adb_hausnummer ON (tt_preorder.adb_hausnummer_id = adb_hausnummer.id)
INNER JOIN `" . FRONKDB_DBNAME . "`.PreorderStatusflagValue psfv ON tt_preorder.id = psfv.preorder_id
INNER JOIN `" . FRONKDB_DBNAME . "`.PreorderStatusflag psf ON psfv.flag_id = psf.id
WHERE $where AND psf.code = " . $statusFlag . " AND psfv.value = 1";
@@ -1121,27 +1133,34 @@ class PreorderModel
$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)
WHEN h.tool_building_type = 2 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 `".ADDRESSDB_DBNAME."`.Hausnummer h ON p.adb_hausnummer_id = h.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' => (int)$data->md_count,
'sd_count' => (int)($data->total_count - $data->md_count),
'total_count' => (int)$data->total_count
];
}
return ['md_count' => 0, 'sd_count' => 0, 'total_count' => 0];
return [
'md_count' => 0,
'sd_count' => 0,
'total_count' => 0
];
}
public static function countTotalUnits($preorderCampaignId = null) {
@@ -1154,23 +1173,41 @@ WHERE p.deleted = 0 AND tt_preorderstatus.code < 899";
$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
COUNT(w.id) AS total_unit_count,
SUM(CASE
WHEN h.tool_building_type IN (0, 1) THEN 1
ELSE 0
END) AS total_unit_count_sd,
SUM(CASE
WHEN h.tool_building_type = 2 THEN 1
ELSE 0
END) 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
LEFT JOIN `".ADDRESSDB_DBNAME."`.Hausnummer h ON n.id = h.netzgebiet_id
LEFT JOIN `".ADDRESSDB_DBNAME."`.Wohneinheit w ON h.id = w.hausnummer_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' => (int)$data->total_unit_count,
'total_unit_count_sd' => (int)$data->total_unit_count_sd,
'total_unit_count_md' => (int)$data->total_unit_count_md
];
}
return ['total_unit_count' => 0, 'total_unit_count_sd' => 0, 'total_unit_count_md' => 0];
return [
'total_unit_count' => 0,
'total_unit_count_sd' => 0,
'total_unit_count_md' => 0
];
}
public static function countHistoryStatus($filter = [], $status_code = null) {

View File

@@ -13,9 +13,6 @@ class Preordercampaign extends mfBaseModel {
private $salesclusters;
private $apiusers;
private $corsorigins;
private $total_homes;
private $total_homes_sd;
private $total_homes_md;
private $workorder_count;
private $required_fields = [];
private $banned_fcps;
@@ -132,41 +129,6 @@ class Preordercampaign extends mfBaseModel {
return $wo_count;
}
if($name == "total_homes_sd") {
$this->getProperty("total_homes");
return $this->total_homes_sd;
}
if($name == "total_homes_md") {
$this->getProperty("total_homes");
return $this->total_homes_md;
}
if($name == "total_homes") {
$total = 0;
$total_sd = 0;
$total_md = 0;
$netzgebiet_ids = null;
if ($this->getProperty("salesclusters")) {
foreach($this->getProperty("salesclusters") as $scluster) {
if($scluster->id) $netzgebiet_ids[] = $scluster->id;
}
}
if(is_array($netzgebiet_ids) && count($netzgebiet_ids)) {
foreach(ADBNetzgebietModel::search(["netzgebiet_id" => $netzgebiet_ids]) as $netzgebiet) {
$total += $netzgebiet->unit_count;
$total_sd += $netzgebiet->unit_count_sd;
$total_md += $netzgebiet->unit_count_md;
}
}
$this->total_homes = $total;
$this->total_homes_sd = $total_sd;
$this->total_homes_md = $total_md;
return $total;
}
if($name == "required_fields") {
if(!$this->required_preorder_fields) return [];
$this->required_fields = json_decode($this->required_preorder_fields);

View File

@@ -53,7 +53,7 @@ class PreordercampaignController extends mfBaseController {
'id' => $c->id,
'network_id' => $c->network_id,
'network_name' => $c->network->name,
'network_owner_name' => $c->network->owner->getCompanyOrName(),
'network_owner_name' => $c->network->owner ? $c->network->owner->getCompanyOrName() : '',
'name' => $c->name,
'area' => $c->area,
'from' => $c->from,