@@ -70,7 +73,11 @@
diff --git a/Layout/default/Invoice/Index.php b/Layout/default/Invoice/Index.php
index 5f269cc04..f80df6423 100644
--- a/Layout/default/Invoice/Index.php
+++ b/Layout/default/Invoice/Index.php
@@ -342,7 +342,8 @@ $pagination_entity_name = "Rechnungen";
=($invoice->billing_type == "sepa") ? "SEPA" : "Überweisung"?> |
=($invoice->billing_delivery == "email") ? "Email" : "Papier"?> |
- $invoice->id])?>" title="CSV-Download">
+ $invoice->id])?>" title="CSV-Download">
+ $invoice->id])?>" title="Download EGN">
|
diff --git a/Layout/default/Order/Form.php b/Layout/default/Order/Form.php
index 7b28f713c..a513c694e 100644
--- a/Layout/default/Order/Form.php
+++ b/Layout/default/Order/Form.php
@@ -1860,7 +1860,7 @@
}
- reader.readAsText(selectedFile);
+ reader.readAsArrayBuffer(selectedFile);
});
diff --git a/application/AddressDB/AddressDB.php b/application/AddressDB/AddressDB.php
index 3c5856bd7..39db020c9 100644
--- a/application/AddressDB/AddressDB.php
+++ b/application/AddressDB/AddressDB.php
@@ -130,9 +130,13 @@ class AddressDB {
}
+ $netowner = $hausnummer->getNetowner();
+ if(!$netowner || !$netowner->id) {
+ $log->debug(__METHOD__.": Unable to determine netowner for Hausnummer ".$hausnummer->id);
+ return true;
+ }
-
- $status_matrix = array_reverse(TT_PREORDER_RIMO_STATUS_MATRIX);
+ $status_matrix = array_reverse(TT_PREORDER_RIMO_STATUS_MATRIX[$netowner->id]);
$log->debug(__METHOD__.": b_ex_state: ".$b_ex_state);
$log->debug(__METHOD__.": b_op_state: ".$b_op_state);
@@ -218,7 +222,6 @@ class AddressDB {
if($hausnummer->status_id != $old_status) {
$hausnummer->save();
}
-
}
//$wohneinheit = new ADBWohneinheit($wohneinheit->id);
@@ -234,9 +237,18 @@ class AddressDB {
}
+ if(array_key_exists("hf", $matrix)) {
+ $hausnummer_flag = $matrix["hf"];
+ if($hausnummer_flag) {
+ $log->debug(__METHOD__.": new Hausnummer (".$wohneinheit->id.") statusflag: ".$matrix["hf"]);
+ $hausnummer->setStatusflag($hausnummer_flag, 1);
+ }
+ }
- break;
+
+ // commented, for 140/141
+ //break;
}
return true;
}
diff --git a/application/Billing/BillingController.php b/application/Billing/BillingController.php
index 0425519d3..7c4c0b915 100644
--- a/application/Billing/BillingController.php
+++ b/application/Billing/BillingController.php
@@ -191,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" => 1221
+ //"owner_id" => 7719
];
foreach(ContractModel::search($contract_search) as $contract) {
@@ -715,6 +715,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 +739,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 +748,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 +758,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/Building/BuildingController.php b/application/Building/BuildingController.php
index 1999bb46e..4cc2c1786 100644
--- a/application/Building/BuildingController.php
+++ b/application/Building/BuildingController.php
@@ -177,6 +177,9 @@ class BuildingController extends mfBaseController {
protected function saveAction() {
$r = $this->request;
$id = $r->id;
+
+ $adb_hausnummer_id = null;
+
//var_dump($r);exit;
if(is_numeric($id) && $id > 0) {
$mode = "edit";
@@ -187,6 +190,9 @@ class BuildingController extends mfBaseController {
}
} else {
$mode = "add";
+ if($r->adb_hausnummer_id) {
+ $adb_hausnummer_id = $r->adb_hausnummer_id;
+ }
}
if(!$r->network_id || !$r->type_id) {
@@ -215,10 +221,17 @@ class BuildingController extends mfBaseController {
$data['contact'] = trim($r->contact);
$data['phone'] = trim($r->phone);
$data['email'] = trim($r->email);
- $data['units'] = trim($r->units);
+
$data['description'] = trim($r->description);
$data['note'] = trim($r->note);
-
+
+ if($adb_hausnummer_id) {
+ $data["adb_hausnummer_id"] = $adb_hausnummer_id;
+ $data['units'] = 0;
+ } else {
+ $data['units'] = trim($r->units);
+ }
+
if($this->me->is(["Admin", "netowner"])) {
if($r->gps_lat) $data['gps_lat'] = trim($r->gps_lat);
if($r->gps_long) $data['gps_long'] = trim($r->gps_long);
@@ -235,7 +248,7 @@ class BuildingController extends mfBaseController {
// check if building exists already
$checkBuilding = BuildingModel::search(['=street' => $data['street'], '=city' => $data['city'], '=zip' => $data['zip']]);
-
+
if($checkBuilding) {
$this->layout()->setFlash("Objekt ist
bereits vorhanden!", "error");
$this->layout()->set("building", $building);
@@ -283,30 +296,49 @@ class BuildingController extends mfBaseController {
}
// Anschlüsse anlegen
-
- if(!$building->terminations && $building->units > 0) {
- for($i = 1; $i <= $building->units; $i++) {
- $data = [];
- $data['building_id'] = $building->id;
- $data['code'] = $building->code . "." . sprintf("%03d", $i);
-
- if($building->units == 1) {
- $data['contact'] = $building->contact;
- $data['phone'] = $building->phone;
- $data['email'] = $building->email;
- }
- /*
- // no more lineworker_id in Termination
- if($building->lineworker_id) {
- $data['lineworker_id'] = $building->lineworker_id;
- }*/
- if($building->oaid) {
- $data['oaid'] = $building->oaid. "." . sprintf("%03d", $i);
- }
-
- $term = TerminationModel::create($data);
- $term->save();
- }
+
+ if($mode == "add" && $adb_hausnummer_id) {
+ $i = 1;
+ foreach(ADBWohneinheitModel::search(["hausnummer_id" => $adb_hausnummer_id]) as $wohneinheit) {
+ $data = [];
+ $data['building_id'] = $building->id;
+
+ $oaid_parts = explode(".", $wohneinheit->oaid);
+ if($wohneinheit->oaid && array_key_exists(1, $oaid_parts)) {
+ $data['code'] = $building->oaid . "." . $oaid_parts[1];
+ } else {
+ $data['code'] = $building->code . "." . sprintf("%04d", $i);
+ }
+ $data['oaid'] = $data['code'];
+
+ $term = TerminationModel::create($data);
+ $term->save();
+
+ $i++;
+ }
+ } elseif(!$building->terminations && $building->units > 0) {
+ for($i = 1; $i <= $building->units; $i++) {
+ $data = [];
+ $data['building_id'] = $building->id;
+ $data['code'] = $building->code . "." . sprintf("%03d", $i);
+
+ if($building->units == 1) {
+ $data['contact'] = $building->contact;
+ $data['phone'] = $building->phone;
+ $data['email'] = $building->email;
+ }
+ /*
+ // no more lineworker_id in Termination
+ if($building->lineworker_id) {
+ $data['lineworker_id'] = $building->lineworker_id;
+ }*/
+ if($building->oaid) {
+ $data['oaid'] = $building->oaid. "." . sprintf("%03d", $i);
+ }
+
+ $term = TerminationModel::create($data);
+ $term->save();
+ }
}
@@ -343,7 +375,55 @@ class BuildingController extends mfBaseController {
$this->layout()->setFlash("Objekt gelöscht", "success");
$this->redirect("Building");
}
-
+
+ protected function createFromAdbAction() {
+ $adb_hausnummer_id = $this->request->adb_hausnummer_id;
+
+ if(!$adb_hausnummer_id) {
+ $this->layout()->setFlash("AddressDB Adresse nicht gefunden.", "error");
+ $this->redirect("AddressDB");
+ }
+
+ $hausnummer = new ADBHausnummer($adb_hausnummer_id);
+ if(!$hausnummer->id) {
+ $this->layout()->setFlash("AddressDB Adresse nicht gefunden.", "error");
+ $this->redirect("AddressDB");
+ }
+
+ $network = NetworkModel::getFirst(["adb_netzgebiet_id" => $hausnummer->netzgebiet_id]);
+ if(!$network) {
+ $this->layout()->setFlash("AddressDB-Netzgebiet ist keinem Netzbau-Netzgebiet zugeordnet!", "error");
+ $this->redirect("AddressDB");
+ }
+
+ $building_data = [];
+ $building_data["adb_hausnummer_id"] = $hausnummer->id;
+ $building_data["network_id"] = $network->id;
+ $building_data["type_id"] = ($hausnummer->tool_building_type <= 1) ? 1 : 3; // 1 = EFH | 2 = MPH
+ $building_data["status_id"] = 1;
+
+ if($hausnummer->oaid) {
+ if(!BuildingModel::getFirst(["code" => $hausnummer->oaid])) {
+ $building_data["code"] = $hausnummer->oaid;
+ }
+ $building_data["oaid"] = $hausnummer->oaid;
+ }
+
+ $building_data["street"] = $hausnummer->strasse->name . " ".$hausnummer->hausnummer;
+ $building_data["city"] = $hausnummer->strasse->gemeinde->name;
+ $building_data["zip"] = $hausnummer->plz->plz;
+ $building_data["gps_lat"] = $hausnummer->gps_lat;
+ $building_data["gps_long"] = $hausnummer->gps_long;
+ $building_data["units"] = "from_adb";
+ $building_data["note"] = "Created from ADB Address {$hausnummer->id}";
+
+ $building = BuildingModel::create($building_data);
+ $this->layout()->set("building", $building);
+ $this->layout()->set("adb_hausnummer_id", $hausnummer->id);
+
+ return $this->addAction();
+ }
+
protected function apiAction() {
if(!$this->me->is(["Admin","netowner","pipeplanner"])) {
diff --git a/application/Building/BuildingModel.php b/application/Building/BuildingModel.php
index 7e0891345..19e55f9a5 100644
--- a/application/Building/BuildingModel.php
+++ b/application/Building/BuildingModel.php
@@ -1,6 +1,7 @@
request->id;
+ if (!is_numeric($id) || !$id) {
+ $this->layout()->setFlash("Rechnung nicht gefunden", "error");
+ $this->redirect("Invoice");
+ }
+
+ $invoice = new Invoice($id);
+ if (!$invoice->id) {
+ $this->layout()->setFlash("Rechnung nicht gefunden", "error");
+ $this->redirect("Invoice");
+ }
+
+ $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"));
+ $start_date->setTime(0,0,0);
+ $end_date = new DateTime($voicenumber->end_date);
+ //$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" => [
+ "from" => $start_date->getTimestamp(),
+ "to" => $end_date->getTimestamp()
+ ],
+ "billable" => 1,
+ ], null, 0, ["key" => "start", "order" => "ASC"]) as $call) {
+ if(!$call->contract_id) continue;
+
+ //$voiceplan = new Voiceplan($voicenumber->voiceplan_id);
+ $voiceplan = VoiceplanModel::getFirst(["name" => $voicenumber->voiceplan]);
+ if(!$voiceplan) {
+ $this->log->warning(__METHOD__.": Voiceplan not found");
+ exit;
+ }
+
+ $number = $voicenumber->voicenumber;
+ $dest_nummer = $call->destination;
+ if (substr($dest_nummer, 0, 2) == "00") {
+ $dest_nummer = substr($dest_nummer, 2);
+ }
+
+ if (substr($dest_nummer, 0, 1) == "+") {
+ $dest_nummer = substr($dest_nummer, 1);
+ }
+
+ if (array_key_exists($dest_nummer, $destinations_cache)) {
+ $destination = $destinations_cache[$dest_nummer];
+ } else {
+ $destination = $voiceplan->getDestinationByNumber($dest_nummer);
+ if (!$destination) {
+ die("Destination für Zielrufnummer " . $call->destination . " nicht gefunden");
+ }
+ $destinations_cache[$dest_nummer] = $destination;
+ }
+ //var_dump($destination);
+
+ $zone = $destination->voiceplanzone;
+
+ if (!$zone) {
+ die("Keine Zone für Destination " . $dest_nummer . " gefunden");
+ }
+
+ //var_dump($zone);exit;
+
+ // inc_first - first minimumm duration to bill
+ // inc - subsequent minimum duration to bill
+ $inc_first = $zone->increment_first;
+ $inc = $zone->increment;
+
+ $billable_duration = $call->duration;
+ if ($billable_duration <= 0) continue;
+
+ // calculate price of first duration unit
+ // then subtract first minimum duration from duration
+ $sec_price = $zone->price / 60;
+ $call_price = $inc_first * $sec_price;
+ $billable_duration -= $inc_first;
+
+ // calculate price of remaining duration and make sure to bill in full duration units
+ if ($billable_duration > 0) {
+ $multi = ceil($billable_duration / $inc);
+ $call_price += ($multi * $inc) * $sec_price;
+ }
+
+ $csv .= '"'.$call->start.'";';
+ $csv .= '"'.$call->source.'"; ';
+ $csv .= '"'.$call->destination.'"; ';
+ $csv .= '"'.$zone->name.'"; ';
+ $csv .= $call->duration.'; ';
+ $csv .= '"'.str_replace(".",",", $call_price).'"';
+ $csv .= "\n";
+
+ $total += $call_price;
+
+ }
+
+ }
+
+ header("Content-type: text/csv; charset=utf-8");
+ header('Content-disposition: attachment; filename="'.$invoice->invoice_number.'-egn.csv"');
+ echo $csv;
+ exit;
+ }
protected function createJob() {
$r = $this->request;
@@ -380,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;
@@ -427,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/20251111171837_termination_resize_code.php b/db/migrations/20251111171837_termination_resize_code.php
new file mode 100644
index 000000000..6507c09d6
--- /dev/null
+++ b/db/migrations/20251111171837_termination_resize_code.php
@@ -0,0 +1,36 @@
+getEnvironment() == "thetool") {
+ $table = $this->table("Termination");
+ $table->changeColumn("code", "string", ["length" => 64, "null" => true, "default" => null]);
+ $table->update();
+
+ $table = $this->table("Building");
+ $table->changeColumn("code", "string", ["length" => 64, "null" => true, "default" => null]);
+ $table->changeColumn("oaid", "string", ["length" => 255, "null" => true, "default" => null]);
+ $table->update();
+ }
+
+ if($this->getEnvironment() == "addressdb") {
+
+ }
+ }
+
+ public function down(): void
+ {
+ if($this->getEnvironment() == "thetool") {
+
+ }
+
+ if($this->getEnvironment() == "addressdb") {
+
+ }
+ }
+}
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") {
+
+ }
+ }
+}