109 lines
5.6 KiB
PHP
109 lines
5.6 KiB
PHP
<?php
|
|
//TODO: enable switching distributors in the order preview
|
|
|
|
class WarehouseOrderRequestController extends TTCrud {
|
|
protected string $headerTitle = 'Bestellwünsche';
|
|
protected string $createText = 'Bestellwunsch erstellen';
|
|
|
|
protected array $columns = [
|
|
['key' => 'id', 'text' => 'ID', 'modal' => false, 'table' => false],
|
|
['key' => 'anzahl', 'text' => 'Anzahl', 'required' => true, 'type' => 'number'],
|
|
['key' => 'ware',
|
|
'text' => 'Ware',
|
|
'required' => true,
|
|
'type' => 'autocomplete',
|
|
'table' => ['class' => 'text-nowrap', 'filter' => 'autocomplete'],
|
|
'modal' => [
|
|
'apiUrl' => 'WarehouseArticle/autocomplete',
|
|
'type' => 'autocomplete',
|
|
'returnText' => true]],
|
|
['key' => 'verwendungszweck', 'text' => 'Verwendungszweck', 'required' => true],
|
|
['key' => 'create', 'text' => 'Beauftragt am', 'required' => true, 'modal' => false, 'table' => ['filter' => 'datepicker']],
|
|
['key' => 'createBy',
|
|
'text' => 'Beauftragt von',
|
|
'required' => true,
|
|
'table' => ['filter' => 'select'],
|
|
'modal' => ['visible' => false, 'type' => 'select', 'items' => []]],
|
|
['key' => 'distributorId',
|
|
'text' => 'Lieferant',
|
|
'required' => false,
|
|
'type' => 'autocomplete',
|
|
'table' => ['class' => 'text-nowrap', 'filter' => 'autocomplete'],
|
|
'modal' => [
|
|
'apiUrl' => 'WarehouseDistributor/autocomplete',
|
|
'type' => 'autocomplete']],
|
|
['key' => 'order', 'text' => 'Bestellt am', 'required' => false, 'type' => 'datepicker', 'table' => ['filter' => 'datepicker']],
|
|
['key' => 'orderBy', 'text' => 'Bestellt von', 'required' => false, 'table' => ['filter' => 'select'], 'modal' => ['type' => 'select', 'items' => []]],
|
|
['key' => 'takeOver', 'text' => 'Übernommen am', 'required' => false, 'type' => 'datepicker', 'table' => ['filter' => 'datepicker']],
|
|
['key' => 'takeOverBy',
|
|
'text' => 'Übernommen von',
|
|
'required' => false,
|
|
'table' => ['filter' => 'select'],
|
|
'modal' => ['type' => 'select', 'items' => []]],
|
|
['key' => 'warehouseLocation', 'text' => 'Lagerort', 'required' => false, 'type' => 'varchar'],
|
|
['key' => 'note', 'text' => 'Notiz', 'required' => false, 'type' => 'textarea'],
|
|
['key' => 'actions',
|
|
'text' => 'Aktionen',
|
|
'required' => false,
|
|
'modal' => false,
|
|
'table' => ['filter' => false, 'sortable' => false, 'class' => 'text-center']],
|
|
];
|
|
|
|
protected array $additionalActions = [['key' => 'openHistory', 'title' => 'Historie', 'class' => 'fas fa-history text-primary']];
|
|
|
|
protected array $infoMessages = ['create' => 'Bestellwunsch wurde erstellt.',
|
|
'update' => 'Bestellwunsch wurde aktualisiert',
|
|
'delete' => 'Bestellwunsch wurde gelöscht',
|
|
'noChanges' => 'Keine Änderungen',];
|
|
|
|
protected array $additionalJSVariables = ['BASE_URL' => '/WarehouseOrderRequest'];
|
|
|
|
public function permissionCheck(): bool {
|
|
return $this->user->can(["WarehouseUser"]);
|
|
}
|
|
|
|
protected function prepareCrudConfig() {
|
|
// Fill Users in createBy column
|
|
$userArray = array_map(function ($user) {
|
|
return ['value' => intval($user->id), 'text' => $user->name];
|
|
}, UserModel::search(['employee' => true]));
|
|
$createByColumn = array_search('createBy', array_column($this->columns, 'key'));
|
|
$this->columns[$createByColumn]['modal']['items'] = $userArray;
|
|
$orderByColumn = array_search('orderBy', array_column($this->columns, 'key'));
|
|
$this->columns[$orderByColumn]['modal']['items'] = $userArray;
|
|
$takeOverByColumn = array_search('takeOverBy', array_column($this->columns, 'key'));
|
|
$this->columns[$takeOverByColumn]['modal']['items'] = $userArray;
|
|
|
|
// if this user can WarehouseAdmin is false then set modal false to warehouselocation, takeOverBy, takeOver, orderBy, order
|
|
if (!$this->user->can(["WarehouseAdmin"])) {
|
|
$warehouselocationColumn = array_search('warehouseLocation', array_column($this->columns, 'key'));
|
|
$this->columns[$warehouselocationColumn]['modal']['visible'] = false;
|
|
$takeOverByColumn = array_search('takeOverBy', array_column($this->columns, 'key'));
|
|
$this->columns[$takeOverByColumn]['modal']['visible'] = false;
|
|
$takeOverColumn = array_search('takeOver', array_column($this->columns, 'key'));
|
|
$this->columns[$takeOverColumn]['modal']['visible'] = false;
|
|
$orderByColumn = array_search('orderBy', array_column($this->columns, 'key'));
|
|
$this->columns[$orderByColumn]['modal']['visible'] = false;
|
|
$orderColumn = array_search('order', array_column($this->columns, 'key'));
|
|
$this->columns[$orderColumn]['modal']['visible'] = false;
|
|
}
|
|
|
|
}
|
|
|
|
protected function customAutoCompleteWare($value) {
|
|
if (!is_numeric($value)) return [ 'id' => $value, 'title' => $value];
|
|
|
|
$article = WarehouseArticleModel::get(intval($value));
|
|
return [ 'id' => $article->id, 'title' => $article->title ];
|
|
}
|
|
|
|
protected function beforeUpdate($postData): bool {
|
|
(new WarehouseHistoryController)->create($postData, $this->mod);
|
|
return true;
|
|
}
|
|
|
|
protected function getHistoryAction() {
|
|
$this->prepareCrudConfig();
|
|
self::returnJson((new WarehouseHistoryController)->getHistory($this->request->id, $this->mod, $this->columns));
|
|
}
|
|
} |