Added address-no-fibunum import script
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
class Address extends mfBaseModel {
|
||||
protected $forcestr = ['street','company','zip','phone','fax','mobile','note'];
|
||||
private $in_after_save = false;
|
||||
private $in_after_save = 0;
|
||||
|
||||
private $parent;
|
||||
private $childaddresses;
|
||||
@@ -19,10 +19,13 @@ class Address extends mfBaseModel {
|
||||
protected function afterSave() {
|
||||
// prevent potential infinite loop
|
||||
if($this->in_after_save) return true;
|
||||
$this->in_after_save = true;
|
||||
$this->in_after_save++;
|
||||
|
||||
$this->generateFibuAccountNumber();
|
||||
$this->syncToFibuMerge();
|
||||
|
||||
$this->in_after_save--;
|
||||
|
||||
}
|
||||
|
||||
private function generateFibuAccountNumber() {
|
||||
@@ -40,11 +43,31 @@ class Address extends mfBaseModel {
|
||||
$this->save();
|
||||
}
|
||||
|
||||
public function getNewCustomerNumber() {
|
||||
$last_num = AddressModel::getLastCustomerNumber();
|
||||
$this->log->debug("last_num: $last_num");
|
||||
if($last_num) {
|
||||
$new_num = $last_num + 1;
|
||||
} else {
|
||||
$new_num = TT_FIRST_CUSTNUM;
|
||||
}
|
||||
|
||||
if(!AddressModel::search(['customer_number' => $new_num])) {
|
||||
$this->customer_number = $new_num;
|
||||
return $this->customer_number;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private function syncToFibuMerge() {
|
||||
if(!$this->customer_number) return true;
|
||||
|
||||
//var_dump($this);exit;
|
||||
|
||||
$me = new User();
|
||||
$me->loadMe();
|
||||
|
||||
if($this->fibu_account_number) {
|
||||
$fibumerge = XinonFibuMergeModel::getFirst(["old_custnum" => $this->customer_number]);
|
||||
if(!$fibumerge) {
|
||||
@@ -57,6 +80,8 @@ class Address extends mfBaseModel {
|
||||
"strasse" => $this->street,
|
||||
"plz" => $this->zip,
|
||||
"ort" => $this->city,
|
||||
"create_by" => $me->id,
|
||||
"edit_by" => $me->id
|
||||
]);
|
||||
$fibumerge->save();
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user