Subversion Repositories SmartDukaan

Rev

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