From fee73ab5f26dafc51dfc0f9b38f186b442878cc8 Mon Sep 17 00:00:00 2001 From: Luca Haid Date: Mon, 28 Apr 2025 13:37:58 +0200 Subject: [PATCH] added new way to select areas for shipping note --- .../WarehouseShippingNoteController.php | 15 +++++++++++++-- .../WarehouseShippingNoteModal.js | 13 ++++++++++--- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/application/WarehouseShippingNote/WarehouseShippingNoteController.php b/application/WarehouseShippingNote/WarehouseShippingNoteController.php index b3c8b3810..084e286ff 100644 --- a/application/WarehouseShippingNote/WarehouseShippingNoteController.php +++ b/application/WarehouseShippingNote/WarehouseShippingNoteController.php @@ -452,15 +452,25 @@ class WarehouseShippingNoteController extends TTCrud { } $parsedDisplayNameParts[] = $part; } - $out[] = ['value' => $entry['lat'] . "," . $entry['lon'], 'text' => implode(',', $parsedDisplayNameParts)]; + + if (!empty($out)) { + foreach ($out as $key => $value) { + if ($value['text'] === implode(',', $parsedDisplayNameParts)) { + continue 2; + } + } + } + $out[] = ['value' => $entry['lat'] . "," . $entry['lon'] . (!isset($entry['house_number']) ? ", area" : ""), 'text' => implode(',', $parsedDisplayNameParts)]; } + + self::returnJson($out); } protected function geoReverseAction() { $lat = $this->request->lat; $lon = $this->request->lon; - $url = "https://nominatim.haid.in/reverse?lat=$lat&lon=$lon&format=json"; + $url = "https://nominatim.haid.in/reverse?lat=$lat&lon=$lon&format=json&addressdetails=1"; $data = json_decode(file_get_contents($url), true); self::returnJson(is_array($data) ? $data : ['data' => $data]); } @@ -468,6 +478,7 @@ class WarehouseShippingNoteController extends TTCrud { //TODO: export this to an api class for openstreetmap protected function getDistanceAction() { + $this->request->to = str_replace("Gebiet ", "", $this->request->to); $filename = TEMP_DIR . "/OpenStreetMap/" . urlencode($this->request->from) . "-" . urlencode($this->request->to) . ".json"; if (file_exists($filename)) { diff --git a/public/js/pages/WarehouseShippingNote/WarehouseShippingNoteModal.js b/public/js/pages/WarehouseShippingNote/WarehouseShippingNoteModal.js index 0bcfe19a0..32f8bb6e3 100644 --- a/public/js/pages/WarehouseShippingNote/WarehouseShippingNoteModal.js +++ b/public/js/pages/WarehouseShippingNote/WarehouseShippingNoteModal.js @@ -163,14 +163,21 @@ Vue.component('warehouse-shipping-note-modal', { }, watch: { geoAddr: async function() { - const [lat, lon] = this.geoAddr.split(','); + if (!this.geoAddr) return; + const areaMode = this.geoAddr.includes(', area'); + const [lat, lon] = this.geoAddr.replace(', area', '').split(','); const { address } = (await axios.get(`${window.TT_CONFIG["BASE_PATH"]}/WarehouseShippingNote/geoReverse?lat=${lat}&lon=${lon}`)).data; + if (areaMode === false) { const addrKey = ['road', 'village', 'hamlet', 'residential', 'city'].find(k => address[k]); this.shippingNote.deliveryAddressLine = addrKey ? `${address[addrKey]}${address["house_number"] ? ` ${address["house_number"]}` : ''}` : ''; + } else if (areaMode === true) { + this.shippingNote.deliveryAddressLine = 'Gebiet'; + this.shippingNote.deliveryAddressName = `Gebiet ${address["village"] ?? address.residential ?? address.city ?? address["town"]}`; + } this.shippingNote.deliveryAddressPLZ = address["postcode"]; - this.shippingNote.deliveryAddressCity = address["village"] ?? address.city ?? address["town"]; + this.shippingNote.deliveryAddressCity = address["village"] ?? address.residential ?? address.city ?? address["town"]; this.updateKilometer().then(); }, selectedBillingAddress: async function() { @@ -223,7 +230,7 @@ Vue.component('warehouse-shipping-note-modal', { this.hoursLoading = false; }, async updateKilometer(carId) { - if (!carId || carId === '0') return this.$refs.hoursManager.updateField('kilometerCount', null); + if (!carId || carId === '0' && this.$refs.hoursManager) return this.$refs.hoursManager?.updateField('kilometerCount', null); this.hoursLoading = true; const delAddr = this.shippingNote.deliveryAddressLine + ' ' + this.shippingNote.deliveryAddressPLZ + ' ' + this.shippingNote.deliveryAddressCity; const {data} = await axios.get(window.TT_CONFIG["BASE_PATH"] + '/WarehouseShippingNote/getDistance?from=Xinon%20GmbH&to=' + delAddr);