diff --git a/Layout/default/Voiceplan/Index.php b/Layout/default/Voiceplan/Index.php
index bc85f0100..e7d0786db 100644
--- a/Layout/default/Voiceplan/Index.php
+++ b/Layout/default/Voiceplan/Index.php
@@ -68,6 +68,7 @@
$plan->id])?>">=$plan->name?>
=$plan->description?>
- =VoiceplandestinationModel::count(['voiceplan_id' => $plan->id])?>
+ =count($plan->zones)?>
+ =count($plan->destinations)?>
=date("d.m.Y H:i", $plan->create)?> (=$plan->creator->name?>)
$plan->id])?>">
diff --git a/Layout/default/Voiceplan/View.php b/Layout/default/Voiceplan/View.php
index 6daaad60d..585e94b9c 100644
--- a/Layout/default/Voiceplan/View.php
+++ b/Layout/default/Voiceplan/View.php
@@ -16,7 +16,7 @@
=$plan->name?>
- Sprachtarife
+ Tarifzonen
@@ -30,10 +30,10 @@
@@ -43,8 +43,8 @@
- Destination
- Prefix
+ Zone
+ Anzahl Prefixes
Taktung
Einkaufspreis
Verkaufspreis
@@ -52,19 +52,19 @@
Bearbeitet
-
+
- =$destination->destination?>
- =$destination->prefix?>
- =($destination->increment_first && $destination->increment) ? "$destination->increment_first"."/".$destination->increment : ""?>
- =$destination->purchase_price?>
- =$destination->price?>
+ $zone->id])?>">=$zone->name?>
+ =count($zone->destinations)?>
+ =($zone->increment_first && $zone->increment) ? $zone->increment_first."/".$zone->increment : ""?>
+ =$zone->purchase_price?>
+ =$zone->price?>
=date("d.m.Y H:i", $plan->create)?> (=$plan->creator->name?>)
=date("d.m.Y H:i", $plan->edit)?> (=$plan->editor->name?>)
- $destination->id])?>">
- $destination->id])?>">
- $destination->id])?>" onclick="if(!confirm('Destination wirklich löschen?')) return false;" class="text-danger" title="Löschen">
+ $zone->id])?>">
+ $zone->id])?>">
+ $zone->id])?>" onclick="if(!confirm('Tarifzone wirklich löschen?')) return false;" class="text-danger" title="Löschen">
diff --git a/Layout/default/Voiceplandestination/Form.php b/Layout/default/Voiceplandestination/Form.php
index 2230525d7..7e0a882cf 100644
--- a/Layout/default/Voiceplandestination/Form.php
+++ b/Layout/default/Voiceplandestination/Form.php
@@ -7,7 +7,8 @@
">=MFAPPNAME_SLUG?>
">Sprachtarife
- $voiceplan->id])?>">
+ $zone->voiceplan_id])?>">Sprachtarif =$zone->voiceplan->name?>
+ Destinationen Tarifzone =$zone->name?>
=($plan->id) ? "Destination ".$destination->destination." bearbeiten" : "Neu" ?>
@@ -31,19 +32,16 @@
@@ -62,27 +60,6 @@
-
-
-
-
-
-
diff --git a/Layout/default/Voiceplanzone/Form.php b/Layout/default/Voiceplanzone/Form.php
new file mode 100644
index 000000000..fd69326e8
--- /dev/null
+++ b/Layout/default/Voiceplanzone/Form.php
@@ -0,0 +1,95 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Layout/default/Voiceplanzone/View.php b/Layout/default/Voiceplanzone/View.php
new file mode 100644
index 000000000..34acb1127
--- /dev/null
+++ b/Layout/default/Voiceplanzone/View.php
@@ -0,0 +1,99 @@
+getUrl($Mod,"View");
+ $pagination_baseurl_params = ["filter" => $filter, "id" => $zone->id];
+ $pagination_entity_name = "Destinations";
+?>
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Layout/default/menu.php b/Layout/default/menu.php
index f8aba54e9..7673c12bb 100644
--- a/Layout/default/menu.php
+++ b/Layout/default/menu.php
@@ -100,7 +100,7 @@
diff --git a/application/OpenAccessId/OpenAccessId.php b/application/OpenAccessId/OpenAccessId.php
index 42238f910..6f9b6dc80 100644
--- a/application/OpenAccessId/OpenAccessId.php
+++ b/application/OpenAccessId/OpenAccessId.php
@@ -73,7 +73,7 @@ class OpenAccessId extends mfBaseModel {
$unit_extdata = $extdata;
}
- if(is_object($extdata) && isset($extdata->rimo) && isset($extdata->rimo->ftu->id)) {
+ if(is_object($extdata) && isset($extdata->rimo) && isset($extdata->rimo->ftu->id) && $extdata->rimo->ftu->id) {
//var_dump($extdata);exit;
$fetch_ftu = false;
}
diff --git a/application/Voiceplan/Voiceplan.php b/application/Voiceplan/Voiceplan.php
index 52bf000c3..5a962148c 100644
--- a/application/Voiceplan/Voiceplan.php
+++ b/application/Voiceplan/Voiceplan.php
@@ -4,6 +4,7 @@ class Voiceplan extends mfBaseModel {
private $creator;
private $editor;
+ private $zones;
private $destinations;
public function importDestinationsFromCsv(File $file) {
@@ -68,10 +69,18 @@ class Voiceplan extends mfBaseModel {
if($this->$name == null) {
if($name == "destinations") {
- $this->destinations = VoiceplandestinationModel::search(["voiceplan_id" => $this->id]);
+ $this->destinations = [];
+ foreach($this->getProperty("zones") as $zone) {
+ $this->destinations[] = $zone->destinations;
+ }
return $this->destinations;
}
+ if($name == "zones") {
+ $this->zones = VoiceplanzoneModel::search(["voiceplan_id" => $this->id]);
+ return $this->zones;
+ }
+
if($name == "creator") {
$user = mfValuecache::singleton()->get("Worker-id-".$this->create_by);
if($user) {
diff --git a/application/Voiceplan/VoiceplanController.php b/application/Voiceplan/VoiceplanController.php
index 2e485b96e..4cdc5cf54 100644
--- a/application/Voiceplan/VoiceplanController.php
+++ b/application/Voiceplan/VoiceplanController.php
@@ -73,9 +73,9 @@ class VoiceplanController extends mfBaseController {
$pagination['start'] = intval($this->request->s);
}
- $pagination['maxItems'] = VoiceplandestinationModel::count(['voiceplan_id' => $id]);
- $destinations = VoiceplandestinationModel::search(['voiceplan_id' => $id], $pagination);
- $this->layout()->set("destinations", $destinations);
+ $pagination['maxItems'] = VoiceplanzoneModel::count(['voiceplan_id' => $id]);
+ $zones = VoiceplanzoneModel::search(['voiceplan_id' => $id], $pagination);
+ $this->layout()->set("zones", $zones);
$this->layout()->set("pagination", $pagination);
diff --git a/application/Voiceplandestination/Voiceplandestination.php b/application/Voiceplandestination/Voiceplandestination.php
index abe6654c8..f88c38c39 100644
--- a/application/Voiceplandestination/Voiceplandestination.php
+++ b/application/Voiceplandestination/Voiceplandestination.php
@@ -3,4 +3,38 @@
class Voiceplandestination extends mfBaseModel {
protected $forcestr = ["name", "destination", "prefix"];
+ private $voiceplan;
+
+ public function getProperty($name) {
+ if($this->$name == null) {
+
+ if(!$this->id) {
+ return null;
+ }
+
+ if($name == "voiceplan") {
+ $zone = $this->getProperty("voiceplanzone");
+ if($zone->voiceplan_id) {
+ $voiceplan = new Voiceplan($zone->voiceplan_id);
+ if($voiceplan->id) {
+ $this->voiceplan = $voiceplan;
+ }
+ }
+ return $this->voiceplan;
+ }
+
+ $classname = ucfirst($name);
+ $idfield = $name."_id";
+ $this->$name = new $classname($this->$idfield);
+
+ if($this->$name->id) {
+ return $this->$name;
+ } else {
+ return null;
+ }
+ }
+
+ return $this->$name;
+ }
+
}
\ No newline at end of file
diff --git a/application/Voiceplandestination/VoiceplandestinationController.php b/application/Voiceplandestination/VoiceplandestinationController.php
index 6f798193f..837da2205 100644
--- a/application/Voiceplandestination/VoiceplandestinationController.php
+++ b/application/Voiceplandestination/VoiceplandestinationController.php
@@ -17,13 +17,14 @@ class VoiceplandestinationController extends mfBaseController {
protected function addAction() {
$this->layout()->setTemplate("Voiceplandestination/Form");
- $voiceplans = VoiceplanModel::getAll();
- $this->layout()->set("voiceplans", $voiceplans);
+ $zones = VoiceplanzoneModel::getAll();
+ $this->layout()->set("zones", $zones);
- $voiceplan_id = $this->request->voiceplan_id;
- if($voiceplan_id) {
- $voiceplan = new Voiceplan($voiceplan_id);
- $this->layout()->set("voiceplan", $voiceplan);
+ $zone_id = $this->request->voiceplanzone_id;
+ if(strtolower($this->action) == "add" && $zone_id) {
+ $zone = new Voiceplanzone($zone_id);
+ $this->layout()->set("zone", $zones);
+ $this->layout()->set("zone_id", $zone->id);
}
}
@@ -47,7 +48,7 @@ class VoiceplandestinationController extends mfBaseController {
protected function saveAction() {
$r = $this->request;
- var_dump($r);
+ //var_dump($r);exit;
$id = $r->id;
if(is_numeric($id) && $id > 0) {
@@ -63,25 +64,11 @@ class VoiceplandestinationController extends mfBaseController {
}
$data = [];
- $data['voiceplan_id'] = $r->voiceplan_id;
+ $data['voiceplanzone_id'] = $r->voiceplanzone_id;
$data['destination'] = $r->destination;
$data['prefix'] = intval($r->prefix);
- $data['purchase_price'] = (str_replace(",",".",$r->purchase_price)) ? str_replace(",",".",$r->purchase_price) : 0;
- $data['price'] = (str_replace(",",".",$r->price)) ? str_replace(",",".",$r->price) : 0;
- if($r->increment) {
- $increments = explode("/",$r->increment);
- if(count($increments) != 2) {
- $this->layout()->setFlash("Ungültige Taktung", "error");
- $this->layout()->set("destination", VoiceplandestinationModel::create($data));
- return $this->addAction();
- }
-
- $data["increment_first"] = $increments[0];
- $data["increment"] = $increments[1];
- }
-
- if(!$data['destination'] || !$data['prefix'] || !$data['voiceplan_id']) {
+ if(!$data['destination'] || !$data['prefix'] || !$data['voiceplanzone_id']) {
$this->layout()->setFlash("Destination, Prefix und Tarifpaket sind erforderlich", "error");
$this->layout()->set("destination", VoiceplandestinationModel::create($data));
return $this->addAction();
@@ -100,6 +87,6 @@ class VoiceplandestinationController extends mfBaseController {
return $this->addAction();
}
- $this->redirect("Voiceplan", "view", ["id" => $destination->voiceplan_id]);
+ $this->redirect("Voiceplanzone", "view", ["id" => $destination->voiceplanzone_id]);
}
}
\ No newline at end of file
diff --git a/application/Voiceplandestination/VoiceplandestinationModel.php b/application/Voiceplandestination/VoiceplandestinationModel.php
index 9a9548165..2d6d7218b 100644
--- a/application/Voiceplandestination/VoiceplandestinationModel.php
+++ b/application/Voiceplandestination/VoiceplandestinationModel.php
@@ -1,14 +1,9 @@
$name == null) {
+
+ if(!$this->id) {
+ return null;
+ }
+
+ if($name == "destinations") {
+ $this->destinations = VoiceplandestinationModel::search(["voiceplanzone_id" => $this->id]);
+ return $this->destinations;
+ }
+
+ $classname = ucfirst($name);
+ $idfield = $name."_id";
+ $this->$name = new $classname($this->$idfield);
+
+ if($this->$name->id) {
+ return $this->$name;
+ } else {
+ return null;
+ }
+ }
+
+ return $this->$name;
+ }
+
+}
\ No newline at end of file
diff --git a/application/Voiceplanzone/VoiceplanzoneController.php b/application/Voiceplanzone/VoiceplanzoneController.php
new file mode 100644
index 000000000..190d27b77
--- /dev/null
+++ b/application/Voiceplanzone/VoiceplanzoneController.php
@@ -0,0 +1,140 @@
+needlogin=true;
+ $me = new User();
+ $me->loadMe();
+ $this->me = $me;
+ $this->layout()->set("me",$me);
+
+ if(!$me->isAdmin()) {
+ $this->redirect("Dashboard");
+ }
+ }
+
+ protected function addAction() {
+ $this->layout()->setTemplate("Voiceplanzone/Form");
+
+ if(strtolower($this->action) == "add" && $this->request->voiceplan_id) {
+ $this->layout()->set("voiceplan_id", $this->request->voiceplan_id);
+ $this->layout()->set("voiceplan", new Voiceplan($this->request->voiceplan_id));
+ }
+ }
+
+ protected function viewAction() {
+ $this->layout()->setTemplate("Voiceplanzone/View");
+ $id = $this->request->id;
+ if(!is_numeric($id) || $id < 1) {
+ $this->layout()->setFlash("Tarifzone nicht gefunden.", "error");
+ $this->redirect("Voiceplan");
+ }
+
+ $zone = new Voiceplanzone($id);
+ if(!$zone->id) {
+ $this->layout()->setFlash("Tarifzone nicht gefunden.", "error");
+ $this->redirect("Voiceplan");
+ }
+
+ $this->layout()->set("zone", $zone);
+
+ $pagination = [];
+ $pagination['start'] = 0;
+ $pagination['count'] = 20;
+ $pagination['maxItems'] = 0;
+
+ if(is_numeric($this->request->s)) {
+ $pagination['start'] = intval($this->request->s);
+ }
+
+ $pagination['maxItems'] = VoiceplandestinationModel::count(['voiceplanzone_id' => $id]);
+ $destinations = VoiceplandestinationModel::search(['voiceplanzone_id' => $id], $pagination);
+ $this->layout()->set("destinations", $destinations);
+
+ $this->layout()->set("pagination", $pagination);
+
+ }
+
+ protected function editAction() {
+ $id = $this->request->id;
+ if(!is_numeric($id) || $id < 1) {
+ $this->layout()->setFlash("Tarifzone nicht gefunden.", "error");
+ $this->redirect("Voiceplan");
+ }
+
+ $zone = new Voiceplanzone($id);
+ if(!$zone->id) {
+ $this->layout()->setFlash("Tarifzone nicht gefunden.", "error");
+ $this->redirect("Voiceplan");
+ }
+
+ $this->layout()->set("zone", $zone);
+ return $this->addAction();
+ }
+
+ protected function saveAction() {
+ $r = $this->request;
+ //var_dump($r);exit;
+
+ $id = $r->id;
+ if(is_numeric($id) && $id > 0) {
+ $mode = "edit";
+ $zone = new Voiceplanzone($id);
+ if(!$zone->id) {
+ $this->layout()->setFlash("Tarifzone nicht gefunden", "error");
+ $this->redirect("Voiceplan");
+ }
+ } else {
+ $id = false;
+ $mode = "add";
+ }
+
+ $data["voiceplan_id"] = $r->voiceplan_id;
+ $data["name"] = $r->name;
+ $data['purchase_price'] = (str_replace(",",".",$r->purchase_price)) ? str_replace(",",".",$r->purchase_price) : 0;
+ $data['price'] = (str_replace(",",".",$r->price)) ? str_replace(",",".",$r->price) : 0;
+
+ if($r->increment) {
+ $increments = explode("/",$r->increment);
+ if(count($increments) != 2) {
+ $this->layout()->setFlash("Ungültige Taktung", "error");
+ if($mode == "edit") {
+ $this->redirect("Voiceplanzone", "edit", ["id" => $id]);
+ } else {
+ $this->layout()->set("zone", VoiceplanzoneModel::create($data));
+ return $this->addAction();
+ }
+ }
+
+ $data["increment_first"] = $increments[0];
+ $data["increment"] = $increments[1];
+ }
+
+ if(!$data['name'] || !$data['voiceplan_id']) {
+ $this->layout()->setFlash("Name und Tarifpaket sind erforderlich", "error");
+ if($mode == "edit") {
+ $this->redirect("Voiceplanzone", "edit", ["id" => $id]);
+ } else {
+ $this->layout()->set("destination", VoiceplanzoneModel::create($data));
+ return $this->addAction();
+ }
+ }
+
+ if($mode == "edit") {
+ $zone->update($data);
+ } else {
+ $zone = VoiceplanzoneModel::create($data);
+ }
+
+ $id = $zone->save();
+ if(!$id) {
+ $this->layout()->setFlash("Fehler beim Speichern!", "error");
+ $this->layout()->set("zone", $zone);
+ return $this->addAction();
+ }
+
+ $this->redirect("Voiceplan", "view", ["id" => $zone->voiceplan_id]);
+
+ }
+}
\ No newline at end of file
diff --git a/application/Voiceplanzone/VoiceplanzoneModel.php b/application/Voiceplanzone/VoiceplanzoneModel.php
new file mode 100644
index 000000000..583eb7182
--- /dev/null
+++ b/application/Voiceplanzone/VoiceplanzoneModel.php
@@ -0,0 +1,134 @@
+ $value) {
+ if(property_exists(get_called_class(), $field)) {
+ $model ->$field = $value;
+ }
+ }
+
+ $me = mfValuecache::singleton()->get("me");
+ if(!$me) {
+ $me = new User();
+ $me->loadMe();
+ mfValuecache::singleton()->set("me", $me);
+ }
+
+ if($model->create_by === null) {
+ $model->create_by = $me->id;
+ }
+ if($model->edit_by === null) {
+ $model->edit_by = $me->id;
+ }
+
+ return $model;
+ }
+
+ public static function getAll() {
+ $items = [];
+
+ $db = FronkDB::singleton();
+
+ $res = $db->select("Voiceplanzone", "*", "1=1 ORDER BY voiceplan_id,name");
+ if($db->num_rows($res)) {
+ while($data = $db->fetch_object($res)) {
+ $items[] = new Voiceplanzone($data);
+ }
+ }
+ return $items;
+
+ }
+
+ public static function getFirst() {
+ $db = FronkDB::singleton();
+
+ $where = self::getSqlFilter($filter);
+ $res = $db->select("Voiceplanzone", "*", "$where ORDER BY voiceplan_id,name");
+ if($db->num_rows($res)) {
+ $data = $db->fetch_object($res);
+ $item = new Voiceplanzone($data);
+ if($item->id) {
+ return $item;
+ } else {
+ return null;
+ }
+ }
+ return null;
+ }
+
+ public static function count($filter) {
+ $db = FronkDB::singleton();
+
+ $where = self::getSqlFilter($filter);
+ $sql = "SELECT COUNT(*) as cnt FROM Voiceplanzone
+ WHERE $where
+ ";
+
+ $res = $db->query($sql);
+ if($db->num_rows($res)) {
+ $data = $db->fetch_object($res);
+ return $data->cnt;
+ }
+ return 0;
+ }
+
+ public static function search($filter) {
+ $items = [];
+ $db = FronkDB::singleton();
+
+ $where = self::getSqlFilter($filter);
+
+ $sql = "SELECT * FROM Voiceplanzone
+ WHERE $where
+ ORDER BY voiceplan_id,name";
+
+ $res = $db->query($sql);
+
+ if($db->num_rows($res)) {
+ while($data = $db->fetch_object($res)) {
+ $items[] = new Voiceplanzone($data);
+ }
+ }
+ return $items;
+ }
+
+ private static function getSqlFilter($filter) {
+ $where = "1=1 ";
+
+
+ if(array_key_exists("voiceplan_id", $filter)) {
+ $voiceplan_id = $filter['voiceplan_id'];
+ if(is_numeric($voiceplan_id)) {
+ $where .= " AND voiceplan_id=$voiceplan_id";
+ }
+ }
+
+ //var_dump($filter);exit;
+ if(array_key_exists("name", $filter)) {
+ $name = FronkDB::singleton()->escape($filter['name']);
+ if($name) {
+ $where .= " AND name='$name'";
+ }
+ }
+
+ //var_dump($filter, $where);exit;
+ return $where;
+ }
+
+}
diff --git a/db/migrations/20231004143109_add_voicenumber_tables.php b/db/migrations/20231004143109_add_voicenumber_tables.php
index fa56f8b6d..51d89e15d 100644
--- a/db/migrations/20231004143109_add_voicenumber_tables.php
+++ b/db/migrations/20231004143109_add_voicenumber_tables.php
@@ -82,10 +82,10 @@ final class AddVoicenumberTables extends AbstractMigration
public function down(): void
{
if($this->getEnvironment() == "thetool") {
- $this->table("Voiceplandestination")->drop();
- $this->table("Voiceplan")->drop();
- $this->table("Voicenumber")->drop();
- $this->table("Voicenumberblock")->drop();
+ $this->table("Voiceplandestination")->drop()->save();
+ $this->table("Voiceplan")->drop()->save();
+ $this->table("Voicenumber")->drop()->save();
+ $this->table("Voicenumberblock")->drop()->save();
}
if($this->getEnvironment() == "addressdb") {
diff --git a/db/migrations/20231010161225_add_voiceplan_zone.php b/db/migrations/20231010161225_add_voiceplan_zone.php
new file mode 100644
index 000000000..276c7aac0
--- /dev/null
+++ b/db/migrations/20231010161225_add_voiceplan_zone.php
@@ -0,0 +1,56 @@
+getEnvironment() == "thetool") {
+ $table = $this->table("Voiceplanzone");
+ $table->addColumn("voiceplan_id", "integer", ["null" => false]);
+ $table->addColumn("name", "string", ["null" => false, "limit" => 255]);
+ $table->addColumn("purchase_price", "decimal", ["null" => false, "precision" => 14, "scale" => 4]);
+ $table->addColumn("price", "decimal", ["null" => false, "precision" => 14, "scale" => 4]);
+ $table->addColumn("increment_first", "integer", ["null" => false, "default" => 60]);
+ $table->addColumn("increment", "integer", ["null" => false, "default" => 30]);
+ $table->addColumn("create_by", "integer", ["null" => false]);
+ $table->addColumn("edit_by", "integer", ["null" => false]);
+ $table->addColumn("create", "integer", ["null" => false]);
+ $table->addColumn("edit", "integer", ["null" => false]);
+ $table->create();
+
+ $table = $this->table("Voiceplandestination");
+ $table->removeColumn("purchase_price");
+ $table->removeColumn("price");
+ $table->removeColumn("increment_first");
+ $table->removeColumn("increment");
+ $table->renameColumn("voiceplan_id", "voiceplanzone_id");
+ $table->update();
+ }
+
+ if($this->getEnvironment() == "addressdb") {
+
+ }
+ }
+
+ public function down(): void
+ {
+ if($this->getEnvironment() == "thetool") {
+ $table = $this->table("Voiceplandestination");
+ $table->renameColumn("voiceplanzone_id", "voiceplan_id");
+ $table->addColumn("purchase_price", "decimal", ["null" => false, "precision" => 14, "scale" => 4]);
+ $table->addColumn("price", "decimal", ["null" => false, "precision" => 14, "scale" => 4]);
+ $table->addColumn("increment_first", "integer", ["null" => false, "default" => 1]);
+ $table->addColumn("increment", "integer", ["null" => false, "default" => 1]);
+ $table->update();
+
+ $this->table("Voiceplanzone")->drop()->save();
+ }
+
+ if($this->getEnvironment() == "addressdb") {
+
+ }
+ }
+}