Merge branch 'bugfix/e-shop' into 'master'
added shipping notes for warehouse e shop See merge request fronk/thetool!659
This commit is contained in:
@@ -42,6 +42,7 @@ class WarehouseEShopOrderController extends TTCrud {
|
||||
|
||||
protected array $additionalActions = [['key' => 'openHistory', 'title' => 'Historie', 'class' => 'fas fa-history text-primary'],
|
||||
['key' => 'showTrackingHistory', 'title' => 'Tracking Historie', 'class' => 'fas fa-truck text-primary'],
|
||||
['key' => 'createShippingNote', 'title' => 'Lieferschein erstellen', 'class' => 'fas fa-file-invoice text-primary'],
|
||||
['key' => 'openSingleOrderEmail', 'title' => 'Bestellbestätigung', 'class' => 'fas fa-envelope text-primary'],];
|
||||
|
||||
protected array $infoMessages = ['create' => 'Bestellung wurde erfolgreich erstellt, sie erhalten in Kürze eine Bestätigungsmail',
|
||||
@@ -61,6 +62,75 @@ class WarehouseEShopOrderController extends TTCrud {
|
||||
$this->columns[10]['modal']['items'] = $users;
|
||||
}
|
||||
|
||||
protected function createShippingNote() {
|
||||
$id = $this->request->id;
|
||||
if (!$id) {
|
||||
self::returnJson(['success' => false, 'message' => 'Keine ID angegeben']);
|
||||
die();
|
||||
}
|
||||
|
||||
$existingShippingNote = WarehouseShippingNoteModel::getAll(['eShopOrderId' => $id]);
|
||||
if (!empty($existingShippingNote)) {
|
||||
self::returnJson(['success' => false, 'message' => 'Für diese Bestellung existiert bereits ein Lieferschein', 'shippingNoteId' => $existingShippingNote[0]->id]);
|
||||
die();
|
||||
}
|
||||
|
||||
$order = WarehouseEShopOrderModel::get($id);
|
||||
$orderItems = WarehouseEShopOrderItemModel::getAll(['orderId' => $id]);
|
||||
|
||||
$articles = WarehouseArticleModel::getAll();
|
||||
$articlePackets = WarehouseArticlePacketModel::getAll();
|
||||
|
||||
$positions = [];
|
||||
foreach ($orderItems as $item) {
|
||||
$newEntry = [];
|
||||
$article = $item->articleId ? array_search($item->articleId, array_column($articles, 'id')) : null;
|
||||
$articlePacket = $item->articlePacketId ? array_search($item->articlePacketId, array_column($articlePackets, 'id')) : null;
|
||||
|
||||
$articleTitle = $item->articleId ? $articles[$article]->title : $articlePackets[$articlePacket]->title;
|
||||
$quantity = $item->quantity;
|
||||
$price = 0;
|
||||
if ($item->articleId) {
|
||||
$cheapestSellPrice = json_decode($articles[$article]->cheapestSellPrice, true);
|
||||
foreach ($cheapestSellPrice as $price) {
|
||||
if ($price['title'] === 'Energie Steiermark') {
|
||||
$price = $price['price'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$price = $articlePackets[$articlePacket]->overrideSellPrice ?? $articlePackets[$articlePacket]->calculatedSellPrice;
|
||||
}
|
||||
|
||||
if ($item->articleId) {
|
||||
$newEntry['article'] = $item->articleId;
|
||||
} else {
|
||||
$newEntry['articlePacket'] = $item->articlePacketId;
|
||||
}
|
||||
$newEntry['amount'] = $quantity;
|
||||
$newEntry['price'] = $price;
|
||||
|
||||
$positions[] = $newEntry;
|
||||
}
|
||||
|
||||
$positions = json_encode($positions);
|
||||
|
||||
$shippingNoteId = WarehouseShippingNoteModel::create(['billingAddressId' => 3265,
|
||||
'deliveryAddressName' => $order->deliveryAddressName,
|
||||
'deliveryAddressLine' => $order->deliveryAddressLine,
|
||||
'deliveryAddressPLZ' => $order->deliveryAddressPLZ,
|
||||
'deliveryAddressCity' => $order->deliveryAddressCity,
|
||||
'status' => 'new',
|
||||
'positions' => $positions,
|
||||
'textElements' => '[]',
|
||||
'eShopOrderId' => $id,
|
||||
'create' => time(),
|
||||
'createBy' => $this->user->id]);
|
||||
|
||||
self::returnJson(['success' => true, 'message' => 'Lieferschein wurde erstellt', 'shippingNoteId' => $shippingNoteId]);
|
||||
|
||||
}
|
||||
|
||||
protected function singleOrderEmailAction() {
|
||||
// this has dryRun and id in get parameter create a E-Mail Body like the things below
|
||||
$isDryRun = $this->request->dryRun ?? false;
|
||||
@@ -110,7 +180,6 @@ class WarehouseEShopOrderController extends TTCrud {
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected function CSVExportNewOrdersMarkAcceptedAction($returnCSV = false, $orderIds = []) {
|
||||
ini_set('display_errors', 1);
|
||||
ini_set('display_startup_errors', 1);
|
||||
@@ -318,6 +387,18 @@ class WarehouseEShopOrderController extends TTCrud {
|
||||
self::returnJson((new WarehouseHistoryController)->getHistory($this->request->id, $this->mod, $this->columns));
|
||||
}
|
||||
|
||||
protected function fetchGLSTrackingAction() {
|
||||
$orderId = $this->request->id;
|
||||
|
||||
$order = WarehouseEShopOrderModel::get($orderId);
|
||||
$trackingNumber = $order->trackingNumber;
|
||||
$plz = $order->deliveryAddressPLZ;
|
||||
|
||||
$tracking = $this->GLSTrackingApi($trackingNumber, $plz);
|
||||
$this->checkAndUpdateTrackingState($tracking, $orderId);
|
||||
die($tracking);
|
||||
}
|
||||
|
||||
protected function GLSTrackingApi($trackingNumber, $plz) {
|
||||
$url = "https://gls-group.eu/app/service/open/rest/AT/de/rstt028/$trackingNumber?postalCode=$plz";
|
||||
return file_get_contents($url);
|
||||
@@ -342,18 +423,6 @@ class WarehouseEShopOrderController extends TTCrud {
|
||||
}
|
||||
}
|
||||
|
||||
protected function fetchGLSTrackingAction() {
|
||||
$orderId = $this->request->id;
|
||||
|
||||
$order = WarehouseEShopOrderModel::get($orderId);
|
||||
$trackingNumber = $order->trackingNumber;
|
||||
$plz = $order->deliveryAddressPLZ;
|
||||
|
||||
$tracking = $this->GLSTrackingApi($trackingNumber, $plz);
|
||||
$this->checkAndUpdateTrackingState($tracking, $orderId);
|
||||
die($tracking);
|
||||
}
|
||||
|
||||
protected function readGLSEmailAction() {
|
||||
$host = '{mail.xinon.at:993/imap/ssl/novalidate-cert}INBOX';
|
||||
$mbox = imap_open($host, 'eshop-versand@xinon.at', 'savemanfb545aw');
|
||||
@@ -408,7 +477,9 @@ class WarehouseEShopOrderController extends TTCrud {
|
||||
// END TRACKING NUMBER PARSING
|
||||
|
||||
|
||||
$orders = WarehouseEShopOrderModel::getAll(['deliveryAddressLine' => $addressLine, 'deliveryAddressPLZ' => $plz, 'deliveryAddressCity' => $city]);
|
||||
$orders = WarehouseEShopOrderModel::getAll(['deliveryAddressLine' => $addressLine,
|
||||
'deliveryAddressPLZ' => $plz,
|
||||
'deliveryAddressCity' => $city]);
|
||||
if (empty($orders)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -182,11 +182,19 @@ class WarehouseShippingNoteController extends TTCrud {
|
||||
|
||||
// loop through all positions and add articleTitle and articleDescription to each position entry
|
||||
foreach (json_decode($shippingNote->positions, true) as $position) {
|
||||
$article = WarehouseArticleModel::get($position['article']);
|
||||
$position['articleTitle'] = $article->title;
|
||||
$position['articleDescription'] = $article->description;
|
||||
$position['articleUnit'] = $article->unit;
|
||||
$positions[] = $position;
|
||||
if (isset($position['article'])) {
|
||||
$article = WarehouseArticleModel::get($position['article']);
|
||||
$position['articleTitle'] = $article->title;
|
||||
$position['articleDescription'] = $article->description === $article->title ? "" : $article->description;
|
||||
$position['articleUnit'] = $article->unit;
|
||||
$positions[] = $position;
|
||||
} elseif (isset($position['articlePacket'])) {
|
||||
$articlePacket = WarehouseArticlePacketModel::get($position['articlePacket']);
|
||||
$position['articleTitle'] = $articlePacket->title;
|
||||
$position['articleDescription'] = $articlePacket->description === $articlePacket->title ? "" : $articlePacket->description;
|
||||
$position['articleUnit'] = 'Stk.';
|
||||
$positions[] = $position;
|
||||
}
|
||||
}
|
||||
|
||||
$textElements = [];
|
||||
|
||||
@@ -10,6 +10,7 @@ class WarehouseShippingNoteModel extends TTCrudBaseModel {
|
||||
public string $status; // 'new'|'accepted'|'invoiced'
|
||||
public string $positions;
|
||||
public string $textElements;
|
||||
public ?int $eShopOrderId;
|
||||
public int $create;
|
||||
public int $createBy;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user