@@ -157,8 +161,8 @@
diff --git a/Layout/default/Address/View.php b/Layout/default/Address/View.php
index f3832d092..f62321c14 100644
--- a/Layout/default/Address/View.php
+++ b/Layout/default/Address/View.php
@@ -128,6 +128,9 @@
| FIBU Lieferanten Konto |
=$address->fibu_supplier_number?> |
+
+ | FIBU Lieferanten Zahlungsziel |
+ =$address->fibu_supplier_due?> |
Zusatzdaten |
diff --git a/Layout/default/Address/bmd_export.csv.php b/Layout/default/Address/bmd_export.csv.php
new file mode 100644
index 000000000..ee1f1ac88
--- /dev/null
+++ b/Layout/default/Address/bmd_export.csv.php
@@ -0,0 +1,9 @@
+Lieferant;Kunde;Kundenummer;FIBU-Verrechnungsnummer;FIBU Lieferantennummer;Zahlungsziel Lieferant;Firma;Vorname;Nachname;Straße Hausnummer;PLZ;Ort;Land;Telefon;Mobil;Mail;UID;Verrechnungsart;Rechnungsversand;Kreditinstitut;Kontoinhaber;IBAN;BIC
+
+=$a["is_supplier"]?>;=$a["is_customer"]?>;=$a["customer_number"]?>;=$a["fibu_account_number"]?>;=$a["fibu_supplier_number"]?>;=$a["fibu_supplier_due"]?>;=$this->nl2ws($a["company"])?>;=$this->nl2ws($a["firstname"])?>;=$this->nl2ws($a["lastname"])?>;=$this->nl2ws($a["street"])?>;=$this->nl2ws($a["$address->zip"])?>;=$this->nl2ws($a["city"])?>;=$this->nl2ws($a["country"])?>;=$this->nl2ws($a["phone"])?>;=$this->nl2ws($a["mobile"])?>;=$this->nl2ws($a["email"])?>;=$this->nl2ws($a["uid"])?>;=$a["billing_type"]?>;=$a["billing_delivery"]?>;=$a["bank"]?>;=$a["owner"]?>;=$a["iban"]?>;=$a["bic"]?>
+
+layout()->set("request", $this->request);
$this->layout()->set("pagination", $pagination);
+
+ $last_export = false;
+ $bmd_export_ts = new mfConfig("bmd.export.ts");
+ if($bmd_export_ts->value()) {
+ $last_export = $bmd_export_ts->value();
+ }
+ $this->layout()->set("last_bmd_export", $last_export);
+
return true;
@@ -165,6 +173,167 @@ class AddressController extends mfBaseController {
}
+ protected function exportBmd() {
+ /*$last_export = new mfConfig("bmd.export.ts");
+ $last_export->type("int");
+ $last_export->value(date("U"));
+ $last_export->save();
+ */
+ $last_export = 0;
+
+ $export_ts = new mfConfig("bmd.export.ts");
+ if($export_ts->value()) {
+ $last_export = $export_ts->value();
+ }
+
+ $type = "inc";
+
+ if($this->request->type == "full") {
+ $last_export = 0;
+ $type = "full";
+ }
+
+ if(!file_exists(TT_ADDRESS_BMD_EXPORT_PATH)) {
+ $this->layout()->setFlash("Export Pfad (".TT_ADDRESS_BMD_EXPORT_PATH.") nicht gefunden!", "error");
+ }
+
+ $export_ts->value(date('U'));
+
+ $search = ["edit>" => $last_export, "customer_or_fibu_numbers" => true];
+
+ if(!AddressModel::count($search)) {
+ $this->layout()->setFlash("Keine geänderten Adressdatensätze gefunden. Export abgebrochen.", "warn");
+ $this->redirect("Address");
+ }
+
+ $addresses = [];
+
+ foreach(AddressModel::search($search) as $address) {
+ // if supplier -> use it
+ if($address->fibu_supplier_number) {
+ $addresses[$address->fibu_supplier_number] = $address;
+ continue;
+ }
+
+ // if is primary -> use it
+ if($address->fibu_account_number && $address->fibu_primary_account) {
+ $addresses[$address->fibu_account_number] = $address;
+ continue;
+ }
+
+ // if only address with fibu_account_num -> make primary
+ if($address->fibu_account_number && !$address->fibu_primary_account) {
+ // look up other addresses with same account num
+ $address_count = AddressModel::count(["fibu_account_number" => $address->fibu_account_number]);
+ if($address_count === 1) {
+ $address->fibu_primary_account = 1;
+ $address->save();
+ $addresses[$address->fibu_account_number] = $address;
+ continue;
+ }
+
+ // if more addresses with fibu_account_num -> find primary
+ if($address_count > 1) {
+ // find primary
+ $primary = AddressModel::getFirst(["fibu_account_number" => $address->fibu_account_number, "fibu_primary_account" => true]);
+ if($primary) {
+ // use single primary
+ $addresses[$primary->fibu_account_number] = $primary;
+ continue;
+ } else {
+ // if no primary -> make last one primary
+ $new_primary = false;
+ foreach(AddressModel::search(["fibu_account_number" => $address->fibu_account_number]) as $primary) {
+ $new_primary = $primary;
+ }
+ if(!$new_primary) {
+ var_dump($address);exit;
+ }
+ $new_primary->fibu_primary_account = 1;
+ $new_primary->save();
+ $addresses[$new_primary->fibu_account_number] = $new_primary;
+ continue;
+ }
+ }
+ var_dump($address);exit;
+ }
+
+ // if no fibu account number but customer number -> create fibu account number
+ if($address->customer_number && !$address->fibu_account_number) {
+ // Address::afterSave() generates new fibu account number
+ $address->save();
+ if(!$address->fibu_account_number) {
+ var_dump($address);exit;
+ }
+ $addresses[$address->fibu_account_number] = $address;
+ continue;
+ }
+
+ }
+
+ $export_addresses = [];
+
+ foreach($addresses as $address) {
+ $a = [];
+ $a["is_supplier"] = (array_key_exists("supplier", $address->types) && $address->types['supplier']) ? "1" : "0";
+ $a["is_customer"] = "1";
+ $a["customer_number"] = $address->customer_number;
+ $a["fibu_account_number"] = $address->fibu_account_number;
+ $a["fibu_supplier_number"] = $address->fibu_supplier_number;
+ $a["fibu_supplier_due"] = (is_numeric($address->fibu_supplier_due)) ? $address->fibu_supplier_due : TT_ADDRESS_DEFAULT_SUPPLIER_DUE;
+ $a["company"] = $address->company;
+ $a["firstname"] = $address->firstname;
+ $a["lastname"] = $address->lastname;
+ $a["street"] = $address->street;
+ $a["zip"] = $address->zip;
+ $a["city"] = $address->city;
+ $a["country"] = $address->country;
+ $a["phone"] = $address->phone;
+ $a["mobile"] = $address->mobile;
+ $a["email"] = $address->email;
+ $a["uid"] = $address->uid;
+ $a["billing_type"] = $address->billing_type;
+ $a["billing_delivery"] = $address->billing_delivery;
+ if(array_key_exists("billing", $address->links) && $address->links["billing"]) {
+ $a["bank"] = $address->links["billing"]->bank_account_bank;
+ $a["bank_owner"] = $address->links["billing"]->bank_account_owner;
+ $a["iban"] = $address->links["billing"]->bank_account_iban;
+ $a["bic"] = $address->links["billing"]->bank_account_bic;
+ } else {
+ $a["bank"] = $address->bank_account_bank;
+ $a["bank_owner"] = $address->bank_account_owner;
+ $a["iban"] = $address->bank_account_iban;
+ $a["bic"] = $address->bank_account_bic;
+ }
+
+ $export_addresses[] = $a;
+ }
+
+
+
+
+ $tpl = new Layout();
+ $tpl->setTemplate("Address/bmd_export.csv");
+ $tpl->set("addresses", $export_addresses);
+ $csv_content = $tpl->render();
+
+ $filename = "thetool_address_export_".$type."_".date("Y-m-d-H-i-s").".csv";
+
+ // save to TT_ADDRESS_BMD_EXPORT_PATH
+ $filepath = TT_ADDRESS_BMD_EXPORT_PATH."/".$filename;
+
+ if(!file_put_contents($filepath, $csv_content)) {
+ $this->layout()->setFlash("Datei $filepath konnte nicht gespeichert werden!", "error");
+ } else {
+ $export_ts->save();
+ $this->layout()->setFlash("Adressen erfolgreich exportiert", "success");
+ }
+
+ $this->redirect("Address");
+
+
+ }
+
protected function saveAction() {
$r = $this->request;
$id = $r->id;
@@ -204,6 +373,7 @@ class AddressController extends mfBaseController {
} else {
$data['fibu_primary_account'] = 0;
}
+ $data['fibu_supplier_due'] = ($r->fibu_supplier_due) ? $r->fibu_supplier_due : null;
// billing data
diff --git a/application/Address/AddressModel.php b/application/Address/AddressModel.php
index 3d2759ebe..4bc868620 100644
--- a/application/Address/AddressModel.php
+++ b/application/Address/AddressModel.php
@@ -166,7 +166,7 @@ class AddressModel {
$res = $db->query($sql);
if($db->num_rows($res)) {
$data = $db->fetch_object($res);
- return $data->cnt;
+ return (int)$data->cnt;
}
return 0;
}
@@ -397,6 +397,35 @@ class AddressModel {
$where .= " AND parent_id IS NULL";
}
}*/
+
+ if(array_key_exists("create>", $filter)) {
+ $create = $filter['create>'];
+ if(is_numeric($create)) {
+ $where .= " AND Address.create > $create";
+ }
+ }
+
+ if(array_key_exists("create<", $filter)) {
+ $create = $filter['create<'];
+ if(is_numeric($create)) {
+ $where .= " AND Address.create < $create";
+ }
+ }
+
+ if(array_key_exists("edit>", $filter)) {
+ $edit = $filter['edit>'];
+ if(is_numeric($edit)) {
+ $where .= " AND Address.edit > $edit";
+ }
+ }
+
+ if(array_key_exists("edit<", $filter)) {
+ $edit = $filter['edit<'];
+ if(is_numeric($edit)) {
+ $where .= " AND Address.edit < $edit";
+ }
+ }
+
//var_dump($filter, $where);exit;
return $where;
}
diff --git a/application/Building/Building.php b/application/Building/Building.php
index 5eac00956..19b14d447 100644
--- a/application/Building/Building.php
+++ b/application/Building/Building.php
@@ -3,6 +3,7 @@
class Building extends mfBaseModel {
protected $forcestr = ['street','zip','phone','email','note'];
+ private $in_after_save;
private $network;
private $networksection;
private $pop;
@@ -29,7 +30,12 @@ class Building extends mfBaseModel {
}
protected function afterSave() {
+ if($this->in_after_save) return true;
+ $this->in_after_save++;
+
$this->resetProperties();
+
+ $this->in_after_save--;
}
public function resetProperties() {
@@ -43,6 +49,18 @@ class Building extends mfBaseModel {
$this->files = null;
}
+ public function updateUnitCount() {
+ if(!$this->id) return true;
+
+ $unit_count = TerminationModel::count(["building_id" => $this->id]);
+ if($this->units != $unit_count) {
+ $this->units = $unit_count;
+ $this->save();
+ }
+
+ return true;
+ }
+
public function getNewObjectCode() {
if(!$this->zip) {
return false;
diff --git a/application/System/SystemController.php b/application/System/SystemController.php
new file mode 100644
index 000000000..708421775
--- /dev/null
+++ b/application/System/SystemController.php
@@ -0,0 +1,67 @@
+loadMe();
+ $this->layout()->set("me",$me);
+ $this->me = $me;
+
+ if(!$me->isAdmin()) {
+ // all users can call non-action methods
+ if($this->action != "" || $request != null) {
+ $this->redirect("Dashboard");
+ }
+ }
+ }
+
+ protected function indexAction() {
+ if(!$this->me->isAdmin()) {
+ $this->redirect("Dashboard");
+ }
+ $this->layout()->setTemplate("System/System");
+ }
+
+ protected function saveAction($request) {
+ if(!$this->me->isAdmin()) {
+ $this->redirect("Dashboard");
+ }
+ foreach($request as $name => $value) {
+ $m = [];
+ if(!preg_match('/^system_(.+)$/',$name,$m)) {
+ continue;
+ }
+ $name = str_replace("_", ".", $m[1]);
+ $config = new mfConfig($name);
+ $config->value($value);
+ $config->save();
+ }
+
+ $this->redirect("System");
+ }
+
+ public function getLastCommit() {
+ $git_path = BASEDIR."/.git";
+ $output = [];
+
+ if(defined("GIT_BIN_PATH") && GIT_BIN_PATH) {
+ $git = GIT_BIN_PATH;
+ } else {
+ $git = "/usr/bin/git";
+ }
+
+ $cmd = "$git --git-dir $git_path rev-parse HEAD";
+ if(!exec($cmd, $output)) {
+ $log = mfLoghandler::singleton();
+ $log->warn("Cannot read git ref!");
+ }
+
+ $ref = $output[0];
+ if(strlen($output[0]) > 8) {
+ $ref = substr($output[0], 0, 8);
+ }
+
+ return $ref;
+ }
+}
\ No newline at end of file
diff --git a/application/Termination/Termination.php b/application/Termination/Termination.php
index 2e5f7d178..8f19c38e6 100644
--- a/application/Termination/Termination.php
+++ b/application/Termination/Termination.php
@@ -3,6 +3,7 @@
class Termination extends mfBaseModel {
protected $forcestr = ['phone','email','note'];
+ private $in_after_save = 0;
private $building;
private $status;
private $lineworker;
@@ -14,7 +15,16 @@ class Termination extends mfBaseModel {
private $creator;
private $editor;
-
+ protected function afterSave() {
+ if($this->in_after_save) return true;
+ $this->in_after_save++;
+
+ if($this->building_id) {
+ $this->getProperty("building")->updateUnitCount();
+ }
+
+ $this->in_after_save--;
+ }
public function getAddress($singelLine = false) {
if(!$this->id) {
diff --git a/application/Termination/TerminationController.php b/application/Termination/TerminationController.php
index 7b21cf476..c164d3f5d 100644
--- a/application/Termination/TerminationController.php
+++ b/application/Termination/TerminationController.php
@@ -69,10 +69,10 @@ class TerminationController extends mfBaseController {
}
// increment Building::units
- if(is_numeric($building->units)) {
+ /*if(is_numeric($building->units)) {
++$building->units;
$building->save();
- }
+ }*/
$this->layout()->setFlash("Anschluss gespeichert.", "success");
$this->redirect("Building", "Index", [], "building=".$term->building_id);
@@ -132,10 +132,11 @@ class TerminationController extends mfBaseController {
$term->delete();
- if($building->units) {
+ $building->updateUnitCount();
+ /*if($building->units) {
--$building->units;
$building->save();
- }
+ }*/
$this->layout()->setFlash("Anschluss gelöscht", "success");
diff --git a/db/migrations/20240104200158_address_add_fibu_supplier_due.php b/db/migrations/20240104200158_address_add_fibu_supplier_due.php
new file mode 100644
index 000000000..1ac6fa875
--- /dev/null
+++ b/db/migrations/20240104200158_address_add_fibu_supplier_due.php
@@ -0,0 +1,33 @@
+getEnvironment() == "thetool") {
+ $table = $this->table("Address");
+ $table->addColumn("fibu_supplier_due", "integer", ["null" => true, "default" => null, "after" => "fibu_supplier_number"]);
+ $table->update();
+ }
+
+ if($this->getEnvironment() == "addressdb") {
+
+ }
+ }
+
+ public function down(): void
+ {
+ if($this->getEnvironment() == "thetool") {
+ $table = $this->table("Address");
+ $table->removeColumn("fibu_supplier_due");
+ $table->save();
+ }
+
+ if($this->getEnvironment() == "addressdb") {
+
+ }
+ }
+}
diff --git a/db/migrations/20240104201005_create_system_table.php b/db/migrations/20240104201005_create_system_table.php
new file mode 100644
index 000000000..66b166495
--- /dev/null
+++ b/db/migrations/20240104201005_create_system_table.php
@@ -0,0 +1,38 @@
+getEnvironment() == "thetool") {
+ $table = $this->table("System");
+ $table->addColumn("active", "integer", ["null" => false, "default" => 1, "limit" => \Phinx\Db\Adapter\MysqlAdapter::INT_TINY]);
+ $table->addColumn("name", "string", ["null" => false, "limit" => 255]);
+ $table->addColumn("value", "string", ["null" => false, "limit" => 1024]);
+ $table->addColumn("type", "enum", ["null" => false, "values" => 'int,float,string,json']);
+ $table->addColumn("create_by", "integer", ["null" => false]);
+ $table->addColumn("edit_by", "integer", ["null" => false]);
+ $table->addColumn("create", "integer", ["null" => false]);
+ $table->addColumn("edit", "integer", ["null" => false]);
+ $table->create();
+ }
+
+ if($this->getEnvironment() == "addressdb") {
+
+ }
+ }
+
+ public function down(): void
+ {
+ if($this->getEnvironment() == "thetool") {
+ $this->table("System")->drop();
+ }
+
+ if($this->getEnvironment() == "addressdb") {
+
+ }
+ }
+}
diff --git a/lib/Layout/Layout.php b/lib/Layout/Layout.php
index 69d4d2d7f..5d0122c12 100644
--- a/lib/Layout/Layout.php
+++ b/lib/Layout/Layout.php
@@ -43,6 +43,10 @@ class Layout extends mfLayout {
return date("d.m.Y", $int);
}
+ public function nl2ws($string) {
+ return str_replace(["\n","\r","\t","\v"], " ", $string);
+ }
+
/*
* Gets mfBaseModel object from Cache or gets in from DB and saves it to Cache
*/
diff --git a/lib/mvcfronk/mfConfig/mfConfig.php b/lib/mvcfronk/mfConfig/mfConfig.php
index 4049879d0..d0bc2250a 100644
--- a/lib/mvcfronk/mfConfig/mfConfig.php
+++ b/lib/mvcfronk/mfConfig/mfConfig.php
@@ -7,6 +7,10 @@ class mfConfig {
private $value;
private $active;
private $type;
+ public $create_by;
+ public $edit_by;
+ public $create;
+ public $edit;
private $me;
public function __construct($name) {
@@ -14,22 +18,27 @@ class mfConfig {
$name = $this->db->escape($name);
$this->name = $name;
-
- $me = new User();
+
+
if(defined("INTERNAL_USER_ID")) {
- $me->id = INTERNAL_USER_ID;
+ $me = new User(INTERNAL_USER_ID);
} else {
+ $me = new User();
$me->loadMe();
}
$this->me = $me;
- $res = $this->db->select("System", "*", "name='$name'");
+ $res = $this->db->select("System", "*", "name='$name' LIMIT 1");
if($this->db->num_rows($res)) {
$data = $this->db->fetch_object($res);
$this->id = $data->id;
$this->value = $data->value;
$this->active = $data->active;
$this->type = $data->type;
+ $this->create_by = $data->create_by;
+ $this->edit_by = $data->edit_by;
+ $this->create = $data->create;
+ $this->edit = $data->edit;
} else {
$this->active = 1;
$this->type = "string";
@@ -40,7 +49,16 @@ class mfConfig {
if($value !== null) {
$this->value = $value;
}
- return $this->value;
+ $return_value = $this->value;
+
+ if($this->type == "int") {
+ $return_value = (int)$return_value;
+ }
+ if($this->type == "float") {
+ $return_value = (float)$return_value;
+ }
+
+ return $return_value;
}
public function type($type = null) {
@@ -54,7 +72,6 @@ class mfConfig {
return $this->active;
}
-
public function save() {
$id = $this->id;