76 lines
3.5 KiB
PHP
76 lines
3.5 KiB
PHP
<?php
|
|
|
|
class WarehouseItemController extends TTCrud {
|
|
protected string $headerTitle = 'Eintrag';
|
|
protected string $createText = 'Eintrag erstellen';
|
|
|
|
// TODO: check if historyController is needed
|
|
// TODO: check if apiUrl uses self::getUrl to get the correct URL
|
|
|
|
// @formatter:off
|
|
protected array $columns = [
|
|
['key' => 'articleId', 'text' => 'Artikel', 'required' => true, 'type' => 'autocomplete','table' => ['class' => 'text-nowrap', 'filter' => 'autocomplete'],'modal' => [
|
|
'apiUrl' => 'WarehouseArticle/autocomplete','items' => 'WarehouseArticle/autocomplete', 'type' => 'autocomplete']],
|
|
['key' => 'warehouseLocationId', 'text' => 'Lagerort', 'required' => true, 'type' => 'autocomplete', 'table' => ['filter' => 'autocomplete'], 'modal' => [
|
|
'items' => 'WarehouseLocation/autocomplete',
|
|
'apiUrl' => 'WarehouseLocation/autocomplete', 'type' => 'autocomplete']],
|
|
['key' => 'quantity', 'text' => 'Menge', 'required' => false, 'type' => 'number'
|
|
// quantity is only visible in modal when warehouseArticle(articleId).serial is false, add modal config here to reference warehouseArticle
|
|
, 'modal' => ['type' => 'number',
|
|
'visible' => ['reference' => 'WarehouseArticle', 'use' => 'articleId=id', 'key' => 'isSerialDocumentation', 'value' => false]
|
|
]
|
|
],
|
|
['key' => 'rack', 'text' => 'Regal', 'required' => false, 'modal' => ['type' => 'text']],
|
|
['key' => 'shelf', 'text' => 'Fach', 'required' => false, 'modal' => ['type' => 'text'], 'table' => false],
|
|
['key' => 'serialNumber', 'text' => 'Seriennummer', 'required' => false, 'modal' => ['type' => 'text', 'visible' => ['reference' => 'WarehouseArticle', 'use' => 'articleId=id', 'key' => 'isSerialDocumentation', 'value' => true]]],
|
|
['key' => 'note', 'text' => 'Notiz', 'required' => false],
|
|
['key' => 'actions', 'text' => 'Aktionen', 'table' => ['filter' => false], 'required' => false, 'modal' => false]
|
|
];
|
|
// @formatter:on
|
|
|
|
protected array $additionalActions = [
|
|
['key' => 'openHistory', 'title' => 'Historie', 'class' => 'fas fa-history text-primary'],
|
|
];
|
|
|
|
protected array $infoMessages = [
|
|
'create' => 'Eintrag wurde erstellt',
|
|
'update' => 'Eintrag wurde aktualisiert',
|
|
'delete' => 'Eintrag wurde gelöscht',
|
|
'noChanges' => 'Keine Änderungen',
|
|
'alreadyExists' => 'Eintrag existiert bereits an diesem Lagerort.'
|
|
];
|
|
|
|
protected function checkExistingItemOnLocation($postData): bool {
|
|
$count = WarehouseItemModel::count(['articleId' => $postData['articleId'],
|
|
'warehouseLocationId' => $postData['warehouseLocationId'],
|
|
'serialNumber' => null]);
|
|
|
|
if ($count > 0) {
|
|
self::returnJson(['success' => false, 'message' => $this->infoMessages['alreadyExists']]);
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
protected function beforeCreate($postData): bool {
|
|
return $this->checkExistingItemOnLocation($postData);
|
|
}
|
|
|
|
protected function beforeUpdate($postData): bool {
|
|
$existing = $this->checkExistingItemOnLocation($postData);
|
|
|
|
if (!$existing) {
|
|
return false;
|
|
}
|
|
|
|
(new WarehouseHistoryController)->create($postData, $this->mod);
|
|
|
|
return true;
|
|
}
|
|
|
|
protected function getHistoryAction() {
|
|
self::returnJson((new WarehouseHistoryController)->getHistory($this->request->id, $this->mod, $this->columns));
|
|
}
|
|
|
|
} |