'purchasePrice', 'text' => 'Einkaufspreis', 'required' => true, 'modal' => ['type' => 'number']], ['key' => 'articleId', 'text' => 'Artikel', 'required' => true, 'modal' => ['type' => 'select', 'data' => 'WarehouseArticle']], ['key' => 'distributorId', 'text' => 'Lieferant', 'required' => true, 'modal' => ['type' => 'select', 'data' => 'WarehouseDistributor']], ['key' => 'externalArticleNumber', 'text' => 'Externe Artikelnummer', 'required' => true], ['key' => 'note', 'text' => 'Notiz', 'required' => false, 'modal' => ['type' => 'textarea']], ['key' => 'actions', 'text' => 'Aktionen', 'required' => false, 'modal' => false, 'table' => ['filter' => false, 'sortable' => false, 'class' => 'text-center']] ]; // @formatter:on protected array $infoMessages = ['create' => 'Lieferanteintrag wurde erstellt', 'update' => 'Lieferanteintrag wurde aktualisiert', 'delete' => 'Lieferanteintrag wurde gelöscht', 'noChanges' => 'Keine Änderungen',]; protected function checkExistingThresholdEntry($postData): bool { $count = WarehouseLocationThresholdOverrideModel::count(['articleId' => $postData['articleId'], 'distributorId' => $postData['distributorId']]); if ($count > 0) { self::returnJson(['success' => false, 'message' => 'Es existiert bereits ein Eintrag mit dieser Artikelnummer und diesem Lieferanten.']); return false; } return true; } protected function beforeCreate($postData): bool { return $this->checkExistingThresholdEntry($postData); } protected function afterCreate($postData) { WarehouseArticleController::updateCheapestPurchasePrice($postData['articleId']); } protected function beforeUpdate($postData): bool { $existing = $this->checkExistingThresholdEntry($postData); if (!$existing) { return false; } (new WarehouseHistoryController)->create($postData, $this->mod); return true; } protected function afterUpdate($postData) { WarehouseArticleController::updateCheapestPurchasePrice($postData['articleId']); } protected function getHistoryAction() { $history = WarehouseHistoryModel::getByRowId($this->request->id, $this->mod); $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); } }