Subversion Repositories SmartDukaan

Rev

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