WIP PreorderPrice 2025-02-21

This commit is contained in:
Frank Schubert
2025-02-24 12:37:33 +01:00
parent fdd6ed7ebb
commit 99bdbd3b39
12 changed files with 1329 additions and 135 deletions

View File

@@ -1,5 +0,0 @@
<?php include(realpath(dirname(__FILE__)."/../../$mfLayoutPackage")."/header.php"); ?>
<?php include(realpath(dirname(__FILE__)."/../../$mfLayoutPackage")."/footer.php"); ?>

View File

@@ -30,36 +30,61 @@
</div>
</div>
<div class="card">
<div class="card-body">
<div class="row">
<div class="col-4">
<form class="form-inline" type="get" action="<?=self::getUrl("PreorderProduct")?>">
<div class="form-group mx-sm-3 mb-2">
<label for="view_date">Ansichtsdatum:</label>
<input type="text" class="form-control datepicker-sys ml-2" name="view_date" placeholder="Datum..." value="<?=$today_date?>" />
</div>
<button type="submit" class="btn btn-primary mb-2">Anzeigen</button>
</form>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col">
<?php foreach($netoperators as $netoperator): // TODO: Netoperators als Tabs anzeigen ?>
<h4><span class="text-pink"><?=$netoperator->getCompanyOrName()?> (<?=$netoperator->id?>)</span></h4>
<?php //foreach([new Address(5668), new Address(4803)] as $netoperator): // TODO: Netoperators als Tabs anzeigen ?>
<h4><?=$netoperator->getCompanyOrName()?> (<?=$netoperator->id?>)</h4>
<div class="card">
<div class="card-body mb-3">
<form method="post" action="<?=self::getUrl("PreorderProduct", "save")?>">
<h4>Produkte</h4>
<?php foreach($products as $product): ?>
<?php $product->setNetoperatorId($netoperator->id) ?>
<?php $prices = (array_key_exists($netoperator->id, $product->prices)) ? $product->prices[$netoperator->id] : false; ?>
<?php //var_dump($prices); ?>
<?php $product->setNetoperatorId($netoperator->id) ?>
<?php $product->setTodayDate($today_date); ?>
<?php //$prices = (array_key_exists($netoperator->id, $product->prices)) ? $product->prices[$netoperator->id] : false; ?>
<div class="card">
<div class="card-body mb-3">
<h4>Preiseinstellungen für <?=$product->name?></h4>
<div class="card-header" >
<h4 class="pointer"
data-toggle="collapse" data-target="#price-detail-<?=$netoperator->id?>-<?=$product->id?>"
id="price-detail-<?=$netoperator->id?>-<?=$product->id?>-collapse" data-collapse-indicator="fa-chevron" onclick="toggleCollapseIndicator(this)"
>
<i class="fas fa-fw fa-chevron-right collapse-indicator"></i> Preiseinstellungen für <span class="text-pink"><?=$product->name?></span>
</h4>
</div>
<div class="card-body mb-3 collapse" id="price-detail-<?=$netoperator->id?>-<?=$product->id?>">
<?php if($product->type == "operator_setup"): ?>
<?php include(__DIR__."/include/netoperator-prices-setup.php"); ?>
<?php include(__DIR__."/include/prices-setup.php"); ?>
<?php elseif($product->type == "enduser_setup"): ?>
<?php include(__DIR__."/include/enduser-prices-setup.php"); ?>
<?php elseif($product->type == "operatr_usage"): ?>
<?php include(__DIR__."/include/prices-setup.php"); ?>
<?php elseif($product->type == "operator_usage"): ?>
<?php include(__DIR__."/include/netoperator-prices-usage.php"); ?>
<?php endif; ?>
</div>
</div>
<hr />
<?php endforeach; ?>
<input type="submit" class="btn btn-primary mt-2" value="Speichern" />
</form>
</div>
</div>
<?php endforeach; ?>
@@ -83,5 +108,40 @@
todayBtn: 'linked',
autoclose: true
});
$('.datepicker-sys').datepicker({
language: 'de',
format: "yyyy-mm-dd",
showWeekDays: true,
todayBtn: 'linked',
autoclose: true
});
$(".select2").select2({
allowClear: true,
placeholder: "",
closeOnSelect: true
});
$(".select2-nc").select2({
allowClear: true,
placeholder: "",
closeOnSelect: false
});
function toggleCollapseIndicator(elem) {
var selector = "#" + $(elem).attr("id");
var itype = $(elem).data("collapse-indicator");
//console.log("selector: " + selector);
if($(selector + " i.collapse-indicator").hasClass(itype + "-right")) {
$(selector + " i.collapse-indicator").removeClass(itype + "-right").addClass(itype + "-down");
} else {
$(selector + " i.collapse-indicator").removeClass(itype + "-down").addClass(itype + "-right");
}
}
</script>
<?php include(realpath(dirname(__FILE__)."/../../$mfLayoutPackage")."/footer.php"); ?>

View File

@@ -1,82 +0,0 @@
<div class="row">
<div class="col-6">
<div class="form-group">
Derzeit gültiger Preis: <strong><?=$product->current_price->price_setup?></strong>
<?php if($product->current_price->end_date): ?>
(bis <?=(new DateTime($product->current_price->end_date))->format("d.m.Y")?>)
<?php endif; ?>
<br />
Derzeit regulärer Preis: <strong><?=$product->current_regular_price->price_setup?></strong><br />
Originalpreis: <?=$product->first_price->price_setup?>
</div>
<div class="form-group">
<button type="button" class="btn btn-outline-success" onclick='$("#pricehistory-<?=$netoperator->id?>-<?=$product->id?>").toggle()'><i class="fas fa-fw fa-list"></i> Preishistory anzeigen</button>
</div>
<div class="row hidden" id="pricehistory-<?=$netoperator->id?>-<?=$product->id?>">
<table class="table table-sm table-striped table-hover">
<tr>
<th>Preis</th>
<th>Gültig von</th>
<th>Gültig bis</th>
</tr>
<?php foreach(PreorderProductPrice::search(["netowner_id" => $netowner->id,"preorderproduct_id" => $product->id, "netoperator_id" => $netoperator->id]) as $line): ?>
<tr>
<td><?=$line->price_setup?></td>
<td><?=($line->start_date) ? (new DateTime($line->start_date))->format("d.m.Y") : "-"?></td>
<td><?=($line->end_date) ? (new DateTime($line->end_date))->format("d.m.Y") : "-"?></td>
</tr>
<?php endforeach; ?>
</table>
</div>
<h4>Neuer Preis</h4>
<div class="form-group">
<label>Bereitstellungsentgelt</label>
<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text">€</span>
</div>
<input type="text" class="form-control" name="netoperators[<?=$netoperator->id?>][<?=$product->id?>][price_setup]" value="" />
</div>
</div>
<div class="form-group">
<label>Neuer Preis Gültigkeit</label>
<div class="row">
<div class="col-6">
<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text">Preis gültig von</span>
</div>
<input type="text" class="form-control datepicker" name="netoperators[<?=$netoperator->id?>][<?=$product->id?>][start_date]" value="" />
</div>
</div>
<div class="col-6">
<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text">Preis gültig bis</span>
</div>
<input type="text" class="form-control datepicker" name="netoperators[<?=$netoperator->id?>][<?=$product->id?>][end_date]" value="" />
</div>
</div>
</div>
<small>
Ohne <strong>Gültig-Bis-Datum</strong> gilt der neue Preis für immer, bis ein neuer Preis eingetragen wird.<br />
Mit <strong>Gültig-Bis-Datum</strong> gilt der neue Preis bis einschließlich dem <strong>Gültig-Bis-Datum</strong>, danach gilt der vorige Preis wieder.
</small>
</div>
</div>
</div>

View File

@@ -1 +1,306 @@
<?php
/**
* @var Address $netowner
* @var Address $netoperator
* @var PreorderProduct $product
* @var Array $campaigns
* @var string $today_date
*/
?>
<div class="row">
<div class="col-6">
<form method="post" action="<?=self::getUrl("PreorderProduct", "save")?>">
<div class="form-group">
<button type="button" class="btn btn-outline-success" onclick='$("#pricehistory-<?=$netoperator->id?>-<?=$product->id?>").toggle()'><i class="fas fa-fw fa-list"></i> Preishistory anzeigen</button>
</div>
<div class="row hidden" id="pricehistory-<?=$netoperator->id?>-<?=$product->id?>">
<table class="table table-sm table-striped table-hover">
<tr>
<th>INET</th>
<th>INET+TV</th>
<th>CATV</th>
<th>Passive</th>
<th>Gültig von</th>
<th>Gültig bis</th>
<th>Kampagnen</th>
<th>Beschreibung</th>
<th>Erstellt von</th>
</tr>
<?php foreach(PreorderProductPrice::search(["netowner_id" => $netowner->id, "preorderproduct_id" => $product->id, "netoperator_id" => $netoperator->id]) as $line): ?>
<tr>
<td class="text-monospace">€ <?=number_format($line->price_inet, 2, ",", ".")?></td>
<td class="text-monospace">€ <?=number_format($line->price_inet_tv, 2, ",", ".")?></td>
<td class="text-monospace">€ <?=number_format($line->price_catv, 2, ",", ".")?></td>
<td class="text-monospace">€ <?=number_format($line->price_passive, 2, ",", ".")?></td>
<td class="text-monospace"><?=($line->start_date) ? (new DateTime($line->start_date))->format("d.m.Y") : "-"?></td>
<td class="text-monospace"><?=($line->end_date) ? (new DateTime($line->end_date))->format("d.m.Y") : "-"?></td>
<td><?=(is_array($line->campaigns) && count($line->campaigns)) ? count($line->campaigns) : ""?></td>
<td><?=$line->description?></td>
<td><?=$line->creator->name?></td>
</tr>
<?php endforeach; ?>
</table>
</div>
<div class="card">
<div class="card-header">
<h4 class="pointer text-info" data-toggle="collapse" data-target="#new-price-<?=$netoperator->id?>-<?=$product->id?>"
id="new-price-<?=$netoperator->id?>-<?=$product->id?>-collapse" data-collapse-indicator="fa-circle-chevron"
onclick="toggleCollapseIndicator(this)">
<i class="fas fa-fw fa-circle-chevron-right collapse-indicator"></i> Neuen Preis eingeben
</h4>
</div>
<div class="card-body collapse" id="new-price-<?=$netoperator->id?>-<?=$product->id?>">
<div class="row">
<div class="col">
<div class="form-group">
<label>Beschreibung</label>
<input type="text" class="form-control" name="netoperators[<?=$netoperator->id?>][<?=$product->id?>][description]" value="" />
</div>
</div>
</div>
<div class="form-group">
<label>Preis Internet</label>
<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text">€</span>
</div>
<input type="text" class="form-control" name="netoperators[<?=$netoperator->id?>][<?=$product->id?>][price_inet]" value="" />
</div>
</div>
<div class="form-group">
<label>Preis Internet + TV</label>
<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text">€</span>
</div>
<input type="text" class="form-control" name="netoperators[<?=$netoperator->id?>][<?=$product->id?>][price_inet_tv]" value="" />
</div>
</div>
<div class="form-group">
<label>Preis Cable-TV</label>
<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text">€</span>
</div>
<input type="text" class="form-control" name="netoperators[<?=$netoperator->id?>][<?=$product->id?>][price_catv]" value="" />
</div>
</div>
<div class="form-group">
<label>Preis Passive Leitung</label>
<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text">€</span>
</div>
<input type="text" class="form-control" name="netoperators[<?=$netoperator->id?>][<?=$product->id?>][price_passive]" value="" />
</div>
</div>
<div class="form-group">
<label>Gültigkeit</label>
<div class="row">
<div class="col-6">
<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text">Preis gültig von</span>
</div>
<input type="text" class="form-control datepicker" name="netoperators[<?=$netoperator->id?>][<?=$product->id?>][start_date]" value="" />
</div>
</div>
<div class="col-6">
<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text">Preis gültig bis</span>
</div>
<input type="text" class="form-control datepicker" name="netoperators[<?=$netoperator->id?>][<?=$product->id?>][end_date]" value="" />
</div>
</div>
</div>
<small>
Ohne <strong>Gültig-Bis-Datum</strong> gilt der neue Preis für immer, bis ein neuer Preis eingetragen wird.<br />
Mit <strong>Gültig-Bis-Datum</strong> gilt der neue Preis bis einschließlich dem <strong>Gültig-Bis-Datum</strong>, danach gilt der vorige Preis wieder.
</small>
<div class="row mt-3">
<div class="col">
<div class="form-group">
<label>Nur gültig in folgenden Kampagnen</label>
<select class="select2-nc form-control select2-multiple" name="netoperators[<?=$netoperator->id?>][<?=$product->id?>][campaigns][]" multiple="multiple" data-placeholder="Kampagnen ...">
<?php foreach ($campaigns as $campaign): ?>
<option value="<?= $campaign->id ?>" <?= (is_array($product->campaigns) && array_key_exists($campaign->id, $product->campaigns)) ? "selected='selected'" : "" ?>><?= $campaign->name ?></option>
<?php endforeach; ?>
</select>
<small>
Wenn keine Kampagne ausgewählt wird, gilt der Preis für alle Kampagnen.
</small>
</div>
</div>
</div>
<h4>Netzdurchdringung</h4>
<div class="row">
<div class="col">
<p>Rabattierte Preise für das Erreichen on Netzdurchdringungszielen</p>
<p>0 - 15% ist der Standardpreis. Falls keine Netzdurchdringung </p>
<table class="table table-sm table-bordered table-striped table-hover">
<tr>
<th>Ziel</th>
<th>INET</th>
<th>INET+TV</th>
<th>CATV</th>
<th>Passive</th>
</tr><tr>
<th>0 - 15%</th>
<th><input type="text" class="form-control" name="netoperators[<?=$netoperator->id?>][<?=$product->id?>][marketshareprice][0-15][inet]" /></th>
<th><input type="text" class="form-control" name="netoperators[<?=$netoperator->id?>][<?=$product->id?>][marketshareprice][0-15][inet_tv]" /></th>
<th><input type="text" class="form-control" name="netoperators[<?=$netoperator->id?>][<?=$product->id?>][marketshareprice][0-15][catv]" /></th>
<th><input type="text" class="form-control" name="netoperators[<?=$netoperator->id?>][<?=$product->id?>][marketshareprice][0-15][passive]" /></th>
</tr><tr>
<th>15,01% - 20%</th>
<th><input type="text" class="form-control" name="netoperators[<?=$netoperator->id?>][<?=$product->id?>][marketshareprice][15-20][inet]" /></th>
<th><input type="text" class="form-control" name="netoperators[<?=$netoperator->id?>][<?=$product->id?>][marketshareprice][15-20][inet_tv]" /></th>
<th><input type="text" class="form-control" name="netoperators[<?=$netoperator->id?>][<?=$product->id?>][marketshareprice][15-20][catv]" /></th>
<th><input type="text" class="form-control" name="netoperators[<?=$netoperator->id?>][<?=$product->id?>][marketshareprice][15-20][passive]" /></th>
</tr><tr>
<th>20,01% - 25%</th>
<th><input type="text" class="form-control" name="netoperators[<?=$netoperator->id?>][<?=$product->id?>][marketshareprice][20-25][inet]" /></th>
<th><input type="text" class="form-control" name="netoperators[<?=$netoperator->id?>][<?=$product->id?>][marketshareprice][20-25][inet_tv]" /></th>
<th><input type="text" class="form-control" name="netoperators[<?=$netoperator->id?>][<?=$product->id?>][marketshareprice][20-25][catv]" /></th>
<th><input type="text" class="form-control" name="netoperators[<?=$netoperator->id?>][<?=$product->id?>][marketshareprice][20-25][passive]" /></th>
</tr><tr>
<th>25,01% - 30%</th>
<th><input type="text" class="form-control" name="netoperators[<?=$netoperator->id?>][<?=$product->id?>][marketshareprice][25-30][inet]" /></th>
<th><input type="text" class="form-control" name="netoperators[<?=$netoperator->id?>][<?=$product->id?>][marketshareprice][25-30][inet_tv]" /></th>
<th><input type="text" class="form-control" name="netoperators[<?=$netoperator->id?>][<?=$product->id?>][marketshareprice][25-30][catv]" /></th>
<th><input type="text" class="form-control" name="netoperators[<?=$netoperator->id?>][<?=$product->id?>][marketshareprice][25-30][passive]" /></th>
</tr><tr>
<th>30,01% - 35%</th>
<th><input type="text" class="form-control" name="netoperators[<?=$netoperator->id?>][<?=$product->id?>][marketshareprice][30-35][inet]" /></th>
<th><input type="text" class="form-control" name="netoperators[<?=$netoperator->id?>][<?=$product->id?>][marketshareprice][30-35][inet_tv]" /></th>
<th><input type="text" class="form-control" name="netoperators[<?=$netoperator->id?>][<?=$product->id?>][marketshareprice][30-35][catv]" /></th>
<th><input type="text" class="form-control" name="netoperators[<?=$netoperator->id?>][<?=$product->id?>][marketshareprice][30-35][passive]" /></th>
</tr><tr>
<th>35,01% - 40%</th>
<th><input type="text" class="form-control" name="netoperators[<?=$netoperator->id?>][<?=$product->id?>][marketshareprice][35-40][inet]" /></th>
<th><input type="text" class="form-control" name="netoperators[<?=$netoperator->id?>][<?=$product->id?>][marketshareprice][35-40][inet_tv]" /></th>
<th><input type="text" class="form-control" name="netoperators[<?=$netoperator->id?>][<?=$product->id?>][marketshareprice][35-40][catv]" /></th>
<th><input type="text" class="form-control" name="netoperators[<?=$netoperator->id?>][<?=$product->id?>][marketshareprice][35-40][passive]" /></th>
</tr><tr>
<th>40,01% - 45%</th>
<th><input type="text" class="form-control" name="netoperators[<?=$netoperator->id?>][<?=$product->id?>][marketshareprice][40-45][inet]" /></th>
<th><input type="text" class="form-control" name="netoperators[<?=$netoperator->id?>][<?=$product->id?>][marketshareprice][40-45][inet_tv]" /></th>
<th><input type="text" class="form-control" name="netoperators[<?=$netoperator->id?>][<?=$product->id?>][marketshareprice][40-45][catv]" /></th>
<th><input type="text" class="form-control" name="netoperators[<?=$netoperator->id?>][<?=$product->id?>][marketshareprice][40-45][passive]" /></th>
</tr>
</table>
</div>
</div>
</div>
<input type="submit" class="btn btn-primary mt-2" value="Speichern" />
</div>
</div>
</form>
</div>
<?php
$current_price = $product->getCurrentPrice($today_date, true);
$current_regular_price = $product->getCurrentRegularPrice($today_date, true);
$first_price = $product->getFirstPrice($today_date);
?>
<div class="col-6">
<div class="row">
<div class="col">
<h4>Aktuelle Preise für <?=$product->getTodayDate()?></h4>
<table class="table">
<tr>
<th></th>
<th>INET</th>
<th>INET+TV</th>
<th>CATV</th>
<th>Passive</th>
<th></th>
</tr>
<tr>
<th>Heute gültiger Preis</th>
<td class="text-monospace">€ <?=number_format($current_price->price_inet, 2, ",", ".")?></td>
<td class="text-monospace">€ <?=number_format($current_price->price_inet_tv, 2, ",", ".")?></td>
<td class="text-monospace">€ <?=number_format($current_price->price_catv, 2, ",", ".")?></td>
<td class="text-monospace">€ <?=number_format($current_price->price_passive, 2, ",", ".")?></td>
<td>
<?=$current_price->description?>
<?php if($current_price->end_date): ?>
bis <?=(new DateTime($current_price->end_date))->format("d.m.Y")?>
<?php endif; ?>
</td>
</tr><tr>
<th>Derzeit regulärer Preis</th>
<td class="text-monospace">€ <?=number_format($current_regular_price->price_inet, 2, ",", ".")?></td>
<td class="text-monospace">€ <?=number_format($current_regular_price->price_inet_tv, 2, ",", ".")?></td>
<td class="text-monospace">€ <?=number_format($current_regular_price->price_catv, 2, ",", ".")?></td>
<td class="text-monospace">€ <?=number_format($current_regular_price->price_passive, 2, ",", ".")?></td>
<td><?=$current_regular_price->description?></td>
</tr><tr>
<td>Initialpreis</td>
<td class="text-monospace">€ <?=number_format($first_price->price_inet, 2, ",", ".")?></td>
<td class="text-monospace">€ <?=number_format($first_price->price_inet_tv, 2, ",", ".")?></td>
<td class="text-monospace">€ <?=number_format($first_price->price_catv, 2, ",", ".")?></td>
<td class="text-monospace">€ <?=number_format($first_price->price_passive, 2, ",", ".")?></td>
<td></td>
</tr>
</table>
</div>
</div>
<div class="row">
<div class="col">
<h4>Preis Pro Kampagne</h4>
<table class="table table-sm table-striped table-hover">
<tr>
<th>Kampagne</th>
<th>INET</th>
<th>INET+TV</th>
<th>CATV</th>
<th>Passive</th>
<th>Gültig von</th>
<th>Gültig bis</th>
<th>Beschreibung</th>
<th></th>
</tr>
<?php foreach($campaigns as $campaign): ?>
<?php $cprice = $product->getCampaignPrice($campaign->id, $today_date); ?>
<tr>
<td><?=$campaign->name?></td>
<td class="text-monospace">€ <?=number_format($cprice->price_inet, 2, ",", ".")?></td>
<td class="text-monospace">€ <?=number_format($cprice->price_inet_tv, 2, ",", ".")?></td>
<td class="text-monospace">€ <?=number_format($cprice->price_catv, 2, ",", ".")?></td>
<td class="text-monospace">€ <?=number_format($cprice->price_passive, 2, ",", ".")?></td>
<td class="text-monospace"><?=($cprice->start_date) ? (new DateTime($cprice->start_date))->format("d.m.Y") : "-"?></td>
<td class="text-monospace"><?=($cprice->end_date) ? (new DateTime($cprice->end_date))->format("d.m.Y") : "-"?></td>
<td><?=$cprice->description?></td>
<td><?=$product->getTodayDate()?></td>
</tr>
<?php endforeach; ?>
</table>
</div>
</div>
</div>
</div>

View File

@@ -0,0 +1,190 @@
<?php
/**
* @var Address $netowner
* @var Address $netoperator
* @var PreorderProduct $product
* @var Array $campaigns
* @var string $today_date
*/
?>
<div class="row">
<div class="col-6">
<form method="post" action="<?=self::getUrl("PreorderProduct", "save")?>">
<div class="form-group">
<button type="button" class="btn btn-outline-success" onclick='$("#pricehistory-<?=$netoperator->id?>-<?=$product->id?>").toggle()'><i class="fas fa-fw fa-list"></i> Preishistory anzeigen</button>
</div>
<div class="row hidden" id="pricehistory-<?=$netoperator->id?>-<?=$product->id?>">
<table class="table table-sm table-striped table-hover">
<tr>
<th>Preis</th>
<th>Gültig von</th>
<th>Gültig bis</th>
<th>Kampagnen</th>
<th>Beschreibung</th>
<th>Erstellt von</th>
</tr>
<?php foreach(PreorderProductPrice::search(["netowner_id" => $netowner->id, "preorderproduct_id" => $product->id, "netoperator_id" => $netoperator->id]) as $line): ?>
<tr>
<td class="text-monospace">€ <?=number_format($line->price_setup, 2, ",", ".")?></td>
<td class="text-monospace"><?=($line->start_date) ? (new DateTime($line->start_date))->format("d.m.Y") : "-"?></td>
<td class="text-monospace"><?=($line->end_date) ? (new DateTime($line->end_date))->format("d.m.Y") : "-"?></td>
<td><?=(is_array($line->campaigns) && count($line->campaigns)) ? count($line->campaigns) : ""?></td>
<td><?=$line->description?></td>
<td><?=$line->creator->name?></td>
</tr>
<?php endforeach; ?>
</table>
</div>
<div class="card">
<div class="card-header">
<h4 class="pointer text-info" data-toggle="collapse" data-target="#new-price-<?=$netoperator->id?>-<?=$product->id?>"
id="new-price-<?=$netoperator->id?>-<?=$product->id?>-collapse" data-collapse-indicator="fa-circle-chevron"
onclick="toggleCollapseIndicator(this)">
<i class="fas fa-fw fa-circle-chevron-right collapse-indicator"></i> Neuen Preis eingeben
</h4>
</div>
<div class="card-body collapse" id="new-price-<?=$netoperator->id?>-<?=$product->id?>">
<div class="row">
<div class="col">
<div class="form-group">
<label>Beschreibung</label>
<input type="text" class="form-control" name="netoperators[<?=$netoperator->id?>][<?=$product->id?>][description]" value="" />
</div>
</div>
</div>
<div class="form-group">
<label>Preis</label>
<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text">€</span>
</div>
<input type="text" class="form-control" name="netoperators[<?=$netoperator->id?>][<?=$product->id?>][price_setup]" value="" />
</div>
</div>
<div class="form-group">
<label>Gültigkeit</label>
<div class="row">
<div class="col-6">
<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text">Preis gültig von</span>
</div>
<input type="text" class="form-control datepicker" name="netoperators[<?=$netoperator->id?>][<?=$product->id?>][start_date]" value="" />
</div>
</div>
<div class="col-6">
<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text">Preis gültig bis</span>
</div>
<input type="text" class="form-control datepicker" name="netoperators[<?=$netoperator->id?>][<?=$product->id?>][end_date]" value="" />
</div>
</div>
</div>
<small>
Ohne <strong>Gültig-Bis-Datum</strong> gilt der neue Preis für immer, bis ein neuer Preis eingetragen wird.<br />
Mit <strong>Gültig-Bis-Datum</strong> gilt der neue Preis bis einschließlich dem <strong>Gültig-Bis-Datum</strong>, danach gilt der vorige Preis wieder.
</small>
<div class="row mt-3">
<div class="col">
<div class="form-group">
<label>Nur gültig in folgenden Kampagnen</label>
<select class="select2-nc form-control select2-multiple" name="netoperators[<?=$netoperator->id?>][<?=$product->id?>][campaigns][]" multiple="multiple" data-placeholder="Kampagnen ...">
<?php foreach ($campaigns as $campaign): ?>
<option value="<?= $campaign->id ?>" <?= (is_array($product->campaigns) && array_key_exists($campaign->id, $product->campaigns)) ? "selected='selected'" : "" ?>><?= $campaign->name ?></option>
<?php endforeach; ?>
</select>
<small>
Wenn keine Kampagne ausgewählt wird, gilt der Preis für alle Kampagnen.
</small>
</div>
</div>
</div>
</div>
<input type="submit" class="btn btn-primary mt-2" value="Speichern" />
</div>
</div>
</form>
</div>
<?php
$current_price = $product->getCurrentPrice($today_date, true);
$current_regular_price = $product->getCurrentRegularPrice($today_date, true);
$first_price = $product->getFirstPrice($today_date);
?>
<div class="col-6">
<div class="row">
<div class="col">
<h4>Aktuelle Preise für <?=$product->getTodayDate()?></h4>
<table class="table">
<tr>
<th>Heute gültiger Preis</th>
<td class="text-monospace">€ <?=number_format($current_price->price_setup, 2, ",", ".")?></td>
<td>
<?=$current_price->description?>
<?php if($current_price->end_date): ?>
bis <?=(new DateTime($current_price->end_date))->format("d.m.Y")?>
<?php endif; ?>
</td>
</tr><tr>
<th>Derzeit regulärer Preis</th>
<td class="text-monospace">€ <?=number_format($current_regular_price->price_setup, 2, ",", ".")?></td>
<td><?=$current_regular_price->description?></td>
</tr><tr>
<td>Initialpreis <span class="text-monospace">€ <?=number_format($first_price->price_setup, 2, ",", ".")?></span></td>
<td></td>
<td></td>
</tr>
</table>
</div>
</div>
<div class="row">
<div class="col">
<h4>Preis Pro Kampagne</h4>
<table class="table table-sm table-striped table-hover">
<tr>
<th>Kampagne</th>
<th>Preis</th>
<th>Gültig von</th>
<th>Gültig bis</th>
<th>Beschreibung</th>
<th></th>
</tr>
<?php foreach($campaigns as $campaign): ?>
<?php $cprice = $product->getCampaignPrice($campaign->id, $today_date); ?>
<tr>
<td><?=$campaign->name?></td>
<td class="text-monospace">€ <?=number_format($cprice->price_setup, 2, ",", ".")?></td>
<td class="text-monospace"><?=($cprice->start_date) ? (new DateTime($cprice->start_date))->format("d.m.Y") : "-"?></td>
<td class="text-monospace"><?=($cprice->end_date) ? (new DateTime($cprice->end_date))->format("d.m.Y") : "-"?></td>
<td><?=$cprice->description?></td>
<td><?=$product->getTodayDate()?></td>
</tr>
<?php endforeach; ?>
</table>
</div>
</div>
</div>
</div>

View File

@@ -3,12 +3,17 @@
class PreorderProduct extends mfBaseModel {
private $filter_netowner_id;
private $filter_netoperator_id;
private $filter_campaign_id;
private $prices;
private $first_price;
private $current_price;
private $current_regular_price;
private $first_campaign_price;
private $current_campaign_price;
private $current_campaign_regular_price;
private $creator;
private $editor;
private $today_date;
protected static $types = ["operator_setup", "enduser_setup", "operator_usage"];
@@ -31,6 +36,230 @@ class PreorderProduct extends mfBaseModel {
return true;
}
public function setCampaignId($campaign_id) {
if(!$campaign_id) {
$this->filter_campaign_id = null;
return true;
}
$this->filter_campaign_id = $campaign_id;
return true;
}
public function setTodayDate($date) {
$this->today_date = date($date);
}
public function getTodayDate() {
return $this->today_date;
}
public function getCampaignFirstPrice($campaign_id, $date = null) {
if(!$date) $date = date("Y-m-d");
$price = PreorderProductPrice::getFirst([
"netowner_id" => $this->filter_netowner_id,
"netoperator_id" => $this->filter_netoperator_id,
"campaign_id" => $campaign_id,
"preorderproduct_id" => $this->id,
"start_date" => null,
"end_date" => null,
], "`create` DESC");
if($price) {
//$this->first_campaign_price = $price;
return $price;
//return $this->first_campaign_price;
}
return null;
}
public function getCampaignCurrentRegularPrice($campaign_id, $date) {
if(!$date) $date = date("Y-m-d");
$price = PreorderProductPrice::getFirst([
"netowner_id" => $this->filter_netowner_id,
"netoperator_id" => $this->filter_netoperator_id,
"campaign_id" => $campaign_id,
"preorderproduct_id" => $this->id,
"start_date<=" => $date,
"end_date" => null,
], "start_date DESC, `create` DESC");
if($price) {
//$this->current_campaign_regular_price = $price;
return $price;
//return $this->current_campaign_regular_price;
} else {
$this->log->debug(__METHOD__.": TRY FIRST PRICE");
return $this->getCampaignFirstPrice($campaign_id, $date);
}
return null;
}
public function getCampaignCurrentPrice($campaign_id, $date = null) {
if(!$date) $date = date("Y-m-d");
// search for discounted price (with startdate and enddate
$price = PreorderProductPrice::getFirst([
"netowner_id" => $this->filter_netowner_id,
"netoperator_id" => $this->filter_netoperator_id,
"campaign_id" => $campaign_id,
"preorderproduct_id" => $this->id,
"start_date<=" => $date,
"end_date>" => $date,
], "start_date DESC, end_date ASC, `create` DESC");
if(!$price) {
// search for current regular price (with startdate and no enddate)
$price = PreorderProductPrice::getFirst([
"netowner_id" => $this->filter_netowner_id,
"netoperator_id" => $this->filter_netoperator_id,
"campaign_id" => $campaign_id,
"preorderproduct_id" => $this->id,
"start_date<=" => $date,
"end_date" => null,
], "start_date DESC, `create` DESC");
}
return $price;
}
public function getCampaignPrice($campaign_id, $date = null) {
$this->log->debug("=== in ".__METHOD__);
if(!$date) $date = date("Y-m-d");
$this->log->debug(__METHOD__.": TRY CURRENT PRICE");
$price = $this->getCampaignCurrentPrice($campaign_id, $date);
if(!$price) {
$this->log->debug(__METHOD__.": TRY CURRENT REGULAR PRICE");
$price = $this->getCampaignCurrentRegularPrice($campaign_id, $date);
}
if(!$price) {
$this->log->debug(__METHOD__.": TRY FIRST PRICE");
$price = $this->getCampaignFirstPrice($campaign_id, $date);
}
if(!$price) {
$this->log->debug(__METHOD__.": No Campaign price found. GET NETOP CURRENT PRICE");
$price = $this->getPrice();
}
if($price) {
$this->log->debug("=== done in ".__METHOD__);
return $price;
}
return null;
}
public function getFirstPrice($date = null) {
if(!$date) $date = date("Y-m-d");
$price = PreorderProductPrice::getFirst([
"netowner_id" => $this->filter_netowner_id,
"netoperator_id" => $this->filter_netoperator_id,
"campaign_id" => null,
"preorderproduct_id" => $this->id,
"start_date" => null,
"end_date" => null,
], "`create` DESC");
if(!$price) {
$price = PreorderProductPrice::getFirst([
"netowner_id" => $this->filter_netowner_id,
"netoperator_id" => null,
"campaign_id" => null,
"preorderproduct_id" => $this->id,
"start_date" => null,
"end_date" => null,
], "`create` DESC");
}
return $price;
}
public function getCurrentRegularPrice($date = null, $allowCascading = false) {
if(!$date) $date = date("Y-m-d");
$price = PreorderProductPrice::getFirst([
"netowner_id" => $this->filter_netowner_id,
"netoperator_id" => $this->filter_netoperator_id,
"campaign_id" => null,
"preorderproduct_id" => $this->id,
"start_date<=" => date($this->today_date),
"end_date" => null,
], "start_date DESC, `create` DESC");
if(!$price && $allowCascading) {
$this->log->debug(__METHOD__.": Cascading to getFirstPrice()");
return $this->getFirstPrice($date, true);
}
return $price;
}
public function getCurrentPrice($date = null, $allowCascading = false) {
if(!$date) $date = date("Y-m-d");
$price = PreorderProductPrice::getFirst([
"netowner_id" => $this->filter_netowner_id,
"netoperator_id" => $this->filter_netoperator_id,
"campaign_id" => null,
"preorderproduct_id" => $this->id,
"start_date<=" => date($this->today_date),
"end_date>" => date($this->today_date),
], "start_date DESC, end_date ASC, `create` DESC");
if(!$price) {
$price = PreorderProductPrice::getFirst([
"netowner_id" => $this->filter_netowner_id,
"netoperator_id" => $this->filter_netoperator_id,
"campaign_id" => null,
"preorderproduct_id" => $this->id,
"start_date<=" => date($this->today_date),
"end_date" => null,
], "start_date DESC, `create` DESC");
}
if(!$price) {
$price = PreorderProductPrice::getFirst([
"netowner_id" => $this->filter_netowner_id,
"netoperator_id" => $this->filter_netoperator_id,
"campaign_id" => null,
"preorderproduct_id" => $this->id,
"start_date" => null,
"end_date" => null,
], "`create` DESC");
}
if(!$price && $allowCascading) {
$this->log->debug(__METHOD__.": Cascading to getCurrentRegularPrice()");
return $this->getCurrentRegularPrice($date, true);
}
return $price;
}
public function getPrice($date = null) {
if(!$date) $date = date("Y-m-d");
$this->log->debug("=== in ".__METHOD__);
$this->log->debug(__METHOD__.": TRY CURRENT PRICE");
$price = $this->getCurrentPrice($date);
if(!$price) {
$this->log->debug(__METHOD__.": TRY CURRENT REGULAR PRICE");
$price = $this->getCurrentRegularPrice($date);
}
if(!$price) {
$this->log->debug(__METHOD__.": TRY FIRST PRICE");
$price = $this->getFirstPrice($date);
}
if(!$price) {
$this->log->error(__METHOD__.": Unable to find price! netowner_id: ".$this->filter_netowner_id, " netoperator_id: ".$this->filter_netoperator_id." date: $date");
return null;
}
$this->log->debug("=== done in ".__METHOD__);
return $price;
}
public function getProperty($name) {
if($this->$name == null) {
@@ -46,9 +275,30 @@ class PreorderProduct extends mfBaseModel {
}
if($name == "first_price") {
if(!$this->today_date) $this->today_date = date("Y-m-d");
}
if($name == "current_regular_price") {
if(!$this->today_date) $this->today_date = date("Y-m-d");
}
if($name == "current_price") {
if(!$this->today_date) $this->today_date = date("Y-m-d");
}
if($name == "first_campaign_price") {
if(!$this->today_date) $this->today_date = date("Y-m-d");
$price = PreorderProductPrice::getFirst([
"netowner_id" => $this->filter_netowner_id,
"netoperator_id" => $this->filter_netoperator_id,
"campaign_id" => $this->filter_campaign_id,
"preorderproduct_id" => $this->id,
"start_date>=" => null,
"end_date>" => null,
@@ -56,66 +306,112 @@ class PreorderProduct extends mfBaseModel {
if(!$price) {
$price = PreorderProductPrice::getFirst([
"netowner_id" => $this->filter_netowner_id,
"netoperator_id" => $this->filter_netoperator_id,
"campaign_id" => null,
"preorderproduct_id" => $this->id,
"start_date>=" => null,
"end_date>" => null,
], "`create` ASC");
}
if(!$price) {
$price = PreorderProductPrice::getFirst([
"netowner_id" => $this->filter_netowner_id,
"netoperator_id" => null,
"campaign_id" => null,
"preorderproduct_id" => $this->id,
"start_date>=" => null,
"end_date>" => null,
], "`create` ASC");
}
if($price) {
$this->current_price = $price;
return $this->current_price;
//$this->first_campaign_price = $price;
return $price;
//return $this->first_campaign_price;
}
return null;
}
if($name == "current_regular_price") {
if($name == "current_campaign_regular_price") {
if(!$this->today_date) $this->today_date = date("Y-m-d");
$price = PreorderProductPrice::getFirst([
"netowner_id" => $this->filter_netowner_id,
"netoperator_id" => $this->filter_netoperator_id,
"campaign_id" => $this->filter_campaign_id,
"preorderproduct_id" => $this->id,
"start_date<=" => date("Y-m-d"),
"start_date<=" => date($this->today_date),
"end_date>" => null,
], "`create` ASC");
if($price) {
$this->current_price = $price;
return $this->current_price;
//$this->current_campaign_regular_price = $price;
return $price;
//return $this->current_campaign_regular_price;
} else {
return $this->getProperty("first_price");
return $this->getProperty("first_campaign_price");
}
return null;
}
if($name == "current_price") {
if($name == "current_campaign_price") {
if(!$this->today_date) $this->today_date = date("Y-m-d");
$price = PreorderProductPrice::getFirst([
"netowner_id" => $this->filter_netowner_id,
"netoperator_id" => $this->filter_netoperator_id,
"campaign_id" => $this->filter_campaign_id,
"preorderproduct_id" => $this->id,
"start_date<=" => date("Y-m-d"),
"end_date>" => date("Y-m-d"),
], "start_date");
"start_date<=" => date($this->today_date),
"end_date>" => date($this->today_date),
], "start_date DESC, end_date ASC, `create` DESC");
if(!$price) {
$price = PreorderProductPrice::getFirst([
"netowner_id" => $this->filter_netowner_id,
"netoperator_id" => $this->filter_netoperator_id,
"campaign_id" => $this->filter_campaign_id,
"preorderproduct_id" => $this->id,
"start_date<=" => date("Y-m-d"),
"start_date<=" => date($this->today_date),
"end_date" => null,
], "start_date");
], "start_date DESC, `create` DESC");
}
if(!$price) {
$price = PreorderProductPrice::getFirst([
"netowner_id" => $this->filter_netowner_id,
"netoperator_id" => $this->filter_netoperator_id,
"campaign_id" => $this->filter_campaign_id,
"preorderproduct_id" => $this->id,
"start_date" => null,
"end_date" => null,
], "start_date");
], "`create` DESC");
}
if(!$price) {
$price = PreorderProductPrice::getFirst([
"netowner_id" => $this->filter_netowner_id,
"netoperator_id" => $this->filter_netoperator_id,
"campaign_id" => null,
"preorderproduct_id" => $this->id,
"start_date<=" => date($this->today_date),
"end_date>" => date($this->today_date),
], "start_date DESC, end_date ASC, `create` DESC");
}
if(!$price) {
$price = PreorderProductPrice::getFirst([
"netowner_id" => $this->filter_netowner_id,
"netoperator_id" => $this->filter_netoperator_id,
"campaign_id" => null,
"preorderproduct_id" => $this->id,
"start_date<=" => date($this->today_date),
"end_date" => null,
], "start_date DESC, `create` DESC");
}
if($price) {
$this->current_price = $price;
return $this->current_price;
return $price;
} else {
return $this->getProperty("current_campaign_regular_price");
}
return null;
}
@@ -168,6 +464,24 @@ class PreorderProduct extends mfBaseModel {
}
public function __clone() {
$this->prices = null;
$this->first_price = null;
$this->current_price = null;
$this->current_regular_price = null;
$this->first_campaign_price = null;
$this->current_campaign_price = null;
$this->current_campaign_regular_price = null;
$this->creator = null;
$this->editor = null;
//$this->filter_netoperator_id = null;
//$this->filter_netowner_id = null;
//$this->filter_campaign_id = null;
}
/********************************
* Begin static Model functions
*/

View File

@@ -44,6 +44,16 @@ class PreorderProductController extends mfBaseController {
}
}
$campaigns = PreordercampaignModel::search(["owner_id" => $netowner_id]);
$today_date = date("Y-m-d");
if($this->request->view_date) {
$today_date = $this->request->view_date;
}
$this->layout()->set("today_date", $today_date);
$this->layout()->set("campaigns", $campaigns);
$this->layout()->set("netoperators", $netoperators);
$this->layout()->set("netowner", $netowner);
}
@@ -61,7 +71,7 @@ class PreorderProductController extends mfBaseController {
$this->layout()->redirect("PreorderProduct");
}
foreach($product_data as $product_id => $price_data) {
var_dump($price_data);
//var_dump($price_data);exit;
$product = new PreorderProduct($product_id);
if(!$product->id) {
$this->layout()->setFlash("Produkt $product_id nicht gefunden", "error");
@@ -74,14 +84,23 @@ class PreorderProductController extends mfBaseController {
"preorderproduct_id" => $product->id,
"netoperator_id" => $netoperator_id,
]);
if($price_data["price_setup"]) $price->price_setup = $price_data["price_setup"];
if($price_data["description"]) $price->description = trim($price_data["description"]);
if($product->type == "operator_setup" || $product->type == "enduser_setup") {
if($price_data["price_setup"]) $price->price_setup = Layout::commaToDot(trim($price_data["price_setup"]));
} elseif($product->type == "operator_usage") {
if($price_data["price_inet"]) $price->price_inet = Layout::commaToDot(trim($price_data["price_inet"]));
if($price_data["price_inet_tv"]) $price->price_inet_tv = Layout::commaToDot(trim($price_data["price_inet_tv"]));
if($price_data["price_catv"]) $price->price_catv = Layout::commaToDot(trim($price_data["price_catv"]));
if($price_data["price_passive"]) $price->price_passive = Layout::commaToDot(trim($price_data["price_passive"]));
}
if(!$price_data["start_date"]) {
$this->layout()->setFlash("Von-datum fehlt bei Produkt '".$product->name."' für '".$netoperator->getCompanyOrName()."'", "error");
$this->redirect("PreorderProduct");
} else {
try {
$start_date = new DateTime("@" . $this->dateToTimestamp($price_data["start_date"]));
$start_date = new DateTime("@" . $this->dateToTimestamp(trim($price_data["start_date"])));
$start_date->setTimezone(new DateTimeZone("Europe/Vienna"));
$price->start_date = $start_date->format("Y-m-d");
} catch(Exception $e) {
@@ -89,9 +108,9 @@ class PreorderProductController extends mfBaseController {
$this->redirect("PreorderProduct");
}
}
if($price_data["end_date"]) {
if(trim($price_data["end_date"])) {
try {
$end_date = new DateTime("@" . $this->dateToTimestamp($price_data["end_date"]));
$end_date = new DateTime("@" . $this->dateToTimestamp(trim($price_data["end_date"])));
$end_date->setTimezone(new DateTimeZone("Europe/Vienna"));
$price->end_date = $end_date->format("Y-m-d");
} catch(Exception $e) {
@@ -100,11 +119,25 @@ class PreorderProductController extends mfBaseController {
}
}
//var_dump($product, $price);
$price->save();
// create PreorderProductPriceCampaign for all submitted campaign_ids
foreach($price_data["campaigns"] as $campaign_id) {
$campaign = new Preordercampaign($campaign_id);
if(!$campaign->id) {
$this->layout()->setFlash("Ungültige Kampagne bei Produkt '".$product->name."' für '".$netoperator->getCompanyOrName()."'", "error");
$this->layout()->redirect("PreorderProduct");
}
$price_campaign = PreorderProductPriceCampaign::create([
"preorderproductprice_id" => $price->id,
"preordercampaign_id" => $campaign->id,
]);
$price_campaign->save();
}
}
}
$this->layout()->setFlash("Neue Preise erflgreich gespeichert", "success");

View File

@@ -4,6 +4,7 @@ class PreorderProductPrice extends mfBaseModel {
private $preorderprduct;
private $netowner;
private $preordercampaign;
private $campaigns;
private $campaign;
private $creator;
private $editor;
@@ -39,6 +40,19 @@ class PreorderProductPrice extends mfBaseModel {
return $this->preordercampaign;
}
if($name == "campaigns") {
$ccount = PreorderProductPriceCampaign::count(["preorderproductprice_id" => $this->id]);
$this->log->debug("Counted $ccount Campaigns for Price ".$this->id);
if(!$ccount) return [];
$this->campaigns = [];
foreach(PreorderProductPriceCampaign::search(["preorderproductprice_id" => $this->id]) as $pppc) {
$campaign = $pppc->campaign;
if(!$campaign || !$campaign->id) continue;
$this->campaigns[$campaign->id] = new PreorderCampaign($campaign->id);
}
return $this->campaigns;
}
if($name == "creator") {
$creator = mfValuecache::singleton()->get("Worker-id-".$this->create_by);
@@ -97,7 +111,7 @@ class PreorderProductPrice extends mfBaseModel {
$table_fields = [
"preorderproduct_id", "netowner_id", "netoperator_id", "preordercampaign_id", "description",
"start_date", "end_date", "price_inet", "price_inet_tv", "price_catv", "price_passive",
"billing_delay", "billing_period", "contract_term", "note",
"billing_delay", "billing_period", "contract_term", "description", "note",
"create_by","edit_by","create","edit"
];
@@ -125,7 +139,12 @@ class PreorderProductPrice extends mfBaseModel {
$db = FronkDB::singleton();
$res = $db->select("PreorderProductPrice", "*", "1 = 1 ORDER BY start_date");
$sql = "SELECT PreorderProductPrice.* FROM PreorderProductPrice
LEFT OUTER JOIN (SELECT COUNT(*) as cnt, preorderproductprice_id, preordercampaign_id as preordercampaign_id FROM PreorderProductPriceCampaign GROUP BY PreorderProductPriceCampaign.preorderproductprice_id, PreorderProductPriceCampaign.preordercampaign_id) pppc ON PreorderProductPrice.id = pppc.preorderproductprice_id
GROUP BY PreorderProductPrice.id
ORDER BY start_date";
$res = $db->query($sql);
if($db->num_rows($res)) {
while($data = $db->fetch_object($res)) {
$items[] = new PreorderProductPrice($data);
@@ -143,8 +162,10 @@ class PreorderProductPrice extends mfBaseModel {
}
$where = self::getSqlFilter($filter);
$sql = "SELECT * FROM PreorderProductPrice
WHERE $where
$sql = "SELECT PreorderProductPrice.* FROM PreorderProductPrice
LEFT OUTER JOIN (SELECT COUNT(*) as cnt, preorderproductprice_id, preordercampaign_id as preordercampaign_id FROM PreorderProductPriceCampaign GROUP BY PreorderProductPriceCampaign.preorderproductprice_id, PreorderProductPriceCampaign.preordercampaign_id) pppc ON PreorderProductPrice.id = pppc.preorderproductprice_id
WHERE $where
GROUP BY PreorderProductPrice.id
ORDER BY $order LIMIT 1";
mfLoghandler::singleton()->debug($sql);
@@ -167,7 +188,9 @@ class PreorderProductPrice extends mfBaseModel {
$where = self::getSqlFilter($filter);
$sql = "SELECT COUNT(*) as cnt FROM PreorderProductPrice
WHERE $where";
LEFT OUTER JOIN (SELECT COUNT(*) as cnt, preorderproductprice_id, preordercampaign_id as preordercampaign_id FROM PreorderProductPriceCampaign GROUP BY PreorderProductPriceCampaign.preorderproductprice_id, PreorderProductPriceCampaign.preordercampaign_id) pppc ON PreorderProductPrice.id = pppc.preorderproductprice_id
WHERE $where
GROUP BY PreorderProductPrice.id";
//mfLoghandler::singleton()->debug($sql);
@@ -190,8 +213,10 @@ class PreorderProductPrice extends mfBaseModel {
$db = FronkDB::singleton();
$where = self::getSqlFilter($filter);
$sql = "SELECT * FROM PreorderProductPrice
$sql = "SELECT PreorderProductPrice.* FROM PreorderProductPrice
LEFT OUTER JOIN (SELECT COUNT(*) as cnt, preorderproductprice_id, preordercampaign_id as preordercampaign_id FROM PreorderProductPriceCampaign GROUP BY PreorderProductPriceCampaign.preorderproductprice_id, PreorderProductPriceCampaign.preordercampaign_id) pppc ON PreorderProductPrice.id = pppc.preorderproductprice_id
WHERE $where
GROUP BY PreorderProductPrice.id
ORDER BY $order";
if(is_array($limit) && count($limit)) {
@@ -233,15 +258,28 @@ class PreorderProductPrice extends mfBaseModel {
if(array_key_exists("netoperator_id", $filter)) {
$netoperator_id = $filter['netoperator_id'];
if(is_numeric($netoperator_id)) {
if($netoperator_id === null || $netoperator_id === false) {
$where .= " AND PreorderProductPrice.netoperator_id IS NULL";
} elseif(is_numeric($netoperator_id)) {
$where .= " AND PreorderProductPrice.netoperator_id=$netoperator_id";
}
}
if(array_key_exists("preordercampaign_id", $filter)) {
$preordercampaign_id = $filter['preordercampaign_id'];
if(is_numeric($preordercampaign_id)) {
$where .= " AND PreorderProductPrice.preordercampaign_id=$preordercampaign_id";
if($preordercampaign_id === null || $preordercampaign_id === false) {
$where .= " AND (pppc.cnt IS NULL OR pppc.cnt = 0)";
} elseif(is_numeric($preordercampaign_id)) {
$where .= " AND pppc.preordercampaign_id=$preordercampaign_id";
}
}
if(array_key_exists("campaign_id", $filter)) {
$preordercampaign_id = $filter['campaign_id'];
if($preordercampaign_id === null || $preordercampaign_id === false) {
$where .= " AND (pppc.cnt IS NULL OR pppc.cnt = 0)";
} elseif(is_numeric($preordercampaign_id)) {
$where .= " AND pppc.preordercampaign_id=$preordercampaign_id";
}
}

View File

@@ -0,0 +1,253 @@
<?php
class PreorderProductPriceCampaign extends mfBaseModel {
private $price;
private $preordercampaign;
private $campaign;
private $preorderproduct;
private $creator;
private $editor;
public function getProperty($name) {
if($this->$name == null) {
if($name == "preorderproduct") {
$price = $this->getProperty("price");
$product = $price->preorderproduct;
if(!$product || !$product->id) {
return null;
}
$this->preorderproduct = $product;
return $this->preorderproduct;
}
if($name == "price") {
$price = new PreorderProductPrice($this->preorderproductprice_id);
if(!$price->id) {
return null;
}
$this->price = $price;
return $this->price;
}
if($name == "netowner") {
$netowner = new Address($this->netowner_id);
if(!$netowner->id) {
return null;
}
$this->netowner = $netowner;
return $this->netowner;
}
if($name == "preordercampaign" || $name == "campaign") {
$campaign = new PreorderCampaign($this->preordercampaign_id);
if(!$campaign->id) {
return null;
}
$this->preordercampaign = $campaign;
$this->campaign = $campaign;
return $this->preordercampaign;
}
if($name == "creator") {
$creator = mfValuecache::singleton()->get("Worker-id-".$this->create_by);
if($creator) {
$this->creator = $creator;
return $this->creator;
}
$this->creator = new User($this->create_by);
if(!$this->creator->id) {
return null;
}
mfValuecache::singleton()->set("Worker-id-".$this->create_by, $this->creator);
return $this->creator;
}
if($name == "editor") {
$editor = mfValuecache::singleton()->get("Worker-id-".$this->edit_by);
if($editor) {
$this->editor = $editor;
return $this->editor;
}
$this->editor = new User($this->edit_by);
if(!$this->editor->id) {
return null;
}
mfValuecache::singleton()->set("Worker-id-".$this->edit_by, $this->editor);
return $this->editor;
}
$classname = ucfirst($name);
$idfield = $name . "_id";
$this->$name = mfValuecache::singleton()->get("mfObjectmodel-$name-" . $this->$idfield);
if(!$this->$name) {
$this->$name = new $classname($this->$idfield);
}
if($this->$name->id) {
mfValuecache::singleton()->set("mfObjectmodel-$name-" . $this->$name->id, $this->$name);
return $this->$name;
} else {
return null;
}
}
return $this->$name;
}
/********************************
* Begin static Model functions
*/
public static function create(Array $data) {
$model = new PreorderProductPriceCampaign();
$table_fields = [
"preorderproductprice_id", "preordercampaign_id",
"create_by","edit_by","create","edit"
];
foreach($data as $field => $value) {
if(in_array($field, $table_fields)) {
$model->$field = $value;
}
}
$me = new User();
$me->loadMe();
if($model->create_by === null) {
$model->create_by = $me->id;
}
if($model->edit_by === null) {
$model->edit_by = $me->id;
}
return $model;
}
public static function getAll() {
$items = [];
$db = FronkDB::singleton();
$res = $db->select("PreorderProductPriceCampaign", "*", "1 = 1 ORDER BY preorderproductprice_id");
if($db->num_rows($res)) {
while($data = $db->fetch_object($res)) {
$items[] = new PreorderProductPriceCampaign($data);
}
}
return $items;
}
public static function getFirst($filter = [], $order = false) {
$db = FronkDB::singleton();
if(!$order) {
$order = "preorderproductprice_id ASC";
}
$where = self::getSqlFilter($filter);
$sql = "SELECT * FROM PreorderProductPriceCampaign
WHERE $where
ORDER BY $order LIMIT 1";
mfLoghandler::singleton()->debug($sql);
$res = $db->query($sql);
if($db->num_rows($res)) {
$data = $db->fetch_object($res);
$item = new PreorderProductPriceCampaign($data);
if($item->id) {
return $item;
} else {
return null;
}
}
return null;
}
public static function count($filter) {
$db = FronkDB::singleton();
$where = self::getSqlFilter($filter);
$sql = "SELECT COUNT(*) as cnt FROM PreorderProductPriceCampaign
WHERE $where";
mfLoghandler::singleton()->debug($sql);
$res = $db->query($sql);
if($db->num_rows($res)) {
$data = $db->fetch_object($res);
return $data->cnt;
}
return 0;
}
public static function search($filter, $limit = false, $order = false) {
//var_dump($filter);exit;
$items = [];
if(!$order) {
$order = "preorderproductprice_id ASC";
}
$db = FronkDB::singleton();
$where = self::getSqlFilter($filter);
$sql = "SELECT * FROM PreorderProductPriceCampaign
WHERE $where
ORDER BY $order";
if(is_array($limit) && count($limit)) {
if(is_numeric($limit['start']) && is_numeric($limit['count'])) {
$sql .= " LIMIT ".$limit['start'].", ".$limit['count'];
} elseif(is_numeric($limit['count'])) {
$sql .= " LIMIT ".$limit['count'];
}
}
mfLoghandler::singleton()->debug($sql);
$res = $db->query($sql);
if($db->num_rows($res)) {
while($data = $db->fetch_object($res)) {
$items[$data->id] = new PreorderProductPriceCampaign($data);
}
}
return $items;
}
private static function getSqlFilter($filter) {
$where = "1=1 ";
if(array_key_exists("preordercampaign_id", $filter)) {
$preordercampaign_id = $filter['preordercampaign_id'];
if(is_numeric($preordercampaign_id)) {
$where .= " AND PreorderProductPriceCampaign.preordercampaign_id=$preordercampaign_id";
}
}
if(array_key_exists("preorderproductprice_id", $filter)) {
$preorderproductprice_id = $filter['preorderproductprice_id'];
if(is_numeric($preorderproductprice_id)) {
$where .= " AND PreorderProductPriceCampaign.preorderproductprice_id=$preorderproductprice_id";
}
}
if(array_key_exists("add-where", $filter)) {
$where .= " ".$filter['add-where'];
}
//var_dump($filter, $where);exit;
return $where;
}
}

View File

@@ -9,13 +9,13 @@ final class PreorderProductChange extends AbstractMigration
{
if($this->getEnvironment() == "thetool") {
$pp = $this->table("PreorderProduct");
//$pp->changeColumn("type", "enum", ["null" => false, "values" => "enduser_setup, operator_setup, operator_usage"]);
//$pp->addColumn("price_setup", "decimal", ["null" => false, "default" => 0, "precision" => 14, "scale" => 4, "after" => "vatgroup_id"]);
$pp->changeColumn("type", "enum", ["null" => false, "values" => "enduser_setup, operator_setup, operator_usage"]);
$pp->addColumn("price_setup", "decimal", ["null" => false, "default" => 0, "precision" => 14, "scale" => 4, "after" => "vatgroup_id"]);
$pp->update();
$ppp = $this->table("PreorderProductPrice");
$ppp->addColumn("netoperator_id", "integer", ["null" => false, "after" => "netowner_id"]);
//$ppp->addColumn("price_setup", "decimal", ["null" => false, "default" => 0, "precision" => 14, "scale" => 4, "after" => "end_date"]);
$ppp->addColumn("price_setup", "decimal", ["null" => false, "default" => 0, "precision" => 14, "scale" => 4, "after" => "end_date"]);
$ppp->update();
}
@@ -27,7 +27,16 @@ final class PreorderProductChange extends AbstractMigration
public function down(): void
{
if($this->getEnvironment() == "thetool") {
$pp = $this->table("PreorderProduct");
$pp->changeColumn("type", "enum", ["null" => false, "values" => "enduser_setup, provider_setup, provider_usage"]);
$pp->removeColumn("price_setup");
$pp->update();
$ppp = $this->table("PreorderProductPrice");
$ppp->removeColumn("netoperator_id");
$ppp->removeColumn("price_setup");
//$ppp->removeColumn("description");
$ppp->update();
}
if($this->getEnvironment() == "addressdb") {

View File

@@ -0,0 +1,35 @@
<?php
declare(strict_types=1);
use Phinx\Migration\AbstractMigration;
final class PreorderProductChange2 extends AbstractMigration
{
public function up(): void
{
if($this->getEnvironment() == "thetool") {
$ppp = $this->table("PreorderProductPrice");
$ppp->changeColumn("netoperator_id", "integer", ["null" => true]);
$ppp->addColumn("description", "text", ["null" => true, "default" => null, "after" => "contract_term"]);
$ppp->update();
}
if($this->getEnvironment() == "addressdb") {
}
}
public function down(): void
{
if($this->getEnvironment() == "thetool") {
$ppp = $this->table("PreorderProductPrice");
$ppp->removeColumn("description");
$ppp->changeColumn("netoperator_id", "integer", ["null" => false]);
$ppp->update();
}
if($this->getEnvironment() == "addressdb") {
}
}
}

View File

@@ -0,0 +1,44 @@
<?php
declare(strict_types=1);
use Phinx\Migration\AbstractMigration;
final class CreatePreorderProductPriceCampaign extends AbstractMigration
{
public function up(): void
{
if($this->getEnvironment() == "thetool") {
$pppc = $this->table("PreorderProductPriceCampaign");
$pppc->addColumn("preorderproductprice_id", "integer", ["null" => false]);
$pppc->addColumn("preordercampaign_id", "integer", ["null" => false]);
$pppc->addColumn("create_by", "integer", ["null" => false]);
$pppc->addColumn("edit_by", "integer", ["null" => false]);
$pppc->addColumn("create", "integer", ["null" => false]);
$pppc->addColumn("edit", "integer", ["null" => false]);
$pppc->create();
$ppp = $this->table("PreorderProductPrice");
$ppp->removeColumn("preordercampaign_id");
$ppp->save();
}
if($this->getEnvironment() == "addressdb") {
}
}
public function down(): void
{
if($this->getEnvironment() == "thetool") {
$this->table("PreorderProductPriceCampaign")->drop()->save();
$this->table("PreorderProductPrice")->addColumn("preordercampaign_id", "integer", ["null" => true, "default" => null, "after" => "netowner_id"])->update();
}
if($this->getEnvironment() == "addressdb") {
}
}
}