Overhauled Address linking

This commit is contained in:
Frank Schubert
2022-06-29 17:16:14 +02:00
parent bbfc6c6eb5
commit 2d09924372
12 changed files with 637 additions and 74 deletions

View File

@@ -1,4 +1,17 @@
<?php //var_dump($address->parent->types);exit;?>
<?php
$urlfilter = [];
if($s) {
$urlfilter['s'] = $s;
}
if($f) {
$urlfilter['f'] = $f;
}
if(is_array($filter) && count($filter)) {
$urlfilter["filter"] = $filter;
}
$posturl = self::getUrl("Address", "save", $urlfilter);
?>
<?php include(realpath(dirname(__FILE__)."/../../$mfLayoutPackage")."/header.php"); ?>
<!-- start page title -->
@@ -7,8 +20,11 @@
<div class="page-title-box">
<div class="page-title-right">
<ol class="breadcrumb m-0">
<li class="breadcrumb-item"><a href="javascript: void(0);"><?=MFAPPNAME_SLUG?></a></li>
<li class="breadcrumb-item"><a href="javascript: void(0);">Personen & Firmen</a></li>
<li class="breadcrumb-item"><a href="<?=self::getUrl("Dashboard")?>"><?=MFAPPNAME_SLUG?></a></li>
<li class="breadcrumb-item"><a href="<?=self::getUrl("Address")?>">Personen & Firmen</a></li>
<?php if($address->id): ?>
<li class="breadcrumb-item"><a href="<?=self::getUrl("Address", "View", ['id' => $address->id])?>"><?=$address->getCompanyOrName()?> [<?=$address->customer_number?>]</a></li>
<?php endif; ?>
<li class="breadcrumb-item active"><?=($address->id) ? "bearbeiten" : "Neu" ?></li>
</ol>
</div>
@@ -25,24 +41,12 @@
<div class="card-body">
<h4><?=($address->id) ? "Person/Firma bearbeiten" : "Neue Person/Firma"?></h4>
<form class="form-horizontal" method="post" name="addressForm" id="addressForm" action="<?=self::getUrl("Address", "save")?>">
<form class="form-horizontal" method="post" name="addressForm" id="addressForm" action="<?=$posturl?>">
<div class="card">
<div class="card-body">
<input type="hidden" name="id" value="<?=$address->id?>" />
<div class="form-group row">
<label class="col-lg-2 col-form-label" for="parent_id">Zugeordnet zu</label>
<div class="col-lg-10">
<select class="select2 form-control " name="parent_id" id="parent_id">
<option></option>
<?php foreach($parents as $parent): if($parent->id == $address->id) continue; ?>
<option value="<?=$parent->id?>" <?=($address->parent_id == $parent->id) ? "selected='selected'" : ""?>><?=($parent->company) ? $parent->company : $parent->getFullName()?></option>
<?php endforeach; ?>
</select>
</div>
</div>
<div class="form-group row">
<label class="col-lg-2 col-form-label" for="customer_number">Kundennummer</label>
<div class="col-lg-10">
@@ -156,23 +160,9 @@
<label class="col-lg-2 col-form-label" for="addresstypes">Rolle</label>
<div class="col-lg-10">
<select class="select2 form-control select2-multiple" name="addresstypes[]" id="addresstypes" multiple="multiple" data-placeholder="Choose ...">
<option value="systemowner" <?=(array_key_exists("systemowner", $address->types)) ? "selected='selected'" : ""?>><?=__("systemowner")?></option>
<option value="productowner" <?=(array_key_exists("productowner", $address->types)) ? "selected='selected'" : ""?>><?=__("productowner")?></option>
<option value="netowner" <?=(array_key_exists("netowner", $address->types)) ? "selected='selected'" : "netowner"?>><?=__("netowner")?></option>
<option value="salespartner" <?=(array_key_exists("salespartner", $address->types)) ? "selected='selected'" : "salespartner"?>><?=__("salespartner")?></option>
<option value="pipeworker" <?=(array_key_exists("pipeworker", $address->types)) ? "selected='selected'" : "pipeworker"?>><?=__("pipeworker")?></option>
<option value="lineworker" <?=(array_key_exists("lineworker", $address->types)) ? "selected='selected'" : "lineworker"?>><?=__("lineworker")?></option>
<option value="pipeplanner" <?=(array_key_exists("pipeplanner", $address->types)) ? "selected='selected'" : "pipeplanner"?>><?=__("pipeplanner")?></option>
<option value="lineplanner" <?=(array_key_exists("lineplanner", $address->types)) ? "selected='selected'" : "lineplanner"?>><?=__("lineplanner")?></option>
<option value="netoperator" <?=(array_key_exists("netoperator", $address->types)) ? "selected='selected'" : "netoperator"?>><?=__("netoperator")?></option>
<option value="support" <?=(array_key_exists("support", $address->types)) ? "selected='selected'" : "support"?>><?=__("support")?></option>
<option value="billing" <?=(array_key_exists("billing", $address->types)) ? "selected='selected'" : ""?>><?=__("billing")?></option>
<option value="employee" <?=(array_key_exists("employee", $address->types)) ? "selected='selected'" : ""?>><?=__("employee")?></option>
<option value="customer" <?=(array_key_exists("customer", $address->types)) ? "selected='selected'" : ""?>><?=__("customer")?></option>
<option value="supplier" <?=(array_key_exists("supplier", $address->types)) ? "selected='selected'" : ""?>><?=__("supplier")?></option>
<option value="contact" <?=(array_key_exists("contact", $address->types)) ? "selected='selected'" : ""?>><?=__("contact")?></option>
<option value="techcontact" <?=(array_key_exists("techcontact", $address->types)) ? "selected='selected'" : ""?>><?=__("techcontact")?></option>
<?php foreach(TT_ROLES as $role): ?>
<option value="<?=$role?>" <?=(array_key_exists($role, $address->types)) ? "selected='selected'" : ""?>><?=__($role)?></option>
<?php endforeach; ?>
</select>
</div>
</div>
@@ -256,11 +246,11 @@
</div>
</div>
<h4>Verknüpfte Adressen</h4>
<h4>Verknüpfungen</h4>
<div class="card">
<div class="card-body" id="link-container">
<table class="table table-striped table-sm">
<table class="table table-striped table-sm table-bordered">
<tr>
<th>Typ</th>
<th>Firma</th>
@@ -271,20 +261,20 @@
<th>Email</th>
<th></th>
</tr>
<?php foreach(['techcontact'] as $type): ?>
<?php foreach(TT_ADDRESS_LINK_TYPES as $type): ?>
<?php if(array_key_exists($type, $address->links)): ?>
<?php foreach($address->links[$type] as $addr): ?>
<?php foreach($address->links[$type] as $link): ?>
<tr>
<td class="font-weight-bold"><?=__($type)?></td>
<td><?=$addr->address->company?></td>
<td><?=$addr->address->firstname?></td>
<td><?=$addr->address->lastname?></td>
<td><?=$addr->address->phone?></td>
<td><?=$addr->address->mobile?></td>
<td><?=$addr->address->email?></td>
<td><a href="<?=self::getUrl("Address", "view", ["id" => $link->address_id])?>" target="_blank"><?=$link->address->company?></a></td>
<td><a href="<?=self::getUrl("Address", "view", ["id" => $link->address_id])?>" target="_blank"><?=$link->address->firstname?></a></td>
<td><a href="<?=self::getUrl("Address", "view", ["id" => $link->address_id])?>" target="_blank"><?=$link->address->lastname?></a></td>
<td><?=$link->address->phone?></td>
<td><?=$link->address->mobile?></td>
<td><?=$link->address->email?></td>
<td>
<a class="mr-2" href="<?=self::getUrl("Address", "edit", ["id" => $address->id])?>"><i class="far fa-edit" title="Bearbeiten"></i></a>
<a href="<?=self::getUrl("Address", "deleteLink", ["id" => $address->id])?>" onclick="if(!confirm('Verknüpgung wirklich löschen?')) return false;" class="text-danger" title="Verknüpfung löschen"><i class="fas fa-xmark-large"></i></a>
<a class="mr-2" href="<?=self::getUrl("Address", "view", ["id" => $link->address_id])?>" target="_blank"><i class="far fa-eyes" title="Anzeigen"></i></a>
<a href="<?=self::getUrl("Address", "deleteLink", ["id" => $link->id])?>" onclick="if(!confirm('Verknüpfung wirklich entfernen?')) return false;" class="text-danger" title="Verknüpfung entfernen"><i class="fas fa-xmark-large"></i></a>
</td>
</tr>
<?php endforeach; ?>
@@ -303,10 +293,12 @@
<div class="input-group mb-3">
<div class="input-group-prepend">
<select class="form-control" name="links[<?=$linknum?>][type]">
<option value="techcontact">Technischer Kontakt</option>
<?php foreach(TT_ADDRESS_LINK_TYPES as $type): ?>
<option value="<?=$type?>"><?=__($type)?></option>
<?php endforeach; ?>
</select>
</div>
<select class="form-control basicAutoComplete link-autocomplete" autocomplete="off" name="links[<?=$linknum?>][address_id]" id="links_<?=$linknum?>_address_id" data-linknum="<?=$linknum?>" data-url="<?=self::getUrl('Address','api')?>?do=findAddress&autocomplete=1&role=techcontact" placeholder="Name, Kundennummer, ID" data-noresults-text="Keine Suchergebnisse">
<select class="form-control basicAutoComplete link-autocomplete" autocomplete="off" name="links[<?=$linknum?>][address_id]" id="links_<?=$linknum?>_address_id" data-linknum="<?=$linknum?>" data-url="<?=self::getUrl('Address','api')?>?do=findAddress&autocomplete=1" placeholder="Name, Kundennummer, ID" data-noresults-text="Keine Suchergebnisse">
<option></option>
</select>
@@ -321,6 +313,25 @@
</div>
<?php if(is_array($address->linked_as) && count($address->linked_as)): ?>
<h4>Verknüpft als</h4>
<div class="card">
<div class="card-body" id="link-container">
<table class="table-sm table-striped">
<?php foreach(TT_ADDRESS_LINK_TYPES as $type): ?>
<?php if(array_key_exists($type, $address->linked_as)): ?>
<?php foreach($address->linked_as[$type] as $link): ?>
<tr>
<td><?=__($type)?> für:</td>
<td><a href="<?=self::getUrl("Address", "view", ['id' => $link->origin_address_id])?>" target="_blank"><?=$link->origin->getCompanyOrName()?><?=($link->origin->customer_number) ? " [".$link->origin->customer_number."]" : ""?></a></td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
<?php endforeach; ?>
</table>
</div>
</div>
<?php endif; ?>
<div class="card">
<div class="card-body">
<div class="form-group row">
@@ -337,7 +348,9 @@
<div class="form-group row">
<label class="col-lg-2"></label>
<div class="col-lg-10">
<button type="submit" class="btn btn-primary">Speichern</button> <span id="error" class="hidden ml-2 alert alert-danger text-danger">Fehler: Ungültige IBAN</span>
<button type="submit" class="btn btn-primary mr-1">Speichern</button>
<button type="submit" name="return" value="index" class="btn btn-primary">Speichern und zur Übersicht</button>
<span id="error" class="hidden ml-2 alert alert-danger text-danger">Fehler: Ungültige IBAN</span>
</div>
</div>

View File

@@ -145,18 +145,6 @@
<div class="col-12">
<div class="float-left">
<h4 class="header-title">Liste aller Personen & Firmen</h4>
<?php if(is_array($filter) && count($filter)): ?>
<p class="sub-header">
<?php if(array_key_exists("parents_only", $filter) && $filter['parents_only'] == 0): ?>
Zeige alle Personen und Firmen<br />
<?php else: ?>
Zeige nur Personen und Firmen ohne Zugehörigkeit an. <a href="<?=self::getUrl("Address", "Index", ['filter' => array_merge($filter, ["parents_only" => 0])])?>">Alle anzeigen</a><br />
<?php endif; ?>
<?php if(is_array($filter['addresstype']) && count($filter['addresstype'])): ?>
Gefiltert nach Rolle: <?=implode(", ", $types)?><br />
<?php endif; ?>
</p>
<?php endif; ?>
</div>
<div class="float-right">
<a class="btn btn-primary" href="<?=self::getUrl("Address", "add")?>"><i class="fas fa-plus"></i> Neue Person/Firma anlegen</a>
@@ -206,8 +194,9 @@
<td><?=$address->email?></td>
<td style="text-align: left; letter-spacing: 4px; font-size: 1.1em;">
<a href="<?=self::getUrl("User", "Index", ["filter" => ["address_id" => $address->id]])?>" title="Benutzer anzeigen"><i class="fas fa-users"></i></a>
<a href="<?=self::getUrl("Address", "edit", ["id" => $address->id])?>"><i class="far fa-edit" title="Bearbeiten"></i></a>
<a href="<?=self::getUrl("Address", "delete", ["id" => $address->id])?>" onclick="if(!confirm('Person/Firma wirklich löschen?')) return false;" class="text-danger" title="Löschen"><i class="fas fa-trash"></i></a>
<a href="<?=self::getUrl("Address", "view", ["id" => $address->id, 'filter' => $filter, 's' => $pagination['start']])?>"><i class="far fa-eyes" title="Anzeigen"></i></a>
<a href="<?=self::getUrl("Address", "edit", ["id" => $address->id, 's' => $pagination['start']])?>"><i class="far fa-edit" title="Bearbeiten"></i></a>
<a href="<?=self::getUrl("Address", "delete", ["id" => $address->id, 's' => $pagination['start']])?>" onclick="if(!confirm('Person/Firma wirklich löschen?')) return false;" class="text-danger" title="Löschen"><i class="fas fa-trash"></i></a>
</td>
</tr>
<?php endforeach; ?>

View File

@@ -0,0 +1,195 @@
<?php include(realpath(dirname(__FILE__)."/../../$mfLayoutPackage")."/header.php"); ?>
<!-- start page title -->
<div class="row">
<div class="col-12">
<div class="page-title-box">
<div class="page-title-right">
<ol class="breadcrumb m-0">
<li class="breadcrumb-item"><a href="javascript: void(0);"><?=MFAPPNAME_SLUG?></a></li>
<li class="breadcrumb-item"><a href="javascript: void(0);">Personen & Firmen</a></li>
<li class="breadcrumb-item active"><?=$address->getCompanyOrName()?> [<?=$address->customer_number?>]</li>
</ol>
</div>
<h4 class="page-title">Personen & Firmen</h4>
</div>
</div>
</div>
<!-- end page title -->
<div class="row">
<div class="col-lg-12">
<div class="card">
<div class="card-body">
<a href="<?=self::getUrl("Address","Index", ['filter' => $filter, 's' => $s])?>" class="btn btn-secondary mr-1"><i class="fas fa-list"></i> Zurück zur Übersicht</a>
<a href="<?=self::getUrl("Address","edit", ['id' => $address->id, 'filter' => $filter, 's' => $s, 'f' => "view"])?>" class="btn btn-outline-success"><i class="fas fa-edit"></i> Adresse bearbeiten</a>
</div>
</div>
<div class="card">
<div class="card-body">
<h4>Person/Firma</h4>
<table class="table table-sm table-striped view-table">
<tr>
<th>Kundennummer</th>
<td><?=$address->customer_number?></td>
</tr><tr>
<th>Firmenname</th>
<td><?=nl2br($address->company)?></td>
</tr><tr>
<th>Vorname</th>
<td><?=$address->firstname?></td>
</tr><tr>
<th>Nachname</th>
<td><?=$address->lastname?></td>
</tr><tr>
<th>Straße</th>
<td><?=$address->street?></td>
</tr><tr>
<th>PLZ / Ort</th>
<td><?=$address->zip?> <?=$address->city?></td>
</tr><tr>
<th>Land</th>
<td><?=$address->country?></td>
</tr><tr>
<th>Telefon</th>
<td><?=$address->phone?></td>
</tr><tr>
<th>Mobil</th>
<td><?=$address->mobile?></td>
</tr><tr>
<th>Fax</th>
<td><?=$address->fax?></td>
</tr><tr>
<th>Email</th>
<td><?=$address->email?></td>
</tr><tr>
<th></th>
<td></td>
</tr><tr>
<th>Service PIN</th>
<td><?=$address->spin?></td>
</tr><tr>
<th>Einwilligungen</th>
<td>
<p><i class="mr-1 fas <?=($address->allow_contact) ? "fa-check text-success" : "fa-xmark-large text-danger"?>"></i> Informationen per Post/Email/Telefon</p>
<p><i class="mr-1 fas <?=($address->allow_spin) ? "fa-check text-success" : "fa-xmark-large text-danger"?>"></i>Auskunft mit Service PIN</p>
</td>
</tr><tr>
<th>Rollen</th>
<td>
<?php if(is_array($address->types) && count($address->types)): ?>
<?php foreach(TT_ROLES as $role): ?>
<ul>
<?php if(array_key_exists($role, $address->types)): ?>
<li><?=__($role)?></li>
<?php endif; ?>
</ul>
<?php endforeach; ?>
<?php endif; ?>
</td>
</tr><tr>
<td colspan="2"><h4>Verrechnungsdaten</h4></td>
</tr><tr>
<th>UID</th>
<td><?=$address->uid?></td>
</tr><tr>
<th>Verrechnungsart</th>
<td><?=($address->billing_type == "sepa") ? "SEPA Bankeinzug" : "Rechnung"?></td>
</tr><tr>
<th>Rechnungsversand</th>
<td><?=($address->billing_delivery == "paper") ? "POST" : "Email"?></td>
</tr><tr>
<th>Kreditinstitut</th>
<td><?=$address->bank_account_bank?></td>
</tr><tr>
<th>Kontoinhaber</th>
<td><?=$address->bank_account_owner?></td>
</tr><tr>
<th>IBAN</th>
<td><?=$address->bank_account_iban?></td>
</tr><tr>
<th>BIC</th>
<td><?=$address->bank_account_bic?></td>
</tr><tr>
<td colspan="2"><h4>Zusatzdaten</h4></td>
</tr><tr>
<th>RTR Code</th>
<td><?=$address->attributes['rtrcode']->value?></td>
</tr>
</table>
<h4>Verknüpfungen</h4>
<?php if(is_array($address->links) && count($address->links)): ?>
<div class="card">
<div class="card-body" id="link-container">
<table class="table table-striped table-sm table-bordered">
<tr>
<th>Typ</th>
<th>Firma</th>
<th>Vorname</th>
<th>Nachname</th>
<th>Telefon</th>
<th>Mobil</th>
<th>Email</th>
<th></th>
</tr>
<?php foreach(TT_ADDRESS_LINK_TYPES as $type): ?>
<?php if(array_key_exists($type, $address->links)): ?>
<?php foreach($address->links[$type] as $link): ?>
<tr>
<td class="font-weight-bold"><?=__($type)?></td>
<td><a href="<?=self::getUrl("Address", "view", ["id" => $link->address_id])?>"><?=$link->address->company?></a></td>
<td><a href="<?=self::getUrl("Address", "view", ["id" => $link->address_id])?>"><?=$link->address->firstname?></a></td>
<td><?=$link->address->lastname?></td>
<td><?=$link->address->phone?></td>
<td><?=$link->address->mobile?></td>
<td><?=$link->address->email?></td>
<td>
<a class="mr-2" href="<?=self::getUrl("Address", "view", ["id" => $link->address_id])?>"><i class="far fa-eyes" title="Anzeigen"></i></a>
</td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
<?php endforeach; ?>
</table>
</div>
</div>
<?php endif; ?>
<?php if(is_array($address->linked_as) && count($address->linked_as)): ?>
<h4>Verknüpft als</h4>
<div class="card">
<div class="card-body" id="link-container">
<table class="table-sm table-striped">
<?php foreach(TT_ADDRESS_LINK_TYPES as $type): ?>
<?php if(array_key_exists($type, $address->linked_as)): ?>
<?php foreach($address->linked_as[$type] as $link): ?>
<tr>
<td><?=__($type)?> für:</td>
<td><a href="<?=self::getUrl("Address", "view", ['id' => $link->origin_address_id])?>"><?=$link->origin->getCompanyOrName()?><?=($link->origin->customer_number) ? " [".$link->origin->customer_number."]" : ""?></a></td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
<?php endforeach; ?>
</table>
</div>
</div>
<?php endif; ?>
</div>
</div>
<div class="card">
<div class="card-body">
<a href="<?=self::getUrl("Address","Index", ['filter' => $filter, 's' => $s])?>" class="btn btn-secondary mr-1"><i class="fas fa-list"></i> Zurück zur Übersicht</a>
<a href="<?=self::getUrl("Address","edit", ['id' => $address->id, 'filter' => $filter, 's' => $s, 'f' => "view"])?>" class="btn btn-outline-success"><i class="fas fa-edit"></i> Adresse bearbeiten</a>
</div>
</div>
</div>
</div>
<?php include(realpath(dirname(__FILE__)."/../../$mfLayoutPackage")."/footer.php"); ?>

View File

@@ -52,7 +52,7 @@
<input type="hidden" name="id" value="<?=$order->id?>" />
<div class="row">
<div class="col-lg-6">
<div class="col-lg-6" id="owner-block">
<div class="form-group row">
@@ -172,7 +172,7 @@
</div>
</div>
<div class="col-lg-6">
<div class="col-lg-6" id="billingaddress-block">
<div class="form-group row">
@@ -292,6 +292,120 @@
</div>
</div>
<div class="row">
<div class="col-lg-6" id="techcontact-block">
<div class="form-group row">
<div class="col-lg-12 mb-2">
<h4>Technischer Kontakt</h4>
<select class="form-control basicAutoComplete" autocomplete="off" name="techcontact_id" id="techcontact_id" data-url="<?=self::getUrl('Address','api')?>?do=findAddress&autocomplete=1" placeholder="Tippen zum Suchen... (Bestandskunden)" data-noresults-text="Keine Suchergebnisse">
<option></option>
</select>
</div>
<div class="col-lg-12 mb-2">
<div class="mt-2"><label><input type="checkbox" name="new_techcontact" id="techcontact_new" <?=($order->new_techcontact) ? "checked='checked'" : ""?> /> Neuen technischen Kontakt anlegen</label></div>
</div>
<div class="col-lg-12 <?=($order->new_techcontact) ? "" : "hidden"?>" id="techcontact-form">
<div class="row">
<div class="col-lg-12">
<div class="form-group">
<label class="form-label" for="techcontact_company">Firmenname</label>
<textarea class="form-control" name="techcontact_company" id="techcontact_company"><?=$order->techcontact_company?></textarea>
</div>
</div>
</div>
<div class="row">
<div class="col-lg-6">
<div class="form-group">
<label class="form-label" for="techcontact_firstname">Vorname</label>
<input type="text" class="form-control" name="techcontact_firstname" id="techcontact_firstname" value="<?=$order->techcontact_firstname?>" />
</div>
</div>
<div class="col-lg-6">
<div class="form-group">
<label class="form-label" for="techcontact_lastname">Nachname</label>
<input type="text" class="form-control" name="techcontact_lastname" id="techcontact_lastname" value="<?=$order->techcontact_lastname?>" />
</div>
</div>
</div>
<div class="row">
<div class="col-lg-12">
<div class="form-group">
<label class="form-label" for="techcontact_street">Straße</label>
<input type="text" class="form-control" name="techcontact_street" id="techcontact_street" value="<?=$order->techcontact_street?>" />
</div>
</div>
</div>
<div class="row">
<div class="col-lg-3">
<div class="form-group">
<label class="form-label" for="techcontact_zip">Postleitzahl</label>
<input type="text" class="form-control" name="techcontact_zip" id="techcontact_zip" value="<?=$order->techcontact_zip?>" />
</div>
</div>
<div class="col-lg-9">
<div class="form-group">
<label class="form-label" for="techcontact_city">Ort</label>
<input type="text" class="form-control" name="techcontact_city" id="techcontact_city" value="<?=$order->techcontact_city?>" />
</div>
</div>
</div>
<div class="row">
<div class="col-lg-12">
<div class="form-group">
<label class="form-label" for="techcontact_country">Land</label>
<input type="text" class="form-control" name="techcontact_country" id="techcontact_country" value="<?=$order->techcontact_country?>" />
</div>
</div>
</div>
<div class="row">
<div class="col-lg-6">
<div class="form-group">
<label class="form-label" for="techcontact_phone">Telefon</label>
<input type="text" class="form-control" name="techcontact_phone" id="techcontact_phone" value="<?=$order->techcontact_phone?>" />
</div>
</div>
<div class="col-lg-6">
<div class="form-group">
<label class="form-label" for="techcontact_mobile">Mobil</label>
<input type="text" class="form-control" name="techcontact_mobile" id="techcontact_mobile" value="<?=$order->techcontact_mobile?>" />
</div>
</div>
</div>
<div class="row">
<div class="col-lg-6">
<div class="form-group">
<label class="form-label" for="techcontact_email">Emailadresse</label>
<input type="text" class="form-control" name="techcontact_email" id="techcontact_email" value="<?=$order->techcontact_email?>" />
</div>
</div>
<div class="col-lg-6">
<div class="form-group">
<label class="form-label" for="techcontact_fax">Fax</label>
<input type="text" class="form-control" name="techcontact_fax" id="techcontact_fax" value="<?=$order->techcontact_fax?>" />
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<hr />
<div class="form-group row">
@@ -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
<?php if($order->techcontact_id && is_object($order->techcontact)): ?>
$('#techcontact_id').autoComplete('set', { value: <?=$order->techcontact_id?>, text: '<?=($order->techcontact_id) ? str_replace("'", "\\'", str_replace(["\n", "\r"], " ", $order->techcontact->getCompanyOrName()))." (".$order->techcontact->zip." ".$order->techcontact->city.", ".$order->techcontact->street.")" : ""?>'});
<?php else: ?>
$('#techcontact_id').autoComplete();
<?php endif; ?>
$('#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();

View File

@@ -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);

View File

@@ -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);
}

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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;

View File

@@ -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);
}
}

View File

@@ -3,6 +3,7 @@
class OrderModel {
public $owner_id;
public $billingaddress_id;
public $techcontact_id;
public $upgrade;
public $partner_number;
public $order_date;

View File

@@ -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;