527 lines
23 KiB
PHP
527 lines
23 KiB
PHP
<?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 -->
|
|
<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="<?=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>
|
|
<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">
|
|
<h4><?=($address->id) ? "Person/Firma bearbeiten" : "Neue Person/Firma"?></h4>
|
|
|
|
<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="customer_number">Kundennummer</label>
|
|
<div class="col-lg-10">
|
|
<input type="text" class="form-control" name="customer_number" id="customer_number" value="<?=$address->customer_number?>" disabled="disabled" />
|
|
</div>
|
|
</div>
|
|
<div class="form-group row">
|
|
<label class="col-lg-2 col-form-label" for="company">Firmenname</label>
|
|
<div class="col-lg-10">
|
|
<textarea name="company" id="company" class="form-control" rows="2"><?=$address->company?></textarea>
|
|
</div>
|
|
</div>
|
|
<div class="form-group row">
|
|
<label class="col-lg-2 col-form-label" for="firstname">Vorname</label>
|
|
<div class="col-lg-10">
|
|
<input type="text" class="form-control" name="firstname" id="firstname" value="<?=$address->firstname?>">
|
|
</div>
|
|
</div>
|
|
<div class="form-group row">
|
|
<label class="col-lg-2 col-form-label" for="lastname">Nachname</label>
|
|
<div class="col-lg-10">
|
|
<input type="text" class="form-control" name="lastname" id="lastname" value="<?=$address->lastname?>">
|
|
</div>
|
|
</div>
|
|
<div class="form-group row">
|
|
<label class="col-lg-2 col-form-label" for="street">Strasse</label>
|
|
<div class="col-lg-10">
|
|
<input type="text" class="form-control" name="street" id="street" value="<?=$address->street?>">
|
|
</div>
|
|
</div>
|
|
<div class="form-group row">
|
|
<label class="col-lg-2 col-form-label" for="zip">PLZ / Ort</label>
|
|
<div class="col-lg-10">
|
|
<div class="row">
|
|
<div class="col-md-4">
|
|
<input type="text" class="form-control" name="zip" id="zip" placeholder="PLZ" value="<?=$address->zip?>">
|
|
</div>
|
|
<div class="col-md-8">
|
|
<input type="text" class="form-control" name="city" id="city" placeholder="Ort" value="<?=$address->city?>">
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="form-group row">
|
|
<label class="col-lg-2 col-form-label" for="country">Land</label>
|
|
<div class="col-lg-10">
|
|
<input type="text" class="form-control" name="country" id="country" value="<?=$address->country?>">
|
|
</div>
|
|
</div>
|
|
<div class="form-group row">
|
|
<label class="col-lg-2 col-form-label" for="phone">Telefon</label>
|
|
<div class="col-lg-10">
|
|
<input type="tel" class="form-control" name="phone" id="phone" value="<?=$address->phone?>">
|
|
</div>
|
|
</div>
|
|
<div class="form-group row">
|
|
<label class="col-lg-2 col-form-label" for="mobile">Mobil</label>
|
|
<div class="col-lg-10">
|
|
<input type="tel" class="form-control" name="mobile" id="mobile" value="<?=$address->mobile?>">
|
|
</div>
|
|
</div>
|
|
<div class="form-group row">
|
|
<label class="col-lg-2 col-form-label" for="fax">Fax</label>
|
|
<div class="col-lg-10">
|
|
<input type="tel" class="form-control" name="fax" id="fax" value="<?=$address->fax?>">
|
|
</div>
|
|
</div>
|
|
<div class="form-group row">
|
|
<label class="col-lg-2 col-form-label" for="email">Email</label>
|
|
<div class="col-lg-10">
|
|
<input type="email" class="form-control" name="email" id="email" value="<?=$address->email?>">
|
|
</div>
|
|
</div>
|
|
|
|
|
|
</div>
|
|
</div>
|
|
|
|
<div class="card">
|
|
<div class="card-body">
|
|
<div class="form-group row">
|
|
<label class="col-lg-2 col-form-label" for="spin">Service PIN</label>
|
|
<div class="col-lg-10">
|
|
<input type="spin" class="form-control" name="spin" id="spin" value="<?=$address->spin?>" disabled="disabled">
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<h4>Einwilligungen</h4>
|
|
<div class="card">
|
|
<div class="card-body">
|
|
<div class="form-group row">
|
|
<div class="col-lg-2"></div>
|
|
<div class="col-lg-10">
|
|
<label class="form-check-label"><input type="checkbox" class="form-check-input" name="allow_contact" id="allow_contact" <?=($address->allow_contact) ? "checked='checked'" : ""?> /> Informationen per Post/Email/Telefon</label>
|
|
</div>
|
|
</div>
|
|
<div class="form-group row">
|
|
<div class="col-lg-2"></div>
|
|
<div class="col-lg-10">
|
|
<label class="form-check-label"><input type="checkbox" class="form-check-input" name="allow_spin" id="allow_spin" <?=($address->allow_spin) ? "checked='checked'" : ""?> /> Auskunft mit Service PIN</label>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="card">
|
|
<div class="card-body">
|
|
<div class="form-group row">
|
|
<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 ...">
|
|
<?php foreach(TT_ROLES as $role): ?>
|
|
<option value="<?=$role?>" <?=(is_array($address->types) && array_key_exists($role, $address->types)) ? "selected='selected'" : ""?>><?=__($role)?></option>
|
|
<?php endforeach; ?>
|
|
</select>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
|
|
<h4>Verrechnungsdaten</h4>
|
|
<div class="card">
|
|
<div class="card-body">
|
|
<div class="form-group row">
|
|
<label class="col-lg-2 col-form-label" for="uid">UID</label>
|
|
<div class="col-lg-10">
|
|
<input type="text" class="form-control" name="uid" id="uid" value="<?=$address->uid?>">
|
|
</div>
|
|
</div>
|
|
|
|
<div class="form-group row">
|
|
<label class="col-lg-2 col-form-label" for="billing_type">Verrechnungsart</label>
|
|
<div class="col-lg-10">
|
|
<select class="form-control" name="billing_type" id="billing_type">
|
|
<option value="invoice" <?=($address->billing_type == "invoice") ? "selected='selected'" : ""?>>Rechnung</option>
|
|
<option value="sepa" <?=($address->billing_type == "sepa") ? "selected='selected'" : ""?>>SEPA Bankeinzug</option>
|
|
</select>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="form-group row">
|
|
<label class="col-lg-2 col-form-label" for="billing_delivery">Rechnungsversand</label>
|
|
<div class="col-lg-10">
|
|
<select class="form-control" name="billing_delivery" id="billing_delivery">
|
|
<option value="email" <?=($address->billing_delivery == "email") ? "selected='selected'" : ""?>>Email</option>
|
|
<option value="paper" <?=($address->billing_delivery == "paper") ? "selected='selected'" : ""?>>Post</option>
|
|
</select>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="form-group row">
|
|
<label class="col-lg-2 col-form-label" for="bank_account_bank">Kreditinstitut</label>
|
|
<div class="col-lg-10">
|
|
<input type="text" class="form-control" name="bank_account_bank" id="bank_account_bank" value="<?=$address->bank_account_bank?>" />
|
|
</div>
|
|
</div>
|
|
|
|
<div class="form-group row">
|
|
<label class="col-lg-2 col-form-label" for="bank_account_owner">Kontoinhaber</label>
|
|
<div class="col-lg-10">
|
|
<input type="text" class="form-control" name="bank_account_owner" id="bank_account_owner" value="<?=$address->bank_account_owner?>" />
|
|
</div>
|
|
</div>
|
|
|
|
<div class="form-group row">
|
|
<label class="col-lg-2 col-form-label" for="bank_account_iban">IBAN</label>
|
|
<div class="col-lg-10">
|
|
<input type="text" class="form-control" name="bank_account_iban" id="bank_account_iban" value="<?=$address->bank_account_iban?>" />
|
|
<small id="iban_error" class="hidden">IBAN ungültig!</small>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="form-group row">
|
|
<label class="col-lg-2 col-form-label" for="bank_account_bic">BIC</label>
|
|
<div class="col-lg-10">
|
|
<input type="text" class="form-control" name="bank_account_bic" id="bank_account_bic" value="<?=$address->bank_account_bic?>" />
|
|
</div>
|
|
</div>
|
|
|
|
|
|
</div>
|
|
</div>
|
|
|
|
|
|
<h4>Zusatzdaten</h4>
|
|
<div class="card">
|
|
<div class="card-body">
|
|
<div class="form-group row">
|
|
<label class="col-lg-2 col-form-label" for="rtrcode">RTR Betreiber ID</label>
|
|
<div class="col-lg-10">
|
|
<input class="form-control" name="attributes[rtrcode]" id="rtrcode" value="<?=$address->attributes['rtrcode']->value?>">
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<h4>Verknüpfungen</h4>
|
|
<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(is_array($address->links) && count($address->links) && 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])?>" 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", "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; ?>
|
|
|
|
<?php endif; ?>
|
|
|
|
<?php endforeach; ?>
|
|
</table>
|
|
|
|
<?php $linknum = 1; ?>
|
|
|
|
<h5>Neue Verknüpfung</h5>
|
|
<div class="form-group row" id="link-<?=$linknum?>">
|
|
<div class="col-lg-2"></div>
|
|
<div class="col-lg-6">
|
|
<div class="input-group mb-3">
|
|
<div class="input-group-prepend">
|
|
<select class="form-control" name="links[<?=$linknum?>][type]">
|
|
<?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" placeholder="Name, Kundennummer, ID" data-noresults-text="Keine Suchergebnisse">
|
|
<option></option>
|
|
</select>
|
|
|
|
<div class="input-group-append">
|
|
<button type="button" class="btn btn-danger" onclick="clearNewLink(<?=$linknum?>)"><i class="fas fa-xmark-large mr-1"></i> Entfernen</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
</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">
|
|
<label class="col-lg-2 col-form-label" for="note">Interne Notiz</label>
|
|
<div class="col-lg-10">
|
|
<textarea id="note" class="form-control" name="note" rows="5"><?=$address->note?></textarea>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
|
|
|
|
<div class="form-group row">
|
|
<label class="col-lg-2"></label>
|
|
<div class="col-lg-10">
|
|
<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>
|
|
|
|
|
|
|
|
</form>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
</div>
|
|
|
|
|
|
<script type="text/javascript">
|
|
$("#parent_id").select2({
|
|
allowClear: true,
|
|
placeholder: ""
|
|
});
|
|
$("#addresstypes").select2();
|
|
|
|
|
|
|
|
|
|
function validateIban(iban) {
|
|
if(!iban) {
|
|
return false;
|
|
}
|
|
iban = iban.toUpperCase().replace(/\s+/, '');
|
|
//check format
|
|
var m;
|
|
|
|
if(!iban.match(/^[A-Z]{2}[0-9]{2}[A-Z0-9]{1,30}$/)) {
|
|
return false;
|
|
}
|
|
|
|
var cc = iban.substr(0, 2);
|
|
var check = parseInt(iban.substr(2, 2));
|
|
var account = iban.substr(4);
|
|
|
|
var searchRange = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".split('');
|
|
//var replaceRange = [];
|
|
var checkStr = account + cc + "00";
|
|
for(var i = 0; i <= 25; i++) {
|
|
checkStr = checkStr.replace(searchRange[i], i + 10);
|
|
};
|
|
// make checksum
|
|
var checksum = parseInt(checkStr.substr(0,1));
|
|
for(pos = 1; pos < checkStr.length; pos++) {
|
|
checksum *= 10;
|
|
checksum += parseInt(checkStr.substr(pos, 1));
|
|
checksum %= 97;
|
|
}
|
|
|
|
if(98 - checksum == check) {
|
|
return true;
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
$('#addressForm').submit(function(e) {
|
|
$("#error").hide();
|
|
if($('#billing_type').val() == "sepa" && !validateIban($("#bank_account_iban").val())) {
|
|
$("#error").show();
|
|
console.log("nope");
|
|
e.preventDefault();
|
|
return false;
|
|
}
|
|
return true;
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
* link autocomplete
|
|
*/
|
|
|
|
$('.link-autocomplete').autoComplete();
|
|
$('.link-autocomplete').keydown(function() {
|
|
if(event.keyCode == 13) {
|
|
event.preventDefault();
|
|
return false;
|
|
}
|
|
});
|
|
|
|
/*
|
|
* Links autocomplete
|
|
*/
|
|
$('.link-autocomplete').on("autocomplete.select", function(evt, item) {
|
|
autocompleteSelect(evt,item);
|
|
});
|
|
|
|
function autocompleteSelect(evt, item) {
|
|
if(item && item.value === 0) {
|
|
$('.link-autocomplete').autoComplete('set', null);
|
|
return;
|
|
}
|
|
|
|
var match = evt.currentTarget.id.match(/links_(\d+)_address_id/);
|
|
var link_num = match[1];
|
|
if(!link_num) {
|
|
console.log("Couldn't find selected Address");
|
|
}
|
|
addLink(Number(link_num) + 1);
|
|
}
|
|
|
|
function addLink(linknum) {
|
|
if(!linknum) {
|
|
console.log("no linknum");
|
|
return false;
|
|
}
|
|
|
|
if($("#links_" + linknum + "_address_id").length) {
|
|
console.log("gibs scho");
|
|
return false;
|
|
}
|
|
|
|
var new_link = '<div class="form-group row" id="link-' + linknum + '"> \
|
|
<label class="col-lg-2 col-form-label" for="links_' + linknum + '_address_id"></label> \
|
|
<div class="col-lg-6"> \
|
|
<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> \
|
|
</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" placeholder="Name, Kundennummer, ID" data-noresults-text="Keine Suchergebnisse"> \
|
|
<option></option> \
|
|
</select> \
|
|
<div class="input-group-append"> \
|
|
<button type="button" class="btn btn-danger" onclick="clearNewLink(' + linknum + ')"><i class="fas fa-xmark-large mr-1"></i> Entfernen</button> \
|
|
</div> \
|
|
</div> \
|
|
</div> \
|
|
</div>';
|
|
|
|
$('#link-container').append(new_link);
|
|
//$('#links_' + linknum + '_address_id').autocomplete();
|
|
$('#links_' + linknum + '_address_id').autoComplete();
|
|
$('#links_' + linknum + '_address_id').keydown(function() {
|
|
if(event.keyCode == 13) {
|
|
event.preventDefault();
|
|
return false;
|
|
}
|
|
});
|
|
|
|
$('#links_' + linknum + '_address_id').on("autocomplete.select", function(evt, item) {
|
|
autocompleteSelect(evt,item);
|
|
});
|
|
}
|
|
|
|
function clearNewLink(linknum) {
|
|
if(!$("#link-" + linknum).length) {
|
|
return;
|
|
|
|
}
|
|
|
|
// only remove is not the only one
|
|
if($('#link-container').find('div.row').length > 1) {
|
|
$("#link-" + linknum).remove();
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</script>
|
|
|
|
<?php include(realpath(dirname(__FILE__)."/../../$mfLayoutPackage")."/footer.php"); ?>
|