Subversion Repositories SmartDukaan

Rev

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