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 @@
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/>
+
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
-
+
-
- {{ row.calculatedSellPrice.toFixed(2) }} €
- {{
- Array.isArray(JSON.parse(row.cheapestSellPrice)) ? JSON.parse(row.cheapestSellPrice).find(price => price.title === 'Energie Steiermark').price.toFixed(2) :
- Object.values(JSON.parse(row.cheapestSellPrice)).find(price => price.title === 'Energie Steiermark').price.toFixed(2) }} €
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
- `, data() {
+
+ {{ row.calculatedSellPrice.toFixed(2) }} €
+
+ {{ getArticlePrice(row).toFixed(2) }} €
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ `, 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: `
-
+
-
+
-
-
-
-
- | Artikel |
- Menge |
- Aktionen |
-
-
-
-
- | Keine Einträge |
-
-
- | {{ position.articleId ? articleNames[position.articleId] : position.articlePacketId ? articlePacketNames[position.articlePacketId] :
- 'Loading...' }}
- |
- {{ position.quantity }} |
-
-
-
- |
-
-
-
-
+
+
+
+
+ | Artikel |
+ Menge |
+ Aktionen |
+
+
+
+
+ | 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: `
-
-
+
+
-
-
-
+
+
+
-
- {{ row.deliveryAddressName }} {{ row.deliveryAddressAdditional ? '(' + row.deliveryAddressAdditional + ')' : '' }}
-
+
+ {{ row.deliveryAddressName }} {{ row.deliveryAddressAdditional ? '(' + row.deliveryAddressAdditional + ')' : '' }}
+
-
- {{ window.moment(row.create * 1000).format('DD.MM.YYYY HH:mm:ss') }}
-
+
+ {{ window.moment(row.create * 1000).format('DD.MM.YYYY HH:mm:ss') }}
+
-
-
-
- -
- Menge: {{ item.quantity }} | {{ item.articlePacketTitle || item.articleTitle }}
-
-
-
-
+
+ Energie Steiermark
+ SBIDI
+ Unbekannt
+
-
-
-
-
-
+
+
+
+ -
+ Menge: {{ item.quantity }} | {{ item.articlePacketTitle || item.articleTitle }}
+
+
+
+
-
-
+
+
+
+
+
-
-
-
-
-
-
-
-
+
+
-
-
-
- -
- {{ entry.date }} {{ entry.time }} - {{ entry.evtDscr }}
-
-
-
+
+
+
+
+
+
+
+
-
+
+
+
+ -
+ {{ entry.date }} {{ entry.time }} - {{ entry.evtDscr }}
+
+
+
+
+
-
- `, data() {
+
+ `, data() {
return {
window: window,
historyModal: false,