Merge branch 'Warehouse/improve' into 'master'

fixed multiple stuff

See merge request fronk/thetool!1251
This commit is contained in:
Luca Haid
2025-04-23 20:41:52 +00:00
13 changed files with 296 additions and 735 deletions

View File

@@ -322,12 +322,23 @@ class AddressModel {
}
}
if (array_key_exists("company", $filter)) {
$company = FronkDB::singleton()->escape($filter["company"]);
if ($company) {
$where .= " AND company like '%$company%'";
if (array_key_exists("company", $filter)) {
$companyInput = trim($filter["company"]);
if ($companyInput !== '') {
$companyParts = preg_split('/\s+/', $companyInput);
$companyConditions = [];
foreach ($companyParts as $companyPart) {
$escapedCompanyPart = FronkDB::singleton()->escape($companyPart);
if ($escapedCompanyPart) {
$companyConditions[] = "company LIKE '%{$escapedCompanyPart}%'";
}
}
if (!empty($companyConditions)) {
$where .= " AND (" . implode(" AND ", $companyConditions) . ")";
}
}
}
}
if (array_key_exists("firstname", $filter)) {
$firstname = FronkDB::singleton()->escape($filter["firstname"]);
@@ -343,12 +354,22 @@ class AddressModel {
}
}
if (array_key_exists("mergedName", $filter)) {
$name = FronkDB::singleton()->escape($filter["mergedName"]);
if ($name) {
$where .= " AND (CONCAT(firstname, ' ', lastname) like '%$name%' OR CONCAT(lastname, ' ', firstname) like '%$name%' )";
if (array_key_exists("mergedName", $filter)) {
$mergedName = trim($filter["mergedName"]);
if ($mergedName !== '') {
$names = preg_split('/\s+/', $mergedName);
$conditions = [];
foreach ($names as $namePart) {
$escapedNamePart = FronkDB::singleton()->escape($namePart);
if ($escapedNamePart) {
$conditions[] = "(firstname LIKE '%{$escapedNamePart}%' OR lastname LIKE '%{$escapedNamePart}%')";
}
}
if (!empty($conditions)) {
$where .= " AND (" . implode(" AND ", $conditions) . ")";
}
}
}
}
if (array_key_exists("street", $filter)) {
$street = FronkDB::singleton()->escape($filter["street"]);

View File

@@ -3,6 +3,7 @@
class WarehouseArticleController extends TTCrud {
protected string $headerTitle = 'Artikel';
protected $createText = 'Artikel erstellen';
protected string $singleText = 'Artikel';
// @formatter:off
protected array $columns = [
@@ -16,8 +17,8 @@ class WarehouseArticleController extends TTCrud {
], 'table' => false], // Boolean value
['key' => 'cheapestPurchasePrice', 'text' => 'Einkauf', 'modal' => false, 'table' => ['class' => 'text-center', 'suffix' => ' €']],
['key' => 'cheapestSellPrice', 'text' => 'Verkauf', 'modal' => false, 'table' => ['class' => 'text-center', 'suffix' => ' €']],
['key' => 'warningAmount', 'text' => 'Warnmenge', 'required' => true,'modal' => ['type' => 'number'], 'table' => ['class' => 'text-center']], // Stock/inventory related
['key' => 'criticalAmount', 'text' => 'Kritische Menge', 'required' => true,'modal' => ['type' => 'number'], 'table' => ['class' => 'text-center']], // Stock/inventory related
['key' => 'warningAmount', 'text' => 'Warnmenge', 'required' => true,'modal' => ['type' => 'number'], 'table' => false], // Stock/inventory related
['key' => 'criticalAmount', 'text' => 'Kritische Menge', 'required' => true,'modal' => ['type' => 'number'], 'table' => false], // Stock/inventory related
['key' => 'isSerialDocumentation', 'text' => 'Seriennummern', 'required' => false,'modal' => ['type' => 'checkbox'], 'table' => false], // Boolean value
['key' => 'isEShop', 'text' => 'Ist E-Shop', 'required' => false,'modal' => ['type' => 'checkbox'], 'table' => false], // Boolean value
['key' => 'isEShopHide', 'text' => 'E-Shop Versteckt', 'required' => false,'modal' => ['type' => 'checkbox'], 'table' => false], // Boolean value
@@ -26,33 +27,18 @@ class WarehouseArticleController extends TTCrud {
protected array $autocompleteColumns = ['articleNumber', 'title', 'description', 'category'];
protected array $additionalActions = [
['key' => 'openHistory','title' => 'Historie','class' => 'fas fa-history text-secondary'],
['key' => 'editDistributorEntries','title' => 'Lieferanten','class' => 'fas fa-truck text-cyan'],
['key' => 'editThresholdEntries','title' => 'Schwellenwerte','class' => 'far fa-fw fa-box-full text-orange'],
['key' => 'editPricesEntries','title' => 'Preise','class' => 'fas fa-euro-sign text-green'],
['key' => 'addToCart','title' => 'Zur Bestellung hinzufügen','class' => 'fas fa-shopping-cart text-primary'],
];
protected array $additionalActions = [['key' => 'openHistory','title' => 'Historie','class' => 'fas fa-history text-secondary']];
// @formatter:on
protected array $additionalJSVariables = ['WAREHOUSE_ADMIN' => true];
protected array $infoMessages = ['create' => 'Artikel wurde erstellt',
'update' => 'Artikel wurde aktualisiert',
'delete' => 'Artikel wurde gelöscht',
'noChanges' => 'Keine Änderungen',];
protected function prepareCrudConfig() {
if (!$this->user->can('WarehouseAdmin')) {
// find column with key actions, cheapestPurchasePrice, warningAmount, criticalAmount and set table to false
foreach ($this->columns as $key => $column) {
if (in_array($column['key'], ['actions', 'cheapestPurchasePrice', 'warningAmount', 'criticalAmount'])) {
$this->columns[$key]['table'] = false;
}
}
$this->createText = false;
$this->additionalJSVariables['WAREHOUSE_ADMIN'] = false;
}
if ($this->user->can('WarehouseAdmin')) return;
array_walk($this->columns, fn(&$col) => in_array($col['key'], ['actions', 'cheapestPurchasePrice', 'warningAmount', 'criticalAmount']) && $col['table'] = false);
$this->createText = false;
$this->additionalJSVariables['WAREHOUSE_ADMIN'] = false;
}
protected function beforeUpdate($postData): bool {
@@ -64,28 +50,11 @@ class WarehouseArticleController extends TTCrud {
self::updateCheapestPurchasePrice($postData['id']);
}
/**
* Updates the cheapest purchase price for a given article from WarehouseArticleDistributorModel prices.
*
* @param int $articleId The ID of the article to update.
* @return void
* @throws Exception If the article is not an instance of WarehouseArticleModel.
*/
public static function updateCheapestPurchasePrice(int $articleId): void {
$article = WarehouseArticleModel::get($articleId);
if (!$article instanceof WarehouseArticleModel) {
throw new Exception("Article is not an instance of WarehouseArticleModel");
}
$order = ['key' => 'purchasePrice', 'order' => 'ASC'];
$cheapestDistributorEntry = WarehouseArticleDistributorModel::getAll(['articleId' => $articleId], 1, 0, $order);
if (empty($cheapestDistributorEntry)) return;
$cheapestPurchasePrice = $cheapestDistributorEntry[0]->purchasePrice;
if ($article->cheapestPurchasePrice == $cheapestPurchasePrice) return;
WarehouseArticleModel::update(array_merge(get_object_vars($article), ['cheapestPurchasePrice' => $cheapestPurchasePrice]));
public static function updateCheapestPurchasePrice(int $id): void {
$article = WarehouseArticleModel::get($id);
if (!$article instanceof WarehouseArticleModel) throw new Exception("Invalid article type");
if (($distributor = WarehouseArticleDistributorModel::getAll(['articleId' => $id], 1, 0, ['key' => 'purchasePrice', 'order' => 'ASC'])) && $article->cheapestPurchasePrice != $distributor[0]->purchasePrice)
WarehouseArticleModel::update(array_merge(get_object_vars($article), ['cheapestPurchasePrice' => $distributor[0]->purchasePrice]));
}
protected function afterCreate($postData) {
@@ -93,42 +62,24 @@ class WarehouseArticleController extends TTCrud {
self::updateSellPrices($postData['id']);
}
/**
* Updates the sell prices for a given article.
*
* @param int $articleId The ID of the article to update.
* @return void
* @throws Exception If the article is not an instance of WarehouseArticleModel.
*/
public static function updateSellPrices(int $articleId) {
$article = WarehouseArticleModel::get($articleId);
if (!$article instanceof WarehouseArticleModel) {
throw new Exception("Article is not an instance of WarehouseArticleModel");
public static function updateSellPrices(int $id): void { // Added return type hint
$a = WarehouseArticleModel::get($id);
if (!$a instanceof WarehouseArticleModel) throw new Exception("Invalid article type");
$aptsById = array_column(WarehouseArticlePriceModel::getAll(['articleId' => $id]), null, 'articlePriceTypeId');
$prices = [];
$cpp = $a->cheapestPurchasePrice;
foreach (WarehouseArticlePriceTypeModel::getAll() as $pt) {
$apt = $aptsById[$pt->id] ?? null;
$p = $apt ? ($apt->priceOverride ?? $apt->priceMultiplier * $cpp) : ($pt->defaultPriceFactor * $cpp);
$prices[] = ['title' => $pt->title, 'price' => round($p, 2)]; // Add title and rounded price
}
$priceTypes = WarehouseArticlePriceTypeModel::getAll();
$articlePriceTypes = WarehouseArticlePriceModel::getAll(['articleId' => $articleId]);
usort($prices, fn($x,$y)=>(match($x['title']){'Verkauf'=>1,'Partner'=>2,'Energie Steiermark'=>3,default=>4})<=>(match($y['title']){'Verkauf'=>1,'Partner'=>2,'Energie Steiermark'=>3,default=>4}));
$cheapestSellPrices = [];
// Calculate sell prices for each price type, use default sell multiplier if no specific price is set
foreach ($priceTypes as $priceType) {
$articlePriceType = null;
foreach ($articlePriceTypes as $apt) {
if ($apt->articlePriceTypeId == $priceType->id) {
$articlePriceType = $apt;
break;
}
}
$sellPrice = $priceType->defaultPriceFactor * $article->cheapestPurchasePrice;
if ($articlePriceType !== null) {
$sellPrice = $articlePriceType->priceOverride ?: $articlePriceType->priceMultiplier * $article->cheapestPurchasePrice;
}
$cheapestSellPrices[$priceType->id] = ['title' => $priceType->title, 'price' => round($sellPrice, 2)];
}
$article->cheapestSellPrice = json_encode($cheapestSellPrices);
WarehouseArticleModel::update(get_object_vars($article));
$a->cheapestSellPrice = json_encode($prices);
WarehouseArticleModel::update(get_object_vars($a));
}
public function updatePricesAction() {
@@ -142,207 +93,4 @@ class WarehouseArticleController extends TTCrud {
protected function getHistoryAction() {
self::returnJson((new WarehouseHistoryController)->getHistory($this->request->id, $this->mod, $this->columns));
}
protected function importAction() {
error_reporting(E_ALL);
ini_set('display_errors', 1);
// read import.json from directory of this file
$json = fopen(dirname(__FILE__) . '/import.json', 'r') or die('Unable to open file!');
// read file content
$data = fread($json, filesize(dirname(__FILE__) . '/import.json'));
// decode json
$data = json_decode($data, true);
// close file
fclose($json);
// die with data length
// loop through data
echo 'Importing ' . count($data) . ' items' . PHP_EOL;
$count = 0;
foreach ($data as $item) {
// echo count + 1
echo ++$count . PHP_EOL;
// Check if Distributor exists
$distributor = WarehouseDistributorModel::getAll(['name' => $item['Lieferant']]);
if (empty($distributor)) {
$distributorId = WarehouseDistributorModel::create(['name' => $item['Lieferant'],
'address' => 'Missing',
'plz' => 'Missing',
'city' => 'Missing',
'countryId' => 1,
'email' => 'Missing',
'phone' => 'Missing',
'contactPerson' => 'Missing',]);
} else {
$distributorId = $distributor[0]->id;
}
// only continue if PRODUKT 1.ZEILE and PRODUKT 2.ZEILE and ARTIKEL GRUPPE and VK and EK and Lieferant/ Hersteller Artikelnr: are set
if (!isset($item['PRODUKT 1.ZEILE'])) {
echo 'Missing data for ' . $item['PRODUKT 1.ZEILE'] . PHP_EOL;
continue;
}
if (empty($item['VK'])) {
$item['VK'] = 0;
$calcSellPriceMultiplier = 0;
} else {
$item['VK'] = floatval(str_replace(',', '', $item['VK']));
}
if (empty($item['EK'])) {
$item['EK'] = 0;
$calcSellPriceMultiplier = 0;
$purchasePrice = 0;
} else {
$item['EK'] = floatval(str_replace(',', '', $item['EK']));
}
if (!empty($item['VK']) && !empty($item['EK'])) {
$calcSellPriceMultiplier = $item['VK'] / $item['EK'];
// if calcSellPriceMultiplier has more than 2 decimal places assign $calcSellPriceOverride
echo strlen(substr(strrchr($calcSellPriceMultiplier, "."), 1)) . PHP_EOL;
if (strlen(substr(strrchr($calcSellPriceMultiplier, "."), 1)) > 2) {
$calcSellPriceOverride = $item['VK'];
}
$purchasePrice = str_replace(',', '', $item['EK']);
}
if (!isset($calcSellPriceMultiplier) && !isset($calcSellPriceOverride) || !isset($purchasePrice)) {
echo 'Missing data for ' . $item['PRODUKT 1.ZEILE'] . PHP_EOL;
continue;
}
// Check if Article exists
$article = WarehouseArticleModel::getAll(['title' => ['exact' => $item['PRODUKT 1.ZEILE']]]);
if (empty($article)) {
$articleCreateData = ['title' => $item['PRODUKT 1.ZEILE'],
'description' => $item['PRODUKT 2. ZEILE'],
'category' => $item['ARTIKEL GRUPPE'],
'cheapestPurchasePrice' => 0,
'warningAmount' => 25,
'criticalAmount' => 10,
'isEShop' => 0,];
// if calcSellPriceOverride is set, add it to the $articleCreateData array
if (isset($calcSellPriceOverride)) {
$articleCreateData['sellPriceOverride'] = $calcSellPriceOverride;
} else if (isset($calcSellPriceMultiplier)) {
$articleCreateData['sellPriceMultiplier'] = $calcSellPriceMultiplier;
}
$articleId = WarehouseArticleModel::create($articleCreateData);
} else {
echo 'Article already exists with title ' . $item['PRODUKT 1.ZEILE'] . PHP_EOL;
$articleId = $article[0]->id;
}
// Check if ArticleDistributor exists
$articleDistributor = WarehouseArticleDistributorModel::getAll(['articleId' => $articleId,
'distributorId' => $distributorId]);
if (empty($articleDistributor)) {
WarehouseArticleDistributorModel::create(['articleId' => $articleId,
'distributorId' => $distributorId,
'purchasePrice' => $purchasePrice,
'externalArticleNumber' => $item['Lieferant/ Hersteller Artikelnr:'],]);
}
}
}
protected function provArticleNumberImportAction() {
// if method is post and file is set read the csv and var dump json and die
// if method is get return basic html with a form to upload a file and a submit button
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_FILES['file'])) {
$file = fopen($_FILES['file']['tmp_name'], 'r');
$data = [];
// parse csv as object with first row as keys as header and use key => value
$firstRow = true;
while (($row = fgetcsv($file)) !== false) {
if ($firstRow) {
$header = $row;
$firstRow = false;
continue;
}
$data[] = array_combine($header, $row);
}
// loop through all the data and if PRODUKT 1.ZEILE is set and articleNumber is not set push the last 4 numbers of "EAN 13 Code" to articleNumber of the found article
foreach ($data as $item) {
if (isset($item['PRODUKT 1.ZEILE'])) {
$articles = WarehouseArticleModel::getAll(['title' => $item['PRODUKT 1.ZEILE']]);
if (!empty($articles)) {
$article = (array) WarehouseArticleModel::get($articles[0]->id);
$article['articleNumber'] = substr($item['EAN 13 Code'], -4);
WarehouseArticleModel::update($article);
}
}
}
fclose($file);
die(json_encode(['success' => true]));
}
$html = '<html><head></head><body><form method="post" enctype="multipart/form-data"><input type="file" name="file"><input type="submit"></form></body></html>';
echo $html;
die();
}
protected function prepareOrderAction() {
// inside post json it will look like
// [
// {
// "amount": "5",
// "itemId": 441,
// "title": "RT-FB-7590AX"
// },
// {
// "amount": "5",
// "itemId": 421,
// "title": "RT-FB-7590"
// }
//]
// get the json from the post request
// then create a array containing each order we need to make, so search through WarehouseArticleDistributorModel to get the distributorId and purchasePrice (use lowest purchasePrice)
// then get the WarehouseDistributorModel and then create a summary of the orders we need to make for each distributor
$postData = json_decode(file_get_contents('php://input'), true);
$orders = [];
foreach ($postData as $order) {
$articleDistributors = WarehouseArticleDistributorModel::getAll(['articleId' => $order['itemId']]);
$cheapestArticleDistributor = $articleDistributors[0];
foreach ($articleDistributors as $articleDistributor) {
if ($articleDistributor->purchasePrice < $cheapestArticleDistributor->purchasePrice) {
$cheapestArticleDistributor = $articleDistributor;
}
}
$distributor = WarehouseDistributorModel::get($cheapestArticleDistributor->distributorId);
if (!isset($orders[$distributor->id])) {
$orders[$distributor->id] = ['distributor' => array($distributor),
'orderAmount' => 0,
'orders' => []];
}
$orders[$distributor->id]['orders'][] = ['articleId' => $order['itemId'],
'amount' => $order['amount'],
'sum' => $order['amount'] * $cheapestArticleDistributor->purchasePrice,
'purchasePrice' => $cheapestArticleDistributor->purchasePrice,
'externalArticleNumber' => $cheapestArticleDistributor->externalArticleNumber,
'title' => $order['title'],];
$orders[$distributor->id]['orderAmount'] += $order['amount'] * $cheapestArticleDistributor->purchasePrice;
}
self::returnJson($orders);
}
}

View File

@@ -0,0 +1,14 @@
<?php
class WarehouseEmailQueue extends TTCrudBaseModel {
public int $id;
public string $from;
public string $fromName;
public string $to;
public string $toName;
public string $subject;
public string $body;
public int $create;
public int $createBy;
public ?int $sent;
}

View File

@@ -418,7 +418,7 @@ $appendToBody
)));
foreach ($requestIds as $requestId) {
$request = (array) WarehouseOrderRequestModel::get($requestId);
$request = (array) WarehouseOrderRequest::get($requestId);
$linkedIds = $request['linkedOrderIds'] ? json_decode($request['linkedOrderIds'], true) : [];
if ($action === 'add' && !in_array($orderId, $linkedIds)) {
@@ -432,7 +432,7 @@ $appendToBody
if ($request['linkedOrderIds'] !== $linkedIds) {
$request['linkedOrderIds'] = $linkedIds;
WarehouseOrderRequestModel::update($request);
WarehouseOrderRequest::update($request);
}
}
}

View File

@@ -75,7 +75,7 @@ class WarehouseOrderRequestController extends TTCrud {
if (!$id || $cancel === false) self::returnJson(['error' => 'Ungültige Anfrage']);
if (!(WarehouseOrderRequest::get($id))) self::returnJson(['error' => 'Bestellwunsch nicht gefunden']);
$currentData = (array) WarehouseOrderRequest::get($id);
$currentData = (array)WarehouseOrderRequest::get($id);
WarehouseOrderRequest::update(array_merge($currentData, ['id' => $id, 'cancelled' => $cancel]));
self::returnJson(['success' => true]);
}
@@ -92,66 +92,29 @@ class WarehouseOrderRequestController extends TTCrud {
if (!$id || $done === false) self::returnJson(['error' => 'Ungültige Anfrage']);
if (!(WarehouseOrderRequest::get($id))) self::returnJson(['error' => 'Bestellwunsch nicht gefunden']);
$currentData = (array) WarehouseOrderRequest::get($id);
$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();
$mail->setFrom('einkauf@xinon.at', 'XINON Einkauf');
$mail->addAddress('einkauf@xinon.at', '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 = '<table style="width: 100%; border-collapse: collapse;">';
$html .= '<tr><th style="border: 1px solid #000; padding: 8px;">Artikel</th><th style="border: 1px solid #000; padding: 8px;">Menge</th><th style="border: 1px solid #000; padding: 8px;">Zweck</th></tr>';
foreach ($orderRequest['positions'] as $position) {
$articleId = isset($position['articleId']) ? WarehouseArticleModel::get($position['articleId'])->title : $position['articleId_text'];
$html .= '<tr>';
$html .= '<td style="border: 1px solid #000; padding: 8px;">' . htmlspecialchars($articleId) . '</td>';
$html .= '<td style="border: 1px solid #000; padding: 8px;">' . htmlspecialchars($position['amount']) . '</td>';
$html .= '<td style="border: 1px solid #000; padding: 8px;">' . htmlspecialchars($position['purpose']) . '</td>';
$html .= '</tr>';
}
$html .= '</table>';
// Set the HTML content
$mail->Body = "Neuer Bestellwunsch #" . $orderRequest['id'] . " von " . $this->user->name . ' eingelangt<br><br>' .
'Notiz: ' . htmlspecialchars($orderRequest['note']) . '<br><br>' . $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;
$rows = '';
foreach ($orderRequest['positions'] as $position) {
$rows .= sprintf(
'<tr><td style="border: 1px solid #000; padding: 8px;">%s</td><td style="border: 1px solid #000; padding: 8px;">%s</td><td style="border: 1px solid #000; padding: 8px;">%s</td></tr>',
htmlspecialchars(isset($position['articleId']) ? WarehouseArticleModel::get($position['articleId'])->title : $position['articleId_text']),
htmlspecialchars($position['amount']),
htmlspecialchars($position['purpose'])
);
}
$html = '<table style="width: 100%; border-collapse: collapse;"><tr><th style="border: 1px solid #000; padding: 8px;">Artikel</th><th style="border: 1px solid #000; padding: 8px;">Menge</th><th style="border: 1px solid #000; padding: 8px;">Zweck</th></tr>' . $rows . '</table>';
WarehouseEmailQueue::create([
'from' => 'einkauf@xinon.at', 'fromName' => 'XINON Einkauf', 'to' => 'einkauf@xinon.at', 'toName' => 'XINON Einkauf',
'subject' => "Neuer Bestellwunsch #{$orderRequest['id']} eingelangt",
'body' => sprintf("Neuer Bestellwunsch #%s von %s eingelangt<br><br>Notiz: %s<br><br>%s", $orderRequest['id'], $this->user->name, htmlspecialchars($orderRequest['note']), $html),
'create' => time(), 'createBy' => intval($this->user->id),
]);
}
protected function createNewLogAction() {
@@ -162,34 +125,17 @@ class WarehouseOrderRequestController extends TTCrud {
return;
}
// send email to einkauf@xinon.at
// Instantiate PHPMailer
$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;
// Recipients
$mail->setFrom('einkauf@xinon.at', 'XINON Einkauf');
$mail->addAddress('einkauf@xinon.at', 'XINON Einkauf');
// Content
$mail->isHTML(true);
$mail->Subject = "Neue Nachricht zu Besteallwunsch #" . $postData['orderRequestId'];
$mail->Body = $postData['note'];
$mail->send();
} catch (Exception $e) {
self::returnJson(['error' => 'Message could not be sent. Mailer Error: ' . $mail->ErrorInfo]);
exit;
}
if (intval($this->user->id !== 1) && intval($this->user->id !== 7))
WarehouseEmailQueue::create([
'from' => 'einkauf@xinon.at',
'fromName' => 'XINON Einkauf',
'to' => 'einkauf@xinon.at',
'toName' => 'XINON Einkauf',
'subject' => 'Neue Nachricht zu Besteallwunsch #' . $postData['orderRequestId'],
'body' => $postData['note'],
'create' => date('U'),
'createBy' => intval($this->user->id),
]);
WarehouseLogModel::create([
"table" => "WarehouseOrderRequest",