diff --git a/backend/controllers/falukantController.js b/backend/controllers/falukantController.js index 3ef0be6..0b5473d 100644 --- a/backend/controllers/falukantController.js +++ b/backend/controllers/falukantController.js @@ -155,10 +155,11 @@ class FalukantController { this.getProductPricesInCities = this._wrapWithUser((userId, req) => { const productId = parseInt(req.query.productId, 10); const currentPrice = parseFloat(req.query.currentPrice); + const currentRegionId = req.query.currentRegionId ? parseInt(req.query.currentRegionId, 10) : null; if (Number.isNaN(productId) || Number.isNaN(currentPrice)) { throw new Error('productId and currentPrice are required'); } - return this.service.getProductPricesInCities(userId, productId, currentPrice); + return this.service.getProductPricesInCities(userId, productId, currentPrice, currentRegionId); }); this.renovate = this._wrapWithUser((userId, req) => this.service.renovate(userId, req.body.element)); this.renovateAll = this._wrapWithUser((userId) => this.service.renovateAll(userId)); diff --git a/backend/services/falukantService.js b/backend/services/falukantService.js index 3bdce5f..42971a0 100644 --- a/backend/services/falukantService.js +++ b/backend/services/falukantService.js @@ -3670,7 +3670,7 @@ class FalukantService extends BaseService { return { price }; } - async getProductPricesInCities(hashedUserId, productId, currentPrice) { + async getProductPricesInCities(hashedUserId, productId, currentPrice, currentRegionId = null) { const user = await this.getFalukantUserByHashedId(hashedUserId); const character = await FalukantCharacter.findOne({ where: { userId: user.id } }); if (!character) { @@ -3725,8 +3725,12 @@ class FalukantService extends BaseService { // Für jede Stadt den Preis berechnen und Branch-Typ bestimmen const results = []; - console.log(`[getProductPricesInCities] productId: ${productId}, currentPrice: ${currentPrice}, knowledgeFactor: ${knowledgeFactor}, product.sellCost: ${product.sellCost}, cities: ${cities.length}`); for (const city of cities) { + // Aktuelle Stadt ausschließen + if (currentRegionId && city.id === currentRegionId) { + continue; + } + // Regionaler Preis-Faktor (worthPercent zwischen 40-60) const worthPercent = worthMap.get(city.id) || 50; // Default 50% wenn nicht gefunden @@ -3738,11 +3742,9 @@ class FalukantService extends BaseService { const max = basePrice; const priceInCity = min + (max - min) * (knowledgeFactor / 100); - console.log(`[getProductPricesInCities] City: ${city.name} (${city.id}), worthPercent: ${worthPercent}, basePrice: ${basePrice}, priceInCity: ${priceInCity}, currentPrice: ${currentPrice}, isBetter: ${priceInCity > currentPrice + 0.001}`); - // Nur Städte zurückgeben, wo der Preis höher ist - // Verwende eine kleine Toleranz (0.001) um Rundungsfehler zu vermeiden - if (priceInCity > currentPrice + 0.001) { + // Keine Toleranz, da wir die aktuelle Stadt bereits ausschließen + if (priceInCity > currentPrice) { // Branch-Typ bestimmen let branchType = null; // null = kein Branch if (city.branches && city.branches.length > 0) { @@ -3767,7 +3769,6 @@ class FalukantService extends BaseService { // Sortiere nach Preis (höchster zuerst) results.sort((a, b) => b.price - a.price); - console.log(`[getProductPricesInCities] Returning ${results.length} cities with better prices`); return results; } diff --git a/frontend/src/components/falukant/RevenueSection.vue b/frontend/src/components/falukant/RevenueSection.vue index 94c43c4..2a05085 100644 --- a/frontend/src/components/falukant/RevenueSection.vue +++ b/frontend/src/components/falukant/RevenueSection.vue @@ -53,6 +53,7 @@ products: { type: Array, required: true }, calculateProductRevenue: { type: Function, required: true }, calculateProductProfit: { type: Function, required: true }, + currentRegionId: { type: Number, default: null }, }, data() { return { @@ -103,14 +104,13 @@ this.loadingPrices.add(product.id); try { const currentPrice = parseFloat(this.calculateProductRevenue(product).absolute); - console.log(`[RevenueSection] Loading prices for product ${product.id} (${product.labelTr}), currentPrice: ${currentPrice}`); const { data } = await apiClient.get('/api/falukant/products/prices-in-cities', { params: { productId: product.id, - currentPrice: currentPrice + currentPrice: currentPrice, + currentRegionId: this.currentRegionId } }); - console.log(`[RevenueSection] Received better prices for product ${product.id}:`, data); this.$set(product, 'betterPrices', data || []); } catch (error) { console.error(`Error loading prices for product ${product.id}:`, error); diff --git a/frontend/src/views/falukant/BranchView.vue b/frontend/src/views/falukant/BranchView.vue index fe5cb69..7fc4d13 100644 --- a/frontend/src/views/falukant/BranchView.vue +++ b/frontend/src/views/falukant/BranchView.vue @@ -49,6 +49,7 @@ :products="products" :calculateProductRevenue="calculateProductRevenue" :calculateProductProfit="calculateProductProfit" + :currentRegionId="selectedBranch?.regionId" ref="revenueSection" />