| Line 642... |
Line 642... |
| 642 |
.collect(Collectors.toList());
|
642 |
.collect(Collectors.toList());
|
| 643 |
}
|
643 |
}
|
| 644 |
List<Menu> menuList = (menus != null) ? this.prepareMenu(menus) : new ArrayList<>();
|
644 |
List<Menu> menuList = (menus != null) ? this.prepareMenu(menus) : new ArrayList<>();
|
| 645 |
//LOGGER.info("menu" + menuList);
|
645 |
//LOGGER.info("menu" + menuList);
|
| 646 |
model.addAttribute("menu", menuList);
|
646 |
model.addAttribute("menu", menuList);
|
| - |
|
647 |
// Feeds the brand-filter dropdown on the "Warehouse Wise Report" widget.
|
| - |
|
648 |
// Filter itself is applied via AJAX to /getWarehouseStockByBrand; loading is unaffected.
|
| - |
|
649 |
model.addAttribute("whrBrandList", saholicInventoryCISRepository.selectAllBrand());
|
| 647 |
return "admin";
|
650 |
return "admin";
|
| 648 |
}
|
651 |
}
|
| 649 |
|
652 |
|
| 650 |
|
653 |
|
| - |
|
654 |
/**
|
| - |
|
655 |
* Reproduces the Warehouse Wise Report data-fetch used by {@link #adminPanel} but
|
| - |
|
656 |
* with an optional brand filter, so the main dashboard can swap the widget's rows
|
| - |
|
657 |
* without a full page reload. Permission scope (fofoIds) is resolved with the
|
| - |
|
658 |
* same rules as adminPanel so a user only ever sees their own warehouse territory.
|
| - |
|
659 |
*
|
| - |
|
660 |
* @param email logged-in user's email — used for fofoId scope resolution
|
| - |
|
661 |
* @param brands non-empty → filter to these brands; null/empty → all brands (identical to adminPanel behavior)
|
| - |
|
662 |
*/
|
| - |
|
663 |
public LinkedHashMap<Integer, WarehouseWiseStockModel> getWarehouseStockMap(String email, List<String> brands) throws Exception {
|
| - |
|
664 |
LinkedHashMap<Integer, WarehouseWiseStockModel> warehouseStockSortedMap = new LinkedHashMap<>();
|
| - |
|
665 |
|
| - |
|
666 |
AuthUser authUser = authRepository.selectByEmailOrMobile(email);
|
| - |
|
667 |
List<Position> positions = positionRepository.selectAllByAuthUserId(authUser.getId());
|
| - |
|
668 |
|
| - |
|
669 |
boolean isRbmL3OrAbove = positions.stream().anyMatch(pos ->
|
| - |
|
670 |
pos.getCategoryId() == ProfitMandiConstants.TICKET_CATEGORY_RBM
|
| - |
|
671 |
&& pos.getEscalationType() != null
|
| - |
|
672 |
&& pos.getEscalationType() != EscalationType.L1
|
| - |
|
673 |
&& pos.getEscalationType() != EscalationType.L2);
|
| - |
|
674 |
boolean isSalesL5OrAbove = positions.stream().anyMatch(pos ->
|
| - |
|
675 |
pos.getCategoryId() == ProfitMandiConstants.TICKET_CATEGORY_SALES
|
| - |
|
676 |
&& pos.getEscalationType() != null
|
| - |
|
677 |
&& pos.getEscalationType() != EscalationType.L1
|
| - |
|
678 |
&& pos.getEscalationType() != EscalationType.L2
|
| - |
|
679 |
&& pos.getEscalationType() != EscalationType.L3
|
| - |
|
680 |
&& pos.getEscalationType() != EscalationType.L4);
|
| - |
|
681 |
boolean canSeeAllStores = isRbmL3OrAbove || isSalesL5OrAbove;
|
| - |
|
682 |
|
| - |
|
683 |
Set<Integer> fofoIds;
|
| - |
|
684 |
if (canSeeAllStores) {
|
| - |
|
685 |
fofoIds = fofoStoreRepository.selectActiveStores().stream().map(x -> x.getId()).collect(Collectors.toSet());
|
| - |
|
686 |
} else {
|
| - |
|
687 |
fofoIds = csService1.getAuthFofoIds(email, true);
|
| - |
|
688 |
}
|
| - |
|
689 |
if (fofoIds == null || fofoIds.isEmpty()) return warehouseStockSortedMap;
|
| - |
|
690 |
|
| - |
|
691 |
Map<Integer, List<Integer>> warehouseIdFofoIdMap = getWarehouseIdFofoIdMap(fofoIds);
|
| - |
|
692 |
List<Integer> warehouseIds = new ArrayList<>(warehouseIdFofoIdMap.keySet());
|
| - |
|
693 |
|
| - |
|
694 |
List<WarehouseWiseStockModel> warehouseStocks;
|
| - |
|
695 |
if (brands == null || brands.isEmpty()) {
|
| - |
|
696 |
warehouseStocks = saholicInventoryCISRepository.selectGroupByWarehouse(warehouseIds);
|
| - |
|
697 |
} else {
|
| - |
|
698 |
warehouseStocks = saholicInventoryCISRepository.selectGroupByWarehouseFilteredByBrands(warehouseIds, brands);
|
| - |
|
699 |
}
|
| - |
|
700 |
|
| - |
|
701 |
Map<Integer, WarehouseWiseStockModel> warehouseStockMap =
|
| - |
|
702 |
warehouseStocks.stream().collect(Collectors.toMap(x -> x.getWarehouseId(), x -> x));
|
| - |
|
703 |
|
| - |
|
704 |
if (!warehouseStockMap.isEmpty()) {
|
| - |
|
705 |
long stockValue = 0, stockQty = 0, pendingIndent = 0, tertiary = 0;
|
| - |
|
706 |
for (Entry<Integer, WarehouseWiseStockModel> e : warehouseStockMap.entrySet()) {
|
| - |
|
707 |
stockValue += e.getValue().getStockValue();
|
| - |
|
708 |
stockQty += e.getValue().getStockQty();
|
| - |
|
709 |
pendingIndent += e.getValue().getPendingIndent();
|
| - |
|
710 |
tertiary += e.getValue().getTertiary();
|
| - |
|
711 |
}
|
| - |
|
712 |
WarehouseWiseStockModel totals = new WarehouseWiseStockModel();
|
| - |
|
713 |
totals.setStockQty(stockQty);
|
| - |
|
714 |
totals.setStockValue(stockValue);
|
| - |
|
715 |
totals.setPendingIndent(pendingIndent);
|
| - |
|
716 |
totals.setTertiary(tertiary);
|
| - |
|
717 |
totals.setWarehouseId(0);
|
| - |
|
718 |
warehouseStockMap.put(0, totals);
|
| - |
|
719 |
}
|
| - |
|
720 |
|
| - |
|
721 |
warehouseStockMap.entrySet().stream()
|
| - |
|
722 |
.sorted(Map.Entry.comparingByKey(Comparator.reverseOrder()))
|
| - |
|
723 |
.forEachOrdered(x -> warehouseStockSortedMap.put(x.getKey(), x.getValue()));
|
| - |
|
724 |
|
| - |
|
725 |
return warehouseStockSortedMap;
|
| - |
|
726 |
}
|
| - |
|
727 |
|
| 651 |
public Map<ProfitMandiConstants.BULLETIN_TYPE_ENUM, List<BulletinOfferModal>> getTodayBulletin(List<Position> positions, LocalDateTime date) throws Exception {
|
728 |
public Map<ProfitMandiConstants.BULLETIN_TYPE_ENUM, List<BulletinOfferModal>> getTodayBulletin(List<Position> positions, LocalDateTime date) throws Exception {
|
| 652 |
List<Long> regionIds = positions.stream().map(x -> Long.valueOf(x.getRegionId())).collect(Collectors.toList());
|
729 |
List<Long> regionIds = positions.stream().map(x -> Long.valueOf(x.getRegionId())).collect(Collectors.toList());
|
| 653 |
|
730 |
|
| 654 |
regionIds.add(5L);
|
731 |
regionIds.add(5L);
|
| 655 |
|
732 |
|