From a4a64a714b6e363440637900789a3cf54a61f336 Mon Sep 17 00:00:00 2001 From: Luca Haid Date: Thu, 9 Oct 2025 11:40:08 +0000 Subject: [PATCH] Update WarehouseShippingNote.js --- .../WarehouseShippingNote.js | 260 +++++++++++++++--- 1 file changed, 215 insertions(+), 45 deletions(-) diff --git a/public/js/pages/WarehouseShippingNote/WarehouseShippingNote.js b/public/js/pages/WarehouseShippingNote/WarehouseShippingNote.js index 8a93f684f..597e26602 100644 --- a/public/js/pages/WarehouseShippingNote/WarehouseShippingNote.js +++ b/public/js/pages/WarehouseShippingNote/WarehouseShippingNote.js @@ -306,25 +306,12 @@ Vue.component('warehouse-shipping-note-see-through', { - +
Erstellt aus Kalendereintrag: {{ calendarEventType }}
-
-
- - Erstellt am: {{ formatDate(currentRow.create) }} -
-
- - Erstellt von: - - {{ creatorName || 'Unbekannt' }} -
-
-
@@ -353,9 +340,7 @@ Vue.component('warehouse-shipping-note-see-through', { perPage: 1, rows: [], activeTab: 'Editieren', - window: window, - creatorName: null, - creatorLoading: false, + window: window } }, computed: { @@ -378,35 +363,7 @@ Vue.component('warehouse-shipping-note-see-through', { return null; } }, - watch: { - currentRow(newVal) { - if (newVal && newVal.createBy) { - this.fetchCreatorInfo(newVal.createBy); - } else { - this.creatorName = null; - } - } - }, methods: { - formatDate(timestamp) { - return window.moment(timestamp * 1000).format('DD.MM.YYYY HH:mm'); - }, - async fetchCreatorInfo(userId) { - if (!userId) { - this.creatorName = null; - return; - } - this.creatorLoading = true; - try { - const response = await axios.get(`/User/getById?id=${userId}`); - this.creatorName = response.data?.name || 'Unbekannt'; - } catch (error) { - console.error(`Failed to fetch user with ID ${userId}`, error); - this.creatorName = 'Fehler'; - } finally { - this.creatorLoading = false; - } - }, tabStyle(tab) { return { padding: '10px 20px', @@ -464,9 +421,222 @@ Vue.component('warehouse-shipping-note-see-through', { +Vue.component('warehouse-shipping-note', { + //language=Vue + template: ` + + + + + + + + + + + + +
+ + + + + +
+ + + + +
+ `, + data() { + return { + window: window, + historyModal: false, + historyModalId: null, + shippingNoteModalId: null, + signingShippingNoteId: null, + addLogModalId: null, + viewerItem: null, + viewerUrl: null, + shippingNoteSeeThrough: false, + articleModalId: null, + calendarEvents: [], + showCalendarDropdown: false, + } + }, + mounted() { + if (window.location.search.includes('doAction=createNew')) { + this.shippingNoteModalId = 'create'; + } + this.fetchCalendarEvents(); + document.addEventListener('click', this.closeDropdown); + }, + beforeDestroy() { + document.removeEventListener('click', this.closeDropdown); + }, + methods: { + async fetchCalendarEvents() { + try { + const response = await axios.get(window.TT_CONFIG.BASE_PATH + '/WarehouseShippingNote/getRecentCalendarEvents'); + this.calendarEvents = response.data; + } catch (error) { + console.error("Could not fetch calendar events", error); + window.notify('error', 'Kalendereinträge konnten nicht geladen werden.'); + } + }, + showPrintPreview(row) { + this.viewerUrl = `${window.TT_CONFIG['BASE_PATH']}/WarehouseShippingNote/createPDF?id=${row.id}`; + this.viewerItem = { mimetype: 'application/pdf' }; + }, + formatEventDate(dateString) { + return window.moment(dateString).format('DD.MM.YYYY HH:mm'); + }, + async createFromEvent(event) { + this.showCalendarDropdown = false; + this.shippingNoteModalId = 'create'; + + await this.$nextTick(); // Wait for the modal component to be created + + if (this.$refs.modal) { + // Parse address string + const locationParts = event.location.split(','); + const line = locationParts[0].trim(); + const plzCityRaw = locationParts[1].trim(); + const plzMatch = plzCityRaw.match(/^(\d+)/); + const plz = plzMatch ? plzMatch[1] : ''; + const city = plzCityRaw.replace(/^\d+\s*/, '').trim(); + + // Create metadata object + const eventTypeMap = { + '2': 'Xinon Inbetriebnahmen', + '3': 'ESTMK Inbetriebnahmen', + '7': 'Sbidi Inbetriebnahmen', + '4': 'SNOPP', + '5': 'Störungen', + '6': 'Support Gespräch' + }; + const eventTypeText = eventTypeMap[event.event_type] || 'Unbekannter Termintyp'; + + const metadata = { + from_calendar: true, + event_type_id: event.event_type, + event_type_text: eventTypeText + }; + + // Check for default positions for SBIDI event type + let defaultPositions = []; + if (event.event_type === '7') { + defaultPositions = [ + {"article": 56, "amount": "1", "isEnergieMaterial": 1}, + {"article": 71, "amount": "1", "isEnergieMaterial": 1}, + {"article": 134, "amount": "1", "isEnergieMaterial": 1}, + {"article": 324, "isEnergieMaterial": 1, "amount": "1"}, + {"article": 325, "amount": "1", "isEnergieMaterial": 1}, + {"article": 539, "amount": "1", "isEnergieMaterial": 1}, + {"article": 660, "amount": "1", "isEnergieMaterial": 1} + ]; + } + + // Directly set the data in the modal's `shippingNote` object + const modalData = this.$refs.modal.shippingNote; + this.$set(modalData, 'deliveryAddressName', event.category); + this.$set(modalData, 'deliveryAddressLine', line); + this.$set(modalData, 'deliveryAddressPLZ', plz); + this.$set(modalData, 'deliveryAddressCity', city); + this.$set(modalData, 'metadata', metadata); // Set metadata + + if (defaultPositions.length > 0) { + this.$set(modalData, 'positions', defaultPositions); // Set default positions + } + } + }, + closeDropdown(event) { + if (!event.target.closest('.dropdown')) { + this.showCalendarDropdown = false; + } + }, + async changeStatus(id, status) { + const response = await axios.post(window.TT_CONFIG.BASE_PATH + '/WarehouseShippingNote/changeStatus', { + id, + status + }); + if (response.data.success) { + this.window.notify('success', response.data.message || 'Erfolgreich aktualisiert'); + this.$refs.table.$refs.table.refreshTable(); + } else { + this.window.notify('error', response.data.message || 'Ein Fehler ist aufgetreten'); + } + }, + } +}) let hiddenTime = null; const RELOAD_AFTER_SECONDS = 300;