implemented new features for warehouseorderrequest

This commit is contained in:
Luca Haid
2025-01-07 16:49:20 +01:00
parent e20af3eca5
commit f622204aa0
12 changed files with 253 additions and 87 deletions
@@ -51,6 +51,29 @@ class WarehouseHistoryController {
}
}
if ($columns[array_search($item['key'], array_column($columns, 'key'))]['modal']['type'] === 'autocomplete') {
if (method_exists($this, 'customAutoComplete' . ucfirst($item['key']))) {
$item['old_value'] = $this->{'customAutoComplete' . ucfirst($item['key'])}($item['old_value']);
$item['new_value'] = $this->{'customAutoComplete' . ucfirst($item['key'])}($item['new_value']);
} else {
$autoCompleteModelName = explode('/', $columns[array_search($item['key'], array_column($columns, 'key'))]['modal']['apiUrl'])[0] . 'Model';
$autoCompleteModel = new $autoCompleteModelName();
$data_old = isset($item['old_value']) && $item['old_value'] !== '' ? $autoCompleteModel::get($item['old_value']) : '';
$data_new = isset($item['new_value']) && $item['new_value'] !== '' ? $autoCompleteModel::get($item['new_value']) : '';
// check if title exists else it should be name
$textColum = $columns[array_search($item['key'], array_column($columns, 'key'))]['modal']['text'] ?? 'name';
$item['old_value'] = isset($data_old) && $data_old !== '' ? $data_old->$textColum : $item['old_value'];
$item['new_value'] = isset($data_new) && $data_new !== '' ? $data_new->$textColum : $item['new_value'];
}
}
}
@@ -6,21 +6,47 @@ class WarehouseOrderRequestController extends TTCrud {
protected string $createText = 'Bestellwunsch erstellen';
protected array $columns = [
['key' => 'id', 'text' => 'ID', 'modal' => false],
['key' => 'id', 'text' => 'ID', 'modal' => false, 'table' => false],
['key' => 'anzahl', 'text' => 'Anzahl', 'required' => true, 'type' => 'number'],
['key' => 'ware', 'text' => 'Ware', 'required' => true],
['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' => 'Erstellt am', 'required' => true, 'modal' => false, 'filter' => 'datetime'],
['key' => 'createBy', 'text' => 'Beauftragt von', 'required' => true, 'table' => ['filter' => 'select'], 'modal' => ['visible' => false, 'type' => 'select', 'items' => []]],
['key' => 'distributorId', 'text' => 'Lieferant', 'required' => true, 'type' => 'autocomplete', 'table' => ['class' => 'text-nowrap', 'filter' => 'autocomplete'], 'modal' => [
'apiUrl' => 'WarehouseDistributor/autocomplete', 'items' => 'WarehouseDistributor/autocomplete', 'type' => 'autocomplete']],
['key' => 'order', 'text' => 'Bestellt am', 'required' => false, 'filter' => 'datetime'],
['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, 'filter' => 'datetime'],
['key' => 'takeOverBy', 'text' => 'Übernommen 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' => 'text'],
['key' => 'actions', 'text' => 'Aktionen', 'required' => false, 'modal' => false, 'table' => ['filter' => false, 'sortable' => false, 'class' => 'text-center']],
['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']];
@@ -30,6 +56,8 @@ class WarehouseOrderRequestController extends TTCrud {
'delete' => 'Bestellwunsch wurde gelöscht',
'noChanges' => 'Keine Änderungen',];
protected array $additionalJSVariables = ['BASE_URL' => '/WarehouseOrderRequest'];
public function permissionCheck(): bool {
return $this->user->can(["WarehouseUser"]);
}
@@ -38,13 +66,35 @@ class WarehouseOrderRequestController extends TTCrud {
// Fill Users in createBy column
$userArray = array_map(function ($user) {
return ['value' => intval($user->id), 'text' => $user->name];
}, UserModel::search());
}, 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 {
@@ -53,6 +103,7 @@ class WarehouseOrderRequestController extends TTCrud {
}
protected function getHistoryAction() {
$this->prepareCrudConfig();
self::returnJson((new WarehouseHistoryController)->getHistory($this->request->id, $this->mod, $this->columns));
}
}
@@ -2,14 +2,18 @@
class WarehouseOrderRequestModel extends TTCrudBaseModel {
public int $id;
public int $distributorId;
public ?string $intRef;
public ?string $extRef;
public float $sum;
public string $status;
public ?string $trackingNumber;
public int $create;
public int $anzahl;
public string $ware;
public string $verwendungszweck;
public string $create;
public int $createBy;
public ?int $distributorId;
public ?string $order;
public ?int $orderBy;
public ?string $takeOver;
public ?int $takeOverBy;
public ?string $warehouseLocation;
public ?string $note;
}
@@ -37,7 +37,7 @@ class WarehouseShippingNoteController extends TTCrud {
protected function prepareCrudConfig() {
$users = array_map(function ($user) {
return ['value' => intval($user->id), 'text' => $user->name];
}, UserModel::search());
}, UserModel::search(['employee' => true]));
$this->columns[array_search('createBy', array_column($this->columns, 'key'))]['modal']['items'] = $users;