Subversion Repositories SmartDukaan

Rev

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

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