diff --git a/backend/migrations/add_condition_to_vehicle.sql b/backend/migrations/add_condition_to_vehicle.sql new file mode 100644 index 0000000..341c01e --- /dev/null +++ b/backend/migrations/add_condition_to_vehicle.sql @@ -0,0 +1,20 @@ +-- Migration: Add condition and available_from columns to vehicle table +-- Date: 2024-12-02 + +ALTER TABLE falukant_data.vehicle +ADD COLUMN IF NOT EXISTS condition INTEGER NOT NULL DEFAULT 100; + +ALTER TABLE falukant_data.vehicle +ADD COLUMN IF NOT EXISTS available_from TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP; + +COMMENT ON COLUMN falukant_data.vehicle.condition IS 'Current condition of the vehicle (0-100)'; +COMMENT ON COLUMN falukant_data.vehicle.available_from IS 'Timestamp when the vehicle becomes available for use'; + +-- Migration: Add build_time_minutes column to vehicle type table +-- Date: 2024-12-03 + +ALTER TABLE falukant_type.vehicle +ADD COLUMN IF NOT EXISTS build_time_minutes INTEGER NOT NULL DEFAULT 0; + +COMMENT ON COLUMN falukant_type.vehicle.build_time_minutes IS 'Time to construct the vehicle, in minutes'; + diff --git a/backend/services/falukantService.js b/backend/services/falukantService.js index 67cb403..3bdce5f 100644 --- a/backend/services/falukantService.js +++ b/backend/services/falukantService.js @@ -3725,6 +3725,7 @@ 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) { // Regionaler Preis-Faktor (worthPercent zwischen 40-60) const worthPercent = worthMap.get(city.id) || 50; // Default 50% wenn nicht gefunden @@ -3737,6 +3738,8 @@ 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) { @@ -3764,6 +3767,7 @@ 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 0edb5ab..94c43c4 100644 --- a/frontend/src/components/falukant/RevenueSection.vue +++ b/frontend/src/components/falukant/RevenueSection.vue @@ -103,12 +103,14 @@ 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 } }); + 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);