Subversion Repositories SmartDukaan

Rev

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