Files
thetool/Layout/default/Contract/include/productchange-action.php
2024-07-24 13:34:39 +02:00

359 lines
19 KiB
PHP

<div class="card border-top-purple">
<div class="card-body">
<h4 class="text-center mb-3">Neuer Contract</h4>
<form method="post" action="<?=self::getUrl("Contract", "saveProductchange")?>">
<input type="hidden" name="contract_id" value="<?=$contract->id?>"/>
<?php if($f): ?>
<input type="hidden" name="f" value="<?=$f?>" />
<?php endif; ?>
<div class="row justify-content-center">
<div class="col-xl-10">
<div class="form-group row">
<label class="col-lg-2 col-form-label" for="product_id">Produkt *</label>
<div class="col-lg-10">
<select class="form-control basicAutoComplete" autocomplete="off"
name="product_id" id="product_id"
data-url="<?=self::getUrl('Product', 'api')?>?do=findProduct&autocomplete=1"
placeholder="Tippen zum suchen..."
data-noresults-text="Keine Suchergebnisse">
<option></option>
</select>
</div>
</div>
<div class="form-group row">
<label class="col-lg-2 col-form-label" for="matchcode">Matchcode:</label>
<div class="col-lg-10">
<input type="text" class="form-control" name="matchcode" id="matchcode"
value="<?=$contract->matchcode?>">
<small class="font-italic">Eindeutige Identifizierung das Produkts. Z.B.
Anschlussadresse, Domainname usw.</small>
</div>
</div>
<?php if(
(is_array($contract->product->attributes) && count($contract->product->attributes))
&& (array_key_exists(TT_ATTRIB_TERMINATION_REQUIRED_NAME, $contract->product->attributes)
&& $contract->product->attributes[TT_ATTRIB_TERMINATION_REQUIRED_NAME]->value == 1)
|| $contract->termination_id
): ?>
<div class="form-group row" id="termination_id-line">
<?php else: ?>
<div class="form-group row hidden" id="termination_id-line">
<?php endif; ?>
<label class="col-lg-2 col-form-label" for="matchcode">Anschluss *</label>
<div class="col-lg-10">
<select name="termination_id" id="termination_id"
class="form-control select2">
<option></option>
<?php foreach($terminations as $t): ?>
<option value="<?=$t->id?>" <?=($t->id == $contract->termination_id) ? "selected='selected'" : ""?>><?=$t->code?>
- <?=$t->getAddress(true)?></option>
<?php endforeach; ?>
</select>
<small>Anschluss nicht gefunden? <a href="<?=self::getUrl("Building")?>" target="_blank">Bitte anlegen</a></small>
</div>
</div>
<div class="form-group row">
<label class="col-lg-2 col-form-label" for="product_name">Individueller
Produktname:</label>
<div class="col-lg-10">
<input type="text" class="form-control" name="product_name"
id="product_name" value="<?=$contract->product_name?>">
<small class="font-italic">Scheint statt dem echten Produktnamen auf der
Rechnung auf</small>
</div>
</div>
<div class="form-group row">
<label class="col-lg-2 col-form-label" for="product_info">Produkt
Zusatztext:</label>
<div class="col-lg-10">
<input type="text" class="form-control" name="product_info"
id="product_info" value="<?=$contract->product_info?>">
</div>
</div>
<div class="form-group row">
<label class="col-lg-2 col-form-label" for="price_setup">Preis Setup:</label>
<div class="col-lg-10">
<input type="text" class="form-control" name="price_setup" id="price_setup"
value="<?=$contract->price_setup?>">
</div>
</div>
<div class="form-group row">
<label class="col-lg-2 col-form-label" for="price">Preis Periodisch:</label>
<div class="col-lg-10">
<input type="text" class="form-control" name="price" id="price"
value="<?=$contract->price?>">
</div>
</div>
<div class="form-group row <?=$me->isAdmin() ? "" : "hidden"?>">
<label class="col-lg-2 col-form-label" for="price_nne">Preis NNE</label>
<div class="col-lg-10">
<input type="text" class="form-control" name="price_nne" id="price_nne"
value="<?=$contract->price_nne?>">
</div>
</div>
<div class="form-group row <?=$me->isAdmin() ? "" : "hidden"?>">
<label class="col-lg-2 col-form-label" for="price_nbe">Preis NBE</label>
<div class="col-lg-10">
<input type="text" class="form-control" name="price_nbe" id="price_nbe"
value="<?=$contract->price_nbe?>">
</div>
</div>
<div class="form-group row">
<label class="col-lg-2 col-form-label"
for="billing_period">Verrechnungsperiode *</label>
<div class="col-lg-10">
<select class="form-control" name="billing_period" id="billing_period"
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>
<div class="form-group row">
<label class="col-lg-2 col-form-label" for="billing_delay">Verzögerter
Verrechnungsstart</label>
<div class="col-lg-10">
<input type="text" class="form-control" name="billing_delay"
id="billing_delay" placeholder="Freimonate"
value="<?=$contract->billing_delay?>">
</div>
</div>
<div class="form-group row">
<label class="col-lg-2 col-form-label" for="billing_delay">Fertigstellungsdatum</label>
<div class="col-lg-10">
<input type="text" class="form-control" name="finish_date" id="finish_date" value="" />
</div>
</div>
<?php if((is_array($contract->linkFrom) && count($contract->linkFrom)) || (is_array($contract->linkTo) && count($contract->linkTo))): ?>
<h4 class="mt-4">Verknüpfte Verträge</h4>
<table class="table table-striped table-sm table-bordered table-hover"
id="link-table">
<tr>
<th title="Verlinkten Contract mit neuem Contract verknüpfen">
Übernehmen
</th>
<th title="Verlinkten Contract mit altem Contract zusammen kündigen">
Kündigen
</th>
<th>Kü.Datum</th>
<th>Kunde</th>
<th>Contract ID</th>
<th>Produkt</th>
<th>Matchcode</th>
<th>Bestelldatum</th>
<th>Fertigstellung</th>
<th>Kündigung</th>
</tr>
<?php foreach($contract->linksWithCredit as $link): ?>
<?php
if($link->contract_id == $contract->id) {
$linkcontract = $link->origin;
} else {
$linkcontract = $link->contract;
}
if($linkcontract->isCancelled()) continue;
?>
<tr data-link-type="<?=$link->type?>" class="<?=($hide_credit && $link->type == "credit") ? "hidden" : ""?>">
<td>
<input type="radio" class="form-check link-keep"
id="link-<?=$link->id?>-action-keep"
name="links[<?=$link->id?>][action]"
value="keep" <?=($linkcontract->cancel_date && $linkcontract->cancel_date < date('U')) ? "" : "checked='checked'"?>
onchange="linkActionChange(<?=$link->id?>)" />
<?php if($link->type == "credit"): ?>
(Gutschrift wird neu erstellt)
<?php endif; ?>
</td>
<td>
<input type="radio" class="form-check link-cancel"
id="link-<?=$link->id?>-action-cancel"
name="links[<?=$link->id?>][action]" value="cancel"
onchange="linkActionChange(<?=$link->id?>)" />
</td>
<td>
<input type="text" class="form-control hidden" id="link-<?=$link->id?>-cancel_date" name="links[<?=$link->id?>][cancel_date]" value="<?=$linkcontract->getRegularCanceldate()?>" />
</td>
<td>
<a href="<?=self::getUrl("Address", "View", ["id" => $linkcontract->owner_id])?>" target="_blank"><?=$linkcontract->owner->getCompanyOrName()?></a>
</td>
<td class="contract <?=($linkcontract->isCancelled()) ? "canceled" : ""?>">
<a href="<?=self::getUrl("Contract", "View", ["contract_id" => $linkcontract->id])?>" target="_blank"><?=$linkcontract->id?></a>
</td>
<td class="contract <?=($linkcontract->isCancelled()) ? "canceled" : ""?>">
<a href="<?=self::getUrl("Contract", "View", ["contract_id" => $linkcontract->id])?>" target="_blank"><?=$linkcontract->product_name?></a>
</td>
<td class="contract <?=($linkcontract->isCancelled()) ? "canceled" : ""?>">
<a href="<?=self::getUrl("Contract", "View", ["contract_id" => $linkcontract->id])?>" target="_blank"><?=$linkcontract->matchcode?></a>
</td>
<td class="contract <?=($linkcontract->isCancelled()) ? "canceled" : ""?>"><?=($linkcontract->order_date) ? date('d.m.Y', $linkcontract->order_date) : ""?></td>
<td class="contract <?=($linkcontract->isCancelled()) ? "canceled" : ""?>"><?=($linkcontract->finish_date) ? date('d.m.Y', $linkcontract->finish_date) : ""?></td>
<td class="contract <?=($linkcontract->isCancelled()) ? "canceled" : ""?>"><?=($linkcontract->cancel_date) ? date('d.m.Y', $linkcontract->cancel_date) : ""?></td>
</tr>
<?php endforeach; ?>
</table>
<?php endif; ?>
<!-- TODO: Fileupload -->
<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"><?=$contract->note?></textarea>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col text-center">
<input type="submit" class="btn btn-purple" value="Produktwechsel speichern"/>
</div>
</div>
</form>
</div>
</div>
<script>
$(".select2").select2({
allowClear: true,
placeholder: ""
});
$("#finish_date").datepicker({
language: 'de',
format: "dd.mm.yyyy",
showWeekDays: true,
todayBtn: 'linked',
autoclose: true
});
/*
* product autocomplete
*/
<?php if($contract->product_id && is_object(($contract->product))): ?>
$('#product_id').autoComplete('set', {
value: <?=$contract->product_id?>,
text: '<?=($contract->product_id) ? str_replace("'", "\\'", str_replace(["\n", "\r"], " ", $contract->product->name)) . " [" . $contract->product_id . "]" : ""?>'
});
<?php else: ?>
$('#product_id').autoComplete();
<?php endif; ?>
$('#product_id').keydown(function () {
if (event.keyCode == 13) {
event.preventDefault();
return false;
}
});
$('#product_id').on("autocomplete.select", function (evt, item) {
if (item && item.value === 0) {
$('#product_id').autoComplete('set', null);
}
if (item && item.value) {
updateProduct(item.value);
}
});
// product autocomplete
function updateProduct() {
var pid = $('input[name=product_id]').val();
$.get("<?=self::getUrl("Product", "Api")?>",
{
"do": "getProduct",
product_id: pid
},
function (success) {
//console.log(success);
p = success.result.product;
$('#product_name').val(p.name);
//$('#product_info').val(p.name);
$('#billing_delay').val(p.billing_delay);
$('#billing_period').val(p.billing_period);
$('#price').val(p.price);
$('#price_setup').val(p.price_setup);
$('#price_nne').val(p.price_nne);
$('#price_nbe').val(p.price_nbe);
if (typeof p.attributes === 'object' && "termination_required" in p.attributes && p.attributes.termination_required == 1) {
$('#termination_id-line').show();
$('#termination_id').select2({
allowClear: true,
placeholder: ""
});
} else {
$('#termination_id-line').hide();
//$('#termination_id-' + id + '-line').hide();
}
// set credit-link to cancel if new product does not need credit
const attrib = p.attributes;
let crediting_partner = false;
let crediting_rate = 0;
if (crediting_partner in p.attributes) {
crediting_partner = parseInt(p.attributes.crediting_partner);
}
if (crediting_rate in p.attributes) {
crediting_rate = parseFloat(p.attributes.crediting_rate);
}
let price_nne = parseFloat(p.price_nne);
//console.log(p.price_nne, crediting_partner, crediting_rate);
if (price_nne || (crediting_partner && crediting_rate)) {
$("#link-table tr[data-link-type='credit'] input.link-keep").prop("checked", "checked");
}
if (!price_nne && (!crediting_partner || !crediting_rate)) {
$("#link-table tr[data-link-type='credit'] input.link-cancel").prop("checked", "checked");
}
},
'json');
}
function linkActionChange(link_id) {
//console.log($("#link-" + link_id + "-action-cancel").prop("checked"));
if($("#link-" + link_id + "-action-cancel").prop("checked") && $("#finish_date").val()) {
$("#link-" + link_id + "-cancel_date").show();
} else {
$("#link-" + link_id + "-cancel_date").hide();
}
//link-<?=$link->id?>-action-cancel
}
</script>