diff --git a/Layout/default/Address/Form.php b/Layout/default/Address/Form.php index f39af477d..0ad49b7ba 100644 --- a/Layout/default/Address/Form.php +++ b/Layout/default/Address/Form.php @@ -1,4 +1,17 @@ parent->types);exit;?> + @@ -7,8 +20,11 @@
@@ -25,24 +41,12 @@

id) ? "Person/Firma bearbeiten" : "Neue Person/Firma"?>

-
"> +
-
- -
- -
-
-
@@ -156,23 +160,9 @@
@@ -256,11 +246,11 @@
-

Verknüpfte Adressen

+

Verknüpfungen

+
+
@@ -337,7 +348,9 @@
- + + +
diff --git a/Layout/default/Address/Index.php b/Layout/default/Address/Index.php index cdce20d66..ac44e9cfd 100644 --- a/Layout/default/Address/Index.php +++ b/Layout/default/Address/Index.php @@ -145,18 +145,6 @@

Liste aller Personen & Firmen

- -

- - Zeige alle Personen und Firmen
- - Zeige nur Personen und Firmen ohne Zugehörigkeit an. array_merge($filter, ["parents_only" => 0])])?>">Alle anzeigen
- - - Gefiltert nach Rolle:
- -

-
"> Neue Person/Firma anlegen @@ -206,8 +194,9 @@ email?> ["address_id" => $address->id]])?>" title="Benutzer anzeigen"> - $address->id])?>"> - $address->id])?>" onclick="if(!confirm('Person/Firma wirklich löschen?')) return false;" class="text-danger" title="Löschen"> + $address->id, 'filter' => $filter, 's' => $pagination['start']])?>"> + $address->id, 's' => $pagination['start']])?>"> + $address->id, 's' => $pagination['start']])?>" onclick="if(!confirm('Person/Firma wirklich löschen?')) return false;" class="text-danger" title="Löschen"> diff --git a/Layout/default/Address/View.php b/Layout/default/Address/View.php new file mode 100644 index 000000000..320917bb2 --- /dev/null +++ b/Layout/default/Address/View.php @@ -0,0 +1,195 @@ + + + +
+
+
+
+ +
+

Personen & Firmen

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

Person/Firma

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Kundennummercustomer_number?>
Firmennamecompany)?>
Vornamefirstname?>
Nachnamelastname?>
Straßestreet?>
PLZ / Ortzip?> city?>
Landcountry?>
Telefonphone?>
Mobilmobile?>
Faxfax?>
Emailemail?>
Service PINspin?>
Einwilligungen +

"> Informationen per Post/Email/Telefon

+

">Auskunft mit Service PIN

+
Rollen + types) && count($address->types)): ?> + +
    + types)): ?> +
  • + +
+ + +

Verrechnungsdaten

UIDuid?>
Verrechnungsartbilling_type == "sepa") ? "SEPA Bankeinzug" : "Rechnung"?>
Rechnungsversandbilling_delivery == "paper") ? "POST" : "Email"?>
Kreditinstitutbank_account_bank?>
Kontoinhaberbank_account_owner?>
IBANbank_account_iban?>
BICbank_account_bic?>

Zusatzdaten

RTR Codeattributes['rtrcode']->value?>
+ +

Verknüpfungen

+ links) && count($address->links)): ?> +
+ +
+ + + linked_as) && count($address->linked_as)): ?> +

Verknüpft als

+ + + +
+
+ + + +
+
+ + \ No newline at end of file diff --git a/Layout/default/Order/Form.php b/Layout/default/Order/Form.php index 231061ece..268fc6d90 100644 --- a/Layout/default/Order/Form.php +++ b/Layout/default/Order/Form.php @@ -52,7 +52,7 @@
-
+
@@ -172,7 +172,7 @@
-
+
@@ -292,6 +292,120 @@
+
+
+ +
+ +
+

Technischer Kontakt

+ + + +
+ +
+
+
+ +
" id="techcontact-form"> +
+
+
+ + +
+
+
+ +
+
+
+ + +
+
+
+
+ + +
+
+
+ +
+
+
+ + +
+
+
+ +
+
+
+ + +
+
+
+
+ + +
+
+
+ +
+
+
+ + +
+
+
+ +
+
+
+ + +
+
+
+
+ + +
+
+
+ +
+
+
+ + +
+
+
+
+ + +
+
+
+ + +
+
+ +
+
+ +
@@ -822,7 +936,9 @@ console.log("is new"); $('#owner_id').autoComplete('set', null); $('#owner_id').prop('disabled', true); + $('#owner-block').addClass("border border-secondary"); } else { + $('#owner-block').removeClass("border border-secondary"); $('#owner_id').prop('disabled', false); } }); @@ -852,7 +968,9 @@ console.log("billing is new"); $('#billingaddress_id').autoComplete('set', null); $('#billingaddress_id').prop('disabled', true); + $('#billingaddress-block').addClass("border border-secondary"); } else { + $('#billingaddress-block').removeClass("border border-secondary"); $('#billingaddress_id').prop('disabled', false); } }); @@ -862,6 +980,39 @@ $('#billingaddress_id').autoComplete('set', null); } }); + + // techcontact + // rechnungsadresse + techcontact_id && is_object($order->techcontact)): ?> + $('#techcontact_id').autoComplete('set', { value: techcontact_id?>, text: 'techcontact_id) ? str_replace("'", "\\'", str_replace(["\n", "\r"], " ", $order->techcontact->getCompanyOrName()))." (".$order->techcontact->zip." ".$order->techcontact->city.", ".$order->techcontact->street.")" : ""?>'}); + + $('#techcontact_id').autoComplete(); + + + $('#techcontact_id').keydown(function() { + if(event.keyCode == 13) { + event.preventDefault(); + return false; + } + }); + + $('#techcontact_new').change(function() { + if($('#techcontact_new').is(":checked")) { + console.log("billing is new"); + $('#techcontact_id').autoComplete('set', null); + $('#techcontact_id').prop('disabled', true); + $('#techcontact-block').addClass("border border-secondary"); + } else { + $('#techcontact-block').removeClass("border border-secondary"); + $('#techcontact_id').prop('disabled', false); + } + }); + + $('#techcontact_id').on("autocomplete.select", function(evt, item) { + if(item && item.value === 0) { + $('#techcontact_id').autoComplete('set', null); + } + }); /* * autocomplete *******************************/ @@ -935,6 +1086,14 @@ } }); + $('#techcontact_new').change(function() { + if($('#techcontact_new').prop('checked')) { + $('#techcontact-form').show(); + } else { + $('#techcontact-form').hide(); + } + }); + /*$('#owner_id').change(function() { var val = $('#owner_id').val(); @@ -944,7 +1103,7 @@ $('#owner-form').hide(); } });*/ - + /* $('#billingaddress_id').change(function() { var val = $('#billingaddress_id').val(); @@ -954,7 +1113,8 @@ $('#billingaddress-form').hide(); } }); - + */ + $('#order_finished').change(function() { if($('#order_finished').is(":checked")) { $('#finish_date_field').show(); diff --git a/application/Address/Address.php b/application/Address/Address.php index 1db2506d3..29340a0a7 100644 --- a/application/Address/Address.php +++ b/application/Address/Address.php @@ -5,6 +5,7 @@ class Address extends mfBaseModel { private $parent; private $childaddresses; private $links; + private $linked_as; private $types; private $attributes; private $permissions; @@ -129,7 +130,7 @@ class Address extends mfBaseModel { return $spin; } - public function deleteLinks() { + /*public function deleteLinks() { $links = $this->getProperty("links"); //var_dump($links);exit; if(is_array($links) && count($links)) { @@ -141,7 +142,7 @@ class Address extends mfBaseModel { } } } - } + }*/ public function getProperty($name) { if($this->$name == null) { @@ -205,6 +206,18 @@ class Address extends mfBaseModel { return $this->links; } + if($name == "linked_as") { + $linked_as = AddressLinkModel::search(['address_id' => $this->id]); + foreach($linked_as as $link) { + if(!array_key_exists($link->type, $this->linked_as)) { + $this->linked_as[$link->type] = []; + } + $this->linked_as[$link->type][] = $link; + //var_dump($this->links);exit; + } + return $this->linked_as; + } + $classname = ucfirst($name); $idfield = $name."_id"; $this->$name = new $classname($this->$idfield); diff --git a/application/Address/AddressController.php b/application/Address/AddressController.php index affa50a93..adf1ad19b 100644 --- a/application/Address/AddressController.php +++ b/application/Address/AddressController.php @@ -84,13 +84,36 @@ class AddressController extends mfBaseController { protected function addAction() { $this->layout()->setTemplate("Address/Form"); + $this->layout->set("filter", $this->request->filter); + $parents = AddressModel::search(['parent_id' => null]); $this->layout()->set("parents", $parents); } + protected function viewAction() { + $this->layout()->setTemplate("Address/View"); + + $this->layout->set("filter", $this->request->filter); + $this->layout->set("f", $this->request->f); + $this->layout->set("s", $this->request->s); + + $address = new Address($this->request->id); + $this->layout()->set("address", $address); + + if(!$address->id) { + $this->layout()->setFlash("Addresse nicht gefunden", "error"); + $this->redirect("Address"); + } + + } + protected function editAction() { $address = new Address($this->request->id); + $this->layout->set("filter", $this->request->filter); + $this->layout->set("f", $this->request->f); + $this->layout->set("s", $this->request->s); + $this->layout()->set("address", $address); if(!$address->id) { @@ -101,6 +124,27 @@ class AddressController extends mfBaseController { return $this->addAction(); } + protected function deleteLink() { + $id = $this->request->id; + + if(!is_numeric($id) || !$id) { + $this->layout()->setFlash("Addresse nicht gefunden", "error"); + $this->redirect("Address"); + } + + $link = new AddressLink($id); + if(!$link->id) { + $this->layout()->setFlash("Addresse nicht gefunden", "error"); + $this->redirect("Address"); + } + + $address_id = $link->origin_address_id; + $link->delete(); + $this->layout()->setFlash("Verknüpfung erfolgreich entfernt", "success"); + $this->redirect("Address", "edit", ['id' => $address_id]); + + } + protected function saveAction() { $r = $this->request; $id = $r->id; @@ -229,7 +273,13 @@ class AddressController extends mfBaseController { } - $address->deleteLinks(); + //$address->deleteLinks(); + + $existing_links = []; + foreach(AddressLinkModel::search(['origin_address_id', $new_id]) as $elink) { + $existing_links[$elink->address_id] = $elink; + } + //var_dump($r->links);exit; if(is_array($r->links) && count($r->links)) { //var_dump($r->links);exit; @@ -237,17 +287,42 @@ class AddressController extends mfBaseController { if(!$link['type'] || !$link['address_id']) { continue; } + if(array_key_exists($link['address_id'], $existing_links)) { + continue; + } $l = AddressLinkModel::create([ 'origin_address_id' => $new_id, 'type' => $link['type'], 'address_id' => $link['address_id'] ]); $l->save(); + } } + $sq = ""; + $query = []; + if($r->s) { + $query['s'] = $r->s; + } + if($r->filter) { + $query["filter"] = $r->filter; + } + if($r->return != "index") { + $query['id'] = $new_id; + } + + $qs = http_build_query($query); + + $this->layout()->setFlash("Adresse erfolgreich gespeichert.", "success"); - $this->redirect("Address", "Edit", ['id' => $new_id]); + if($r->return == "index") { + $this->redirect("Address", "Index", $qs); + } + if($r->f == "view") { + $this->redirect("Address", "View", $qs); + } + $this->redirect("Address", "Edit", $qs); } diff --git a/application/Address/AddressModel.php b/application/Address/AddressModel.php index 079ab5609..cfa87d0fe 100644 --- a/application/Address/AddressModel.php +++ b/application/Address/AddressModel.php @@ -346,13 +346,13 @@ class AddressModel { $where .= " AND Address.create_by IN (". implode(",",$create_by).")"; } } - + /* if(array_key_exists("parents_only", $filter)) { $po = $filter['parents_only']; if($po) { $where .= " AND parent_id IS NULL"; } - } + }*/ //var_dump($filter, $where);exit; return $where; } diff --git a/application/AddressLink/AddressLinkModel.php b/application/AddressLink/AddressLinkModel.php index a91f55612..45c95b4fd 100644 --- a/application/AddressLink/AddressLinkModel.php +++ b/application/AddressLink/AddressLinkModel.php @@ -36,7 +36,8 @@ class AddressLinkModel { $db = FronkDB::singleton(); $where = self::getSqlFilter($filter); - $res = $db->select("AddressLink", "*", "$where ORDER BY address_id,`create`,origin_address_idLIMIT 1"); + + $res = $db->select("AddressLink", "*", "$where ORDER BY address_id,`create`,origin_address_id LIMIT 1"); if($db->num_rows($res)) { $data = $db->fetch_object($res); $item = new AddressLink($data); @@ -125,6 +126,23 @@ class AddressLinkModel { } } + if(array_key_exists("type", $filter)) { + switch($filter['type']) { + case "employee": + $where .= " AND type='employee'"; + break; + case "billing": + $where .= " AND type='billing'"; + break; + case "contact": + $where .= " AND type='contact'"; + break; + case "techcontact": + $where .= " AND type='techcontact'"; + break; + } + } + return $where; } diff --git a/application/Order/Order.php b/application/Order/Order.php index a9f170c70..f084cb28b 100644 --- a/application/Order/Order.php +++ b/application/Order/Order.php @@ -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; diff --git a/application/Order/OrderController.php b/application/Order/OrderController.php index 878adc315..2368727d2 100644 --- a/application/Order/OrderController.php +++ b/application/Order/OrderController.php @@ -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); } } diff --git a/application/Order/OrderModel.php b/application/Order/OrderModel.php index fec1d3ba5..9a383529c 100644 --- a/application/Order/OrderModel.php +++ b/application/Order/OrderModel.php @@ -3,6 +3,7 @@ class OrderModel { public $owner_id; public $billingaddress_id; + public $techcontact_id; public $upgrade; public $partner_number; public $order_date; diff --git a/public/assets/css/thetool.css b/public/assets/css/thetool.css index 98c331638..3722094ce 100644 --- a/public/assets/css/thetool.css +++ b/public/assets/css/thetool.css @@ -17,6 +17,13 @@ background-color: rgba(0, 0, 0, 0.075); } +.table.view-table th { + text-align:right; +} +.table.view-table td { + text-align:left; +} + .btn-primary { color: #fff; background-color: #0d6efd;