Updated WarehouseOrder and WarehouseOrderRequest
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user