Vue.component('change-status-modal', { props: { orderId: {type: Number, required: true}, type: {type: String, default: 'accept'} }, data() { return { window: window, order: null, newStatus: 'noChanges', note: '', file: null, uploadedFiles: [], sendEmail: false, sendEmailViewedPDF: false, sendEmailMail: '', submitLoading: false }; }, async mounted() { const response = await axios.get(`${window.TT_CONFIG["BASE_PATH"]}/WarehouseOrder/getById`, {params: {id: this.orderId}}); // if order.status is canceled emit close event and window.notify('error', 'Bestellung wurde storniert') if (response.data.status === 'cancelled') { this.$emit('close'); window.notify('error', 'Bestellung wurde storniert'); } this.order = response.data; }, computed: { availableStatuses() { switch (this.order.status) { case 'new': return [ {value: 'noChanges', text: 'Keine Änderungen'}, {value: 'accepted', text: 'Akzeptiert'}, {value: 'cancelled', text: 'Storniert'}, ]; case 'accepted': return [ {value: 'noChanges', text: 'Keine Änderungen'}, {value: 'ordered', text: 'Bestellt'}, {value: 'cancelled', text: 'Storniert'}, ]; case 'ordered': return [ {value: 'noChanges', text: 'Keine Änderungen'}, {value: 'sent', text: 'Versendet'}, {value: 'fullyDelivered', text: 'Geliefert'}, {value: 'cancelled', text: 'Storniert'}, {value: 'cancelled', text: 'Storniert'}, ]; case 'sent': return [ {value: 'noChanges', text: 'Keine Änderungen'}, {value: 'partiallyDelivered', text: 'Teilweise geliefert'}, {value: 'fullyDelivered', text: 'Geliefert'}, {value: 'cancelled', text: 'Storniert'}, ]; case 'partiallyDelivered': return [ {value: 'noChanges', text: 'Keine Änderungen'}, {value: 'fullyDelivered', text: 'Geliefert'}, {value: 'cancelled', text: 'Storniert'}, ]; case 'fullyDelivered': return [ {value: 'noChanges', text: 'Keine Änderungen'}, {value: 'cancelled', text: 'Storniert'}, ]; } } }, methods: { async handleFileUpload(event) { const files = event.target.files; if (!files.length) return; for (let i = 0; i < files.length; i++) { const file = files[i]; const formData = new FormData(); formData.append('file', file); try { const response = await axios.post(`${window.TT_CONFIG["BASE_PATH"]}/WarehouseOrder/uploadFile`, formData, { headers: { 'Content-Type': 'multipart/form-data' } }); if (response.data.success) { this.uploadedFiles.push({ id: response.data.fileId, name: file.name }); window.notify('success', `File "${file.name}" uploaded successfully`); } else { window.notify('error', `File "${file.name}" upload failed: ${response.data.error || 'Unknown error'}`); } } catch (error) { window.notify('error', `Error uploading file "${file.name}"`); } } // Clear the file input event.target.value = ''; }, removeFile: index => this.uploadedFiles.splice(index, 1), async submit() { this.submitLoading = true; if (this.newStatus === 'accepted' && this.sendEmail && !this.sendEmailMail) { window.notify('error', 'Bitte geben Sie eine E-Mail-Adresse ein'); this.submitLoading = false; return; } else if (this.newStatus === 'accepted' && this.sendEmail && !this.sendEmailViewedPDF) { window.notify('error', 'Bitte öffnen Sie das PDF bevor Sie die E-Mail senden'); this.submitLoading = false; return; } else if (this.newStatus === 'accepted' && this.sendEmail && this.sendEmailMail) { if (this.order.sendShippingNote > 0) { const shippingNoteId = await this.generateShippingNote(); await this.submitEmail(shippingNoteId); } else await this.submitEmail(); } const fileIds = this.uploadedFiles.map(file => file.id); const response = await axios.post(`${window.TT_CONFIG["BASE_PATH"]}/WarehouseOrder/createNewLogAction`, { orderId: this.order.id, status: this.newStatus, note: this.note, fileIds: JSON.stringify(fileIds), }); if (response.data.success) { this.$emit('close'); window.notify('success', response.data.message ?? 'Status erfolgreich geändert'); } else { window.notify('error', response.data.errors ? Object.values(response.data.errors).join('
') : response.data.message || 'Ein Fehler ist aufgetreten'); } this.submitLoading = false; }, async generateShippingNote() { const positions = this.order.positions.map(position => ({ article: position.article, amount: position.amount, price: position.buyPrice })); const response = await axios.post(`${window.TT_CONFIG["BASE_PATH"]}/WarehouseShippingNote/create`, { "billingAddressId": this.order.sendShippingNote, "deliveryAddressName": this.order.delAddrName, "deliveryAddressLine": this.order.delAddrLine, "deliveryAddressPLZ": this.order.delAddrPLZ, "deliveryAddressCity": this.order.delAddrCity, "deliveryAddressEMail": this.order.delAddrEMail, "textElements": [], "hoursEntries": [], "positions": positions, "note": "Bestellung #" + this.order.orderNumber, "status": "new" }); return response.data.id; }, async submitEmail(shippingNote = null) { const response = await axios.get(`${window.TT_CONFIG["BASE_PATH"]}/WarehouseOrder/sendEmail?id=${this.order.id}&email=${this.sendEmailMail}${shippingNote ? '&shippingNote=' + shippingNote : ''}`); if (response.data.success) { window.notify('success', response.data.message); } else { window.notify('error', response.data.message || 'Ein Fehler ist aufgetreten'); } } }, template: ` ` }); Vue.component('warehouse-order-modal', { props: { id: {type: [String, Number], required: true}, mode: {type: String, default: 'sign'} }, template: `

Bestelldetails


Positionen


Lieferadresse


`, data() { return { window: window, showSendShippingNote: null, lastDistributorFetch: null, positionsConfig: { customOrdering: 'distributorId', fields: { article: { type: 'autocomplete', label: 'Artikel', apiUrl: '/WarehouseArticle/autoComplete', customFieldReference: 'WarehouseArticle', emitDisplayValue: true, }, distributorId: {type: 'select', label: 'Lieferant', options: [], customFieldReference: 'WarehouseDistributor'}, distributorArticleNumber: {type: 'input', label: 'Lieferant Art-Nr.'}, amount: {type: 'input', label: 'Menge', inputType: 'number'}, buyPrice: {type: 'input', label: 'Einkaufspreis', inputType: 'number'}, verwendung: {type: 'input', label: 'Verwendung'}, }, validateFormOptions: [ {key: 'amount', message: 'Bitte füllen Sie die Menge aus'}, {key: 'distributorId', message: 'Bitte füllen Sie den Lieferanten aus'}, {key: 'article', message: 'Bitte füllen Sie den Artikel aus'}, {key: 'buyPrice', message: 'Bitte füllen Sie den Einkaufspreis aus'} ], }, order: { extReference: '', delAddrName: 'XINON GmbH', delAddrLine: 'Fladnitz im Raabtal 150', delAddrPLZ: '8322', delAddrCity: 'Studenzen', delAddrEMail: 'einkauf@xinon.at', note: '', editor: window.TT_CONFIG['USER_ID'], sendShippingNote: null, positions: [], } } }, async mounted() { if (this.id !== 'create') { const {data} = await axios.get(`${window.TT_CONFIG.BASE_PATH}/WarehouseOrder/getById?disableParse`, {params: {id: this.id}}); this.order = {...data, positions: JSON.parse(data.positions)}; return; } const orderRequests = JSON.parse(localStorage.getItem('WarehouseOrder_create')); if (!orderRequests) return; for (const orderRequest of orderRequests) { const positions = JSON.parse(orderRequest.positions); const parsedPositions = await Promise.all(positions.map(async p => { const distributor = (await axios.get(`${window.TT_CONFIG.BASE_PATH}/WarehouseOrder/getArticleDistributorData`, {params: {articleId: p.articleId}})).data[0]; return { article: p.articleId, amount: p.amount, buyPrice: distributor.purchasePrice, distributorId: distributor.id, distributorArticleNumber: distributor.externalArticleNumber, verwendung: `${p.hasOwnProperty('purpose') ? p.purpose : ''} [Bestellwunsch: #${orderRequest.id}]`, linkedOrderRequestId: orderRequest.id }; })); this.order.positions = [...this.order.positions, ...parsedPositions]; } localStorage.removeItem('WarehouseOrder_create'); }, methods: { async submit() { if (this.order.positions.length === 0) return window.notify('error', 'Bitte fügen Sie mindestens eine Position hinzu.'); if (this.id === 'create') { const distributorIds = [...new Set(this.order.positions.map(position => position.distributorId))]; for (const distributorId of distributorIds) { const response = await axios.post(`${window.TT_CONFIG["BASE_PATH"]}/WarehouseOrder/create`, { ...this.order, distributorId, positions: this.order.positions.filter(position => position.distributorId === distributorId) } ); if (response.data.success) { this.$emit('close'); window.notify('success', response.data.message ?? 'Bestellung erfolgreich erstellt'); } else window.notify('error', response.data.errors ? Object.values(response.data.errors).join('
') : response.data.message || 'Ein Fehler ist aufgetreten'); } } else { const response = await axios.post(`${window.TT_CONFIG["BASE_PATH"]}/WarehouseOrder/update`, this.order); if (response.data.success) { this.$emit('close'); window.notify('success', response.data.message ?? 'Bestellung erfolgreich aktualisiert'); } else window.notify('error', response.data.errors ? Object.values(response.data.errors).join('
') : response.data.message || 'Ein Fehler ist aufgetreten'); } }, async deleteOrder() { if (!window.confirm('Bestellung wirklich löschen?')) return; const response = await axios.post(`${window.TT_CONFIG["BASE_PATH"]}/WarehouseOrder/delete`, {id: this.id}); if (response.data.success) { this.$emit('close'); window.notify('success', response.data.message || 'Bestellung erfolgreich gelöscht'); } else window.notify('error', response.data.message || 'Ein Fehler ist aufgetreten'); }, async fetchDistributors(article) { const url = `${window.TT_CONFIG["BASE_PATH"]}/WarehouseOrder/getArticleDistributorData`; const params = typeof article === 'string' ? {allDistributor: true} : {articleId: article}; if (JSON.stringify(params) === JSON.stringify(this.lastDistributorFetch)) return; this.lastDistributorFetch = params; const response = await axios.get(url, {params}); this.positionsConfig.fields.distributorId.options = response.data.map(distributor => ({ value: distributor.id, text: distributor.name, externalArticleNumber: distributor.externalArticleNumber || null, purchasePrice: distributor.purchasePrice || null, })); }, async fetchDistributorData(distributorId) { if (distributorId && typeof this.$refs.positionsManager.formData.article === 'number') { const distributor = this.positionsConfig.fields.distributorId.options.find(distributor => parseInt(distributor.value) === parseInt(distributorId)); this.$refs.positionsManager.updateField('distributorArticleNumber', distributor.externalArticleNumber); this.$refs.positionsManager.updateField('buyPrice', distributor.purchasePrice); } }, }, watch: { 'order.positions': { handler(newPositions) { if (this.id !== 'create' && new Set(newPositions.map(p => p.distributorId)).size > 1) { window.notify('error', 'Eine bestehende Bestellung kann nur Positionen vom gleichen Lieferanten enthalten.'); this.order.positions = newPositions.filter(p => p.distributorId === this.order.distributorId); } }, deep: true } } , }); Vue.component('tt-file', { props: ['id'], data: () => ({file: null}), async mounted() { const response = await axios.get(`${window.TT_CONFIG.BASE_PATH}/File/getById`, {params: {id: this.id}}); this.file = response.data; }, template: `
{{ file.filename }}
` }) Vue.component('warehouse-order-detail', { template: ` `, props: ['id'], data: () => ({order: {}, orderLog: null, loading: true}), async mounted() { const [orderResponse, logResponse] = await Promise.all([ axios.get(`${window.TT_CONFIG.BASE_PATH}/WarehouseOrder/getById`, {params: {id: this.id}}), axios.get(`${window.TT_CONFIG.BASE_PATH}/WarehouseOrder/getLogById`, {params: {id: this.id}}) ]); this.order = orderResponse.data; this.orderLog = logResponse.data; this.loading = false; }, methods: { formatDate: date => window.moment(date * 1000).format('DD.MM.YYYY HH:mm'), getUserName: id => window.TT_CONFIG.CRUD_CONFIG.columns.find(col => col.key === 'createBy')?.modal.items.find(u => u.value === id)?.text } }); Vue.component('warehouse-order', { template: ` `, data: () => ({ orderModalId: null, changeStatusModalId: null }), mounted() { if (JSON.parse(localStorage.getItem('WarehouseOrder_create'))) this.orderModalId = 'create'; }, methods: { async closeModal() { this.orderModalId = null; this.changeStatusModalId = null; await new Promise(resolve => setTimeout(resolve, 250)); this.$refs.table.$refs.table.refreshTable(); }, calculateSum: positions => positions.reduce((sum, {amount, buyPrice}) => sum + amount * buyPrice, 0), openPDF: order => window.open(`${window.TT_CONFIG["BASE_PATH"]}/WarehouseOrder/createPDF?id=${order.id}`) } });