Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
21615 kshitij.so 1
package com.spice.profitmandi.web.controller;
2
 
25649 tejbeer 3
import com.google.gson.Gson;
28825 tejbeer 4
import com.mongodb.DBObject;
25651 tejbeer 5
import com.spice.profitmandi.common.enumuration.ContentType;
25683 tejbeer 6
import com.spice.profitmandi.common.enumuration.MessageType;
22481 ashik.ali 7
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
29932 amit.gupta 8
import com.spice.profitmandi.common.model.*;
25651 tejbeer 9
import com.spice.profitmandi.common.web.util.ResponseSender;
26011 amit.gupta 10
import com.spice.profitmandi.dao.entity.auth.AuthUser;
27355 tejbeer 11
import com.spice.profitmandi.dao.entity.catalog.Item;
27636 tejbeer 12
import com.spice.profitmandi.dao.entity.catalog.TagListing;
28471 tejbeer 13
import com.spice.profitmandi.dao.entity.cs.Position;
27660 tejbeer 14
import com.spice.profitmandi.dao.entity.cs.TicketAssigned;
25651 tejbeer 15
import com.spice.profitmandi.dao.entity.dtr.Document;
25649 tejbeer 16
import com.spice.profitmandi.dao.entity.dtr.NotificationCampaign;
29932 amit.gupta 17
import com.spice.profitmandi.dao.entity.fofo.*;
29720 manish 18
import com.spice.profitmandi.dao.entity.transaction.LineItem;
27586 tejbeer 19
import com.spice.profitmandi.dao.entity.transaction.Order;
29707 tejbeer 20
import com.spice.profitmandi.dao.enumuration.catalog.UpgradeOfferStatus;
31259 tejbeer 21
import com.spice.profitmandi.dao.enumuration.fofo.Milestone;
28409 tejbeer 22
import com.spice.profitmandi.dao.enumuration.transaction.OrderStatus;
29707 tejbeer 23
import com.spice.profitmandi.dao.model.SamsungUpgradeOfferModel;
29932 amit.gupta 24
import com.spice.profitmandi.dao.model.*;
25976 amit.gupta 25
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
27355 tejbeer 26
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
29707 tejbeer 27
import com.spice.profitmandi.dao.repository.catalog.SamsungUpgradeOfferRepository;
27632 tejbeer 28
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
26090 amit.gupta 29
import com.spice.profitmandi.dao.repository.cs.CsService;
28471 tejbeer 30
import com.spice.profitmandi.dao.repository.cs.PositionRepository;
27660 tejbeer 31
import com.spice.profitmandi.dao.repository.cs.TicketAssignedRepository;
26418 tejbeer 32
import com.spice.profitmandi.dao.repository.cs.TicketRepository;
29932 amit.gupta 33
import com.spice.profitmandi.dao.repository.dtr.*;
34
import com.spice.profitmandi.dao.repository.fofo.*;
27529 tejbeer 35
import com.spice.profitmandi.dao.repository.inventory.ReporticoCacheTableRepository;
36
import com.spice.profitmandi.dao.repository.inventory.SaholicInventoryCISRepository;
29720 manish 37
import com.spice.profitmandi.dao.repository.transaction.LineItemRepository;
27893 tejbeer 38
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
28443 tejbeer 39
import com.spice.profitmandi.dao.repository.transaction.PriceDropRepository;
28468 tejbeer 40
import com.spice.profitmandi.service.AdminUser;
41
import com.spice.profitmandi.service.FofoUser;
24336 amit.gupta 42
import com.spice.profitmandi.service.PartnerInvestmentService;
26460 amit.gupta 43
import com.spice.profitmandi.service.PartnerStatsService;
23844 amit.gupta 44
import com.spice.profitmandi.service.authentication.RoleManager;
25677 amit.gupta 45
import com.spice.profitmandi.service.inventory.InventoryService;
27876 amit.gupta 46
import com.spice.profitmandi.service.offers.OfferService;
27586 tejbeer 47
import com.spice.profitmandi.service.transaction.TransactionService;
26005 amit.gupta 48
import com.spice.profitmandi.service.user.RetailerService;
22481 ashik.ali 49
import com.spice.profitmandi.web.model.LoginDetails;
50
import com.spice.profitmandi.web.util.CookiesProcessor;
27529 tejbeer 51
import com.spice.profitmandi.web.util.MVCResponseSender;
29932 amit.gupta 52
import org.apache.logging.log4j.LogManager;
53
import org.apache.logging.log4j.Logger;
54
import org.json.JSONObject;
55
import org.springframework.beans.factory.annotation.Autowired;
56
import org.springframework.beans.factory.annotation.Value;
57
import org.springframework.core.io.InputStreamResource;
58
import org.springframework.http.HttpHeaders;
59
import org.springframework.http.HttpStatus;
60
import org.springframework.http.ResponseEntity;
61
import org.springframework.stereotype.Controller;
62
import org.springframework.ui.Model;
30224 tejbeer 63
import org.springframework.web.bind.annotation.PathVariable;
29932 amit.gupta 64
import org.springframework.web.bind.annotation.RequestMapping;
65
import org.springframework.web.bind.annotation.RequestMethod;
66
import org.springframework.web.bind.annotation.RequestParam;
22481 ashik.ali 67
 
29932 amit.gupta 68
import javax.servlet.http.HttpServletRequest;
69
import javax.transaction.Transactional;
30455 amit.gupta 70
import java.io.File;
71
import java.io.FileInputStream;
72
import java.io.FileNotFoundException;
29932 amit.gupta 73
import java.time.LocalDate;
74
import java.time.LocalDateTime;
75
import java.time.LocalTime;
76
import java.time.YearMonth;
77
import java.time.format.DateTimeFormatter;
78
import java.util.*;
31259 tejbeer 79
import java.util.Map.Entry;
29932 amit.gupta 80
import java.util.stream.Collectors;
81
 
30455 amit.gupta 82
import static in.shop2020.model.v1.order.OrderStatus.*;
83
 
21615 kshitij.so 84
@Controller
25222 amit.gupta 85
@Transactional(rollbackOn = Throwable.class)
21615 kshitij.so 86
public class DashboardController {
23923 amit.gupta 87
 
27727 tejbeer 88
	List<String> emails = Arrays.asList("kamini.sharma@smartdukaan.com", "neeraj.gupta@smartdukaan.com",
31129 tejbeer 89
			"amit.gupta@smartdukaan.com", "tejbeer.kaur@smartdukaan.com", "kanan.choudhary@smartdukaan.com");
27727 tejbeer 90
 
23379 ashik.ali 91
	@Value("${web.api.host}")
92
	private String webApiHost;
23923 amit.gupta 93
 
24072 amit.gupta 94
	@Value("${web.api.scheme}")
95
	private String webApiScheme;
24288 amit.gupta 96
 
24078 amit.gupta 97
	@Value("${web.api.root}")
98
	private String webApiRoot;
99
 
23379 ashik.ali 100
	@Value("${web.api.port}")
101
	private int webApiPort;
28430 tejbeer 102
 
22481 ashik.ali 103
	@Autowired
28443 tejbeer 104
	private PriceDropRepository priceDropRepository;
105
 
106
	@Autowired
22927 ashik.ali 107
	private CookiesProcessor cookiesProcessor;
26468 amit.gupta 108
 
26460 amit.gupta 109
	@Autowired
28409 tejbeer 110
	private PendingOrderRepository pendingOrderRepository;
111
 
112
	@Autowired
26460 amit.gupta 113
	private PartnerStatsService partnerStatsService;
23923 amit.gupta 114
 
23568 govind 115
	@Autowired
26090 amit.gupta 116
	private CsService csService;
117
 
118
	@Autowired
25653 amit.gupta 119
	private ResponseSender<?> responseSender;
26012 amit.gupta 120
 
26005 amit.gupta 121
	@Autowired
122
	RetailerService retailerService;
25214 amit.gupta 123
 
124
	@Autowired
28468 tejbeer 125
	private AdminUser adminUser;
126
 
127
	@Autowired
23786 amit.gupta 128
	private RoleManager roleManager;
23923 amit.gupta 129
 
23838 ashik.ali 130
	@Autowired
131
	private FofoStoreRepository fofoStoreRepository;
23884 amit.gupta 132
 
133
	@Autowired
24880 govind 134
	private PartnerInvestmentService partnerInvestmentService;
24288 amit.gupta 135
 
23884 amit.gupta 136
	@Autowired
25653 amit.gupta 137
	DocumentRepository documentRepository;
26236 amit.gupta 138
 
26234 amit.gupta 139
	@Autowired
140
	InventoryItemRepository inventoryItemRepository;
25683 tejbeer 141
 
25677 amit.gupta 142
	@Autowired
143
	InventoryService inventoryService;
23923 amit.gupta 144
 
23884 amit.gupta 145
	@Autowired
28409 tejbeer 146
	private PendingOrderItemRepository pendingOrderItemRepository;
147
 
148
	@Autowired
24203 amit.gupta 149
	private CurrentInventorySnapshotRepository currentInventorySnapshotRepository;
150
 
24880 govind 151
	@Autowired
152
	private FofoOrderItemRepository fofoOrderItemRepository;
26012 amit.gupta 153
 
26011 amit.gupta 154
	@Autowired
25566 tejbeer 155
	private PartnerTypeChangeService partnerTypeChangeService;
25136 amit.gupta 156
 
24996 amit.gupta 157
	@Autowired
25649 tejbeer 158
	private HygieneDataRepository hygieneDataRepository;
159
 
160
	@Autowired
161
	private UserAccountRepository userAccountRepository;
162
 
163
	@Autowired
164
	private NotificationCampaignRepository notificationCampaignRepository;
165
 
166
	@Autowired
25976 amit.gupta 167
	private AuthRepository authRepository;
24880 govind 168
 
25649 tejbeer 169
	@Autowired
26071 tejbeer 170
	private FofoOrderRepository fofoOrderRepository;
171
 
172
	@Autowired
25649 tejbeer 173
	private Gson gson;
174
 
26418 tejbeer 175
	@Autowired
176
	TicketRepository ticketRepository;
177
 
178
	@Autowired
27876 amit.gupta 179
	private OfferService offerService;
180
 
181
	@Autowired
27355 tejbeer 182
	private ItemRepository itemRepository;
26588 tejbeer 183
 
27509 tejbeer 184
	@Autowired
27529 tejbeer 185
	private SaholicInventoryCISRepository saholicInventoryCISRepository;
186
 
187
	@Autowired
188
	private MVCResponseSender mvcResponseSender;
189
 
190
	@Autowired
191
	private ReporticoCacheTableRepository reporticoCacheTableRepository;
192
 
27586 tejbeer 193
	@Autowired
194
	private TransactionService transactionService;
195
 
27632 tejbeer 196
	@Autowired
197
	private TagListingRepository tagListingRepository;
198
 
27660 tejbeer 199
	@Autowired
200
	private TicketAssignedRepository ticketAssignedRepository;
201
 
27893 tejbeer 202
	@Autowired
203
	private OrderRepository orderRepository;
28468 tejbeer 204
 
205
	@Autowired
206
	private FofoUser fofoUser;
29875 tejbeer 207
 
28471 tejbeer 208
	@Autowired
28825 tejbeer 209
	private ActivatedImeiRepository activatedImeiRepository;
210
 
211
	@Autowired
212
	private Mongo mongoClient;
213
 
214
	@Autowired
29578 tejbeer 215
	private SchemeInOutRepository schemeInOutRepository;
29875 tejbeer 216
 
29578 tejbeer 217
	@Autowired
29720 manish 218
	private LineItemRepository lineItemRepository;
29875 tejbeer 219
 
29720 manish 220
	@Autowired
29578 tejbeer 221
	private FofoLineItemRepository fofoLineItemRepository;
222
 
223
	@Autowired
28471 tejbeer 224
	private PositionRepository positionRepository;
29707 tejbeer 225
 
226
	@Autowired
31211 tejbeer 227
	private MonthlyTargetRepository monthlyTargetRepository;
228
	@Autowired
29707 tejbeer 229
	private SamsungUpgradeOfferRepository samsungUpgradeOfferRepository;
23568 govind 230
	private static final Logger LOGGER = LogManager.getLogger(DashboardController.class);
23923 amit.gupta 231
 
25136 amit.gupta 232
	@RequestMapping(value = "/12dashboard34", method = RequestMethod.GET)
25726 amit.gupta 233
	public String dashboard1(HttpServletRequest request, Model model, @RequestParam int fofoId) throws Exception {
25740 amit.gupta 234
		boolean isAdmin = false;
235
		model.addAttribute("isAdmin", isAdmin);
236
 
237
		model.addAttribute("webApiHost", webApiHost);
238
		model.addAttribute("webApiPort", webApiPort);
239
		model.addAttribute("webApiScheme", webApiScheme);
240
		model.addAttribute("webApiRoot", webApiRoot);
241
		if (isAdmin) {
242
			return "dashboard1";
26236 amit.gupta 243
		}
244
 
245
		FofoStore fofoStore = null;
26234 amit.gupta 246
		try {
247
			CustomRetailer customRetailer = retailerService.getFofoRetailer(fofoId);
248
			fofoStore = fofoStoreRepository.selectByRetailerId(fofoId);
249
			if (!fofoStore.isActive()) {
250
				return "redirect:/login";
251
			}
25740 amit.gupta 252
 
26234 amit.gupta 253
			PartnerType partnerType = partnerTypeChangeService.getTypeOnDate(fofoStore.getId(), LocalDate.now());
254
			model.addAttribute("partnerType", partnerType);
255
			model.addAttribute("partnerTypeImage", PartnerType.imageMap.get(partnerType));
256
			model.addAttribute("fofoStore", customRetailer);
257
			model.addAttribute("partnerType", partnerType);
28468 tejbeer 258
			model.addAttribute("hasGift", fofoUser.hasGift(fofoId));
26234 amit.gupta 259
			model.addAttribute("giftItemId", ProfitMandiConstants.GIFT_ID);
25740 amit.gupta 260
 
28468 tejbeer 261
			model.addAttribute("brandStockPrices", fofoUser.getBrandStockPrices(fofoId));
262
			model.addAttribute("salesMap", fofoUser.getSales(fofoId));
26234 amit.gupta 263
			model.addAttribute("activatedImeis", inventoryItemRepository.selectCountByActivatedNotSold(fofoId));
264
			// this.setInvestments
265
			//
28272 tejbeer 266
			Map<Integer, String> monthValueMap = new HashMap<>();
267
			for (int i = 0; i <= 5; i++) {
268
				LocalDateTime startOfMonth = LocalDateTime.now().withDayOfMonth(1).minusMonths(i);
269
				monthValueMap.put(i, startOfMonth.format(DateTimeFormatter.ofPattern("MMM''uu")));
270
			}
271
			LOGGER.info("monthValueMap" + monthValueMap);
272
			model.addAttribute("monthValueMap", monthValueMap);
28468 tejbeer 273
			model.addAttribute("investments", fofoUser.getInvestments(fofoId));
26234 amit.gupta 274
			model.addAttribute("isInvestmentOk",
275
					partnerInvestmentService.isInvestmentOk(fofoId, 10, ProfitMandiConstants.CUTOFF_INVESTMENT));
276
		} catch (ProfitMandiBusinessException e) {
277
			LOGGER.error("FofoStore Code not found of fofoId {}", fofoId);
25740 amit.gupta 278
 
279
		}
280
 
28430 tejbeer 281
		return "12dashboard34";
28272 tejbeer 282
	}
25740 amit.gupta 283
 
27474 tejbeer 284
	@RequestMapping(value = "/getMonthSale", method = RequestMethod.GET)
285
	public String getMonthsale(HttpServletRequest request, Model model) throws Exception {
286
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
287
		int fofoId = loginDetails.getFofoId();
288
		Map<Integer, MonthSaleModel> monthSaleMap = new HashMap<>();
289
		LocalDateTime curDate = LocalDate.now().atStartOfDay();
290
		int dayOfMonth = curDate.getDayOfMonth();
291
		for (int i = 1; i <= 6; i++) {
292
			LocalDateTime startOfMonth = curDate.withDayOfMonth(1).minusMonths(i);
27555 tejbeer 293
			int lengthOfMonth = YearMonth.from(startOfMonth).lengthOfMonth();
29875 tejbeer 294
			LOGGER.info("Start of previous Month {}, start of next month Month {}", startOfMonth,
295
					startOfMonth.plusMonths(1));
27474 tejbeer 296
			double monthSales = fofoOrderItemRepository.selectSumMopGroupByRetailer(startOfMonth,
297
					startOfMonth.plusMonths(1), loginDetails.getFofoId(), false).get(fofoId);
298
 
27574 tejbeer 299
			double mtdSales = fofoOrderItemRepository
300
					.selectSumMopGroupByRetailer(startOfMonth,
301
							startOfMonth.plusDays(Math.min(dayOfMonth, lengthOfMonth)), loginDetails.getFofoId(), false)
302
					.get(fofoId);
27474 tejbeer 303
 
304
			PartnerType partnerType = partnerTypeChangeService.getTypeOnDate(fofoId, startOfMonth.toLocalDate());
305
 
306
			MonthSaleModel ms = new MonthSaleModel();
28468 tejbeer 307
			ms.setMtdSales(fofoUser.format((long) mtdSales));
308
			ms.setMonthlySales(fofoUser.format(((long) monthSales)));
27474 tejbeer 309
			ms.setPartnerType(partnerType);
27476 tejbeer 310
			ms.setMonth(startOfMonth.format(DateTimeFormatter.ofPattern("MMM''uu")));
27474 tejbeer 311
			monthSaleMap.put(i, ms);
29875 tejbeer 312
		}
27474 tejbeer 313
 
314
		model.addAttribute("monthSales", monthSaleMap);
315
		return "monthSales";
316
	}
317
 
21615 kshitij.so 318
	@RequestMapping(value = "/dashboard", method = RequestMethod.GET)
25653 amit.gupta 319
	public String dashboard(HttpServletRequest request, Model model) throws Exception {
22927 ashik.ali 320
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
26011 amit.gupta 321
		String email = loginDetails.getEmailId();
28430 tejbeer 322
		int fofoId = loginDetails.getFofoId();
25180 amit.gupta 323
		boolean isAdmin = roleManager.isAdmin(loginDetails.getRoleIds());
324
		model.addAttribute("isAdmin", isAdmin);
23923 amit.gupta 325
 
25274 amit.gupta 326
		model.addAttribute("webApiHost", webApiHost);
327
		model.addAttribute("webApiPort", webApiPort);
328
		model.addAttribute("webApiScheme", webApiScheme);
25544 amit.gupta 329
		model.addAttribute("webApiRoot", webApiRoot);
25183 amit.gupta 330
		if (isAdmin) {
28468 tejbeer 331
			return adminUser.adminPanel(loginDetails.getFofoId(), email, model);
25180 amit.gupta 332
		} else {
25740 amit.gupta 333
			FofoStore fofoStore = null;
25180 amit.gupta 334
			try {
335
				fofoStore = fofoStoreRepository.selectByRetailerId(loginDetails.getFofoId());
25544 amit.gupta 336
				if (!fofoStore.isActive()) {
337
					return "redirect:/login";
338
				}
30346 tejbeer 339
 
30455 amit.gupta 340
				LocalDateTime startDate = LocalDate.now().withDayOfYear(1).atStartOfDay();
341
				LocalDateTime endtDate = LocalDateTime.now();
342
				OnlineDeliveredOrderSum onlineDeliveredOrderSum = pendingOrderItemRepository
343
						.selectSumSellingPriceOnlineOrder(fofoId, startDate, endtDate);
344
				LOGGER.info("onlineDeliveredOrderSum" + onlineDeliveredOrderSum.getSellingPrice());
345
 
346
				long countOrder = pendingOrderRepository.pendingOrderCount(fofoId, OrderStatus.PROCESSING);
347
				LOGGER.info("countOrder" + countOrder);
348
 
349
				ArrayList<in.shop2020.model.v1.order.OrderStatus> orderStatus = new ArrayList<>();
350
 
351
				orderStatus.add(SUBMITTED_FOR_PROCESSING);
352
				orderStatus.add(BILLED);
353
				orderStatus.add(SHIPPED_FROM_WH);
354
				orderStatus.add(DELIVERY_SUCCESS);
355
 
356
				List<Order> openOrders = orderRepository.selectGrnTimestampNull(fofoId, orderStatus);
357
				List<LineItem> submittedLineItemIds = openOrders.stream()
30564 tejbeer 358
						.filter(x -> x.getStatus().equals(SUBMITTED_FOR_PROCESSING)).map(x -> x.getLineItem())
359
						.collect(Collectors.toList());
360
				List<LineItem> billedOrderIds = openOrders.stream().filter(x -> x.getStatus().equals(BILLED))
30455 amit.gupta 361
						.map(x -> x.getLineItem()).collect(Collectors.toList());
30564 tejbeer 362
				List<LineItem> shippedOrderIds = openOrders.stream().filter(x -> x.getStatus().equals(SHIPPED_FROM_WH))
30455 amit.gupta 363
						.map(x -> x.getLineItem()).collect(Collectors.toList());
364
				List<LineItem> grnPendingLineItemIds = openOrders.stream()
30564 tejbeer 365
						.filter(x -> x.getStatus().equals(DELIVERY_SUCCESS)).map(x -> x.getLineItem())
366
						.collect(Collectors.toList());
30455 amit.gupta 367
 
368
				long imeiActivationPendingCount = 0;
369
				long imeiActivationPendingValue = 0;
30564 tejbeer 370
				List<Integer> grnPendingOrderIds = openOrders.stream()
371
						.filter(x -> x.getStatus().equals(SHIPPED_FROM_WH) || x.getStatus().equals(DELIVERY_SUCCESS))
372
						.map(x -> x.getId()).collect(Collectors.toList());
30455 amit.gupta 373
				if (grnPendingOrderIds.size() > 0) {
30564 tejbeer 374
					List<ImeiActivationTimestampModel> imeiActivationTimestampModels = activatedImeiRepository
375
							.selectActivatedImeisByOrders(grnPendingOrderIds);
30455 amit.gupta 376
					imeiActivationPendingCount = imeiActivationTimestampModels.size();
30564 tejbeer 377
					imeiActivationPendingValue = imeiActivationTimestampModels.stream()
378
							.collect(Collectors.summingDouble(x -> x.getSellingPrice())).longValue();
30455 amit.gupta 379
				}
380
 
30564 tejbeer 381
				long grnPendingCount = grnPendingLineItemIds.stream()
382
						.collect(Collectors.summingLong(LineItem::getQuantity));
30455 amit.gupta 383
				long grnPendingValue = grnPendingLineItemIds.stream()
384
						.collect(Collectors.summingLong(x -> x.getTotalPrice().longValue()));
385
				model.addAttribute("grnPendingCount", grnPendingCount);
386
				model.addAttribute("grnPendingValue", grnPendingValue);
387
 
30564 tejbeer 388
				long submittedCount = submittedLineItemIds.stream()
389
						.collect(Collectors.summingLong(LineItem::getQuantity));
30455 amit.gupta 390
				long submittedValue = submittedLineItemIds.stream()
391
						.collect(Collectors.summingLong(x -> x.getTotalPrice().longValue()));
392
				model.addAttribute("submittedCount", submittedCount);
393
				model.addAttribute("submittedValue", submittedValue);
394
 
395
				long billedCount = billedOrderIds.stream().collect(Collectors.summingLong(LineItem::getQuantity));
30564 tejbeer 396
				long billedValue = billedOrderIds.stream()
397
						.collect(Collectors.summingLong(x -> x.getTotalPrice().longValue()));
30455 amit.gupta 398
				model.addAttribute("billedValue", billedValue);
399
				model.addAttribute("billedCount", billedCount);
400
				LOGGER.info("billedCount {}", billedCount);
401
 
402
				long shippedCount = shippedOrderIds.stream().collect(Collectors.summingLong(LineItem::getQuantity));
403
				model.addAttribute("shippedCount", shippedCount);
404
				LOGGER.info("shippedCount {}", shippedCount);
405
				long shippedValue = shippedOrderIds.stream()
406
						.collect(Collectors.summingLong(x -> x.getTotalPrice().longValue()));
407
				model.addAttribute("shippedValue", shippedValue);
408
 
409
				LocalDateTime curDate = LocalDate.now().atStartOfDay();
410
 
411
				LocalDateTime currentMonthStart = curDate.withDayOfMonth(1);
412
				LocalDateTime lastMonthStart = currentMonthStart.minusMonths(1);
413
				LocalDateTime currentMonthEnd = currentMonthStart.withDayOfMonth(1);
414
 
415
				LOGGER.info("lastMonthStart" + lastMonthStart);
416
				LOGGER.info("currentMonthEnd" + currentMonthEnd);
417
 
418
				model.addAttribute("countOrder", countOrder);
419
				model.addAttribute("onlineDeliveredOrderSum", onlineDeliveredOrderSum.getSellingPrice());
420
 
25740 amit.gupta 421
				PartnerType partnerType = partnerTypeChangeService.getTypeOnDate(fofoStore.getId(), LocalDate.now());
25566 tejbeer 422
				model.addAttribute("partnerType", partnerType);
25653 amit.gupta 423
				model.addAttribute("partnerTypeImage", PartnerType.imageMap.get(partnerType));
25180 amit.gupta 424
				model.addAttribute("fofoStore", fofoStore);
25566 tejbeer 425
				model.addAttribute("partnerType", partnerType);
28468 tejbeer 426
				model.addAttribute("hasGift", fofoUser.hasGift(loginDetails.getFofoId()));
25180 amit.gupta 427
				model.addAttribute("giftItemId", ProfitMandiConstants.GIFT_ID);
26222 tejbeer 428
				model.addAttribute("retailers", new JSONObject().append("code", fofoStore.getCode())
26162 amit.gupta 429
						.append("partnerId", fofoStore.getId()).toString());
26460 amit.gupta 430
				model.addAttribute("activatedImeis",
431
						inventoryItemRepository.selectCountByActivatedNotSold(loginDetails.getFofoId()));
30564 tejbeer 432
				model.addAttribute("imeiActivationPendingCount", imeiActivationPendingCount);
433
				model.addAttribute("imeiActivationPendingValue", imeiActivationPendingValue);
30053 manish 434
 
26071 tejbeer 435
				Map<Integer, Double> accesoriesmtdsale = fofoOrderRepository
436
						.selectSumSaleGroupByFofoIdsForMobileOrAccessories(loginDetails.getFofoId(),
437
								curDate.withDayOfMonth(1), curDate.with(LocalTime.MAX), Optional.of(false));
27701 tejbeer 438
 
26071 tejbeer 439
				Double accesoriesStock = currentInventorySnapshotRepository
440
						.selectSumStockGroupByFofoIdsForMobileOrAccessories(loginDetails.getFofoId(),
441
								Optional.of(false))
442
						.get(loginDetails.getFofoId());
25180 amit.gupta 443
 
26071 tejbeer 444
				model.addAttribute("accesoriesStock", String.format("%.0f", accesoriesStock));
28468 tejbeer 445
				model.addAttribute("brandStockPrices", fofoUser.getBrandStockPrices(loginDetails.getFofoId()));
446
				model.addAttribute("salesMap", fofoUser.getSales(loginDetails.getFofoId()));
447
				ChartModel cm = fofoUser.getBrandChart(loginDetails.getFofoId());
26055 tejbeer 448
 
449
				LOGGER.info("chartMap" + gson.toJson(cm));
450
				model.addAttribute("chartMap", gson.toJson(cm));
27701 tejbeer 451
 
27876 amit.gupta 452
				List<CreateOfferRequest> publishedOffers = offerService.getPublishedOffers(loginDetails.getFofoId(),
453
						YearMonth.from(LocalDateTime.now()));
454
				model.addAttribute("publishedOffers", publishedOffers);
28468 tejbeer 455
				model.addAttribute("investments", fofoUser.getInvestments(loginDetails.getFofoId()));
25544 amit.gupta 456
				model.addAttribute("isInvestmentOk", partnerInvestmentService.isInvestmentOk(loginDetails.getFofoId(),
457
						10, ProfitMandiConstants.CUTOFF_INVESTMENT));
26460 amit.gupta 458
 
30564 tejbeer 459
				double currentMonthRating = hygieneDataRepository.selectRatingAvg(loginDetails.getFofoId(),
460
						currentMonthStart, currentMonthEnd) / 2;
30455 amit.gupta 461
				double lastMonthRating = hygieneDataRepository.selectRatingAvg(loginDetails.getFofoId(), lastMonthStart,
462
						currentMonthStart) / 2;
30564 tejbeer 463
				double ratingTillDate = hygieneDataRepository.selectRatingAvg(loginDetails.getFofoId(),
464
						LocalDateTime.MIN, currentMonthEnd) / 2;
30455 amit.gupta 465
				model.addAttribute("currentMonthRating", (float) Math.round(currentMonthRating * 10) / 10);
466
				model.addAttribute("lastMonthRating", (float) Math.round(lastMonthRating * 10) / 10);
467
				model.addAttribute("ratingTillDate", (float) Math.round(ratingTillDate * 10) / 10);
468
 
30564 tejbeer 469
				long hygieneCount = hygieneDataRepository.selectHygieneCount(loginDetails.getFofoId(), true,
470
						currentMonthStart, currentMonthEnd);
30455 amit.gupta 471
 
472
				long invalidHygieneCount = hygieneDataRepository.selectHygieneCount(loginDetails.getFofoId(), false,
473
						currentMonthStart, currentMonthEnd);
474
				if (hygieneCount == 0 && invalidHygieneCount == 0) {
475
					invalidHygieneCount = 1;
476
				}
477
				Map<Integer, String> monthValueMap = new HashMap<>();
478
				for (int i = 0; i <= 5; i++) {
479
					LocalDateTime startOfMonth = LocalDateTime.now().withDayOfMonth(1).minusMonths(i);
480
					monthValueMap.put(i, startOfMonth.format(DateTimeFormatter.ofPattern("MMM''uu")));
481
				}
482
 
31211 tejbeer 483
				MonthlyTarget monthlyTarget = monthlyTargetRepository.selectByDateAndFofoId(YearMonth.now(), fofoId);
484
				model.addAttribute("monthlyTarget", monthlyTarget);
485
 
30455 amit.gupta 486
				model.addAttribute("monthValueMap", monthValueMap);
487
				model.addAttribute("month", 0);
488
				model.addAttribute("hygienePercentage", (hygieneCount * 100) / (invalidHygieneCount + hygieneCount));
489
				model.addAttribute("monthDays", LocalDate.now().minusDays(1).lengthOfMonth());
490
				model.addAttribute("dayOfMonth", LocalDate.now().minusDays(1).getDayOfMonth());
491
 
25180 amit.gupta 492
			} catch (ProfitMandiBusinessException e) {
493
				LOGGER.error("FofoStore Code not found of fofoId {}", loginDetails.getFofoId());
494
 
495
			}
30455 amit.gupta 496
			return "dashboard1";
22481 ashik.ali 497
		}
25649 tejbeer 498
 
21615 kshitij.so 499
	}
29875 tejbeer 500
 
29720 manish 501
	@RequestMapping(value = "/getGrnPendingOrderStatus", method = RequestMethod.GET)
502
	public String getGrnPendingOrderStatus(HttpServletRequest request, Model model) throws Exception {
29875 tejbeer 503
 
29720 manish 504
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
505
		int fofoId = loginDetails.getFofoId();
30224 tejbeer 506
		List<Order> grnPendingOrders = orderRepository.selectGrnTimestampNull(fofoId,
507
				Arrays.asList(in.shop2020.model.v1.order.OrderStatus.DELIVERY_SUCCESS));
29746 manish 508
 
29934 amit.gupta 509
		model.addAttribute("grnPendingOrders", grnPendingOrders);
29720 manish 510
		return "purchase-grn-order-status";
511
	}
29875 tejbeer 512
 
29720 manish 513
	@RequestMapping(value = "/getPendingOrderStatus", method = RequestMethod.GET)
514
	public String getPendingOrderStatus(HttpServletRequest request, Model model) throws Exception {
29875 tejbeer 515
 
29720 manish 516
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
517
		int fofoId = loginDetails.getFofoId();
29875 tejbeer 518
		ArrayList<in.shop2020.model.v1.order.OrderStatus> orderStatus = new ArrayList<>();
519
 
29720 manish 520
		orderStatus.add(in.shop2020.model.v1.order.OrderStatus.SUBMITTED_FOR_PROCESSING);
29875 tejbeer 521
 
522
		List<Order> order = orderRepository.selectOrders(fofoId, orderStatus);
523
		List<Integer> submittedOrderIds = order.stream()
524
				.filter(x -> x.getStatus() == in.shop2020.model.v1.order.OrderStatus.SUBMITTED_FOR_PROCESSING)
525
				.map(x -> x.getId()).collect(Collectors.toList());
526
		model.addAttribute("submittedOrderIds", submittedOrderIds);
527
		if (!submittedOrderIds.isEmpty()) {
528
 
529
			List<LineItem> submittedLineItem = lineItemRepository.selectLineItem(submittedOrderIds);
530
			Map<Integer, LineItem> submittedLineItemMap = submittedLineItem.stream()
531
					.collect(Collectors.toMap(x -> x.getOrderId(), x -> x));
532
			LOGGER.info("submittedLineItemMap {}", submittedLineItemMap);
533
			model.addAttribute("submittedLineItemMap", submittedLineItemMap);
534
		}
535
 
29720 manish 536
		return "purchase-pending-order-status";
537
	}
29875 tejbeer 538
 
29720 manish 539
	@RequestMapping(value = "/getBilledOrderStatus", method = RequestMethod.GET)
540
	public String getBilledOrderStatus(HttpServletRequest request, Model model) throws Exception {
29875 tejbeer 541
 
29720 manish 542
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
543
		int fofoId = loginDetails.getFofoId();
29875 tejbeer 544
		ArrayList<in.shop2020.model.v1.order.OrderStatus> orderStatus = new ArrayList<>();
29720 manish 545
		orderStatus.add(in.shop2020.model.v1.order.OrderStatus.BILLED);
29875 tejbeer 546
 
547
		List<Order> order = orderRepository.selectOrders(fofoId, orderStatus);
548
		List<Integer> billedOrderIds = order.stream()
549
				.filter(x -> x.getStatus() == in.shop2020.model.v1.order.OrderStatus.BILLED).map(x -> x.getId())
550
				.collect(Collectors.toList());
551
		LOGGER.info("billedOrderIds {}", billedOrderIds);
552
		model.addAttribute("billedOrderIds", billedOrderIds);
553
 
554
		if (!billedOrderIds.isEmpty()) {
555
			List<LineItem> billedLineItem = lineItemRepository.selectLineItem(billedOrderIds);
556
			Map<Integer, LineItem> billedLineItemMap = billedLineItem.stream()
557
					.collect(Collectors.toMap(x -> x.getOrderId(), x -> x));
558
			LOGGER.info("billedLineItemMap {}", billedLineItemMap);
559
			model.addAttribute("billedLineItemMap", billedLineItemMap);
560
		}
561
 
29720 manish 562
		return "purchase-billed-order-status";
563
	}
29875 tejbeer 564
 
29720 manish 565
	@RequestMapping(value = "/getShippedOrderStatus", method = RequestMethod.GET)
566
	public String getShippedOrderStatus(HttpServletRequest request, Model model) throws Exception {
29875 tejbeer 567
 
29720 manish 568
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
569
		int fofoId = loginDetails.getFofoId();
29875 tejbeer 570
		ArrayList<in.shop2020.model.v1.order.OrderStatus> orderStatus = new ArrayList<>();
571
 
30455 amit.gupta 572
		orderStatus.add(SHIPPED_FROM_WH);
29875 tejbeer 573
 
574
		List<Order> order = orderRepository.selectOrders(fofoId, orderStatus);
30347 tejbeer 575
		List<Integer> shippedOrderIds = order.stream().filter(x -> x.getPartnerGrnTimestamp() == null)
29875 tejbeer 576
				.map(x -> x.getId()).collect(Collectors.toList());
577
		model.addAttribute("shippedOrderIds", shippedOrderIds);
578
		LOGGER.info("shippedOrderIds {}", shippedOrderIds);
579
 
580
		if (!shippedOrderIds.isEmpty()) {
581
			List<LineItem> shippedLineItem = lineItemRepository.selectLineItem(shippedOrderIds);
582
			Map<Integer, LineItem> shippedLineItemMap = shippedLineItem.stream()
583
					.collect(Collectors.toMap(x -> x.getOrderId(), x -> x));
584
			LOGGER.info("shippedLineItemMap {}", shippedLineItemMap);
585
 
586
			model.addAttribute("shippedLineItemMap", shippedLineItemMap);
587
		}
29720 manish 588
		return "purchase-shipped-order-status";
589
	}
23923 amit.gupta 590
 
30224 tejbeer 591
	@RequestMapping(value = "/partnerTotalIncomeByMonth/{yearMonth}", method = RequestMethod.GET)
592
	public String getPartnerTotalIncomeByMonth(HttpServletRequest request, @PathVariable int yearMonth, Model model)
593
			throws Exception {
594
 
595
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
596
		long pendingIncome = 0;
597
		long partnerPurchaseIn = 0;
598
		long partnerCreditedSale = 0;
599
		long partnerFrontIncome = 0;
600
 
601
		LocalDateTime currentStartMonth = LocalDate.now().minusMonths(yearMonth).withDayOfMonth(1).atStartOfDay();
602
		LocalDateTime currentDate = currentStartMonth.plusMonths(1).withDayOfMonth(1).toLocalDate().atStartOfDay();
603
 
604
		AllPurchaseInventoryModel partnerlPendingSaleAmount = schemeInOutRepository
605
				.selectAllPendingSaleInventoryByFofoId(loginDetails.getFofoId(), currentStartMonth, currentDate);
606
		AllPurchaseInventoryModel partnerCreditedSaleAmount = schemeInOutRepository
607
				.selectAllCreditedSaleInventoryByFofoId(loginDetails.getFofoId(), currentStartMonth, currentDate);
608
		AllPurchaseInventoryModel partnerPurchaseInAmount = schemeInOutRepository
609
				.selectAllPurchaseInventoryByFofoId(loginDetails.getFofoId(), currentStartMonth, currentDate);
610
 
611
		AllPurchaseInventoryModel partnerFrontIncomes = schemeInOutRepository
612
				.selectFrontIncomeByFofoId(loginDetails.getFofoId(), currentStartMonth, currentDate);
613
 
614
		LOGGER.info("partnerfrontIncomes" + partnerFrontIncomes);
615
 
616
		LOGGER.info("partnerCreditedSaleAmount" + partnerCreditedSaleAmount);
617
		LOGGER.info("partnerPurchaseInAmount" + partnerPurchaseInAmount);
618
		LOGGER.info("partnerlPendingSaleAmount" + partnerlPendingSaleAmount);
619
 
620
		if (partnerlPendingSaleAmount != null) {
621
 
622
			pendingIncome = partnerlPendingSaleAmount.getAmount();
623
 
624
			LOGGER.info("pendingIncome" + pendingIncome);
625
 
626
		}
627
 
628
		if (partnerCreditedSaleAmount != null) {
629
 
630
			partnerCreditedSale = partnerCreditedSaleAmount.getAmount();
631
 
632
			LOGGER.info("partnerCreditedSale" + partnerCreditedSale);
633
 
634
		}
635
		if (partnerFrontIncomes != null) {
636
 
637
			partnerFrontIncome = partnerFrontIncomes.getAmount();
638
			LOGGER.info("partnerPurchaseIn" + partnerPurchaseIn);
639
 
640
		}
641
		if (partnerPurchaseInAmount != null) {
642
 
643
			partnerPurchaseIn = partnerPurchaseInAmount.getAmount();
644
			LOGGER.info("partnerPurchaseIn" + partnerPurchaseIn);
645
 
646
		}
647
 
648
		LOGGER.info("partnerPurchaseInTT" + partnerPurchaseIn);
649
		LOGGER.info("partnerCreditedSaleTT" + partnerCreditedSale);
650
		LOGGER.info("pendingIncomeTT" + pendingIncome);
651
 
652
		long totalIncome = partnerCreditedSale + partnerPurchaseIn + pendingIncome + partnerFrontIncome;
653
 
654
		long creditedIncome = partnerCreditedSale + partnerPurchaseIn + partnerFrontIncome;
655
 
656
		long pendingTotalIncome = pendingIncome;
657
		LOGGER.info("totalIncome" + totalIncome);
658
		LOGGER.info("creditedIncome" + creditedIncome);
659
		LOGGER.info("pendingTotalIncome" + pendingTotalIncome);
660
 
661
		model.addAttribute("totalIncome", totalIncome);
662
		model.addAttribute("creditedIncome", creditedIncome);
663
		model.addAttribute("pendingTotalIncome", pendingTotalIncome);
664
 
665
		Map<Integer, String> monthValueMap = new HashMap<>();
666
		for (int i = 0; i <= 5; i++) {
667
			LocalDateTime startOfMonth = LocalDateTime.now().withDayOfMonth(1).minusMonths(i);
668
			monthValueMap.put(i, startOfMonth.format(DateTimeFormatter.ofPattern("MMM''uu")));
669
		}
670
 
671
		model.addAttribute("month", yearMonth);
672
		model.addAttribute("monthValueMap", monthValueMap);
673
 
674
		return "partner-total-income";
675
	}
676
 
28272 tejbeer 677
	@RequestMapping(value = "/getMonthsInvestment", method = RequestMethod.GET)
678
	public String getMonthsInvestment(HttpServletRequest request,
30564 tejbeer 679
			@RequestParam(name = "month", required = true, defaultValue = "0") int month, Model model)
28272 tejbeer 680
			throws Exception {
681
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
682
		int fofoId = loginDetails.getFofoId();
28468 tejbeer 683
		Map<String, Object> investment = fofoUser.getInvestmentsMonths(fofoId, month);
28430 tejbeer 684
 
28272 tejbeer 685
		LocalDateTime currentMonthStart = LocalDateTime.now().withDayOfMonth(1);
686
		LocalDateTime lastMonthStart = currentMonthStart.minusMonths(1);
687
		LocalDateTime currentMonthEnd = currentMonthStart.plusMonths(1).withDayOfMonth(1);
688
		double currentMonthRating = hygieneDataRepository.selectRatingAvg(loginDetails.getFofoId(), currentMonthStart,
689
				currentMonthEnd) / 2;
690
		double lastMonthRating = hygieneDataRepository.selectRatingAvg(loginDetails.getFofoId(), lastMonthStart,
691
				currentMonthStart) / 2;
692
		double ratingTillDate = hygieneDataRepository.selectRatingAvg(loginDetails.getFofoId(), LocalDateTime.MIN,
693
				currentMonthEnd) / 2;
694
		model.addAttribute("currentMonthRating", (float) Math.round(currentMonthRating * 10) / 10);
695
		model.addAttribute("lastMonthRating", (float) Math.round(lastMonthRating * 10) / 10);
696
		model.addAttribute("ratingTillDate", (float) Math.round(ratingTillDate * 10) / 10);
697
 
28430 tejbeer 698
		long hygieneCount = hygieneDataRepository.selectHygieneCount(loginDetails.getFofoId(), true,
699
				currentMonthStart.minusMonths(month), currentMonthEnd.minusMonths(month));
28272 tejbeer 700
 
701
		long invalidHygieneCount = hygieneDataRepository.selectHygieneCount(loginDetails.getFofoId(), false,
28430 tejbeer 702
				currentMonthStart.minusMonths(month), currentMonthEnd.minusMonths(month));
28272 tejbeer 703
		if (hygieneCount == 0 && invalidHygieneCount == 0) {
704
			invalidHygieneCount = 1;
705
		}
706
		Map<Integer, String> monthValueMap = new HashMap<>();
707
		for (int i = 0; i <= 5; i++) {
708
			LocalDateTime startOfMonth = LocalDateTime.now().withDayOfMonth(1).minusMonths(i);
709
			monthValueMap.put(i, startOfMonth.format(DateTimeFormatter.ofPattern("MMM''uu")));
710
		}
711
		model.addAttribute("hygienePercentage", (hygieneCount * 100) / (invalidHygieneCount + hygieneCount));
28430 tejbeer 712
		model.addAttribute("monthValueMap", monthValueMap);
28272 tejbeer 713
		model.addAttribute("investments", investment);
714
		model.addAttribute("monthDays", LocalDate.now().minusMonths(month).lengthOfMonth());
715
		model.addAttribute("dayOfMonth", LocalDate.now().minusMonths(month).lengthOfMonth());
28430 tejbeer 716
		model.addAttribute("month", month);
28272 tejbeer 717
		return "performance";
718
	}
719
 
27884 tejbeer 720
	@RequestMapping(value = "/investmentDetails", method = RequestMethod.GET)
721
	public String getInvestmentDetails(HttpServletRequest request, Model model) throws Exception {
722
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
723
		int fofoId = loginDetails.getFofoId();
28468 tejbeer 724
		ChartInvestmentModel cm = fofoUser.getInvestmentChart(fofoId);
27884 tejbeer 725
		model.addAttribute("chartPieMap", gson.toJson(cm));
726
 
727
		LOGGER.info("InvestmentChart" + gson.toJson(cm));
728
		LOGGER.info("InvestmentChart" + cm);
729
		return "investmentdetails";
730
	}
731
 
28430 tejbeer 732
	@RequestMapping(value = "/getlmsLineChart", method = RequestMethod.GET)
733
	public String getlmsLineChart(HttpServletRequest request, Model model) throws Exception {
734
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
735
		int fofoId = loginDetails.getFofoId();
28468 tejbeer 736
		ChartModel cm = fofoUser.getLmsLineChart(loginDetails.getFofoId());
28430 tejbeer 737
 
738
		LOGGER.info("linechartMap" + gson.toJson(cm));
739
		model.addAttribute("linechartMap", gson.toJson(cm));
740
		return "lmsLineChart";
741
	}
742
 
28439 tejbeer 743
	@RequestMapping(value = "/getMonthlyPurchaseLineChart", method = RequestMethod.GET)
744
	public String getMonthlyPurchaseLineChart(HttpServletRequest request, Model model) throws Exception {
745
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
746
		int fofoId = loginDetails.getFofoId();
28468 tejbeer 747
		ChartModel cm = fofoUser.getPurchaseOrderChart(fofoId);
28439 tejbeer 748
 
749
		LOGGER.info("chartMap" + gson.toJson(cm));
750
		model.addAttribute("chartMap", gson.toJson(cm));
751
 
752
		return "purchase_chart";
753
	}
754
 
28430 tejbeer 755
	@RequestMapping(value = "/getBarChart", method = RequestMethod.GET)
756
	public String getBarChart(HttpServletRequest request, Model model) throws Exception {
757
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
758
		int fofoId = loginDetails.getFofoId();
28468 tejbeer 759
		ChartModel cm = fofoUser.getBrandChart(fofoId);
28430 tejbeer 760
 
761
		LOGGER.info("chartMap" + gson.toJson(cm));
762
		model.addAttribute("chartMap", gson.toJson(cm));
763
 
764
		return "bar_chart";
765
	}
766
 
28455 tejbeer 767
	@RequestMapping(value = "/getPriceDropDetails", method = RequestMethod.GET)
768
	public String getPriceDropDetails(HttpServletRequest request,
30564 tejbeer 769
			@RequestParam(name = "fofoId", required = true, defaultValue = "0") int fofoId,
770
			@RequestParam(name = "brand", required = true, defaultValue = "0") String brand,
771
			@RequestParam(name = "yearMonth", required = false, defaultValue = "0") String yearMonth, Model model)
28455 tejbeer 772
			throws Exception {
773
 
774
		LOGGER.info("params" + fofoId + brand + yearMonth);
775
 
776
		List<PriceDropWithDetailsByYearMonthModel> priceDropdetailsList = priceDropRepository
777
				.selectBrandPendingPriceDropWithDetailsByYearMonth(fofoId, brand, yearMonth);
778
 
779
		LOGGER.info("priceDropdetailsList" + priceDropdetailsList);
780
 
781
		model.addAttribute("priceDropdetailsList", priceDropdetailsList);
782
 
783
		return "price-drop-details";
784
	}
28825 tejbeer 785
 
28641 amit.gupta 786
	@RequestMapping(value = "/getPriceDropDetailSixMonths", method = RequestMethod.GET)
787
	public String getPriceDropDetailSixMonths(HttpServletRequest request,
30564 tejbeer 788
			@RequestParam(name = "fofoId", required = true, defaultValue = "0") int fofoId,
789
			@RequestParam(name = "brand", required = true, defaultValue = "0") String brand, Model model)
28641 amit.gupta 790
			throws Exception {
28455 tejbeer 791
 
28641 amit.gupta 792
		LOGGER.info("params" + fofoId + brand);
793
		LocalDateTime curDate = LocalDate.now().atStartOfDay();
794
		LocalDateTime startfMonthSixMonth = curDate.withDayOfMonth(1).minusMonths(12);
795
		LocalDateTime endMonthTotal = curDate.withDayOfMonth(1).minusMonths(6);
796
 
797
		List<PriceDropWithDetailsByYearMonthModel> priceDropdetailsList = priceDropRepository
28825 tejbeer 798
				.selectBrandPendingPriceDropWithDetailsAndSixMonth(fofoId, brand, startfMonthSixMonth, endMonthTotal);
28641 amit.gupta 799
 
800
		LOGGER.info("priceDropdetailsList" + priceDropdetailsList);
801
 
802
		model.addAttribute("priceDropdetailsList", priceDropdetailsList);
803
 
804
		return "price-drop-details";
805
	}
806
 
28455 tejbeer 807
	@RequestMapping(value = "/getMonthlyPriceDrop", method = RequestMethod.GET)
808
	public String getMonthlyPriceDropTabular(HttpServletRequest request, Model model) throws Exception {
809
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
810
		int fofoId = loginDetails.getFofoId();
811
		LocalDateTime curDate = LocalDate.now().atStartOfDay();
812
 
813
		LocalDateTime startOfMonth = curDate.withDayOfMonth(1).minusMonths(6);
28641 amit.gupta 814
		LocalDateTime startfMonthTotal = curDate.withDayOfMonth(1).minusMonths(12);
29875 tejbeer 815
		LocalDateTime endMonthTotal = curDate.withDayOfMonth(1).minusMonths(5);
28455 tejbeer 816
 
29875 tejbeer 817
		LOGGER.info("startfMonthTotal" + startfMonthTotal);
818
 
819
		LOGGER.info("endMonthTotal" + endMonthTotal);
28641 amit.gupta 820
		List<YearMonth> yms = new ArrayList<YearMonth>();
28455 tejbeer 821
 
29875 tejbeer 822
		for (int i = 0; i <= 5; i++) {
28641 amit.gupta 823
			yms.add(YearMonth.from(curDate.withDayOfMonth(1).minusMonths(i)));
28455 tejbeer 824
		}
28641 amit.gupta 825
		Collections.reverse(yms);
826
		model.addAttribute("yms", yms);
827
		LOGGER.info("ym" + yms);
28455 tejbeer 828
 
829
		List<PriceDropYearMonthModel> priceDropYearMonthModels = priceDropRepository
830
				.selectBrandPendingPriceDropByYearMonth(fofoId, startOfMonth);
831
 
28641 amit.gupta 832
		List<PriceDropBrandModel> priceDropBrandSixMonthTotals = priceDropRepository
833
				.selectSixMonthBrandPriceDropByYearMonth(fofoId, startfMonthTotal, endMonthTotal);
834
 
28455 tejbeer 835
		DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("MM-yyyy");
836
 
837
		Map<String, Map<YearMonth, Double>> brandMonthValue = new HashMap<>();
28641 amit.gupta 838
 
839
		LOGGER.info("priceDropBrandSixMonthTotals" + priceDropBrandSixMonthTotals);
28825 tejbeer 840
 
841
		Map<String, Double> priceDropBrandSixMonthMap = priceDropBrandSixMonthTotals.stream()
842
				.collect(Collectors.toMap(x -> x.getBrand(), x -> (double) x.getAmount()));
843
 
28641 amit.gupta 844
		model.addAttribute("priceDropBrandSixMonthMap", priceDropBrandSixMonthMap);
28455 tejbeer 845
		LOGGER.info("priceDropYearMonthModels" + priceDropYearMonthModels);
28641 amit.gupta 846
 
28455 tejbeer 847
		for (PriceDropYearMonthModel pdm : priceDropYearMonthModels) {
28641 amit.gupta 848
			Map<YearMonth, Double> brandValue = new HashMap<>();
28455 tejbeer 849
 
850
			if (brandMonthValue.containsKey(pdm.getBrand())) {
851
				brandValue = brandMonthValue.get(pdm.getBrand());
852
				brandValue.put(YearMonth.parse(pdm.getYearMonth(), dateTimeFormatter), (double) pdm.getAmount());
853
			} else {
854
 
855
				brandValue.put(YearMonth.parse(pdm.getYearMonth(), dateTimeFormatter), (double) pdm.getAmount());
856
 
857
			}
858
			brandMonthValue.put(pdm.getBrand(), brandValue);
859
		}
860
		List<String> brands = new ArrayList<>();
861
		brands.add("Accessories");
862
		brands.add("Oppo");
863
		brands.add("Vivo");
864
		brands.add("Samsung");
865
		brands.add("Realme");
28462 tejbeer 866
		brands.add("MI");
28455 tejbeer 867
		brands.add("Tecno");
868
		brands.add("Itel");
869
		brands.add("Nokia");
29578 tejbeer 870
 
28455 tejbeer 871
		Map<String, List<Double>> sortedBrandValue = new LinkedHashMap<>();
872
 
28825 tejbeer 873
		model.addAttribute("brands", brands);
874
 
28455 tejbeer 875
		for (String brand : brands) {
876
			Map<YearMonth, Double> yearMonthValue = brandMonthValue.get(brand);
29875 tejbeer 877
			for (int i = 5; i >= 0; i--) {
28455 tejbeer 878
 
879
				LocalDateTime startMonth = curDate.withDayOfMonth(1).minusMonths(i);
880
 
881
				if (yearMonthValue != null) {
882
					if (yearMonthValue.get(YearMonth.from(startMonth)) == null) {
883
						yearMonthValue.put(YearMonth.from(startMonth), 0.0);
884
					}
885
 
886
				} else {
887
					yearMonthValue = new HashMap<>();
888
					yearMonthValue.put(YearMonth.from(startMonth), 0.0);
889
				}
890
			}
891
 
892
			Map<YearMonth, Double> sortedMonthBrandValue = new TreeMap<>(yearMonthValue);
893
 
894
			brandMonthValue.put(brand, sortedMonthBrandValue);
895
 
896
			sortedBrandValue.put(brand, sortedMonthBrandValue.values().stream().collect(Collectors.toList()));
897
 
898
		}
899
 
29578 tejbeer 900
		LOGGER.info("sortedBrandValue" + sortedBrandValue);
901
		model.addAttribute("fofoId", fofoId);
28455 tejbeer 902
 
29578 tejbeer 903
		model.addAttribute("sortedBrandValue", sortedBrandValue);
28455 tejbeer 904
 
29578 tejbeer 905
		return "price-drop-tabular";
906
	}
28455 tejbeer 907
 
29578 tejbeer 908
	@RequestMapping(value = "/getMonthlyActivation", method = RequestMethod.GET)
909
	public String getMonthlyActivation(HttpServletRequest request, Model model) throws Exception {
910
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
911
		int fofoId = loginDetails.getFofoId();
28455 tejbeer 912
 
29578 tejbeer 913
		LocalDateTime curDate = LocalDate.now().atStartOfDay();
914
		LocalDateTime startOfMonth = curDate.withDayOfMonth(1).minusMonths(6);
915
 
916
		List<YearMonth> yms = new ArrayList<YearMonth>();
917
 
29580 tejbeer 918
		for (int i = 0; i <= 5; i++) {
29578 tejbeer 919
			yms.add(YearMonth.from(curDate.withDayOfMonth(1).minusMonths(i)));
920
		}
921
		Collections.reverse(yms);
922
		model.addAttribute("yms", yms);
923
		LOGGER.info("ym" + yms);
924
 
925
		List<ActivationYearMonthModel> pendingActivationModels = schemeInOutRepository
926
				.selectPendingActivationGroupByBrandYearMonth(fofoId, startOfMonth);
927
 
928
		List<ActivationBrandModel> pendingActivationBeforeSixMonth = schemeInOutRepository
929
				.selectByYearMonthActivationGroupByBrand(fofoId, startOfMonth);
930
 
931
		Map<String, Double> pendingActivationBeforeSixMonthMap = pendingActivationBeforeSixMonth.stream()
932
				.collect(Collectors.toMap(x -> x.getBrand(), x -> (double) x.getAmount()));
933
 
934
		model.addAttribute("pendingActivationBeforeSixMonthMap", pendingActivationBeforeSixMonthMap);
935
 
936
		DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("MM-yyyy");
937
 
938
		Map<String, Map<YearMonth, Double>> activationBrandMonthMap = new HashMap<>();
939
 
940
		for (ActivationYearMonthModel pam : pendingActivationModels) {
941
			Map<YearMonth, Double> brandValue = new HashMap<>();
942
 
943
			if (activationBrandMonthMap.containsKey(pam.getBrand())) {
944
				brandValue = activationBrandMonthMap.get(pam.getBrand());
945
				brandValue.put(YearMonth.parse(pam.getYearMonth(), dateTimeFormatter), (double) pam.getAmount());
946
			} else {
947
 
948
				brandValue.put(YearMonth.parse(pam.getYearMonth(), dateTimeFormatter), (double) pam.getAmount());
949
 
28455 tejbeer 950
			}
29578 tejbeer 951
			activationBrandMonthMap.put(pam.getBrand(), brandValue);
952
		}
28455 tejbeer 953
 
29578 tejbeer 954
		List<String> brands = new ArrayList<>();
955
		brands.add("Oppo");
956
		brands.add("Vivo");
957
		brands.add("Samsung");
958
		brands.add("Realme");
959
		brands.add("MI");
960
		brands.add("Tecno");
961
		brands.add("Itel");
962
		brands.add("Nokia");
963
		brands.add("Lava");
964
		Map<String, List<Double>> sortedBrandValue = new LinkedHashMap<>();
965
 
966
		model.addAttribute("brands", brands);
967
 
968
		for (String brand : brands) {
969
			Map<YearMonth, Double> yearMonthValue = activationBrandMonthMap.get(brand);
29580 tejbeer 970
			for (int i = 5; i >= 0; i--) {
29578 tejbeer 971
				LocalDateTime startMonth = curDate.withDayOfMonth(1).minusMonths(i);
972
				if (yearMonthValue != null) {
973
					if (yearMonthValue.get(YearMonth.from(startMonth)) == null) {
974
						yearMonthValue.put(YearMonth.from(startMonth), 0.0);
975
					}
976
 
977
				} else {
978
					yearMonthValue = new HashMap<>();
979
					yearMonthValue.put(YearMonth.from(startMonth), 0.0);
980
				}
981
			}
982
			Map<YearMonth, Double> sortedMonthBrandValue = new TreeMap<>(yearMonthValue);
983
			activationBrandMonthMap.put(brand, sortedMonthBrandValue);
984
			sortedBrandValue.put(brand, sortedMonthBrandValue.values().stream().collect(Collectors.toList()));
28455 tejbeer 985
		}
986
 
29580 tejbeer 987
		LOGGER.info("sortedBrandValue" + sortedBrandValue);
29578 tejbeer 988
		model.addAttribute("sortedBrandValue", sortedBrandValue);
28455 tejbeer 989
		model.addAttribute("fofoId", fofoId);
29578 tejbeer 990
		return "activation-tabular";
991
	}
28455 tejbeer 992
 
29578 tejbeer 993
	@RequestMapping(value = "/getMonthlyActivationItemDetail", method = RequestMethod.GET)
994
	public String getMonthlyActivationItemDetail(HttpServletRequest request,
30564 tejbeer 995
			@RequestParam(name = "fofoId", required = true, defaultValue = "0") int fofoId,
996
			@RequestParam(name = "brand", required = true, defaultValue = "0") String brand,
997
			@RequestParam(name = "yearMonth", required = false, defaultValue = "0") String yearMonth, Model model)
29578 tejbeer 998
			throws Exception {
28455 tejbeer 999
 
29578 tejbeer 1000
		LOGGER.info("params" + fofoId + brand + yearMonth);
1001
 
1002
		List<ActivationItemDetailModel> activationItemDetails = schemeInOutRepository
1003
				.selectBrandPendingActivationItemDetails(fofoId, brand, yearMonth);
1004
 
1005
		for (ActivationItemDetailModel activationItemDetail : activationItemDetails) {
1006
 
1007
			List<FofoLineItem> flis = fofoLineItemRepository
1008
					.selectByInventoryItemId(activationItemDetail.getInventoryItemId());
1009
 
1010
			LOGGER.info("flis" + flis);
1011
 
1012
			int maxFofoOrderItemId = flis.stream().mapToInt(x -> x.getFofoOrderItemId()).max()
1013
					.orElseThrow(NoSuchElementException::new);
1014
			LOGGER.info("maxFofoOrderItemId" + maxFofoOrderItemId);
1015
 
1016
			FofoOrderItem foi = fofoOrderItemRepository.selectById(maxFofoOrderItemId);
1017
 
1018
			FofoOrder fo = fofoOrderRepository.selectByOrderId(foi.getOrderId());
1019
 
1020
			activationItemDetail.setInvoiceNumber(fo.getInvoiceNumber());
1021
 
1022
		}
1023
		LOGGER.info("activationItemDetails" + activationItemDetails);
1024
 
1025
		model.addAttribute("activationItemDetails", activationItemDetails);
1026
 
1027
		return "activation-pending-item-details";
28455 tejbeer 1028
	}
1029
 
29578 tejbeer 1030
	@RequestMapping(value = "/getMonthlyActivationBeforeSixMonthsItemDetail", method = RequestMethod.GET)
1031
	public String getMonthlyActivationItemDetail(HttpServletRequest request,
30564 tejbeer 1032
			@RequestParam(name = "fofoId", required = true, defaultValue = "0") int fofoId,
1033
			@RequestParam(name = "brand", required = true, defaultValue = "0") String brand, Model model)
29578 tejbeer 1034
			throws Exception {
1035
		LocalDateTime curDate = LocalDate.now().atStartOfDay();
1036
 
1037
		LocalDateTime startOfMonth = curDate.withDayOfMonth(1).minusMonths(6);
1038
 
1039
		List<ActivationItemDetailModel> activationItemDetails = schemeInOutRepository
1040
				.selectBrandPendingActivationItemDetailByYearMonth(fofoId, brand, startOfMonth);
1041
 
1042
		for (ActivationItemDetailModel activationItemDetail : activationItemDetails) {
1043
 
1044
			List<FofoLineItem> flis = fofoLineItemRepository
1045
					.selectByInventoryItemId(activationItemDetail.getInventoryItemId());
1046
			LOGGER.info("flis" + flis);
1047
 
1048
			int maxFofoOrderItemId = flis.stream().mapToInt(x -> x.getFofoOrderItemId()).max()
1049
					.orElseThrow(NoSuchElementException::new);
1050
			LOGGER.info("maxFofoOrderItemId" + maxFofoOrderItemId);
1051
 
1052
			FofoOrderItem foi = fofoOrderItemRepository.selectById(maxFofoOrderItemId);
1053
 
1054
			FofoOrder fo = fofoOrderRepository.selectByOrderId(foi.getOrderId());
1055
 
1056
			activationItemDetail.setInvoiceNumber(fo.getInvoiceNumber());
1057
 
1058
		}
1059
		LOGGER.info("activationItemDetails" + activationItemDetails);
1060
 
1061
		model.addAttribute("activationItemDetails", activationItemDetails);
1062
 
1063
		return "activation-pending-item-details";
1064
	}
1065
 
29707 tejbeer 1066
	@RequestMapping(value = "/getMonthlySamsungUpgradeOffer", method = RequestMethod.GET)
1067
	public String getMonthlySamsungUpgradeOffer(HttpServletRequest request, Model model) throws Exception {
1068
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1069
		int fofoId = loginDetails.getFofoId();
1070
 
1071
		LocalDateTime curDate = LocalDate.now().atStartOfDay();
1072
		LocalDateTime startOfMonth = curDate.withDayOfMonth(1).minusMonths(6);
1073
 
1074
		List<YearMonth> yms = new ArrayList<YearMonth>();
1075
 
1076
		for (int i = 0; i <= 5; i++) {
1077
			yms.add(YearMonth.from(curDate.withDayOfMonth(1).minusMonths(i)));
1078
		}
1079
		Collections.reverse(yms);
1080
		model.addAttribute("yms", yms);
1081
		LOGGER.info("ym" + yms);
1082
 
1083
		List<SamsungUpgradeOfferModel> suos = samsungUpgradeOfferRepository.selectUpgradeOfferGroupByYearMonth(fofoId,
1084
				UpgradeOfferStatus.approved, startOfMonth);
1085
 
1086
		LOGGER.info("suos" + suos);
1087
 
1088
		List<BrandAmountModel> beforeSixMonthOffers = samsungUpgradeOfferRepository
1089
				.selectUpgradeOfferByYearMonthGroupByBrand(fofoId, UpgradeOfferStatus.approved, startOfMonth);
1090
 
1091
		Map<String, Double> pendingUpgradeOfferBeforeSixMonthMap = beforeSixMonthOffers.stream()
1092
				.collect(Collectors.toMap(x -> x.getBrand(), x -> (double) x.getAmount()));
1093
 
1094
		model.addAttribute("pendingUpgradeOfferBeforeSixMonthMap", pendingUpgradeOfferBeforeSixMonthMap);
1095
 
1096
		DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("MM-yyyy");
1097
 
1098
		Map<String, Map<YearMonth, Double>> upgradeOfferBrandMonthMap = new HashMap<>();
1099
 
1100
		for (SamsungUpgradeOfferModel suo : suos) {
1101
			Map<YearMonth, Double> brandValue = new HashMap<>();
1102
 
1103
			if (upgradeOfferBrandMonthMap.containsKey(suo.getBrand())) {
1104
				brandValue = upgradeOfferBrandMonthMap.get(suo.getBrand());
1105
				brandValue.put(YearMonth.parse(suo.getYearMonth(), dateTimeFormatter), (double) suo.getAmount());
1106
			} else {
1107
 
1108
				brandValue.put(YearMonth.parse(suo.getYearMonth(), dateTimeFormatter), (double) suo.getAmount());
1109
 
1110
			}
1111
			upgradeOfferBrandMonthMap.put(suo.getBrand(), brandValue);
1112
		}
1113
 
1114
		Map<String, List<Double>> sortedBrandValue = new LinkedHashMap<>();
1115
		String brand = "Samsung";
1116
 
1117
		Map<YearMonth, Double> yearMonthValue = upgradeOfferBrandMonthMap.get(brand);
1118
		for (int i = 5; i >= 0; i--) {
1119
			LocalDateTime startMonth = curDate.withDayOfMonth(1).minusMonths(i);
1120
			if (yearMonthValue != null) {
1121
				if (yearMonthValue.get(YearMonth.from(startMonth)) == null) {
1122
					yearMonthValue.put(YearMonth.from(startMonth), 0.0);
1123
				}
1124
 
1125
			} else {
1126
				yearMonthValue = new HashMap<>();
1127
				yearMonthValue.put(YearMonth.from(startMonth), 0.0);
1128
			}
1129
		}
1130
		Map<YearMonth, Double> sortedMonthBrandValue = new TreeMap<>(yearMonthValue);
1131
		upgradeOfferBrandMonthMap.put(brand, sortedMonthBrandValue);
1132
		sortedBrandValue.put(brand, sortedMonthBrandValue.values().stream().collect(Collectors.toList()));
1133
		LOGGER.info("sortedBrandValue" + sortedBrandValue);
1134
 
1135
		model.addAttribute("brand", brand);
1136
		model.addAttribute("sortedBrandValue", sortedBrandValue);
1137
		model.addAttribute("fofoId", fofoId);
1138
		return "upgrade-offer-tabular";
1139
 
1140
	}
1141
 
1142
	@RequestMapping(value = "/getMonthlyUpgradeOfferItemDetail", method = RequestMethod.GET)
1143
	public String getMonthlyUpgradeOfferItemDetail(HttpServletRequest request,
30564 tejbeer 1144
			@RequestParam(name = "fofoId", required = true, defaultValue = "0") int fofoId,
1145
			@RequestParam(name = "brand", required = true, defaultValue = "0") String brand,
1146
			@RequestParam(name = "yearMonth", required = false, defaultValue = "0") String yearMonth, Model model)
29707 tejbeer 1147
			throws Exception {
1148
 
1149
		LOGGER.info("params" + fofoId + brand + yearMonth);
1150
		List<UpgradeOfferItemDetailModel> offerItems = samsungUpgradeOfferRepository
1151
				.selectUpgradeOfferItemDetails(fofoId, UpgradeOfferStatus.approved, brand, yearMonth);
1152
 
1153
		model.addAttribute("offerItems", offerItems);
1154
 
1155
		return "upgrade-offer-item-detail";
1156
	}
1157
 
1158
	@RequestMapping(value = "/getUpgradeOfferBeforeSixMonthItemDetail", method = RequestMethod.GET)
1159
	public String getUpgradeOfferBeforeSixMonthItemDetail(HttpServletRequest request,
30564 tejbeer 1160
			@RequestParam(name = "fofoId", required = true, defaultValue = "0") int fofoId,
1161
			@RequestParam(name = "brand", required = true, defaultValue = "0") String brand, Model model)
29707 tejbeer 1162
			throws Exception {
1163
		LocalDateTime curDate = LocalDate.now().atStartOfDay();
1164
 
1165
		LocalDateTime startOfMonth = curDate.withDayOfMonth(1).minusMonths(6);
1166
 
1167
		List<UpgradeOfferItemDetailModel> offerItems = samsungUpgradeOfferRepository
1168
				.selectUpgradeOfferItemDetailByYearMonth(fofoId, UpgradeOfferStatus.approved, brand, startOfMonth);
1169
 
1170
		model.addAttribute("offerItems", offerItems);
1171
 
1172
		return "upgrade-offer-item-detail";
1173
	}
1174
 
26468 amit.gupta 1175
	@RequestMapping(value = "/getAuthUserPartners", method = RequestMethod.GET)
26418 tejbeer 1176
	public String AuthUserPartnersDetail(HttpServletRequest request, Model model, @RequestParam int authId)
1177
			throws Exception {
1178
 
1179
		Map<Integer, List<Integer>> pp = csService.getAuthUserIdPartnerIdMapping();
26963 amit.gupta 1180
		Map<Integer, CustomRetailer> fofoIdAndPartnerMap = retailerService.getFofoRetailers(false);
26418 tejbeer 1181
 
26468 amit.gupta 1182
		Map<Integer, PartnerDetailModel> fofoIdAndallValues = partnerStatsService.getAllPartnerStats();
1183
		if (authId != 0) {
1184
			List<Integer> fofoIds = pp.get(authId);
1185
			fofoIdAndallValues = fofoIdAndallValues.entrySet().stream().filter(x -> fofoIds.contains(x.getKey()))
1186
					.collect(Collectors.toMap(x -> x.getKey(), x -> x.getValue()));
26474 amit.gupta 1187
		} else {
26418 tejbeer 1188
		}
1189
 
1190
		model.addAttribute("fofoIdAndallValues", fofoIdAndallValues);
1191
		model.addAttribute("fofoIdAndPartnerMap", fofoIdAndPartnerMap);
1192
 
1193
		return "auth_user_partner_detail";
26468 amit.gupta 1194
	}
26418 tejbeer 1195
 
27545 tejbeer 1196
	@RequestMapping(value = "/getWarehousePartners", method = RequestMethod.GET)
1197
	public String warehousePartnersDetail(HttpServletRequest request, Model model, @RequestParam int warehouseId)
1198
			throws Exception {
27701 tejbeer 1199
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1200
		String email = loginDetails.getEmailId();
28472 tejbeer 1201
 
1202
		Set<Integer> authfofoIds = new HashSet<>();
31152 tejbeer 1203
		authfofoIds = csService.getAuthFofoIds(email);
27701 tejbeer 1204
		Map<Integer, List<Integer>> warehouseIdFofoIdMap = fofoStoreRepository
1205
				.selectActivePartnersByRetailerIds(new ArrayList<>(authfofoIds)).stream().collect(Collectors.groupingBy(
1206
						FofoStore::getWarehouseId, Collectors.mapping(FofoStore::getId, Collectors.toList())));
1207
 
27545 tejbeer 1208
		Map<Integer, CustomRetailer> fofoIdAndPartnerMap = retailerService.getFofoRetailers(false);
28468 tejbeer 1209
		Map<Integer, PartnerDetailModel> fofoIdAndallValues = adminUser.getPartnersStatDataFromFile();
27545 tejbeer 1210
		if (warehouseId != 0) {
27701 tejbeer 1211
			List<Integer> fofoIds = warehouseIdFofoIdMap.get(warehouseId);
1212
			/*
1213
			 * List<Integer> fofoIds =
1214
			 * fofoStoreRepository.selectActivePartnerByWarehouse(warehouseId).stream()
1215
			 * .map(x -> x.getId()).collect(Collectors.toList());
1216
			 */
27545 tejbeer 1217
			fofoIdAndallValues = fofoIdAndallValues.entrySet().stream().filter(x -> fofoIds.contains(x.getKey()))
1218
					.collect(Collectors.toMap(x -> x.getKey(), x -> x.getValue()));
1219
		} else {
28472 tejbeer 1220
 
1221
			List<Integer> fofoIds = new ArrayList<>(authfofoIds);
1222
			fofoIdAndallValues = fofoIdAndallValues.entrySet().stream().filter(x -> fofoIds.contains(x.getKey()))
27701 tejbeer 1223
					.collect(Collectors.toMap(x -> x.getKey(), x -> x.getValue()));
27545 tejbeer 1224
		}
29164 manish 1225
		ChartInvestmentModel cm = adminUser.getAllStatePartnerType(fofoIdAndallValues);
1226
		model.addAttribute("chartPieMap", gson.toJson(cm));
27545 tejbeer 1227
 
29164 manish 1228
		LOGGER.info("adminUserChart" + gson.toJson(cm));
1229
 
31211 tejbeer 1230
		Map<Integer, MonthlyTarget> monthlyTargetMap = monthlyTargetRepository.selectByDate(YearMonth.now()).stream()
1231
				.collect(Collectors.toMap(x -> x.getFofoId(), x -> x));
1232
 
27545 tejbeer 1233
		model.addAttribute("fofoIdAndallValues", fofoIdAndallValues);
1234
		model.addAttribute("fofoIdAndPartnerMap", fofoIdAndPartnerMap);
31211 tejbeer 1235
		model.addAttribute("monthlyTargetMap", monthlyTargetMap);
27545 tejbeer 1236
 
31154 tejbeer 1237
		List<PartnerType> partnerTypes = Arrays.asList(PartnerType.values()).stream()
1238
				.filter(x -> !x.equals(PartnerType.ALL)).collect(Collectors.toList());
31211 tejbeer 1239
 
31154 tejbeer 1240
		model.addAttribute("partnerTypes", partnerTypes);
1241
 
27545 tejbeer 1242
		return "auth_user_partner_detail";
1243
	}
1244
 
27509 tejbeer 1245
	@RequestMapping(value = "/getWarehouseWiseBrandStock", method = RequestMethod.GET)
27701 tejbeer 1246
	public String getWarehouseWiseBrandStock(HttpServletRequest request, Model model,
30564 tejbeer 1247
			@RequestParam List<Integer> warehouseId) throws Exception {
27701 tejbeer 1248
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1249
		String email = loginDetails.getEmailId();
31152 tejbeer 1250
		Set<Integer> authfofoIds = csService.getAuthFofoIds(email);
27701 tejbeer 1251
		Map<Integer, List<Integer>> warehouseIdFofoIdMap = fofoStoreRepository
1252
				.selectActivePartnersByRetailerIds(new ArrayList<>(authfofoIds)).stream().collect(Collectors.groupingBy(
1253
						FofoStore::getWarehouseId, Collectors.mapping(FofoStore::getId, Collectors.toList())));
1254
		List<WarehouseWiseBrandStockModel> warehouseWiseBrandStock = new ArrayList<>();
1255
		if (!warehouseId.contains(0)) {
1256
			warehouseWiseBrandStock = saholicInventoryCISRepository.selectGroupByWarehouseAndBrand(warehouseId);
1257
		} else {
1258
			LOGGER.info("warehouseIdFofoIdMap" + warehouseIdFofoIdMap.keySet());
1259
			warehouseWiseBrandStock = saholicInventoryCISRepository
1260
					.selectGroupByWarehouseAndBrand(new ArrayList<>(warehouseIdFofoIdMap.keySet()));
1261
 
1262
		}
27542 tejbeer 1263
		Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
27509 tejbeer 1264
		model.addAttribute("warehouseWiseBrandStock", warehouseWiseBrandStock);
27542 tejbeer 1265
		model.addAttribute("warehouseId", warehouseId);
27509 tejbeer 1266
		model.addAttribute("warehouseMap", warehouseMap);
27660 tejbeer 1267
 
27509 tejbeer 1268
		return "warehouse_brand_stock";
1269
	}
1270
 
27529 tejbeer 1271
	@RequestMapping(value = "/getWarehouseWiseData", method = RequestMethod.GET)
1272
	public String getWarehouseWiseData(HttpServletRequest request, Model model) throws Exception {
1273
		inventoryService.getItemAvailabilityAndIndent();
31238 amit.gupta 1274
		model.addAttribute("response1", mvcResponseSender.createResponseString(true));
27529 tejbeer 1275
		return "response";
1276
	}
1277
 
27539 tejbeer 1278
	@RequestMapping(value = "/getWarehouseWiseBrandAndCategory", method = RequestMethod.GET)
1279
	public String getWarehouseWiseBrandAndCategory(HttpServletRequest request, Model model,
30564 tejbeer 1280
			@RequestParam List<Integer> warehouseId, @RequestParam List<String> brands, @RequestParam String category)
27538 tejbeer 1281
			throws Exception {
27509 tejbeer 1282
 
1283
		Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
27529 tejbeer 1284
		List<String> listbrands = saholicInventoryCISRepository.selectAllBrand();
27538 tejbeer 1285
		List<String> listCategory = saholicInventoryCISRepository.selectAllSubCategory();
27539 tejbeer 1286
 
27509 tejbeer 1287
		model.addAttribute("warehouseMap", warehouseMap);
27529 tejbeer 1288
		model.addAttribute("brands", listbrands);
27538 tejbeer 1289
		model.addAttribute("listCategory", listCategory);
1290
 
27529 tejbeer 1291
		model.addAttribute("selectedBrand", brands);
27538 tejbeer 1292
		model.addAttribute("selectedWarehouse", warehouseId);
27539 tejbeer 1293
		model.addAttribute("selectedCategory", category);
1294
 
27509 tejbeer 1295
		return "warehouse_brand_item_stock";
1296
	}
1297
 
27538 tejbeer 1298
	@RequestMapping(value = "/getWarehouseWiseItemStock", method = RequestMethod.GET)
1299
	public String getWarehouseWiseItemStock(HttpServletRequest request, Model model,
30564 tejbeer 1300
			@RequestParam List<Integer> warehouseId, @RequestParam List<String> brands, @RequestParam String category)
27538 tejbeer 1301
			throws Exception {
27539 tejbeer 1302
		Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
1303
		if (warehouseId.contains(0)) {
1304
			warehouseId.addAll(warehouseMap.keySet());
1305
		}
27538 tejbeer 1306
		List<WarehouseWiseitemStockModel> warehouseWiseItemStock = saholicInventoryCISRepository
1307
				.selectWarehouseItemStock(warehouseId, brands, category);
27539 tejbeer 1308
 
27538 tejbeer 1309
		model.addAttribute("warehouseWiseItemStock", warehouseWiseItemStock);
1310
		model.addAttribute("warehouseMap", warehouseMap);
1311
		return "warehouse_item_details";
1312
	}
1313
 
27556 tejbeer 1314
	@RequestMapping(value = "/getWarehouseWiseBrandPartnerSale", method = RequestMethod.GET)
27591 tejbeer 1315
	public String getWarehouseWiseBrandPartnerSale(HttpServletRequest request, Model model, @RequestParam String brand)
1316
			throws Exception {
27701 tejbeer 1317
 
1318
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1319
		String email = loginDetails.getEmailId();
1320
 
31152 tejbeer 1321
		Set<Integer> authfofoIds = csService.getAuthFofoIds(email);
28472 tejbeer 1322
 
27670 tejbeer 1323
		Map<Integer, WarehouseWiseBrandSaleModel> warehouseWiseBrandPartnerSales = fofoStoreRepository
27701 tejbeer 1324
				.selectGroupByWarehouseBrandWisePartnerSale(brand, new ArrayList<>(authfofoIds)).stream()
27670 tejbeer 1325
				.collect(Collectors.toMap(x -> x.getWarehouseId(), x -> x));
1326
 
1327
		List<WarehouseWiseBrandUnbilledActivatedModel> unbilledStock = fofoStoreRepository
27701 tejbeer 1328
				.selectUnbilledActivateStockGroupByWarehouse(brand, new ArrayList<>(authfofoIds));
27670 tejbeer 1329
 
1330
		for (WarehouseWiseBrandUnbilledActivatedModel un : unbilledStock) {
1331
			WarehouseWiseBrandSaleModel bpt = warehouseWiseBrandPartnerSales.get(un.getWarehouseId());
1332
			if (bpt != null) {
1333
				bpt.setAmtd(un.getUnbilledMtd());
27676 tejbeer 1334
				bpt.setUamtdQty(un.getUnbilledQty());
27670 tejbeer 1335
			} else {
1336
				bpt = new WarehouseWiseBrandSaleModel();
1337
				bpt.setWarehouseId(un.getWarehouseId());
1338
				bpt.setAmtd(un.getUnbilledMtd());
27677 tejbeer 1339
				bpt.setUamtdQty(un.getUnbilledQty());
27670 tejbeer 1340
				bpt.setLms(0);
1341
				bpt.setLmtd(0);
1342
				bpt.setMtd(0);
1343
				bpt.setMtdQty(0);
1344
				bpt.setLmtd(0);
1345
				bpt.setLmtdQty(0);
1346
				warehouseWiseBrandPartnerSales.put(un.getWarehouseId(), bpt);
1347
			}
1348
		}
27556 tejbeer 1349
		Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
27591 tejbeer 1350
 
1351
		Set<String> brands = inventoryService.getAllTagListingBrands();
1352
		model.addAttribute("warehouseWiseBrandPartnerSales", warehouseWiseBrandPartnerSales);
27556 tejbeer 1353
		model.addAttribute("warehouseMap", warehouseMap);
27591 tejbeer 1354
		model.addAttribute("brands", brands);
1355
		model.addAttribute("selectedbrand", brand);
1356
		return "warehousewise_brand_partners_sale";
27556 tejbeer 1357
	}
1358
 
27594 tejbeer 1359
	@RequestMapping(value = "/getWarehouseWiseAccesoriesBrandPartnerSale", method = RequestMethod.GET)
1360
	public String getWarehouseWiseAccesoriesBrandPartnerSale(HttpServletRequest request, Model model,
30564 tejbeer 1361
			@RequestParam String brand) throws Exception {
27701 tejbeer 1362
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1363
		String email = loginDetails.getEmailId();
1364
		Map<String, Set<Integer>> storeGuyMap = csService.getAuthUserPartnerIdMapping();
1365
		Set<Integer> authfofoIds = storeGuyMap.get(email);
28472 tejbeer 1366
 
1367
		AuthUser authUser = authRepository.selectByEmailOrMobile(email);
1368
		if (authfofoIds == null) {
1369
			List<Position> positions1 = positionRepository.selectAll(authUser.getId());
1370
			if (positions1.stream().filter(x -> x.getCategoryId() == ProfitMandiConstants.TICKET_CATEGORY_MASTER)
1371
					.count() > 0) {
1372
				authfofoIds = csService.getPositionCustomRetailerMap(positions1).values().stream()
1373
						.flatMap(x -> x.stream()).map(x -> x.getPartnerId()).collect(Collectors.toSet());
1374
			}
1375
		}
27594 tejbeer 1376
		List<WarehouseWiseBrandSaleModel> warehouseWiseBrandPartnerSales = fofoStoreRepository
27701 tejbeer 1377
				.selectGroupByWarehouseAccesoriesBrandWisePartnerSale(brand, new ArrayList<>(authfofoIds));
27594 tejbeer 1378
		Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
1379
 
1380
		Set<String> brands = inventoryService.getAllTagListingBrands();
1381
		model.addAttribute("warehouseWiseBrandPartnerSales", warehouseWiseBrandPartnerSales);
1382
		model.addAttribute("warehouseMap", warehouseMap);
1383
		model.addAttribute("brands", brands);
1384
		model.addAttribute("selectedbrand", brand);
1385
		return "warehousewise_accessoriesbrand_sale";
1386
	}
1387
 
27556 tejbeer 1388
	@RequestMapping(value = "/getWarehouseBrandWiseItemSale", method = RequestMethod.GET)
1389
	public String getWarehouseBrandWiseItemSale(HttpServletRequest request, Model model,
30564 tejbeer 1390
			@RequestParam List<Integer> warehouseId, @RequestParam String brand) throws Exception {
27556 tejbeer 1391
		Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
27701 tejbeer 1392
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1393
		String email = loginDetails.getEmailId();
31152 tejbeer 1394
		Set<Integer> authfofoIds = csService.getAuthFofoIds(email);
27670 tejbeer 1395
		Map<Integer, WarehouseBrandWiseItemSaleModel> branditemSalesMap = fofoStoreRepository
27701 tejbeer 1396
				.selectWarehouseBrandItemSale(warehouseId, brand, new ArrayList<>(authfofoIds)).stream()
27670 tejbeer 1397
				.collect(Collectors.toMap(x -> x.getItemId(), x -> x));
1398
 
1399
		List<WarehouseBrandItemUnbilledActivatedModel> unbilledItems = fofoStoreRepository
27701 tejbeer 1400
				.selectWarehouseBrandItemUnbilledActivateStock(warehouseId, brand, new ArrayList<>(authfofoIds));
27670 tejbeer 1401
 
1402
		for (WarehouseBrandItemUnbilledActivatedModel un : unbilledItems) {
1403
			WarehouseBrandWiseItemSaleModel bpt = branditemSalesMap.get(un.getItemId());
1404
			if (bpt != null) {
1405
				bpt.setAmtd(un.getAmtd());
27676 tejbeer 1406
				bpt.setUamtdQty(un.getUnmtdQty());
27670 tejbeer 1407
			} else {
1408
				bpt = new WarehouseBrandWiseItemSaleModel();
1409
				bpt.setWarehouseId(un.getWarehouseId());
1410
				bpt.setItemId(un.getItemId());
1411
				bpt.setAmtd(un.getAmtd());
27677 tejbeer 1412
				bpt.setUamtdQty(un.getUnmtdQty());
27670 tejbeer 1413
				bpt.setBrand(un.getBrand());
1414
				bpt.setModelName(un.getModelName());
1415
				bpt.setModelNumber(un.getModelNumber());
1416
				bpt.setColor(un.getColor());
1417
				bpt.setLms(0);
1418
				bpt.setLmtd(0);
1419
				bpt.setMtd(0);
1420
				bpt.setMtdQty(0);
1421
				bpt.setLmtd(0);
1422
				bpt.setLmtdQty(0);
1423
				branditemSalesMap.put(un.getItemId(), bpt);
1424
			}
1425
		}
1426
		model.addAttribute("branditemSales", branditemSalesMap);
27556 tejbeer 1427
		model.addAttribute("warehouseMap", warehouseMap);
1428
		return "warehouse_partner_itemwise_sale";
1429
	}
1430
 
27594 tejbeer 1431
	@RequestMapping(value = "/getWarehouseAccesoriesBrandWiseItemSale", method = RequestMethod.GET)
1432
	public String getWarehouseAccesoriesBrandWiseItemSale(HttpServletRequest request, Model model,
30564 tejbeer 1433
			@RequestParam List<Integer> warehouseId, @RequestParam String brand) throws Exception {
27594 tejbeer 1434
		Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
27701 tejbeer 1435
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1436
		String email = loginDetails.getEmailId();
1437
		Map<String, Set<Integer>> storeGuyMap = csService.getAuthUserPartnerIdMapping();
1438
		Set<Integer> authfofoIds = storeGuyMap.get(email);
27594 tejbeer 1439
		List<WarehouseBrandWiseItemSaleModel> branditemSales = fofoStoreRepository
27701 tejbeer 1440
				.selectWarehouseAccesoriesBrandItemSale(warehouseId, brand, new ArrayList<>(authfofoIds));
27594 tejbeer 1441
		model.addAttribute("branditemSales", branditemSales);
1442
		model.addAttribute("warehouseMap", warehouseMap);
1443
		return "warehouse_accessories_itemwsie_sale";
1444
	}
1445
 
22354 ashik.ali 1446
	@RequestMapping(value = "/contactUs", method = RequestMethod.GET)
23923 amit.gupta 1447
	public String contactUs(HttpServletRequest request, Model model) throws Throwable {
22354 ashik.ali 1448
		model.addAttribute("appContextPath", request.getContextPath());
1449
		return "contact-us";
1450
	}
23923 amit.gupta 1451
 
25649 tejbeer 1452
	@RequestMapping(value = "/notifications", method = RequestMethod.GET)
25683 tejbeer 1453
	public String getNotificationsWithType(HttpServletRequest request,
30564 tejbeer 1454
			@RequestParam(required = false) MessageType messageType,
1455
			@RequestParam(name = "offset", defaultValue = "0") int offset,
1456
			@RequestParam(name = "limit", defaultValue = "20") int limit, Model model) throws Exception {
25649 tejbeer 1457
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
26060 tejbeer 1458
		int userId = 0;
1459
		boolean isAdmin = roleManager.isAdmin(loginDetails.getRoleIds());
1460
		if (isAdmin) {
1461
			userId = loginDetails.getFofoId();
1462
		} else {
1463
			userId = userAccountRepository.selectUserIdByRetailerId(loginDetails.getFofoId());
1464
		}
25683 tejbeer 1465
		List<Notification> notifications = null;
1466
 
26086 tejbeer 1467
		List<NotificationCampaign> notificationCampaigns = notificationCampaignRepository.getNotifications(messageType,
1468
				userId, offset, limit);
1469
		LOGGER.info("messageType" + messageType);
28468 tejbeer 1470
		notifications = fofoUser.getNotifications(notificationCampaigns, messageType);
26086 tejbeer 1471
 
25683 tejbeer 1472
		model.addAttribute("notifications", notifications);
1473
 
1474
		LOGGER.info("notifications" + notifications);
1475
		return "notification-template";
1476
	}
1477
 
25651 tejbeer 1478
	@RequestMapping(value = "/notifyDocument/documentId", method = RequestMethod.GET)
1479
	public ResponseEntity<?> retailerDocumentById(HttpServletRequest request,
30564 tejbeer 1480
			@RequestParam(name = ProfitMandiConstants.DOCUMENT_ID) int documentId, @RequestParam int cid)
25651 tejbeer 1481
			throws ProfitMandiBusinessException {
1482
		Document document = documentRepository.selectById(documentId);
1483
		NotificationCampaign nc = notificationCampaignRepository.selectById(cid);
1484
		if (nc.getDocumentId() == null) {
1485
			throw new ProfitMandiBusinessException("cid", nc.getId(), "not available");
1486
		}
1487
		if (nc.getDocumentId() != documentId) {
1488
			throw new ProfitMandiBusinessException(ProfitMandiConstants.DOCUMENT_ID, documentId, "RTLR_1014");
1489
		}
1490
		return responseSender.ok(document);
25649 tejbeer 1491
	}
1492
 
25651 tejbeer 1493
	@RequestMapping(value = "/notifyDocument/download", method = RequestMethod.GET)
1494
	public ResponseEntity<?> downloadRetailerDocument(HttpServletRequest request, @RequestParam int cid, Model model)
1495
			throws ProfitMandiBusinessException {
1496
 
1497
		NotificationCampaign nc = notificationCampaignRepository.selectById(cid);
1498
 
1499
		if (nc.getDocumentId() == null) {
1500
			throw new ProfitMandiBusinessException("cid", nc.getId(), "not available");
1501
		}
1502
 
1503
		Document document = documentRepository.selectById(nc.getDocumentId());
1504
 
1505
		FileInputStream file = null;
1506
		try {
1507
			file = new FileInputStream(document.getPath() + File.separator + document.getName());
1508
		} catch (FileNotFoundException e) {
1509
			LOGGER.error("Retailer Document file not found : ", e);
1510
			throw new ProfitMandiBusinessException(ProfitMandiConstants.DOCUMENT_ID, document.getId(), "RTLR_1013");
1511
		}
1512
		// ByteArrayOutputStream byteArrayOutputStream = new
1513
		// ByteArrayOutputStream();
1514
		// ExcelUtils.writeSchemeModels(schemeModels, byteArrayOutputStream);
1515
 
1516
		final HttpHeaders headers = new HttpHeaders();
1517
		String contentType = "";
1518
		if (document.getContentType() == ContentType.JPEG) {
1519
			contentType = "image/jpeg";
1520
		} else if (document.getContentType() == ContentType.PNG) {
1521
			contentType = "image/png";
1522
		} else if (document.getContentType() == ContentType.PDF) {
1523
			contentType = "application/pdf";
1524
		}
1525
		headers.set("Content-Type", contentType);
1526
		headers.set("Content-disposition", "inline; filename=" + document.getName());
1527
		headers.setContentLength(document.getSize());
1528
		final InputStreamResource inputStreamResource = new InputStreamResource(file);
1529
		return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
1530
	}
26460 amit.gupta 1531
 
27579 tejbeer 1532
	@RequestMapping(value = "/getItemWiseTertiary", method = RequestMethod.GET)
1533
	public String getItemWiseTertiary(HttpServletRequest request,
30564 tejbeer 1534
			@RequestParam(name = ProfitMandiConstants.FOFO_ID) int fofoId, Model model)
27579 tejbeer 1535
			throws ProfitMandiBusinessException {
1536
		List<ItemWiseTertiaryModel> itemWiseTertiary = fofoOrderRepository.SelectItemWiseTertiary(fofoId);
1537
 
1538
		LOGGER.info("itemWiseTertiary" + itemWiseTertiary);
27586 tejbeer 1539
		CustomRetailer customRetailer = retailerService.getFofoRetailer(fofoId);
1540
		model.addAttribute("customRetailer", customRetailer);
27579 tejbeer 1541
		model.addAttribute("itemWiseTertiary", itemWiseTertiary);
1542
		return "item-wise-tertiary";
1543
	}
1544
 
27586 tejbeer 1545
	@RequestMapping(value = "/getItemWiseIndent", method = RequestMethod.GET)
1546
	public String getItemWiseIndent(HttpServletRequest request,
30564 tejbeer 1547
			@RequestParam(name = ProfitMandiConstants.FOFO_ID) int fofoId, Model model)
27586 tejbeer 1548
			throws ProfitMandiBusinessException {
1549
 
1550
		List<Order> unbilledOrders = transactionService.getInTransitOrders(fofoId);
1551
		model.addAttribute("unbilledOrders", unbilledOrders);
1552
 
1553
		return "item-wise-indent";
1554
	}
1555
 
27636 tejbeer 1556
	@RequestMapping(value = "/getPartnerInvestment", method = RequestMethod.GET)
1557
	public String getPartnerInvestment(HttpServletRequest request,
30564 tejbeer 1558
			@RequestParam(name = ProfitMandiConstants.FOFO_ID) int fofoId, Model model) throws Exception {
28468 tejbeer 1559
		Map<Integer, PartnerDetailModel> partnerStats = adminUser.getPartnersStatDataFromFile();
27636 tejbeer 1560
		PartnerDetailModel partnerDetailModel = partnerStats.get(fofoId);
1561
		CustomRetailer customRetailer = retailerService.getFofoRetailer(fofoId);
1562
		model.addAttribute("partnerDetailModel", partnerDetailModel);
1563
		model.addAttribute("customRetailer", customRetailer);
1564
		return "partner-investment";
1565
	}
27727 tejbeer 1566
 
27704 amit.gupta 1567
	@RequestMapping(value = "/getPartnerPendingIndentItem", method = RequestMethod.GET)
1568
	public String getPartnerPendingIndentItem(HttpServletRequest request, @RequestParam int warehouseId,
30564 tejbeer 1569
			@RequestParam int itemId, Model model) throws ProfitMandiBusinessException {
27704 amit.gupta 1570
		List<PartnerPendingIndentItemModel> partnerPendingIndent = fofoStoreRepository
1571
				.selectPartnerPendingIndentItem(itemId, warehouseId);
27636 tejbeer 1572
 
27704 amit.gupta 1573
		model.addAttribute("partnerPendingIndent", partnerPendingIndent);
1574
		return "partner-pending-indent-item";
1575
	}
1576
 
27636 tejbeer 1577
	@RequestMapping(value = "/getPatnerActivateStock", method = RequestMethod.GET)
1578
	public String getPartnerActivateStockItem(HttpServletRequest request,
30564 tejbeer 1579
			@RequestParam(name = ProfitMandiConstants.FOFO_ID) int fofoId, Model model) throws Exception {
27636 tejbeer 1580
		List<ActivateItemModel> activateStocks = new ArrayList<>();
1581
		List<InventoryItem> inventoryItems = inventoryItemRepository.selectByActivatedNotSold(fofoId);
1582
		CustomRetailer customRetailer = retailerService.getFofoRetailer(fofoId);
1583
 
1584
		for (InventoryItem inventoryItem : inventoryItems) {
1585
			TagListing tagListing = tagListingRepository.selectByItemId(inventoryItem.getItemId());
1586
			Item item = itemRepository.selectById(inventoryItem.getItemId());
1587
			ActivateItemModel aim = new ActivateItemModel();
1588
			aim.setFofoId(inventoryItem.getFofoId());
1589
			aim.setQuantity(inventoryItem.getGoodQuantity());
1590
			aim.setAmount(tagListing.getSellingPrice());
1591
			aim.setItemDescription(item.getItemDescription());
1592
			aim.setItemId(inventoryItem.getItemId());
1593
			activateStocks.add(aim);
1594
		}
1595
 
1596
		model.addAttribute("activateStocks", activateStocks);
1597
		model.addAttribute("customRetailer", customRetailer);
1598
		return "partner-activate-stock";
1599
	}
1600
 
1601
	@RequestMapping(value = "/getPatnerBrandWiseMTDSale", method = RequestMethod.GET)
1602
	public String getPatnerBrandWiseMTDSale(HttpServletRequest request,
30564 tejbeer 1603
			@RequestParam(name = ProfitMandiConstants.FOFO_ID) int fofoId, Model model) throws Exception {
27636 tejbeer 1604
		LocalDateTime curDate = LocalDate.now().atStartOfDay();
1605
		CustomRetailer customRetailer = retailerService.getFofoRetailer(fofoId);
1606
		Map<String, Double> brandMtdAmount = fofoOrderItemRepository
1607
				.selectSumAmountGroupByBrand(curDate.withDayOfMonth(1), curDate.with(LocalTime.MAX), fofoId);
27638 tejbeer 1608
		Map<String, Long> brandMtdQty = fofoOrderItemRepository.selectSumQuantityGroupByBrand(curDate.withDayOfMonth(1),
1609
				curDate.with(LocalTime.MAX), fofoId);
27636 tejbeer 1610
		Double accesoriesmtdsale = fofoOrderRepository.selectSumSaleGroupByFofoIdsForMobileOrAccessories(fofoId,
1611
				curDate.withDayOfMonth(1), curDate.with(LocalTime.MAX), Optional.of(false)).get(fofoId);
27638 tejbeer 1612
		Long accesoriesmtdqty = fofoOrderRepository.selectSumSaleQuantityGroupByFofoIdsForMobileOrAccessories(fofoId,
1613
				curDate.withDayOfMonth(1), curDate.with(LocalTime.MAX), Optional.of(false)).get(fofoId);
1614
 
27636 tejbeer 1615
		LOGGER.info("accesoriesmtdsale" + accesoriesmtdsale);
1616
		model.addAttribute("brandMtdAmount", brandMtdAmount);
27638 tejbeer 1617
		model.addAttribute("brandMtdQty", brandMtdQty);
27636 tejbeer 1618
		model.addAttribute("accesoriesmtdsale", accesoriesmtdsale);
27638 tejbeer 1619
		model.addAttribute("accesoriesmtdqty", accesoriesmtdqty);
1620
 
27636 tejbeer 1621
		model.addAttribute("customRetailer", customRetailer);
1622
		return "partner-brand-mtd-sale";
1623
	}
1624
 
27637 tejbeer 1625
	@RequestMapping(value = "/getPatnerBrandWiseLMTDSale", method = RequestMethod.GET)
1626
	public String getPatnerBrandWiseLMTDSale(HttpServletRequest request,
30564 tejbeer 1627
			@RequestParam(name = ProfitMandiConstants.FOFO_ID) int fofoId, Model model) throws Exception {
27637 tejbeer 1628
		LocalDateTime curDate = LocalDate.now().atStartOfDay();
1629
		CustomRetailer customRetailer = retailerService.getFofoRetailer(fofoId);
1630
		Map<String, Double> brandLMtdAmount = fofoOrderItemRepository.selectSumAmountGroupByBrand(
1631
				curDate.withDayOfMonth(1).minusMonths(1), curDate.with(LocalTime.MAX).minusMonths(1), fofoId);
27638 tejbeer 1632
		Map<String, Long> brandLmtdQty = fofoOrderItemRepository.selectSumQuantityGroupByBrand(
1633
				curDate.withDayOfMonth(1).minusMonths(1), curDate.with(LocalTime.MAX).minusMonths(1), fofoId);
27637 tejbeer 1634
 
1635
		Double accesorieslmtdsale = fofoOrderRepository
1636
				.selectSumSaleGroupByFofoIdsForMobileOrAccessories(fofoId, curDate.withDayOfMonth(1).minusMonths(1),
1637
						curDate.with(LocalTime.MAX).minusMonths(1), Optional.of(false))
1638
				.get(fofoId);
27638 tejbeer 1639
		Long accesorieslmtdqty = fofoOrderRepository.selectSumSaleQuantityGroupByFofoIdsForMobileOrAccessories(fofoId,
1640
				curDate.withDayOfMonth(1).minusMonths(1), curDate.with(LocalTime.MAX).minusMonths(1),
1641
				Optional.of(false)).get(fofoId);
1642
 
27637 tejbeer 1643
		model.addAttribute("brandLMtdAmount", brandLMtdAmount);
27638 tejbeer 1644
		model.addAttribute("brandLmtdQty", brandLmtdQty);
1645
		model.addAttribute("accesorieslmtdqty", accesorieslmtdqty);
27637 tejbeer 1646
		model.addAttribute("accesorieslmtdsale", accesorieslmtdsale);
1647
		model.addAttribute("customRetailer", customRetailer);
1648
		return "partner-brand-lmtd-sale";
1649
	}
1650
 
27660 tejbeer 1651
	@RequestMapping(value = "/getPatnerBrandWiseLMSSale", method = RequestMethod.GET)
1652
	public String getPatnerBrandWiseLMSSale(HttpServletRequest request,
30564 tejbeer 1653
			@RequestParam(name = ProfitMandiConstants.FOFO_ID) int fofoId, Model model) throws Exception {
27660 tejbeer 1654
		LocalDateTime curDate = LocalDate.now().atStartOfDay();
1655
		CustomRetailer customRetailer = retailerService.getFofoRetailer(fofoId);
1656
		int lengthOfMonth = YearMonth.from(curDate.minusMonths(1)).lengthOfMonth();
1657
 
1658
		Map<String, Double> brandLMSAmount = fofoOrderItemRepository.selectSumAmountGroupByBrand(
27893 tejbeer 1659
				curDate.withDayOfMonth(1).minusMonths(1), curDate.withDayOfMonth(1), fofoId);
27660 tejbeer 1660
		Map<String, Long> brandLmsQty = fofoOrderItemRepository.selectSumQuantityGroupByBrand(
27893 tejbeer 1661
				curDate.withDayOfMonth(1).minusMonths(1), curDate.withDayOfMonth(1), fofoId);
27660 tejbeer 1662
 
27893 tejbeer 1663
		Double accesorieslmssale = fofoOrderRepository.selectSumSaleGroupByFofoIdsForMobileOrAccessories(fofoId,
1664
				curDate.withDayOfMonth(1).minusMonths(1), curDate.withDayOfMonth(1), Optional.of(false)).get(fofoId);
27660 tejbeer 1665
		Long accesorieslmsqty = fofoOrderRepository
1666
				.selectSumSaleQuantityGroupByFofoIdsForMobileOrAccessories(fofoId,
27893 tejbeer 1667
						curDate.withDayOfMonth(1).minusMonths(1), curDate.withDayOfMonth(1), Optional.of(false))
27660 tejbeer 1668
				.get(fofoId);
1669
 
1670
		model.addAttribute("brandLMSAmount", brandLMSAmount);
1671
		model.addAttribute("brandLmsQty", brandLmsQty);
1672
		model.addAttribute("accesorieslmssale", accesorieslmssale);
1673
		model.addAttribute("accesorieslmsqty", accesorieslmsqty);
1674
		model.addAttribute("customRetailer", customRetailer);
1675
		return "partner-brand-lms-sale";
1676
	}
1677
 
27640 tejbeer 1678
	@RequestMapping(value = "/getPatnerInStock", method = RequestMethod.GET)
1679
	public String getPatnerInStock(HttpServletRequest request,
30564 tejbeer 1680
			@RequestParam(name = ProfitMandiConstants.FOFO_ID) int fofoId, Model model) throws Exception {
27640 tejbeer 1681
 
1682
		CustomRetailer customRetailer = retailerService.getFofoRetailer(fofoId);
1683
 
27660 tejbeer 1684
		List<InStockBrandModel> mobileStocks = currentInventorySnapshotRepository
27640 tejbeer 1685
				.selectSumInStockMobileGroupByBrand(fofoId);
27660 tejbeer 1686
		List<InStockBrandModel> accesStock = currentInventorySnapshotRepository
27640 tejbeer 1687
				.selectSumInStockAccessoriesGroupByBrand(fofoId);
1688
 
27660 tejbeer 1689
		List<InStockBrandItemModel> stockItemlist = currentInventorySnapshotRepository
1690
				.selectInStockItemsByBrand(fofoId);
1691
 
1692
		Map<String, List<InStockBrandItemModel>> stockItemMap = stockItemlist.stream()
1693
				.collect(Collectors.groupingBy(InStockBrandItemModel::getBrand));
1694
 
1695
		model.addAttribute("stockItemMap", stockItemMap);
1696
		model.addAttribute("mobileStock", mobileStocks);
1697
		model.addAttribute("accesStock", accesStock);
27640 tejbeer 1698
		model.addAttribute("customRetailer", customRetailer);
1699
		return "partner-instock-item";
1700
	}
1701
 
27660 tejbeer 1702
	@RequestMapping(value = "/getOpenTicketByFofoId", method = RequestMethod.GET)
1703
	public String getOpenTicketByFofoId(HttpServletRequest request,
30564 tejbeer 1704
			@RequestParam(name = ProfitMandiConstants.FOFO_ID) int fofoId, Model model) throws Exception {
27660 tejbeer 1705
		Map<Integer, AuthUser> ticketIdAuthUser = new HashMap<>();
1706
		CustomRetailer customRetailer = retailerService.getFofoRetailer(fofoId);
1707
		List<Integer> ticketIds = ticketRepository.selectAllOpenTicketByRetailer(fofoId).stream().map(x -> x.getId())
1708
				.collect(Collectors.toList());
1709
		List<TicketAssigned> ticketAssigns = ticketAssignedRepository.selectByTicketIds(ticketIds);
1710
 
1711
		for (TicketAssigned ticketAssign : ticketAssigns) {
1712
			AuthUser authUser = authRepository.selectById(ticketAssign.getAssineeId());
1713
			ticketIdAuthUser.put(ticketAssign.getTicketId(), authUser);
1714
		}
1715
		model.addAttribute("ticketIdAuthUser", ticketIdAuthUser);
1716
		model.addAttribute("ticketAssigns", ticketAssigns);
1717
		model.addAttribute("customRetailer", customRetailer);
1718
		return "open-ticket";
1719
	}
1720
 
27893 tejbeer 1721
	@RequestMapping(value = "/getPartnerSecondarySale", method = RequestMethod.GET)
1722
	public String getPartnerSecondarySale(HttpServletRequest request,
30564 tejbeer 1723
			@RequestParam(name = ProfitMandiConstants.FOFO_ID) int fofoId, @RequestParam String timeValue, Model model)
27893 tejbeer 1724
			throws Exception {
1725
		LocalDateTime curDate = LocalDate.now().atStartOfDay();
1726
		CustomRetailer customRetailer = retailerService.getFofoRetailer(fofoId);
1727
		int lengthOfMonth = YearMonth.from(curDate.minusMonths(1)).lengthOfMonth();
1728
		LocalDateTime startDate = null;
1729
		LocalDateTime endDate = null;
1730
		List<InStockBrandModel> secondarySale = null;
1731
		Map<String, List<InStockBrandItemModel>> secondaryItemSale = null;
1732
 
1733
		if (timeValue.equals("mtd")) {
1734
			startDate = curDate.withDayOfMonth(1);
1735
			endDate = curDate.with(LocalTime.MAX);
1736
			secondarySale = orderRepository.selectAllBilledOrderBrandByFofoId(startDate, endDate, fofoId);
1737
			secondaryItemSale = orderRepository.selectAllBilledOrderBrandItemByFofoId(startDate, endDate, fofoId)
1738
					.stream().collect(Collectors.groupingBy(InStockBrandItemModel::getBrand));
1739
			LOGGER.info("secondarySalemtd" + secondarySale);
1740
		} else if (timeValue.equals("lmtd")) {
1741
			startDate = curDate.withDayOfMonth(1).minusMonths(1);
1742
			endDate = curDate.with(LocalTime.MAX).minusMonths(1);
1743
			secondaryItemSale = orderRepository.selectAllBilledOrderBrandItemByFofoId(startDate, endDate, fofoId)
1744
					.stream().collect(Collectors.groupingBy(InStockBrandItemModel::getBrand));
1745
 
1746
			secondarySale = orderRepository.selectAllBilledOrderBrandByFofoId(startDate, endDate, fofoId);
1747
			LOGGER.info("secondarySalelmtd" + secondarySale);
1748
 
1749
		} else {
1750
			startDate = curDate.withDayOfMonth(1).minusMonths(1);
1751
			endDate = curDate.withDayOfMonth(1);
1752
			secondaryItemSale = orderRepository.selectAllBilledOrderBrandItemByFofoId(startDate, endDate, fofoId)
1753
					.stream().collect(Collectors.groupingBy(InStockBrandItemModel::getBrand));
1754
 
1755
			secondarySale = orderRepository.selectAllBilledOrderBrandByFofoId(startDate, endDate, fofoId);
1756
			LOGGER.info("secondarySalelms" + secondarySale);
1757
 
1758
		}
1759
 
1760
		LOGGER.info("secondarySale" + secondarySale);
1761
		model.addAttribute("secondarySale", secondarySale);
1762
		model.addAttribute("secondaryItemSale", secondaryItemSale);
1763
		model.addAttribute("customRetailer", customRetailer);
1764
 
1765
		return "partner-secondary-order";
1766
	}
1767
 
28451 tejbeer 1768
	@RequestMapping(value = "/getMobileBrandWise", method = RequestMethod.GET)
1769
	public String getMobileBrandWise(HttpServletRequest request, Model model) throws Exception {
1770
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1771
		String email = loginDetails.getEmailId();
1772
 
1773
		AuthUser authUser = authRepository.selectByEmailOrMobile(email);
31152 tejbeer 1774
		Set<Integer> fofoIds = csService.getAuthFofoIds(email);
28451 tejbeer 1775
 
1776
		Map<String, BrandWisePartnerSaleModel> partnersBrandSaleMap = null;
1777
		partnersBrandSaleMap = fofoStoreRepository.selectGroupByBrandWarehousePartnerSale(new ArrayList<>(fofoIds))
1778
				.stream().collect(Collectors.toMap(x -> x.getBrand(), x -> x));
1779
 
1780
		List<BrandWiseUnbilledActivateStockModel> unbilledActivatedStock = fofoStoreRepository
1781
				.selectUnbilledActivateStockGroupByBrand(new ArrayList<>(fofoIds));
1782
		for (BrandWiseUnbilledActivateStockModel un : unbilledActivatedStock) {
1783
			BrandWisePartnerSaleModel bpt = partnersBrandSaleMap.get(un.getBrand());
1784
			if (bpt != null) {
1785
				bpt.setAmtd(un.getUnbilledMtd());
1786
				bpt.setUamtdQty(un.getUnbilledMTDQty());
1787
			} else {
1788
				bpt = new BrandWisePartnerSaleModel();
1789
				bpt.setBrand(un.getBrand());
1790
				bpt.setAmtd(un.getUnbilledMtd());
1791
				bpt.setUamtdQty(un.getUnbilledMTDQty());
1792
				bpt.setLms(0);
1793
				bpt.setLmtd(0);
1794
				bpt.setMtd(0);
1795
				bpt.setMtdQty(0);
1796
				bpt.setLmtd(0);
1797
				bpt.setLmtdQty(0);
1798
				partnersBrandSaleMap.put(un.getBrand(), bpt);
1799
			}
1800
		}
1801
 
1802
		model.addAttribute("brandSalesMap", partnersBrandSaleMap);
1803
 
1804
		return "mobile-brand-wise-report";
1805
	}
1806
 
1807
	@RequestMapping(value = "/getAccessoriesBrandWise", method = RequestMethod.GET)
1808
	public String getAccessoriesBrandWise(HttpServletRequest request, Model model) throws Exception {
1809
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1810
		String email = loginDetails.getEmailId();
1811
 
31152 tejbeer 1812
		Set<Integer> fofoIds = csService.getAuthFofoIds(email);
28451 tejbeer 1813
 
1814
		List<BrandWisePartnerSaleModel> accessoriesBrandSales = null;
1815
 
1816
		accessoriesBrandSales = fofoStoreRepository
1817
				.selectGroupByBrandAccesoriesWarehousePartnerSale(new ArrayList<>(fofoIds));
1818
 
1819
		model.addAttribute("accessoriesBrandSales", accessoriesBrandSales);
1820
		return "accessories-brand-wise-report";
1821
	}
1822
 
1823
	@RequestMapping(value = "/getMobileLMSGraph", method = RequestMethod.GET)
28461 tejbeer 1824
	public String getMobileLMSGraph(HttpServletRequest request, @RequestParam(required = false) int warehouseId,
30564 tejbeer 1825
			@RequestParam(required = false) LocalDateTime date, @RequestParam(required = false) LocalDateTime endDate,
1826
			@RequestParam List<Integer> fofoIds, @RequestParam String filterType, Model model) throws Exception {
28451 tejbeer 1827
		Map<Integer, List<Integer>> warehouseIdFofoIdMap = fofoStoreRepository
1828
				.selectActivePartnersByRetailerIds(new ArrayList<>(fofoIds)).stream().collect(Collectors.groupingBy(
1829
						FofoStore::getWarehouseId, Collectors.mapping(FofoStore::getId, Collectors.toList())));
1830
 
1831
		ChartModel cm;
1832
		if (warehouseId != 0) {
28468 tejbeer 1833
			cm = adminUser.getBrandWiseLms(Arrays.asList(warehouseId),
30279 tejbeer 1834
					fofoIds.stream().map(x -> x).collect(Collectors.toList()), date.toLocalDate(),
1835
					endDate.toLocalDate(), filterType);
28451 tejbeer 1836
		} else {
28468 tejbeer 1837
			cm = adminUser.getBrandWiseLms(new ArrayList<>(warehouseIdFofoIdMap.keySet()),
30279 tejbeer 1838
					fofoIds.stream().map(x -> x).collect(Collectors.toList()), date.toLocalDate(),
1839
					endDate.toLocalDate(), filterType);
28451 tejbeer 1840
 
1841
		}
1842
 
1843
		LOGGER.info("chartMap" + gson.toJson(cm));
1844
		model.addAttribute("chartMap", gson.toJson(cm));
1845
		return "brand-wise-mobile-lms-chart";
1846
	}
1847
 
28461 tejbeer 1848
	@RequestMapping(value = "/getMobileLMSFilter", method = RequestMethod.GET)
1849
	public String getMobileLMSFilter(HttpServletRequest request,
30564 tejbeer 1850
			@RequestParam(required = false, defaultValue = "0") int warehouseId,
1851
			@RequestParam(required = false) LocalDateTime date, @RequestParam(required = false) LocalDateTime endDate,
1852
			Model model) throws Exception {
28461 tejbeer 1853
 
1854
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1855
		String email = loginDetails.getEmailId();
1856
 
30279 tejbeer 1857
		if (date == null) {
1858
			LocalDateTime curDate = LocalDate.now().atStartOfDay();
28461 tejbeer 1859
 
30279 tejbeer 1860
			LocalDateTime startOfMonth = curDate.withDayOfMonth(1).minusMonths(6);
1861
			date = startOfMonth.toLocalDate().atStartOfDay();
1862
		}
28461 tejbeer 1863
 
30279 tejbeer 1864
		if (endDate == null) {
1865
			LocalDateTime curDate = LocalDate.now().atTime(LocalTime.MAX);
1866
 
1867
			endDate = curDate;
1868
 
1869
		}
1870
 
1871
		Map<String, Object> map = adminUser.getFilter(warehouseId, email, date, endDate);
28461 tejbeer 1872
		model.addAttribute("warehouseId", warehouseId);
1873
		model.addAllAttributes(map);
1874
 
30279 tejbeer 1875
		return "chart-filter-lms";
28461 tejbeer 1876
	}
1877
 
1878
	@RequestMapping(value = "/getMobileLMPGraph", method = RequestMethod.GET)
1879
	public String getMobileLMPGraph(HttpServletRequest request, @RequestParam(required = false) int warehouseId,
30564 tejbeer 1880
			@RequestParam(required = false) LocalDateTime date, @RequestParam(required = false) LocalDateTime endDate,
1881
			@RequestParam List<Integer> fofoIds, @RequestParam String filterType, Model model) throws Exception {
28461 tejbeer 1882
		Map<Integer, List<Integer>> warehouseIdFofoIdMap = fofoStoreRepository
1883
				.selectActivePartnersByRetailerIds(new ArrayList<>(fofoIds)).stream().collect(Collectors.groupingBy(
1884
						FofoStore::getWarehouseId, Collectors.mapping(FofoStore::getId, Collectors.toList())));
1885
 
1886
		ChartModel cm;
1887
		if (warehouseId != 0) {
28468 tejbeer 1888
			cm = adminUser.getBrandWiseLmp(Arrays.asList(warehouseId),
30279 tejbeer 1889
					fofoIds.stream().map(x -> x).collect(Collectors.toList()), date.toLocalDate(),
1890
					endDate.toLocalDate(), filterType);
28461 tejbeer 1891
		} else {
28468 tejbeer 1892
			cm = adminUser.getBrandWiseLmp(new ArrayList<>(warehouseIdFofoIdMap.keySet()),
30279 tejbeer 1893
					fofoIds.stream().map(x -> x).collect(Collectors.toList()), date.toLocalDate(),
1894
					endDate.toLocalDate(), filterType);
28461 tejbeer 1895
 
1896
		}
1897
 
1898
		LOGGER.info("chartMap" + gson.toJson(cm));
1899
		model.addAttribute("chartMap", gson.toJson(cm));
1900
		return "brand-wise-mobile-lmp-chart";
1901
	}
1902
 
31259 tejbeer 1903
	@RequestMapping(value = "/getCountByCategory", method = RequestMethod.GET)
1904
	public String getCountByCategory(HttpServletRequest request,
1905
			@RequestParam(required = false, defaultValue = "0") int warehouseId, Model model) throws Exception {
1906
 
1907
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1908
		String email = loginDetails.getEmailId();
1909
 
1910
		Set<Integer> fofoIds = csService.getAuthFofoIds(email);
1911
 
1912
		if (fofoIds != null && fofoIds.size() > 0) {
1913
			Map<Integer, PartnerDetailModel> partnerStats = adminUser.getPartnersStatDataFromFile();
1914
			if (partnerStats != null) {
1915
 
31263 tejbeer 1916
				List<PartnerDetailModel> partnerDetails = fofoIds.stream().filter(x -> partnerStats.containsKey(x))
1917
						.map(x -> partnerStats.get(x)).collect(Collectors.toList());
31259 tejbeer 1918
 
31267 tejbeer 1919
				Map<Integer, Double> last3MonthSale = fofoOrderItemRepository.selectSumMopGroupByRetailer(
1920
						LocalDateTime.now().withDayOfMonth(1).minusMonths(2), LocalDateTime.now(), 0, false);
1921
 
1922
				Map<String, Long> lmsMap = new HashMap<>();
1923
				if (!last3MonthSale.isEmpty()) {
1924
 
1925
					int days = 60 + LocalDateTime.now().getDayOfMonth();
1926
 
1927
					for (Entry<Integer, Double> last3MonthEntry : last3MonthSale.entrySet()) {
1928
						if (fofoIds.contains(last3MonthEntry.getKey())) {
1929
 
1930
							Double monthSale = last3MonthEntry.getValue();
1931
 
1932
							if (monthSale == null) {
1933
								monthSale = (double) 0;
1934
 
1935
							}
1936
 
1937
							double avg3MonthSale = (monthSale / days) * 30;
1938
							String milestone = Milestone.get((int) avg3MonthSale);
1939
 
1940
							long value = 0;
1941
 
1942
							if (lmsMap.containsKey(milestone)) {
1943
								value = lmsMap.get(milestone) + 1;
1944
								lmsMap.put(milestone, value);
1945
							} else {
1946
								lmsMap.put(milestone, value + 1);
1947
 
1948
							}
1949
						}
1950
 
1951
					}
1952
 
1953
				}
1954
 
1955
				LOGGER.info("partnerDetails" + LocalDateTime.now().withDayOfMonth(1).minusMonths(2));
1956
 
31260 tejbeer 1957
				if (partnerDetails != null) {
31263 tejbeer 1958
 
31267 tejbeer 1959
					Map<String, Long> mtdMap = partnerDetails.stream()
31260 tejbeer 1960
							.collect(Collectors.groupingBy(x -> x.getMtdValue(), Collectors.counting()));
31267 tejbeer 1961
					Map<String, Long> lmtdMap = partnerDetails.stream()
31263 tejbeer 1962
							.collect(Collectors.groupingBy(x -> Milestone.get(x.getLmtd()), Collectors.counting()));
31259 tejbeer 1963
 
31264 tejbeer 1964
					LOGGER.info("mtdMap" + mtdMap);
1965
 
1966
					LOGGER.info("lmtdMap" + lmtdMap);
1967
 
1968
					LOGGER.info("lmsMap" + lmsMap);
1969
 
31260 tejbeer 1970
					model.addAttribute("mtdMap", mtdMap);
1971
					model.addAttribute("lmtdMap", lmtdMap);
1972
					model.addAttribute("lmsMap", lmsMap);
1973
 
1974
				}
1975
 
31259 tejbeer 1976
			}
1977
		}
1978
 
31267 tejbeer 1979
		model.addAttribute("warehouseMap", ProfitMandiConstants.WAREHOUSE_MAP);
1980
 
1981
		LOGGER.info("warehouseId" + Milestone.values());
1982
 
1983
		model.addAttribute("warehouseId", warehouseId);
1984
 
31259 tejbeer 1985
		model.addAttribute("milestones", Milestone.values());
1986
 
1987
		return "milestone";
1988
 
1989
	}
1990
 
28825 tejbeer 1991
	@RequestMapping(value = "/getActivatedModelWarehouseWise", method = RequestMethod.GET)
1992
	public String getActivatedModelWarehouseWise(HttpServletRequest request, Model model, @RequestParam String brand)
1993
			throws Exception {
1994
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1995
		List<Integer> fofoIds = getFofoIds(loginDetails);
1996
		List<WarehouseWiseActivatedModel> warehouseWiseActivatedModels = activatedImeiRepository
1997
				.selectActivatedModelGroupByWarehouse(brand, fofoIds);
1998
		Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
1999
 
2000
		List<DBObject> mobileBrands = mongoClient.getAllBrandsToDisplay(3);
2001
 
2002
		List<String> brands = mobileBrands.stream().map(x -> (String) x.get("name")).collect(Collectors.toList());
2003
		LOGGER.info("brands" + brands.add("Redmi"));
2004
 
2005
		model.addAttribute("warehouseWiseActivatedModels", warehouseWiseActivatedModels);
2006
		model.addAttribute("warehouseMap", warehouseMap);
2007
		model.addAttribute("brands", brands);
2008
		model.addAttribute("selectedbrand", brand);
2009
		return "warehousewise_activated_model";
2010
	}
2011
 
2012
	@RequestMapping(value = "/getActivatedModelByBrand", method = RequestMethod.GET)
2013
	public String getActivatedModelByBrand(HttpServletRequest request, Model model) throws Exception {
2014
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
31152 tejbeer 2015
		Set<Integer> fofoIds = csService.getAuthFofoIds(loginDetails.getEmailId());
2016
 
28825 tejbeer 2017
		List<BrandWiseActivatedModel> activatedModels = activatedImeiRepository
2018
				.selectActivatedModelGroupByBrand(new ArrayList<>(fofoIds));
2019
		model.addAttribute("activatedModels", activatedModels);
2020
		return "activation-brandwise-report";
2021
	}
2022
 
2023
	@RequestMapping(value = "/getWarehouseBrandWiseItemActivatedModel", method = RequestMethod.GET)
2024
	public String getWarehouseBrandWiseItemActivatedModel(HttpServletRequest request, Model model,
30564 tejbeer 2025
			@RequestParam List<Integer> warehouseId, @RequestParam String brand) throws Exception {
28825 tejbeer 2026
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
2027
		List<Integer> fofoIds = getFofoIds(loginDetails);
2028
 
2029
		Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
2030
		List<WarehouseBrandWiseItemActivatedModel> activatedItems = activatedImeiRepository
2031
				.selectWarehouseBrandActivatedItem(warehouseId, brand, fofoIds);
2032
		model.addAttribute("warehouseMap", warehouseMap);
2033
		model.addAttribute("activatedItems", activatedItems);
2034
		return "warehouse-activated-itemwise-model";
2035
 
2036
	}
2037
 
2038
	@RequestMapping(value = "/getActivatedImeiUpdationDate", method = RequestMethod.GET)
2039
	public String getActivatedImeiUpdationDate(HttpServletRequest request, Model model) throws Exception {
2040
 
2041
		Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
2042
 
2043
		List<ActivationImeiUpdationModel> activationImeiUpdations = activatedImeiRepository
2044
				.selectActivatedUpdationDate();
2045
		model.addAttribute("warehouseMap", warehouseMap);
2046
		model.addAttribute("activationImeiUpdations", activationImeiUpdations);
2047
		return "activation-updation-timestamp";
2048
 
2049
	}
2050
 
2051
	private List<Integer> getFofoIds(LoginDetails loginDetails) throws ProfitMandiBusinessException {
2052
		String email = loginDetails.getEmailId();
2053
 
2054
		AuthUser authUser = authRepository.selectByEmailOrMobile(email);
2055
		Map<String, Set<Integer>> storeGuyMap = csService.getAuthUserPartnerIdMapping();
2056
 
2057
		Set<Integer> fofoIds = storeGuyMap.get(authUser.getEmailId());
2058
		if (emails.contains(authUser.getEmailId())) {
2059
			fofoIds = storeGuyMap.get("tarun.verma@smartdukaan.com");
2060
			LOGGER.info("fofoIds" + fofoIds);
2061
		}
2062
 
2063
		if (fofoIds == null) {
2064
			List<Position> positions1 = positionRepository.selectAll(authUser.getId());
2065
			if (positions1.stream().filter(x -> x.getCategoryId() == ProfitMandiConstants.TICKET_CATEGORY_MASTER)
2066
					.count() > 0) {
2067
				fofoIds = csService.getPositionCustomRetailerMap(positions1).values().stream().flatMap(x -> x.stream())
2068
						.map(x -> x.getPartnerId()).collect(Collectors.toSet());
2069
			}
2070
		}
2071
		return new ArrayList<>(fofoIds);
2072
	}
2073
 
21615 kshitij.so 2074
}