Files
thetool/Layout/default/Order/Form.php
2024-07-30 15:43:52 +02:00

1779 lines
84 KiB
PHP

<?php
$includes_external_product = false;
$urlfilter = [];
if($s) {
$urlfilter['s'] = $s;
}
if($noTermProducts) {
$urlfilter['noTermProducts'] = 1;
}
if(isset($filter) && is_array($filter) && count($filter)) {
$urlfilter["filter"] = $filter;
}
$posturl = self::getUrl("Order", "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("Order")?>">Bestellungen</a></li>
<li class="breadcrumb-item active"><?=($order->id) ? "bearbeiten" : "Neu" ?></li>
</ol>
</div>
<h4 class="page-title">Bestellungen</h4>
</div>
</div>
</div>
<!-- end page title -->
<div class="row">
<div class="col-lg-12">
<div class="row justify-content-center " >
<div class="hidden mb-4 col-6 alert alert-warning text-center" id="contract-readonly-notice">
Diese Bestellung kann nicht mehr bearbeitet werden, da sie bereits abgeschlossen und in Verrechnung ist.
</div>
</div>
<div class="card no-shadow">
<div class="card-body bg-light">
<h4 class="mb-2"><?=($order->id) ? "Bestellung bearbeiten" : "Neue Bestellung"?></h4>
<form class="form-horizontal" method="post" action="<?=$posturl?>" name="orderForm" id="orderForm" enctype="multipart/form-data">
<div class="card">
<div class="card-body">
<input type="hidden" name="id" value="<?=$order->id?>" />
<div class="row">
<div class="col-lg-6" id="owner-block">
<div class="form-group row">
<div class="col-lg-12 mb-2">
<h4>Vertragsinhaber</h4>
<select class="form-control basicAutoComplete" autocomplete="off" name="owner_id" id="owner_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_owner" id="owner_new" <?=($order->new_owner) ? "checked='checked'" : ""?> /> Neukunde anlegen</label></div>
</div>
<div class="col-lg-12 <?=($order->new_owner) ? "" : "hidden"?>" id="owner-form">
<div class="row">
<div class="col-lg-12">
<div class="form-group">
<label class="form-label" for="owner_company">Firmenname</label>
<textarea class="form-control" name="owner_company" id="owner_company"><?=$order->owner_company?></textarea>
</div>
</div>
</div>
<div class="row">
<div class="col-lg-6">
<div class="form-group">
<label class="form-label" for="owner_firstname">Vorname</label>
<input type="text" class="form-control" name="owner_firstname" id="owner_firstname" value="<?=$order->owner_firstname?>" />
</div>
</div>
<div class="col-lg-6">
<div class="form-group">
<label class="form-label" for="owner_lastname">Nachname</label>
<input type="text" class="form-control" name="owner_lastname" id="owner_lastname" value="<?=$order->owner_lastname?>" />
</div>
</div>
</div>
<div class="row">
<div class="col-lg-12">
<div class="form-group">
<label class="form-label" for="owner_street">Straße *</label>
<input type="text" class="form-control" name="owner_street" id="owner_street" value="<?=$order->owner_street?>" />
</div>
</div>
</div>
<div class="row">
<div class="col-lg-3">
<div class="form-group">
<label class="form-label" for="owner_zip">Postleitzahl *</label>
<input type="text" class="form-control" name="owner_zip" id="owner_zip" value="<?=$order->owner_zip?>" />
</div>
</div>
<div class="col-lg-9">
<div class="form-group">
<label class="form-label" for="owner_city">Ort *</label>
<input type="text" class="form-control" name="owner_city" id="owner_city" value="<?=$order->owner_city?>" />
</div>
</div>
</div>
<div class="row">
<div class="col-lg-12">
<div class="form-group">
<label class="form-label" for="owner_country_id">Land</label>
<select name="owner_country_id" id="owner_country_id" class="form-control">
<?php foreach($countries as $country): ?>
<option value="<?=$country->id?>" <?=(($order && $order->owner_country_id == $country->id) || ((!$order || !$order->owner_country_id) && $country->name == "Österreich")) ? "selected='selected'" : ""?>><?=$country->name?></option>
<?php endforeach; ?>
</select>
</div>
</div>
</div>
<div class="row">
<div class="col-lg-6">
<div class="form-group">
<label class="form-label" for="owner_phone">Telefon *</label>
<input type="text" class="form-control" name="owner_phone" id="owner_phone" value="<?=$order->owner_phone?>" />
</div>
</div>
<div class="col-lg-6">
<div class="form-group">
<label class="form-label" for="owner_mobile">Mobil</label>
<input type="text" class="form-control" name="owner_mobile" id="owner_mobile" value="<?=$order->owner_mobile?>" />
</div>
</div>
</div>
<div class="row">
<div class="col-lg-6">
<div class="form-group">
<label class="form-label" for="owner_email">Emailadresse *</label>
<input type="text" class="form-control" name="owner_email" id="owner_email" value="<?=$order->owner_email?>" />
</div>
</div>
<div class="col-lg-6">
<div class="form-group">
<label class="form-label" for="owner_fax">Fax</label>
<input type="text" class="form-control" name="owner_fax" id="owner_fax" value="<?=$order->owner_fax?>" />
</div>
</div>
</div>
<div class="row">
<div class="col-lg-6">
<div class="form-group">
<label class="form-label" for="owner_uid">UID</label>
<input type="text" class="form-control" name="owner_uid" id="owner_uid" value="<?=$order->owner_uid?>" />
</div>
</div>
</div>
</div>
</div>
</div>
<div class="col-lg-6" id="billingaddress-block">
<div class="form-group row">
<div class="col-lg-12 mb-2">
<h4>Rechungsadresse</h4>
<select class="form-control basicAutoComplete" autocomplete="off" name="billingaddress_id" id="billingaddress_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_billingaddress" id="billingaddress_new" <?=($order->new_billingaddress) ? "checked='checked'" : ""?> /> Neue Rechnungsadresse anlegen</label></div>
</div>
<div class="col-lg-12 <?=(!$order->new_billingaddress) ? "hidden" : ""?>" id="billingaddress-form">
<div class="row">
<div class="col-lg-12">
<div class="form-group">
<label class="form-label" for="owner_company">Firmenname</label>
<textarea class="form-control" name="billing_company" id="billing_company"><?=$order->billing_company?></textarea>
</div>
</div>
</div>
<div class="row">
<div class="col-lg-6">
<div class="form-group">
<label class="form-label" for="billing_firstname">Vorname</label>
<input type="text" class="form-control" name="billing_firstname" id="billing_firstname" value="<?=$order->billing_firstname?>" />
</div>
</div>
<div class="col-lg-6">
<div class="form-group">
<label class="form-label" for="billing_lastname">Nachname</label>
<input type="text" class="form-control" name="billing_lastname" id="billing_lastname" value="<?=$order->billing_lastname?>" />
</div>
</div>
</div>
<div class="row">
<div class="col-lg-12">
<div class="form-group">
<label class="form-label" for="billing_street">Straße *</label>
<input type="text" class="form-control" name="billing_street" id="billing_street" value="<?=$order->billing_street?>" />
</div>
</div>
</div>
<div class="row">
<div class="col-lg-3">
<div class="form-group">
<label class="form-label" for="billing_zip">Postleitzahl *</label>
<input type="text" class="form-control" name="billing_zip" id="billing_zip" value="<?=$order->billing_zip?>" />
</div>
</div>
<div class="col-lg-9">
<div class="form-group">
<label class="form-label" for="billing_city">Ort *</label>
<input type="text" class="form-control" name="billing_city" id="billing_city" value="<?=$order->billing_city?>" />
</div>
</div>
</div>
<div class="row">
<div class="col-lg-12">
<div class="form-group">
<label class="form-label" for="billing_country_id">Land</label>
<select name="billing_country_id" id="billing_country_id" class="form-control">
<?php foreach($countries as $country): ?>
<option value="<?=$country->id?>" <?=(($order && $order->billing_country_id == $country->id) || ((!$order || !$order->billing_country_id) && $country->name == "Österreich")) ? "selected='selected'" : ""?>><?=$country->name?></option>
<?php endforeach; ?>
</select>
</div>
</div>
</div>
<div class="row">
<div class="col-lg-6">
<div class="form-group">
<label class="form-label" for="billing_phone">Telefon *</label>
<input type="text" class="form-control" name="billing_phone" id="billing_phone" value="<?=$order->billing_phone?>" />
</div>
</div>
<div class="col-lg-6">
<div class="form-group">
<label class="form-label" for="billing_mobile">Mobil</label>
<input type="text" class="form-control" name="billing_mobile" id="billing_mobile" value="<?=$order->billing_mobile?>" />
</div>
</div>
</div>
<div class="row">
<div class="col-lg-6">
<div class="form-group">
<label class="form-label" for="billing_email">Emailadresse *</label>
<input type="text" class="form-control" name="billing_email" id="billing_email" value="<?=$order->billing_email?>" />
</div>
</div>
<div class="col-lg-6">
<div class="form-group">
<label class="form-label" for="billing_fax">Fax</label>
<input type="text" class="form-control" name="billing_fax" id="billing_fax" value="<?=$order->billing_fax?>" />
</div>
</div>
</div>
<div class="row">
<div class="col-lg-6">
<div class="form-group">
<label class="form-label" for="billing_uid">UID</label>
<input type="text" class="form-control" name="billing_uid" id="billing_uid" value="<?=$order->billing_uid?>" />
</div>
</div>
</div>
</div>
</div>
</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_id">Land</label>
<select name="techcontact_country_id" id="techcontact_country_id" class="form-control">
<?php foreach($countries as $country): ?>
<option value="<?=$country->id?>" <?=(($order && $order->techcontact_country_id == $country->id) || ((!$order || !$order->techcontact_country_id) && $country->name == "Österreich")) ? "selected='selected'" : ""?>><?=$country->name?></option>
<?php endforeach; ?>
</select>
</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">
<label class="col-lg-2 col-form-label" for="order_date">Bestelldatum</label>
<div class="col-lg-4">
<input type="text" class="form-control" name="order_date" id="order_date" value="<?=($order->order_date) ? date("d.m.Y", $order->order_date) : ""?>" />
</div>
</div>
<div class="form-group row">
<label class="col-lg-2 col-form-label" for="partner_number">Partnernummer</label>
<div class="col-lg-4">
<input type="text" class="form-control" name="partner_number" id="partner_number" value="<?=$order->partner_number?>" />
</div>
</div>
<h4 class="mt-3">Verzögerte Herstellung:</h4>
<div class="form-group row">
<label class="col-lg-2 col-form-label" for="finish_after">Herstellbar ab</label>
<div class="col-lg-4">
<input type="text" class="form-control" name="finish_after" id="finish_after" value="<?=($order->finish_after) ? date("d.m.Y", $order->finish_after) : ""?>" />
</div>
</div>
<div class="form-group row">
<label class="col-lg-2 col-form-label" for="finish_after_comment">Verzögerungsgrund</label>
<div class="col-lg-4">
<textarea class="form-control" name="finish_after_comment" id="finish_after_comment" placeholder="Verzögerungsgrund"><?=$order->finish_after_comment?></textarea>
</div>
</div>
</div>
</div>
<div id="billing_block" class="hidden">
<h4>Verrechnung</h4>
<div class="card">
<div class="card-body">
<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">Rechnung</option>
<option value="sepa">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">Email</option>
<option value="paper">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="<?=$order->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="<?=$order->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="<?=$order->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="<?=$order->bank_account_bic?>" />
</div>
</div>
<div class="form-group row">
<label class="col-lg-2 col-form-label" for="bank_account_bic"></label>
<div class="col-lg-10 alert alert-danger hidden" id="bank-error"></div>
</div>
</div>
</div>
</div>
<div id="accept_block" class="hidden">
<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" <?=($order->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" <?=($order->allow_spin) ? "checked='checked'" : ""?> /> Auskunft mit Service PIN</label>
</div>
</div>
</div>
</div>
</div>
<div class="card">
<div class="card-body" id="products-form">
<h4>Produkte</h4>
<div class="row col-12 mt-2 mb-2">
<label><input type="checkbox" class="input-check" name="upgrade" value="1" <?=($order->upgrade) ? "checked='checked'" : ""?> /> Bestellung ist Upgrade</label>
</div>
<div></div>
<?php $i = 1; ?>
<?php if(is_array($order->products) && count($order->products)): ?>
<?php foreach($order->products as $product): ?>
<?php
if(!is_object($product)) continue;
if($product->product->external == 1) {
$includes_external_product = true;
}
?>
<div class="row product-container" id="position-<?=$i?>">
<input type="hidden" name="products[<?=$i?>][delete]" id="products-<?=$i?>-delete" value="0" />
<input type="hidden" name="products[<?=$i?>][orderproduct_id]" value="<?=$product->id?>" />
<div class="col-md-1 product-<?=$i?>">
<div class="row">
<div class="col-md-12">
<!-- pos number -->
<div class="form-group">
<label class="form-label" for="pos-<?=$i?>">Position</label>
<input type="number" class="form-control" name="products[<?=$i?>][pos]" id="pos-<?=$i?>" value="<?=$i?>" placeholder="Position" />
</div>
</div>
</div>
<div class="row">
<div class="col-md-12 delete-button-container">
<i class="btn btn-outline-danger fas fa-trash-can pointer" style="font-size: 1.5em" onclick="toggleDeletePos(<?=$i?>)"></i>
</div>
</div>
</div>
<div class="col-md-11">
<!-- product lines -->
<div class="row">
<!-- line 1 -->
<div class="col-4">
<label class="form-label" for="product_id-<?=$i?>">Produkt</label>
<select name="products[<?=$i?>][product_id]" id="product_id-<?=$i?>" class="form-control select2" onchange="updateProduct(<?=$i?>)">
<option></option>
<?php foreach($products as $p): ?>
<option value="<?=$p->id?>" <?=($p->id == $product->product_id) ? "selected='selected'" : ""?>><?=$p->name?></option>
<?php endforeach; ?>
</select>
</div>
<div class="col-2">
<label class="form-label" for="amount-<?=$i?>">Anzahl/Menge</label>
<input type="number" class="form-control" name="products[<?=$i?>][amount]" id="amount-<?=$i?>" value="<?=($product) ? $product->formatAmount() : ""?>" placeholder="Anzahl/Menge" />
</div>
<div class="col-2">
<label class="form-label" for="billing_period-<?=$i?>">Rechungsperiode</label>
<select class="form-control" name="products[<?=$i?>][billing_period]" id="billing_period-<?=$i?>" placeholder="Rechnungsperiode">
<option value="1" <?=($product->billing_period == 1) ? "selected='selected'" : ""?>>Monatlich</option>
<option value="12" <?=($product->billing_period == 12) ? "selected='selected'" : ""?>>Jährlich</option>
<option value="0" <?=($product->billing_period == 0) ? "selected='selected'" : ""?>>Einmalig</option>
</select>
</div>
<div class="col-2">
<label class="form-label" for="price-<?=$i?>">Preis p. Periode</label>
<input type="text" class="form-control" name="products[<?=$i?>][price]" id="price-<?=$i?>" value="<?=$this::dotToComma($product->price)?>" placeholder="Preis p. Periode" />
</div>
<div class="col-2">
<label class="form-label" for="price_setup-<?=$i?>">Preis Setup</label>
<input type="text" class="form-control" name="products[<?=$i?>][price_setup]" id="price_setup-<?=$i?>" value="<?=$this::dotToComma($product->price_setup)?>" placeholder="Preis Setup" />
</div>
</div>
<?php if(
(is_array($product->product->attributes) && count($product->product->attributes))
&& (array_key_exists(TT_ATTRIB_TERMINATION_REQUIRED_NAME, $product->product->attributes)
&& $product->product->attributes[TT_ATTRIB_TERMINATION_REQUIRED_NAME]->value == 1)
|| $product->termination_id
): ?>
<div class="row mt-1 mb-2" id="termination_id-<?=$i?>-line">
<?php else: ?>
<div class="row mt-1 mb-2 hidden" id="termination_id-<?=$i?>-line">
<?php endif; ?>
<!-- line to choose termination -->
<div class="col-12">
<label class="form-label" for="termination_id-<?=$i?>">Anschluss</label>
<select name="products[<?=$i?>][termination_id]" id="termination_id-<?=$i?>" class="form-control select2">
<option></option>
<?php foreach($terminations as $t): ?>
<option value="<?=$t->id?>" <?=($t->id == $product->termination_id) ? "selected='selected'" : ""?>><?=$t->code?> - <?=$t->getAddress()?></option>
<?php endforeach; ?>
</select>
</div>
</div>
<?php if(
(is_array($product->product->attributes) && count($product->product->attributes))
&& (array_key_exists(TT_ATTRIB_VOICENUMBER_REQUIRED_NAME, $product->product->attributes)
&& $product->product->attributes[TT_ATTRIB_VOICENUMBER_REQUIRED_NAME]->value == 1)
|| $product->voicenumbers
): ?>
<div class="row mt-1 mb-2" id="voicenumber-<?=$i?>-line">
<?php else: ?>
<div class="row mt-1 mb-2 hidden" id="voicenumber-<?=$i?>-line">
<?php endif; ?>
<!-- line to input voicenumber -->
<div class="col-6">
<!-- line to input voicenumber -->
<?php if(is_array($product->voicenumbers) && count($product->voicenumbers)): ?>
Rufnummer: <strong><?=implode("\n<br />", $product->voicenumbers)?></strong> <i class="fas fa-pencil pointer text-primary" onclick="toggleVoicenumberEdit(<?=$i?>)"></i>
<?php endif; ?>
<div class="row <?=is_array($product->voicenumbers) && count($product->voicenumbers) ? "hidden" : ""?>" id="voicenumber-edit-<?=$i?>">
<div class="col-4" id="voicenumberblock-<?=$i?>-line">
<label class="form-label" for="voicenumberblock-<?=$i?>">Nummernblock *</label>
<select name="voicenumberblock_id" id="voicenumberblock_id-<?=$i?>" class="form-control select2" onchange="loadVoicenumbers(<?=$i?>)">
<option></option>
<option value="portin">Rufnummernportierung</option>
<?php foreach(VoicenumberblockModel::getAll() as $block): ?>
<option value="<?=$block->id?>">+<?=$block->countrycode?> <?=$block->areacode?> (<?=$block->name?>)</option>
<?php endforeach; ?>
</select>
</div>
<div class="col-4 hidden" id="voicenumber-select-<?=$i?>-line">
<label class="form-label" for="voicenumber-<?=$i?>">Rufnummer wählen *</label>
<select name="products[<?=$i?>][voicenumber]" id="voicenumber-<?=$i?>" class="form-control select2">
</select>
</div>
<div class="col-4 hidden" id="voicenumber-custom-<?=$i?>-line">
<label class="form-label" for="voicenumber_custom-<?=$i?>">Rufnummer eingeben *</label>
<input type="text" class="form-control" name="products[<?=$i?>][voicenumber_custom]" id="voicenumber_custom-<?=$i?>" value="" placeholder="Gesamte Rufnummer (+43 123 456 78 )" />
</div>
</div>
</div>
</div>
<div class="row mt-1 mb-2">
<!-- line 2 -->
<div class="col-6">
<label class="form-label" for="description-<?=$i?>" >Zusatztext</label>
<textarea class="form-control" name="products[<?=$i?>][description]" id="description-<?=$i?>" placeholder="Zusatztext"><?=$product->description?></textarea>
</div>
<div class="col-2">
<label class="form-label" for="contract_term-<?=$i?>">Mindestvertragslaufzeit</label>
<select class="form-control" name="products[<?=$i?>][contract_term]" id="contract_term-<?=$i?>" placeholder="Mindestvertragslaufzeit">
<option value="0" <?=($product->contract_term == 0) ? "selected='selected'" : ""?>>Keine</option>
<option value="1" <?=($product->contract_term == 1) ? "selected='selected'" : ""?>>1 Monat</option>
<option value="12" <?=($product->contract_term == 12) ? "selected='selected'" : ""?>>12 Monate</option>
<option value="24" <?=($product->contract_term == 24) ? "selected='selected'" : ""?>>24 Monate</option>
<option value="36" <?=($product->contract_term == 36) ? "selected='selected'" : ""?>>36 Monate</option>
<option value="48" <?=($product->contract_term == 48) ? "selected='selected'" : ""?>>48 Monate</option>
<option value="60" <?=($product->contract_term == 60) ? "selected='selected'" : ""?>>60 Monate</option>
</select>
</div>
<div class="col-2">
<label class="form-label" for="billing_delay-<?=$i?>" >Verzögerter Verrechnungsstart</label>
<input type="number" class="form-control" name="products[<?=$i?>][billing_delay]" id="billing_delay-<?=$i?>" value="<?=$product->billing_delay?>" placeholder="Freimonate" />
<small>Max. 6 Monate</small>
</div>
<?php if($me->is("Admin")): ?>
<div class="col-1">
<label class="form-label" for="price_nne-<?=$i?>">Preis NNE</label>
<input type="text" class="form-control" name="products[<?=$i?>][price_nne]" id="price_nne-<?=$i?>" value="<?=$this::dotToComma($product->price_nne)?>" placeholder="NNE" />
</div>
<div class="col-1">
<label class="form-label" for="price_nbe-<?=$i?>">Preis NBE</label>
<input type="text" class="form-control" name="products[<?=$i?>][price_nbe]" id="price_nne-<?=$i?>" value="<?=$this::dotToComma($product->price_nbe)?>" placeholder="NBE" />
</div>
<?php endif; ?>
</div>
</div>
</div>
<?php $i++; ?>
<?php endforeach; ?>
<?php endif; ?>
<?php if(!$order->finish_date || (!is_array($order->contracts) || !count($order->contracts))): ?>
<!-- New position -->
<div class="row product-container" id="position-<?=$i?>">
<div class="col-md-1 product-<?=$i?>">
<div class="row">
<div class="col-md-12">
<!-- pos number -->
<div class="form-group">
<label class="form-label" for="pos-<?=$i?>">Position</label>
<input type="number" class="form-control" name="products[<?=$i?>][pos]" id="pos-<?=$i?>" value="<?=$i?>" placeholder="Position" />
</div>
</div>
</div>
<div class="row">
<div class="col-md-12 delete-button-container">
<i class="btn btn-outline-info fas fa-trash-can pointer" title="Inhalte löschen" style="font-size: 1.5em" onclick="clearNewPos(<?=$i?>)"></i>
</div>
</div>
</div>
<div class="col-md-11">
<!-- product lines -->
<div class="row">
<!-- line 1 -->
<div class="col-4">
<label class="form-label" for="product_id-<?=$i?>">Produkt</label>
<select name="products[<?=$i?>][product_id]" id="product_id-<?=$i?>" class="form-control select2" onchange="updateProduct(<?=$i?>)">
<option></option>
<?php foreach($products as $p): ?>
<option value="<?=$p->id?>"><?=$p->name?></option>
<?php endforeach; ?>
</select>
</div>
<div class="col-2">
<label class="form-label" for="amount-<?=$i?>">Anzahl/Menge</label>
<input type="number" class="form-control" name="products[<?=$i?>][amount]" id="amount-<?=$i?>" value="" placeholder="Anzahl/Menge" />
</div>
<div class="col-2">
<label class="form-label" for="billing_period-<?=$i?>">Verrechungsperiode</label>
<select class="form-control" name="products[<?=$i?>][billing_period]" id="billing_period-<?=$i?>" placeholder="Rechnungsperiode">
<option value="1">Monatlich</option>
<option value="12">Jährlich</option>
<option value="0">Einmalig</option>
</select>
</div>
<div class="col-2">
<label class="form-label" for="price-<?=$i?>">Preis p. Periode</label>
<input type="text" class="form-control" name="products[<?=$i?>][price]" id="price-<?=$i?>" value="" placeholder="Preis p. Periode" />
</div>
<div class="col-2">
<label class="form-label" for="price_setup-<?=$i?>">Preis Setup</label>
<input type="text" class="form-control" name="products[<?=$i?>][price_setup]" id="price_setup-<?=$i?>" value="" placeholder="Preis Setup" />
</div>
</div>
<div class="row mt-1 mb-2 hidden" id="termination_id-<?=$i?>-line">
<!-- line to choose termination -->
<div class="col-12">
<label class="form-label" for="termination_id-<?=$i?>">Anschluss</label>
<select name="products[<?=$i?>][termination_id]" id="termination_id-<?=$i?>" class="form-control select2">
<option></option>
<?php foreach($terminations as $t): ?>
<option value="<?=$t->id?>"><?=$t->code?> - <?=$t->getAddress()?></option>
<?php endforeach; ?>
</select>
</div>
</div>
<div class="row mt-1 mb-2 hidden" id="voicenumber-<?=$i?>-line">
<div class="col-6">
<!-- line to input voicenumber -->
<div class="row">
<div class="col-4" id="voicenumberblock-<?=$i?>-line">
<label class="form-label" for="voicenumberblock-<?=$i?>">Nummernblock *</label>
<select name="voicenumberblock_id" id="voicenumberblock_id-<?=$i?>" class="form-control select2" onchange="loadVoicenumbers(<?=$i?>)">
<option></option>
<option value="portin">Rufnummernportierung</option>
<?php foreach(VoicenumberblockModel::getAll() as $block): ?>
<option value="<?=$block->id?>">+<?=$block->countrycode?> <?=$block->areacode?> (<?=$block->name?>)</option>
<?php endforeach; ?>
</select>
</div>
<div class="col-4 hidden" id="voicenumber-select-<?=$i?>-line">
<label class="form-label" for="voicenumber-<?=$i?>">Rufnummer wählen *</label>
<select name="products[<?=$i?>][voicenumber]" id="voicenumber-<?=$i?>" class="form-control select2">
</select>
</div>
<div class="col-4 hidden" id="voicenumber-custom-<?=$i?>-line">
<label class="form-label" for="voicenumber_custom-<?=$i?>">Rufnummer eingeben *</label>
<input type="text" class="form-control" name="products[<?=$i?>][voicenumber_custom]" id="voicenumber_custom-<?=$i?>" value="" placeholder="Gesamte Rufnummer (+43 123 456 78 )" />
</div>
</div>
</div>
</div>
<div class="row mt-1 mb-2">
<!-- line 2 -->
<div class="col-6">
<label class="form-label" for="description-<?=$i?>" >Zusatztext</label>
<textarea class="form-control" name="products[<?=$i?>][description]" id="description-<?=$i?>" placeholder="Zusatztext"></textarea>
</div>
<div class="col-2">
<label class="form-label" for="contract_term-<?=$i?>">Mindestvertragslaufzeit</label>
<select class="form-control" name="products[<?=$i?>][contract_term]" id="contract_term-<?=$i?>" placeholder="Mindestvertragslaufzeit">
<option value="0">Keine</option>
<option value="1">1 Monat</option>
<option value="12">12 Monate</option>
<option value="24">24 Monate</option>
<option value="36">36 Monate</option>
<option value="48">48 Monate</option>
<option value="60">60 Monate</option>
</select>
</div>
<div class="col-2">
<label class="form-label" for="billing_delay-<?=$i?>" >Verzögerter Verrechnungsstart</label>
<input type="number" class="form-control" name="products[<?=$i?>][billing_delay]" id="billing_delay-<?=$i?>" value="" placeholder="Freimonate" />
<small>Max. 6 Monate</small>
</div>
<?php if($me->is("Admin")): ?>
<div class="col-1">
<label class="form-label" for="price_nne-<?=$i?>">Preis NNE</label>
<input type="text" class="form-control" name="products[<?=$i?>][price_nne]" id="price_nne-<?=$i?>" value="" placeholder="NNE" />
</div>
<div class="col-1">
<label class="form-label" for="price_nbe-<?=$i?>">Preis NBE</label>
<input type="text" class="form-control" name="products[<?=$i?>][price_nbe]" id="price_nbe-<?=$i?>" value="" placeholder="NBE" />
</div>
<?php endif; ?>
</div>
</div>
</div>
<?php endif; ?>
</div>
</div>
<h4>Dokumente</h4>
<div class="card">
<div class="card-body">
<?php if(!$order->id): ?>
<i class="text-pink">Verfügbar nach speichern.</i>
<?php else: ?>
<?php if(is_array($order->files) && count($order->files)): ?>
<table id="files-table" class="table table-striped table-hover">
<tr>
<th>Name</th>
<th>Beschreibung</th>
<th>Dateiname</th>
<th>Hochgeladen</th>
<th></th>
</tr>
<?php foreach($order->files as $file): ?>
<tr>
<td>
<a href="<?=self::getUrl("File", "Download", ['id' => $file->file->id])?>">
<?php if(defined("TT_ORDER_FILE_TYPES") && array_key_exists($file->name, TT_ORDER_FILE_TYPES)): ?>
<?=TT_ORDER_FILE_TYPES[$file->name]?>
<?php else: ?>
<?=$file->name?>
<?php endif; ?>
</a>
</td>
<td><?=nl2br(htmlentities($file->description))?></td>
<td><?=$file->file->filename?></td>
<td class="text-monospace"><?=date("d.m.Y", $file->create)?> (<?=$file->creator->name?>)</td>
<td>
<a class="delete-button" href="<?=self::getUrl("OrderFile", "delete", ["id" => $file->id])?>" onclick="if(!confirm('Dokument wirklich löschen?')) return false;" title="Löschen"><i class="fas fa-trash text-danger"></i></a>
</td>
</tr>
<?php endforeach; ?>
</table>
<?php endif; ?>
<h4>Neues Dokument</h4>
<div class="form-group row">
<label class="col-lg-2 col-form-label" for="file_name">Dateityp</label>
<div class="col-lg-10">
<?php if(defined("TT_ORDER_FILE_TYPES") && is_array(TT_ORDER_FILE_TYPES)): ?>
<select name="file_name" class="form-control">
<?php foreach(TT_ORDER_FILE_TYPES as $key => $type): ?>
<option value="<?=$key?>"><?=$type?></option>
<?php endforeach; ?>
</select>
<?php endif; ?>
</div>
</div>
<div class="form-group row">
<label class="col-lg-2 col-form-label" for="file_description">Beschreibung</label>
<div class="col-lg-10">
<textarea class="form-control" name="file_description"></textarea>
</div>
</div>
<div class="form-group row">
<label class="col-lg-2 col-form-label" for="note">Datei auswählen</label>
<div class="col-lg-10">
<input type="file" name="OrderFileUpload" class="form-control" />
<small>Erlaubte Dateiendungen: <?=MFUPLOAD_ALLOWED_EXTENSIONS_STR?></small>
</div>
</div>
<?php endif; ?>
</div>
</div>
<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"><?=$order->note?></textarea>
</div>
</div>
</div>
</div>
<div class="card">
<div class="card-body">
<?php if($me->is("Admin", "netoperator")): ?>
<div class="form-group row">
<label class="col-lg-2"></label>
<div class="col-lg-10">
<label class="form-check-label"><input type="checkbox" class="form-check-input" name="order_finished" value="1" id="order_finished" <?=($order->finish_date) ? "checked='checked'" : ""?> /> Bestellung abschließen</label>
</div>
</div>
<div class="form-group row" id="finish_date_field">
<label class="col-lg-2 col-form-label" for="finish_date">Abgeschlossen am</label>
<div class="col-lg-4">
<?php if($order->shippingdate): ?>
<input type="text" class="form-control" name="finish_date" id="finish_date" value="<?=date("d.m.Y", $order->shippingdate)?>" />
<?php else: ?>
<input type="text" class="form-control" name="finish_date" id="finish_date" value="<?=($order->shippingdate ? $order->shippingdate : $order->finish_date) ? date("d.m.Y", $order->finish_date) : ""?>" />
<?php endif; ?>
</div>
</div>
<?php endif; ?>
<div class="form-group row">
<label class="col-lg-2"></label>
<div class="col-lg-10">
<button type="submit" name="return" value="form" 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="form-error" class="text-danger hidden">Bitte alle benötigten Felder ausfüllen!</span>
</div>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
<script type="text/javascript">
$(".select2").select2({
allowClear: true,
placeholder: ""
});
/*$("#billingaddress_id").select2({
allowClear: true,
placeholder: ""
});*/
/************************
* autocomplete
*/
// kunde
<?php if($order->owner_id && is_object(($order->owner))): ?>
$('#owner_id').autoComplete('set', { value: <?=$order->owner_id?>, text: '<?=($order->owner_id) ? str_replace("'", "\\'", str_replace(["\n", "\r"], " ", $order->owner->getCompanyOrName()))." (".$order->owner->zip." ".$order->owner->city.", ".$order->owner->street.")".(($order->owner->customer_number) ? " [".$order->owner->customer_number."]" : "") : ""?>'});
<?php else: ?>
$('#owner_id').autoComplete();
<?php endif; ?>
$('#owner_id').keydown(function() {
if(event.keyCode == 13) {
event.preventDefault();
return false;
}
});
$('#owner_new').change(function() {
if($('#owner_new').is(":checked")) {
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);
}
});
$('#owner_id').on("autocomplete.select", function(evt, item) {
if(item && item.value === 0) {
$('#owner_id').autoComplete('set', null);
}
});
// rechnungsadresse
<?php if($order->billingaddress_id && is_object($order->billingaddress)): ?>
$('#billingaddress_id').autoComplete('set', { value: <?=$order->billingaddress_id?>, text: '<?=($order->billingaddress_id) ? str_replace("'", "\\'", str_replace(["\n", "\r"], " ", $order->billingaddress->getCompanyOrName()))." (".$order->billingaddress->zip." ".$order->billingaddress->city.", ".$order->billingaddress->street.")" : ""?>'});
<?php else: ?>
$('#billingaddress_id').autoComplete();
<?php endif; ?>
$('#billingaddress_id').keydown(function() {
if(event.keyCode == 13) {
event.preventDefault();
return false;
}
});
$('#billingaddress_new').change(function() {
if($('#billingaddress_new').is(":checked")) {
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);
}
});
$('#billingaddress_id').on("autocomplete.select", function(evt, item) {
if(item && item.value === 0) {
$('#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
*******************************/
$('.select2').each(function(){
$(this).select2({
allowClear: true,
placeholder: ""
});
});
$('#owner_new').change(function() {
if($('#owner_new').prop('checked')) {
$('#owner-form').show();
$('#accept_block').show();
$('#billing_block').show();
} else {
$('#owner-form').hide();
$('#accept_block').hide();
if(!$('#billingaddress_new').prop('checked')) {
$('#billing_block').hide();
}
}
});
$('#billingaddress_new').change(function() {
if($('#billingaddress_new').prop('checked')) {
$('#billingaddress-form').show();
$('#billing_block').show();
} else {
$('#billingaddress-form').hide();
if(!$('#owner_new').prop('checked')) {
$('#billing_block').hide();
}
}
});
$('#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();
if(val == "new") {
$('#owner-form').show();
} else {
$('#owner-form').hide();
}
});*/
/*
$('#billingaddress_id').change(function() {
var val = $('#billingaddress_id').val();
if(val == "new") {
$('#billingaddress-form').show();
} else {
$('#billingaddress-form').hide();
}
});
*/
$('#order_finished').change(function() {
if($('#order_finished').is(":checked")) {
$('#finish_date_field').show();
} else {
$('#finish_date_field').hide();
}
});
$('#order_date').datepicker({
language: 'de',
format: "dd.mm.yyyy",
showWeekDays: true,
todayBtn: 'linked',
autoclose: true
});
$('#finish_after').datepicker({
language: 'de',
format: "dd.mm.yyyy",
showWeekDays: true,
todayBtn: 'linked',
autoclose: true
});
$('#finish_date').datepicker({
language: 'de',
format: "dd.mm.yyyy",
showWeekDays: true,
todayBtn: 'linked',
autoclose: true
});
// disable mousewheel on input number field when in focus
$('form').on('focus', 'input[type=number]', function (e) {
$(this).on('wheel.disableScroll', function (e) {
e.preventDefault()
})
});
$('form').on('blur', 'input[type=number]', function (e) {
$(this).off('wheel.disableScroll')
});
function updateProduct(id) {
var pid = $('#product_id-' + id).val();
$.get("<?=self::getUrl("Product", "Api")?>",
{
"do": "getProduct",
product_id: pid,
form_id: id
},
function (success) {
console.log(success);
p = success.result.product;
id = success.result.form_id;
$('#billing_delay-' + id).val(p.billing_delay);
$('#billing_period-' + id).val(p.billing_period);
$('#contract_term-' + id).val(p.contract_term);
$('#price-' + id).val(p.price);
$('#price_setup-' + id).val(p.price_setup);
$('#price_nne-' + id).val(p.price_nne);
$('#price_nbe-' + id).val(p.price_nbe);
var period = Number.parseInt(p.billing_period);
var price = Number.parseFloat(p.price);
if(!period && !price) {
$('#price-' + id).prop("disabled", true);
} else {
$('#price-' + id).prop("disabled", false);
}
console.log(p.attributes);
console.log("form_id: " + id);
if(typeof p.attributes === 'object' && "termination_required" in p.attributes && p.attributes.termination_required == 1) {
console.log("termination_required");
$('#termination_id-' + id + '-line').show();
console.log($('#termination_id-' + id).val());
$('#termination_id-' + id).select2({
allowClear: true,
placeholder: ""
});
} else {
$('#termination_id-' + id + '-line').hide();
//$('#termination_id-' + id + '-line').hide();
}
if(typeof p.attributes === 'object' && "needs_number" in p.attributes && p.attributes.needs_number == 1) {
console.log("needs_number");
$('#voicenumber-' + id + '-line').show();
} else {
$('#voicenumber-' + id + '-line').hide();
}
},
'json');
addNewProductLine(Number(id) + 1);
}
function toggleVoicenumberEdit(id) {
$('#voicenumber-edit-' + id).toggle();
$("#voicenumber-select-" + id + "-line select").empty();
$("#voicenumber-custom-" + id + "-line input").val("");
}
function loadVoicenumbers(id) {
var block_id = $("#voicenumberblock_id-" + id).val();
if(block_id == "portin") {
$("#voicenumber-select-" + id + "-line").hide();
$("#voicenumber-select-" + id + "-line select").val("");
$("#voicenumber-" + id).empty();
$("#voicenumber-custom-" + id + "-line").show();
//$("#voicenumberblock-" + id + "-line").hide();
return;
}
if(!block_id) return;
$.ajax({
url: "<?=self::getUrl("Voicenumberblock", "api")?>",
type: "POST",
context: id,
data: {
do: "getFreeNumbers",
id: block_id
},
success: function(success) {
//console.log(success, id);
if(success.status != "OK") return;
if(("numbers" in success.result) && success.result.numbers.length) {
$("#voicenumber-" + id).empty();
success.result.numbers.forEach(function(num) {
$("#voicenumber-" + id).append("<option value='" + num + "'>+" + num + "</option>");
});
//$("#voicenumberblock-" + id + "-line").hide();
$("#voicenumber-custom-" + id + "-line").hide();
$("#voicenumber-custom-" + id + "-line input").val("");
$("#voicenumber-select-" + id + "-line").show();
}
},
dataType: "json"
});
}
/*********************
* Form validation
*/
var bankdata_valid = false;
// iban validation
function validateIbanFormat(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;
}
}
function validateIbanBic(iban, bic) {
if(!iban) return false;
iban = iban.toUpperCase().replace(/\s+/, '');
$.post("<?=self::getUrl("Address", "api")?>", {
do: "validateIbanBic",
iban: iban,
bic: bic
},
function(success) {
if(success.status == "OK") {
var data = success.result;
$("#bank-error").hide();
$("#bank-error").text("");
if(data.iban_correct && data.bic_correct && (!data.iban_sus || data.iban_sus === "www")) {
bankdata_valid = true;
$('#orderForm').submit();
return;
}
var bank_error = [];
if(!data.iban_correct) {
$("#bank_account_iban").addClass("invalid");
bank_error.push("Ungültige IBAN!");
}
if(data.iban_sus && data.iban_sus !== "www") {
$("#bank_account_iban").addClass("invalid");
bank_error.push("IBAN verdächtig (" + data.iban_sus + ")!");
}
if(!data.bic_correct) {
$("#bank_account_bic").addClass("invalid");
bank_error.push("Ungültige BIC!");
if(Array.isArray(data.bic)) {
bank_error.push(" Mögliche korrekte BIC: " + data.bic.join(", "));
}
}
$("#bank-error").html(bank_error.join("<br />\n"));
$("#bank-error").show();
} else {
$("#bank-error").text("Beim Validieren der Bankdaten ist ein Fehler aufgetreten.");
}
},
"json"
);
return false;
}
function validateOrderForm() {
var allFields = [
"owner_company", "owner_firstname", "owner_lastname", "owner_street", "owner_zip", "owner_city", "owner_country_id", "owner_phone", "owner_email",
"billing_company", "billing_firstname", "billing_lastname", "billing_street", "billing_zip", "billing_city", "billing_country_id", "billing_phone", "billing_email",
"order_date", "finish_after", "finish_after_comment", "billing_type", "bank_account_bank", "bank_account_owner", "bank_account_iban", "bank_account_bic"
];
var checkEmpty = [];
var error = false;
// remove invalid class
allFields.forEach(function(field) {
//console.log("remove invalid " + field);
$("#" + field).removeClass("invalid");
});
$("#form-error").hide();
$("#iban_error").hide();
$('#owner_id').next().find('.select2-selection').removeClass('invalid');
$('#billingaddress_id').next().find('.select2-selection').removeClass('invalid');
checkEmpty.push("order_date");
if($('#finish_after').val()) {
checkEmpty.push("finish_after_comment");
}
if(!$('#owner_id').length) {
if(!$('#owner_company').val()) {
//console.log("no owner_company");
if(!$('#owner_firstname').val() || !$('#owner_lastname').val()) {
$('#owner_company').addClass("invalid");
$('#owner_firstname').addClass("invalid");
$('#owner_lastname').addClass("invalid");
error = true;
}
}
checkEmpty.push("owner_street");
checkEmpty.push("owner_zip");
checkEmpty.push("owner_city");
//checkEmpty.push("owner_country");
checkEmpty.push("owner_phone");
checkEmpty.push("owner_email");
}
/*
if(!$('#owner_id :selected').val()) {
$('#owner_id').addClass("invalid");
$('#owner_id').next().find('.select2-selection').addClass('invalid');
error = true;
}*/
if(!$('#billingaddress_id').length) {
if(!$('#billing_company').val()) {
//console.log("no billing_company");
if(!$('#billing_firstname').val() || !$('#billing_lastname').val()) {
$('#billing_company').addClass("invalid");
$('#billing_firstname').addClass("invalid");
$('#billing_lastname').addClass("invalid");
error = true;
}
}
checkEmpty.push("billing_street");
checkEmpty.push("billing_zip");
checkEmpty.push("billing_city");
//checkEmpty.push("billing_country");
checkEmpty.push("billing_phone");
checkEmpty.push("billing_email");
}
//alert("error: " + error);
/*
if(!$('#billingaddress_id :selected').val()) {
if(!$('#owner_id :selected').val()) {
$('#billingaddress_id').addClass("invalid");
$('#billingaddress_id').next().find('.select2-selection').addClass('invalid');
error = true;
}
}*/
// check bankdaten
if($('#billing_type').val() == "sepa" && !bankdata_valid) {
checkEmpty.push("bank_account_bank");
checkEmpty.push("bank_account_owner");
checkEmpty.push("bank_account_bic");
$("#bank_account_iban").removeClass("invalid");
$("#bank_account_bic").removeClass("invalid");
if(!validateIbanFormat($("#bank_account_iban").val())) {
$("#bank_account_iban").addClass("invalid");
$("#iban_error").show();
error = true;
}
if(!validateIbanBic($("#bank_account_iban").val(), $("#bank_account_bic").val())) {
error = true;
}
}
// owner_id & billingaddress_id
if(!$('input[name=owner_id').length) {
error = true;
console.log("owner_id empty");
$('input[name=owner_id').addClass("invalid");
}
if(!$('input[name=billingaddress_id').length) {
error = true;
console.log("billingaddress_id empty");
$('input[name=billingaddress_id').addClass("invalid");
}
if(checkEmpty.length) {
checkEmpty.forEach(function(field) {
if(!$("#" + field).val().length) {
console.log(field + " empty");
$("#" + field).addClass("invalid");
error = true;
}
});
}
if(error) {
$("#form-error").show();
return false;
}
console.log("empty: " + checkEmpty);
return true;
}
$(document).ready(function() {
$('#orderForm').submit(function(e) {
console.log("submit");
if(!validateOrderForm()) {
console.log("nope");
e.preventDefault();
return false;
}
return true;
});
<?php if(!$order->finish_date): ?>
$('#finish_date_field').hide();
<?php endif; ?>
<?php if($order->finish_date && is_array($order->contracts) && count($order->contracts)): ?>
$("input").prop("disabled", true);
$("input[type=text]").prop("readonly", true);
$("select").prop("disabled", true);
$("textarea").prop("disabled", true);
$("button").prop("disabled", true);
//$("#files-table a.edit-button").removeAttr("href");
$("#files-table a.delete-button").removeAttr("href").removeAttr("onclick");
$("#contract-readonly-notice").show();
<?php endif; ?>
$('.product-container input').each(function() {
});
});
function toggleDeletePos(id) {
if($('#products-' + id + '-delete').val() == "0") {
$('#position-' + id).addClass('deleted text-white');
$('#position-' + id + ' .delete-button-container i').removeClass("btn-outline-danger fa-trash-can").addClass("btn-danger fa-trash-can-slash");
$('#position-' + id + ' .delete-button-container').append('<p class="text-white font-weight-bold">Wird gelöscht!</p>');
//$('#position-' + id + ' .delete-button-container i').removeClass("fa-trash-can").addClass("fa-trash-can-slash");
$('#products-' + id + '-delete').val(1);
$('#position-' + id).each(function() {
$(this).find('input').attr("readonly", true).addClass("text-danger");
$(this).find('select').attr("readonly", true).addClass("text-danger");
$(this).find('textarea').attr("readonly", true).addClass("text-danger");
});
} else {
$('#products-' + id + '-delete').val(0);
//$('#position-' + id + ' .delete-button-container i').removeClass("fa-trash-can-slash").addClass("fa-trash-can");
$('#position-' + id + ' .delete-button-container').html('<i class="btn btn-outline-danger fas fa-trash-can pointer" style="font-size: 1.5em" onclick="toggleDeletePos(' + id + ')"></i>');
//$('#position-' + id + ' .delete-button-container i').removeClass("btn-outline-white fa-trash-can-slash").addClass("text-danger fa-trash-can");
$('#position-' + id).removeClass('text-white deleted');
$('#position-' + id).each(function() {
$(this).find('input').attr("readonly", false).removeClass("text-danger");
$(this).find('select').attr("readonly", false).removeClass("text-danger");
$(this).find('textarea').attr("readonly", false).removeClass("text-danger");
});
}
}
function addNewProductLine(i) {
if(!i) {
return;
}
console.log("new_line num " + i);
if($('#position-' + i).length) {
console.log("gibts scho");
return;
}
var new_line = '<div class="row product-container" id="position-' + i +'"> \
<div class="col-md-1 product-' + i +'"> \
<div class="row"> \
<div class="col-md-12"> \
<div class="form-group"> \
<label class="form-label" for="pos-' + i +'">Position</label> \
<input type="number" class="form-control" name="products[' + i +'][pos]" id="pos-' + i +'" value="' + i +'" placeholder="Position" /> \
</div> \
</div> \
</div> \
<div class="row"> \
<div class="col-md-12 delete-button-container"> \
<i class="btn btn-outline-info fas fa-trash-can pointer" title="Inhalte löschen" style="font-size: 1.5em" onclick="clearNewPos(' + i +')"></i> \
</div> \
</div> \
</div> \
\
<div class="col-md-11"> \
<!-- product lines --> \
<div class="row"> \
<!-- line 1 --> \
<div class="col-4"> \
<label class="form-label" for="product_id-' + i +'">Produkt</label> \
<select name="products[' + i +'][product_id]" id="product_id-' + i +'" class="form-control select2" onchange="updateProduct(' + i +')"> \
<option></option>';
<?php foreach($products as $p): ?>
new_line += '<option value="<?=$p->id?>"><?=$p->name?></option>';
<?php endforeach; ?>
new_line += '</select> \
\
</div> \
<div class="col-2"> \
<label class="form-label" for="amount-' + i +'">Anzahl/Menge</label> \
<input type="number" class="form-control" name="products[' + i +'][amount]" id="amount-' + i +'" value="" placeholder="Anzahl/Menge" /> \
</div> \
<div class="col-2"> \
<label class="form-label" for="billing_period-' + i +'">Verrechungsperiode</label> \
<select class="form-control" name="products[' + i +'][billing_period]" id="billing_period-' + i +'" placeholder="Rechnungsperiode"> \
<option value="1">Monatlich</option> \
<option value="12">Jährlich</option> \
<option value="0">Einmalig</option> \
</select> \
</div> \
<div class="col-2"> \
<label class="form-label" for="price-' + i +'">Preis p. Periode</label> \
<input type="text" class="form-control" name="products[' + i +'][price]" id="price-' + i +'" value="" placeholder="Preis p. Periode" /> \
</div> \
<div class="col-2"> \
<label class="form-label" for="price_setup-' + i +'">Preis Setup</label> \
<input type="text" class="form-control" name="products[' + i +'][price_setup]" id="price_setup-' + i +'" value="" placeholder="Preis Setup" /> \
</div> \
</div> \
\
<div class="row mt-1 mb-2 hidden" id="termination_id-' + i +'-line"> \
<!-- line to choose termination --> \
<div class="col-12"> \
<label class="form-label" for="termination_id-' + i +'">Anschluss</label> \
<select name="products[' + i +'][termination_id]" id="termination_id-' + i +'" class="form-control select2"> \
<option></option>';
<?php foreach($terminations as $t): ?>
new_line += '<option value="<?=$t->id?>"><?=$t->code?> - <?=$t->getAddress(true)?></option>';
<?php endforeach; ?>
new_line += '</select> \
</div> \
</div> \
\
<div class="row mt-1 mb-2 hidden" id="voicenumber-' + i + '-line"> \
<!-- line to input voicenumber --> \
<div class="col-6"> \
<label class="form-label" for="voicenumber-' + i + '">Rufnummer</label> \
<textarea class="form-control" name="products[' + i + '][voicenumber]" id="voicenumber-' + i + '" placeholder="Eine Rufnummer pro Zeile (+43 123 456 78)" /></textarea> \
<small>Wenn Rufnummern bekannt sind oder portiert werden (Eine Rufnummer pro Zeile (+43 123 456 78))</small> \
</div> \
</div> \
\
<div class="row mt-1 mb-2"> \
<!-- line 2 --> \
<div class="col-6"> \
<label class="form-label" for="description-' + i +'" >Zusatztext</label> \
<textarea class="form-control" name="products[' + i +'][description]" id="description-' + i +'" placeholder="Zusatztext"></textarea> \
</div> \
<div class="col-2"> \
<label class="form-label" for="contract_term-' + i + '">Mindestvertragslaufzeit</label> \
<select class="form-control" name="products[' + i + '][contract_term]" id="contract_term-<?=$i?>" placeholder="Mindestvertragslaufzeit"> \
<option value="0">Keine</option> \
<option value="1">1 Monat</option> \
<option value="12">12 Monate</option> \
<option value="24">24 Monate</option> \
<option value="36">36 Monate</option> \
<option value="48">48 Monate</option> \
<option value="60">60 Monate</option> \
</select> \
</div> \
<div class="col-2"> \
<label class="form-label" for="billing_delay-' + i +'" >Verzögerter Verrechnungsstart</label> \
<input type="number" class="form-control" name="products[' + i +'][billing_delay]" id="billing_delay-' + i + '" value="" placeholder="Freimonate" /> \
<small>Max. 6 Monate</small> \
</div> \
<?php if($me->is("Admin")): ?>
<div class="col-1"> \
<label class="form-label" for="price_nne-' + i +'">Preis NNE</label> \
<input type="text" class="form-control" name="products[' + i +'][price_nne]" id="price_nne-' + i +'" value="" placeholder="NNE" /> \
</div> \
<div class="col-1"> \
<label class="form-label" for="price_nbe-' + i +'">Preis NBE</label> \
<input type="text" class="form-control" name="products[' + i +'][price_nbe]" id="price_nbe-' + i +'" value="" placeholder="NBE" /> \
</div> \
<?php endif; ?>
\
</div> \
</div> \
</div> \
';
$('#products-form').append(new_line);
$("#product_id-" + i).select2({
allowClear: true,
placeholder: ""
});
}
function clearNewPos(i) {
if(!$('#position-' + i).length) {
return;
}
$('#position-' + i).remove();
}
</script>
<?php include(realpath(dirname(__FILE__)."/../../$mfLayoutPackage")."/footer.php"); ?>