139 lines
6.0 KiB
PHP
139 lines
6.0 KiB
PHP
<?php /** @noinspection PhpVoidFunctionResultUsedInspection */
|
|
|
|
class WarehouseOrderRequestController extends TTCrud {
|
|
protected string $headerTitle = 'Bestellwünsche';
|
|
protected string $createText = 'Neuer Bestellwunsch';
|
|
protected string $singleText = 'Bestellwunsch';
|
|
|
|
//@formatter:off
|
|
protected array $columns = [
|
|
['key' => 'id', 'text' => 'Bestellnummer', 'table' => false, 'modal' => false],
|
|
['key' => 'purpose', 'text' => 'Verwendungszweck', 'required' => true],
|
|
['key' => 'positions', 'text' => 'Positionen', 'required' => true, 'modal' => ['type' => 'positions-manager', 'config' => [
|
|
'header' => 'Positionen',
|
|
'fields' => [
|
|
'articleId' => [
|
|
'apiUrl' => '/WarehouseArticle/autoComplete',
|
|
'type' => 'autocomplete',
|
|
'emitDisplayValue' => true,
|
|
'customFieldReference' => 'WarehouseArticle',
|
|
'label' => 'Artikel',
|
|
],
|
|
'amount' => ['type' => 'input', 'label' => 'Menge', 'inputType' => 'number'],
|
|
'purpose' => ['type' => 'input', 'label' => 'Zweck'],
|
|
],
|
|
'validateFormOptions' => [
|
|
['key' => 'articleId', 'message' => 'Bitte füllen Sie den Artikel aus'],
|
|
['key' => 'amount', 'message' => 'Bitte füllen Sie die Menge aus'],
|
|
['key' => 'purpose', 'message' => 'Bitte füllen Sie den Zweck aus'],
|
|
],
|
|
]], 'table' => false],
|
|
['key' => 'linkedOrderIds', 'text' => 'Verlinkte Bestellung', 'modal' => false],
|
|
['key' => 'createBy', 'text' => 'Erstellt von', 'required' => true, 'modal' => ['visible' => false, 'type' => 'select'], 'table' => ['filter' => 'select']],
|
|
['key' => 'create', 'text' => 'Erstellt am', 'required' => true, 'modal' => false],
|
|
['key' => 'cancelled', 'text' => 'Storniert', 'modal' => ['visible' => false, 'type' => 'icon-select', 'items' => [
|
|
['value' => 0, 'text' => 'Bestellwunsch nicht storniert', 'icon' => 'fa-regular fa-circle-check text-success'],
|
|
['value' => 1, 'text' => 'Bestellwunsch storniert', 'icon' => 'fa-regular fa-circle-xmark text-danger']]], 'table' => ['filter' => 'iconSelect']
|
|
],
|
|
['key' => 'actions', 'text' => 'Aktionen', 'required' => false, 'modal' => false, 'table' => ['filter' => false, 'sortable' => false, 'class' => 'text-center']],
|
|
];
|
|
//@formatter:on
|
|
|
|
protected array $permissionCheck = ['WarehouseUser'];
|
|
|
|
protected array $additionalActions = [
|
|
['key' => 'openHistory', 'title' => 'Historie', 'class' => 'fas fa-history text-primary'],
|
|
['key' => 'createLog', 'title' => 'Log-Eintrag erstellen', 'class' => 'fas fa-plus text-primary'],
|
|
];
|
|
|
|
protected function prepareCrudConfig() {
|
|
$this->additionalJSVariables = [
|
|
'user_id' => $this->user->id,
|
|
'BASE_URL' => '/WarehouseOrderRequest',
|
|
'WAREHOUSE_ADMIN' => $this->user->can('WarehouseAdmin')
|
|
];
|
|
}
|
|
|
|
protected function beforeUpdate($postData): bool {
|
|
(new WarehouseHistoryController)->create($postData, $this->mod);
|
|
return true;
|
|
}
|
|
|
|
protected function afterCreate($postData): void {
|
|
return;
|
|
//TODO: this should be working again
|
|
if ($_SERVER['HTTP_HOST'] === 'localhost') return;
|
|
die("TODO we need this to work with new positions manager");
|
|
|
|
$email = new Emailnotification();
|
|
$postData['ware'] = is_numeric($postData['ware']) ? WarehouseArticleModel::get((int) $postData['ware'])->title : $postData['ware'];
|
|
$paddedId = str_pad($postData['id'], 5, '0', STR_PAD_LEFT);
|
|
|
|
$email->setSubject("TheTool: Neue Interne Bestellung #$paddedId")
|
|
->setBody(<<<BODY
|
|
Hallo,
|
|
|
|
es wurde eine neue interne Bestellung erstellt.
|
|
|
|
Bestellnummer: #$paddedId
|
|
Ware: {$postData['ware']}
|
|
Anzahl: {$postData['anzahl']}
|
|
Verwendungszweck: {$postData['verwendungszweck']}
|
|
Beauftragt von: {$this->user->name}
|
|
Beauftragt am: {date('d.m.Y H:i')}
|
|
Notiz: {$postData['note']}
|
|
|
|
BODY
|
|
)
|
|
->setFrom(TT_OUTGOING_EMAIL_2FA, TT_OUTGOING_EMAIL_2FA)
|
|
->setTo("einkauf@xinon.at", "Einkauf")
|
|
->send();
|
|
}
|
|
|
|
protected function cancelAction() {
|
|
$id = filter_var($this->request->id, FILTER_VALIDATE_INT);
|
|
$cancel = filter_var($this->request->cancel, FILTER_VALIDATE_INT, ['options' => ['min_range' => 0, 'max_range' => 1]]);
|
|
|
|
if (!$id || $cancel === false) self::returnJson(['error' => 'Ungültige Anfrage']);
|
|
if (!(WarehouseOrderRequestModel::get($id))) self::returnJson(['error' => 'Bestellwunsch nicht gefunden']);
|
|
|
|
WarehouseOrderRequestModel::update(['id' => $id, 'canceled' => $cancel]);
|
|
self::returnJson(['success' => true]);
|
|
}
|
|
|
|
protected function createNewLogAction() {
|
|
$postData = json_decode(file_get_contents('php://input'), true);
|
|
|
|
if (empty($postData['orderRequestId']) || empty($postData['note'])) {
|
|
self::returnJson(['error' => 'Order Request ID is required']);
|
|
return;
|
|
}
|
|
|
|
WarehouseLogModel::create([
|
|
"table" => "WarehouseOrderRequest",
|
|
"rowId" => intval($postData['orderRequestId']),
|
|
"type" => 'noChanges',
|
|
"message" => $postData['note'],
|
|
"createBy" => intval($this->user->id),
|
|
"create" => time()
|
|
]);
|
|
self::returnJson(['success' => 'Log entry created']);
|
|
}
|
|
|
|
protected function getLogByIdAction() {
|
|
$orderRequestId = $this->request->orderRequestId;
|
|
if (empty($orderRequestId)) {
|
|
self::returnJson(['error' => 'Order ID is required']);
|
|
return;
|
|
}
|
|
|
|
$log = WarehouseLogModel::getAll(['table' => 'WarehouseOrderRequest', 'rowId' => $orderRequestId]);
|
|
self::returnJson($log);
|
|
}
|
|
|
|
protected function getHistoryAction() {
|
|
$this->prepareCrudConfig();
|
|
self::returnJson((new WarehouseHistoryController)->getHistory($this->request->id, $this->mod, $this->columns));
|
|
}
|
|
}
|