'locationId', 'text' => 'Lagerort', 'required' => true, 'modal' => ['type' => 'select', 'data' => 'WarehouseLocation']], ['key' => 'articleId', 'text' => 'Artikel', 'required' => true, 'modal' => ['type' => 'select', 'data' => 'WarehouseArticle']], ['key' => 'warningAmount', 'text' => 'Warnmenge', 'required' => true, 'modal' => ['type' => 'number']], ['key' => 'criticalAmount', 'text' => 'Kritische Menge', 'required' => true, 'modal' => ['type' => 'number']], ['key' => 'actions', 'text' => 'Aktionen', 'required' => false, 'modal' => false, 'table' => ['filter' => false, 'sortable' => false, 'class' => 'text-center']] ]; // @formatter:on protected array $infoMessages = ['create' => 'Lagerort Schwellenwert wurde erstellt', 'update' => 'Lagerort Schwellenwert wurde aktualisiert', 'delete' => 'Lagerort Schwellenwert wurde gelöscht', 'noChanges' => 'Keine Änderungen']; protected function checkExistingDistributorEntry($postData): bool { // if postData id exists check if there is already an entry with the same articleId and locationId if postdata id and WarehouseLocationThresholdOverrideModel id are different return false if (isset($postData['id'])) { $count = WarehouseLocationThresholdOverrideModel::count(['locationId' => $postData['locationId'], 'articleId' => $postData['articleId'], 'id' => $postData['id']]); if ($count > 0) { return true; } } else { $count = WarehouseLocationThresholdOverrideModel::count(['locationId' => $postData['locationId'], 'articleId' => $postData['articleId']]); if ($count > 0) { self::returnJson(['success' => false, 'message' => 'Es existiert bereits ein Eintrag mit dieser Artikelnummer und diesem Lagerort.']); return false; } } return true; } protected function beforeCreate($postData): bool { return $this->checkExistingDistributorEntry($postData); } protected function beforeUpdate($postData): bool { $existing = $this->checkExistingDistributorEntry($postData); if (!$existing) { return false; } (new WarehouseHistoryController)->create($postData, $this->mod); return true; } protected function getHistoryAction() { $history = WarehouseHistoryModel::getByRowId($this->request->id, 'WarehouseArticleDistributor'); $history = array_map(function ($item) { $item = (array) $item; $item['columnHeader'] = $this->columns[array_search($item['key'], array_column($this->columns, 'key'))]['text']; return $item; }, $history); self::returnJson($history); } }