diff --git a/Layout/default/Preorder/Index.php b/Layout/default/Preorder/Index.php
index 3fa4d331d..e8df26cb2 100644
--- a/Layout/default/Preorder/Index.php
+++ b/Layout/default/Preorder/Index.php
@@ -1353,6 +1353,7 @@ $pagination_entity_name = "Vorbestellungen";
// toggle controls
$("#preorder-detail-activationdate-" + pid + "-text").toggle();
$("#preorder-detail-activationdate-" + pid + "-input").toggle();
+ $("#preorder-detail-activation-billing-" + pid).toggle();
return false;
}
@@ -1363,6 +1364,9 @@ $pagination_entity_name = "Vorbestellungen";
}
var value = $("#preorder-detail-activationdate-" + pid + "-input input").val();
+ var activation_billing = $("#preorder-detail-activation-billing-" + pid + " input[type='checkbox'").is(":checked") ? 1 : 0;
+ console.log($("#preorder-detail-activation-billing-" + pid + " input[type='checkbox'"));
+ console.log(activation_billing);
//console.log("add opacity-5 to ")
$("#preorder-" + pid + "-body").addClass("opacity-5");
@@ -1378,17 +1382,25 @@ $pagination_entity_name = "Vorbestellungen";
{
'do': "saveActivationdate",
id: pid,
- activation_date: value
+ activation_date: value,
+ activation_billing: activation_billing
},
function(success) {
if(success.status == "OK") {
console.log(success);
var new_activationdate = success.result.activation_date;
+ var new_activation_billing = success.result.activation_billing;
var pid = success.result.preorder_id;
//console.log(updates);
$("#preorder-detail-activationdate-" + pid + "-textpart").text(new_activationdate);
$("#preorder-detail-activationdate-" + pid + "-input").val(new_activationdate);
+ console.log($("#preorder-detail-activationdate-" + pid + "-activation-billing-part"));
+ $("#preorder-detail-activationdate-" + pid + "-activation-billing-part").text("");
+ if(new_activation_billing) {
+ $("#preorder-detail-activationdate-" + pid + "-activation-billing-part").text("(Billing ab Aktivierung)");
+ }
+
$("#preorder-detail-activationdate-" + pid + "-text").addClass("text-success");
setTimeout(() => { $("#preorder-detail-activationdate-" + pid + "-text").removeClass("text-success") }, 1500);
diff --git a/Layout/default/Preorder/include/preorder-detail.php b/Layout/default/Preorder/include/preorder-detail.php
index 35b970bc4..51f68642b 100644
--- a/Layout/default/Preorder/include/preorder-detail.php
+++ b/Layout/default/Preorder/include/preorder-detail.php
@@ -89,7 +89,7 @@
Aktivierungsdatum (Status 500): |
getStatuschangeTo(500)): ?>
- getStatuschangeTo(500)))->format("d.m.Y") : ""?>">=($preorder->getStatuschangeTo(500)) ? (new DateTime("@".$preorder->getStatuschangeTo(500)))->format("d.m.Y") : ""?>
+ getStatuschangeTo(500)))->format("d.m.Y") : ""?>">=($preorder->getStatuschangeTo(500)) ? (new DateTime("@".$preorder->getStatuschangeTo(500)))->format("d.m.Y") : ""?> =($preorder->activation_billing) ? "(Billing ab Aktivierung)" : ""?>
+
+
+
|
diff --git a/application/Preorder/PreorderController.php b/application/Preorder/PreorderController.php
index 89b206192..d9dab2f30 100644
--- a/application/Preorder/PreorderController.php
+++ b/application/Preorder/PreorderController.php
@@ -1177,6 +1177,9 @@ class PreorderController extends mfBaseController {
private function saveActivationdateApi() {
$preorder_id = $this->request->id;
$activation_date = $this->request->activation_date;
+ $activation_billing = $this->request->activation_billing ? 1 : 0;
+
+ $this->log->debug(print_r($this->request->get(), true));
$preorder = new Preorder($preorder_id);
if(!$preorder->id) {
@@ -1199,7 +1202,15 @@ class PreorderController extends mfBaseController {
$history->changed = $activationdate->getTimestamp();
$history->save();
- return ["message" => "Activationdate saved successfully", "preorder_id" => $preorder_id, "activation_date" => $activation_date];
+ //$this->log->debug(print_r($preorder, true));
+ $this->log->debug(print_r($activation_billing, true));
+ if($preorder->activation_billing != $activation_billing) {
+ $preorder->activation_billing = $activation_billing;
+ $this->log->debug(print_r($preorder, true));
+ $preorder->save();
+ }
+
+ return ["message" => "Activationdate saved successfully", "preorder_id" => $preorder_id, "activation_date" => $activation_date, "activation_billing" => $activation_billing];
}
private function addWorkorderRemarkApi() {
diff --git a/application/Preorder/PreorderModel.php b/application/Preorder/PreorderModel.php
index 5e5fefd96..edd9d6a6e 100644
--- a/application/Preorder/PreorderModel.php
+++ b/application/Preorder/PreorderModel.php
@@ -64,6 +64,7 @@ class PreorderModel
public $workorder_export_date;
public $workorder_export_data;
public $order_date;
+ public $activation_billing;
public $cancel_request;
public $cancel_request_by;
diff --git a/application/PreorderBilling/PreorderBilling.php b/application/PreorderBilling/PreorderBilling.php
index d70147dde..a56479e63 100644
--- a/application/PreorderBilling/PreorderBilling.php
+++ b/application/PreorderBilling/PreorderBilling.php
@@ -8,7 +8,7 @@ class PreorderBilling extends mfBaseModel {
private $creator;
private $editor;
- public static $earliest_bill_date = "2025-01-01";
+ public static $earliest_bill_date = "2025-01-01"; // TODO: auslagern in config file
public function getProperty($name) {
if($this->$name == null) {
diff --git a/application/PreorderBilling/PreorderBillingController.php b/application/PreorderBilling/PreorderBillingController.php
index 05bef7059..adeb7e264 100644
--- a/application/PreorderBilling/PreorderBillingController.php
+++ b/application/PreorderBilling/PreorderBillingController.php
@@ -134,7 +134,7 @@ class PreorderBillingController extends mfBaseController {
}
$netowner_config = TT_PREORDER_BILLING[$netowner_id];
- $earliest_bill_date = new DateTime(PreorderBilling::$earliest_bill_date);
+ $earliest_bill_date = new DateTime(PreorderBilling::$earliest_bill_date); // TODO: auslagern in config file
$now_year = date("Y");
$now_month = date("m");
@@ -180,7 +180,7 @@ class PreorderBillingController extends mfBaseController {
$preorder_search = [
"preordercampaign_id" => $campaign_ids,
">=status_code" => 244,
- //"oaid" => "AT-8943-a1116acf.001",
+ //"oaid" => "AT-8943-f2c2ae10.001",
];
$billing_records = [];
@@ -263,7 +263,6 @@ class PreorderBillingController extends mfBaseController {
if($preorder->status->code >= 500) {
if($bill_operator_setup) $this->billSetup($preorder, "operator_setup", $bill_params);
if($bill_usage) $this->billOperatorPeriodic($preorder, $bill_params);
- //exit;
}
}
@@ -589,7 +588,7 @@ class PreorderBillingController extends mfBaseController {
$cancel_date = new DateTime("@".$cancel_change->changed);
}
- $first_bill_date = clone $status_change_date;
+
// get earlier missing billing records and bill them too
@@ -642,10 +641,56 @@ class PreorderBillingController extends mfBaseController {
}
break;
}
+
+ if($preorder->activation_billing) {
+ // bill from activation_date, even if it's before earliest_bill_date
+ $first_bill_date = clone $status_change_date;
+ $create_date = clone $earliest_bill_date;
+ $create_date->modify("first day of this month");
+ $create_date->modify("-1 month");
+ $create_date->setTime(0,0,0);
+
+ //var_dump($first_bill_date);
+ /*var_dump($create_date);
+ var_dump($earliest_bill_date);*/
+
+ // get months from activation date
+ $last_create_date = false;
+ while($create_date->format("Ym") < $earliest_bill_date->format("Ym")) {
+ //var_dump($create_date);
+ if($last_create_date) {
+ //var_dump($create_dates);
+ // just for safety / shouldn't happen
+ break;
+ //die("need-date ran out of dates");
+ }
+
+ //echo " - \$create_date ".$create_date->format("Y-m-d H:i:s")."
\n";
+ //echo " - \$earliest_bill_date ".$earliest_bill_date->format("Y-m-d H:i:s")."
\n";
+ if($create_date->format("Y") == $first_bill_date->format("Y") && $create_date->format("m") == $first_bill_date->format("m")) {
+ // this is the finish month, so set day back to day of finish_date
+ $create_date->setDate($first_bill_date->format("Y"), $first_bill_date->format("m"), $first_bill_date->format("d"));
+ $last_create_date = true;
+ }
+
+ $existing_bill = PreorderBilling::getFirst(["product_id" => $product->id, "preorder_id" => $preorder->id, "start_date" => $create_date->format("Y-m-d")]);
+ //var_dump($existing_bill);
+ if(!$existing_bill) {
+ if($netoperator_config["billing-period"] == "quarterly" && $create_date->format("Ymd") > $latest_quarter_bill_date->format("Ymd")) {
+ $this->log->debug(__METHOD__.": Skipping operator_usage ".$create_date->format("m/Y")." for preorder ".$preorder->id." because Billing date ".$create_date->format("Y-m-d")." is after latest_quarter_bill_date ".$latest_quarter_bill_date->format("Y-m-d"));
+ return true;
+ }
+ $new_create_date = clone $create_date;
+ $to_bill_dates[] = $new_create_date;
+ $create_date->modify("-1 months");
+ continue;
+ }
+ break;
+ }
+ }
//var_dump($to_bill_dates);
//exit;
-
foreach($to_bill_dates as $start_date) {
$end_date = clone $start_date;
$end_date->modify("first day of this month");
diff --git a/db/migrations/20250625065640_preorder_add_activation_billing.php b/db/migrations/20250625065640_preorder_add_activation_billing.php
new file mode 100644
index 000000000..671f37719
--- /dev/null
+++ b/db/migrations/20250625065640_preorder_add_activation_billing.php
@@ -0,0 +1,33 @@
+getEnvironment() == "thetool") {
+ $table = $this->table("Preorder");
+ $table->addColumn("activation_billing", "integer", ["default" => 0, "length" => \Phinx\Db\Adapter\MysqlAdapter::INT_TINY, "after" => "order_date"]);
+ $table->update();
+ }
+
+ if($this->getEnvironment() == "addressdb") {
+
+ }
+ }
+
+ public function down(): void
+ {
+ if($this->getEnvironment() == "thetool") {
+ $table = $this->table("Preorder");
+ $table->removeColumn("activation_billing");
+ $table->update();
+ }
+
+ if($this->getEnvironment() == "addressdb") {
+
+ }
+ }
+}