PreorderBilling

This commit is contained in:
Frank Schubert
2025-03-31 13:50:49 +02:00
parent 21655c5ff4
commit 17405c8c5d
17 changed files with 704 additions and 43 deletions

View File

@@ -5,6 +5,8 @@ class PreorderBilling extends mfBaseModel {
private $preorder;
private $invoice;
private $adb_wohneinheit;
private $creator;
private $editor;
public static $earliest_bill_date = "2025-01-01";
@@ -84,9 +86,10 @@ class PreorderBilling extends mfBaseModel {
$model = new PreorderBilling();
$table_fields = [
"netowner_id","invoice_id", "preorder_id", "product_type", "oaid", "adb_wohneinheit_id", "order_date", "start_date", "end_date", "preorderbillingcustomer_id",
"owner_id", "billingaddress_id", "fibu_account_number", "company", "firstname", "lastname", "street", "zip", "city", "country", "email", "uid", "billing_delivery",
"product_id", "product_type", "product_name", "product_info", "article_number", "amount", "unit", "price", "price_setup", "vatrate", "billing_period",
"netowner_id","invoice_id", "preorder_id", "product_type", "oaid", "adb_wohneinheit_id", "extref", "order_date", "start_date", "end_date", "preorderbillingcustomer_id",
"owner_id", "billingaddress_id", "fibu_account_number", "fibu_cost_account", "fibu_revenue_account", "company", "firstname", "lastname", "street", "zip", "city",
"country", "email", "uid", "billing_delivery", "product_id", "product_type", "product_name", "product_info", "article_number", "amount", "unit", "price",
"price_setup", "vatrate", "billing_period",
"create_by","edit_by","create","edit"
];

View File

@@ -230,6 +230,19 @@ class PreorderBillingController extends mfBaseController {
}
$netoperator_config = $netowner_config["netoperators"][$netoperator->id];
$fibu_cost_code = TT_PREORDER_BILLING[$netowner_id]["fibu-cost-code"];
if($fibu_cost_code == "=from-campaign") {
$campaign_cost_code = $preorder->campaign->netowner_fibu_cost_code;
if(!$campaign_cost_code) {
die("campaign cost_code not found for preorder ".$preorder->id." campaign ".$preorder->campaign->id);
}
$fibu_cost_code = $campaign_cost_code;
}
//var_dump($fibu_cost_code);exit;
if(!$fibu_cost_code) {
die("fibu_cost_code not found for preorder ".$preorder->id);
}
$bill_params = [
"netowner" => $netowner,
"netowner_config" => $netowner_config,
@@ -240,7 +253,8 @@ class PreorderBillingController extends mfBaseController {
"bill_date" => $bill_date,
"earliest_bill_date" => $earliest_bill_date,
"latest_bill_date" => $latest_bill_date,
"latest_quarter_bill_date" => $latest_quarter_bill_date
"latest_quarter_bill_date" => $latest_quarter_bill_date,
"fibu_cost_code" => $fibu_cost_code,
];
if($preorder->status->code >= 241) {
@@ -260,6 +274,9 @@ class PreorderBillingController extends mfBaseController {
}
/*********************************
* Enduser Setup & Netoperator Setup Billing
*/
private function billSetup($preorder, $type, $options) {
$netowner = $options['netowner'];
$netowner_config = $options['netowner_config'];
@@ -271,6 +288,7 @@ class PreorderBillingController extends mfBaseController {
$latest_bill_date = $options['latest_bill_date'];
$earliest_bill_date = $options['earliest_bill_date'];
$latest_quarter_bill_date = $options["latest_quarter_bill_date"];
$fibu_cost_code = $options['fibu_cost_code'];
$this->log->debug(__METHOD__.": bill $type Preorder ".$preorder->id);
@@ -338,6 +356,7 @@ class PreorderBillingController extends mfBaseController {
"preorder_id" => $preorder->id,
"oaid" => $preorder->oaid,
"adb_wohneinheit_id" => $preorder->adb_wohneinheit_id,
"extref" => ($preorder->extref) ?: null,
"order_date" => $order_date->format("Y-m-d"),
"start_date" => $status_change_date->format("Y-m-d"),
"end_date" => $status_change_date->format("Y-m-d"),
@@ -352,11 +371,19 @@ class PreorderBillingController extends mfBaseController {
"price_setup" => round($price->price_setup, 2),
"vatrate" => 20,
"billing_period" => 0,
"fibu_cost_account" => $fibu_cost_code,
];
$fibu_revenue_code = "";
if($type == "enduser_setup") {
// Endkunde Setup Gebühr
$fibu_revenue_code = $netowner_config["fibu-revenue-code"];
if(!$fibu_revenue_code) {
die("fibu_revenue_code not found for preorder ".$preorder->id);
}
if($order_date->format("Ymd") < $earliest_bill_date->format("Ymd")) {
return true;
}
@@ -394,13 +421,21 @@ class PreorderBillingController extends mfBaseController {
$billing_data[$key] = $value;
}
$address = $preorder->adb_hausnummer->strasse->name." ".$preorder->adb_hausnummer->hausnummer." ".($preorder->adb_hausnummer->stiege ? "/".$preorder->adb_hausnummer->stiege : "").", ".$preorder->adb_hausnummer->plz->plz." ".$preorder->adb_hausnummer->ortschaft->name;
$address = $preorder->adb_hausnummer->strasse->name." ".$preorder->adb_hausnummer->hausnummer.($preorder->adb_hausnummer->stiege ? " /".$preorder->adb_hausnummer->stiege : "").", ".$preorder->adb_hausnummer->plz->plz." ".$preorder->adb_hausnummer->ortschaft->name;
$billing_data["preorderbillingcustomer_id"] = $customer->id;
$billing_data["fibu_account_number"] = $customer->fibu_account_number;
$billing_data["fibu_revenue_account"] = $fibu_revenue_code;
$billing_data["product_name"] = "Herstellungsentgelt Glasfaser-Internetanschluss";
$billing_data["product_info"] = $address;
} elseif($type == "operator_setup") {
if(array_key_exists("fibu-revenue-code", $netoperator_config) && $netoperator_config["fibu-revenue-code"]) {
$fibu_revenue_code = $netoperator_config["fibu-revenue-code"];
}
if(!$fibu_revenue_code) {
die("fibu_revenue code not found for preorder ".$preorder->id);
}
$change_to_active = PreorderHistoryModel::getFirstStatusChangeTo($preorder->id, 500);
if($change_to_active) {
$status_change_date = new DateTime("@".$change_to_active->changed);
@@ -423,6 +458,7 @@ class PreorderBillingController extends mfBaseController {
$billing_data["owner_id"] = $netoperator->id;
$billing_data["billingaddress_id"] = $netoperator->id;
$billing_data["fibu_account_number"] = $netoperator->attributes['rml-fibu-account']->value;
$billing_data["fibu_revenue_account"] = $fibu_revenue_code;
$billing_data["company"] = trim($netoperator->company);
$billing_data["firstname"] = trim($netoperator->firstname);
$billing_data["lastname"] = trim($netoperator->lastname);
@@ -451,6 +487,9 @@ class PreorderBillingController extends mfBaseController {
return true;
}
/*********************************
* Usage Billing
*/
private function billOperatorPeriodic($preorder, $options) {
$netowner = $options['netowner'];
$netowner_config = $options['netowner_config'];
@@ -462,12 +501,24 @@ class PreorderBillingController extends mfBaseController {
$latest_bill_date = $options['latest_bill_date'];
$earliest_bill_date = $options['earliest_bill_date'];
$latest_quarter_bill_date = $options["latest_quarter_bill_date"];
$fibu_cost_code = $options['fibu_cost_code'];
$cancel_date = false;
$campaign = new PreorderCampaign($preorder->preordercampaign_id);
if(!$campaign) {
die("Campaign ".$preorder->preordercampaign_id." not found!");
}
$fibu_revenue_code = "";
if(array_key_exists("fibu-revenue-code", $netoperator_config) && $netoperator_config["fibu-revenue-code"]) {
$fibu_revenue_code = $netoperator_config["fibu-revenue-code"];
}
if(!$fibu_revenue_code) {
die("fibu_revenue code not found for preorder ".$preorder->id);
}
if(!array_key_exists($campaign->id, $this->marketshare)) {
$this->marketshare[$campaign->id] = [];
$this->marketshare[$campaign->id]["max"] = $campaign->getUnitCount();
@@ -479,12 +530,6 @@ class PreorderBillingController extends mfBaseController {
$this->marketshare[$campaign->id]["netops"][$netoperator->id]["bracket_price"] = [];
}
if($preorder->status->code >= 899) {
$this->log->debug(__METHOD__.": Preorder ".$preorder->id." / ".$preorder->oaid." is cancelled");
// TODO: is cancelled, so determine if refund is necessary
return true;
}
// get price_setup
$product = PreorderProduct::getFirst(["type" => "operator_usage"]);
if(!$product) {
@@ -518,6 +563,22 @@ class PreorderBillingController extends mfBaseController {
return true;
}
if($preorder->status->code >= 899) {
$this->log->debug(__METHOD__.": Preorder ".$preorder->id." / ".$preorder->oaid." is cancelled");
// get cancel date
if(!$status_change) {
$this->log->debug(__METHOD__.": But was never 500, so skipping");
return true;
}
$cancel_change = PreorderHistoryModel::getLastStatusChangeToOrHigher($preorder->id, 899);
if(!$cancel_change) {
die("Preorder ".$preorder->oaid." gekündigt (Status ".$preorder->status->code."), aber kein Cancel date gefunden");
}
$cancel_date = new DateTime("@".$cancel_change->changed);
}
$first_bill_date = clone $status_change_date;
@@ -581,6 +642,9 @@ class PreorderBillingController extends mfBaseController {
$end_date->modify("+1 months");
$end_date->modify("-1 day");
if($cancel_date && $cancel_date->format("Ym") == $start_date->format("Ym")) {
$end_date = clone $cancel_date;
}
$sday = $start_date->format("d");
$eday = $end_date->format("d");
@@ -622,7 +686,7 @@ class PreorderBillingController extends mfBaseController {
$bill_price = $base_price;
if ($base_price && ($sday > 1)) {
if ($base_price && ($sday > 1 || $cancel_date)) {
// Aliquoten Preis errechnen
$first_of_period = clone $start_date;
$first_of_period->modify("first day of this month");
@@ -667,6 +731,8 @@ class PreorderBillingController extends mfBaseController {
"owner_id" => $netoperator->id,
"billingaddress_id" => $netoperator->id,
"fibu_account_number" => $netoperator->attributes['rml-fibu-account']->value,
"fibu_cost_account" => $fibu_cost_code,
"fibu_revenue_account" => $fibu_revenue_code,
"company" => trim($netoperator->company),
"firstname" => trim($netoperator->firstname),
"lastname" => trim($netoperator->lastname),
@@ -685,6 +751,9 @@ class PreorderBillingController extends mfBaseController {
}
$ms_bill_month = $start_date->format("Ym");
if(!array_key_exists("billed-$ms_bill_month", $this->marketshare[$campaign->id]["netops"][$netoperator->id])) {
$this->marketshare[$campaign->id]["netops"][$netoperator->id]["billed-$ms_bill_month"] = 0;
}
$this->marketshare[$campaign->id]["netops"][$netoperator->id]["billed-$ms_bill_month"]++;
//$this->marketshare[$campaign->id]["netops"][$netoperator->id]["billed-$ms_bill_month"]
}