WIP Productchange 2024-07-16
This commit is contained in:
@@ -46,6 +46,11 @@
|
||||
</tr><tr>
|
||||
<th>Produkt Info:</th>
|
||||
<td><?=$contract->product_info?></td>
|
||||
</tr><tr>
|
||||
<th>Verrechnungsperiode:</th>
|
||||
<td>
|
||||
<?=__($contract->billing_period, "billing_period")?>
|
||||
</td>
|
||||
</tr><tr>
|
||||
<th>Fertigstellungsdatum:</th>
|
||||
<td><?=date("d.m.Y",$contract->finish_date)?></td>
|
||||
@@ -75,7 +80,7 @@
|
||||
<div class="form-group row">
|
||||
<label class="col-lg-2 col-form-label" for="cancel_date">Kündigungsdatum:</label>
|
||||
<div class="col-lg-10">
|
||||
<input type="text" class="form-control" name="cancel_date" id="cancel_date" value="<?=($term_end_date) ? $term_end_date->format("d.m.Y") : ""?>">
|
||||
<input type="text" class="form-control" name="cancel_date" id="cancel_date" value="<?=($term_end_date) ? $term_end_date : ""?>">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -84,8 +89,8 @@
|
||||
<div class="col-lg-10">
|
||||
<button type="button" class="btn btn-outline-primary" onclick="setCancelDate('<?=date("d.m.Y")?>')">Heute</button>
|
||||
<button type="button" class="btn btn-outline-primary" onclick="setCancelDate('<?=($tomorrow) ? $tomorrow->format("d.m.Y") : ""?>')">Morgen</button>
|
||||
<button type="button" class="btn btn-outline-primary" onclick="setCancelDate('<?=($term_end_date) ? $term_end_date->format("d.m.Y") : ""?>')">Ende der Vertragslaufzeit</button>
|
||||
<button type="button" class="btn btn-outline-primary" onclick="setCancelDate('<?=($period_end_date) ? $period_end_date->format("d.m.Y") : ""?>')">Ende der aktuellen Rechnungsperiode</button>
|
||||
<button type="button" class="btn btn-outline-primary" onclick="setCancelDate('<?=($term_end_date) ? $term_end_date : ""?>')">Ende der Vertragslaufzeit</button>
|
||||
<button type="button" class="btn btn-outline-primary" onclick="setCancelDate('<?=($period_end_date) ? $period_end_date : ""?>')">Ende der aktuellen Rechnungsperiode</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -122,6 +127,7 @@
|
||||
$linkcontract = $link->contract;
|
||||
}
|
||||
|
||||
if($linkcontract->isCancelled()) continue;
|
||||
if(!$linkcontract->billing_period) continue;
|
||||
|
||||
?>
|
||||
|
||||
@@ -86,7 +86,7 @@
|
||||
<div class="form-group row" id="termination_row">
|
||||
<label class="col-lg-2 col-form-label" for="matchcode">Anschluss *</label>
|
||||
<div class="col-lg-10">
|
||||
<select name="products[<?=$i?>][termination_id]" id="termination_id-<?=$i?>" class="form-control select2">
|
||||
<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()?></option>
|
||||
|
||||
@@ -6,9 +6,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("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"><a
|
||||
href="<?=self::getUrl("Contract", "view", ['id' => $contract->id])?>"><?=$contract->product_name?>
|
||||
[<?=$contract->matchcode?>]</a></li>
|
||||
<li class="breadcrumb-item active">Product-/Standortwechsel</li>
|
||||
</ol>
|
||||
</div>
|
||||
@@ -23,7 +26,8 @@
|
||||
|
||||
<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>
|
||||
<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>
|
||||
|
||||
@@ -35,17 +39,37 @@
|
||||
<tr>
|
||||
<th style="max-width: 50vw;">Matchcode:</th>
|
||||
<td style="width: 50vw;"><?=$contract->matchcode?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
</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>
|
||||
<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>
|
||||
<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><tr>
|
||||
<th>Preis Netto:</th>
|
||||
<td class="<?=($contract->price < 0) ? "text-danger" : ""?>">€ <?=number_format(($contract->amount != 1) ? $contract->price * $contract->amount : $contract->price, 4, ",", ".")?></td>
|
||||
</tr><tr>
|
||||
<th>Preis Brutto:</th>
|
||||
<td class="<?=($contract->price < 0) ? "text-danger" : ""?>">€
|
||||
<?php if($contract->price && $contract->vatrate): ?>
|
||||
<?php if($contract->amount != 1): ?>
|
||||
<?=number_format($contract->price + ($contract->price / 100) * $contract->vatrate, 4, ",", ".")?>
|
||||
<?php else: ?>
|
||||
<?=number_format(($contract->price + ($contract->price / 100) * $contract->vatrate) * $contract->amount, 4, ",", ".")?>
|
||||
<?php endif; ?>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
</tr><tr>
|
||||
<th>Fertigstellungsdatum:</th>
|
||||
<td><?=date("d.m.Y", $contract->finish_date)?></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
@@ -61,12 +85,16 @@
|
||||
<input type="hidden" name="contract_id" value="<?=$contract->id?>"/>
|
||||
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-xl-6">
|
||||
<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">
|
||||
<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>
|
||||
@@ -75,8 +103,10 @@
|
||||
<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>
|
||||
<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>
|
||||
|
||||
@@ -92,72 +122,99 @@
|
||||
<?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">
|
||||
<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>
|
||||
<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>
|
||||
<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>
|
||||
<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>
|
||||
<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?>">
|
||||
<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?>">
|
||||
<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?>">
|
||||
<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?>">
|
||||
<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?>">
|
||||
<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>
|
||||
<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 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>
|
||||
<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?>">
|
||||
<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>
|
||||
|
||||
@@ -165,10 +222,16 @@
|
||||
<?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">
|
||||
<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 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>
|
||||
@@ -184,22 +247,43 @@
|
||||
$linkcontract = $link->origin;
|
||||
} else {
|
||||
$linkcontract = $link->contract;
|
||||
|
||||
}
|
||||
|
||||
if($linkcontract->isCancelled()) continue;
|
||||
|
||||
?>
|
||||
<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'"?> />
|
||||
<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?>]" 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>
|
||||
<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>
|
||||
@@ -214,7 +298,8 @@
|
||||
<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>
|
||||
<textarea id="note" class="form-control" name="note"
|
||||
rows="5"><?=$contract->note?></textarea>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -222,8 +307,6 @@
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
<div class="row">
|
||||
<div class="col text-center">
|
||||
<input type="submit" class="btn btn-primary" value="Produktwechsel speichern"/>
|
||||
@@ -236,10 +319,10 @@
|
||||
</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>
|
||||
<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>
|
||||
|
||||
@@ -252,11 +335,21 @@
|
||||
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."]" : ""?>'});
|
||||
$('#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; ?>
|
||||
@@ -276,8 +369,8 @@
|
||||
updateProduct(item.value);
|
||||
}
|
||||
});
|
||||
// product autocomplete
|
||||
|
||||
// product autocomplete
|
||||
|
||||
|
||||
function updateProduct() {
|
||||
@@ -339,6 +432,16 @@
|
||||
'json');
|
||||
|
||||
}
|
||||
|
||||
function linkActionChange(link_id) {
|
||||
//console.log($("#link-" + link_id + "-action-cancel").prop("checked"));
|
||||
if($("#link-" + link_id + "-action-cancel").prop("checked")) {
|
||||
$("#link-" + link_id + "-cancel_date").show();
|
||||
} else {
|
||||
$("#link-" + link_id + "-cancel_date").hide();
|
||||
}
|
||||
//link-<?=$link->id?>-action-cancel
|
||||
}
|
||||
</script>
|
||||
|
||||
<?php include(realpath(dirname(__FILE__) . "/../../$mfLayoutPackage") . "/footer.php"); ?>
|
||||
@@ -24,7 +24,6 @@
|
||||
<div class="card-body">
|
||||
<a href="<?=self::getUrl("Contract","Index")?>" class="btn btn-sm btn-secondary mr-1"><i class="fas fa-list"></i> Zurück zur Vertragsübersicht</a>
|
||||
<a href="<?=self::getUrl("Contract","edit", ['contract_id' => $contract->id, 'f' => "view"])?>" class="btn btn-sm btn-outline-success"><i class="fas fa-edit"></i> Vertrag bearbeiten</a>
|
||||
<?php if($me->username == "fronk"): ?><a href="<?=self::getUrl("Contract","sendCancelNotification", ['contract_id' => $contract->id])?>" class="btn btn-sm btn-purple"><i class="fas fa-edit"></i> Temp button</a><?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -64,7 +63,7 @@
|
||||
<th>Upgrade auf:</th>
|
||||
<td>
|
||||
<?php foreach($contract->upgradeTo as $link): ?>
|
||||
<a href="<?=self::getUrl("Contract", "View", ["contract_id" => $link->contract_id])?>" class="contract-link <?=($link->contract->cancel_date && $link->contract->cancel_date <= date('U')) ? "canceled" : ""?>"><?=$link->contract->product_name?> [<?=$link->contract->matchcode?>] (<?=$link->contract_id?>)</a><br />
|
||||
<a href="<?=self::getUrl("Contract", "View", ["contract_id" => $link->contract_id])?>" class="contract-link <?=($link->contract->cancel_date && $link->contract->cancel_date <= date('U')) ? "canceled" : ""?> <?=(!$link->contract->isFinished()) ? "not-finished" : "" ?>"><?=$link->contract->product_name?> [<?=$link->contract->matchcode?>] (<?=$link->contract_id?>)</a><br />
|
||||
<?php endforeach; ?>
|
||||
</td>
|
||||
</tr>
|
||||
@@ -233,7 +232,7 @@
|
||||
<a href="<?=self::getUrl("Contract", "productchange", ["contract_id" => $contract->id])?>"><button type="button" class="btn btn-sm btn-outline-purple"><i class="far fa-truck-container fa-fw"></i> Produkt-/Standortwechsel</button></a>
|
||||
<a href="<?=self::getUrl("Contract", "cancel", ["contract_id" => $contract->id])?>"><button type="button" class="btn btn-sm btn-outline-danger"><i class="far fa-axe fa-fw"></i> Kündigen</button></a>
|
||||
<?php else: ?>
|
||||
<a href="<?=self::getUrl("Contract", "finishContract", ['contract_id' => $contract->id])?>" onclick="if(!confirm('Jetzt fertigstellen und in Verrechnung geben?')) return false"><button type="button" class="btn btn-sm btn-success"><i class="far fa-face-confused fa-fw"></i> Fertigstellen</button></a>
|
||||
<a href="<?=self::getUrl("Contract", "finishContract", ['contract_id' => $contract->id])?>" onclick="if(!confirm('Jetzt fertigstellen und in Verrechnung geben?')) return false"><button type="button" class="btn btn-sm btn-success"><i class="far fa-face-confused fa-fw"></i> Jetzt fertigstellen</button></a>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
</tr>
|
||||
@@ -290,11 +289,13 @@
|
||||
<td><i class="fas fa-cogs text-secondary pl-1"></i></td>
|
||||
<td style="width: 100%">
|
||||
<?php if($j->value == "manual"): ?>
|
||||
<em>Vertrag manuell angelegt</em>
|
||||
<em>Vertrag manuell erstellt</em>
|
||||
<?php elseif($j->value == "import"): ?>
|
||||
<em>Vertrag importiert: <?=nl2br(htmlentities($j->text))?>
|
||||
<?php elseif($j->value == "order"): ?>
|
||||
<em>Vertrag aus Bestellung <a href="<?=self::getUrl("Order", "edit", ["id" => $contract->orderproduct->order_id])?>">#<?=$contract->orderproduct->order_id?></a> erstellt
|
||||
<?php elseif($j->value == "productchange"): ?>
|
||||
<em>Vertrag erstellt: <?=nl2br(htmlentities($j->text))?>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
<?php elseif($j->type == "contract_finished"): ?>
|
||||
@@ -311,7 +312,9 @@
|
||||
<?php $link = new Contract($j->value); ?>
|
||||
<td><i class="fas fa-link text-secondary pl-1"></i></td>
|
||||
<td style="width: 100%"><em>Verknüpfung mit <a href="<?=self::getUrl("Contract", "view", ['contract_id' => $link->id])?>"><?=$link->id?> - <?=$link->product_name?> [<?=$link->matchcode?>]</a> erstellt</em></td>
|
||||
|
||||
<?php elseif($j->type == "canceled"): ?>
|
||||
<td><i class="fas fa-skull-crossbones bg-danger text-white p-1"></i></td>
|
||||
<td style="width: 100%"><em>Vertag gekündigt</em></td>
|
||||
<?php endif; ?>
|
||||
<td style="white-space: nowrap">
|
||||
<a href="<?=self::getUrl("Contractjournal", "edit", ["journal_id" => $j->id])?>" title="Journaleintrag bearbeiten"><i class="fas fa-edit"></i></a>
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
class Contract extends mfBaseModel {
|
||||
protected $forcestr = ["product_name", "product_info", "matchcode"];
|
||||
private $in_after_save = 0;
|
||||
|
||||
private $owner;
|
||||
private $billingaddress;
|
||||
@@ -38,11 +39,104 @@ class Contract extends mfBaseModel {
|
||||
|
||||
|
||||
protected function afterSave() {
|
||||
if($this->in_after_save) return true;
|
||||
$this->in_after_save++;
|
||||
|
||||
if($this->billingaddress_id) {
|
||||
$this->getProperty("billingaddress")->generateFibuAccountNumber();
|
||||
}
|
||||
|
||||
$this->runTriggers();
|
||||
|
||||
$this->in_after_save--;
|
||||
}
|
||||
|
||||
public function runTriggers() {
|
||||
$dir = opendir(__DIR__."/trigger");
|
||||
while($filename = readdir($dir)) {
|
||||
if(strpos($filename, ".") === 0 ) continue;
|
||||
$m = [];
|
||||
if(!preg_match('/^([a-z0-9_]+)\.php$/i', $filename, $m)) continue;
|
||||
$trigger_name = $m[1];
|
||||
$classname = "ContractTrigger_$trigger_name";
|
||||
$filepath = __DIR__."/trigger/$trigger_name.php";
|
||||
|
||||
$this->log->debug(__METHOD__.": Looking for $classname in $filepath");
|
||||
|
||||
if(!file_exists($filepath)) {
|
||||
$this->log->debug(__METHOD__.": $filepath not found");
|
||||
continue;
|
||||
}
|
||||
|
||||
require_once $filepath;
|
||||
|
||||
if(!class_exists($classname)) {
|
||||
$this->log->debug(__METHOD__.": $classname not found");
|
||||
continue;
|
||||
}
|
||||
|
||||
$me = new User();
|
||||
$me->loadMe();
|
||||
|
||||
$injection = [
|
||||
"db" => $this->db,
|
||||
"log" => $this->log,
|
||||
"me" => $me,
|
||||
"contract" => $this
|
||||
];
|
||||
|
||||
try {
|
||||
$trigger = new $classname($injection);
|
||||
if($trigger->precheck()) {
|
||||
$this->log->debug(__METHOD__.": precheck successful: running");
|
||||
$trigger->run();
|
||||
}
|
||||
} catch(Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function getRegularCanceldate($format = "d.m.Y") {
|
||||
if(!$this->finish_date) return "";
|
||||
|
||||
$today = new DateTime();
|
||||
$tomorrow = clone($today);
|
||||
$tomorrow->modify("+1 day");
|
||||
|
||||
$finish_date = new DateTime("@".$this->finish_date);
|
||||
$finish_date->setTimezone(new DateTimeZone("Europe/Vienna"));
|
||||
|
||||
$period_end_date = clone($finish_date);
|
||||
$period_end_date->modify("+".$this->contract_term." months");
|
||||
|
||||
while($period_end_date->format("Y-m-d") <= $today->format("Y-m-d")) {
|
||||
$period_end_date = $period_end_date->modify("+".$this->billing_period." months");
|
||||
|
||||
}
|
||||
$period_end_date->modify("-1 day");
|
||||
return $period_end_date->format($format);
|
||||
}
|
||||
|
||||
public function getNextBillingPeriodEnd($format = "d.m.Y") {
|
||||
if(!$this->finish_date) return "";
|
||||
|
||||
$today = new DateTime();
|
||||
|
||||
$finish_date = new DateTime("@".$this->finish_date);
|
||||
$finish_date->setTimezone(new DateTimeZone("Europe/Vienna"));
|
||||
|
||||
$next_billing_period = clone($finish_date);
|
||||
$next_billing_period->modify("+".$this->billing_period." months");
|
||||
while($next_billing_period->format("Y-m-d") <= $today->format("Y-m-d")) {
|
||||
$next_billing_period->modify("+".$this->billing_period." months");
|
||||
}
|
||||
$next_billing_period->modify("-1 day");
|
||||
|
||||
return $next_billing_period->format($format);
|
||||
}
|
||||
|
||||
private function getLinks() {
|
||||
$this->linkFrom = [];
|
||||
@@ -385,14 +479,6 @@ class Contract extends mfBaseModel {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*if($name == "contractConfigItems") {
|
||||
$product = $this->getProperty("product");
|
||||
|
||||
@@ -411,7 +497,8 @@ class Contract extends mfBaseModel {
|
||||
$vatrate = $vatgroup->rates["domestic"]->rate;
|
||||
if($this->country_id && $country->is_eu) {
|
||||
$vatrate = $vatgroup->rates["eu"]->rate;
|
||||
} if($this->country_id && !$country->is_eu) {
|
||||
}
|
||||
if($this->country_id && !$country->is_eu) {
|
||||
$vatrate = $vatgroup->rates["other"]->rate;
|
||||
}
|
||||
$this->vatrate = $vatrate;
|
||||
@@ -530,7 +617,6 @@ class Contract extends mfBaseModel {
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* When object is cloned, new object will call this funtion to let us clean up the new Contract.
|
||||
* Throws Exception if cloning fails.
|
||||
|
||||
@@ -140,34 +140,13 @@ class ContractController extends mfBaseController
|
||||
$this->redirect("Contract", "view", ["contract_id" => $contract->id]);
|
||||
}
|
||||
|
||||
if($contract->finish_date) {
|
||||
$today = new DateTime();
|
||||
$tomorrow = clone($today);
|
||||
$tomorrow->modify("+1 day");
|
||||
|
||||
$finish_date = new DateTime("@".$contract->finish_date);
|
||||
$finish_date->setTimezone(new DateTimeZone("Europe/Vienna"));
|
||||
|
||||
$period_end_date = clone($finish_date);
|
||||
$period_end_date->modify("+".$contract->contract_term." months");
|
||||
|
||||
while($period_end_date->format("Y-m-d") <= $today->format("Y-m-d")) {
|
||||
$period_end_date = $finish_date->modify("+".$contract->billing_period." months");
|
||||
|
||||
}
|
||||
$period_end_date->modify("-1 day");
|
||||
|
||||
$next_billing_period = clone($finish_date);
|
||||
$next_billing_period->modify("+".$contract->billing_period." months");
|
||||
while($next_billing_period->format("Y-m-d") <= $today->format("Y-m-d")) {
|
||||
$next_billing_period->modify("+".$contract->billing_period." months");
|
||||
}
|
||||
$next_billing_period->modify("-1 day");
|
||||
|
||||
$this->layout()->set("tomorrow", $tomorrow);
|
||||
$this->layout()->set("term_end_date", $period_end_date);
|
||||
$this->layout()->set("period_end_date", $next_billing_period);
|
||||
}
|
||||
$this->layout()->set("term_end_date", $contract->getRegularCanceldate());
|
||||
$this->layout()->set("period_end_date", $contract->getNextBillingPeriodEnd());
|
||||
|
||||
|
||||
$this->layout()->set("contract", $contract);
|
||||
@@ -191,7 +170,7 @@ class ContractController extends mfBaseController
|
||||
|
||||
try {
|
||||
$cancel_date = DateTime::createFromFormat("d.m.Y", trim($r->cancel_date), new DateTimeZone("Europe/Vienna"));
|
||||
$cancel_date->setTime(2,0,0);
|
||||
$cancel_date->setTime(23,59,59);
|
||||
} catch(Exception $e) {
|
||||
$this->layout()->setFlash("Ungültiges Datumsformat");
|
||||
$this->redirect("Contract", "cancel", ["contract_id" => $contract->id]);
|
||||
@@ -288,6 +267,7 @@ class ContractController extends mfBaseController
|
||||
protected function saveProductchangeAction()
|
||||
{
|
||||
$r = $this->request;
|
||||
//var_dump($r->links);exit;
|
||||
|
||||
$id = $r->contract_id;
|
||||
if (!is_numeric($id) || !$id) {
|
||||
@@ -330,6 +310,22 @@ class ContractController extends mfBaseController
|
||||
$contract_data['product_external_id'] = $product->external_id;
|
||||
$contract_data['sla_id'] = $product->sla_id;
|
||||
|
||||
if($r->finish_date) {
|
||||
try {
|
||||
$finish_date = DateTime::createFromFormat("d.m.Y", $r->finish_date, new DateTimeZone("Europe/Vienna"));
|
||||
} catch (Exception $e) {
|
||||
$this->layout()->setFlash("Ungültiges Kündigungsdateum", "error");
|
||||
$this->redirect("Contract", "productchange", ["contract_id" => $id]);
|
||||
}
|
||||
|
||||
$finish_date->setTime(0,0,0);
|
||||
$contract_data["finish_date"] = $finish_date->getTimestamp();
|
||||
|
||||
$contract_cancel_date = clone($finish_date);
|
||||
$contract_cancel_date->modify("-1 day");
|
||||
$contract_cancel_date->setTime(23,59,59);
|
||||
}
|
||||
|
||||
$require_term = false;
|
||||
if (array_key_exists(TT_ATTRIB_TERMINATION_REQUIRED_NAME, $product->attributes) && $product->attributes[TT_ATTRIB_TERMINATION_REQUIRED_NAME]->value == 1) {
|
||||
//var_dump($prod->attributes);
|
||||
@@ -353,23 +349,54 @@ class ContractController extends mfBaseController
|
||||
$this->redirect("Contract", "productchange", ["contract_id" => $id]);
|
||||
}
|
||||
|
||||
if($contract_cancel_date) {
|
||||
$contract->cancel_date = $contract_cancel_date->getTimestamp();
|
||||
$contract->save();
|
||||
}
|
||||
|
||||
$journal = ContractjournalModel::create([
|
||||
'contract_id' => $new_contract->id,
|
||||
'type' => "created_from",
|
||||
'value' => "productchange",
|
||||
'text' => "Produkt-/Standortwechsel von Contract ID ".$contract->id
|
||||
]);
|
||||
$journal->save();
|
||||
|
||||
if (is_array($r->links) && count($r->links)) {
|
||||
foreach ($r->links as $link_id => $action) {
|
||||
foreach ($r->links as $link_id => $link_data) {
|
||||
$action = $link_data["action"];
|
||||
$cancel_date = false;
|
||||
if($link_data["cancel_date"]) {
|
||||
try {
|
||||
$cancel_date = DateTime::createFromFormat("d.m.Y", $link_data["cancel_date"], new DateTimeZone("Europe/Vienna"));
|
||||
} catch (Exception $e) {
|
||||
$this->layout()->setFlash("Ungültiges Kündigungsdateum", "error");
|
||||
$this->redirect("Contract", "productchange", ["contract_id" => $id]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$old_link = new ContractLink($link_id);
|
||||
if (!$old_link->id) continue;
|
||||
|
||||
// check if link contains this contract
|
||||
if ($old_link->contract_id == $contract->id) {
|
||||
$origin_id = $old_link->origin_contract_id;
|
||||
$link_contract_id = $old_link->contract_id;
|
||||
|
||||
$new_link_contract_id = $new_contract->id;
|
||||
$new_link_origin_id = $old_link->origin_contract_id;
|
||||
} elseif ($old_link->origin_contract_id == $contract->id) {
|
||||
$origin_id = $old_link->contract_id;
|
||||
$link_contract_id = $old_link->origin_contract_id;
|
||||
|
||||
$new_link_contract_id = $old_link->contract_id;
|
||||
$new_link_origin_id = $new_contract->id;
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
|
||||
if($action != "cancel" && $old_link->type != "credit") {
|
||||
$new_link = ContractLinkModel::create([
|
||||
'contract_id' => $new_link_contract_id,
|
||||
'origin_contract_id' => $new_link_origin_id,
|
||||
@@ -378,16 +405,68 @@ class ContractController extends mfBaseController
|
||||
if (!$new_link->save()) {
|
||||
$this->layout()->setFlash("Konnte neuen Link nicht speichern", "warn");
|
||||
}
|
||||
}
|
||||
|
||||
if ($action == "cancel") {
|
||||
if($cancel_date) {
|
||||
// insert cancel_date in old contract
|
||||
$lc = new Contract($origin_id);
|
||||
$lc->cancel_date = $cancel_date->getTimestamp();
|
||||
$lc->save();
|
||||
} else {
|
||||
// leave cancellation for later (when finishing upgrade)
|
||||
$old_link->change_action = "cancel";
|
||||
if (!$old_link->save()) {
|
||||
$this->layout()->setFlash("Konnte alten Link nicht speichern", "warn");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ($old_link->type == "credit" && $action == "keep") {
|
||||
// XXX - if we have finish date then recreate credit contract right now
|
||||
if($contract_cancel_date) {
|
||||
$new_credit = ContractModel::createCreditForContract($new_contract);
|
||||
$new_credit->save();
|
||||
|
||||
// create journal for credit
|
||||
$journal = ContractjournalModel::create([
|
||||
'contract_id' => $new_credit->id,
|
||||
'type' => "created_from",
|
||||
'value' => "productchange",
|
||||
'text' => "Produkt-/Standortwechsel von Contract ID ".$new_link_origin_id
|
||||
]);
|
||||
$journal->save();
|
||||
|
||||
|
||||
$this->log->debug(print_r($new_credit, true));
|
||||
|
||||
// set cancel date for old credit
|
||||
$old_credit = new Contract($origin_id);
|
||||
$old_credit->cancel_date = $contract_cancel_date->getTimestamp();
|
||||
$old_credit->save();
|
||||
|
||||
// create link to new credit contract
|
||||
$link = ContractLinkModel::create([
|
||||
"contract_id" => $new_credit->id,
|
||||
"origin_contract_id" => $new_contract->id,
|
||||
"type" => "credit"
|
||||
]);
|
||||
$link->save();
|
||||
|
||||
// create upgrade link from old to new credit contract
|
||||
$link = ContractLinkModel::create([
|
||||
"contract_id" => $new_credit->id,
|
||||
"origin_contract_id" => $origin_id,
|
||||
"type" => "upgrade"
|
||||
]);
|
||||
$link->save();
|
||||
|
||||
} else {
|
||||
$old_link->change_action = "recreate";
|
||||
$old_link->save();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//var_dump($new_link);exit;
|
||||
@@ -439,82 +518,23 @@ class ContractController extends mfBaseController
|
||||
$this->redirect("Contract");
|
||||
}
|
||||
|
||||
$now = date('U');
|
||||
$now = new DateTime("now");
|
||||
$now->setTime(0,0,0);
|
||||
|
||||
/*
|
||||
* Vorgänger Contracts kündigen
|
||||
*/
|
||||
foreach (ContractLinkModel::search(['contract_id' => $id]) as $link) {
|
||||
if (!in_array($link->type, ["upgrade", "downgrade", "relocation", "productchange"])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$origin = $link->origin;
|
||||
$origin->cancel_date = $now;
|
||||
$origin->cancel_date_by = $this->me->id;
|
||||
$origin->edit_by = $this->me->id;
|
||||
if (!$origin->save()) {
|
||||
$this->layout()->setFlash("Achtung: Konnte nicht alle Vorgängercontracts kündigen!", "warn");
|
||||
}
|
||||
|
||||
/*
|
||||
* alte Links übernehmen / kündigen
|
||||
*/
|
||||
foreach (ContractLinkModel::search(['type' => "link", 'contract_id' => $origin->id]) as $old_link) {
|
||||
// verlinkten Contract kündigen (wenn nicht schon gekündigt)
|
||||
if ($old_link->change_action == "cancel" && !$old_link->contract->cancel_date) {
|
||||
$old_link->origin->update([
|
||||
'cancel_date' => $now,
|
||||
'cancel_date_by' => $this->me->id,
|
||||
'edit_by' => $this->me->id
|
||||
]);
|
||||
$old_link->origin->save();
|
||||
|
||||
$old_link->change_action = null;
|
||||
$old_link->save();
|
||||
}
|
||||
}
|
||||
|
||||
foreach (ContractLinkModel::search(['type' => "link", 'origin_contract_id' => $origin->id]) as $old_link) {
|
||||
// verlinkten Contract kündigen (wenn nicht schon gekündigt)
|
||||
if ($old_link->change_action == "cancel" && !$old_link->contract->cancel_date) {
|
||||
$old_link->contract->update([
|
||||
'cancel_date' => $now,
|
||||
'cancel_date_by' => $this->me->id,
|
||||
'edit_by' => $this->me->id
|
||||
]);
|
||||
$old_link->contract->save();
|
||||
|
||||
$old_link->change_action = null;
|
||||
$old_link->save();
|
||||
}
|
||||
}
|
||||
|
||||
foreach (ContractLinkModel::search(['type' => "credit", 'contract_id' => $origin->id]) as $old_credit) {
|
||||
// verlinkten Contract kündigen (wenn nicht schon gekündigt)
|
||||
if ($old_credit->change_action == "recreate" && !$old_credit->contract->cancel_date) {
|
||||
$old_credit->origin->update([
|
||||
'cancel_date' => $now,
|
||||
'cancel_date_by' => $this->me->id,
|
||||
'edit_by' => $this->me->id
|
||||
]);
|
||||
$old_credit->origin->save();
|
||||
|
||||
$old_credit->change_action = null;
|
||||
$old_credit->save();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
$contract->finish_date = $now;
|
||||
$contract->finish_date = $now->getTimestamp();
|
||||
$contract->finish_date_by = $this->me->id;
|
||||
if (!$contract->save()) {
|
||||
try {
|
||||
$saved = $contract->save();
|
||||
} catch(Exception $e) {
|
||||
$saved = false;
|
||||
}
|
||||
|
||||
if(!$saved) {
|
||||
$this->layout()->setFlash("Contract konnte nicht gespeichert werden", "error");
|
||||
$this->redirect("Contract", "view", ['contract_id' => $id]);
|
||||
}
|
||||
|
||||
|
||||
// create Journal
|
||||
$journal = ContractjournalModel::create([
|
||||
'contract_id' => $contract->id,
|
||||
@@ -620,6 +640,10 @@ class ContractController extends mfBaseController
|
||||
$contract_data['billing_delay'] = (int)$r->billing_delay;
|
||||
$contract_data['note'] = $r->note;
|
||||
|
||||
if($r->termination_id) {
|
||||
$contract_data["termination_id"] = $r->termination_id;
|
||||
}
|
||||
|
||||
if($r->order_date) {
|
||||
$order_date = new DateTime("@" . $this->dateToTimestamp($r->order_date));
|
||||
$order_date->setTimezone(new DateTimeZone("Europe/Vienna"));
|
||||
|
||||
@@ -185,6 +185,108 @@ class ContractModel {
|
||||
return $contract;
|
||||
}
|
||||
|
||||
public static function createCreditForContract($contract) {
|
||||
$log = mfLoghandler::singleton();
|
||||
$me = new User();
|
||||
$me->loadMe();
|
||||
|
||||
if(!$contract->id) {
|
||||
$log->warning(__METHOD__."(): Invalid Contractqueue object");
|
||||
return false;
|
||||
}
|
||||
|
||||
$product = $contract->product;
|
||||
$owner = $contract->owner;
|
||||
|
||||
if(!$product->id) {
|
||||
$log->warning(__METHOD__."(): Invalid Product");
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get credit price from NNE or percentage of sales price
|
||||
*/
|
||||
$crediting_partner_id = false;
|
||||
$crediting_partner_rate = false;
|
||||
|
||||
$product_attribs = $product->attributes;
|
||||
if(is_array($product_attribs) && array_key_exists("crediting_partner", $product_attribs) && $product_attribs["crediting_partner"] && is_object($product_attribs["crediting_partner"])) {
|
||||
if($product_attribs["crediting_partner"]->value) {
|
||||
$crediting_partner_id = $product_attribs["crediting_partner"]->value;
|
||||
}
|
||||
if($product_attribs["crediting_rate"]->value) {
|
||||
$crediting_partner_rate = str_replace(",", ".",$product_attribs["crediting_rate"]->value);
|
||||
}
|
||||
}
|
||||
|
||||
// or from netowner if anschluss product
|
||||
if(!$crediting_partner_id && $contract->termination_id) {
|
||||
$crediting_partner_id = $contract->termination->building->network->owner_id;
|
||||
}
|
||||
|
||||
$crediting_partner = new Address($crediting_partner_id);
|
||||
if(!$crediting_partner->id) {
|
||||
$log->error(__METHOD__.": Kein Crediting Partner gefunden für Credit für Contract ID ".$contract->id);
|
||||
return false;
|
||||
}
|
||||
|
||||
// determine price:
|
||||
// either NNE or percentage based, depends on product
|
||||
$crediting_price = $product->price_nne;
|
||||
if($crediting_partner_rate) {
|
||||
$crediting_price = round($contract->price / 100 * $crediting_partner_rate, 4);
|
||||
}
|
||||
|
||||
if(!$crediting_price) return true;
|
||||
$crediting_price *= -1;
|
||||
|
||||
$data = [];
|
||||
$data["orderproduct_id"] = null;
|
||||
$data["owner_id"] = $crediting_partner_id;
|
||||
$data["billingaddress_id"] = null;
|
||||
$data["termination_id"] = null;
|
||||
$data["product_id"] = $contract->product_id;
|
||||
$data["product_name"] = $contract->product_name;
|
||||
$data["product_info"] = $contract->product_info;
|
||||
$data["amount"] = $contract->amount;
|
||||
$data["sla_id"] = $contract->sla_id;
|
||||
$data["product_external"] = $contract->product_external;
|
||||
$data["product_external_id"] = $contract->product_external_id;
|
||||
$data["billing_delay"] = $contract->billing_delay;
|
||||
$data["billing_period"] = $contract->billing_period;
|
||||
$data["contract_term"] = $contract->contract_term;
|
||||
$data["order_date"] = $contract->order_date;
|
||||
|
||||
$data["finish_date"] = $contract->finish_date;
|
||||
$data["finish_date_by"] = $me->id;
|
||||
$data["note"] = null;
|
||||
|
||||
|
||||
// matchcode
|
||||
$owner_address = $owner->street.", ".$owner->zip." ".$owner->city;
|
||||
if($contract->termination_id) {
|
||||
$termination = new Termination($contract->termination_id);
|
||||
$termination_address = $termination->building->street.", ".$termination->building->zip." ".$termination->building->city;
|
||||
$matchcode = $termination_address;
|
||||
} else {
|
||||
$matchcode = $owner_address;
|
||||
}
|
||||
|
||||
$matchcode = $contract->owner->getCompanyOrName()."; $matchcode";
|
||||
|
||||
$data["matchcode"] = $matchcode;
|
||||
$data["price"] = $crediting_price;
|
||||
$data["price_setup"] = 0;
|
||||
$data["price_nne"] = 0;
|
||||
$data["price_nbe"] = 0;
|
||||
$data["vatgroup_id"] = $contract->vatgroup_id;
|
||||
|
||||
|
||||
$credit = ContractModel::create($data);
|
||||
|
||||
return $credit;
|
||||
}
|
||||
|
||||
public static function getAll() {
|
||||
$items = [];
|
||||
|
||||
|
||||
186
application/Contract/trigger/Finished.php
Normal file
186
application/Contract/trigger/Finished.php
Normal file
@@ -0,0 +1,186 @@
|
||||
<?php
|
||||
|
||||
class ContractTrigger_Finished {
|
||||
private $log;
|
||||
private $db;
|
||||
private $me;
|
||||
private $contract;
|
||||
public $errors;
|
||||
|
||||
public function __construct($injection = []) {
|
||||
foreach($injection as $name => $value) {
|
||||
if(in_array($name, ["log", "db", "contract", "me"])) {
|
||||
$this->$name = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks Contract if can/must run
|
||||
* return true if it wants to run
|
||||
* @return bool
|
||||
*/
|
||||
public function precheck() {
|
||||
$contract = $this->contract;
|
||||
if($contract->finish_date && !$contract->_old_data->finish_date) {
|
||||
// contract was just finished, so we need to run
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public function run() {
|
||||
$contract = $this->contract;
|
||||
if($contract->_old_data->finish_date) {
|
||||
var_dump($contract->finish_date, $contract->_old_data->finish_date);
|
||||
return true;
|
||||
}
|
||||
// contract was just finished, so we need to run
|
||||
|
||||
/*
|
||||
* Vorgänger Contracts kündigen
|
||||
*/
|
||||
foreach (ContractLinkModel::search(['contract_id' => $contract->id]) as $link) {
|
||||
if (!in_array($link->type, ["upgrade", "downgrade", "relocation", "productchange", "ownerchange"])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$now = new DateTime("now");
|
||||
$now->setTime(2,0,0);
|
||||
|
||||
$cancel_date = clone($now);
|
||||
$cancel_date->setTime(23,59,59);
|
||||
|
||||
$origin = $link->origin;
|
||||
$origin->cancel_date = $cancel_date->getTimestamp();
|
||||
$origin->cancel_date_by = $this->me->id;
|
||||
$origin->edit_by = $this->me->id;
|
||||
if (!$origin->save()) {
|
||||
throw new Exception("Fehler beim Speichern der Kündigung des Vorgängercontracts!");
|
||||
}
|
||||
// cancel journal
|
||||
$journal = ContractjournalModel::create([
|
||||
'contract_id' => $origin->id,
|
||||
'type' => "canceled",
|
||||
'value' => "",
|
||||
'text' => ""
|
||||
]);
|
||||
$journal->save();
|
||||
|
||||
|
||||
/*
|
||||
* alte Links übernehmen / kündigen
|
||||
*/
|
||||
foreach (ContractLinkModel::search(['type' => "link", 'contract_id' => $origin->id]) as $old_link) {
|
||||
// verlinkten Contract kündigen (wenn nicht schon gekündigt)
|
||||
if ($old_link->change_action == "cancel" && !$old_link->origin->cancel_date) {
|
||||
$old_link->origin->update([
|
||||
'cancel_date' => $now->getTimestamp(),
|
||||
'cancel_date_by' => $this->me->id,
|
||||
'edit_by' => $this->me->id
|
||||
]);
|
||||
if(!$old_link->origin->save()) {
|
||||
throw new Exception("Fehler beim Speichern der Kündigung des Vorgängercontracts!");
|
||||
}
|
||||
|
||||
$old_link->change_action = null;
|
||||
$old_link->save();
|
||||
|
||||
// cancel journal
|
||||
$journal = ContractjournalModel::create([
|
||||
'contract_id' => $old_link->origin->id,
|
||||
'type' => "canceled",
|
||||
'value' => "",
|
||||
'text' => ""
|
||||
]);
|
||||
$journal->save();
|
||||
}
|
||||
}
|
||||
|
||||
foreach (ContractLinkModel::search(['type' => "link", 'origin_contract_id' => $origin->id]) as $old_link) {
|
||||
// verlinkten Contract kündigen (wenn nicht schon gekündigt)
|
||||
if ($old_link->change_action == "cancel" && !$old_link->contract->cancel_date) {
|
||||
$old_link->contract->update([
|
||||
'cancel_date' => $now->getTimestamp(),
|
||||
'cancel_date_by' => $this->me->id,
|
||||
'edit_by' => $this->me->id
|
||||
]);
|
||||
//$this->log->debug(print_r($old_link->contract, true));
|
||||
$old_link->contract->save();
|
||||
|
||||
$old_link->change_action = null;
|
||||
$old_link->save();
|
||||
|
||||
// cancel journal
|
||||
$journal = ContractjournalModel::create([
|
||||
'contract_id' => $old_link->contract->id,
|
||||
'type' => "canceled",
|
||||
'value' => "",
|
||||
'text' => ""
|
||||
]);
|
||||
$journal->save();
|
||||
}
|
||||
}
|
||||
|
||||
foreach (ContractLinkModel::search(['type' => "credit", 'origin_contract_id' => $origin->id]) as $old_credit) {
|
||||
if ($old_credit->change_action == "recreate" && !$old_credit->contract->cancel_date) {
|
||||
// Alte Gutschrift kündigen und neue anlegen
|
||||
//var_dump($old_credit->contract);
|
||||
$old_credit->contract->update([
|
||||
'cancel_date' => $now->getTimestamp(),
|
||||
'cancel_date_by' => $this->me->id,
|
||||
'edit_by' => $this->me->id
|
||||
]);
|
||||
$old_credit->contract->save();
|
||||
//var_dump($old_credit->contract);
|
||||
//exit;
|
||||
|
||||
$old_credit->change_action = null;
|
||||
$old_credit->save();
|
||||
|
||||
$new_credit = ContractModel::createCreditForContract($contract);
|
||||
if(!$new_credit->save()) {
|
||||
$this->log->debug(print_r($new_credit, true));
|
||||
throw new Exception("Fehler beim Speichern des neuen Gutschrift Contracts");
|
||||
}
|
||||
|
||||
// create journal for credit
|
||||
$journal = ContractjournalModel::create([
|
||||
'contract_id' => $new_credit->id,
|
||||
'type' => "created_from",
|
||||
'value' => "productchange",
|
||||
'text' => "Produkt-/Standortwechsel von Contract ID ".$old_credit->contract_id
|
||||
]);
|
||||
$journal->save();
|
||||
|
||||
|
||||
$this->log->debug(print_r($new_credit, true));
|
||||
|
||||
// create link to new credit contract
|
||||
$link = ContractLinkModel::create([
|
||||
"contract_id" => $new_credit->id,
|
||||
"origin_contract_id" => $contract->id,
|
||||
"type" => "credit"
|
||||
]);
|
||||
$link->save();
|
||||
|
||||
// create link from old to new credit contract
|
||||
$link = ContractLinkModel::create([
|
||||
"contract_id" => $new_credit->id,
|
||||
"origin_contract_id" => $old_credit->contract_id,
|
||||
"type" => "upgrade"
|
||||
]);
|
||||
$link->save();
|
||||
|
||||
$journal = ContractjournalModel::create([
|
||||
'contract_id' => $old_credit->contract_id,
|
||||
'type' => "canceled",
|
||||
'value' => "",
|
||||
'text' => ""
|
||||
]);
|
||||
$journal->save();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
|
||||
final class ContractLinkChangeChangeactionToVarchar extends AbstractMigration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
if($this->getEnvironment() == "thetool") {
|
||||
$table = $this->table("ContractLink");
|
||||
$table->changeColumn("change_action", "string", ["null" => true, "default" => null, "limit" => 64]);
|
||||
$table->update();
|
||||
}
|
||||
|
||||
if($this->getEnvironment() == "addressdb") {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
if($this->getEnvironment() == "thetool") {
|
||||
|
||||
}
|
||||
|
||||
if($this->getEnvironment() == "addressdb") {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user