Subversion Repositories SmartDukaan

Rev

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