WIP Voiceplan Zones

This commit is contained in:
Frank Schubert
2023-10-13 11:31:45 +02:00
parent 97432a24bb
commit 33c2c63100
17 changed files with 654 additions and 93 deletions

View File

@@ -68,6 +68,7 @@
<tr> <tr>
<th>Name</th> <th>Name</th>
<th>Beschreibung</th> <th>Beschreibung</th>
<th>Anzahl Tarifzonen</th>
<th>Anzahl Destinations</th> <th>Anzahl Destinations</th>
<th>Erstellt</th> <th>Erstellt</th>
<th></th> <th></th>
@@ -76,7 +77,8 @@
<tr> <tr>
<td><a href="<?=self::getUrl("Voiceplan", "view", ['id' => $plan->id])?>"><?=$plan->name?></a></td> <td><a href="<?=self::getUrl("Voiceplan", "view", ['id' => $plan->id])?>"><?=$plan->name?></a></td>
<td><?=$plan->description?></td> <td><?=$plan->description?></td>
<td><?=VoiceplandestinationModel::count(['voiceplan_id' => $plan->id])?></td> <td><?=count($plan->zones)?></td>
<td><?=count($plan->destinations)?></td>
<td><?=date("d.m.Y H:i", $plan->create)?> (<?=$plan->creator->name?>)</td> <td><?=date("d.m.Y H:i", $plan->create)?> (<?=$plan->creator->name?>)</td>
<td style="text-align: left; letter-spacing: 4px; font-size: 1.1em;"> <td style="text-align: left; letter-spacing: 4px; font-size: 1.1em;">
<a href="<?=self::getUrl("Voiceplan", "view", ["id" => $plan->id])?>"><i class="far fa-eyes" title="Anzeigen"></i></a> <a href="<?=self::getUrl("Voiceplan", "view", ["id" => $plan->id])?>"><i class="far fa-eyes" title="Anzeigen"></i></a>

View File

@@ -16,7 +16,7 @@
<li class="breadcrumb-item active"><?=$plan->name?></li> <li class="breadcrumb-item active"><?=$plan->name?></li>
</ol> </ol>
</div> </div>
<h4 class="page-title">Sprachtarife</h4> <h4 class="page-title">Tarifzonen</h4>
</div> </div>
</div> </div>
</div> </div>
@@ -30,10 +30,10 @@
<div class="row"> <div class="row">
<div class="col-12"> <div class="col-12">
<div class="float-left"> <div class="float-left">
<h4 class="header-title">Destinations für Sprachtarifpaket <?=$plan->name?></h4> <h4 class="header-title">Tarifzonen für Sprachtarifpaket <?=$plan->name?></h4>
</div> </div>
<div class="float-right"> <div class="float-right">
<a class="btn btn-primary mb-2" href="<?=self::getUrl("Voiceplandestination", "add", ["voiceplan_id" => $plan->id])?>"><i class="fas fa-plus"></i> Neue Destination anlegen</a> <a class="btn btn-primary mb-2" href="<?=self::getUrl("Voiceplanzone", "add", ["voiceplan_id" => $plan->id])?>"><i class="fas fa-plus"></i> Neue Tarifzone anlegen</a>
</div> </div>
</div> </div>
</div> </div>
@@ -43,8 +43,8 @@
<table class="table table-striped table-hover"> <table class="table table-striped table-hover">
<tr> <tr>
<th>Destination</th> <th>Zone</th>
<th>Prefix</th> <th>Anzahl Prefixes</th>
<th>Taktung</th> <th>Taktung</th>
<th>Einkaufspreis</th> <th>Einkaufspreis</th>
<th>Verkaufspreis</th> <th>Verkaufspreis</th>
@@ -52,19 +52,19 @@
<th>Bearbeitet</th> <th>Bearbeitet</th>
<th></th> <th></th>
</tr> </tr>
<?php foreach($destinations as $destination): ?> <?php foreach($zones as $zone): ?>
<tr> <tr>
<td><?=$destination->destination?></td> <td><a href="<?=self::getUrl("Voiceplanzone", "view", ["id" => $zone->id])?>"><?=$zone->name?></a></td>
<td><?=$destination->prefix?></td> <td><?=count($zone->destinations)?></td>
<td><?=($destination->increment_first && $destination->increment) ? "$destination->increment_first"."/".$destination->increment : ""?></td> <td><?=($zone->increment_first && $zone->increment) ? $zone->increment_first."/".$zone->increment : ""?></td>
<td><?=$destination->purchase_price?></td> <td><?=$zone->purchase_price?></td>
<td><?=$destination->price?></td> <td><?=$zone->price?></td>
<td><?=date("d.m.Y H:i", $plan->create)?> (<?=$plan->creator->name?>)</td> <td><?=date("d.m.Y H:i", $plan->create)?> (<?=$plan->creator->name?>)</td>
<td><?=date("d.m.Y H:i", $plan->edit)?> (<?=$plan->editor->name?>)</td> <td><?=date("d.m.Y H:i", $plan->edit)?> (<?=$plan->editor->name?>)</td>
<td style="text-align: left; letter-spacing: 4px; font-size: 1.1em;"> <td style="text-align: left; letter-spacing: 4px; font-size: 1.1em;">
<a href="<?=self::getUrl("Voiceplandestination", "view", ["id" => $destination->id])?>"><i class="far fa-eyes" title="Anzeigen"></i></a> <a href="<?=self::getUrl("Voiceplanzone", "view", ["id" => $zone->id])?>"><i class="far fa-eyes" title="Prefixes anzeigen"></i></a>
<a href="<?=self::getUrl("Voiceplandestination", "edit", ["id" => $destination->id])?>"><i class="far fa-edit" title="Bearbeiten"></i></a> <a href="<?=self::getUrl("Voiceplanzone", "edit", ["id" => $zone->id])?>"><i class="far fa-edit" title="Zone bearbeiten"></i></a>
<a href="<?=self::getUrl("Voiceplandestination", "delete", ["id" => $destination->id])?>" onclick="if(!confirm('Destination wirklich löschen?')) return false;" class="text-danger" title="Löschen"><i class="fas fa-trash"></i></a> <a href="<?=self::getUrl("Voiceplanzone", "delete", ["id" => $zone->id])?>" onclick="if(!confirm('Tarifzone wirklich löschen?')) return false;" class="text-danger" title="Löschen"><i class="fas fa-trash"></i></a>
</td> </td>
</tr> </tr>
<?php endforeach; ?> <?php endforeach; ?>

View File

@@ -7,7 +7,8 @@
<ol class="breadcrumb m-0"> <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("Voiceplan")?>">Sprachtarife</a></li> <li class="breadcrumb-item"><a href="<?=self::getUrl("Voiceplan")?>">Sprachtarife</a></li>
<li class="breadcrumb-item"><a href="<?=self::getUrl("Voiceplan", "view", ["id" => $voiceplan->id])?>"></a></li> <li class="breadcrumb-item"><a href="<?=self::getUrl("Voiceplan", "view", ["id" => $zone->voiceplan_id])?>">Sprachtarif <?=$zone->voiceplan->name?></a></li>
<li class="breadcrumb-item active">Destinationen Tarifzone <?=$zone->name?></li>
<li class="breadcrumb-item active"><?=($plan->id) ? "Destination ".$destination->destination." bearbeiten" : "Neu" ?></li> <li class="breadcrumb-item active"><?=($plan->id) ? "Destination ".$destination->destination." bearbeiten" : "Neu" ?></li>
</ol> </ol>
</div> </div>
@@ -31,19 +32,16 @@
<input type="hidden" name="id" value="<?=$destination->id?>" /> <input type="hidden" name="id" value="<?=$destination->id?>" />
<div class="form-group row"> <div class="form-group row">
<label class="col-lg-2 col-form-label" for="voiceplan_id">Tarifpaket</label> <label class="col-lg-2 col-form-label" for="voiceplanzone_id">Tarifzone</label>
<div class="col-lg-10"> <div class="col-lg-10">
<select name="voiceplan_id" class="form-control"> <select name="voiceplanzone_id" class="form-control">
<option value=""></option> <?php foreach($zones as $zone): ?>
<?php if($destination && $destination->voiceplan_id): ?> <?php if($destination->id): ?>
<?php foreach($voiceplans as $vp): ?> <option value="<?=$zone->id?>" <?=($zone->id == $destination->voiceplanzone_id) ? "selected='selected'" : ""?>><?=$zone->voiceplan->name?> - <?=$zone->name?></option>
<option value="<?=$vp->id?>" <?=($destination->voiceplan_id == $vp->id) ? "selected='selected'" : ""?>><?=$vp->name?></option> <?php else: ?>
<?php endforeach; ?> <option value="<?=$zone->id?>" <?=($zone->id == $zone_id) ? "selected='selected'" : ""?>><?=$zone->voiceplan->name?> - <?=$zone->name?></option>
<?php elseif($voiceplan): ?> <?php endif; ?>
<?php foreach($voiceplans as $vp): ?> <?php endforeach; ?>
<option value="<?=$vp->id?>" <?=($vp->id == $voiceplan->id) ? "selected='selected'" : ""?>><?=$vp->name?></option>
<?php endforeach; ?>
<?php endif; ?>
</select> </select>
</div> </div>
</div> </div>
@@ -62,27 +60,6 @@
</div> </div>
</div> </div>
<div class="form-group row">
<label class="col-lg-2 col-form-label" for="purchase_price">Einkaufspreis *</label>
<div class="col-lg-10">
<input type="text" class="form-control" name="purchase_price" id="purchase_price" value="<?=$destination->purchase_price?>" />
</div>
</div>
<div class="form-group row">
<label class="col-lg-2 col-form-label" for="price">Verkaufspreis *</label>
<div class="col-lg-10">
<input type="text" class="form-control" name="price" id="price" value="<?=$destination->price?>" />
</div>
</div>
<div class="form-group row">
<label class="col-lg-2 col-form-label" for="name">Taktung *</label>
<div class="col-lg-10">
<input type="text" class="form-control" name="increment" id="increment" value="<?=($destination->increment_first && $destination->increment) ? $destination->increment_first."/".$destination->increment : ""?>" placeholder="60/30" />
</div>
</div>
</div> </div>
</div> </div>

View File

@@ -0,0 +1,95 @@
<?php include(realpath(dirname(__FILE__)."/../../$mfLayoutPackage")."/header.php"); ?>
<!-- start page title -->
<div class="row">
<div class="col-12">
<div class="page-title-box">
<div class="page-title-right">
<ol class="breadcrumb m-0">
<li class="breadcrumb-item"><a href="<?=self::getUrl("Dashboard")?>"><?=MFAPPNAME_SLUG?></a></li>
<li class="breadcrumb-item"><a href="<?=self::getUrl("Voiceplan")?>">Sprachtarife</a></li>
<li class="breadcrumb-item active"><?=($plan->id) ? "Tarifzone ".$destination->destination." bearbeiten" : "Neue Tarifzone" ?></li>
</ol>
</div>
<h4 class="page-title">Sprachtarife</h4>
</div>
</div>
</div>
<!-- end page title -->
<div class="row">
<div class="col-lg-12">
<div class="card">
<div class="card-body">
<h4 class="header-title mb-2"><?=($zone->id) ? "Zone bearbeiten" : "Neue Zone"?></h4>
<form class="form-horizontal" method="post" action="<?=self::getUrl("Voiceplanzone", "save")?>">
<div class="card">
<div class="card-body">
<input type="hidden" name="id" value="<?=$zone->id?>" />
<div class="form-group row">
<label class="col-lg-2 col-form-label" for="name">Sprachtarif *</label>
<div class="col-lg-10">
<select name="voiceplan_id" class="form-control">
<?php foreach(VoiceplanModel::getAll() as $vp): ?>
<?php if($voiceplan_id): ?>
<option value="<?=$vp->id?>" <?=($vp->id == $voiceplan_id) ? "selected='selected'" : ""?>><?=$vp->name?></option>
<?php else: ?>
<option value="<?=$vp->id?>" <?=($vp->id == $zone->voiceplan_id) ? "selected='selected'" : ""?>><?=$vp->name?></option>
<?php endif; ?>
<?php endforeach; ?>
</select>
</div>
</div>
<div class="form-group row">
<label class="col-lg-2 col-form-label" for="name">Tarifzone Name *</label>
<div class="col-lg-10">
<input type="text" class="form-control" name="name" id="name" value="<?=$zone->name?>" />
</div>
</div>
<div class="form-group row">
<label class="col-lg-2 col-form-label" for="purchase_price">Einkaufspreis *</label>
<div class="col-lg-10">
<input type="text" class="form-control" name="purchase_price" id="purchase_price" value="<?=$zone->purchase_price?>" />
</div>
</div>
<div class="form-group row">
<label class="col-lg-2 col-form-label" for="price">Verkaufspreis *</label>
<div class="col-lg-10">
<input type="text" class="form-control" name="price" id="price" value="<?=$zone->price?>" />
</div>
</div>
<div class="form-group row">
<label class="col-lg-2 col-form-label" for="name">Taktung *</label>
<div class="col-lg-10">
<input type="text" class="form-control" name="increment" id="increment" value="<?=($zone->increment_first && $zone->increment) ? $zone->increment_first."/".$zone->increment : ""?>" placeholder="60/30" />
</div>
</div>
</div>
</div>
<div class="form-group row">
<label class="col-lg-2"></label>
<div class="col-lg-10">
<button type="submit" class="btn btn-primary">Speichern</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
<?php include(realpath(dirname(__FILE__)."/../../$mfLayoutPackage")."/footer.php"); ?>

View File

@@ -0,0 +1,99 @@
<?php
$pagination_baseurl = $this->getUrl($Mod,"View");
$pagination_baseurl_params = ["filter" => $filter, "id" => $zone->id];
$pagination_entity_name = "Destinations";
?>
<?php include(realpath(dirname(__FILE__)."/../../$mfLayoutPackage")."/header.php"); ?>
<!-- start page title -->
<div class="row">
<div class="col-12">
<div class="page-title-box">
<div class="page-title-right">
<ol class="breadcrumb m-0">
<li class="breadcrumb-item"><a href="<?=self::getUrl("Dashboard")?>"><?=MFAPPNAME_SLUG?></a></li>
<li class="breadcrumb-item"><a href="<?=self::getUrl("Voiceplan")?>">Sprachtarife</a></li>
<li class="breadcrumb-item"><a href="<?=self::getUrl("Voiceplan", "view", ["id" => $zone->voiceplan_id])?>">Sprachtarif <?=$zone->voiceplan->name?></a></li>
<li class="breadcrumb-item active">Destinationen Tarifzone <?=$zone->name?></li>
</ol>
</div>
<h4 class="page-title">Tarifzonen</h4>
</div>
</div>
</div>
<!-- end page title -->
<div class="row">
<div class="col-lg-12">
<div class="card">
<div class="card-body mb-3">
<div class="row">
<div class="col-12">
<div class="float-left">
<h4 class="header-title">Destinations für Sprachtarifzone <?=$zone->name?></h4>
</div>
<div class="float-right">
<a class="btn btn-primary mb-2" href="<?=self::getUrl("Voiceplandestination", "add", ["voiceplanzone_id" => $zone->id])?>"><i class="fas fa-plus"></i> Neue Destination anlegen</a>
</div>
</div>
</div>
<?php include(realpath(dirname(__FILE__)."/../")."/tpl/pagination.php"); ?>
<?php include(realpath(dirname(__FILE__)."/../")."/tpl/pagination-summary.php"); ?>
<table class="table table-striped table-hover">
<tr>
<th>Destination</th>
<th>Prefix</th>
<th>Erstellt</th>
<th>Bearbeitet</th>
<th></th>
</tr>
<?php foreach($destinations as $destination): ?>
<tr>
<td><?=$destination->destination?></td>
<td><?=$destination->prefix?></td>
<td><?=date("d.m.Y H:i", $zone->create)?> (<?=$zone->creator->name?>)</td>
<td><?=date("d.m.Y H:i", $zone->edit)?> (<?=$zone->editor->name?>)</td>
<td style="text-align: left; letter-spacing: 4px; font-size: 1.1em;">
<a href="<?=self::getUrl("Voiceplanzone", "edit", ["id" => $zone->id])?>"><i class="far fa-edit" title="Zone bearbeiten"></i></a>
<a href="<?=self::getUrl("Voiceplanzone", "delete", ["id" => $zone->id])?>" onclick="if(!confirm('Tarifzone wirklich löschen?')) return false;" class="text-danger" title="Löschen"><i class="fas fa-trash"></i></a>
</td>
</tr>
<?php endforeach; ?>
</table>
<?php include(realpath(dirname(__FILE__)."/../")."/tpl/pagination-summary.php"); ?>
<?php include(realpath(dirname(__FILE__)."/../")."/tpl/pagination.php"); ?>
</div>
</div>
</div>
</div>
<script type="text/javascript">
function toggleBlock(id) {
$('#block-detail-' + id).toggle();
if($('#block-detail-' + id).is(":hidden")) {
$('#block-' + id).removeClass("table-info");
$('#block-' + id).removeClass("text-info");
} else {
$('#block-' + id).addClass("text-info");
$('#block-' + id).addClass("table-info");
}
}
var block;
var hash = window.location.hash.substr(1);
var match = hash.match(/block=(\d+)/);
if(match && match[1]) {
block = match[1]
toggleBlock(block);
}
</script>
<?php include(realpath(dirname(__FILE__)."/../../$mfLayoutPackage")."/footer.php"); ?>

View File

@@ -100,7 +100,7 @@
</a> </a>
<ul class="submenu"> <ul class="submenu">
<?php if($me->isAdmin() || $me->can("Voipnumbering")): ?><li><a href="<?=self::getUrl("Voicenumberblock")?>"><i class="fad fa-fw fa-phone-office text-info"></i> Rufnummernblöcke</a></li><?php endif; ?> <?php if($me->isAdmin() || $me->can("Voipnumbering")): ?><li><a href="<?=self::getUrl("Voicenumberblock")?>"><i class="fad fa-fw fa-phone-office text-info"></i> Rufnummernblöcke</a></li><?php endif; ?>
<?php if($me->isAdmin() || $me->can("Voiceplan")): ?><li><a href="<?=self::getUrl("Voiceplan")?>"><i class="fas fa-fw fa-phone-arrow-up-right text-info"></i> Rufnummernpläne</a></li><?php endif; ?> <?php if($me->isAdmin() || $me->can("Voiceplan")): ?><li><a href="<?=self::getUrl("Voiceplan")?>"><i class="fas fa-fw fa-phone-arrow-up-right text-info"></i> Sprachtarife</a></li><?php endif; ?>
</ul> </ul>
</li> </li>
<?php endif; ?> <?php endif; ?>

View File

@@ -73,7 +73,7 @@ class OpenAccessId extends mfBaseModel {
$unit_extdata = $extdata; $unit_extdata = $extdata;
} }
if(is_object($extdata) && isset($extdata->rimo) && isset($extdata->rimo->ftu->id)) { if(is_object($extdata) && isset($extdata->rimo) && isset($extdata->rimo->ftu->id) && $extdata->rimo->ftu->id) {
//var_dump($extdata);exit; //var_dump($extdata);exit;
$fetch_ftu = false; $fetch_ftu = false;
} }

View File

@@ -4,6 +4,7 @@ class Voiceplan extends mfBaseModel {
private $creator; private $creator;
private $editor; private $editor;
private $zones;
private $destinations; private $destinations;
public function importDestinationsFromCsv(File $file) { public function importDestinationsFromCsv(File $file) {
@@ -68,10 +69,18 @@ class Voiceplan extends mfBaseModel {
if($this->$name == null) { if($this->$name == null) {
if($name == "destinations") { if($name == "destinations") {
$this->destinations = VoiceplandestinationModel::search(["voiceplan_id" => $this->id]); $this->destinations = [];
foreach($this->getProperty("zones") as $zone) {
$this->destinations[] = $zone->destinations;
}
return $this->destinations; return $this->destinations;
} }
if($name == "zones") {
$this->zones = VoiceplanzoneModel::search(["voiceplan_id" => $this->id]);
return $this->zones;
}
if($name == "creator") { if($name == "creator") {
$user = mfValuecache::singleton()->get("Worker-id-".$this->create_by); $user = mfValuecache::singleton()->get("Worker-id-".$this->create_by);
if($user) { if($user) {

View File

@@ -73,9 +73,9 @@ class VoiceplanController extends mfBaseController {
$pagination['start'] = intval($this->request->s); $pagination['start'] = intval($this->request->s);
} }
$pagination['maxItems'] = VoiceplandestinationModel::count(['voiceplan_id' => $id]); $pagination['maxItems'] = VoiceplanzoneModel::count(['voiceplan_id' => $id]);
$destinations = VoiceplandestinationModel::search(['voiceplan_id' => $id], $pagination); $zones = VoiceplanzoneModel::search(['voiceplan_id' => $id], $pagination);
$this->layout()->set("destinations", $destinations); $this->layout()->set("zones", $zones);
$this->layout()->set("pagination", $pagination); $this->layout()->set("pagination", $pagination);

View File

@@ -3,4 +3,38 @@
class Voiceplandestination extends mfBaseModel { class Voiceplandestination extends mfBaseModel {
protected $forcestr = ["name", "destination", "prefix"]; protected $forcestr = ["name", "destination", "prefix"];
private $voiceplan;
public function getProperty($name) {
if($this->$name == null) {
if(!$this->id) {
return null;
}
if($name == "voiceplan") {
$zone = $this->getProperty("voiceplanzone");
if($zone->voiceplan_id) {
$voiceplan = new Voiceplan($zone->voiceplan_id);
if($voiceplan->id) {
$this->voiceplan = $voiceplan;
}
}
return $this->voiceplan;
}
$classname = ucfirst($name);
$idfield = $name."_id";
$this->$name = new $classname($this->$idfield);
if($this->$name->id) {
return $this->$name;
} else {
return null;
}
}
return $this->$name;
}
} }

View File

@@ -17,13 +17,14 @@ class VoiceplandestinationController extends mfBaseController {
protected function addAction() { protected function addAction() {
$this->layout()->setTemplate("Voiceplandestination/Form"); $this->layout()->setTemplate("Voiceplandestination/Form");
$voiceplans = VoiceplanModel::getAll(); $zones = VoiceplanzoneModel::getAll();
$this->layout()->set("voiceplans", $voiceplans); $this->layout()->set("zones", $zones);
$voiceplan_id = $this->request->voiceplan_id; $zone_id = $this->request->voiceplanzone_id;
if($voiceplan_id) { if(strtolower($this->action) == "add" && $zone_id) {
$voiceplan = new Voiceplan($voiceplan_id); $zone = new Voiceplanzone($zone_id);
$this->layout()->set("voiceplan", $voiceplan); $this->layout()->set("zone", $zones);
$this->layout()->set("zone_id", $zone->id);
} }
} }
@@ -47,7 +48,7 @@ class VoiceplandestinationController extends mfBaseController {
protected function saveAction() { protected function saveAction() {
$r = $this->request; $r = $this->request;
var_dump($r); //var_dump($r);exit;
$id = $r->id; $id = $r->id;
if(is_numeric($id) && $id > 0) { if(is_numeric($id) && $id > 0) {
@@ -63,25 +64,11 @@ class VoiceplandestinationController extends mfBaseController {
} }
$data = []; $data = [];
$data['voiceplan_id'] = $r->voiceplan_id; $data['voiceplanzone_id'] = $r->voiceplanzone_id;
$data['destination'] = $r->destination; $data['destination'] = $r->destination;
$data['prefix'] = intval($r->prefix); $data['prefix'] = intval($r->prefix);
$data['purchase_price'] = (str_replace(",",".",$r->purchase_price)) ? str_replace(",",".",$r->purchase_price) : 0;
$data['price'] = (str_replace(",",".",$r->price)) ? str_replace(",",".",$r->price) : 0;
if($r->increment) { if(!$data['destination'] || !$data['prefix'] || !$data['voiceplanzone_id']) {
$increments = explode("/",$r->increment);
if(count($increments) != 2) {
$this->layout()->setFlash("Ungültige Taktung", "error");
$this->layout()->set("destination", VoiceplandestinationModel::create($data));
return $this->addAction();
}
$data["increment_first"] = $increments[0];
$data["increment"] = $increments[1];
}
if(!$data['destination'] || !$data['prefix'] || !$data['voiceplan_id']) {
$this->layout()->setFlash("Destination, Prefix und Tarifpaket sind erforderlich", "error"); $this->layout()->setFlash("Destination, Prefix und Tarifpaket sind erforderlich", "error");
$this->layout()->set("destination", VoiceplandestinationModel::create($data)); $this->layout()->set("destination", VoiceplandestinationModel::create($data));
return $this->addAction(); return $this->addAction();
@@ -100,6 +87,6 @@ class VoiceplandestinationController extends mfBaseController {
return $this->addAction(); return $this->addAction();
} }
$this->redirect("Voiceplan", "view", ["id" => $destination->voiceplan_id]); $this->redirect("Voiceplanzone", "view", ["id" => $destination->voiceplanzone_id]);
} }
} }

View File

@@ -1,14 +1,9 @@
<?php <?php
class VoiceplandestinationModel { class VoiceplandestinationModel {
public $voiceplan_id; public $voiceplanzone_id;
public $description;
public $destination; public $destination;
public $prefix; public $prefix;
public $purchase_price;
public $price;
public $increment_first;
public $increment;
public $create_by; public $create_by;
public $edit_by; public $edit_by;
@@ -124,10 +119,10 @@ class VoiceplandestinationModel {
return $where; return $where;
} }
if(array_key_exists("voiceplan_id", $filter)) { if(array_key_exists("voiceplanzone_id", $filter)) {
$voiceplan_id = $filter['voiceplan_id']; $voiceplanzone_id = $filter['voiceplanzone_id'];
if(is_numeric($voiceplan_id)) { if(is_numeric($voiceplanzone_id)) {
$where .= " AND voiceplan_id = $voiceplan_id"; $where .= " AND voiceplanzone_id = $voiceplanzone_id";
} }
} }

View File

@@ -0,0 +1,33 @@
<?php
class Voiceplanzone extends mfBaseModel {
private $destinations;
private $voiceplan;
public function getProperty($name) {
if($this->$name == null) {
if(!$this->id) {
return null;
}
if($name == "destinations") {
$this->destinations = VoiceplandestinationModel::search(["voiceplanzone_id" => $this->id]);
return $this->destinations;
}
$classname = ucfirst($name);
$idfield = $name."_id";
$this->$name = new $classname($this->$idfield);
if($this->$name->id) {
return $this->$name;
} else {
return null;
}
}
return $this->$name;
}
}

View File

@@ -0,0 +1,140 @@
<?php
class VoiceplanzoneController extends mfBaseController {
protected function init() {
$this->needlogin=true;
$me = new User();
$me->loadMe();
$this->me = $me;
$this->layout()->set("me",$me);
if(!$me->isAdmin()) {
$this->redirect("Dashboard");
}
}
protected function addAction() {
$this->layout()->setTemplate("Voiceplanzone/Form");
if(strtolower($this->action) == "add" && $this->request->voiceplan_id) {
$this->layout()->set("voiceplan_id", $this->request->voiceplan_id);
$this->layout()->set("voiceplan", new Voiceplan($this->request->voiceplan_id));
}
}
protected function viewAction() {
$this->layout()->setTemplate("Voiceplanzone/View");
$id = $this->request->id;
if(!is_numeric($id) || $id < 1) {
$this->layout()->setFlash("Tarifzone nicht gefunden.", "error");
$this->redirect("Voiceplan");
}
$zone = new Voiceplanzone($id);
if(!$zone->id) {
$this->layout()->setFlash("Tarifzone nicht gefunden.", "error");
$this->redirect("Voiceplan");
}
$this->layout()->set("zone", $zone);
$pagination = [];
$pagination['start'] = 0;
$pagination['count'] = 20;
$pagination['maxItems'] = 0;
if(is_numeric($this->request->s)) {
$pagination['start'] = intval($this->request->s);
}
$pagination['maxItems'] = VoiceplandestinationModel::count(['voiceplanzone_id' => $id]);
$destinations = VoiceplandestinationModel::search(['voiceplanzone_id' => $id], $pagination);
$this->layout()->set("destinations", $destinations);
$this->layout()->set("pagination", $pagination);
}
protected function editAction() {
$id = $this->request->id;
if(!is_numeric($id) || $id < 1) {
$this->layout()->setFlash("Tarifzone nicht gefunden.", "error");
$this->redirect("Voiceplan");
}
$zone = new Voiceplanzone($id);
if(!$zone->id) {
$this->layout()->setFlash("Tarifzone nicht gefunden.", "error");
$this->redirect("Voiceplan");
}
$this->layout()->set("zone", $zone);
return $this->addAction();
}
protected function saveAction() {
$r = $this->request;
//var_dump($r);exit;
$id = $r->id;
if(is_numeric($id) && $id > 0) {
$mode = "edit";
$zone = new Voiceplanzone($id);
if(!$zone->id) {
$this->layout()->setFlash("Tarifzone nicht gefunden", "error");
$this->redirect("Voiceplan");
}
} else {
$id = false;
$mode = "add";
}
$data["voiceplan_id"] = $r->voiceplan_id;
$data["name"] = $r->name;
$data['purchase_price'] = (str_replace(",",".",$r->purchase_price)) ? str_replace(",",".",$r->purchase_price) : 0;
$data['price'] = (str_replace(",",".",$r->price)) ? str_replace(",",".",$r->price) : 0;
if($r->increment) {
$increments = explode("/",$r->increment);
if(count($increments) != 2) {
$this->layout()->setFlash("Ungültige Taktung", "error");
if($mode == "edit") {
$this->redirect("Voiceplanzone", "edit", ["id" => $id]);
} else {
$this->layout()->set("zone", VoiceplanzoneModel::create($data));
return $this->addAction();
}
}
$data["increment_first"] = $increments[0];
$data["increment"] = $increments[1];
}
if(!$data['name'] || !$data['voiceplan_id']) {
$this->layout()->setFlash("Name und Tarifpaket sind erforderlich", "error");
if($mode == "edit") {
$this->redirect("Voiceplanzone", "edit", ["id" => $id]);
} else {
$this->layout()->set("destination", VoiceplanzoneModel::create($data));
return $this->addAction();
}
}
if($mode == "edit") {
$zone->update($data);
} else {
$zone = VoiceplanzoneModel::create($data);
}
$id = $zone->save();
if(!$id) {
$this->layout()->setFlash("Fehler beim Speichern!", "error");
$this->layout()->set("zone", $zone);
return $this->addAction();
}
$this->redirect("Voiceplan", "view", ["id" => $zone->voiceplan_id]);
}
}

View File

@@ -0,0 +1,134 @@
<?php
class VoiceplanzoneModel {
public $voiceplan_id;
public $name;
public $purchase_price;
public $price;
public $increment_first;
public $increment;
public $create_by;
public $edit_by;
public $create;
public $edit;
public static function create(Array $data) {
$model = new Voiceplanzone();
foreach($data as $field => $value) {
if(property_exists(get_called_class(), $field)) {
$model ->$field = $value;
}
}
$me = mfValuecache::singleton()->get("me");
if(!$me) {
$me = new User();
$me->loadMe();
mfValuecache::singleton()->set("me", $me);
}
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("Voiceplanzone", "*", "1=1 ORDER BY voiceplan_id,name");
if($db->num_rows($res)) {
while($data = $db->fetch_object($res)) {
$items[] = new Voiceplanzone($data);
}
}
return $items;
}
public static function getFirst() {
$db = FronkDB::singleton();
$where = self::getSqlFilter($filter);
$res = $db->select("Voiceplanzone", "*", "$where ORDER BY voiceplan_id,name");
if($db->num_rows($res)) {
$data = $db->fetch_object($res);
$item = new Voiceplanzone($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 Voiceplanzone
WHERE $where
";
$res = $db->query($sql);
if($db->num_rows($res)) {
$data = $db->fetch_object($res);
return $data->cnt;
}
return 0;
}
public static function search($filter) {
$items = [];
$db = FronkDB::singleton();
$where = self::getSqlFilter($filter);
$sql = "SELECT * FROM Voiceplanzone
WHERE $where
ORDER BY voiceplan_id,name";
$res = $db->query($sql);
if($db->num_rows($res)) {
while($data = $db->fetch_object($res)) {
$items[] = new Voiceplanzone($data);
}
}
return $items;
}
private static function getSqlFilter($filter) {
$where = "1=1 ";
if(array_key_exists("voiceplan_id", $filter)) {
$voiceplan_id = $filter['voiceplan_id'];
if(is_numeric($voiceplan_id)) {
$where .= " AND voiceplan_id=$voiceplan_id";
}
}
//var_dump($filter);exit;
if(array_key_exists("name", $filter)) {
$name = FronkDB::singleton()->escape($filter['name']);
if($name) {
$where .= " AND name='$name'";
}
}
//var_dump($filter, $where);exit;
return $where;
}
}

View File

@@ -82,10 +82,10 @@ final class AddVoicenumberTables extends AbstractMigration
public function down(): void public function down(): void
{ {
if($this->getEnvironment() == "thetool") { if($this->getEnvironment() == "thetool") {
$this->table("Voiceplandestination")->drop(); $this->table("Voiceplandestination")->drop()->save();
$this->table("Voiceplan")->drop(); $this->table("Voiceplan")->drop()->save();
$this->table("Voicenumber")->drop(); $this->table("Voicenumber")->drop()->save();
$this->table("Voicenumberblock")->drop(); $this->table("Voicenumberblock")->drop()->save();
} }
if($this->getEnvironment() == "addressdb") { if($this->getEnvironment() == "addressdb") {

View File

@@ -0,0 +1,56 @@
<?php
declare(strict_types=1);
use Phinx\Migration\AbstractMigration;
final class AddVoiceplanZone extends AbstractMigration
{
public function up(): void
{
if($this->getEnvironment() == "thetool") {
$table = $this->table("Voiceplanzone");
$table->addColumn("voiceplan_id", "integer", ["null" => false]);
$table->addColumn("name", "string", ["null" => false, "limit" => 255]);
$table->addColumn("purchase_price", "decimal", ["null" => false, "precision" => 14, "scale" => 4]);
$table->addColumn("price", "decimal", ["null" => false, "precision" => 14, "scale" => 4]);
$table->addColumn("increment_first", "integer", ["null" => false, "default" => 60]);
$table->addColumn("increment", "integer", ["null" => false, "default" => 30]);
$table->addColumn("create_by", "integer", ["null" => false]);
$table->addColumn("edit_by", "integer", ["null" => false]);
$table->addColumn("create", "integer", ["null" => false]);
$table->addColumn("edit", "integer", ["null" => false]);
$table->create();
$table = $this->table("Voiceplandestination");
$table->removeColumn("purchase_price");
$table->removeColumn("price");
$table->removeColumn("increment_first");
$table->removeColumn("increment");
$table->renameColumn("voiceplan_id", "voiceplanzone_id");
$table->update();
}
if($this->getEnvironment() == "addressdb") {
}
}
public function down(): void
{
if($this->getEnvironment() == "thetool") {
$table = $this->table("Voiceplandestination");
$table->renameColumn("voiceplanzone_id", "voiceplan_id");
$table->addColumn("purchase_price", "decimal", ["null" => false, "precision" => 14, "scale" => 4]);
$table->addColumn("price", "decimal", ["null" => false, "precision" => 14, "scale" => 4]);
$table->addColumn("increment_first", "integer", ["null" => false, "default" => 1]);
$table->addColumn("increment", "integer", ["null" => false, "default" => 1]);
$table->update();
$this->table("Voiceplanzone")->drop()->save();
}
if($this->getEnvironment() == "addressdb") {
}
}
}