diff --git a/Layout/default/Voiceplan/Form.php b/Layout/default/Voiceplan/Form.php index 69ee2467f..779af2baa 100644 --- a/Layout/default/Voiceplan/Form.php +++ b/Layout/default/Voiceplan/Form.php @@ -53,7 +53,7 @@
- + " />
diff --git a/Layout/default/Voiceplan/View.php b/Layout/default/Voiceplan/View.php index 5e9cb47cf..7d48bc692 100644 --- a/Layout/default/Voiceplan/View.php +++ b/Layout/default/Voiceplan/View.php @@ -21,10 +21,52 @@ - +
+
+
+

Filter

+ +
"> + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ +
+ +
+
+
@@ -55,8 +97,12 @@ $zone->id])?>">name?> - destinations) > 1) ? count($zone->destinations)." Destinations" : "+".$zone->destinations[0]->prefix.""?> - increment_first && $zone->increment) ? $zone->increment_first."/".$zone->increment : ""?> + destinations) > 1): ?> + ">destinations)?> Destinations + + +destinations[0]->prefix?> + + increment_first && $zone->increment) ? $zone->increment_first."/".$zone->increment : ""?> purchase_price?> price?> create)?> (creator->name?>) diff --git a/application/Voiceplan/VoiceplanController.php b/application/Voiceplan/VoiceplanController.php index a1bc10666..02aa5bbc7 100644 --- a/application/Voiceplan/VoiceplanController.php +++ b/application/Voiceplan/VoiceplanController.php @@ -64,6 +64,17 @@ class VoiceplanController extends mfBaseController { $this->layout()->set("plan", $plan); + $filter = []; + if(is_array($this->request->filter)) { + $filter = $this->request->filter; + } + + $this->layout->set("filter", $filter); + + if($filter) { + $filter = $this->getPreparedViewFilter($filter); + } + $pagination = []; $pagination['start'] = 0; $pagination['count'] = 20; @@ -73,14 +84,36 @@ class VoiceplanController extends mfBaseController { $pagination['start'] = intval($this->request->s); } - $pagination['maxItems'] = VoiceplanzoneModel::count(['voiceplan_id' => $id]); - $zones = VoiceplanzoneModel::search(['voiceplan_id' => $id], $pagination); + $zone_search = $filter; + $zone_search['voiceplan_id'] = $id; + + $pagination['maxItems'] = VoiceplanzoneModel::count($zone_search); + $zones = VoiceplanzoneModel::search($zone_search, $pagination); $this->layout()->set("zones", $zones); $this->layout()->set("pagination", $pagination); } + private function getPreparedViewFilter($filter) { + $new_filter = []; + + if(array_key_exists("prefix", $filter) && $filter['prefix']) { + $prefix = $filter['prefix']; + if(substr($prefix, 0, 1) == "+") { + $prefix = substr($prefix, 1)."%"; + } + $new_filter['prefix'] = $prefix; + unset($filter['prefix']); + } + + foreach($filter as $name => $value) { + $new_filter[$name] = $value; + } + + return $new_filter; + } + protected function addAction() { $this->layout()->setTemplate("Voiceplan/Form"); @@ -124,7 +157,7 @@ class VoiceplanController extends mfBaseController { $data = []; $data['name'] = $r->name; $data['description'] = $r->description; - $data['price_multiplicator'] = ($r->price_multiplicator) ? $r->price_multiplicator : 1; + $data['price_multiplicator'] = ($r->price_multiplicator) ? $r->price_multiplicator : null; if($r->increment) { diff --git a/application/Voiceplanzone/VoiceplanzoneModel.php b/application/Voiceplanzone/VoiceplanzoneModel.php index 1575a64cd..c16aaf6c0 100644 --- a/application/Voiceplanzone/VoiceplanzoneModel.php +++ b/application/Voiceplanzone/VoiceplanzoneModel.php @@ -77,9 +77,20 @@ class VoiceplanzoneModel { $db = FronkDB::singleton(); $where = self::getSqlFilter($filter); - $sql = "SELECT COUNT(*) as cnt FROM Voiceplanzone + /*$sql = "SELECT COUNT(*) as cnt FROM Voiceplanzone + LEFT JOIN Voiceplan ON (Voiceplanzone.voiceplan_id = Voiceplan.id) + LEFT JOIN Voiceplandestination ON (Voiceplandestination.voiceplanzone_id = Voiceplanzone.id) WHERE $where "; + */ + $sql = "SELECT COUNT(*) as cnt FROM ( + SELECT Voiceplanzone.* FROM Voiceplanzone + LEFT JOIN Voiceplan ON (Voiceplanzone.voiceplan_id = Voiceplan.id) + LEFT JOIN Voiceplandestination ON (Voiceplandestination.voiceplanzone_id = Voiceplanzone.id) + WHERE $where + GROUP BY Voiceplanzone.id + ) c + "; $res = $db->query($sql); if($db->num_rows($res)) { @@ -95,9 +106,12 @@ class VoiceplanzoneModel { $where = self::getSqlFilter($filter); - $sql = "SELECT * FROM Voiceplanzone + $sql = "SELECT Voiceplanzone.* FROM Voiceplanzone + LEFT JOIN Voiceplan ON (Voiceplanzone.voiceplan_id = Voiceplan.id) + LEFT JOIN Voiceplandestination ON (Voiceplandestination.voiceplanzone_id = Voiceplanzone.id) WHERE $where - ORDER BY voiceplan_id,name"; + GROUP BY Voiceplanzone.id + ORDER BY voiceplan_id,Voiceplanzone.name"; if(is_array($limit) && count($limit)) { if(is_numeric($limit['start']) && is_numeric($limit['count'])) { @@ -107,6 +121,7 @@ class VoiceplanzoneModel { } } + mfLoghandler::singleton()->debug($sql); $res = $db->query($sql); if($db->num_rows($res)) { @@ -132,17 +147,33 @@ class VoiceplanzoneModel { if(array_key_exists("name", $filter)) { $name = FronkDB::singleton()->escape($filter['name']); if($name) { - $where .= " AND name='$name'"; + $where .= " AND Voiceplanzone.name like '%$name%'"; } } if(array_key_exists("extref", $filter)) { $extref = FronkDB::singleton()->escape($filter['extref']); if($extref) { - $where .= " AND extref='$extref'"; + $where .= " AND Voiceplanzone.extref='$extref'"; } } + if(array_key_exists("prefix", $filter)) { + $prefix = FronkDB::singleton()->escape($filter['prefix']); + if($prefix) { + $where .= " AND Voiceplandestination.prefix LIKE '$prefix'"; + } + } + + if(array_key_exists("price_difference", $filter)) { + if($filter['price_difference'] == "same") { + $where .= " AND IF(Voiceplan.price_multiplicator > 0, price = ROUND(Voiceplan.price_multiplicator * purchase_price, 4), 1=1)"; + } elseif($filter['price_difference'] == "diff") { + $where .= " AND IF(Voiceplan.price_multiplicator > 0, price <> ROUND(Voiceplan.price_multiplicator * purchase_price, 4), 1=1)"; + } + + } + //var_dump($filter, $where);exit; return $where; } diff --git a/db/migrations/20231205174410_voiceplan_add_price_multiplicator.php b/db/migrations/20231205174410_voiceplan_add_price_multiplicator.php index 9c61bf092..640045ed2 100644 --- a/db/migrations/20231205174410_voiceplan_add_price_multiplicator.php +++ b/db/migrations/20231205174410_voiceplan_add_price_multiplicator.php @@ -9,7 +9,7 @@ final class VoiceplanAddPriceMultiplicator extends AbstractMigration { if($this->getEnvironment() == "thetool") { $table = $this->table("Voiceplan"); - $table->addColumn("price_multiplicator", "decimal", ["null" => false, "default" => 1.000, "precision" => 8, "scale" => 4, "after" => "increment"]); + $table->addColumn("price_multiplicator", "decimal", ["null" => true, "default" => null, "precision" => 8, "scale" => 4, "after" => "increment"]); $table->update(); }