From fc422eb7ae66e0c02a3c357492cd5e8be135db35 Mon Sep 17 00:00:00 2001 From: Luca Haid Date: Thu, 17 Jul 2025 13:48:55 +0200 Subject: [PATCH 01/24] fixed import bugs and filter --- application/ConstructionConsent/ConstructionConsent.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/ConstructionConsent/ConstructionConsent.php b/application/ConstructionConsent/ConstructionConsent.php index f65b14df2..eb2931f17 100644 --- a/application/ConstructionConsent/ConstructionConsent.php +++ b/application/ConstructionConsent/ConstructionConsent.php @@ -435,7 +435,7 @@ class ConstructionConsent extends mfBaseModel { END), 0) > 0 OR COALESCE(SUM(CASE WHEN approve_override = 1 THEN 0 - ELSE (cwo.result = 'open') + ELSE (cwo.result = 'open' AND cwo.status != 'new') END), 0) > 0 OR COALESCE(SUM(CASE WHEN approve_override = 1 THEN 0 From fc7bf317aa5702f3afa954809d1674b1d171248c Mon Sep 17 00:00:00 2001 From: Luca Haid Date: Thu, 17 Jul 2025 13:52:05 +0200 Subject: [PATCH 02/24] fixed import bugs and filter --- application/ConstructionConsent/ConstructionConsent.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/application/ConstructionConsent/ConstructionConsent.php b/application/ConstructionConsent/ConstructionConsent.php index eb2931f17..75857f1d9 100644 --- a/application/ConstructionConsent/ConstructionConsent.php +++ b/application/ConstructionConsent/ConstructionConsent.php @@ -247,6 +247,9 @@ class ConstructionConsent extends mfBaseModel { } foreach($owners as $owner) { + if($owner->result == "open" && $owner->status == "new") { + $owner->result = "new"; + } if(!array_key_exists($owner->result, $counts)) { $counts[$owner->result] = 0; } From 246e6551b9e11a3970aed82feb01ee7e54f5c5ff Mon Sep 17 00:00:00 2001 From: Luca Haid Date: Thu, 17 Jul 2025 13:57:20 +0200 Subject: [PATCH 03/24] fixed import bugs and filter --- Layout/default/ConstructionConsent/View.php | 5 +++++ application/ConstructionConsent/ConstructionConsent.php | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/Layout/default/ConstructionConsent/View.php b/Layout/default/ConstructionConsent/View.php index 82a48fe79..28086a510 100644 --- a/Layout/default/ConstructionConsent/View.php +++ b/Layout/default/ConstructionConsent/View.php @@ -1348,6 +1348,11 @@ $pagination_entity_name = "Adressen"; background-color: #337ab7; /* Blue */ } + .ConstructionConsentOwnerResult-new { + /*red background color here for this tr*/ + background-color: #337ab7 + } + .ConstructionConsentOwnerResult-denied { /*red background color here for this tr*/ background-color: #f9a39f diff --git a/application/ConstructionConsent/ConstructionConsent.php b/application/ConstructionConsent/ConstructionConsent.php index 75857f1d9..a2ead70a6 100644 --- a/application/ConstructionConsent/ConstructionConsent.php +++ b/application/ConstructionConsent/ConstructionConsent.php @@ -428,6 +428,10 @@ class ConstructionConsent extends mfBaseModel { COUNT(cwo.id) AS total_owners, CASE WHEN ConstructionConsent.approve_override = 1 THEN 'green' + WHEN COALESCE(SUM(CASE + WHEN approve_override = 1 THEN 0 + ELSE (cwo.result = 'open' AND cwo.status = 'new') + END), 0) > 0 THEN 'blue' WHEN COALESCE(SUM(CASE WHEN approve_override = 1 THEN 0 ELSE (cwo.result = 'denied') From 0611eb4a29418344d6e415ff6d01667bb4ae0594 Mon Sep 17 00:00:00 2001 From: Luca Haid Date: Thu, 17 Jul 2025 14:00:05 +0200 Subject: [PATCH 04/24] fixed import bugs and filter --- Layout/default/ConstructionConsent/Index.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Layout/default/ConstructionConsent/Index.php b/Layout/default/ConstructionConsent/Index.php index dc704a731..21f22e6d1 100644 --- a/Layout/default/ConstructionConsent/Index.php +++ b/Layout/default/ConstructionConsent/Index.php @@ -431,6 +431,8 @@ $pagination_entity_name = "Zustimmungserklärungen"; $approve_override = $item->approve_override; if (isset($approve_override) && $approve_override) { $status_class = 'green'; // Blue if approve override + } if (isset($item->owner_result_counts['new']) && $item->owner_result_counts['new'] > 0) { + $status_class = 'blue'; } elseif (isset($item->owner_result_counts['denied']) && $item->owner_result_counts['denied'] > 0) { $status_class = 'red'; // Red if at least one denied From 9811af9f7805866605e8318cd8473ab9b891aef8 Mon Sep 17 00:00:00 2001 From: Luca Haid Date: Thu, 17 Jul 2025 12:02:18 +0000 Subject: [PATCH 05/24] Construction consent/fix bugs2 --- Layout/default/ConstructionConsent/View.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Layout/default/ConstructionConsent/View.php b/Layout/default/ConstructionConsent/View.php index 28086a510..51787996c 100644 --- a/Layout/default/ConstructionConsent/View.php +++ b/Layout/default/ConstructionConsent/View.php @@ -295,7 +295,7 @@ $pagination_entity_name = "Adressen";
Zusammenfassung Status (von owners)?>)
owner_status_counts as $type => $count): ?> - + @@ -308,6 +308,8 @@ $pagination_entity_name = "Adressen"; $status_class = 'blue'; // Default to blue (all open) if (isset($item->owner_result_counts['denied']) && $item->owner_result_counts['denied'] > 0) { $status_class = 'red'; // Red if at least one denied + } elseif (isset($item->owner_result_counts['open']) && $item->owner_result_counts['open'] > 0) { + $status_class = 'blue'; // Blue if at least one open } elseif ( (isset($item->owner_result_counts['unresolvable']) && $item->owner_result_counts['unresolvable'] > 0) || (isset($item->owner_result_counts['moved']) && $item->owner_result_counts['moved'] > 0) || @@ -1349,8 +1351,7 @@ $pagination_entity_name = "Adressen"; } .ConstructionConsentOwnerResult-new { - /*red background color here for this tr*/ - background-color: #337ab7 + background-color: #9bcdff; } .ConstructionConsentOwnerResult-denied { From b0f72e58f358dcf6566ffe20cfdf30cadf1d1fce Mon Sep 17 00:00:00 2001 From: Luca Haid Date: Mon, 21 Jul 2025 07:24:40 +0200 Subject: [PATCH 06/24] WarehouseOffer fixed bugs --- application/WarehouseOffer/WarehouseOfferController.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/application/WarehouseOffer/WarehouseOfferController.php b/application/WarehouseOffer/WarehouseOfferController.php index 6bc9fea13..f22207f8a 100644 --- a/application/WarehouseOffer/WarehouseOfferController.php +++ b/application/WarehouseOffer/WarehouseOfferController.php @@ -53,11 +53,13 @@ class WarehouseOfferController extends TTCrud $this->postData['offerNumber'] = 'AN' . date('Y') . '-' . str_pad($currentCount + 1, 4, '0', STR_PAD_LEFT); $this->postData['status'] = 'new'; $this->postData['version'] = 1; + $this->postData['alternativePositions'] = json_encode([]); return true; } - protected function afterCreate($id): void + protected function afterCreate(WarehouseOfferModel $offer): void { + $id = $offer->id; $offer = WarehouseOfferModel::get($id); $this->createHistoryEntry($id, 1, $offer); } From 92117cf97357bf927f8f6630ab84701fe6e56072 Mon Sep 17 00:00:00 2001 From: Luca Haid Date: Mon, 21 Jul 2025 07:27:15 +0200 Subject: [PATCH 07/24] WarehouseOffer fixed bugs --- application/WarehouseOffer/WarehouseOfferController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/application/WarehouseOffer/WarehouseOfferController.php b/application/WarehouseOffer/WarehouseOfferController.php index f22207f8a..4d19c3405 100644 --- a/application/WarehouseOffer/WarehouseOfferController.php +++ b/application/WarehouseOffer/WarehouseOfferController.php @@ -57,9 +57,9 @@ class WarehouseOfferController extends TTCrud return true; } - protected function afterCreate(WarehouseOfferModel $offer): void + protected function afterCreate($offer): void { - $id = $offer->id; + $id = $offer['id']; $offer = WarehouseOfferModel::get($id); $this->createHistoryEntry($id, 1, $offer); } From 48f5d2fae46b558ec4d6b25f6f2b9cadc6b8c8d9 Mon Sep 17 00:00:00 2001 From: Luca Haid Date: Mon, 21 Jul 2025 06:58:30 +0000 Subject: [PATCH 08/24] Fixed housenumber typo in PreorderIFrameModel --- application/PreorderIFrame/PreorderIFrameModel.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/application/PreorderIFrame/PreorderIFrameModel.php b/application/PreorderIFrame/PreorderIFrameModel.php index 4dc8f0f96..aa85d31cf 100644 --- a/application/PreorderIFrame/PreorderIFrameModel.php +++ b/application/PreorderIFrame/PreorderIFrameModel.php @@ -156,7 +156,7 @@ class PreorderIFrameModel extends mfBaseModel return [ 'oaid' => $row['unit_oaid'] ?? $row['oaid'], 'street' => $row['street'], - 'housenumber' => $row['housenumber'], + 'housenumber' => $row['hausnummer'], 'hausnummer_id' => $row['hausnummer_id'], 'wohneinheit_id' => $row['wohneinheit_id'], 'building_type' => intval($row['building_type']), @@ -182,4 +182,4 @@ class PreorderIFrameModel extends mfBaseModel return $parts ? implode(', ', $parts) : "Top {$counter}"; } -} \ No newline at end of file +} From a867bcc6b8bd5f824528777bb38c367b9ded0221 Mon Sep 17 00:00:00 2001 From: Luca Haid Date: Mon, 21 Jul 2025 12:27:26 +0200 Subject: [PATCH 09/24] WarehouseOffer fixed bugs --- Layout/default/menu.php | 10 +- .../WarehouseArticleController.php | 2 + .../WarehouseArticleModel.php | 2 + .../WarehouseArticlePacket.php | 9 - .../WarehouseArticlePacketController.php | 60 +++-- .../WarehouseArticlePacketModel.php | 6 +- application/WarehouseEShop/WarehouseEShop.php | 9 - .../WarehouseEShopController.php | 80 ++++--- .../WarehouseEShopOrder.php | 9 - .../WarehouseEShopOrderController.php | 195 ++++++++++------ .../WarehouseEShopOrderModel.php | 4 +- .../WarehouseEShopOrderItem.php | 9 - ...00_shop_and_order_address_enhancements.php | 103 +++++++++ lib/TTCrud/TTCrud.php | 1 + .../WarehouseArticlePacket.js | 15 ++ .../js/pages/WarehouseEShop/WarehouseEShop.js | 101 +++++---- .../WarehouseEShopOrder.js | 214 +++++++++--------- 17 files changed, 526 insertions(+), 303 deletions(-) delete mode 100644 application/WarehouseArticlePacket/WarehouseArticlePacket.php delete mode 100644 application/WarehouseEShop/WarehouseEShop.php delete mode 100644 application/WarehouseEShopOrder/WarehouseEShopOrder.php delete mode 100644 application/WarehouseEShopOrderItem/WarehouseEShopOrderItem.php create mode 100644 db/migrations/20250721112500_shop_and_order_address_enhancements.php diff --git a/Layout/default/menu.php b/Layout/default/menu.php index 2c076da33..fd2dd7619 100644 --- a/Layout/default/menu.php +++ b/Layout/default/menu.php @@ -162,7 +162,7 @@
  • can("WarehouseEShop") && !($me->can("WarehouseAdmin") || $me->can("WarehouseUser"))): ?> - E-Shop
    + address_id == 9633 ? "SBIDI Shop" : "E-Shop" ?>
    can("WarehouseAdmin") || $me->can("WarehouseUser")): ?> Lager
    @@ -179,9 +179,11 @@ can("WarehouseAdmin")): ?>
  • "> Administration
  • - can("WarehouseAdmin") || $me->can("WarehouseEShop")): ?>
  • E-Stmk Shop
  • - can("WarehouseEShop")): ?>
  • "> E-Shop
  • - can("WarehouseAdmin")): ?>
  • "> E-Shop Bestellungen
  • + can("WarehouseAdmin") || $me->can("WarehouseEShop")): ?>
  • address_id == 9633 ? "SBIDI Shop" : "E-Shop" ?>
  • + can("WarehouseEShop") && !$me->isAdmin()): ?>
  • "> address_id == 9633 ? "SBIDI Shop" : "E-Shop" ?>
  • + can("WarehouseEShop") && $me->isAdmin()): ?>
  • ?shop=e"> E-Shop
  • + can("WarehouseEShop") && $me->isAdmin()): ?>
  • ?shop=sbidi"> SBIDI-Shop
  • + can("WarehouseAdmin")): ?>
  • "> E/SBIDI-Shop Bestellungen
  • can("WarehouseAdmin")): ?>
  • "> Artikel-Pakete
  • diff --git a/application/WarehouseArticle/WarehouseArticleController.php b/application/WarehouseArticle/WarehouseArticleController.php index b035e1956..912b9a700 100644 --- a/application/WarehouseArticle/WarehouseArticleController.php +++ b/application/WarehouseArticle/WarehouseArticleController.php @@ -20,6 +20,8 @@ class WarehouseArticleController extends TTCrud { ['key' => 'isSerialDocumentation', 'text' => 'Seriennummern', 'required' => false,'modal' => ['type' => 'checkbox'], 'table' => false], ['key' => 'isEShop', 'text' => 'Ist E-Shop', 'required' => false,'modal' => ['type' => 'checkbox'], 'table' => false], ['key' => 'isEShopHide', 'text' => 'E-Shop Versteckt', 'required' => false,'modal' => ['type' => 'checkbox'], 'table' => false], + ['key' => 'isSbidiShop', 'text' => 'Ist SBIDI-Shop', 'required' => false,'modal' => ['type' => 'checkbox'], 'table' => false], + ['key' => 'isSbidiShopHide', 'text' => 'SBIDI-Shop Versteckt', 'required' => false,'modal' => ['type' => 'checkbox'], 'table' => false], ['key' => 'actions', 'text' => 'Aktionen', 'required' => false, 'modal' => false, 'table' => ['filter' => false, 'sortable' => false, 'class' => 'text-center', 'priority' => 8]] ]; diff --git a/application/WarehouseArticle/WarehouseArticleModel.php b/application/WarehouseArticle/WarehouseArticleModel.php index 12d651b76..217243029 100644 --- a/application/WarehouseArticle/WarehouseArticleModel.php +++ b/application/WarehouseArticle/WarehouseArticleModel.php @@ -12,6 +12,8 @@ class WarehouseArticleModel extends TTCrudBaseModel { public int $criticalAmount; public ?int $isEShop; public ?int $isEShopHide; + public ?int $isSbidiShop; + public ?int $isSbidiShopHide; public string $unit; public ?int $isSerialDocumentation; public int $revenueAccount; diff --git a/application/WarehouseArticlePacket/WarehouseArticlePacket.php b/application/WarehouseArticlePacket/WarehouseArticlePacket.php deleted file mode 100644 index 7b4d60ff1..000000000 --- a/application/WarehouseArticlePacket/WarehouseArticlePacket.php +++ /dev/null @@ -1,9 +0,0 @@ - 'overrideSellPrice', 'text' => 'Überschriebener Verkaufspreis', 'required' => false, 'modal' => ['type' => 'number'], 'table' => false], ['key' => 'calculatedSellPrice', 'text' => 'Verkaufspreis', 'required' => false, 'modal' => false, 'table' => ['filter' => false, 'sortable' => false]], ['key' => 'subItems', 'text' => 'Unterartikel', 'required' => true], + ['key' => 'isEShop', 'text' => 'Energie Steiermark Shop', 'required' => false, 'modal' => ['type' => 'checkbox', 'items' => [['value' => 1, 'icon' => 'fas fa-check-circle text-success', 'text' => 'Ja'], ['value' => 0, 'icon' => 'fas fa-times-circle text-danger', 'text' => 'Nein']]], 'table' => ['filter' => 'iconSelect']], + ['key' => 'isEShopHide', 'text' => 'Energie Steiermark Shop Ausblenden', 'required' => false, 'modal' => ['type' => 'checkbox', 'items' => [['value' => 1, 'icon' => 'fas fa-check-circle text-success', 'text' => 'Ja'], ['value' => 0, 'icon' => 'fas fa-times-circle text-danger', 'text' => 'Nein']]], 'table' => ['filter' => 'iconSelect']], + ['key' => 'isSbidiShop', 'text' => 'Sbidi Shop', 'required' => false, 'modal' => ['type' => 'checkbox', 'items' => [['value' => 1, 'icon' => 'fas fa-check-circle text-success', 'text' => 'Ja'], ['value' => 0, 'icon' => 'fas fa-times-circle text-danger', 'text' => 'Nein']]], 'table' => ['filter' => 'iconSelect']], + ['key' => 'isSbidiShopHide', 'text' => 'Sbidi Shop Ausblenden', 'required' => false, 'modal' => ['type' => 'checkbox', 'items' => [['value' => 1, 'icon' => 'fas fa-check-circle text-success', 'text' => 'Ja'], ['value' => 0, 'icon' => 'fas fa-times-circle text-danger', 'text' => 'Nein']]], 'table' => ['filter' => 'iconSelect']], ['key' => 'actions', 'text' => 'Aktionen', 'required' => false, 'modal' => false, 'table' => ['filter' => false, 'sortable' => false, 'class' => 'text-center', 'priority' => 10]], ]; // @formatter:on protected array $infoMessages = ['create' => 'Artikel-Paket wurde erstellt', - 'update' => 'Artikel-Paket wurde aktualisiert', - 'delete' => 'Artikel-Paket wurde gelöscht', - 'noChanges' => 'Keine Änderungen']; + 'update' => 'Artikel-Paket wurde aktualisiert', + 'delete' => 'Artikel-Paket wurde gelöscht', + 'noChanges' => 'Keine Änderungen']; protected function prepareCrudConfig() { $articles = array_map(function ($article) { return ['value' => $article->id, 'text' => $article->title]; }, WarehouseArticleModel::getAll( - ['isEShop' => 1], + // Filter articles based on the user's address_id for the shop context + ($this->user->address_id === 209) ? ['isEShop' => 1] : (($this->user->address_id === 210) ? ['isSbidiShop' => 1] : []), )); $this->columns[6]['modal']['items'] = $articles; @@ -35,9 +40,21 @@ class WarehouseArticlePacketController extends TTCrud { //TODO: make this so it does not update all packets at the same time protected function updatePacketPricesAction() { $packets = WarehouseArticlePacketModel::getAll(); - $articles = WarehouseArticleModel::getAll(['isEShop' => 1]); - // packet has $calculatedSellPrice for this but when overrideSellPrice is set, it should be used + // Determine which shop's articles to use for price calculation based on the current user's shop context + // This is a simplification; in a multi-tenant system, this might need to be more robust, + // e.g., by iterating through all possible shop types or having a dedicated price calculation service. + $shopPriceTitle = ''; + $articleFilter = []; + if ($this->user->address_id === 209) { + $shopPriceTitle = 'Energie Steiermark'; + $articleFilter['isEShop'] = 1; + } elseif ($this->user->address_id === 210) { + $shopPriceTitle = 'Sbidi'; + $articleFilter['isSbidiShop'] = 1; + } + + $articles = WarehouseArticleModel::getAll($articleFilter); foreach ($packets as $packet) { if ($packet->overrideSellPrice) { @@ -47,20 +64,29 @@ class WarehouseArticlePacketController extends TTCrud { $calculatedSellPrice = 0; foreach ($subItems as $subItem) { - $article = WarehouseArticleModel::get($subItem->id); - $cheapestSellPrices = json_decode($article->cheapestSellPrice, true); - // find in array cheapestSellPrices by title === 'Energie Steiermark' and get the price - $articlePrice = array_values(array_filter($cheapestSellPrices, function ($cheapestSellPrice) { - return $cheapestSellPrice['title'] === 'Energie Steiermark'; - })); + $article = null; + // Find the article by ID from the already fetched articles to avoid N+1 queries + foreach ($articles as $a) { + if ($a->id == $subItem->id) { + $article = $a; + break; + } + } - $articlePrice = $articlePrice[0]['price'] ?? 0; - - $calculatedSellPrice += $subItem->amount * $articlePrice; + if ($article) { + $cheapestSellPrices = json_decode($article->cheapestSellPrice, true); + $articlePrice = 0; + // Find price for the specific shop + $foundPrice = array_values(array_filter($cheapestSellPrices, function ($cheapestSellPrice) use ($shopPriceTitle) { + return $cheapestSellPrice['title'] === $shopPriceTitle; + })); + $articlePrice = $foundPrice[0]['price'] ?? 0; + $calculatedSellPrice += $subItem->amount * $articlePrice; + } } } - - WarehouseArticlePacketModel::update(array_merge(get_object_vars($packet), ['calculatedSellPrice' => $calculatedSellPrice])); + + WarehouseArticlePacketModel::update(array_merge(get_object_vars($packet), ['calculatedSellPrice' => $calculatedSellPrice])); } return true; diff --git a/application/WarehouseArticlePacket/WarehouseArticlePacketModel.php b/application/WarehouseArticlePacket/WarehouseArticlePacketModel.php index bf30fe54f..72dc48586 100644 --- a/application/WarehouseArticlePacket/WarehouseArticlePacketModel.php +++ b/application/WarehouseArticlePacket/WarehouseArticlePacketModel.php @@ -9,4 +9,8 @@ class WarehouseArticlePacketModel extends TTCrudBaseModel { public ?float $overrideSellPrice; public ?float $calculatedSellPrice; public string $subItems; -} \ No newline at end of file + public ?int $isEShop; // New field for Energie Steiermark shop visibility + public ?int $isEShopHide; // New field to hide from Energie Steiermark shop + public ?int $isSbidiShop; // New field for Sbidi shop visibility + public ?int $isSbidiShopHide; // New field to hide from Sbidi shop +} diff --git a/application/WarehouseEShop/WarehouseEShop.php b/application/WarehouseEShop/WarehouseEShop.php deleted file mode 100644 index 2e930f6fc..000000000 --- a/application/WarehouseEShop/WarehouseEShop.php +++ /dev/null @@ -1,9 +0,0 @@ - 'title', 'text' => 'Artikel', 'priority' => 11], ['key' => 'category', 'text' => 'Kategorie', 'table' => false], @@ -15,22 +11,33 @@ class WarehouseEShopController extends TTCrud { ['key' => 'amount', 'text' => 'Menge', 'table' => ['filter' => false, 'sortable' => false, 'class' => 'p-0 width-80'], 'priority' => 9], ['key' => 'add', 'text' => 'Hinzufügen', 'table' => ['filter' => false, 'sortable' => false, 'class' => 'width-120 text-center'], 'priority' => 5000] ]; - + //@formatter:on protected array $permissionCheck = ['WarehouseEShop']; + protected array $additionalJSVariables = []; - protected array $infoMessages = [ - 'create' => 'Not possible', - 'update' => 'Not possible', - 'delete' => 'Not possible', - 'noChanges' => 'Keine Änderungen', - ]; - - protected function prepareCrudConfig() { - if (!$this->user->can('WarehouseAdmin')) { - $this->columns[2]['table'] = false; + protected function afterInit() { + if ($this->user->isAdmin()) { + if (isset($_GET['shop']) && in_array($_GET['shop'], ['e', 'sbidi'])) { + $flag = new WorkerFlag($this->user->id, 'WarehouseSelectedShop'); + $flag->value($_GET['shop']); + $flag->save(); + $this->user->address_id = ($_GET['shop'] === 'e') ? '209' : '9633'; + } elseif (!$this->user->getFlag('WarehouseSelectedShop')) self::sendError("Bitte wählen Sie einen Shop aus."); + } else { + $selectedShop = $this->user->getFlag('WarehouseSelectedShop')->value(); + if ($selectedShop) $this->user->address_id = ($selectedShop === 'e') ? '209' : '9633'; } } + protected function prepareCrudConfig() { + if (!$this->user->can('WarehouseAdmin')) $this->columns[2]['table'] = false; + + $this->additionalJSVariables['userAddressId'] = $this->user->address_id ?? null; + + if ($this->user->address_id == 209) $this->headerTitle = 'Energie Steiermark Shop'; + elseif ($this->user->address_id == 9633) $this->headerTitle = 'SBIDI Shop'; + else self::sendError("Keine Berechtigung für diesen Shop"); + } public function getAction() { $filter = $this->postData['filters'] ?? []; @@ -39,28 +46,41 @@ class WarehouseEShopController extends TTCrud { $perPage = $this->postData['pagination']['per_page'] ?? 10; $warehouseArticleFilter = $filter; - $warehouseArticleFilter['isEShop'] = 1; - $warehouseArticleFilter['isEShopHide'] = 0; + $warehousePacketFilter = $filter; + + if (!in_array(intval($this->user->address_id), [209, 9633])) self::sendError("Keine Berechtigung für diesen Shop"); + + $shopType = (intval($this->user->address_id) === 209) ? 'eShop' : 'sbidiShop'; + $this->headerTitle = (intval($this->user->address_id) === 209) ? 'Energie Steiermark Shop' : 'SBIDI Shop'; + + $warehouseArticleFilter["is{$shopType}"] = 1; + $warehouseArticleFilter["is{$shopType}Hide"] = 0; + $warehousePacketFilter["is{$shopType}"] = 1; + $warehousePacketFilter["is{$shopType}Hide"] = 0; $warehouseArticles = WarehouseArticleModel::getAll($warehouseArticleFilter, null, 0, $order); - $warehouseArticlesTotal = WarehouseArticleModel::count(['isEShop' => 1, 'isEShopHide' => 0]); + $warehouseArticlesTotal = WarehouseArticleModel::count($warehouseArticleFilter); $warehouseArticlesAvailable = WarehouseArticleModel::count($warehouseArticleFilter); - $warehousePackets = WarehouseArticlePacketModel::getAll($filter, null, 0, $order); - $warehousePacketsTotal = WarehouseArticlePacketModel::count(); - $warehousePacketsAvailable = WarehouseArticlePacketModel::count($filter); + $warehousePackets = WarehouseArticlePacketModel::getAll($warehousePacketFilter, null, 0, $order); + $warehousePacketsTotal = WarehouseArticlePacketModel::count($warehousePacketFilter); + $warehousePacketsAvailable = WarehouseArticlePacketModel::count($warehousePacketFilter); $filteredAvailable = $warehouseArticlesAvailable + $warehousePacketsAvailable; $totalRows = $warehouseArticlesTotal + $warehousePacketsTotal; $rows = [...$warehouseArticles, ...$warehousePackets]; - $rows = array_slice($rows, ($page - 1) * $perPage, $perPage); + usort($rows, function($a, $b) { return strcmp($a->title, $b->title); }); - self::returnJson(["rows" => $rows, - "pagination" => ["page" => $page, - "total_pages" => ceil($filteredAvailable / $perPage), - "per_page" => $perPage, - "filtered_available" => $filteredAvailable, - "total_rows" => $totalRows]]); + self::returnJson([ + "rows" => array_slice($rows, ($page - 1) * $perPage, $perPage), + "pagination" => [ + "page" => $page, + "total_pages" => ceil($filteredAvailable / $perPage), + "per_page" => $perPage, + "filtered_available" => $filteredAvailable, + "total_rows" => $totalRows + ] + ]); } -} \ No newline at end of file +} diff --git a/application/WarehouseEShopOrder/WarehouseEShopOrder.php b/application/WarehouseEShopOrder/WarehouseEShopOrder.php deleted file mode 100644 index 5e76e3afc..000000000 --- a/application/WarehouseEShopOrder/WarehouseEShopOrder.php +++ /dev/null @@ -1,9 +0,0 @@ - 'id', 'text' => 'ID', 'modal' => false], ['key' => 'extRef', 'text' => 'Externe Referenz', 'required' => true], + ['key' => 'addressId', 'text' => 'Shop', 'modal' => false, 'table' => ['filter' => 'select'], 'type' => 'select', 'items' => []], // New column for address ID ['key' => 'status', 'text' => 'Status', 'required' => true, 'modal' => ['type' => 'select', 'items' => [['value' => 'new', 'text' => 'Neu'], ['value' => 'accepted', 'text' => 'An Lieferant übergeben'], ['value' => 'acceptedInternally', 'text' => 'Interne verarbeitung'], ['value' => 'sent', 'text' => 'Gesendet'], ['value' => 'done', 'text' => 'Erledigt'],]], 'table' => ['filter' => 'select']], ['key' => 'shippingNoteStatus', 'text' => 'LS-Status', 'required' => false, 'modal' => false, 'table' => ['filter' => false, 'order' => false]], ['key' => 'deliveryMode', 'text' => 'Liefermodus', 'required' => true, 'modal' => ['type' => 'select', 'items' => [['value' => 'singleAddress', 'text' => 'Einzelne Adresse']]]], @@ -69,6 +70,16 @@ class WarehouseEShopOrderController extends TTCrud { $createByIndex = array_search('createBy', array_column($this->columns, 'key')); $this->columns[$createByIndex]['modal']['items'] = $users; + + // Add options for the new addressId column filter + $addressIdColumnIndex = array_search('addressId', array_column($this->columns, 'key')); + if ($addressIdColumnIndex !== false) { + $this->columns[$addressIdColumnIndex]['items'] = [ + ['value' => 209, 'text' => 'Energie Steiermark'], + ['value' => 9633, 'text' => 'SBIDI'], + ]; + $this->columns[$addressIdColumnIndex]['modal']['items'] = $this->columns[$addressIdColumnIndex]['items']; + } } protected function createShippingNote() { @@ -81,8 +92,8 @@ class WarehouseEShopOrderController extends TTCrud { $existingShippingNote = WarehouseShippingNoteModel::getAll(['eShopOrderId' => $id]); if (!empty($existingShippingNote)) { self::returnJson(['success' => false, - 'message' => 'Für diese Bestellung existiert bereits ein Lieferschein', - 'shippingNoteId' => $existingShippingNote[0]->id]); + 'message' => 'Für diese Bestellung existiert bereits ein Lieferschein', + 'shippingNoteId' => $existingShippingNote[0]->id]); die(); } @@ -101,11 +112,19 @@ class WarehouseEShopOrderController extends TTCrud { $articleTitle = $item->articleId ? $articles[$article]->title : $articlePackets[$articlePacket]->title; $quantity = $item->quantity; $price = 0; + + $priceTitle = ''; + if ($order->addressId === 209) { + $priceTitle = 'Energie Steiermark'; + } elseif ($order->addressId === 9633) { + $priceTitle = 'SBIDI'; + } + if ($item->articleId) { $cheapestSellPrice = json_decode($articles[$article]->cheapestSellPrice, true); - foreach ($cheapestSellPrice as $price) { - if ($price['title'] === 'Energie Steiermark') { - $price = $price['price']; + foreach ($cheapestSellPrice as $p) { + if ($p['title'] === $priceTitle) { + $price = $p['price']; break; } } @@ -126,20 +145,20 @@ class WarehouseEShopOrderController extends TTCrud { $positions = json_encode($positions); - $shippingNoteId = WarehouseShippingNoteModel::create(['billingAddressId' => 3265, - 'deliveryAddressName' => $order->deliveryAddressName, - 'deliveryAddressLine' => $order->deliveryAddressLine, - 'deliveryAddressPLZ' => $order->deliveryAddressPLZ, - 'deliveryAddressCity' => $order->deliveryAddressCity, - 'deliveryAddressEMail' => '', - 'note' => 'Erstellung aus Energie Steiermark Shop Bestellung #' . $id, - 'status' => 'new', - 'positions' => $positions, - 'textElements' => '[]', - 'hoursEntries' => '[]', - 'eShopOrderId' => $id, - 'create' => time(), - 'createBy' => $this->user->id]); + $shippingNoteId = WarehouseShippingNoteModel::create(['billingAddressId' => 3265, // Assuming a default billing address + 'deliveryAddressName' => $order->deliveryAddressName, + 'deliveryAddressLine' => $order->deliveryAddressLine, + 'deliveryAddressPLZ' => $order->deliveryAddressPLZ, + 'deliveryAddressCity' => $order->deliveryAddressCity, + 'deliveryAddressEMail' => '', + 'note' => 'Erstellung aus Shop Bestellung #' . $id, + 'status' => 'new', + 'positions' => $positions, + 'textElements' => '[]', + 'hoursEntries' => '[]', + 'eShopOrderId' => $id, + 'create' => time(), + 'createBy' => $this->user->id]); self::returnJson(['success' => true, 'message' => 'Lieferschein wurde erstellt', 'shippingNoteId' => $shippingNoteId]); @@ -167,8 +186,9 @@ class WarehouseEShopOrderController extends TTCrud { $article = $item->articleId ? array_search($item->articleId, array_column($articles, 'id')) : null; $articlePacket = $item->articlePacketId ? array_search($item->articlePacketId, array_column($articlePackets, 'id')) : null; - $articleExtRef = $articleDistributor[array_search($item->articleId, array_column($articleDistributor, 'articleId'))]; - $articleExtRef = $item->articleId ? $articleExtRef->externalArticleNumber : (!empty($articlePacket->externalArticleNumber) ? $articlePacket->externalArticleNumber : null); + $articleExtRef = $item->articleId && isset($articleDistributor[array_search($item->articleId, array_column($articleDistributor, 'articleId'))]) ? $articleDistributor[array_search($item->articleId, array_column($articleDistributor, 'articleId'))]->externalArticleNumber : null; + $articleExtRef = $item->articlePacketId && isset($articlePackets[$articlePacket]) && !empty($articlePackets[$articlePacket]->externalArticleNumber) ? $articlePackets[$articlePacket]->externalArticleNumber : $articleExtRef; + $articleTitle = $item->articleId ? $articles[$article]->title : $articlePackets[$articlePacket]->title; $quantity = $item->quantity; $body .= $articleExtRef !== null ? "$quantity x $articleExtRef ($articleTitle)\n" : "$quantity x $articleTitle\n"; @@ -183,7 +203,16 @@ class WarehouseEShopOrderController extends TTCrud { } else { $csvContent = $this->CSVExportNewOrdersMarkAcceptedAction(true, [$id]); - foreach (["ftth-versand@triotronik.com", "eshop-versand@xinon.at"] as $emailAddr) { + // Determine recipient emails based on addressId + $recipientEmails = ["eshop-versand@xinon.at"]; // Default for all orders + if ($order->addressId === 209) { + $recipientEmails[] = "ftth-versand@triotronik.com"; // Energie Steiermark specific + } elseif ($order->addressId === 9633) { + $recipientEmails[] = "sbidi-versand@xinon.at"; // SBIDI specific (example, adjust as needed) + } + + + foreach ($recipientEmails as $emailAddr) { $email = new Emailnotification(); $email->setSubject("Bestellbestätigung Bestellung #$paddedId"); $email->setBody($body); @@ -263,23 +292,32 @@ class WarehouseEShopOrderController extends TTCrud { return "$quantity x $articleExtRef ($articleTitle)"; }, $orderItems)); - $rows[] = ['AddressNumber' => '23000539', - 'Name' => $order['deliveryAddressName'], - 'Straße' => $order['deliveryAddressLine'], - 'Postleitzahl' => $order['deliveryAddressPLZ'], - 'Ort' => $order['deliveryAddressCity'], - 'Land' => 'AT', - 'Anschriftenzusatz 1' => $order['deliveryAddressAdditional'], - 'Produkte' => $orderItemsStr]; + // Determine AddressNumber based on order's addressId + $addressNumber = ''; + if ($order['addressId'] === 209) { + $addressNumber = '23000539'; // Energie Steiermark + } elseif ($order['addressId'] === 9633) { + $addressNumber = 'SBIDI_CUSTOMER_NUMBER'; // Placeholder for SBIDI, replace with actual + } + + + $rows[] = ['AddressNumber' => $addressNumber, + 'Name' => $order['deliveryAddressName'], + 'Straße' => $order['deliveryAddressLine'], + 'Postleitzahl' => $order['deliveryAddressPLZ'], + 'Ort' => $order['deliveryAddressCity'], + 'Land' => 'AT', + 'Anschriftenzusatz 1' => $order['deliveryAddressAdditional'], + 'Produkte' => $orderItemsStr]; WarehouseHistoryModel::create(['table' => 'WarehouseEShopOrder', - 'row_id' => $order['id'], - 'key' => 'status', - 'old_value' => 'new', - 'new_value' => 'accepted', - 'note' => 'CSV Export', - 'user_id' => $this->user->id, - 'create' => time()]); + 'row_id' => $order['id'], + 'key' => 'status', + 'old_value' => 'new', + 'new_value' => 'accepted', + 'note' => 'CSV Export', + 'user_id' => $this->user->id, + 'create' => time()]); $order['status'] = 'accepted'; WarehouseEShopOrderModel::update($order); @@ -310,15 +348,19 @@ class WarehouseEShopOrderController extends TTCrud { $article = $item['articleId'] ? array_search($item['articleId'], array_column($articles, 'id')) : null; $articlePacket = $item['articlePacketId'] ? array_search($item['articlePacketId'], array_column($articlePackets, 'id')) : null; - $articleExtRef = array_search($item['articleId'], array_column($articleDistributor, 'articleId'))['externalArticleNumber'] ?? null; + $articleExtRef = null; + if ($item['articleId'] && isset($articleDistributor[array_search($item['articleId'], array_column($articleDistributor, 'articleId'))])) { + $articleExtRef = $articleDistributor[array_search($item['articleId'], array_column($articleDistributor, 'articleId'))]->externalArticleNumber; + } + $orderItems[$item['orderId']][] = ['id' => $item['id'], - 'articleId' => $item['articleId'], - 'articleExtRef' => $articleExtRef, - 'articleTitle' => isset($articles[$article]) ? $articles[$article]->title : null, - 'articlePacketId' => $item['articlePacketId'], - 'articlePacketTitle' => isset($articlePackets[$articlePacket]) ? $articlePackets[$articlePacket]->title : null, - 'quantity' => $item['quantity']]; + 'articleId' => $item['articleId'], + 'articleExtRef' => $articleExtRef, + 'articleTitle' => isset($articles[$article]) ? $articles[$article]->title : null, + 'articlePacketId' => $item['articlePacketId'], + 'articlePacketTitle' => isset($articlePackets[$articlePacket]) ? $articlePackets[$articlePacket]->title : null, + 'quantity' => $item['quantity']]; } return $orderItems; @@ -339,19 +381,22 @@ class WarehouseEShopOrderController extends TTCrud { $json['status'] = 'new'; $json['create'] = time(); $json['createBy'] = $this->user->id; + $json['addressId'] = $this->user->address_id; // Store the address_id of the ordering user Helper::validateArray($json, $this->getCheckArray()); $id = WarehouseEShopOrderModel::create(['status' => 'new', - 'extRef' => $json['extRef'], - 'deliveryMode' => $json['deliveryMode'], - 'deliveryAddressAdditional' => $json['deliveryAddressAdditional'] ?? '', - 'deliveryAddressName' => $json['deliveryAddressName'], - 'deliveryAddressLine' => $json['deliveryAddressLine'], - 'deliveryAddressPLZ' => $json['deliveryAddressPLZ'], - 'deliveryAddressCity' => $json['deliveryAddressCity'], - 'create' => $json['create'], - 'createBy' => $json['createBy'],]); + 'extRef' => $json['extRef'], + 'deliveryMode' => $json['deliveryMode'], + 'deliveryAddressAdditional' => $json['deliveryAddressAdditional'] ?? '', + 'deliveryAddressName' => $json['deliveryAddressName'], + 'deliveryAddressLine' => $json['deliveryAddressLine'], + 'deliveryAddressPLZ' => $json['deliveryAddressPLZ'], + 'deliveryAddressCity' => $json['deliveryAddressCity'], + 'create' => $json['create'], + 'createBy' => $json['createBy'], + 'addressId' => $json['addressId'], // Pass the addressId + ]); // now create WarehouseEShopOrderItems for each item in the shopping cart foreach ($shoppingCart as $item) { @@ -359,12 +404,12 @@ class WarehouseEShopOrderController extends TTCrud { // parse this and either fill articleId or articlePacketId for warehouseEShopOrderItem if (strpos($item['itemId'], 'P-') === 0) { WarehouseEShopOrderItemModel::create(['orderId' => $id, - 'articlePacketId' => intval(substr($item['itemId'], 2)), - 'quantity' => intval($item['amount']),]); + 'articlePacketId' => intval(substr($item['itemId'], 2)), + 'quantity' => intval($item['amount']),]); } else if (strpos($item['itemId'], 'I-') === 0) { WarehouseEShopOrderItemModel::create(['orderId' => $id, - 'articleId' => intval(substr($item['itemId'], 2)), - 'quantity' => intval($item['amount']),]); + 'articleId' => intval(substr($item['itemId'], 2)), + 'quantity' => intval($item['amount']),]); } else { self::returnJson(['success' => false, 'message' => 'Invalid item id']); die(); @@ -390,8 +435,17 @@ class WarehouseEShopOrderController extends TTCrud { $user = UserModel::getOne($json['createBy']); - if ($_SERVER['HTTP_HOST'] !== 'localhost') - foreach (["office@xinon.at", $user->email] as $emailAddr) { + if ($_SERVER['HTTP_HOST'] !== 'localhost') { + $recipientEmails = ["office@xinon.at", $user->email]; + // Add shop-specific email if applicable + if ($json['addressId'] === 209) { + $recipientEmails[] = "ftth-versand@triotronik.com"; + } elseif ($json['addressId'] === 9633) { + $recipientEmails[] = "sbidi-versand@xinon.at"; // Example for SBIDI + } + $recipientEmails = array_unique($recipientEmails); // Remove duplicates + + foreach ($recipientEmails as $emailAddr) { $email = new Emailnotification(); $email->setSubject("Bestellbestätigung Bestellung #$subjectId - Referenz: " . $json['extRef']); $email->setBody($body); @@ -399,10 +453,11 @@ class WarehouseEShopOrderController extends TTCrud { $email->setTo($emailAddr); $email->send(); } + } self::returnJson(['success' => true, - 'message' => $this->infoMessages['create'], - 'id' => $id]); + 'message' => $this->infoMessages['create'], + 'id' => $id]); } protected function beforeCreate(): bool { @@ -551,8 +606,8 @@ class WarehouseEShopOrderController extends TTCrud { $orders = WarehouseEShopOrderModel::getAll(['deliveryAddressLine' => $addressLine, - 'deliveryAddressPLZ' => $plz, - 'deliveryAddressCity' => $city]); + 'deliveryAddressPLZ' => $plz, + 'deliveryAddressCity' => $city]); if (empty($orders)) { echo "No order found with address: $addressLine, $plz, $city" . PHP_EOL; continue; @@ -570,13 +625,13 @@ class WarehouseEShopOrderController extends TTCrud { WarehouseEShopOrderModel::update($order); WarehouseHistoryModel::create(['table' => 'WarehouseEShopOrder', - 'row_id' => $order['id'], - 'key' => 'trackingNumber', - 'old_value' => '', - 'new_value' => $trackingNumber, - 'note' => '', - 'user_id' => 1, - 'create' => date('U')]); + 'row_id' => $order['id'], + 'key' => 'trackingNumber', + 'old_value' => '', + 'new_value' => $trackingNumber, + 'note' => '', + 'user_id' => 1, + 'create' => date('U')]); // echo "Subject: " . $overview[0]->subject . "\n"; // echo "From: " . $overview[0]->from . "\n"; diff --git a/application/WarehouseEShopOrder/WarehouseEShopOrderModel.php b/application/WarehouseEShopOrder/WarehouseEShopOrderModel.php index 91e03f16f..7c26ffa9d 100644 --- a/application/WarehouseEShopOrder/WarehouseEShopOrderModel.php +++ b/application/WarehouseEShopOrder/WarehouseEShopOrderModel.php @@ -11,6 +11,7 @@ * @property string $deliveryAddressCity * @property int $create * @property int $createBy + * @property int $addressId // Added addressId property */ class WarehouseEShopOrderModel extends TTCrudBaseModel { @@ -28,4 +29,5 @@ class WarehouseEShopOrderModel extends TTCrudBaseModel { public ?string $trackingNumber; public int $create; public int $createBy; -} \ No newline at end of file + public ?int $addressId; // New field to store the address_id of the ordering entity +} diff --git a/application/WarehouseEShopOrderItem/WarehouseEShopOrderItem.php b/application/WarehouseEShopOrderItem/WarehouseEShopOrderItem.php deleted file mode 100644 index 71be18ff5..000000000 --- a/application/WarehouseEShopOrderItem/WarehouseEShopOrderItem.php +++ /dev/null @@ -1,9 +0,0 @@ -getEnvironment() == "thetool") { + $eShopOrder = $this->table('WarehouseEShopOrder'); + $eShopOrder + ->addColumn('addressId', 'integer', [ + 'null' => true, + 'after' => 'createBy' + ]) + ->addIndex(['addressId'], ['name' => 'idx_addressId']) + ->save(); + + $this->execute("UPDATE `WarehouseEShopOrder` SET `addressId` = 209 WHERE `addressId` IS NULL"); + + $article = $this->table('WarehouseArticle'); + $article + ->addColumn('isSbidiShop', 'integer', [ + 'default' => 0, + 'after' => 'isEShop' + ]) + ->addColumn('isSbidiShopHide', 'integer', [ + 'default' => 0, + 'after' => 'isSbidiShop' + ]) + ->addIndex(['isEShop'], ['name' => 'idx_isEShop']) + ->addIndex(['isEShopHide'], ['name' => 'idx_isEShopHide']) + ->addIndex(['isSbidiShop'], ['name' => 'idx_isSbidiShop']) + ->addIndex(['isSbidiShopHide'], ['name' => 'idx_isSbidiShopHide']) + ->save(); + + $this->execute("UPDATE `WarehouseArticle` SET `isSbidiShop` = 0, `isSbidiShopHide` = 0 WHERE `isSbidiShop` IS NULL"); + + $articlePacket = $this->table('WarehouseArticlePacket'); + $articlePacket + ->addColumn('isEShop', 'integer', [ + 'default' => 0, + 'after' => 'calculatedSellPrice' + ]) + ->addColumn('isEShopHide', 'integer', [ + 'default' => 0, + 'after' => 'isEShop' + ]) + ->addColumn('isSbidiShop', 'integer', [ + 'default' => 0, + 'after' => 'isEShopHide' + ]) + ->addColumn('isSbidiShopHide', 'integer', [ + 'default' => 0, + 'after' => 'isSbidiShop' + ]) + ->addIndex(['isEShop'], ['name' => 'idx_isEShop_packet']) + ->addIndex(['isEShopHide'], ['name' => 'idx_isEShopHide_packet']) + ->addIndex(['isSbidiShop'], ['name' => 'idx_isSbidiShop_packet']) + ->addIndex(['isSbidiShopHide'], ['name' => 'idx_isSbidiShopHide_packet']) + ->save(); + + $this->execute(" + UPDATE `WarehouseArticlePacket` + SET `isEShop` = 1, `isEShopHide` = 0, `isSbidiShop` = 0, `isSbidiShopHide` = 0 + WHERE `isEShop` IS NULL + "); + } + } + + public function down(): void + { + if ($this->getEnvironment() == "thetool") { + $articlePacket = $this->table('WarehouseArticlePacket'); + $articlePacket + ->removeColumn('isSbidiShopHide') + ->removeColumn('isSbidiShop') + ->removeColumn('isEShopHide') + ->removeColumn('isEShop') + ->save(); + + $article = $this->table('WarehouseArticle'); + $article + ->removeColumn('isSbidiShopHide') + ->removeColumn('isSbidiShop') + ->save(); + + $article + ->removeIndexByName('idx_isEShop') + ->removeIndexByName('idx_isEShopHide') + ->removeIndexByName('idx_isSbidiShop') + ->removeIndexByName('idx_isSbidiShopHide') + ->save(); + + $eShopOrder = $this->table('WarehouseEShopOrder'); + $eShopOrder + ->removeColumn('addressId') + ->save(); + } + } +} diff --git a/lib/TTCrud/TTCrud.php b/lib/TTCrud/TTCrud.php index a99a81c20..4dcf2072a 100644 --- a/lib/TTCrud/TTCrud.php +++ b/lib/TTCrud/TTCrud.php @@ -49,6 +49,7 @@ class TTCrud extends mfBaseController { $this->postData = json_decode(file_get_contents('php://input'), true); $this->checkArray = $this->getCheckArray(); $this->infoMessages = $this->getInfoMessages(); + if (method_exists($this, 'afterInit')) $this->afterInit(); } /** diff --git a/public/js/pages/WarehouseArticlePacket/WarehouseArticlePacket.js b/public/js/pages/WarehouseArticlePacket/WarehouseArticlePacket.js index a6fdda079..dbf08a22d 100644 --- a/public/js/pages/WarehouseArticlePacket/WarehouseArticlePacket.js +++ b/public/js/pages/WarehouseArticlePacket/WarehouseArticlePacket.js @@ -37,6 +37,21 @@ Vue.component('WarehouseArticlePacket', { articles: [], } }, beforeMount() { + // Dynamically filter articles based on the user's shop context + // This assumes TT_CONFIG is available and contains userAddressId + const userAddressId = window['TT_CONFIG']['userAddressId']; + let articleFilter = {}; + if (userAddressId === 209) { + articleFilter = { isEShop: 1 }; + } else if (userAddressId === 210) { + articleFilter = { isSbidiShop: 1 }; + } + + // The current implementation directly uses `window['TT_CONFIG']['CRUD_CONFIG'].columns.find(...)` + // which might not reflect the filtered articles. + // To properly filter, the `input-article` component or its underlying API call needs to be aware of the shop context. + // For now, this will just get all articles that were passed from the backend during initial config. + // A more robust solution would involve modifying the `WarehouseArticle/autocomplete` API to accept shop filters. this.articles = window['TT_CONFIG']['CRUD_CONFIG'].columns.find(column => column.key === 'subItems').modal.items; } }) diff --git a/public/js/pages/WarehouseEShop/WarehouseEShop.js b/public/js/pages/WarehouseEShop/WarehouseEShop.js index 5a6168991..509157109 100644 --- a/public/js/pages/WarehouseEShop/WarehouseEShop.js +++ b/public/js/pages/WarehouseEShop/WarehouseEShop.js @@ -1,53 +1,53 @@ Vue.component('warehouse-e-shop', { //language=Vue template: ` - - + + - - - + + - + ]" sm row/> + - - - - - - - - - + + + + + + + - + - + - - - - - - - `, data() { + + + + + + + + + `, data() { return { window: window, itemAmounts: {}, shoppingCart: [], createOrderDialog: false, createOrderDialogData: { deliveryMode: 'singleAddress', @@ -59,9 +59,29 @@ Vue.component('warehouse-e-shop', { deliveryAddressPLZ: '', deliveryAddressCity: '', }, + userAddressId: window['TT_CONFIG']['userAddressId'] || null, // Get user's address ID from PHP } }, methods: { + getArticlePrice(row) { + const cheapestSellPrice = JSON.parse(row.cheapestSellPrice); + let priceTitle = ''; + + if (this.userAddressId === 209) { + priceTitle = 'Energie Steiermark'; + } else if (this.userAddressId === 9633) { + priceTitle = 'SBIDI'; + } else { + // Default or error handling if addressId is not recognized + return 0; + } + + const foundPrice = Array.isArray(cheapestSellPrice) + ? cheapestSellPrice.find(price => price.title === priceTitle) + : Object.values(cheapestSellPrice).find(price => price.title === priceTitle); + + return foundPrice ? foundPrice.price : 0; + }, async openOrderDialog() { this.createOrderDialog = true; }, @@ -81,6 +101,7 @@ Vue.component('warehouse-e-shop', { if (response.data.success) { this.window.notify('success', response.data.message || 'Erfolgreich gespeichert'); this.shoppingCart = []; + this.itemAmounts = {}; // Clear item amounts after successful order this.createOrderDialogData = { deliveryMode: 'singleAddress', extRef: '', diff --git a/public/js/pages/WarehouseEShopOrder/WarehouseEShopOrder.js b/public/js/pages/WarehouseEShopOrder/WarehouseEShopOrder.js index a66d6b0c5..ac100e128 100644 --- a/public/js/pages/WarehouseEShopOrder/WarehouseEShopOrder.js +++ b/public/js/pages/WarehouseEShopOrder/WarehouseEShopOrder.js @@ -45,7 +45,7 @@ Vue.component('warehouse-e-shop-order-modal-positions-mgmt', { } for (const response of articlePacketResponses) { - this.$set(this.articlePacketNames, response.data[0].value, response.data[0].text); + this.$set(this.articlePacketNames, response.data[0].value, response.data[0].data[0].text); // Adjusted for packet autocomplete response structure } }, @@ -109,47 +109,47 @@ Vue.component('warehouse-e-shop-order-modal-positions-mgmt', { }, }, watch: {positions: {handler: 'fetchNames', immediate: true}}, //language=Vue template: ` -
    +
    -
    - - - -
    - -
    -
    +
    + + + +
    + +
    +
    -
    -
    - - - - - - - - - - - - - - - - - -
    ArtikelMengeAktionen
    Keine Einträge
    {{ position.articleId ? articleNames[position.articleId] : position.articlePacketId ? articlePacketNames[position.articlePacketId] : - 'Loading...' }} - {{ position.quantity }} - - -
    - +
    + + + + + + + + + + + + + + + + + + +
    ArtikelMengeAktionen
    Keine Einträge
    {{ position.articleId ? articleNames[position.articleId] : position.articlePacketId ? articlePacketNames[position.articlePacketId] : + 'Loading...' }} + {{ position.quantity }} + + +
    +
    - - `, + + `, }) @@ -157,83 +157,89 @@ Vue.component('warehouse-e-shop-order-modal-positions-mgmt', { Vue.component('warehouse-e-shop-order', { //language=Vue template: ` - - + + - + - + - + - + - + - - + - - -
    -

    -
    - -
    - -
    -
    +
    + - -
    -
      -
    • - {{ entry.date }} {{ entry.time }} - {{ entry.evtDscr }} -
    • -
    -
    + + +
    +

    +
    + +
    + +
    +
    -
    + +
    +
      +
    • + {{ entry.date }} {{ entry.time }} - {{ entry.evtDscr }} +
    • +
    +
    + +
    -
    - `, data() { + + `, data() { return { window: window, historyModal: false, From 4b56f7e87c0cab448d387d7c020902d9f16533b1 Mon Sep 17 00:00:00 2001 From: Luca Haid Date: Mon, 21 Jul 2025 12:34:08 +0200 Subject: [PATCH 10/24] Added defer to some stuff to improve loading times --- Layout/default/vueHeader.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Layout/default/vueHeader.php b/Layout/default/vueHeader.php index e24275a07..5d04b6adb 100644 --- a/Layout/default/vueHeader.php +++ b/Layout/default/vueHeader.php @@ -39,11 +39,11 @@ - - - - - + + + + + From a5e41fc579261f564ad880544da1bee72035ca45 Mon Sep 17 00:00:00 2001 From: Luca Haid Date: Mon, 21 Jul 2025 13:07:44 +0200 Subject: [PATCH 11/24] fixed bug in eShop --- .../WarehouseEShopController.php | 65 ++++++++----------- 1 file changed, 26 insertions(+), 39 deletions(-) diff --git a/application/WarehouseEShop/WarehouseEShopController.php b/application/WarehouseEShop/WarehouseEShopController.php index c01cac00e..1a812f954 100644 --- a/application/WarehouseEShop/WarehouseEShopController.php +++ b/application/WarehouseEShop/WarehouseEShopController.php @@ -4,70 +4,57 @@ class WarehouseEShopController extends TTCrud { protected string $headerTitle = 'Energie Steiermark Shop'; protected bool $createText = false; //@formatter:off + protected array $columns = [ ['key' => 'title', 'text' => 'Artikel', 'priority' => 11], ['key' => 'category', 'text' => 'Kategorie', 'table' => false], - ['key' => 'price', 'text' => 'Preis', 'table' => ['filter' => false, 'sortable' => false, 'class' => 'text-right']], + ['key' => 'price', 'text' => 'Preis', 'table' => false], ['key' => 'amount', 'text' => 'Menge', 'table' => ['filter' => false, 'sortable' => false, 'class' => 'p-0 width-80'], 'priority' => 9], ['key' => 'add', 'text' => 'Hinzufügen', 'table' => ['filter' => false, 'sortable' => false, 'class' => 'width-120 text-center'], 'priority' => 5000] ]; //@formatter:on protected array $permissionCheck = ['WarehouseEShop']; - protected array $additionalJSVariables = []; protected function afterInit() { - if ($this->user->isAdmin()) { - if (isset($_GET['shop']) && in_array($_GET['shop'], ['e', 'sbidi'])) { - $flag = new WorkerFlag($this->user->id, 'WarehouseSelectedShop'); - $flag->value($_GET['shop']); - $flag->save(); - $this->user->address_id = ($_GET['shop'] === 'e') ? '209' : '9633'; - } elseif (!$this->user->getFlag('WarehouseSelectedShop')) self::sendError("Bitte wählen Sie einen Shop aus."); - } else { - $selectedShop = $this->user->getFlag('WarehouseSelectedShop')->value(); - if ($selectedShop) $this->user->address_id = ($selectedShop === 'e') ? '209' : '9633'; + if (!$this->user->isAdmin()) return; + if (!$this->user->getFlag('WarehouseSelectedShop') && !isset($_GET['shop'])) self::sendError("Bitte wählen Sie einen Shop aus."); + + if (in_array($_GET['shop'], ['e', 'sbidi'])) { + $flag = new WorkerFlag($this->user->id, 'WarehouseSelectedShop'); + $flag->value($_GET['shop']); + $flag->save(); + $this->user->address_id = ($_GET['shop'] === 'e') ? '209' : '9633'; + return; } + + $this->user->address_id = ($this->user->getFlag('WarehouseSelectedShop')->value() === 'e') ? '209' : '9633'; } + protected function prepareCrudConfig() { - if (!$this->user->can('WarehouseAdmin')) $this->columns[2]['table'] = false; + if (!in_array(intval($this->user->address_id), [209, 9633])) self::sendError("Keine Berechtigung für diesen Shop"); $this->additionalJSVariables['userAddressId'] = $this->user->address_id ?? null; - - if ($this->user->address_id == 209) $this->headerTitle = 'Energie Steiermark Shop'; - elseif ($this->user->address_id == 9633) $this->headerTitle = 'SBIDI Shop'; - else self::sendError("Keine Berechtigung für diesen Shop"); + $this->headerTitle = $this->user->address_id == 209 ? 'Energie Steiermark Shop' : 'SBIDI Shop'; } public function getAction() { + if (!in_array(intval($this->user->address_id), [209, 9633])) self::sendError("Keine Berechtigung für diesen Shop"); + $filter = $this->postData['filters'] ?? []; $order = $this->postData['order'] ?? ['key' => null, 'order' => 'ASC']; $page = $this->postData['pagination']['page'] ?? 1; $perPage = $this->postData['pagination']['per_page'] ?? 10; - $warehouseArticleFilter = $filter; - $warehousePacketFilter = $filter; + $shopType = (intval($this->user->address_id) === 209) ? 'EShop' : 'SbidiShop'; + $filter["is{$shopType}"] = 1; + $filter["is{$shopType}Hide"] = 0; - if (!in_array(intval($this->user->address_id), [209, 9633])) self::sendError("Keine Berechtigung für diesen Shop"); + $warehouseArticles = WarehouseArticleModel::getAll($filter, null, 0, $order); + $warehousePackets = WarehouseArticlePacketModel::getAll($filter, null, 0, $order); - $shopType = (intval($this->user->address_id) === 209) ? 'eShop' : 'sbidiShop'; - $this->headerTitle = (intval($this->user->address_id) === 209) ? 'Energie Steiermark Shop' : 'SBIDI Shop'; + $filteredAvailable = WarehouseArticlePacketModel::count($filter) + WarehouseArticleModel::count($filter); - $warehouseArticleFilter["is{$shopType}"] = 1; - $warehouseArticleFilter["is{$shopType}Hide"] = 0; - $warehousePacketFilter["is{$shopType}"] = 1; - $warehousePacketFilter["is{$shopType}Hide"] = 0; - - $warehouseArticles = WarehouseArticleModel::getAll($warehouseArticleFilter, null, 0, $order); - $warehouseArticlesTotal = WarehouseArticleModel::count($warehouseArticleFilter); - $warehouseArticlesAvailable = WarehouseArticleModel::count($warehouseArticleFilter); - - $warehousePackets = WarehouseArticlePacketModel::getAll($warehousePacketFilter, null, 0, $order); - $warehousePacketsTotal = WarehouseArticlePacketModel::count($warehousePacketFilter); - $warehousePacketsAvailable = WarehouseArticlePacketModel::count($warehousePacketFilter); - - $filteredAvailable = $warehouseArticlesAvailable + $warehousePacketsAvailable; - $totalRows = $warehouseArticlesTotal + $warehousePacketsTotal; $rows = [...$warehouseArticles, ...$warehousePackets]; usort($rows, function($a, $b) { return strcmp($a->title, $b->title); }); @@ -79,8 +66,8 @@ class WarehouseEShopController extends TTCrud { "total_pages" => ceil($filteredAvailable / $perPage), "per_page" => $perPage, "filtered_available" => $filteredAvailable, - "total_rows" => $totalRows + "total_rows" => $filteredAvailable ] ]); } -} +} \ No newline at end of file From aef629a404a5e8670155e94f45f13c4ae175f45f Mon Sep 17 00:00:00 2001 From: Luca Haid Date: Mon, 21 Jul 2025 13:08:54 +0200 Subject: [PATCH 12/24] fixed bug in eShop --- .../WarehouseArticlePacketController.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/application/WarehouseArticlePacket/WarehouseArticlePacketController.php b/application/WarehouseArticlePacket/WarehouseArticlePacketController.php index 2d4fa21a7..434e5fdad 100644 --- a/application/WarehouseArticlePacket/WarehouseArticlePacketController.php +++ b/application/WarehouseArticlePacket/WarehouseArticlePacketController.php @@ -13,10 +13,10 @@ class WarehouseArticlePacketController extends TTCrud { ['key' => 'overrideSellPrice', 'text' => 'Überschriebener Verkaufspreis', 'required' => false, 'modal' => ['type' => 'number'], 'table' => false], ['key' => 'calculatedSellPrice', 'text' => 'Verkaufspreis', 'required' => false, 'modal' => false, 'table' => ['filter' => false, 'sortable' => false]], ['key' => 'subItems', 'text' => 'Unterartikel', 'required' => true], - ['key' => 'isEShop', 'text' => 'Energie Steiermark Shop', 'required' => false, 'modal' => ['type' => 'checkbox', 'items' => [['value' => 1, 'icon' => 'fas fa-check-circle text-success', 'text' => 'Ja'], ['value' => 0, 'icon' => 'fas fa-times-circle text-danger', 'text' => 'Nein']]], 'table' => ['filter' => 'iconSelect']], - ['key' => 'isEShopHide', 'text' => 'Energie Steiermark Shop Ausblenden', 'required' => false, 'modal' => ['type' => 'checkbox', 'items' => [['value' => 1, 'icon' => 'fas fa-check-circle text-success', 'text' => 'Ja'], ['value' => 0, 'icon' => 'fas fa-times-circle text-danger', 'text' => 'Nein']]], 'table' => ['filter' => 'iconSelect']], - ['key' => 'isSbidiShop', 'text' => 'Sbidi Shop', 'required' => false, 'modal' => ['type' => 'checkbox', 'items' => [['value' => 1, 'icon' => 'fas fa-check-circle text-success', 'text' => 'Ja'], ['value' => 0, 'icon' => 'fas fa-times-circle text-danger', 'text' => 'Nein']]], 'table' => ['filter' => 'iconSelect']], - ['key' => 'isSbidiShopHide', 'text' => 'Sbidi Shop Ausblenden', 'required' => false, 'modal' => ['type' => 'checkbox', 'items' => [['value' => 1, 'icon' => 'fas fa-check-circle text-success', 'text' => 'Ja'], ['value' => 0, 'icon' => 'fas fa-times-circle text-danger', 'text' => 'Nein']]], 'table' => ['filter' => 'iconSelect']], + ['key' => 'isEShop', 'text' => 'E-Shop', 'required' => false, 'modal' => ['type' => 'checkbox', 'items' => [['value' => 1, 'icon' => 'fas fa-check-circle text-success', 'text' => 'Ja'], ['value' => 0, 'icon' => 'fas fa-times-circle text-danger', 'text' => 'Nein']]], 'table' => ['filter' => 'iconSelect']], + ['key' => 'isEShopHide', 'text' => 'Hide', 'required' => false, 'modal' => ['type' => 'checkbox', 'items' => [['value' => 1, 'icon' => 'fas fa-check-circle text-success', 'text' => 'Ja'], ['value' => 0, 'icon' => 'fas fa-times-circle text-danger', 'text' => 'Nein']]], 'table' => ['filter' => 'iconSelect']], + ['key' => 'isSbidiShop', 'text' => 'S-Shop', 'required' => false, 'modal' => ['type' => 'checkbox', 'items' => [['value' => 1, 'icon' => 'fas fa-check-circle text-success', 'text' => 'Ja'], ['value' => 0, 'icon' => 'fas fa-times-circle text-danger', 'text' => 'Nein']]], 'table' => ['filter' => 'iconSelect']], + ['key' => 'isSbidiShopHide', 'text' => 'Hide', 'required' => false, 'modal' => ['type' => 'checkbox', 'items' => [['value' => 1, 'icon' => 'fas fa-check-circle text-success', 'text' => 'Ja'], ['value' => 0, 'icon' => 'fas fa-times-circle text-danger', 'text' => 'Nein']]], 'table' => ['filter' => 'iconSelect']], ['key' => 'actions', 'text' => 'Aktionen', 'required' => false, 'modal' => false, 'table' => ['filter' => false, 'sortable' => false, 'class' => 'text-center', 'priority' => 10]], ]; // @formatter:on From f7218ab144911ac25239ce4eec82fa358062fba9 Mon Sep 17 00:00:00 2001 From: Luca Haid Date: Mon, 21 Jul 2025 22:27:40 +0200 Subject: [PATCH 13/24] added v2 of cpeprov --- Layout/default/header.php | 2 +- .../CpeprovisioningController.php | 283 +++++++++++++++++- application/Order/OrderModel.php | 7 + .../OrderProduct/OrderProductModel.php | 4 +- ...20250721222300_cpeprov_add_new_indexes.php | 52 ++++ docker/php/Dockerfile | 11 + docker/php/apache.conf | 20 ++ .../pages/Cpeprovisioning/Cpeprovisioning.css | 159 ++++++++++ .../pages/Cpeprovisioning/Cpeprovisioning.js | 217 ++++++++++++++ .../plugins/bookstack/bookstackIntegration.js | 79 ++--- .../bookstack/bookstackIntegration.min.js | 1 + .../vue/tt-components/css/tt-tooltip.css | 5 +- .../plugins/vue/tt-components/tt-checkbox.js | 3 - 13 files changed, 786 insertions(+), 57 deletions(-) create mode 100644 db/migrations/20250721222300_cpeprov_add_new_indexes.php create mode 100644 public/js/pages/Cpeprovisioning/Cpeprovisioning.css create mode 100644 public/js/pages/Cpeprovisioning/Cpeprovisioning.js create mode 100644 public/plugins/bookstack/bookstackIntegration.min.js diff --git a/Layout/default/header.php b/Layout/default/header.php index cf5329afd..34df75eb0 100644 --- a/Layout/default/header.php +++ b/Layout/default/header.php @@ -56,7 +56,7 @@ - + diff --git a/application/Cpeprovisioning/CpeprovisioningController.php b/application/Cpeprovisioning/CpeprovisioningController.php index 0701e0316..682bbb35c 100644 --- a/application/Cpeprovisioning/CpeprovisioningController.php +++ b/application/Cpeprovisioning/CpeprovisioningController.php @@ -5,12 +5,11 @@ class CpeprovisioningController extends mfBaseController protected function init() { $this->needlogin = true; - $me = new User(); - $me->loadMe(); - $this->me = $me; - $this->layout()->set("me", $me); + $this->me = new User(); + $this->me->loadMe(); + $this->layout()->set("me", $this->me); - if (!$me->is(["Admin"])) { + if (!$this->me->is(["Admin"])) { $this->redirect("Dashboard"); } } @@ -283,11 +282,275 @@ class CpeprovisioningController extends mfBaseController $query["filter"] = $this->request->filter; } - $qs = http_build_query($query); - $this->layout()->setFlash("Eintrag erfolgreich gespeichert.", "success"); - $this->redirect("Cpeprovisioning", "Index", $qs); - + $this->redirect("Cpeprovisioning", "Index", http_build_query($query)); } -} + protected function apiSaveAction() { + try { + $p = json_decode(file_get_contents('php://input'), true); + + $id = $p['id'] ?? null; + $mode = $id ? "edit" : "add"; + + if ($mode === 'edit') { + $cpe = new Cpeprovisioning($id); + if (!$cpe->id) throw new Exception("Eintrag nicht gefunden"); + } + + if (empty($p['termination_id']) && empty($p['order_id'])) throw new Exception("Anschluss oder Bestellung nicht gefunden"); + if (!OrderProductModel::getFirst(["order_id" => $p['order_id'], "termination_id" => $p['termination_id']])) throw new Exception("Anschluss gehört nicht zur Bestellung"); + + if (!empty($p['ont_sn'])) { + $termination = new Termination($p['termination_id']); + $orig_sn = $termination->getWorkflowvalue("ont_sn", "string"); + + if ($orig_sn === null) { + if ($sn_item = WorkflowitemModel::getFirst(["name" => "ont_sn", "object_type" => "termination"])) { + $sn_item->setObjectId($p['termination_id']); + $termination->workflowitems["ont_sn"] = $sn_item; + } else { + $this->log->error("ont_sn workflow item not found"); + } + } + + if ($p['ont_sn'] !== $orig_sn && isset($termination->workflowitems["ont_sn"])) { + $termination->workflowitems["ont_sn"]->value->setValue($p['ont_sn']); + $termination->workflowitems["ont_sn"]->value->save(); + } + } + + $data = [ + "termination_id" => $p['termination_id'] ?: null, + "order_id" => $p['order_id'], + "orderproduct_id" => $p['orderproduct_id'], + "routerconfig_finished" => (int)($p['routerconfig_finished'] ?? 0), + "shipping" => (int)($p['shipping'] ?? 0), + "routertype" => $p['routertype'] ?? null, + "wifi_ssid" => $p['wifi_ssid'] ?? null, + "wifi_pass" => $p['wifi_pass'] ?? null, + "mac" => $p['mac'] ?? null, + "note" => $p['note'] ?? null, + "edit_by" => $this->me->id, + ]; + + foreach (['ship_weight', 'ship_length', 'ship_width', 'ship_height'] as $key) $data[$key] = empty($p[$key]) ? null : $p[$key]; + foreach (['public', 'nat', 'ipv6'] as $type) $data["vlan_{$type}"] = !empty($p['vlans'][$type]['checked']) ? ($p['vlans'][$type]['tag'] ?? null) : null; + + if ($mode === 'add') { + $data["create_by"] = $this->me->id; + $cpe = CpeprovisioningModel::create($data); + } else $cpe->update($data); + + if (!$cpe->save()) throw new Exception("Fehler beim Speichern"); + + if ($cpe->routerconfig_finished) { + $order_product = new OrderProduct($p['orderproduct_id']); + + $shipping_text = $cpe->shipping + ? "zum Versand vorbereitet" + : "vorbereitet für Techniker zur Vorortinstallation"; + + $text = "CPE zu Produkt \"{$order_product->product->name}\" {$shipping_text}.\n\n" + . "Router: {$cpe->routertype}\n" + . "Zugangstyp: {$order_product->product->attributes['bras_type']->value}\n"; + + if ($cpe->vlan_public) $text .= "Vlan Public: {$cpe->vlan_public}\n"; + if ($cpe->vlan_nat) $text .= "Vlan NAT: {$cpe->vlan_nat}\n"; + if ($cpe->vlan_ipv6) $text .= "Vlan IPv6: {$cpe->vlan_ipv6}\n"; + + $journal = new OrderJournal(); + $journal->order_id = $p['order_id']; + $journal->text = $text; + $journal->create_by = $this->me->id; + $journal->edit_by = $this->me->id; + + if (!($journal_id = $journal->save())) { + $this->layout()->setFlash("Konnte nicht ins Bestelljournal schreiben!", "warning"); + } else { + $cpe->order_journal_id = $journal_id; + $cpe->save(); + } + } + + self::returnJson(['success' => true, 'message' => 'Eintrag erfolgreich gespeichert.']); + + } catch (Exception $e) { + http_response_code(400); + self::returnJson(['success' => false, 'message' => $e->getMessage()]); + } + } + protected function apiGetAction() + { + $p = json_decode(file_get_contents('php://input'), true) ?? []; + + // --- Pagination and Sorting setup --- + $page = (int)($p['pagination']['page'] ?? 1); + $perPage = (int)($p['pagination']['per_page'] ?? 25); + $orderBy = $p['order']['key'] ?? null; + $orderDir = $p['order']['order'] ?? 'asc'; + + // Calculate start and end indexes for manual pagination, just like in the old indexAction + $start = ($page - 1) * $perPage; + $end = $start + $perPage; + + // --- Data Fetching (same as before) --- + $searchFilter = $this->getPreparedFilter($p['filters'] ?? []); + // if routerconfig_finished === 0 then we can add key add-where to searchFilter and only show orders withing the last 180 days either by create or edit (caution this is unix timestamp) + if (isset($searchFilter['routerconfig_finished']) && !$searchFilter['routerconfig_finished']) { + $searchFilter['add-where'] = "`Order`.create > " . (time() - 365 * 86400) . " OR `Order`.edit > " . (time() - 365 * 86400); + } + + $orders = OrderModel::search($searchFilter); // cpeprovisioning_enabled + // Use the same uncached precache from indexAction to get all potential products +// $prefetched = OrderProductModel::precache("`Terminationstatus`.`code` < " . TT_TERMSTATUS_CONNECTED . " AND `ProducttechAttribute`.`name` = 'bras_type'"); + $sqlWhere = "`ProducttechAttribute`.`name` = 'bras_type'"; + // if filter routerconfig_finished === 0 then we can filter the precache by routerconfig_finished = 0 or is null + if (isset($searchFilter['routerconfig_finished']) && !$searchFilter['routerconfig_finished']) { +// $sqlWhere .= " AND (`Cpeprovisioning`.`routerconfig_finished` = 0 OR `Cpeprovisioning`.`routerconfig_finished` IS NULL)"; + } + + $prefetched = OrderProductModel::precache($sqlWhere); + + $paginatedRows = []; + $totalRows = 0; + $orderInfoCache = []; // Cache for order-level info to avoid repeated calculations + + foreach ($orders as $order) { + // --- Apply the same initial filters as the old and new methods --- + if (($searchFilter["hide_delayed_finish"] ?? false) && $order->finish_after && $order->finish_after > strtotime('+31 days')) continue; + if (isset($prefetched['terminations'][$order->id][0]) && !$order->cpeprovisioning_enabled && $prefetched['terminations'][$order->id][0]['statuscode'] < TT_TERMSTATUS_CONNECTED) continue; + if (empty($prefetched[$order->id])) continue; + + // Loop through the prefetched raw data, similar to indexAction + foreach ($prefetched[$order->id] as $opData) { + // --- Apply the same product-level filters --- + if (!is_array($opData) || ($opData['routerconfig_finished'] xor ($searchFilter['routerconfig_finished'] ?? false)) || empty($opData['attributes']['bras_type'])) continue; + + // This item is a valid candidate for the list. + $totalRows++; + + // *** THE CORE PERFORMANCE IMPROVEMENT *** + // If the current item is not on the page we want, skip the expensive processing below. + if ($totalRows <= $start || $totalRows > $end) { + continue; + } + + // --- Now, do the expensive processing ONLY for the items on the current page --- + + // Calculate and cache order-level info only when it's first needed for a visible item + if (!isset($orderInfoCache[$order->id])) { + $orderInfo = ['vot' => false, 'hw' => [], 'voip' => false]; + foreach ($order->products as $prod) { + $attrs = $prod->product->attributes ?? []; + if (empty($attrs) || !is_array($attrs)) continue; + + if ($attrs['hw_only']->value ?? false) $orderInfo['hw'][] = (int)$prod->amount . "x " . $prod->product->name; + if ($attrs['addon']->value ?? false) $orderInfo['hw'][] = $prod->product->name; + if ($attrs['voip_chan']->value ?? false) $orderInfo['voip'] = true; + if ($attrs['vot']->value ?? false) $orderInfo['vot'] = true; + } + $orderInfoCache[$order->id] = $orderInfo; + } + $orderInfo = $orderInfoCache[$order->id]; + + // Hydrate the full model object, but only for this one item + $product = OrderProductModel::getOne($opData['id']); + $term = $product->termination; + $attrs = $product->product->attributes; + $cpe = $product->cpeprovisioning; + + $vlanPublicDefault = $term ? $term->getPop()->vlan_public : ($attrs['vlan_default_public']->value ?? null); + $vlanNatDefault = $term ? $term->getPop()->vlan_nat : ($attrs['vlan_default_nat']->value ?? null); + $vlanIpv6Default = $term ? $term->getPop()->vlan_ipv6 : ($attrs['vlan_default_ipv6']->value ?? null); + + /** @noinspection PhpElementIsNotAvailableInCurrentPhpVersionInspection */ + $paginatedRows[] = [ + 'id' => $product->id, 'order_id' => $product->order_id, 'termination_id' => $product->termination_id, 'orderproduct_id' => $product->id, + 'network' => $term->building->network->name ?? "{$order->owner->zip} {$order->owner->city}", + 'spin' => $order->owner->spin, 'customer' => $order->owner->getCompanyOrName(), + 'product_name' => $product->product->name, 'product_code' => $term->code ?? '', + 'access_type' => $attrs['bras_type']->value, + 'access_type_down' => $attrs["bw_down"]->value, + 'access_type_up' => $attrs["bw_up"]->value, + 'ont_deployed' => $term ? $term->getWorkflowValue("ont_deployed", "int") : 0, + 'ont_sn' => $term ? $term->getWorkflowValue("ont_sn", "string") : null, + 'vot' => $orderInfo['vot'] || $order->install_date, + 'hw' => !empty($orderInfo['hw']) ? implode("
    ", $orderInfo['hw']) : null, + 'voip' => $orderInfo['voip'], + 'note' => $order->note, + 'show_snopp_button' => ($attrs['hostnetwork_order']->value ?? 0) == 1 && !str_contains($product->product->name, 'XDSL'), + 'snopp_url' => 'https://snopp.breitband-steiermark.at/Termination/index?filter[status][]=connected&filter[address]=' . urlencode($order->owner->street), + 'vlans' => [ + 'public' => ['tag' => $cpe->vlan_public ?? $vlanPublicDefault, 'checked' => $product->cpeprovisioning->vlan_public], + 'nat' => ['tag' => $cpe->vlan_nat ?? $vlanNatDefault, 'checked' => $product->cpeprovisioning->vlan_nat], + 'ipv6' => ['tag' => $cpe->vlan_ipv6 ?? $vlanIpv6Default, 'checked' => $product->cpeprovisioning->vlan_ipv6], + ], + 'cpe_id' => $cpe->id ?? null, + 'cpe_data' => $this->fixCpeData($cpe->data ?? null), + ]; + } + } + + // Sort the final (small) array of results for the current page + if ($orderBy) { + usort($paginatedRows, fn($a, $b) => ($orderDir === 'asc' ? 1 : -1) * strnatcasecmp($a[$orderBy] ?? '', $b[$orderBy] ?? '')); + } + + // No need for array_slice, we already built the paginated list manually + self::returnJson([ + 'rows' => $paginatedRows, + 'pagination' => [ + 'page' => $page, 'per_page' => $perPage, 'total_rows' => $totalRows, + 'filtered_available' => $totalRows, 'total_pages' => ceil($totalRows / $perPage) + ] + ]); + } + + protected function newIndexAction() + { + $this->layout()->set('additionalJS', ['js/pages/Cpeprovisioning/Cpeprovisioning.js']); + $this->layout()->set('additionalHead', ['']); + + Helper::renderVue( + $this, + "Cpeprovisioning", // The root Vue component name + "CPE Provisioning", // The page title + [ + // Pass API URLs and initial data to the frontend + "CPE_PROV_API_GET_URL" => $this->getUrl("Cpeprovisioning", "apiGet"), + "CPE_PROV_API_SAVE_URL" => $this->getUrl("Cpeprovisioning", "apiSave"), + "ORDER_URL" => $this->getUrl("Order"), + "NETWORKS" => NetworkModel::getAll(), + "ROUTER_OPTIONS" => [ + // General Options + ['value' => 'eigener Router', 'text' => 'Eigener Router'], + ['value' => 'anderes CPE', 'text' => 'Anderes CPE'], + // PPPoE/DHCP Routers + ['value' => 'TP-Link Archer C80', 'text' => 'TP-Link Archer C80 (Inet, IPTV)'], + ['value' => 'FritzBox 4040', 'text' => 'FritzBox 4040 (Inet, IPTV)'], + ['value' => 'FritzBox 4050', 'text' => 'FritzBox 4050 (Inet, Phone IPTV)'], + ['value' => 'FritzBox 5530', 'text' => 'FritzBox 5530 (Inet FiberP2P, Phone, IPTV)'], + ['value' => 'FritzBox 7530', 'text' => 'FritzBox 7530 (Inet, Phone, IPTV)'], + ['value' => 'FritzBox 7590', 'text' => 'FritzBox 7590 (Inet, Phone, IPTV)'], + ['value' => 'FritzBox 7690', 'text' => 'FritzBox 7690 (Inet, Phone, IPTV)'], + // Static Routers + ['value' => 'Mikrotik HAP AC', 'text' => 'Mikrotik HAP AC (Inet, IPTV)'], + ['value' => 'Mikrotik HEX S', 'text' => 'Mikrotik HEX S (Inet, IPTV)'], + ['value' => 'Mikrotik RB3011', 'text' => 'Mikrotik RB3011 (Inet, IPTV)'], + // CMTS Routers + ['value' => 'FritzBox 6490 Cable', 'text' => 'FritzBox 6490 Cable (Inet, Phone, IPTV)'], + ] + ] + ); + } + + private function fixCpeData($data) { + if (!$data) return []; + $data->shipping = (bool)$data->shipping; + $data->routerconfig_finished = (bool)$data->routerconfig_finished; + return $data; + } + + +} \ No newline at end of file diff --git a/application/Order/OrderModel.php b/application/Order/OrderModel.php index f491dae57..caee15c8a 100644 --- a/application/Order/OrderModel.php +++ b/application/Order/OrderModel.php @@ -529,6 +529,13 @@ class OrderModel { } } + + if(array_key_exists("add-where", $filter)) { + $add_where = $filter['add-where']; + if($add_where) { + $where .= " AND ($add_where)"; + } + } //var_dump($filter, $where);exit; return $where; diff --git a/application/OrderProduct/OrderProductModel.php b/application/OrderProduct/OrderProductModel.php index 98c3759f5..e9ab464d6 100644 --- a/application/OrderProduct/OrderProductModel.php +++ b/application/OrderProduct/OrderProductModel.php @@ -141,7 +141,7 @@ class OrderProductModel return $items; } - public static function precache() + public static function precache($where = false): array { $items = []; $db = FronkDB::singleton(); @@ -162,7 +162,7 @@ class OrderProductModel "; //mfLoghandler::singleton()->debug($sql); - $res = $db->query($sql); + $res = $db->query($sql . ($where ? " WHERE $where" : "")); if ($db->num_rows($res)) { $oldProduct = ""; $oldOrder = ""; diff --git a/db/migrations/20250721222300_cpeprov_add_new_indexes.php b/db/migrations/20250721222300_cpeprov_add_new_indexes.php new file mode 100644 index 000000000..894fd5c05 --- /dev/null +++ b/db/migrations/20250721222300_cpeprov_add_new_indexes.php @@ -0,0 +1,52 @@ +getEnvironment() == 'thetool') { + $orderProduct = $this->table('OrderProduct'); + $orderProduct->addIndex('product_id', ['name' => 'idx_product_id']) + ->addIndex('termination_id', ['name' => 'idx_termination_id']) + ->save(); + + $product = $this->table('Product'); + $product->addIndex('producttech_id', ['name' => 'idx_producttech_id']) + ->save(); + + $productAttribute = $this->table('ProductAttribute'); + $productAttribute->addIndex('producttechattribute_id', ['name' => 'idx_producttechattribute_id']) + ->save(); + + $termination = $this->table('Termination'); + $termination->addIndex('status_id', ['name' => 'idx_status_id']) + ->save(); + } + } + + public function down(): void + { + if ($this->getEnvironment() == 'thetool') { + $orderProduct = $this->table('OrderProduct'); + $orderProduct->removeIndexByName('idx_product_id') + ->removeIndexByName('idx_termination_id') + ->save(); + + $product = $this->table('Product'); + $product->removeIndexByName('idx_producttech_id') + ->save(); + + $productAttribute = $this->table('ProductAttribute'); + $productAttribute->removeIndexByName('idx_producttechattribute_id') + ->save(); + + $termination = $this->table('Termination'); + $termination->removeIndexByName('idx_status_id') + ->save(); + } + } +} diff --git a/docker/php/Dockerfile b/docker/php/Dockerfile index 432a43e52..8561a7318 100644 --- a/docker/php/Dockerfile +++ b/docker/php/Dockerfile @@ -37,3 +37,14 @@ RUN echo "* * * * * /root/clean_old_logs.sh" > /etc/cron.d/clean_old_logs && \ # Start Apache in the foreground CMD ["apachectl", "-D", "FOREGROUND"] + + +# Install XDEBUG +# apt install -y php8.2-xdebug +# +# cat <<'EOF' > /etc/php/8.2/apache2/conf.d/99-xdebug-custom.ini + #[xdebug] + #xdebug.mode=profile + #xdebug.start_with_request=trigger + #xdebug.output_dir="/tmp/xdebug_profiles" + #EOF \ No newline at end of file diff --git a/docker/php/apache.conf b/docker/php/apache.conf index 29f0d6673..dd7e83203 100644 --- a/docker/php/apache.conf +++ b/docker/php/apache.conf @@ -6,4 +6,24 @@ AllowOverride All + + + # Enable compression + SetOutputFilter DEFLATE + + # Set compression level (1-9, 9 is highest) + DeflateCompressionLevel 6 + + # Add compression for specific MIME types + AddOutputFilterByType DEFLATE text/plain + AddOutputFilterByType DEFLATE text/html + AddOutputFilterByType DEFLATE text/xml + AddOutputFilterByType DEFLATE text/css + AddOutputFilterByType DEFLATE application/xml + AddOutputFilterByType DEFLATE application/xhtml+xml + AddOutputFilterByType DEFLATE application/rss+xml + AddOutputFilterByType DEFLATE application/javascript + AddOutputFilterByType DEFLATE application/json + AddOutputFilterByType DEFLATE image/svg+xml + diff --git a/public/js/pages/Cpeprovisioning/Cpeprovisioning.css b/public/js/pages/Cpeprovisioning/Cpeprovisioning.css new file mode 100644 index 000000000..83fad4933 --- /dev/null +++ b/public/js/pages/Cpeprovisioning/Cpeprovisioning.css @@ -0,0 +1,159 @@ +/* Cpeprovisioning.css */ + +.cpe-provisioning-page .filter-card { + margin-bottom: 1rem; +} + +.cpe-provisioning-page .filter-grid { + display: grid; + grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); + gap: 1rem; + align-items: end; +} + +.cpe-provisioning-page .filter-actions { + display: flex; + gap: 0.5rem; + padding-top: 1.5rem; /* Align with form labels */ +} + +.cpe-provisioning-page .cpe-details-grid { + display: grid; + grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); + gap: 1rem; + padding: 1rem; + background-color: #f8f9fa; + border-top: 1px solid #dee2e6; +} + +.cpe-provisioning-page .section-title { + grid-column: 1 / -1; + font-size: 1.1rem; + font-weight: 600; + color: #005384; + margin-top: 0.5rem; + margin-bottom: 0; + padding-bottom: 0.5rem; + border-bottom: 2px solid #f7c423; +} + +.cpe-provisioning-page .info-pills { + display: flex; + flex-wrap: wrap; + gap: 0.5rem; + padding: 0.5rem 0; +} + +.cpe-provisioning-page .info-pill { + background-color: #e9ecef; + color: #495057; + padding: 0.25rem 0.6rem; + border-radius: 1rem; + font-size: 0.8rem; + display: inline-flex; + align-items: center; + gap: 0.3rem; + white-space: nowrap; +} + +.cpe-provisioning-page .info-pill i { + color: #005384; +} + +/* Ensure form groups don't have excessive bottom margin in the grid */ +.cpe-provisioning-page .cpe-details-grid .form-group { + margin-bottom: 0; +} + +/* Save button alignment */ +.cpe-provisioning-page .save-button-container { + grid-column: 1 / -1; + display: flex; + justify-content: flex-end; + margin-top: 1rem; +} + +/* For tt-table expanded row content */ +.tt-table tbody tr[style*="display: table-row;"] > td { + background-color: #f8f9fa !important; + padding: 0; +} + +/* Change tracking */ +.cpe-provisioning-page .is-dirty { + background-color: #fff3cd; /* A light yellow to indicate changes */ + border-color: #ffeeba; +} + +.cpe-provisioning-page .form-group-condensed .col-form-label { + padding-bottom: 0; +} + +/* Responsive adjustments */ +@media (max-width: 768px) { + .cpe-provisioning-page .filter-grid, + .cpe-provisioning-page .cpe-details-grid { + grid-template-columns: 1fr; /* Stack on smaller screens */ + } + + .cpe-provisioning-page .filter-actions { + padding-top: 0; + flex-direction: column; + } + + .cpe-provisioning-page .filter-actions .btn { + width: 100%; + } +} + + +.vlans-container { + display: flex; + flex-wrap: wrap; + /*center items in the middle of the full width*/ + justify-content: center; + /*flex-direction: column;*/ + gap: 0.5rem; +} + +/* TODO: MOVE TT-CHIP TO OWN FILE */ +.tt-chip { + display: inline-flex; + align-items: center; + padding: 5px 12px; + border-radius: 16px; /* Pill shape */ + background-color: #f1f3f5; /* Light grey for unchecked state */ + border: 1px solid #dee2e6; + font-size: 0.875em; /* 14px if base is 16px */ + margin: 3px; + transition: background-color 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease; + cursor: default; + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; + max-width: 200px; +} + +.tt-chip.is-checked { + background-color: #e7f5ff; /* A pleasant light blue for the checked state */ + border-color: #a5d8ff; + color: #1c7ed6; + font-weight: 500; +} + +/* Add a subtle shadow on hover for interactivity */ +.tt-chip:hover { + box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1); +} + +/* Style elements passed into the slot for consistent spacing and alignment */ +.tt-chip > * + * { + margin-left: 8px; +} + +.tt-chip input[type="checkbox"] { + margin: 0; + width: 15px; + height: 15px; + cursor: pointer; +} diff --git a/public/js/pages/Cpeprovisioning/Cpeprovisioning.js b/public/js/pages/Cpeprovisioning/Cpeprovisioning.js new file mode 100644 index 000000000..e3b1aff1e --- /dev/null +++ b/public/js/pages/Cpeprovisioning/Cpeprovisioning.js @@ -0,0 +1,217 @@ +// Cpeprovisioning.js +Vue.component('tt-chip', { + props: { + checked: { type: Boolean, default: false } + }, + template: `
    ` +}); + +Vue.component('Cpeprovisioning', { + template: ` +
    + +
    +
    + + + + +
    + + +
    +
    +
    +
    + + + + + + + + + + + + + +
    + `, + data() { + return { + window, + filters: { + network_id: '', + routerconfig_finished: '0', + hide_delayed_finish: '1', + owner: '' + }, + statusOptions: [ + { value: '0', text: 'Offen' }, + { value: '1', text: 'Abgeschlossen' } + ], + delayOptions: [ + { value: '1', text: 'Nicht anzeigen' }, + { value: '0', text: 'Anzeigen' } + ], + tableConfig: { + key: 'cpeProvisioning', + tableHeader: 'CPE Provisioning', + expandCondition: () => true, + customRowClass: row => (row.isDirty ? 'is-dirty' : ''), + headers: [ + { key: 'customer', text: 'Kunde', sortable: false, filter: false, priority: 100 }, + { key: 'product', text: 'Produkt', sortable: false, filter: false, priority: 90 }, + { key: 'vlans', text: 'VLANs', sortable: false, filter: false, priority: 80 }, + ] + } + } + }, + computed: { + networkOptions() { + const networks = window.TT_CONFIG.NETWORKS || []; + return [{ value: '', text: 'Alle Gebiete' }, ...networks.map(net => ({ value: net.id, text: net.name }))]; + }, + routerOptions() { + return window.TT_CONFIG.ROUTER_OPTIONS || []; + } + }, + methods: { + applyFilters(fetch = true) { + const table = this.$refs.cpeTable; + if (table) { + table.filters = JSON.parse(JSON.stringify(this.filters)); + if (fetch) table.fetchData(1); + } + }, + resetFilters() { + this.filters = { + network_id: '', + routerconfig_finished: '0', + hide_delayed_finish: '1', + owner: '' + }; + this.applyFilters(); + }, + markDirty(row, field) { + console.log(`Marking row as dirty for field ${field}`); + this.$set(row, 'isDirty', true); + }, + async saveCpe(row) { + this.$set(row, 'isSaving', true); + + const payload = { + id: row.cpe_id, + order_id: row.order_id, + orderproduct_id: row.orderproduct_id, + termination_id: row.termination_id, + ont_sn: row.ont_sn, + vlans: row.vlans, + ...row.cpe_data, + shipping: row.cpe_data.shipping ? 1 : 0, + routerconfig_finished: row.cpe_data.routerconfig_finished ? 1 : 0, + }; + + try { + const { data } = await axios.post(this.window.TT_CONFIG.CPE_PROV_API_SAVE_URL, payload); + if (data.success) { + this.window.notify('success', data.message); + this.$set(row, 'isDirty', false); + this.$refs.cpeTable.refreshTable(); + } else { + this.window.notify('error', data.message || 'Fehler beim Speichern.'); + } + } catch (error) { + this.window.notify('error', 'Ein unerwarteter Fehler ist aufgetreten.'); + } finally { + this.$set(row, 'isSaving', false); + } + } + }, + mounted() { + this.applyFilters(false); + } +}); \ No newline at end of file diff --git a/public/plugins/bookstack/bookstackIntegration.js b/public/plugins/bookstack/bookstackIntegration.js index 23abfdde0..59523a5bb 100644 --- a/public/plugins/bookstack/bookstackIntegration.js +++ b/public/plugins/bookstack/bookstackIntegration.js @@ -1,50 +1,51 @@ document.addEventListener('DOMContentLoaded', async () => { - const articleTag = (() => { - const path = window.location.pathname; - const segments = path.split('/').filter(Boolean); - return segments.length > 0 ? segments[0] : 'DefaultTag'; - })(); + const linkEl = document.getElementById('bookstackLink'); + if (!linkEl) return; + const articleTag = window.location.pathname.split('/').filter(Boolean)[0] || 'DefaultTag'; + const cacheKey = `bookstack_article_${articleTag}`; - const apiUrl = `https://bookstack.xinon.at/api/search?query=%5Bshowurl%3D${encodeURIComponent(articleTag)}%5D%7Btype%3Apage%7D`; - const linkElement = document.getElementById('bookstackLink'); + const setupLinkAction = url => { + linkEl.style.display = 'block'; + linkEl.querySelector('a').onclick = e => { + e.preventDefault(); + const modal = document.createElement('div'); + modal.className = 'bookstack-integration-modal'; + modal.innerHTML = `
    `; + modal.onclick = ev => { + if (ev.target === modal || ev.target.classList.contains('bookstack-integration-close-btn')) { + modal.remove(); + } + }; + document.body.appendChild(modal); + }; + }; + + document.addEventListener('keydown', e => { + if (e.ctrlKey && e.key === 'F8') { + e.preventDefault(); + localStorage.removeItem(cacheKey); + window.notify('success', `📗 BookStack cache für '${articleTag}' wurde gelöscht.`); + } + }); try { - const response = await fetch(apiUrl, { - headers: { - 'Authorization': 'Token XmGSDWlg3bZhHKXFchNXQ9LpXvCaBuM1:k6XNe6RUU1BIxkv5pxpZ9PSErqZbHJ4i' - } + const cachedItem = JSON.parse(localStorage.getItem(cacheKey) || 'null'); + if (cachedItem && (Date.now() - cachedItem.timestamp < (cachedItem.url ? 604800000 : 259200000))) { + if (cachedItem.url) setupLinkAction(cachedItem.url); + return; + } + + const response = await fetch(`https://bookstack.xinon.at/api/search?query=%5Bshowurl%3D${encodeURIComponent(articleTag)}%5D%7Btype%3Apage%7D`, { + headers: { 'Authorization': 'Token XmGSDWlg3bZhHKXFchNXQ9LpXvCaBuM1:k6XNe6RUU1BIxkv5pxpZ9PSErqZbHJ4i' } }); const data = await response.json(); + const articleUrl = data.data?.[0]?.url || null; - if (data.data && data.data.length > 0) { - const article = data.data[0]; - linkElement.style.display = 'block'; - linkElement.querySelector('a').addEventListener('click', (e) => { - e.preventDefault(); - showArticleModal(article.url); - }); - } + localStorage.setItem(cacheKey, JSON.stringify({ url: articleUrl, timestamp: Date.now() })); + articleUrl ? setupLinkAction(articleUrl) : (linkEl.style.display = 'none'); } catch (error) { console.error('BookStack API error:', error); - linkElement.style.display = 'none'; + linkEl.style.display = 'none'; } - - function showArticleModal(url) { - const modal = document.createElement('div'); - modal.className = 'bookstack-integration-modal'; - modal.innerHTML = ` -
    - - -
    - `; - - modal.querySelector('.bookstack-integration-close-btn').addEventListener('click', () => modal.remove()); - modal.addEventListener('click', (e) => { - if (e.target === modal) modal.remove(); - }); - - document.body.appendChild(modal); - } -}); +}); \ No newline at end of file diff --git a/public/plugins/bookstack/bookstackIntegration.min.js b/public/plugins/bookstack/bookstackIntegration.min.js new file mode 100644 index 000000000..97df3ee40 --- /dev/null +++ b/public/plugins/bookstack/bookstackIntegration.min.js @@ -0,0 +1 @@ +document.addEventListener("DOMContentLoaded",(async()=>{const t=document.getElementById("bookstackLink");if(!t)return;const e=window.location.pathname.split("/").filter(Boolean)[0]||"DefaultTag",o=`bookstack_article_${e}`,a=e=>{t.style.display="block",t.querySelector("a").onclick=t=>{t.preventDefault();const o=document.createElement("div");o.className="bookstack-integration-modal",o.innerHTML=`
    `,o.onclick=t=>{(t.target===o||t.target.classList.contains("bookstack-integration-close-btn"))&&o.remove()},document.body.appendChild(o)}};document.addEventListener("keydown",(t=>{t.ctrlKey&&"F8"===t.key&&(t.preventDefault(),localStorage.removeItem(o),window.notify("success",`📗 BookStack cache für '${e}' wurde gelöscht.`))}));try{const n=JSON.parse(localStorage.getItem(o)||"null");if(n&&Date.now()-n.timestamp<(n.url?6048e5:2592e5))return void(n.url&&a(n.url));const c=await fetch(`https://bookstack.xinon.at/api/search?query=%5Bshowurl%3D${encodeURIComponent(e)}%5D%7Btype%3Apage%7D`,{headers:{Authorization:"Token XmGSDWlg3bZhHKXFchNXQ9LpXvCaBuM1:k6XNe6RUU1BIxkv5pxpZ9PSErqZbHJ4i"}}),r=await c.json(),s=r.data?.[0]?.url||null;localStorage.setItem(o,JSON.stringify({url:s,timestamp:Date.now()})),s?a(s):t.style.display="none"}catch(e){console.error("BookStack API error:",e),t.style.display="none"}})); \ No newline at end of file diff --git a/public/plugins/vue/tt-components/css/tt-tooltip.css b/public/plugins/vue/tt-components/css/tt-tooltip.css index f33131e51..f180459ec 100644 --- a/public/plugins/vue/tt-components/css/tt-tooltip.css +++ b/public/plugins/vue/tt-components/css/tt-tooltip.css @@ -18,7 +18,7 @@ text-align: center; /* Center text */ } -/* Make tooltip visible when showTooltip is true */ +/* Make tooltip visible on hover */ .tt-tooltip-wrapper:hover .tt-tooltip-box { opacity: 1; } @@ -89,7 +89,8 @@ border-color: transparent #333 transparent transparent; } +/* The problematic 'width: 100% !important;' has been removed from the selector below. +*/ .tt-tooltip-wrapper > * { display: inline-block; /* Ensure the tooltip wrapper behaves correctly */ - width: 100% !important; } \ No newline at end of file diff --git a/public/plugins/vue/tt-components/tt-checkbox.js b/public/plugins/vue/tt-components/tt-checkbox.js index 40f501de1..f76a45476 100644 --- a/public/plugins/vue/tt-components/tt-checkbox.js +++ b/public/plugins/vue/tt-components/tt-checkbox.js @@ -18,9 +18,6 @@ Vue.component('tt-checkbox', { this.checkedValue = val; } }, - mounted() { - this.$emit('input', this.checkedValue); - }, template: `
    From e2a8d67eee4ab839804fbede75f6e4d52a99bbaa Mon Sep 17 00:00:00 2001 From: Luca Haid Date: Tue, 22 Jul 2025 09:02:32 +0200 Subject: [PATCH 14/24] improved logging --- .../ConstructionConsentController.php | 21 ++++++++++++++++++- .../ConstructionConsentOwnerController.php | 9 ++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/application/ConstructionConsent/ConstructionConsentController.php b/application/ConstructionConsent/ConstructionConsentController.php index 5e7394113..ac2f4a312 100644 --- a/application/ConstructionConsent/ConstructionConsentController.php +++ b/application/ConstructionConsent/ConstructionConsentController.php @@ -1112,6 +1112,22 @@ class ConstructionConsentController extends mfBaseController { $projectId = $this->request->project_id; $importData = json_decode(file_get_contents('php://input'), true); + // save full post request and project id to file as log with metadata like user id etc as json file +// MFUPLOAD_FILE_SAVE_PATH . /ConstructionConsentImports + + $logData = [ + "user_id" => $this->me->id, + "project_id" => $projectId, + "import_data" => $importData, + "timestamp" => date("Y-m-d H:i:s") + ]; + $logFileName = MFUPLOAD_FILE_SAVE_PATH . "/ConstructionConsentImports/import_" . date("Ymd_His") . "_user_{$this->me->id}_project_{$projectId}.json"; + if (!file_exists(dirname($logFileName))) { + mkdir(dirname($logFileName), 0777, true); + } + file_put_contents($logFileName, json_encode($logData, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE)); + + if (empty($importData) || !is_array($importData)) { $this->layout()->setFlash("Keine Daten gefunden", "error"); return $this->redirect("ConstructionConsent"); } if (!is_numeric($projectId) || $projectId < 1) { $this->layout()->setFlash("Projekt nicht gefunden", "error"); return $this->redirect("ConstructionConsent"); } if (!($consentProject = new ConstructionConsentProject($projectId))->id) { $this->layout()->setFlash("Projekt nicht gefunden", "error"); return $this->redirect("ConstructionConsent"); } @@ -1178,7 +1194,10 @@ class ConstructionConsentController extends mfBaseController { $journal = ConstructionConsentJournal::create([ "constructionconsent_id" => $consentRecord->id, - "text" => "Import: Eigentümer $firstname $lastname wurde hinzugefügt" + "text" => + $ownerRecord->company ? + "Import: Eigentümer $ownerRecord->company wurde hinzugefügt" : + "Import: Eigentümer $firstname $lastname wurde hinzugefügt" ]); $journal->save(); diff --git a/application/ConstructionConsentOwner/ConstructionConsentOwnerController.php b/application/ConstructionConsentOwner/ConstructionConsentOwnerController.php index 4b4d4713f..e8a59c51c 100644 --- a/application/ConstructionConsentOwner/ConstructionConsentOwnerController.php +++ b/application/ConstructionConsentOwner/ConstructionConsentOwnerController.php @@ -156,6 +156,15 @@ class ConstructionConsentOwnerController extends mfBaseController $file->delete(); } + $journal = ConstructionConsentJournal::create([ + "constructionconsent_id" => $consent->id, + "text" => + $owner->company ? + "Eigentümer $owner->company wurde gelöscht" : + "Eigentümer $owner->firstname $owner->lastname wurde gelöscht" + ]); + $journal->save(); + $owner->delete(); $this->layout()->setFlash("Besitzer gelöscht!", "success"); From e8be372560dfcf00ef1e727d89c9f42402468539 Mon Sep 17 00:00:00 2001 From: Luca Haid Date: Tue, 22 Jul 2025 10:38:42 +0200 Subject: [PATCH 15/24] improved cpev2 --- Layout/default/Cpeprovisioning/PDF_MAIN.php | 45 +++++++++++++++++++ .../CpeprovisioningController.php | 37 +++++++++++++-- .../pages/Cpeprovisioning/Cpeprovisioning.js | 23 +++++++++- 3 files changed, 101 insertions(+), 4 deletions(-) create mode 100644 Layout/default/Cpeprovisioning/PDF_MAIN.php diff --git a/Layout/default/Cpeprovisioning/PDF_MAIN.php b/Layout/default/Cpeprovisioning/PDF_MAIN.php new file mode 100644 index 000000000..edad91437 --- /dev/null +++ b/Layout/default/Cpeprovisioning/PDF_MAIN.php @@ -0,0 +1,45 @@ +setReturnValue(['filename' => "xyz." . time() . "pdf"]); +?> + + + + CPE-Etikett + + + + +
    +
    +
    +
    +
    +
    + + \ No newline at end of file diff --git a/application/Cpeprovisioning/CpeprovisioningController.php b/application/Cpeprovisioning/CpeprovisioningController.php index 682bbb35c..a64f6a42c 100644 --- a/application/Cpeprovisioning/CpeprovisioningController.php +++ b/application/Cpeprovisioning/CpeprovisioningController.php @@ -482,9 +482,9 @@ class CpeprovisioningController extends mfBaseController 'show_snopp_button' => ($attrs['hostnetwork_order']->value ?? 0) == 1 && !str_contains($product->product->name, 'XDSL'), 'snopp_url' => 'https://snopp.breitband-steiermark.at/Termination/index?filter[status][]=connected&filter[address]=' . urlencode($order->owner->street), 'vlans' => [ - 'public' => ['tag' => $cpe->vlan_public ?? $vlanPublicDefault, 'checked' => $product->cpeprovisioning->vlan_public], - 'nat' => ['tag' => $cpe->vlan_nat ?? $vlanNatDefault, 'checked' => $product->cpeprovisioning->vlan_nat], - 'ipv6' => ['tag' => $cpe->vlan_ipv6 ?? $vlanIpv6Default, 'checked' => $product->cpeprovisioning->vlan_ipv6], + 'public' => ['tag' => ($cpe ? $cpe->vlan_public : null) ?? $vlanPublicDefault, 'checked' => ($cpe ? $cpe->vlan_public : null)], + 'nat' => ['tag' => ($cpe ? $cpe->vlan_nat : null) ?? $vlanNatDefault, 'checked' => ($cpe ? $cpe->vlan_nat : null)], + 'ipv6' => ['tag' => ($cpe ? $cpe->vlan_ipv6 : null) ?? $vlanIpv6Default, 'checked' => ($cpe ? $cpe->vlan_ipv6 : null)], ], 'cpe_id' => $cpe->id ?? null, 'cpe_data' => $this->fixCpeData($cpe->data ?? null), @@ -520,6 +520,7 @@ class CpeprovisioningController extends mfBaseController // Pass API URLs and initial data to the frontend "CPE_PROV_API_GET_URL" => $this->getUrl("Cpeprovisioning", "apiGet"), "CPE_PROV_API_SAVE_URL" => $this->getUrl("Cpeprovisioning", "apiSave"), + "CPE_PROV_PRINT_PDF_URL" => $this->getUrl("Cpeprovisioning", "printPDF"), "ORDER_URL" => $this->getUrl("Order"), "NETWORKS" => NetworkModel::getAll(), "ROUTER_OPTIONS" => [ @@ -540,6 +541,13 @@ class CpeprovisioningController extends mfBaseController ['value' => 'Mikrotik RB3011', 'text' => 'Mikrotik RB3011 (Inet, IPTV)'], // CMTS Routers ['value' => 'FritzBox 6490 Cable', 'text' => 'FritzBox 6490 Cable (Inet, Phone, IPTV)'], + ], + "ROUTER_SHIPPING_DATA" => [ + "TP-Link Archer C80" => ["weight" => 1, "length" => 35, "width" => 24, "height" => 8], + "FritzBox 4040" => ["weight" => 1, "length" => 30, "width" => 24, "height" => 7], + "FritzBox 7530" => ["weight" => 1, "length" => 26, "width" => 19, "height" => 7], + "FritzBox 7590" => ["weight" => 1, "length" => 30, "width" => 24, "height" => 7], + "FritzBox 6490 Cable" => ["weight" => 1, "length" => 30, "width" => 26, "height" => 8] ] ] ); @@ -552,5 +560,28 @@ class CpeprovisioningController extends mfBaseController return $data; } + protected function printPDFAction() { + $order_id = $this->request->order_id; + + $order = OrderModel::getOne($order_id); + if (!$order) self::sendError("Order not found", 404); + + $pdf_vars = [ + 'firstline' => $order->owner->getCompanyOrName(), + 'secondline' => $order->owner->street, + 'thirdline' => $order->owner->zip . " " . $order->owner->city, + 'fourthline' => $order->owner->customer_number + ]; + + $pdf = new PdfForm("Cpeprovisioning/PDF_MAIN", $pdf_vars); + $wkhtmltopdfArgs = "--page-height 32.5mm --page-width 57.5mm --margin-top 1mm --margin-bottom 0 --margin-left 0 --margin-right 0 --disable-smart-shrinking --encoding utf-8"; + $filename = $pdf->render($wkhtmltopdfArgs); + + header('Content-Type: application/pdf'); + header('Content-Disposition: inline; filename="' . $filename . '"'); + readfile($filename); + die(); + } + } \ No newline at end of file diff --git a/public/js/pages/Cpeprovisioning/Cpeprovisioning.js b/public/js/pages/Cpeprovisioning/Cpeprovisioning.js index e3b1aff1e..47c17c0dc 100644 --- a/public/js/pages/Cpeprovisioning/Cpeprovisioning.js +++ b/public/js/pages/Cpeprovisioning/Cpeprovisioning.js @@ -51,6 +51,9 @@ Vue.component('Cpeprovisioning', { + + +