Subversion Repositories SmartDukaan

Rev

Rev 31129 | Rev 31154 | 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
 
1226
		return "auth_user_partner_detail";
1227
	}
1228
 
27509 tejbeer 1229
	@RequestMapping(value = "/getWarehouseWiseBrandStock", method = RequestMethod.GET)
27701 tejbeer 1230
	public String getWarehouseWiseBrandStock(HttpServletRequest request, Model model,
30564 tejbeer 1231
			@RequestParam List<Integer> warehouseId) throws Exception {
27701 tejbeer 1232
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1233
		String email = loginDetails.getEmailId();
31152 tejbeer 1234
		Set<Integer> authfofoIds = csService.getAuthFofoIds(email);
27701 tejbeer 1235
		Map<Integer, List<Integer>> warehouseIdFofoIdMap = fofoStoreRepository
1236
				.selectActivePartnersByRetailerIds(new ArrayList<>(authfofoIds)).stream().collect(Collectors.groupingBy(
1237
						FofoStore::getWarehouseId, Collectors.mapping(FofoStore::getId, Collectors.toList())));
1238
		List<WarehouseWiseBrandStockModel> warehouseWiseBrandStock = new ArrayList<>();
1239
		if (!warehouseId.contains(0)) {
1240
			warehouseWiseBrandStock = saholicInventoryCISRepository.selectGroupByWarehouseAndBrand(warehouseId);
1241
		} else {
1242
			LOGGER.info("warehouseIdFofoIdMap" + warehouseIdFofoIdMap.keySet());
1243
			warehouseWiseBrandStock = saholicInventoryCISRepository
1244
					.selectGroupByWarehouseAndBrand(new ArrayList<>(warehouseIdFofoIdMap.keySet()));
1245
 
1246
		}
27542 tejbeer 1247
		Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
27509 tejbeer 1248
		model.addAttribute("warehouseWiseBrandStock", warehouseWiseBrandStock);
27542 tejbeer 1249
		model.addAttribute("warehouseId", warehouseId);
27509 tejbeer 1250
		model.addAttribute("warehouseMap", warehouseMap);
27660 tejbeer 1251
 
27509 tejbeer 1252
		return "warehouse_brand_stock";
1253
	}
1254
 
27529 tejbeer 1255
	@RequestMapping(value = "/getWarehouseWiseData", method = RequestMethod.GET)
1256
	public String getWarehouseWiseData(HttpServletRequest request, Model model) throws Exception {
1257
		inventoryService.getItemAvailabilityAndIndent();
1258
		model.addAttribute("response", mvcResponseSender.createResponseString(true));
1259
		return "response";
1260
	}
1261
 
27539 tejbeer 1262
	@RequestMapping(value = "/getWarehouseWiseBrandAndCategory", method = RequestMethod.GET)
1263
	public String getWarehouseWiseBrandAndCategory(HttpServletRequest request, Model model,
30564 tejbeer 1264
			@RequestParam List<Integer> warehouseId, @RequestParam List<String> brands, @RequestParam String category)
27538 tejbeer 1265
			throws Exception {
27509 tejbeer 1266
 
1267
		Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
27529 tejbeer 1268
		List<String> listbrands = saholicInventoryCISRepository.selectAllBrand();
27538 tejbeer 1269
		List<String> listCategory = saholicInventoryCISRepository.selectAllSubCategory();
27539 tejbeer 1270
 
27509 tejbeer 1271
		model.addAttribute("warehouseMap", warehouseMap);
27529 tejbeer 1272
		model.addAttribute("brands", listbrands);
27538 tejbeer 1273
		model.addAttribute("listCategory", listCategory);
1274
 
27529 tejbeer 1275
		model.addAttribute("selectedBrand", brands);
27538 tejbeer 1276
		model.addAttribute("selectedWarehouse", warehouseId);
27539 tejbeer 1277
		model.addAttribute("selectedCategory", category);
1278
 
27509 tejbeer 1279
		return "warehouse_brand_item_stock";
1280
	}
1281
 
27538 tejbeer 1282
	@RequestMapping(value = "/getWarehouseWiseItemStock", method = RequestMethod.GET)
1283
	public String getWarehouseWiseItemStock(HttpServletRequest request, Model model,
30564 tejbeer 1284
			@RequestParam List<Integer> warehouseId, @RequestParam List<String> brands, @RequestParam String category)
27538 tejbeer 1285
			throws Exception {
27539 tejbeer 1286
		Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
1287
		if (warehouseId.contains(0)) {
1288
			warehouseId.addAll(warehouseMap.keySet());
1289
		}
27538 tejbeer 1290
		List<WarehouseWiseitemStockModel> warehouseWiseItemStock = saholicInventoryCISRepository
1291
				.selectWarehouseItemStock(warehouseId, brands, category);
27539 tejbeer 1292
 
27538 tejbeer 1293
		model.addAttribute("warehouseWiseItemStock", warehouseWiseItemStock);
1294
		model.addAttribute("warehouseMap", warehouseMap);
1295
		return "warehouse_item_details";
1296
	}
1297
 
27556 tejbeer 1298
	@RequestMapping(value = "/getWarehouseWiseBrandPartnerSale", method = RequestMethod.GET)
27591 tejbeer 1299
	public String getWarehouseWiseBrandPartnerSale(HttpServletRequest request, Model model, @RequestParam String brand)
1300
			throws Exception {
27701 tejbeer 1301
 
1302
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1303
		String email = loginDetails.getEmailId();
1304
 
31152 tejbeer 1305
		Set<Integer> authfofoIds = csService.getAuthFofoIds(email);
28472 tejbeer 1306
 
27670 tejbeer 1307
		Map<Integer, WarehouseWiseBrandSaleModel> warehouseWiseBrandPartnerSales = fofoStoreRepository
27701 tejbeer 1308
				.selectGroupByWarehouseBrandWisePartnerSale(brand, new ArrayList<>(authfofoIds)).stream()
27670 tejbeer 1309
				.collect(Collectors.toMap(x -> x.getWarehouseId(), x -> x));
1310
 
1311
		List<WarehouseWiseBrandUnbilledActivatedModel> unbilledStock = fofoStoreRepository
27701 tejbeer 1312
				.selectUnbilledActivateStockGroupByWarehouse(brand, new ArrayList<>(authfofoIds));
27670 tejbeer 1313
 
1314
		for (WarehouseWiseBrandUnbilledActivatedModel un : unbilledStock) {
1315
			WarehouseWiseBrandSaleModel bpt = warehouseWiseBrandPartnerSales.get(un.getWarehouseId());
1316
			if (bpt != null) {
1317
				bpt.setAmtd(un.getUnbilledMtd());
27676 tejbeer 1318
				bpt.setUamtdQty(un.getUnbilledQty());
27670 tejbeer 1319
			} else {
1320
				bpt = new WarehouseWiseBrandSaleModel();
1321
				bpt.setWarehouseId(un.getWarehouseId());
1322
				bpt.setAmtd(un.getUnbilledMtd());
27677 tejbeer 1323
				bpt.setUamtdQty(un.getUnbilledQty());
27670 tejbeer 1324
				bpt.setLms(0);
1325
				bpt.setLmtd(0);
1326
				bpt.setMtd(0);
1327
				bpt.setMtdQty(0);
1328
				bpt.setLmtd(0);
1329
				bpt.setLmtdQty(0);
1330
				warehouseWiseBrandPartnerSales.put(un.getWarehouseId(), bpt);
1331
			}
1332
		}
27556 tejbeer 1333
		Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
27591 tejbeer 1334
 
1335
		Set<String> brands = inventoryService.getAllTagListingBrands();
1336
		model.addAttribute("warehouseWiseBrandPartnerSales", warehouseWiseBrandPartnerSales);
27556 tejbeer 1337
		model.addAttribute("warehouseMap", warehouseMap);
27591 tejbeer 1338
		model.addAttribute("brands", brands);
1339
		model.addAttribute("selectedbrand", brand);
1340
		return "warehousewise_brand_partners_sale";
27556 tejbeer 1341
	}
1342
 
27594 tejbeer 1343
	@RequestMapping(value = "/getWarehouseWiseAccesoriesBrandPartnerSale", method = RequestMethod.GET)
1344
	public String getWarehouseWiseAccesoriesBrandPartnerSale(HttpServletRequest request, Model model,
30564 tejbeer 1345
			@RequestParam String brand) throws Exception {
27701 tejbeer 1346
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1347
		String email = loginDetails.getEmailId();
1348
		Map<String, Set<Integer>> storeGuyMap = csService.getAuthUserPartnerIdMapping();
1349
		Set<Integer> authfofoIds = storeGuyMap.get(email);
28472 tejbeer 1350
 
1351
		AuthUser authUser = authRepository.selectByEmailOrMobile(email);
1352
		if (authfofoIds == null) {
1353
			List<Position> positions1 = positionRepository.selectAll(authUser.getId());
1354
			if (positions1.stream().filter(x -> x.getCategoryId() == ProfitMandiConstants.TICKET_CATEGORY_MASTER)
1355
					.count() > 0) {
1356
				authfofoIds = csService.getPositionCustomRetailerMap(positions1).values().stream()
1357
						.flatMap(x -> x.stream()).map(x -> x.getPartnerId()).collect(Collectors.toSet());
1358
			}
1359
		}
27594 tejbeer 1360
		List<WarehouseWiseBrandSaleModel> warehouseWiseBrandPartnerSales = fofoStoreRepository
27701 tejbeer 1361
				.selectGroupByWarehouseAccesoriesBrandWisePartnerSale(brand, new ArrayList<>(authfofoIds));
27594 tejbeer 1362
		Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
1363
 
1364
		Set<String> brands = inventoryService.getAllTagListingBrands();
1365
		model.addAttribute("warehouseWiseBrandPartnerSales", warehouseWiseBrandPartnerSales);
1366
		model.addAttribute("warehouseMap", warehouseMap);
1367
		model.addAttribute("brands", brands);
1368
		model.addAttribute("selectedbrand", brand);
1369
		return "warehousewise_accessoriesbrand_sale";
1370
	}
1371
 
27556 tejbeer 1372
	@RequestMapping(value = "/getWarehouseBrandWiseItemSale", method = RequestMethod.GET)
1373
	public String getWarehouseBrandWiseItemSale(HttpServletRequest request, Model model,
30564 tejbeer 1374
			@RequestParam List<Integer> warehouseId, @RequestParam String brand) throws Exception {
27556 tejbeer 1375
		Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
27701 tejbeer 1376
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1377
		String email = loginDetails.getEmailId();
31152 tejbeer 1378
		Set<Integer> authfofoIds = csService.getAuthFofoIds(email);
27670 tejbeer 1379
		Map<Integer, WarehouseBrandWiseItemSaleModel> branditemSalesMap = fofoStoreRepository
27701 tejbeer 1380
				.selectWarehouseBrandItemSale(warehouseId, brand, new ArrayList<>(authfofoIds)).stream()
27670 tejbeer 1381
				.collect(Collectors.toMap(x -> x.getItemId(), x -> x));
1382
 
1383
		List<WarehouseBrandItemUnbilledActivatedModel> unbilledItems = fofoStoreRepository
27701 tejbeer 1384
				.selectWarehouseBrandItemUnbilledActivateStock(warehouseId, brand, new ArrayList<>(authfofoIds));
27670 tejbeer 1385
 
1386
		for (WarehouseBrandItemUnbilledActivatedModel un : unbilledItems) {
1387
			WarehouseBrandWiseItemSaleModel bpt = branditemSalesMap.get(un.getItemId());
1388
			if (bpt != null) {
1389
				bpt.setAmtd(un.getAmtd());
27676 tejbeer 1390
				bpt.setUamtdQty(un.getUnmtdQty());
27670 tejbeer 1391
			} else {
1392
				bpt = new WarehouseBrandWiseItemSaleModel();
1393
				bpt.setWarehouseId(un.getWarehouseId());
1394
				bpt.setItemId(un.getItemId());
1395
				bpt.setAmtd(un.getAmtd());
27677 tejbeer 1396
				bpt.setUamtdQty(un.getUnmtdQty());
27670 tejbeer 1397
				bpt.setBrand(un.getBrand());
1398
				bpt.setModelName(un.getModelName());
1399
				bpt.setModelNumber(un.getModelNumber());
1400
				bpt.setColor(un.getColor());
1401
				bpt.setLms(0);
1402
				bpt.setLmtd(0);
1403
				bpt.setMtd(0);
1404
				bpt.setMtdQty(0);
1405
				bpt.setLmtd(0);
1406
				bpt.setLmtdQty(0);
1407
				branditemSalesMap.put(un.getItemId(), bpt);
1408
			}
1409
		}
1410
		model.addAttribute("branditemSales", branditemSalesMap);
27556 tejbeer 1411
		model.addAttribute("warehouseMap", warehouseMap);
1412
		return "warehouse_partner_itemwise_sale";
1413
	}
1414
 
27594 tejbeer 1415
	@RequestMapping(value = "/getWarehouseAccesoriesBrandWiseItemSale", method = RequestMethod.GET)
1416
	public String getWarehouseAccesoriesBrandWiseItemSale(HttpServletRequest request, Model model,
30564 tejbeer 1417
			@RequestParam List<Integer> warehouseId, @RequestParam String brand) throws Exception {
27594 tejbeer 1418
		Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
27701 tejbeer 1419
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1420
		String email = loginDetails.getEmailId();
1421
		Map<String, Set<Integer>> storeGuyMap = csService.getAuthUserPartnerIdMapping();
1422
		Set<Integer> authfofoIds = storeGuyMap.get(email);
27594 tejbeer 1423
		List<WarehouseBrandWiseItemSaleModel> branditemSales = fofoStoreRepository
27701 tejbeer 1424
				.selectWarehouseAccesoriesBrandItemSale(warehouseId, brand, new ArrayList<>(authfofoIds));
27594 tejbeer 1425
		model.addAttribute("branditemSales", branditemSales);
1426
		model.addAttribute("warehouseMap", warehouseMap);
1427
		return "warehouse_accessories_itemwsie_sale";
1428
	}
1429
 
22354 ashik.ali 1430
	@RequestMapping(value = "/contactUs", method = RequestMethod.GET)
23923 amit.gupta 1431
	public String contactUs(HttpServletRequest request, Model model) throws Throwable {
22354 ashik.ali 1432
		model.addAttribute("appContextPath", request.getContextPath());
1433
		return "contact-us";
1434
	}
23923 amit.gupta 1435
 
25649 tejbeer 1436
	@RequestMapping(value = "/notifications", method = RequestMethod.GET)
25683 tejbeer 1437
	public String getNotificationsWithType(HttpServletRequest request,
30564 tejbeer 1438
			@RequestParam(required = false) MessageType messageType,
1439
			@RequestParam(name = "offset", defaultValue = "0") int offset,
1440
			@RequestParam(name = "limit", defaultValue = "20") int limit, Model model) throws Exception {
25649 tejbeer 1441
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
26060 tejbeer 1442
		int userId = 0;
1443
		boolean isAdmin = roleManager.isAdmin(loginDetails.getRoleIds());
1444
		if (isAdmin) {
1445
			userId = loginDetails.getFofoId();
1446
		} else {
1447
			userId = userAccountRepository.selectUserIdByRetailerId(loginDetails.getFofoId());
1448
		}
25683 tejbeer 1449
		List<Notification> notifications = null;
1450
 
26086 tejbeer 1451
		List<NotificationCampaign> notificationCampaigns = notificationCampaignRepository.getNotifications(messageType,
1452
				userId, offset, limit);
1453
		LOGGER.info("messageType" + messageType);
28468 tejbeer 1454
		notifications = fofoUser.getNotifications(notificationCampaigns, messageType);
26086 tejbeer 1455
 
25683 tejbeer 1456
		model.addAttribute("notifications", notifications);
1457
 
1458
		LOGGER.info("notifications" + notifications);
1459
		return "notification-template";
1460
	}
1461
 
25651 tejbeer 1462
	@RequestMapping(value = "/notifyDocument/documentId", method = RequestMethod.GET)
1463
	public ResponseEntity<?> retailerDocumentById(HttpServletRequest request,
30564 tejbeer 1464
			@RequestParam(name = ProfitMandiConstants.DOCUMENT_ID) int documentId, @RequestParam int cid)
25651 tejbeer 1465
			throws ProfitMandiBusinessException {
1466
		Document document = documentRepository.selectById(documentId);
1467
		NotificationCampaign nc = notificationCampaignRepository.selectById(cid);
1468
		if (nc.getDocumentId() == null) {
1469
			throw new ProfitMandiBusinessException("cid", nc.getId(), "not available");
1470
		}
1471
		if (nc.getDocumentId() != documentId) {
1472
			throw new ProfitMandiBusinessException(ProfitMandiConstants.DOCUMENT_ID, documentId, "RTLR_1014");
1473
		}
1474
		return responseSender.ok(document);
25649 tejbeer 1475
	}
1476
 
25651 tejbeer 1477
	@RequestMapping(value = "/notifyDocument/download", method = RequestMethod.GET)
1478
	public ResponseEntity<?> downloadRetailerDocument(HttpServletRequest request, @RequestParam int cid, Model model)
1479
			throws ProfitMandiBusinessException {
1480
 
1481
		NotificationCampaign nc = notificationCampaignRepository.selectById(cid);
1482
 
1483
		if (nc.getDocumentId() == null) {
1484
			throw new ProfitMandiBusinessException("cid", nc.getId(), "not available");
1485
		}
1486
 
1487
		Document document = documentRepository.selectById(nc.getDocumentId());
1488
 
1489
		FileInputStream file = null;
1490
		try {
1491
			file = new FileInputStream(document.getPath() + File.separator + document.getName());
1492
		} catch (FileNotFoundException e) {
1493
			LOGGER.error("Retailer Document file not found : ", e);
1494
			throw new ProfitMandiBusinessException(ProfitMandiConstants.DOCUMENT_ID, document.getId(), "RTLR_1013");
1495
		}
1496
		// ByteArrayOutputStream byteArrayOutputStream = new
1497
		// ByteArrayOutputStream();
1498
		// ExcelUtils.writeSchemeModels(schemeModels, byteArrayOutputStream);
1499
 
1500
		final HttpHeaders headers = new HttpHeaders();
1501
		String contentType = "";
1502
		if (document.getContentType() == ContentType.JPEG) {
1503
			contentType = "image/jpeg";
1504
		} else if (document.getContentType() == ContentType.PNG) {
1505
			contentType = "image/png";
1506
		} else if (document.getContentType() == ContentType.PDF) {
1507
			contentType = "application/pdf";
1508
		}
1509
		headers.set("Content-Type", contentType);
1510
		headers.set("Content-disposition", "inline; filename=" + document.getName());
1511
		headers.setContentLength(document.getSize());
1512
		final InputStreamResource inputStreamResource = new InputStreamResource(file);
1513
		return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
1514
	}
26460 amit.gupta 1515
 
27579 tejbeer 1516
	@RequestMapping(value = "/getItemWiseTertiary", method = RequestMethod.GET)
1517
	public String getItemWiseTertiary(HttpServletRequest request,
30564 tejbeer 1518
			@RequestParam(name = ProfitMandiConstants.FOFO_ID) int fofoId, Model model)
27579 tejbeer 1519
			throws ProfitMandiBusinessException {
1520
		List<ItemWiseTertiaryModel> itemWiseTertiary = fofoOrderRepository.SelectItemWiseTertiary(fofoId);
1521
 
1522
		LOGGER.info("itemWiseTertiary" + itemWiseTertiary);
27586 tejbeer 1523
		CustomRetailer customRetailer = retailerService.getFofoRetailer(fofoId);
1524
		model.addAttribute("customRetailer", customRetailer);
27579 tejbeer 1525
		model.addAttribute("itemWiseTertiary", itemWiseTertiary);
1526
		return "item-wise-tertiary";
1527
	}
1528
 
27586 tejbeer 1529
	@RequestMapping(value = "/getItemWiseIndent", method = RequestMethod.GET)
1530
	public String getItemWiseIndent(HttpServletRequest request,
30564 tejbeer 1531
			@RequestParam(name = ProfitMandiConstants.FOFO_ID) int fofoId, Model model)
27586 tejbeer 1532
			throws ProfitMandiBusinessException {
1533
 
1534
		List<Order> unbilledOrders = transactionService.getInTransitOrders(fofoId);
1535
		model.addAttribute("unbilledOrders", unbilledOrders);
1536
 
1537
		return "item-wise-indent";
1538
	}
1539
 
27636 tejbeer 1540
	@RequestMapping(value = "/getPartnerInvestment", method = RequestMethod.GET)
1541
	public String getPartnerInvestment(HttpServletRequest request,
30564 tejbeer 1542
			@RequestParam(name = ProfitMandiConstants.FOFO_ID) int fofoId, Model model) throws Exception {
28468 tejbeer 1543
		Map<Integer, PartnerDetailModel> partnerStats = adminUser.getPartnersStatDataFromFile();
27636 tejbeer 1544
		PartnerDetailModel partnerDetailModel = partnerStats.get(fofoId);
1545
		CustomRetailer customRetailer = retailerService.getFofoRetailer(fofoId);
1546
		model.addAttribute("partnerDetailModel", partnerDetailModel);
1547
		model.addAttribute("customRetailer", customRetailer);
1548
		return "partner-investment";
1549
	}
27727 tejbeer 1550
 
27704 amit.gupta 1551
	@RequestMapping(value = "/getPartnerPendingIndentItem", method = RequestMethod.GET)
1552
	public String getPartnerPendingIndentItem(HttpServletRequest request, @RequestParam int warehouseId,
30564 tejbeer 1553
			@RequestParam int itemId, Model model) throws ProfitMandiBusinessException {
27704 amit.gupta 1554
		List<PartnerPendingIndentItemModel> partnerPendingIndent = fofoStoreRepository
1555
				.selectPartnerPendingIndentItem(itemId, warehouseId);
27636 tejbeer 1556
 
27704 amit.gupta 1557
		model.addAttribute("partnerPendingIndent", partnerPendingIndent);
1558
		return "partner-pending-indent-item";
1559
	}
1560
 
27636 tejbeer 1561
	@RequestMapping(value = "/getPatnerActivateStock", method = RequestMethod.GET)
1562
	public String getPartnerActivateStockItem(HttpServletRequest request,
30564 tejbeer 1563
			@RequestParam(name = ProfitMandiConstants.FOFO_ID) int fofoId, Model model) throws Exception {
27636 tejbeer 1564
		List<ActivateItemModel> activateStocks = new ArrayList<>();
1565
		List<InventoryItem> inventoryItems = inventoryItemRepository.selectByActivatedNotSold(fofoId);
1566
		CustomRetailer customRetailer = retailerService.getFofoRetailer(fofoId);
1567
 
1568
		for (InventoryItem inventoryItem : inventoryItems) {
1569
			TagListing tagListing = tagListingRepository.selectByItemId(inventoryItem.getItemId());
1570
			Item item = itemRepository.selectById(inventoryItem.getItemId());
1571
			ActivateItemModel aim = new ActivateItemModel();
1572
			aim.setFofoId(inventoryItem.getFofoId());
1573
			aim.setQuantity(inventoryItem.getGoodQuantity());
1574
			aim.setAmount(tagListing.getSellingPrice());
1575
			aim.setItemDescription(item.getItemDescription());
1576
			aim.setItemId(inventoryItem.getItemId());
1577
			activateStocks.add(aim);
1578
		}
1579
 
1580
		model.addAttribute("activateStocks", activateStocks);
1581
		model.addAttribute("customRetailer", customRetailer);
1582
		return "partner-activate-stock";
1583
	}
1584
 
1585
	@RequestMapping(value = "/getPatnerBrandWiseMTDSale", method = RequestMethod.GET)
1586
	public String getPatnerBrandWiseMTDSale(HttpServletRequest request,
30564 tejbeer 1587
			@RequestParam(name = ProfitMandiConstants.FOFO_ID) int fofoId, Model model) throws Exception {
27636 tejbeer 1588
		LocalDateTime curDate = LocalDate.now().atStartOfDay();
1589
		CustomRetailer customRetailer = retailerService.getFofoRetailer(fofoId);
1590
		Map<String, Double> brandMtdAmount = fofoOrderItemRepository
1591
				.selectSumAmountGroupByBrand(curDate.withDayOfMonth(1), curDate.with(LocalTime.MAX), fofoId);
27638 tejbeer 1592
		Map<String, Long> brandMtdQty = fofoOrderItemRepository.selectSumQuantityGroupByBrand(curDate.withDayOfMonth(1),
1593
				curDate.with(LocalTime.MAX), fofoId);
27636 tejbeer 1594
		Double accesoriesmtdsale = fofoOrderRepository.selectSumSaleGroupByFofoIdsForMobileOrAccessories(fofoId,
1595
				curDate.withDayOfMonth(1), curDate.with(LocalTime.MAX), Optional.of(false)).get(fofoId);
27638 tejbeer 1596
		Long accesoriesmtdqty = fofoOrderRepository.selectSumSaleQuantityGroupByFofoIdsForMobileOrAccessories(fofoId,
1597
				curDate.withDayOfMonth(1), curDate.with(LocalTime.MAX), Optional.of(false)).get(fofoId);
1598
 
27636 tejbeer 1599
		LOGGER.info("accesoriesmtdsale" + accesoriesmtdsale);
1600
		model.addAttribute("brandMtdAmount", brandMtdAmount);
27638 tejbeer 1601
		model.addAttribute("brandMtdQty", brandMtdQty);
27636 tejbeer 1602
		model.addAttribute("accesoriesmtdsale", accesoriesmtdsale);
27638 tejbeer 1603
		model.addAttribute("accesoriesmtdqty", accesoriesmtdqty);
1604
 
27636 tejbeer 1605
		model.addAttribute("customRetailer", customRetailer);
1606
		return "partner-brand-mtd-sale";
1607
	}
1608
 
27637 tejbeer 1609
	@RequestMapping(value = "/getPatnerBrandWiseLMTDSale", method = RequestMethod.GET)
1610
	public String getPatnerBrandWiseLMTDSale(HttpServletRequest request,
30564 tejbeer 1611
			@RequestParam(name = ProfitMandiConstants.FOFO_ID) int fofoId, Model model) throws Exception {
27637 tejbeer 1612
		LocalDateTime curDate = LocalDate.now().atStartOfDay();
1613
		CustomRetailer customRetailer = retailerService.getFofoRetailer(fofoId);
1614
		Map<String, Double> brandLMtdAmount = fofoOrderItemRepository.selectSumAmountGroupByBrand(
1615
				curDate.withDayOfMonth(1).minusMonths(1), curDate.with(LocalTime.MAX).minusMonths(1), fofoId);
27638 tejbeer 1616
		Map<String, Long> brandLmtdQty = fofoOrderItemRepository.selectSumQuantityGroupByBrand(
1617
				curDate.withDayOfMonth(1).minusMonths(1), curDate.with(LocalTime.MAX).minusMonths(1), fofoId);
27637 tejbeer 1618
 
1619
		Double accesorieslmtdsale = fofoOrderRepository
1620
				.selectSumSaleGroupByFofoIdsForMobileOrAccessories(fofoId, curDate.withDayOfMonth(1).minusMonths(1),
1621
						curDate.with(LocalTime.MAX).minusMonths(1), Optional.of(false))
1622
				.get(fofoId);
27638 tejbeer 1623
		Long accesorieslmtdqty = fofoOrderRepository.selectSumSaleQuantityGroupByFofoIdsForMobileOrAccessories(fofoId,
1624
				curDate.withDayOfMonth(1).minusMonths(1), curDate.with(LocalTime.MAX).minusMonths(1),
1625
				Optional.of(false)).get(fofoId);
1626
 
27637 tejbeer 1627
		model.addAttribute("brandLMtdAmount", brandLMtdAmount);
27638 tejbeer 1628
		model.addAttribute("brandLmtdQty", brandLmtdQty);
1629
		model.addAttribute("accesorieslmtdqty", accesorieslmtdqty);
27637 tejbeer 1630
		model.addAttribute("accesorieslmtdsale", accesorieslmtdsale);
1631
		model.addAttribute("customRetailer", customRetailer);
1632
		return "partner-brand-lmtd-sale";
1633
	}
1634
 
27660 tejbeer 1635
	@RequestMapping(value = "/getPatnerBrandWiseLMSSale", method = RequestMethod.GET)
1636
	public String getPatnerBrandWiseLMSSale(HttpServletRequest request,
30564 tejbeer 1637
			@RequestParam(name = ProfitMandiConstants.FOFO_ID) int fofoId, Model model) throws Exception {
27660 tejbeer 1638
		LocalDateTime curDate = LocalDate.now().atStartOfDay();
1639
		CustomRetailer customRetailer = retailerService.getFofoRetailer(fofoId);
1640
		int lengthOfMonth = YearMonth.from(curDate.minusMonths(1)).lengthOfMonth();
1641
 
1642
		Map<String, Double> brandLMSAmount = fofoOrderItemRepository.selectSumAmountGroupByBrand(
27893 tejbeer 1643
				curDate.withDayOfMonth(1).minusMonths(1), curDate.withDayOfMonth(1), fofoId);
27660 tejbeer 1644
		Map<String, Long> brandLmsQty = fofoOrderItemRepository.selectSumQuantityGroupByBrand(
27893 tejbeer 1645
				curDate.withDayOfMonth(1).minusMonths(1), curDate.withDayOfMonth(1), fofoId);
27660 tejbeer 1646
 
27893 tejbeer 1647
		Double accesorieslmssale = fofoOrderRepository.selectSumSaleGroupByFofoIdsForMobileOrAccessories(fofoId,
1648
				curDate.withDayOfMonth(1).minusMonths(1), curDate.withDayOfMonth(1), Optional.of(false)).get(fofoId);
27660 tejbeer 1649
		Long accesorieslmsqty = fofoOrderRepository
1650
				.selectSumSaleQuantityGroupByFofoIdsForMobileOrAccessories(fofoId,
27893 tejbeer 1651
						curDate.withDayOfMonth(1).minusMonths(1), curDate.withDayOfMonth(1), Optional.of(false))
27660 tejbeer 1652
				.get(fofoId);
1653
 
1654
		model.addAttribute("brandLMSAmount", brandLMSAmount);
1655
		model.addAttribute("brandLmsQty", brandLmsQty);
1656
		model.addAttribute("accesorieslmssale", accesorieslmssale);
1657
		model.addAttribute("accesorieslmsqty", accesorieslmsqty);
1658
		model.addAttribute("customRetailer", customRetailer);
1659
		return "partner-brand-lms-sale";
1660
	}
1661
 
27640 tejbeer 1662
	@RequestMapping(value = "/getPatnerInStock", method = RequestMethod.GET)
1663
	public String getPatnerInStock(HttpServletRequest request,
30564 tejbeer 1664
			@RequestParam(name = ProfitMandiConstants.FOFO_ID) int fofoId, Model model) throws Exception {
27640 tejbeer 1665
 
1666
		CustomRetailer customRetailer = retailerService.getFofoRetailer(fofoId);
1667
 
27660 tejbeer 1668
		List<InStockBrandModel> mobileStocks = currentInventorySnapshotRepository
27640 tejbeer 1669
				.selectSumInStockMobileGroupByBrand(fofoId);
27660 tejbeer 1670
		List<InStockBrandModel> accesStock = currentInventorySnapshotRepository
27640 tejbeer 1671
				.selectSumInStockAccessoriesGroupByBrand(fofoId);
1672
 
27660 tejbeer 1673
		List<InStockBrandItemModel> stockItemlist = currentInventorySnapshotRepository
1674
				.selectInStockItemsByBrand(fofoId);
1675
 
1676
		Map<String, List<InStockBrandItemModel>> stockItemMap = stockItemlist.stream()
1677
				.collect(Collectors.groupingBy(InStockBrandItemModel::getBrand));
1678
 
1679
		model.addAttribute("stockItemMap", stockItemMap);
1680
		model.addAttribute("mobileStock", mobileStocks);
1681
		model.addAttribute("accesStock", accesStock);
27640 tejbeer 1682
		model.addAttribute("customRetailer", customRetailer);
1683
		return "partner-instock-item";
1684
	}
1685
 
27660 tejbeer 1686
	@RequestMapping(value = "/getOpenTicketByFofoId", method = RequestMethod.GET)
1687
	public String getOpenTicketByFofoId(HttpServletRequest request,
30564 tejbeer 1688
			@RequestParam(name = ProfitMandiConstants.FOFO_ID) int fofoId, Model model) throws Exception {
27660 tejbeer 1689
		Map<Integer, AuthUser> ticketIdAuthUser = new HashMap<>();
1690
		CustomRetailer customRetailer = retailerService.getFofoRetailer(fofoId);
1691
		List<Integer> ticketIds = ticketRepository.selectAllOpenTicketByRetailer(fofoId).stream().map(x -> x.getId())
1692
				.collect(Collectors.toList());
1693
		List<TicketAssigned> ticketAssigns = ticketAssignedRepository.selectByTicketIds(ticketIds);
1694
 
1695
		for (TicketAssigned ticketAssign : ticketAssigns) {
1696
			AuthUser authUser = authRepository.selectById(ticketAssign.getAssineeId());
1697
			ticketIdAuthUser.put(ticketAssign.getTicketId(), authUser);
1698
		}
1699
		model.addAttribute("ticketIdAuthUser", ticketIdAuthUser);
1700
		model.addAttribute("ticketAssigns", ticketAssigns);
1701
		model.addAttribute("customRetailer", customRetailer);
1702
		return "open-ticket";
1703
	}
1704
 
27893 tejbeer 1705
	@RequestMapping(value = "/getPartnerSecondarySale", method = RequestMethod.GET)
1706
	public String getPartnerSecondarySale(HttpServletRequest request,
30564 tejbeer 1707
			@RequestParam(name = ProfitMandiConstants.FOFO_ID) int fofoId, @RequestParam String timeValue, Model model)
27893 tejbeer 1708
			throws Exception {
1709
		LocalDateTime curDate = LocalDate.now().atStartOfDay();
1710
		CustomRetailer customRetailer = retailerService.getFofoRetailer(fofoId);
1711
		int lengthOfMonth = YearMonth.from(curDate.minusMonths(1)).lengthOfMonth();
1712
		LocalDateTime startDate = null;
1713
		LocalDateTime endDate = null;
1714
		List<InStockBrandModel> secondarySale = null;
1715
		Map<String, List<InStockBrandItemModel>> secondaryItemSale = null;
1716
 
1717
		if (timeValue.equals("mtd")) {
1718
			startDate = curDate.withDayOfMonth(1);
1719
			endDate = curDate.with(LocalTime.MAX);
1720
			secondarySale = orderRepository.selectAllBilledOrderBrandByFofoId(startDate, endDate, fofoId);
1721
			secondaryItemSale = orderRepository.selectAllBilledOrderBrandItemByFofoId(startDate, endDate, fofoId)
1722
					.stream().collect(Collectors.groupingBy(InStockBrandItemModel::getBrand));
1723
			LOGGER.info("secondarySalemtd" + secondarySale);
1724
		} else if (timeValue.equals("lmtd")) {
1725
			startDate = curDate.withDayOfMonth(1).minusMonths(1);
1726
			endDate = curDate.with(LocalTime.MAX).minusMonths(1);
1727
			secondaryItemSale = orderRepository.selectAllBilledOrderBrandItemByFofoId(startDate, endDate, fofoId)
1728
					.stream().collect(Collectors.groupingBy(InStockBrandItemModel::getBrand));
1729
 
1730
			secondarySale = orderRepository.selectAllBilledOrderBrandByFofoId(startDate, endDate, fofoId);
1731
			LOGGER.info("secondarySalelmtd" + secondarySale);
1732
 
1733
		} else {
1734
			startDate = curDate.withDayOfMonth(1).minusMonths(1);
1735
			endDate = curDate.withDayOfMonth(1);
1736
			secondaryItemSale = orderRepository.selectAllBilledOrderBrandItemByFofoId(startDate, endDate, fofoId)
1737
					.stream().collect(Collectors.groupingBy(InStockBrandItemModel::getBrand));
1738
 
1739
			secondarySale = orderRepository.selectAllBilledOrderBrandByFofoId(startDate, endDate, fofoId);
1740
			LOGGER.info("secondarySalelms" + secondarySale);
1741
 
1742
		}
1743
 
1744
		LOGGER.info("secondarySale" + secondarySale);
1745
		model.addAttribute("secondarySale", secondarySale);
1746
		model.addAttribute("secondaryItemSale", secondaryItemSale);
1747
		model.addAttribute("customRetailer", customRetailer);
1748
 
1749
		return "partner-secondary-order";
1750
	}
1751
 
28451 tejbeer 1752
	@RequestMapping(value = "/getMobileBrandWise", method = RequestMethod.GET)
1753
	public String getMobileBrandWise(HttpServletRequest request, Model model) throws Exception {
1754
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1755
		String email = loginDetails.getEmailId();
1756
 
1757
		AuthUser authUser = authRepository.selectByEmailOrMobile(email);
31152 tejbeer 1758
		Set<Integer> fofoIds = csService.getAuthFofoIds(email);
28451 tejbeer 1759
 
1760
		Map<String, BrandWisePartnerSaleModel> partnersBrandSaleMap = null;
1761
		partnersBrandSaleMap = fofoStoreRepository.selectGroupByBrandWarehousePartnerSale(new ArrayList<>(fofoIds))
1762
				.stream().collect(Collectors.toMap(x -> x.getBrand(), x -> x));
1763
 
1764
		List<BrandWiseUnbilledActivateStockModel> unbilledActivatedStock = fofoStoreRepository
1765
				.selectUnbilledActivateStockGroupByBrand(new ArrayList<>(fofoIds));
1766
		for (BrandWiseUnbilledActivateStockModel un : unbilledActivatedStock) {
1767
			BrandWisePartnerSaleModel bpt = partnersBrandSaleMap.get(un.getBrand());
1768
			if (bpt != null) {
1769
				bpt.setAmtd(un.getUnbilledMtd());
1770
				bpt.setUamtdQty(un.getUnbilledMTDQty());
1771
			} else {
1772
				bpt = new BrandWisePartnerSaleModel();
1773
				bpt.setBrand(un.getBrand());
1774
				bpt.setAmtd(un.getUnbilledMtd());
1775
				bpt.setUamtdQty(un.getUnbilledMTDQty());
1776
				bpt.setLms(0);
1777
				bpt.setLmtd(0);
1778
				bpt.setMtd(0);
1779
				bpt.setMtdQty(0);
1780
				bpt.setLmtd(0);
1781
				bpt.setLmtdQty(0);
1782
				partnersBrandSaleMap.put(un.getBrand(), bpt);
1783
			}
1784
		}
1785
 
1786
		model.addAttribute("brandSalesMap", partnersBrandSaleMap);
1787
 
1788
		return "mobile-brand-wise-report";
1789
	}
1790
 
1791
	@RequestMapping(value = "/getAccessoriesBrandWise", method = RequestMethod.GET)
1792
	public String getAccessoriesBrandWise(HttpServletRequest request, Model model) throws Exception {
1793
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1794
		String email = loginDetails.getEmailId();
1795
 
31152 tejbeer 1796
		Set<Integer> fofoIds = csService.getAuthFofoIds(email);
28451 tejbeer 1797
 
1798
		List<BrandWisePartnerSaleModel> accessoriesBrandSales = null;
1799
 
1800
		accessoriesBrandSales = fofoStoreRepository
1801
				.selectGroupByBrandAccesoriesWarehousePartnerSale(new ArrayList<>(fofoIds));
1802
 
1803
		model.addAttribute("accessoriesBrandSales", accessoriesBrandSales);
1804
		return "accessories-brand-wise-report";
1805
	}
1806
 
1807
	@RequestMapping(value = "/getMobileLMSGraph", method = RequestMethod.GET)
28461 tejbeer 1808
	public String getMobileLMSGraph(HttpServletRequest request, @RequestParam(required = false) int warehouseId,
30564 tejbeer 1809
			@RequestParam(required = false) LocalDateTime date, @RequestParam(required = false) LocalDateTime endDate,
1810
			@RequestParam List<Integer> fofoIds, @RequestParam String filterType, Model model) throws Exception {
28451 tejbeer 1811
		Map<Integer, List<Integer>> warehouseIdFofoIdMap = fofoStoreRepository
1812
				.selectActivePartnersByRetailerIds(new ArrayList<>(fofoIds)).stream().collect(Collectors.groupingBy(
1813
						FofoStore::getWarehouseId, Collectors.mapping(FofoStore::getId, Collectors.toList())));
1814
 
1815
		ChartModel cm;
1816
		if (warehouseId != 0) {
28468 tejbeer 1817
			cm = adminUser.getBrandWiseLms(Arrays.asList(warehouseId),
30279 tejbeer 1818
					fofoIds.stream().map(x -> x).collect(Collectors.toList()), date.toLocalDate(),
1819
					endDate.toLocalDate(), filterType);
28451 tejbeer 1820
		} else {
28468 tejbeer 1821
			cm = adminUser.getBrandWiseLms(new ArrayList<>(warehouseIdFofoIdMap.keySet()),
30279 tejbeer 1822
					fofoIds.stream().map(x -> x).collect(Collectors.toList()), date.toLocalDate(),
1823
					endDate.toLocalDate(), filterType);
28451 tejbeer 1824
 
1825
		}
1826
 
1827
		LOGGER.info("chartMap" + gson.toJson(cm));
1828
		model.addAttribute("chartMap", gson.toJson(cm));
1829
		return "brand-wise-mobile-lms-chart";
1830
	}
1831
 
28461 tejbeer 1832
	@RequestMapping(value = "/getMobileLMSFilter", method = RequestMethod.GET)
1833
	public String getMobileLMSFilter(HttpServletRequest request,
30564 tejbeer 1834
			@RequestParam(required = false, defaultValue = "0") int warehouseId,
1835
			@RequestParam(required = false) LocalDateTime date, @RequestParam(required = false) LocalDateTime endDate,
1836
			Model model) throws Exception {
28461 tejbeer 1837
 
1838
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1839
		String email = loginDetails.getEmailId();
1840
 
30279 tejbeer 1841
		if (date == null) {
1842
			LocalDateTime curDate = LocalDate.now().atStartOfDay();
28461 tejbeer 1843
 
30279 tejbeer 1844
			LocalDateTime startOfMonth = curDate.withDayOfMonth(1).minusMonths(6);
1845
			date = startOfMonth.toLocalDate().atStartOfDay();
1846
		}
28461 tejbeer 1847
 
30279 tejbeer 1848
		if (endDate == null) {
1849
			LocalDateTime curDate = LocalDate.now().atTime(LocalTime.MAX);
1850
 
1851
			endDate = curDate;
1852
 
1853
		}
1854
 
1855
		Map<String, Object> map = adminUser.getFilter(warehouseId, email, date, endDate);
28461 tejbeer 1856
		model.addAttribute("warehouseId", warehouseId);
1857
		model.addAllAttributes(map);
1858
 
30279 tejbeer 1859
		return "chart-filter-lms";
28461 tejbeer 1860
	}
1861
 
1862
	@RequestMapping(value = "/getMobileLMPGraph", method = RequestMethod.GET)
1863
	public String getMobileLMPGraph(HttpServletRequest request, @RequestParam(required = false) int warehouseId,
30564 tejbeer 1864
			@RequestParam(required = false) LocalDateTime date, @RequestParam(required = false) LocalDateTime endDate,
1865
			@RequestParam List<Integer> fofoIds, @RequestParam String filterType, Model model) throws Exception {
28461 tejbeer 1866
		Map<Integer, List<Integer>> warehouseIdFofoIdMap = fofoStoreRepository
1867
				.selectActivePartnersByRetailerIds(new ArrayList<>(fofoIds)).stream().collect(Collectors.groupingBy(
1868
						FofoStore::getWarehouseId, Collectors.mapping(FofoStore::getId, Collectors.toList())));
1869
 
1870
		ChartModel cm;
1871
		if (warehouseId != 0) {
28468 tejbeer 1872
			cm = adminUser.getBrandWiseLmp(Arrays.asList(warehouseId),
30279 tejbeer 1873
					fofoIds.stream().map(x -> x).collect(Collectors.toList()), date.toLocalDate(),
1874
					endDate.toLocalDate(), filterType);
28461 tejbeer 1875
		} else {
28468 tejbeer 1876
			cm = adminUser.getBrandWiseLmp(new ArrayList<>(warehouseIdFofoIdMap.keySet()),
30279 tejbeer 1877
					fofoIds.stream().map(x -> x).collect(Collectors.toList()), date.toLocalDate(),
1878
					endDate.toLocalDate(), filterType);
28461 tejbeer 1879
 
1880
		}
1881
 
1882
		LOGGER.info("chartMap" + gson.toJson(cm));
1883
		model.addAttribute("chartMap", gson.toJson(cm));
1884
		return "brand-wise-mobile-lmp-chart";
1885
	}
1886
 
28825 tejbeer 1887
	@RequestMapping(value = "/getActivatedModelWarehouseWise", method = RequestMethod.GET)
1888
	public String getActivatedModelWarehouseWise(HttpServletRequest request, Model model, @RequestParam String brand)
1889
			throws Exception {
1890
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1891
		List<Integer> fofoIds = getFofoIds(loginDetails);
1892
		List<WarehouseWiseActivatedModel> warehouseWiseActivatedModels = activatedImeiRepository
1893
				.selectActivatedModelGroupByWarehouse(brand, fofoIds);
1894
		Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
1895
 
1896
		List<DBObject> mobileBrands = mongoClient.getAllBrandsToDisplay(3);
1897
 
1898
		List<String> brands = mobileBrands.stream().map(x -> (String) x.get("name")).collect(Collectors.toList());
1899
		LOGGER.info("brands" + brands.add("Redmi"));
1900
 
1901
		model.addAttribute("warehouseWiseActivatedModels", warehouseWiseActivatedModels);
1902
		model.addAttribute("warehouseMap", warehouseMap);
1903
		model.addAttribute("brands", brands);
1904
		model.addAttribute("selectedbrand", brand);
1905
		return "warehousewise_activated_model";
1906
	}
1907
 
1908
	@RequestMapping(value = "/getActivatedModelByBrand", method = RequestMethod.GET)
1909
	public String getActivatedModelByBrand(HttpServletRequest request, Model model) throws Exception {
1910
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
31152 tejbeer 1911
		Set<Integer> fofoIds = csService.getAuthFofoIds(loginDetails.getEmailId());
1912
 
28825 tejbeer 1913
		List<BrandWiseActivatedModel> activatedModels = activatedImeiRepository
1914
				.selectActivatedModelGroupByBrand(new ArrayList<>(fofoIds));
1915
		model.addAttribute("activatedModels", activatedModels);
1916
		return "activation-brandwise-report";
1917
	}
1918
 
1919
	@RequestMapping(value = "/getWarehouseBrandWiseItemActivatedModel", method = RequestMethod.GET)
1920
	public String getWarehouseBrandWiseItemActivatedModel(HttpServletRequest request, Model model,
30564 tejbeer 1921
			@RequestParam List<Integer> warehouseId, @RequestParam String brand) throws Exception {
28825 tejbeer 1922
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1923
		List<Integer> fofoIds = getFofoIds(loginDetails);
1924
 
1925
		Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
1926
		List<WarehouseBrandWiseItemActivatedModel> activatedItems = activatedImeiRepository
1927
				.selectWarehouseBrandActivatedItem(warehouseId, brand, fofoIds);
1928
		model.addAttribute("warehouseMap", warehouseMap);
1929
		model.addAttribute("activatedItems", activatedItems);
1930
		return "warehouse-activated-itemwise-model";
1931
 
1932
	}
1933
 
1934
	@RequestMapping(value = "/getActivatedImeiUpdationDate", method = RequestMethod.GET)
1935
	public String getActivatedImeiUpdationDate(HttpServletRequest request, Model model) throws Exception {
1936
 
1937
		Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
1938
 
1939
		List<ActivationImeiUpdationModel> activationImeiUpdations = activatedImeiRepository
1940
				.selectActivatedUpdationDate();
1941
		model.addAttribute("warehouseMap", warehouseMap);
1942
		model.addAttribute("activationImeiUpdations", activationImeiUpdations);
1943
		return "activation-updation-timestamp";
1944
 
1945
	}
1946
 
1947
	private List<Integer> getFofoIds(LoginDetails loginDetails) throws ProfitMandiBusinessException {
1948
		String email = loginDetails.getEmailId();
1949
 
1950
		AuthUser authUser = authRepository.selectByEmailOrMobile(email);
1951
		Map<String, Set<Integer>> storeGuyMap = csService.getAuthUserPartnerIdMapping();
1952
 
1953
		Set<Integer> fofoIds = storeGuyMap.get(authUser.getEmailId());
1954
		if (emails.contains(authUser.getEmailId())) {
1955
			fofoIds = storeGuyMap.get("tarun.verma@smartdukaan.com");
1956
			LOGGER.info("fofoIds" + fofoIds);
1957
		}
1958
 
1959
		if (fofoIds == null) {
1960
			List<Position> positions1 = positionRepository.selectAll(authUser.getId());
1961
			if (positions1.stream().filter(x -> x.getCategoryId() == ProfitMandiConstants.TICKET_CATEGORY_MASTER)
1962
					.count() > 0) {
1963
				fofoIds = csService.getPositionCustomRetailerMap(positions1).values().stream().flatMap(x -> x.stream())
1964
						.map(x -> x.getPartnerId()).collect(Collectors.toSet());
1965
			}
1966
		}
1967
		return new ArrayList<>(fofoIds);
1968
	}
1969
 
21615 kshitij.so 1970
}