diff --git a/application/Address/Address.php b/application/Address/Address.php index 1d4e297bf..d5e881e6a 100644 --- a/application/Address/Address.php +++ b/application/Address/Address.php @@ -20,7 +20,7 @@ class Address extends mfBaseModel { private $creator; private $editor; - protected function afterSave() { + public function afterSave() { // prevent potential infinite loop if($this->in_after_save) return true; $this->in_after_save++; @@ -91,13 +91,26 @@ class Address extends mfBaseModel { } elseif(OrderModel::getFirst(["billingaddress_id" => $this->id])) { $create_fibu_num = true; } + + if(is_array($this->getProperty("types")) && array_key_exists("fullcustomer", $this->getProperty("types")) && $this->getProperty("types")["fullcustomer"]) { + $create_fibu_num = true; + } } if(!$create_fibu_num) { return false; } + if(!$this->customer_number) { + // create customer number first + $new_custnum = $this->getNewCustomerNumber(); + if(!$new_custnum) { + return false; + } + $this->customer_number = $new_custnum; + $this->save(); + } $fibu_account_number = Address::getNextFibuAccountNumber(); if(!$fibu_account_number) { diff --git a/application/Address/AddressController.php b/application/Address/AddressController.php index 1c22f9b41..ab0050adb 100644 --- a/application/Address/AddressController.php +++ b/application/Address/AddressController.php @@ -461,6 +461,9 @@ class AddressController extends mfBaseController { } } + + // run afterSave() again in case anything importand has changed + $address->afterSave(); $sq = ""; $query = []; diff --git a/db/migrations/20250107132447_addresstype_add_fullcustomer.php b/db/migrations/20250107132447_addresstype_add_fullcustomer.php new file mode 100644 index 000000000..765de4655 --- /dev/null +++ b/db/migrations/20250107132447_addresstype_add_fullcustomer.php @@ -0,0 +1,33 @@ +getEnvironment() == "thetool") { + $addresstype = $this->table("Addresstype"); + $addresstype->changeColumn("type", "enum", ["null" => false, "values" => "systemowner,productowner,netowner,salespartner,pipeworker,lineworker,pipeplanner,lineplanner,netoperator,supplier,billing,employee,customer,fullcustomer,contact,techcontact,commercialcontact"]); + $addresstype->update(); + } + + if($this->getEnvironment() == "addressdb") { + + } + } + + public function down(): void + { + if($this->getEnvironment() == "thetool") { + $addresstype = $this->table("Addresstype"); + $addresstype->changeColumn("type", "enum", ["null" => false, "values" => "systemowner,productowner,netowner,salespartner,pipeworker,lineworker,pipeplanner,lineplanner,netoperator,supplier,billing,employee,customer,contact,techcontact,commercialcontact"]); + $addresstype->update(); + } + + if($this->getEnvironment() == "addressdb") { + + } + } +} diff --git a/lang/de.php b/lang/de.php index a57d0a599..cd99cb7c3 100644 --- a/lang/de.php +++ b/lang/de.php @@ -14,6 +14,7 @@ $l['planner'] = "Planer"; $l['support'] = "Support"; $l['employee'] = "Mitarbeiter"; $l['customer'] = "Kunde"; +$l['fullcustomer'] = "Xinonkunde"; $l['customers'] = "Kunden"; $l['supplier'] = "Lieferant"; $l['suppliers'] = "Lieferanten"; diff --git a/lib/mvcfronk/mfBase/mfBaseModel.php b/lib/mvcfronk/mfBase/mfBaseModel.php index 3499d4cc1..2a3beeaa6 100644 --- a/lib/mvcfronk/mfBase/mfBaseModel.php +++ b/lib/mvcfronk/mfBase/mfBaseModel.php @@ -238,7 +238,8 @@ class mfBaseModel { } protected function getChangedFields($include_system = false) { - if(!$this->_old_data->id) return []; + if(!is_object($this->_old_data) || !property_exists($this->_old_data, "id") || !$this->_old_data->id) return []; + if(!is_object($this->data) || !is_object($this->_old_data)) { return []; }