Subversion Repositories SmartDukaan

Rev

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

Rev 37838 Rev 37846
Line 1... Line 1...
1
package com.spice.profitmandi.web.controller;
1
package com.spice.profitmandi.web.controller;
2
 
2
 
-
 
3
import com.spice.profitmandi.service.warehouse.BillingWarehouseService;
-
 
4
 
3
import com.google.gson.Gson;
5
import com.google.gson.Gson;
4
import com.mongodb.DBObject;
6
import com.mongodb.DBObject;
5
import com.spice.profitmandi.common.enumuration.ContentType;
7
import com.spice.profitmandi.common.enumuration.ContentType;
6
import com.spice.profitmandi.common.enumuration.MessageType;
8
import com.spice.profitmandi.common.enumuration.MessageType;
7
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
9
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
Line 88... Line 90...
88
 
90
 
89
@Controller
91
@Controller
90
@Transactional(rollbackFor = Throwable.class)
92
@Transactional(rollbackFor = Throwable.class)
91
public class DashboardController {
93
public class DashboardController {
92
 
94
 
-
 
95
    @Autowired
-
 
96
    private BillingWarehouseService billingWarehouseService;
-
 
97
 
-
 
98
 
93
    List<String> emails = Arrays.asList("kamini.sharma@smartdukaan.com", "neeraj.gupta@smartdukaan.com", "amit.gupta@smartdukaan.com", "ranu.rajput@smartdukaan.com", "vikas.jangra@smartdukaan.com", "tanay.gupta@smartdukaan.com", "rudy.kanwar@smartdukaan.com");
99
    List<String> emails = Arrays.asList("kamini.sharma@smartdukaan.com", "neeraj.gupta@smartdukaan.com", "amit.gupta@smartdukaan.com", "ranu.rajput@smartdukaan.com", "vikas.jangra@smartdukaan.com", "tanay.gupta@smartdukaan.com", "rudy.kanwar@smartdukaan.com");
94
 
100
 
95
    @Value("${web.api.host}")
101
    @Value("${web.api.host}")
96
    private String webApiHost;
102
    private String webApiHost;
97
 
103
 
Line 1425... Line 1431...
1425
        Map<Integer, List<Integer>> warehouseIdFofoIdMap = fofoStoreRepository
1431
        Map<Integer, List<Integer>> warehouseIdFofoIdMap = fofoStoreRepository
1426
                .selectActivePartnersByRetailerIds(new ArrayList<>(fofoIds)).stream()
1432
                .selectActivePartnersByRetailerIds(new ArrayList<>(fofoIds)).stream()
1427
                .collect(Collectors.groupingBy(FofoStore::getWarehouseId,
1433
                .collect(Collectors.groupingBy(FofoStore::getWarehouseId,
1428
                        Collectors.mapping(FofoStore::getId, Collectors.toList())));
1434
                        Collectors.mapping(FofoStore::getId, Collectors.toList())));
1429
 
1435
 
1430
        // Same rule as AdminUser.getWarehouseIdFofoIdMap: every warehouse holding stock is included, even with no
1436
        // Same rule as AdminUser.getWarehouseIdFofoIdMap: the ACTIVE warehouses, each even with no franchise store of
1431
        // franchise store of its own (the HR hubs carry only internal stores).
1437
        // its own (the HR hubs carry only internal stores), and no suspended or closed one even while it holds stock.
1432
        for (Integer stockWarehouseId : saholicInventoryCISRepository.selectWarehouseIdsWithStock()) {
1438
        Set<Integer> activeWarehouseIds = billingWarehouseService.getActiveWarehouses().keySet();
-
 
1439
        for (Integer activeWarehouseId : activeWarehouseIds) {
1433
            warehouseIdFofoIdMap.putIfAbsent(stockWarehouseId, new ArrayList<>());
1440
            warehouseIdFofoIdMap.putIfAbsent(activeWarehouseId, new ArrayList<>());
1434
        }
1441
        }
-
 
1442
        warehouseIdFofoIdMap.keySet().retainAll(activeWarehouseIds);
1435
        List<WarehouseWiseBrandStockModel> warehouseWiseBrandStock = new ArrayList<>();
1443
        List<WarehouseWiseBrandStockModel> warehouseWiseBrandStock = new ArrayList<>();
1436
        if (!warehouseId.contains(0)) {
1444
        if (!warehouseId.contains(0)) {
1437
            warehouseWiseBrandStock = saholicInventoryCISRepository.selectGroupByWarehouseAndBrand(warehouseId);
1445
            warehouseWiseBrandStock = saholicInventoryCISRepository.selectGroupByWarehouseAndBrand(warehouseId);
1438
        } else {
1446
        } else {
1439
            LOGGER.info("warehouseIdFofoIdMap" + warehouseIdFofoIdMap.keySet());
1447
            LOGGER.info("warehouseIdFofoIdMap" + warehouseIdFofoIdMap.keySet());
1440
            warehouseWiseBrandStock = saholicInventoryCISRepository.selectGroupByWarehouseAndBrand(new ArrayList<>(warehouseIdFofoIdMap.keySet()));
1448
            warehouseWiseBrandStock = saholicInventoryCISRepository.selectGroupByWarehouseAndBrand(new ArrayList<>(warehouseIdFofoIdMap.keySet()));
1441
 
1449
 
1442
        }
1450
        }
1443
        Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
1451
        Map<Integer, String> warehouseMap = billingWarehouseService.getActiveWarehouses();
1444
        model.addAttribute("warehouseWiseBrandStock", warehouseWiseBrandStock);
1452
        model.addAttribute("warehouseWiseBrandStock", warehouseWiseBrandStock);
1445
        model.addAttribute("warehouseId", warehouseId);
1453
        model.addAttribute("warehouseId", warehouseId);
1446
        model.addAttribute("warehouseMap", warehouseMap);
1454
        model.addAttribute("warehouseMap", warehouseMap);
1447
 
1455
 
1448
        return "warehouse_brand_stock";
1456
        return "warehouse_brand_stock";
Line 1463... Line 1471...
1463
                                           Model model) throws Exception {
1471
                                           Model model) throws Exception {
1464
        LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1472
        LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1465
        LinkedHashMap<Integer, WarehouseWiseStockModel> stockMap =
1473
        LinkedHashMap<Integer, WarehouseWiseStockModel> stockMap =
1466
                adminUser.getWarehouseStockMap(loginDetails.getEmailId(), brands);
1474
                adminUser.getWarehouseStockMap(loginDetails.getEmailId(), brands);
1467
        // Same shape adminPanel uses so the Total Values row (key 0) renders its label.
1475
        // Same shape adminPanel uses so the Total Values row (key 0) renders its label.
1468
        LinkedHashMap<Integer, String> warehouseMap = new LinkedHashMap<>(ProfitMandiConstants.WAREHOUSE_MAP);
1476
        LinkedHashMap<Integer, String> warehouseMap = new LinkedHashMap<>(billingWarehouseService.getActiveWarehouses());
1469
        warehouseMap.put(0, "Total Values");
1477
        warehouseMap.put(0, "Total Values");
1470
        model.addAttribute("warehouseStockMap", stockMap);
1478
        model.addAttribute("warehouseStockMap", stockMap);
1471
        model.addAttribute("warehouseMap", warehouseMap);
1479
        model.addAttribute("warehouseMap", warehouseMap);
1472
        return "warehouse_wise_stock_rows";
1480
        return "warehouse_wise_stock_rows";
1473
    }
1481
    }
Line 1475... Line 1483...
1475
    @RequestMapping(value = "/getWarehouseWiseBrandAndCategory", method = RequestMethod.GET)
1483
    @RequestMapping(value = "/getWarehouseWiseBrandAndCategory", method = RequestMethod.GET)
1476
    public String getWarehouseWiseBrandAndCategory(HttpServletRequest request, Model
1484
    public String getWarehouseWiseBrandAndCategory(HttpServletRequest request, Model
1477
            model, @RequestParam List<Integer> warehouseId, @RequestParam List<String> brands, @RequestParam String
1485
            model, @RequestParam List<Integer> warehouseId, @RequestParam List<String> brands, @RequestParam String
1478
                                                           category) throws Exception {
1486
                                                           category) throws Exception {
1479
 
1487
 
1480
        Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
1488
        Map<Integer, String> warehouseMap = billingWarehouseService.getActiveWarehouses();
1481
        List<String> listbrands = saholicInventoryCISRepository.selectAllBrand();
1489
        List<String> listbrands = saholicInventoryCISRepository.selectAllBrand();
1482
        List<String> listCategory = saholicInventoryCISRepository.selectAllSubCategory();
1490
        List<String> listCategory = saholicInventoryCISRepository.selectAllSubCategory();
1483
 
1491
 
1484
        model.addAttribute("warehouseMap", warehouseMap);
1492
        model.addAttribute("warehouseMap", warehouseMap);
1485
        model.addAttribute("brands", listbrands);
1493
        model.addAttribute("brands", listbrands);
Line 1494... Line 1502...
1494
 
1502
 
1495
    @RequestMapping(value = "/getWarehouseWiseItemStock", method = RequestMethod.GET)
1503
    @RequestMapping(value = "/getWarehouseWiseItemStock", method = RequestMethod.GET)
1496
    public String getWarehouseWiseItemStock(HttpServletRequest request, Model
1504
    public String getWarehouseWiseItemStock(HttpServletRequest request, Model
1497
            model, @RequestParam(name = "warehouseId") List<Integer> warehouseIds, @RequestParam List<String> brands, @RequestParam String
1505
            model, @RequestParam(name = "warehouseId") List<Integer> warehouseIds, @RequestParam List<String> brands, @RequestParam String
1498
                                                    category) throws Exception {
1506
                                                    category) throws Exception {
1499
        Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
1507
        Map<Integer, String> warehouseMap = billingWarehouseService.getActiveWarehouses();
1500
        if (warehouseIds.contains(0)) {
1508
        if (warehouseIds.contains(0)) {
1501
            warehouseIds.addAll(warehouseMap.keySet());
1509
            warehouseIds.addAll(warehouseMap.keySet());
1502
        }
1510
        }
1503
        // Band-aid for URL '+' decode issue on brand names (e.g. "Ai+"):
1511
        // Band-aid for URL '+' decode issue on brand names (e.g. "Ai+"):
1504
        // if a brand doesn't exist in catalog.brand as-is but "<brand>+" does,
1512
        // if a brand doesn't exist in catalog.brand as-is but "<brand>+" does,
Line 1576... Line 1584...
1576
                bpt.setLmtd(0);
1584
                bpt.setLmtd(0);
1577
                bpt.setLmtdQty(0);
1585
                bpt.setLmtdQty(0);
1578
                warehouseWiseBrandPartnerSales.put(un.getWarehouseId(), bpt);
1586
                warehouseWiseBrandPartnerSales.put(un.getWarehouseId(), bpt);
1579
            }
1587
            }
1580
        }
1588
        }
1581
        Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
1589
        Map<Integer, String> warehouseMap = billingWarehouseService.getActiveWarehouses();
1582
 
1590
 
1583
        Set<String> brands = inventoryService.getAllTagListingBrands();
1591
        Set<String> brands = inventoryService.getAllTagListingBrands();
1584
        model.addAttribute("warehouseWiseBrandPartnerSales", warehouseWiseBrandPartnerSales);
1592
        model.addAttribute("warehouseWiseBrandPartnerSales", warehouseWiseBrandPartnerSales);
1585
        model.addAttribute("warehouseMap", warehouseMap);
1593
        model.addAttribute("warehouseMap", warehouseMap);
1586
        model.addAttribute("brands", brands);
1594
        model.addAttribute("brands", brands);
Line 1602... Line 1610...
1602
            if (positions1.stream().filter(x -> x.getCategoryId() == ProfitMandiConstants.TICKET_CATEGORY_MASTER).count() > 0) {
1610
            if (positions1.stream().filter(x -> x.getCategoryId() == ProfitMandiConstants.TICKET_CATEGORY_MASTER).count() > 0) {
1603
                authfofoIds = csService.getPositionCustomRetailerMap(positions1).values().stream().flatMap(x -> x.stream()).map(x -> x.getPartnerId()).collect(Collectors.toSet());
1611
                authfofoIds = csService.getPositionCustomRetailerMap(positions1).values().stream().flatMap(x -> x.stream()).map(x -> x.getPartnerId()).collect(Collectors.toSet());
1604
            }
1612
            }
1605
        }
1613
        }
1606
        List<WarehouseWiseBrandSaleModel> warehouseWiseBrandPartnerSales = fofoStoreRepository.selectGroupByWarehouseAccesoriesBrandWisePartnerSale(brand, new ArrayList<>(authfofoIds));
1614
        List<WarehouseWiseBrandSaleModel> warehouseWiseBrandPartnerSales = fofoStoreRepository.selectGroupByWarehouseAccesoriesBrandWisePartnerSale(brand, new ArrayList<>(authfofoIds));
1607
        Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
1615
        Map<Integer, String> warehouseMap = billingWarehouseService.getActiveWarehouses();
1608
 
1616
 
1609
        Set<String> brands = inventoryService.getAllTagListingBrands();
1617
        Set<String> brands = inventoryService.getAllTagListingBrands();
1610
        model.addAttribute("warehouseWiseBrandPartnerSales", warehouseWiseBrandPartnerSales);
1618
        model.addAttribute("warehouseWiseBrandPartnerSales", warehouseWiseBrandPartnerSales);
1611
        model.addAttribute("warehouseMap", warehouseMap);
1619
        model.addAttribute("warehouseMap", warehouseMap);
1612
        model.addAttribute("brands", brands);
1620
        model.addAttribute("brands", brands);
Line 1615... Line 1623...
1615
    }
1623
    }
1616
 
1624
 
1617
    @RequestMapping(value = "/getWarehouseBrandWiseItemSale", method = RequestMethod.GET)
1625
    @RequestMapping(value = "/getWarehouseBrandWiseItemSale", method = RequestMethod.GET)
1618
    public String getWarehouseBrandWiseItemSale(HttpServletRequest request, Model
1626
    public String getWarehouseBrandWiseItemSale(HttpServletRequest request, Model
1619
            model, @RequestParam List<Integer> warehouseId, @RequestParam String brand) throws Exception {
1627
            model, @RequestParam List<Integer> warehouseId, @RequestParam String brand) throws Exception {
1620
        Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
1628
        Map<Integer, String> warehouseMap = billingWarehouseService.getActiveWarehouses();
1621
        LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1629
        LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1622
        String email = loginDetails.getEmailId();
1630
        String email = loginDetails.getEmailId();
1623
        Set<Integer> authfofoIds = csService1.getAuthFofoIds(email, true);
1631
        Set<Integer> authfofoIds = csService1.getAuthFofoIds(email, true);
1624
        Map<Integer, WarehouseBrandWiseItemSaleModel> branditemSalesMap = fofoStoreRepository.selectWarehouseBrandItemSale(warehouseId, brand, new ArrayList<>(authfofoIds)).stream().collect(Collectors.toMap(x -> x.getItemId(), x -> x));
1632
        Map<Integer, WarehouseBrandWiseItemSaleModel> branditemSalesMap = fofoStoreRepository.selectWarehouseBrandItemSale(warehouseId, brand, new ArrayList<>(authfofoIds)).stream().collect(Collectors.toMap(x -> x.getItemId(), x -> x));
1625
 
1633
 
Line 1655... Line 1663...
1655
    }
1663
    }
1656
 
1664
 
1657
    @RequestMapping(value = "/getWarehouseAccesoriesBrandWiseItemSale", method = RequestMethod.GET)
1665
    @RequestMapping(value = "/getWarehouseAccesoriesBrandWiseItemSale", method = RequestMethod.GET)
1658
    public String getWarehouseAccesoriesBrandWiseItemSale(HttpServletRequest request, Model
1666
    public String getWarehouseAccesoriesBrandWiseItemSale(HttpServletRequest request, Model
1659
            model, @RequestParam List<Integer> warehouseId, @RequestParam String brand) throws Exception {
1667
            model, @RequestParam List<Integer> warehouseId, @RequestParam String brand) throws Exception {
1660
        Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
1668
        Map<Integer, String> warehouseMap = billingWarehouseService.getActiveWarehouses();
1661
        LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1669
        LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1662
        String email = loginDetails.getEmailId();
1670
        String email = loginDetails.getEmailId();
1663
        Map<String, Set<Integer>> storeGuyMap = csService.getAuthUserPartnerIdMapping();
1671
        Map<String, Set<Integer>> storeGuyMap = csService.getAuthUserPartnerIdMapping();
1664
        Set<Integer> authfofoIds = storeGuyMap.get(email);
1672
        Set<Integer> authfofoIds = storeGuyMap.get(email);
1665
        List<WarehouseBrandWiseItemSaleModel> branditemSales = fofoStoreRepository.selectWarehouseAccesoriesBrandItemSale(warehouseId, brand, new ArrayList<>(authfofoIds));
1673
        List<WarehouseBrandWiseItemSaleModel> branditemSales = fofoStoreRepository.selectWarehouseAccesoriesBrandItemSale(warehouseId, brand, new ArrayList<>(authfofoIds));
Line 2406... Line 2414...
2406
                }
2414
                }
2407
 
2415
 
2408
            }
2416
            }
2409
        }
2417
        }
2410
 
2418
 
2411
        model.addAttribute("warehouseMap", ProfitMandiConstants.WAREHOUSE_MAP);
2419
        model.addAttribute("warehouseMap", billingWarehouseService.getActiveWarehouses());
2412
        model.addAttribute("warehouseId", warehouseId);
2420
        model.addAttribute("warehouseId", warehouseId);
2413
        model.addAttribute("milestones", Milestone.values());
2421
        model.addAttribute("milestones", Milestone.values());
2414
 
2422
 
2415
        return "sale-milestone";
2423
        return "sale-milestone";
2416
 
2424
 
Line 2488... Line 2496...
2488
                }
2496
                }
2489
 
2497
 
2490
            }
2498
            }
2491
        }
2499
        }
2492
 
2500
 
2493
        model.addAttribute("warehouseMap", ProfitMandiConstants.WAREHOUSE_MAP);
2501
        model.addAttribute("warehouseMap", billingWarehouseService.getActiveWarehouses());
2494
        model.addAttribute("warehouseId", warehouseId);
2502
        model.addAttribute("warehouseId", warehouseId);
2495
        model.addAttribute("milestones", Milestone.values());
2503
        model.addAttribute("milestones", Milestone.values());
2496
 
2504
 
2497
        return "purchase-milestone";
2505
        return "purchase-milestone";
2498
 
2506
 
Line 2502... Line 2510...
2502
    public String getActivatedModelWarehouseWise(HttpServletRequest request, Model model, @RequestParam String
2510
    public String getActivatedModelWarehouseWise(HttpServletRequest request, Model model, @RequestParam String
2503
            brand) throws Exception {
2511
            brand) throws Exception {
2504
        LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
2512
        LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
2505
        List<Integer> fofoIds = getFofoIds(loginDetails);
2513
        List<Integer> fofoIds = getFofoIds(loginDetails);
2506
        List<WarehouseWiseActivatedModel> warehouseWiseActivatedModels = activatedImeiRepository.selectActivatedModelGroupByWarehouse(brand, fofoIds);
2514
        List<WarehouseWiseActivatedModel> warehouseWiseActivatedModels = activatedImeiRepository.selectActivatedModelGroupByWarehouse(brand, fofoIds);
2507
        Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
2515
        Map<Integer, String> warehouseMap = billingWarehouseService.getActiveWarehouses();
2508
 
2516
 
2509
        List<DBObject> mobileBrands = mongoClient.getAllBrandsToDisplay(3);
2517
        List<DBObject> mobileBrands = mongoClient.getAllBrandsToDisplay(3);
2510
 
2518
 
2511
        List<String> brands = mobileBrands.stream().map(x -> (String) x.get("name")).collect(Collectors.toList());
2519
        List<String> brands = mobileBrands.stream().map(x -> (String) x.get("name")).collect(Collectors.toList());
2512
        LOGGER.info("brands" + brands.add("Redmi"));
2520
        LOGGER.info("brands" + brands.add("Redmi"));
Line 2532... Line 2540...
2532
    public String getWarehouseBrandWiseItemActivatedModel(HttpServletRequest request, Model
2540
    public String getWarehouseBrandWiseItemActivatedModel(HttpServletRequest request, Model
2533
            model, @RequestParam List<Integer> warehouseId, @RequestParam String brand) throws Exception {
2541
            model, @RequestParam List<Integer> warehouseId, @RequestParam String brand) throws Exception {
2534
        LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
2542
        LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
2535
        List<Integer> fofoIds = getFofoIds(loginDetails);
2543
        List<Integer> fofoIds = getFofoIds(loginDetails);
2536
 
2544
 
2537
        Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
2545
        Map<Integer, String> warehouseMap = billingWarehouseService.getActiveWarehouses();
2538
        List<WarehouseBrandWiseItemActivatedModel> activatedItems = activatedImeiRepository.selectWarehouseBrandActivatedItem(warehouseId, brand, fofoIds);
2546
        List<WarehouseBrandWiseItemActivatedModel> activatedItems = activatedImeiRepository.selectWarehouseBrandActivatedItem(warehouseId, brand, fofoIds);
2539
        model.addAttribute("warehouseMap", warehouseMap);
2547
        model.addAttribute("warehouseMap", warehouseMap);
2540
        model.addAttribute("activatedItems", activatedItems);
2548
        model.addAttribute("activatedItems", activatedItems);
2541
        return "warehouse-activated-itemwise-model";
2549
        return "warehouse-activated-itemwise-model";
2542
 
2550
 
2543
    }
2551
    }
2544
 
2552
 
2545
    @RequestMapping(value = "/getActivatedImeiUpdationDate", method = RequestMethod.GET)
2553
    @RequestMapping(value = "/getActivatedImeiUpdationDate", method = RequestMethod.GET)
2546
    public String getActivatedImeiUpdationDate(HttpServletRequest request, Model model) throws Exception {
2554
    public String getActivatedImeiUpdationDate(HttpServletRequest request, Model model) throws Exception {
2547
 
2555
 
2548
        Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
2556
        Map<Integer, String> warehouseMap = billingWarehouseService.getActiveWarehouses();
2549
        List<String> brands = ProfitMandiConstants.BRANDS;
2557
        List<String> brands = ProfitMandiConstants.BRANDS;
2550
 
2558
 
2551
        List<ActivationImeiUpdationModel> activationImeiUpdations = activatedImeiRepository.selectActivatedUpdationDate();
2559
        List<ActivationImeiUpdationModel> activationImeiUpdations = activatedImeiRepository.selectActivatedUpdationDate();
2552
 
2560
 
2553
        // Create a map for quick lookup of existing results
2561
        // Create a map for quick lookup of existing results