Subversion Repositories SmartDukaan

Rev

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