Subversion Repositories SmartDukaan

Rev

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