diff --git a/Layout/default/Address/Form.php b/Layout/default/Address/Form.php index 4ebf5f683..12b5dc107 100644 --- a/Layout/default/Address/Form.php +++ b/Layout/default/Address/Form.php @@ -168,7 +168,6 @@ -

Verrechnungsdaten

@@ -233,6 +232,32 @@
+

FIBU

+
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+
+

Zusatzdaten

diff --git a/Layout/default/Address/Index.php b/Layout/default/Address/Index.php index 054bc5db5..2d09bf920 100644 --- a/Layout/default/Address/Index.php +++ b/Layout/default/Address/Index.php @@ -33,6 +33,18 @@
+ can("Fibu")): ?> + + +

Filter

@@ -65,63 +77,69 @@
- + " />
- + " /> +
+ +
+ + " />
- + " />
- + " />
- + " />
- +
+
- + " />
- + " />
- + " />
- + " />
- + " />
- + " />
- + " />
@@ -159,6 +177,7 @@ Typ Kundennummer + FIBU Verrechnungskonto Firma Name Adresse @@ -168,7 +187,7 @@ - types)):?> + types) && count($address->types)):?> types); $l7d_types = []; @@ -179,6 +198,8 @@ "> 1) ? ", ..." : ""?> + + $address->id, 'filter' => $filter, 's' => $pagination['start']])?>"> @@ -186,6 +207,7 @@ spin) ? "
".$address->spin."" : ""?>
+ fibu_account_number?>fibu_primary_account) ? " " : ""?> $address->id, 'filter' => $filter, 's' => $pagination['start']])?>">company)?> $address->id, 'filter' => $filter, 's' => $pagination['start']])?>">getFullName()?> diff --git a/Layout/default/Address/View.php b/Layout/default/Address/View.php index 7d2384d2b..f3832d092 100644 --- a/Layout/default/Address/View.php +++ b/Layout/default/Address/View.php @@ -116,6 +116,18 @@ BIC bank_account_bic?> + +

FIBU

+ + + Ist primäres Verrechnungskonto + fibu_primary_account) ? "" : ""?> + + FIBU Verrechnungskonto + fibu_account_number?> + + FIBU Lieferanten Konto + fibu_supplier_number?>

Zusatzdaten

@@ -123,7 +135,7 @@ attributes) && array_key_exists("rtrcode", $address->attributes)) ? $address->attributes['rtrcode']->value : ""?> - +

Verknüpfungen

links) && count($address->links)): ?>
diff --git a/Layout/default/Preorderlogistics/Index.php b/Layout/default/Preorderlogistics/Index.php index b1ee30847..c0eb7e2ae 100644 --- a/Layout/default/Preorderlogistics/Index.php +++ b/Layout/default/Preorderlogistics/Index.php @@ -46,8 +46,7 @@
diff --git a/Layout/default/User/Form.php b/Layout/default/User/Form.php index e2eaa2e9f..4853b9091 100644 --- a/Layout/default/User/Form.php +++ b/Layout/default/User/Form.php @@ -56,21 +56,28 @@
- id == 1) ? "disabled='disabled'" : ""?>>
+
+ + +
- + +
- @@ -78,7 +85,7 @@
- @@ -87,7 +94,7 @@
- @@ -199,6 +206,17 @@
+

Zusatzberechtigungen

+ +
+
+
+ can("Fibu")) ? "checked='checked'" : ""?> /> + +
+
+
+
diff --git a/application/Address/Address.php b/application/Address/Address.php index e4a79b023..84784c65a 100644 --- a/application/Address/Address.php +++ b/application/Address/Address.php @@ -2,6 +2,8 @@ class Address extends mfBaseModel { protected $forcestr = ['street','company','zip','phone','fax','mobile','note']; + private $in_after_save = false; + private $parent; private $childaddresses; private $links = []; @@ -14,6 +16,55 @@ class Address extends mfBaseModel { private $phoneparts; + protected function afterSave() { + // prevent potential infinite loop + if($this->in_after_save) return true; + $this->in_after_save = true; + + $this->syncToFibuMerge(); + } + + private function syncToFibuMerge() { + if(!$this->customer_number) return true; + + //var_dump($this);exit; + + if($this->fibu_account_number) { + $fibumerge = XinonFibuMergeModel::getFirst(["old_custnum" => $this->customer_number]); + if(!$fibumerge) { + // create fibu merge + $fibumerge = XinonFibuMergeModel::create([ + "old_custnum" => $this->customer_number, + "new_custnum" => $this->fibu_account_number, + "name" => ($this->company) ? $this->company : $this->lastname, + "vorname" => ($this->company) ? "" : $this->firstname, + "strasse" => $this->street, + "plz" => $this->zip, + "ort" => $this->city, + ]); + $fibumerge->save(); + return true; + } + + if($fibumerge->new_custnum != $this->fibu_account_number) { + $fibumerge->new_custnum = $this->fibu_account_number; + $fibumerge->save(); + } + } elseif($this->_old_data->fibu_account_number) { + // fibu account number was removed => remove fibumerge entry + $fibumerge = XinonFibuMergeModel::getFirst(["old_custnum" => $this->customer_number, "new_custnum" => $this->_old_data->fibu_account_number]); + //var_dump($fibumerge);exit; + if(!$fibumerge) return true; + + $fibumerge->delete(); + + } + + + return true; + + } + public function getFullName() { // Assumes "Firma1 Firma2" or "firstname lastname" as readable form $name = ""; @@ -146,6 +197,24 @@ class Address extends mfBaseModel { } }*/ + public static function getNextSupplierNumber() { + $db = FronkDB::singleton(); + $res = $db->select("Address","fibu_supplier_number", "fibu_supplier_number > 0 ORDER BY fibu_supplier_number DESC LIMIT 1"); + if(!$db->num_rows($res)) { + return TT_FIRST_SUPPLIER_NUM; + } + + $data = $db->fetch_object($res); + $last_num = $data->fibu_supplier_number; + if($last_num) { + $new_num = $last_num + 1; + } else { + $new_num = TT_FIRST_SUPPLIER_NUM; + } + return $new_num; + + } + public function getProperty($name) { if($this->$name == null) { diff --git a/application/Address/AddressController.php b/application/Address/AddressController.php index adf1ad19b..2ea7d8c14 100644 --- a/application/Address/AddressController.php +++ b/application/Address/AddressController.php @@ -73,6 +73,11 @@ class AddressController extends mfBaseController { $new_filter["parents_only"] = 1; } + if(array_key_exists("fibu_account_number", $filter) && $filter['fibu_account_number']) { + $new_filter['fibu_account_number'] = $filter['fibu_account_number']."%"; + unset($filter['fibu_account_number']); + } + foreach($filter as $name => $value) { $new_filter[$name] = $value; } @@ -177,6 +182,13 @@ class AddressController extends mfBaseController { $data['email'] = $r->email; $data['note'] = $r->note; $data['uid'] = $r->uid; + $data['fibu_account_number'] = ($r->fibu_account_number) ? $r->fibu_account_number : null; + $data['fibu_supplier_number'] = ($r->fibu_supplier_number) ? $r->fibu_supplier_number : null; + if($r->fibu_primary_account) { + $data['fibu_primary_account'] = 1; + } else { + $data['fibu_primary_account'] = 0; + } // billing data @@ -236,6 +248,17 @@ class AddressController extends mfBaseController { return $this->add(); } + // check for multiple primary fibu accounts, and remove from any other than this one + if($address->fibu_primary_account && $address->fibu_account_number) { + foreach(AddressModel::search(["fibu_primary_account" => true, "fibu_account_number" => $address->fibu_account_number]) as $fibu_primary) { + if($fibu_primary->id == $address->id) continue; + $fibu_primary->fibu_primary_account = 0; + $fibu_primary->save(); + } + } + + + // save address types $new_types = $r->addresstypes; if(is_array($new_types)) { foreach($address->types as $existing_type) { @@ -258,6 +281,19 @@ class AddressController extends mfBaseController { } } + // generate new supplier account number if is supplier and supplier num empty + //var_dump($mode, $address->fibu_supplier_number, $address->types);exit; + if(!$address->fibu_supplier_number && array_key_exists("supplier", $address->types)) { + $supplier_num = Address::getNextSupplierNumber(); + if(!$supplier_num) { + $this->layout()->setFlash("Lieferantennummer konnte nicht generiert werden."); + } else { + $this->log->debug("new supplier number: ". $supplier_num); + $address->fibu_supplier_number = $supplier_num; + $address->save(); + } + } + $attribs = $r->attributes; //var_dump($attribs);exit; if(is_array($attribs) && count($attribs)) { diff --git a/application/Address/AddressModel.php b/application/Address/AddressModel.php index 1792778a5..977cc96cb 100644 --- a/application/Address/AddressModel.php +++ b/application/Address/AddressModel.php @@ -1,20 +1,23 @@ escape($fan); + $where .= " AND fibu_account_number LIKE '$fan'"; + } + } + } + + if(array_key_exists("fibu_supplier_number", $filter)) { + $fsn = $filter["fibu_supplier_number"]; + if(is_numeric($fsn)) { + $where .= " AND fibu_supplier_number=$fsn"; + } + } + + if(array_key_exists("fibu_primary_account", $filter)) { + $fpa = $filter["fibu_primary_account"]; + if($fpa) { + $where .= " AND fibu_primary_account=1"; + } else { + $where .= " AND fibu_primary_account=0"; + } + } + if(array_key_exists("spin", $filter)) { $spin = FronkDB::singleton()->escape($filter["spin"]); if($spin) { diff --git a/application/User/User.php b/application/User/User.php index a176baed4..c9d2bbcd3 100644 --- a/application/User/User.php +++ b/application/User/User.php @@ -111,7 +111,7 @@ class User extends mfBaseModel { $m = []; if(preg_match('/^([^ ]+) ([^ ]+)(?: ([^ ]+))?$/', $this->name, $m)) { $firstname = $m[1]; - if($m[3]) { + if(array_key_exists(3, $m) && $m[3]) { $middlename = $m[2]; $lastname = $m[3]; } else { @@ -261,7 +261,6 @@ class User extends mfBaseModel { public function myNetworks($types) { $typenets = []; $my_networks = $this->getProperty("my_networks"); - if(!is_array($types)) { $types = [$types]; } diff --git a/application/User/UserController.php b/application/User/UserController.php index 722643fd1..eb6a396d6 100644 --- a/application/User/UserController.php +++ b/application/User/UserController.php @@ -188,6 +188,12 @@ class UserController extends mfBaseController $user->permissions->admin = "false"; } + if ($r->employee == "true") { + $user->permissions->employee = "true"; + } else { + $user->permissions->employee = "false"; + } + if ($r->technician == "true") { $user->permissions->technician = "true"; } else { @@ -218,10 +224,11 @@ class UserController extends mfBaseController $user->permissions->canVoipnumbering = "false"; $user->permissions->canPreorder = "false"; $user->permissions->canOrder = "false"; + $user->permissions->canFibu = "false"; if($r->get("can") && is_array($r->can)) { foreach($r->can as $key => $can) { - var_dump($key . "=> ".$can); + //var_dump($key . "=> ".$can); if($can) { $user->permissions->{"can$key"} = "true"; } diff --git a/application/WorkerPermission/WorkerPermission.php b/application/WorkerPermission/WorkerPermission.php index e1bed311e..4fa25500a 100644 --- a/application/WorkerPermission/WorkerPermission.php +++ b/application/WorkerPermission/WorkerPermission.php @@ -2,7 +2,7 @@ class WorkerPermission extends mfBaseModel { public $isAdmin = false; - public $isTicketadmin = false; + public $isEmployee = false; public $isTechnician = false; public $isPreorderfront = false; public $isPreorderaddressreporting = false; @@ -26,8 +26,8 @@ class WorkerPermission extends mfBaseModel { if($this->admin == 'true') { $this->isAdmin = true; } - if($this->ticketadmin == 'true') { - $this->isTicketadmin = true; + if($this->employee == 'true') { + $this->isEmployee = true; } if($this->technician == 'true') { $this->isTechnician = true; diff --git a/application/XinonFibuMerge/XinonFibuMerge.php b/application/XinonFibuMerge/XinonFibuMerge.php new file mode 100644 index 000000000..e932c4896 --- /dev/null +++ b/application/XinonFibuMerge/XinonFibuMerge.php @@ -0,0 +1,35 @@ +$name == null) { + + if(!$this->id) { + return null; + } + + if($name == "address") { + if(!$this->old_custnum) return null; + + $address = new Address($this->old_custnum); + if(!$address->id) return null; + return $address; + } + + + $classname = ucfirst($name); + $idfield = $name."_id"; + $this->$name = new $classname($this->$idfield); + + if($this->$name->id) { + return $this->$name; + } else { + return null; + } + } + + return $this->$name; + } +} \ No newline at end of file diff --git a/application/XinonFibuMerge/XinonFibuMergeModel.php b/application/XinonFibuMerge/XinonFibuMergeModel.php new file mode 100644 index 000000000..2e46a3983 --- /dev/null +++ b/application/XinonFibuMerge/XinonFibuMergeModel.php @@ -0,0 +1,142 @@ + $value) { + if (property_exists(get_called_class(), $field)) { + $model->$field = $value; + } + } + + $me = mfValuecache::singleton()->get("me"); + if (!$me) { + $me = new User(); + $me->loadMe(); + mfValuecache::singleton()->set("me", $me); + } + + if ($model->create_by === null) { + $model->create_by = $me->id; + } + if ($model->edit_by === null) { + $model->edit_by = $me->id; + } + + return $model; + } + + public static function getFirst($filter = []) { + $db = FronkDB::singleton(); + + $where = self::getSqlFilter($filter); + $res = $db->select("XinonFibuMerge", "*", "$where ORDER BY old_custnum LIMIT 1"); + if ($db->num_rows($res)) { + $data = $db->fetch_object($res); + $item = new XinonFibuMerge($data); + if ($item->id) { + return $item; + } else { + return null; + } + } + return null; + } + + public static function getAll() { + $items = []; + + $db = FronkDB::singleton(); + + $res = $db->select("XinonFibuMerge", "*", "1=1 ORDER BY old_custnum"); + if ($db->num_rows($res)) { + while ($data = $db->fetch_object($res)) { + $items[] = new XinonFibuMerge($data); + } + } + return $items; + } + + public static function count($filter) { + $db = FronkDB::singleton(); + + $where = self::getSqlFilter($filter); + $sql = "SELECT COUNT(*) as cnt FROM XinonFibuMerge + WHERE $where + "; + + $res = $db->query($sql); + if ($db->num_rows($res)) { + $data = $db->fetch_object($res); + return $data->cnt; + } + return 0; + } + + public static function search($filter = [], $limit = false) { + $items = []; + $db = FronkDB::singleton(); + + $where = self::getSqlFilter($filter); + $sql = "SELECT * FROM XinonFibuMerge + WHERE $where + ORDER BY old_custnum"; + + mfLoghandler::singleton()->debug($sql); + if (is_array($limit) && count($limit)) { + if (is_numeric($limit['start']) && is_numeric($limit['count'])) { + $sql .= " LIMIT " . $limit['start'] . ", " . $limit['count']; + } elseif (is_numeric($count)) { + $sql .= " LIMIT " . $limit['count']; + } + } + + $res = $db->query($sql); + if ($db->num_rows($res)) { + while ($data = $db->fetch_object($res)) { + $items[] = new XinonFibuMerge($data); + } + } + return $items; + } + + private static function getSqlFilter($filter) { + $where = "1=1 "; + + + + if(array_key_exists("old_custnum", $filter)) { + $old_custnum = $filter['old_custnum']; + if (is_numeric($old_custnum)) { + $where .= " AND XinonFibuMerge.old_custnum=$old_custnum"; + } + } + + if(array_key_exists("new_custnum", $filter)) { + $new_custnum = $filter['new_custnum']; + if (is_numeric($new_custnum)) { + $where .= " AND XinonFibuMerge.new_custnum=$new_custnum"; + } + } + + + //var_dump($filter, $where);exit; + return $where; + } + +} diff --git a/db/migrations/20231212142423_address_add_fibubillingnumber_suppliernumber.php b/db/migrations/20231212142423_address_add_fibubillingnumber_suppliernumber.php new file mode 100644 index 000000000..8ec343038 --- /dev/null +++ b/db/migrations/20231212142423_address_add_fibubillingnumber_suppliernumber.php @@ -0,0 +1,37 @@ +getEnvironment() == "thetool") { + $table = $this->table("Address"); + $table->addColumn("fibu_account_number","integer", ["null" => true, "default" => null, "after" => "customer_number"]); + $table->addColumn("fibu_supplier_number","integer", ["null" => true, "default" => null, "after" => "fibu_account_number"]); + $table->addColumn("fibu_primary_account","integer", ["null" => false, "default" => 0, "limit" => \Phinx\Db\Adapter\MysqlAdapter::INT_TINY, "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_primary_account"); + $table->removeColumn("fibu_supplier_number"); + $table->removeColumn("fibu_account_number"); + $table->save(); + } + + if($this->getEnvironment() == "addressdb") { + + } + } +} diff --git a/db/migrations/20231214141719_worker_permission_add_employee.php b/db/migrations/20231214141719_worker_permission_add_employee.php new file mode 100644 index 000000000..013052ee5 --- /dev/null +++ b/db/migrations/20231214141719_worker_permission_add_employee.php @@ -0,0 +1,35 @@ +getEnvironment() == "thetool") { + $table = $this->table("WorkerPermission"); + $table->addColumn("employee", "enum", ["values" => 'false,true', "default" => "false", "after" => "admin"]); + $table->addColumn("canFibu", "enum", ["values" => 'false,true', "default" => "false", "after" => "preorderlogistics"]); + $table->update(); + } + + if($this->getEnvironment() == "addressdb") { + + } + } + + public function down(): void + { + if($this->getEnvironment() == "thetool") { + $table = $this->table("WorkerPermission"); + $table->removeColumn("canFibu"); + $table->removeColumn("employee"); + $table->save(); + } + + if($this->getEnvironment() == "addressdb") { + + } + } +}