WarehouseOffer fixed bugs
This commit is contained in:
@@ -162,7 +162,7 @@
|
||||
<li class="has-submenu">
|
||||
<a href="#">
|
||||
<?php if ($me->can("WarehouseEShop") && !($me->can("WarehouseAdmin") || $me->can("WarehouseUser"))): ?>
|
||||
<i class="fas fa-fw fa-shopping-cart"></i>E-Shop<div class="arrow-down"></div>
|
||||
<i class="fas fa-fw fa-shopping-cart"></i><?= $me->address_id == 9633 ? "SBIDI Shop" : "E-Shop" ?><div class="arrow-down"></div>
|
||||
<?php elseif ($me->can("WarehouseAdmin") || $me->can("WarehouseUser")): ?>
|
||||
<i class="fas fa-fw fa-warehouse"></i>Lager<div class="arrow-down"></div>
|
||||
<?php endif; ?>
|
||||
@@ -179,9 +179,11 @@
|
||||
|
||||
<?php if($me->can("WarehouseAdmin")): ?><li><a href="<?=self::getUrl("WarehouseDistributor")?>"><i class="far fa-fw fa-cogs text-info"></i> Administration</a></li><?php endif; ?>
|
||||
|
||||
<?php if($me->can("WarehouseAdmin") || $me->can("WarehouseEShop")): ?><li class="has-sub-submenu font-weight-bold"><a>E-Stmk Shop</a></li><?php endif; ?>
|
||||
<?php if($me->can("WarehouseEShop")): ?><li><a href="<?=self::getUrl("WarehouseEShop")?>"><i class="far fa-fw fa-shopping-cart text-info"></i> E-Shop</a></li><?php endif; ?>
|
||||
<?php if($me->can("WarehouseAdmin")): ?><li><a href="<?=self::getUrl("WarehouseEShopOrder")?>"><i class="far fa-fw fa-shopping-basket text-info"></i> E-Shop Bestellungen</a></li><?php endif; ?>
|
||||
<?php if($me->can("WarehouseAdmin") || $me->can("WarehouseEShop")): ?><li class="has-sub-submenu font-weight-bold"><a> <?= $me->address_id == 9633 ? "SBIDI Shop" : "E-Shop" ?></a></li><?php endif; ?>
|
||||
<?php if($me->can("WarehouseEShop") && !$me->isAdmin()): ?><li><a href="<?=self::getUrl("WarehouseEShop")?>"><i class="far fa-fw fa-shopping-cart text-info"></i> <?=$me->address_id == 9633 ? "SBIDI Shop" : "E-Shop" ?></a></li><?php endif; ?>
|
||||
<?php if($me->can("WarehouseEShop") && $me->isAdmin()): ?><li><a href="<?=self::getUrl("WarehouseEShop")?>?shop=e"><i class="far fa-fw fa-box text-info"></i> E-Shop</a></li><?php endif; ?>
|
||||
<?php if($me->can("WarehouseEShop") && $me->isAdmin()): ?><li><a href="<?=self::getUrl("WarehouseEShop")?>?shop=sbidi"><i class="far fa-fw fa-box text-info"></i> SBIDI-Shop</a></li><?php endif; ?>
|
||||
<?php if($me->can("WarehouseAdmin")): ?><li><a href="<?=self::getUrl("WarehouseEShopOrder")?>"><i class="far fa-fw fa-shopping-basket text-info"></i> E/SBIDI-Shop Bestellungen</a></li><?php endif; ?>
|
||||
<?php if($me->can("WarehouseAdmin")): ?><li><a href="<?=self::getUrl("WarehouseArticlePacket")?>"><i class="far fa-fw fa-box text-info"></i> Artikel-Pakete</a></li><?php endif; ?>
|
||||
</ul>
|
||||
</li>
|
||||
|
||||
@@ -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]]
|
||||
];
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @property mixed|null $name
|
||||
*/
|
||||
class WarehouseArticlePacket extends mfBaseModel
|
||||
{
|
||||
|
||||
}
|
||||
@@ -13,20 +13,25 @@ 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' => '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;
|
||||
|
||||
@@ -9,4 +9,8 @@ class WarehouseArticlePacketModel extends TTCrudBaseModel {
|
||||
public ?float $overrideSellPrice;
|
||||
public ?float $calculatedSellPrice;
|
||||
public string $subItems;
|
||||
}
|
||||
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
|
||||
}
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @property mixed|null $name
|
||||
*/
|
||||
class WarehouseEShop extends mfBaseModel
|
||||
{
|
||||
|
||||
}
|
||||
@@ -1,13 +1,9 @@
|
||||
<?php
|
||||
// Warrenkorb löschen
|
||||
// File Upload ermöglichen
|
||||
// Hide Articles
|
||||
|
||||
|
||||
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],
|
||||
@@ -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
|
||||
]
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @property mixed|null $name
|
||||
*/
|
||||
class WarehouseEShopOrder extends mfBaseModel
|
||||
{
|
||||
|
||||
}
|
||||
@@ -8,6 +8,7 @@ class WarehouseEShopOrderController extends TTCrud {
|
||||
protected array $columns = [
|
||||
['key' => '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";
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
public ?int $addressId; // New field to store the address_id of the ordering entity
|
||||
}
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @property mixed|null $name
|
||||
*/
|
||||
class WarehouseEShopOrderItem extends mfBaseModel
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
|
||||
final class ShopAndOrderAddressEnhancements extends AbstractMigration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
if ($this->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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
})
|
||||
|
||||
@@ -1,53 +1,53 @@
|
||||
Vue.component('warehouse-e-shop', {
|
||||
//language=Vue
|
||||
template: `
|
||||
<tt-card>
|
||||
<tt-expandable-shopping-cart :cart-items="shoppingCart" @submitOrder="openOrderDialog"/>
|
||||
<tt-card>
|
||||
<tt-expandable-shopping-cart :cart-items="shoppingCart" @submitOrder="openOrderDialog"/>
|
||||
|
||||
<tt-modal :show.sync="createOrderDialog"
|
||||
:delete="false"
|
||||
title="Bestellung abschicken"
|
||||
@submit="submitOrder">
|
||||
|
||||
<tt-select v-model="createOrderDialogData.deliveryMode" label="Adresse" :options="[
|
||||
<tt-modal :show.sync="createOrderDialog"
|
||||
:delete="false"
|
||||
title="Bestellung abschicken"
|
||||
@submit="submitOrder">
|
||||
|
||||
<tt-select v-model="createOrderDialogData.deliveryMode" label="Adresse" :options="[
|
||||
{text: 'Einzelne Adresse', value: 'singleAddress'},
|
||||
// {text: 'Mehrere Adressen', value: 'multipleAddresses'},
|
||||
]" sm row/>
|
||||
<tt-input v-model="createOrderDialogData.extRef" label="Externe Referenz" sm row/>
|
||||
]" sm row/>
|
||||
<tt-input v-model="createOrderDialogData.extRef" label="Externe Referenz" sm row/>
|
||||
|
||||
<tt-input v-model="createOrderDialogData.deliveryAddressName" label="Name" sm row/>
|
||||
<tt-input v-model="createOrderDialogData.deliveryAddressMail" label="E-Mail" sm row/>
|
||||
<tt-input v-model="createOrderDialogData.deliveryAddressPhone" label="Nummer" sm row/>
|
||||
<tt-input v-model="createOrderDialogData.deliveryAddressAdditional" label="Anschriftenzusatz" sm row/>
|
||||
<tt-input v-model="createOrderDialogData.deliveryAddressLine" label="Straße" sm row/>
|
||||
<tt-input v-model="createOrderDialogData.deliveryAddressPLZ" label="PLZ" sm row/>
|
||||
<tt-input v-model="createOrderDialogData.deliveryAddressCity" label="Stadt" sm row/>
|
||||
|
||||
</tt-modal>
|
||||
<tt-input v-model="createOrderDialogData.deliveryAddressName" label="Name" sm row/>
|
||||
<tt-input v-model="createOrderDialogData.deliveryAddressMail" label="E-Mail" sm row/>
|
||||
<tt-input v-model="createOrderDialogData.deliveryAddressPhone" label="Nummer" sm row/>
|
||||
<tt-input v-model="createOrderDialogData.deliveryAddressAdditional" label="Anschriftenzusatz" sm row/>
|
||||
<tt-input v-model="createOrderDialogData.deliveryAddressLine" label="Straße" sm row/>
|
||||
<tt-input v-model="createOrderDialogData.deliveryAddressPLZ" label="PLZ" sm row/>
|
||||
<tt-input v-model="createOrderDialogData.deliveryAddressCity" label="Stadt" sm row/>
|
||||
|
||||
<tt-table-crud>
|
||||
</tt-modal>
|
||||
|
||||
<template v-slot:price="{ row }">
|
||||
<span v-if="row.hasOwnProperty('calculatedSellPrice')"> {{ row.calculatedSellPrice.toFixed(2) }} €</span>
|
||||
<span v-else>{{
|
||||
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) }} €</span>
|
||||
</template>
|
||||
<tt-table-crud>
|
||||
|
||||
<template v-slot:amount="{ row }">
|
||||
<!-- this has no padding - add a full width full height tt-input with -->
|
||||
<tt-input type="number" style="width: 100%; height: 100%;margin:0 !important" v-model="itemAmounts[row.hasOwnProperty('calculatedSellPrice') ? 'P-' + row.id : 'I-' + row.id]" sm/>
|
||||
</template>
|
||||
|
||||
<template v-slot:add="{ row }">
|
||||
<a style="cursor: pointer;" @click="addToCart(row, row.hasOwnProperty('calculatedSellPrice') ? 'P' : 'I')">
|
||||
<i class="fas fa-shopping-cart text-primary"></i>
|
||||
</a>
|
||||
</template>
|
||||
|
||||
</tt-table-crud>
|
||||
</tt-card>
|
||||
`, data() {
|
||||
<template v-slot:price="{ row }">
|
||||
<span v-if="row.hasOwnProperty('calculatedSellPrice')"> {{ row.calculatedSellPrice.toFixed(2) }} €</span>
|
||||
<span v-else>
|
||||
{{ getArticlePrice(row).toFixed(2) }} €
|
||||
</span>
|
||||
</template>
|
||||
|
||||
<template v-slot:amount="{ row }">
|
||||
<!-- this has no padding - add a full width full height tt-input with -->
|
||||
<tt-input type="number" style="width: 100%; height: 100%;margin:0 !important" v-model="itemAmounts[row.hasOwnProperty('calculatedSellPrice') ? 'P-' + row.id : 'I-' + row.id]" sm/>
|
||||
</template>
|
||||
|
||||
<template v-slot:add="{ row }">
|
||||
<a style="cursor: pointer;" @click="addToCart(row, row.hasOwnProperty('calculatedSellPrice') ? 'P' : 'I')">
|
||||
<i class="fas fa-shopping-cart text-primary"></i>
|
||||
</a>
|
||||
</template>
|
||||
|
||||
</tt-table-crud>
|
||||
</tt-card>
|
||||
`, 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: '',
|
||||
|
||||
@@ -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: `
|
||||
<div>
|
||||
<div>
|
||||
|
||||
<div style="display: grid;grid-template-columns: 2fr 1fr 0.5fr 1fr;grid-gap: 10px;">
|
||||
<tt-autocomplete v-model="articleId" :api-url="articleAPIUrl" label="Artikel" sm ref="article"/>
|
||||
<tt-autocomplete v-model="articlePacketId" :api-url="articlePacketAPIUrl" label="Artikel Packet" sm/>
|
||||
<tt-input v-model="amount" label="Menge" sm/>
|
||||
<div style="display: flex;flex-direction: column;justify-content: center;padding-top: 13px;">
|
||||
<button @click="addPosition" class="btn btn-primary">Hinzufügen</button>
|
||||
</div>
|
||||
</div>
|
||||
<div style="display: grid;grid-template-columns: 2fr 1fr 0.5fr 1fr;grid-gap: 10px;">
|
||||
<tt-autocomplete v-model="articleId" :api-url="articleAPIUrl" label="Artikel" sm ref="article"/>
|
||||
<tt-autocomplete v-model="articlePacketId" :api-url="articlePacketAPIUrl" label="Artikel Packet" sm/>
|
||||
<tt-input v-model="amount" label="Menge" sm/>
|
||||
<div style="display: flex;flex-direction: column;justify-content: center;padding-top: 13px;">
|
||||
<button @click="addPosition" class="btn btn-primary">Hinzufügen</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div style="display: flex; align-items: center; justify-content: center;">
|
||||
<table class="table table-striped table-sm" style="width: max-content">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Artikel</th>
|
||||
<th>Menge</th>
|
||||
<th>Aktionen</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-if="positions.length === 0">
|
||||
<td colspan="4" class="text-center">Keine Einträge</td>
|
||||
</tr>
|
||||
<tr v-for="(position, index) in positions" :key="index">
|
||||
<td>{{ position.articleId ? articleNames[position.articleId] : position.articlePacketId ? articlePacketNames[position.articlePacketId] :
|
||||
'Loading...' }}
|
||||
</td>
|
||||
<td>{{ position.quantity }}</td>
|
||||
<td>
|
||||
<button class="btn btn-sm btn-danger" @click="deletePosition(position.id)">Löschen</button>
|
||||
<button class="btn btn-sm btn-primary" @click="editPosition(position.id)">Bearbeiten</button>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div style="display: flex; align-items: center; justify-content: center;">
|
||||
<table class="table table-striped table-sm" style="width: max-content">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Artikel</th>
|
||||
<th>Menge</th>
|
||||
<th>Aktionen</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-if="positions.length === 0">
|
||||
<td colspan="4" class="text-center">Keine Einträge</td>
|
||||
</tr>
|
||||
<tr v-for="(position, index) in positions" :key="index">
|
||||
<td>{{ position.articleId ? articleNames[position.articleId] : position.articlePacketId ? articlePacketNames[position.articlePacketId] :
|
||||
'Loading...' }}
|
||||
</td>
|
||||
<td>{{ position.quantity }}</td>
|
||||
<td>
|
||||
<button class="btn btn-sm btn-danger" @click="deletePosition(position.id)">Löschen</button>
|
||||
<button class="btn btn-sm btn-primary" @click="editPosition(position.id)">Bearbeiten</button>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
`,
|
||||
</div>
|
||||
`,
|
||||
|
||||
|
||||
})
|
||||
@@ -157,83 +157,89 @@ Vue.component('warehouse-e-shop-order-modal-positions-mgmt', {
|
||||
Vue.component('warehouse-e-shop-order', {
|
||||
//language=Vue
|
||||
template: `
|
||||
<tt-card>
|
||||
<tt-table-crud @openHistory="historyModal = true; historyModalId = $event.id"
|
||||
@openSingleOrderEmail="openSingleOrderEmailModal = true; singleOrderEmailModalId = $event.id"
|
||||
@createShippingNote="createShippingNote($event.id)"
|
||||
@showTrackingHistory="openTrackingHistoryModal = true; trackingHistoryModalId = $event.id"
|
||||
ref="table">
|
||||
<tt-card>
|
||||
<tt-table-crud @openHistory="historyModal = true; historyModalId = $event.id"
|
||||
@openSingleOrderEmail="openSingleOrderEmailModal = true; singleOrderEmailModalId = $event.id"
|
||||
@createShippingNote="createShippingNote($event.id)"
|
||||
@showTrackingHistory="openTrackingHistoryModal = true; trackingHistoryModalId = $event.id"
|
||||
ref="table">
|
||||
|
||||
<template v-slot:table-top-buttons>
|
||||
<button @click="createCSVExportAndMarkAsAccepted" type="button" class="btn btn-outline-success">
|
||||
<i class="fas fa-file-excel"></i>
|
||||
Excel Export für neue Bestellungen
|
||||
</button>
|
||||
</template>
|
||||
<template v-slot:table-top-buttons>
|
||||
<button @click="createCSVExportAndMarkAsAccepted" type="button" class="btn btn-outline-success">
|
||||
<i class="fas fa-file-excel"></i>
|
||||
Excel Export für neue Bestellungen
|
||||
</button>
|
||||
</template>
|
||||
|
||||
<template v-slot:deliveryaddressname="{ row }">
|
||||
{{ row.deliveryAddressName }} {{ row.deliveryAddressAdditional ? '(' + row.deliveryAddressAdditional + ')' : '' }}
|
||||
</template>
|
||||
<template v-slot:deliveryaddressname="{ row }">
|
||||
{{ row.deliveryAddressName }} {{ row.deliveryAddressAdditional ? '(' + row.deliveryAddressAdditional + ')' : '' }}
|
||||
</template>
|
||||
|
||||
<template v-slot:create="{ row }">
|
||||
{{ window.moment(row.create * 1000).format('DD.MM.YYYY HH:mm:ss') }}
|
||||
</template>
|
||||
<template v-slot:create="{ row }">
|
||||
{{ window.moment(row.create * 1000).format('DD.MM.YYYY HH:mm:ss') }}
|
||||
</template>
|
||||
|
||||
<template v-slot:expandedRow="{ row }">
|
||||
<div>
|
||||
<ul class="list-group" v-if="articleItems && articleItems[row.id]">
|
||||
<li class="list-group-item" v-for="item in articleItems[row.id]">
|
||||
Menge: {{ item.quantity }} | {{ item.articlePacketTitle || item.articleTitle }}
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</template>
|
||||
<template v-slot:addressid="{ row }">
|
||||
<span v-if="row.addressId === 209">Energie Steiermark</span>
|
||||
<span v-else-if="row.addressId === 9633">SBIDI</span>
|
||||
<span v-else>Unbekannt</span>
|
||||
</template>
|
||||
|
||||
<template v-slot:positions-modal="{ crudModalData }">
|
||||
<div>
|
||||
<warehouse-e-shop-order-modal-positions-mgmt :id="crudModalData.id"/>
|
||||
</div>
|
||||
</template>
|
||||
<template v-slot:expandedRow="{ row }">
|
||||
<div>
|
||||
<ul class="list-group" v-if="articleItems && articleItems[row.id]">
|
||||
<li class="list-group-item" v-for="item in articleItems[row.id]">
|
||||
Menge: {{ item.quantity }} | {{ item.articlePacketTitle || item.articleTitle }}
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
</tt-table-crud>
|
||||
<warehouse-history-modal :show.sync="historyModal" :id="historyModalId"/>
|
||||
<template v-slot:positions-modal="{ crudModalData }">
|
||||
<div>
|
||||
<warehouse-e-shop-order-modal-positions-mgmt :id="crudModalData.id"/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<!-- add a tt-modal which just shows some text from the api to show a email for a single order-->
|
||||
<tt-modal :show.sync="openSingleOrderEmailModal"
|
||||
:title="'Email für Bestellung ' + singleOrderEmailModalId"
|
||||
@close="openSingleOrderEmailModal = false"
|
||||
save-text="E-Mail senden"
|
||||
@submit="sendSingleOrderEmail"
|
||||
:delete="false"
|
||||
>
|
||||
<div v-if="singleOrderEmailModalId && singleOrderEmailModalText">
|
||||
<p v-html="singleOrderEmailModalText.body.replaceAll('\\n', '<br>')"></p>
|
||||
</div>
|
||||
<!-- else show loader-->
|
||||
<div v-else>
|
||||
<tt-loader/>
|
||||
</div>
|
||||
</tt-modal>
|
||||
</tt-table-crud>
|
||||
<warehouse-history-modal :show.sync="historyModal" :id="historyModalId"/>
|
||||
|
||||
<tt-modal :show.sync="openTrackingHistoryModal"
|
||||
:title="'Tracking Historie für Bestellung ' + trackingHistoryModalId"
|
||||
@close="openTrackingHistoryModal = false"
|
||||
:delete="false"
|
||||
:save="false"
|
||||
>
|
||||
<div v-if="trackingHistoryModalData">
|
||||
<ul class="list-group">
|
||||
<li class="list-group item" v-for="entry in trackingHistoryModalData.history">
|
||||
<strong>{{ entry.date }} {{ entry.time }}</strong> - {{ entry.evtDscr }}
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<!-- add a tt-modal which just shows some text from the api to show a email for a single order-->
|
||||
<tt-modal :show.sync="openSingleOrderEmailModal"
|
||||
:title="'Email für Bestellung ' + singleOrderEmailModalId"
|
||||
@close="openSingleOrderEmailModal = false"
|
||||
save-text="E-Mail senden"
|
||||
@submit="sendSingleOrderEmail"
|
||||
:delete="false"
|
||||
>
|
||||
<div v-if="singleOrderEmailModalId && singleOrderEmailModalText">
|
||||
<p v-html="singleOrderEmailModalText.body.replaceAll('\\n', '<br>')"></p>
|
||||
</div>
|
||||
<!-- else show loader-->
|
||||
<div v-else>
|
||||
<tt-loader/>
|
||||
</div>
|
||||
</tt-modal>
|
||||
|
||||
</tt-modal>
|
||||
<tt-modal :show.sync="openTrackingHistoryModal"
|
||||
:title="'Tracking Historie für Bestellung ' + trackingHistoryModalId"
|
||||
@close="openTrackingHistoryModal = false"
|
||||
:delete="false"
|
||||
:save="false"
|
||||
>
|
||||
<div v-if="trackingHistoryModalData">
|
||||
<ul class="list-group">
|
||||
<li class="list-group item" v-for="entry in trackingHistoryModalData.history">
|
||||
<strong>{{ entry.date }} {{ entry.time }}</strong> - {{ entry.evtDscr }}
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
</tt-modal>
|
||||
|
||||
|
||||
</tt-card>
|
||||
`, data() {
|
||||
</tt-card>
|
||||
`, data() {
|
||||
return {
|
||||
window: window,
|
||||
historyModal: false,
|
||||
|
||||
Reference in New Issue
Block a user