Subversion Repositories SmartDukaan

Rev

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