From 7646345779bde3edfb14a3eaef0ee9751f322030 Mon Sep 17 00:00:00 2001 From: Frank Schubert Date: Fri, 5 Jan 2024 13:56:02 +0100 Subject: [PATCH] WIP Address BMD Export --- Layout/default/Address/Form.php | 8 ++ Layout/default/Address/Index.php | 11 ++- Layout/default/Address/View.php | 3 + Layout/default/Address/bmd_export.csv.php | 9 ++ application/Address/AddressController.php | 97 +++++++++++++++++++ application/Address/AddressModel.php | 29 ++++++ application/System/SystemController.php | 67 +++++++++++++ ...04200158_address_add_fibu_supplier_due.php | 33 +++++++ .../20240104201005_create_system_table.php | 38 ++++++++ lib/Layout/Layout.php | 4 + lib/mvcfronk/mfConfig/mfConfig.php | 18 +++- 11 files changed, 308 insertions(+), 9 deletions(-) create mode 100644 Layout/default/Address/bmd_export.csv.php create mode 100644 application/System/SystemController.php create mode 100644 db/migrations/20240104200158_address_add_fibu_supplier_due.php create mode 100644 db/migrations/20240104201005_create_system_table.php diff --git a/Layout/default/Address/Form.php b/Layout/default/Address/Form.php index 12b5dc107..bff629cb1 100644 --- a/Layout/default/Address/Form.php +++ b/Layout/default/Address/Form.php @@ -256,6 +256,14 @@ + +
+ +
+ + Standard: 30 Tage +
+
diff --git a/Layout/default/Address/Index.php b/Layout/default/Address/Index.php index 170f0336b..d37b6fd14 100644 --- a/Layout/default/Address/Index.php +++ b/Layout/default/Address/Index.php @@ -38,7 +38,10 @@
@@ -47,7 +50,7 @@
-

Filter

+

Filter

">
@@ -157,8 +160,8 @@
- - ">Filter zurücksetzen + + "> Filter zurücksetzen
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 fibu_supplier_number?> + + FIBU Lieferanten Zahlungsziel + 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..b8e3cb6dc --- /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 + +;;;;;;nl2ws($a["company"])?>;nl2ws($a["firstname"])?>;nl2ws($a["lastname"])?>;nl2ws($a["street"])?>;nl2ws($a["$address->zip"])?>;nl2ws($a["city"])?>;nl2ws($a["country"])?>;nl2ws($a["phone"])?>;nl2ws($a["mobile"])?>;nl2ws($a["email"])?>;nl2ws($a["uid"])?>;;;;;; + +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) { + $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"] = $address->fibu_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; + } + + $addresses[] = $a; + } + + + + + $tpl = new Layout(); + $tpl->setTemplate("Address/bmd_export.csv"); + $tpl->set("addresses", $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 +300,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..e6ca33522 100644 --- a/application/Address/AddressModel.php +++ b/application/Address/AddressModel.php @@ -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/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/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..fcbc8c7d2 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"; @@ -54,7 +63,6 @@ class mfConfig { return $this->active; } - public function save() { $id = $this->id;