76 lines
2.9 KiB
PHP
76 lines
2.9 KiB
PHP
<?php
|
|
|
|
class WarehouseArticlePriceTypeController extends TTCrud {
|
|
protected string $headerTitle = 'Artikel Verkaufspreise';
|
|
protected string $createText = 'Artikel Verkaufspreis erstellen';
|
|
|
|
// @formatter:off
|
|
protected array $columns = [
|
|
['key' => 'title', 'text' => 'Titel', 'required' => true],
|
|
['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 Verkaufspreis wurde erstellt',
|
|
'update' => 'Artikel Verkaufspreis wurde aktualisiert',
|
|
'delete' => 'Artikel Verkaufspreis 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 = WarehouseArticlePriceTypeModel::count(['title' => $postData['title'], 'id' => $postData['id']]);
|
|
if ($count > 0) {
|
|
return true;
|
|
}
|
|
} else {
|
|
$count = WarehouseArticlePriceTypeModel::count(['title' => $postData['title']]);
|
|
if ($count > 0) {
|
|
self::returnJson(['success' => false,
|
|
'message' => 'Es existiert bereits ein Preis Typ mit diesem Titel.']);
|
|
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 afterUpdate($postData) {
|
|
WarehouseArticleController::updateCheapestPurchasePrice($postData['articleId']);
|
|
}
|
|
|
|
protected function afterCreate($postData) {
|
|
//TODO: fix this
|
|
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);
|
|
}
|
|
|
|
} |