WarehouseOffer fixed bugs
This commit is contained in:
@@ -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
|
||||
{
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user