Fixed invoicing only one of several voicezones with same name

This commit is contained in:
Frank Schubert
2025-11-11 21:41:32 +01:00
parent d00f340a25
commit 937b71244d
4 changed files with 64 additions and 17 deletions

View File

@@ -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!");

View File

@@ -7,6 +7,7 @@ class BillingVoicenumberModel {
public $start_date;
public $end_date;
public $voiceplan;
public $zone_id;
public $zone;
public $call_count;
public $duration;

View File

@@ -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;

View File

@@ -0,0 +1,31 @@
<?php
declare(strict_types=1);
use Phinx\Migration\AbstractMigration;
final class BillingVoicenumberAddZoneId extends AbstractMigration
{
public function up(): void
{
if($this->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") {
}
}
}