73 lines
3.2 KiB
PHP
73 lines
3.2 KiB
PHP
<?php
|
|
|
|
class WarehouseEShopController extends TTCrud {
|
|
protected string $headerTitle = 'Energie Steiermark Shop';
|
|
protected bool $createText = false;
|
|
//@formatter:off
|
|
|
|
protected array $columns = [
|
|
['key' => 'title', 'text' => 'Artikel', 'priority' => 11],
|
|
['key' => 'category', 'text' => 'Kategorie', 'table' => false],
|
|
['key' => 'price', 'text' => 'Preis', 'table' => false],
|
|
['key' => 'amount', 'text' => 'Menge', 'table' => ['filter' => false, 'sortable' => false, 'class' => 'p-0 width-80'], 'priority' => 9],
|
|
['key' => 'add', 'text' => 'Hinzufügen', 'table' => ['filter' => false, 'sortable' => false, 'class' => 'width-120 text-center'], 'priority' => 5000]
|
|
];
|
|
//@formatter:on
|
|
protected array $permissionCheck = ['WarehouseEShop'];
|
|
|
|
protected function afterInit() {
|
|
if (!$this->user->isAdmin()) return;
|
|
if (!$this->user->getFlag('WarehouseSelectedShop') && !isset($_GET['shop'])) self::sendError("Bitte wählen Sie einen Shop aus.");
|
|
|
|
if (in_array($_GET['shop'], ['e', 'sbidi'])) {
|
|
$flag = new WorkerFlag($this->user->id, 'WarehouseSelectedShop');
|
|
$flag->value($_GET['shop']);
|
|
$flag->save();
|
|
$this->user->address_id = ($_GET['shop'] === 'e') ? '209' : '9633';
|
|
return;
|
|
}
|
|
|
|
$this->user->address_id = ($this->user->getFlag('WarehouseSelectedShop')->value() === 'e') ? '209' : '9633';
|
|
}
|
|
|
|
|
|
protected function prepareCrudConfig() {
|
|
if (!in_array(intval($this->user->address_id), [209, 9633])) self::sendError("Keine Berechtigung für diesen Shop");
|
|
|
|
$this->additionalJSVariables['userAddressId'] = $this->user->address_id ?? null;
|
|
$this->headerTitle = $this->user->address_id == 209 ? 'Energie Steiermark Shop' : 'SBIDI Shop';
|
|
}
|
|
|
|
public function getAction() {
|
|
if (!in_array(intval($this->user->address_id), [209, 9633])) self::sendError("Keine Berechtigung für diesen Shop");
|
|
|
|
$filter = $this->postData['filters'] ?? [];
|
|
$order = $this->postData['order'] ?? ['key' => null, 'order' => 'ASC'];
|
|
$page = $this->postData['pagination']['page'] ?? 1;
|
|
$perPage = $this->postData['pagination']['per_page'] ?? 10;
|
|
|
|
$shopType = (intval($this->user->address_id) === 209) ? 'EShop' : 'SbidiShop';
|
|
$filter["is{$shopType}"] = 1;
|
|
$filter["is{$shopType}Hide"] = 0;
|
|
|
|
$warehouseArticles = WarehouseArticleModel::getAll($filter, null, 0, $order);
|
|
$warehousePackets = WarehouseArticlePacketModel::getAll($filter, null, 0, $order);
|
|
|
|
$filteredAvailable = WarehouseArticlePacketModel::count($filter) + WarehouseArticleModel::count($filter);
|
|
|
|
$rows = [...$warehouseArticles, ...$warehousePackets];
|
|
|
|
usort($rows, function($a, $b) { return strcmp($a->title, $b->title); });
|
|
|
|
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" => $filteredAvailable
|
|
]
|
|
]);
|
|
}
|
|
} |