Subversion Repositories SmartDukaan

Rev

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

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