317 lines
14 KiB
JavaScript
317 lines
14 KiB
JavaScript
window.TT_CONFIG["CRUD_CONFIG"]["additionalActions"] = [
|
|
{
|
|
"key": "status_to_progress",
|
|
"title": "In Bearbeitung",
|
|
"class": "fas fa-cog text-warning",
|
|
"condition": (row) => window.TT_CONFIG['WAREHOUSE_ADMIN'] === '1' && ['new', 'on_hold'].includes(row.status),
|
|
},
|
|
{
|
|
"key": "status_to_accepted",
|
|
"title": "Akzeptieren",
|
|
"class": "fas fa-check text-success",
|
|
"condition": (row) => window.TT_CONFIG['WAREHOUSE_ADMIN'] === '1' && ['new', 'in_progress', 'on_hold'].includes(row.status),
|
|
},
|
|
{
|
|
"key": "status_to_invoiced",
|
|
"title": "Verrechnet",
|
|
"class": "fas fa-file-invoice text-info",
|
|
"condition": (row) => window.TT_CONFIG['WAREHOUSE_ADMIN'] === '1' && ['in_progress', 'accepted', 'on_hold'].includes(row.status),
|
|
},
|
|
{
|
|
"key": "status_to_on_hold",
|
|
"title": "On Hold",
|
|
"class": "fas fa-pause text-warning",
|
|
"condition": (row) => window.TT_CONFIG['WAREHOUSE_ADMIN'] === '1' && ['accepted', 'new', 'in_progress'].includes(row.status),
|
|
},
|
|
{
|
|
"key": "status_to_cancelled",
|
|
"title": "Storniert",
|
|
"class": "fas fa-ban text-danger",
|
|
"condition": (row) => (window.TT_CONFIG['WAREHOUSE_ADMIN'] === '1' && ['new', 'in_progress', 'accepted'].includes(row.status)) || (row.status === 'new' && row.signature === null),
|
|
},
|
|
{
|
|
"key": "add_log",
|
|
"title": "Log Eintrag hinzufügen",
|
|
"class": "fas fa-plus text-primary",
|
|
},
|
|
{
|
|
"key": "print",
|
|
"title": "Drucken",
|
|
"class": "fas fa-print text-primary",
|
|
}
|
|
]
|
|
|
|
// normal regie 50% 100%
|
|
|
|
window.TT_CONFIG["CRUD_CONFIG"]["editCondition"] = (row) => row.status === 'new' && row.signature === null || window.TT_CONFIG['WAREHOUSE_ADMIN'] === '1';
|
|
|
|
Vue.component('warehouse-shipping-note-positions', {
|
|
//language=Vue
|
|
props: {
|
|
positions: Array,
|
|
hoursEntries: Array
|
|
}, data() {
|
|
return {
|
|
articleData: {}, loading: false, articlePacketData: {}, userData: {}
|
|
}
|
|
}, template: `
|
|
<div>
|
|
<div v-if="loading" class="text-center">
|
|
<i class="fa fa-spinner fa-spin"></i>
|
|
</div>
|
|
|
|
|
|
<ul v-if="!loading">
|
|
<li v-for="position in positions">
|
|
<span>{{ position.amount }}x
|
|
{{ position.article ? articleData[position.article]?.text : position.articlePacket ? articlePacketData[position.articlePacket]?.text : position.articleText }}</span>
|
|
</li>
|
|
<template v-for="entry in hoursEntries">
|
|
<li><span>{{ entry.hourCount }}h Arbeitszeit</span></li>
|
|
<li v-if="entry.carId">{{ entry.kilometerCount }}km Anfahrt</li>
|
|
</template>
|
|
</ul>
|
|
</div>
|
|
`, async mounted() {
|
|
this.loading = true;
|
|
for (const position of this.positions) {
|
|
if (position.article) {
|
|
const response = await axios.get(window.TT_CONFIG["BASE_PATH"] + '/WarehouseArticle/autoComplete?searchedID=' + position.article);
|
|
this.$set(this.articleData, position.article, response.data[0]);
|
|
} else if (position.articlePacket) {
|
|
const response = await axios.get(window.TT_CONFIG["BASE_PATH"] + '/WarehouseArticlePacket/autoComplete?searchedID=' + position.articlePacket);
|
|
this.$set(this.articlePacketData, position.articlePacket, response.data[0]);
|
|
}
|
|
}
|
|
for (const entry of this.hoursEntries) {
|
|
if (entry.userId) {
|
|
const response = await axios.get(window.TT_CONFIG["BASE_PATH"] + '/WarehouseShippingNote/userAutoComplete?searchedID=' + entry.userId);
|
|
this.$set(this.userData, entry.userId, response.data[0]);
|
|
}
|
|
}
|
|
this.loading = false;
|
|
}
|
|
})
|
|
|
|
Vue.component('add-log-modal-sn', {
|
|
props: {
|
|
shippingNoteId: {type: Number, required: true},
|
|
},
|
|
data() {
|
|
return {
|
|
window: window,
|
|
note: '',
|
|
file: null,
|
|
uploadedFiles: [],
|
|
submitLoading: false
|
|
};
|
|
},
|
|
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"]}/WarehouseShippingNote/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;
|
|
|
|
const fileIds = this.uploadedFiles.map(file => file.id);
|
|
const response = await axios.post(`${window.TT_CONFIG["BASE_PATH"]}/WarehouseShippingNote/createNewLogAction`, {
|
|
shippingNoteId: this.shippingNoteId,
|
|
note: this.note,
|
|
fileIds: JSON.stringify(fileIds),
|
|
});
|
|
|
|
if (response.data.success) {
|
|
this.$emit('close');
|
|
window.notify('success', response.data.message ?? 'Log Eintrag erfolgreich erstellt');
|
|
} else {
|
|
window.notify('error',
|
|
response.data.errors ? Object.values(response.data.errors).join('<br>') : response.data.message || 'Ein Fehler ist aufgetreten');
|
|
}
|
|
this.submitLoading = false;
|
|
},
|
|
},
|
|
template: `
|
|
<tt-modal :show="true" @submit="submit" :delete="false" @update:show="$emit('close')" title="Logeintrag hinzufügen" :save-loading="submitLoading">
|
|
<template>
|
|
|
|
<div class="form-group" style="margin: 10px 0">
|
|
<label>Dateiupload (Mehrere)</label>
|
|
<input type="file" class="form-control" @change="handleFileUpload" multiple/>
|
|
</div>
|
|
|
|
<div v-if="uploadedFiles.length" class="upload-success-alert">
|
|
<div class="alert-header">
|
|
<i class="fa fa-check-circle" aria-hidden="true"></i>
|
|
<span v-if="uploadedFiles.length === 1">Datei erfolgreich hochgeladen</span>
|
|
<span v-else>Dateien erfolgreich hochgeladen</span>
|
|
</div>
|
|
<ul class="file-list">
|
|
<li v-for="(file, index) in uploadedFiles" :key="file.id" class="file-item">
|
|
<i class="fa fa-file" aria-hidden="true"></i>
|
|
<span class="file-name">{{ file.name }}</span>
|
|
<button type="button" class="remove-btn" @click="removeFile(index)">
|
|
<i class="fa fa-times" aria-hidden="true"></i>
|
|
</button>
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
|
|
|
|
<tt-textarea label="Bemerkung" v-model="note" sm/>
|
|
</template>
|
|
</tt-modal>
|
|
`
|
|
})
|
|
|
|
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: `
|
|
<div>
|
|
<a :href="'/File/download?id=' + id" target="_blank" v-if="file">{{ file.filename }}</a>
|
|
<template v-else>
|
|
<div class="spinner-border spinner-border-sm text-primary" role="status"><span class="sr-only">Loading...</span></div>
|
|
</template>
|
|
</div>
|
|
`
|
|
})
|
|
|
|
|
|
Vue.component('warehouse-shipping-note-logs', {
|
|
props: {
|
|
shippingNoteId: {type: Number, required: true},
|
|
},
|
|
data() {
|
|
return {
|
|
logs: [], loading: false,
|
|
};
|
|
},
|
|
//language=Vue
|
|
template: `
|
|
<div>
|
|
<div v-if="loading" class="text-center">
|
|
<i class="fa fa-spinner fa-spin"></i>
|
|
</div>
|
|
|
|
<div v-if="!loading">
|
|
<div v-for="log in logs">
|
|
{{ formatDate(log.create) }} ({{ getUserName(log.createBy) }}) | {{ log.message }}
|
|
<template v-if="log.fileIds">
|
|
<div v-for="file in JSON.parse(log.fileIds)">
|
|
<tt-file :id="file"/>
|
|
</div>
|
|
</template>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
`,
|
|
async mounted() {
|
|
this.loading = true;
|
|
const response = await axios.get(window.TT_CONFIG.BASE_PATH + '/WarehouseShippingNote/getLog', {params: {shippingNoteId: this.shippingNoteId}});
|
|
this.logs = response.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
|
|
}
|
|
})
|
|
|
|
// noinspection JSUnusedLocalSymbols
|
|
Vue.component('warehouse-shipping-note', {
|
|
//language=Vue
|
|
template: `
|
|
<tt-card>
|
|
<warehouse-shipping-note-modal v-if="shippingNoteModalId" :id="shippingNoteModalId"
|
|
@close="shippingNoteModalId = null;$refs.table.$refs.table.refreshTable()"
|
|
@open-signing-modal="signingShippingNoteId = $event"/>
|
|
<warehouse-history-modal :show.sync="historyModal" :id="historyModalId"/>
|
|
<warehouse-shipping-note-signature-pad v-if="signingShippingNoteId" :shipping-note-id="signingShippingNoteId"
|
|
@close="signingShippingNoteId = null"/>
|
|
<add-log-modal-sn v-if="addLogModalId" :shipping-note-id="addLogModalId" @close="addLogModalId = null"/>
|
|
|
|
<button @click="shippingNoteModalId = 'create'" class="btn btn-primary">Lieferschein erstellen</button>
|
|
|
|
<tt-table-crud emit-edit
|
|
@openHistory="historyModal = true; historyModalId = $event.id"
|
|
@print="window.open(window.TT_CONFIG['BASE_PATH'] + '/WarehouseShippingNote/createPDF?id=' + $event.id)"
|
|
@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')"
|
|
@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
|
|
}
|
|
},
|
|
mounted() {
|
|
// check if get parameter doAction = createNew is set, if so open the modal with 'create' as id
|
|
if (window.location.search.includes('doAction=createNew')) {
|
|
this.shippingNoteModalId = 'create';
|
|
}
|
|
},
|
|
methods: {
|
|
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');
|
|
}
|
|
},
|
|
}
|
|
})
|