Subversion Repositories SmartDukaan

Rev

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