Merge branch 'fronkdev' into 'master'
Preorderadmin & Superexpert mode See merge request fronk/thetool!284
This commit is contained in:
@@ -140,6 +140,45 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<h4>Multianschlussbestellungen aufsplitten</h4>
|
||||
<div class="row justify-content-end">
|
||||
<div class="col-10">
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
Splittet Bestellungen mit mehereren Anschlüssen auf einzelne Bestellungen auf:
|
||||
</div>
|
||||
</div>
|
||||
<div class="row mt-1">
|
||||
<div class="col">
|
||||
<a href="<?=self::getUrl("Preordercampaign","splitMultipleConnections", ["id" => $campaign->id])?>" class="btn btn-primary"><i class="fad fa-copy"></i> Bestellungen Splitten</a><br />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<h4>Wohneinheiten hinzufügen</h4>
|
||||
<div class="row justify-content-end">
|
||||
<div class="col-10">
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
Trägt Wohneinheiten in Bestellungen ein, wenn fehlt:
|
||||
</div>
|
||||
</div>
|
||||
<div class="row mt-1">
|
||||
<div class="col">
|
||||
<a href="<?=self::getUrl("Preordercampaign","addUnits", ["id" => $campaign->id])?>" class="btn btn-primary"><i class="fas fa-igloo"></i> Wohneinheiten hinzufügen</a><br />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<div class="container-fluid">
|
||||
<div class="row">
|
||||
<div class="col-md-6 <?=(MFAPPNAME == "devthetool") ? "text-danger" : ""?>">
|
||||
<span title="<?=MFAPPNAME?>">the tool © <?=date('Y')?></span> <a href="https://www.xinon.at">Xinon GmbH</a>
|
||||
<span title="<?=MFAPPNAME?>">the to<span class="secondO">o</span>l © <?=date('Y')?></span> <a href="https://www.xinon.at">Xinon GmbH</a>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
@@ -36,6 +36,111 @@
|
||||
$(this).parent('li').toggleClass('open').find('.submenu:first').toggleClass('open');
|
||||
}
|
||||
});
|
||||
|
||||
<?php if($me->can("Superexpert")): ?>
|
||||
$(".secondO").addClass("pointer");
|
||||
|
||||
var se_to = 0;
|
||||
var se_intv;
|
||||
var se_notf;
|
||||
$(".footer .secondO").click(function() {
|
||||
if(!se_to) {
|
||||
$.post("<?=self::getUrl("User", "api")?>",{
|
||||
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 = $('<div class="fixed-top alert alert-warning mx-4 mt-3" id="se_notf" style="width: 50vh;">Achtung: Noch <span class="time">' + rest_duration +'</span> Sekunden. <a href="#" onclick="extSe()">Jetzt verlängern!</a></div>');
|
||||
$("body").prepend(notf_html);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function extSe() {
|
||||
console.log("in ese");
|
||||
$.post("<?=self::getUrl("User", "api")?>", {
|
||||
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("<?=self::getUrl("User", "api")?>", {
|
||||
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('<li id="SeMark"><a class="nav-link dropdown-toggle text-danger" href="#" role="button" aria-haspopup="false" aria-expanded="false" onclick="endSe(); return false;" title="Beenden"><i class="fas fa-crown"></i></a></li>');
|
||||
}
|
||||
}
|
||||
|
||||
function removeSeMark() {
|
||||
$("#SeMark").remove();
|
||||
}
|
||||
|
||||
<?php if($me->superexpertEnabled()): ?>
|
||||
addSeMark();
|
||||
if(!se_intv) {
|
||||
se_to = <?=$me->flags["superexpert_lock_date"]?>;
|
||||
setInterval(checkSe, 1000);
|
||||
}
|
||||
<?php endif; ?>
|
||||
<?php endif; ?>
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,7 +1,7 @@
|
||||
<!-- Topbar Start -->
|
||||
<div class="navbar-custom">
|
||||
<div class="container-fluid">
|
||||
<ul class="list-unstyled topnav-menu float-right mb-0">
|
||||
<ul class="list-unstyled topnav-menu float-right mb-0" id="topbar">
|
||||
|
||||
<li class="dropdown notification-list">
|
||||
<!-- Mobile menu toggle-->
|
||||
@@ -14,7 +14,7 @@
|
||||
</a>
|
||||
<!-- End mobile menu toggle-->
|
||||
</li>
|
||||
|
||||
|
||||
<li class="dropdown notification-list">
|
||||
<a class="nav-link dropdown-toggle" data-toggle="adropdown" href="#" role="button" aria-haspopup="false" aria-expanded="false">
|
||||
<i class="fe-bell noti-icon"></i>
|
||||
|
||||
@@ -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]);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -144,6 +144,62 @@ class User extends mfBaseModel {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function superexpertStart($duration = 1800) {
|
||||
if(!$this->can("Superexpert")) return false;
|
||||
|
||||
$ts = $this->getFlag("superexpert_lock_date");
|
||||
$ts->value(date("U") + $duration);
|
||||
$ts->save();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function superexpertStop($duration = 1800) {
|
||||
if(!$this->can("Superexpert")) return false;
|
||||
|
||||
$ts = $this->getFlag("superexpert_lock_date");
|
||||
$ts->value(0);
|
||||
$ts->save();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function superexpertExtend($duration = 1800) {
|
||||
if(!$this->can("Superexpert")) return false;
|
||||
|
||||
$ts = $this->getFlag("superexpert_lock_date");
|
||||
$ts->value(date("U") + $duration);
|
||||
$ts->save();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function superexpertEnabled() {
|
||||
if(!$this->can("Superexpert")) return false;
|
||||
|
||||
$tsFlag = $this->getFlag("superexpert_lock_date");
|
||||
$ts = $tsFlag->value();
|
||||
|
||||
if(!is_numeric($ts) || !$ts) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$now = date("U");
|
||||
|
||||
// if superexpert is longer than 60 minutes -> disable
|
||||
if($ts > $now + 3601) {
|
||||
$tsFlag->value(null);
|
||||
$tsFlag->save();
|
||||
return false;
|
||||
}
|
||||
|
||||
if($ts > $now) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getFlag($name) {
|
||||
return new WorkerFlag($this->id, $name);
|
||||
}
|
||||
|
||||
@@ -109,8 +109,7 @@ class UserController extends mfBaseController
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected function saveAction()
|
||||
{
|
||||
$r = $this->request;
|
||||
@@ -342,4 +341,75 @@ class UserController extends mfBaseController
|
||||
|
||||
return $me->isAdmin();
|
||||
}
|
||||
|
||||
protected function apiAction() {
|
||||
if(!$this->me->is(["Admin"])) {
|
||||
$this->redirect("Dashboard");
|
||||
}
|
||||
$do = $this->request->do;
|
||||
$data = [];
|
||||
|
||||
switch($do) {
|
||||
case "sse":
|
||||
$return = $this->startSuperexpertApi();
|
||||
break;
|
||||
case "ese":
|
||||
$return = $this->extendSuperexpertApi();
|
||||
break;
|
||||
case "endse":
|
||||
$return = $this->endSuperexpertApi();
|
||||
break;
|
||||
default:
|
||||
$return = false;
|
||||
}
|
||||
|
||||
if(!is_array($return) || !count($return)) {
|
||||
$data = ["status" => "error"];
|
||||
$this->returnJson($data);
|
||||
}
|
||||
$data['status'] = "OK";
|
||||
$data['result'] = $return;
|
||||
$this->returnJson($data);
|
||||
}
|
||||
|
||||
private function startSuperexpertApi() {
|
||||
$me = new User();
|
||||
$me->loadMe();
|
||||
|
||||
if($me->superexpertEnabled() ) {
|
||||
// superexpert mode started already
|
||||
return false;
|
||||
}
|
||||
|
||||
$me->superexpertStart(1800);
|
||||
|
||||
return ["valid_to" => $me->getFlag("superexpert_lock_date")->value()];
|
||||
}
|
||||
|
||||
private function extendSuperexpertApi() {
|
||||
$me = new User();
|
||||
$me->loadMe();
|
||||
|
||||
if(!$me->superexpertEnabled() ) {
|
||||
// superexpert mode must be started already
|
||||
$this->log->debug("se not started");
|
||||
return false;
|
||||
}
|
||||
$this->log->debug("ese");
|
||||
$me->superexpertExtend(1800);
|
||||
|
||||
return ["valid_to" => $me->getFlag("superexpert_lock_date")->value()];
|
||||
}
|
||||
|
||||
private function endSuperexpertApi() {
|
||||
$me = new User();
|
||||
$me->loadMe();
|
||||
|
||||
if($me->superexpertEnabled() ) {
|
||||
$me->superexpertStop();
|
||||
}
|
||||
|
||||
|
||||
return ["valid_to" => null];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
|
||||
final class WorkerPermissionAddcanSuperexpert extends AbstractMigration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
if($this->getEnvironment() == "thetool") {
|
||||
$table = $this->table("WorkerPermission");
|
||||
$table->addColumn("canSuperexpert", "enum", ["null" => false,"values" => 'false,true', "default" => "false", "after" => "canStatistics"]);
|
||||
$table->update();
|
||||
}
|
||||
|
||||
if($this->getEnvironment() == "addressdb") {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
if($this->getEnvironment() == "thetool") {
|
||||
$this->table("WorkerPermission")->removeColumn("canSuperexpert")->save();
|
||||
}
|
||||
|
||||
if($this->getEnvironment() == "addressdb") {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,5 @@ $me = new User(1);
|
||||
define("INTERNAL_USER_ID", $me->id);
|
||||
define("INTERNAL_USER_USERNAME", $me->username);
|
||||
|
||||
foreach(PreorderModel::searchActive(["adb_hausnummer_id" => 1788466, "<status_code" => 145]) as $preorder) {
|
||||
echo $preorder->id."\n";
|
||||
}
|
||||
$netzgebiet = new ADBNetzgebiet(45);
|
||||
var_dump($netzgebiet->getOption("hausnummer_dont_overwrite_netzgebiet"));
|
||||
Reference in New Issue
Block a user