Files
thetool/Layout/default/Contract/ProductchangeForm.php
2024-04-18 22:58:37 +02:00

344 lines
17 KiB
PHP

<?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("Contract")?>">Aktive Produkte</a></li>
<li class="breadcrumb-item"><a href="<?=self::getUrl("Contract", "view", ['id' => $contract->id])?>"><?=$contract->product_name?> [<?=$contract->matchcode?>]</a></li>
<li class="breadcrumb-item active">Konfiguration</li>
</ol>
</div>
<h4 class="page-title">Aktives Produkt</h4>
</div>
</div>
</div>
<!-- end page title -->
<div class="row">
<div class="col-lg-12">
<div class="card">
<div class="card-body">
<a href="<?=self::getUrl("Contract","View", ['id' => $contract->id, 'filter' => $filter, 's' => $s])?>" class="btn btn-sm btn-secondary mr-1"><i class="fas fa-list"></i> Zurück zur Vertragsansicht</a>
</div>
</div>
<div class="card">
<div class="card-body">
<h3 class="text-center mb-3"><?=$contract->product_name?> (<?=$contract->id?>)</h3>
<table class="table table-sm table-striped view-table">
<tr>
<th style="max-width: 50vw;">Matchcode:</th>
<td style="width: 50vw;"><?=$contract->matchcode?></td>
</tr>
<tr>
<th>Vertragsinhaber:</th>
<td><a href="<?=self::getUrl("Address", "View", ["id" => $contract->owner->id])?>"><?=$contract->owner->getCompanyOrName()?> (<?=$contract->owner->customer_number?>)</a></td>
</tr>
<tr>
<th>Produkt:</th>
<td><?=$contract->product_name?> [<?=$contract->product_id?>]<?=($contract->product_name != $contract->product->name) ? " <i>(".$contract->product->name.")</i>" : ""?></td>
</tr><tr>
<th>Produkt Info:</th>
<td><?=$contract->product_info?></td>
</tr>
</table>
</div>
</div>
<div class="card">
<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?>" />
<div class="row justify-content-center">
<div class="col-xl-6">
<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>
</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">
<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">
<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>
<?php if((is_array($contract->linkFrom) && count($contract->linkFrom)) || (is_array($contract->linkTo) && count($contract->linkTo))): ?>
<h4>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>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;
}
?>
<tr data-link-type="<?=$link->type?>">
<td>
<input type="radio" class="form-check link-keep" id="link-<?=$link->id?>-action-keep" name="links[<?=$link->id?>]" value="keep" <?=($linkcontract->cancel_date && $linkcontract->cancel_date < date('U')) ? "" : "checked='checked'"?> />
<?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?>]" value="cancel" /></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-primary" value="Produktwechsel speichern" />
</div>
</div>
</form>
</div>
</div>
<div class="card">
<div class="card-body">
<a href="<?=self::getUrl("Contract","View", ['id' => $contract->id, 'filter' => $filter, 's' => $s])?>" class="btn btn-sm btn-secondary mr-1"><i class="fas fa-list"></i> Zurück zur Vertragsansicht</a>
</div>
</div>
</div>
</div>
<script>
$(".select2").select2({
allowClear: true,
placeholder: ""
});
/*
* 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');
}
</script>
<?php include(realpath(dirname(__FILE__)."/../../$mfLayoutPackage")."/footer.php"); ?>