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