Merge branch 'fronkdev' of code.fronk.at:fronk/thetool into fronkdev

This commit is contained in:
Frank Schubert
2024-10-10 14:16:56 +02:00
6 changed files with 227 additions and 17 deletions

View File

@@ -8,6 +8,8 @@ class ADBNetzgebietModel {
public $rimo_id; public $rimo_id;
public $freigabe; public $freigabe;
public $unit_count; public $unit_count;
public $unit_count_sd;
public $unit_count_md;
public $create = null; public $create = null;
public $edit = null; public $edit = null;

View File

@@ -44,7 +44,30 @@ class ADBWohneinheit extends mfBaseModel {
if($hausnummer->netzgebiet_id) { if($hausnummer->netzgebiet_id) {
$netzgebiet = new ADBNetzgebiet($hausnummer->netzgebiet_id); $netzgebiet = new ADBNetzgebiet($hausnummer->netzgebiet_id);
if($netzgebiet->id) { if($netzgebiet->id) {
$netzgebiet->unit_count = ADBWohneinheitModel::count(['netzgebiet_id' => $hausnummer->netzgebiet_id]); /*$netzgebiet->unit_count = ADBWohneinheitModel::count(['netzgebiet_id' => $hausnummer->netzgebiet_id]);
$gda_egenschaft = strtolower($hausnummer->gdaeigenschaft);
if($gda_egenschaft && array_key_exists($gda_egenschaft, TT_ADB_GDA_TYPES)) {
$netzgebiet->{"unit_count_".TT_ADB_GDA_TYPES[$gda_egenschaft]};
}*/
$unit_count = ADBWohneinheitModel::count(['netzgebiet_id' => $hausnummer->netzgebiet_id]);
if($unit_count) {
$unit_count_gda = [];
foreach(ADBHausnummerModel::search(["netzgebiet_id" => $hausnummer->netzgebiet_id]) as $hausnummer) {
$gda_egenschaft = strtolower($hausnummer->gdaeigenschaft);
if($gda_egenschaft && array_key_exists($gda_egenschaft, TT_ADB_GDA_TYPES)) {
$type = TT_ADB_GDA_TYPES[$gda_egenschaft];
if(!array_key_exists($type, $unit_count_gda)) {
$unit_count_gda[$type] = 0;
}
$unit_count_gda[$type] += $hausnummer->unit_count;
}
}
foreach($unit_count_gda as $type => $count) {
$netzgebiet->{"unit_count_$type"} = $count;
}
}
$netzgebiet->unit_count = $unit_count;
$netzgebiet->save(); $netzgebiet->save();
} }
} }

View File

@@ -60,7 +60,9 @@ class Preorder extends mfBaseModel {
$this->setOrCreateOaid(); $this->setOrCreateOaid();
if($this->oaid != $old_oaid) { if($this->oaid != $old_oaid) {
$this->resetSaveNesting();
$this->save(); $this->save();
return true;
} }
//TODO: history start //TODO: history start
@@ -339,17 +341,27 @@ class Preorder extends mfBaseModel {
} }
if(!$this->adb_wohneinheit_id) { if(!$this->adb_wohneinheit_id) {
$this->oaid = null;
return false; return false;
} }
$wohneinheit = new ADBWohneinheit($this->adb_wohneinheit_id); $wohneinheit = new ADBWohneinheit($this->adb_wohneinheit_id);
if(!$wohneinheit) {
return true;
}
if($this->oaid) { if($this->oaid) {
// If current OAID is from correct Origin then do nothing // If current OAID is from correct Origin then do nothing
if($campaign->oaid_origin == "thetool") { if($campaign->oaid_origin == "thetool") {
$current_oaid = OpenAccessIdModel::getFirstOaid($this->oaid); $current_oaid = OpenAccessIdModel::getFirstOaid($this->oaid);
if($current_oaid) { if($current_oaid) {
$this->log->warning("OAID of Preorder " . $this->id . " should be thetool, but is OFAA"); $this->log->warning("OAID of Preorder " . $this->id . " should be thetool, but is OFAA");
} else {
if($wohneinheit->oaid != $this->oaid) {
$this->oaid = $wohneinheit->oaid;
return true;
}
} }
} elseif($campaign->oaid_origin == "ofaa") { } elseif($campaign->oaid_origin == "ofaa") {
$current_oaid = OpenAccessIdModel::getFirstOaid($this->oaid); $current_oaid = OpenAccessIdModel::getFirstOaid($this->oaid);
@@ -363,6 +375,10 @@ class Preorder extends mfBaseModel {
if(!$wohneinheit->oaid) { if(!$wohneinheit->oaid) {
$wohneinheit->oaid = $current_oaid->oaid; $wohneinheit->oaid = $current_oaid->oaid;
$wohneinheit->save(); $wohneinheit->save();
} elseif($wohneinheit->oaid != $this->oaid) {
// also check if wohneinheit has a different OAID and set it in the Preorder
// No need to update OAID object, it should be correct already, because Wohneinheit is the source of oaid data,
$this->oaid = $wohneinheit->oaid;
} }
return true; return true;
} }

View File

@@ -5,13 +5,18 @@ class Preordercampaign extends mfBaseModel {
private $adb_netzgebiet; private $adb_netzgebiet;
private $preorders; private $preorders;
private $active_preorders; private $active_preorders;
private $active_preorder_count = 0; private $active_preorder_count;
private $active_preorder_count_sd;
private $active_preorder_count_md;
private $types; private $types;
private $setup_products = []; private $setup_products = [];
private $salesclusters; private $salesclusters;
private $apiusers; private $apiusers;
private $corsorigins; private $corsorigins;
private $total_homes; private $total_homes;
private $total_homes_sd;
private $total_homes_md;
private $workorder_count;
private $required_fields = []; private $required_fields = [];
private $banned_fcps; private $banned_fcps;
private $all_fcp_names; private $all_fcp_names;
@@ -95,9 +100,29 @@ class Preordercampaign extends mfBaseModel {
public function getProperty($name) { public function getProperty($name) {
if($this->$name == null) { if($this->$name == null) {
if($name == "workorder_count") {
$wo_count = PreorderModel::count(["rimo_workorder" => true, "preordercampaign_id" => $this->id]);
if($wo_count) {
$this->workorder_count = $wo_count;
}
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") { if($name == "total_homes") {
$total = 0; $total = 0;
$total_sd = 0;
$total_md = 0;
$netzgebiet_ids = null; $netzgebiet_ids = null;
foreach($this->getProperty("salesclusters") as $scluster) { foreach($this->getProperty("salesclusters") as $scluster) {
@@ -106,10 +131,14 @@ class Preordercampaign extends mfBaseModel {
if(is_array($netzgebiet_ids) && count($netzgebiet_ids)) { if(is_array($netzgebiet_ids) && count($netzgebiet_ids)) {
foreach(ADBNetzgebietModel::search(["netzgebiet_id" => $netzgebiet_ids]) as $netzgebiet) { foreach(ADBNetzgebietModel::search(["netzgebiet_id" => $netzgebiet_ids]) as $netzgebiet) {
$total += $netzgebiet->unit_count; $total += $netzgebiet->unit_count;
$total_sd += $netzgebiet->unit_count_sd;
$total_md += $netzgebiet->unit_count_md;
} }
} }
$this->total_homes = $total; $this->total_homes = $total;
$this->total_homes_sd = $total_sd;
$this->total_homes_md = $total_md;
return $total; return $total;
} }
@@ -130,21 +159,37 @@ class Preordercampaign extends mfBaseModel {
return $this->active_preorders; return $this->active_preorders;
} }
if($name == "active_preorder_count") { if($name == "active_preorder_count_sd") {
$count = 0; $this->getProperty("active_preorder_count");
foreach($this->getProperty("active_preorders") as $preorder) { return $this->active_preorder_count_sd;
//echo "/c:".$preorder->connection_count."/";
if($preorder->connection_count) {
$count += (int)$preorder->connection_count;
} else {
$count++;
}
//echo "/s:$count/";
} }
$this->active_preorder_count = $count;
return $this->active_preorder_count; if($name == "active_preorder_count_md") {
} $this->getProperty("active_preorder_count");
return $this->active_preorder_count_md;
}
if($name == "active_preorder_count") {
$count = 0;
$count_sd = 0;
$count_md = 0;
foreach($this->getProperty("active_preorders") as $preorder) {
//echo "/c:".$preorder->connection_count."/";
if($preorder->connection_type == "single-dwelling") {
$count_sd += $preorder->connection_count ? (int)$preorder->connection_count : 1;
} elseif ($preorder->connection_type == "multi-dwelling") {
$count_md += $preorder->connection_count ? (int)$preorder->connection_count : 1;
}
$count += (int)$preorder->connection_count;
//echo "/s:$count/";
}
$this->active_preorder_count = $count;
$this->active_preorder_count_sd = $count_sd;
$this->active_preorder_count_md = $count_md;
return $this->active_preorder_count;
}
if($name == "types") { if($name == "types") {
$types = PreordercampaignTypeModel::search(['preordercampaign_id' => $this->id]); $types = PreordercampaignTypeModel::search(['preordercampaign_id' => $this->id]);
foreach($types as $type) { foreach($types as $type) {

View File

@@ -0,0 +1,35 @@
<?php
declare(strict_types=1);
use Phinx\Migration\AbstractMigration;
final class NetzgebietAddUnitcountSdMd extends AbstractMigration
{
public function up(): void
{
if($this->getEnvironment() == "thetool") {
}
if($this->getEnvironment() == "addressdb") {
$table = $this->table("Netzgebiet");
$table->addColumn("unit_count_sd", "integer", ["null" => false, "default" => 0, "comment" => "single-dwelling", "after" => "unit_count"]);
$table->addColumn("unit_count_md", "integer", ["null" => false, "default" => 0, "comment" => "multi-dwelling", "after" => "unit_count_sd"]);
$table->update();
}
}
public function down(): void
{
if($this->getEnvironment() == "thetool") {
}
if($this->getEnvironment() == "addressdb") {
$this->table("Netzgebiet")
->removeColumn("unit_count_md")
->removeColumn("unit_count_sd")
->update();
}
}
}

89
scripts/delete-oaid.php Normal file
View File

@@ -0,0 +1,89 @@
#!/usr/bin/php
<?php
exit;
//require 'vendor/autoload.php';
require("../config/config.php");
define('FRONKDB_SQLDEBUG',false);
error_reporting(E_ALL & ~(E_NOTICE | E_STRICT | E_DEPRECATED));
require_once(LIBDIR."/mvcfronk/mfRouter/mfRouter.php");
require_once(LIBDIR."/mvcfronk/mfBase/mfBaseModel.php");
require_once(LIBDIR."/mvcfronk/mfBase/mfBaseController.php");
$me = new User(1);
define("INTERNAL_USER_ID", $me->id);
define("INTERNAL_USER_USERNAME", $me->username);
define("MFBASE_BYPASS_LOGIN", true);
$hausnummern = [
1680565,
1680564,
1680562,
1680563
];
$preorders = [];
$db = new FronkDB();
$adb = new FronkDB(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
// delete OAIDs from rimo
foreach($hausnummern as $hausnummmer_id) {
foreach(ADBWohneinheitModel::search(["hausnummer_id" => $hausnummmer_id]) as $unit) {
$oaid = $unit->oaid;
$ftu = $unit->ftu_data;
$ftu_id = $ftu["id"];
echo "$ftu_id ".$unit->oaid."\n";
if(!$ftu_id) {
echo "Keine ftu id for home with oaid ".$unit->oaid."\n";
}
Rimoapi::unassignOaid($oaid, $ftu_id);
}
}
// remove OAIDs from Wohneinheiten und Preorders (out of framework)
foreach($hausnummern as $hausnummmer_id) {
foreach(ADBWohneinheitModel::search(["hausnummer_id" => $hausnummmer_id]) as $unit) {
$update_preorder_sql = "";
$update_unit_sql = "";
$update_oaid_sql = "";
if(!$unit->oaid) continue;
// delete oaid from preorder
$preorder = PreorderModel::getFirst(["oaid" => $unit->oaid]);
if($preorder) {
$update_preorder_sql = "UPDATE Preorder SET oaid=NULL WHERE id=" . $preorder->id;
$preorders[] = $preorder;
}
// delete oaid from unit
$update_unit_sql = "UPDATE Wohneinheit SET oaid=NULL WHERE id=".$unit->id;
// delete oaid from OpenSccessId
$oaid_object = OpenAccessIdModel::getFirst(["oaid" => $unit->oaid]);
if($oaid_object) {
$update_oaid_sql = "UPDATE OpenAccessId SET assigned=0, adb_wohneinheit_id=NULL, exported=0, exported_to=NULL, export_data=NULL, address=NULL, unit_string=NULL WHERE id=".$oaid_object->id;
}
echo $unit->oaid."\n";
echo "$update_preorder_sql\n$update_unit_sql\n$update_oaid_sql\n";
if($update_preorder_sql) $db->query($update_preorder_sql, true);
if($update_unit_sql) $adb->query($update_unit_sql, true);
if($update_oaid_sql) $db->query($update_oaid_sql, true);
foreach(RimoWorkorderModel::search(["adb_wohneinheit_id" => $unit->id]) as $wo) {
echo "lösche Workorder ".$wo->id."\n";
$wo->delete();
}
echo "\n";
}
}
//exit;
// Preorders speichern, um neue OAID zu generieren
foreach($preorders as $preorder) {
$preorder->save();
}