Subversion Repositories SmartDukaan

Rev

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

Rev 31246 Rev 31884
Line 31... Line 31...
31
import java.util.stream.Collectors;
31
import java.util.stream.Collectors;
32
 
32
 
33
@Component
33
@Component
34
public class FofoUser {
34
public class FofoUser {
35
 
35
 
36
	@Autowired
36
    @Autowired
37
	private Gson gson;
37
    private Gson gson;
38
 
38
 
39
	@Autowired
39
    @Autowired
40
	private PartnerInvestmentService partnerInvestmentService;
40
    private PartnerInvestmentService partnerInvestmentService;
41
 
41
 
42
	@Autowired
42
    @Autowired
43
	private PartnerDailyInvestmentRepository partnerDailyInvestmentRepository;
43
    private PartnerDailyInvestmentRepository partnerDailyInvestmentRepository;
44
 
44
 
45
	@Autowired
45
    @Autowired
46
	ChartService chartService;
46
    ChartService chartService;
47
 
47
 
48
	@Autowired
48
    @Autowired
49
	FofoOrderItemRepository fofoOrderItemRepository;
49
    FofoOrderItemRepository fofoOrderItemRepository;
50
 
50
 
51
	@Autowired
51
    @Autowired
52
	FofoOrderRepository fofoOrderRepository;
52
    FofoOrderRepository fofoOrderRepository;
53
 
53
 
54
	@Autowired
54
    @Autowired
55
	PartnerTypeChangeService partnerTypeChangeService;
55
    PartnerTypeChangeService partnerTypeChangeService;
56
 
56
 
57
	@Autowired
57
    @Autowired
58
	PartnerTargetRepository partnerTargetRepository;
58
    PartnerTargetRepository partnerTargetRepository;
59
 
59
 
60
	@Autowired
60
    @Autowired
61
	InventoryService inventoryService;
61
    InventoryService inventoryService;
62
 
62
 
63
	@Autowired
63
    @Autowired
64
	private Mongo mongoClient;
64
    private Mongo mongoClient;
65
 
65
 
66
	@Autowired
66
    @Autowired
67
	private OrderRepository orderRepository;
67
    private OrderRepository orderRepository;
68
 
68
 
69
	@Autowired
69
    @Autowired
70
	DocumentRepository documentRepository;
70
    DocumentRepository documentRepository;
71
 
71
 
72
	@Autowired
72
    @Autowired
73
	CurrentInventorySnapshotRepository currentInventorySnapshotRepository;
73
    CurrentInventorySnapshotRepository currentInventorySnapshotRepository;
74
 
74
 
75
	private static final Logger LOGGER = LogManager.getLogger(FofoUser.class);
75
    private static final Logger LOGGER = LogManager.getLogger(FofoUser.class);
76
 
76
 
77
	List<String> colorList = Arrays.asList("papayawhip", "mediumseagreen", "dodgerblue", "darkblue", "gold", "#eb0029", "coral",
77
    List<String> colorList = Arrays.asList("papayawhip", "mediumseagreen", "dodgerblue", "darkblue", "gold", "#eb0029", "coral", "steelblue", "red", "deeppink", "midnightblue", "cornsilk");
78
			"steelblue", "red", "deeppink", "midnightblue", "cornsilk");
78
 
79
 
79
    List<String> borderList = Arrays.asList("pink", "lawngreen", "lightblue", "#0000cd", "#f7e98e", "#eb0029", "lightcoral", "#0000cd", "lightsalmon", "pink", "#0000cd", "cornsilk");
80
	List<String> borderList = Arrays.asList("pink", "lawngreen", "lightblue", "#0000cd", "#f7e98e", "#eb0029", "lightcoral",
80
 
81
			"#0000cd", "lightsalmon", "pink", "#0000cd", "cornsilk");
81
    List<String> brands = Arrays.asList("Accessories", "Oppo", "Vivo", "Samsung", "Realme", "Xiaomi", "OnePlus", "Tecno", "Itel", "Lava", "Nokia");
82
 
82
 
83
	List<String> brands = Arrays.asList("Accessories", "Oppo", "Vivo", "Samsung", "Realme", "Xiaomi", "OnePlus", "Tecno", "Itel",
83
    public String format(long value) {
84
			"Lava", "Nokia");
84
        String finalval = null;
85
 
85
 
86
	public String format(long value) {
86
        if (value >= 100000 && value < 10000000) {
87
		String finalval = null;
87
            long reminder = value / 100000;
88
 
88
            long quitonent = value % 100000;
89
		if (value >= 100000 && value < 10000000) {
89
            String secondval = String.format("%05d", quitonent);
90
			long reminder = value / 100000;
90
            secondval = secondval.substring(0, 2);
91
			long quitonent = value % 100000;
91
            finalval = reminder + "." + secondval;
92
			String secondval = String.format("%05d", quitonent);
92
            return String.valueOf(finalval) + " Lacs";
93
			secondval = secondval.substring(0, 2);
93
        } else if (value >= 1000 && value < 100000) {
94
			finalval = reminder + "." + secondval;
94
            long reminder = value / 1000;
95
			return String.valueOf(finalval) + " Lacs";
95
            long quitonent = value % 1000;
96
		} else if (value >= 1000 && value < 100000) {
96
            String secondval = String.format("%03d", quitonent);
97
			long reminder = value / 1000;
97
            secondval = secondval.substring(0, 2);
98
			long quitonent = value % 1000;
98
            finalval = reminder + "." + secondval;
99
			String secondval = String.format("%03d", quitonent);
99
            return String.valueOf(finalval) + " K";
100
			secondval = secondval.substring(0, 2);
100
        } else if (value >= 10000000 && value < 1000000000) {
101
			finalval = reminder + "." + secondval;
101
            long reminder = value / 10000000;
102
			return String.valueOf(finalval) + " K";
102
            long quitonent = value % 10000000;
103
		} else if (value >= 10000000 && value < 1000000000) {
103
            finalval = reminder + "." + quitonent;
104
			long reminder = value / 10000000;
104
            String secondval = String.format("%07d", quitonent);
105
			long quitonent = value % 10000000;
105
            secondval = secondval.substring(0, 2);
106
			finalval = reminder + "." + quitonent;
106
            finalval = reminder + "." + secondval;
107
			String secondval = String.format("%07d", quitonent);
107
            return String.valueOf(finalval) + " Cr";
108
			secondval = secondval.substring(0, 2);
108
        }
109
			finalval = reminder + "." + secondval;
109
        return String.valueOf(finalval);
110
			return String.valueOf(finalval) + " Cr";
110
 
111
		}
111
    }
112
		return String.valueOf(finalval);
112
 
113
 
113
    public List<BrandStockPrice> getBrandStockPrices(int fofoId, boolean allBrands) throws Exception {
114
	}
114
        Map<String, BrandStockPrice> brandStockPricesMap = inventoryService.getBrandWiseStockValue(fofoId);
115
 
115
 
116
	public List<BrandStockPrice> getBrandStockPrices(int fofoId) throws Exception {
116
        List<DBObject> mobileBrands = mongoClient.getAllBrandsToDisplay(3);
117
		Map<String, BrandStockPrice> brandStockPricesMap = inventoryService.getBrandWiseStockValue(fofoId);
117
        List<BrandStockPrice> brandStockPrices = new ArrayList<>();
118
 
118
 
119
		List<DBObject> mobileBrands = mongoClient.getAllBrandsToDisplay(3);
119
        mobileBrands.stream().forEach(x -> {
120
		List<BrandStockPrice> brandStockPrices = new ArrayList<>();
120
            String brand = (String) x.get("name");
121
 
121
            if (brandStockPricesMap.containsKey(brand)) {
122
		mobileBrands.stream().forEach(x -> {
122
                BrandStockPrice brandStockPrice = brandStockPricesMap.get(brand);
123
			String brand = (String) x.get("name");
123
                brandStockPrice.setBrandUrl((String) x.get("url"));
124
			if (brandStockPricesMap.containsKey(brand)) {
124
                brandStockPrice.setRank(((Double) x.get("rank")).intValue());
125
				BrandStockPrice brandStockPrice = brandStockPricesMap.get(brand);
125
                brandStockPrices.add(brandStockPrice);
126
				brandStockPrice.setBrandUrl((String) x.get("url"));
126
            }
127
				brandStockPrice.setRank(((Double) x.get("rank")).intValue());
127
        });
128
				brandStockPrices.add(brandStockPrice);
128
 
129
			}
129
        if (allBrands) {
130
		});
130
            return brandStockPrices.stream().sorted(Comparator.comparingInt(BrandStockPrice::getRank)).collect(Collectors.toList());
131
 
131
 
132
		return brandStockPrices.stream().filter(x -> x.getTotalQty() > 0).sorted(Comparator.comparingInt(BrandStockPrice::getRank))
132
        }
133
				.collect(Collectors.toList());
133
 
134
	}
134
        return brandStockPrices.stream().filter(x -> x.getTotalQty() > 0).sorted(Comparator.comparingInt(BrandStockPrice::getRank)).collect(Collectors.toList());
135
 
135
    }
136
	public Map<String, Object> getInvestments(int fofoId) throws Exception {
136
 
137
		Map<String, Object> investments = new LinkedHashMap<>();
137
    public Map<String, Object> getInvestments(int fofoId) throws Exception {
138
		PartnerDailyInvestment investment = partnerInvestmentService.getInvestment(fofoId, 0);
138
        Map<String, Object> investments = new LinkedHashMap<>();
139
		LocalDate currentMonthStart = LocalDate.now().withDayOfMonth(1);
139
        PartnerDailyInvestment investment = partnerInvestmentService.getInvestment(fofoId, 0);
140
		LocalDate yesterDate = LocalDate.now().minusDays(1);
140
        LocalDate currentMonthStart = LocalDate.now().withDayOfMonth(1);
141
		PartnerDailyInvestment yesterdayInvestment = partnerDailyInvestmentRepository.select(fofoId, yesterDate);
141
        LocalDate yesterDate = LocalDate.now().minusDays(1);
142
		if (yesterdayInvestment == null) {
142
        PartnerDailyInvestment yesterdayInvestment = partnerDailyInvestmentRepository.select(fofoId, yesterDate);
143
			yesterdayInvestment = new PartnerDailyInvestment();
143
        if (yesterdayInvestment == null) {
144
		}
144
            yesterdayInvestment = new PartnerDailyInvestment();
145
 
145
        }
146
		List<PartnerDailyInvestment> currentMonthInvestments = partnerDailyInvestmentRepository.selectAll(fofoId,
146
 
147
				currentMonthStart, currentMonthStart.withDayOfMonth(currentMonthStart.lengthOfMonth()));
147
        List<PartnerDailyInvestment> currentMonthInvestments = partnerDailyInvestmentRepository.selectAll(fofoId, currentMonthStart, currentMonthStart.withDayOfMonth(currentMonthStart.lengthOfMonth()));
148
 
148
 
149
		long okInvestmentDays = currentMonthInvestments.stream().filter(x -> x.getShortPercentage() <= 10)
149
        long okInvestmentDays = currentMonthInvestments.stream().filter(x -> x.getShortPercentage() <= 10).collect(Collectors.counting());
150
				.collect(Collectors.counting());
150
        investments.put("today", investment.getTotalInvestment());
151
		investments.put("today", investment.getTotalInvestment());
151
        investments.put("investment", investment);
152
		investments.put("investment", investment);
152
        investments.put("inStock", investment.getInStockAmount());
153
		investments.put("inStock", investment.getInStockAmount());
153
        investments.put("minimum", investment.getMinInvestmentString());
154
		investments.put("minimum", investment.getMinInvestmentString());
154
        investments.put("short", investment.getShortPercentage());
155
		investments.put("short", investment.getShortPercentage());
155
        investments.put("activated_stock", investment.getActivatedStockAmount());
156
		investments.put("activated_stock", investment.getActivatedStockAmount());
156
        investments.put("okDays", okInvestmentDays);
157
		investments.put("okDays", okInvestmentDays);
157
        return investments;
158
		return investments;
158
    }
159
	}
159
 
160
 
160
    public Map<String, Object> getInvestmentsMonths(int fofoId, int month) throws Exception {
161
	public Map<String, Object> getInvestmentsMonths(int fofoId, int month) throws Exception {
161
        Map<String, Object> investments = new LinkedHashMap<>();
162
		Map<String, Object> investments = new LinkedHashMap<>();
162
        PartnerDailyInvestment investment = partnerInvestmentService.getInvestment(fofoId, 0);
163
		PartnerDailyInvestment investment = partnerInvestmentService.getInvestment(fofoId, 0);
163
        LocalDate currentMonthStart = LocalDate.now().withDayOfMonth(1).minusMonths(month);
164
		LocalDate currentMonthStart = LocalDate.now().withDayOfMonth(1).minusMonths(month);
164
 
165
 
165
        LocalDate yesterDate = LocalDate.now().minusDays(1);
166
		LocalDate yesterDate = LocalDate.now().minusDays(1);
166
        PartnerDailyInvestment yesterdayInvestment = partnerDailyInvestmentRepository.select(fofoId, yesterDate);
167
		PartnerDailyInvestment yesterdayInvestment = partnerDailyInvestmentRepository.select(fofoId, yesterDate);
167
        if (yesterdayInvestment == null) {
168
		if (yesterdayInvestment == null) {
168
            yesterdayInvestment = new PartnerDailyInvestment();
169
			yesterdayInvestment = new PartnerDailyInvestment();
169
        }
170
		}
170
 
171
 
171
        List<PartnerDailyInvestment> currentMonthInvestments = partnerDailyInvestmentRepository.selectAll(fofoId, currentMonthStart, currentMonthStart.withDayOfMonth(currentMonthStart.lengthOfMonth()));
172
		List<PartnerDailyInvestment> currentMonthInvestments = partnerDailyInvestmentRepository.selectAll(fofoId,
172
 
173
				currentMonthStart, currentMonthStart.withDayOfMonth(currentMonthStart.lengthOfMonth()));
173
        long okInvestmentDays = currentMonthInvestments.stream().filter(x -> x.getShortPercentage() <= 10).collect(Collectors.counting());
174
 
174
        investments.put("today", investment.getTotalInvestment());
175
		long okInvestmentDays = currentMonthInvestments.stream().filter(x -> x.getShortPercentage() <= 10)
175
        investments.put("investment", investment);
176
				.collect(Collectors.counting());
176
        investments.put("inStock", investment.getInStockAmount());
177
		investments.put("today", investment.getTotalInvestment());
177
        investments.put("minimum", investment.getMinInvestmentString());
178
		investments.put("investment", investment);
178
        investments.put("short", investment.getShortPercentage());
179
		investments.put("inStock", investment.getInStockAmount());
179
        investments.put("activated_stock", investment.getActivatedStockAmount());
180
		investments.put("minimum", investment.getMinInvestmentString());
180
        investments.put("okDays", okInvestmentDays);
181
		investments.put("short", investment.getShortPercentage());
181
        return investments;
182
		investments.put("activated_stock", investment.getActivatedStockAmount());
182
    }
183
		investments.put("okDays", okInvestmentDays);
183
 
184
		return investments;
184
    public ChartModel getLmsLineChart(int fofoId) throws ProfitMandiBusinessException {
185
	}
185
 
186
 
186
        LocalDateTime curDate = LocalDate.now().atStartOfDay();
187
	public ChartModel getLmsLineChart(int fofoId) throws ProfitMandiBusinessException {
187
        Map<String, Map<YearMonth, Double>> brandMonthValue = new HashMap<>();
188
 
188
        Map<YearMonth, Map<String, Double>> monthValueMap = new HashMap<>();
189
		LocalDateTime curDate = LocalDate.now().atStartOfDay();
189
 
190
		Map<String, Map<YearMonth, Double>> brandMonthValue = new HashMap<>();
190
        Map<String, Double> lmsBrandWiseSale = null;
191
		Map<YearMonth, Map<String, Double>> monthValueMap = new HashMap<>();
191
 
192
 
192
        for (int i = 0; i <= 6; i++) {
193
		Map<String, Double> lmsBrandWiseSale = null;
193
 
194
 
194
            LocalDateTime startOfMonth = curDate.withDayOfMonth(1).minusMonths(i);
195
		for (int i = 0; i <= 6; i++) {
195
 
196
 
196
            LOGGER.info("startOfMonth" + startOfMonth);
197
			LocalDateTime startOfMonth = curDate.withDayOfMonth(1).minusMonths(i);
197
 
198
 
198
            lmsBrandWiseSale = fofoOrderItemRepository.selectSumAmountGroupByBrand(
199
			LOGGER.info("startOfMonth" + startOfMonth);
199
                    curDate.withDayOfMonth(1).minusMonths(i), curDate.withDayOfMonth(1).minusMonths(i - 1), fofoId);
200
 
200
 
201
			lmsBrandWiseSale = fofoOrderItemRepository.selectSumAmountGroupByBrand(
201
            Map<Integer, Double> accesorieslmsSale = fofoOrderRepository.selectSumSaleGroupByFofoIdsForMobileOrAccessories(fofoId, curDate.withDayOfMonth(1).minusMonths(i), curDate.withDayOfMonth(1).minusMonths(i - 1), Optional.of(false));
202
					curDate.withDayOfMonth(1).minusMonths(i), curDate.withDayOfMonth(1).minusMonths(i - 1), fofoId);
202
            LOGGER.info("lmsBrandWiseSale" + lmsBrandWiseSale);
203
 
203
 
204
			Map<Integer, Double> accesorieslmsSale = fofoOrderRepository
204
            lmsBrandWiseSale.put("Accessories", accesorieslmsSale.get(fofoId));
205
					.selectSumSaleGroupByFofoIdsForMobileOrAccessories(fofoId, curDate.withDayOfMonth(1).minusMonths(i),
205
 
206
							curDate.withDayOfMonth(1).minusMonths(i - 1), Optional.of(false));
206
            monthValueMap.put(YearMonth.from(startOfMonth), lmsBrandWiseSale);
207
			LOGGER.info("lmsBrandWiseSale" + lmsBrandWiseSale);
207
            for (Entry<String, Double> lbw : lmsBrandWiseSale.entrySet()) {
208
 
208
                Map<YearMonth, Double> yearMonthValue = new HashMap<>();
209
			lmsBrandWiseSale.put("Accessories", accesorieslmsSale.get(fofoId));
209
                if (brandMonthValue.containsKey(lbw.getKey())) {
210
 
210
                    yearMonthValue = brandMonthValue.get(lbw.getKey());
211
			monthValueMap.put(YearMonth.from(startOfMonth), lmsBrandWiseSale);
211
                    yearMonthValue.put(YearMonth.from(startOfMonth), lbw.getValue());
212
			for (Entry<String, Double> lbw : lmsBrandWiseSale.entrySet()) {
212
                } else {
213
				Map<YearMonth, Double> yearMonthValue = new HashMap<>();
213
 
214
				if (brandMonthValue.containsKey(lbw.getKey())) {
214
                    yearMonthValue.put(YearMonth.from(startOfMonth), lbw.getValue());
215
					yearMonthValue = brandMonthValue.get(lbw.getKey());
215
 
216
					yearMonthValue.put(YearMonth.from(startOfMonth), lbw.getValue());
216
                }
217
				} else {
217
                brandMonthValue.put(lbw.getKey(), yearMonthValue);
218
 
218
 
219
					yearMonthValue.put(YearMonth.from(startOfMonth), lbw.getValue());
219
            }
220
 
220
 
221
				}
221
        }
222
				brandMonthValue.put(lbw.getKey(), yearMonthValue);
222
 
223
 
223
        LOGGER.info("brandMonthValue" + brandMonthValue);
224
			}
224
 
225
 
225
        Map<String, List<Double>> sortedBrandValue = new LinkedHashMap<>();
226
		}
226
 
227
 
227
        for (String brand : brands) {
228
		LOGGER.info("brandMonthValue" + brandMonthValue);
228
            Map<YearMonth, Double> yearMonthValue = brandMonthValue.get(brand);
229
 
229
            for (int i = 6; i >= 0; i--) {
230
		Map<String, List<Double>> sortedBrandValue = new LinkedHashMap<>();
230
 
231
 
231
                LocalDateTime startMonth = curDate.withDayOfMonth(1).minusMonths(i);
232
		for (String brand : brands) {
232
                LOGGER.info("startMonth" + startMonth);
233
			Map<YearMonth, Double> yearMonthValue = brandMonthValue.get(brand);
233
 
234
			for (int i = 6; i >= 0; i--) {
234
                if (yearMonthValue != null) {
235
 
235
                    if (yearMonthValue.get(YearMonth.from(startMonth)) == null) {
236
				LocalDateTime startMonth = curDate.withDayOfMonth(1).minusMonths(i);
236
                        yearMonthValue.put(YearMonth.from(startMonth), 0.0);
237
				LOGGER.info("startMonth" + startMonth);
237
                    }
238
 
238
 
239
				if (yearMonthValue != null) {
239
                } else {
240
					if (yearMonthValue.get(YearMonth.from(startMonth)) == null) {
240
                    yearMonthValue = new HashMap<>();
241
						yearMonthValue.put(YearMonth.from(startMonth), 0.0);
241
                    yearMonthValue.put(YearMonth.from(startMonth), 0.0);
242
					}
242
                }
243
 
243
            }
244
				} else {
244
 
245
					yearMonthValue = new HashMap<>();
245
            Map<YearMonth, Double> sortedMonthBrandValue = new TreeMap<>(yearMonthValue);
246
					yearMonthValue.put(YearMonth.from(startMonth), 0.0);
246
 
247
				}
247
            brandMonthValue.put(brand, sortedMonthBrandValue);
248
			}
248
 
249
 
249
            sortedBrandValue.put(brand, sortedMonthBrandValue.values().stream().collect(Collectors.toList()));
250
			Map<YearMonth, Double> sortedMonthBrandValue = new TreeMap<>(yearMonthValue);
250
 
251
 
251
        }
252
			brandMonthValue.put(brand, sortedMonthBrandValue);
252
 
253
 
253
        LOGGER.info("brandMonthValue" + brandMonthValue);
254
			sortedBrandValue.put(brand, sortedMonthBrandValue.values().stream().collect(Collectors.toList()));
254
 
255
 
255
        LOGGER.info("sortedBrandValue" + sortedBrandValue);
256
		}
256
 
257
 
257
        ChartModel cm = chartService.createChart(6, sortedBrandValue, colorList, borderList, "Brand Wise LMS");
258
		LOGGER.info("brandMonthValue" + brandMonthValue);
258
 
259
 
259
        return cm;
260
		LOGGER.info("sortedBrandValue" + sortedBrandValue);
260
 
261
 
261
    }
262
		ChartModel cm = chartService.createChart(6, sortedBrandValue, colorList, borderList, "Brand Wise LMS");
262
 
263
 
263
    public ChartModel getPurchaseOrderChart(int fofoId) throws ProfitMandiBusinessException {
264
		return cm;
264
 
265
 
265
        LocalDateTime curDate = LocalDate.now().atStartOfDay();
266
	}
266
 
267
 
267
        LOGGER.info("startMonth" + curDate.withDayOfMonth(1).minusMonths(6));
268
	public ChartModel getPurchaseOrderChart(int fofoId) throws ProfitMandiBusinessException {
268
 
269
 
269
        LocalDateTime startOfMonth = curDate.withDayOfMonth(1).minusMonths(1);
270
		LocalDateTime curDate = LocalDate.now().atStartOfDay();
270
        List<BrandWiseModel> soblms = orderRepository.selectAllBilledOrderGroupByBrandFofoId(fofoId, curDate.withDayOfMonth(1).minusMonths(6));
271
 
271
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("MM-yyyy");
272
		LOGGER.info("startMonth" + curDate.withDayOfMonth(1).minusMonths(6));
272
        Map<String, Map<YearMonth, Double>> brandMonthValue = new HashMap<>();
273
 
273
        for (BrandWiseModel bwl : soblms) {
274
		LocalDateTime startOfMonth = curDate.withDayOfMonth(1).minusMonths(1);
274
            Map<YearMonth, Double> yearMonthValue = new HashMap<>();
275
		List<BrandWiseModel> soblms = orderRepository.selectAllBilledOrderGroupByBrandFofoId(fofoId,
275
            if (brandMonthValue.containsKey(bwl.getBrand())) {
276
				curDate.withDayOfMonth(1).minusMonths(6));
276
                yearMonthValue = brandMonthValue.get(bwl.getBrand());
277
		DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("MM-yyyy");
277
                yearMonthValue.put(YearMonth.parse(bwl.getYearMonth(), dateTimeFormatter), (double) bwl.getAmount());
278
		Map<String, Map<YearMonth, Double>> brandMonthValue = new HashMap<>();
278
            } else {
279
		for (BrandWiseModel bwl : soblms) {
279
 
280
			Map<YearMonth, Double> yearMonthValue = new HashMap<>();
280
                yearMonthValue.put(YearMonth.parse(bwl.getYearMonth(), dateTimeFormatter), (double) bwl.getAmount());
281
			if (brandMonthValue.containsKey(bwl.getBrand())) {
281
 
282
				yearMonthValue = brandMonthValue.get(bwl.getBrand());
282
            }
283
				yearMonthValue.put(YearMonth.parse(bwl.getYearMonth(), dateTimeFormatter), (double) bwl.getAmount());
283
            brandMonthValue.put(bwl.getBrand(), yearMonthValue);
284
			} else {
284
 
285
 
285
        }
286
				yearMonthValue.put(YearMonth.parse(bwl.getYearMonth(), dateTimeFormatter), (double) bwl.getAmount());
286
        LOGGER.info("soblms" + brandMonthValue);
287
 
287
 
288
			}
288
        Map<String, List<Double>> sortedBrandValue = new LinkedHashMap<>();
289
			brandMonthValue.put(bwl.getBrand(), yearMonthValue);
289
 
290
 
290
        for (String brand : brands) {
291
		}
291
            Map<YearMonth, Double> yearMonthValue = brandMonthValue.get(brand);
292
		LOGGER.info("soblms" + brandMonthValue);
292
            for (int i = 6; i >= 0; i--) {
293
 
293
 
294
		Map<String, List<Double>> sortedBrandValue = new LinkedHashMap<>();
294
                LocalDateTime startMonth = curDate.withDayOfMonth(1).minusMonths(i);
295
 
295
 
296
		for (String brand : brands) {
296
                if (yearMonthValue != null) {
297
			Map<YearMonth, Double> yearMonthValue = brandMonthValue.get(brand);
297
                    if (yearMonthValue.get(YearMonth.from(startMonth)) == null) {
298
			for (int i = 6; i >= 0; i--) {
298
                        yearMonthValue.put(YearMonth.from(startMonth), 0.0);
299
 
299
                    }
300
				LocalDateTime startMonth = curDate.withDayOfMonth(1).minusMonths(i);
300
 
301
 
301
                } else {
302
				if (yearMonthValue != null) {
302
                    yearMonthValue = new HashMap<>();
303
					if (yearMonthValue.get(YearMonth.from(startMonth)) == null) {
303
                    yearMonthValue.put(YearMonth.from(startMonth), 0.0);
304
						yearMonthValue.put(YearMonth.from(startMonth), 0.0);
304
                }
305
					}
305
            }
306
 
306
 
307
				} else {
307
            Map<YearMonth, Double> sortedMonthBrandValue = new TreeMap<>(yearMonthValue);
308
					yearMonthValue = new HashMap<>();
308
 
309
					yearMonthValue.put(YearMonth.from(startMonth), 0.0);
309
            brandMonthValue.put(brand, sortedMonthBrandValue);
310
				}
310
 
311
			}
311
            sortedBrandValue.put(brand, sortedMonthBrandValue.values().stream().collect(Collectors.toList()));
312
 
312
 
313
			Map<YearMonth, Double> sortedMonthBrandValue = new TreeMap<>(yearMonthValue);
313
        }
314
 
314
 
315
			brandMonthValue.put(brand, sortedMonthBrandValue);
315
        LOGGER.info("brandMonthValue" + brandMonthValue);
316
 
316
 
317
			sortedBrandValue.put(brand, sortedMonthBrandValue.values().stream().collect(Collectors.toList()));
317
        ChartModel cm = chartService.createChart(6, sortedBrandValue, colorList, borderList, "Brand Wise Monthly Purchase");
318
 
318
 
319
		}
319
        return cm;
320
 
320
 
321
		LOGGER.info("brandMonthValue" + brandMonthValue);
321
    }
322
 
322
 
323
		ChartModel cm = chartService.createChart(6, sortedBrandValue, colorList, borderList,
323
    public Map<String, Object> getSales(int fofoId) {
324
				"Brand Wise Monthly Purchase");
324
 
325
 
325
        Map<String, Object> salesMap = new LinkedHashMap<>();
326
		return cm;
326
        LocalDateTime now = LocalDateTime.now();
327
 
327
        LocalDateTime startOfToday = LocalDate.now().atStartOfDay();
328
	}
328
        int monthLength = LocalDate.now().lengthOfMonth();
329
 
329
        int daysGone = now.getDayOfMonth() - 1;
330
	public Map<String, Object> getSales(int fofoId) {
330
        int daysRemaining = monthLength - daysGone;
331
 
331
        Double todaySale = fofoOrderItemRepository.selectSumMopGroupByRetailer(startOfToday, now, fofoId, false).get(fofoId);
332
		Map<String, Object> salesMap = new LinkedHashMap<>();
332
        Double mtdSaleTillYesterDay = fofoOrderItemRepository.selectSumMopGroupByRetailer(startOfToday.withDayOfMonth(1), startOfToday, fofoId, false).get(fofoId);
333
		LocalDateTime now = LocalDateTime.now();
333
        Double mtdSale = mtdSaleTillYesterDay + todaySale;
334
		LocalDateTime startOfToday = LocalDate.now().atStartOfDay();
334
        Double lmtdSale = fofoOrderItemRepository.selectSumMopGroupByRetailer(
335
		int monthLength = LocalDate.now().lengthOfMonth();
335
                startOfToday.withDayOfMonth(1).minusMonths(1), now.minusMonths(1), fofoId, false).get(fofoId);
336
		int daysGone = now.getDayOfMonth() - 1;
336
 
337
		int daysRemaining = monthLength - daysGone;
337
        List<PartnerTargetDetails> partnerTargetDetails = partnerTargetRepository.selectAllGeEqAndLeEqStartDateAndEndDate(LocalDateTime.now());
338
		Double todaySale = fofoOrderItemRepository.selectSumMopGroupByRetailer(startOfToday, now, fofoId, false)
338
        if (partnerTargetDetails.isEmpty()) {
339
				.get(fofoId);
339
            partnerTargetDetails = partnerTargetRepository.selectAllGeEqAndLeEqStartDateAndEndDate(LocalDateTime.now().minusMonths(3));
340
		Double mtdSaleTillYesterDay = fofoOrderItemRepository
340
        }
341
				.selectSumMopGroupByRetailer(startOfToday.withDayOfMonth(1), startOfToday, fofoId, false).get(fofoId);
341
 
342
		Double mtdSale = mtdSaleTillYesterDay + todaySale;
342
        PartnerType partnerType = partnerTypeChangeService.getTypeOnDate(fofoId, LocalDate.now());
343
		Double lmtdSale = fofoOrderItemRepository.selectSumMopGroupByRetailer(
343
 
344
				startOfToday.withDayOfMonth(1).minusMonths(1), now.minusMonths(1), fofoId, false).get(fofoId);
344
        int currentRate = 0;
345
 
345
        if (mtdSaleTillYesterDay > 0) {
346
		List<PartnerTargetDetails> partnerTargetDetails = partnerTargetRepository
346
            currentRate = (int) (mtdSaleTillYesterDay / daysGone);
347
				.selectAllGeEqAndLeEqStartDateAndEndDate(LocalDateTime.now());
347
        }
348
		if (partnerTargetDetails.isEmpty()) {
348
 
349
			partnerTargetDetails = partnerTargetRepository
349
        salesMap.put("requiredType", partnerType.next());
350
					.selectAllGeEqAndLeEqStartDateAndEndDate(LocalDateTime.now().minusMonths(3));
350
        float reqdAmount = partnerTypeChangeService.getMinimumAmount(partnerType.next());
351
		}
351
        int requiredRate = (int) ((reqdAmount - mtdSaleTillYesterDay) / daysRemaining);
352
 
352
        if (partnerType.equals(PartnerType.PLATINUM) && requiredRate < currentRate) {
353
		PartnerType partnerType = partnerTypeChangeService.getTypeOnDate(fofoId, LocalDate.now());
353
            requiredRate = currentRate;
354
 
354
        }
355
		int currentRate = 0;
355
        salesMap.put("requiredRate", requiredRate);
356
		if (mtdSaleTillYesterDay > 0) {
356
        salesMap.put("requiredTypeImage", PartnerType.imageMap.get(partnerType.next()));
357
			currentRate = (int) (mtdSaleTillYesterDay / daysGone);
357
 
358
		}
358
        salesMap.put("todaySale", todaySale == null ? 0 : todaySale);
359
 
359
        salesMap.put("mtdSale", mtdSale == null ? 0 : mtdSale);
360
		salesMap.put("requiredType", partnerType.next());
360
        salesMap.put("lmtdSale", lmtdSale == null ? 0 : lmtdSale);
361
		float reqdAmount = partnerTypeChangeService.getMinimumAmount(partnerType.next());
361
 
362
		int requiredRate = (int) ((reqdAmount - mtdSaleTillYesterDay) / daysRemaining);
362
        PartnerType currentType = partnerTypeChangeService.getPartnerTypeByAmount(currentRate * monthLength);
363
		if (partnerType.equals(PartnerType.PLATINUM) && requiredRate < currentRate) {
363
        salesMap.put("currentRate", currentRate);
364
			requiredRate = currentRate;
364
        salesMap.put("currentType", currentType);
365
		}
365
        salesMap.put("currentTypeImage", PartnerType.imageMap.get(currentType));
366
		salesMap.put("requiredRate", requiredRate);
366
        return salesMap;
367
		salesMap.put("requiredTypeImage", PartnerType.imageMap.get(partnerType.next()));
367
    }
368
 
368
 
369
		salesMap.put("todaySale", todaySale == null ? 0 : todaySale);
369
    public ChartModel getBrandChart(int fofoId) {
370
		salesMap.put("mtdSale", mtdSale == null ? 0 : mtdSale);
370
 
371
		salesMap.put("lmtdSale", lmtdSale == null ? 0 : lmtdSale);
371
        LocalDateTime curDate = LocalDate.now().atStartOfDay();
372
 
372
 
373
		PartnerType currentType = partnerTypeChangeService.getPartnerTypeByAmount(currentRate * monthLength);
373
        LOGGER.info("cur Date" + curDate.withDayOfMonth(1));
374
		salesMap.put("currentRate", currentRate);
374
 
375
		salesMap.put("currentType", currentType);
375
        LOGGER.info("curDateYear" + curDate.with(LocalTime.MAX));
376
		salesMap.put("currentTypeImage", PartnerType.imageMap.get(currentType));
376
 
377
		return salesMap;
377
        Map<String, Double> brandwisesale = fofoOrderItemRepository.selectSumAmountGroupByBrand(curDate.withDayOfMonth(1), curDate.with(LocalTime.MAX), fofoId);
378
	}
378
 
379
 
379
        LOGGER.info("brandwisesale" + brandwisesale);
380
	public ChartModel getBrandChart(int fofoId) {
380
 
381
 
381
        Map<Integer, Double> accesoriesmtdsale = fofoOrderRepository.selectSumSaleGroupByFofoIdsForMobileOrAccessories(
382
		LocalDateTime curDate = LocalDate.now().atStartOfDay();
382
                fofoId, curDate.withDayOfMonth(1), curDate.with(LocalTime.MAX), Optional.of(false));
383
 
383
        brandwisesale.put("Accessories", accesoriesmtdsale.get(fofoId));
384
		LOGGER.info("cur Date" + curDate.withDayOfMonth(1));
384
 
385
 
385
        Map<String, Double> activatedImeisWithSellingPriceMTD = fofoOrderRepository.selectValueOfActivatedImeis(curDate.withDayOfMonth(1), curDate.with(LocalTime.MAX), fofoId).stream().collect(Collectors.toMap(x -> x.getBrand(), x -> (double) x.getSellingPrice()));
386
		LOGGER.info("curDateYear" + curDate.with(LocalTime.MAX));
386
 
387
 
387
        activatedImeisWithSellingPriceMTD.put("Lava", brandwisesale.get("Lava"));
388
		Map<String, Double> brandwisesale = fofoOrderItemRepository
388
 
389
				.selectSumAmountGroupByBrand(curDate.withDayOfMonth(1), curDate.with(LocalTime.MAX), fofoId);
389
        Map<String, Double> activatedImeisWithSellingPriceLMTD = fofoOrderRepository.selectValueOfActivatedImeis(curDate.withDayOfMonth(1).minusMonths(1), curDate.with(LocalTime.MAX).minusMonths(1), fofoId).stream().collect(Collectors.toMap(x -> x.getBrand(), x -> (double) x.getSellingPrice()));
390
 
390
        Map<String, Double> lmtdBrandWiseSale = fofoOrderItemRepository.selectSumAmountGroupByBrand(
391
		LOGGER.info("brandwisesale" + brandwisesale);
391
                curDate.withDayOfMonth(1).minusMonths(1), curDate.with(LocalTime.MAX).minusMonths(1), fofoId);
392
 
392
        activatedImeisWithSellingPriceLMTD.put("Lava", lmtdBrandWiseSale.get("Lava"));
393
		Map<Integer, Double> accesoriesmtdsale = fofoOrderRepository.selectSumSaleGroupByFofoIdsForMobileOrAccessories(
393
 
394
				fofoId, curDate.withDayOfMonth(1), curDate.with(LocalTime.MAX), Optional.of(false));
394
        Map<Integer, Double> accesorieslmtdsale = fofoOrderRepository.selectSumSaleGroupByFofoIdsForMobileOrAccessories(
395
		brandwisesale.put("Accessories", accesoriesmtdsale.get(fofoId));
395
                fofoId, curDate.withDayOfMonth(1).minusMonths(1), curDate.with(LocalTime.MAX).minusMonths(1), Optional.of(false));
396
 
396
 
397
		Map<String, Double> activatedImeisWithSellingPriceMTD = fofoOrderRepository
397
        lmtdBrandWiseSale.put("Accessories", accesorieslmtdsale.get(fofoId));
398
				.selectValueOfActivatedImeis(curDate.withDayOfMonth(1), curDate.with(LocalTime.MAX), fofoId).stream()
398
 
399
				.collect(Collectors.toMap(x -> x.getBrand(), x -> (double) x.getSellingPrice()));
399
        ChartModel cm = new ChartModel();
400
 
400
 
401
		activatedImeisWithSellingPriceMTD.put("Lava", brandwisesale.get("Lava"));
401
        HashSet<String> labels = new HashSet<String>();
402
 
402
        labels.addAll(brandwisesale.keySet());
403
		Map<String, Double> activatedImeisWithSellingPriceLMTD = fofoOrderRepository
403
        labels.addAll(lmtdBrandWiseSale.keySet());
404
				.selectValueOfActivatedImeis(curDate.withDayOfMonth(1).minusMonths(1),
404
 
405
						curDate.with(LocalTime.MAX).minusMonths(1), fofoId)
405
        List<String> labelList = new ArrayList<>(labels);
406
				.stream().collect(Collectors.toMap(x -> x.getBrand(), x -> (double) x.getSellingPrice()));
406
 
407
		Map<String, Double> lmtdBrandWiseSale = fofoOrderItemRepository.selectSumAmountGroupByBrand(
407
        List<Double> mtdActivatedImeisValues = new ArrayList<>();
408
				curDate.withDayOfMonth(1).minusMonths(1), curDate.with(LocalTime.MAX).minusMonths(1), fofoId);
408
 
409
		activatedImeisWithSellingPriceLMTD.put("Lava", lmtdBrandWiseSale.get("Lava"));
409
        List<Double> mtdValues = new ArrayList<>();
410
 
410
        List<Double> lmtdUnActivatedImeisValues = new ArrayList<>();
411
		Map<Integer, Double> accesorieslmtdsale = fofoOrderRepository.selectSumSaleGroupByFofoIdsForMobileOrAccessories(
411
        List<Double> lmtdActivatedImeisValues = new ArrayList<>();
412
				fofoId, curDate.withDayOfMonth(1).minusMonths(1), curDate.with(LocalTime.MAX).minusMonths(1),
412
        List<Double> mtdUnActivatedImeisValues = new ArrayList<>();
413
				Optional.of(false));
413
        List<Double> lmtdValues = new ArrayList<>();
414
 
414
        for (String label : labelList) {
415
		lmtdBrandWiseSale.put("Accessories", accesorieslmtdsale.get(fofoId));
415
            mtdActivatedImeisValues.add(activatedImeisWithSellingPriceMTD.get(label) == null ? 0 : activatedImeisWithSellingPriceMTD.get(label));
416
 
416
            lmtdActivatedImeisValues.add(activatedImeisWithSellingPriceLMTD.get(label) == null ? 0 : activatedImeisWithSellingPriceLMTD.get(label));
417
		ChartModel cm = new ChartModel();
417
 
418
 
418
            mtdValues.add(brandwisesale.get(label) == null ? 0 : brandwisesale.get(label));
419
		HashSet<String> labels = new HashSet<String>();
419
            if (brandwisesale.get(label) != null) {
420
		labels.addAll(brandwisesale.keySet());
420
                mtdUnActivatedImeisValues.add(brandwisesale.get(label) - (activatedImeisWithSellingPriceMTD.get(label) == null ? 0 : activatedImeisWithSellingPriceMTD.get(label)));
421
		labels.addAll(lmtdBrandWiseSale.keySet());
421
            } else {
422
 
422
                mtdUnActivatedImeisValues.add(0.0);
423
		List<String> labelList = new ArrayList<>(labels);
423
            }
424
 
424
            if (lmtdBrandWiseSale.get(label) != null) {
425
		List<Double> mtdActivatedImeisValues = new ArrayList<>();
425
                lmtdUnActivatedImeisValues.add(lmtdBrandWiseSale.get(label) - (activatedImeisWithSellingPriceLMTD.get(label) == null ? 0 : activatedImeisWithSellingPriceLMTD.get(label)));
426
 
426
            } else {
427
		List<Double> mtdValues = new ArrayList<>();
427
                lmtdUnActivatedImeisValues.add(0.0);
428
		List<Double> lmtdUnActivatedImeisValues = new ArrayList<>();
428
            }
429
		List<Double> lmtdActivatedImeisValues = new ArrayList<>();
429
 
430
		List<Double> mtdUnActivatedImeisValues = new ArrayList<>();
430
            lmtdValues.add(lmtdBrandWiseSale.get(label) == null ? 0 : lmtdBrandWiseSale.get(label));
431
		List<Double> lmtdValues = new ArrayList<>();
431
        }
432
		for (String label : labelList) {
432
        DatasetModel dsmtotal = new DatasetModel();
433
			mtdActivatedImeisValues.add(activatedImeisWithSellingPriceMTD.get(label) == null ? 0
433
        dsmtotal.setLabel("MTD");
434
					: activatedImeisWithSellingPriceMTD.get(label));
434
        dsmtotal.setBackgroundColor("blue");
435
			lmtdActivatedImeisValues.add(activatedImeisWithSellingPriceLMTD.get(label) == null ? 0
435
        dsmtotal.setBorderColor("blue");
436
					: activatedImeisWithSellingPriceLMTD.get(label));
436
        dsmtotal.setData(mtdValues);
437
 
437
        dsmtotal.setStack("stack0");
438
			mtdValues.add(brandwisesale.get(label) == null ? 0 : brandwisesale.get(label));
438
        dsmtotal.setOrder(1);
439
			if (brandwisesale.get(label) != null) {
439
 
440
				mtdUnActivatedImeisValues
440
        DatasetModel dsmUnactivated = new DatasetModel();
441
						.add(brandwisesale.get(label) - (activatedImeisWithSellingPriceMTD.get(label) == null ? 0
441
        dsmUnactivated.setLabel("MTD Unactivated");
442
								: activatedImeisWithSellingPriceMTD.get(label)));
442
        dsmUnactivated.setBackgroundColor("red");
443
			} else {
443
        dsmUnactivated.setBorderColor("red");
444
				mtdUnActivatedImeisValues.add(0.0);
444
        dsmUnactivated.setData(mtdUnActivatedImeisValues);
445
			}
445
        dsmUnactivated.setStack("stack0");
446
			if (lmtdBrandWiseSale.get(label) != null) {
446
        dsmUnactivated.setOrder(1);
447
				lmtdUnActivatedImeisValues
447
 
448
						.add(lmtdBrandWiseSale.get(label) - (activatedImeisWithSellingPriceLMTD.get(label) == null ? 0
448
        LOGGER.info("mtdValuesMoney" + mtdValues);
449
								: activatedImeisWithSellingPriceLMTD.get(label)));
449
 
450
			} else {
450
        DatasetModel mtdActivatedImeis = new DatasetModel();
451
				lmtdUnActivatedImeisValues.add(0.0);
451
        mtdActivatedImeis.setLabel("MTD Activation");
452
			}
452
        mtdActivatedImeis.setBorderColor("#00008b");
453
 
453
        mtdActivatedImeis.setData(mtdActivatedImeisValues);
454
			lmtdValues.add(lmtdBrandWiseSale.get(label) == null ? 0 : lmtdBrandWiseSale.get(label));
454
        mtdActivatedImeis.setBackgroundColor("#00008b");
455
		}
455
        mtdActivatedImeis.setStack("stack0");
456
		DatasetModel dsmtotal = new DatasetModel();
456
        mtdActivatedImeis.setOrder(1);
457
		dsmtotal.setLabel("MTD");
457
 
458
		dsmtotal.setBackgroundColor("blue");
458
        DatasetModel lmtddsmtotal = new DatasetModel();
459
		dsmtotal.setBorderColor("blue");
459
        lmtddsmtotal.setLabel("LMTD");
460
		dsmtotal.setData(mtdValues);
460
        lmtddsmtotal.setBackgroundColor("blue");
461
		dsmtotal.setStack("stack0");
461
        lmtddsmtotal.setData(lmtdValues);
462
		dsmtotal.setOrder(1);
462
        lmtddsmtotal.setBorderColor("blue");
463
 
463
        lmtddsmtotal.setStack("stack1");
464
		DatasetModel dsmUnactivated = new DatasetModel();
464
        lmtddsmtotal.setOrder(1);
465
		dsmUnactivated.setLabel("MTD Unactivated");
465
 
466
		dsmUnactivated.setBackgroundColor("red");
466
        DatasetModel lmtdUnActivated = new DatasetModel();
467
		dsmUnactivated.setBorderColor("red");
467
        lmtdUnActivated.setLabel("LMTD Unactivation");
468
		dsmUnactivated.setData(mtdUnActivatedImeisValues);
468
        lmtdUnActivated.setBackgroundColor("red");
469
		dsmUnactivated.setStack("stack0");
469
        lmtdUnActivated.setBorderColor("red");
470
		dsmUnactivated.setOrder(1);
470
        lmtdUnActivated.setData(lmtdUnActivatedImeisValues);
471
 
471
        lmtdUnActivated.setStack("stack1");
472
		LOGGER.info("mtdValuesMoney" + mtdValues);
472
        lmtdUnActivated.setOrder(1);
473
 
473
 
474
		DatasetModel mtdActivatedImeis = new DatasetModel();
474
        DatasetModel LmtdActivatedImeis = new DatasetModel();
475
		mtdActivatedImeis.setLabel("MTD Activation");
475
        LmtdActivatedImeis.setLabel("LMTD Activation");
476
		mtdActivatedImeis.setBorderColor("#00008b");
476
        LmtdActivatedImeis.setBackgroundColor("#87ceeb");
477
		mtdActivatedImeis.setData(mtdActivatedImeisValues);
477
        LmtdActivatedImeis.setBorderColor("#87ceeb");
478
		mtdActivatedImeis.setBackgroundColor("#00008b");
478
        LmtdActivatedImeis.setData(lmtdActivatedImeisValues);
479
		mtdActivatedImeis.setStack("stack0");
479
        LmtdActivatedImeis.setStack("stack1");
480
		mtdActivatedImeis.setOrder(1);
480
        LmtdActivatedImeis.setOrder(1);
481
 
481
 
482
		DatasetModel lmtddsmtotal = new DatasetModel();
482
        DatasetModel linemtdChart = new DatasetModel();
483
		lmtddsmtotal.setLabel("LMTD");
483
        linemtdChart.setLabel("MTD");
484
		lmtddsmtotal.setBackgroundColor("blue");
484
        linemtdChart.setBackgroundColor("#006400");
485
		lmtddsmtotal.setData(lmtdValues);
485
        linemtdChart.setBorderColor("#006400");
486
		lmtddsmtotal.setBorderColor("blue");
486
        linemtdChart.setData(mtdValues);
487
		lmtddsmtotal.setStack("stack1");
487
        linemtdChart.setType("line");
488
		lmtddsmtotal.setOrder(1);
488
        linemtdChart.setOrder(2);
489
 
489
        linemtdChart.setFill("false");
490
		DatasetModel lmtdUnActivated = new DatasetModel();
490
 
491
		lmtdUnActivated.setLabel("LMTD Unactivation");
491
        DatasetModel lineLmtdChart = new DatasetModel();
492
		lmtdUnActivated.setBackgroundColor("red");
492
        lineLmtdChart.setLabel("LMTD");
493
		lmtdUnActivated.setBorderColor("red");
493
        lineLmtdChart.setBackgroundColor("hotpink");
494
		lmtdUnActivated.setData(lmtdUnActivatedImeisValues);
494
        lineLmtdChart.setBorderColor("hotpink");
495
		lmtdUnActivated.setStack("stack1");
495
        lineLmtdChart.setData(lmtdValues);
496
		lmtdUnActivated.setOrder(1);
496
        lineLmtdChart.setType("line");
497
 
497
        lineLmtdChart.setOrder(3);
498
		DatasetModel LmtdActivatedImeis = new DatasetModel();
498
        lineLmtdChart.setFill("false");
499
		LmtdActivatedImeis.setLabel("LMTD Activation");
499
 
500
		LmtdActivatedImeis.setBackgroundColor("#87ceeb");
500
        List<DatasetModel> datasets = new ArrayList<>();
501
		LmtdActivatedImeis.setBorderColor("#87ceeb");
501
        datasets.add(mtdActivatedImeis);
502
		LmtdActivatedImeis.setData(lmtdActivatedImeisValues);
502
        datasets.add(dsmUnactivated);
503
		LmtdActivatedImeis.setStack("stack1");
503
        datasets.add(LmtdActivatedImeis);
504
		LmtdActivatedImeis.setOrder(1);
504
        datasets.add(lmtdUnActivated);
505
 
505
        datasets.add(linemtdChart);
506
		DatasetModel linemtdChart = new DatasetModel();
506
        datasets.add(lineLmtdChart);
507
		linemtdChart.setLabel("MTD");
507
 
508
		linemtdChart.setBackgroundColor("#006400");
508
        DataModel dm = new DataModel();
509
		linemtdChart.setBorderColor("#006400");
509
        dm.setDatasets(datasets);
510
		linemtdChart.setData(mtdValues);
510
        dm.setLabels(labels);
511
		linemtdChart.setType("line");
511
 
512
		linemtdChart.setOrder(2);
512
        Tooltips tooltips = new Tooltips();
513
		linemtdChart.setFill("false");
513
        tooltips.setBodyFontSize(10);
514
 
514
        tooltips.setTitleFontSize(10);
515
		DatasetModel lineLmtdChart = new DatasetModel();
515
        tooltips.setMode("index");
516
		lineLmtdChart.setLabel("LMTD");
516
        tooltips.setIntersect(false);
517
		lineLmtdChart.setBackgroundColor("hotpink");
517
        tooltips.setBackgroundColor("rgba(0, 0, 0, .5)");
518
		lineLmtdChart.setBorderColor("hotpink");
518
        HoverModel hover = new HoverModel();
519
		lineLmtdChart.setData(lmtdValues);
519
        hover.setIntersect(false);
520
		lineLmtdChart.setType("line");
520
        hover.setMode("index");
521
		lineLmtdChart.setOrder(3);
521
 
522
		lineLmtdChart.setFill("false");
522
        LegendModel lm = new LegendModel();
523
 
523
        lm.setPosition("top");
524
		List<DatasetModel> datasets = new ArrayList<>();
524
 
525
		datasets.add(mtdActivatedImeis);
525
        TitleModel tm = new TitleModel();
526
		datasets.add(dsmUnactivated);
526
        tm.setText("Brand Wise Sales");
527
		datasets.add(LmtdActivatedImeis);
527
        tm.setDisplay(true);
528
		datasets.add(lmtdUnActivated);
528
        tm.setFontSize(20);
529
		datasets.add(linemtdChart);
529
        tm.setFontColor("#111");
530
		datasets.add(lineLmtdChart);
530
 
531
 
531
        List<Axis> xAxes = new ArrayList<>();
532
		DataModel dm = new DataModel();
532
        Axis xAxis = new Axis();
533
		dm.setDatasets(datasets);
533
        xAxis.setStacked(true);
534
		dm.setLabels(labels);
534
        xAxes.add(xAxis);
535
 
535
 
536
		Tooltips tooltips = new Tooltips();
536
        List<Axis> yAxes = new ArrayList<>();
537
		tooltips.setBodyFontSize(10);
537
        Axis yAxis = new Axis();
538
		tooltips.setTitleFontSize(10);
538
        yAxis.setStacked(false);
539
		tooltips.setMode("index");
539
        yAxes.add(yAxis);
540
		tooltips.setIntersect(false);
540
 
541
		tooltips.setBackgroundColor("rgba(0, 0, 0, .5)");
541
        ScalesModel sm = new ScalesModel();
542
		HoverModel hover = new HoverModel();
542
        sm.setxAxes(xAxes);
543
		hover.setIntersect(false);
543
 
544
		hover.setMode("index");
544
        OptionsModel om = new OptionsModel();
545
 
545
        om.setLegend(lm);
546
		LegendModel lm = new LegendModel();
546
        om.setTitle(tm);
547
		lm.setPosition("top");
547
        om.setScales(sm);
548
 
548
        om.setHover(hover);
549
		TitleModel tm = new TitleModel();
549
        om.setTooltips(tooltips);
550
		tm.setText("Brand Wise Sales");
550
 
551
		tm.setDisplay(true);
551
        cm.setType("bar");
552
		tm.setFontSize(20);
552
        cm.setData(dm);
553
		tm.setFontColor("#111");
553
        cm.setOptions(om);
554
 
554
 
555
		List<Axis> xAxes = new ArrayList<>();
555
        LOGGER.info("cm" + cm);
556
		Axis xAxis = new Axis();
556
 
557
		xAxis.setStacked(true);
557
        return cm;
558
		xAxes.add(xAxis);
558
 
559
 
559
    }
560
		List<Axis> yAxes = new ArrayList<>();
560
 
561
		Axis yAxis = new Axis();
561
    public ChartInvestmentModel getInvestmentChart(int fofoId) throws ProfitMandiBusinessException {
562
		yAxis.setStacked(false);
562
        PartnerDailyInvestment investment = partnerInvestmentService.getInvestment(fofoId, 0);
563
		yAxes.add(yAxis);
563
 
564
 
564
        Map<String, Float> investmentWalletAmount = new HashMap<>();
565
		ScalesModel sm = new ScalesModel();
565
        investmentWalletAmount.put("Wallet", investment.getWalletAmount());
566
		sm.setxAxes(xAxes);
566
        investmentWalletAmount.put("InStocks", investment.getInStockAmount() - investment.getActivatedStockAmount());
567
 
567
        investmentWalletAmount.put("Unbilled Order", investment.getUnbilledAmount());
568
		OptionsModel om = new OptionsModel();
568
        investmentWalletAmount.put("GrnPending", investment.getGrnPendingAmount() - investment.getActivatedGrnPendingAmount());
569
		om.setLegend(lm);
569
        investmentWalletAmount.put("ReturnInTransit", investment.getReturnInTransitAmount());
570
		om.setTitle(tm);
570
 
571
		om.setScales(sm);
571
        if (investment.getShortInvestment() > 0) {
572
		om.setHover(hover);
572
            investmentWalletAmount.put("Short Investment", investment.getShortInvestment());
573
		om.setTooltips(tooltips);
573
        }
574
 
574
 
575
		cm.setType("bar");
575
        ChartInvestmentModel cm = new ChartInvestmentModel();
576
		cm.setData(dm);
576
 
577
		cm.setOptions(om);
577
        HashSet<String> labels = new HashSet<String>();
578
 
578
        labels.addAll(investmentWalletAmount.keySet());
579
		LOGGER.info("cm" + cm);
579
 
580
 
580
        List<String> labelList = new ArrayList<>(labels);
581
		return cm;
581
        List<String> backgroundColor = new ArrayList<>();
582
 
582
        List<Float> values = new ArrayList<>();
583
	}
583
        for (String label : labelList) {
584
 
584
            values.add(investmentWalletAmount.get(label));
585
	public ChartInvestmentModel getInvestmentChart(int fofoId) throws ProfitMandiBusinessException {
585
            if (label.equals("Wallet")) {
586
		PartnerDailyInvestment investment = partnerInvestmentService.getInvestment(fofoId, 0);
586
                backgroundColor.add("pink");
587
 
587
            }
588
		Map<String, Float> investmentWalletAmount = new HashMap<>();
588
            if (label.equals("Short Investment")) {
589
		investmentWalletAmount.put("Wallet", investment.getWalletAmount());
589
                backgroundColor.add("red");
590
		investmentWalletAmount.put("InStocks", investment.getInStockAmount() - investment.getActivatedStockAmount());
590
            }
591
		investmentWalletAmount.put("Unbilled Order", investment.getUnbilledAmount());
591
            if (label.equals("InStocks")) {
592
		investmentWalletAmount.put("GrnPending", investment.getGrnPendingAmount() - investment.getActivatedGrnPendingAmount());
592
                backgroundColor.add("#9ACD32");
593
		investmentWalletAmount.put("ReturnInTransit", investment.getReturnInTransitAmount());
593
            }
594
 
594
            if (label.equals("Unbilled Order")) {
595
		if (investment.getShortInvestment() > 0) {
595
                backgroundColor.add("blue");
596
			investmentWalletAmount.put("Short Investment", investment.getShortInvestment());
596
            }
597
		}
597
 
598
 
598
            if (label.equals("ReturnInTransit")) {
599
		ChartInvestmentModel cm = new ChartInvestmentModel();
599
                backgroundColor.add("orange");
600
 
600
            }
601
		HashSet<String> labels = new HashSet<String>();
601
            if (label.equals("GrnPending")) {
602
		labels.addAll(investmentWalletAmount.keySet());
602
                backgroundColor.add("yellow");
603
 
603
            }
604
		List<String> labelList = new ArrayList<>(labels);
604
 
605
		List<String> backgroundColor = new ArrayList<>();
605
        }
606
		List<Float> values = new ArrayList<>();
606
 
607
		for (String label : labelList) {
607
        Data data = new Data();
608
			values.add(investmentWalletAmount.get(label));
608
        data.setData(values);
609
			if (label.equals("Wallet")) {
609
        data.setBackgroundColor(backgroundColor);
610
				backgroundColor.add("pink");
610
        data.setLabel("DataSet 1");
611
			}
611
 
612
			if (label.equals("Short Investment")) {
612
        PieLables label = new PieLables();
613
				backgroundColor.add("red");
613
        label.setFontColor("White");
614
			}
614
        label.setFontSize(15);
615
			if (label.equals("InStocks")) {
615
 
616
				backgroundColor.add("#9ACD32");
616
        Legend legend = new Legend();
617
			}
617
        legend.setLabels(label);
618
			if (label.equals("Unbilled Order")) {
618
        legend.setPosition("left");
619
				backgroundColor.add("blue");
619
 
620
			}
620
        List<Data> dataList = new ArrayList<>();
621
 
621
        dataList.add(data);
622
			if (label.equals("ReturnInTransit")) {
622
 
623
				backgroundColor.add("orange");
623
        DataInvestmentModel datasets = new DataInvestmentModel();
624
			}
624
        datasets.setDatasets(dataList);
625
			if (label.equals("GrnPending")) {
625
        datasets.setLabels(labels);
626
				backgroundColor.add("yellow");
626
 
627
			}
627
        OptionModel om = new OptionModel();
628
 
628
        om.setLegend(legend);
629
		}
629
        cm.setType("pie");
630
 
630
        cm.setData(datasets);
631
		Data data = new Data();
631
        cm.setOptions(om);
632
		data.setData(values);
632
 
633
		data.setBackgroundColor(backgroundColor);
633
        return cm;
634
		data.setLabel("DataSet 1");
634
    }
635
 
635
 
636
		PieLables label = new PieLables();
636
    public List<Notification> getNotifications(List<NotificationCampaign> nc, MessageType messageType) throws ProfitMandiBusinessException {
637
		label.setFontColor("White");
637
        List<Notification> notifications = new ArrayList<>();
638
		label.setFontSize(15);
638
        Document document = null;
639
 
639
        if (messageType != null) {
640
		Legend legend = new Legend();
640
            for (NotificationCampaign notificationCampaign : nc) {
641
		legend.setLabels(label);
641
                if (notificationCampaign.getMessageType() == messageType) {
642
		legend.setPosition("left");
642
                    Notification ns = new Notification();
643
 
643
                    SimpleCampaignParams scp = gson.fromJson(notificationCampaign.getImplementationParams(), SimpleCampaignParams.class);
644
		List<Data> dataList = new ArrayList<>();
644
                    Campaign campaign = new SimpleCampaign(scp);
645
		dataList.add(data);
645
                    LocalDateTime expire = campaign.getExpireTimestamp();
646
 
646
                    ns.setCid(Integer.toString(notificationCampaign.getId()));
647
		DataInvestmentModel datasets = new DataInvestmentModel();
647
                    ns.setType(campaign.getType());
648
		datasets.setDatasets(dataList);
648
                    ns.setMessage(campaign.getMessage());
649
		datasets.setLabels(labels);
649
                    ns.setTitle(campaign.getTitle());
650
 
650
                    if (notificationCampaign.getDocumentId() != null) {
651
		OptionModel om = new OptionModel();
651
                        document = documentRepository.selectById(notificationCampaign.getDocumentId());
652
		om.setLegend(legend);
652
                        ns.setDocumentName(document.getDisplayName());
653
		cm.setType("pie");
653
                    }
654
		cm.setData(datasets);
654
                    ns.setUrl(campaign.getUrl());
655
		cm.setOptions(om);
655
                    ns.setShowImage(campaign.getShowImage());
656
 
656
                    ns.setImageUrl(campaign.getImageUrl());
657
		return cm;
657
                    ns.setDocumentId(notificationCampaign.getDocumentId());
658
	}
658
                    ns.setMessageType(notificationCampaign.getMessageType());
659
 
659
                    ns.setCreated(
660
	public List<Notification> getNotifications(List<NotificationCampaign> nc, MessageType messageType)
660
                            notificationCampaign.getCreatedTimestamp().toEpochSecond(ZoneOffset.ofHoursMinutes(5, 30)) * 1000);
661
			throws ProfitMandiBusinessException {
661
                    if (LocalDateTime.now().isAfter(expire)) {
662
		List<Notification> notifications = new ArrayList<>();
662
                        ns.setExpired(true);
663
		Document document = null;
663
                    } else {
664
		if (messageType != null) {
664
                        ns.setExpired(false);
665
			for (NotificationCampaign notificationCampaign : nc) {
665
                    }
666
				if (notificationCampaign.getMessageType() == messageType) {
666
                    notifications.add(ns);
667
					Notification ns = new Notification();
667
                }
668
					SimpleCampaignParams scp = gson.fromJson(notificationCampaign.getImplementationParams(),
668
            }
669
							SimpleCampaignParams.class);
669
        } else {
670
					Campaign campaign = new SimpleCampaign(scp);
670
            for (NotificationCampaign notificationCampaign : nc) {
671
					LocalDateTime expire = campaign.getExpireTimestamp();
671
 
672
					ns.setCid(Integer.toString(notificationCampaign.getId()));
672
                Notification ns = new Notification();
673
					ns.setType(campaign.getType());
673
                SimpleCampaignParams scp = gson.fromJson(notificationCampaign.getImplementationParams(), SimpleCampaignParams.class);
674
					ns.setMessage(campaign.getMessage());
674
                Campaign campaign = new SimpleCampaign(scp);
675
					ns.setTitle(campaign.getTitle());
675
                LocalDateTime expire = campaign.getExpireTimestamp();
676
					if (notificationCampaign.getDocumentId() != null) {
676
                ns.setCid(Integer.toString(notificationCampaign.getId()));
677
						document = documentRepository.selectById(notificationCampaign.getDocumentId());
677
                ns.setType(campaign.getType());
678
						ns.setDocumentName(document.getDisplayName());
678
                ns.setMessage(campaign.getMessage());
679
					}
679
                ns.setTitle(campaign.getTitle());
680
					ns.setUrl(campaign.getUrl());
680
                if (notificationCampaign.getDocumentId() != null) {
681
					ns.setShowImage(campaign.getShowImage());
681
                    document = documentRepository.selectById(notificationCampaign.getDocumentId());
682
					ns.setImageUrl(campaign.getImageUrl());
682
                    ns.setDocumentName(document.getDisplayName());
683
					ns.setDocumentId(notificationCampaign.getDocumentId());
683
                }
684
					ns.setMessageType(notificationCampaign.getMessageType());
684
                ns.setUrl(campaign.getUrl());
685
					ns.setCreated(
685
                ns.setShowImage(campaign.getShowImage());
686
							notificationCampaign.getCreatedTimestamp().toEpochSecond(ZoneOffset.ofHoursMinutes(5, 30))
686
                ns.setImageUrl(campaign.getImageUrl());
687
									* 1000);
687
                ns.setDocumentId(notificationCampaign.getDocumentId());
688
					if (LocalDateTime.now().isAfter(expire)) {
688
                ns.setMessageType(notificationCampaign.getMessageType());
689
						ns.setExpired(true);
689
                ns.setCreated(notificationCampaign.getCreatedTimestamp().toEpochSecond(ZoneOffset.ofHoursMinutes(5, 30)) * 1000);
690
					} else {
690
                if (LocalDateTime.now().isAfter(expire)) {
691
						ns.setExpired(false);
691
                    ns.setExpired(true);
692
					}
692
                } else {
693
					notifications.add(ns);
693
                    ns.setExpired(false);
694
				}
694
                }
695
			}
695
                notifications.add(ns);
696
		} else {
696
            }
697
			for (NotificationCampaign notificationCampaign : nc) {
697
 
698
 
698
        }
699
				Notification ns = new Notification();
699
        return notifications;
700
				SimpleCampaignParams scp = gson.fromJson(notificationCampaign.getImplementationParams(),
700
 
701
						SimpleCampaignParams.class);
701
    }
702
				Campaign campaign = new SimpleCampaign(scp);
702
 
703
				LocalDateTime expire = campaign.getExpireTimestamp();
703
    // This method is currently hardcoded to faciliate watches sold as gift.
704
				ns.setCid(Integer.toString(notificationCampaign.getId()));
704
    public boolean hasGift(int fofoId) {
705
				ns.setType(campaign.getType());
705
        try {
706
				ns.setMessage(campaign.getMessage());
706
            return currentInventorySnapshotRepository.selectByItemIdAndFofoId(ProfitMandiConstants.GIFT_ID, fofoId).getAvailability() > 0;
707
				ns.setTitle(campaign.getTitle());
707
        } catch (ProfitMandiBusinessException e) {
708
				if (notificationCampaign.getDocumentId() != null) {
708
            return false;
709
					document = documentRepository.selectById(notificationCampaign.getDocumentId());
709
        }
710
					ns.setDocumentName(document.getDisplayName());
710
    }
711
				}
-
 
712
				ns.setUrl(campaign.getUrl());
-
 
713
				ns.setShowImage(campaign.getShowImage());
-
 
714
				ns.setImageUrl(campaign.getImageUrl());
-
 
715
				ns.setDocumentId(notificationCampaign.getDocumentId());
-
 
716
				ns.setMessageType(notificationCampaign.getMessageType());
-
 
717
				ns.setCreated(notificationCampaign.getCreatedTimestamp().toEpochSecond(ZoneOffset.ofHoursMinutes(5, 30))
-
 
718
						* 1000);
-
 
719
				if (LocalDateTime.now().isAfter(expire)) {
-
 
720
					ns.setExpired(true);
-
 
721
				} else {
-
 
722
					ns.setExpired(false);
-
 
723
				}
-
 
724
				notifications.add(ns);
-
 
725
			}
-
 
726
 
-
 
727
		}
-
 
728
		return notifications;
-
 
729
 
-
 
730
	}
-
 
731
 
-
 
732
	// This method is currently hardcoded to faciliate watches sold as gift.
-
 
733
	public boolean hasGift(int fofoId) {
-
 
734
		try {
-
 
735
			return currentInventorySnapshotRepository.selectByItemIdAndFofoId(ProfitMandiConstants.GIFT_ID, fofoId)
-
 
736
					.getAvailability() > 0;
-
 
737
		} catch (ProfitMandiBusinessException e) {
-
 
738
			return false;
-
 
739
		}
-
 
740
	}
-
 
741
 
711
 
742
}
712
}