diff --git a/Layout/default/PreorderProduct/Form.php b/Layout/default/PreorderProduct/Form.php deleted file mode 100644 index 8d4a7a33b..000000000 --- a/Layout/default/PreorderProduct/Form.php +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/Layout/default/PreorderProduct/Index.php b/Layout/default/PreorderProduct/Index.php index a23651dd5..249ba29d9 100644 --- a/Layout/default/PreorderProduct/Index.php +++ b/Layout/default/PreorderProduct/Index.php @@ -30,36 +30,61 @@ +
+
+
+
+
"> +
+ + +
+ +
+
+
+ +
+
+
-

getCompanyOrName()?> (id?>)

+ +

getCompanyOrName()?> (id?>)

-
"> +

Produkte

- setNetoperatorId($netoperator->id) ?> - id, $product->prices)) ? $product->prices[$netoperator->id] : false; ?> - + setNetoperatorId($netoperator->id) ?> + setTodayDate($today_date); ?> + id, $product->prices)) ? $product->prices[$netoperator->id] : false; ?>
-
-

Preiseinstellungen für name?>

+
+

+ Preiseinstellungen für name?> +

+
+
type == "operator_setup"): ?> - + type == "enduser_setup"): ?> - - type == "operatr_usage"): ?> + + type == "operator_usage"): ?>
-
+ - - + +
@@ -83,5 +108,40 @@ todayBtn: 'linked', autoclose: true }); + $('.datepicker-sys').datepicker({ + language: 'de', + format: "yyyy-mm-dd", + showWeekDays: true, + todayBtn: 'linked', + autoclose: true + }); + + $(".select2").select2({ + allowClear: true, + placeholder: "", + closeOnSelect: true + }); + + $(".select2-nc").select2({ + allowClear: true, + placeholder: "", + closeOnSelect: false + }); + + function toggleCollapseIndicator(elem) { + var selector = "#" + $(elem).attr("id"); + var itype = $(elem).data("collapse-indicator"); + + //console.log("selector: " + selector); + + if($(selector + " i.collapse-indicator").hasClass(itype + "-right")) { + $(selector + " i.collapse-indicator").removeClass(itype + "-right").addClass(itype + "-down"); + } else { + $(selector + " i.collapse-indicator").removeClass(itype + "-down").addClass(itype + "-right"); + } + + } + + \ No newline at end of file diff --git a/Layout/default/PreorderProduct/include/netoperator-prices-setup.php b/Layout/default/PreorderProduct/include/netoperator-prices-setup.php deleted file mode 100644 index ce2378595..000000000 --- a/Layout/default/PreorderProduct/include/netoperator-prices-setup.php +++ /dev/null @@ -1,82 +0,0 @@ -
-
- - - -
- Derzeit gültiger Preis: current_price->price_setup?> - current_price->end_date): ?> - (bis current_price->end_date))->format("d.m.Y")?>) - -
- Derzeit regulärer Preis: current_regular_price->price_setup?>
- Originalpreis: first_price->price_setup?> - -
- -
- -
- - - - -

Neuer Preis

-
- -
-
- -
- -
- -
- -
- -
-
-
-
- Preis gültig von -
- -
-
- -
-
-
- Preis gültig bis -
- -
- -
-
- - - Ohne Gültig-Bis-Datum gilt der neue Preis für immer, bis ein neuer Preis eingetragen wird.
- Mit Gültig-Bis-Datum gilt der neue Preis bis einschließlich dem Gültig-Bis-Datum, danach gilt der vorige Preis wieder. -
-
- -
-
diff --git a/Layout/default/PreorderProduct/include/netoperator-prices-usage.php b/Layout/default/PreorderProduct/include/netoperator-prices-usage.php index b3d9bbc7f..12d4df175 100644 --- a/Layout/default/PreorderProduct/include/netoperator-prices-usage.php +++ b/Layout/default/PreorderProduct/include/netoperator-prices-usage.php @@ -1 +1,306 @@ + +
+
+
"> + +
+ +
+ + + + + + +
+
+

+ Neuen Preis eingeben +

+
+
+
+
+
+ + +
+
+
+ +
+ +
+
+ +
+ +
+
+
+ +
+
+ +
+ +
+
+
+ +
+
+ +
+ +
+
+
+ +
+
+ +
+ +
+
+ + +
+ +
+
+
+
+ Preis gültig von +
+ +
+
+ +
+
+
+ Preis gültig bis +
+ +
+ +
+
+ + Ohne Gültig-Bis-Datum gilt der neue Preis für immer, bis ein neuer Preis eingetragen wird.
+ Mit Gültig-Bis-Datum gilt der neue Preis bis einschließlich dem Gültig-Bis-Datum, danach gilt der vorige Preis wieder. +
+ +
+
+
+ + + + Wenn keine Kampagne ausgewählt wird, gilt der Preis für alle Kampagnen. + +
+
+
+ +

Netzdurchdringung

+
+
+

Rabattierte Preise für das Erreichen on Netzdurchdringungszielen

+

0 - 15% ist der Standardpreis. Falls keine Netzdurchdringung

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
ZielINETINET+TVCATVPassive
0 - 15%
15,01% - 20%
20,01% - 25%
25,01% - 30%
30,01% - 35%
35,01% - 40%
40,01% - 45%
+
+
+ +
+ +
+
+
+ +
+ + + + + getCurrentPrice($today_date, true); + $current_regular_price = $product->getCurrentRegularPrice($today_date, true); + $first_price = $product->getFirstPrice($today_date); + ?> +
+
+
+

Aktuelle Preise für getTodayDate()?>

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
INETINET+TVCATVPassive
Heute gültiger Preisprice_inet, 2, ",", ".")?>price_inet_tv, 2, ",", ".")?>price_catv, 2, ",", ".")?>price_passive, 2, ",", ".")?> + description?> + end_date): ?> + bis end_date))->format("d.m.Y")?> + +
Derzeit regulärer Preisprice_inet, 2, ",", ".")?>price_inet_tv, 2, ",", ".")?>price_catv, 2, ",", ".")?>price_passive, 2, ",", ".")?>description?>
Initialpreisprice_inet, 2, ",", ".")?>price_inet_tv, 2, ",", ".")?>price_catv, 2, ",", ".")?>price_passive, 2, ",", ".")?>
+ +
+
+ +
+
+

Preis Pro Kampagne

+ + + + + + + + + + + + + + getCampaignPrice($campaign->id, $today_date); ?> + + + + + + + + + + + + +
KampagneINETINET+TVCATVPassiveGü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()?>
+
+
+ +
+ +
diff --git a/Layout/default/PreorderProduct/include/prices-setup.php b/Layout/default/PreorderProduct/include/prices-setup.php new file mode 100644 index 000000000..232703823 --- /dev/null +++ b/Layout/default/PreorderProduct/include/prices-setup.php @@ -0,0 +1,190 @@ + + +
+
+
"> + +
+ +
+ + + + + + +
+
+

+ Neuen Preis eingeben +

+
+
+
+
+
+ + +
+
+
+ +
+ +
+
+ +
+ +
+ +
+ +
+ +
+
+
+
+ Preis gültig von +
+ +
+
+ +
+
+
+ Preis gültig bis +
+ +
+ +
+
+ + Ohne Gültig-Bis-Datum gilt der neue Preis für immer, bis ein neuer Preis eingetragen wird.
+ Mit Gültig-Bis-Datum gilt der neue Preis bis einschließlich dem Gültig-Bis-Datum, danach gilt der vorige Preis wieder. +
+ +
+
+
+ + + + Wenn keine Kampagne ausgewählt wird, gilt der Preis für alle Kampagnen. + +
+
+
+ +
+ +
+
+
+ +
+ + + + + getCurrentPrice($today_date, true); + $current_regular_price = $product->getCurrentRegularPrice($today_date, true); + $first_price = $product->getFirstPrice($today_date); + ?> +
+
+
+

Aktuelle Preise für getTodayDate()?>

+ + + + + + + + + + + + + + +
Heute gültiger Preisprice_setup, 2, ",", ".")?> + description?> + end_date): ?> + bis end_date))->format("d.m.Y")?> + +
Derzeit regulärer Preisprice_setup, 2, ",", ".")?>description?>
Initialpreis price_setup, 2, ",", ".")?>
+ +
+
+ +
+
+

Preis Pro Kampagne

+ + + + + + + + + + + getCampaignPrice($campaign->id, $today_date); ?> + + + + + + + + + +
KampagnePreisGültig vonGültig bisBeschreibung
name?>price_setup, 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()?>
+
+
+ +
+ +
diff --git a/application/PreorderProduct/PreorderProduct.php b/application/PreorderProduct/PreorderProduct.php index 59776280e..432126f5b 100644 --- a/application/PreorderProduct/PreorderProduct.php +++ b/application/PreorderProduct/PreorderProduct.php @@ -3,12 +3,17 @@ class PreorderProduct extends mfBaseModel { private $filter_netowner_id; private $filter_netoperator_id; + private $filter_campaign_id; private $prices; private $first_price; private $current_price; private $current_regular_price; + private $first_campaign_price; + private $current_campaign_price; + private $current_campaign_regular_price; private $creator; private $editor; + private $today_date; protected static $types = ["operator_setup", "enduser_setup", "operator_usage"]; @@ -31,6 +36,230 @@ class PreorderProduct extends mfBaseModel { return true; } + public function setCampaignId($campaign_id) { + if(!$campaign_id) { + $this->filter_campaign_id = null; + return true; + } + $this->filter_campaign_id = $campaign_id; + return true; + } + + public function setTodayDate($date) { + $this->today_date = date($date); + } + + public function getTodayDate() { + return $this->today_date; + } + + public function getCampaignFirstPrice($campaign_id, $date = null) { + if(!$date) $date = date("Y-m-d"); + + + $price = PreorderProductPrice::getFirst([ + "netowner_id" => $this->filter_netowner_id, + "netoperator_id" => $this->filter_netoperator_id, + "campaign_id" => $campaign_id, + "preorderproduct_id" => $this->id, + "start_date" => null, + "end_date" => null, + ], "`create` DESC"); + if($price) { + //$this->first_campaign_price = $price; + return $price; + //return $this->first_campaign_price; + } + return null; + } + + public function getCampaignCurrentRegularPrice($campaign_id, $date) { + if(!$date) $date = date("Y-m-d"); + + $price = PreorderProductPrice::getFirst([ + "netowner_id" => $this->filter_netowner_id, + "netoperator_id" => $this->filter_netoperator_id, + "campaign_id" => $campaign_id, + "preorderproduct_id" => $this->id, + "start_date<=" => $date, + "end_date" => null, + ], "start_date DESC, `create` DESC"); + + if($price) { + //$this->current_campaign_regular_price = $price; + return $price; + //return $this->current_campaign_regular_price; + } else { + $this->log->debug(__METHOD__.": TRY FIRST PRICE"); + return $this->getCampaignFirstPrice($campaign_id, $date); + } + return null; + } + + public function getCampaignCurrentPrice($campaign_id, $date = null) { + if(!$date) $date = date("Y-m-d"); + + // search for discounted price (with startdate and enddate + $price = PreorderProductPrice::getFirst([ + "netowner_id" => $this->filter_netowner_id, + "netoperator_id" => $this->filter_netoperator_id, + "campaign_id" => $campaign_id, + "preorderproduct_id" => $this->id, + "start_date<=" => $date, + "end_date>" => $date, + ], "start_date DESC, end_date ASC, `create` DESC"); + + if(!$price) { + // search for current regular price (with startdate and no enddate) + $price = PreorderProductPrice::getFirst([ + "netowner_id" => $this->filter_netowner_id, + "netoperator_id" => $this->filter_netoperator_id, + "campaign_id" => $campaign_id, + "preorderproduct_id" => $this->id, + "start_date<=" => $date, + "end_date" => null, + ], "start_date DESC, `create` DESC"); + } + + return $price; + } + + + + public function getCampaignPrice($campaign_id, $date = null) { + $this->log->debug("=== in ".__METHOD__); + if(!$date) $date = date("Y-m-d"); + + $this->log->debug(__METHOD__.": TRY CURRENT PRICE"); + $price = $this->getCampaignCurrentPrice($campaign_id, $date); + if(!$price) { + $this->log->debug(__METHOD__.": TRY CURRENT REGULAR PRICE"); + $price = $this->getCampaignCurrentRegularPrice($campaign_id, $date); + } + if(!$price) { + $this->log->debug(__METHOD__.": TRY FIRST PRICE"); + $price = $this->getCampaignFirstPrice($campaign_id, $date); + } + if(!$price) { + $this->log->debug(__METHOD__.": No Campaign price found. GET NETOP CURRENT PRICE"); + $price = $this->getPrice(); + } + + if($price) { + $this->log->debug("=== done in ".__METHOD__); + return $price; + } + return null; + + } + + public function getFirstPrice($date = null) { + if(!$date) $date = date("Y-m-d"); + + $price = PreorderProductPrice::getFirst([ + "netowner_id" => $this->filter_netowner_id, + "netoperator_id" => $this->filter_netoperator_id, + "campaign_id" => null, + "preorderproduct_id" => $this->id, + "start_date" => null, + "end_date" => null, + ], "`create` DESC"); + if(!$price) { + $price = PreorderProductPrice::getFirst([ + "netowner_id" => $this->filter_netowner_id, + "netoperator_id" => null, + "campaign_id" => null, + "preorderproduct_id" => $this->id, + "start_date" => null, + "end_date" => null, + ], "`create` DESC"); + } + + return $price; + } + + public function getCurrentRegularPrice($date = null, $allowCascading = false) { + if(!$date) $date = date("Y-m-d"); + + $price = PreorderProductPrice::getFirst([ + "netowner_id" => $this->filter_netowner_id, + "netoperator_id" => $this->filter_netoperator_id, + "campaign_id" => null, + "preorderproduct_id" => $this->id, + "start_date<=" => date($this->today_date), + "end_date" => null, + ], "start_date DESC, `create` DESC"); + + if(!$price && $allowCascading) { + $this->log->debug(__METHOD__.": Cascading to getFirstPrice()"); + return $this->getFirstPrice($date, true); + } + return $price; + } + + public function getCurrentPrice($date = null, $allowCascading = false) { + if(!$date) $date = date("Y-m-d"); + + $price = PreorderProductPrice::getFirst([ + "netowner_id" => $this->filter_netowner_id, + "netoperator_id" => $this->filter_netoperator_id, + "campaign_id" => null, + "preorderproduct_id" => $this->id, + "start_date<=" => date($this->today_date), + "end_date>" => date($this->today_date), + ], "start_date DESC, end_date ASC, `create` DESC"); + if(!$price) { + $price = PreorderProductPrice::getFirst([ + "netowner_id" => $this->filter_netowner_id, + "netoperator_id" => $this->filter_netoperator_id, + "campaign_id" => null, + "preorderproduct_id" => $this->id, + "start_date<=" => date($this->today_date), + "end_date" => null, + ], "start_date DESC, `create` DESC"); + } + if(!$price) { + $price = PreorderProductPrice::getFirst([ + "netowner_id" => $this->filter_netowner_id, + "netoperator_id" => $this->filter_netoperator_id, + "campaign_id" => null, + "preorderproduct_id" => $this->id, + "start_date" => null, + "end_date" => null, + ], "`create` DESC"); + } + + if(!$price && $allowCascading) { + $this->log->debug(__METHOD__.": Cascading to getCurrentRegularPrice()"); + return $this->getCurrentRegularPrice($date, true); + } + return $price; + } + + public function getPrice($date = null) { + if(!$date) $date = date("Y-m-d"); + + $this->log->debug("=== in ".__METHOD__); + $this->log->debug(__METHOD__.": TRY CURRENT PRICE"); + $price = $this->getCurrentPrice($date); + if(!$price) { + $this->log->debug(__METHOD__.": TRY CURRENT REGULAR PRICE"); + $price = $this->getCurrentRegularPrice($date); + } + if(!$price) { + $this->log->debug(__METHOD__.": TRY FIRST PRICE"); + $price = $this->getFirstPrice($date); + } + + if(!$price) { + $this->log->error(__METHOD__.": Unable to find price! netowner_id: ".$this->filter_netowner_id, " netoperator_id: ".$this->filter_netoperator_id." date: $date"); + return null; + } + $this->log->debug("=== done in ".__METHOD__); + return $price; + } + + public function getProperty($name) { if($this->$name == null) { @@ -46,9 +275,30 @@ class PreorderProduct extends mfBaseModel { } if($name == "first_price") { + if(!$this->today_date) $this->today_date = date("Y-m-d"); + + + } + + if($name == "current_regular_price") { + if(!$this->today_date) $this->today_date = date("Y-m-d"); + + + } + + if($name == "current_price") { + if(!$this->today_date) $this->today_date = date("Y-m-d"); + + + } + + if($name == "first_campaign_price") { + if(!$this->today_date) $this->today_date = date("Y-m-d"); + $price = PreorderProductPrice::getFirst([ "netowner_id" => $this->filter_netowner_id, "netoperator_id" => $this->filter_netoperator_id, + "campaign_id" => $this->filter_campaign_id, "preorderproduct_id" => $this->id, "start_date>=" => null, "end_date>" => null, @@ -56,66 +306,112 @@ class PreorderProduct extends mfBaseModel { if(!$price) { $price = PreorderProductPrice::getFirst([ "netowner_id" => $this->filter_netowner_id, + "netoperator_id" => $this->filter_netoperator_id, + "campaign_id" => null, + "preorderproduct_id" => $this->id, + "start_date>=" => null, + "end_date>" => null, + ], "`create` ASC"); + } + if(!$price) { + $price = PreorderProductPrice::getFirst([ + "netowner_id" => $this->filter_netowner_id, + "netoperator_id" => null, + "campaign_id" => null, "preorderproduct_id" => $this->id, "start_date>=" => null, "end_date>" => null, ], "`create` ASC"); } if($price) { - $this->current_price = $price; - return $this->current_price; + //$this->first_campaign_price = $price; + return $price; + //return $this->first_campaign_price; } return null; } - if($name == "current_regular_price") { + if($name == "current_campaign_regular_price") { + if(!$this->today_date) $this->today_date = date("Y-m-d"); + $price = PreorderProductPrice::getFirst([ "netowner_id" => $this->filter_netowner_id, "netoperator_id" => $this->filter_netoperator_id, + "campaign_id" => $this->filter_campaign_id, "preorderproduct_id" => $this->id, - "start_date<=" => date("Y-m-d"), + "start_date<=" => date($this->today_date), "end_date>" => null, ], "`create` ASC"); if($price) { - $this->current_price = $price; - return $this->current_price; + //$this->current_campaign_regular_price = $price; + return $price; + //return $this->current_campaign_regular_price; } else { - return $this->getProperty("first_price"); + return $this->getProperty("first_campaign_price"); } return null; } - if($name == "current_price") { + if($name == "current_campaign_price") { + if(!$this->today_date) $this->today_date = date("Y-m-d"); + $price = PreorderProductPrice::getFirst([ "netowner_id" => $this->filter_netowner_id, "netoperator_id" => $this->filter_netoperator_id, + "campaign_id" => $this->filter_campaign_id, "preorderproduct_id" => $this->id, - "start_date<=" => date("Y-m-d"), - "end_date>" => date("Y-m-d"), - ], "start_date"); + "start_date<=" => date($this->today_date), + "end_date>" => date($this->today_date), + ], "start_date DESC, end_date ASC, `create` DESC"); + if(!$price) { $price = PreorderProductPrice::getFirst([ "netowner_id" => $this->filter_netowner_id, "netoperator_id" => $this->filter_netoperator_id, + "campaign_id" => $this->filter_campaign_id, "preorderproduct_id" => $this->id, - "start_date<=" => date("Y-m-d"), + "start_date<=" => date($this->today_date), "end_date" => null, - ], "start_date"); + ], "start_date DESC, `create` DESC"); } + if(!$price) { $price = PreorderProductPrice::getFirst([ "netowner_id" => $this->filter_netowner_id, "netoperator_id" => $this->filter_netoperator_id, + "campaign_id" => $this->filter_campaign_id, "preorderproduct_id" => $this->id, "start_date" => null, "end_date" => null, - ], "start_date"); + ], "`create` DESC"); } + if(!$price) { + $price = PreorderProductPrice::getFirst([ + "netowner_id" => $this->filter_netowner_id, + "netoperator_id" => $this->filter_netoperator_id, + "campaign_id" => null, + "preorderproduct_id" => $this->id, + "start_date<=" => date($this->today_date), + "end_date>" => date($this->today_date), + ], "start_date DESC, end_date ASC, `create` DESC"); + } + + if(!$price) { + $price = PreorderProductPrice::getFirst([ + "netowner_id" => $this->filter_netowner_id, + "netoperator_id" => $this->filter_netoperator_id, + "campaign_id" => null, + "preorderproduct_id" => $this->id, + "start_date<=" => date($this->today_date), + "end_date" => null, + ], "start_date DESC, `create` DESC"); + } if($price) { - $this->current_price = $price; - return $this->current_price; + return $price; + } else { + return $this->getProperty("current_campaign_regular_price"); } return null; } @@ -168,6 +464,24 @@ class PreorderProduct extends mfBaseModel { } + public function __clone() { + $this->prices = null; + + $this->first_price = null; + $this->current_price = null; + $this->current_regular_price = null; + + $this->first_campaign_price = null; + $this->current_campaign_price = null; + $this->current_campaign_regular_price = null; + + $this->creator = null; + $this->editor = null; + //$this->filter_netoperator_id = null; + //$this->filter_netowner_id = null; + //$this->filter_campaign_id = null; + } + /******************************** * Begin static Model functions */ diff --git a/application/PreorderProduct/PreorderProductController.php b/application/PreorderProduct/PreorderProductController.php index e421c4413..18049b5e7 100644 --- a/application/PreorderProduct/PreorderProductController.php +++ b/application/PreorderProduct/PreorderProductController.php @@ -44,6 +44,16 @@ class PreorderProductController extends mfBaseController { } } + $campaigns = PreordercampaignModel::search(["owner_id" => $netowner_id]); + + $today_date = date("Y-m-d"); + + if($this->request->view_date) { + $today_date = $this->request->view_date; + } + + $this->layout()->set("today_date", $today_date); + $this->layout()->set("campaigns", $campaigns); $this->layout()->set("netoperators", $netoperators); $this->layout()->set("netowner", $netowner); } @@ -61,7 +71,7 @@ class PreorderProductController extends mfBaseController { $this->layout()->redirect("PreorderProduct"); } foreach($product_data as $product_id => $price_data) { - var_dump($price_data); + //var_dump($price_data);exit; $product = new PreorderProduct($product_id); if(!$product->id) { $this->layout()->setFlash("Produkt $product_id nicht gefunden", "error"); @@ -74,14 +84,23 @@ class PreorderProductController extends mfBaseController { "preorderproduct_id" => $product->id, "netoperator_id" => $netoperator_id, ]); - if($price_data["price_setup"]) $price->price_setup = $price_data["price_setup"]; + if($price_data["description"]) $price->description = trim($price_data["description"]); + + if($product->type == "operator_setup" || $product->type == "enduser_setup") { + if($price_data["price_setup"]) $price->price_setup = Layout::commaToDot(trim($price_data["price_setup"])); + } elseif($product->type == "operator_usage") { + if($price_data["price_inet"]) $price->price_inet = Layout::commaToDot(trim($price_data["price_inet"])); + if($price_data["price_inet_tv"]) $price->price_inet_tv = Layout::commaToDot(trim($price_data["price_inet_tv"])); + if($price_data["price_catv"]) $price->price_catv = Layout::commaToDot(trim($price_data["price_catv"])); + if($price_data["price_passive"]) $price->price_passive = Layout::commaToDot(trim($price_data["price_passive"])); + } if(!$price_data["start_date"]) { $this->layout()->setFlash("Von-datum fehlt bei Produkt '".$product->name."' für '".$netoperator->getCompanyOrName()."'", "error"); $this->redirect("PreorderProduct"); } else { try { - $start_date = new DateTime("@" . $this->dateToTimestamp($price_data["start_date"])); + $start_date = new DateTime("@" . $this->dateToTimestamp(trim($price_data["start_date"]))); $start_date->setTimezone(new DateTimeZone("Europe/Vienna")); $price->start_date = $start_date->format("Y-m-d"); } catch(Exception $e) { @@ -89,9 +108,9 @@ class PreorderProductController extends mfBaseController { $this->redirect("PreorderProduct"); } } - if($price_data["end_date"]) { + if(trim($price_data["end_date"])) { try { - $end_date = new DateTime("@" . $this->dateToTimestamp($price_data["end_date"])); + $end_date = new DateTime("@" . $this->dateToTimestamp(trim($price_data["end_date"]))); $end_date->setTimezone(new DateTimeZone("Europe/Vienna")); $price->end_date = $end_date->format("Y-m-d"); } catch(Exception $e) { @@ -100,11 +119,25 @@ class PreorderProductController extends mfBaseController { } } - //var_dump($product, $price); $price->save(); + + // create PreorderProductPriceCampaign for all submitted campaign_ids + foreach($price_data["campaigns"] as $campaign_id) { + $campaign = new Preordercampaign($campaign_id); + if(!$campaign->id) { + $this->layout()->setFlash("Ungültige Kampagne bei Produkt '".$product->name."' für '".$netoperator->getCompanyOrName()."'", "error"); + $this->layout()->redirect("PreorderProduct"); + } + $price_campaign = PreorderProductPriceCampaign::create([ + "preorderproductprice_id" => $price->id, + "preordercampaign_id" => $campaign->id, + ]); + $price_campaign->save(); + } } + } $this->layout()->setFlash("Neue Preise erflgreich gespeichert", "success"); diff --git a/application/PreorderProductPrice/PreorderProductPrice.php b/application/PreorderProductPrice/PreorderProductPrice.php index 91878175d..b6d1f244e 100644 --- a/application/PreorderProductPrice/PreorderProductPrice.php +++ b/application/PreorderProductPrice/PreorderProductPrice.php @@ -4,6 +4,7 @@ class PreorderProductPrice extends mfBaseModel { private $preorderprduct; private $netowner; private $preordercampaign; + private $campaigns; private $campaign; private $creator; private $editor; @@ -39,6 +40,19 @@ class PreorderProductPrice extends mfBaseModel { return $this->preordercampaign; } + if($name == "campaigns") { + $ccount = PreorderProductPriceCampaign::count(["preorderproductprice_id" => $this->id]); + $this->log->debug("Counted $ccount Campaigns for Price ".$this->id); + if(!$ccount) return []; + $this->campaigns = []; + foreach(PreorderProductPriceCampaign::search(["preorderproductprice_id" => $this->id]) as $pppc) { + $campaign = $pppc->campaign; + if(!$campaign || !$campaign->id) continue; + $this->campaigns[$campaign->id] = new PreorderCampaign($campaign->id); + } + return $this->campaigns; + } + if($name == "creator") { $creator = mfValuecache::singleton()->get("Worker-id-".$this->create_by); @@ -97,7 +111,7 @@ class PreorderProductPrice extends mfBaseModel { $table_fields = [ "preorderproduct_id", "netowner_id", "netoperator_id", "preordercampaign_id", "description", "start_date", "end_date", "price_inet", "price_inet_tv", "price_catv", "price_passive", - "billing_delay", "billing_period", "contract_term", "note", + "billing_delay", "billing_period", "contract_term", "description", "note", "create_by","edit_by","create","edit" ]; @@ -125,7 +139,12 @@ class PreorderProductPrice extends mfBaseModel { $db = FronkDB::singleton(); - $res = $db->select("PreorderProductPrice", "*", "1 = 1 ORDER BY start_date"); + $sql = "SELECT PreorderProductPrice.* FROM PreorderProductPrice + LEFT OUTER JOIN (SELECT COUNT(*) as cnt, preorderproductprice_id, preordercampaign_id as preordercampaign_id FROM PreorderProductPriceCampaign GROUP BY PreorderProductPriceCampaign.preorderproductprice_id, PreorderProductPriceCampaign.preordercampaign_id) pppc ON PreorderProductPrice.id = pppc.preorderproductprice_id + GROUP BY PreorderProductPrice.id + ORDER BY start_date"; + + $res = $db->query($sql); if($db->num_rows($res)) { while($data = $db->fetch_object($res)) { $items[] = new PreorderProductPrice($data); @@ -143,8 +162,10 @@ class PreorderProductPrice extends mfBaseModel { } $where = self::getSqlFilter($filter); - $sql = "SELECT * FROM PreorderProductPrice - WHERE $where + $sql = "SELECT PreorderProductPrice.* FROM PreorderProductPrice + LEFT OUTER JOIN (SELECT COUNT(*) as cnt, preorderproductprice_id, preordercampaign_id as preordercampaign_id FROM PreorderProductPriceCampaign GROUP BY PreorderProductPriceCampaign.preorderproductprice_id, PreorderProductPriceCampaign.preordercampaign_id) pppc ON PreorderProductPrice.id = pppc.preorderproductprice_id + WHERE $where + GROUP BY PreorderProductPrice.id ORDER BY $order LIMIT 1"; mfLoghandler::singleton()->debug($sql); @@ -167,7 +188,9 @@ class PreorderProductPrice extends mfBaseModel { $where = self::getSqlFilter($filter); $sql = "SELECT COUNT(*) as cnt FROM PreorderProductPrice - WHERE $where"; + LEFT OUTER JOIN (SELECT COUNT(*) as cnt, preorderproductprice_id, preordercampaign_id as preordercampaign_id FROM PreorderProductPriceCampaign GROUP BY PreorderProductPriceCampaign.preorderproductprice_id, PreorderProductPriceCampaign.preordercampaign_id) pppc ON PreorderProductPrice.id = pppc.preorderproductprice_id + WHERE $where + GROUP BY PreorderProductPrice.id"; //mfLoghandler::singleton()->debug($sql); @@ -190,8 +213,10 @@ class PreorderProductPrice extends mfBaseModel { $db = FronkDB::singleton(); $where = self::getSqlFilter($filter); - $sql = "SELECT * FROM PreorderProductPrice + $sql = "SELECT PreorderProductPrice.* FROM PreorderProductPrice + LEFT OUTER JOIN (SELECT COUNT(*) as cnt, preorderproductprice_id, preordercampaign_id as preordercampaign_id FROM PreorderProductPriceCampaign GROUP BY PreorderProductPriceCampaign.preorderproductprice_id, PreorderProductPriceCampaign.preordercampaign_id) pppc ON PreorderProductPrice.id = pppc.preorderproductprice_id WHERE $where + GROUP BY PreorderProductPrice.id ORDER BY $order"; if(is_array($limit) && count($limit)) { @@ -233,15 +258,28 @@ class PreorderProductPrice extends mfBaseModel { if(array_key_exists("netoperator_id", $filter)) { $netoperator_id = $filter['netoperator_id']; - if(is_numeric($netoperator_id)) { + if($netoperator_id === null || $netoperator_id === false) { + $where .= " AND PreorderProductPrice.netoperator_id IS NULL"; + } elseif(is_numeric($netoperator_id)) { $where .= " AND PreorderProductPrice.netoperator_id=$netoperator_id"; } } if(array_key_exists("preordercampaign_id", $filter)) { $preordercampaign_id = $filter['preordercampaign_id']; - if(is_numeric($preordercampaign_id)) { - $where .= " AND PreorderProductPrice.preordercampaign_id=$preordercampaign_id"; + if($preordercampaign_id === null || $preordercampaign_id === false) { + $where .= " AND (pppc.cnt IS NULL OR pppc.cnt = 0)"; + } elseif(is_numeric($preordercampaign_id)) { + $where .= " AND pppc.preordercampaign_id=$preordercampaign_id"; + } + } + + if(array_key_exists("campaign_id", $filter)) { + $preordercampaign_id = $filter['campaign_id']; + if($preordercampaign_id === null || $preordercampaign_id === false) { + $where .= " AND (pppc.cnt IS NULL OR pppc.cnt = 0)"; + } elseif(is_numeric($preordercampaign_id)) { + $where .= " AND pppc.preordercampaign_id=$preordercampaign_id"; } } diff --git a/application/PreorderProductPriceCampaign/PreorderProductPriceCampaign.php b/application/PreorderProductPriceCampaign/PreorderProductPriceCampaign.php new file mode 100644 index 000000000..612f81fb7 --- /dev/null +++ b/application/PreorderProductPriceCampaign/PreorderProductPriceCampaign.php @@ -0,0 +1,253 @@ +$name == null) { + + if($name == "preorderproduct") { + $price = $this->getProperty("price"); + $product = $price->preorderproduct; + if(!$product || !$product->id) { + return null; + } + $this->preorderproduct = $product; + return $this->preorderproduct; + } + + if($name == "price") { + $price = new PreorderProductPrice($this->preorderproductprice_id); + if(!$price->id) { + return null; + } + $this->price = $price; + return $this->price; + } + + if($name == "netowner") { + $netowner = new Address($this->netowner_id); + if(!$netowner->id) { + return null; + } + $this->netowner = $netowner; + return $this->netowner; + } + + if($name == "preordercampaign" || $name == "campaign") { + $campaign = new PreorderCampaign($this->preordercampaign_id); + if(!$campaign->id) { + return null; + } + $this->preordercampaign = $campaign; + $this->campaign = $campaign; + return $this->preordercampaign; + } + + + 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 PreorderProductPriceCampaign(); + + $table_fields = [ + "preorderproductprice_id", "preordercampaign_id", + "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("PreorderProductPriceCampaign", "*", "1 = 1 ORDER BY preorderproductprice_id"); + if($db->num_rows($res)) { + while($data = $db->fetch_object($res)) { + $items[] = new PreorderProductPriceCampaign($data); + } + } + return $items; + + } + + public static function getFirst($filter = [], $order = false) { + $db = FronkDB::singleton(); + + if(!$order) { + $order = "preorderproductprice_id ASC"; + } + + $where = self::getSqlFilter($filter); + $sql = "SELECT * FROM PreorderProductPriceCampaign + WHERE $where + ORDER BY $order LIMIT 1"; + + mfLoghandler::singleton()->debug($sql); + + $res = $db->query($sql); + if($db->num_rows($res)) { + $data = $db->fetch_object($res); + $item = new PreorderProductPriceCampaign($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 PreorderProductPriceCampaign + 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"; + } + + $db = FronkDB::singleton(); + + $where = self::getSqlFilter($filter); + $sql = "SELECT * FROM PreorderProductPriceCampaign + 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 PreorderProductPriceCampaign($data); + } + } + + return $items; + } + + private static function getSqlFilter($filter) { + $where = "1=1 "; + + if(array_key_exists("preordercampaign_id", $filter)) { + $preordercampaign_id = $filter['preordercampaign_id']; + if(is_numeric($preordercampaign_id)) { + $where .= " AND PreorderProductPriceCampaign.preordercampaign_id=$preordercampaign_id"; + } + } + + if(array_key_exists("preorderproductprice_id", $filter)) { + $preorderproductprice_id = $filter['preorderproductprice_id']; + if(is_numeric($preorderproductprice_id)) { + $where .= " AND PreorderProductPriceCampaign.preorderproductprice_id=$preorderproductprice_id"; + } + } + + + + + 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/db/migrations/20250217133744_preorder_product_change.php b/db/migrations/20250217133744_preorder_product_change.php index 914c3f574..9390cb078 100644 --- a/db/migrations/20250217133744_preorder_product_change.php +++ b/db/migrations/20250217133744_preorder_product_change.php @@ -9,13 +9,13 @@ final class PreorderProductChange extends AbstractMigration { if($this->getEnvironment() == "thetool") { $pp = $this->table("PreorderProduct"); - //$pp->changeColumn("type", "enum", ["null" => false, "values" => "enduser_setup, operator_setup, operator_usage"]); - //$pp->addColumn("price_setup", "decimal", ["null" => false, "default" => 0, "precision" => 14, "scale" => 4, "after" => "vatgroup_id"]); + $pp->changeColumn("type", "enum", ["null" => false, "values" => "enduser_setup, operator_setup, operator_usage"]); + $pp->addColumn("price_setup", "decimal", ["null" => false, "default" => 0, "precision" => 14, "scale" => 4, "after" => "vatgroup_id"]); $pp->update(); $ppp = $this->table("PreorderProductPrice"); $ppp->addColumn("netoperator_id", "integer", ["null" => false, "after" => "netowner_id"]); - //$ppp->addColumn("price_setup", "decimal", ["null" => false, "default" => 0, "precision" => 14, "scale" => 4, "after" => "end_date"]); + $ppp->addColumn("price_setup", "decimal", ["null" => false, "default" => 0, "precision" => 14, "scale" => 4, "after" => "end_date"]); $ppp->update(); } @@ -27,7 +27,16 @@ final class PreorderProductChange extends AbstractMigration public function down(): void { if($this->getEnvironment() == "thetool") { - + $pp = $this->table("PreorderProduct"); + $pp->changeColumn("type", "enum", ["null" => false, "values" => "enduser_setup, provider_setup, provider_usage"]); + $pp->removeColumn("price_setup"); + $pp->update(); + + $ppp = $this->table("PreorderProductPrice"); + $ppp->removeColumn("netoperator_id"); + $ppp->removeColumn("price_setup"); + //$ppp->removeColumn("description"); + $ppp->update(); } if($this->getEnvironment() == "addressdb") { diff --git a/db/migrations/20250218141907_preorder_product_change_2.php b/db/migrations/20250218141907_preorder_product_change_2.php new file mode 100644 index 000000000..e2688b9c4 --- /dev/null +++ b/db/migrations/20250218141907_preorder_product_change_2.php @@ -0,0 +1,35 @@ +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(); + } + + if($this->getEnvironment() == "addressdb") { + + } + } + + public function down(): void + { + if($this->getEnvironment() == "thetool") { + $ppp = $this->table("PreorderProductPrice"); + $ppp->removeColumn("description"); + $ppp->changeColumn("netoperator_id", "integer", ["null" => false]); + $ppp->update(); + } + + if($this->getEnvironment() == "addressdb") { + + } + } +} diff --git a/db/migrations/20250218144547_create_preorder_product_price_campaign.php b/db/migrations/20250218144547_create_preorder_product_price_campaign.php new file mode 100644 index 000000000..49876450d --- /dev/null +++ b/db/migrations/20250218144547_create_preorder_product_price_campaign.php @@ -0,0 +1,44 @@ +getEnvironment() == "thetool") { + $pppc = $this->table("PreorderProductPriceCampaign"); + $pppc->addColumn("preorderproductprice_id", "integer", ["null" => false]); + $pppc->addColumn("preordercampaign_id", "integer", ["null" => false]); + + $pppc->addColumn("create_by", "integer", ["null" => false]); + $pppc->addColumn("edit_by", "integer", ["null" => false]); + $pppc->addColumn("create", "integer", ["null" => false]); + $pppc->addColumn("edit", "integer", ["null" => false]); + $pppc->create(); + + $ppp = $this->table("PreorderProductPrice"); + $ppp->removeColumn("preordercampaign_id"); + $ppp->save(); + + + } + + if($this->getEnvironment() == "addressdb") { + + } + } + + public function down(): void + { + if($this->getEnvironment() == "thetool") { + $this->table("PreorderProductPriceCampaign")->drop()->save(); + $this->table("PreorderProductPrice")->addColumn("preordercampaign_id", "integer", ["null" => true, "default" => null, "after" => "netowner_id"])->update(); + } + + if($this->getEnvironment() == "addressdb") { + + } + } +}