Subversion Repositories SmartDukaan

Rev

Rev 35776 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 35776 Rev 35782
Line 2331... Line 2331...
2331
 
2331
 
2332
        LOGGER.info("itemIds {}", itemIds);
2332
        LOGGER.info("itemIds {}", itemIds);
2333
        LOGGER.info("itemIdsWithBothStocks {}", itemIdsWithBothStocks);
2333
        LOGGER.info("itemIdsWithBothStocks {}", itemIdsWithBothStocks);
2334
        LOGGER.info("availableStockItemIds {}", availableStockItemIds);
2334
        LOGGER.info("availableStockItemIds {}", availableStockItemIds);
2335
        LOGGER.info("intransitItemIdsFiltered {}", intransitItemIdsFiltered);
2335
        LOGGER.info("intransitItemIdsFiltered {}", intransitItemIdsFiltered);
-
 
2336
        List<Item> instockItems = new ArrayList<>();
-
 
2337
        if (itemIdsWithBothStocks.isEmpty() && availableStockItemIds.isEmpty() && intransitItemIdsFiltered.isEmpty()) {
-
 
2338
            instockItems = itemRepository.selectByIds(itemIds);
-
 
2339
        } else {
2336
        List<Item> instockItems = itemRepository.selectByIds(itemIdsWithBothStocks);
2340
            instockItems = itemRepository.selectByIds(itemIdsWithBothStocks);
-
 
2341
        }
-
 
2342
 
2337
 
2343
 
2338
        model.addAttribute("poItems", instockItems);
2344
        model.addAttribute("poItems", instockItems);
2339
        model.addAttribute("price", price);
2345
        model.addAttribute("price", price);
2340
 
2346
 
2341
        return "po-catalog-items";
2347
        return "po-catalog-items";
Line 2445... Line 2451...
2445
            return responseSender.ok(Collections.emptyList());
2451
            return responseSender.ok(Collections.emptyList());
2446
        }
2452
        }
2447
    }
2453
    }
2448
 
2454
 
2449
    @RequestMapping(value = "/indent/getOutOfStockDetails", method = RequestMethod.GET)
2455
    @RequestMapping(value = "/indent/getOutOfStockDetails", method = RequestMethod.GET)
2450
    public ResponseEntity<?> getOutOfStockDetails(HttpServletRequest request, @RequestParam String brand, @RequestParam int warehouseId, Model model) throws Exception {
2456
    public ResponseEntity<?> getOutOfStockDetails(HttpServletRequest request, @RequestParam String brand, @RequestParam int warehouseId, @RequestParam int fofoId, Model model) throws Exception {
2451
        try {
2457
        try {
2452
            // Get all catalogs for the brand with their movement status
2458
            // Get all catalogs for the brand with their movement status
2453
            List<CategorisedCatalogListModel> catalogMovements = categorisedCatalogRepository.getBrandWiseCatalogMovement(brand);
2459
            List<CategorisedCatalogListModel> catalogMovements = categorisedCatalogRepository.getBrandWiseCatalogMovement(brand);
2454
 
2460
 
2455
            // Filter only HID, FASTMOVING, RUNNING status
2461
            // Filter only HID, FASTMOVING, RUNNING status
Line 2462... Line 2468...
2462
 
2468
 
2463
            if (filteredCatalogs.isEmpty()) {
2469
            if (filteredCatalogs.isEmpty()) {
2464
                return responseSender.ok(Collections.emptyList());
2470
                return responseSender.ok(Collections.emptyList());
2465
            }
2471
            }
2466
 
2472
 
-
 
2473
            // Get all catalog IDs for partner stock lookup
-
 
2474
            Set<Integer> allCatalogIds = filteredCatalogs.stream()
-
 
2475
                    .map(CategorisedCatalogListModel::getModelId)
-
 
2476
                    .collect(Collectors.toSet());
-
 
2477
 
-
 
2478
            // Get partner stock for all catalogs - fetch all partner stock and map to catalog IDs
-
 
2479
            Map<Integer, Integer> partnerStockMap = new HashMap<>();
-
 
2480
            if (!allCatalogIds.isEmpty()) {
-
 
2481
                List<CurrentInventorySnapshot> partnerSnapshots = currentInventorySnapshotRepository.selectByFofoId(fofoId);
-
 
2482
                // Get item IDs from snapshots
-
 
2483
                Set<Integer> itemIds = partnerSnapshots.stream()
-
 
2484
                        .map(CurrentInventorySnapshot::getItemId)
-
 
2485
                        .collect(Collectors.toSet());
-
 
2486
                // Get items to map itemId -> catalogId
-
 
2487
                Map<Integer, Integer> itemToCatalogMap = new HashMap<>();
-
 
2488
                for (Integer itemId : itemIds) {
-
 
2489
                    Item item = itemRepository.selectById(itemId);
-
 
2490
                    if (item != null) {
-
 
2491
                        itemToCatalogMap.put(itemId, item.getCatalogItemId());
-
 
2492
                    }
-
 
2493
                }
-
 
2494
                // Group by catalog ID
-
 
2495
                for (CurrentInventorySnapshot snap : partnerSnapshots) {
-
 
2496
                    Integer catalogId = itemToCatalogMap.get(snap.getItemId());
-
 
2497
                    if (catalogId != null && allCatalogIds.contains(catalogId)) {
-
 
2498
                        partnerStockMap.merge(catalogId, snap.getAvailability(), Integer::sum);
-
 
2499
                    }
-
 
2500
                }
-
 
2501
            }
-
 
2502
 
-
 
2503
            // Get GRN pending orders for partner
-
 
2504
            Map<Integer, Integer> grnPendingMap = new HashMap<>();
-
 
2505
            List<Order> pendingGrnOrders = orderRepository.selectPendingGrnOrders(fofoId);
-
 
2506
            for (Order order : pendingGrnOrders) {
-
 
2507
                int itemId = order.getLineItem().getItemId();
-
 
2508
                Item item = itemRepository.selectById(itemId);
-
 
2509
                if (item != null && allCatalogIds.contains(item.getCatalogItemId())) {
-
 
2510
                    grnPendingMap.merge(item.getCatalogItemId(), order.getLineItem().getQuantity(), Integer::sum);
-
 
2511
                }
-
 
2512
            }
-
 
2513
 
-
 
2514
            // Get tag listings (DP prices) for all catalogs
-
 
2515
            List<Integer> catalogIdList = new ArrayList<>(allCatalogIds);
-
 
2516
            Map<Integer, TagListing> tagListingsMap = tagListingRepository.selectAllByCatalogIds(catalogIdList);
-
 
2517
 
2467
            List<Map<String, Object>> result = new ArrayList<>();
2518
            List<Map<String, Object>> result = new ArrayList<>();
2468
 
2519
 
2469
            for (CategorisedCatalogListModel catalogModel : filteredCatalogs) {
2520
            for (CategorisedCatalogListModel catalogModel : filteredCatalogs) {
2470
                int catalogId = catalogModel.getModelId();
2521
                int catalogId = catalogModel.getModelId();
2471
 
2522
 
2472
                // Get all items for this catalog
2523
                // Get all items for this catalog
2473
                List<Item> items = itemRepository.selectAllByCatalogItemId(catalogId);
2524
                List<Item> items = itemRepository.selectAllByCatalogItemId(catalogId);
2474
                List<Integer> itemIds = items.stream().map(Item::getId).collect(Collectors.toList());
2525
                List<Integer> itemIds = items.stream().map(Item::getId).collect(Collectors.toList());
2475
 
2526
 
-
 
2527
                // Get DP price from tag listings
-
 
2528
                TagListing tagListing = tagListingsMap.get(catalogId);
-
 
2529
                double dpPrice = tagListing != null ? tagListing.getSellingPrice() : 0;
-
 
2530
 
2476
                if (itemIds.isEmpty()) {
2531
                if (itemIds.isEmpty()) {
2477
                    // No items means out of stock for this model
2532
                    // No items means out of stock for this model
2478
                    Map<String, Object> itemDetail = new HashMap<>();
2533
                    Map<String, Object> itemDetail = new HashMap<>();
2479
                    itemDetail.put("catalogId", catalogId);
2534
                    itemDetail.put("catalogId", catalogId);
2480
                    itemDetail.put("modelNumber", catalogModel.getModelNumber());
2535
                    itemDetail.put("modelNumber", catalogModel.getModelNumber());
2481
                    itemDetail.put("status", catalogModel.getCurrentStatus().getValue());
2536
                    itemDetail.put("status", catalogModel.getCurrentStatus().getValue());
2482
                    itemDetail.put("qty", 0);
2537
                    itemDetail.put("qty", 0);
-
 
2538
                    itemDetail.put("partnerCurrentQty", partnerStockMap.getOrDefault(catalogId, 0) + grnPendingMap.getOrDefault(catalogId, 0));
-
 
2539
                    itemDetail.put("dp", dpPrice);
2483
                    result.add(itemDetail);
2540
                    result.add(itemDetail);
2484
                    continue;
2541
                    continue;
2485
                }
2542
                }
2486
 
2543
 
2487
                // Get saholic stock for these items
2544
                // Get saholic stock for these items
Line 2503... Line 2560...
2503
                    Map<String, Object> itemDetail = new HashMap<>();
2560
                    Map<String, Object> itemDetail = new HashMap<>();
2504
                    itemDetail.put("catalogId", catalogId);
2561
                    itemDetail.put("catalogId", catalogId);
2505
                    itemDetail.put("modelNumber", catalogModel.getModelNumber());
2562
                    itemDetail.put("modelNumber", catalogModel.getModelNumber());
2506
                    itemDetail.put("status", catalogModel.getCurrentStatus().getValue());
2563
                    itemDetail.put("status", catalogModel.getCurrentStatus().getValue());
2507
                    itemDetail.put("qty", totalNetAvailability);
2564
                    itemDetail.put("qty", totalNetAvailability);
-
 
2565
                    itemDetail.put("partnerCurrentQty", partnerStockMap.getOrDefault(catalogId, 0) + grnPendingMap.getOrDefault(catalogId, 0));
-
 
2566
                    itemDetail.put("dp", dpPrice);
2508
                    result.add(itemDetail);
2567
                    result.add(itemDetail);
2509
                }
2568
                }
2510
            }
2569
            }
2511
 
2570
 
2512
            return responseSender.ok(result);
2571
            return responseSender.ok(result);
2513
        } catch (Exception e) {
2572
        } catch (Exception e) {
2514
            LOGGER.error("Error getting out of stock details for brand: {} warehouseId: {}", brand, warehouseId, e);
2573
            LOGGER.error("Error getting out of stock details for brand: {} warehouseId: {} fofoId: {}", brand, warehouseId, fofoId, e);
2515
            return responseSender.ok(Collections.emptyList());
2574
            return responseSender.ok(Collections.emptyList());
2516
        }
2575
        }
2517
    }
2576
    }
2518
 
2577
 
2519
    @Autowired
2578
    @Autowired
Line 2709... Line 2768...
2709
                partnerWarehouseStockAgingSummaryModelList.stream().collect(Collectors.groupingBy(
2768
                partnerWarehouseStockAgingSummaryModelList.stream().collect(Collectors.groupingBy(
2710
                        PartnerWarehouseStockAgingSummaryModel::getBrand,
2769
                        PartnerWarehouseStockAgingSummaryModel::getBrand,
2711
                        Collectors.groupingBy(PartnerWarehouseStockAgingSummaryModel::getStatus)
2770
                        Collectors.groupingBy(PartnerWarehouseStockAgingSummaryModel::getStatus)
2712
                ));
2771
                ));
2713
//map of list as hid,fast,slow and other in last otherwise other is coming in start (here is using status order)
2772
//map of list as hid,fast,slow and other in last otherwise other is coming in start (here is using status order)
-
 
2773
        // Also sort items alphabetically by model number within each status group
2714
        Map<String, Map<String, List<PartnerWarehouseStockAgingSummaryModel>>> sortedBrandStatusWiseStockListMap =
2774
        Map<String, Map<String, List<PartnerWarehouseStockAgingSummaryModel>>> sortedBrandStatusWiseStockListMap =
2715
                brandStatusWiseStockListMap.entrySet().stream().collect(Collectors.toMap(
2775
                brandStatusWiseStockListMap.entrySet().stream().collect(Collectors.toMap(
2716
                        Map.Entry::getKey, // Key (Brand)
2776
                        Map.Entry::getKey, // Key (Brand)
2717
                        entry -> {
2777
                        entry -> {
2718
                            Map<String, List<PartnerWarehouseStockAgingSummaryModel>> sortedStatusMap = entry.getValue().entrySet().stream()
2778
                            Map<String, List<PartnerWarehouseStockAgingSummaryModel>> sortedStatusMap = entry.getValue().entrySet().stream()
Line 2720... Line 2780...
2720
                                            statusOrder.indexOf(e1.getKey()),
2780
                                            statusOrder.indexOf(e1.getKey()),
2721
                                            statusOrder.indexOf(e2.getKey())
2781
                                            statusOrder.indexOf(e2.getKey())
2722
                                    ))
2782
                                    ))
2723
                                    .collect(Collectors.toMap(
2783
                                    .collect(Collectors.toMap(
2724
                                            Map.Entry::getKey,
2784
                                            Map.Entry::getKey,
2725
                                            Map.Entry::getValue,
2785
                                            e -> e.getValue().stream()
-
 
2786
                                                    .sorted(Comparator.comparing(PartnerWarehouseStockAgingSummaryModel::getModelNumber, String.CASE_INSENSITIVE_ORDER))
-
 
2787
                                                    .collect(Collectors.toList()),
2726
                                            (v1, v2) -> v1,
2788
                                            (v1, v2) -> v1,
2727
                                            LinkedHashMap::new // Ensure ordering is maintained
2789
                                            LinkedHashMap::new // Ensure ordering is maintained
2728
                                    ));
2790
                                    ));
2729
                            return sortedStatusMap;
2791
                            return sortedStatusMap;
2730
                        },
2792
                        },