Added scripts to update units and split preorders with connection_count
> 1
This commit is contained in:
@@ -153,7 +153,7 @@
|
||||
<div class="col-lg-10">
|
||||
<select class="form-control" name="adb_wohneinheit_id" id="adb_wohneinheit_id" />
|
||||
<?php if($preorder->adb_wohneinheit_id): ?>
|
||||
<option value="<?=$preorder->adb_wohneinheit_id?>" selected="selected"><?=$preorder->adb_hausnummer->strasse->name?> <?=$preorder->adb_hausnummer->hausnummer?> <?=$preorder->adb_wohneinheit?></option>
|
||||
<option value="<?=$preorder->adb_wohneinheit_id?>" selected="selected"><?=$preorder->adb_hausnummer->strasse->name?> <?=$preorder->adb_hausnummer->hausnummer?> <?=$preorder->adb_wohneinheit?><?=($preorder->adb_wohneinheit->extref) ? " (".$preorder->adb_wohneinheit->extref.")" : ""?></option>
|
||||
<?php endif; ?>
|
||||
</select>
|
||||
</div>
|
||||
@@ -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)
|
||||
|
||||
@@ -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 = [];
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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";
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
111
scripts/preorders-split-multiple-connections.php
Executable file
111
scripts/preorders-split-multiple-connections.php
Executable file
@@ -0,0 +1,111 @@
|
||||
#!/usr/bin/php
|
||||
<?php
|
||||
|
||||
//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);
|
||||
|
||||
$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";
|
||||
88
scripts/update-preorder-add-unit.php
Executable file
88
scripts/update-preorder-add-unit.php
Executable file
@@ -0,0 +1,88 @@
|
||||
#!/usr/bin/php
|
||||
<?php
|
||||
|
||||
//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);
|
||||
|
||||
$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";
|
||||
Reference in New Issue
Block a user