Subversion Repositories SmartDukaan

Rev

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

Rev 31762 Rev 32232
Line 31... Line 31...
31
import com.spice.profitmandi.dao.repository.transaction.TransactionRepository;
31
import com.spice.profitmandi.dao.repository.transaction.TransactionRepository;
32
import com.spice.profitmandi.service.authentication.RoleManager;
32
import com.spice.profitmandi.service.authentication.RoleManager;
33
import com.spice.profitmandi.service.inventory.InventoryService;
33
import com.spice.profitmandi.service.inventory.InventoryService;
34
import com.spice.profitmandi.service.offers.OfferService;
34
import com.spice.profitmandi.service.offers.OfferService;
35
import com.spice.profitmandi.service.offers.PartnerCriteria;
35
import com.spice.profitmandi.service.offers.PartnerCriteria;
-
 
36
import com.spice.profitmandi.service.pricecircular.PriceCircularService;
36
import com.spice.profitmandi.service.scheme.SchemeService;
37
import com.spice.profitmandi.service.scheme.SchemeService;
37
import com.spice.profitmandi.service.user.RetailerService;
38
import com.spice.profitmandi.service.user.RetailerService;
38
import com.spice.profitmandi.service.wallet.WalletService;
39
import com.spice.profitmandi.service.wallet.WalletService;
39
import com.spice.profitmandi.web.model.LoginDetails;
40
import com.spice.profitmandi.web.model.LoginDetails;
40
import com.spice.profitmandi.web.util.CookiesProcessor;
41
import com.spice.profitmandi.web.util.CookiesProcessor;
Line 140... Line 141...
140
    private SamsungUpgradeOfferRepository samsungUpgradeOfferRepository;
141
    private SamsungUpgradeOfferRepository samsungUpgradeOfferRepository;
141
    @Autowired
142
    @Autowired
142
    private CsService csService;
143
    private CsService csService;
143
    @Autowired
144
    @Autowired
144
    private CategoryRepository categoryRepository;
145
    private CategoryRepository categoryRepository;
-
 
146
 
-
 
147
    @Autowired
-
 
148
    PriceCircularService priceCircularService;
-
 
149
 
-
 
150
 
145
    @Autowired
151
    @Autowired
146
    private Gson gson;
152
    private Gson gson;
147
 
153
 
148
    private boolean getAccess(String emailId) {
154
    private boolean getAccess(String emailId) {
149
 
155
 
Line 628... Line 634...
628
            model.addAttribute("customRetailer", customRetailer);
634
            model.addAttribute("customRetailer", customRetailer);
629
        }
635
        }
630
        return "scheme-imei-history";
636
        return "scheme-imei-history";
631
    }
637
    }
632
 
638
 
-
 
639
 
-
 
640
    @Autowired
-
 
641
    PriceDropController priceDropController;
-
 
642
 
633
    @RequestMapping(value = "/getSchemes", method = RequestMethod.GET)
643
    @RequestMapping(value = "/getSchemes", method = RequestMethod.GET)
634
    public String getSchemes(HttpServletRequest request, @RequestParam(name = "offset", defaultValue = "0") int offset,
644
    public String getSchemes(HttpServletRequest request, @RequestParam(name = "offset", defaultValue = "0") int offset,
635
                             @RequestParam(required = false) LocalDate date,
645
                             @RequestParam(required = false) LocalDate date,
636
                             @RequestParam(name = "limit", required = false, defaultValue = "30") int limit,
646
                             @RequestParam(name = "limit", required = false, defaultValue = "30") int limit,
637
                             @RequestParam(name = "searchModel", required = false, defaultValue = "0") int searchModel,
647
                             @RequestParam(name = "searchModel", required = false, defaultValue = "0") int searchModel,
Line 779... Line 789...
779
                model.addAttribute("offerRequestMap", offerRequestMap);
789
                model.addAttribute("offerRequestMap", offerRequestMap);
780
                model.addAttribute("inventoryItem", inventoryItem);
790
                model.addAttribute("inventoryItem", inventoryItem);
781
                model.addAttribute("inventoryItem", inventoryItem);
791
                model.addAttribute("inventoryItem", inventoryItem);
782
 
792
 
783
            }
793
            }
784
            model.addAttribute("netEarnings", netEarnings);
-
 
785
            model.addAttribute("fofoId", loginDetails.getFofoId());
794
            model.addAttribute("fofoId", loginDetails.getFofoId());
786
            model.addAttribute("schemeMap", schemeMap);
795
            model.addAttribute("schemeMap", schemeMap);
787
            model.addAttribute("item", item);
796
            model.addAttribute("item", item);
788
            model.addAttribute("schemeInOut", schemeInOuts);
797
            model.addAttribute("schemeInOut", schemeInOuts);
789
            return "schemes-partner";
798
            return "schemes-partner";
Line 1054... Line 1063...
1054
 
1063
 
1055
        Map<String, Map<String, Double>> lastMonthPurchaseInMapPairMap = lastMonthPurchaseInImeis.stream()
1064
        Map<String, Map<String, Double>> lastMonthPurchaseInMapPairMap = lastMonthPurchaseInImeis.stream()
1056
                .collect(Collectors.groupingBy(x -> x.getImei(),
1065
                .collect(Collectors.groupingBy(x -> x.getImei(),
1057
                        Collectors.groupingBy(x -> x.getDescription(), Collectors.summingDouble(x -> x.getAmount()))));
1066
                        Collectors.groupingBy(x -> x.getDescription(), Collectors.summingDouble(x -> x.getAmount()))));
1058
        Map<String, LocalDate> imeiPurchaseDateMap = lastMonthPurchaseInImeis.stream().collect(Collectors.toMap(x -> x.getImei(), x -> x.getCreateTimeStamp().toLocalDate(), (x, y) -> x));
1067
        Map<String, LocalDate> imeiPurchaseDateMap = lastMonthPurchaseInImeis.stream().collect(Collectors.toMap(x -> x.getImei(), x -> x.getCreateTimeStamp().toLocalDate(), (x, y) -> x));
1059
        Map<String, LocalDate> imeiSaleDateMap = lastMonthCreditedImeis.stream().collect(Collectors.toMap(x -> x.getImei(), x -> x.getCreateTimeStamp().toLocalDate(), (x, y) -> x));
1068
        Map<String, LocalDate> imeiSaleDateMap = lastMonthFrontEndImeis.stream().collect(Collectors.toMap(x -> x.getImei(), x -> x.getCreated()));
1060
        Map<String, Map<String, Double>> lastMonthCreditedMapPairMap = lastMonthCreditedImeis.stream()
1069
        Map<String, Map<String, Double>> lastMonthCreditedMapPairMap = lastMonthCreditedImeis.stream()
1061
                .collect(Collectors.groupingBy(x -> x.getImei(),
1070
                .collect(Collectors.groupingBy(x -> x.getImei(),
1062
                        Collectors.groupingBy(x -> x.getDescription(), Collectors.summingDouble(x -> x.getAmount()))));
1071
                        Collectors.groupingBy(x -> x.getDescription(), Collectors.summingDouble(x -> x.getAmount()))));
1063
 
1072
 
1064
        // descriptionSet.add("")
1073
        // descriptionSet.add("")
Line 1082... Line 1091...
1082
        }
1091
        }
1083
 
1092
 
1084
        for (Map.Entry<String, Map<String, Double>> entry : lastMonthCreditedMapPairMap.entrySet()) {
1093
        for (Map.Entry<String, Map<String, Double>> entry : lastMonthCreditedMapPairMap.entrySet()) {
1085
            Map<String, Double> descriptionAmountMap = entry.getValue();
1094
            Map<String, Double> descriptionAmountMap = entry.getValue();
1086
            if (!imeiWiseIncomeMapOfMap.containsKey(entry.getKey())) {
1095
            if (!imeiWiseIncomeMapOfMap.containsKey(entry.getKey())) {
1087
                ImeiWiseIncomePairAndMapModel modelImeiMap = new ImeiWiseIncomePairAndMapModel(entry.getKey(), null,
1096
                imeiWiseIncomeMapOfMap.put(entry.getKey(), new ImeiWiseIncomePairAndMapModel(entry.getKey(), null, null));
1088
                        imeiSaleDateMap.get(entry.getKey()));
-
 
1089
                imeiWiseIncomeMapOfMap.put(entry.getKey(), modelImeiMap);
-
 
1090
            } else {
-
 
1091
                ImeiWiseIncomePairAndMapModel modelImeiMap = imeiWiseIncomeMapOfMap.get(entry.getKey());
-
 
1092
                modelImeiMap.setSaleDate(imeiSaleDateMap.get(entry.getKey()));
-
 
1093
            }
1097
            }
-
 
1098
            ImeiWiseIncomePairAndMapModel modelImeiMap = imeiWiseIncomeMapOfMap.get(entry.getKey());
-
 
1099
            ;
-
 
1100
            modelImeiMap.setSaleDate(imeiSaleDateMap.get(entry.getKey()));
1094
 
1101
 
1095
            double totalAmount = descriptionAmountMap.entrySet().stream()
1102
            double totalAmount = descriptionAmountMap.entrySet().stream()
1096
                    .collect(Collectors.summingDouble(x -> x.getValue()));
1103
                    .collect(Collectors.summingDouble(x -> x.getValue()));
1097
            imeiWiseIncomeMapOfMap.get(entry.getKey())
1104
            imeiWiseIncomeMapOfMap.get(entry.getKey())
1098
                    .setTotalIncome(totalAmount + imeiWiseIncomeMapOfMap.get(entry.getKey()).getTotalIncome());
1105
                    .setTotalIncome(totalAmount + imeiWiseIncomeMapOfMap.get(entry.getKey()).getTotalIncome());
1099
        }
1106
        }
1100
 
1107
 
1101
        /*lastMonthFrontEndImeis.stream().forEach(x -> {
-
 
1102
            if (imeiWiseIncomeMapOfMap.containsKey(x.getImei())) {
-
 
1103
                ImeiWiseIncomePairAndMapModel imeiWiseIncomePairAndMapModel = imeiWiseIncomeMapOfMap
-
 
1104
                        .get(x.getImei());
-
 
1105
                imeiWiseIncomePairAndMapModel.setTotalIncome(imeiWiseIncomePairAndMapModel.getTotalIncome() + x.getAmount());
-
 
1106
                imeiWiseIncomePairAndMapModel.setFrontMargin(x.getAmount());
-
 
1107
            }
-
 
1108
        });*/
-
 
1109
 
-
 
1110
        //Imeis for pending activation
1108
        //Imeis for pending activation
1111
        lastMonthCreditedImeis.stream().filter(x -> x.getStatus().equals(SchemePayoutStatus.PENDING)).forEach(x -> {
1109
        lastMonthCreditedImeis.stream().filter(x -> x.getStatus().equals(SchemePayoutStatus.PENDING)).forEach(x -> {
1112
            if (!imeiWiseIncomeMapOfMap.containsKey(x.getImei())) {
1110
            if (!imeiWiseIncomeMapOfMap.containsKey(x.getImei())) {
1113
                ImeiWiseIncomePairAndMapModel imeiWiseIncomePairAndMapModel = new ImeiWiseIncomePairAndMapModel(x.getImei(), null, null);
1111
                imeiWiseIncomeMapOfMap.put(x.getImei(), new ImeiWiseIncomePairAndMapModel(x.getImei()));
1114
            }
1112
            }
1115
            ImeiWiseIncomePairAndMapModel imeiWiseIncomePairAndMapModel = imeiWiseIncomeMapOfMap
1113
            ImeiWiseIncomePairAndMapModel imeiWiseIncomePairAndMapModel = imeiWiseIncomeMapOfMap
1116
                    .get(x.getImei());
1114
                    .get(x.getImei());
1117
            imeiWiseIncomePairAndMapModel.setSaleDate(x.getCreateTimeStamp().toLocalDate());
1115
            imeiWiseIncomePairAndMapModel.setSaleDate(x.getCreateTimeStamp().toLocalDate());
1118
            imeiWiseIncomePairAndMapModel.setTotalIncome(x.getPendingSaleAmount() + imeiWiseIncomePairAndMapModel.getTotalIncome());
1116
            imeiWiseIncomePairAndMapModel.setTotalIncome(x.getPendingSaleAmount() + imeiWiseIncomePairAndMapModel.getTotalIncome());
1119
        });
1117
        });
1120
 
1118
 
1121
        lastMonthFrontEndImeis.stream().forEach(lastMonthFrontEndImeiModel -> {
1119
        lastMonthFrontEndImeis.stream().forEach(lastMonthFrontEndImeiModel -> {
1122
            if (imeiWiseIncomeMapOfMap.containsKey(lastMonthFrontEndImeiModel.getImei())) {
1120
            if (!imeiWiseIncomeMapOfMap.containsKey(lastMonthFrontEndImeiModel.getImei())) {
1123
                lastMonthFrontEndImeiModel.setNlc(lastMonthFrontEndImeiModel.getDp()
-
 
1124
                        - (float) imeiWiseIncomeMapOfMap.get(lastMonthFrontEndImeiModel.getImei()).getTotalIncome());
-
 
1125
                lastMonthFrontEndImeiModel.setNetIncome(lastMonthFrontEndImeiModel.getSellingPrice() - lastMonthFrontEndImeiModel.getNlc());
1121
                imeiWiseIncomeMapOfMap.put(lastMonthFrontEndImeiModel.getImei(), new ImeiWiseIncomePairAndMapModel(lastMonthFrontEndImeiModel.getImei()));
1126
            }
1122
            }
-
 
1123
            ImeiWiseIncomePairAndMapModel imeiWiseIncomePairAndMapModel = imeiWiseIncomeMapOfMap
-
 
1124
                    .get(lastMonthFrontEndImeiModel.getImei());
-
 
1125
            lastMonthFrontEndImeiModel.setNlc(lastMonthFrontEndImeiModel.getDp()
-
 
1126
                    - (float) imeiWiseIncomeMapOfMap.get(lastMonthFrontEndImeiModel.getImei()).getTotalIncome());
-
 
1127
            lastMonthFrontEndImeiModel.setNetIncome(lastMonthFrontEndImeiModel.getSellingPrice() - lastMonthFrontEndImeiModel.getNlc());
-
 
1128
            imeiWiseIncomePairAndMapModel.setSaleDate(lastMonthFrontEndImeiModel.getCreated());
1127
        });
1129
        });
1128
 
1130
 
1129
        model.addAttribute("imeiWisePendingSaleAmount", imeiWisePendingSaleAmount);
1131
        model.addAttribute("imeiWisePendingSaleAmount", imeiWisePendingSaleAmount);
1130
        model.addAttribute("month", month);
1132
        model.addAttribute("month", month);
1131
        model.addAttribute("purchaseList", purchaseList);
1133
        model.addAttribute("purchaseList", purchaseList);
Line 1143... Line 1145...
1143
    }
1145
    }
1144
 
1146
 
1145
    @RequestMapping(value = "/brandWiseIncome", method = RequestMethod.GET)
1147
    @RequestMapping(value = "/brandWiseIncome", method = RequestMethod.GET)
1146
    public String getBrandWiseIncome(HttpServletRequest request,
1148
    public String getBrandWiseIncome(HttpServletRequest request,
1147
                                     @RequestParam(name = "brand", required = false, defaultValue = "") String brand,
1149
                                     @RequestParam(name = "brand", required = false, defaultValue = "") String brand,
1148
                                     @RequestParam(name = "status", required = false, defaultValue = "") String status,
1150
                                     @RequestParam(name = "month", required = false, defaultValue = "") int month,
1149
                                     @RequestParam(name = "month", required = false, defaultValue = "") int month, Model model)
1151
                                     Model model)
1150
            throws ProfitMandiBusinessException {
1152
            throws ProfitMandiBusinessException {
1151
        LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1153
        LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1152
        LOGGER.info("loginDetails {}", loginDetails);
1154
        LOGGER.info("loginDetails {}", loginDetails);
1153
        LOGGER.info("brand" + brand);
1155
        LOGGER.info("brand" + brand);
1154
        LOGGER.info("month {}", month);
1156
        LOGGER.info("month {}", month);
Line 1156... Line 1158...
1156
        LocalDateTime monthStart = LocalDate.now().minusMonths(month).withDayOfMonth(1).atStartOfDay();
1158
        LocalDateTime monthStart = LocalDate.now().minusMonths(month).withDayOfMonth(1).atStartOfDay();
1157
        LocalDateTime monthEnd = monthStart.plusMonths(1);
1159
        LocalDateTime monthEnd = monthStart.plusMonths(1);
1158
 
1160
 
1159
        List<OfferPayoutImeiIncomeModel> offerPayoutImeiIncomeModels = offerPayoutRepository.getTotalPayoutsByPartnerPeriod(
1161
        List<OfferPayoutImeiIncomeModel> offerPayoutImeiIncomeModels = offerPayoutRepository.getTotalPayoutsByPartnerPeriod(
1160
                YearMonth.of(monthStart.getYear(), monthStart.getMonth()), loginDetails.getFofoId(), brand, null);
1162
                YearMonth.of(monthStart.getYear(), monthStart.getMonth()), loginDetails.getFofoId(), brand, null);
-
 
1163
        LOGGER.info("offerPayoutImeiIncomeModels - {}", offerPayoutImeiIncomeModels);
1161
        Map<Integer, Double> additionalPurchasePayout = offerPayoutImeiIncomeModels.stream().collect(Collectors.groupingBy(x -> x.getCatalogId(), Collectors.summingDouble(x -> x.getPurchasePayout())));
1164
        Map<Integer, Double> additionalPurchasePayout = offerPayoutImeiIncomeModels.stream().filter(x -> x.getPurchasePayout() > 0).collect(Collectors.groupingBy(x -> x.getCatalogId(), Collectors.summingDouble(x -> x.getPurchasePayout())));
-
 
1165
        Map<Integer, Integer> additionalPurchaseQty = offerPayoutImeiIncomeModels.stream().filter(x -> x.getPurchasePayout() > 0).collect(Collectors.groupingBy(x -> x.getCatalogId(), Collectors.summingInt(x -> 1)));
1162
        Map<Integer, Double> additionalSalePayout = offerPayoutImeiIncomeModels.stream().collect(Collectors.groupingBy(x -> x.getCatalogId(), Collectors.summingDouble(x -> x.getSalePayout())));
1166
        Map<Integer, Double> additionalSalePayoutMap = offerPayoutImeiIncomeModels.stream().filter(x -> x.getSalePayout() > 0).collect(Collectors.groupingBy(x -> x.getCatalogId(), Collectors.summingDouble(x -> x.getSalePayout())));
-
 
1167
        Map<Integer, Integer> additionalSaleQty = offerPayoutImeiIncomeModels.stream().filter(x -> x.getSalePayout() > 0).collect(Collectors.groupingBy(x -> x.getCatalogId(), Collectors.summingInt(x -> 1)));
1163
 
1168
 
-
 
1169
        Set<Integer> allCatalogIds = offerPayoutImeiIncomeModels.stream().map(x -> x.getCatalogId()).collect(Collectors.toSet());
1164
        boolean partnerTypeUpgraded = partnerTypeChangeService.isPartnerTypeUpgraded(loginDetails.getFofoId(),
1170
        boolean partnerTypeUpgraded = partnerTypeChangeService.isPartnerTypeUpgraded(loginDetails.getFofoId(),
1165
                YearMonth.now());
1171
                YearMonth.now());
1166
 
1172
 
1167
        LOGGER.info("partnerType" + partnerTypeUpgraded);
1173
        LOGGER.info("partnerType" + partnerTypeUpgraded);
1168
 
1174
 
Line 1174... Line 1180...
1174
                    .stream().collect(Collectors.toMap(x -> x.getBrand(), x -> x.getAmount()));
1180
                    .stream().collect(Collectors.toMap(x -> x.getBrand(), x -> x.getAmount()));
1175
        }
1181
        }
1176
 
1182
 
1177
        List<LastMonthFrontEndBrandWiseIncome> modelWiseSalesMargins = schemeInOutRepository
1183
        List<LastMonthFrontEndBrandWiseIncome> modelWiseSalesMargins = schemeInOutRepository
1178
                .selectFrontIncomeBrandWise(loginDetails.getFofoId(), brand, monthStart, monthEnd);
1184
                .selectFrontIncomeBrandWise(loginDetails.getFofoId(), brand, monthStart, monthEnd);
-
 
1185
        Map<Integer, LastMonthFrontEndBrandWiseIncome> modelWiseSalesMarginsMap = modelWiseSalesMargins.stream().collect(Collectors.toMap(x -> x.getCatalogItemId(), x -> x));
-
 
1186
 
1179
 
1187
 
1180
        List<LastMonthBrandWiseIncomeModel> modelWiseSchemeOutMargins = schemeInOutRepository
1188
        List<LastMonthBrandWiseIncomeModel> modelWiseSchemeOutMargins = schemeInOutRepository
1181
                .selectLastMonthBrandWiseIncome(loginDetails.getFofoId(), brand, monthStart, monthEnd);
1189
                .selectLastMonthBrandWiseIncome(loginDetails.getFofoId(), brand, monthStart, monthEnd);
1182
        Map<Integer, LastMonthBrandWiseIncomeModel> modelWiseSchemeOutMarginsMap = modelWiseSchemeOutMargins.stream()
1190
        Map<Integer, LastMonthBrandWiseIncomeModel> modelWiseSchemeOutMarginsMap = modelWiseSchemeOutMargins.stream()
1183
                .collect(Collectors.toMap(x -> x.getCatalogItemId(), x -> x));
1191
                .collect(Collectors.toMap(x -> x.getCatalogItemId(), x -> x));
Line 1185... Line 1193...
1185
        List<LastMonthBrandWiseIncomeModel> modelWiseSchemeInMargins = schemeInOutRepository
1193
        List<LastMonthBrandWiseIncomeModel> modelWiseSchemeInMargins = schemeInOutRepository
1186
                .selectLastMonthPurchaseBrandWiseIncome(loginDetails.getFofoId(), brand, monthStart, monthEnd);
1194
                .selectLastMonthPurchaseBrandWiseIncome(loginDetails.getFofoId(), brand, monthStart, monthEnd);
1187
        Map<Integer, LastMonthBrandWiseIncomeModel> modelWiseSchemeInMarginsMap = modelWiseSchemeInMargins.stream()
1195
        Map<Integer, LastMonthBrandWiseIncomeModel> modelWiseSchemeInMarginsMap = modelWiseSchemeInMargins.stream()
1188
                .collect(Collectors.toMap(x -> x.getCatalogItemId(), x -> x));
1196
                .collect(Collectors.toMap(x -> x.getCatalogItemId(), x -> x));
1189
 
1197
 
-
 
1198
        allCatalogIds.addAll(modelWiseSalesMargins.stream().map(x -> x.getCatalogItemId()).collect(Collectors.toSet()));
-
 
1199
        allCatalogIds.addAll(modelWiseSchemeInMargins.stream().map(x -> x.getCatalogItemId()).collect(Collectors.toSet()));
-
 
1200
        allCatalogIds.addAll(modelWiseSchemeOutMargins.stream().map(x -> x.getCatalogItemId()).collect(Collectors.toSet()));
-
 
1201
 
-
 
1202
        Map<Integer, String> modelNameMap = itemRepository.selectAllByCatalogIds(allCatalogIds).stream().collect(Collectors.toMap(x -> x.getCatalogItemId(), x -> x.getModel(), (u, v) -> u));
1190
        Map<Integer, Double> modelTotalIncomeMap = new HashMap<>();
1203
        Map<Integer, Double> modelIncomeMap = new HashMap<>();
-
 
1204
        Map<Integer, Integer> modelPurchaseQtyMap = new HashMap<>();
1191
        Map<Integer, String> modelNameMap = new HashMap<>();
1205
        Map<Integer, Integer> modelSaleQtyMap = new HashMap<>();
-
 
1206
        for (int catalogItemId : modelNameMap.keySet()) {
-
 
1207
            int saleQty = 0;
-
 
1208
            int purchaseQty = 0;
-
 
1209
            double income = 0;
1192
 
1210
 
1193
        offerPayoutImeiIncomeModels.stream().forEach(x -> {
1211
            if (modelWiseSchemeInMarginsMap.containsKey(catalogItemId)) {
-
 
1212
                income += modelWiseSchemeInMarginsMap.get(catalogItemId).getAmount() + modelWiseSchemeInMarginsMap.get(catalogItemId).getPendingSaleAmount();
-
 
1213
                purchaseQty += modelWiseSchemeInMarginsMap.get(catalogItemId).getQty();
-
 
1214
            }
1194
            if (!modelTotalIncomeMap.containsKey(x.getCatalogId())) {
1215
            if (modelWiseSchemeOutMarginsMap.containsKey(catalogItemId)) {
1195
                modelNameMap.put(x.getCatalogId(), (x.getModelNumber() + " " + x.getModelName()).trim());
1216
                income += modelWiseSchemeOutMarginsMap.get(catalogItemId).getAmount() + modelWiseSchemeOutMarginsMap.get(catalogItemId).getPendingSaleAmount();
-
 
1217
            }
-
 
1218
            if (additionalSalePayoutMap.containsKey(catalogItemId)) {
1196
                modelTotalIncomeMap.put(x.getCatalogId(), 0d);
1219
                income += additionalSalePayoutMap.get(catalogItemId);
-
 
1220
            }
-
 
1221
            if (additionalPurchasePayout.containsKey(catalogItemId)) {
-
 
1222
                income += additionalPurchasePayout.get(catalogItemId);
-
 
1223
            }
-
 
1224
            if (modelWiseSalesMarginsMap.containsKey(catalogItemId)) {
-
 
1225
                income += modelWiseSalesMarginsMap.get(catalogItemId).getAmount();
-
 
1226
                saleQty = (int) modelWiseSalesMarginsMap.get(catalogItemId).getQty();
1197
            }
1227
            }
-
 
1228
            if (additionalPurchaseQty.containsKey(catalogItemId)) {
1198
            modelTotalIncomeMap.put(x.getCatalogId(), modelTotalIncomeMap.get(x.getCatalogId()) + x.getPurchasePayout() + x.getSalePayout());
1229
                purchaseQty = Math.max(additionalPurchaseQty.get(catalogItemId), purchaseQty);
1199
 
1230
 
1200
        });
1231
            }
-
 
1232
            modelIncomeMap.put(catalogItemId, income);
-
 
1233
            modelSaleQtyMap.put(catalogItemId, saleQty);
-
 
1234
            modelPurchaseQtyMap.put(catalogItemId, purchaseQty);
1201
 
1235
 
1202
        modelWiseSchemeOutMargins.stream().forEach(x -> {
-
 
1203
            if (!modelNameMap.containsKey(x.getCatalogItemId())) {
-
 
1204
                modelTotalIncomeMap.put(x.getCatalogItemId(), 0d);
-
 
1205
                modelNameMap.put(x.getCatalogItemId(), (x.getModelNumber() + " " + x.getModelName()).trim());
-
 
1206
            }
-
 
1207
            modelTotalIncomeMap.put(x.getCatalogItemId(), modelTotalIncomeMap.get(x.getCatalogItemId()) + x.getAmount() + x.getPendingSaleAmount());
-
 
1208
 
-
 
1209
        });
-
 
1210
 
-
 
1211
        LastMonthBrandWiseIncomeModel totalModel = new LastMonthBrandWiseIncomeModel();
-
 
1212
        modelWiseSalesMargins.stream().forEach(x -> {
-
 
1213
            if (!modelWiseSchemeOutMarginsMap.containsKey(x.getCatalogItemId())) {
-
 
1214
                LastMonthBrandWiseIncomeModel lmbwIncomeModel = new LastMonthBrandWiseIncomeModel();
-
 
1215
                lmbwIncomeModel.setModelName(x.getModelName());
-
 
1216
                lmbwIncomeModel.setModelNumber(x.getModelNumber());
-
 
1217
                lmbwIncomeModel.setBrand(x.getBrand());
-
 
1218
                lmbwIncomeModel.setCatalogItemId(x.getCatalogItemId());
-
 
1219
                modelWiseSchemeOutMarginsMap.put(x.getCatalogItemId(), lmbwIncomeModel);
-
 
1220
                totalModel.setQty(totalModel.getQty() + x.getQty());
-
 
1221
            }
-
 
1222
            modelNameMap.put(x.getCatalogItemId(), (x.getModelNumber() + x.getModelName()).trim());
-
 
1223
            LOGGER.info("Modelname {}, Model {}", modelNameMap.get(x.getCatalogItemId()), x.getQty());
-
 
1224
            LastMonthBrandWiseIncomeModel lmbwIncomeModel = modelWiseSchemeOutMarginsMap.get(x.getCatalogItemId());
-
 
1225
 
-
 
1226
            lmbwIncomeModel.setAmount(lmbwIncomeModel.getAmount() + x.getAmount());
-
 
1227
            lmbwIncomeModel.setQty(x.getQty());
-
 
1228
            if (!modelTotalIncomeMap.containsKey(x.getCatalogItemId())) {
-
 
1229
                modelTotalIncomeMap.put(x.getCatalogItemId(), 0d);
-
 
1230
            }
-
 
1231
            modelTotalIncomeMap.put(x.getCatalogItemId(), x.getAmount() + modelTotalIncomeMap.get(x.getCatalogItemId()));
-
 
1232
            totalModel.setAmount(totalModel.getAmount() + x.getAmount());
-
 
1233
            totalModel.setPendingSaleAmount(totalModel.getPendingSaleAmount());
-
 
1234
 
-
 
1235
        });
-
 
1236
        modelWiseSchemeInMargins.stream().forEach(x -> {
-
 
1237
            if (!modelTotalIncomeMap.containsKey(x.getCatalogItemId())) {
-
 
1238
                modelTotalIncomeMap.put(x.getCatalogItemId(), 0d);
-
 
1239
            }
-
 
1240
            modelTotalIncomeMap.put(x.getCatalogItemId(),
-
 
1241
                    modelTotalIncomeMap.get(x.getCatalogItemId()) + x.getAmount());
-
 
1242
            modelNameMap.put(x.getCatalogItemId(), (x.getModelNumber() + x.getModelName()).trim());
-
 
1243
            totalModel.setQty(totalModel.getQty() + x.getQty());
-
 
1244
            totalModel.setAmount(totalModel.getAmount() + x.getAmount());
-
 
1245
 
-
 
1246
        });
1236
        }
1247
 
1237
 
1248
        model.addAttribute("month", month);
1238
        model.addAttribute("month", month);
-
 
1239
        model.addAttribute("modelWiseSalesMarginsMap", modelWiseSalesMarginsMap);
1249
        model.addAttribute("modelWiseSchemeOutMarginsMap", modelWiseSchemeOutMarginsMap);
1240
        model.addAttribute("modelWiseSchemeOutMarginsMap", modelWiseSchemeOutMarginsMap);
1250
        model.addAttribute("modelWiseSchemeInMarginsMap", modelWiseSchemeInMarginsMap);
1241
        model.addAttribute("modelWiseSchemeInMarginsMap", modelWiseSchemeInMarginsMap);
1251
        model.addAttribute("modelNameMap", modelNameMap);
1242
        model.addAttribute("modelNameMap", modelNameMap);
-
 
1243
        model.addAttribute("modelPurchaseQtyMap", modelPurchaseQtyMap);
-
 
1244
        model.addAttribute("modelSaleQtyMap", modelSaleQtyMap);
1252
        model.addAttribute("modelTotalIncomeMap", modelTotalIncomeMap);
1245
        model.addAttribute("modelIncomeMap", modelIncomeMap);
1253
        model.addAttribute("categoryUpgradeBrandModelMap", categoryUpgradeBrandModelMap);
1246
        model.addAttribute("categoryUpgradeBrandModelMap", categoryUpgradeBrandModelMap);
1254
        model.addAttribute("additionalPurchasePayoutMap", additionalPurchasePayout);
1247
        model.addAttribute("additionalPurchasePayoutMap", additionalPurchasePayout);
1255
        model.addAttribute("additionalSalePayoutMap", additionalSalePayout);
1248
        model.addAttribute("additionalSalePayoutMap", additionalSalePayoutMap);
1256
        model.addAttribute("totalModel", totalModel);
-
 
1257
 
1249
 
1258
        return "monthly-brand-wise-income";
1250
        return "monthly-brand-wise-income";
1259
 
1251
 
1260
    }
1252
    }
1261
 
1253
 
Line 1280... Line 1272...
1280
                    .selectLastMonthCategoryUpgradeMarginByBrand(loginDetails.getFofoId(), startOfMonth,
1272
                    .selectLastMonthCategoryUpgradeMarginByBrand(loginDetails.getFofoId(), startOfMonth,
1281
                            lastMonthEnd)
1273
                            lastMonthEnd)
1282
                    .stream().collect(Collectors.toMap(x -> x.getBrand(), x -> x.getAmount()));
1274
                    .stream().collect(Collectors.toMap(x -> x.getBrand(), x -> x.getAmount()));
1283
        }
1275
        }
1284
 
1276
 
1285
        String status = "CREDITED";
-
 
1286
 
-
 
1287
        List<LastMonthCreditedIncomeModel> lastMonthPendingIncomeModels = schemeInOutRepository
1277
        List<LastMonthCreditedIncomeModel> lastMonthPendingIncomeModels = schemeInOutRepository
1288
                .selectLastMonthPendingIncomeByFofoId(loginDetails.getFofoId(), startOfMonth, lastMonthEnd);
1278
                .selectLastMonthPendingIncomeByFofoId(loginDetails.getFofoId(), startOfMonth, lastMonthEnd);
1289
 
1279
 
1290
        List<LastMonthCreditedIncomeModel> lastMonthCreditedIncomeModels = schemeInOutRepository
1280
        List<LastMonthCreditedIncomeModel> lastMonthCreditedIncomeModels = schemeInOutRepository
1291
                .selectLastMonthCreditedIncomeByFofoId(loginDetails.getFofoId(), startOfMonth, lastMonthEnd);
1281
                .selectLastMonthCreditedIncomeByFofoId(loginDetails.getFofoId(), startOfMonth, lastMonthEnd);
Line 1293... Line 1283...
1293
        List<LastMonthCreditedIncomeModel> lastMonthPurchaseInMargins = schemeInOutRepository
1283
        List<LastMonthCreditedIncomeModel> lastMonthPurchaseInMargins = schemeInOutRepository
1294
                .selectLastMonthPurchaseInMarginByFofoId(loginDetails.getFofoId(), startOfMonth, lastMonthEnd);
1284
                .selectLastMonthPurchaseInMarginByFofoId(loginDetails.getFofoId(), startOfMonth, lastMonthEnd);
1295
 
1285
 
1296
        List<LastMonthCreditedIncomeModel> lastMonthFrontEndIncomes = schemeInOutRepository
1286
        List<LastMonthCreditedIncomeModel> lastMonthFrontEndIncomes = schemeInOutRepository
1297
                .selectFrontIncomeByBrand(loginDetails.getFofoId(), startOfMonth, lastMonthEnd);
1287
                .selectFrontIncomeByBrand(loginDetails.getFofoId(), startOfMonth, lastMonthEnd);
-
 
1288
        Map<String, LastMonthCreditedIncomeModel> lastMonthFrontEndIncomeMap = lastMonthFrontEndIncomes.stream().collect(Collectors.toMap(x -> x.getBrand(), x -> x));
1298
 
1289
 
1299
        List<OfferPayoutImeiIncomeModel> offerPayoutImeiIncomeModels = offerPayoutRepository.getTotalPayoutsByPartnerPeriod(
1290
        List<OfferPayoutImeiIncomeModel> offerPayoutImeiIncomeModels = offerPayoutRepository.getTotalPayoutsByPartnerPeriod(
1300
                YearMonth.of(startOfMonth.getYear(), startOfMonth.getMonth()), loginDetails.getFofoId(), null, null);
1291
                YearMonth.of(startOfMonth.getYear(), startOfMonth.getMonth()), loginDetails.getFofoId(), null, null);
1301
 
1292
 
1302
        Map<String, Double> additionalPurchasePayout = offerPayoutImeiIncomeModels.stream().collect(Collectors.groupingBy(OfferPayoutImeiIncomeModel::getBrand, Collectors.summingDouble(OfferPayoutImeiIncomeModel::getPurchasePayout)));
1293
        Map<String, Double> additionalPurchasePayout = offerPayoutImeiIncomeModels.stream().collect(Collectors.groupingBy(OfferPayoutImeiIncomeModel::getBrand, Collectors.summingDouble(OfferPayoutImeiIncomeModel::getPurchasePayout)));
Line 1311... Line 1302...
1311
 
1302
 
1312
 
1303
 
1313
        Map<String, LastMonthCreditedIncomeModel> lastMonthPendingIncomeMap = lastMonthPendingIncomeModels.stream()
1304
        Map<String, LastMonthCreditedIncomeModel> lastMonthPendingIncomeMap = lastMonthPendingIncomeModels.stream()
1314
                .collect(Collectors.toMap(x -> x.getBrand(), x -> x));
1305
                .collect(Collectors.toMap(x -> x.getBrand(), x -> x));
1315
 
1306
 
1316
        lastMonthFrontEndIncomes.stream().forEach(x -> {
-
 
1317
            if (lastMonthSaleMarginMap.containsKey(x.getBrand())) {
-
 
1318
                x.setAmount(lastMonthSaleMarginMap.get(x.getBrand()).getAmount() + x.getAmount());
-
 
1319
 
-
 
1320
                lastMonthSaleMarginMap.put(x.getBrand(), x);
-
 
1321
            } else {
-
 
1322
                lastMonthSaleMarginMap.put(x.getBrand(), x);
-
 
1323
            }
-
 
1324
 
-
 
1325
        });
-
 
1326
        Map<String, Float> totalAmountMap = lastMonthSaleMarginMap.entrySet().stream()
1307
        Map<String, Float> totalAmountMap = lastMonthSaleMarginMap.entrySet().stream()
1327
                .collect(Collectors.toMap(x -> x.getKey(), x -> x.getValue().getAmount()));
1308
                .collect(Collectors.toMap(x -> x.getKey(), x -> x.getValue().getAmount()));
1328
        Set<String> brandSet = new HashSet<>();
1309
        Set<String> brandSet = new HashSet<>();
1329
        brandSet.addAll(lastMonthPurchaseInMarginMap.keySet());
1310
        brandSet.addAll(lastMonthPurchaseInMarginMap.keySet());
1330
        brandSet.addAll(lastMonthSaleMarginMap.keySet());
1311
        brandSet.addAll(lastMonthSaleMarginMap.keySet());
Line 1335... Line 1316...
1335
            totalAmountMap.put(brand,
1316
            totalAmountMap.put(brand,
1336
                    (lastMonthSaleMarginMap.get(brand) == null ? 0 : lastMonthSaleMarginMap.get(brand).getAmount()) +
1317
                    (lastMonthSaleMarginMap.get(brand) == null ? 0 : lastMonthSaleMarginMap.get(brand).getAmount()) +
1337
                            (lastMonthPurchaseInMarginMap.get(brand) == null ? 0 : lastMonthPurchaseInMarginMap.get(brand).getAmount()) +
1318
                            (lastMonthPurchaseInMarginMap.get(brand) == null ? 0 : lastMonthPurchaseInMarginMap.get(brand).getAmount()) +
1338
                            (lastMonthPendingIncomeMap.get(brand) == null ? 0 : lastMonthPendingIncomeMap.get(brand).getAmount()) +
1319
                            (lastMonthPendingIncomeMap.get(brand) == null ? 0 : lastMonthPendingIncomeMap.get(brand).getAmount()) +
1339
                            (additionalPurchasePayout.get(brand) == null ? 0 : additionalPurchasePayout.get(brand).longValue()) +
1320
                            (additionalPurchasePayout.get(brand) == null ? 0 : additionalPurchasePayout.get(brand).longValue()) +
1340
                            (additionSalePayout.get(brand) == null ? 0 : additionSalePayout.get(brand).longValue())
1321
                            (additionSalePayout.get(brand) == null ? 0 : additionSalePayout.get(brand).longValue()) +
-
 
1322
                            (lastMonthFrontEndIncomeMap.get(brand) == null ? 0 : lastMonthFrontEndIncomeMap.get(brand).getAmount())
1341
            );
1323
            );
1342
        });
1324
        });
1343
 
1325
 
1344
        Map<Integer, String> monthValueMap = new HashMap<>();
1326
        Map<Integer, String> monthValueMap = new HashMap<>();
1345
        for (int i = 0; i <= 5; i++) {
1327
        for (int i = 0; i <= 5; i++) {
1346
            LocalDateTime monthStart = LocalDateTime.now().withDayOfMonth(1).minusMonths(i);
1328
            LocalDateTime monthStart = LocalDateTime.now().withDayOfMonth(1).minusMonths(i);
1347
            monthValueMap.put(i, monthStart.format(DateTimeFormatter.ofPattern("MMM''uu")));
1329
            monthValueMap.put(i, monthStart.format(DateTimeFormatter.ofPattern("MMM''uu")));
1348
        }
1330
        }
1349
        model.addAttribute("monthValueMap", monthValueMap);
1331
        model.addAttribute("monthValueMap", monthValueMap);
1350
 
1332
 
1351
        model.addAttribute("keySet", brandSet);
1333
        model.addAttribute("brandSet", brandSet);
1352
        model.addAttribute("lastMonthPurchaseInMarginMap", lastMonthPurchaseInMarginMap);
1334
        model.addAttribute("lastMonthPurchaseInMarginMap", lastMonthPurchaseInMarginMap);
1353
        model.addAttribute("lastMonthSaleMarginMap", lastMonthSaleMarginMap);
1335
        model.addAttribute("lastMonthSaleMarginMap", lastMonthSaleMarginMap);
1354
        model.addAttribute("lastMonthPendingIncomeMap", lastMonthPendingIncomeMap);
1336
        model.addAttribute("lastMonthPendingIncomeMap", lastMonthPendingIncomeMap);
1355
        model.addAttribute("additionalPurchasePayoutMap", additionalPurchasePayout);
1337
        model.addAttribute("additionalPurchasePayoutMap", additionalPurchasePayout);
1356
        model.addAttribute("additionalSalePayoutMap", additionSalePayout);
1338
        model.addAttribute("additionalSalePayoutMap", additionSalePayout);
-
 
1339
        model.addAttribute("lastMonthFrontEndIncomeMap", lastMonthFrontEndIncomeMap);
1357
 
1340
 
1358
        model.addAttribute("totalAmountMap", totalAmountMap);
1341
        model.addAttribute("totalAmountMap", totalAmountMap);
1359
        model.addAttribute("status", status);
-
 
1360
        model.addAttribute("month", yearMonth);
1342
        model.addAttribute("month", yearMonth);
1361
        model.addAttribute("lastMonthCategoryUpgradeMarginMap", lastMonthCategoryUpgradeMarginMap);
1343
        model.addAttribute("lastMonthCategoryUpgradeMarginMap", lastMonthCategoryUpgradeMarginMap);
1362
        LOGGER.info("totalAmountMap {}", totalAmountMap);
1344
        LOGGER.info("totalAmountMap {}", totalAmountMap);
1363
        LOGGER.info("lastMonthSaleMarginMap {}", lastMonthSaleMarginMap);
1345
        LOGGER.info("lastMonthSaleMarginMap {}", lastMonthSaleMarginMap);
1364
 
1346