diff --git a/Layout/default/Preordercampaign/Admin.php b/Layout/default/Preordercampaign/Admin.php
index def872bf0..f7310f477 100644
--- a/Layout/default/Preordercampaign/Admin.php
+++ b/Layout/default/Preordercampaign/Admin.php
@@ -140,6 +140,45 @@
+
+
+
Multianschlussbestellungen aufsplitten
+
+
+
+
+ Splittet Bestellungen mit mehereren Anschlüssen auf einzelne Bestellungen auf:
+
+
+
+
+
+
+
+
+
+
+
Wohneinheiten hinzufügen
+
+
+
+
+ Trägt Wohneinheiten in Bestellungen ein, wenn fehlt:
+
+
+
+
+
+
+
diff --git a/application/Preordercampaign/PreordercampaignController.php b/application/Preordercampaign/PreordercampaignController.php
index 19d57acbf..66219d8d2 100644
--- a/application/Preordercampaign/PreordercampaignController.php
+++ b/application/Preordercampaign/PreordercampaignController.php
@@ -480,7 +480,7 @@ class PreordercampaignController extends mfBaseController {
$this->layout()->set("campaign", $campaign);
}
- protected function updateUnitOAIDs() {
+ protected function updateUnitOAIDsAction() {
$this->layout()->setTemplate("Preordercampaign/Admin");
$id = $this->request->id;
@@ -513,7 +513,7 @@ class PreordercampaignController extends mfBaseController {
}
- protected function assignOpenAccessIdsToPreorders() {
+ protected function assignOpenAccessIdsToPreordersAction() {
$this->layout()->setTemplate("Preordercampaign/Admin");
$id = $this->request->id;
@@ -735,7 +735,7 @@ class PreordercampaignController extends mfBaseController {
}
- protected function exportOaidsToRimo() {
+ protected function exportOaidsToRimoAction() {
$this->layout()->setTemplate("Preordercampaign/Admin");
@@ -802,7 +802,7 @@ class PreordercampaignController extends mfBaseController {
}
- protected function updateOaidFromUnit() {
+ protected function updateOaidFromUnitAction() {
$this->layout()->setTemplate("Preordercampaign/Admin");
$id = $this->request->id;
@@ -895,4 +895,192 @@ class PreordercampaignController extends mfBaseController {
}
+ protected function splitMultipleConnectionsAction() {
+ $id = $this->request->id;
+ if(!is_numeric($id) || !$id) {
+ $this->layout()->setFlash("Vorbestellkampagne nicht gefunden", "error");
+ $this->redirect("Preordercampaign");
+ }
+
+ $campaign = new Preordercampaign($id);
+ if(!$campaign->id) {
+ $this->layout()->setFlash("Vorbestellkampagne nicht gefunden", "error");
+ $this->redirect("Preordercampaign");
+ }
+
+ $orders_split = 0;
+ $orders_new = 0;
+ $missing_units = 0;
+
+ foreach(PreorderModel::searchActive(["preordercampaign_id" => $campaign->id, "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) {
+ $missing_units++;
+ /*$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->connection_count > count($available_units)) {
+ $missing_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();
+ }
+
+ if($missing_units) {
+ $this->layout()->setFlash("$missing_units Bestellungen konnten nicht geteilt werden, da nicht genug Wohneinheiten verfügbar sind.", "warning");
+ }
+
+ if($orders_new) {
+ $this->layout()->setFlash("$orders_split Bestellungen in $orders_new Bestellungen aufgeteilt.", "success");
+ }
+ $this->redirect("Preordercampaign", "Admin", ["id" => $id]);
+ }
+
+ protected function addUnitsAction() {
+ $id = $this->request->id;
+ if(!is_numeric($id) || !$id) {
+ $this->layout()->setFlash("Vorbestellkampagne nicht gefunden", "error");
+ $this->redirect("Preordercampaign");
+ }
+
+ $campaign = new Preordercampaign($id);
+ if(!$campaign->id) {
+ $this->layout()->setFlash("Vorbestellkampagne nicht gefunden", "error");
+ $this->redirect("Preordercampaign");
+ }
+
+ $units_added = 0;
+ $missing_units = 0;
+
+ foreach(PreorderModel::searchActive(['preordercampaign_id' => $campaign->id, 'adb_wohneinheit_id' => null, 'connection_count' => 1, "connection_type" => "single-dwelling"]) as $preorder) {
+ if($preorder->adb_wohneinheit_id) {
+ 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)) {
+ $missing_units++;
+ continue;
+ }
+ $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();
+
+ $units_added++;
+ continue;
+ }
+
+
+ if($unit_count > 1) {
+ // legacy comment: assume its single-dwelling with erroneously high door count
+ // current comment: Just use any unit
+ $unit_candidates = [];
+
+ foreach($wohneinheiten as $unit) {
+ if(!$unit->tuer) continue;
+ if($unit->tuer > 1) {
+ $unit_candidates[$unit->tuer] = $unit;
+ }
+ }
+
+ // no candidates with door number -> use any
+
+ if(!count($unit_candidates)) {
+ foreach($wohneinheiten as $unit) {
+ $unit_candidates[] = $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();
+
+ $units_added++;
+ continue;
+ }
+ }
+
+ $i++;
+ }
+
+ if($missing_units) {
+ $this->layout()->setFlash("Für $missing_units Bestellungen wurde keine Wohneinheit gefunden.", "warning");
+ }
+
+ if($units_added) {
+ $this->layout()->setFlash("$units_added Wohneinheiten eingetragen.", "success");
+ }
+ $this->redirect("Preordercampaign", "Admin", ["id" => $id]);
+
+ }
+
}
\ No newline at end of file