Merge branch 'WarehouseOffer/add-drag-drop' into 'master'
offer fix See merge request fronk/thetool!1848
This commit is contained in:
@@ -1,12 +1,7 @@
|
||||
<?php
|
||||
|
||||
class CpeprovisioningController extends mfBaseController
|
||||
{
|
||||
class CpeprovisioningController extends mfBaseController {
|
||||
protected function init() {
|
||||
// disable error display for all requests to avoid information leakage
|
||||
ini_set('display_errors', '0');
|
||||
error_reporting(E_ALL & ~E_NOTICE & ~E_WARNING);
|
||||
|
||||
if (defined('TT_CPE_PROV_ALLOW_COUNTS_IP') &&
|
||||
in_array($_SERVER['REMOTE_ADDR'], TT_CPE_PROV_ALLOW_COUNTS_IP) &&
|
||||
!mfLoginController::isLoggedIn()) {
|
||||
@@ -26,13 +21,10 @@ class CpeprovisioningController extends mfBaseController
|
||||
$this->me->loadMe();
|
||||
$this->layout()->set("me", $this->me);
|
||||
|
||||
if (!$this->me->is(["Admin"])) {
|
||||
$this->redirect("Dashboard");
|
||||
}
|
||||
if (!$this->me->is(["Admin"])) $this->redirect("Dashboard");
|
||||
}
|
||||
|
||||
protected function indexAction()
|
||||
{
|
||||
protected function indexAction() {
|
||||
$cpecounter = 0;
|
||||
$r = $this->request;
|
||||
$page = $r->s;
|
||||
@@ -120,8 +112,7 @@ class CpeprovisioningController extends mfBaseController
|
||||
$this->layout()->set("products", $cpeproducts);
|
||||
}
|
||||
|
||||
private function getPreparedFilter($filter)
|
||||
{
|
||||
private function getPreparedFilter($filter) {
|
||||
$new_filter = [];
|
||||
|
||||
if (!is_array($filter)) $filter = [];
|
||||
@@ -161,8 +152,7 @@ class CpeprovisioningController extends mfBaseController
|
||||
return $new_filter;
|
||||
}
|
||||
|
||||
protected function saveAction()
|
||||
{
|
||||
protected function saveAction() {
|
||||
$r = $this->request;
|
||||
$id = $r->id;
|
||||
//var_dump($r);exit;
|
||||
@@ -397,8 +387,7 @@ class CpeprovisioningController extends mfBaseController
|
||||
self::returnJson(['success' => false, 'message' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
protected function apiGetAction()
|
||||
{
|
||||
protected function apiGetAction(){
|
||||
$p = json_decode(file_get_contents('php://input'), true) ?? [];
|
||||
|
||||
// --- Pagination and Sorting setup ---
|
||||
@@ -528,8 +517,7 @@ class CpeprovisioningController extends mfBaseController
|
||||
]);
|
||||
}
|
||||
|
||||
protected function newIndexAction()
|
||||
{
|
||||
protected function newIndexAction() {
|
||||
$this->layout()->set('additionalJS', ['js/pages/Cpeprovisioning/Cpeprovisioning.js']);
|
||||
$this->layout()->set('additionalHead', ['<link rel="stylesheet" href="/js/pages/Cpeprovisioning/Cpeprovisioning.css">']);
|
||||
|
||||
@@ -650,6 +638,4 @@ class CpeprovisioningController extends mfBaseController
|
||||
|
||||
self::returnJson(['open_count' => $openCount]);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
574
public/js/pages/WarehouseOffer/WarehouseBasicOfferModal.js
Normal file
574
public/js/pages/WarehouseOffer/WarehouseBasicOfferModal.js
Normal file
@@ -0,0 +1,574 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
181
public/js/pages/WarehouseOffer/WarehouseLib.js
Normal file
181
public/js/pages/WarehouseOffer/WarehouseLib.js
Normal file
@@ -0,0 +1,181 @@
|
||||
Vue.component('tt-file-upload-light', {
|
||||
props: {
|
||||
/**
|
||||
* Allows multiple files to be selected.
|
||||
*/
|
||||
multiple: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
/**
|
||||
* Text for the upload button.
|
||||
*/
|
||||
buttonText: {
|
||||
type: String,
|
||||
default: 'Datei hochladen'
|
||||
},
|
||||
/**
|
||||
* Optional icon for the upload button.
|
||||
*/
|
||||
buttonIcon: {
|
||||
type: String,
|
||||
default: 'fas fa-paperclip'
|
||||
}
|
||||
},
|
||||
template: `
|
||||
<div class="tt-file-upload-light">
|
||||
<!-- Hidden file input, triggered by the button -->
|
||||
<input type="file" :multiple="multiple" @change="handleFileSelect" ref="fileInput" style="display: none;"/>
|
||||
|
||||
<!-- The button that users click to select files -->
|
||||
<button type="button" class="btn btn-outline-secondary btn-sm" @click="triggerFileInput" :disabled="isUploading">
|
||||
<i :class="buttonIcon"></i>
|
||||
<span v-if="buttonText" class="ml-1">{{ buttonText }}</span>
|
||||
</button>
|
||||
|
||||
<!-- List of files being uploaded or already uploaded -->
|
||||
<div v-if="files.length > 0" class="file-list mt-2">
|
||||
<div v-for="(file, index) in files" :key="index" class="file-item">
|
||||
<div class="file-info">
|
||||
<i :class="fileIcon(file)" class="file-icon"></i>
|
||||
<span class="file-name">{{ file.file.name }}</span>
|
||||
<span class="file-size">({{ formatSize(file.file.size) }})</span>
|
||||
</div>
|
||||
<div class="file-status">
|
||||
<!-- Progress bar during upload -->
|
||||
<div v-if="file.status === 'uploading'" class="progress" style="height: 10px; width: 100px;">
|
||||
<div class="progress-bar" role="progressbar" :style="{ width: file.progress + '%' }" aria-valuenow="file.progress" aria-valuemin="0" aria-valuemax="100"></div>
|
||||
</div>
|
||||
<!-- Status text -->
|
||||
<span v-if="file.status === 'error'" class="text-danger small">Fehler</span>
|
||||
<span v-if="file.status === 'success'" class="text-success small">Fertig</span>
|
||||
|
||||
<!-- Remove button -->
|
||||
<button type="button" class="btn btn-link btn-sm text-danger p-0 ml-2" @click="removeFile(index)">
|
||||
<i class="fas fa-times"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`,
|
||||
data() {
|
||||
return {
|
||||
files: [], // Array to store file wrappers { file, progress, status, response }
|
||||
uploadUrl: window.TT_CONFIG['BASE_PATH'] + '/File/upload', // Standard file upload endpoint
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
/**
|
||||
* Checks if any file is currently being uploaded.
|
||||
* @returns {boolean}
|
||||
*/
|
||||
isUploading() {
|
||||
return this.files.some(f => f.status === 'uploading');
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
/**
|
||||
* Programmatically clicks the hidden file input element.
|
||||
*/
|
||||
triggerFileInput() {
|
||||
this.$refs.fileInput.click();
|
||||
},
|
||||
|
||||
/**
|
||||
* Handles the file selection event when the user chooses files.
|
||||
* @param {Event} event - The file input change event.
|
||||
*/
|
||||
handleFileSelect(event) {
|
||||
const selectedFiles = event.target.files;
|
||||
if (!selectedFiles) return;
|
||||
|
||||
// Create a wrapper for each file and start the upload
|
||||
Array.from(selectedFiles).forEach(file => {
|
||||
const fileWrapper = {
|
||||
file: file,
|
||||
progress: 0,
|
||||
status: 'pending', // Status: pending, uploading, success, error
|
||||
response: null,
|
||||
};
|
||||
this.files.push(fileWrapper);
|
||||
this.uploadFile(fileWrapper);
|
||||
});
|
||||
|
||||
// Reset the input value to allow selecting the same file again
|
||||
event.target.value = '';
|
||||
},
|
||||
|
||||
/**
|
||||
* Uploads a single file to the server.
|
||||
* @param {object} fileWrapper - The file object wrapper.
|
||||
*/
|
||||
async uploadFile(fileWrapper) {
|
||||
const formData = new FormData();
|
||||
formData.append('file', fileWrapper.file);
|
||||
fileWrapper.status = 'uploading';
|
||||
|
||||
try {
|
||||
const response = await axios.post(this.uploadUrl, formData, {
|
||||
onUploadProgress: (progressEvent) => {
|
||||
fileWrapper.progress = Math.round((progressEvent.loaded * 100) / progressEvent.total);
|
||||
}
|
||||
});
|
||||
|
||||
fileWrapper.status = 'success';
|
||||
fileWrapper.response = response.data;
|
||||
|
||||
// Emit an event with the successful upload data
|
||||
this.$emit('uploaded', response.data);
|
||||
window.notify('success', `${fileWrapper.file.name} erfolgreich hochgeladen.`);
|
||||
|
||||
} catch (error) {
|
||||
fileWrapper.status = 'error';
|
||||
console.error('File upload failed:', error);
|
||||
window.notify('error', `Upload von ${fileWrapper.file.name} fehlgeschlagen.`);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Public method to reset the component state, clearing all files.
|
||||
*/
|
||||
reset() {
|
||||
this.files = [];
|
||||
},
|
||||
|
||||
/**
|
||||
* Removes a file from the list.
|
||||
* @param {number} index - The index of the file to remove.
|
||||
*/
|
||||
removeFile(index) {
|
||||
this.files.splice(index, 1);
|
||||
},
|
||||
|
||||
/**
|
||||
* Formats file size from bytes to a readable string.
|
||||
* @param {number} bytes - The file size in bytes.
|
||||
* @returns {string}
|
||||
*/
|
||||
formatSize(bytes) {
|
||||
if (bytes === 0) return '0 Bytes';
|
||||
const k = 1024;
|
||||
const sizes = ['Bytes', 'KB', 'MB', 'GB'];
|
||||
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
||||
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns a Font Awesome icon class based on the file status.
|
||||
* @param {object} file - The file wrapper object.
|
||||
* @returns {string}
|
||||
*/
|
||||
fileIcon(file) {
|
||||
switch (file.status) {
|
||||
case 'uploading': return 'fas fa-spinner fa-spin';
|
||||
case 'success': return 'fas fa-check-circle text-success';
|
||||
case 'error': return 'fas fa-exclamation-circle text-danger';
|
||||
default: return 'fas fa-file-alt';
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
File diff suppressed because it is too large
Load Diff
319
public/js/pages/WarehouseOffer/WarehouseOfferModal.js
Normal file
319
public/js/pages/WarehouseOffer/WarehouseOfferModal.js
Normal file
@@ -0,0 +1,319 @@
|
||||
Vue.component('warehouse-offer-modal', {
|
||||
props: {
|
||||
id: {type: [String, Number], required: true},
|
||||
},
|
||||
template: `
|
||||
<tt-modal :show="true"
|
||||
@submit="submit"
|
||||
:delete="id !== 'create'"
|
||||
:title="modalTitle"
|
||||
@update:show="$emit('close')"
|
||||
size="xl">
|
||||
<div style="width: 99%">
|
||||
<!-- Header with Version Dropdown -->
|
||||
<h4 class="text-center mb-0">Angebotsdetails</h4>
|
||||
<div v-if="id !== 'create' && versions.length > 0" class="d-flex align-items-center">
|
||||
<label for="version-select" class="mr-2 mb-0">Version:</label>
|
||||
<select id="version-select" class="form-control form-control-sm mr-2" v-model="selectedVersion" @change="loadVersion" style="max-width:300px">
|
||||
<option v-for="v in versions" :value="v.version">{{ v.version }} ({{ formatDate(v.date) }} - {{ v.user }})</option>
|
||||
</select>
|
||||
<tt-button text="PDF für diese Version" @click="openVersionPDF" sm icon="fas fa-file-pdf" additional-class="btn-primary"/>
|
||||
</div>
|
||||
|
||||
<!-- Customer and Contact -->
|
||||
<div class="card mb-3">
|
||||
<div class="card-header">Kunde & Kontakt</div>
|
||||
<div class="card-body">
|
||||
<div class="row">
|
||||
<div class="col-md-4">
|
||||
<tt-autocomplete label="Kunde" v-model="offer.customerNumber" sm :api-url="billAddrAutoCompleteUrl" :disabled="isReadonly"/>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<tt-input label="Kontaktperson" v-model="offer.contactPerson" sm :disabled="isReadonly"/>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<tt-input label="Kontakt E-Mail" v-model="offer.contactPersonEmail" sm :disabled="isReadonly"/>
|
||||
</div>
|
||||
</div>
|
||||
<tt-input label="Kundenreferenz" v-model="offer.reference" sm row :disabled="isReadonly"/>
|
||||
<tt-textarea label="Angebotszweck" v-model="offer.purpose" sm row :disabled="isReadonly"/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Customer Address -->
|
||||
<div class="card mb-3">
|
||||
<div class="card-header">Kundenadresse</div>
|
||||
<div class="card-body">
|
||||
<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 :disabled="isReadonly"/>
|
||||
<tt-input label="Straße" v-model="offer.customerStreet" sm :disabled="isReadonly"/>
|
||||
<tt-input label="PLZ" v-model="offer.customerZip" sm :disabled="isReadonly"/>
|
||||
<tt-input label="Ort" v-model="offer.customerCity" sm :disabled="isReadonly"/>
|
||||
<tt-input label="USt-IdNr." v-model="offer.customerVAT" sm :disabled="isReadonly"/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Positions -->
|
||||
<div class="card mb-3">
|
||||
<div class="card-header">Positionen</div>
|
||||
<div class="card-body" ref="positionsManagerContainer">
|
||||
<tt-positions-manager group-mode ref="positionsManager" v-model="offer.positions" :config="positionsConfig"
|
||||
@updateField-article="fetchArticleData" :readonly="isReadonly"/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Summary and Terms -->
|
||||
<div class="card mb-3">
|
||||
<div class="card-header">Konditionen & Schlusstext</div>
|
||||
<div class="card-body">
|
||||
<div class="row">
|
||||
<div class="col-md-8">
|
||||
<tt-input label="Gesamtrabatt (%)" v-model.number="offer.totalDiscount" sm row type="number" :disabled="isReadonly"/>
|
||||
<tt-select label="Zahlungskonditionen" :options="paymentTerms" sm row v-model="offer.paymentTerms" :disabled="isReadonly"/>
|
||||
<tt-select label="Lieferkonditionen" :options="deliveryTerms" sm row v-model="offer.deliveryTerms" :disabled="isReadonly"/>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<h5 class="text-right">Nettobetrag: {{ formatPrice(netTotalPrice) }} €</h5>
|
||||
<h5 class="text-right">Alternativbetrag: {{ formatPrice(alternativeTotalPrice) }} €</h5>
|
||||
<h4 class="text-right">Gesamtbetrag: {{ formatPrice(offerTotalPrice) }} €</h4>
|
||||
</div>
|
||||
</div>
|
||||
<hr>
|
||||
<div class="d-flex justify-content-between align-items-center">
|
||||
<label>Schlusstext</label>
|
||||
<tt-button v-if="!isReadonly" text="Vorlage wählen" @click="showClosingTextModal = true" sm/>
|
||||
</div>
|
||||
<tt-textarea sm rows="8" row v-model="offer.closingText" :disabled="isReadonly"/>
|
||||
<hr>
|
||||
<tt-textarea label="Interne Notizen" v-model="offer.notes" sm row :disabled="isReadonly"/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Modals -->
|
||||
<closing-text-modal v-if="showClosingTextModal" @close="showClosingTextModal = false" @select="applyClosingText"/>
|
||||
|
||||
<template v-slot:footer-prepend v-if="!isReadonly">
|
||||
<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,
|
||||
isAddressManuallyChanged: false,
|
||||
versions: [],
|
||||
selectedVersion: null,
|
||||
isReadonly: false,
|
||||
showClosingTextModal: false,
|
||||
positionsConfig: {
|
||||
fields: {
|
||||
article: { type: 'input-article', label: 'Artikel', customFieldReference: 'WarehouseArticle' },
|
||||
amount: { type: 'input', label: 'Menge', inputType: 'number', editableInTable: true },
|
||||
unit: { type: 'input', label: 'Einheit' },
|
||||
articleNumber: { type: 'input', label: 'Artikelnummer' },
|
||||
unitPrice: { type: 'input', label: 'Einzelpreis', inputType: 'number', editableInTable: true },
|
||||
discount: { type: 'input', label: 'Rabatt (%)', inputType: 'number', editableInTable: true },
|
||||
comment: { type: 'input', label: 'Kommentar', editableInTable: true },
|
||||
isAlternative: { type: 'checkbox', label: 'Alternativ' },
|
||||
},
|
||||
validateForm: (formData) => { /* ... validation logic ... */ 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'},
|
||||
],
|
||||
offer: {
|
||||
editor: window.TT_CONFIG['USER_ID'],
|
||||
customerNumber: '',
|
||||
reference: '',
|
||||
purpose: '',
|
||||
customerName: '',
|
||||
customerStreet: '',
|
||||
customerZip: '',
|
||||
customerCity: '',
|
||||
customerVAT: '',
|
||||
contactPerson: '',
|
||||
contactPersonEmail: '',
|
||||
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.\nAuftragsgültigkeit erhöhen (Stichtag Datum), sind wir gezwungen die Preise anzupassen.\nDiese Angebot hat eine Gültigkeit von 4 Wochen.\nVerrechnung erfolgt nach tatsächlichem Aufwand.\nWir sind sicher, Ihnen ein konkurenzfähiges Angebot unterbreitet zu haben und sehen gern Ihrer Bestellung entgegen.\nSollten Sie noch Fragen oder weitere Informationen benötigen stehen wir Ihnen jederzeit gern zu Verfügung.',
|
||||
notes: '',
|
||||
},
|
||||
templateName: '',
|
||||
ignoreFirstAddressChange: false,
|
||||
}
|
||||
},
|
||||
async mounted() {
|
||||
if (this.id !== 'create') {
|
||||
this.ignoreFirstAddressChange = true;
|
||||
await this.loadOffer(this.id);
|
||||
await this.loadVersions();
|
||||
} else {
|
||||
this.offer.editor = parseInt(window.TT_CONFIG['USER_ID']);
|
||||
}
|
||||
// Add focus-out listener to scroll up
|
||||
this.$refs.positionsManagerContainer.addEventListener('focusout', () => {
|
||||
this.$refs.positionsManagerContainer.scrollTop = 0;
|
||||
});
|
||||
},
|
||||
methods: {
|
||||
formatDate: ts => ts ? window.moment(ts * 1000).format('DD.MM.YYYY HH:mm') : '-',
|
||||
formatPrice: price => new Intl.NumberFormat('de-AT', { style: 'currency', currency: 'EUR' }).format(price || 0),
|
||||
async loadOffer(id) {
|
||||
const response = await axios.get(`${window.TT_CONFIG["BASE_PATH"]}/WarehouseOffer/getById`, {params: {id}});
|
||||
this.offer = response.data;
|
||||
this.offer.positions = JSON.parse(this.offer.positions || '[]');
|
||||
this.selectedVersion = this.offer.version;
|
||||
this.isReadonly = false; // Default to editable
|
||||
},
|
||||
async loadVersions() {
|
||||
const response = await axios.get(`${window.TT_CONFIG["BASE_PATH"]}/WarehouseOffer/getVersions`, {params: {id: this.id}});
|
||||
this.versions = response.data.sort((a, b) => b.version - a.version);
|
||||
if(this.versions.length > 0 && !this.selectedVersion) {
|
||||
this.selectedVersion = this.versions[0].version;
|
||||
}
|
||||
},
|
||||
loadVersion() {
|
||||
const versionData = this.versions.find(v => v.version == this.selectedVersion);
|
||||
if (versionData && versionData.data) {
|
||||
this.offer = versionData.data;
|
||||
// Ensure positions is always an array
|
||||
this.offer.positions = typeof versionData.data.positions === 'string' ? JSON.parse(versionData.data.positions || '[]') : (versionData.data.positions || []);
|
||||
this.isReadonly = this.selectedVersion != this.versions[0].version; // Only latest version is editable
|
||||
window.notify('info', `Version ${this.selectedVersion} geladen. Nur die aktuellste Version ist bearbeitbar.`);
|
||||
}
|
||||
},
|
||||
openVersionPDF() {
|
||||
if (!this.selectedVersion) {
|
||||
window.notify('error', 'Keine Version ausgewählt.');
|
||||
return;
|
||||
}
|
||||
window.open(`${window.TT_CONFIG['BASE_PATH']}/WarehouseOffer/createPDF?id=${this.id}&version=${this.selectedVersion}`);
|
||||
},
|
||||
applyClosingText(text) {
|
||||
this.offer.closingText = text;
|
||||
this.showClosingTextModal = false;
|
||||
},
|
||||
async submit() {
|
||||
if (this.isReadonly) {
|
||||
return window.notify('info', 'Alte Versionen können nicht gespeichert werden. Erstellen Sie eine neue Version durch Bearbeiten der Aktuellsten.');
|
||||
}
|
||||
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`;
|
||||
|
||||
try {
|
||||
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');
|
||||
}
|
||||
} catch (e) {
|
||||
window.notify('error', 'Speichern fehlgeschlagen: ' + e.message);
|
||||
}
|
||||
},
|
||||
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');
|
||||
}
|
||||
},
|
||||
trackManualAddressChange() {
|
||||
if (this.id === 'create' || !this.isReadonly) {
|
||||
this.isAddressManuallyChanged = true;
|
||||
}
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
'offer.customerNumber': async function (newVal, oldVal) {
|
||||
if (!newVal || this.isAddressManuallyChanged) return;
|
||||
if (this.ignoreFirstAddressChange) {
|
||||
this.ignoreFirstAddressChange = false;
|
||||
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) {
|
||||
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 || '';
|
||||
this.offer.contactPersonEmail = address.email || '';
|
||||
},
|
||||
'offer.customerName': function() { this.trackManualAddressChange() },
|
||||
'offer.customerStreet': function() { this.trackManualAddressChange() },
|
||||
'offer.customerZip': function() { this.trackManualAddressChange() },
|
||||
'offer.customerCity': function() { this.trackManualAddressChange() },
|
||||
},
|
||||
computed: {
|
||||
modalTitle() {
|
||||
if (this.id === 'create') return 'Angebot erstellen';
|
||||
let title = `Angebot #${this.offer.offerNumber} (v${this.selectedVersion || this.offer.version})`;
|
||||
if(this.isReadonly) title += ' - Schreibgeschützt';
|
||||
return title;
|
||||
},
|
||||
netTotalPrice() {
|
||||
if (!this.offer.positions) return 0;
|
||||
return this.offer.positions.reduce((total, p) => {
|
||||
if (p.isAlternative || !p.amount || !p.unitPrice) return total;
|
||||
const discount = p.discount ? (p.unitPrice * p.amount) * p.discount / 100 : 0;
|
||||
return total + (p.unitPrice * p.amount) - discount;
|
||||
}, 0);
|
||||
},
|
||||
alternativeTotalPrice() {
|
||||
if (!this.offer.positions) return 0;
|
||||
return this.offer.positions.reduce((total, p) => {
|
||||
if (!p.isAlternative || !p.amount || !p.unitPrice) return total;
|
||||
const discount = p.discount ? (p.unitPrice * p.amount) * p.discount / 100 : 0;
|
||||
return total + (p.unitPrice * p.amount) - discount;
|
||||
}, 0);
|
||||
},
|
||||
offerTotalPrice() {
|
||||
const total = this.netTotalPrice;
|
||||
return total - (total * (this.offer.totalDiscount || 0) / 100);
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -23,16 +23,16 @@
|
||||
}
|
||||
|
||||
.positions-manager .form-container .button-wrapper {
|
||||
align-self: flex-end; /* Align button container at the bottom */
|
||||
align-self: flex-end;
|
||||
}
|
||||
|
||||
.positions-manager .form-container [class*="tt-input"],
|
||||
.positions-manager .form-container [class*="tt-checkbox"] {
|
||||
flex: 1 1; /* Flexible width with a minimum of 200px */
|
||||
flex: 1 1;
|
||||
}
|
||||
|
||||
.positions-manager .form-container .btn {
|
||||
align-self: flex-end; /* Align button at the bottom of the form area */
|
||||
align-self: flex-end;
|
||||
}
|
||||
|
||||
.positions-manager table {
|
||||
@@ -51,11 +51,11 @@
|
||||
.positions-manager table th,
|
||||
.positions-manager table td {
|
||||
padding: 8px;
|
||||
vertical-align: middle; /* Vertically center text */
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
.positions-manager table tbody tr:nth-child(even) {
|
||||
background-color: #f9f9f9; /* Alternate row color */
|
||||
background-color: #f9f9f9;
|
||||
}
|
||||
|
||||
.positions-manager table .btn {
|
||||
@@ -64,24 +64,26 @@
|
||||
|
||||
.positions-manager .form-container .btn-sm,
|
||||
.positions-manager table .btn.btn-sm {
|
||||
padding: 0.3rem 0.6rem; /* Small button padding */
|
||||
padding: 0.3rem 0.6rem;
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
|
||||
.positions-manager.ctrl-pressed .position-row {
|
||||
.positions-manager.ctrl-pressed .position-row,
|
||||
.positions-manager.ctrl-pressed .group-header-row {
|
||||
cursor: grab;
|
||||
}
|
||||
|
||||
.positions-manager.ctrl-pressed .position-row:active {
|
||||
.positions-manager.ctrl-pressed .position-row:active,
|
||||
.positions-manager.ctrl-pressed .group-header-row:active {
|
||||
cursor: grabbing;
|
||||
}
|
||||
|
||||
.position-row.dragging {
|
||||
.position-row.dragging,
|
||||
.group-header-row.dragging {
|
||||
opacity: 0.5;
|
||||
background: #f0f0f0;
|
||||
}
|
||||
|
||||
/* Style for the drop indicator */
|
||||
.drop-indicator {
|
||||
border-top: 2px solid #007bff !important;
|
||||
}
|
||||
}
|
||||
@@ -56,10 +56,10 @@ Vue.component('tt-positions-manager', {
|
||||
index: null,
|
||||
key: null
|
||||
},
|
||||
// --- New properties for Drag and Drop ---
|
||||
ctrlPressed: false, // Is the Ctrl key currently pressed?
|
||||
draggingItem: null, // The actual position object being dragged
|
||||
dragOverItem: null // The position object the mouse is currently over
|
||||
ctrlPressed: false,
|
||||
draggingItem: null,
|
||||
dragOverItem: null,
|
||||
draggingGroup: null
|
||||
}
|
||||
},
|
||||
template: `
|
||||
@@ -127,7 +127,6 @@ Vue.component('tt-positions-manager', {
|
||||
/>
|
||||
<slot :name="key + '-prepend'" v-bind:field="field" v-bind:value="formData[key]"/>
|
||||
</div>
|
||||
|
||||
</slot>
|
||||
</template>
|
||||
</template>
|
||||
@@ -138,11 +137,8 @@ Vue.component('tt-positions-manager', {
|
||||
:additional-class="selectedIndex === null ? 'btn-primary' : 'btn-success'"
|
||||
:text="selectedIndex === null ? 'Hinzufügen' : 'Aktualisieren'"/>
|
||||
</div>
|
||||
|
||||
<slot name="form-actions-append"></slot>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="form-container" v-if="groupMode">
|
||||
<tt-input label="Gruppenname" v-model="groupName" sm/>
|
||||
<tt-button @click="addGroup" sm text="Gruppe hinzufügen" additional-class="btn-primary"/>
|
||||
@@ -158,10 +154,16 @@ Vue.component('tt-positions-manager', {
|
||||
<template v-for="(group, groupName) in positionsToRender">
|
||||
<tr v-if="groupMode"
|
||||
class="group-header-row"
|
||||
:class="{
|
||||
'dragging': draggingGroup === groupName,
|
||||
'drop-indicator': dragOverItem === groupName && draggingGroup && draggingGroup !== groupName
|
||||
}"
|
||||
:draggable="ctrlPressed"
|
||||
@dragstart="onGroupDragStart(groupName, $event)"
|
||||
@dragend="onDragEnd"
|
||||
@dragover.prevent="dragOverItem = groupName"
|
||||
@dragleave="dragOverItem = null"
|
||||
@drop="onDrop(groupName)"
|
||||
:class="{'drop-indicator': dragOverItem === groupName}">
|
||||
@drop.stop="onDrop(groupName)">
|
||||
<td :colspan="Object.keys(config.fields).length + 1">
|
||||
<div class="d-flex justify-content-center align-items-center">
|
||||
<template v-if="editingGroupName === groupName">
|
||||
@@ -184,15 +186,14 @@ Vue.component('tt-positions-manager', {
|
||||
class="position-row"
|
||||
:class="{
|
||||
'dragging': draggingItem === position,
|
||||
'drop-indicator': dragOverItem === position
|
||||
'drop-indicator': dragOverItem === position && draggingItem
|
||||
}"
|
||||
:draggable="ctrlPressed"
|
||||
@dragstart="onDragStart(position, $event)"
|
||||
@dragend="onDragEnd"
|
||||
@dragover.prevent="dragOverItem = position"
|
||||
@dragleave="dragOverItem = null"
|
||||
@drop="onDrop(position)">
|
||||
|
||||
@drop.stop="onDrop(position)">
|
||||
<td v-for="(field, key) in config.fields"
|
||||
:class="{'editable-cell': field.editableInTable && (field.type === 'input' || field.type === 'textarea')}"
|
||||
@click="startCellEdit(groupName, positions.indexOf(position), key, field)">
|
||||
@@ -242,49 +243,57 @@ Vue.component('tt-positions-manager', {
|
||||
</div>
|
||||
`,
|
||||
methods: {
|
||||
// --- NEW DRAG AND DROP METHODS ---
|
||||
handleKeyDown(event) {
|
||||
if (event.key === 'Control' || event.key === 'Meta') { // Meta is for MacOS Command key
|
||||
this.ctrlPressed = true;
|
||||
}
|
||||
if (event.key === 'Control' || event.key === 'Meta') this.ctrlPressed = true;
|
||||
},
|
||||
handleKeyUp(event) {
|
||||
if (event.key === 'Control' || event.key === 'Meta') {
|
||||
this.ctrlPressed = false;
|
||||
}
|
||||
if (event.key === 'Control' || event.key === 'Meta') this.ctrlPressed = false;
|
||||
},
|
||||
onDragStart(position, event) {
|
||||
this.draggingItem = position;
|
||||
// Necessary for Firefox to enable drag
|
||||
this.draggingGroup = null;
|
||||
event.dataTransfer.setData('text/plain', '');
|
||||
event.dataTransfer.effectAllowed = 'move';
|
||||
},
|
||||
onGroupDragStart(groupName, event) {
|
||||
this.draggingGroup = groupName;
|
||||
this.draggingItem = null;
|
||||
event.dataTransfer.setData('text/plain', '');
|
||||
event.dataTransfer.effectAllowed = 'move';
|
||||
},
|
||||
onDrop(targetItemOrGroup) {
|
||||
if (!this.draggingItem) return;
|
||||
if (this.draggingItem) {
|
||||
const draggedIndex = this.positions.indexOf(this.draggingItem);
|
||||
const itemToMove = this.positions.splice(draggedIndex, 1)[0];
|
||||
let targetIndex, newGroup;
|
||||
if (typeof targetItemOrGroup === 'string') {
|
||||
newGroup = targetItemOrGroup;
|
||||
const firstItemOfGroup = this.positions.find(p => (p._group || 'Keine Gruppe') === newGroup);
|
||||
targetIndex = firstItemOfGroup ? this.positions.indexOf(firstItemOfGroup) : this.positions.length;
|
||||
} else {
|
||||
newGroup = targetItemOrGroup._group || 'Keine Gruppe';
|
||||
targetIndex = this.positions.indexOf(targetItemOrGroup);
|
||||
}
|
||||
this.$set(itemToMove, '_group', newGroup);
|
||||
this.positions.splice(targetIndex, 0, itemToMove);
|
||||
this.$emit('input', this.positions);
|
||||
} else if (this.draggingGroup) {
|
||||
const targetGroupName = typeof targetItemOrGroup === 'string'
|
||||
? targetItemOrGroup
|
||||
: (targetItemOrGroup._group || 'Keine Gruppe');
|
||||
if (this.draggingGroup === targetGroupName) return this.cleanupDrag();
|
||||
|
||||
const draggedIndex = this.positions.indexOf(this.draggingItem);
|
||||
// Remove item from its original position
|
||||
const itemToMove = this.positions.splice(draggedIndex, 1)[0];
|
||||
const groupOrder = [...this.allGroups];
|
||||
const fromIndex = groupOrder.indexOf(this.draggingGroup);
|
||||
const [movedGroup] = groupOrder.splice(fromIndex, 1);
|
||||
const toIndex = groupOrder.indexOf(targetGroupName);
|
||||
groupOrder.splice(toIndex, 0, movedGroup);
|
||||
|
||||
let targetIndex;
|
||||
let newGroup;
|
||||
|
||||
if (typeof targetItemOrGroup === 'string') {
|
||||
// Dropped on a group header
|
||||
newGroup = targetItemOrGroup;
|
||||
const firstItemOfGroup = this.positions.find(p => (p._group || 'Keine Gruppe') === newGroup);
|
||||
targetIndex = firstItemOfGroup ? this.positions.indexOf(firstItemOfGroup) : this.positions.length;
|
||||
} else {
|
||||
// Dropped on another position item
|
||||
newGroup = targetItemOrGroup._group || 'Keine Gruppe';
|
||||
targetIndex = this.positions.indexOf(targetItemOrGroup);
|
||||
const newPositions = groupOrder.flatMap(groupName =>
|
||||
this.positions.filter(p => (p._group || 'Keine Gruppe') === groupName)
|
||||
);
|
||||
this.$emit('input', newPositions);
|
||||
}
|
||||
|
||||
// Update group and insert at the new position
|
||||
this.$set(itemToMove, '_group', newGroup);
|
||||
this.positions.splice(targetIndex, 0, itemToMove);
|
||||
|
||||
this.$emit('input', this.positions);
|
||||
this.cleanupDrag();
|
||||
},
|
||||
onDragEnd() {
|
||||
@@ -293,9 +302,8 @@ Vue.component('tt-positions-manager', {
|
||||
cleanupDrag() {
|
||||
this.draggingItem = null;
|
||||
this.dragOverItem = null;
|
||||
this.draggingGroup = null;
|
||||
},
|
||||
|
||||
// --- EXISTING METHODS (some are simplified) ---
|
||||
updateField(key, value) {
|
||||
this.$set(this.formData, key, value);
|
||||
},
|
||||
@@ -376,9 +384,7 @@ Vue.component('tt-positions-manager', {
|
||||
if (confirm(`Möchten Sie die Gruppe "${groupName}" wirklich löschen? Alle Einträge werden in "Keine Gruppe" verschoben.`)) {
|
||||
this.positions = this.positions.filter(position => {
|
||||
if (position._group === groupName) {
|
||||
if (Object.keys(position).length === 1) {
|
||||
return false;
|
||||
}
|
||||
if (Object.keys(position).length === 1) return false;
|
||||
this.$set(position, '_group', 'Keine Gruppe');
|
||||
}
|
||||
return true;
|
||||
@@ -386,7 +392,7 @@ Vue.component('tt-positions-manager', {
|
||||
this.$emit('input', this.positions);
|
||||
}
|
||||
},
|
||||
async editEntry(position) { // Simplified to take position object
|
||||
async editEntry(position) {
|
||||
const index = this.positions.indexOf(position);
|
||||
if (index === -1) return;
|
||||
|
||||
@@ -406,7 +412,7 @@ Vue.component('tt-positions-manager', {
|
||||
this.$refs.formContainer.scrollIntoView({ behavior: 'smooth', block: 'start' });
|
||||
});
|
||||
},
|
||||
deleteEntry(position) { // Simplified to take position object
|
||||
deleteEntry(position) {
|
||||
const index = this.positions.indexOf(position);
|
||||
if (index > -1) {
|
||||
this.positions.splice(index, 1);
|
||||
@@ -437,15 +443,11 @@ Vue.component('tt-positions-manager', {
|
||||
this.editingCell = { groupName, index, key };
|
||||
this.$nextTick(() => {
|
||||
const inputElement = this.$el.querySelector(`.editable-cell input[type="${field.type}"], .editable-cell textarea`);
|
||||
if (inputElement) {
|
||||
inputElement.focus();
|
||||
}
|
||||
if (inputElement) inputElement.focus();
|
||||
});
|
||||
},
|
||||
saveCellEdit(position, key) {
|
||||
this.editingCell = { groupName: null, index: null, key: null };
|
||||
// Since `position` is an object from the array, it's already reactive.
|
||||
// We just emit the change.
|
||||
this.$emit('input', this.positions);
|
||||
},
|
||||
isCellEditing(groupName, index, key) {
|
||||
@@ -469,38 +471,28 @@ Vue.component('tt-positions-manager', {
|
||||
},
|
||||
mounted() {
|
||||
this.resetForm();
|
||||
// Add listeners for the Ctrl key
|
||||
window.addEventListener('keydown', this.handleKeyDown);
|
||||
window.addEventListener('keyup', this.handleKeyUp);
|
||||
window.addEventListener('blur', () => { this.ctrlPressed = false; }); // Reset if window loses focus
|
||||
window.addEventListener('blur', () => { this.ctrlPressed = false; });
|
||||
},
|
||||
beforeDestroy() {
|
||||
// Important: remove listeners to prevent memory leaks
|
||||
window.removeEventListener('keydown', this.handleKeyDown);
|
||||
window.removeEventListener('keyup', this.handleKeyUp);
|
||||
},
|
||||
computed: {
|
||||
groupedPositions() {
|
||||
const groups = {};
|
||||
// Ensure there's a default group for items without one
|
||||
if (this.positions.some(p => !p._group && Object.keys(p).length > 1)) {
|
||||
groups['Keine Gruppe'] = [];
|
||||
}
|
||||
|
||||
// Get all unique group names first to preserve order
|
||||
const groupNames = [...new Set(this.positions.map(p => p._group).filter(Boolean))];
|
||||
groupNames.forEach(name => {
|
||||
groups[name] = [];
|
||||
});
|
||||
groupNames.forEach(name => groups[name] = []);
|
||||
|
||||
for (const position of this.positions) {
|
||||
// Ignore empty group placeholders
|
||||
if (Object.keys(position).length === 1 && position._group) continue;
|
||||
|
||||
const groupName = position._group || 'Keine Gruppe';
|
||||
if (!groups[groupName]) {
|
||||
groups[groupName] = [];
|
||||
}
|
||||
if (!groups[groupName]) groups[groupName] = [];
|
||||
groups[groupName].push(position);
|
||||
}
|
||||
return groups;
|
||||
@@ -509,7 +501,16 @@ Vue.component('tt-positions-manager', {
|
||||
return this.groupMode ? this.groupedPositions : {'': this.positions};
|
||||
},
|
||||
allGroups() {
|
||||
return ['Keine Gruppe', ...Object.keys(this.groupedPositions).filter(g => g !== 'Keine Gruppe')];
|
||||
const groupOrder = [];
|
||||
const seenGroups = new Set();
|
||||
for (const pos of this.positions) {
|
||||
const groupName = pos._group || 'Keine Gruppe';
|
||||
if (!seenGroups.has(groupName)) {
|
||||
seenGroups.add(groupName);
|
||||
groupOrder.push(groupName);
|
||||
}
|
||||
}
|
||||
return groupOrder;
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
@@ -520,4 +521,4 @@ Vue.component('tt-positions-manager', {
|
||||
deep: true
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user