Subversion Repositories SmartDukaan

Rev

Rev 37014 | Rev 37084 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 37014 Rev 37015
Line 322... Line 322...
322
 
322
 
323
    /**
323
    /**
324
     * Server-side port of the legacy Zustand carry-bag rule: any item with
324
     * Server-side port of the legacy Zustand carry-bag rule: any item with
325
     * sellingPrice > ₹12,000 needs one carry bag per unit. Runs BEFORE addItemsToCart
325
     * sellingPrice > ₹12,000 needs one carry bag per unit. Runs BEFORE addItemsToCart
326
     * so the full-sync semantics keep the cart consistent in one round-trip.
326
     * so the full-sync semantics keep the cart consistent in one round-trip.
-
 
327
     *
-
 
328
     * Pricing mirrors {@code CartServiceImpl.getCartValidation} (lines 271-278):
-
 
329
     *   PLATINUM / DIAMOND / GOLD / NEW (Rising Star) -> ₹1 flat
-
 
330
     *   SILVER / BRONZE                              -> MRP from carry-bag TagListing
327
     */
331
     */
328
    private void rebalanceCarryBag(List<CartItem> desired) {
332
    private void rebalanceCarryBag(List<CartItem> desired, int fofoId) {
329
        int bagsNeeded = 0;
333
        int bagsNeeded = 0;
330
        for (CartItem ci : desired) {
334
        for (CartItem ci : desired) {
331
            if (ci.getItemId() == ProfitMandiConstants.ITEM_CARRY_BAG) continue;
335
            if (ci.getItemId() == ProfitMandiConstants.ITEM_CARRY_BAG) continue;
332
            if (ci.getSellingPrice() > CARRY_BAG_THRESHOLD) {
336
            if (ci.getSellingPrice() > CARRY_BAG_THRESHOLD) {
333
                bagsNeeded += ci.getQuantity();
337
                bagsNeeded += ci.getQuantity();
334
            }
338
            }
335
        }
339
        }
336
        desired.removeIf(ci -> ci.getItemId() == ProfitMandiConstants.ITEM_CARRY_BAG);
340
        desired.removeIf(ci -> ci.getItemId() == ProfitMandiConstants.ITEM_CARRY_BAG);
337
        if (bagsNeeded > 0) {
341
        if (bagsNeeded > 0) {
338
            CartItem bag = new CartItem(bagsNeeded, ProfitMandiConstants.ITEM_CARRY_BAG);
342
            CartItem bag = new CartItem(bagsNeeded, ProfitMandiConstants.ITEM_CARRY_BAG);
339
            bag.setSellingPrice(CARRY_BAG_PRICE);
343
            bag.setSellingPrice(resolveCarryBagPrice(fofoId));
340
            desired.add(bag);
344
            desired.add(bag);
341
        }
345
        }
342
    }
346
    }
343
 
347
 
-
 
348
    private float resolveCarryBagPrice(int fofoId) {
-
 
349
        PartnerType tier = null;
-
 
350
        try {
-
 
351
            tier = partnerTypeChangeService.getTypeOnDate(fofoId, LocalDate.now());
-
 
352
        } catch (Exception e) {
-
 
353
            // fall through to premium price
-
 
354
        }
-
 
355
        if (tier == PartnerType.SILVER || tier == PartnerType.BRONZE) {
-
 
356
            try {
-
 
357
                TagListing tl = tagListingRepository.selectByItemId(ProfitMandiConstants.ITEM_CARRY_BAG);
-
 
358
                if (tl != null) return tl.getSellingPrice();
-
 
359
            } catch (Exception e) {
-
 
360
                // fall through to premium price
-
 
361
            }
-
 
362
        }
-
 
363
        return CARRY_BAG_PREMIUM_PRICE;
-
 
364
    }
-
 
365
 
344
    private List<CartItem> currentLinesAsItems(int cartId) {
366
    private List<CartItem> currentLinesAsItems(int cartId) {
345
        List<CartLine> lines = cartLineRepository.selectAllByCart(cartId);
367
        List<CartLine> lines = cartLineRepository.selectAllByCart(cartId);
346
        if (lines == null) return new ArrayList<>();
368
        if (lines == null) return new ArrayList<>();
347
        return lines.stream()
369
        return lines.stream()
348
                .map(l -> {
370
                .map(l -> {