diff --git a/Layout/default/Preorder/Form.php b/Layout/default/Preorder/Form.php
index ec0d9107e..1630e429e 100644
--- a/Layout/default/Preorder/Form.php
+++ b/Layout/default/Preorder/Form.php
@@ -153,7 +153,7 @@
adb_wohneinheit_id): ?>
-
+
@@ -588,6 +588,7 @@
if(unit.extra) {
opt += " " + unit.extra;
}
+ if(unit.extref) opt += " (" + unit.extref + ")";
/*let extras = new Array();
if(unit.block) extras.push("Block " + unit.block);
@@ -608,6 +609,7 @@
$('#adb_wohneinheit_id').append(opt);
$('#adb_wohneinheit_id').addClass("is-invalid");
$('#adb_wohneinheit_id')
+ .data("extref", unit.extref)
.data("zip", unit.zip)
.data("city", unit.city)
.data("street", unit.street)
diff --git a/application/ADBWohneinheit/ADBWohneinheit.php b/application/ADBWohneinheit/ADBWohneinheit.php
index 24511f435..cdf7dc696 100644
--- a/application/ADBWohneinheit/ADBWohneinheit.php
+++ b/application/ADBWohneinheit/ADBWohneinheit.php
@@ -75,7 +75,15 @@ class ADBWohneinheit extends mfBaseModel {
$bcode = $this->getProperty("hausnummer")->oaid;
//var_dump($bcode);
if(!$bcode) {
- return false;
+ $hausnummer = $this->getProperty("hausnummer");
+ $hausnummer->oaid = $hausnummer->getNewOAID();
+ if(!$hausnummer->oaid) {
+ return false;
+ }
+ if(!$hausnummer->save()) {
+ return false;
+ }
+ $bcode = $hausnummer->oaid;
}
$codes = [];
diff --git a/application/AddressDB/AddressDBController.php b/application/AddressDB/AddressDBController.php
index 99e494d4f..d357e4097 100644
--- a/application/AddressDB/AddressDBController.php
+++ b/application/AddressDB/AddressDBController.php
@@ -581,6 +581,7 @@ class AddressDBController extends mfBaseController {
foreach($units as $unit) {
$u = [];
$u['id'] = $unit->id;
+ $u['extref'] = $unit->extref;
$u['zip'] = $unit->hausnummer->plz->plzstring;
$u['city'] = $unit->hausnummer->ortschaft->name;
$u['street'] = $unit->hausnummer->strasse->name;
diff --git a/application/Building/BuildingController.php b/application/Building/BuildingController.php
index 7cebc8ea1..e39630a25 100644
--- a/application/Building/BuildingController.php
+++ b/application/Building/BuildingController.php
@@ -414,7 +414,7 @@ class BuildingController extends mfBaseController {
if($term->status->code >= TT_TERMSTATUS_CONNECTED) {
$building_term['status'] = "connected";
$data->status = "connected";
- } elseif($building->status->code == TT_BUILDINGSTATUS_CONNECTED) {
+ } elseif($building->status->code >= TT_BUILDINGSTATUS_CONNECTED) {
$building_term['status'] = "pipework-done";
if($data->status != "connected") $data->status = "pipework-done";
}
diff --git a/application/Preorder/Preorder.php b/application/Preorder/Preorder.php
index ea09c7b98..1f3d6ced5 100644
--- a/application/Preorder/Preorder.php
+++ b/application/Preorder/Preorder.php
@@ -228,4 +228,35 @@ class Preorder extends mfBaseModel {
return $this->$name;
}
+
+ public function __clone() {
+ $me = new User;
+ $me->loadMe();
+
+ $old_id = $this->id;
+ //$old_ucode = $this->ucode;
+ $this->id = null;
+
+ $this->data = clone($this->data);
+ $this->_old_data = new StdClass();
+
+ $this->status = null;
+ $this->campaign = null;
+ $this->partner = null;
+ $this->building = null;
+ $this->adb_hausnummer = null;
+ $this->adb_wohneinheit;
+
+ // cleanup Preorder data
+ $this->create_by = $me->id;
+ $this->edit_by = $me->id;
+
+ $this->create = null;
+ $this->edit = null;
+ $this->saved = 0;
+ $this->mode = "new";
+
+ //$this->save();
+ $this->log->debug("Cloned Preorder $old_id");
+ }
}
\ No newline at end of file
diff --git a/scripts/preorders-split-multiple-connections.php b/scripts/preorders-split-multiple-connections.php
new file mode 100755
index 000000000..128cb66d9
--- /dev/null
+++ b/scripts/preorders-split-multiple-connections.php
@@ -0,0 +1,111 @@
+#!/usr/bin/php
+id);
+define("INTERNAL_USER_USERNAME", $me->username);
+
+$ignore_preorders = [];
+
+$campaign_prem_nord = 5;
+$same_unit_count = 0;
+
+$missing_units = [];
+$missing_doors = [];
+
+$total = 0;
+$c = 0;
+foreach(PreorderModel::search(["deleted" => 0, "preordercampaign_id" => $campaign_prem_nord, "connection_count" => 2]) as $preorder) {
+ // check if we have enough units with extref
+ $wohneinheiten = ADBWohneinheitModel::search(["hausnummer_id" => $preorder->adb_hausnummer_id]);
+ $unit_count = count($wohneinheiten);
+ if($unit_count < $preorder->connection_count) {
+ $mu = [];
+ $mu['preorder'] = $preorder;
+ $mu['unit_count'] = $unit_count;
+ $missing_units[] = $mu;
+ //echo "Nicht genug Wohneinheiten - Preorder id ".$preorder->id.": ".count($wohneinheiten)." - need ".$preorder->connection_count."\n";
+ continue;
+ }
+
+ $available_units = [];
+
+ foreach($wohneinheiten as $unit) {
+ if(!PreorderModel::getFirst(["adb_wohneinheit_id" => $unit->id])) {
+ if($unit->tuer || preg_match('/^Top\s+\d+$/', $unit->zusatz)) {
+ $available_units[] = $unit;
+ }
+ }
+ }
+
+ if($preorder->connection_count > count($available_units)) {
+ $md = [];
+ $md["unit_count"] = $unit_count;
+ $md["door_count"] = count($available_units);
+ $md["preorder"] = $preorder;
+ $missing_doors[] = $md;
+ //echo "Not enough units with tuer (hausnummer id ".$preorder->adb_hausnummer_id.") units total: ".count($wohneinheiten)."; units with tuer: ".count($available_units)."; preorder connection count: ".$preorder->connection_count."\n";
+ continue;
+ }
+
+ // create new Preorders with available units
+ // then set original Preorder deleted
+ echo "Creating ".$preorder->connection_count." new preorders\n";
+ for($i = 0; $i < $preorder->connection_count; $i++) {
+ if(!$available_units[$i]->oaid) {
+ $available_units[$i]->oaid = $available_units[$i]->getNewOAID();
+ $available_units[$i]->save();
+ }
+
+ $new_preorder = clone($preorder);
+ $new_preorder->ucode = $preorder->ucode.".".($i+1);
+ $new_preorder->connection_count = 1;
+ $new_preorder->adb_wohneinheit_id = $available_units[$i]->id;
+ $new_preorder->oaid = $available_units[$i]->oaid;
+ //var_dump($new_preorder);exit;
+ $new_preorder->save();
+ }
+
+ $preorder->deleted = 1;
+ $preorder->delete_reason = "connection_split";
+ $preorder->save();
+ $i++;
+}
+
+echo "Adresse;Bestellte Anschlüsse;Vorhandene Wohneinheiten;Vorhanden Wohneinheiten mit Tür/Top Nummer\n";
+foreach($missing_units as $mu) {
+ $preorder = $mu['preorder'];
+ /*echo "Adresse: ".$preorder->adb_hausnummer->strasse->name." ".$preorder->adb_hausnummer->hausnummer;
+ echo " | Bestellte Anschlüsse: ".$preorder->connection_count;
+ echo " | Vorhandene Wohneinheiten: ".$mu['unit_count'];*/
+ echo '"'.$preorder->adb_hausnummer->strasse->name.'";';
+ echo $preorder->connection_count.';';
+ echo $mu['unit_count'].';';
+ echo ';';
+ echo "\n";
+}
+
+foreach($missing_doors as $md) {
+ $preorder = $md['preorder'];
+ /*echo "Adresse: ".$preorder->adb_hausnummer->strasse->name." ".$preorder->adb_hausnummer->hausnummer;
+ echo " | Bestellte Anschlüsse: ".$preorder->connection_count;
+ echo " | Vorhandene Wohneinheiten: ".$md['unit_count'];
+ echo " | Vorhandene Tür/Top Nummern: ".$md["door_count"];*/
+ echo '"'.$preorder->adb_hausnummer->strasse->name.'";';
+ echo $preorder->connection_count.';';
+ echo $md["unit_count"].';';
+ echo $md["door_count"].';';
+ echo "\n";
+}
+
+echo "Processed $total, created $c preorders\n";
\ No newline at end of file
diff --git a/scripts/update-preorder-add-unit.php b/scripts/update-preorder-add-unit.php
new file mode 100755
index 000000000..e98929ad2
--- /dev/null
+++ b/scripts/update-preorder-add-unit.php
@@ -0,0 +1,88 @@
+#!/usr/bin/php
+id);
+define("INTERNAL_USER_USERNAME", $me->username);
+
+$ignore_preorders = [];
+
+$campaign_prem_nord = 5;
+$same_unit_count = 0;
+
+$i = 0;
+foreach(PreorderModel::search(['preordercampaign_id' => $campaign_prem_nord, 'adb_wohneinheit_id' => null, 'connection_count' => 1, "connection_type" => "single-dwelling", "deleted" => 0]) as $preorder) {
+ if(in_array($preorder->id, $ignore_preorders)) continue;
+ //if($preorder->connection_type != "single-dwelling") continue;
+
+ if($preorder->adb_wohneinheit_id) {
+ echo "hat eh a unit\n";
+ continue;
+ }
+ if(!$preorder->adb_hausnummer_id) {
+ echo "missing hausnummer Preorder ".$preorder->id."\n";
+ continue;
+ }
+
+ $wohneinheiten = ADBWohneinheitModel::search(['hausnummer_id' => $preorder->adb_hausnummer_id]);
+ if(!count($wohneinheiten)) {
+ echo "Keine Wohneinheit gefunden. Preorder ".$preorder->id."\n";
+ }
+ $unit_count = count($wohneinheiten);
+ //echo "$unit_count\n";
+ if($unit_count === 1) {
+ $same_unit_count++;
+ $unit = $wohneinheiten[0];
+ $preorder->adb_wohneinheit_id = $unit->id;
+ $preorder->save();
+ continue;
+ }
+
+
+ if($unit_count > 1 && $unit_count <= 4) {
+ // assume its single-dwelling with erroneously high door count
+ $unit_candidates = [];
+
+ foreach($wohneinheiten as $unit) {
+ if(!$unit->tuer) continue;
+ if($unit->tuer > 1) {
+ $unit_candidates[$unit->tuer] = $unit;
+ }
+ }
+
+ /*if(!count($unit_candidates)) {
+ foreach($wohneinheiten as $unit) {
+ if(!$unit->zusatz) continue;
+ if(preg_match('/Top\s+\d+/i',$unit->zusatz)) {
+ $unit_candidates[$unit->zusatz] = $unit;
+ }
+ }
+ }*/
+
+ if(count($unit_candidates)) {
+ ksort($unit_candidates, SORT_NUMERIC);
+ $new_unit = array_shift($unit_candidates);
+ $preorder->adb_wohneinheit_id = $new_unit->id;
+ $preorder->save();
+
+ echo "$i Wohneinheit saved\n";
+ continue;
+ }
+ }
+
+ $i++;
+}
+
+
+echo "Same unit count: $same_unit_count (".$i - $same_unit_count." with different unit count)\n";
+echo "Processed $i Preorders\n";