Merge branch 'warehouse-order-improvements' into 'master'
Updated WarehouseOrder and WarehouseOrderRequest See merge request fronk/thetool!1075
This commit is contained in:
@@ -73,4 +73,19 @@ class FileController extends mfBaseController {
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function getByIdAction() {
|
||||
$file = new File($this->request->id);
|
||||
|
||||
if (!$file->id) {
|
||||
http_response_code(404);
|
||||
self::returnJson(["error" => "File not found"]);
|
||||
return;
|
||||
}
|
||||
|
||||
self::returnJson([
|
||||
"id" => $file->id,
|
||||
"filename" => $file->orig_filename
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -442,4 +442,10 @@ class UserController extends mfBaseController
|
||||
|
||||
return ["valid_to" => null];
|
||||
}
|
||||
|
||||
protected function getByIdAction() {
|
||||
$id = $this->request->id;
|
||||
$user = new User($id);
|
||||
$this->returnJson($user->toArray());
|
||||
}
|
||||
}
|
||||
|
||||
9
application/WarehouseLog/WarehouseLog.php
Normal file
9
application/WarehouseLog/WarehouseLog.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @property mixed|null $name
|
||||
*/
|
||||
class WarehouseLog extends mfBaseModel
|
||||
{
|
||||
|
||||
}
|
||||
12
application/WarehouseLog/WarehouseLogModel.php
Normal file
12
application/WarehouseLog/WarehouseLogModel.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
class WarehouseLogModel extends TTCrudBaseModel {
|
||||
public int $id;
|
||||
public string $table;
|
||||
public int $rowId;
|
||||
public string $type;
|
||||
public ?string $fileIds;
|
||||
public string $message;
|
||||
public int $create;
|
||||
public int $createBy;
|
||||
}
|
||||
@@ -18,7 +18,15 @@ class WarehouseOrderController extends TTCrud {
|
||||
['key' => 'editor', 'text' => 'Bearbeiter', 'required' => true, 'modal' => ['type' => 'select'], 'table' => ['filter' => 'select']],
|
||||
['key' => 'note', 'text' => 'Notiz', 'required' => false, 'modal' => false, 'table' => false],
|
||||
['key' => 'sum', 'text' => 'Summe', 'required' => false, 'modal' => false, 'table' => ['class' => 'text-right']],
|
||||
['key' => 'status', 'text' => 'Status', 'required' => false, 'modal' => ['type' => 'select', 'items' => []], 'table' => ['filter' => 'select']],
|
||||
['key' => 'status', 'text' => 'Status', 'required' => false, 'modal' => ['type' => 'select', 'items' => [
|
||||
['value' => 'new', 'text' => 'Neu'],
|
||||
['value' => 'accepted', 'text' => 'Akzeptiert'],
|
||||
['value' => 'ordered', 'text' => 'Bestellt'],
|
||||
['value' => 'sent', 'text' => 'Versendet'],
|
||||
['value' => 'partiallyDelivered', 'text' => 'Teilweise geliefert'],
|
||||
['value' => 'fullyDelivered', 'text' => 'Geliefert'],
|
||||
['value' => 'cancelled', 'text' => 'Storniert'],
|
||||
]], 'table' => ['filter' => 'select']],
|
||||
['key' => 'positions', 'text' => 'Positionen', 'required' => true, 'modal' => false, 'table' => false],
|
||||
['key' => 'extReference', 'text' => 'Externe Referenz', 'required' => false, 'modal' => false],
|
||||
['key' => 'createBy', 'text' => 'Erstellt von', 'required' => true, 'modal' => ['type' => 'select'], 'table' => ['filter' => 'select']],
|
||||
@@ -40,21 +48,17 @@ class WarehouseOrderController extends TTCrud {
|
||||
return ['value' => intval($user->id), 'text' => $user->name];
|
||||
}, UserModel::search(['employee' => true]));
|
||||
|
||||
$statusIndex = array_search('status', array_column($this->columns, 'key'));
|
||||
$this->columns[$statusIndex]['modal']['items'] = [
|
||||
['value' => 'new', 'text' => 'Neu'],
|
||||
['value' => 'accepted', 'text' => 'Akzeptiert'],
|
||||
['value' => 'ordered', 'text' => 'Bestellt'],
|
||||
['value' => 'sent', 'text' => 'Versendet'],
|
||||
['value' => 'partiallyDelivered', 'text' => 'Teilweise geliefert'],
|
||||
['value' => 'fullyDelivered', 'text' => 'Geliefert'],
|
||||
['value' => 'cancelled', 'text' => 'Storniert'],
|
||||
];
|
||||
|
||||
$distributorIndex = array_search('distributorId', array_column($this->columns, 'key'));
|
||||
$this->columns[$distributorIndex]['modal']['items'] = array_map(function ($distributor) {
|
||||
return ['value' => intval($distributor->id), 'text' => $distributor->name];
|
||||
}, WarehouseDistributorModel::getAll());
|
||||
|
||||
$this->additionalActions[] = [
|
||||
'key' => 'changeStatus',
|
||||
'title' => 'Status ändern',
|
||||
'class' => 'fas fa-exchange-alt',
|
||||
'color' => 'warning',
|
||||
];
|
||||
}
|
||||
|
||||
protected function beforeCreate(): bool {
|
||||
@@ -116,8 +120,7 @@ class WarehouseOrderController extends TTCrud {
|
||||
|
||||
$headerHtml = file_get_contents(BASEDIR . "/Layout/default/WarehouseOrder/PDF_HEADER.html");
|
||||
$headerHtml = str_replace("{{ basedir }}", BASEDIR, $headerHtml);
|
||||
$headerHtml = str_replace("{{ externalReference }}", count($order['extReference']) > 0 ? "<strong>Ext. Ref.:</strong> ". $order['extReference'] : "", $headerHtml);
|
||||
|
||||
$headerHtml = str_replace("{{ externalReference }}", !empty($order['extReference']) && count($order['extReference']) > 0 ? "<strong>Ext. Ref.:</strong> ". $order['extReference'] : "", $headerHtml);
|
||||
$headerHtml = str_replace("{{ addressLine_header }}", $shouldGenerateEnglisch ? "Supplier" : "Lieferant", $headerHtml);
|
||||
$headerHtml = str_replace("{{ addressLine_1 }}", WarehouseDistributorModel::get($distributorId)->name, $headerHtml);
|
||||
$headerHtml = str_replace("{{ addressLine_2 }}", WarehouseDistributorModel::get($distributorId)->address, $headerHtml);
|
||||
@@ -165,5 +168,110 @@ class WarehouseOrderController extends TTCrud {
|
||||
|
||||
}
|
||||
|
||||
protected function getLogAction() {
|
||||
$orderId = $this->request->orderId;
|
||||
if (empty($orderId)) {
|
||||
self::returnJson(['error' => 'Order ID is required']);
|
||||
return;
|
||||
}
|
||||
|
||||
$logs = WarehouseLogModel::getAll(['table' => 'WarehouseOrder','rowId' => $orderId], ['timestamp' => 'DESC']);
|
||||
self::returnJson($logs);
|
||||
}
|
||||
|
||||
protected function createNewLogAction() {
|
||||
$postData = json_decode(file_get_contents('php://input'), true);
|
||||
|
||||
if (empty($postData['orderId']) || empty($postData['status'])) {
|
||||
self::returnJson(['error' => 'Order ID and Status are required']);
|
||||
return;
|
||||
}
|
||||
|
||||
$log = [
|
||||
"table" => "WarehouseOrder",
|
||||
"rowId" => intval($postData['orderId']),
|
||||
"type" => $postData['status'] === 'noChanges' ? 'noChanges' : 'statusChange',
|
||||
"fileIds" => $postData['fileIds'] ?? null,
|
||||
"message" => $postData['note'] ?? null,
|
||||
"createBy" => intval($this->user->id),
|
||||
"create" => time()
|
||||
];
|
||||
|
||||
try {
|
||||
$order = WarehouseOrderModel::get($log['orderId']);
|
||||
if ($postData['status'] !== 'noChanges') {
|
||||
$oldStatusText = array_values(array_filter($this->columns, fn($c) => $c['key'] === 'status'))[0]['modal']['items'][array_search($order->status, array_column(array_values(array_filter($this->columns, fn($c) => $c['key'] === 'status'))[0]['modal']['items'], 'value'))]['text'];
|
||||
$newStatusText = array_values(array_filter($this->columns, fn($c) => $c['key'] === 'status'))[0]['modal']['items'][array_search($postData['status'], array_column(array_values(array_filter($this->columns, fn($c) => $c['key'] === 'status'))[0]['modal']['items'], 'value'))]['text'];
|
||||
$log['message'] = 'Status wurde geändert von ' . $oldStatusText . ' auf ' . $newStatusText . ($log['message'] ? ': ' . $log['message'] : '');
|
||||
$order->status = $postData['status'];
|
||||
$order = (array) $order;
|
||||
WarehouseOrderModel::update($order);
|
||||
}
|
||||
|
||||
WarehouseLogModel::create($log);
|
||||
self::returnJson(['success' => 'Log entry created']);
|
||||
} catch (Exception $e) {
|
||||
self::returnJson(['error' => 'Error creating log entry']);
|
||||
}
|
||||
}
|
||||
|
||||
protected function uploadFileAction() {
|
||||
if (!isset($_FILES['file']) || $_FILES['file']['error'] !== UPLOAD_ERR_OK) {
|
||||
self::returnJson(['error' => 'No file uploaded or upload error occurred']);
|
||||
return;
|
||||
}
|
||||
|
||||
$_FILES = ['WarehouseOrder' => $_FILES['file']];
|
||||
|
||||
try {
|
||||
$file = mfUpload::handleFormUpload("WarehouseOrder", false, "/WarehouseOrder");
|
||||
|
||||
// Return the file ID
|
||||
self::returnJson(['success' => true, 'fileId' => $file->id]);
|
||||
} catch (Exception $ex) {
|
||||
self::returnJson(['error' => 'Error uploading file: ' . $ex->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected function getLogByIdAction() {
|
||||
$orderId = $this->request->id;
|
||||
if (empty($orderId)) {
|
||||
self::returnJson(['error' => 'Order ID is required']);
|
||||
return;
|
||||
}
|
||||
|
||||
$log = WarehouseLogModel::getAll(['table' => 'WarehouseOrder', 'rowId' => $orderId]);
|
||||
self::returnJson($log);
|
||||
}
|
||||
|
||||
|
||||
protected function afterUpdate($postData) {
|
||||
$this->updateOrderRequestLinkedOrderIds($postData['id']);
|
||||
}
|
||||
|
||||
protected function afterCreate($postData) {
|
||||
$this->updateOrderRequestLinkedOrderIds($postData['id']);
|
||||
}
|
||||
protected function updateOrderRequestLinkedOrderIds($id) {
|
||||
$order = (array) WarehouseOrderModel::get($id);
|
||||
foreach (json_decode($order['positions'], true) as $position) {
|
||||
if (!empty($position['linkedOrderRequestId'])) {
|
||||
$warehouseOrderRequest = (array) WarehouseOrderRequestModel::get($position['linkedOrderRequestId']);
|
||||
if (is_null($warehouseOrderRequest['linkedOrderIds'])) {
|
||||
$warehouseOrderRequest['linkedOrderIds'] = [$id];
|
||||
WarehouseOrderRequestModel::update($warehouseOrderRequest);
|
||||
} else {
|
||||
if (!in_array($id, $warehouseOrderRequest['linkedOrderIds'])) {
|
||||
$warehouseOrderRequest['linkedOrderIds'][] = $id;
|
||||
WarehouseOrderRequestModel::update($warehouseOrderRequest);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
<?php
|
||||
//TODO: migration for extReference
|
||||
/**
|
||||
* Class WarehouseOrderModel
|
||||
*
|
||||
@@ -25,6 +24,7 @@ class WarehouseOrderModel extends TTCrudBaseModel {
|
||||
public string $orderNumber;
|
||||
public ?string $extReference;
|
||||
public int $distributorId;
|
||||
public ?string $status;
|
||||
public string $delAddrCity;
|
||||
public string $delAddrEMail;
|
||||
public string $delAddrLine;
|
||||
|
||||
@@ -1,107 +1,56 @@
|
||||
<?php
|
||||
//TODO: enable switching distributors in the order preview
|
||||
<?php /** @noinspection PhpVoidFunctionResultUsedInspection */
|
||||
|
||||
class WarehouseOrderRequestController extends TTCrud {
|
||||
protected string $headerTitle = 'Bestellwünsche';
|
||||
protected string $createText = 'Bestellwunsch erstellen';
|
||||
protected string $createText = 'Neuer Bestellwunsch';
|
||||
protected string $singleText = 'Bestellwunsch';
|
||||
|
||||
//@formatter:off
|
||||
protected array $columns = [
|
||||
['key' => 'id', 'text' => 'ID', 'modal' => false, 'table' => false],
|
||||
['key' => 'ware',
|
||||
'text' => 'Ware',
|
||||
'required' => true,
|
||||
'type' => 'autocomplete',
|
||||
'table' => ['class' => 'text-nowrap', 'filter' => 'autocomplete'],
|
||||
'modal' => [
|
||||
'apiUrl' => 'WarehouseArticle/autocomplete',
|
||||
'type' => 'autocomplete',
|
||||
'returnText' => true]],
|
||||
['key' => 'anzahl', 'text' => 'Anzahl', 'required' => true, 'type' => 'number'],
|
||||
['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' => 'canceled',
|
||||
'text' => 'Storniert',
|
||||
'required' => false,
|
||||
'modal' => ['visible' => false, 'type' => 'select', 'items' => [['value' => 0, 'text' => 'Nein'], ['value' => 1, 'text' => 'Ja']]],
|
||||
'table' => ['filter' => 'select']],
|
||||
['key' => 'note', 'text' => 'Notiz', 'required' => false, 'type' => 'textarea'],
|
||||
['key' => 'actions',
|
||||
'text' => 'Aktionen',
|
||||
'required' => false,
|
||||
'modal' => false,
|
||||
'table' => ['filter' => false, 'sortable' => false, 'class' => 'text-center']],
|
||||
['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']];
|
||||
|
||||
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', 'WAREHOUSE_ADMIN' => true];
|
||||
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() {
|
||||
// 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;
|
||||
}
|
||||
|
||||
$this->additionalJSVariables['user_id'] = $this->user->id;
|
||||
if (!$this->user->can('WarehouseAdmin')) {
|
||||
$this->additionalJSVariables['WAREHOUSE_ADMIN'] = 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];
|
||||
$this->additionalJSVariables = [
|
||||
'user_id' => $this->user->id,
|
||||
'BASE_URL' => '/WarehouseOrderRequest',
|
||||
'WAREHOUSE_ADMIN' => $this->user->can('WarehouseAdmin')
|
||||
];
|
||||
}
|
||||
|
||||
protected function beforeUpdate($postData): bool {
|
||||
@@ -110,62 +59,73 @@ class WarehouseOrderRequestController extends TTCrud {
|
||||
}
|
||||
|
||||
protected function afterCreate($postData): void {
|
||||
if ($_SERVER['HTTP_HOST'] == 'localhost') return;
|
||||
|
||||
if (is_numeric($postData['ware'])) {
|
||||
$article = WarehouseArticleModel::get(intval($postData['ware']));
|
||||
$postData['ware'] = $article->title;
|
||||
}
|
||||
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");
|
||||
|
||||
$body = "Hallo,\n\nes wurde eine neue interne Bestellung erstellt.\n\n";
|
||||
$body .= "Bestellnummer: #$paddedId\n";
|
||||
$body .= "Ware: " . $postData['ware'] . "\n";
|
||||
$body .= "Anzahl: " . $postData['anzahl'] . "\n";
|
||||
$body .= "Verwendungszweck: " . $postData['verwendungszweck'] . "\n";
|
||||
$body .= "Beauftragt von: " . $this->user->name . "\n";
|
||||
$body .= "Beauftragt am: " . date('d.m.Y H:i') . "\n";
|
||||
$body .= "Notiz: " . $postData['note'] . "\n\n";
|
||||
$email->setSubject("TheTool: Neue Interne Bestellung #$paddedId")
|
||||
->setBody(<<<BODY
|
||||
Hallo,
|
||||
|
||||
$email->setBody($body);
|
||||
$email->setFrom(TT_OUTGOING_EMAIL_2FA, TT_OUTGOING_EMAIL_2FA);
|
||||
$email->setTo("einkauf@xinon.at", "Einkauf");
|
||||
$email->send();
|
||||
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 = $this->request->id;
|
||||
$cancel = $this->request->cancel;
|
||||
$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 (!is_numeric($id) || !is_numeric($cancel)) {
|
||||
self::returnJson(['error' => 'Invalid request']);
|
||||
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;
|
||||
}
|
||||
|
||||
$order = (array) WarehouseOrderRequestModel::get($id);
|
||||
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']);
|
||||
}
|
||||
|
||||
if (empty($order)) {
|
||||
self::returnJson(['error' => 'Order not found']);
|
||||
protected function getLogByIdAction() {
|
||||
$orderRequestId = $this->request->orderRequestId;
|
||||
if (empty($orderRequestId)) {
|
||||
self::returnJson(['error' => 'Order ID is required']);
|
||||
return;
|
||||
}
|
||||
|
||||
// $cancel is either 0 for uncancelling or 1 for cancelling
|
||||
|
||||
if ($cancel == 1) {
|
||||
$order['canceled'] = 1;
|
||||
} else {
|
||||
$order['canceled'] = 0;
|
||||
}
|
||||
|
||||
$order['id'] = $id;
|
||||
|
||||
if (!WarehouseOrderRequestModel::update($order)) {
|
||||
self::returnJson(['error' => 'Error updating order']);
|
||||
}
|
||||
|
||||
self::returnJson(['success' => true, 'message' => 'Order updated']);
|
||||
|
||||
$log = WarehouseLogModel::getAll(['table' => 'WarehouseOrderRequest', 'rowId' => $orderRequestId]);
|
||||
self::returnJson($log);
|
||||
}
|
||||
|
||||
protected function getHistoryAction() {
|
||||
|
||||
@@ -2,19 +2,12 @@
|
||||
|
||||
class WarehouseOrderRequestModel extends TTCrudBaseModel {
|
||||
public int $id;
|
||||
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 $purpose;
|
||||
public string $positions;
|
||||
public ?string $note;
|
||||
|
||||
public ?int $canceled;
|
||||
public ?string $linkedOrderIds;
|
||||
public ?int $cancelled;
|
||||
public int $create;
|
||||
public int $createBy;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,34 +3,45 @@
|
||||
class WarehouseProjectController extends TTCrud {
|
||||
protected string $headerTitle = 'Projekte';
|
||||
protected string $createText = 'Neues Projekt erstellen';
|
||||
protected string $singleText = 'Projekt';
|
||||
|
||||
//@formatter:off
|
||||
protected array $columns = [
|
||||
['key' => 'title', 'text' => 'Titel', 'required' => true, 'table' => ['class' => 'text-nowrap', 'priority' => 9]],
|
||||
['key' => 'description', 'text' => 'Beschreibung', 'required' => true, 'table' => ['class' => 'text-nowrap']],
|
||||
['key' => 'createBy', 'text' => 'Erstellt von', 'required' => true, 'type' => 'select', 'table' => ['class' => 'text-nowrap', 'filter' => 'select'], 'modal' => ['items' => [], 'type' => 'select']],
|
||||
['key' => 'create', 'text' => 'Erstellt am', 'required' => true, 'table' => ['filter' => 'date', 'class' => 'text-center']],
|
||||
['key' => 'address', 'text' => 'Adresse', 'required' => true, 'type' => 'autocomplete', 'table' => ['class' => 'text-nowrap', 'filter' => false], 'modal' => ['apiUrl' => '/Address/api?do=findAddress', 'items' => '/Address/api?do=findAddress', 'type' => 'autocomplete']],
|
||||
['key' => 'status', 'text' => 'Status', 'required' => true, 'table' => ['filter' => 'select'], 'modal' => [ 'type' => 'select', 'items' => [ ['value' => 'erstellt', 'text' => 'Erstellt'], ['value' => 'in_bearbeitung', 'text' => 'In Bearbeitung'], ['value' => 'erledigt', 'text' => 'Erledigt'], ['value' => 'verrechnet', 'text' => 'Verrechnet']]]]
|
||||
];
|
||||
['key' => 'title', 'text' => 'Titel', 'required' => true],
|
||||
['key' => 'description', 'text' => 'Projektbeschreibung', 'modal' => ['type' => 'textarea']],
|
||||
|
||||
['key' => 'startDate', 'text' => 'Startdatum', 'required' => true, 'modal' => ['type' => 'datepicker']],
|
||||
['key' => 'endDate', 'text' => 'Enddatum', 'required' => true, 'modal' => ['type' => 'datepicker']],
|
||||
['key' => 'positions', 'text' => 'Positionen', 'required' => true, 'modal' => ['type' => 'positions-manager', 'config' => [
|
||||
'header' => 'Positionen',
|
||||
'fields' => [
|
||||
'articleId' => ['apiUrl' => '/WarehouseArticle/autoComplete','type' => 'autocomplete','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' => 'assignedPersons', 'text' => 'Zugewiesene Personen', 'modal' => ['type' => 'positions-manager', 'config' => [
|
||||
'header' => 'Zugewiesene Personen',
|
||||
'fields' => [
|
||||
'userId' => ['apiUrl' => '/WarehouseShippingNote/userAutoComplete','type' => 'autocomplete','label' => 'Person','customFieldReference' => 'User']
|
||||
],
|
||||
'validateFormOptions' => [
|
||||
['key' => 'userId', 'message' => 'Bitte füllen Sie die Person aus'],
|
||||
],
|
||||
]], 'table' => false],
|
||||
|
||||
protected array $additionalActions = [
|
||||
];
|
||||
|
||||
protected array $infoMessages = [
|
||||
'create' => 'Projekt wurde erstellt',
|
||||
'update' => 'Projekt wurde aktualisiert',
|
||||
'delete' => 'Projekt wurde gelöscht',
|
||||
'noChanges' => 'Keine Änderungen',
|
||||
['key' => 'storageLocation', 'text' => 'Lagerort', 'modal' => ['type' => 'input']],
|
||||
['key' => 'note', 'text' => 'Notiz', 'modal' => ['type' => 'textarea']],
|
||||
['key' => 'createBy', 'text' => 'Erstellt von', 'required' => true, 'modal' => ['visible' => false, 'type' => 'select'], 'table' => ['filter' => 'select']],
|
||||
['key' => 'create', 'text' => 'Erstellt', 'required' => true, 'modal' => false],
|
||||
['key' => 'actions', 'text' => 'Aktionen', 'required' => false, 'modal' => false, 'table' => ['filter' => false, 'sortable' => false, 'class' => 'text-center']],
|
||||
];
|
||||
//@formatter:on
|
||||
|
||||
public function prepareCrudConfig() {
|
||||
$users = array_map(function($user) {
|
||||
return ['value' => $user->id, 'text' => $user->name];
|
||||
}, UserModel::search(['employee' => true]));
|
||||
|
||||
$this->columns[1]['modal']['items'] = $users;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user