Update WarehouseShippingNote.js

This commit is contained in:
Luca Haid
2025-10-09 11:38:49 +00:00
parent 58c01eff89
commit c50117a9c6

View File

@@ -306,12 +306,25 @@ Vue.component('warehouse-shipping-note-see-through', {
</template>
</template>
</div>
<div v-if="calendarEventType" style="margin-top: 10px; font-style: italic; color: #555;">
<i class="fas fa-calendar-alt" style="margin-right: 5px;"></i>
Erstellt aus Kalendereintrag: {{ calendarEventType }}
</div>
<div v-if="currentRow" style="margin-top: 10px; font-style: italic; color: #555;">
<div>
<i class="fas fa-clock" style="margin-right: 5px;"></i>
Erstellt am: {{ formatDate(currentRow.create) }}
</div>
<div>
<i class="fas fa-user" style="margin-right: 5px;"></i>
Erstellt von:
<span v-if="creatorLoading"><i class="fa fa-spinner fa-spin"></i></span>
<span v-else>{{ creatorName || 'Unbekannt' }}</span>
</div>
</div>
</div>
<div v-if="activeTab === 'Editieren'" style="flex: 1; overflow: auto;" class="see-through-test-modal">
<warehouse-shipping-note-modal v-if="currentRow" :id="currentRow.id" @close="fetchData" ref="modal">
@@ -340,7 +353,9 @@ Vue.component('warehouse-shipping-note-see-through', {
perPage: 1,
rows: [],
activeTab: 'Editieren',
window: window
window: window,
creatorName: null,
creatorLoading: false,
}
},
computed: {
@@ -363,7 +378,35 @@ 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',
@@ -421,222 +464,9 @@ Vue.component('warehouse-shipping-note-see-through', {
Vue.component('warehouse-shipping-note', {
//language=Vue
template: `
<tt-card>
<tt-fullscreen-viewer
v-if="viewerItem"
:item="viewerItem"
:url="viewerUrl"
@close="viewerItem = null; viewerUrl = null"
/>
<warehouse-shipping-note-see-through
@close="shippingNoteSeeThrough = false;$refs.table.$refs.table.refreshTable()"
v-if="shippingNoteSeeThrough !== false"
:wanted-state="shippingNoteSeeThrough"
@status_to_progress="changeStatus($event.id, 'in_progress')"
@status_to_new="changeStatus($event.id, 'new')"
@status_to_on_hold="changeStatus($event.id, 'on_hold')"
@status_to_cancelled="changeStatus($event.id, 'cancelled')"
@status_to_invoiced="changeStatus($event.id, 'invoiced')"
@status_to_accepted="changeStatus($event.id, 'accepted')"/>
<warehouse-shipping-note-modal v-if="shippingNoteModalId" :id="shippingNoteModalId"
ref="modal"
@close="shippingNoteModalId = null;$refs.table.$refs.table.refreshTable()"
@open-article-modal="articleModalId = true;window.console.log($event)"
@open-signing-modal="signingShippingNoteId = $event"/>
<warehouse-article-modal
v-if="articleModalId"
:id="articleModalId"
@close="articleModalId = null"
@article-selected="$refs.modal.$refs.positionsManager.updateField('article', $event.id);"/>
<warehouse-history-modal :show.sync="historyModal" :id="historyModalId"/>
<warehouse-shipping-note-signature-pad v-if="signingShippingNoteId" :shipping-note-id="signingShippingNoteId"
@close="signingShippingNoteId = null;shippingNoteModalId = null;$refs.table.$refs.table.refreshTable()"/>
<add-log-modal-sn v-if="addLogModalId" :shipping-note-id="addLogModalId" @close="addLogModalId = null"/>
<div class="mb-3">
<button @click="shippingNoteModalId = 'create'" class="btn btn-primary">Lieferschein erstellen</button>
<div class="dropdown" style="display: inline-block; margin-left: 10px;">
<button class="btn btn-info dropdown-toggle" type="button" @click.stop="showCalendarDropdown = !showCalendarDropdown">
Aus Kalendereintrag erstellen
</button>
<div class="dropdown-menu" :class="{'show': showCalendarDropdown}" style="cursor: pointer; max-height: 500px; overflow-y: auto;">
<a v-if="!calendarEvents.length" class="dropdown-item disabled">Lade Termine...</a>
<a v-for="event in calendarEvents" class="dropdown-item" @click="createFromEvent(event)">
<div style="white-space: normal;">
<strong>{{ event.category }}</strong><br>
<small>{{ event.location }}</small><br>
<small class="text-muted">{{ formatEventDate(event.date) }}</small>
</div>
</a>
</div>
</div>
<div class="dropdown" style="display: inline-block; margin-left: 10px;"
v-if="window.TT_CONFIG['WAREHOUSE_ADMIN'] === '1'">
<button class="btn btn-primary dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown"
aria-haspopup="true" aria-expanded="false">
Durchschau-Modus
</button>
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton" style="cursor: pointer;">
<a class="dropdown-item" @click="shippingNoteSeeThrough = 'new'">Neue</a>
<a class="dropdown-item" @click="shippingNoteSeeThrough = 'in_progress'">In Bearbeitung</a>
<a class="dropdown-item" @click="shippingNoteSeeThrough = 'accepted'">Akzeptierte</a>
<a class="dropdown-item" @click="shippingNoteSeeThrough = 'on_hold'">On Hold</a>
</div>
</div>
</div>
<tt-table-crud emit-edit
@openHistory="historyModal = true; historyModalId = $event.id"
@print="showPrintPreview($event)"
@status_to_progress="changeStatus($event.id, 'in_progress')"
@status_to_accepted="changeStatus($event.id, 'accepted')"
@status_to_invoiced="changeStatus($event.id, 'invoiced')"
@status_to_on_hold="changeStatus($event.id, 'on_hold')"
@status_to_cancelled="changeStatus($event.id, 'cancelled')"
@status_to_new="changeStatus($event.id, 'new')"
@add_log="addLogModalId = $event.id"
@edit="shippingNoteModalId = $event.id"
ref="table">
<template v-slot:expandedRow="{ row }">
<warehouse-shipping-note-positions :positions="JSON.parse(row.positions)"
:hours-entries="JSON.parse(row.hoursEntries)"/>
<warehouse-shipping-note-logs :shipping-note-id="row.id"/>
</template>
</tt-table-crud>
</tt-card>
`,
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;
@@ -692,4 +522,4 @@ document.addEventListener('DOMContentLoaded', () => {
logoutButton.addEventListener('click', handleLogout);
document.body.appendChild(logoutButton);
});
});