From dcdec3e1f198b027ddc440f3bc6cdd9b9481485f Mon Sep 17 00:00:00 2001 From: Frank Schubert Date: Thu, 12 Oct 2023 15:54:17 +0200 Subject: [PATCH] Fixed preorder split ignoring original unit --- .../preorders-split-multiple-connections.php | 42 +++++++++++++------ 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/scripts/preorder/preorders-split-multiple-connections.php b/scripts/preorder/preorders-split-multiple-connections.php index 7aa398316..8c6cd9197 100755 --- a/scripts/preorder/preorders-split-multiple-connections.php +++ b/scripts/preorder/preorders-split-multiple-connections.php @@ -18,6 +18,7 @@ define("INTERNAL_USER_USERNAME", $me->username); $ignore_preorders = []; $campaign_prem_nord = 5; +$campaign_prem_sued = 6; $campaign_gross_st_florian = 7; $same_unit_count = 0; @@ -26,7 +27,7 @@ $missing_doors = []; $total = 0; $c = 0; -foreach(PreorderModel::search(["deleted" => 0, "preordercampaign_id" => $campaign_prem_nord, "connection_count" => 2]) as $preorder) { +foreach(PreorderModel::search(["deleted" => 0, "preordercampaign_id" => $campaign_prem_nord, "connection_count" => 2, "adb_hausnummer_id" => 1898]) as $preorder) { // check if we have enough units with extref $wohneinheiten = ADBWohneinheitModel::search(["hausnummer_id" => $preorder->adb_hausnummer_id]); $unit_count = count($wohneinheiten); @@ -44,14 +45,14 @@ foreach(PreorderModel::search(["deleted" => 0, "preordercampaign_id" => $campaig $available_units = []; $additional_units = []; // to sort non-specific units last foreach($wohneinheiten as $unit) { - if(!PreorderModel::getFirst(["adb_wohneinheit_id" => $unit->id, "deleted" => 0])) { + if($preorder->adb_wohneinheit_id == $unit->id || !PreorderModel::getFirst(["adb_wohneinheit_id" => $unit->id, "deleted" => 0])) { if($unit->tuer || preg_match('/^Top\s+\d+$/', $unit->zusatz)) { $available_units[] = $unit; } else { $additional_units[] = $unit; } } else { - echo $preorder->id." balh\n"; + //echo $preorder->id." balh\n"; } } @@ -61,6 +62,13 @@ foreach(PreorderModel::search(["deleted" => 0, "preordercampaign_id" => $campaig }*/ + /*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; @@ -74,21 +82,31 @@ foreach(PreorderModel::search(["deleted" => 0, "preordercampaign_id" => $campaig // 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(); + + for($c = 0; $c < $preorder->connection_count; $c++) { + if(!$available_units[$c]->oaid) { + $available_units[$c]->oaid = $available_units[$i]->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.".".($i+1); + $new_preorder->ucode = $preorder->ucode.".".($c+1); $new_preorder->connection_count = 1; - $new_preorder->adb_wohneinheit_id = $available_units[$i]->id; - $new_preorder->oaid = $available_units[$i]->oaid; + $new_preorder->adb_wohneinheit_id = $available_units[$c]->id; + $new_preorder->oaid = $available_units[$c]->oaid; + + //var_dump($new_preorder); + $new_preorder->save(); } - - $preorder->deleted = 1; + //exit; + $preorder->deleted = date("U"); $preorder->delete_reason = "connection_split"; $preorder->save(); $i++;