Subversion Repositories SmartDukaan

Rev

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

Rev 34397 Rev 34412
Line 2141... Line 2141...
2141
                Arrays.asList(OrderStatus.BILLED, OrderStatus.SHIPPED_FROM_WH, OrderStatus.SHIPPED_TO_LOGST, OrderStatus.DELIVERY_SUCCESS, OrderStatus.ACCEPTED, OrderStatus.SUBMITTED_FOR_PROCESSING),
2141
                Arrays.asList(OrderStatus.BILLED, OrderStatus.SHIPPED_FROM_WH, OrderStatus.SHIPPED_TO_LOGST, OrderStatus.DELIVERY_SUCCESS, OrderStatus.ACCEPTED, OrderStatus.SUBMITTED_FOR_PROCESSING),
2142
                curDate, curDate.with(LocalTime.MAX)).stream().collect(Collectors.toMap(x -> x.getId(), x -> x.getAmount()));
2142
                curDate, curDate.with(LocalTime.MAX)).stream().collect(Collectors.toMap(x -> x.getId(), x -> x.getAmount()));
2143
 
2143
 
2144
        double purchasedFtd = secondaryToday.getOrDefault(fofoId, 0.0);
2144
        double purchasedFtd = secondaryToday.getOrDefault(fofoId, 0.0);
2145
 
2145
 
-
 
2146
        MonthlyTarget monthlyTarget = monthlyTargetRepository.selectByDateAndFofoId(YearMonth.now(), fofoId);
-
 
2147
 
2146
        double purchaseTargetFtd = rbmTargetService.calculateFofoIdTodayTarget(fofoId, purchaseMtd);
2148
        double purchaseTargetFtd = rbmTargetService.calculateFofoIdTodayTarget(fofoId, purchaseMtd);
2147
 
2149
 
2148
        double saleMtd = (Double) fofoUser.getSales(fofoId).get("mtdSale");
2150
        double saleMtd = (Double) fofoUser.getSales(fofoId).get("mtdSale");
2149
 
2151
 
2150
        double recoverableAmount = saleMtd - purchaseMtd;
2152
        double recoverableAmount = saleMtd - purchaseMtd;
2151
 
2153
 
2152
        SDCreditRequirement sdCreditRequirement = sdCreditRequirementRepository.selectByFofoId(fofoId);
2154
        SDCreditRequirement sdCreditRequirement = sdCreditRequirementRepository.selectByFofoId(fofoId);
2153
        BigDecimal availableLimit = sdCreditRequirement.getAvailableLimit();
-
 
-
 
2155
 
2154
        UserWallet userWallet = walletService.getUserWallet(fofoId);
2156
        UserWallet userWallet = walletService.getUserWallet(fofoId);
2155
 
2157
 
2156
        BigDecimal totalAvailableFunds = availableLimit.add(BigDecimal.valueOf(userWallet.getAmount()));
2158
        BigDecimal totalAvailableFunds = sdCreditRequirement.getAvailableLimit().add(BigDecimal.valueOf(userWallet.getAmount()));
2157
 
2159
 
2158
        List<Loan> loans = loanRepository.selectActiveLoan(fofoId);
2160
        List<Loan> loans = loanRepository.selectActiveLoan(fofoId);
-
 
2161
        double totalPendingAmount = loans.stream()
-
 
2162
                .map(Loan::getPendingAmount)
-
 
2163
                .mapToDouble(BigDecimal::doubleValue)
-
 
2164
                .sum();
-
 
2165
 
2159
        boolean isLoanPending = false;
2166
        boolean isLoanPending = false;
2160
        if (loans.size() > 0) {
2167
        if (loans.size() > 0) {
2161
            isLoanPending = true;
2168
            isLoanPending = true;
2162
        }
2169
        }
2163
 
2170
 
2164
//      Sort the BRANDS list based on MTD sale in descending order
2171
        List<String> sortedBrandsByMtd = brandToMtdMap.entrySet()
-
 
2172
                .stream()
2165
        List<String> sortedBrands = ProfitMandiConstants.BRANDS.stream()
2173
                .sorted((e1, e2) -> Long.compare(e2.getValue(), e1.getValue())) // Descending MTD
2166
                .sorted((b1, b2) -> {
2174
                .map(Map.Entry::getKey)
2167
                    long mtd1 = brandToMtdMap.getOrDefault(b1, 0L);
2175
                .collect(Collectors.toList());
-
 
2176
 
2168
                    long mtd2 = brandToMtdMap.getOrDefault(b2, 0L);
2177
        List<String> remainingBrands = ProfitMandiConstants.BRANDS.stream()
2169
                    return Long.compare(mtd2, mtd1); // descending
2178
                .filter(x -> !brandToMtdMap.containsKey(x))
2170
                }).collect(Collectors.toList());
2179
                .collect(Collectors.toList());
-
 
2180
 
-
 
2181
        List<String> finalSortedBrands = new ArrayList<>();
-
 
2182
        finalSortedBrands.addAll(sortedBrandsByMtd);
-
 
2183
        finalSortedBrands.addAll(remainingBrands);
2171
 
2184
 
2172
        List<PartnerWarehouseStockSummaryModel> partnerWarehouseStockSummaryModels = saholicInventoryService.getSaholicAndPartnerStock(fofoId, fofoStore.getWarehouseId());
2185
        List<PartnerWarehouseStockSummaryModel> partnerWarehouseStockSummaryModels = saholicInventoryService.getSaholicAndPartnerStock(fofoId, fofoStore.getWarehouseId());
2173
 
2186
 
2174
        Set<Integer> catalogIds = partnerWarehouseStockSummaryModels.stream().map(x -> x.getCatalogId()).collect(Collectors.toSet());
2187
        Set<Integer> catalogIds = partnerWarehouseStockSummaryModels.stream().map(x -> x.getCatalogId()).collect(Collectors.toSet());
-
 
2188
        LOGGER.info("fofoid {} , catalogIds {}", catalogIds, fofoId);
2175
 
2189
 
2176
        List<DateWiseSoldCatalogQtyModel> sevenDayAboveSoldsCatalogs = fofoOrderRepository.getDateWiseSoldCatalogQty(fofoId, catalogIds, presentDate.minusDays(7));
2190
        List<DateWiseSoldCatalogQtyModel> sevenDayAboveSoldsCatalogs = fofoOrderRepository.getDateWiseSoldCatalogQty(fofoId, catalogIds, presentDate.minusDays(7));
2177
        Map<Integer, DateWiseSoldCatalogQtyModel> sevenDayAboveSoldsCatalogsMap = sevenDayAboveSoldsCatalogs.stream().collect(Collectors.toMap(x -> x.getCatalogId(), x -> x));
-
 
2178
 
2191
 
2179
        List<DateWiseSoldCatalogQtyModel> fourteenDayAboveSoldsCatalogs = fofoOrderRepository.getDateWiseSoldCatalogQty(fofoId, catalogIds, presentDate.minusDays(14));
2192
        List<DateWiseSoldCatalogQtyModel> fourteenDayAboveSoldsCatalogs = fofoOrderRepository.getDateWiseSoldCatalogQty(fofoId, catalogIds, presentDate.minusDays(14));
2180
        Map<Integer, DateWiseSoldCatalogQtyModel> fourteenDayAboveSoldsCatalogsMap = fourteenDayAboveSoldsCatalogs.stream().collect(Collectors.toMap(x -> x.getCatalogId(), x -> x));
-
 
2181
 
2193
 
2182
        List<DateWiseSoldCatalogQtyModel> twentyOneDayAboveSoldsCatalogs = fofoOrderRepository.getDateWiseSoldCatalogQty(fofoId, catalogIds, presentDate.minusDays(21));
2194
        List<DateWiseSoldCatalogQtyModel> twentyOneDayAboveSoldsCatalogs = fofoOrderRepository.getDateWiseSoldCatalogQty(fofoId, catalogIds, presentDate.minusDays(21));
2183
        Map<Integer, DateWiseSoldCatalogQtyModel> twentyOneDayAboveSoldsCatalogsMap = twentyOneDayAboveSoldsCatalogs.stream().collect(Collectors.toMap(x -> x.getCatalogId(), x -> x));
-
 
-
 
2195
 
2184
        LOGGER.info("twentyOneDayAboveSoldsCatalogs {}", twentyOneDayAboveSoldsCatalogs);
2196
        LOGGER.info("twentyOneDayAboveSoldsCatalogs {}", twentyOneDayAboveSoldsCatalogs);
-
 
2197
 
2185
        List<DateWiseSoldCatalogQtyModel> twentyEightDayAboveSoldsCatalogs = fofoOrderRepository.getDateWiseSoldCatalogQty(fofoId, catalogIds, presentDate.minusDays(28));
2198
        List<DateWiseSoldCatalogQtyModel> twentyEightDayAboveSoldsCatalogs = fofoOrderRepository.getDateWiseSoldCatalogQty(fofoId, catalogIds, presentDate.minusDays(28));
2186
        Map<Integer, DateWiseSoldCatalogQtyModel> twentyEightDayAboveSoldsCatalogsMap = twentyEightDayAboveSoldsCatalogs.stream().collect(Collectors.toMap(x -> x.getCatalogId(), x -> x));
-
 
-
 
2199
 
2187
 
2200
 
2188
        List<CatalogAgingModel> catalogAgingModels = ageingService.getCatalogsAgingByWarehouse(catalogIds, fofoStore.getWarehouseId());
2201
        List<CatalogAgingModel> catalogAgingModels = ageingService.getCatalogsAgingByWarehouse(catalogIds, fofoStore.getWarehouseId());
2189
 
2202
 
2190
        Map<Integer, CatalogAgingModel> catalogAgingModelMap = catalogAgingModels.stream().collect(Collectors.toMap(x -> x.getCatalogId(), x -> x));
2203
        Map<Integer, CatalogAgingModel> catalogAgingModelMap = catalogAgingModels.stream().collect(Collectors.toMap(x -> x.getCatalogId(), x -> x));
2191
 
2204
 
Line 2239... Line 2252...
2239
                        (v1, v2) -> v1,
2252
                        (v1, v2) -> v1,
2240
                        LinkedHashMap::new // Maintain order of brands
2253
                        LinkedHashMap::new // Maintain order of brands
2241
                ));
2254
                ));
2242
 
2255
 
2243
        model.addAttribute("brandStatusWiseStockListMap", sortedBrandStatusWiseStockListMap);
2256
        model.addAttribute("brandStatusWiseStockListMap", sortedBrandStatusWiseStockListMap);
2244
        model.addAttribute("sevenDayAboveSoldsCatalogsMap", sevenDayAboveSoldsCatalogsMap);
2257
        model.addAttribute("brands", finalSortedBrands);
2245
        model.addAttribute("fourteenDayAboveSoldsCatalogsMap", fourteenDayAboveSoldsCatalogsMap);
-
 
2246
        model.addAttribute("twentyOneDayAboveSoldsCatalogsMap", twentyOneDayAboveSoldsCatalogsMap);
-
 
2247
        model.addAttribute("twentyEightDayAboveSoldsCatalogsMap", twentyEightDayAboveSoldsCatalogsMap);
-
 
2248
        model.addAttribute("brands", sortedBrands);
2258
        model.addAttribute("brandToMtdMap", brandToMtdMap);
2249
        model.addAttribute("brand", brand);
2259
        model.addAttribute("brand", brand);
2250
        model.addAttribute("fofoId", fofoId);
2260
        model.addAttribute("fofoId", fofoId);
2251
        model.addAttribute("customRetailer", customRetailer);
2261
        model.addAttribute("customRetailer", customRetailer);
2252
        model.addAttribute("shortInvest", shortInvest);
2262
        model.addAttribute("shortInvest", shortInvest);
2253
        model.addAttribute("purchaseMtd", purchaseMtd);
2263
        model.addAttribute("purchaseMtd", purchaseMtd);
Line 2255... Line 2265...
2255
        model.addAttribute("saleMtd", saleMtd);
2265
        model.addAttribute("saleMtd", saleMtd);
2256
        model.addAttribute("purchaseTargetFtd", purchaseTargetFtd);
2266
        model.addAttribute("purchaseTargetFtd", purchaseTargetFtd);
2257
        model.addAttribute("recoverableAmount", recoverableAmount);
2267
        model.addAttribute("recoverableAmount", recoverableAmount);
2258
        model.addAttribute("isLoanPending", isLoanPending);
2268
        model.addAttribute("isLoanPending", isLoanPending);
2259
        model.addAttribute("totalAvailableFunds", totalAvailableFunds);
2269
        model.addAttribute("totalAvailableFunds", totalAvailableFunds);
-
 
2270
        model.addAttribute("sdCreditRequirement", sdCreditRequirement);
-
 
2271
        model.addAttribute("userWallet", userWallet);
-
 
2272
        model.addAttribute("monthlyTarget", monthlyTarget);
-
 
2273
        model.addAttribute("totalPendingAmount", totalPendingAmount);
-
 
2274
 
-
 
2275
        model.addAttribute("sevenDayAboveSoldsCatalogs", sevenDayAboveSoldsCatalogs);
-
 
2276
        model.addAttribute("fourteenDayAboveSoldsCatalogs", fourteenDayAboveSoldsCatalogs);
-
 
2277
        model.addAttribute("twentyOneDayAboveSoldsCatalogs", twentyOneDayAboveSoldsCatalogs);
-
 
2278
        model.addAttribute("twentyEightDayAboveSoldsCatalogs", twentyEightDayAboveSoldsCatalogs);
2260
        return "partner-stock";
2279
        return "partner-stock";
2261
 
2280
 
2262
    }
2281
    }
2263
 
2282
 
2264
    private List<PartnerStockDescriptionModel> getBrandItemwiseDescription(String brand,
2283
    private List<PartnerStockDescriptionModel> getBrandItemwiseDescription(String brand,