Feature/warehouse
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @property mixed|null $name
|
||||
*/
|
||||
class WarehouseArticlePrice extends mfBaseModel
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
class WarehouseArticlePriceController extends TTCrud {
|
||||
protected string $headerTitle = 'Artikel Verkaufspreise';
|
||||
protected string $createText = 'Artikel Verkaufspreis erstellen';
|
||||
|
||||
// @formatter:off
|
||||
protected array $columns = [
|
||||
['key' => 'articleId', 'text' => 'Artikel', 'required' => true],
|
||||
['key' => 'articlePriceTypeId', 'text' => 'Preistyp', 'required' => true],
|
||||
['key' => 'priceMultiplier', 'text' => 'Preismultiplikator', 'required' => false],
|
||||
['key' => 'priceOverride', 'text' => 'Preisüberschreibung', 'required' => false]
|
||||
];
|
||||
// @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 beforeCreate($postData): bool {
|
||||
return $this->validate($postData);
|
||||
}
|
||||
|
||||
protected function validate($postData): bool {
|
||||
// check if postData priceOverride or priceMultiplier is set but only one of them
|
||||
if (isset($postData['priceOverride']) && isset($postData['priceMultiplier'])) {
|
||||
self::returnJson(['success' => false,
|
||||
'message' => 'Entweder Preismultiplikator oder Preisüberschreibung kann gesetzt werden.']);
|
||||
return false;
|
||||
} else if (!isset($postData['priceOverride']) && !isset($postData['priceMultiplier'])) {
|
||||
self::returnJson(['success' => false,
|
||||
'message' => 'Entweder Preismultiplikator oder Preisüberschreibung muss gesetzt werden.']);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if (isset($postData['id'])) {
|
||||
$count = WarehouseArticlePriceModel::count(['articleId' => $postData['articleId'],
|
||||
'articlePriceTypeId' => $postData['articlePriceTypeId'],
|
||||
'id' => $postData['id']]);
|
||||
if ($count > 0) return true;
|
||||
} else {
|
||||
$count = WarehouseArticlePriceModel::count(['articleId' => $postData['articleId'],
|
||||
'articlePriceTypeId' => $postData['articlePriceTypeId']]);
|
||||
if ($count > 0) {
|
||||
self::returnJson(['success' => false,
|
||||
'message' => 'Es existiert bereits ein Preis für diesen Artikel und diesen Preistyp.']);
|
||||
return false;
|
||||
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function beforeUpdate($postData): bool {
|
||||
$existing = $this->validate($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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
class WarehouseArticlePriceModel extends TTCrudBaseModel {
|
||||
public int $id;
|
||||
public int $articleId;
|
||||
public int $articlePriceTypeId;
|
||||
public ?float $priceMultiplier;
|
||||
public ?float $priceOverride;
|
||||
}
|
||||
Reference in New Issue
Block a user