871 lines
39 KiB
JavaScript
871 lines
39 KiB
JavaScript
// noinspection JSUnresolvedReference
|
|
|
|
Vue.component('warehouse-offer-create-basic-offer-modal', {
|
|
props: {
|
|
show: {type: Boolean, default: false}
|
|
},
|
|
data() {
|
|
return {
|
|
window: window,
|
|
loading: false,
|
|
billAddrAutoCompleteUrl: window.TT_CONFIG['BASE_PATH'] + '/Address/Api?do=findAddress',
|
|
productSearchUrl: window.TT_CONFIG['BASE_PATH'] + '/Product/api?do=findProduct',
|
|
|
|
creatorSignaturePad: null,
|
|
creatorSignatureNotes: '',
|
|
|
|
positionsConfig: {
|
|
fields: {
|
|
article: {
|
|
type: 'autocomplete',
|
|
label: 'Artikel',
|
|
apiUrl: '/WarehouseArticle/autoComplete',
|
|
customFieldReference: 'WarehouseArticle',
|
|
},
|
|
amount: {type: 'input', label: 'Menge', inputType: 'number'},
|
|
unit: {type: 'input', label: 'Einheit'},
|
|
articleNumber: {type: 'input', label: 'Artikelnummer'},
|
|
isAlternative: {type: 'checkbox', label: 'Alternativposition'},
|
|
unitPrice: {type: 'input', label: 'Einzelpreis', inputType: 'number'},
|
|
discount: {type: 'input', label: 'Rabatt (%)', inputType: 'number'},
|
|
},
|
|
validateForm: (formData) => {
|
|
const requiredFields = ['article', 'amount', 'unitPrice'];
|
|
for (const field of requiredFields) {
|
|
if (!formData[field]) {
|
|
window.notify('error', `Bitte füllen Sie ${this.positionsConfig.fields[field].label} aus`);
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
},
|
|
},
|
|
|
|
offer: {
|
|
editor: window.TT_CONFIG['USER_ID'],
|
|
customerNumber: '',
|
|
reference: '',
|
|
purpose: '',
|
|
customerName: '',
|
|
customerStreet: '',
|
|
customerZip: '',
|
|
customerCity: '',
|
|
customerVAT: '',
|
|
contactPerson: '',
|
|
positions: [],
|
|
totalDiscount: 0,
|
|
paymentTerms: 'net30',
|
|
deliveryTerms: 'ex_works',
|
|
closingText: 'Sollten sich die Rohstoffpreise bzw. die Preise unserer Zulieferer um mehr als 10% innerhalb der Angebots bzw.\n\nAuftragsgültigkeit erhöhen (Stichtag Datum), sind wir gezwungen die Preise anzupassen.\n\nDiese Angebot hat eine Gültigkeit von 4 Wochen.\n\nVerrechnung erfolgt nach tatsächlichem Aufwand.\n\nWir sind sicher, Ihnen ein konkurenzfähiges Angebot unterbreitet zu haben und sehen gern Ihrer Bestellung entgegen.\n\nSollten Sie noch Fragen oder weitere Informationen benötigen stehen wir Ihnen jederzeit gern zu Verfügung.',
|
|
notes: '',
|
|
},
|
|
|
|
// Simple product search and selection
|
|
productSearch: '',
|
|
searchResults: [],
|
|
selectedProducts: [],
|
|
showProductSearch: false,
|
|
|
|
paymentTerms: [
|
|
{value: 'net30', text: '30 Tage netto'},
|
|
{value: 'net60', text: '60 Tage netto'},
|
|
{value: 'immediate', text: 'Sofort fällig'},
|
|
],
|
|
deliveryTerms: [
|
|
{value: 'ex_works', text: 'Ab Werk'},
|
|
{value: 'free_delivery', text: 'Frei Haus'},
|
|
{value: 'fob', text: 'FOB'},
|
|
],
|
|
}
|
|
},
|
|
template: `
|
|
<tt-modal :show="show"
|
|
@submit="submit"
|
|
:delete="false"
|
|
title="Einfaches Angebot erstellen"
|
|
@update:show="$emit('close')"
|
|
:save-loading="loading">
|
|
<div style="width: 99%">
|
|
|
|
<!-- Customer Section -->
|
|
<div class="card mb-3">
|
|
<div class="card-header">
|
|
<h5 class="mb-0"><i class="fas fa-user"></i> Kunde</h5>
|
|
</div>
|
|
<div class="card-body">
|
|
<tt-autocomplete label="Kunde suchen"
|
|
v-model="offer.customerNumber"
|
|
:api-url="billAddrAutoCompleteUrl"
|
|
sm row
|
|
placeholder="Kundenname oder -nummer eingeben"/>
|
|
<tt-input label="Kundenreferenz"
|
|
v-model="offer.reference"
|
|
sm row
|
|
placeholder="Ihre Referenz oder Bestellnummer"/>
|
|
<tt-input label="Kontaktperson"
|
|
v-model="offer.contactPerson"
|
|
sm row
|
|
placeholder="Ansprechpartner beim Kunden"/>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Customer Address (Auto-filled) -->
|
|
<div class="card mb-3" v-if="offer.customerName">
|
|
<div class="card-header">
|
|
<h5 class="mb-0"><i class="fas fa-map-marker-alt"></i> Kundenadresse</h5>
|
|
</div>
|
|
<div class="card-body">
|
|
<div class="row">
|
|
<div class="col-md-6">
|
|
<strong>{{ offer.customerName }}</strong><br>
|
|
{{ offer.customerStreet }}<br>
|
|
{{ offer.customerZip }} {{ offer.customerCity }}
|
|
</div>
|
|
<div class="col-md-6" v-if="offer.customerVAT">
|
|
<small class="text-muted">USt-IdNr.: {{ offer.customerVAT }}</small>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Purpose -->
|
|
<div class="card mb-3">
|
|
<div class="card-header">
|
|
<h5 class="mb-0"><i class="fas fa-clipboard-list"></i> Angebotszweck</h5>
|
|
</div>
|
|
<div class="card-body">
|
|
<tt-textarea label="Wofür ist dieses Angebot?"
|
|
v-model="offer.purpose"
|
|
rows="2"
|
|
placeholder="Kurze Beschreibung des Projekts oder Bedarfs"/>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Product Selection -->
|
|
<div class="card mb-3">
|
|
<div class="card-header d-flex justify-content-between align-items-center">
|
|
<h5 class="mb-0"><i class="fas fa-box"></i> Produkte</h5>
|
|
<button type="button"
|
|
class="btn btn-primary btn-sm"
|
|
@click="showProductSearch = !showProductSearch">
|
|
<i class="fas fa-plus"></i> Produkt hinzufügen
|
|
</button>
|
|
</div>
|
|
<div class="card-body">
|
|
|
|
<!-- Product Search -->
|
|
<div v-if="showProductSearch" class="border rounded p-3 mb-3 bg-light">
|
|
<div class="input-group mb-2">
|
|
<input type="text"
|
|
class="form-control"
|
|
v-model="productSearch"
|
|
@input="searchProducts"
|
|
placeholder="Produktname oder ID eingeben..."
|
|
@keyup.enter="searchProducts">
|
|
<div class="input-group-append">
|
|
<button class="btn btn-outline-secondary"
|
|
type="button"
|
|
@click="searchProducts">
|
|
<i class="fas fa-search"></i>
|
|
</button>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Search Results -->
|
|
<div v-if="searchResults.length" class="list-group">
|
|
<button type="button"
|
|
class="list-group-item list-group-item-action"
|
|
v-for="product in searchResults"
|
|
:key="product.value"
|
|
@click="addProduct(product)">
|
|
{{ product.text }}
|
|
</button>
|
|
</div>
|
|
|
|
<div class="text-center mt-2">
|
|
<button type="button"
|
|
class="btn btn-secondary btn-sm"
|
|
@click="showProductSearch = false">
|
|
Schließen
|
|
</button>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Selected Products -->
|
|
<div v-if="selectedProducts.length">
|
|
<div v-for="(product, index) in selectedProducts"
|
|
:key="index"
|
|
class="border rounded p-3 mb-2">
|
|
<div class="row align-items-center">
|
|
<div class="col-md-4">
|
|
<strong>{{ product.name }}</strong>
|
|
<br><small class="text-muted">{{ product.description || 'Keine Beschreibung' }}</small>
|
|
</div>
|
|
<div class="col-md-2">
|
|
<tt-input label="Menge"
|
|
v-model="product.amount"
|
|
type="number"
|
|
min="1"
|
|
sm no-form-group/>
|
|
</div>
|
|
<div class="col-md-2">
|
|
<tt-input label="Einzelpreis (€)"
|
|
v-model="product.unitPrice"
|
|
type="number"
|
|
step="0.01"
|
|
sm no-form-group/>
|
|
</div>
|
|
<div class="col-md-2">
|
|
<tt-input label="Rabatt (%)"
|
|
v-model="product.discount"
|
|
type="number"
|
|
min="0"
|
|
max="100"
|
|
sm no-form-group/>
|
|
</div>
|
|
<div class="col-md-1 text-center">
|
|
<strong>{{ formatPrice(calculateProductTotal(product)) }} €</strong>
|
|
</div>
|
|
<div class="col-md-1 text-center">
|
|
<button type="button"
|
|
class="btn btn-danger btn-sm"
|
|
@click="removeProduct(index)">
|
|
<i class="fas fa-trash"></i>
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Total -->
|
|
<div class="row mt-3">
|
|
<div class="col-md-8">
|
|
<tt-input label="Gesamtrabatt (%)"
|
|
v-model="offer.totalDiscount"
|
|
type="number"
|
|
min="0"
|
|
max="100"
|
|
sm row/>
|
|
</div>
|
|
<div class="col-md-4 text-right">
|
|
<h4>Gesamtsumme: <strong>{{ formatPrice(totalPrice) }} €</strong></h4>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div v-else class="text-center text-muted py-4">
|
|
<i class="fas fa-box-open fa-3x mb-2"></i>
|
|
<p>Noch keine Produkte ausgewählt</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Additional Positions -->
|
|
<div class="card mb-3">
|
|
<div class="card-header">
|
|
<h5 class="mb-0"><i class="fas fa-plus-square"></i> Zusätzliche Positionen</h5>
|
|
</div>
|
|
<div class="card-body">
|
|
<tt-positions-manager group-mode ref="positionsManager" v-model="offer.positions" :config="positionsConfig"
|
|
@updateField-article="fetchArticleData"/>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Terms -->
|
|
<div class="card mb-3">
|
|
<div class="card-header">
|
|
<h5 class="mb-0"><i class="fas fa-handshake"></i> Konditionen</h5>
|
|
</div>
|
|
<div class="card-body">
|
|
<div class="row">
|
|
<div class="col-md-6">
|
|
<tt-select label="Zahlungskonditionen"
|
|
:options="paymentTerms"
|
|
v-model="offer.paymentTerms"
|
|
sm/>
|
|
</div>
|
|
<div class="col-md-6">
|
|
<tt-select label="Lieferkonditionen"
|
|
:options="deliveryTerms"
|
|
v-model="offer.deliveryTerms"
|
|
sm/>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="card mb-3">
|
|
<div class="card-header">
|
|
<h5 class="mb-0"><i class="fas fa-signature"></i> Unterschrift Angebotsersteller</h5>
|
|
</div>
|
|
<div class="card-body">
|
|
<div class="row mb-3">
|
|
<div class="col-md-12">
|
|
<tt-input v-model="creatorSignatureNotes"
|
|
label="Unterschrieben von..."
|
|
placeholder="Name oder i.V."
|
|
sm/>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="signature-area mb-3">
|
|
<canvas id="creator-signature-pad" width="800" height="200" class="border rounded"></canvas>
|
|
</div>
|
|
|
|
<div class="signature-actions text-right">
|
|
<button class="btn btn-outline-secondary btn-sm mr-2" @click="clearCreatorSignature()">
|
|
<i class="fas fa-eraser"></i> Zurücksetzen
|
|
</button>
|
|
<button class="btn btn-primary btn-sm" @click="saveCreatorSignature()">
|
|
<i class="fas fa-save"></i> Unterschrift speichern
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
|
|
<!-- Notes -->
|
|
<div class="card mb-3">
|
|
<div class="card-header">
|
|
<h5 class="mb-0"><i class="fas fa-sticky-note"></i> Notizen</h5>
|
|
</div>
|
|
<div class="card-body">
|
|
<tt-textarea label="Interne Notizen"
|
|
v-model="offer.notes"
|
|
rows="3"
|
|
placeholder="Zusätzliche Informationen (nur intern sichtbar)"/>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
</tt-modal>
|
|
`,
|
|
methods: {
|
|
clearCreatorSignature() {
|
|
this.creatorSignaturePad.clear();
|
|
},
|
|
|
|
async fetchArticleData(article) {
|
|
if (typeof article === 'number') {
|
|
const response = await axios.get(`${window.TT_CONFIG["BASE_PATH"]}/WarehouseArticle/getById`, {params: {id: article}});
|
|
this.$refs.positionsManager.updateField('articleNumber', response.data.articleNumber);
|
|
this.$refs.positionsManager.updateField('unitPrice',
|
|
Object.values(JSON.parse(response.data.cheapestSellPrice)).find(price => price.title === 'Verkauf').price);
|
|
this.$refs.positionsManager.updateField('unit', response.data.unit);
|
|
}
|
|
},
|
|
|
|
async saveCreatorSignature() {
|
|
if (this.creatorSignaturePad.isEmpty()) {
|
|
this.window.notify('error', 'Bitte eine Unterschrift hinzufügen');
|
|
return;
|
|
}
|
|
|
|
this.offer.creatorSignature = this.creatorSignaturePad.toDataURL();
|
|
this.offer.creatorSignatureNotes = this.creatorSignatureNotes;
|
|
|
|
this.window.notify('success', 'Unterschrift erfolgreich gespeichert');
|
|
},
|
|
|
|
async searchProducts() {
|
|
if (!this.productSearch || this.productSearch.length < 2) {
|
|
this.searchResults = [];
|
|
return;
|
|
}
|
|
|
|
try {
|
|
const response = await axios.get(this.productSearchUrl, {
|
|
params: { q: this.productSearch }
|
|
});
|
|
this.searchResults = response.data || [];
|
|
} catch (error) {
|
|
console.error('Product search failed:', error);
|
|
window.notify('error', 'Produktsuche fehlgeschlagen');
|
|
this.searchResults = [];
|
|
}
|
|
},
|
|
|
|
async addProduct(searchResult) {
|
|
if (searchResult.value === 0) return; // Skip "more results" indicator
|
|
|
|
try {
|
|
// Get detailed product information
|
|
const response = await axios.get(`${window.TT_CONFIG["BASE_PATH"]}/Product/api`, {
|
|
params: {
|
|
do: 'getProduct',
|
|
product_id: searchResult.value
|
|
}
|
|
});
|
|
|
|
if (response.data.status === 'OK' && response.data.result["product"]) {
|
|
const productData = response.data.result["product"];
|
|
|
|
const product = {
|
|
id: searchResult.value,
|
|
name: searchResult.text,
|
|
description: productData.description || '',
|
|
amount: 1,
|
|
unitPrice: parseFloat(productData.price || '0'),
|
|
discount: 0,
|
|
unit: 'Stk',
|
|
articleNumber: productData.id || '',
|
|
article: searchResult.value // For compatibility with existing system
|
|
};
|
|
|
|
this.selectedProducts.push(product);
|
|
this.productSearch = '';
|
|
this.searchResults = [];
|
|
this.showProductSearch = false;
|
|
|
|
window.notify('success', 'Produkt hinzugefügt');
|
|
} else {
|
|
window.notify('error', 'Produktdetails konnten nicht geladen werden');
|
|
}
|
|
} catch (error) {
|
|
console.error('Failed to load product details:', error);
|
|
window.notify('error', 'Fehler beim Laden der Produktdetails');
|
|
}
|
|
},
|
|
|
|
removeProduct(index) {
|
|
this.selectedProducts.splice(index, 1);
|
|
},
|
|
|
|
calculateProductTotal(product) {
|
|
if (!product.amount || !product.unitPrice) return 0;
|
|
|
|
const subtotal = product.amount * product.unitPrice;
|
|
const discount = product.discount ? (subtotal * product.discount / 100) : 0;
|
|
return subtotal - discount;
|
|
},
|
|
|
|
formatPrice(price) {
|
|
|
|
return parseFloat(price || '0').toFixed(2);
|
|
},
|
|
|
|
async submit() {
|
|
this.loading = true;
|
|
|
|
// Validation
|
|
if (!this.offer.customerNumber) {
|
|
this.loading = false;
|
|
return window.notify('error', 'Bitte wählen Sie einen Kunden aus');
|
|
}
|
|
|
|
if (!this.selectedProducts.length) {
|
|
this.loading = false;
|
|
return window.notify('error', 'Bitte fügen Sie mindestens ein Produkt hinzu');
|
|
}
|
|
|
|
// Convert selected products to the format expected by the existing system
|
|
this.offer.positions = this.selectedProducts.map(product => ({
|
|
article: product.article,
|
|
amount: product.amount,
|
|
unit: product.unit,
|
|
articleNumber: product.articleNumber,
|
|
unitPrice: product.unitPrice,
|
|
discount: product.discount || 0,
|
|
isAlternative: false
|
|
}));
|
|
|
|
this.offer.totalAmount = this.totalPrice;
|
|
|
|
try {
|
|
const response = await axios.post(
|
|
`${window.TT_CONFIG["BASE_PATH"]}/WarehouseOffer/create`,
|
|
this.offer
|
|
);
|
|
|
|
if (response.data.success) {
|
|
window.notify('success', response.data.message || 'Angebot erfolgreich erstellt');
|
|
this.$emit('close');
|
|
this.$emit('created', response.data);
|
|
} else {
|
|
window.notify('error',
|
|
response.data.errors
|
|
? Object.values(response.data.errors).join('<br>')
|
|
: response.data.message || 'Ein Fehler ist aufgetreten'
|
|
);
|
|
}
|
|
} catch (error) {
|
|
console.error('Submit failed:', error);
|
|
window.notify('error', 'Fehler beim Speichern des Angebots');
|
|
}
|
|
|
|
this.loading = false;
|
|
},
|
|
|
|
resetForm() {
|
|
this.offer = {
|
|
editor: window.TT_CONFIG['USER_ID'],
|
|
customerNumber: '',
|
|
reference: '',
|
|
purpose: '',
|
|
customerName: '',
|
|
customerStreet: '',
|
|
customerZip: '',
|
|
customerCity: '',
|
|
customerVAT: '',
|
|
contactPerson: '',
|
|
positions: [],
|
|
totalDiscount: 0,
|
|
paymentTerms: 'net30',
|
|
deliveryTerms: 'ex_works',
|
|
closingText: this.offer.closingText, // Keep default text
|
|
notes: '',
|
|
};
|
|
this.selectedProducts = [];
|
|
this.productSearch = '';
|
|
this.searchResults = [];
|
|
this.showProductSearch = false;
|
|
}
|
|
},
|
|
mounted() {
|
|
this.$nextTick(() => {
|
|
console.log(document.getElementById('creator-signature-pad'));
|
|
const canvas = document.getElementById('creator-signature-pad');
|
|
this.creatorSignaturePad = new SignaturePad(canvas, {
|
|
penColor: '#000000',
|
|
penWidth: 2,
|
|
velocityFilterWeight: 0.5
|
|
});
|
|
});
|
|
},
|
|
computed: {
|
|
totalPrice() {
|
|
const subtotal = this.selectedProducts.reduce((total, product) => {
|
|
return total + this.calculateProductTotal(product);
|
|
}, 0);
|
|
|
|
const totalDiscount = this.offer.totalDiscount ? (subtotal * this.offer.totalDiscount / 100) : 0;
|
|
return subtotal - totalDiscount;
|
|
}
|
|
},
|
|
watch: {
|
|
'offer.customerNumber': async function() {
|
|
if (!this.offer.customerNumber) return;
|
|
|
|
try {
|
|
const response = await axios.get(
|
|
`${window.TT_CONFIG["BASE_PATH"]}/Address/api?do=getAddress&id=${this.offer.customerNumber}`
|
|
);
|
|
|
|
if (response.data.status !== 'OK' || !response.data.result.address) {
|
|
window.notify('error', 'Kundenadresse konnte nicht gefunden werden');
|
|
return;
|
|
}
|
|
|
|
const address = response.data.result.address;
|
|
this.offer.customerName = address.company || `${address.firstname} ${address.lastname}`;
|
|
this.offer.customerStreet = address.street;
|
|
this.offer.customerZip = address.zip;
|
|
this.offer.customerCity = address.city;
|
|
this.offer.customerVAT = address.vat_number || '';
|
|
} catch (error) {
|
|
console.error('Failed to load customer address:', error);
|
|
window.notify('error', 'Fehler beim Laden der Kundenadresse');
|
|
}
|
|
},
|
|
|
|
show(newVal) {
|
|
if (newVal) {
|
|
this.resetForm();
|
|
}
|
|
}
|
|
}
|
|
});
|
|
|
|
Vue.component('warehouse-offer-modal', {
|
|
props: {
|
|
id: {type: [String, Number], required: true},
|
|
mode: {type: String, default: 'edit'}
|
|
},
|
|
template: `
|
|
<tt-modal :show="true"
|
|
@submit="submit"
|
|
:delete="id !== 'create'"
|
|
:title="id === 'create' ? 'Angebot erstellen' : \`Angebot #\${id} bearbeiten\`"
|
|
@update:show="$emit('close')">
|
|
<div style="width: 99%"><h4 class="text-center">Angebotsdetails</h4>
|
|
<tt-select label="Sachbearbeiter"
|
|
:options="window.TT_CONFIG.CRUD_CONFIG.columns.find(column => column.key === 'createBy')?.modal.items"
|
|
sm
|
|
row
|
|
v-model="offer.editor"/>
|
|
|
|
<tt-autocomplete label="Kunde" v-model="offer.customerNumber" sm row :api-url="billAddrAutoCompleteUrl"/>
|
|
<tt-input label="Kundenreferenz" v-model="offer.reference" sm row/>
|
|
<tt-textarea label="Angebotszweck" v-model="offer.purpose" sm row/>
|
|
<hr>
|
|
<h4 class="text-center">Kundenadresse</h4>
|
|
<div style="display: grid; grid-gap: 10px; grid-template-columns: 2fr 1fr 2fr 1fr 1fr 1fr;">
|
|
<tt-input label="Name" v-model="offer.customerName" sm/>
|
|
<tt-input label="Kontakt" v-model="offer.contactPerson" sm/>
|
|
<tt-input label="Straße" v-model="offer.customerStreet" sm/>
|
|
<tt-input label="PLZ" v-model="offer.customerZip" sm/>
|
|
<tt-input label="Ort" v-model="offer.customerCity" sm/>
|
|
<tt-input label="USt-IdNr." v-model="offer.customerVAT" sm/>
|
|
</div>
|
|
<hr>
|
|
<h4 class="text-center">Positionen</h4>
|
|
<tt-positions-manager group-mode ref="positionsManager" v-model="offer.positions" :config="positionsConfig"
|
|
@updateField-article="fetchArticleData"/>
|
|
<hr>
|
|
<tt-input label="Gesamtrabatt (%)" v-model="offer.totalDiscount" sm row type="number"/>
|
|
<tt-input label="Gesamtsumme" v-model="offerTotalPrice" sm row type="number" disabled/>
|
|
<tt-select label="Zahlungskonditionen" :options="paymentTerms" sm row v-model="offer.paymentTerms"/>
|
|
<tt-select label="Lieferkonditionen" :options="deliveryTerms" sm row v-model="offer.deliveryTerms"/>
|
|
<tt-textarea label="Schlusstext" sm rows="11" row v-model="offer.closingText"/>
|
|
<hr>
|
|
<tt-textarea label="Notizen" v-model="offer.notes" sm row/>
|
|
</div>
|
|
|
|
|
|
<template v-slot:footer-prepend v-if="window.TT_CONFIG['WAREHOUSE_ADMIN'] === '1'">
|
|
<tt-input placeholder="Vorlagenname" no-form-group v-model="templateName"/>
|
|
<tt-button text="Als Vorlage speichern" @click="saveTemplate" icon="fas fa-save" additional-class="btn-success"/>
|
|
</template>
|
|
</tt-modal>
|
|
`,
|
|
data() {
|
|
return {
|
|
billAddrAutoCompleteUrl: window.TT_CONFIG['BASE_PATH'] + '/Address/Api?do=findAddress&fibu_primary_account=1',
|
|
window: window,
|
|
positionsConfig: {
|
|
fields: {
|
|
article: {
|
|
type: 'input-article',
|
|
label: 'Artikel',
|
|
customFieldReference: 'WarehouseArticle',
|
|
},
|
|
amount: {type: 'input', label: 'Menge', inputType: 'number'},
|
|
unit: {type: 'input', label: 'Einheit'},
|
|
articleNumber: {type: 'input', label: 'Artikelnummer'},
|
|
isAlternative: {type: 'checkbox', label: 'Alternativposition'},
|
|
unitPrice: {type: 'input', label: 'Einzelpreis', inputType: 'number'},
|
|
discount: {type: 'input', label: 'Rabatt (%)', inputType: 'number'},
|
|
},
|
|
validateForm: (formData) => {
|
|
const requiredFields = ['article', 'amount', 'unitPrice'];
|
|
for (const field of requiredFields) {
|
|
if (!formData[field]) {
|
|
window.notify('error', `Bitte füllen Sie ${this.positionsConfig.fields[field].label} aus`);
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
},
|
|
},
|
|
paymentTerms: [
|
|
{value: 'net30', text: '30 Tage netto'},
|
|
{value: 'net60', text: '60 Tage netto'},
|
|
{value: 'immediate', text: 'Sofort fällig'},
|
|
],
|
|
deliveryTerms: [
|
|
{value: 'ex_works', text: 'Ab Werk'},
|
|
{value: 'free_delivery', text: 'Frei Haus'},
|
|
{value: 'fob', text: 'FOB'},
|
|
],
|
|
offer: {
|
|
editor: window.TT_CONFIG['USER_ID'],
|
|
customerNumber: '',
|
|
reference: '',
|
|
purpose: '',
|
|
customerName: '',
|
|
customerStreet: '',
|
|
customerZip: '',
|
|
customerCity: '',
|
|
customerVAT: '',
|
|
positions: [],
|
|
alternativePositions: [],
|
|
totalDiscount: 0,
|
|
paymentTerms: 'net30',
|
|
deliveryTerms: 'ex_works',
|
|
closingText: 'Sollten sich die Rohstoffpreise bzw. die Preise unserer Zulieferer um mehr als 10% innerhalb der Angebots bzw.\n' +
|
|
'\n' +
|
|
'Auftragsgültigkeit erhöhen (Stichtag Datum), sind wir gezwungen die Preise anzupassen.\n' +
|
|
'\n' +
|
|
'Diese Angebot hat eine Gültigkeit von 4 Wochen.\n' +
|
|
'\n' +
|
|
'Verrechnung erfolgt nach tatsächlichem Aufwand.\n' +
|
|
'\n' +
|
|
'Wir sind sicher, Ihnen ein konkurenzfähiges Angebot unterbreitet zu haben und sehen gern Ihrer Bestellung entgegen.\n' +
|
|
'\n' +
|
|
'Sollten Sie noch Fragen oder weitere Informationen benötigen stehen wir Ihnen jederzeit gern zu Verfügung.\n' +
|
|
' ',
|
|
notes: '',
|
|
},
|
|
templateName: '',
|
|
}
|
|
},
|
|
async mounted() {
|
|
if (this.id !== 'create') {
|
|
const response = await axios.get(`${window.TT_CONFIG["BASE_PATH"]}/WarehouseOffer/getById`, {params: {id: this.id}});
|
|
this.offer = response.data;
|
|
this.offer.positions = JSON.parse(this.offer.positions);
|
|
this.offer.alternativePositions = JSON.parse(this.offer.alternativePositions);
|
|
} else {
|
|
await this.$nextTick();
|
|
this.offer.editor = parseInt(window.TT_CONFIG['USER_ID']);
|
|
}
|
|
},
|
|
methods: {
|
|
async submit() {
|
|
this.offer.totalAmount = this.offerTotalPrice;
|
|
if (this.offer.positions.length === 0) return window.notify('error', 'Bitte fügen Sie mindestens eine Position hinzu.');
|
|
|
|
const url = this.id === 'create'
|
|
? `${window.TT_CONFIG["BASE_PATH"]}/WarehouseOffer/create`
|
|
: `${window.TT_CONFIG["BASE_PATH"]}/WarehouseOffer/update`;
|
|
|
|
const response = await axios.post(url, this.offer);
|
|
|
|
if (response.data.success) {
|
|
window.notify('success', response.data.message ?? 'Angebot erfolgreich gespeichert');
|
|
this.$emit('close');
|
|
} else {
|
|
window.notify('error',
|
|
response.data.errors ? Object.values(response.data.errors).join('<br>') : response.data.message || 'Ein Fehler ist aufgetreten');
|
|
}
|
|
},
|
|
async fetchArticleData(article) {
|
|
if (typeof article === 'number') {
|
|
const response = await axios.get(`${window.TT_CONFIG["BASE_PATH"]}/WarehouseArticle/getById`, {params: {id: article}});
|
|
this.$refs.positionsManager.updateField('articleNumber', response.data.articleNumber);
|
|
this.$refs.positionsManager.updateField('unitPrice',
|
|
Object.values(JSON.parse(response.data.cheapestSellPrice)).find(price => price.title === 'Verkauf').price);
|
|
this.$refs.positionsManager.updateField('unit', response.data.unit);
|
|
}
|
|
},
|
|
async saveTemplate() {
|
|
if (!this.templateName) return window.notify('error', 'Bitte geben Sie einen Namen für die Vorlage ein.');
|
|
if (this.offer.positions.length === 0) return window.notify('error', 'Bitte fügen Sie mindestens eine Position hinzu.');
|
|
|
|
const response = await axios.post(`${window.TT_CONFIG["BASE_PATH"]}/WarehouseOffer/createTemplate`, {
|
|
name: this.templateName,
|
|
positions: this.offer.positions,
|
|
totalDiscount: this.offer.totalDiscount,
|
|
paymentTerms: this.offer.paymentTerms,
|
|
deliveryTerms: this.offer.deliveryTerms,
|
|
closingText: this.offer.closingText,
|
|
notes: this.offer.notes
|
|
});
|
|
|
|
if (response.data.success) {
|
|
window.notify('success', response.data.message ?? 'Vorlage erfolgreich gespeichert');
|
|
} else {
|
|
window.notify('error', response.data.message || 'Ein Fehler ist aufgetreten');
|
|
}
|
|
}
|
|
},
|
|
watch: {
|
|
'offer.customerNumber': async function () {
|
|
if (!this.offer.customerNumber) return;
|
|
|
|
const response = await axios.get(`${window.TT_CONFIG["BASE_PATH"]}/Address/api?do=getAddress&id=${this.offer.customerNumber}`);
|
|
if (response.data.status !== 'OK' || !response.data.result.address) {
|
|
this.window.notify('error', 'Kundenadresse konnte nicht gefunden werden');
|
|
return;
|
|
}
|
|
|
|
const address = response.data.result.address;
|
|
this.offer.customerName = address.company || `${address.firstname} ${address.lastname}`;
|
|
this.offer.customerStreet = address.street;
|
|
this.offer.customerZip = address.zip;
|
|
this.offer.customerCity = address.city;
|
|
}
|
|
},
|
|
computed: {
|
|
offerTotalPrice() {
|
|
const totalPrice = this.offer.positions.reduce((total, position) => {
|
|
if (!position.amount) return total;
|
|
const discount = position.discount ? (position.unitPrice * position.amount) * position.discount / 100 : 0;
|
|
return total + (position.unitPrice * position.amount) - discount;
|
|
}, 0);
|
|
|
|
return totalPrice - (totalPrice * this.offer.totalDiscount / 100).toFixed(2);
|
|
}
|
|
}
|
|
});
|
|
|
|
Vue.component('warehouse-offer', {
|
|
template: `
|
|
<tt-card>
|
|
<warehouse-offer-modal v-if="offerModalId" :id="offerModalId" ref="modal"
|
|
@close="offerModalId = null;$refs.table.$refs.table.refreshTable()"/>
|
|
<warehouse-offer-create-basic-offer-modal
|
|
v-if="showBasicModal"
|
|
:show="true"
|
|
@close="showBasicModal = false"
|
|
@created="showBasicModal = false"/>
|
|
|
|
<div style="display: flex; gap: 8px">
|
|
<button @click="offerModalId = 'create'" class="btn btn-primary">Angebot erstellen</button>
|
|
<div class="dropdown">
|
|
<button class="btn btn-outline-primary dropdown-toggle" @click.stop="offerTemplatesDropdown = !offerTemplatesDropdown" >
|
|
Angebot aus Vorlage erstellen <i class="fas fa-caret-down"></i>
|
|
</button>
|
|
<ul class="dropdown-menu" :class="{'show': offerTemplatesDropdown}" >
|
|
<li v-for="template in offerTemplates" @click="createOfferFromTemplate(template)" style="display: flex; gap: 2px;cursor: pointer;margin-bottom: 4px;margin-right: 4px">
|
|
<a class="dropdown-item">{{ template.templateName }}</a>
|
|
<tt-button
|
|
v-if="window.TT_CONFIG['WAREHOUSE_ADMIN'] === '1'"
|
|
icon="fas fa-trash" sm additional-class="btn-danger" @click.stop="deleteTemplate(template.id)"/>
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
|
|
<!-- <button @click="showBasicModal = true" class="btn btn-success">-->
|
|
<!-- <i class="fas fa-plus"></i> Einfaches Angebot erstellen-->
|
|
<!-- </button>-->
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<tt-table-crud emit-edit @edit="offerModalId = $event.id" ref="table"
|
|
@openpdf="window.open(window.TT_CONFIG['BASE_PATH'] + '/WarehouseOffer/createPDF?id=' + $event.id)"
|
|
|
|
>
|
|
</tt-table-crud>
|
|
</tt-card>
|
|
`,
|
|
data() {
|
|
return {
|
|
window: window,
|
|
offerModalId: null,
|
|
offerTemplates: [],
|
|
offerTemplatesDropdown: false,
|
|
showBasicModal: false,
|
|
}
|
|
},
|
|
async mounted() {
|
|
const response = await axios.get(`${window.TT_CONFIG["BASE_PATH"]}/WarehouseOffer/getTemplates`);
|
|
this.offerTemplates = response.data;
|
|
},
|
|
methods: {
|
|
async createOfferFromTemplate(template) {
|
|
this.offerModalId = 'create';
|
|
await this.$nextTick();
|
|
|
|
this.$refs.modal.offer.positions = JSON.parse(template.positions);
|
|
this.$refs.modal.offer.totalDiscount = template.totalDiscount;
|
|
this.$refs.modal.offer.paymentTerms = template.paymentTerms;
|
|
this.$refs.modal.offer.deliveryTerms = template.deliveryTerms;
|
|
this.$refs.modal.offer.closingText = template.closingText;
|
|
this.$refs.modal.offer.notes = template.notes;
|
|
|
|
this.window.notify('success', 'Angebot aus Vorlage erstellt');
|
|
},
|
|
async deleteTemplate(id) {
|
|
const response = await axios.get(`${window.TT_CONFIG["BASE_PATH"]}/WarehouseOffer/deleteTemplate?id=${id}`);
|
|
if (response.data.success) {
|
|
this.offerTemplates = this.offerTemplates.filter(template => template.id !== id);
|
|
this.window.notify('success', 'Vorlage erfolgreich gelöscht');
|
|
} else {
|
|
this.window.notify('error', response.data.message || 'Ein Fehler ist aufgetreten');
|
|
}
|
|
}
|
|
}
|
|
});
|