From 236932d45269fc8f846ed899c514badc59d2daab Mon Sep 17 00:00:00 2001 From: Frank Schubert Date: Tue, 25 Feb 2025 13:45:23 +0100 Subject: [PATCH] WIP PreorderProduct 2025-02-24 --- Layout/default/PreorderProduct/Index.php | 19 ++ .../include/netoperator-prices-usage.php | 117 +++++----- .../PreorderProduct/include/prices-setup.php | 4 +- .../PreorderProductController.php | 19 ++ .../PreorderProductMarketshareDiscount.php | 204 ++++++++++++++++++ .../PreorderProductPrice.php | 8 + ...250218141907_preorder_product_change_2.php | 1 - ...r_product_marketshare_discount_bracket.php | 43 ++++ 8 files changed, 355 insertions(+), 60 deletions(-) create mode 100644 application/PreorderProductMarketshareDiscount/PreorderProductMarketshareDiscount.php create mode 100644 db/migrations/20250224124143_preorder_product_marketshare_discount_bracket.php diff --git a/Layout/default/PreorderProduct/Index.php b/Layout/default/PreorderProduct/Index.php index 249ba29d9..ffc68c5c8 100644 --- a/Layout/default/PreorderProduct/Index.php +++ b/Layout/default/PreorderProduct/Index.php @@ -139,7 +139,26 @@ } else { $(selector + " i.collapse-indicator").removeClass(itype + "-down").addClass(itype + "-right"); } + } + function priceToMarketshare(netop_id, product_id, type) { + console.log(netop_id, product_id, type); + + let price = $("#price-" + type + "-" + netop_id + "-" + product_id).val(); + console.log(price); + if(!price.length) return; + + $("#marketshare-0-" + netop_id + "-" + product_id + "-" + type).val(price); + } + + function marketshareToPrice(netop_id, product_id, type) { + console.log(netop_id, product_id, type); + + let price = $("#marketshare-0-" + netop_id + "-" + product_id + "-" + type).val(); + console.log(price); + if(!price.length) return; + + $("#price-" + type + "-" + netop_id + "-" + product_id).val(price); } diff --git a/Layout/default/PreorderProduct/include/netoperator-prices-usage.php b/Layout/default/PreorderProduct/include/netoperator-prices-usage.php index 12d4df175..84a501791 100644 --- a/Layout/default/PreorderProduct/include/netoperator-prices-usage.php +++ b/Layout/default/PreorderProduct/include/netoperator-prices-usage.php @@ -9,7 +9,7 @@ ?>
-
+
">
@@ -72,7 +72,7 @@
- +
@@ -81,7 +81,7 @@
- +
@@ -90,7 +90,7 @@
- +
@@ -99,7 +99,7 @@
- +
@@ -131,7 +131,7 @@ Mit Gültig-Bis-Datum gilt der neue Preis bis einschließlich dem Gültig-Bis-Datum, danach gilt der vorige Preis wieder. -
+ -

Netzdurchdringung

+

Netzdurchdringung

Rabattierte Preise für das Erreichen on Netzdurchdringungszielen

-

0 - 15% ist der Standardpreis. Falls keine Netzdurchdringung

+

0 - 15% ist der Standardpreis

@@ -161,46 +161,46 @@ - - - - + + + + - - - - + + + + - - - - + + + + - - - - + + + + - - - - + + + + - - - - + + + + - - - - + + + +
ZielPassive
0 - 15%
15,01% - 20%
20,01% - 25%
25,01% - 30%
30,01% - 35%
35,01% - 40%
40,01% - 45%
@@ -223,7 +223,7 @@ $current_regular_price = $product->getCurrentRegularPrice($today_date, true); $first_price = $product->getFirstPrice($today_date); ?> -
+

Aktuelle Preise für getTodayDate()?>

@@ -270,33 +270,36 @@
-

Preis Pro Kampagne

+

Preise Netzdurchdringung

+ +
Heute gültige Preise
+ Gültig von: start_date) ? (new DateTime($current_price->start_date))->format("d.m.Y") : ""?>
+ Gültig bis: end_date) ? (new DateTime($current_price->end_date))->format("d.m.Y") : ""?> - + - - - - - - getCampaignPrice($campaign->id, $today_date); ?> - - - - - - - - - - - + + + + + + + + marketsharediscounts as $bracket => $discount): ?> + + + + + + + +
KampagneGruppe INET INET+TV CATV PassiveGültig vonGültig bisBeschreibung
name?>price_inet, 2, ",", ".")?>price_inet_tv, 2, ",", ".")?>price_catv, 2, ",", ".")?>price_passive, 2, ",", ".")?>start_date) ? (new DateTime($cprice->start_date))->format("d.m.Y") : "-"?>end_date) ? (new DateTime($cprice->end_date))->format("d.m.Y") : "-"?>description?>getTodayDate()?>
0 - 15%price_inet?>price_inet_tv?>price_catv?>price_passive?>
% - %price_inet?>price_inet_tv?>price_catv?>price_passive?>
diff --git a/Layout/default/PreorderProduct/include/prices-setup.php b/Layout/default/PreorderProduct/include/prices-setup.php index 232703823..c808caee3 100644 --- a/Layout/default/PreorderProduct/include/prices-setup.php +++ b/Layout/default/PreorderProduct/include/prices-setup.php @@ -9,7 +9,7 @@ ?>
-
+
">
@@ -130,7 +130,7 @@ $current_regular_price = $product->getCurrentRegularPrice($today_date, true); $first_price = $product->getFirstPrice($today_date); ?> -
+

Aktuelle Preise für getTodayDate()?>

diff --git a/application/PreorderProduct/PreorderProductController.php b/application/PreorderProduct/PreorderProductController.php index 18049b5e7..970fdbbed 100644 --- a/application/PreorderProduct/PreorderProductController.php +++ b/application/PreorderProduct/PreorderProductController.php @@ -123,6 +123,25 @@ class PreorderProductController extends mfBaseController { $price->save(); + // marketshare prices + if(array_key_exists("marketshareprice", $price_data) && is_array($price_data["marketshareprice"])) { + foreach($price_data["marketshareprice"] as $msbracket => $msprice) { + if(!is_numeric($msbracket)) continue; + if(!$msbracket) continue; // dont save 0 + + $msp = PreorderProductMarketshareDiscount::create([ + "preorderproductprice_id" => $price->id, + "bracket" => $msbracket, + "price_inet" => Layout::commaToDot(trim($msprice["inet"])), + "price_inet_tv" => Layout::commaToDot(trim($msprice["inet_tv"])), + "price_catv" => Layout::commaToDot(trim($msprice["catv"])), + "price_passive" => Layout::commaToDot(trim($msprice["passive"])), + ]); + $msp->save(); + + } + } + // create PreorderProductPriceCampaign for all submitted campaign_ids foreach($price_data["campaigns"] as $campaign_id) { $campaign = new Preordercampaign($campaign_id); diff --git a/application/PreorderProductMarketshareDiscount/PreorderProductMarketshareDiscount.php b/application/PreorderProductMarketshareDiscount/PreorderProductMarketshareDiscount.php new file mode 100644 index 000000000..37992bfeb --- /dev/null +++ b/application/PreorderProductMarketshareDiscount/PreorderProductMarketshareDiscount.php @@ -0,0 +1,204 @@ +$name == null) { + + if($name == "creator") { + $creator = mfValuecache::singleton()->get("Worker-id-".$this->create_by); + if($creator) { + $this->creator = $creator; + return $this->creator; + } + $this->creator = new User($this->create_by); + + if(!$this->creator->id) { + return null; + } + mfValuecache::singleton()->set("Worker-id-".$this->create_by, $this->creator); + return $this->creator; + } + + if($name == "editor") { + $editor = mfValuecache::singleton()->get("Worker-id-".$this->edit_by); + if($editor) { + $this->editor = $editor; + return $this->editor; + } + $this->editor = new User($this->edit_by); + if(!$this->editor->id) { + return null; + } + mfValuecache::singleton()->set("Worker-id-".$this->edit_by, $this->editor); + return $this->editor; + } + + $classname = ucfirst($name); + $idfield = $name . "_id"; + $this->$name = mfValuecache::singleton()->get("mfObjectmodel-$name-" . $this->$idfield); + if(!$this->$name) { + $this->$name = new $classname($this->$idfield); + } + + if($this->$name->id) { + mfValuecache::singleton()->set("mfObjectmodel-$name-" . $this->$name->id, $this->$name); + return $this->$name; + } else { + return null; + } + } + + return $this->$name; + + } + + /******************************** + * Begin static Model functions + */ + + public static function create(Array $data) { + $model = new PreorderProductMarketshareDiscount(); + + $table_fields = [ + "preorderproductprice_id", "bracket", "price_inet", "price_inet_tv", "price_catv", "price_passive", + "create_by","edit_by","create","edit" + ]; + + foreach($data as $field => $value) { + if(in_array($field, $table_fields)) { + $model->$field = $value; + } + } + + $me = new User(); + $me->loadMe(); + + 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("PreorderProductMarketshareDiscount", "*", "1 = 1 ORDER BY preorderproductprice_id,bracket"); + if($db->num_rows($res)) { + while($data = $db->fetch_object($res)) { + $items[] = new PreorderProductMarketshareDiscount($data); + } + } + return $items; + + } + + public static function getFirst($filter) { + $db = FronkDB::singleton(); + + $where = self::getSqlFilter($filter); + $sql = "SELECT * FROM PreorderProductMarketshareDiscount + WHERE $where + ORDER BY preorderproductprice_id,bracket LIMIT 1"; + //var_dump($sql);exit; + $res = $db->query($sql); + if($db->num_rows($res)) { + $data = $db->fetch_object($res); + $item = new PreorderProductMarketshareDiscount($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 PreorderProductMarketshareDiscount + WHERE $where"; + + //mfLoghandler::singleton()->debug($sql); + + $res = $db->query($sql); + if($db->num_rows($res)) { + $data = $db->fetch_object($res); + return $data->cnt; + } + return 0; + } + + public static function search($filter, $limit = false, $order = false) { + //var_dump($filter);exit; + $items = []; + + if(!$order) { + $order = "preorderproductprice_id ASC, bracket ASC"; + } + + $db = FronkDB::singleton(); + + $where = self::getSqlFilter($filter); + $sql = "SELECT * FROM PreorderProductMarketshareDiscount + WHERE $where + ORDER BY $order"; + + if(is_array($limit) && count($limit)) { + if(is_numeric($limit['start']) && is_numeric($limit['count'])) { + $sql .= " LIMIT ".$limit['start'].", ".$limit['count']; + } elseif(is_numeric($limit['count'])) { + $sql .= " LIMIT ".$limit['count']; + } + } + + mfLoghandler::singleton()->debug($sql); + + $res = $db->query($sql); + if($db->num_rows($res)) { + while($data = $db->fetch_object($res)) { + $items[$data->id] = new PreorderProductMarketshareDiscount($data); + } + } + + return $items; + } + + private static function getSqlFilter($filter) { + $where = "1=1 "; + + if(array_key_exists("preorderproductprice_id", $filter)) { + $preorderproductprice_id = $filter['preorderproductprice_id']; + if(is_numeric($preorderproductprice_id)) { + $where .= " AND PreorderProductMarketshareDiscount.preorderproductprice_id=$preorderproductprice_id"; + } + } + + if(array_key_exists("bracket", $filter)) { + $bracket = $filter['bracket']; + if(is_numeric($bracket)) { + $where .= " AND PreorderProductMarketshareDiscount.bracket=$bracket"; + } + } + + + if(array_key_exists("add-where", $filter)) { + $where .= " ".$filter['add-where']; + } + + //var_dump($filter, $where);exit; + return $where; + } + +} \ No newline at end of file diff --git a/application/PreorderProductPrice/PreorderProductPrice.php b/application/PreorderProductPrice/PreorderProductPrice.php index b6d1f244e..a7e1a0e4c 100644 --- a/application/PreorderProductPrice/PreorderProductPrice.php +++ b/application/PreorderProductPrice/PreorderProductPrice.php @@ -6,6 +6,7 @@ class PreorderProductPrice extends mfBaseModel { private $preordercampaign; private $campaigns; private $campaign; + private $marketsharediscounts; private $creator; private $editor; @@ -53,6 +54,13 @@ class PreorderProductPrice extends mfBaseModel { return $this->campaigns; } + if($name == "marketsharediscounts") { + if(!PreorderProductMarketshareDiscount::count(["preorderproductprice_id" => $this->id])) return []; + foreach(PreorderProductMarketshareDiscount::search(["preorderproductprice_id" => $this->id]) as $discount) { + $this->marketsharediscounts[$discount->bracket] = $discount; + } + return $this->marketsharediscounts; + } if($name == "creator") { $creator = mfValuecache::singleton()->get("Worker-id-".$this->create_by); diff --git a/db/migrations/20250218141907_preorder_product_change_2.php b/db/migrations/20250218141907_preorder_product_change_2.php index e2688b9c4..dc6341f61 100644 --- a/db/migrations/20250218141907_preorder_product_change_2.php +++ b/db/migrations/20250218141907_preorder_product_change_2.php @@ -10,7 +10,6 @@ final class PreorderProductChange2 extends AbstractMigration if($this->getEnvironment() == "thetool") { $ppp = $this->table("PreorderProductPrice"); $ppp->changeColumn("netoperator_id", "integer", ["null" => true]); - $ppp->addColumn("description", "text", ["null" => true, "default" => null, "after" => "contract_term"]); $ppp->update(); } diff --git a/db/migrations/20250224124143_preorder_product_marketshare_discount_bracket.php b/db/migrations/20250224124143_preorder_product_marketshare_discount_bracket.php new file mode 100644 index 000000000..b61c8d51f --- /dev/null +++ b/db/migrations/20250224124143_preorder_product_marketshare_discount_bracket.php @@ -0,0 +1,43 @@ +getEnvironment() == "thetool") { + $ppmsd = $this->table("PreorderProductMarketshareDiscount"); + $ppmsd->addColumn("bracket", "integer", ["null" => false, "after" => "preorderproductprice_id"]); + $ppmsd->addColumn("price_inet", "decimal", ["null" => false, "default" => 0, "precision" => 14, "scale" => 4, "after" => "bracket"]); + $ppmsd->addColumn("price_inet_tv", "decimal", ["null" => false, "default" => 0, "precision" => 14, "scale" => 4, "after" => "price_inet"]); + $ppmsd->addColumn("price_catv", "decimal", ["null" => false, "default" => 0, "precision" => 14, "scale" => 4, "after" => "price_inet_tv"]); + $ppmsd->addColumn("price_passive", "decimal", ["null" => false, "default" => 0, "precision" => 14, "scale" => 4, "after" => "price_catv"]); + $ppmsd->removeColumn("price_15"); + $ppmsd->removeColumn("price_20"); + $ppmsd->removeColumn("price_25"); + $ppmsd->removeColumn("price_30"); + $ppmsd->removeColumn("price_35"); + $ppmsd->removeColumn("price_40"); + $ppmsd->removeColumn("price_45"); + $ppmsd->removeColumn("price_50"); + $ppmsd->save(); + } + + if($this->getEnvironment() == "addressdb") { + + } + } + + public function down(): void + { + if($this->getEnvironment() == "thetool") { + + } + + if($this->getEnvironment() == "addressdb") { + + } + } +}