From 2df2ca22a14d1acfeedfa03757d76af4b0906875 Mon Sep 17 00:00:00 2001 From: Frank Schubert Date: Thu, 7 Mar 2024 15:33:59 +0100 Subject: [PATCH 1/2] added superexpert mode --- Layout/default/footer.php | 107 +++++++++++++++++- Layout/default/topbar.php | 4 +- application/User/User.php | 56 +++++++++ application/User/UserController.php | 74 +++++++++++- ...0_worker_permission_addcan_superexpert.php | 31 +++++ scripts/test.php | 5 +- 6 files changed, 269 insertions(+), 8 deletions(-) create mode 100644 db/migrations/20240305143620_worker_permission_addcan_superexpert.php diff --git a/Layout/default/footer.php b/Layout/default/footer.php index e18e6fa8b..58916a8d7 100644 --- a/Layout/default/footer.php +++ b/Layout/default/footer.php @@ -7,7 +7,7 @@
"> - the tool © Xinon GmbH + the tool © Xinon GmbH
@@ -36,6 +36,111 @@ $(this).parent('li').toggleClass('open').find('.submenu:first').toggleClass('open'); } }); + + can("Superexpert")): ?> + $(".secondO").addClass("pointer"); + + var se_to = 0; + var se_intv; + var se_notf; + $(".footer .secondO").click(function() { + if(!se_to) { + $.post("",{ + do: "sse" + }, + function(success) { + if(!("status" in success)) return; + if(success.status == "OK") { + if(!("result" in success)) return; + if(!("valid_to" in success.result) || !success.result.valid_to) return; + + se_to = success.result.valid_to; + addSeMark(); + se_intv = setInterval(checkSe, 1000); + location.reload(); + } + }, + "json"); + } + }); + + function checkSe() { + var now = Math.floor(Date.now() / 1000); + if(!se_to || se_to < 0) { + clearInterval(se_intv); + se_to = null; + $("#se_notf").remove(); + removeSeMark(); + return; + } + var rest_duration = se_to - now; + + if(rest_duration <= 0) { + clearInterval(se_intv); + se_to = null; + $("#se_notf").remove(); + removeSeMark(); + return; + } + + if(rest_duration < 60*5) { + // show notification + if($("#se_notf").length) { + $("#se_notf .time").text(rest_duration); + } else { + var notf_html = $('
Achtung: Noch ' + rest_duration +' Sekunden. Jetzt verlängern!
'); + $("body").prepend(notf_html); + } + + } + } + + function extSe() { + console.log("in ese"); + $.post("", { + do: "ese" + }, + function(success) { + if(!("result" in success)) return; + if(!("valid_to" in success.result) || !success.result.valid_to) return; + se_to = success.result.valid_to; + }, + "json" + ); + } + + function endSe() { + $.post("", { + do: "endse" + }, + function(success) { + if(!("result" in success)) return; + if(!("valid_to" in success.result)) return; + se_to = success.result.valid_to; + location.reload(); + }, + "json" + ); + } + + function addSeMark() { + if(!$("#se-mark").length) { + $("#topbar").append('
  • '); + } + } + + function removeSeMark() { + $("#SeMark").remove(); + } + + superexpertEnabled()): ?> + addSeMark(); + if(!se_intv) { + se_to = flags["superexpert_lock_date"]?>; + setInterval(checkSe, 1000); + } + + \ No newline at end of file diff --git a/Layout/default/topbar.php b/Layout/default/topbar.php index 1bb203247..07ae03c02 100644 --- a/Layout/default/topbar.php +++ b/Layout/default/topbar.php @@ -1,7 +1,7 @@ + +
    +
    +

    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