Files
thetool/Layout/default/Order/Form.php
Frank Schubert 121312cdc3 WIP Contract Form
2022-06-09 17:05:34 +02:00

1384 lines
63 KiB
PHP

<?php
$includes_external_product = false;
$urlfilter = [];
if($s) {
$urlfilter['s'] = $s;
}
if($noTermProducts) {
$urlfilter['noTermProducts'] = 1;
}
if(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">
<div class="card-body">
<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">
<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">Land</label>
<input type="text" class="form-control" name="owner_country" id="owner_country" value="<?=$order->owner_country?>" />
</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">
<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">Land</label>
<input type="text" class="form-control" name="billing_country" id="billing_country" value="<?=$order->billing_country?>" />
</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>
<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) : date("d.m.Y")?>" />
</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>
</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?>">Verrechungsperiode</label>
<select class="form-control" name="products[<?=$i?>][billing_period]" id="billing_period-<?=$i?>" placeholder="Verrechnungsperiode">
<option value="1" <?=($product->billing_period == 1) ? "selected='selected'" : ""?>>Monatlich</option>
<option value="12" <?=($product->billing_period == 12) ? "selected='selected'" : ""?>>Jährlich</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>
<div class="row mt-1 mb-2">
<!-- line 2 -->
<div class="col-8">
<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="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="Verrechnungsperiode">
<option value="1">Monatlich</option>
<option value="12">Jährlich</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">
<!-- line 2 -->
<div class="col-8">
<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="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_nne-<?=$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])?>"><?=$file->name?></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">Name</label>
<div class="col-lg-10">
<input type="text" class="form-control" name="file_name" id="file_name" />
</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")): ?>
<?php if(TT_FEATURE_IVT): ?>
<?php if($order->id && !$includes_external_product): ?>
<div class="form-group row">
<label class="col-lg-2"></label>
<div class="col-lg-10 mb-2">
<button type="button" id="savetoivt-button" class="btn btn-pink">Kunde an IVT übertragen</button>
<span id="savetoivt-info"></span>
</div>
</div>
<?php endif; ?>
<?php endif; ?>
<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);
} else {
$('#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);
} else {
$('#billingaddress_id').prop('disabled', false);
}
});
$('#billingaddress_id').on("autocomplete.select", function(evt, item) {
if(item && item.value === 0) {
$('#billingaddress_id').autoComplete('set', null);
}
});
/*
* autocomplete
*******************************/
$('.select2').each(function(){
$(this).select2({
allowClear: true,
placeholder: ""
});
});
<?php if($order->id): ?>
$('#savetoivt-button').click(function() {
$('#savetoivt-button').prop("disabled", true);
$('#savetoivt-info').html("<img src='<?=self::getResourcePath()?>img/ajax-loader.gif' />");
$.get("<?=self::getUrl("IvtCustomer","create", ["order_id" => $order->id])?>",
{},
function(data) {
console.log(data);
if(data.status == "OK") {
$('#savetoivt-info').removeClass("text-danger");
$('#savetoivt-info').addClass("text-success");
$('#savetoivt-info').text("Kunde erfolgreich an IVT übertragen!");
$('#savetoivt-button').remove();
} else {
$('#savetoivt-info').removeClass("text-success");
$('#savetoivt-info').addClass("text-danger");
if(data.reason) {
if(data.reason == "no-cust-num") {
$('#savetoivt-info').text("Inhaber und/oder Rechungsempfänger hat keine Kundennummer!");
}
if(data.reason == "ivt-exist") {
$('#savetoivt-info').text("Kunde existiert bereits im IVT!");
}
} else {
$('#savetoivt-info').text("Fehler bei übertragung.");
}
$('#savetoivt-button').prop("disabled", false);
}
},
"json"
);
});
<?php endif; ?>
$('#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();
}
}
});
/*$('#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);
$('#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);
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();
}
},
'json');
addNewProductLine(Number(id) + 1);
}
/*********************
* Form validation
*/
// iban validation
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;
}
}
function validateOrderForm() {
var allFields = [
"owner_company", "owner_firstname", "owner_lastname", "owner_street", "owner_zip", "owner_city", "owner_country", "owner_phone", "owner_email",
"billing_company", "billing_firstname", "billing_lastname", "billing_street", "billing_zip", "billing_city", "billing_country", "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") {
checkEmpty.push("bank_account_bank");
checkEmpty.push("bank_account_owner");
checkEmpty.push("bank_account_bic");
if(!validateIban($("#bank_account_iban").val())) {
$("#bank_account_iban").addClass("invalid");
$("#iban_error").show();
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="Verrechnungsperiode"> \
<option value="1">Monatlich</option> \
<option value="12">Jährlich</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"> \
<!-- line 2 --> \
<div class="col-8"> \
<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="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_nne-' + 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"); ?>