Subversion Repositories SmartDukaan

Rev

Rev 29578 | Rev 29677 | 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
 
29580 tejbeer 725
		for (int i = 0; i <= 5; i++) {
29578 tejbeer 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);
29580 tejbeer 777
			for (int i = 5; i >= 0; i--) {
29578 tejbeer 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
 
29580 tejbeer 794
		LOGGER.info("sortedBrandValue" + sortedBrandValue);
29578 tejbeer 795
		model.addAttribute("sortedBrandValue", sortedBrandValue);
28455 tejbeer 796
		model.addAttribute("fofoId", fofoId);
29578 tejbeer 797
		return "activation-tabular";
798
	}
28455 tejbeer 799
 
29578 tejbeer 800
	@RequestMapping(value = "/getMonthlyActivationItemDetail", method = RequestMethod.GET)
801
	public String getMonthlyActivationItemDetail(HttpServletRequest request,
802
			@RequestParam(name = "fofoId", required = true, defaultValue = "0") int fofoId,
803
			@RequestParam(name = "brand", required = true, defaultValue = "0") String brand,
804
			@RequestParam(name = "yearMonth", required = false, defaultValue = "0") String yearMonth, Model model)
805
			throws Exception {
28455 tejbeer 806
 
29578 tejbeer 807
		LOGGER.info("params" + fofoId + brand + yearMonth);
808
 
809
		List<ActivationItemDetailModel> activationItemDetails = schemeInOutRepository
810
				.selectBrandPendingActivationItemDetails(fofoId, brand, yearMonth);
811
 
812
		for (ActivationItemDetailModel activationItemDetail : activationItemDetails) {
813
 
814
			List<FofoLineItem> flis = fofoLineItemRepository
815
					.selectByInventoryItemId(activationItemDetail.getInventoryItemId());
816
 
817
			LOGGER.info("flis" + flis);
818
 
819
			int maxFofoOrderItemId = flis.stream().mapToInt(x -> x.getFofoOrderItemId()).max()
820
					.orElseThrow(NoSuchElementException::new);
821
			LOGGER.info("maxFofoOrderItemId" + maxFofoOrderItemId);
822
 
823
			FofoOrderItem foi = fofoOrderItemRepository.selectById(maxFofoOrderItemId);
824
 
825
			FofoOrder fo = fofoOrderRepository.selectByOrderId(foi.getOrderId());
826
 
827
			activationItemDetail.setInvoiceNumber(fo.getInvoiceNumber());
828
 
829
		}
830
		LOGGER.info("activationItemDetails" + activationItemDetails);
831
 
832
		model.addAttribute("activationItemDetails", activationItemDetails);
833
 
834
		return "activation-pending-item-details";
28455 tejbeer 835
	}
836
 
29578 tejbeer 837
	@RequestMapping(value = "/getMonthlyActivationBeforeSixMonthsItemDetail", method = RequestMethod.GET)
838
	public String getMonthlyActivationItemDetail(HttpServletRequest request,
839
			@RequestParam(name = "fofoId", required = true, defaultValue = "0") int fofoId,
840
			@RequestParam(name = "brand", required = true, defaultValue = "0") String brand, Model model)
841
			throws Exception {
842
		LocalDateTime curDate = LocalDate.now().atStartOfDay();
843
 
844
		LocalDateTime startOfMonth = curDate.withDayOfMonth(1).minusMonths(6);
845
 
846
		List<ActivationItemDetailModel> activationItemDetails = schemeInOutRepository
847
				.selectBrandPendingActivationItemDetailByYearMonth(fofoId, brand, startOfMonth);
848
 
849
		for (ActivationItemDetailModel activationItemDetail : activationItemDetails) {
850
 
851
			List<FofoLineItem> flis = fofoLineItemRepository
852
					.selectByInventoryItemId(activationItemDetail.getInventoryItemId());
853
			LOGGER.info("flis" + flis);
854
 
855
			int maxFofoOrderItemId = flis.stream().mapToInt(x -> x.getFofoOrderItemId()).max()
856
					.orElseThrow(NoSuchElementException::new);
857
			LOGGER.info("maxFofoOrderItemId" + maxFofoOrderItemId);
858
 
859
			FofoOrderItem foi = fofoOrderItemRepository.selectById(maxFofoOrderItemId);
860
 
861
			FofoOrder fo = fofoOrderRepository.selectByOrderId(foi.getOrderId());
862
 
863
			activationItemDetail.setInvoiceNumber(fo.getInvoiceNumber());
864
 
865
		}
866
		LOGGER.info("activationItemDetails" + activationItemDetails);
867
 
868
		model.addAttribute("activationItemDetails", activationItemDetails);
869
 
870
		return "activation-pending-item-details";
871
	}
872
 
26468 amit.gupta 873
	@RequestMapping(value = "/getAuthUserPartners", method = RequestMethod.GET)
26418 tejbeer 874
	public String AuthUserPartnersDetail(HttpServletRequest request, Model model, @RequestParam int authId)
875
			throws Exception {
876
 
877
		Map<Integer, List<Integer>> pp = csService.getAuthUserIdPartnerIdMapping();
26963 amit.gupta 878
		Map<Integer, CustomRetailer> fofoIdAndPartnerMap = retailerService.getFofoRetailers(false);
26418 tejbeer 879
 
26468 amit.gupta 880
		Map<Integer, PartnerDetailModel> fofoIdAndallValues = partnerStatsService.getAllPartnerStats();
881
		if (authId != 0) {
882
			List<Integer> fofoIds = pp.get(authId);
883
			fofoIdAndallValues = fofoIdAndallValues.entrySet().stream().filter(x -> fofoIds.contains(x.getKey()))
884
					.collect(Collectors.toMap(x -> x.getKey(), x -> x.getValue()));
26474 amit.gupta 885
		} else {
26418 tejbeer 886
		}
887
 
888
		model.addAttribute("fofoIdAndallValues", fofoIdAndallValues);
889
		model.addAttribute("fofoIdAndPartnerMap", fofoIdAndPartnerMap);
890
 
891
		return "auth_user_partner_detail";
26468 amit.gupta 892
	}
26418 tejbeer 893
 
27545 tejbeer 894
	@RequestMapping(value = "/getWarehousePartners", method = RequestMethod.GET)
895
	public String warehousePartnersDetail(HttpServletRequest request, Model model, @RequestParam int warehouseId)
896
			throws Exception {
27701 tejbeer 897
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
898
		String email = loginDetails.getEmailId();
28472 tejbeer 899
 
900
		Set<Integer> authfofoIds = new HashSet<>();
27701 tejbeer 901
		Map<String, Set<Integer>> storeGuyMap = csService.getAuthUserPartnerIdMapping();
28472 tejbeer 902
		authfofoIds = storeGuyMap.get(email);
27545 tejbeer 903
 
28472 tejbeer 904
		AuthUser authUser = authRepository.selectByEmailOrMobile(email);
905
		if (authfofoIds == null) {
906
			List<Position> positions1 = positionRepository.selectAll(authUser.getId());
907
			if (positions1.stream().filter(x -> x.getCategoryId() == ProfitMandiConstants.TICKET_CATEGORY_MASTER)
908
					.count() > 0) {
909
				authfofoIds = csService.getPositionCustomRetailerMap(positions1).values().stream()
910
						.flatMap(x -> x.stream()).map(x -> x.getPartnerId()).collect(Collectors.toSet());
911
			}
912
		}
27701 tejbeer 913
		Map<Integer, List<Integer>> warehouseIdFofoIdMap = fofoStoreRepository
914
				.selectActivePartnersByRetailerIds(new ArrayList<>(authfofoIds)).stream().collect(Collectors.groupingBy(
915
						FofoStore::getWarehouseId, Collectors.mapping(FofoStore::getId, Collectors.toList())));
916
 
27545 tejbeer 917
		Map<Integer, CustomRetailer> fofoIdAndPartnerMap = retailerService.getFofoRetailers(false);
28468 tejbeer 918
		Map<Integer, PartnerDetailModel> fofoIdAndallValues = adminUser.getPartnersStatDataFromFile();
27545 tejbeer 919
		if (warehouseId != 0) {
27701 tejbeer 920
			List<Integer> fofoIds = warehouseIdFofoIdMap.get(warehouseId);
921
			/*
922
			 * List<Integer> fofoIds =
923
			 * fofoStoreRepository.selectActivePartnerByWarehouse(warehouseId).stream()
924
			 * .map(x -> x.getId()).collect(Collectors.toList());
925
			 */
27545 tejbeer 926
			fofoIdAndallValues = fofoIdAndallValues.entrySet().stream().filter(x -> fofoIds.contains(x.getKey()))
927
					.collect(Collectors.toMap(x -> x.getKey(), x -> x.getValue()));
928
		} else {
28472 tejbeer 929
 
930
			List<Integer> fofoIds = new ArrayList<>(authfofoIds);
931
			fofoIdAndallValues = fofoIdAndallValues.entrySet().stream().filter(x -> fofoIds.contains(x.getKey()))
27701 tejbeer 932
					.collect(Collectors.toMap(x -> x.getKey(), x -> x.getValue()));
27545 tejbeer 933
		}
29164 manish 934
		ChartInvestmentModel cm = adminUser.getAllStatePartnerType(fofoIdAndallValues);
935
		model.addAttribute("chartPieMap", gson.toJson(cm));
27545 tejbeer 936
 
29164 manish 937
		LOGGER.info("adminUserChart" + gson.toJson(cm));
938
 
27545 tejbeer 939
		model.addAttribute("fofoIdAndallValues", fofoIdAndallValues);
940
		model.addAttribute("fofoIdAndPartnerMap", fofoIdAndPartnerMap);
941
 
942
		return "auth_user_partner_detail";
943
	}
944
 
27509 tejbeer 945
	@RequestMapping(value = "/getWarehouseWiseBrandStock", method = RequestMethod.GET)
27701 tejbeer 946
	public String getWarehouseWiseBrandStock(HttpServletRequest request, Model model,
947
			@RequestParam List<Integer> warehouseId) throws Exception {
948
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
949
		String email = loginDetails.getEmailId();
950
		Map<String, Set<Integer>> storeGuyMap = csService.getAuthUserPartnerIdMapping();
951
		Set<Integer> authfofoIds = storeGuyMap.get(email);
28471 tejbeer 952
		AuthUser authUser = authRepository.selectByEmailOrMobile(email);
27509 tejbeer 953
 
28471 tejbeer 954
		if (authfofoIds == null) {
955
			List<Position> positions1 = positionRepository.selectAll(authUser.getId());
956
			if (positions1.stream().filter(x -> x.getCategoryId() == ProfitMandiConstants.TICKET_CATEGORY_MASTER)
957
					.count() > 0) {
958
				authfofoIds = csService.getPositionCustomRetailerMap(positions1).values().stream()
959
						.flatMap(x -> x.stream()).map(x -> x.getPartnerId()).collect(Collectors.toSet());
960
			}
961
		}
962
 
27701 tejbeer 963
		Map<Integer, List<Integer>> warehouseIdFofoIdMap = fofoStoreRepository
964
				.selectActivePartnersByRetailerIds(new ArrayList<>(authfofoIds)).stream().collect(Collectors.groupingBy(
965
						FofoStore::getWarehouseId, Collectors.mapping(FofoStore::getId, Collectors.toList())));
966
		List<WarehouseWiseBrandStockModel> warehouseWiseBrandStock = new ArrayList<>();
967
		if (!warehouseId.contains(0)) {
968
			warehouseWiseBrandStock = saholicInventoryCISRepository.selectGroupByWarehouseAndBrand(warehouseId);
969
		} else {
970
			LOGGER.info("warehouseIdFofoIdMap" + warehouseIdFofoIdMap.keySet());
971
			warehouseWiseBrandStock = saholicInventoryCISRepository
972
					.selectGroupByWarehouseAndBrand(new ArrayList<>(warehouseIdFofoIdMap.keySet()));
973
 
974
		}
27542 tejbeer 975
		Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
27509 tejbeer 976
		model.addAttribute("warehouseWiseBrandStock", warehouseWiseBrandStock);
27542 tejbeer 977
		model.addAttribute("warehouseId", warehouseId);
27509 tejbeer 978
		model.addAttribute("warehouseMap", warehouseMap);
27660 tejbeer 979
 
27509 tejbeer 980
		return "warehouse_brand_stock";
981
	}
982
 
27529 tejbeer 983
	@RequestMapping(value = "/getWarehouseWiseData", method = RequestMethod.GET)
984
	public String getWarehouseWiseData(HttpServletRequest request, Model model) throws Exception {
985
		inventoryService.getItemAvailabilityAndIndent();
986
		model.addAttribute("response", mvcResponseSender.createResponseString(true));
987
		return "response";
988
	}
989
 
27628 tejbeer 990
	@RequestMapping(value = "/getPartnersStatData", method = RequestMethod.GET)
991
	public String getPartnersStatData(HttpServletRequest request, Model model) throws Exception {
992
		Map<Integer, PartnerDetailModel> partnerStats = partnerStatsService.getAllPartnerStats();
993
		ObjectOutputStream oos = null;
994
		FileOutputStream fout = null;
995
		try {
996
			fout = new FileOutputStream("/tmp/partnerStat.tmp", false);
997
			oos = new ObjectOutputStream(fout);
998
			oos.writeObject(partnerStats);
999
 
1000
		} catch (Exception ex) {
1001
			ex.printStackTrace();
1002
		} finally {
1003
			if (oos != null) {
1004
				oos.close();
1005
			}
1006
		}
1007
		ReporticoCacheTable rct = reporticoCacheTableRepository.selectByTableName("partnerStat");
1008
		if (rct == null) {
1009
			rct = new ReporticoCacheTable();
1010
			rct.setTableName("partnerStat");
1011
 
1012
		}
1013
		rct.setLastCreatedTimestamp(LocalDateTime.now());
1014
		reporticoCacheTableRepository.persist(rct);
1015
		model.addAttribute("response", mvcResponseSender.createResponseString(true));
1016
		return "response";
1017
	}
1018
 
27539 tejbeer 1019
	@RequestMapping(value = "/getWarehouseWiseBrandAndCategory", method = RequestMethod.GET)
1020
	public String getWarehouseWiseBrandAndCategory(HttpServletRequest request, Model model,
27538 tejbeer 1021
			@RequestParam List<Integer> warehouseId, @RequestParam List<String> brands, @RequestParam String category)
1022
			throws Exception {
27509 tejbeer 1023
 
1024
		Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
27529 tejbeer 1025
		List<String> listbrands = saholicInventoryCISRepository.selectAllBrand();
27538 tejbeer 1026
		List<String> listCategory = saholicInventoryCISRepository.selectAllSubCategory();
27539 tejbeer 1027
 
27509 tejbeer 1028
		model.addAttribute("warehouseMap", warehouseMap);
27529 tejbeer 1029
		model.addAttribute("brands", listbrands);
27538 tejbeer 1030
		model.addAttribute("listCategory", listCategory);
1031
 
27529 tejbeer 1032
		model.addAttribute("selectedBrand", brands);
27538 tejbeer 1033
		model.addAttribute("selectedWarehouse", warehouseId);
27539 tejbeer 1034
		model.addAttribute("selectedCategory", category);
1035
 
27509 tejbeer 1036
		return "warehouse_brand_item_stock";
1037
	}
1038
 
27538 tejbeer 1039
	@RequestMapping(value = "/getWarehouseWiseItemStock", method = RequestMethod.GET)
1040
	public String getWarehouseWiseItemStock(HttpServletRequest request, Model model,
1041
			@RequestParam List<Integer> warehouseId, @RequestParam List<String> brands, @RequestParam String category)
1042
			throws Exception {
27539 tejbeer 1043
		Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
1044
		if (warehouseId.contains(0)) {
1045
			warehouseId.addAll(warehouseMap.keySet());
1046
		}
27538 tejbeer 1047
		List<WarehouseWiseitemStockModel> warehouseWiseItemStock = saholicInventoryCISRepository
1048
				.selectWarehouseItemStock(warehouseId, brands, category);
27539 tejbeer 1049
 
27538 tejbeer 1050
		model.addAttribute("warehouseWiseItemStock", warehouseWiseItemStock);
1051
		model.addAttribute("warehouseMap", warehouseMap);
1052
		return "warehouse_item_details";
1053
	}
1054
 
27556 tejbeer 1055
	@RequestMapping(value = "/getWarehouseWiseBrandPartnerSale", method = RequestMethod.GET)
27591 tejbeer 1056
	public String getWarehouseWiseBrandPartnerSale(HttpServletRequest request, Model model, @RequestParam String brand)
1057
			throws Exception {
27701 tejbeer 1058
 
1059
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1060
		String email = loginDetails.getEmailId();
1061
		Map<String, Set<Integer>> storeGuyMap = csService.getAuthUserPartnerIdMapping();
1062
		Set<Integer> authfofoIds = storeGuyMap.get(email);
1063
 
28472 tejbeer 1064
		AuthUser authUser = authRepository.selectByEmailOrMobile(email);
1065
		if (authfofoIds == null) {
1066
			List<Position> positions1 = positionRepository.selectAll(authUser.getId());
1067
			if (positions1.stream().filter(x -> x.getCategoryId() == ProfitMandiConstants.TICKET_CATEGORY_MASTER)
1068
					.count() > 0) {
1069
				authfofoIds = csService.getPositionCustomRetailerMap(positions1).values().stream()
1070
						.flatMap(x -> x.stream()).map(x -> x.getPartnerId()).collect(Collectors.toSet());
1071
			}
1072
		}
1073
 
27670 tejbeer 1074
		Map<Integer, WarehouseWiseBrandSaleModel> warehouseWiseBrandPartnerSales = fofoStoreRepository
27701 tejbeer 1075
				.selectGroupByWarehouseBrandWisePartnerSale(brand, new ArrayList<>(authfofoIds)).stream()
27670 tejbeer 1076
				.collect(Collectors.toMap(x -> x.getWarehouseId(), x -> x));
1077
 
1078
		List<WarehouseWiseBrandUnbilledActivatedModel> unbilledStock = fofoStoreRepository
27701 tejbeer 1079
				.selectUnbilledActivateStockGroupByWarehouse(brand, new ArrayList<>(authfofoIds));
27670 tejbeer 1080
 
1081
		for (WarehouseWiseBrandUnbilledActivatedModel un : unbilledStock) {
1082
			WarehouseWiseBrandSaleModel bpt = warehouseWiseBrandPartnerSales.get(un.getWarehouseId());
1083
			if (bpt != null) {
1084
				bpt.setAmtd(un.getUnbilledMtd());
27676 tejbeer 1085
				bpt.setUamtdQty(un.getUnbilledQty());
27670 tejbeer 1086
			} else {
1087
				bpt = new WarehouseWiseBrandSaleModel();
1088
				bpt.setWarehouseId(un.getWarehouseId());
1089
				bpt.setAmtd(un.getUnbilledMtd());
27677 tejbeer 1090
				bpt.setUamtdQty(un.getUnbilledQty());
27670 tejbeer 1091
				bpt.setLms(0);
1092
				bpt.setLmtd(0);
1093
				bpt.setMtd(0);
1094
				bpt.setMtdQty(0);
1095
				bpt.setLmtd(0);
1096
				bpt.setLmtdQty(0);
1097
				warehouseWiseBrandPartnerSales.put(un.getWarehouseId(), bpt);
1098
			}
1099
		}
27556 tejbeer 1100
		Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
27591 tejbeer 1101
 
1102
		Set<String> brands = inventoryService.getAllTagListingBrands();
1103
		model.addAttribute("warehouseWiseBrandPartnerSales", warehouseWiseBrandPartnerSales);
27556 tejbeer 1104
		model.addAttribute("warehouseMap", warehouseMap);
27591 tejbeer 1105
		model.addAttribute("brands", brands);
1106
		model.addAttribute("selectedbrand", brand);
1107
		return "warehousewise_brand_partners_sale";
27556 tejbeer 1108
	}
1109
 
27594 tejbeer 1110
	@RequestMapping(value = "/getWarehouseWiseAccesoriesBrandPartnerSale", method = RequestMethod.GET)
1111
	public String getWarehouseWiseAccesoriesBrandPartnerSale(HttpServletRequest request, Model model,
1112
			@RequestParam String brand) throws Exception {
27701 tejbeer 1113
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1114
		String email = loginDetails.getEmailId();
1115
		Map<String, Set<Integer>> storeGuyMap = csService.getAuthUserPartnerIdMapping();
1116
		Set<Integer> authfofoIds = storeGuyMap.get(email);
28472 tejbeer 1117
 
1118
		AuthUser authUser = authRepository.selectByEmailOrMobile(email);
1119
		if (authfofoIds == null) {
1120
			List<Position> positions1 = positionRepository.selectAll(authUser.getId());
1121
			if (positions1.stream().filter(x -> x.getCategoryId() == ProfitMandiConstants.TICKET_CATEGORY_MASTER)
1122
					.count() > 0) {
1123
				authfofoIds = csService.getPositionCustomRetailerMap(positions1).values().stream()
1124
						.flatMap(x -> x.stream()).map(x -> x.getPartnerId()).collect(Collectors.toSet());
1125
			}
1126
		}
27594 tejbeer 1127
		List<WarehouseWiseBrandSaleModel> warehouseWiseBrandPartnerSales = fofoStoreRepository
27701 tejbeer 1128
				.selectGroupByWarehouseAccesoriesBrandWisePartnerSale(brand, new ArrayList<>(authfofoIds));
27594 tejbeer 1129
		Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
1130
 
1131
		Set<String> brands = inventoryService.getAllTagListingBrands();
1132
		model.addAttribute("warehouseWiseBrandPartnerSales", warehouseWiseBrandPartnerSales);
1133
		model.addAttribute("warehouseMap", warehouseMap);
1134
		model.addAttribute("brands", brands);
1135
		model.addAttribute("selectedbrand", brand);
1136
		return "warehousewise_accessoriesbrand_sale";
1137
	}
1138
 
27556 tejbeer 1139
	@RequestMapping(value = "/getWarehouseBrandWiseItemSale", method = RequestMethod.GET)
1140
	public String getWarehouseBrandWiseItemSale(HttpServletRequest request, Model model,
1141
			@RequestParam List<Integer> warehouseId, @RequestParam String brand) throws Exception {
1142
		Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
27701 tejbeer 1143
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1144
		String email = loginDetails.getEmailId();
1145
		Map<String, Set<Integer>> storeGuyMap = csService.getAuthUserPartnerIdMapping();
1146
		Set<Integer> authfofoIds = storeGuyMap.get(email);
27670 tejbeer 1147
		Map<Integer, WarehouseBrandWiseItemSaleModel> branditemSalesMap = fofoStoreRepository
27701 tejbeer 1148
				.selectWarehouseBrandItemSale(warehouseId, brand, new ArrayList<>(authfofoIds)).stream()
27670 tejbeer 1149
				.collect(Collectors.toMap(x -> x.getItemId(), x -> x));
1150
 
1151
		List<WarehouseBrandItemUnbilledActivatedModel> unbilledItems = fofoStoreRepository
27701 tejbeer 1152
				.selectWarehouseBrandItemUnbilledActivateStock(warehouseId, brand, new ArrayList<>(authfofoIds));
27670 tejbeer 1153
 
1154
		for (WarehouseBrandItemUnbilledActivatedModel un : unbilledItems) {
1155
			WarehouseBrandWiseItemSaleModel bpt = branditemSalesMap.get(un.getItemId());
1156
			if (bpt != null) {
1157
				bpt.setAmtd(un.getAmtd());
27676 tejbeer 1158
				bpt.setUamtdQty(un.getUnmtdQty());
27670 tejbeer 1159
			} else {
1160
				bpt = new WarehouseBrandWiseItemSaleModel();
1161
				bpt.setWarehouseId(un.getWarehouseId());
1162
				bpt.setItemId(un.getItemId());
1163
				bpt.setAmtd(un.getAmtd());
27677 tejbeer 1164
				bpt.setUamtdQty(un.getUnmtdQty());
27670 tejbeer 1165
				bpt.setBrand(un.getBrand());
1166
				bpt.setModelName(un.getModelName());
1167
				bpt.setModelNumber(un.getModelNumber());
1168
				bpt.setColor(un.getColor());
1169
				bpt.setLms(0);
1170
				bpt.setLmtd(0);
1171
				bpt.setMtd(0);
1172
				bpt.setMtdQty(0);
1173
				bpt.setLmtd(0);
1174
				bpt.setLmtdQty(0);
1175
				branditemSalesMap.put(un.getItemId(), bpt);
1176
			}
1177
		}
1178
		model.addAttribute("branditemSales", branditemSalesMap);
27556 tejbeer 1179
		model.addAttribute("warehouseMap", warehouseMap);
1180
		return "warehouse_partner_itemwise_sale";
1181
	}
1182
 
27594 tejbeer 1183
	@RequestMapping(value = "/getWarehouseAccesoriesBrandWiseItemSale", method = RequestMethod.GET)
1184
	public String getWarehouseAccesoriesBrandWiseItemSale(HttpServletRequest request, Model model,
1185
			@RequestParam List<Integer> warehouseId, @RequestParam String brand) throws Exception {
1186
		Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
27701 tejbeer 1187
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1188
		String email = loginDetails.getEmailId();
1189
		Map<String, Set<Integer>> storeGuyMap = csService.getAuthUserPartnerIdMapping();
1190
		Set<Integer> authfofoIds = storeGuyMap.get(email);
27594 tejbeer 1191
		List<WarehouseBrandWiseItemSaleModel> branditemSales = fofoStoreRepository
27701 tejbeer 1192
				.selectWarehouseAccesoriesBrandItemSale(warehouseId, brand, new ArrayList<>(authfofoIds));
27594 tejbeer 1193
		model.addAttribute("branditemSales", branditemSales);
1194
		model.addAttribute("warehouseMap", warehouseMap);
1195
		return "warehouse_accessories_itemwsie_sale";
1196
	}
1197
 
22354 ashik.ali 1198
	@RequestMapping(value = "/contactUs", method = RequestMethod.GET)
23923 amit.gupta 1199
	public String contactUs(HttpServletRequest request, Model model) throws Throwable {
22354 ashik.ali 1200
		model.addAttribute("appContextPath", request.getContextPath());
1201
		return "contact-us";
1202
	}
23923 amit.gupta 1203
 
25649 tejbeer 1204
	@RequestMapping(value = "/notifications", method = RequestMethod.GET)
25683 tejbeer 1205
	public String getNotificationsWithType(HttpServletRequest request,
1206
			@RequestParam(required = false) MessageType messageType,
25649 tejbeer 1207
			@RequestParam(name = "offset", defaultValue = "0") int offset,
1208
			@RequestParam(name = "limit", defaultValue = "20") int limit, Model model) throws Exception {
1209
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
26060 tejbeer 1210
		int userId = 0;
1211
		boolean isAdmin = roleManager.isAdmin(loginDetails.getRoleIds());
1212
		if (isAdmin) {
1213
			userId = loginDetails.getFofoId();
1214
		} else {
1215
			userId = userAccountRepository.selectUserIdByRetailerId(loginDetails.getFofoId());
1216
		}
25683 tejbeer 1217
		List<Notification> notifications = null;
1218
 
26086 tejbeer 1219
		List<NotificationCampaign> notificationCampaigns = notificationCampaignRepository.getNotifications(messageType,
1220
				userId, offset, limit);
1221
		LOGGER.info("messageType" + messageType);
28468 tejbeer 1222
		notifications = fofoUser.getNotifications(notificationCampaigns, messageType);
26086 tejbeer 1223
 
25683 tejbeer 1224
		model.addAttribute("notifications", notifications);
1225
 
1226
		LOGGER.info("notifications" + notifications);
1227
		return "notification-template";
1228
	}
1229
 
25651 tejbeer 1230
	@RequestMapping(value = "/notifyDocument/documentId", method = RequestMethod.GET)
1231
	public ResponseEntity<?> retailerDocumentById(HttpServletRequest request,
1232
			@RequestParam(name = ProfitMandiConstants.DOCUMENT_ID) int documentId, @RequestParam int cid)
1233
			throws ProfitMandiBusinessException {
1234
		Document document = documentRepository.selectById(documentId);
1235
		NotificationCampaign nc = notificationCampaignRepository.selectById(cid);
1236
		if (nc.getDocumentId() == null) {
1237
			throw new ProfitMandiBusinessException("cid", nc.getId(), "not available");
1238
		}
1239
		if (nc.getDocumentId() != documentId) {
1240
			throw new ProfitMandiBusinessException(ProfitMandiConstants.DOCUMENT_ID, documentId, "RTLR_1014");
1241
		}
1242
		return responseSender.ok(document);
25649 tejbeer 1243
	}
1244
 
25651 tejbeer 1245
	@RequestMapping(value = "/notifyDocument/download", method = RequestMethod.GET)
1246
	public ResponseEntity<?> downloadRetailerDocument(HttpServletRequest request, @RequestParam int cid, Model model)
1247
			throws ProfitMandiBusinessException {
1248
 
1249
		NotificationCampaign nc = notificationCampaignRepository.selectById(cid);
1250
 
1251
		if (nc.getDocumentId() == null) {
1252
			throw new ProfitMandiBusinessException("cid", nc.getId(), "not available");
1253
		}
1254
 
1255
		Document document = documentRepository.selectById(nc.getDocumentId());
1256
 
1257
		FileInputStream file = null;
1258
		try {
1259
			file = new FileInputStream(document.getPath() + File.separator + document.getName());
1260
		} catch (FileNotFoundException e) {
1261
			LOGGER.error("Retailer Document file not found : ", e);
1262
			throw new ProfitMandiBusinessException(ProfitMandiConstants.DOCUMENT_ID, document.getId(), "RTLR_1013");
1263
		}
1264
		// ByteArrayOutputStream byteArrayOutputStream = new
1265
		// ByteArrayOutputStream();
1266
		// ExcelUtils.writeSchemeModels(schemeModels, byteArrayOutputStream);
1267
 
1268
		final HttpHeaders headers = new HttpHeaders();
1269
		String contentType = "";
1270
		if (document.getContentType() == ContentType.JPEG) {
1271
			contentType = "image/jpeg";
1272
		} else if (document.getContentType() == ContentType.PNG) {
1273
			contentType = "image/png";
1274
		} else if (document.getContentType() == ContentType.PDF) {
1275
			contentType = "application/pdf";
1276
		}
1277
		headers.set("Content-Type", contentType);
1278
		headers.set("Content-disposition", "inline; filename=" + document.getName());
1279
		headers.setContentLength(document.getSize());
1280
		final InputStreamResource inputStreamResource = new InputStreamResource(file);
1281
		return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
1282
	}
26460 amit.gupta 1283
 
27579 tejbeer 1284
	@RequestMapping(value = "/getItemWiseTertiary", method = RequestMethod.GET)
1285
	public String getItemWiseTertiary(HttpServletRequest request,
1286
			@RequestParam(name = ProfitMandiConstants.FOFO_ID) int fofoId, Model model)
1287
			throws ProfitMandiBusinessException {
1288
		List<ItemWiseTertiaryModel> itemWiseTertiary = fofoOrderRepository.SelectItemWiseTertiary(fofoId);
1289
 
1290
		LOGGER.info("itemWiseTertiary" + itemWiseTertiary);
27586 tejbeer 1291
		CustomRetailer customRetailer = retailerService.getFofoRetailer(fofoId);
1292
		model.addAttribute("customRetailer", customRetailer);
27579 tejbeer 1293
		model.addAttribute("itemWiseTertiary", itemWiseTertiary);
1294
		return "item-wise-tertiary";
1295
	}
1296
 
27586 tejbeer 1297
	@RequestMapping(value = "/getItemWiseIndent", method = RequestMethod.GET)
1298
	public String getItemWiseIndent(HttpServletRequest request,
1299
			@RequestParam(name = ProfitMandiConstants.FOFO_ID) int fofoId, Model model)
1300
			throws ProfitMandiBusinessException {
1301
 
1302
		List<Order> unbilledOrders = transactionService.getInTransitOrders(fofoId);
1303
		model.addAttribute("unbilledOrders", unbilledOrders);
1304
 
1305
		return "item-wise-indent";
1306
	}
1307
 
27636 tejbeer 1308
	@RequestMapping(value = "/getPartnerInvestment", method = RequestMethod.GET)
1309
	public String getPartnerInvestment(HttpServletRequest request,
1310
			@RequestParam(name = ProfitMandiConstants.FOFO_ID) int fofoId, Model model) throws Exception {
28468 tejbeer 1311
		Map<Integer, PartnerDetailModel> partnerStats = adminUser.getPartnersStatDataFromFile();
27636 tejbeer 1312
		PartnerDetailModel partnerDetailModel = partnerStats.get(fofoId);
1313
		CustomRetailer customRetailer = retailerService.getFofoRetailer(fofoId);
1314
		model.addAttribute("partnerDetailModel", partnerDetailModel);
1315
		model.addAttribute("customRetailer", customRetailer);
1316
		return "partner-investment";
1317
	}
27727 tejbeer 1318
 
27704 amit.gupta 1319
	@RequestMapping(value = "/getPartnerPendingIndentItem", method = RequestMethod.GET)
1320
	public String getPartnerPendingIndentItem(HttpServletRequest request, @RequestParam int warehouseId,
1321
			@RequestParam int itemId, Model model) throws ProfitMandiBusinessException {
1322
		List<PartnerPendingIndentItemModel> partnerPendingIndent = fofoStoreRepository
1323
				.selectPartnerPendingIndentItem(itemId, warehouseId);
27636 tejbeer 1324
 
27704 amit.gupta 1325
		model.addAttribute("partnerPendingIndent", partnerPendingIndent);
1326
		return "partner-pending-indent-item";
1327
	}
1328
 
27636 tejbeer 1329
	@RequestMapping(value = "/getPatnerActivateStock", method = RequestMethod.GET)
1330
	public String getPartnerActivateStockItem(HttpServletRequest request,
1331
			@RequestParam(name = ProfitMandiConstants.FOFO_ID) int fofoId, Model model) throws Exception {
1332
		List<ActivateItemModel> activateStocks = new ArrayList<>();
1333
		List<InventoryItem> inventoryItems = inventoryItemRepository.selectByActivatedNotSold(fofoId);
1334
		CustomRetailer customRetailer = retailerService.getFofoRetailer(fofoId);
1335
 
1336
		for (InventoryItem inventoryItem : inventoryItems) {
1337
			TagListing tagListing = tagListingRepository.selectByItemId(inventoryItem.getItemId());
1338
			Item item = itemRepository.selectById(inventoryItem.getItemId());
1339
			ActivateItemModel aim = new ActivateItemModel();
1340
			aim.setFofoId(inventoryItem.getFofoId());
1341
			aim.setQuantity(inventoryItem.getGoodQuantity());
1342
			aim.setAmount(tagListing.getSellingPrice());
1343
			aim.setItemDescription(item.getItemDescription());
1344
			aim.setItemId(inventoryItem.getItemId());
1345
			activateStocks.add(aim);
1346
		}
1347
 
1348
		model.addAttribute("activateStocks", activateStocks);
1349
		model.addAttribute("customRetailer", customRetailer);
1350
		return "partner-activate-stock";
1351
	}
1352
 
1353
	@RequestMapping(value = "/getPatnerBrandWiseMTDSale", method = RequestMethod.GET)
1354
	public String getPatnerBrandWiseMTDSale(HttpServletRequest request,
1355
			@RequestParam(name = ProfitMandiConstants.FOFO_ID) int fofoId, Model model) throws Exception {
1356
		LocalDateTime curDate = LocalDate.now().atStartOfDay();
1357
		CustomRetailer customRetailer = retailerService.getFofoRetailer(fofoId);
1358
		Map<String, Double> brandMtdAmount = fofoOrderItemRepository
1359
				.selectSumAmountGroupByBrand(curDate.withDayOfMonth(1), curDate.with(LocalTime.MAX), fofoId);
27638 tejbeer 1360
		Map<String, Long> brandMtdQty = fofoOrderItemRepository.selectSumQuantityGroupByBrand(curDate.withDayOfMonth(1),
1361
				curDate.with(LocalTime.MAX), fofoId);
27636 tejbeer 1362
		Double accesoriesmtdsale = fofoOrderRepository.selectSumSaleGroupByFofoIdsForMobileOrAccessories(fofoId,
1363
				curDate.withDayOfMonth(1), curDate.with(LocalTime.MAX), Optional.of(false)).get(fofoId);
27638 tejbeer 1364
		Long accesoriesmtdqty = fofoOrderRepository.selectSumSaleQuantityGroupByFofoIdsForMobileOrAccessories(fofoId,
1365
				curDate.withDayOfMonth(1), curDate.with(LocalTime.MAX), Optional.of(false)).get(fofoId);
1366
 
27636 tejbeer 1367
		LOGGER.info("accesoriesmtdsale" + accesoriesmtdsale);
1368
		model.addAttribute("brandMtdAmount", brandMtdAmount);
27638 tejbeer 1369
		model.addAttribute("brandMtdQty", brandMtdQty);
27636 tejbeer 1370
		model.addAttribute("accesoriesmtdsale", accesoriesmtdsale);
27638 tejbeer 1371
		model.addAttribute("accesoriesmtdqty", accesoriesmtdqty);
1372
 
27636 tejbeer 1373
		model.addAttribute("customRetailer", customRetailer);
1374
		return "partner-brand-mtd-sale";
1375
	}
1376
 
27637 tejbeer 1377
	@RequestMapping(value = "/getPatnerBrandWiseLMTDSale", method = RequestMethod.GET)
1378
	public String getPatnerBrandWiseLMTDSale(HttpServletRequest request,
1379
			@RequestParam(name = ProfitMandiConstants.FOFO_ID) int fofoId, Model model) throws Exception {
1380
		LocalDateTime curDate = LocalDate.now().atStartOfDay();
1381
		CustomRetailer customRetailer = retailerService.getFofoRetailer(fofoId);
1382
		Map<String, Double> brandLMtdAmount = fofoOrderItemRepository.selectSumAmountGroupByBrand(
1383
				curDate.withDayOfMonth(1).minusMonths(1), curDate.with(LocalTime.MAX).minusMonths(1), fofoId);
27638 tejbeer 1384
		Map<String, Long> brandLmtdQty = fofoOrderItemRepository.selectSumQuantityGroupByBrand(
1385
				curDate.withDayOfMonth(1).minusMonths(1), curDate.with(LocalTime.MAX).minusMonths(1), fofoId);
27637 tejbeer 1386
 
1387
		Double accesorieslmtdsale = fofoOrderRepository
1388
				.selectSumSaleGroupByFofoIdsForMobileOrAccessories(fofoId, curDate.withDayOfMonth(1).minusMonths(1),
1389
						curDate.with(LocalTime.MAX).minusMonths(1), Optional.of(false))
1390
				.get(fofoId);
27638 tejbeer 1391
		Long accesorieslmtdqty = fofoOrderRepository.selectSumSaleQuantityGroupByFofoIdsForMobileOrAccessories(fofoId,
1392
				curDate.withDayOfMonth(1).minusMonths(1), curDate.with(LocalTime.MAX).minusMonths(1),
1393
				Optional.of(false)).get(fofoId);
1394
 
27637 tejbeer 1395
		model.addAttribute("brandLMtdAmount", brandLMtdAmount);
27638 tejbeer 1396
		model.addAttribute("brandLmtdQty", brandLmtdQty);
1397
		model.addAttribute("accesorieslmtdqty", accesorieslmtdqty);
27637 tejbeer 1398
		model.addAttribute("accesorieslmtdsale", accesorieslmtdsale);
1399
		model.addAttribute("customRetailer", customRetailer);
1400
		return "partner-brand-lmtd-sale";
1401
	}
1402
 
27660 tejbeer 1403
	@RequestMapping(value = "/getPatnerBrandWiseLMSSale", method = RequestMethod.GET)
1404
	public String getPatnerBrandWiseLMSSale(HttpServletRequest request,
1405
			@RequestParam(name = ProfitMandiConstants.FOFO_ID) int fofoId, Model model) throws Exception {
1406
		LocalDateTime curDate = LocalDate.now().atStartOfDay();
1407
		CustomRetailer customRetailer = retailerService.getFofoRetailer(fofoId);
1408
		int lengthOfMonth = YearMonth.from(curDate.minusMonths(1)).lengthOfMonth();
1409
 
1410
		Map<String, Double> brandLMSAmount = fofoOrderItemRepository.selectSumAmountGroupByBrand(
27893 tejbeer 1411
				curDate.withDayOfMonth(1).minusMonths(1), curDate.withDayOfMonth(1), fofoId);
27660 tejbeer 1412
		Map<String, Long> brandLmsQty = fofoOrderItemRepository.selectSumQuantityGroupByBrand(
27893 tejbeer 1413
				curDate.withDayOfMonth(1).minusMonths(1), curDate.withDayOfMonth(1), fofoId);
27660 tejbeer 1414
 
27893 tejbeer 1415
		Double accesorieslmssale = fofoOrderRepository.selectSumSaleGroupByFofoIdsForMobileOrAccessories(fofoId,
1416
				curDate.withDayOfMonth(1).minusMonths(1), curDate.withDayOfMonth(1), Optional.of(false)).get(fofoId);
27660 tejbeer 1417
		Long accesorieslmsqty = fofoOrderRepository
1418
				.selectSumSaleQuantityGroupByFofoIdsForMobileOrAccessories(fofoId,
27893 tejbeer 1419
						curDate.withDayOfMonth(1).minusMonths(1), curDate.withDayOfMonth(1), Optional.of(false))
27660 tejbeer 1420
				.get(fofoId);
1421
 
1422
		model.addAttribute("brandLMSAmount", brandLMSAmount);
1423
		model.addAttribute("brandLmsQty", brandLmsQty);
1424
		model.addAttribute("accesorieslmssale", accesorieslmssale);
1425
		model.addAttribute("accesorieslmsqty", accesorieslmsqty);
1426
		model.addAttribute("customRetailer", customRetailer);
1427
		return "partner-brand-lms-sale";
1428
	}
1429
 
27640 tejbeer 1430
	@RequestMapping(value = "/getPatnerInStock", method = RequestMethod.GET)
1431
	public String getPatnerInStock(HttpServletRequest request,
1432
			@RequestParam(name = ProfitMandiConstants.FOFO_ID) int fofoId, Model model) throws Exception {
1433
 
1434
		CustomRetailer customRetailer = retailerService.getFofoRetailer(fofoId);
1435
 
27660 tejbeer 1436
		List<InStockBrandModel> mobileStocks = currentInventorySnapshotRepository
27640 tejbeer 1437
				.selectSumInStockMobileGroupByBrand(fofoId);
27660 tejbeer 1438
		List<InStockBrandModel> accesStock = currentInventorySnapshotRepository
27640 tejbeer 1439
				.selectSumInStockAccessoriesGroupByBrand(fofoId);
1440
 
27660 tejbeer 1441
		List<InStockBrandItemModel> stockItemlist = currentInventorySnapshotRepository
1442
				.selectInStockItemsByBrand(fofoId);
1443
 
1444
		Map<String, List<InStockBrandItemModel>> stockItemMap = stockItemlist.stream()
1445
				.collect(Collectors.groupingBy(InStockBrandItemModel::getBrand));
1446
 
1447
		model.addAttribute("stockItemMap", stockItemMap);
1448
		model.addAttribute("mobileStock", mobileStocks);
1449
		model.addAttribute("accesStock", accesStock);
27640 tejbeer 1450
		model.addAttribute("customRetailer", customRetailer);
1451
		return "partner-instock-item";
1452
	}
1453
 
27660 tejbeer 1454
	@RequestMapping(value = "/getOpenTicketByFofoId", method = RequestMethod.GET)
1455
	public String getOpenTicketByFofoId(HttpServletRequest request,
1456
			@RequestParam(name = ProfitMandiConstants.FOFO_ID) int fofoId, Model model) throws Exception {
1457
		Map<Integer, AuthUser> ticketIdAuthUser = new HashMap<>();
1458
		CustomRetailer customRetailer = retailerService.getFofoRetailer(fofoId);
1459
		List<Integer> ticketIds = ticketRepository.selectAllOpenTicketByRetailer(fofoId).stream().map(x -> x.getId())
1460
				.collect(Collectors.toList());
1461
		List<TicketAssigned> ticketAssigns = ticketAssignedRepository.selectByTicketIds(ticketIds);
1462
 
1463
		for (TicketAssigned ticketAssign : ticketAssigns) {
1464
			AuthUser authUser = authRepository.selectById(ticketAssign.getAssineeId());
1465
			ticketIdAuthUser.put(ticketAssign.getTicketId(), authUser);
1466
		}
1467
		model.addAttribute("ticketIdAuthUser", ticketIdAuthUser);
1468
		model.addAttribute("ticketAssigns", ticketAssigns);
1469
		model.addAttribute("customRetailer", customRetailer);
1470
		return "open-ticket";
1471
	}
1472
 
27893 tejbeer 1473
	@RequestMapping(value = "/getPartnerSecondarySale", method = RequestMethod.GET)
1474
	public String getPartnerSecondarySale(HttpServletRequest request,
1475
			@RequestParam(name = ProfitMandiConstants.FOFO_ID) int fofoId, @RequestParam String timeValue, Model model)
1476
			throws Exception {
1477
		LocalDateTime curDate = LocalDate.now().atStartOfDay();
1478
		CustomRetailer customRetailer = retailerService.getFofoRetailer(fofoId);
1479
		int lengthOfMonth = YearMonth.from(curDate.minusMonths(1)).lengthOfMonth();
1480
		LocalDateTime startDate = null;
1481
		LocalDateTime endDate = null;
1482
		List<InStockBrandModel> secondarySale = null;
1483
		Map<String, List<InStockBrandItemModel>> secondaryItemSale = null;
1484
 
1485
		if (timeValue.equals("mtd")) {
1486
			startDate = curDate.withDayOfMonth(1);
1487
			endDate = curDate.with(LocalTime.MAX);
1488
			secondarySale = orderRepository.selectAllBilledOrderBrandByFofoId(startDate, endDate, fofoId);
1489
			secondaryItemSale = orderRepository.selectAllBilledOrderBrandItemByFofoId(startDate, endDate, fofoId)
1490
					.stream().collect(Collectors.groupingBy(InStockBrandItemModel::getBrand));
1491
			LOGGER.info("secondarySalemtd" + secondarySale);
1492
		} else if (timeValue.equals("lmtd")) {
1493
			startDate = curDate.withDayOfMonth(1).minusMonths(1);
1494
			endDate = curDate.with(LocalTime.MAX).minusMonths(1);
1495
			secondaryItemSale = orderRepository.selectAllBilledOrderBrandItemByFofoId(startDate, endDate, fofoId)
1496
					.stream().collect(Collectors.groupingBy(InStockBrandItemModel::getBrand));
1497
 
1498
			secondarySale = orderRepository.selectAllBilledOrderBrandByFofoId(startDate, endDate, fofoId);
1499
			LOGGER.info("secondarySalelmtd" + secondarySale);
1500
 
1501
		} else {
1502
			startDate = curDate.withDayOfMonth(1).minusMonths(1);
1503
			endDate = curDate.withDayOfMonth(1);
1504
			secondaryItemSale = orderRepository.selectAllBilledOrderBrandItemByFofoId(startDate, endDate, fofoId)
1505
					.stream().collect(Collectors.groupingBy(InStockBrandItemModel::getBrand));
1506
 
1507
			secondarySale = orderRepository.selectAllBilledOrderBrandByFofoId(startDate, endDate, fofoId);
1508
			LOGGER.info("secondarySalelms" + secondarySale);
1509
 
1510
		}
1511
 
1512
		LOGGER.info("secondarySale" + secondarySale);
1513
		model.addAttribute("secondarySale", secondarySale);
1514
		model.addAttribute("secondaryItemSale", secondaryItemSale);
1515
		model.addAttribute("customRetailer", customRetailer);
1516
 
1517
		return "partner-secondary-order";
1518
	}
1519
 
28451 tejbeer 1520
	@RequestMapping(value = "/getMobileBrandWise", method = RequestMethod.GET)
1521
	public String getMobileBrandWise(HttpServletRequest request, Model model) throws Exception {
1522
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1523
		String email = loginDetails.getEmailId();
1524
 
1525
		AuthUser authUser = authRepository.selectByEmailOrMobile(email);
1526
		Map<String, Set<Integer>> storeGuyMap = csService.getAuthUserPartnerIdMapping();
1527
 
1528
		Set<Integer> fofoIds = storeGuyMap.get(authUser.getEmailId());
1529
		if (emails.contains(authUser.getEmailId())) {
1530
			fofoIds = storeGuyMap.get("tarun.verma@smartdukaan.com");
1531
			LOGGER.info("fofoIds" + fofoIds);
1532
		}
1533
 
28471 tejbeer 1534
		if (fofoIds == null) {
1535
			List<Position> positions1 = positionRepository.selectAll(authUser.getId());
1536
			if (positions1.stream().filter(x -> x.getCategoryId() == ProfitMandiConstants.TICKET_CATEGORY_MASTER)
1537
					.count() > 0) {
1538
				fofoIds = csService.getPositionCustomRetailerMap(positions1).values().stream().flatMap(x -> x.stream())
1539
						.map(x -> x.getPartnerId()).collect(Collectors.toSet());
1540
			}
1541
		}
1542
 
28451 tejbeer 1543
		Map<String, BrandWisePartnerSaleModel> partnersBrandSaleMap = null;
1544
		partnersBrandSaleMap = fofoStoreRepository.selectGroupByBrandWarehousePartnerSale(new ArrayList<>(fofoIds))
1545
				.stream().collect(Collectors.toMap(x -> x.getBrand(), x -> x));
1546
 
1547
		List<BrandWiseUnbilledActivateStockModel> unbilledActivatedStock = fofoStoreRepository
1548
				.selectUnbilledActivateStockGroupByBrand(new ArrayList<>(fofoIds));
1549
		for (BrandWiseUnbilledActivateStockModel un : unbilledActivatedStock) {
1550
			BrandWisePartnerSaleModel bpt = partnersBrandSaleMap.get(un.getBrand());
1551
			if (bpt != null) {
1552
				bpt.setAmtd(un.getUnbilledMtd());
1553
				bpt.setUamtdQty(un.getUnbilledMTDQty());
1554
			} else {
1555
				bpt = new BrandWisePartnerSaleModel();
1556
				bpt.setBrand(un.getBrand());
1557
				bpt.setAmtd(un.getUnbilledMtd());
1558
				bpt.setUamtdQty(un.getUnbilledMTDQty());
1559
				bpt.setLms(0);
1560
				bpt.setLmtd(0);
1561
				bpt.setMtd(0);
1562
				bpt.setMtdQty(0);
1563
				bpt.setLmtd(0);
1564
				bpt.setLmtdQty(0);
1565
				partnersBrandSaleMap.put(un.getBrand(), bpt);
1566
			}
1567
		}
1568
 
1569
		model.addAttribute("brandSalesMap", partnersBrandSaleMap);
1570
 
1571
		return "mobile-brand-wise-report";
1572
	}
1573
 
1574
	@RequestMapping(value = "/getAccessoriesBrandWise", method = RequestMethod.GET)
1575
	public String getAccessoriesBrandWise(HttpServletRequest request, Model model) throws Exception {
1576
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1577
		String email = loginDetails.getEmailId();
1578
 
1579
		AuthUser authUser = authRepository.selectByEmailOrMobile(email);
1580
		Map<String, Set<Integer>> storeGuyMap = csService.getAuthUserPartnerIdMapping();
1581
 
1582
		Set<Integer> fofoIds = storeGuyMap.get(authUser.getEmailId());
1583
		if (emails.contains(authUser.getEmailId())) {
1584
			fofoIds = storeGuyMap.get("tarun.verma@smartdukaan.com");
1585
			LOGGER.info("fofoIds" + fofoIds);
1586
		}
1587
 
28471 tejbeer 1588
		if (fofoIds == null) {
1589
			List<Position> positions1 = positionRepository.selectAll(authUser.getId());
1590
			if (positions1.stream().filter(x -> x.getCategoryId() == ProfitMandiConstants.TICKET_CATEGORY_MASTER)
1591
					.count() > 0) {
1592
				fofoIds = csService.getPositionCustomRetailerMap(positions1).values().stream().flatMap(x -> x.stream())
1593
						.map(x -> x.getPartnerId()).collect(Collectors.toSet());
1594
			}
1595
		}
1596
 
28451 tejbeer 1597
		List<BrandWisePartnerSaleModel> accessoriesBrandSales = null;
1598
 
1599
		accessoriesBrandSales = fofoStoreRepository
1600
				.selectGroupByBrandAccesoriesWarehousePartnerSale(new ArrayList<>(fofoIds));
1601
 
1602
		model.addAttribute("accessoriesBrandSales", accessoriesBrandSales);
1603
		return "accessories-brand-wise-report";
1604
	}
1605
 
1606
	@RequestMapping(value = "/getMobileLMSGraph", method = RequestMethod.GET)
28461 tejbeer 1607
	public String getMobileLMSGraph(HttpServletRequest request, @RequestParam(required = false) int warehouseId,
28451 tejbeer 1608
			@RequestParam(required = false) LocalDate date, @RequestParam List<Integer> fofoIds, Model model)
1609
			throws Exception {
1610
		Map<Integer, List<Integer>> warehouseIdFofoIdMap = fofoStoreRepository
1611
				.selectActivePartnersByRetailerIds(new ArrayList<>(fofoIds)).stream().collect(Collectors.groupingBy(
1612
						FofoStore::getWarehouseId, Collectors.mapping(FofoStore::getId, Collectors.toList())));
1613
 
1614
		ChartModel cm;
1615
		if (warehouseId != 0) {
28468 tejbeer 1616
			cm = adminUser.getBrandWiseLms(Arrays.asList(warehouseId),
28451 tejbeer 1617
					fofoIds.stream().map(x -> x).collect(Collectors.toList()), date);
1618
		} else {
28468 tejbeer 1619
			cm = adminUser.getBrandWiseLms(new ArrayList<>(warehouseIdFofoIdMap.keySet()),
28451 tejbeer 1620
					fofoIds.stream().map(x -> x).collect(Collectors.toList()), date);
1621
 
1622
		}
1623
 
1624
		LOGGER.info("chartMap" + gson.toJson(cm));
1625
		model.addAttribute("chartMap", gson.toJson(cm));
1626
		return "brand-wise-mobile-lms-chart";
1627
	}
1628
 
28461 tejbeer 1629
	@RequestMapping(value = "/getMobileLMSFilter", method = RequestMethod.GET)
1630
	public String getMobileLMSFilter(HttpServletRequest request,
1631
			@RequestParam(required = false, defaultValue = "0") int warehouseId,
1632
			@RequestParam(required = false) LocalDate date, Model model) throws Exception {
1633
 
1634
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1635
		String email = loginDetails.getEmailId();
28468 tejbeer 1636
		Map<String, Object> map = adminUser.getFilter(warehouseId, email, date);
28461 tejbeer 1637
		model.addAttribute("warehouseId", warehouseId);
1638
		model.addAllAttributes(map);
1639
 
1640
		return "chart-filter-lms";
1641
	}
1642
 
1643
	@RequestMapping(value = "/getMobileLMPFilter", method = RequestMethod.GET)
1644
	public String getMobileLMPFilter(HttpServletRequest request,
1645
			@RequestParam(required = false, defaultValue = "0") int warehouseId,
1646
			@RequestParam(required = false) LocalDate date, Model model) throws Exception {
1647
 
1648
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1649
		String email = loginDetails.getEmailId();
28468 tejbeer 1650
		Map<String, Object> map = adminUser.getFilter(warehouseId, email, date);
28461 tejbeer 1651
		model.addAttribute("warehouseId", warehouseId);
1652
		model.addAllAttributes(map);
1653
 
1654
		return "chart-filter-lmp";
1655
	}
1656
 
1657
	@RequestMapping(value = "/getMobileLMPGraph", method = RequestMethod.GET)
1658
	public String getMobileLMPGraph(HttpServletRequest request, @RequestParam(required = false) int warehouseId,
1659
			@RequestParam(required = false) LocalDate date, @RequestParam List<Integer> fofoIds, Model model)
1660
			throws Exception {
1661
		Map<Integer, List<Integer>> warehouseIdFofoIdMap = fofoStoreRepository
1662
				.selectActivePartnersByRetailerIds(new ArrayList<>(fofoIds)).stream().collect(Collectors.groupingBy(
1663
						FofoStore::getWarehouseId, Collectors.mapping(FofoStore::getId, Collectors.toList())));
1664
 
1665
		ChartModel cm;
1666
		if (warehouseId != 0) {
28468 tejbeer 1667
			cm = adminUser.getBrandWiseLmp(Arrays.asList(warehouseId),
28461 tejbeer 1668
					fofoIds.stream().map(x -> x).collect(Collectors.toList()), date);
1669
		} else {
28468 tejbeer 1670
			cm = adminUser.getBrandWiseLmp(new ArrayList<>(warehouseIdFofoIdMap.keySet()),
28461 tejbeer 1671
					fofoIds.stream().map(x -> x).collect(Collectors.toList()), date);
1672
 
1673
		}
1674
 
1675
		LOGGER.info("chartMap" + gson.toJson(cm));
1676
		model.addAttribute("chartMap", gson.toJson(cm));
1677
		return "brand-wise-mobile-lmp-chart";
1678
	}
1679
 
28825 tejbeer 1680
	@RequestMapping(value = "/getActivatedModelWarehouseWise", method = RequestMethod.GET)
1681
	public String getActivatedModelWarehouseWise(HttpServletRequest request, Model model, @RequestParam String brand)
1682
			throws Exception {
1683
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1684
		List<Integer> fofoIds = getFofoIds(loginDetails);
1685
		List<WarehouseWiseActivatedModel> warehouseWiseActivatedModels = activatedImeiRepository
1686
				.selectActivatedModelGroupByWarehouse(brand, fofoIds);
1687
		Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
1688
 
1689
		List<DBObject> mobileBrands = mongoClient.getAllBrandsToDisplay(3);
1690
 
1691
		List<String> brands = mobileBrands.stream().map(x -> (String) x.get("name")).collect(Collectors.toList());
1692
		LOGGER.info("brands" + brands.add("Redmi"));
1693
 
1694
		model.addAttribute("warehouseWiseActivatedModels", warehouseWiseActivatedModels);
1695
		model.addAttribute("warehouseMap", warehouseMap);
1696
		model.addAttribute("brands", brands);
1697
		model.addAttribute("selectedbrand", brand);
1698
		return "warehousewise_activated_model";
1699
	}
1700
 
1701
	@RequestMapping(value = "/getActivatedModelByBrand", method = RequestMethod.GET)
1702
	public String getActivatedModelByBrand(HttpServletRequest request, Model model) throws Exception {
1703
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1704
		List<Integer> fofoIds = getFofoIds(loginDetails);
1705
		List<BrandWiseActivatedModel> activatedModels = activatedImeiRepository
1706
				.selectActivatedModelGroupByBrand(new ArrayList<>(fofoIds));
1707
		model.addAttribute("activatedModels", activatedModels);
1708
		return "activation-brandwise-report";
1709
	}
1710
 
1711
	@RequestMapping(value = "/getWarehouseBrandWiseItemActivatedModel", method = RequestMethod.GET)
1712
	public String getWarehouseBrandWiseItemActivatedModel(HttpServletRequest request, Model model,
1713
			@RequestParam List<Integer> warehouseId, @RequestParam String brand) throws Exception {
1714
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1715
		List<Integer> fofoIds = getFofoIds(loginDetails);
1716
 
1717
		Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
1718
		List<WarehouseBrandWiseItemActivatedModel> activatedItems = activatedImeiRepository
1719
				.selectWarehouseBrandActivatedItem(warehouseId, brand, fofoIds);
1720
		model.addAttribute("warehouseMap", warehouseMap);
1721
		model.addAttribute("activatedItems", activatedItems);
1722
		return "warehouse-activated-itemwise-model";
1723
 
1724
	}
1725
 
1726
	@RequestMapping(value = "/getActivatedImeiUpdationDate", method = RequestMethod.GET)
1727
	public String getActivatedImeiUpdationDate(HttpServletRequest request, Model model) throws Exception {
1728
 
1729
		Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
1730
 
1731
		List<ActivationImeiUpdationModel> activationImeiUpdations = activatedImeiRepository
1732
				.selectActivatedUpdationDate();
1733
		model.addAttribute("warehouseMap", warehouseMap);
1734
		model.addAttribute("activationImeiUpdations", activationImeiUpdations);
1735
		return "activation-updation-timestamp";
1736
 
1737
	}
1738
 
1739
	private List<Integer> getFofoIds(LoginDetails loginDetails) throws ProfitMandiBusinessException {
1740
		String email = loginDetails.getEmailId();
1741
 
1742
		AuthUser authUser = authRepository.selectByEmailOrMobile(email);
1743
		Map<String, Set<Integer>> storeGuyMap = csService.getAuthUserPartnerIdMapping();
1744
 
1745
		Set<Integer> fofoIds = storeGuyMap.get(authUser.getEmailId());
1746
		if (emails.contains(authUser.getEmailId())) {
1747
			fofoIds = storeGuyMap.get("tarun.verma@smartdukaan.com");
1748
			LOGGER.info("fofoIds" + fofoIds);
1749
		}
1750
 
1751
		if (fofoIds == null) {
1752
			List<Position> positions1 = positionRepository.selectAll(authUser.getId());
1753
			if (positions1.stream().filter(x -> x.getCategoryId() == ProfitMandiConstants.TICKET_CATEGORY_MASTER)
1754
					.count() > 0) {
1755
				fofoIds = csService.getPositionCustomRetailerMap(positions1).values().stream().flatMap(x -> x.stream())
1756
						.map(x -> x.getPartnerId()).collect(Collectors.toSet());
1757
			}
1758
		}
1759
		return new ArrayList<>(fofoIds);
1760
	}
1761
 
21615 kshitij.so 1762
}