Subversion Repositories SmartDukaan

Rev

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

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