Subversion Repositories SmartDukaan

Rev

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