From 4a58cc44da8ee499dfa2f813ed63118b777dff51 Mon Sep 17 00:00:00 2001 From: Luca Haid Date: Thu, 7 Aug 2025 16:33:49 +0200 Subject: [PATCH] added new end of life --- .../WarehouseArticleController.php | 36 +++++++++++++++++++ .../WarehouseArticleModel.php | 1 + .../WarehouseOrderRequestController.php | 2 +- ...0_warehouse_article_add_is_end_of_life.php | 25 +++++++++++++ lib/TTCrud/TTCrud.php | 4 +-- .../WarehouseArticle/WarehouseArticle.css | 33 +++++++++-------- .../WarehouseArticle/WarehouseArticle.js | 4 +++ 7 files changed, 88 insertions(+), 17 deletions(-) create mode 100644 db/migrations/20250807162000_warehouse_article_add_is_end_of_life.php diff --git a/application/WarehouseArticle/WarehouseArticleController.php b/application/WarehouseArticle/WarehouseArticleController.php index 8f0d6cc69..59e648ea9 100644 --- a/application/WarehouseArticle/WarehouseArticleController.php +++ b/application/WarehouseArticle/WarehouseArticleController.php @@ -19,6 +19,9 @@ class WarehouseArticleController extends TTCrud { ['key' => 'warningAmount', 'text' => 'Warnmenge', 'required' => true,'modal' => ['type' => 'number'], 'table' => false], ['key' => 'criticalAmount', 'text' => 'Kritische Menge', 'required' => true,'modal' => ['type' => 'number'], 'table' => false], ['key' => 'isSerialDocumentation', 'text' => 'Seriennummern', 'required' => false,'modal' => ['type' => 'checkbox'], 'table' => false], + ['key' => 'isEndOfLife', 'text' => 'End of Life', 'required' => false,'modal' => ['type' => 'checkbox', 'items' => [ + ['value' => 0, 'text' => 'Nicht End of Life', 'icon' => 'fa-regular fa-circle-check text-success'], + ['value' => 1, 'text' => 'End of Life', 'icon' => 'fa-regular fa-circle-xmark text-danger']]], 'table' => ['filter' => 'iconSelect']], ['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], @@ -127,4 +130,37 @@ class WarehouseArticleController extends TTCrud { protected function getHistoryAction() { self::returnJson((new WarehouseHistoryController)->getHistory($this->request->id, $this->mod, $this->columns)); } + + protected function autocompleteAction() { + $textKey = property_exists($this->model, 'name') ? 'name' : 'title'; + if (strlen($this->request->searchedID) > 0) { + $filter = ['id' => $this->request->searchedID]; + $data = $this->model::getAll($filter, 10); + } else { + if (isset($this->autocompleteColumns) && is_array($this->autocompleteColumns)) { + $filterKey = join('|', $this->autocompleteColumns); + } else { + $filterKey = $textKey; + } + + $data = []; + if (count($data) < 11) { + if (isset($_GET['hideEndOfLife'])) { + $data = $this->model::getAll([$textKey => $this->request->q . '%', 'isEndOfLife' => 0], 10); + $lazyData = $this->model::getAll([$filterKey => $this->request->q, 'isEndOfLife' => 0], 10); + } else { + $data = $this->model::getAll([$textKey => $this->request->q . '%'], 10); + $lazyData = $this->model::getAll([$filterKey => $this->request->q], 10); + } + + $data = array_merge($data, $lazyData); + $data = array_unique($data, SORT_REGULAR); + $data = array_slice($data, 0, 10); + } + } + + self::returnJson(array_map(function ($item) use ($textKey) { + return ['value' => $item->id, 'text' => $item->$textKey]; + }, $data)); + } } diff --git a/application/WarehouseArticle/WarehouseArticleModel.php b/application/WarehouseArticle/WarehouseArticleModel.php index b8765a07c..245e3bb64 100644 --- a/application/WarehouseArticle/WarehouseArticleModel.php +++ b/application/WarehouseArticle/WarehouseArticleModel.php @@ -14,6 +14,7 @@ class WarehouseArticleModel extends TTCrudBaseModel { public ?int $isEShopHide; public ?int $isSbidiShop; public ?int $isSbidiShopHide; + public ?int $isEndOfLife; public string $unit; public ?int $isSerialDocumentation; public int $revenueAccount; diff --git a/application/WarehouseOrderRequest/WarehouseOrderRequestController.php b/application/WarehouseOrderRequest/WarehouseOrderRequestController.php index a23abcd53..00006f7c5 100644 --- a/application/WarehouseOrderRequest/WarehouseOrderRequestController.php +++ b/application/WarehouseOrderRequest/WarehouseOrderRequestController.php @@ -18,7 +18,7 @@ class WarehouseOrderRequestController extends TTCrud { 'header' => 'Positionen', 'fields' => [ 'articleId' => [ - 'apiUrl' => '/WarehouseArticle/autoComplete', + 'apiUrl' => '/WarehouseArticle/autoComplete?hideEndOfLife=1', 'type' => 'input-article', 'emitDisplayValue' => true, 'customFieldReference' => 'WarehouseArticle', diff --git a/db/migrations/20250807162000_warehouse_article_add_is_end_of_life.php b/db/migrations/20250807162000_warehouse_article_add_is_end_of_life.php new file mode 100644 index 000000000..362df2cc3 --- /dev/null +++ b/db/migrations/20250807162000_warehouse_article_add_is_end_of_life.php @@ -0,0 +1,25 @@ +getEnvironment() == "thetool") { + $this->table("WarehouseArticle") + ->addColumn("isEndOfLife", "integer", ["null" => false, "default" => 0, "after" => "criticalAmount"]) + ->update(); + } + } + + public function down(): void + { + if ($this->getEnvironment() == "thetool") { + $this->table("WarehouseArticle") + ->removeColumn("isEndOfLife") + ->update(); + } + } +} diff --git a/lib/TTCrud/TTCrud.php b/lib/TTCrud/TTCrud.php index d16b0ff14..fc08accf8 100644 --- a/lib/TTCrud/TTCrud.php +++ b/lib/TTCrud/TTCrud.php @@ -271,10 +271,10 @@ class TTCrud extends mfBaseController { } protected function updateAction() { - if (property_exists($this->model, 'create') && isset($this->postData['create'])) { + if (property_exists($this->model, 'create')) { $this->postData['create'] = $this->model::get($this->postData['id'])->create; } - if (property_exists($this->model, 'createBy') && isset($this->postData['createBy'])) { + if (property_exists($this->model, 'createBy')) { $this->postData['createBy'] = $this->model::get($this->postData['id'])->createBy; } diff --git a/public/js/pages/WarehouseArticle/WarehouseArticle.css b/public/js/pages/WarehouseArticle/WarehouseArticle.css index 764bec90a..cdcefa24d 100644 --- a/public/js/pages/WarehouseArticle/WarehouseArticle.css +++ b/public/js/pages/WarehouseArticle/WarehouseArticle.css @@ -1,38 +1,43 @@ -/* style.css */ +.end-of-life { + background-color: #f8d7da !important; +} + .warehouse-article-prices > div, .warehouse-article-distributor > div { display: grid; - grid-template-columns: repeat(3, minmax(150px, 1fr)) 120px; /* Defines 4 columns */ - gap: 12px; /* Use gap for spacing */ - margin-bottom: 8px; /* Add small gap between rows */ + grid-template-columns: repeat(3, minmax(150px, 1fr)) 120px; + gap: 12px; + margin-bottom: 8px; } .warehouse-article-prices .form-group, .warehouse-article-distributor .form-group { - margin-bottom: 0; /* Keep inputs tight in grid cells */ + margin-bottom: 0; } @media (max-width: 992px) { .warehouse-article-prices > div, .warehouse-article-distributor > div { - display: block; /* Stack items vertically */ - border: 1px solid #eee; /* Lighter border */ + display: block; + border: 1px solid #eee; padding: 10px; margin-bottom: 10px; } .warehouse-article-prices > div > *, .warehouse-article-distributor > div > * { - display: block; /* Ensure children are block */ - margin-bottom: 10px !important; /* Add space between stacked items */ + display: block; + margin-bottom: 10px !important; } - .warehouse-article-prices > div > div:last-child, /* Target button container */ + + .warehouse-article-prices > div > div:last-child, .warehouse-article-distributor > div > div:last-child { - text-align: right; /* Keep buttons aligned right */ - margin-bottom: 0 !important; /* Remove extra margin below buttons */ + text-align: right; + margin-bottom: 0 !important; } - .warehouse-article-prices > div > div:last-child > *, /* Target buttons inside */ + + .warehouse-article-prices > div > div:last-child > *, .warehouse-article-distributor > div > div:last-child > * { - margin-left: 5px; /* Add small space between buttons */ + margin-left: 5px; } } \ No newline at end of file diff --git a/public/js/pages/WarehouseArticle/WarehouseArticle.js b/public/js/pages/WarehouseArticle/WarehouseArticle.js index eafbecef8..bfe645844 100644 --- a/public/js/pages/WarehouseArticle/WarehouseArticle.js +++ b/public/js/pages/WarehouseArticle/WarehouseArticle.js @@ -1,3 +1,7 @@ +window.TT_CONFIG.CRUD_CONFIG.customRowClass = (row) => { + if (row.isEndOfLife) return 'end-of-life'; +} + async function handleApiResponse(responsePromise) { const res = await responsePromise; if (!res.data.success) {