diff --git a/Layout/default/Product/Index.php b/Layout/default/Product/Index.php
index 25a0e0dbd..dfc84dc25 100644
--- a/Layout/default/Product/Index.php
+++ b/Layout/default/Product/Index.php
@@ -158,8 +158,8 @@
=$product->ivt_id?> |
$product->id])?>">
- $product->id])?>">
- $product->id])?>" class="text-danger" onclick="if(!confirm('Berechtigungen wirklich löschen?')) return false;" title="Produkt Löschen">
+ $product->id])?>" onclick="if(!confirm('Wirklich Kopie erstellen?')) return false;">
+ $product->id])?>" class="text-danger" onclick="if(!confirm('Produkt wirklich löschen?')) return false;" title="Produkt Löschen">
|
diff --git a/application/Contract/ContractModel.php b/application/Contract/ContractModel.php
index cb1856594..24e4591fb 100644
--- a/application/Contract/ContractModel.php
+++ b/application/Contract/ContractModel.php
@@ -154,7 +154,7 @@ class ContractModel {
return null;
}
- public static function count($filter) {
+ public static function countActive($filter) {
$db = FronkDB::singleton();
$where = self::getSqlFilter($filter);
@@ -215,6 +215,30 @@ class ContractModel {
return $items;
}
+ public static function count($filter) {
+ $db = FronkDB::singleton();
+
+ $where = self::getSqlFilter($filter);
+ $sql = "SELECT COUNT(*) as cnt FROM (
+ SELECT Contract.* FROM Contract
+ LEFT JOIN Address ON (Contract.owner_id = Address.id)
+ LEFT JOIN OrderProduct ON (Contract.orderproduct_id = OrderProduct.id)
+ LEFT JOIN `Order` ON (OrderProduct.order_id = `Order`.id)
+ LEFT JOIN Product ON (Contract.product_id = Product.id)
+ WHERE $where
+ GROUP BY Contract.id
+ ) contract";
+
+ 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) {
//var_dump($filter);exit;
$items = [];
diff --git a/application/OrderProduct/OrderProductModel.php b/application/OrderProduct/OrderProductModel.php
index 0af892007..bcfa395b3 100644
--- a/application/OrderProduct/OrderProductModel.php
+++ b/application/OrderProduct/OrderProductModel.php
@@ -100,7 +100,25 @@ class OrderProductModel
}
return null;
}
+
+ public static function count($filter) {
+ $db = FronkDB::singleton();
+ $where = self::getSqlFilter($filter);
+ $sql = "SELECT COUNT(*) as cnt FROM OrderProduct
+ 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)
{
$items = [];
@@ -187,7 +205,7 @@ class OrderProductModel
if (array_key_exists("product_id", $filter)) {
$product_id = $filter['product_id'];
if (is_numeric($product_id)) {
- $where .= " AND order_id=$product_id";
+ $where .= " AND product_id=$product_id";
}
}
diff --git a/application/Preorder/PreorderModel.php b/application/Preorder/PreorderModel.php
index f63475731..a294f6847 100644
--- a/application/Preorder/PreorderModel.php
+++ b/application/Preorder/PreorderModel.php
@@ -544,6 +544,20 @@ class PreorderModel {
}
}
+ if(array_key_exists("product_id", $filter)) {
+ $product_id = $filter['product_id'];
+ if(is_numeric($product_id)) {
+ $where .= " AND tt_preorder.product_id=$product_id";
+ }
+ }
+
+ if(array_key_exists("setup_product_id", $filter)) {
+ $setup_product_id = $filter['setup_product_id'];
+ if(is_numeric($setup_product_id)) {
+ $where .= " AND tt_preorder.setup_product_id=$setup_product_id";
+ }
+ }
+
if(array_key_exists("address_created", $filter)) {
$address_created = $filter['address_created'];
if($address_created === true) {
@@ -610,6 +624,8 @@ class PreorderModel {
}
}
+
+
if(array_key_exists("extref", $filter)) {
$extref = FronkDB::singleton()->escape($filter['extref']);
if($extref) {
diff --git a/application/Product/ProductController.php b/application/Product/ProductController.php
index 731d17f62..ef758bd55 100644
--- a/application/Product/ProductController.php
+++ b/application/Product/ProductController.php
@@ -312,8 +312,39 @@ class ProductController extends mfBaseController {
$this->redirect("Product");
}
- // check if Product is unused
+ // check if product is in use
+ if(OrderProductModel::count(["product_id" => $product->id])) {
+ $this->layout()->setFlash("Produkt kann nicht gelöscht werden, da es in Verwendung ist!", "error");
+ $this->redirect("Product");
+ }
+
+ if(ContractModel::count(["product_id" => $product->id])) {
+ $this->layout()->setFlash("Produkt kann nicht gelöscht werden, da es in Verwendung ist!", "error");
+ $this->redirect("Product");
+ }
+
+ if(ContractqueueModel::count(["product_id" => $product->id])) {
+ $this->layout()->setFlash("Produkt kann nicht gelöscht werden, da es in Verwendung ist!", "error");
+ $this->redirect("Product");
+ }
+
+ if(PreorderModel::count(["product_id" => $product->id]) || PreorderModel::count(["setup_product_id" => $product->id])) {
+ $this->layout()->setFlash("Produkt kann nicht gelöscht werden, da es in Verwendung ist!", "error");
+ $this->redirect("Product");
+ }
+
+ // delete attributes
+ foreach($product->attributes as $attrib) {
+ $attrib->delete();
+ }
+ // delete networks
+ foreach(ProductNetworkModel::search(['product_id' => $product->id]) as $pn) {
+ $pn->delete();
+ }
+
+ // delete product
$product->delete();
+ $this->layout()->setFlash("Produkt erfolgreich gelöscht", "success");
$this->redirect("Product");
}