diff --git a/backend/controllers/falukantController.js b/backend/controllers/falukantController.js index 7ceaac5..3c77829 100644 --- a/backend/controllers/falukantController.js +++ b/backend/controllers/falukantController.js @@ -262,11 +262,17 @@ class FalukantController { const body = req.body || {}; const items = Array.isArray(body.items) ? body.items : []; const currentRegionId = body.currentRegionId != null ? parseInt(body.currentRegionId, 10) : null; + const includeTransportCosts = body.includeTransportCosts === true || body.includeTransportCosts === 'true'; const valid = items.map(i => ({ productId: parseInt(i.productId, 10), currentPrice: parseFloat(i.currentPrice) })).filter(i => !Number.isNaN(i.productId) && !Number.isNaN(i.currentPrice)); - return this.service.getProductPricesInCitiesBatch(userId, valid, Number.isNaN(currentRegionId) ? null : currentRegionId); + return this.service.getProductPricesInCitiesBatch( + userId, + valid, + Number.isNaN(currentRegionId) ? null : currentRegionId, + { includeTransportCosts } + ); }); this.renovate = this._wrapWithUser((userId, req) => this.service.renovate(userId, req.body.element), { blockInDebtorsPrison: true }); this.renovateAll = this._wrapWithUser((userId) => this.service.renovateAll(userId), { blockInDebtorsPrison: true }); diff --git a/backend/services/falukantService.js b/backend/services/falukantService.js index 11d13b1..3c2efcc 100644 --- a/backend/services/falukantService.js +++ b/backend/services/falukantService.js @@ -7079,8 +7079,9 @@ class FalukantService extends BaseService { * @param {number|null} currentRegionId * @returns {Promise>>} */ - async getProductPricesInCitiesBatch(hashedUserId, items, currentRegionId = null) { + async getProductPricesInCitiesBatch(hashedUserId, items, currentRegionId = null, options = {}) { if (!items || items.length === 0) return {}; + const includeTransportCosts = Boolean(options?.includeTransportCosts); const productIds = [...new Set(items.map(i => i.productId))]; const priceByProduct = new Map(items.map(i => [i.productId, i.currentPrice])); @@ -7189,7 +7190,9 @@ ORDER BY r.id`, const grossPrice = calcRegionalSellPriceSync(product, knowledgeFactor, worthPercent); if (grossPrice == null) continue; const taxPercent = Number(taxByCity.get(city.id) || 0); - const transportPerPiece = currentRegionId && city.id !== currentRegionId ? (grossPrice * 0.01) : 0; + const transportPerPiece = includeTransportCosts && currentRegionId && city.id !== currentRegionId + ? (grossPrice * 0.01) + : 0; const taxableProfit = Math.max(0, grossPrice - pieceCost - transportPerPiece); const taxPerPiece = taxableProfit * (taxPercent / 100); const netPerPiece = grossPrice - pieceCost - taxPerPiece - transportPerPiece;