From 937b71244debecf75aa64a6f3480ebe3cbd44005 Mon Sep 17 00:00:00 2001 From: Frank Schubert Date: Tue, 11 Nov 2025 21:41:32 +0100 Subject: [PATCH 1/2] Fixed invoicing only one of several voicezones with same name --- application/Billing/BillingController.php | 10 +++-- .../BillingVoicenumberModel.php | 1 + application/Invoice/InvoiceController.php | 39 ++++++++++++------- ...201335_billing_voicenumber_add_zone_id.php | 31 +++++++++++++++ 4 files changed, 64 insertions(+), 17 deletions(-) create mode 100644 db/migrations/20251111201335_billing_voicenumber_add_zone_id.php diff --git a/application/Billing/BillingController.php b/application/Billing/BillingController.php index 0425519d3..9f0694e9f 100644 --- a/application/Billing/BillingController.php +++ b/application/Billing/BillingController.php @@ -153,6 +153,7 @@ class BillingController extends mfBaseController { $v = 0; $today = new DateTime("now"); + //$today = new DateTime("2026-01-09"); $today->setTime(0,0,0); $now_year = date("Y"); @@ -191,7 +192,7 @@ class BillingController extends mfBaseController { $contract_search = [ "finish_date<" => mktime(2,0,0,$now_month, $now_day, $now_year), "cancel_date_null_or_gte" => mktime(0,0,0,$now_month, 1, $now_year), - //"owner_id" => 1221 + "owner_id" => 7719 ]; foreach(ContractModel::search($contract_search) as $contract) { @@ -715,6 +716,7 @@ class BillingController extends mfBaseController { } if (!array_key_exists($zone->id, $voicebills[$number][$call_date_start])) { $voicebills[$number][$call_date_start][$zone->id] = [ + //"zone_id" => $zone->id, "zone_name" => $zone->name, "voiceplan" => $voiceplan->name, "duration" => 0, @@ -738,8 +740,8 @@ class BillingController extends mfBaseController { // save to BillingVoicenumber foreach($voicebills as $vbnumber => $zones) { - foreach($zones as $zone_id => $zone) { - foreach($zone as $zone_start_date => $vb) { + foreach($zones as $zone_start_date => $zone) { + foreach($zone as $zone_id => $vb) { $vbdata = []; $vbdata["billing_id"] = $billing->id; $vbdata["contract_id"] = $contract->id; @@ -747,6 +749,7 @@ class BillingController extends mfBaseController { $vbdata["start_date"] = $vb["start_date"]; $vbdata["end_date"] = $vb["end_date"]; $vbdata["voiceplan"] = $vb["voiceplan"]; + $vbdata["zone_id"] = $zone_id; $vbdata["zone"] = $vb["zone_name"]; $vbdata["call_count"] = $vb["count"]; $vbdata["duration"] = $vb["duration"]; @@ -756,6 +759,7 @@ class BillingController extends mfBaseController { $vbdata["increment_first"] = $vb["increment_first"]; $bill_voice = BillingVoicenumberModel::create($vbdata); + $this->log->debug(__METHOD__.": billingvoicenumber record created: ".print_r($vbdata, true)); if(!$bill_voice->save()) { var_dump($vbdata); die("Error saving Billing Voicenumber!"); diff --git a/application/BillingVoicenumber/BillingVoicenumberModel.php b/application/BillingVoicenumber/BillingVoicenumberModel.php index f44184c85..f205854a8 100644 --- a/application/BillingVoicenumber/BillingVoicenumberModel.php +++ b/application/BillingVoicenumber/BillingVoicenumberModel.php @@ -7,6 +7,7 @@ class BillingVoicenumberModel { public $start_date; public $end_date; public $voiceplan; + public $zone_id; public $zone; public $call_count; public $duration; diff --git a/application/Invoice/InvoiceController.php b/application/Invoice/InvoiceController.php index f860ed672..6d44febed 100644 --- a/application/Invoice/InvoiceController.php +++ b/application/Invoice/InvoiceController.php @@ -227,8 +227,9 @@ class InvoiceController extends mfBaseController { $csv = "Startzeit;Abgehende Nummer;Zielnummer;Zone;Dauer;Kosten\n"; + $total = 0; $destinations_cache = []; - + //var_dump($invoice->voicenumbers);exit; foreach($invoice->voicenumbers as $voicenumber) { $start_date = new DateTime($voicenumber->start_date); //$start_date->setTimezone(new DateTimeZone("Europe/Vienna")); @@ -237,6 +238,8 @@ class InvoiceController extends mfBaseController { //$end_date->setTimezone(new DateTimeZone("Europe/Vienna")); $end_date->setTime(23,59,59); + $call_date_start = $start_date->format("Y-m-d"); + foreach(VoiceCallHistoryModel::getVoiceCallHistoryAsEntity([ "voice_account" => $voicenumber->voicenumber, "start" => [ @@ -251,7 +254,8 @@ class InvoiceController extends mfBaseController { $voiceplan = VoiceplanModel::getFirst(["name" => $voicenumber->voiceplan]); if(!$voiceplan) { $this->log->warning(__METHOD__.": Voiceplan not found"); - }; + exit; + } $number = $voicenumber->voicenumber; $dest_nummer = $call->destination; @@ -309,6 +313,9 @@ class InvoiceController extends mfBaseController { $csv .= $call->duration.'; '; $csv .= '"'.str_replace(".",",", $call_price).'"'; $csv .= "\n"; + + $total += $call_price; + } } @@ -486,34 +493,38 @@ class InvoiceController extends mfBaseController { $inc = reset($voicebills)->increment; $inc_first = reset($voicebills)->increment_first; + $zoneId2ZoneName = []; + $voice_rows = []; foreach ($voicebills as $voicebill) { $number = $voicebill->voicenumber; + $zone_id = $voicebill->zone_id; $zone = $voicebill->zone; $call_count = $voicebill->call_count; $duration = $voicebill->duration; $price = $voicebill->price; $price_total = $voicebill->price_total; + $zoneId2ZoneName[$zone_id] = $zone; if (!array_key_exists($number, $voice_rows)) { $voice_rows[$number] = []; } - if (!array_key_exists($zone, $voice_rows[$number])) { - $voice_rows[$number][$zone] = []; + if (!array_key_exists($zone_id, $voice_rows[$number])) { + $voice_rows[$number][$zone_id] = []; } - if (!array_key_exists($price, $voice_rows[$number][$zone])) { - $voice_rows[$number][$zone][$price] = []; - $voice_rows[$number][$zone][$price]["call_count"] = 0; - $voice_rows[$number][$zone][$price]["duration"] = 0; - $voice_rows[$number][$zone][$price]["price_total"] = 0; + if (!array_key_exists($price, $voice_rows[$number][$zone_id])) { + $voice_rows[$number][$zone_id][$price] = []; + $voice_rows[$number][$zone_id][$price]["call_count"] = 0; + $voice_rows[$number][$zone_id][$price]["duration"] = 0; + $voice_rows[$number][$zone_id][$price]["price_total"] = 0; } - $voice_rows[$number][$zone][$price]["call_count"] += $call_count; - $voice_rows[$number][$zone][$price]["duration"] = $duration; - $voice_rows[$number][$zone][$price]["price_total"] = $price_total; + $voice_rows[$number][$zone_id][$price]["call_count"] += $call_count; + $voice_rows[$number][$zone_id][$price]["duration"] = $duration; + $voice_rows[$number][$zone_id][$price]["price_total"] = $price_total; } //var_dump($voice_rows);exit; @@ -533,10 +544,10 @@ class InvoiceController extends mfBaseController { $invoice_voicenumber->voicenumberzones = []; - foreach ($zones as $zone => $prices) { + foreach ($zones as $zone_id => $prices) { foreach ($prices as $price => $row_values) { $zone_data = []; - $zone_data["zone"] = $zone; + $zone_data["zone"] = $zoneId2ZoneName[$zone_id]; $zone_data["call_count"] = $row_values["call_count"]; $zone_data["duration"] = $row_values["duration"]; $zone_data["price"] = $price; diff --git a/db/migrations/20251111201335_billing_voicenumber_add_zone_id.php b/db/migrations/20251111201335_billing_voicenumber_add_zone_id.php new file mode 100644 index 000000000..611f2108f --- /dev/null +++ b/db/migrations/20251111201335_billing_voicenumber_add_zone_id.php @@ -0,0 +1,31 @@ +getEnvironment() == "thetool") { + $table = $this->table("BillingVoicenumber"); + $table->addColumn("zone_id", "integer", ["null" => true, "default" => null, "after" => "voiceplan"]); + $table->update(); + } + + if($this->getEnvironment() == "addressdb") { + + } + } + + public function down(): void + { + if($this->getEnvironment() == "thetool") { + $this->table("BillingVoicenumber")->removeColumn("zone_id")->update(); + } + + if($this->getEnvironment() == "addressdb") { + + } + } +} From 9e550f4c4f76cb49e2aff19607257eb2b9ded26a Mon Sep 17 00:00:00 2001 From: Frank Schubert Date: Tue, 11 Nov 2025 21:42:52 +0100 Subject: [PATCH 2/2] Fixed invoicing only one of several voicezones with same name --- application/Billing/BillingController.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/application/Billing/BillingController.php b/application/Billing/BillingController.php index 9f0694e9f..7c4c0b915 100644 --- a/application/Billing/BillingController.php +++ b/application/Billing/BillingController.php @@ -153,7 +153,6 @@ class BillingController extends mfBaseController { $v = 0; $today = new DateTime("now"); - //$today = new DateTime("2026-01-09"); $today->setTime(0,0,0); $now_year = date("Y"); @@ -192,7 +191,7 @@ class BillingController extends mfBaseController { $contract_search = [ "finish_date<" => mktime(2,0,0,$now_month, $now_day, $now_year), "cancel_date_null_or_gte" => mktime(0,0,0,$now_month, 1, $now_year), - "owner_id" => 7719 + //"owner_id" => 7719 ]; foreach(ContractModel::search($contract_search) as $contract) {