168 lines
5.4 KiB
PHP
Executable File
168 lines
5.4 KiB
PHP
Executable File
#!/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_ids = [];
|
|
$campaign_ids["premnord"] = 5;
|
|
$campaign_ids["premsued"] = 6;
|
|
$campaign_ids["gsf"] = 7;
|
|
$campaign_ids["kalwang"] = 41;
|
|
$campaign_ids["st_stefan_stainz"] = 36;
|
|
$campaign_ids["wettmannst"] = 37;
|
|
$campaign_ids["mureck"] = 42;
|
|
$campaign_ids["lieboch"] = 35;
|
|
$campaign_ids["lieboch_vorab"] = 49;
|
|
$campaign_ids["lieboch_smart"] = 39;
|
|
|
|
if(!array_key_exists(1,$argv)) {
|
|
|
|
echo "Bitte eines der folgenden Netzgebiete angeben:\n\n";
|
|
echo implode("\n", array_keys($campaign_ids));
|
|
echo "\n\n";
|
|
exit(1);
|
|
}
|
|
|
|
if(!array_key_exists($argv[1], $campaign_ids)) {
|
|
die("Ungültige Kampagne\n");
|
|
}
|
|
|
|
$selected_campaign = $campaign_ids[$argv[1]];
|
|
|
|
if(!$selected_campaign) {
|
|
echo "Keine Kampagne ausgewählt.\n";
|
|
exit;
|
|
}
|
|
|
|
echo "selected campaign: $selected_campaign - ".$argv[1]."\n";
|
|
|
|
$same_unit_count = 0;
|
|
$missing_units = [];
|
|
$missing_doors = [];
|
|
|
|
$total = 0;
|
|
$c = 0;
|
|
foreach(PreorderModel::searchActive(["preordercampaign_id" => $selected_campaign, "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 = [];
|
|
$additional_units = []; // to sort non-specific units last
|
|
foreach($wohneinheiten as $unit) {
|
|
if($preorder->adb_wohneinheit_id == $unit->id || !PreorderModel::getFirstActive(["adb_wohneinheit_id" => $unit->id])) {
|
|
if($unit->tuer || preg_match('/^(Top|Tuer|Tür)\s+\d+$/i', $unit->zusatz)) {
|
|
$available_units[] = $unit;
|
|
} else {
|
|
$additional_units[] = $unit;
|
|
}
|
|
} else {
|
|
//echo $preorder->id." balh\n";
|
|
}
|
|
}
|
|
|
|
if(count($additional_units)) $available_units = array_merge($available_units, $additional_units);
|
|
/*if($preorder->id == 2441) {
|
|
var_dump($available_units);exit;
|
|
}*/
|
|
|
|
|
|
/*foreach($available_units as $au) {
|
|
echo "unit id: ".$au->id."\n";
|
|
echo "hausnummer ".$au->hausnummer_id." \n";
|
|
echo $au->extref."\n\n";
|
|
}*/
|
|
|
|
|
|
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($c = 0; $c < $preorder->connection_count; $c++) {
|
|
if(!$available_units[$c]->oaid) {
|
|
$available_units[$c]->oaid = $available_units[$c]->getNewOAID();
|
|
$available_units[$c]->save();
|
|
}
|
|
|
|
/*
|
|
echo "unit id: ".$available_units[$c]->id."\n";
|
|
echo "hausnummer ".$available_units[$c]->hausnummer_id." \n";
|
|
echo $available_units[$c]->extref."\n\n";
|
|
*/
|
|
|
|
$new_preorder = clone($preorder);
|
|
$new_preorder->ucode = $preorder->ucode.".".($c+1);
|
|
$new_preorder->connection_count = 1;
|
|
$new_preorder->adb_wohneinheit_id = $available_units[$c]->id;
|
|
$new_preorder->oaid = $available_units[$c]->oaid;
|
|
|
|
//var_dump($new_preorder);
|
|
|
|
$new_preorder->save();
|
|
}
|
|
//exit;
|
|
$preorder->deleted = date("U");
|
|
$preorder->delete_reason = "connection_split";
|
|
$preorder->save();
|
|
}
|
|
|
|
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." ".$preorder->adb_hausnummer->hausnummer.'";';
|
|
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." ".$preorder->adb_hausnummer->hausnummer.'";';
|
|
echo $preorder->connection_count.';';
|
|
echo $md["unit_count"].';';
|
|
echo $md["door_count"].';';
|
|
echo "\n";
|
|
}
|
|
|
|
echo "Processed $total, created $c preorders\n";
|