Subversion Repositories SmartDukaan

Rev

Rev 33245 | Rev 34426 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
28468 tejbeer 1
package com.spice.profitmandi.service;
2
 
3
import com.google.gson.Gson;
4
import com.spice.profitmandi.common.enumuration.MessageType;
5
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
30250 amit.gupta 6
import com.spice.profitmandi.common.model.*;
28468 tejbeer 7
import com.spice.profitmandi.dao.Interface.Campaign;
33087 amit.gupta 8
import com.spice.profitmandi.dao.entity.catalog.BrandCatalog;
28468 tejbeer 9
import com.spice.profitmandi.dao.entity.dtr.Document;
10
import com.spice.profitmandi.dao.entity.dtr.NotificationCampaign;
11
import com.spice.profitmandi.dao.entity.fofo.PartnerDailyInvestment;
12
import com.spice.profitmandi.dao.entity.fofo.PartnerTargetDetails;
13
import com.spice.profitmandi.dao.entity.fofo.PartnerType;
14
import com.spice.profitmandi.dao.model.BrandWiseModel;
15
import com.spice.profitmandi.dao.model.SimpleCampaign;
16
import com.spice.profitmandi.dao.model.SimpleCampaignParams;
17
import com.spice.profitmandi.dao.repository.dtr.DocumentRepository;
18
import com.spice.profitmandi.dao.repository.dtr.Mongo;
30250 amit.gupta 19
import com.spice.profitmandi.dao.repository.fofo.*;
28468 tejbeer 20
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
33087 amit.gupta 21
import com.spice.profitmandi.service.catalog.BrandsService;
28468 tejbeer 22
import com.spice.profitmandi.service.inventory.InventoryService;
30250 amit.gupta 23
import org.apache.logging.log4j.LogManager;
24
import org.apache.logging.log4j.Logger;
25
import org.springframework.beans.factory.annotation.Autowired;
26
import org.springframework.stereotype.Component;
28468 tejbeer 27
 
30250 amit.gupta 28
import java.time.*;
29
import java.time.format.DateTimeFormatter;
30
import java.util.*;
31
import java.util.Map.Entry;
32
import java.util.stream.Collectors;
33
 
28468 tejbeer 34
@Component
35
public class FofoUser {
36
 
31884 tejbeer 37
    @Autowired
38
    private Gson gson;
28468 tejbeer 39
 
31884 tejbeer 40
    @Autowired
41
    private PartnerInvestmentService partnerInvestmentService;
28468 tejbeer 42
 
31884 tejbeer 43
    @Autowired
44
    private PartnerDailyInvestmentRepository partnerDailyInvestmentRepository;
28468 tejbeer 45
 
31884 tejbeer 46
    @Autowired
47
    ChartService chartService;
28468 tejbeer 48
 
31884 tejbeer 49
    @Autowired
50
    FofoOrderItemRepository fofoOrderItemRepository;
28468 tejbeer 51
 
31884 tejbeer 52
    @Autowired
53
    FofoOrderRepository fofoOrderRepository;
28468 tejbeer 54
 
31884 tejbeer 55
    @Autowired
56
    PartnerTypeChangeService partnerTypeChangeService;
28468 tejbeer 57
 
31884 tejbeer 58
    @Autowired
59
    PartnerTargetRepository partnerTargetRepository;
28468 tejbeer 60
 
31884 tejbeer 61
    @Autowired
62
    InventoryService inventoryService;
28468 tejbeer 63
 
31884 tejbeer 64
    @Autowired
65
    private Mongo mongoClient;
28468 tejbeer 66
 
31884 tejbeer 67
    @Autowired
68
    private OrderRepository orderRepository;
28468 tejbeer 69
 
31884 tejbeer 70
    @Autowired
71
    DocumentRepository documentRepository;
28468 tejbeer 72
 
31884 tejbeer 73
    @Autowired
33087 amit.gupta 74
    BrandsService brandsService;
75
 
76
    @Autowired
31884 tejbeer 77
    CurrentInventorySnapshotRepository currentInventorySnapshotRepository;
28468 tejbeer 78
 
31884 tejbeer 79
    private static final Logger LOGGER = LogManager.getLogger(FofoUser.class);
28468 tejbeer 80
 
31884 tejbeer 81
    List<String> colorList = Arrays.asList("papayawhip", "mediumseagreen", "dodgerblue", "darkblue", "gold", "#eb0029", "coral", "steelblue", "red", "deeppink", "midnightblue", "cornsilk");
28468 tejbeer 82
 
31884 tejbeer 83
    List<String> borderList = Arrays.asList("pink", "lawngreen", "lightblue", "#0000cd", "#f7e98e", "#eb0029", "lightcoral", "#0000cd", "lightsalmon", "pink", "#0000cd", "cornsilk");
28468 tejbeer 84
 
31884 tejbeer 85
    List<String> brands = Arrays.asList("Accessories", "Oppo", "Vivo", "Samsung", "Realme", "Xiaomi", "OnePlus", "Tecno", "Itel", "Lava", "Nokia");
28468 tejbeer 86
 
31884 tejbeer 87
    public String format(long value) {
88
        String finalval = null;
28468 tejbeer 89
 
31884 tejbeer 90
        if (value >= 100000 && value < 10000000) {
91
            long reminder = value / 100000;
92
            long quitonent = value % 100000;
93
            String secondval = String.format("%05d", quitonent);
94
            secondval = secondval.substring(0, 2);
95
            finalval = reminder + "." + secondval;
96
            return String.valueOf(finalval) + " Lacs";
97
        } else if (value >= 1000 && value < 100000) {
98
            long reminder = value / 1000;
99
            long quitonent = value % 1000;
100
            String secondval = String.format("%03d", quitonent);
101
            secondval = secondval.substring(0, 2);
102
            finalval = reminder + "." + secondval;
103
            return String.valueOf(finalval) + " K";
104
        } else if (value >= 10000000 && value < 1000000000) {
105
            long reminder = value / 10000000;
106
            long quitonent = value % 10000000;
107
            finalval = reminder + "." + quitonent;
108
            String secondval = String.format("%07d", quitonent);
109
            secondval = secondval.substring(0, 2);
110
            finalval = reminder + "." + secondval;
111
            return String.valueOf(finalval) + " Cr";
112
        }
113
        return String.valueOf(finalval);
28468 tejbeer 114
 
31884 tejbeer 115
    }
28468 tejbeer 116
 
31884 tejbeer 117
    public List<BrandStockPrice> getBrandStockPrices(int fofoId, boolean allBrands) throws Exception {
118
        Map<String, BrandStockPrice> brandStockPricesMap = inventoryService.getBrandWiseStockValue(fofoId);
119
        List<BrandStockPrice> brandStockPrices = new ArrayList<>();
33127 amit.gupta 120
        List<BrandCatalog> mobileBrands = brandsService.getBrandsToDisplay(3);
31884 tejbeer 121
        mobileBrands.stream().forEach(x -> {
33087 amit.gupta 122
            if (brandStockPricesMap.containsKey(x.getName())) {
123
                BrandStockPrice brandStockPrice = brandStockPricesMap.get(x.getName());
33119 amit.gupta 124
                brandStockPrice.setBrandUrl(x.getLogoUrl());
33087 amit.gupta 125
                brandStockPrice.setRank(x.getBrandCategory().getRank());
31884 tejbeer 126
                brandStockPrices.add(brandStockPrice);
127
            }
128
        });
28468 tejbeer 129
 
31884 tejbeer 130
        if (allBrands) {
131
            return brandStockPrices.stream().sorted(Comparator.comparingInt(BrandStockPrice::getRank)).collect(Collectors.toList());
28468 tejbeer 132
 
31884 tejbeer 133
        }
28468 tejbeer 134
 
31884 tejbeer 135
        return brandStockPrices.stream().filter(x -> x.getTotalQty() > 0).sorted(Comparator.comparingInt(BrandStockPrice::getRank)).collect(Collectors.toList());
136
    }
28468 tejbeer 137
 
31884 tejbeer 138
    public Map<String, Object> getInvestments(int fofoId) throws Exception {
139
        Map<String, Object> investments = new LinkedHashMap<>();
140
        PartnerDailyInvestment investment = partnerInvestmentService.getInvestment(fofoId, 0);
141
        LocalDate currentMonthStart = LocalDate.now().withDayOfMonth(1);
142
        LocalDate yesterDate = LocalDate.now().minusDays(1);
143
        PartnerDailyInvestment yesterdayInvestment = partnerDailyInvestmentRepository.select(fofoId, yesterDate);
144
        if (yesterdayInvestment == null) {
145
            yesterdayInvestment = new PartnerDailyInvestment();
146
        }
28468 tejbeer 147
 
31884 tejbeer 148
        List<PartnerDailyInvestment> currentMonthInvestments = partnerDailyInvestmentRepository.selectAll(fofoId, currentMonthStart, currentMonthStart.withDayOfMonth(currentMonthStart.lengthOfMonth()));
28468 tejbeer 149
 
31884 tejbeer 150
        long okInvestmentDays = currentMonthInvestments.stream().filter(x -> x.getShortPercentage() <= 10).collect(Collectors.counting());
151
        investments.put("today", investment.getTotalInvestment());
152
        investments.put("investment", investment);
153
        investments.put("inStock", investment.getInStockAmount());
154
        investments.put("minimum", investment.getMinInvestmentString());
155
        investments.put("short", investment.getShortPercentage());
156
        investments.put("activated_stock", investment.getActivatedStockAmount());
157
        investments.put("okDays", okInvestmentDays);
158
        return investments;
159
    }
28468 tejbeer 160
 
31884 tejbeer 161
    public Map<String, Object> getInvestmentsMonths(int fofoId, int month) throws Exception {
162
        Map<String, Object> investments = new LinkedHashMap<>();
163
        PartnerDailyInvestment investment = partnerInvestmentService.getInvestment(fofoId, 0);
164
        LocalDate currentMonthStart = LocalDate.now().withDayOfMonth(1).minusMonths(month);
28468 tejbeer 165
 
31884 tejbeer 166
        LocalDate yesterDate = LocalDate.now().minusDays(1);
167
        PartnerDailyInvestment yesterdayInvestment = partnerDailyInvestmentRepository.select(fofoId, yesterDate);
168
        if (yesterdayInvestment == null) {
169
            yesterdayInvestment = new PartnerDailyInvestment();
170
        }
28468 tejbeer 171
 
31884 tejbeer 172
        List<PartnerDailyInvestment> currentMonthInvestments = partnerDailyInvestmentRepository.selectAll(fofoId, currentMonthStart, currentMonthStart.withDayOfMonth(currentMonthStart.lengthOfMonth()));
28468 tejbeer 173
 
31884 tejbeer 174
        long okInvestmentDays = currentMonthInvestments.stream().filter(x -> x.getShortPercentage() <= 10).collect(Collectors.counting());
175
        investments.put("today", investment.getTotalInvestment());
176
        investments.put("investment", investment);
177
        investments.put("inStock", investment.getInStockAmount());
178
        investments.put("minimum", investment.getMinInvestmentString());
179
        investments.put("short", investment.getShortPercentage());
180
        investments.put("activated_stock", investment.getActivatedStockAmount());
181
        investments.put("okDays", okInvestmentDays);
182
        return investments;
183
    }
28468 tejbeer 184
 
31884 tejbeer 185
    public ChartModel getLmsLineChart(int fofoId) throws ProfitMandiBusinessException {
28468 tejbeer 186
 
31884 tejbeer 187
        LocalDateTime curDate = LocalDate.now().atStartOfDay();
188
        Map<String, Map<YearMonth, Double>> brandMonthValue = new HashMap<>();
189
        Map<YearMonth, Map<String, Double>> monthValueMap = new HashMap<>();
28468 tejbeer 190
 
31884 tejbeer 191
        Map<String, Double> lmsBrandWiseSale = null;
28468 tejbeer 192
 
31884 tejbeer 193
        for (int i = 0; i <= 6; i++) {
28530 tejbeer 194
 
31884 tejbeer 195
            LocalDateTime startOfMonth = curDate.withDayOfMonth(1).minusMonths(i);
28468 tejbeer 196
 
31884 tejbeer 197
            LOGGER.info("startOfMonth" + startOfMonth);
28468 tejbeer 198
 
31884 tejbeer 199
            lmsBrandWiseSale = fofoOrderItemRepository.selectSumAmountGroupByBrand(
200
                    curDate.withDayOfMonth(1).minusMonths(i), curDate.withDayOfMonth(1).minusMonths(i - 1), fofoId);
28468 tejbeer 201
 
31884 tejbeer 202
            Map<Integer, Double> accesorieslmsSale = fofoOrderRepository.selectSumSaleGroupByFofoIdsForMobileOrAccessories(fofoId, curDate.withDayOfMonth(1).minusMonths(i), curDate.withDayOfMonth(1).minusMonths(i - 1), Optional.of(false));
203
            LOGGER.info("lmsBrandWiseSale" + lmsBrandWiseSale);
28468 tejbeer 204
 
31884 tejbeer 205
            lmsBrandWiseSale.put("Accessories", accesorieslmsSale.get(fofoId));
28468 tejbeer 206
 
31884 tejbeer 207
            monthValueMap.put(YearMonth.from(startOfMonth), lmsBrandWiseSale);
208
            for (Entry<String, Double> lbw : lmsBrandWiseSale.entrySet()) {
209
                Map<YearMonth, Double> yearMonthValue = new HashMap<>();
210
                if (brandMonthValue.containsKey(lbw.getKey())) {
211
                    yearMonthValue = brandMonthValue.get(lbw.getKey());
212
                    yearMonthValue.put(YearMonth.from(startOfMonth), lbw.getValue());
213
                } else {
28468 tejbeer 214
 
31884 tejbeer 215
                    yearMonthValue.put(YearMonth.from(startOfMonth), lbw.getValue());
28468 tejbeer 216
 
31884 tejbeer 217
                }
218
                brandMonthValue.put(lbw.getKey(), yearMonthValue);
28468 tejbeer 219
 
31884 tejbeer 220
            }
28530 tejbeer 221
 
31884 tejbeer 222
        }
28468 tejbeer 223
 
31884 tejbeer 224
        LOGGER.info("brandMonthValue" + brandMonthValue);
28468 tejbeer 225
 
31884 tejbeer 226
        Map<String, List<Double>> sortedBrandValue = new LinkedHashMap<>();
28468 tejbeer 227
 
31884 tejbeer 228
        for (String brand : brands) {
229
            Map<YearMonth, Double> yearMonthValue = brandMonthValue.get(brand);
230
            for (int i = 6; i >= 0; i--) {
28468 tejbeer 231
 
31884 tejbeer 232
                LocalDateTime startMonth = curDate.withDayOfMonth(1).minusMonths(i);
233
                LOGGER.info("startMonth" + startMonth);
28468 tejbeer 234
 
31884 tejbeer 235
                if (yearMonthValue != null) {
236
                    if (yearMonthValue.get(YearMonth.from(startMonth)) == null) {
237
                        yearMonthValue.put(YearMonth.from(startMonth), 0.0);
238
                    }
28468 tejbeer 239
 
31884 tejbeer 240
                } else {
241
                    yearMonthValue = new HashMap<>();
242
                    yearMonthValue.put(YearMonth.from(startMonth), 0.0);
243
                }
244
            }
28468 tejbeer 245
 
31884 tejbeer 246
            Map<YearMonth, Double> sortedMonthBrandValue = new TreeMap<>(yearMonthValue);
28468 tejbeer 247
 
31884 tejbeer 248
            brandMonthValue.put(brand, sortedMonthBrandValue);
28468 tejbeer 249
 
31884 tejbeer 250
            sortedBrandValue.put(brand, sortedMonthBrandValue.values().stream().collect(Collectors.toList()));
28530 tejbeer 251
 
31884 tejbeer 252
        }
28468 tejbeer 253
 
31884 tejbeer 254
        LOGGER.info("brandMonthValue" + brandMonthValue);
28468 tejbeer 255
 
31884 tejbeer 256
        LOGGER.info("sortedBrandValue" + sortedBrandValue);
28468 tejbeer 257
 
31884 tejbeer 258
        ChartModel cm = chartService.createChart(6, sortedBrandValue, colorList, borderList, "Brand Wise LMS");
28468 tejbeer 259
 
31884 tejbeer 260
        return cm;
28468 tejbeer 261
 
31884 tejbeer 262
    }
28530 tejbeer 263
 
31884 tejbeer 264
    public ChartModel getPurchaseOrderChart(int fofoId) throws ProfitMandiBusinessException {
28530 tejbeer 265
 
31884 tejbeer 266
        LocalDateTime curDate = LocalDate.now().atStartOfDay();
28468 tejbeer 267
 
31884 tejbeer 268
        LOGGER.info("startMonth" + curDate.withDayOfMonth(1).minusMonths(6));
28468 tejbeer 269
 
31884 tejbeer 270
        LocalDateTime startOfMonth = curDate.withDayOfMonth(1).minusMonths(1);
271
        List<BrandWiseModel> soblms = orderRepository.selectAllBilledOrderGroupByBrandFofoId(fofoId, curDate.withDayOfMonth(1).minusMonths(6));
272
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("MM-yyyy");
273
        Map<String, Map<YearMonth, Double>> brandMonthValue = new HashMap<>();
274
        for (BrandWiseModel bwl : soblms) {
275
            Map<YearMonth, Double> yearMonthValue = new HashMap<>();
276
            if (brandMonthValue.containsKey(bwl.getBrand())) {
277
                yearMonthValue = brandMonthValue.get(bwl.getBrand());
278
                yearMonthValue.put(YearMonth.parse(bwl.getYearMonth(), dateTimeFormatter), (double) bwl.getAmount());
279
            } else {
28468 tejbeer 280
 
31884 tejbeer 281
                yearMonthValue.put(YearMonth.parse(bwl.getYearMonth(), dateTimeFormatter), (double) bwl.getAmount());
28468 tejbeer 282
 
31884 tejbeer 283
            }
284
            brandMonthValue.put(bwl.getBrand(), yearMonthValue);
28468 tejbeer 285
 
31884 tejbeer 286
        }
287
        LOGGER.info("soblms" + brandMonthValue);
28468 tejbeer 288
 
31884 tejbeer 289
        Map<String, List<Double>> sortedBrandValue = new LinkedHashMap<>();
28468 tejbeer 290
 
31884 tejbeer 291
        for (String brand : brands) {
292
            Map<YearMonth, Double> yearMonthValue = brandMonthValue.get(brand);
293
            for (int i = 6; i >= 0; i--) {
28468 tejbeer 294
 
31884 tejbeer 295
                LocalDateTime startMonth = curDate.withDayOfMonth(1).minusMonths(i);
28468 tejbeer 296
 
31884 tejbeer 297
                if (yearMonthValue != null) {
298
                    if (yearMonthValue.get(YearMonth.from(startMonth)) == null) {
299
                        yearMonthValue.put(YearMonth.from(startMonth), 0.0);
300
                    }
28468 tejbeer 301
 
31884 tejbeer 302
                } else {
303
                    yearMonthValue = new HashMap<>();
304
                    yearMonthValue.put(YearMonth.from(startMonth), 0.0);
305
                }
306
            }
28468 tejbeer 307
 
31884 tejbeer 308
            Map<YearMonth, Double> sortedMonthBrandValue = new TreeMap<>(yearMonthValue);
28468 tejbeer 309
 
31884 tejbeer 310
            brandMonthValue.put(brand, sortedMonthBrandValue);
28530 tejbeer 311
 
31884 tejbeer 312
            sortedBrandValue.put(brand, sortedMonthBrandValue.values().stream().collect(Collectors.toList()));
28530 tejbeer 313
 
31884 tejbeer 314
        }
28468 tejbeer 315
 
31884 tejbeer 316
        LOGGER.info("brandMonthValue" + brandMonthValue);
28468 tejbeer 317
 
31884 tejbeer 318
        ChartModel cm = chartService.createChart(6, sortedBrandValue, colorList, borderList, "Brand Wise Monthly Purchase");
28468 tejbeer 319
 
31884 tejbeer 320
        return cm;
28468 tejbeer 321
 
31884 tejbeer 322
    }
28468 tejbeer 323
 
33245 ranu 324
    public Map<String, Object> getSales(int fofoId) throws ProfitMandiBusinessException {
28468 tejbeer 325
 
31884 tejbeer 326
        Map<String, Object> salesMap = new LinkedHashMap<>();
327
        LocalDateTime now = LocalDateTime.now();
328
        LocalDateTime startOfToday = LocalDate.now().atStartOfDay();
329
        int monthLength = LocalDate.now().lengthOfMonth();
330
        int daysGone = now.getDayOfMonth() - 1;
331
        int daysRemaining = monthLength - daysGone;
332
        Double todaySale = fofoOrderItemRepository.selectSumMopGroupByRetailer(startOfToday, now, fofoId, false).get(fofoId);
333
        Double mtdSaleTillYesterDay = fofoOrderItemRepository.selectSumMopGroupByRetailer(startOfToday.withDayOfMonth(1), startOfToday, fofoId, false).get(fofoId);
334
        Double mtdSale = mtdSaleTillYesterDay + todaySale;
335
        Double lmtdSale = fofoOrderItemRepository.selectSumMopGroupByRetailer(
336
                startOfToday.withDayOfMonth(1).minusMonths(1), now.minusMonths(1), fofoId, false).get(fofoId);
28468 tejbeer 337
 
31884 tejbeer 338
        List<PartnerTargetDetails> partnerTargetDetails = partnerTargetRepository.selectAllGeEqAndLeEqStartDateAndEndDate(LocalDateTime.now());
339
        if (partnerTargetDetails.isEmpty()) {
340
            partnerTargetDetails = partnerTargetRepository.selectAllGeEqAndLeEqStartDateAndEndDate(LocalDateTime.now().minusMonths(3));
341
        }
28468 tejbeer 342
 
31884 tejbeer 343
        PartnerType partnerType = partnerTypeChangeService.getTypeOnDate(fofoId, LocalDate.now());
28468 tejbeer 344
 
31884 tejbeer 345
        int currentRate = 0;
346
        if (mtdSaleTillYesterDay > 0) {
347
            currentRate = (int) (mtdSaleTillYesterDay / daysGone);
348
        }
28468 tejbeer 349
 
31884 tejbeer 350
        salesMap.put("requiredType", partnerType.next());
351
        float reqdAmount = partnerTypeChangeService.getMinimumAmount(partnerType.next());
352
        int requiredRate = (int) ((reqdAmount - mtdSaleTillYesterDay) / daysRemaining);
353
        if (partnerType.equals(PartnerType.PLATINUM) && requiredRate < currentRate) {
354
            requiredRate = currentRate;
355
        }
356
        salesMap.put("requiredRate", requiredRate);
357
        salesMap.put("requiredTypeImage", PartnerType.imageMap.get(partnerType.next()));
28468 tejbeer 358
 
31884 tejbeer 359
        salesMap.put("todaySale", todaySale == null ? 0 : todaySale);
360
        salesMap.put("mtdSale", mtdSale == null ? 0 : mtdSale);
361
        salesMap.put("lmtdSale", lmtdSale == null ? 0 : lmtdSale);
28468 tejbeer 362
 
31884 tejbeer 363
        PartnerType currentType = partnerTypeChangeService.getPartnerTypeByAmount(currentRate * monthLength);
364
        salesMap.put("currentRate", currentRate);
365
        salesMap.put("currentType", currentType);
366
        salesMap.put("currentTypeImage", PartnerType.imageMap.get(currentType));
367
        return salesMap;
368
    }
28468 tejbeer 369
 
370
 
34388 tejus.loha 371
    public ChartModel getBrandChart(int fofoId, LocalDate startDate, LocalDate endDate, boolean isQuantity) {
28468 tejbeer 372
 
34388 tejus.loha 373
        LocalDateTime curDate = startDate == null ? LocalDate.now().atStartOfDay().withDayOfMonth(1) : startDate.atStartOfDay();
374
        LocalDateTime lastDate = endDate == null ? LocalDate.now().atStartOfDay().with(LocalTime.MAX) : endDate.atStartOfDay();
28468 tejbeer 375
 
34388 tejus.loha 376
        Map<String, Double> brandWiseAllSale = fofoOrderItemRepository.selectSumAmountGroupByBrand(curDate, lastDate, fofoId);
377
        Map<String, Long> brandWiseSaleQuantity = fofoOrderItemRepository.selectSumQuantityGroupByBrand(curDate, lastDate, fofoId);
28468 tejbeer 378
 
34388 tejus.loha 379
        Map<Integer, Double> accesoriesmtdsale = fofoOrderRepository.selectSumSaleGroupByFofoIdsForMobileOrAccessories(fofoId, curDate, lastDate, Optional.of(false));
380
        brandWiseAllSale.put("Accessories", accesoriesmtdsale.get(fofoId));
381
        Map<Integer, Long> accesoriesMtdSaleQuantity = fofoOrderRepository.selectSumSaleQuantityGroupByFofoIdsForMobileOrAccessories(fofoId, curDate, lastDate, Optional.of(false));
382
        brandWiseSaleQuantity.put("Accessories", accesoriesMtdSaleQuantity.get(fofoId));
383
        List<ActivatedImeisWithSellingPrice> activatedImeisWithSellingPrices = fofoOrderRepository.selectValueOfActivatedImeis(curDate, lastDate, fofoId);
384
        Map<String, Double> activatedImeisWithSellingPriceMTD = activatedImeisWithSellingPrices.stream().collect(Collectors.toMap(x -> x.getBrand(), x -> (double) x.getSellingPrice()));
385
        Map<String, Long> activatedImeisWithSellingQuantityMTD = activatedImeisWithSellingPrices.stream().collect(Collectors.toMap(x -> x.getBrand(), x -> (long) x.getQuantity()));
28468 tejbeer 386
 
34388 tejus.loha 387
        activatedImeisWithSellingPriceMTD.put("Lava", brandWiseAllSale.get("Lava"));
388
        activatedImeisWithSellingQuantityMTD.put("Lava", brandWiseSaleQuantity.get("Lava"));
28468 tejbeer 389
 
34388 tejus.loha 390
        //--------------------------
28468 tejbeer 391
 
34388 tejus.loha 392
        Map<String, Double> LMTDBrandWiseSale = fofoOrderItemRepository.selectSumAmountGroupByBrand(curDate.minusMonths(1), lastDate.minusMonths(1), fofoId);
393
        Map<String, Long> LMTDBrandWiseSaleQuantity = fofoOrderItemRepository.selectSumQuantityGroupByBrand(curDate.minusMonths(1), lastDate.minusMonths(1), fofoId);
28468 tejbeer 394
 
34388 tejus.loha 395
        List<ActivatedImeisWithSellingPrice> LMTDActivatedImeisWithSellingPrices = fofoOrderRepository.selectValueOfActivatedImeis(curDate.minusMonths(1), lastDate.minusMonths(1), fofoId);
396
        Map<String, Double> LMTDActivatedImeisWithSellingPrice = LMTDActivatedImeisWithSellingPrices.stream().collect(Collectors.toMap(x -> x.getBrand(), x -> (double) x.getSellingPrice()));
397
        Map<String, Long> LMTDActivatedImeisWithSellingQuantity = LMTDActivatedImeisWithSellingPrices.stream().collect(Collectors.toMap(x -> x.getBrand(), x -> (long) x.getQuantity()));
28468 tejbeer 398
 
34388 tejus.loha 399
        LMTDActivatedImeisWithSellingPrice.put("Lava", LMTDBrandWiseSale.get("Lava"));
400
        LMTDActivatedImeisWithSellingQuantity.put("Lava", LMTDBrandWiseSaleQuantity.get("Lava"));
28468 tejbeer 401
 
31884 tejbeer 402
        ChartModel cm = new ChartModel();
28468 tejbeer 403
 
34388 tejus.loha 404
        List<String> brandList = Arrays.asList("Vivo", "Oppo", "Samsung", "Realme", "Xiaomi", "POCO", "Apple", "Tecno", "Lava", "Itel");
405
        LinkedHashSet<String> brandAsLabel = new LinkedHashSet<>(brandList);
28468 tejbeer 406
 
31884 tejbeer 407
        List<Double> mtdActivatedImeisValues = new ArrayList<>();
34388 tejus.loha 408
        List<Double> mtdValues = new ArrayList<>();
409
        List<Double> mtdUnActivatedImeisValues = new ArrayList<>();
410
        List<Double> mtdActivatedImeisQuantity = new ArrayList<>();
411
        List<Double> mtdQuantity = new ArrayList<>();
412
        List<Double> mtdUnActivatedImeisQuantity = new ArrayList<>();
28468 tejbeer 413
 
31884 tejbeer 414
        List<Double> lmtdActivatedImeisValues = new ArrayList<>();
415
        List<Double> lmtdValues = new ArrayList<>();
34388 tejus.loha 416
        List<Double> lmtdUnActivatedImeisValues = new ArrayList<>();
417
        List<Double> lmtdActivatedImeisQuantity = new ArrayList<>();
418
        List<Double> lmtdQuantity = new ArrayList<>();
419
        List<Double> lmtdUnActivatedImeisQuantity = new ArrayList<>();
28468 tejbeer 420
 
34388 tejus.loha 421
 
422
        for (String brand : brandList) {
423
            if (isQuantity) {
424
                mtdActivatedImeisQuantity.add(activatedImeisWithSellingQuantityMTD.get(brand) == null ? 0 : (double) activatedImeisWithSellingQuantityMTD.get(brand));
425
                mtdQuantity.add(brandWiseSaleQuantity.get(brand) == null ? 0 : (double) brandWiseSaleQuantity.get(brand));
426
                if (brandWiseSaleQuantity.get(brand) != null) {
427
                    mtdUnActivatedImeisQuantity.add(brandWiseSaleQuantity.get(brand) - (activatedImeisWithSellingQuantityMTD.get(brand) == null ? 0 : (double) activatedImeisWithSellingQuantityMTD.get(brand)));
428
                }
429
                lmtdQuantity.add(LMTDBrandWiseSaleQuantity.get(brand) == null ? 0 : (double) LMTDBrandWiseSaleQuantity.get(brand));
430
                lmtdActivatedImeisQuantity.add(LMTDActivatedImeisWithSellingQuantity.get(brand) == null ? 0 : (double) LMTDActivatedImeisWithSellingQuantity.get(brand));
431
                lmtdUnActivatedImeisQuantity.add(LMTDBrandWiseSaleQuantity.get(brand) == null ? 0 : LMTDBrandWiseSaleQuantity.get(brand) - (LMTDActivatedImeisWithSellingQuantity.get(brand) == null ? 0 : (double) LMTDActivatedImeisWithSellingQuantity.get(brand)));
31884 tejbeer 432
            } else {
34388 tejus.loha 433
                mtdActivatedImeisValues.add(activatedImeisWithSellingPriceMTD.get(brand) == null ? 0 : activatedImeisWithSellingPriceMTD.get(brand));
434
                mtdValues.add(brandWiseAllSale.get(brand) == null ? 0 : brandWiseAllSale.get(brand));
435
                if (brandWiseAllSale.get(brand) != null) {
436
                    mtdUnActivatedImeisValues.add(brandWiseAllSale.get(brand) - (activatedImeisWithSellingPriceMTD.get(brand) == null ? 0 : activatedImeisWithSellingPriceMTD.get(brand)));
437
                }
438
                lmtdValues.add(LMTDBrandWiseSale.get(brand) == null ? 0.0 : LMTDBrandWiseSale.get(brand));
439
                lmtdActivatedImeisValues.add(LMTDActivatedImeisWithSellingPrice.get(brand) == null ? 0.0 : LMTDActivatedImeisWithSellingPrice.get(brand));
440
                if (LMTDBrandWiseSale.get(brand) != null) {
441
                    lmtdUnActivatedImeisValues.add(LMTDBrandWiseSale.get(brand) - (LMTDActivatedImeisWithSellingPrice.get(brand) == null ? 0.0 : LMTDActivatedImeisWithSellingPrice.get(brand)));
442
                }
31884 tejbeer 443
            }
444
        }
28468 tejbeer 445
 
34388 tejus.loha 446
        DatasetModel mtdActivatedImeis = new DatasetModel();
447
        mtdActivatedImeis.setLabel("Total Activation");
448
        mtdActivatedImeis.setBorderColor("#00008b");
449
        mtdActivatedImeis.setBackgroundColor("#00008b");
450
        mtdActivatedImeis.setStack("stack0");
451
        mtdActivatedImeis.setOrder(0);
452
 
31884 tejbeer 453
        DatasetModel dsmUnactivated = new DatasetModel();
34388 tejus.loha 454
        dsmUnactivated.setLabel("Total Unactivated");
31884 tejbeer 455
        dsmUnactivated.setBackgroundColor("red");
456
        dsmUnactivated.setBorderColor("red");
457
        dsmUnactivated.setStack("stack0");
458
        dsmUnactivated.setOrder(1);
28468 tejbeer 459
 
34388 tejus.loha 460
        DatasetModel linemtdChart = new DatasetModel();
461
        linemtdChart.setLabel("Total");
462
        linemtdChart.setBackgroundColor("#006400");
463
        linemtdChart.setBorderColor("#006400");
464
        linemtdChart.setType("line");
465
        linemtdChart.setOrder(2);
466
        linemtdChart.setFill("false");
28468 tejbeer 467
 
34388 tejus.loha 468
        DatasetModel lmtdActivatedImeis = new DatasetModel();
469
        lmtdActivatedImeis.setLabel("PM Total Activation");
470
        lmtdActivatedImeis.setBackgroundColor("#87ceeb");
471
        lmtdActivatedImeis.setBorderColor("#87ceeb");
472
        lmtdActivatedImeis.setStack("stack1");
473
        lmtdActivatedImeis.setOrder(3);
28468 tejbeer 474
 
475
 
31884 tejbeer 476
        DatasetModel lmtdUnActivated = new DatasetModel();
34388 tejus.loha 477
        lmtdUnActivated.setLabel("PM Total Unactivation");
31884 tejbeer 478
        lmtdUnActivated.setBackgroundColor("red");
479
        lmtdUnActivated.setBorderColor("red");
480
        lmtdUnActivated.setStack("stack1");
34388 tejus.loha 481
        lmtdUnActivated.setOrder(4);
28468 tejbeer 482
 
483
 
31884 tejbeer 484
        DatasetModel lineLmtdChart = new DatasetModel();
34388 tejus.loha 485
        lineLmtdChart.setLabel("PM TOTAL");
31884 tejbeer 486
        lineLmtdChart.setBackgroundColor("hotpink");
487
        lineLmtdChart.setBorderColor("hotpink");
488
        lineLmtdChart.setType("line");
34388 tejus.loha 489
        lineLmtdChart.setOrder(5);
31884 tejbeer 490
        lineLmtdChart.setFill("false");
28468 tejbeer 491
 
34388 tejus.loha 492
        if (isQuantity) {
493
            mtdActivatedImeis.setData(mtdActivatedImeisQuantity);
494
            dsmUnactivated.setData(mtdUnActivatedImeisQuantity);
495
            linemtdChart.setData(mtdQuantity);
496
            lmtdActivatedImeis.setData(lmtdActivatedImeisQuantity);
497
            lmtdUnActivated.setData(lmtdUnActivatedImeisQuantity);
498
            lineLmtdChart.setData(lmtdQuantity);
499
        } else {
500
            mtdActivatedImeis.setData(mtdActivatedImeisValues);
501
            dsmUnactivated.setData(mtdUnActivatedImeisValues);
502
            linemtdChart.setData(mtdValues);
503
            lmtdActivatedImeis.setData(lmtdActivatedImeisValues);
504
            lmtdUnActivated.setData(lmtdUnActivatedImeisValues);
505
            lineLmtdChart.setData(lmtdValues);
506
        }
507
 
31884 tejbeer 508
        List<DatasetModel> datasets = new ArrayList<>();
509
        datasets.add(mtdActivatedImeis);
510
        datasets.add(dsmUnactivated);
34388 tejus.loha 511
        datasets.add(linemtdChart);
512
        datasets.add(lmtdActivatedImeis);
31884 tejbeer 513
        datasets.add(lmtdUnActivated);
514
        datasets.add(lineLmtdChart);
28468 tejbeer 515
 
31884 tejbeer 516
        DataModel dm = new DataModel();
517
        dm.setDatasets(datasets);
34388 tejus.loha 518
        dm.setLabels(brandAsLabel);
31884 tejbeer 519
        Tooltips tooltips = new Tooltips();
34388 tejus.loha 520
        tooltips.setBodyFontSize(25);
521
        tooltips.setTitleFontSize(25);
31884 tejbeer 522
        tooltips.setMode("index");
523
        tooltips.setIntersect(false);
34388 tejus.loha 524
        tooltips.setBackgroundColor("rgba(0, 0, 0, 0.7)");
31884 tejbeer 525
        HoverModel hover = new HoverModel();
526
        hover.setIntersect(false);
527
        hover.setMode("index");
28468 tejbeer 528
 
31884 tejbeer 529
        LegendModel lm = new LegendModel();
530
        lm.setPosition("top");
28468 tejbeer 531
 
31884 tejbeer 532
        TitleModel tm = new TitleModel();
533
        tm.setText("Brand Wise Sales");
534
        tm.setDisplay(true);
535
        tm.setFontSize(20);
536
        tm.setFontColor("#111");
28468 tejbeer 537
 
31884 tejbeer 538
        List<Axis> xAxes = new ArrayList<>();
539
        Axis xAxis = new Axis();
540
        xAxis.setStacked(true);
541
        xAxes.add(xAxis);
28468 tejbeer 542
 
31884 tejbeer 543
        List<Axis> yAxes = new ArrayList<>();
544
        Axis yAxis = new Axis();
545
        yAxis.setStacked(false);
546
        yAxes.add(yAxis);
28468 tejbeer 547
 
31884 tejbeer 548
        ScalesModel sm = new ScalesModel();
549
        sm.setxAxes(xAxes);
28468 tejbeer 550
 
31884 tejbeer 551
        OptionsModel om = new OptionsModel();
552
        om.setLegend(lm);
553
        om.setTitle(tm);
554
        om.setScales(sm);
555
        om.setHover(hover);
556
        om.setTooltips(tooltips);
28468 tejbeer 557
 
31884 tejbeer 558
        cm.setType("bar");
559
        cm.setData(dm);
560
        cm.setOptions(om);
28468 tejbeer 561
 
31884 tejbeer 562
        LOGGER.info("cm" + cm);
28468 tejbeer 563
 
31884 tejbeer 564
        return cm;
28468 tejbeer 565
 
31884 tejbeer 566
    }
28468 tejbeer 567
 
31884 tejbeer 568
    public ChartInvestmentModel getInvestmentChart(int fofoId) throws ProfitMandiBusinessException {
569
        PartnerDailyInvestment investment = partnerInvestmentService.getInvestment(fofoId, 0);
28468 tejbeer 570
 
31884 tejbeer 571
        Map<String, Float> investmentWalletAmount = new HashMap<>();
572
        investmentWalletAmount.put("Wallet", investment.getWalletAmount());
573
        investmentWalletAmount.put("InStocks", investment.getInStockAmount() - investment.getActivatedStockAmount());
574
        investmentWalletAmount.put("Unbilled Order", investment.getUnbilledAmount());
575
        investmentWalletAmount.put("GrnPending", investment.getGrnPendingAmount() - investment.getActivatedGrnPendingAmount());
576
        investmentWalletAmount.put("ReturnInTransit", investment.getReturnInTransitAmount());
28468 tejbeer 577
 
31884 tejbeer 578
        if (investment.getShortInvestment() > 0) {
579
            investmentWalletAmount.put("Short Investment", investment.getShortInvestment());
580
        }
28468 tejbeer 581
 
31884 tejbeer 582
        ChartInvestmentModel cm = new ChartInvestmentModel();
28468 tejbeer 583
 
31884 tejbeer 584
        HashSet<String> labels = new HashSet<String>();
585
        labels.addAll(investmentWalletAmount.keySet());
28468 tejbeer 586
 
31884 tejbeer 587
        List<String> labelList = new ArrayList<>(labels);
588
        List<String> backgroundColor = new ArrayList<>();
589
        List<Float> values = new ArrayList<>();
590
        for (String label : labelList) {
591
            values.add(investmentWalletAmount.get(label));
592
            if (label.equals("Wallet")) {
593
                backgroundColor.add("pink");
594
            }
595
            if (label.equals("Short Investment")) {
596
                backgroundColor.add("red");
597
            }
598
            if (label.equals("InStocks")) {
599
                backgroundColor.add("#9ACD32");
600
            }
601
            if (label.equals("Unbilled Order")) {
602
                backgroundColor.add("blue");
603
            }
28468 tejbeer 604
 
31884 tejbeer 605
            if (label.equals("ReturnInTransit")) {
606
                backgroundColor.add("orange");
607
            }
608
            if (label.equals("GrnPending")) {
609
                backgroundColor.add("yellow");
610
            }
28468 tejbeer 611
 
31884 tejbeer 612
        }
28468 tejbeer 613
 
31884 tejbeer 614
        Data data = new Data();
615
        data.setData(values);
616
        data.setBackgroundColor(backgroundColor);
617
        data.setLabel("DataSet 1");
28468 tejbeer 618
 
31884 tejbeer 619
        PieLables label = new PieLables();
620
        label.setFontColor("White");
621
        label.setFontSize(15);
28468 tejbeer 622
 
31884 tejbeer 623
        Legend legend = new Legend();
624
        legend.setLabels(label);
625
        legend.setPosition("left");
28468 tejbeer 626
 
31884 tejbeer 627
        List<Data> dataList = new ArrayList<>();
628
        dataList.add(data);
28468 tejbeer 629
 
31884 tejbeer 630
        DataInvestmentModel datasets = new DataInvestmentModel();
631
        datasets.setDatasets(dataList);
632
        datasets.setLabels(labels);
28468 tejbeer 633
 
31884 tejbeer 634
        OptionModel om = new OptionModel();
635
        om.setLegend(legend);
636
        cm.setType("pie");
637
        cm.setData(datasets);
638
        cm.setOptions(om);
28468 tejbeer 639
 
31884 tejbeer 640
        return cm;
641
    }
28468 tejbeer 642
 
31884 tejbeer 643
    public List<Notification> getNotifications(List<NotificationCampaign> nc, MessageType messageType) throws ProfitMandiBusinessException {
644
        List<Notification> notifications = new ArrayList<>();
645
        Document document = null;
646
        if (messageType != null) {
647
            for (NotificationCampaign notificationCampaign : nc) {
648
                if (notificationCampaign.getMessageType() == messageType) {
649
                    Notification ns = new Notification();
650
                    SimpleCampaignParams scp = gson.fromJson(notificationCampaign.getImplementationParams(), SimpleCampaignParams.class);
651
                    Campaign campaign = new SimpleCampaign(scp);
652
                    LocalDateTime expire = campaign.getExpireTimestamp();
653
                    ns.setCid(Integer.toString(notificationCampaign.getId()));
654
                    ns.setType(campaign.getType());
655
                    ns.setMessage(campaign.getMessage());
656
                    ns.setTitle(campaign.getTitle());
657
                    if (notificationCampaign.getDocumentId() != null) {
658
                        document = documentRepository.selectById(notificationCampaign.getDocumentId());
659
                        ns.setDocumentName(document.getDisplayName());
660
                    }
661
                    ns.setUrl(campaign.getUrl());
662
                    ns.setShowImage(campaign.getShowImage());
663
                    ns.setImageUrl(campaign.getImageUrl());
664
                    ns.setDocumentId(notificationCampaign.getDocumentId());
665
                    ns.setMessageType(notificationCampaign.getMessageType());
666
                    ns.setCreated(
667
                            notificationCampaign.getCreatedTimestamp().toEpochSecond(ZoneOffset.ofHoursMinutes(5, 30)) * 1000);
668
                    if (LocalDateTime.now().isAfter(expire)) {
669
                        ns.setExpired(true);
670
                    } else {
671
                        ns.setExpired(false);
672
                    }
673
                    notifications.add(ns);
674
                }
675
            }
676
        } else {
677
            for (NotificationCampaign notificationCampaign : nc) {
28468 tejbeer 678
 
31884 tejbeer 679
                Notification ns = new Notification();
680
                SimpleCampaignParams scp = gson.fromJson(notificationCampaign.getImplementationParams(), SimpleCampaignParams.class);
681
                Campaign campaign = new SimpleCampaign(scp);
682
                LocalDateTime expire = campaign.getExpireTimestamp();
683
                ns.setCid(Integer.toString(notificationCampaign.getId()));
684
                ns.setType(campaign.getType());
685
                ns.setMessage(campaign.getMessage());
686
                ns.setTitle(campaign.getTitle());
687
                if (notificationCampaign.getDocumentId() != null) {
688
                    document = documentRepository.selectById(notificationCampaign.getDocumentId());
689
                    ns.setDocumentName(document.getDisplayName());
690
                }
691
                ns.setUrl(campaign.getUrl());
692
                ns.setShowImage(campaign.getShowImage());
693
                ns.setImageUrl(campaign.getImageUrl());
694
                ns.setDocumentId(notificationCampaign.getDocumentId());
695
                ns.setMessageType(notificationCampaign.getMessageType());
696
                ns.setCreated(notificationCampaign.getCreatedTimestamp().toEpochSecond(ZoneOffset.ofHoursMinutes(5, 30)) * 1000);
697
                if (LocalDateTime.now().isAfter(expire)) {
698
                    ns.setExpired(true);
699
                } else {
700
                    ns.setExpired(false);
701
                }
702
                notifications.add(ns);
703
            }
28468 tejbeer 704
 
31884 tejbeer 705
        }
706
        return notifications;
28468 tejbeer 707
 
31884 tejbeer 708
    }
709
 
710
    public boolean hasGift(int fofoId) {
711
        try {
712
            return currentInventorySnapshotRepository.selectByItemIdAndFofoId(ProfitMandiConstants.GIFT_ID, fofoId).getAvailability() > 0;
713
        } catch (ProfitMandiBusinessException e) {
714
            return false;
715
        }
716
    }
717
 
34388 tejus.loha 718
    public ChartModel getModelBrandChart(int fofoId, String brand, LocalDate startDate, LocalDate endDate, boolean isQuantity) {
719
 
720
        LocalDateTime curDate = startDate == null ? LocalDate.now().atStartOfDay().withDayOfMonth(1) : startDate.atStartOfDay();
721
        LocalDateTime lastDate = endDate == null ? LocalDate.now().atStartOfDay().with(LocalTime.MAX) : endDate.atStartOfDay();
722
 
723
        //----------------------------MTD-------------------------
724
        Map<String, Double> modelWiseSale = fofoOrderItemRepository.selectSumAmountGroupByBrand(curDate, lastDate, fofoId, "modelNumber", brand);
725
        Map<String, Long> modelWiseSaleQuantity = fofoOrderItemRepository.selectSumQuantityGroupByBrand(curDate, lastDate, fofoId, "modelNumber", brand);
726
 
727
        List<ActivatedImeisWithSellingPrice> activatedImeisWithSellingPricesMTD = fofoOrderItemRepository.selectValueOfActivatedImeisModelWise(curDate, lastDate, fofoId, brand);
728
        Map<String, Double> activatedImeisWithSellingPriceMTD = activatedImeisWithSellingPricesMTD.stream().collect(Collectors.toMap(x -> x.getModel(), x -> (double) x.getSellingPrice()));
729
        Map<String, Long> activatedImeisWithSellingQuantityMTD = activatedImeisWithSellingPricesMTD.stream().collect(Collectors.toMap(x -> x.getModel(), x -> (long) x.getQuantity()));
730
 
731
 
732
        //---------------------------------LMTD----------------------
733
        Map<String, Double> lmtdModelWiseSale = fofoOrderItemRepository.selectSumAmountGroupByBrand(curDate.minusMonths(1), lastDate.minusMonths(1), fofoId, "modelNumber", brand);
734
        Map<String, Long> lmtdModelWiseSaleQuantity = fofoOrderItemRepository.selectSumQuantityGroupByBrand(curDate.minusMonths(1), lastDate.minusMonths(1), fofoId, "modelNumber", brand);
735
 
736
        List<ActivatedImeisWithSellingPrice> lmtdActivatedImeisWithSellingPrices = fofoOrderItemRepository.selectValueOfActivatedImeisModelWise(curDate.minusMonths(1), lastDate.minusMonths(1), fofoId, brand);
737
        Map<String, Double> lmtdActivatedImeisWithSellingPrice = lmtdActivatedImeisWithSellingPrices.stream().collect(Collectors.toMap(x -> x.getModel(), x -> (double) x.getSellingPrice()));
738
        Map<String, Long> lmtdActivatedImeisWithSellingQuantity = lmtdActivatedImeisWithSellingPrices.stream().collect(Collectors.groupingBy(x -> x.getModel(), Collectors.summingLong(x -> x.getQuantity())));
739
 
740
        ChartModel cm = new ChartModel();
741
 
742
        List<String> brandList1 = lmtdModelWiseSale.keySet().stream().collect(Collectors.toList());
743
        List<String> brandList2 = modelWiseSale.keySet().stream().collect(Collectors.toList());
744
        HashSet<String> brandsAsLabelList = new HashSet<>();
745
        brandsAsLabelList.addAll(brandList1);
746
        brandsAsLabelList.addAll(brandList2);
747
        // for MTD
748
        List<Double> mtdActivatedImeisValues = new ArrayList<>();
749
        List<Double> mtdUnActivatedImeisValues = new ArrayList<>();
750
        List<Double> mtdValues = new ArrayList<>();
751
        List<Double> mtdActivatedImeisQuantity = new ArrayList<>();
752
        List<Double> mtdUnActivatedImeisQuantity = new ArrayList<>();
753
        List<Double> mtdQuantity = new ArrayList<>();
754
 
755
        // for LMTD
756
        List<Double> lmtdActivatedImeisValues = new ArrayList<>();
757
        List<Double> lmtdUnActivatedImeisValues = new ArrayList<>();
758
        List<Double> lmtdValues = new ArrayList<>();
759
        List<Double> lmtdActivatedImeisQuantity = new ArrayList<>();
760
        List<Double> lmtdUnActivatedImeisQuantity = new ArrayList<>();
761
        List<Double> lmtdQuantity = new ArrayList<>();
762
 
763
 
764
        LOGGER.info("labelsList - " + brandsAsLabelList);
765
        for (String brandAsLabel : brandsAsLabelList) {
766
            brandAsLabel = brandAsLabel.trim();
767
            if (isQuantity) {
768
                mtdActivatedImeisQuantity.add(activatedImeisWithSellingQuantityMTD.get(brandAsLabel) == null ? 0 : (double) activatedImeisWithSellingQuantityMTD.get(brandAsLabel));
769
                mtdQuantity.add(modelWiseSaleQuantity.get(brandAsLabel) == null ? 0 : (double) modelWiseSaleQuantity.get(brandAsLabel));
770
                mtdUnActivatedImeisQuantity.add(modelWiseSaleQuantity.get(brandAsLabel) == null ? 0 : modelWiseSaleQuantity.get(brandAsLabel) - (activatedImeisWithSellingQuantityMTD.get(brandAsLabel) == null ? 0 : (double) activatedImeisWithSellingQuantityMTD.get(brandAsLabel)));
771
 
772
                lmtdActivatedImeisQuantity.add(lmtdActivatedImeisWithSellingQuantity.get(brandAsLabel) == null ? 0 : (double) lmtdActivatedImeisWithSellingQuantity.get(brandAsLabel));
773
                lmtdUnActivatedImeisQuantity.add(lmtdModelWiseSaleQuantity.get(brandAsLabel) == null ? 0 : lmtdModelWiseSaleQuantity.get(brandAsLabel) - (lmtdActivatedImeisWithSellingQuantity.get(brandAsLabel) == null ? 0 : (double) lmtdActivatedImeisWithSellingQuantity.get(brandAsLabel)));
774
                lmtdQuantity.add(lmtdModelWiseSaleQuantity.get(brandAsLabel) == null ? 0 : (double) lmtdModelWiseSaleQuantity.get(brandAsLabel));
775
            } else {
776
                mtdActivatedImeisValues.add(activatedImeisWithSellingPriceMTD.get(brandAsLabel) == null ? 0 : activatedImeisWithSellingPriceMTD.get(brandAsLabel));
777
                mtdValues.add(modelWiseSale.get(brandAsLabel) == null ? 0 : modelWiseSale.get(brandAsLabel));
778
                if (modelWiseSale.get(brandAsLabel) != null) {
779
                    mtdUnActivatedImeisValues.add(modelWiseSale.get(brandAsLabel) - (activatedImeisWithSellingPriceMTD.get(brandAsLabel) == null ? 0 : activatedImeisWithSellingPriceMTD.get(brandAsLabel)));
780
                } else {
781
                    mtdUnActivatedImeisValues.add(0.0);
782
                }
783
                lmtdValues.add(lmtdModelWiseSale.get(brandAsLabel) == null ? 0 : lmtdModelWiseSale.get(brandAsLabel));
784
                lmtdActivatedImeisValues.add(lmtdActivatedImeisWithSellingPrice.get(brandAsLabel) == null ? 0 : lmtdActivatedImeisWithSellingPrice.get(brandAsLabel));
785
                if (lmtdModelWiseSale.get(brandAsLabel.trim()) != null) {
786
                    lmtdUnActivatedImeisValues.add(lmtdModelWiseSale.get(brandAsLabel) - (lmtdActivatedImeisWithSellingPrice.get(brandAsLabel) == null ? 0 : lmtdActivatedImeisWithSellingPrice.get(brandAsLabel)));
787
                } else {
788
                    lmtdUnActivatedImeisValues.add(0.0);
789
                }
790
            }
791
        }
792
 
793
        DatasetModel mtdActivatedImeis = new DatasetModel();
794
        mtdActivatedImeis.setLabel("Total Activation");
795
        mtdActivatedImeis.setBorderColor("#00008b");
796
        mtdActivatedImeis.setBackgroundColor("#00008b");
797
        mtdActivatedImeis.setStack("stack0");
798
        mtdActivatedImeis.setOrder(0);
799
 
800
        DatasetModel dsmUnactivated = new DatasetModel();
801
        dsmUnactivated.setLabel("Total Unactivated");
802
        dsmUnactivated.setBackgroundColor("red");
803
        dsmUnactivated.setBorderColor("red");
804
        dsmUnactivated.setStack("stack0");
805
        dsmUnactivated.setOrder(1);
806
 
807
        DatasetModel linemtdChart = new DatasetModel();
808
        linemtdChart.setLabel("Total");
809
        linemtdChart.setBackgroundColor("#006400");
810
        linemtdChart.setBorderColor("#006400");
811
        linemtdChart.setType("line");
812
        linemtdChart.setOrder(2);
813
        linemtdChart.setFill("false");
814
 
815
        DatasetModel LmtdActivatedImeis = new DatasetModel();
816
        LmtdActivatedImeis.setLabel("PM Total Activation");
817
        LmtdActivatedImeis.setBackgroundColor("#87ceeb");
818
        LmtdActivatedImeis.setBorderColor("#87ceeb");
819
        LmtdActivatedImeis.setStack("stack1");
820
        LmtdActivatedImeis.setOrder(3);
821
 
822
        DatasetModel lmtdUnActivated = new DatasetModel();
823
        lmtdUnActivated.setLabel("PM Total Unactivation");
824
        lmtdUnActivated.setBackgroundColor("red");
825
        lmtdUnActivated.setBorderColor("red");
826
        lmtdUnActivated.setStack("stack1");
827
        lmtdUnActivated.setOrder(4);
828
 
829
        DatasetModel lineLmtdChart = new DatasetModel();
830
        lineLmtdChart.setLabel("PM TOTAL");
831
        lineLmtdChart.setBackgroundColor("hotpink");
832
        lineLmtdChart.setBorderColor("hotpink");
833
        lineLmtdChart.setType("line");
834
        lineLmtdChart.setOrder(5);
835
        lineLmtdChart.setFill("false");
836
 
837
 
838
        if (isQuantity) {
839
            mtdActivatedImeis.setData(mtdActivatedImeisQuantity);
840
            dsmUnactivated.setData(mtdUnActivatedImeisQuantity);
841
            linemtdChart.setData(mtdQuantity);
842
            LmtdActivatedImeis.setData(lmtdActivatedImeisQuantity);
843
            lmtdUnActivated.setData(lmtdUnActivatedImeisQuantity);
844
            lineLmtdChart.setData(lmtdQuantity);
845
        } else {
846
            mtdActivatedImeis.setData(mtdActivatedImeisValues);
847
            dsmUnactivated.setData(mtdUnActivatedImeisValues);
848
            linemtdChart.setData(mtdValues);
849
            LmtdActivatedImeis.setData(lmtdActivatedImeisValues);
850
            lmtdUnActivated.setData(lmtdUnActivatedImeisValues);
851
            lineLmtdChart.setData(lmtdValues);
852
        }
853
 
854
        List<DatasetModel> datasets = new ArrayList<>();
855
        datasets.add(mtdActivatedImeis);
856
        datasets.add(dsmUnactivated);
857
        datasets.add(linemtdChart);
858
        datasets.add(LmtdActivatedImeis);
859
        datasets.add(lmtdUnActivated);
860
        datasets.add(lineLmtdChart);
861
 
862
        DataModel dm = new DataModel();
863
        dm.setDatasets(datasets);
864
        dm.setLabels(brandsAsLabelList);
865
 
866
        Tooltips tooltips = new Tooltips();
867
        tooltips.setBodyFontSize(25);
868
        tooltips.setTitleFontSize(25);
869
        tooltips.setMode("index");
870
        tooltips.setIntersect(false);
871
        tooltips.setBackgroundColor("rgba(0, 0, 0, 0.7)");
872
        HoverModel hover = new HoverModel();
873
        hover.setIntersect(false);
874
        hover.setMode("index");
875
 
876
        LegendModel lm = new LegendModel();
877
        lm.setPosition("top");
878
 
879
        TitleModel tm = new TitleModel();
880
        tm.setText("Model Wise Sales");
881
        tm.setDisplay(true);
882
        tm.setFontSize(20);
883
        tm.setFontColor("#111");
884
 
885
        List<Axis> xAxes = new ArrayList<>();
886
        Axis xAxis = new Axis();
887
        xAxis.setStacked(true);
888
        xAxes.add(xAxis);
889
 
890
        List<Axis> yAxes = new ArrayList<>();
891
        Axis yAxis = new Axis();
892
        yAxis.setStacked(false);
893
        yAxes.add(yAxis);
894
 
895
        ScalesModel sm = new ScalesModel();
896
        sm.setxAxes(xAxes);
897
 
898
        OptionsModel om = new OptionsModel();
899
        om.setLegend(lm);
900
        om.setTitle(tm);
901
        om.setScales(sm);
902
        om.setHover(hover);
903
        om.setTooltips(tooltips);
904
 
905
        cm.setType("bar");
906
        cm.setData(dm);
907
        cm.setOptions(om);
908
 
909
        LOGGER.info("Model_cm" + cm);
910
        return cm;
911
 
912
    }
913
 
28468 tejbeer 914
}