Overhauled Address linking
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
class Order extends mfBaseModel {
|
||||
private $owner;
|
||||
private $billingaddress;
|
||||
private $techcontact;
|
||||
private $products;
|
||||
private $customer_type;
|
||||
private $contracts;
|
||||
@@ -251,6 +252,17 @@ class Order extends mfBaseModel {
|
||||
return $this->billingaddress;
|
||||
}
|
||||
|
||||
if($name == "techcontact") {
|
||||
$this->techcontact = mfValuecache::singleton()->get("mfObjectmodel-Address-".$this->techcontact_id);
|
||||
if($this->techcontact === null) {
|
||||
$this->techcontact = new Address($this->techcontact_id);
|
||||
if($this->techcontact->id) {
|
||||
mfValuecache::singleton()->set("mfObjectmodel-Address-".$this->techcontact_id, $this->techcontact);
|
||||
}
|
||||
}
|
||||
return $this->techcontact;
|
||||
}
|
||||
|
||||
if($name == "products") {
|
||||
$this->products = OrderProductModel::search(["order_id" => $this->id]);
|
||||
//var_dump($this->products);exit;
|
||||
|
||||
@@ -546,6 +546,44 @@ class OrderController extends mfBaseController {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// validate techcontact
|
||||
$techcontact = false;
|
||||
if($r->techcontact_id) {
|
||||
// techcontact can be empty
|
||||
if(is_numeric($r->techcontact_id)) {
|
||||
$techcontact = new Address($r->techcontact_id);
|
||||
if(!$techcontact->id) {
|
||||
$this->layout()->setFlash("Ungültiger technischer Kontakt.", "error");
|
||||
$this->layout()->set("order", $r);
|
||||
return $this->add();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// if any required part of new techcontact is set
|
||||
$techcontact_new = false;
|
||||
if(!$r->techcontact_id
|
||||
&& ($r->techcontact_company || $r->techcontact_firstname || $r->techcontact_lastname
|
||||
|| $r->techcontact_street || $r->techcontact_zip || $r->techcontact_city || $r->techcontact_phone || $r->techcontact_email)
|
||||
) {
|
||||
$techcontact_new = true;
|
||||
|
||||
if(!$r->techcontact_company && !$r->techcontact_firstname && !$r->techcontact_lastname) {
|
||||
$this->layout()->setFlash("Fehler in technischem Kontakt: Firmenname oder Name benötigt.");
|
||||
$this->layout()->set("order", $r);
|
||||
return $this->add();
|
||||
}
|
||||
|
||||
if(!$r->techcontact_phone && !$r->techcontact_mobile && !$r->techcontact_email) {
|
||||
$this->layout()->setFlash("Fehler in technischem Kontakt: Kontaktmöglichkeit benötigt.");
|
||||
$this->layout()->set("order", $r);
|
||||
return $this->add();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// validate sepa
|
||||
if(!$r->billing_type) {
|
||||
$this->layout()->setFlash("Ungültige Verrechnungsart.");
|
||||
@@ -566,6 +604,7 @@ class OrderController extends mfBaseController {
|
||||
// create objects for saving (if new) but don't save yet
|
||||
$owner_data = [];
|
||||
$billing_data = [];
|
||||
$techcontact_data = [];
|
||||
|
||||
$request = $r->get();
|
||||
foreach($request as $field => $value) {
|
||||
@@ -577,6 +616,9 @@ class OrderController extends mfBaseController {
|
||||
if($m[1] == "billing" && !$billingaddress) {
|
||||
$billing_data[$m[2]] = $value;
|
||||
}
|
||||
if($m[1] == "techcontact" && !$techcontact) {
|
||||
$techcontact_data[$m[2]] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -622,6 +664,9 @@ class OrderController extends mfBaseController {
|
||||
if(!$billingaddress) {
|
||||
$billingaddress = AddressModel::create($billing_data);
|
||||
}
|
||||
if(!$techcontact) {
|
||||
$techcontact = AddressModel::create($techcontact_data);
|
||||
}
|
||||
|
||||
// create or save Order object
|
||||
|
||||
@@ -632,6 +677,9 @@ class OrderController extends mfBaseController {
|
||||
if(is_numeric($r->billingaddress_id)) {
|
||||
$order_data['billingaddress_id'] = $r->billingaddress_id;
|
||||
}
|
||||
if(is_numeric($r->techcontact_id)) {
|
||||
$order_data['techcontact_id'] = $r->techcontact_id;
|
||||
}
|
||||
|
||||
$order_data['partner_number'] = $r->partner_number;
|
||||
$order_data['allow_contact'] = ($r->allow_contact) ? 1 : 0;
|
||||
@@ -685,7 +733,7 @@ class OrderController extends mfBaseController {
|
||||
exit;*/
|
||||
|
||||
|
||||
if(!$owner || !$billingaddress) {
|
||||
if(!$owner) {
|
||||
$this->layout()->setFlash("Fehler beim Speichern", "error");
|
||||
$this->layout()->set("order", $order);
|
||||
return $this->add();
|
||||
@@ -720,6 +768,38 @@ class OrderController extends mfBaseController {
|
||||
|
||||
$order->billingaddress_id = $billingaddress_id;
|
||||
$order->save();
|
||||
|
||||
// add billingaddress as AddressLink to owner
|
||||
$linkdata = [];
|
||||
$linkdata['address_id'] = $billingaddress->id;
|
||||
$linkdata['origin_address_id'] = $order->owner_id;
|
||||
$linkdata['type'] = "billing";
|
||||
$link = AddressLinkModel::create($linkdata);
|
||||
$link->save();
|
||||
}
|
||||
if($techcontact_new) {
|
||||
$techcontact_id = $techcontact->save();
|
||||
if(!$techcontact_id) {
|
||||
$this->layout()->setFlash("Fehler beim Speichern des technischen Kontakts", "error");
|
||||
$this->redirect("Order", "edit", ['id' => $new_id]);
|
||||
}
|
||||
// create addresstype (techcontact)
|
||||
$at = AddresstypeModel::create(['address_id' => $techcontact_id, 'type' => "techcontact"]);
|
||||
$at->save();
|
||||
|
||||
$order->techcontact_id = $techcontact_id;
|
||||
$order->save();
|
||||
}
|
||||
|
||||
// add techcontact as AddressLink to owner if not exists
|
||||
$link = AddressLinkModel::getFirst(['address_id' => $techcontact->id, 'origin_address_id' => $order->owner_id, 'type' => "techcontact"]);
|
||||
if(!$link) {
|
||||
$linkdata = [];
|
||||
$linkdata['address_id'] = $techcontact->id;
|
||||
$linkdata['origin_address_id'] = $order->owner_id;
|
||||
$linkdata['type'] = "techcontact";
|
||||
$link = AddressLinkModel::create($linkdata);
|
||||
$link->save();
|
||||
}
|
||||
|
||||
|
||||
@@ -986,7 +1066,7 @@ class OrderController extends mfBaseController {
|
||||
if($r->return == "index") {
|
||||
$this->redirect("Order", "Index", $qs, "order=$new_id-details");
|
||||
} else {
|
||||
$this->redirect("Order", "edit", $qs, "order=$new_id-details");
|
||||
$this->redirect("Order", "edit", $qs);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
class OrderModel {
|
||||
public $owner_id;
|
||||
public $billingaddress_id;
|
||||
public $techcontact_id;
|
||||
public $upgrade;
|
||||
public $partner_number;
|
||||
public $order_date;
|
||||
|
||||
Reference in New Issue
Block a user