feat(falukant): add transport cost option to product price calculations
All checks were successful
Deploy to production / deploy (push) Successful in 2m49s

- Updated the `getProductPricesInCitiesBatch` method in FalukantService to accept an options parameter for including transport costs in price calculations.
- Modified the tax calculation logic to conditionally apply transport costs based on the new parameter, enhancing the accuracy of pricing based on regional differences.
- Adjusted the FalukantController to pass the includeTransportCosts option from the request body, improving flexibility in pricing queries.
This commit is contained in:
Torsten Schulz (local)
2026-04-13 16:11:53 +02:00
parent b50d2a9a93
commit 9deda3147e
2 changed files with 12 additions and 3 deletions

View File

@@ -7079,8 +7079,9 @@ class FalukantService extends BaseService {
* @param {number|null} currentRegionId
* @returns {Promise<Record<number, Array<{ regionId, regionName, price, branchType }>>>}
*/
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;