Added Products
This commit is contained in:
@@ -10,8 +10,7 @@
|
||||
<div class="page-title-right">
|
||||
<ol class="breadcrumb m-0">
|
||||
<li class="breadcrumb-item"><a href="javascript: void(0);">the-tool</a></li>
|
||||
<li class="breadcrumb-item"><a href="javascript: void(0);">Dashboard</a></li>
|
||||
<li class="breadcrumb-item active">Starter</li>
|
||||
<li class="breadcrumb-item active">Dashboard</li>
|
||||
</ol>
|
||||
</div>
|
||||
<h4 class="page-title">Dashboard</h4>
|
||||
|
||||
@@ -133,6 +133,7 @@
|
||||
<table class="table table-bordered">
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Netzeigentümer</th>
|
||||
<?php foreach(TT_NETWORK_ROLES as $role): ?>
|
||||
<th class="text-center"><?=__($role)?></th>
|
||||
<?php endforeach ?>
|
||||
@@ -141,10 +142,11 @@
|
||||
<?php foreach($network->addresstypes as $address_id => $addresstypes): ?>
|
||||
<tr>
|
||||
<td><?=AddressModel::getOne($address_id)->getCompanyOrName()?></td>
|
||||
<td><input type="checkbox" <?=($network->owner_id == $address_id) ? "checked='checked'" : ""?> disabled="disabled" /></td>
|
||||
<?php foreach(TT_NETWORK_ROLES as $role): ?>
|
||||
<td class="text-center">
|
||||
<?php if(AddresstypeModel::getFirst(['address_id' => $address_id, 'addresstype' => [$role]]) !== null): ?>
|
||||
<input
|
||||
<input type="checkbox"
|
||||
type="checkbox"
|
||||
name="roles[<?=$address_id?>][]"
|
||||
value="<?=$role?>"
|
||||
@@ -158,7 +160,7 @@
|
||||
</td>
|
||||
<?php endforeach; ?>
|
||||
<td class="controls" style="text-align: left; letter-spacing: 4px; font-size: 1.1em;">
|
||||
<a href="<?=self::getUrl("NetworkAddress", "delete", ["id" => $address_id])?>" class="text-danger" title="Löschen"><i class="fas fa-trash"></i></a>
|
||||
<a href="<?=self::getUrl("NetworkAddress", "delete", ["network_id" => $network->id, "address_id" => $address_id])?>" onclick="if(!confirm('Berechtigungen wirklich löschen?')) return false;" class="text-danger" title="Löschen"><i class="fas fa-trash"></i></a>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
@@ -184,7 +186,7 @@
|
||||
|
||||
<tr>
|
||||
<td>
|
||||
<select class="select2 form-control " name="address_id" id="address_id">
|
||||
<select class="select2 form-control" name="address_id" id="address_id">
|
||||
<option></option>
|
||||
<?php foreach(AddressModel::search(["parents_only" => 1]) as $address): ?>
|
||||
<?php if(is_array($network->addresstypes) && array_key_exists($address->id, $network->addresstypes)) continue; ?>
|
||||
|
||||
@@ -148,10 +148,10 @@
|
||||
$(this).on('wheel.disableScroll', function (e) {
|
||||
e.preventDefault()
|
||||
})
|
||||
})
|
||||
});
|
||||
$('form').on('blur', 'input[type=number]', function (e) {
|
||||
$(this).off('wheel.disableScroll')
|
||||
})
|
||||
});
|
||||
</script>
|
||||
|
||||
<?php include(realpath(dirname(__FILE__)."/../")."/footer.php"); ?>
|
||||
235
Layout/default/Product/Form.php
Normal file
235
Layout/default/Product/Form.php
Normal file
@@ -0,0 +1,235 @@
|
||||
<?php include(realpath(dirname(__FILE__)."/../")."/header.php"); ?>
|
||||
|
||||
<div class="wrapper">
|
||||
<div class="container-fluid">
|
||||
|
||||
<!-- 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")?>">the-tool</a></li>
|
||||
<li class="breadcrumb-item"><a href="<?=self::getUrl("Product")?>">Produkte</a></li>
|
||||
<li class="breadcrumb-item active"><?=($product->id) ? "bearbeiten" : "Neu" ?></li>
|
||||
</ol>
|
||||
</div>
|
||||
<h4 class="page-title">Produkte</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"><?=($product->id) ? "Produkt bearbeiten" : "Neues Produkt"?></h4>
|
||||
|
||||
<form class="form-horizontal" method="post" action="<?=self::getUrl("Product", "save")?>">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
|
||||
<input type="hidden" name="id" value="<?=$product->id?>" />
|
||||
|
||||
<div class="form-group row">
|
||||
<label class="col-lg-2 col-form-label" for="name">Name</label>
|
||||
<div class="col-lg-10">
|
||||
<input type="text" class="form-control" name="name" id="name" value="<?=$product->name?>" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group row">
|
||||
<label class="col-lg-2 col-form-label" for="description">Beschreibung</label>
|
||||
<div class="col-lg-10">
|
||||
<textarea name="description" id="description" class="form-control" rows="2"><?=$product->description?></textarea>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group row">
|
||||
<label class="col-lg-2 col-form-label" for="external">Fremdprodukt</label>
|
||||
<div class="col-lg-10">
|
||||
<select class="select2 form-control " name="external" id="external">
|
||||
<option value="0" <?=($product->external != 1) ? "selected='selected'" : ""?>>Nein</option>
|
||||
<option value="1" <?=($product->external == 1) ? "selected='selected'" : ""?>>Ja</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group row">
|
||||
<label class="col-lg-2 col-form-label" for="productgroup_id">Produktgruppe</label>
|
||||
<div class="col-lg-10">
|
||||
<select class="select2 form-control" name="productgroup_id" id="productgroup_id">
|
||||
<option></option>
|
||||
<option value="new">Neue Produktgruppe...</option>
|
||||
<option value="1">1</option>
|
||||
<?php foreach($productgroups as $group): ?>
|
||||
<option value="<?=$group->id?>" <?=($product->productgroup_id == $group->id) ? "selected='selected'" : ""?>><?=$group->name?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group row" id="productgroup_form" style="display:none;">
|
||||
<label class="col-lg-2 col-form-label" for="productgroup_new"></label>
|
||||
<div class="col-lg-10">
|
||||
<div class="row">
|
||||
<div class="col-lg-2">Neue Produktgruppe:</div>
|
||||
<div class="col-lg-10">
|
||||
Name: <input type="text" class="form-control" name="productgroup_new_name" id="productgroup_new_name" value="<?=$productgroup_new_name?>">
|
||||
Code: <input type="text" class="form-control" name="productgroup_new_code" id="productgroup_new_code" value="<?=$productgroup_new_code?>">
|
||||
Beschreibung: <textarea class="form-control" name="productgroup_new_description" id="productgroup_new_description"><?=$productgroup_new_description?></textarea>
|
||||
Interne Notiz: <textarea class="form-control" name="productgroup_new_note" id="productgroup_new_note"><?=$productgroup_new_note?></textarea>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group row">
|
||||
<label class="col-lg-2 col-form-label" for="producttech_id">Technologie</label>
|
||||
<div class="col-lg-10">
|
||||
<select class="select2 form-control " name="producttech_id" id="producttech_id">
|
||||
<option></option>
|
||||
<option value="new">Neue Technologie...</option>
|
||||
<?php foreach($producttechs as $tech): ?>
|
||||
<option value="<?=$tech->id?>" <?=($product->producttech_id == $tech->id) ? "selected='selected'" : ""?>><?=$tech->name?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group row" id="producttech_form" style="display: none;">
|
||||
<label class="col-lg-2 col-form-label" for="producttech_new"></label>
|
||||
<div class="col-lg-10">
|
||||
<div class="row">
|
||||
<div class="col-lg-2">Neue Technologie:</div>
|
||||
<div class="col-lg-10">
|
||||
Name: <input type="text" class="form-control" name="producttech_new_name" id="producttech_new_name" value="<?=$producttech_new_name?>">
|
||||
Code: <input type="text" class="form-control" name="producttech_new_code" id="producttech_new_code" value="<?=$producttech_new_code?>">
|
||||
Beschreibung: <textarea class="form-control" name="producttech_new_description" id="productgroup_new_description"><?=$producttech_new_description?></textarea>
|
||||
Interne Notiz: <textarea class="form-control" name="producttech_new_note" id="productgroup_new_note"><?=$producttech_new_note?></textarea>
|
||||
</div>
|
||||
</div>
|
||||
</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" name="price" id="price" class="form-control" value="<?=$this::dotToComma($product->price)?>" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group row">
|
||||
<label class="col-lg-2 col-form-label" for="nne">Netznutzungsentgelt (NNE)</label>
|
||||
<div class="col-lg-10">
|
||||
<input type="text" class="form-control" name="price_nne" id="price_nne" value="<?=$this::dotToComma($product->price_nne)?>">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group row">
|
||||
<label class="col-lg-2 col-form-label" for="nbe">Netzbetriebsentgelt (NBE)</label>
|
||||
<div class="col-lg-10">
|
||||
<input type="text" class="form-control" name="price_nbe" id="price_nbe" value="<?=$this::dotToComma($product->price_nbe)?>">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group row">
|
||||
<label class="col-lg-2 col-form-label" for="billing_period">Verrechnungsperiode</label>
|
||||
<div class="col-lg-10">
|
||||
<select class="select2 form-control " name="billing_period" id="billing_period">
|
||||
<option value="1" <?=($product->billing_period == 1) ? "selected='selected'" : ""?>>Jährlich</option>
|
||||
<option value="12" <?=($product->billing_period == 12) ? "selected='selected'" : ""?>>Monatlich</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php if(is_array($attributes) && count($attributes)): ?>
|
||||
<h4 class="header-title mb-2">Zusatzdaten</h4>
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<div class="form-group row">
|
||||
<label class="col-lg-2 col-form-label" for="rtrcode">RTR Betreiber ID</label>
|
||||
<div class="col-lg-10">
|
||||
<input class="form-control" name="attributes[rtrcode]" id="rtrcode" value="<?=$address->attributes['rtrcode']->value?>">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<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"><?=$product->note?></textarea>
|
||||
</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>
|
||||
|
||||
</div> <!-- end container-fluid -->
|
||||
</div>
|
||||
<!-- end wrapper -->
|
||||
|
||||
<script type="text/javascript">
|
||||
$("#productgroup_id").select2({
|
||||
allowClear: true,
|
||||
placeholder: ""
|
||||
});
|
||||
$("#producttech_id").select2({
|
||||
allowClear: true,
|
||||
placeholder: ""
|
||||
});
|
||||
|
||||
|
||||
$('#productgroup_id').change(function() {
|
||||
var value = $('#productgroup_id option:selected').val();
|
||||
console.log(value);
|
||||
if(value == "new") {
|
||||
$('#productgroup_form').show();
|
||||
} else {
|
||||
$('#productgroup_form').hide();
|
||||
}
|
||||
});
|
||||
|
||||
$('#producttech_id').change(function() {
|
||||
var value = $('#producttech_id option:selected').val();
|
||||
console.log(value);
|
||||
if(value == "new") {
|
||||
$('#producttech_form').show();
|
||||
} else {
|
||||
$('#producttech_form').hide();
|
||||
}
|
||||
});
|
||||
|
||||
// disable mousewheel on input number field when in focus
|
||||
$('form').on('focus', 'input[type=number]', function (e) {
|
||||
$(this).on('wheel.disableScroll', function (e) {
|
||||
e.preventDefault()
|
||||
})
|
||||
});
|
||||
$('form').on('blur', 'input[type=number]', function (e) {
|
||||
$(this).off('wheel.disableScroll')
|
||||
});
|
||||
</script>
|
||||
|
||||
<?php include(realpath(dirname(__FILE__)."/../")."/footer.php"); ?>
|
||||
69
Layout/default/Product/Index.php
Normal file
69
Layout/default/Product/Index.php
Normal file
@@ -0,0 +1,69 @@
|
||||
<?php include(realpath(dirname(__FILE__)."/../")."/header.php"); ?>
|
||||
|
||||
<div class="wrapper">
|
||||
<div class="container-fluid">
|
||||
|
||||
<!-- 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")?>">the-tool</a></li>
|
||||
<li class="breadcrumb-item active"><a href="<?=self::getUrl("Product")?>">Produkte</a></li>
|
||||
</ol>
|
||||
</div>
|
||||
<h4 class="page-title">Produkte</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="float-left">
|
||||
<h4 class="header-title">Liste aller Produkte</h4>
|
||||
</div>
|
||||
<div class="float-right">
|
||||
<a class="btn btn-primary mb-2" href="<?=self::getUrl("Product", "add")?>"><i class="fas fa-plus"></i> Neues Produkt anlegen</a>
|
||||
</div>
|
||||
|
||||
<table class="table table-striped table-hover">
|
||||
<tr>
|
||||
<th>Fremdprodukt</th>
|
||||
<th>Gruppe</th>
|
||||
<th>Name</th>
|
||||
<th>Technologie</th>
|
||||
<th>Verkaufspreis</th>
|
||||
<th>Verr. Periode</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
<?php foreach($products as $product): ?>
|
||||
<tr>
|
||||
<td><?=($product->external == 1) ? "<i class='fas fa-check text-success'></i>" : ""?></td>
|
||||
<td><?=$product->productgroup->name?></td>
|
||||
<td><?=$product->name?></td>
|
||||
<td><?=$product->producttech->name?></td>
|
||||
<td><?=$product->price?></td>
|
||||
<td><?=$product->billing_period?>x Jährlich</td>
|
||||
<td style="text-align: left; letter-spacing: 4px; font-size: 1.1em;">
|
||||
<a href="<?=self::getUrl("Product", "edit", ["id" => $product->id])?>"><i class="far fa-edit" title="Produkt Bearbeiten"></i></a>
|
||||
<a href="<?=self::getUrl("Product", "delete", ["id" => $product->id])?>" class="text-danger" onclick="if(!confirm('Berechtigungen wirklich löschen?')) return false;" title="Produkt Löschen"><i class="fas fa-trash"></i></a>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div> <!-- end container-fluid -->
|
||||
</div>
|
||||
<!-- end wrapper -->
|
||||
|
||||
<?php include(realpath(dirname(__FILE__)."/../")."/footer.php"); ?>
|
||||
@@ -3,7 +3,7 @@
|
||||
<div class="container-fluid">
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
the tool © 2021 <a href="https://www.xinon.at">Xinon GmbH</a> - Made by fronk - Simulor Theme by Coderthemes
|
||||
the tool © 2021 <a href="https://www.xinon.at">Xinon GmbH</a> - Made by fronk
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<div class="text-md-right footer-links d-none d-sm-block">
|
||||
|
||||
@@ -7,11 +7,10 @@
|
||||
<li class="has-submenu">
|
||||
<a href="<?=self::getUrl("Dashboard")?>"><i class="fe-airplay"></i>Dashboard</a>
|
||||
</li>
|
||||
|
||||
<li class="has-submenu">
|
||||
<a href="#">
|
||||
<i class="fas fa-database"></i>Stammdaten <div class="arrow-down"></div>
|
||||
</a>
|
||||
</a>
|
||||
<ul class="submenu">
|
||||
<li class="has-sub-submenu">
|
||||
<a href="<?=self::getUrl("Address")?>">Personen & Firmen</a>
|
||||
@@ -23,10 +22,10 @@
|
||||
</li>
|
||||
<li><a href="<?=self::getUrl("User")?>">Benutzer</a></li>
|
||||
<li><a href="<?=self::getUrl("Network")?>">Neztgebiete</a></li>
|
||||
<li><a href="<?=self::getUrl("Product")?>">Produkte</a></li>
|
||||
<li><a href="<?=self::getUrl("Productgroup")?>">Produktgruppen</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
|
||||
|
||||
</ul>
|
||||
<!-- End navigation menu -->
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ class NetworkController extends mfBaseController {
|
||||
$mode = "edit";
|
||||
$network = new Network($id);
|
||||
if(!$network->id) {
|
||||
$this->layout()->setFlash("Netzgebie tnicht gefunden", "error");
|
||||
$this->layout()->setFlash("Netzgebiet nicht gefunden", "error");
|
||||
$this->redirect("Network");
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -20,6 +20,16 @@ class NetworkModel {
|
||||
}
|
||||
}
|
||||
|
||||
$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;
|
||||
}
|
||||
|
||||
|
||||
@@ -100,4 +100,42 @@ class NetworkAddressController extends mfBaseController {
|
||||
|
||||
$this->redirect("Network", "Index", [],"view=roles&net=$network_id");
|
||||
}
|
||||
|
||||
protected function deleteAction() {
|
||||
$r = $this->request;
|
||||
//var_dump($r->roles);exit;
|
||||
if(!is_numeric($r->network_id) && $r->network_id <= 0) {
|
||||
$this->layout()->setFlash("Netzgebiet nicht gefunden.", "error");
|
||||
$this->redirect("Network");
|
||||
}
|
||||
if(!is_numeric($r->address_id) && $r->address_id <= 0) {
|
||||
$this->layout()->setFlash("Person/Firma nicht gefunden.", "error");
|
||||
$this->redirect("Network");
|
||||
}
|
||||
|
||||
$network_id = $r->network_id;
|
||||
$address_id = $r->address_id;
|
||||
|
||||
$network = new Network($network_id);
|
||||
if(!$network->id) {
|
||||
$this->layout()->setFlash("Netzgebiet nicht gefunden.", "error");
|
||||
$this->redirect("Network");
|
||||
}
|
||||
|
||||
$address = new Address($address_id);
|
||||
if(!$address->id) {
|
||||
$this->layout()->setFlash("Person/Firma nicht gefunden.", "error");
|
||||
$this->redirect("Network", "Index", [], "view=roles&net=$network_id");
|
||||
}
|
||||
|
||||
$roles = NetworkAddressModel::search(["network_id" => $network_id, "address_id" => $address_id]);
|
||||
//var_dump($roles);exit;
|
||||
|
||||
foreach($roles as $role) {
|
||||
$role->delete();
|
||||
}
|
||||
|
||||
$this->layout()->setFlash("Berechtigungen erfolgreich gelöscht.", "success");
|
||||
$this->redirect("Network", "Index", [], "view=roles&net=$network_id");
|
||||
}
|
||||
}
|
||||
21
application/Product/Product.php
Normal file
21
application/Product/Product.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
class Product extends mfBaseModel {
|
||||
private $productgroup;
|
||||
private $producttech;
|
||||
|
||||
public function getProperty($name) {
|
||||
if($this->$name == null) {
|
||||
|
||||
$classname = ucfirst($name);
|
||||
$idfield = $name."_id";
|
||||
$this->$name = new $classname($this->$idfield);
|
||||
|
||||
if($this->$name->id) {
|
||||
return $this->$name;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
134
application/Product/ProductController.php
Normal file
134
application/Product/ProductController.php
Normal file
@@ -0,0 +1,134 @@
|
||||
<?php
|
||||
|
||||
class ProductController 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 indexAction() {
|
||||
$this->layout()->set("products", ProductModel::getAll());
|
||||
}
|
||||
|
||||
protected function addAction() {
|
||||
$this->layout()->setTemplate("Product/Form");
|
||||
$this->layout()->set("productgroups", ProductgroupModel::getAll());
|
||||
$this->layout()->set("producttechs", ProducttechModel::getAll());
|
||||
|
||||
}
|
||||
|
||||
protected function editAction() {
|
||||
$product_id = $this->request->id;
|
||||
$product = new Product($product_id);
|
||||
if(!$product->id) {
|
||||
$this->layout()->setFlash("Produkt nicht gefunden.", "error");
|
||||
$this->redirect("Product");
|
||||
}
|
||||
|
||||
$this->layout()->set("product", $product);
|
||||
|
||||
return $this->addAction();
|
||||
}
|
||||
|
||||
protected function saveAction() {
|
||||
$r = $this->request;
|
||||
//var_dump($r);exit;
|
||||
$id = $r->id;
|
||||
if(is_numeric($id) && $id > 0) {
|
||||
$mode = "edit";
|
||||
$product = new Product($id);
|
||||
if(!$product->id) {
|
||||
$this->layout()->setFlash("Produkt nicht gefunden", "error");
|
||||
$this->redirect("Produkt");
|
||||
}
|
||||
} else {
|
||||
$id = false;
|
||||
$mode = "add";
|
||||
}
|
||||
|
||||
$data = [];
|
||||
$data['name'] = $r->name;
|
||||
$data['description'] = $r->description;
|
||||
$data['external'] = ($r->external == 1) ? "1" : "0";
|
||||
$data['price_nne'] = Layout::commaToDot($r->price_nne);
|
||||
$data['price_nbe'] = Layout::commaToDot($r->price_nbe);
|
||||
$data['price'] = Layout::commaToDot($r->price);
|
||||
$data['billing_period'] = $r->billing_period;
|
||||
$data['note'] = $r->note;
|
||||
|
||||
if(is_numeric($r->producttech_id)) {
|
||||
$data['producttech_id'] = $r->producttech_id;
|
||||
}
|
||||
if(is_numeric($r->productgroup_id)) {
|
||||
$data['productgroup_id'] = $r->productgroup_id;
|
||||
}
|
||||
|
||||
$data['edit_by'] = 1;
|
||||
|
||||
if($mode == "add") {
|
||||
$data['create_by'] = 1;
|
||||
$product = ProductModel::create($data);
|
||||
} else {
|
||||
$product->update($data);
|
||||
}
|
||||
|
||||
//var_dump($address);exit;
|
||||
|
||||
$new_id = $product->save();
|
||||
if(!$new_id) {
|
||||
$this->layout()->setFlash("Fehler beim Speichern", "error");
|
||||
$this->layout()->set("product", $product);
|
||||
return $this->add();
|
||||
}
|
||||
|
||||
// create new product group and tech
|
||||
|
||||
if($r->productgroup_id == "new") {
|
||||
$ng = [];
|
||||
$ng['name'] = $r->productgroup_new_name;
|
||||
$ng['description'] = $r->productgroup_new_description;
|
||||
$ng['note'] = $r->productgroup_new_note;
|
||||
$group = ProductgroupModel::create($ng);
|
||||
$group_id = $group->save();
|
||||
$product->productgroup_id = $group_id;
|
||||
$product->save();
|
||||
}
|
||||
|
||||
if($r->producttech_id == "new") {
|
||||
$nt = [];
|
||||
$nt['name'] = $r->producttech_new_name;
|
||||
$nt['code'] = $r->producttech_new_code;
|
||||
$nt['description'] = $r->producttech_new_description;
|
||||
$nt['note'] = $r->producttech_new_note;
|
||||
$tech = ProducttechModel::create($nt);
|
||||
$tech_id = $tech->save();
|
||||
$product->producttech_id = $tech_id;
|
||||
$product->save();
|
||||
}
|
||||
|
||||
$this->layout()->setFlash("Produkt erfolgreich gespeichert.", "success");
|
||||
$this->redirect("Product", "Edit", ['id' => $new_id]);
|
||||
}
|
||||
|
||||
protected function delete() {
|
||||
$id = $this->request->id;
|
||||
|
||||
$product = new Product($id);
|
||||
if(!$product->id || $product->id != $id) {
|
||||
$this->layout()->setFlash("Produkt nicht gefunden.", "error");
|
||||
$this->redirect("Product");
|
||||
}
|
||||
|
||||
// check if Product is unused
|
||||
$product->delete();
|
||||
$this->redirect("Product");
|
||||
}
|
||||
}
|
||||
142
application/Product/ProductModel.php
Normal file
142
application/Product/ProductModel.php
Normal file
@@ -0,0 +1,142 @@
|
||||
<?php
|
||||
|
||||
class ProductModel {
|
||||
public $name = null;
|
||||
public $description = null;
|
||||
public $external = null;
|
||||
public $productgroup_id = null;
|
||||
public $producttech_id = null;
|
||||
public $price = null;
|
||||
public $price_nne = null;
|
||||
public $price_nbe = null;
|
||||
public $billing_period = null;
|
||||
|
||||
public $note = null;
|
||||
public $create_by = null;
|
||||
public $edit_by = null;
|
||||
public $create = null;
|
||||
public $edit = null;
|
||||
|
||||
|
||||
public static function create(Array $data) {
|
||||
$model = new Product();
|
||||
|
||||
foreach($data as $field => $value) {
|
||||
if(property_exists(get_called_class(), $field)) {
|
||||
$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 getOne($id) {
|
||||
if(!is_numeric($id) || !$id) {
|
||||
throw new Exception("Invalid number", 400);
|
||||
}
|
||||
$item = [];
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$res = $db->select("Product", "*", "id=$id LIMIT 1");
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
$item = new Product($data);
|
||||
}
|
||||
return $item;
|
||||
}
|
||||
|
||||
public static function getAll() {
|
||||
$items = [];
|
||||
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$res = $db->select("Product", "*", "1 = 1 ORDER BY producttech_id, name");
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[] = new Product($data);
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
|
||||
}
|
||||
|
||||
public static function getFirst() {
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$res = $db->select("Product", "*", "$where ORDER BY producttech_id, name LIMIT 1");
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
$item = new Product($data);
|
||||
if($item->id) {
|
||||
return $item;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function search($filter) {
|
||||
$items = [];
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$res = $db->select("Product", "*", "$where ORDER BY name, owner_id");
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[] = new Product($data);
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
}
|
||||
|
||||
private function getSqlFilter($filter) {
|
||||
$where = "1=1 ";
|
||||
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
//var_dump($filter);exit;
|
||||
if(array_key_exists("productgroup_id", $filter)) {
|
||||
$productgroup_id = $filter['productgroup_id'];
|
||||
if(is_numeric($productgroup_id)) {
|
||||
$where .= " AND productgroup_id=$productgroup_id";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("producttech_id", $filter)) {
|
||||
$producttech_id = $filter['producttech_id'];
|
||||
if(is_numeric($producttech_id)) {
|
||||
$where .= " AND producttech_id=$producttech_id";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("name", $filter)) {
|
||||
$name = $db->escape($filter['name']);
|
||||
if($name) {
|
||||
$where .= " AND `name` like '$name'";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("nameLike", $filter)) {
|
||||
$name = $db->escape($filter['nameLike']);
|
||||
if($name) {
|
||||
$where .= " AND `name` like '%$name%'";
|
||||
}
|
||||
}
|
||||
|
||||
//var_dump($filter, $where);exit;
|
||||
return $where;
|
||||
}
|
||||
|
||||
}
|
||||
5
application/Productgroup/Productgroup.php
Normal file
5
application/Productgroup/Productgroup.php
Normal file
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
class Productgroup extends mfBaseModel {
|
||||
|
||||
}
|
||||
30
application/Productgroup/ProductgroupController.php
Normal file
30
application/Productgroup/ProductgroupController.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
class ProductgroupController 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 indexAction() {
|
||||
|
||||
}
|
||||
|
||||
protected function addAction() {
|
||||
|
||||
}
|
||||
|
||||
protected function editAction() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
122
application/Productgroup/ProductgroupModel.php
Normal file
122
application/Productgroup/ProductgroupModel.php
Normal file
@@ -0,0 +1,122 @@
|
||||
<?php
|
||||
|
||||
class ProductgroupModel {
|
||||
public $name = null;
|
||||
public $description = null;
|
||||
|
||||
public $note = null;
|
||||
|
||||
public $create_by = null;
|
||||
public $edit_by = null;
|
||||
public $create = null;
|
||||
public $edit = null;
|
||||
|
||||
|
||||
public static function create(Array $data) {
|
||||
$model = new Productgroup();
|
||||
|
||||
foreach($data as $field => $value) {
|
||||
if(property_exists(get_called_class(), $field)) {
|
||||
$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 getOne($id) {
|
||||
if(!is_numeric($id) || !$id) {
|
||||
throw new Exception("Invalid number", 400);
|
||||
}
|
||||
$item = [];
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$res = $db->select("Productgroup", "*", "id=$id LIMIT 1");
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
$item = new Productgroup($data);
|
||||
}
|
||||
return $item;
|
||||
}
|
||||
|
||||
public static function getAll() {
|
||||
$items = [];
|
||||
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$res = $db->select("Productgroup", "*", "1 = 1 ORDER BY name");
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[$data->id] = new Productgroup($data);
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
|
||||
}
|
||||
|
||||
public static function getFirst() {
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$res = $db->select("Productgroup", "*", "$where ORDER BY name");
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
$item = new Productgroup($data);
|
||||
if($item->id) {
|
||||
return $item;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function search($filter) {
|
||||
$items = [];
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$res = $db->select("Productgroup", "*", "$where ORDER BY name");
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[$data->id] = new Productgroup($data);
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
}
|
||||
|
||||
private function getSqlFilter($filter) {
|
||||
$where = "1=1 ";
|
||||
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
//var_dump($filter);exit;
|
||||
if(array_key_exists("name", $filter)) {
|
||||
$name = $db->escape($filter['name']);
|
||||
if($name) {
|
||||
$where .= " AND `name` like '$name'";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("nameLike", $filter)) {
|
||||
$name = $db->escape($filter['nameLike']);
|
||||
if($name) {
|
||||
$where .= " AND `name` like '%$name%'";
|
||||
}
|
||||
}
|
||||
|
||||
//var_dump($filter, $where);exit;
|
||||
return $where;
|
||||
}
|
||||
|
||||
}
|
||||
5
application/Producttech/Producttech.php
Normal file
5
application/Producttech/Producttech.php
Normal file
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
class Producttech extends mfBaseModel {
|
||||
|
||||
}
|
||||
129
application/Producttech/ProducttechModel.php
Normal file
129
application/Producttech/ProducttechModel.php
Normal file
@@ -0,0 +1,129 @@
|
||||
<?php
|
||||
|
||||
class ProducttechModel {
|
||||
public $name = null;
|
||||
public $code = null;
|
||||
public $description = null;
|
||||
|
||||
public $note = null;
|
||||
public $create_by = null;
|
||||
public $edit_by = null;
|
||||
public $create = null;
|
||||
public $edit = null;
|
||||
|
||||
|
||||
public static function create(Array $data) {
|
||||
$model = new Producttech();
|
||||
|
||||
foreach($data as $field => $value) {
|
||||
if(property_exists(get_called_class(), $field)) {
|
||||
$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 getOne($id) {
|
||||
if(!is_numeric($id) || !$id) {
|
||||
throw new Exception("Invalid number", 400);
|
||||
}
|
||||
$item = [];
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$res = $db->select("Producttech", "*", "id=$id LIMIT 1");
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
$item = new Producttech($data);
|
||||
}
|
||||
return $item;
|
||||
}
|
||||
|
||||
public static function getAll() {
|
||||
$items = [];
|
||||
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$res = $db->select("Producttech", "*", "1 = 1 ORDER BY name");
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[$data->id] = new Producttech($data);
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
|
||||
}
|
||||
|
||||
public static function getFirst() {
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$res = $db->select("Producttech", "*", "$where ORDER BY name");
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
$item = new Producttech($data);
|
||||
if($item->id) {
|
||||
return $item;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function search($filter) {
|
||||
$items = [];
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$res = $db->select("Producttech", "*", "$where ORDER BY name");
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[$data->id] = new Producttech($data);
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
}
|
||||
|
||||
private function getSqlFilter($filter) {
|
||||
$where = "1=1 ";
|
||||
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
//var_dump($filter);exit;
|
||||
if(array_key_exists("name", $filter)) {
|
||||
$name = $db->escape($filter['name']);
|
||||
if($name) {
|
||||
$where .= " AND `name` like '$name'";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("nameLike", $filter)) {
|
||||
$name = $db->escape($filter['nameLike']);
|
||||
if($name) {
|
||||
$where .= " AND `name` like '%$name%'";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("code", $filter)) {
|
||||
$code = $db->escape($filter['code']);
|
||||
if($code) {
|
||||
$where .= " AND `code` like '$code'";
|
||||
}
|
||||
}
|
||||
|
||||
//var_dump($filter, $where);exit;
|
||||
return $where;
|
||||
}
|
||||
|
||||
}
|
||||
83
contrib/migrations/20210705-product-tables.sql
Normal file
83
contrib/migrations/20210705-product-tables.sql
Normal file
@@ -0,0 +1,83 @@
|
||||
CREATE TABLE `Product` (
|
||||
`id` int NOT NULL AUTO_INCREMENT,
|
||||
`name` varchar(1024) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci NOT NULL,
|
||||
`description` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci,
|
||||
`external` tinyint(1) NOT NULL DEFAULT '0',
|
||||
`producttech_id` int DEFAULT NULL,
|
||||
`productgroup_id` int DEFAULT NULL,
|
||||
`price_nne` decimal(12,2) DEFAULT NULL,
|
||||
`price_nbe` decimal(12,2) DEFAULT NULL,
|
||||
`price` decimal(12,2) NOT NULL,
|
||||
`billing_period` int NOT NULL COMMENT 'in months',
|
||||
`note` text COLLATE utf8mb4_unicode_520_ci,
|
||||
`create_by` int NOT NULL,
|
||||
`edit_by` int NOT NULL,
|
||||
`create` int NOT NULL,
|
||||
`edit` int NOT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci
|
||||
|
||||
CREATE TABLE `ProductNetwork` (
|
||||
`id` int NOT NULL AUTO_INCREMENT,
|
||||
`product_id` int NOT NULL,
|
||||
`network_id` int NOT NULL,
|
||||
`create_by` int NOT NULL,
|
||||
`edit_by` int NOT NULL,
|
||||
`create` int NOT NULL,
|
||||
`edit` int NOT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci
|
||||
|
||||
CREATE TABLE `Productattribute` (
|
||||
`id` int NOT NULL AUTO_INCREMENT,
|
||||
`product_id` int NOT NULL,
|
||||
`producttechattribute_id` int NOT NULL,
|
||||
`name` varchar(1024) COLLATE utf8mb4_unicode_520_ci NOT NULL,
|
||||
`displayname` varchar(1024) COLLATE utf8mb4_unicode_520_ci NOT NULL,
|
||||
`value` varchar(1024) COLLATE utf8mb4_unicode_520_ci NOT NULL,
|
||||
`description` text COLLATE utf8mb4_unicode_520_ci NOT NULL,
|
||||
`note` text COLLATE utf8mb4_unicode_520_ci NOT NULL,
|
||||
`create_by` int NOT NULL,
|
||||
`edit_by` int NOT NULL,
|
||||
`create` int NOT NULL,
|
||||
`edit` int NOT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci
|
||||
|
||||
CREATE TABLE `Productgroup` (
|
||||
`id` int NOT NULL AUTO_INCREMENT,
|
||||
`name` varchar(1024) COLLATE utf8mb4_unicode_520_ci NOT NULL,
|
||||
`description` text COLLATE utf8mb4_unicode_520_ci NOT NULL,
|
||||
`note` text COLLATE utf8mb4_unicode_520_ci NOT NULL,
|
||||
`create_by` int NOT NULL,
|
||||
`edit_by` int NOT NULL,
|
||||
`create` int NOT NULL,
|
||||
`edit` int NOT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci
|
||||
|
||||
CREATE TABLE `Producttech` (
|
||||
`id` int NOT NULL AUTO_INCREMENT,
|
||||
`name` varchar(1024) COLLATE utf8mb4_unicode_520_ci NOT NULL,
|
||||
`code` varchar(255) COLLATE utf8mb4_unicode_520_ci NOT NULL,
|
||||
`description` text COLLATE utf8mb4_unicode_520_ci NOT NULL,
|
||||
`note` text COLLATE utf8mb4_unicode_520_ci NOT NULL,
|
||||
`create_by` int NOT NULL,
|
||||
`edit_by` int NOT NULL,
|
||||
`create` int NOT NULL,
|
||||
`edit` int NOT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci
|
||||
|
||||
CREATE TABLE `ProducttechAttribute` (
|
||||
`id` int NOT NULL,
|
||||
`name` varchar(1024) COLLATE utf8mb4_unicode_520_ci NOT NULL,
|
||||
`displayname` varchar(1024) COLLATE utf8mb4_unicode_520_ci NOT NULL,
|
||||
`value` varchar(1024) COLLATE utf8mb4_unicode_520_ci NOT NULL,
|
||||
`description` text COLLATE utf8mb4_unicode_520_ci NOT NULL,
|
||||
`note` text COLLATE utf8mb4_unicode_520_ci NOT NULL,
|
||||
`create_by` int NOT NULL,
|
||||
`edit_by` int NOT NULL,
|
||||
`create` int NOT NULL,
|
||||
`edit` int NOT NULL
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci
|
||||
@@ -19,4 +19,8 @@ class Layout extends mfLayout {
|
||||
public function dotToComma($num) {
|
||||
return str_replace(".", ",", $num);
|
||||
}
|
||||
|
||||
public function commaToDot($num) {
|
||||
return str_replace(",", ".", $num);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user