diff --git a/application/WarehouseOrderRequest/WarehouseOrderRequest.php b/application/WarehouseOrderRequest/WarehouseOrderRequest.php index 01379d254..17c5c45a0 100644 --- a/application/WarehouseOrderRequest/WarehouseOrderRequest.php +++ b/application/WarehouseOrderRequest/WarehouseOrderRequest.php @@ -1,9 +1,15 @@ 'id', 'text' => 'Bestellnummer', 'table' => ['filter' => false], 'modal' => false], ['key' => 'addressId', 'text' => 'Kunde', 'required' => false, 'type' => 'autocomplete', 'table' => ['class' => 'text-nowrap', 'filter' => 'autocomplete'], 'modal' => ['apiUrl' => 'Address/api?do=findAddress&fibu_primary_account=1', 'items' => '/Address/Api?do=findAddress&fibu_primary_account=1', 'type' => 'autocomplete']], ['key' => 'purpose', 'text' => 'Verwendungszweck', 'required' => true], + ['key' => 'note', 'text' => 'Notiz', 'required' => false], ['key' => 'positions', 'text' => 'Positionen', 'required' => true, 'modal' => ['type' => 'positions-manager', 'config' => [ 'header' => 'Positionen', 'fields' => [ @@ -69,10 +73,10 @@ class WarehouseOrderRequestController extends TTCrud { $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']); + if (!(WarehouseOrderRequest::get($id))) self::returnJson(['error' => 'Bestellwunsch nicht gefunden']); - $currentData = (array) WarehouseOrderRequestModel::get($id); - WarehouseOrderRequestModel::update(array_merge($currentData, ['id' => $id, 'cancelled' => $cancel])); + $currentData = (array) WarehouseOrderRequest::get($id); + WarehouseOrderRequest::update(array_merge($currentData, ['id' => $id, 'cancelled' => $cancel])); self::returnJson(['success' => true]); } @@ -86,13 +90,71 @@ class WarehouseOrderRequestController extends TTCrud { $done = filter_var($this->request->done, FILTER_VALIDATE_INT, ['options' => ['min_range' => 0, 'max_range' => 1]]); if (!$id || $done === false) self::returnJson(['error' => 'Ungültige Anfrage']); - if (!(WarehouseOrderRequestModel::get($id))) self::returnJson(['error' => 'Bestellwunsch nicht gefunden']); + if (!(WarehouseOrderRequest::get($id))) self::returnJson(['error' => 'Bestellwunsch nicht gefunden']); - $currentData = (array) WarehouseOrderRequestModel::get($id); - WarehouseOrderRequestModel::update(array_merge($currentData, ['id' => $id, 'done' => $done])); + $currentData = (array) WarehouseOrderRequest::get($id); + WarehouseOrderRequest::update(array_merge($currentData, ['id' => $id, 'done' => $done])); self::returnJson(['success' => true]); } + private function getPHPMailer() { + $mail = new PHPMailer\PHPMailer\PHPMailer(true); + try { + // Server settings + $mail->isSMTP(); + $mail->Host = TT_WAREHOUSE_ORDER_SMTP_HOST; + $mail->SMTPAuth = true; + $mail->Username = TT_WAREHOUSE_ORDER_SMTP_USER; + $mail->Password = TT_WAREHOUSE_ORDER_SMTP_PASS; + $mail->SMTPSecure = PHPMailer\PHPMailer\PHPMailer::ENCRYPTION_STARTTLS; + $mail->Port = 587; + + return $mail; + } catch (Exception $e) { + self::returnJson(['error' => 'Mailer Error: ' . $mail->ErrorInfo]); + exit; + } + } + + protected function afterCreate($orderRequest) { + try { + $mail = $this->getPHPMailer(); + + // Recipients luca@haid.in + $mail->setFrom('einkauf@xinon.at', 'XINON Einkauf'); + $mail->addAddress('luca@haid.in', 'XINON Einkauf'); + + $mail->isHTML(true); + $mail->Subject = "Neuer Bestellwunsch #" . $orderRequest['id'] . " von " . $this->user->name . ' eingelangt'; + +// build html table and fetch articleId if set else use articleId_text if its a text article + $html = ''; + $html .= ''; + foreach ($orderRequest['positions'] as $position) { + $articleId = isset($position['articleId']) ? WarehouseArticleModel::get($position['articleId'])->title : $position['articleId_text']; + $html .= ''; + $html .= ''; + $html .= ''; + $html .= ''; + $html .= ''; + } + $html .= '
ArtikelMengeZweck
' . htmlspecialchars($articleId) . '' . htmlspecialchars($position['amount']) . '' . htmlspecialchars($position['purpose']) . '
'; + + // Set the HTML content + $mail->Body = "Neuer Bestellwunsch #" . $orderRequest['id'] . " von " . $this->user->name . ' eingelangt

' . + 'Notiz: ' . htmlspecialchars($orderRequest['note']) . '

' . $html; + + // Send the email + if (!$mail->send()) { + self::returnJson(['error' => 'Message could not be sent. Mailer Error: ' . $mail->ErrorInfo]); + exit; + } + } catch (Exception $e) { + self::returnJson(['error' => 'Message could not be sent. Mailer Error: ' . $mail->ErrorInfo]); + exit; + } + } + protected function createNewLogAction() { $postData = json_decode(file_get_contents('php://input'), true); diff --git a/application/WarehouseOrderRequest/WarehouseOrderRequestModel.php b/application/WarehouseOrderRequest/WarehouseOrderRequestModel.php deleted file mode 100644 index c1ff10ad2..000000000 --- a/application/WarehouseOrderRequest/WarehouseOrderRequestModel.php +++ /dev/null @@ -1,15 +0,0 @@ -