| Line 487... |
Line 487... |
| 487 |
model.addAttribute("bulletins", bulletins);
|
487 |
model.addAttribute("bulletins", bulletins);
|
| 488 |
return "bulletin-list";
|
488 |
return "bulletin-list";
|
| 489 |
}
|
489 |
}
|
| 490 |
|
490 |
|
| 491 |
|
491 |
|
| 492 |
@RequestMapping(value = "/dashboard", method = RequestMethod.GET)
|
- |
|
| 493 |
public String dashboard(HttpServletRequest request, Model model) throws Exception {
|
- |
|
| 494 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
- |
|
| 495 |
String email = loginDetails.getEmailId();
|
- |
|
| 496 |
int fofoId = loginDetails.getFofoId();
|
- |
|
| 497 |
boolean isAdmin = roleManager.isAdmin(loginDetails.getRoleIds());
|
- |
|
| 498 |
model.addAttribute("isAdmin", isAdmin);
|
- |
|
| 499 |
|
- |
|
| 500 |
model.addAttribute("webApiHost", webApiHost);
|
- |
|
| 501 |
model.addAttribute("webApiPort", webApiPort);
|
- |
|
| 502 |
model.addAttribute("webApiScheme", webApiScheme);
|
- |
|
| 503 |
model.addAttribute("webApiRoot", webApiRoot);
|
- |
|
| 504 |
model.addAttribute("googleApiKey", googleApiKey);
|
- |
|
| 505 |
|
- |
|
| 506 |
if (isAdmin) {
|
- |
|
| 507 |
return adminUser.adminPanel(loginDetails.getFofoId(), email, model);
|
- |
|
| 508 |
} else {
|
- |
|
| 509 |
FofoStore fofoStore;
|
- |
|
| 510 |
List<PartnerRegion> partnerRegion = partnerRegionRepository.selectByfofoId(fofoId);
|
- |
|
| 511 |
LocalDateTime currentDate = LocalDateTime.now();
|
- |
|
| 512 |
List<PrintResource> printResources = printResourceRepository.selectPrintResourcesByFofoRegion(partnerRegion.get(0).getRegionId(), currentDate);
|
- |
|
| 513 |
LOGGER.info("printresourcesList {}", printResources);
|
- |
|
| 514 |
model.addAttribute("printResources", printResources);
|
- |
|
| 515 |
try {
|
- |
|
| 516 |
fofoStore = fofoStoreRepository.selectByRetailerId(loginDetails.getFofoId());
|
- |
|
| 517 |
if (!fofoStore.isActive()) {
|
- |
|
| 518 |
return "redirect:/login";
|
- |
|
| 519 |
}
|
- |
|
| 520 |
|
- |
|
| 521 |
LocalDateTime startDate = LocalDate.now().withDayOfYear(1).atStartOfDay();
|
- |
|
| 522 |
LocalDateTime endtDate = LocalDateTime.now();
|
- |
|
| 523 |
OnlineDeliveredOrderSum onlineDeliveredOrderSum = pendingOrderItemRepository.selectSumSellingPriceOnlineOrder(fofoId, startDate, endtDate);
|
- |
|
| 524 |
LOGGER.info("onlineDeliveredOrderSum" + onlineDeliveredOrderSum.getSellingPrice());
|
- |
|
| 525 |
|
- |
|
| 526 |
long countOrder = pendingOrderRepository.pendingOrderCount(fofoId, OrderStatus.PROCESSING);
|
- |
|
| 527 |
LOGGER.info("countOrder" + countOrder);
|
- |
|
| 528 |
|
- |
|
| 529 |
ArrayList<in.shop2020.model.v1.order.OrderStatus> orderStatus = new ArrayList<>();
|
- |
|
| 530 |
|
- |
|
| 531 |
orderStatus.add(SUBMITTED_FOR_PROCESSING);
|
- |
|
| 532 |
orderStatus.add(BILLED);
|
- |
|
| 533 |
orderStatus.add(SHIPPED_FROM_WH);
|
- |
|
| 534 |
orderStatus.add(DELIVERY_SUCCESS);
|
- |
|
| 535 |
|
- |
|
| 536 |
List<Order> openOrders = orderRepository.selectGrnTimestampNull(fofoId, orderStatus);
|
- |
|
| 537 |
List<LineItem> submittedLineItemIds = openOrders.stream().filter(x -> x.getStatus().equals(SUBMITTED_FOR_PROCESSING)).map(x -> x.getLineItem()).collect(Collectors.toList());
|
- |
|
| 538 |
List<LineItem> billedOrderIds = openOrders.stream().filter(x -> x.getStatus().equals(BILLED)).map(x -> x.getLineItem()).collect(Collectors.toList());
|
- |
|
| 539 |
List<LineItem> shippedOrderIds = openOrders.stream().filter(x -> x.getStatus().equals(SHIPPED_FROM_WH)).map(x -> x.getLineItem()).collect(Collectors.toList());
|
- |
|
| 540 |
List<LineItem> grnPendingLineItemIds = openOrders.stream().filter(x -> x.getStatus().equals(DELIVERY_SUCCESS)).map(x -> x.getLineItem()).collect(Collectors.toList());
|
- |
|
| 541 |
|
- |
|
| 542 |
long imeiActivationPendingCount = 0;
|
- |
|
| 543 |
long imeiActivationPendingValue = 0;
|
- |
|
| 544 |
//Only delivered orders should be visible
|
- |
|
| 545 |
List<Integer> grnPendingOrderIds = openOrders.stream().filter(x -> x.getStatus().equals(DELIVERY_SUCCESS)).map(x -> x.getId()).collect(Collectors.toList());
|
- |
|
| 546 |
if (grnPendingOrderIds.size() > 0) {
|
492 |
private static String formatIndianCurrency(long amount) {
|
| 547 |
List<ImeiActivationTimestampModel> imeiActivationTimestampModels = activatedImeiRepository.selectActivatedImeisByOrders(grnPendingOrderIds);
|
- |
|
| 548 |
imeiActivationPendingCount = imeiActivationTimestampModels.size();
|
- |
|
| 549 |
imeiActivationPendingValue = imeiActivationTimestampModels.stream().collect(Collectors.summingDouble(x -> x.getSellingPrice())).longValue();
|
- |
|
| 550 |
}
|
- |
|
| 551 |
|
- |
|
| 552 |
long grnPendingCount = grnPendingLineItemIds.stream().collect(Collectors.summingLong(LineItem::getQuantity));
|
- |
|
| 553 |
long grnPendingValue = grnPendingLineItemIds.stream().collect(Collectors.summingLong(x -> x.getTotalPrice().longValue()));
|
- |
|
| 554 |
model.addAttribute("grnPendingCount", grnPendingCount);
|
- |
|
| 555 |
model.addAttribute("grnPendingValue", grnPendingValue);
|
- |
|
| 556 |
|
- |
|
| 557 |
long submittedCount = submittedLineItemIds.stream().collect(Collectors.summingLong(LineItem::getQuantity));
|
- |
|
| 558 |
long submittedValue = submittedLineItemIds.stream().collect(Collectors.summingLong(x -> x.getTotalPrice().longValue()));
|
- |
|
| 559 |
model.addAttribute("submittedCount", submittedCount);
|
- |
|
| 560 |
model.addAttribute("submittedValue", submittedValue);
|
- |
|
| 561 |
|
- |
|
| 562 |
long billedCount = billedOrderIds.stream().collect(Collectors.summingLong(LineItem::getQuantity));
|
- |
|
| 563 |
long billedValue = billedOrderIds.stream().collect(Collectors.summingLong(x -> x.getTotalPrice().longValue()));
|
- |
|
| 564 |
model.addAttribute("billedValue", billedValue);
|
- |
|
| 565 |
model.addAttribute("billedCount", billedCount);
|
- |
|
| 566 |
LOGGER.info("billedCount {}", billedCount);
|
- |
|
| 567 |
|
- |
|
| 568 |
long shippedCount = shippedOrderIds.stream().collect(Collectors.summingLong(LineItem::getQuantity));
|
- |
|
| 569 |
model.addAttribute("shippedCount", shippedCount);
|
- |
|
| 570 |
LOGGER.info("shippedCount {}", shippedCount);
|
- |
|
| 571 |
long shippedValue = shippedOrderIds.stream().collect(Collectors.summingLong(x -> x.getTotalPrice().longValue()));
|
- |
|
| 572 |
model.addAttribute("shippedValue", shippedValue);
|
- |
|
| 573 |
|
- |
|
| 574 |
LocalDateTime curDate = LocalDate.now().atStartOfDay();
|
- |
|
| 575 |
|
- |
|
| 576 |
LocalDateTime currentMonthStart = curDate.withDayOfMonth(1);
|
- |
|
| 577 |
LocalDateTime lastMonthStart = currentMonthStart.minusMonths(1);
|
- |
|
| 578 |
LocalDateTime currentMonthEnd = currentMonthStart.withDayOfMonth(1);
|
- |
|
| 579 |
|
- |
|
| 580 |
LOGGER.info("lastMonthStart" + lastMonthStart);
|
- |
|
| 581 |
LOGGER.info("currentMonthEnd" + currentMonthEnd);
|
- |
|
| 582 |
|
- |
|
| 583 |
Scheme staticScheme = schemeService.getStaticScheme(fofoId);
|
- |
|
| 584 |
double schemeAchievement = 0;
|
- |
|
| 585 |
String schemeCategory = null;
|
- |
|
| 586 |
if (staticScheme != null) {
|
- |
|
| 587 |
Map<Integer, Double> schemeAchievementMap = orderRepository.selectBillingDatesBetweenSumGroupByRetailerId(staticScheme.getStartDateTime(), staticScheme.getEndDateTime());
|
- |
|
| 588 |
if (schemeAchievementMap.get(fofoId) != null) {
|
- |
|
| 589 |
schemeAchievement = schemeAchievementMap.get(fofoId);
|
- |
|
| 590 |
// Super Retailer - Club 5 (2026-07-01 to 2026-12-30) tiers
|
- |
|
| 591 |
if (staticScheme.getTarget() >= 2000000 && staticScheme.getTarget() < 4000000) {
|
- |
|
| 592 |
schemeCategory = "Shuruaat"; // 20 Lacs to 39.99 Lacs
|
- |
|
| 593 |
} else if (staticScheme.getTarget() < 7000000) {
|
- |
|
| 594 |
schemeCategory = "Udaan"; // 40 Lacs to 69.99 Lacs
|
- |
|
| 595 |
} else if (staticScheme.getTarget() < 9000000) {
|
- |
|
| 596 |
schemeCategory = "Raftaar"; // 70 Lacs to 89.99 Lacs
|
- |
|
| 597 |
} else if (staticScheme.getTarget() < 12000000) {
|
- |
|
| 598 |
schemeCategory = "Tarakki"; // 90 Lacs to 1.19 Cr
|
- |
|
| 599 |
} else if (staticScheme.getTarget() < 24000000) {
|
- |
|
| 600 |
schemeCategory = "Vijeta"; // 1.20 Cr to 2.39 Cr
|
- |
|
| 601 |
} else {
|
493 |
if (amount >= 10000000L) {
|
| 602 |
schemeCategory = "Maharaja"; // 2.40 Cr and above
|
- |
|
| 603 |
}
|
- |
|
| 604 |
}
|
- |
|
| 605 |
}
|
- |
|
| 606 |
|
- |
|
| 607 |
|
- |
|
| 608 |
model.addAttribute("countOrder", countOrder);
|
- |
|
| 609 |
model.addAttribute("onlineDeliveredOrderSum", onlineDeliveredOrderSum.getSellingPrice());
|
- |
|
| 610 |
|
- |
|
| 611 |
PartnerType partnerType = partnerTypeChangeService.getTypeOnDate(fofoStore.getId(), LocalDate.now());
|
- |
|
| 612 |
model.addAttribute("partnerType", partnerType);
|
- |
|
| 613 |
model.addAttribute("partnerTypeImage", PartnerType.imageMap.get(partnerType));
|
- |
|
| 614 |
model.addAttribute("fofoStore", fofoStore);
|
- |
|
| 615 |
model.addAttribute("partnerType", partnerType);
|
- |
|
| 616 |
model.addAttribute("hasGift", fofoUser.hasGift(loginDetails.getFofoId()));
|
- |
|
| 617 |
model.addAttribute("giftItemId", ProfitMandiConstants.GIFT_ID);
|
- |
|
| 618 |
model.addAttribute("retailers", new JSONObject().append("code", fofoStore.getCode()).append("partnerId", fofoStore.getId()).toString());
|
- |
|
| 619 |
model.addAttribute("activatedImeis", inventoryItemRepository.selectCountByActivatedNotSold(loginDetails.getFofoId()));
|
- |
|
| 620 |
model.addAttribute("imeiActivationPendingCount", imeiActivationPendingCount);
|
- |
|
| 621 |
model.addAttribute("imeiActivationPendingValue", imeiActivationPendingValue);
|
- |
|
| 622 |
|
- |
|
| 623 |
Map<Integer, Double> accesoriesmtdsale = fofoOrderRepository.selectSumSaleGroupByFofoIdsForMobileOrAccessories(loginDetails.getFofoId(), curDate.withDayOfMonth(1), curDate.with(LocalTime.MAX), Optional.of(false));
|
- |
|
| 624 |
|
- |
|
| 625 |
Double accesoriesStock = currentInventorySnapshotRepository.selectSumStockGroupByFofoIdsForMobileOrAccessories(loginDetails.getFofoId(), Optional.of(false)).get(loginDetails.getFofoId());
|
- |
|
| 626 |
|
- |
|
| 627 |
model.addAttribute("accesoriesStock", String.format("%.0f", accesoriesStock));
|
- |
|
| 628 |
model.addAttribute("staticScheme", staticScheme);
|
- |
|
| 629 |
model.addAttribute("schemeCategory", schemeCategory);
|
- |
|
| 630 |
model.addAttribute("schemeAchievement", schemeAchievement);
|
- |
|
| 631 |
model.addAttribute("brandStockPrices", fofoUser.getBrandStockPrices(loginDetails.getFofoId(), false));
|
- |
|
| 632 |
model.addAttribute("salesMap", fofoUser.getSales(loginDetails.getFofoId()));
|
- |
|
| 633 |
ChartModel cm = fofoUser.getBrandChart(loginDetails.getFofoId(),null,null,false);
|
- |
|
| 634 |
|
- |
|
| 635 |
LOGGER.info("chartMap" + gson.toJson(cm));
|
- |
|
| 636 |
model.addAttribute("chartMap", gson.toJson(cm));
|
- |
|
| 637 |
|
- |
|
| 638 |
List<CreateOfferRequest> createOffers = offerService.getPublishedOffers(loginDetails.getFofoId(), YearMonth.from(LocalDateTime.now()));
|
- |
|
| 639 |
|
- |
|
| 640 |
// Batch fetch all catalog IDs to avoid N+1 queries
|
- |
|
| 641 |
Set<Integer> allCatalogIds = createOffers.stream()
|
- |
|
| 642 |
.flatMap(offer -> offer.getTargetSlabs().stream())
|
- |
|
| 643 |
.flatMap(slab -> slab.getItemCriteriaPayouts().stream())
|
- |
|
| 644 |
.map(ItemCriteriaPayout::getItemCriteria)
|
- |
|
| 645 |
.flatMap(criteria -> criteria.getCatalogIds().stream())
|
- |
|
| 646 |
.collect(Collectors.toSet());
|
- |
|
| 647 |
|
- |
|
| 648 |
final Map<Integer, String> catalogBrandMap = new HashMap<>();
|
- |
|
| 649 |
if (!allCatalogIds.isEmpty()) {
|
- |
|
| 650 |
try {
|
- |
|
| 651 |
catalogBrandMap.putAll(catalogRepository.selectAllByIds(new ArrayList<>(allCatalogIds)).stream()
|
- |
|
| 652 |
.collect(Collectors.toMap(c -> c.getId(), c -> c.getBrand())));
|
- |
|
| 653 |
} catch (ProfitMandiBusinessException e) {
|
- |
|
| 654 |
LOGGER.error("Error fetching catalogs by IDs", e);
|
- |
|
| 655 |
}
|
- |
|
| 656 |
}
|
- |
|
| 657 |
|
- |
|
| 658 |
List<CreateOfferRequest> publishedOffers = createOffers.stream()
|
- |
|
| 659 |
.filter(createOffer -> createOffer.getTargetSlabs().stream()
|
- |
|
| 660 |
.flatMap(slab -> slab.getItemCriteriaPayouts().stream())
|
- |
|
| 661 |
.map(ItemCriteriaPayout::getItemCriteria)
|
- |
|
| 662 |
.flatMap(criteria -> criteria.getCatalogIds().stream())
|
- |
|
| 663 |
.noneMatch(catalogId -> "Live Demo".equals(catalogBrandMap.get(catalogId))))
|
- |
|
| 664 |
.collect(Collectors.toList());
|
- |
|
| 665 |
|
- |
|
| 666 |
model.addAttribute("publishedOffers", publishedOffers);
|
- |
|
| 667 |
model.addAttribute("investments", fofoUser.getInvestments(loginDetails.getFofoId()));
|
- |
|
| 668 |
model.addAttribute("isInvestmentOk", partnerInvestmentService.isInvestmentOk(loginDetails.getFofoId(), ProfitMandiConstants.MIN_INVESTMENT_PERCENTAGE, ProfitMandiConstants.CUTOFF_INVESTMENT));
|
- |
|
| 669 |
|
- |
|
| 670 |
double currentMonthRating = hygieneDataRepository.selectRatingAvg(loginDetails.getFofoId(), DateRangeModel.of(currentMonthStart, currentMonthEnd)) / 2;
|
- |
|
| 671 |
double lastMonthRating = hygieneDataRepository.selectRatingAvg(loginDetails.getFofoId(), DateRangeModel.of(lastMonthStart, currentMonthStart)) / 2;
|
- |
|
| 672 |
double ratingTillDate = hygieneDataRepository.selectRatingAvg(loginDetails.getFofoId(), DateRangeModel.withEndDate(currentMonthEnd)) / 2;
|
- |
|
| 673 |
model.addAttribute("currentMonthRating", (float) Math.round(currentMonthRating * 10) / 10);
|
- |
|
| 674 |
model.addAttribute("lastMonthRating", (float) Math.round(lastMonthRating * 10) / 10);
|
- |
|
| 675 |
model.addAttribute("ratingTillDate", (float) Math.round(ratingTillDate * 10) / 10);
|
- |
|
| 676 |
|
- |
|
| 677 |
long hygieneCount = hygieneDataRepository.selectHygieneCount(loginDetails.getFofoId(), true, currentMonthStart, currentMonthEnd);
|
- |
|
| 678 |
|
- |
|
| 679 |
long invalidHygieneCount = hygieneDataRepository.selectHygieneCount(loginDetails.getFofoId(), false, currentMonthStart, currentMonthEnd);
|
- |
|
| 680 |
if (hygieneCount == 0 && invalidHygieneCount == 0) {
|
- |
|
| 681 |
invalidHygieneCount = 1;
|
- |
|
| 682 |
}
|
- |
|
| 683 |
Map<Integer, String> monthValueMap = new HashMap<>();
|
- |
|
| 684 |
for (int i = 0; i <= 12; i++) {
|
- |
|
| 685 |
LocalDateTime startOfMonth = LocalDateTime.now().withDayOfMonth(1).minusMonths(i);
|
- |
|
| 686 |
monthValueMap.put(i, startOfMonth.format(DateTimeFormatter.ofPattern("MMM''uu")));
|
- |
|
| 687 |
}
|
- |
|
| 688 |
|
- |
|
| 689 |
MonthlyTarget monthlyTarget = monthlyTargetRepository.selectByDateAndFofoId(YearMonth.now(), fofoId);
|
- |
|
| 690 |
model.addAttribute("monthlyTarget", monthlyTarget);
|
- |
|
| 691 |
Set<String> brands = brandsService.getBrandsToDisplay(3).stream().map(x -> x.getName()).collect(Collectors.toSet());
|
- |
|
| 692 |
|
- |
|
| 693 |
model.addAttribute("brands", brands);
|
- |
|
| 694 |
model.addAttribute("monthValueMap", monthValueMap);
|
494 |
return String.format("%.2f Cr", amount / 10000000.0);
|
| 695 |
model.addAttribute("month", 0);
|
- |
|
| 696 |
model.addAttribute("hygienePercentage", (hygieneCount * 100) / (invalidHygieneCount + hygieneCount));
|
- |
|
| 697 |
model.addAttribute("monthDays", LocalDate.now().minusDays(1).lengthOfMonth());
|
- |
|
| 698 |
model.addAttribute("dayOfMonth", LocalDate.now().minusDays(1).getDayOfMonth());
|
- |
|
| 699 |
Map<String, Object> rewardsMap = saleRewardService.findByFofoAndRegionId(fofoId, partnerRegion.get(0).getRegionId());
|
- |
|
| 700 |
StoreSalesTarget targetData = saleRewardService.findTargetsByFofoId(fofoId);
|
- |
|
| 701 |
model.addAttribute("rewardsMap", rewardsMap);
|
- |
|
| 702 |
model.addAttribute("targetData", targetData);
|
- |
|
| 703 |
model.addAttribute("regionId", partnerRegion.get(0).getRegionId());
|
- |
|
| 704 |
|
- |
|
| 705 |
|
- |
|
| 706 |
|
- |
|
| 707 |
} catch (
|
- |
|
| 708 |
ProfitMandiBusinessException e) {
|
- |
|
| 709 |
LOGGER.error("FofoStore Code not found of fofoId {}", loginDetails.getFofoId());
|
- |
|
| 710 |
|
- |
|
| 711 |
}
|
- |
|
| 712 |
return "dashboard1";
|
- |
|
| 713 |
}
|
495 |
}
|
| - |
|
496 |
if (amount >= 100000L) {
|
| - |
|
497 |
return String.format("%.2f L", amount / 100000.0);
|
| 714 |
|
498 |
}
|
| - |
|
499 |
return String.format("%,d", amount);
|
| 715 |
}
|
500 |
}
|
| 716 |
|
501 |
|
| 717 |
@RequestMapping(value = "/getGrnPendingOrderStatus", method = RequestMethod.GET)
|
502 |
@RequestMapping(value = "/getGrnPendingOrderStatus", method = RequestMethod.GET)
|
| 718 |
public String getGrnPendingOrderStatus(HttpServletRequest request, Model model) throws Exception {
|
503 |
public String getGrnPendingOrderStatus(HttpServletRequest request, Model model) throws Exception {
|
| 719 |
|
504 |
|
| Line 2897... |
Line 2682... |
| 2897 |
|
2682 |
|
| 2898 |
@GetMapping("/getRestartServer")
|
2683 |
@GetMapping("/getRestartServer")
|
| 2899 |
public String getRestartServer(HttpServletRequest request, Model model) {
|
2684 |
public String getRestartServer(HttpServletRequest request, Model model) {
|
| 2900 |
return "restart-server-page";
|
2685 |
return "restart-server-page";
|
| 2901 |
}
|
2686 |
}
|
| - |
|
2687 |
|
| - |
|
2688 |
private static String ordinalDay(int day) {
|
| - |
|
2689 |
if (day >= 11 && day <= 13) return day + "th";
|
| - |
|
2690 |
switch (day % 10) {
|
| - |
|
2691 |
case 1:
|
| - |
|
2692 |
return day + "st";
|
| - |
|
2693 |
case 2:
|
| - |
|
2694 |
return day + "nd";
|
| - |
|
2695 |
case 3:
|
| - |
|
2696 |
return day + "rd";
|
| - |
|
2697 |
default:
|
| - |
|
2698 |
return day + "th";
|
| - |
|
2699 |
}
|
| - |
|
2700 |
}
|
| - |
|
2701 |
|
| - |
|
2702 |
private static String formatSchemePeriodDisplay(LocalDateTime start, LocalDateTime end) {
|
| - |
|
2703 |
if (start == null || end == null) return "";
|
| - |
|
2704 |
String startPart = ordinalDay(start.getDayOfMonth()) + " " +
|
| - |
|
2705 |
start.getMonth().getDisplayName(java.time.format.TextStyle.FULL, Locale.ENGLISH);
|
| - |
|
2706 |
String endPart = ordinalDay(end.getDayOfMonth()) + " " +
|
| - |
|
2707 |
end.getMonth().getDisplayName(java.time.format.TextStyle.FULL, Locale.ENGLISH) + " " + end.getYear();
|
| - |
|
2708 |
long months = java.time.temporal.ChronoUnit.MONTHS.between(
|
| - |
|
2709 |
start.toLocalDate().withDayOfMonth(1),
|
| - |
|
2710 |
end.toLocalDate().withDayOfMonth(1)) + 1;
|
| - |
|
2711 |
return startPart + " – " + endPart + " (" + months + " Months)";
|
| - |
|
2712 |
}
|
| - |
|
2713 |
|
| - |
|
2714 |
@RequestMapping(value = "/dashboard", method = RequestMethod.GET)
|
| - |
|
2715 |
public String dashboard(HttpServletRequest request, Model model) throws Exception {
|
| - |
|
2716 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| - |
|
2717 |
String email = loginDetails.getEmailId();
|
| - |
|
2718 |
int fofoId = loginDetails.getFofoId();
|
| - |
|
2719 |
boolean isAdmin = roleManager.isAdmin(loginDetails.getRoleIds());
|
| - |
|
2720 |
model.addAttribute("isAdmin", isAdmin);
|
| - |
|
2721 |
|
| - |
|
2722 |
model.addAttribute("webApiHost", webApiHost);
|
| - |
|
2723 |
model.addAttribute("webApiPort", webApiPort);
|
| - |
|
2724 |
model.addAttribute("webApiScheme", webApiScheme);
|
| - |
|
2725 |
model.addAttribute("webApiRoot", webApiRoot);
|
| - |
|
2726 |
model.addAttribute("googleApiKey", googleApiKey);
|
| - |
|
2727 |
|
| - |
|
2728 |
if (isAdmin) {
|
| - |
|
2729 |
return adminUser.adminPanel(loginDetails.getFofoId(), email, model);
|
| - |
|
2730 |
} else {
|
| - |
|
2731 |
FofoStore fofoStore;
|
| - |
|
2732 |
List<PartnerRegion> partnerRegion = partnerRegionRepository.selectByfofoId(fofoId);
|
| - |
|
2733 |
LocalDateTime currentDate = LocalDateTime.now();
|
| - |
|
2734 |
List<PrintResource> printResources = printResourceRepository.selectPrintResourcesByFofoRegion(partnerRegion.get(0).getRegionId(), currentDate);
|
| - |
|
2735 |
LOGGER.info("printresourcesList {}", printResources);
|
| - |
|
2736 |
model.addAttribute("printResources", printResources);
|
| - |
|
2737 |
try {
|
| - |
|
2738 |
fofoStore = fofoStoreRepository.selectByRetailerId(loginDetails.getFofoId());
|
| - |
|
2739 |
if (!fofoStore.isActive()) {
|
| - |
|
2740 |
return "redirect:/login";
|
| - |
|
2741 |
}
|
| - |
|
2742 |
|
| - |
|
2743 |
LocalDateTime startDate = LocalDate.now().withDayOfYear(1).atStartOfDay();
|
| - |
|
2744 |
LocalDateTime endtDate = LocalDateTime.now();
|
| - |
|
2745 |
OnlineDeliveredOrderSum onlineDeliveredOrderSum = pendingOrderItemRepository.selectSumSellingPriceOnlineOrder(fofoId, startDate, endtDate);
|
| - |
|
2746 |
LOGGER.info("onlineDeliveredOrderSum" + onlineDeliveredOrderSum.getSellingPrice());
|
| - |
|
2747 |
|
| - |
|
2748 |
long countOrder = pendingOrderRepository.pendingOrderCount(fofoId, OrderStatus.PROCESSING);
|
| - |
|
2749 |
LOGGER.info("countOrder" + countOrder);
|
| - |
|
2750 |
|
| - |
|
2751 |
ArrayList<in.shop2020.model.v1.order.OrderStatus> orderStatus = new ArrayList<>();
|
| - |
|
2752 |
|
| - |
|
2753 |
orderStatus.add(SUBMITTED_FOR_PROCESSING);
|
| - |
|
2754 |
orderStatus.add(BILLED);
|
| - |
|
2755 |
orderStatus.add(SHIPPED_FROM_WH);
|
| - |
|
2756 |
orderStatus.add(DELIVERY_SUCCESS);
|
| - |
|
2757 |
|
| - |
|
2758 |
List<Order> openOrders = orderRepository.selectGrnTimestampNull(fofoId, orderStatus);
|
| - |
|
2759 |
List<LineItem> submittedLineItemIds = openOrders.stream().filter(x -> x.getStatus().equals(SUBMITTED_FOR_PROCESSING)).map(x -> x.getLineItem()).collect(Collectors.toList());
|
| - |
|
2760 |
List<LineItem> billedOrderIds = openOrders.stream().filter(x -> x.getStatus().equals(BILLED)).map(x -> x.getLineItem()).collect(Collectors.toList());
|
| - |
|
2761 |
List<LineItem> shippedOrderIds = openOrders.stream().filter(x -> x.getStatus().equals(SHIPPED_FROM_WH)).map(x -> x.getLineItem()).collect(Collectors.toList());
|
| - |
|
2762 |
List<LineItem> grnPendingLineItemIds = openOrders.stream().filter(x -> x.getStatus().equals(DELIVERY_SUCCESS)).map(x -> x.getLineItem()).collect(Collectors.toList());
|
| - |
|
2763 |
|
| - |
|
2764 |
long imeiActivationPendingCount = 0;
|
| - |
|
2765 |
long imeiActivationPendingValue = 0;
|
| - |
|
2766 |
//Only delivered orders should be visible
|
| - |
|
2767 |
List<Integer> grnPendingOrderIds = openOrders.stream().filter(x -> x.getStatus().equals(DELIVERY_SUCCESS)).map(x -> x.getId()).collect(Collectors.toList());
|
| - |
|
2768 |
if (grnPendingOrderIds.size() > 0) {
|
| - |
|
2769 |
List<ImeiActivationTimestampModel> imeiActivationTimestampModels = activatedImeiRepository.selectActivatedImeisByOrders(grnPendingOrderIds);
|
| - |
|
2770 |
imeiActivationPendingCount = imeiActivationTimestampModels.size();
|
| - |
|
2771 |
imeiActivationPendingValue = imeiActivationTimestampModels.stream().collect(Collectors.summingDouble(x -> x.getSellingPrice())).longValue();
|
| - |
|
2772 |
}
|
| - |
|
2773 |
|
| - |
|
2774 |
long grnPendingCount = grnPendingLineItemIds.stream().collect(Collectors.summingLong(LineItem::getQuantity));
|
| - |
|
2775 |
long grnPendingValue = grnPendingLineItemIds.stream().collect(Collectors.summingLong(x -> x.getTotalPrice().longValue()));
|
| - |
|
2776 |
model.addAttribute("grnPendingCount", grnPendingCount);
|
| - |
|
2777 |
model.addAttribute("grnPendingValue", grnPendingValue);
|
| - |
|
2778 |
|
| - |
|
2779 |
long submittedCount = submittedLineItemIds.stream().collect(Collectors.summingLong(LineItem::getQuantity));
|
| - |
|
2780 |
long submittedValue = submittedLineItemIds.stream().collect(Collectors.summingLong(x -> x.getTotalPrice().longValue()));
|
| - |
|
2781 |
model.addAttribute("submittedCount", submittedCount);
|
| - |
|
2782 |
model.addAttribute("submittedValue", submittedValue);
|
| - |
|
2783 |
|
| - |
|
2784 |
long billedCount = billedOrderIds.stream().collect(Collectors.summingLong(LineItem::getQuantity));
|
| - |
|
2785 |
long billedValue = billedOrderIds.stream().collect(Collectors.summingLong(x -> x.getTotalPrice().longValue()));
|
| - |
|
2786 |
model.addAttribute("billedValue", billedValue);
|
| - |
|
2787 |
model.addAttribute("billedCount", billedCount);
|
| - |
|
2788 |
LOGGER.info("billedCount {}", billedCount);
|
| - |
|
2789 |
|
| - |
|
2790 |
long shippedCount = shippedOrderIds.stream().collect(Collectors.summingLong(LineItem::getQuantity));
|
| - |
|
2791 |
model.addAttribute("shippedCount", shippedCount);
|
| - |
|
2792 |
LOGGER.info("shippedCount {}", shippedCount);
|
| - |
|
2793 |
long shippedValue = shippedOrderIds.stream().collect(Collectors.summingLong(x -> x.getTotalPrice().longValue()));
|
| - |
|
2794 |
model.addAttribute("shippedValue", shippedValue);
|
| - |
|
2795 |
|
| - |
|
2796 |
LocalDateTime curDate = LocalDate.now().atStartOfDay();
|
| - |
|
2797 |
|
| - |
|
2798 |
LocalDateTime currentMonthStart = curDate.withDayOfMonth(1);
|
| - |
|
2799 |
LocalDateTime lastMonthStart = currentMonthStart.minusMonths(1);
|
| - |
|
2800 |
LocalDateTime currentMonthEnd = currentMonthStart.withDayOfMonth(1);
|
| - |
|
2801 |
|
| - |
|
2802 |
LOGGER.info("lastMonthStart" + lastMonthStart);
|
| - |
|
2803 |
LOGGER.info("currentMonthEnd" + currentMonthEnd);
|
| - |
|
2804 |
|
| - |
|
2805 |
Scheme staticScheme = schemeService.getStaticScheme(fofoId);
|
| - |
|
2806 |
double schemeAchievement = 0;
|
| - |
|
2807 |
double mobileLedAchievement = 0;
|
| - |
|
2808 |
double accessoriesAchievement = 0;
|
| - |
|
2809 |
long mobileLedTarget = 0;
|
| - |
|
2810 |
long accessoriesTarget = 0;
|
| - |
|
2811 |
long totalTarget = 0;
|
| - |
|
2812 |
int achievementPercent = 0;
|
| - |
|
2813 |
String aimingTier = null;
|
| - |
|
2814 |
if (staticScheme != null) {
|
| - |
|
2815 |
// Mobile (10006) + LED (14202) are the primary target; accessories is everything else.
|
| - |
|
2816 |
Set<Integer> mobileLedCategoryIds = new HashSet<>(Arrays.asList(10006, 14202));
|
| - |
|
2817 |
Map<Integer, Double> mobileLedMap = fofoOrderRepository.selectSumSaleGroupByFofoIdForCategories(
|
| - |
|
2818 |
fofoId, staticScheme.getStartDateTime(), staticScheme.getEndDateTime(), mobileLedCategoryIds, true);
|
| - |
|
2819 |
Map<Integer, Double> accessoriesMap = fofoOrderRepository.selectSumSaleGroupByFofoIdForCategories(
|
| - |
|
2820 |
fofoId, staticScheme.getStartDateTime(), staticScheme.getEndDateTime(), mobileLedCategoryIds, false);
|
| - |
|
2821 |
mobileLedAchievement = mobileLedMap.getOrDefault(fofoId, 0.0);
|
| - |
|
2822 |
accessoriesAchievement = accessoriesMap.getOrDefault(fofoId, 0.0);
|
| - |
|
2823 |
schemeAchievement = mobileLedAchievement + accessoriesAchievement;
|
| - |
|
2824 |
|
| - |
|
2825 |
mobileLedTarget = staticScheme.getTarget();
|
| - |
|
2826 |
// Accessories target is fixed at 1% of the assigned mobile+LED target.
|
| - |
|
2827 |
accessoriesTarget = Math.round(mobileLedTarget * 0.01);
|
| - |
|
2828 |
totalTarget = mobileLedTarget + accessoriesTarget;
|
| - |
|
2829 |
achievementPercent = totalTarget > 0 ? (int) Math.round(schemeAchievement * 100.0 / totalTarget) : 0;
|
| - |
|
2830 |
|
| - |
|
2831 |
// "Currently aiming for" — dynamic tier based on total achievement (not assigned target).
|
| - |
|
2832 |
// Same SRC5 thresholds; the tier advances as achievement crosses each ceiling.
|
| - |
|
2833 |
if (schemeAchievement < 4000000) {
|
| - |
|
2834 |
aimingTier = "Shuruaat"; // up to 40 Lacs
|
| - |
|
2835 |
} else if (schemeAchievement < 7000000) {
|
| - |
|
2836 |
aimingTier = "Udaan"; // 40 – 70 Lacs
|
| - |
|
2837 |
} else if (schemeAchievement < 9000000) {
|
| - |
|
2838 |
aimingTier = "Raftaar"; // 70 – 90 Lacs
|
| - |
|
2839 |
} else if (schemeAchievement < 12000000) {
|
| - |
|
2840 |
aimingTier = "Tarakki"; // 90 Lacs – 1.20 Cr
|
| - |
|
2841 |
} else if (schemeAchievement < 24000000) {
|
| - |
|
2842 |
aimingTier = "Vijeta"; // 1.20 – 2.40 Cr
|
| - |
|
2843 |
} else {
|
| - |
|
2844 |
aimingTier = "Maharaja"; // 2.40 Cr and above
|
| - |
|
2845 |
}
|
| - |
|
2846 |
}
|
| - |
|
2847 |
|
| - |
|
2848 |
|
| - |
|
2849 |
model.addAttribute("countOrder", countOrder);
|
| - |
|
2850 |
model.addAttribute("onlineDeliveredOrderSum", onlineDeliveredOrderSum.getSellingPrice());
|
| - |
|
2851 |
|
| - |
|
2852 |
PartnerType partnerType = partnerTypeChangeService.getTypeOnDate(fofoStore.getId(), LocalDate.now());
|
| - |
|
2853 |
model.addAttribute("partnerType", partnerType);
|
| - |
|
2854 |
model.addAttribute("partnerTypeImage", PartnerType.imageMap.get(partnerType));
|
| - |
|
2855 |
model.addAttribute("fofoStore", fofoStore);
|
| - |
|
2856 |
model.addAttribute("partnerType", partnerType);
|
| - |
|
2857 |
model.addAttribute("hasGift", fofoUser.hasGift(loginDetails.getFofoId()));
|
| - |
|
2858 |
model.addAttribute("giftItemId", ProfitMandiConstants.GIFT_ID);
|
| - |
|
2859 |
model.addAttribute("retailers", new JSONObject().append("code", fofoStore.getCode()).append("partnerId", fofoStore.getId()).toString());
|
| - |
|
2860 |
model.addAttribute("activatedImeis", inventoryItemRepository.selectCountByActivatedNotSold(loginDetails.getFofoId()));
|
| - |
|
2861 |
model.addAttribute("imeiActivationPendingCount", imeiActivationPendingCount);
|
| - |
|
2862 |
model.addAttribute("imeiActivationPendingValue", imeiActivationPendingValue);
|
| - |
|
2863 |
|
| - |
|
2864 |
Map<Integer, Double> accesoriesmtdsale = fofoOrderRepository.selectSumSaleGroupByFofoIdsForMobileOrAccessories(loginDetails.getFofoId(), curDate.withDayOfMonth(1), curDate.with(LocalTime.MAX), Optional.of(false));
|
| - |
|
2865 |
|
| - |
|
2866 |
Double accesoriesStock = currentInventorySnapshotRepository.selectSumStockGroupByFofoIdsForMobileOrAccessories(loginDetails.getFofoId(), Optional.of(false)).get(loginDetails.getFofoId());
|
| - |
|
2867 |
|
| - |
|
2868 |
model.addAttribute("accesoriesStock", String.format("%.0f", accesoriesStock));
|
| - |
|
2869 |
model.addAttribute("staticScheme", staticScheme);
|
| - |
|
2870 |
model.addAttribute("schemeAchievement", schemeAchievement);
|
| - |
|
2871 |
model.addAttribute("mobileLedAchievement", mobileLedAchievement);
|
| - |
|
2872 |
model.addAttribute("accessoriesAchievement", accessoriesAchievement);
|
| - |
|
2873 |
model.addAttribute("mobileLedTarget", mobileLedTarget);
|
| - |
|
2874 |
model.addAttribute("accessoriesTarget", accessoriesTarget);
|
| - |
|
2875 |
model.addAttribute("totalTarget", totalTarget);
|
| - |
|
2876 |
model.addAttribute("totalTargetDisplay", formatIndianCurrency(totalTarget));
|
| - |
|
2877 |
model.addAttribute("schemeAchievementDisplay", formatIndianCurrency((long) schemeAchievement));
|
| - |
|
2878 |
model.addAttribute("mobileLedAchievementDisplay", formatIndianCurrency((long) mobileLedAchievement));
|
| - |
|
2879 |
model.addAttribute("accessoriesAchievementDisplay", formatIndianCurrency((long) accessoriesAchievement));
|
| - |
|
2880 |
model.addAttribute("achievementPercent", achievementPercent);
|
| - |
|
2881 |
model.addAttribute("aimingTier", aimingTier);
|
| - |
|
2882 |
if (staticScheme != null) {
|
| - |
|
2883 |
model.addAttribute("schemePeriodDisplay",
|
| - |
|
2884 |
formatSchemePeriodDisplay(staticScheme.getStartDateTime(), staticScheme.getEndDateTime()));
|
| - |
|
2885 |
}
|
| - |
|
2886 |
model.addAttribute("brandStockPrices", fofoUser.getBrandStockPrices(loginDetails.getFofoId(), false));
|
| - |
|
2887 |
model.addAttribute("salesMap", fofoUser.getSales(loginDetails.getFofoId()));
|
| - |
|
2888 |
ChartModel cm = fofoUser.getBrandChart(loginDetails.getFofoId(),null,null,false);
|
| - |
|
2889 |
|
| - |
|
2890 |
LOGGER.info("chartMap" + gson.toJson(cm));
|
| - |
|
2891 |
model.addAttribute("chartMap", gson.toJson(cm));
|
| - |
|
2892 |
|
| - |
|
2893 |
List<CreateOfferRequest> createOffers = offerService.getPublishedOffers(loginDetails.getFofoId(), YearMonth.from(LocalDateTime.now()));
|
| - |
|
2894 |
|
| - |
|
2895 |
// Batch fetch all catalog IDs to avoid N+1 queries
|
| - |
|
2896 |
Set<Integer> allCatalogIds = createOffers.stream()
|
| - |
|
2897 |
.flatMap(offer -> offer.getTargetSlabs().stream())
|
| - |
|
2898 |
.flatMap(slab -> slab.getItemCriteriaPayouts().stream())
|
| - |
|
2899 |
.map(ItemCriteriaPayout::getItemCriteria)
|
| - |
|
2900 |
.flatMap(criteria -> criteria.getCatalogIds().stream())
|
| - |
|
2901 |
.collect(Collectors.toSet());
|
| - |
|
2902 |
|
| - |
|
2903 |
final Map<Integer, String> catalogBrandMap = new HashMap<>();
|
| - |
|
2904 |
if (!allCatalogIds.isEmpty()) {
|
| - |
|
2905 |
try {
|
| - |
|
2906 |
catalogBrandMap.putAll(catalogRepository.selectAllByIds(new ArrayList<>(allCatalogIds)).stream()
|
| - |
|
2907 |
.collect(Collectors.toMap(c -> c.getId(), c -> c.getBrand())));
|
| - |
|
2908 |
} catch (ProfitMandiBusinessException e) {
|
| - |
|
2909 |
LOGGER.error("Error fetching catalogs by IDs", e);
|
| - |
|
2910 |
}
|
| - |
|
2911 |
}
|
| - |
|
2912 |
|
| - |
|
2913 |
List<CreateOfferRequest> publishedOffers = createOffers.stream()
|
| - |
|
2914 |
.filter(createOffer -> createOffer.getTargetSlabs().stream()
|
| - |
|
2915 |
.flatMap(slab -> slab.getItemCriteriaPayouts().stream())
|
| - |
|
2916 |
.map(ItemCriteriaPayout::getItemCriteria)
|
| - |
|
2917 |
.flatMap(criteria -> criteria.getCatalogIds().stream())
|
| - |
|
2918 |
.noneMatch(catalogId -> "Live Demo".equals(catalogBrandMap.get(catalogId))))
|
| - |
|
2919 |
.collect(Collectors.toList());
|
| - |
|
2920 |
|
| - |
|
2921 |
model.addAttribute("publishedOffers", publishedOffers);
|
| - |
|
2922 |
model.addAttribute("investments", fofoUser.getInvestments(loginDetails.getFofoId()));
|
| - |
|
2923 |
model.addAttribute("isInvestmentOk", partnerInvestmentService.isInvestmentOk(loginDetails.getFofoId(), ProfitMandiConstants.MIN_INVESTMENT_PERCENTAGE, ProfitMandiConstants.CUTOFF_INVESTMENT));
|
| - |
|
2924 |
|
| - |
|
2925 |
double currentMonthRating = hygieneDataRepository.selectRatingAvg(loginDetails.getFofoId(), DateRangeModel.of(currentMonthStart, currentMonthEnd)) / 2;
|
| - |
|
2926 |
double lastMonthRating = hygieneDataRepository.selectRatingAvg(loginDetails.getFofoId(), DateRangeModel.of(lastMonthStart, currentMonthStart)) / 2;
|
| - |
|
2927 |
double ratingTillDate = hygieneDataRepository.selectRatingAvg(loginDetails.getFofoId(), DateRangeModel.withEndDate(currentMonthEnd)) / 2;
|
| - |
|
2928 |
model.addAttribute("currentMonthRating", (float) Math.round(currentMonthRating * 10) / 10);
|
| - |
|
2929 |
model.addAttribute("lastMonthRating", (float) Math.round(lastMonthRating * 10) / 10);
|
| - |
|
2930 |
model.addAttribute("ratingTillDate", (float) Math.round(ratingTillDate * 10) / 10);
|
| - |
|
2931 |
|
| - |
|
2932 |
long hygieneCount = hygieneDataRepository.selectHygieneCount(loginDetails.getFofoId(), true, currentMonthStart, currentMonthEnd);
|
| - |
|
2933 |
|
| - |
|
2934 |
long invalidHygieneCount = hygieneDataRepository.selectHygieneCount(loginDetails.getFofoId(), false, currentMonthStart, currentMonthEnd);
|
| - |
|
2935 |
if (hygieneCount == 0 && invalidHygieneCount == 0) {
|
| - |
|
2936 |
invalidHygieneCount = 1;
|
| - |
|
2937 |
}
|
| - |
|
2938 |
Map<Integer, String> monthValueMap = new HashMap<>();
|
| - |
|
2939 |
for (int i = 0; i <= 12; i++) {
|
| - |
|
2940 |
LocalDateTime startOfMonth = LocalDateTime.now().withDayOfMonth(1).minusMonths(i);
|
| - |
|
2941 |
monthValueMap.put(i, startOfMonth.format(DateTimeFormatter.ofPattern("MMM''uu")));
|
| - |
|
2942 |
}
|
| - |
|
2943 |
|
| - |
|
2944 |
MonthlyTarget monthlyTarget = monthlyTargetRepository.selectByDateAndFofoId(YearMonth.now(), fofoId);
|
| - |
|
2945 |
model.addAttribute("monthlyTarget", monthlyTarget);
|
| - |
|
2946 |
Set<String> brands = brandsService.getBrandsToDisplay(3).stream().map(x -> x.getName()).collect(Collectors.toSet());
|
| - |
|
2947 |
|
| - |
|
2948 |
model.addAttribute("brands", brands);
|
| - |
|
2949 |
model.addAttribute("monthValueMap", monthValueMap);
|
| - |
|
2950 |
model.addAttribute("month", 0);
|
| - |
|
2951 |
model.addAttribute("hygienePercentage", (hygieneCount * 100) / (invalidHygieneCount + hygieneCount));
|
| - |
|
2952 |
model.addAttribute("monthDays", LocalDate.now().minusDays(1).lengthOfMonth());
|
| - |
|
2953 |
model.addAttribute("dayOfMonth", LocalDate.now().minusDays(1).getDayOfMonth());
|
| - |
|
2954 |
Map<String, Object> rewardsMap = saleRewardService.findByFofoAndRegionId(fofoId, partnerRegion.get(0).getRegionId());
|
| - |
|
2955 |
StoreSalesTarget targetData = saleRewardService.findTargetsByFofoId(fofoId);
|
| - |
|
2956 |
model.addAttribute("rewardsMap", rewardsMap);
|
| - |
|
2957 |
model.addAttribute("targetData", targetData);
|
| - |
|
2958 |
model.addAttribute("regionId", partnerRegion.get(0).getRegionId());
|
| - |
|
2959 |
|
| - |
|
2960 |
|
| - |
|
2961 |
|
| - |
|
2962 |
} catch (
|
| - |
|
2963 |
ProfitMandiBusinessException e) {
|
| - |
|
2964 |
LOGGER.error("FofoStore Code not found of fofoId {}", loginDetails.getFofoId());
|
| - |
|
2965 |
|
| - |
|
2966 |
}
|
| - |
|
2967 |
return "dashboard1";
|
| - |
|
2968 |
}
|
| - |
|
2969 |
|
| - |
|
2970 |
}
|
| 2902 |
}
|
2971 |
}
|