Subversion Repositories SmartDukaan

Rev

Rev 29707 | Rev 29746 | 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);	
580
	    List<Integer>	grnOrderIds = order.stream().map(x -> x.getId()).collect(Collectors.toList());
581
	    model.addAttribute("grnOrderIds", grnOrderIds);
582
	    if(!grnOrderIds.isEmpty()) {
583
 
584
	    List<LineItem>  grnPendingLineItem = lineItemRepository.selectLineItem(grnOrderIds);
585
	    Map<Integer, LineItem> grnPendingLineMap = grnPendingLineItem.stream().collect(Collectors.toMap(x -> x.getOrderId(), x -> x));
586
	    LOGGER.info("grnPendingLineMap {}", grnPendingLineMap);
587
	    model.addAttribute("grnPendingLineMap", grnPendingLineMap);
588
 
589
	    }
590
 
591
		return "purchase-grn-order-status";
592
	}
593
 
594
	@RequestMapping(value = "/getPendingOrderStatus", method = RequestMethod.GET)
595
	public String getPendingOrderStatus(HttpServletRequest request, Model model) throws Exception {
596
 
597
 
598
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
599
		int fofoId = loginDetails.getFofoId();
600
        ArrayList<in.shop2020.model.v1.order.OrderStatus> orderStatus = new ArrayList<>();
601
 
602
		orderStatus.add(in.shop2020.model.v1.order.OrderStatus.SUBMITTED_FOR_PROCESSING);
603
 
604
 
605
		List<Order> order =orderRepository.selectOrders(fofoId,orderStatus);	
606
	    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());
607
	    model.addAttribute("submittedOrderIds", submittedOrderIds);
608
	    if(!submittedOrderIds.isEmpty()) {
609
 
610
	    List<LineItem>  submittedLineItem = lineItemRepository.selectLineItem(submittedOrderIds);
611
	    Map<Integer, LineItem> submittedLineItemMap = submittedLineItem.stream().collect(Collectors.toMap(x -> x.getOrderId(), x -> x));
612
	    LOGGER.info("submittedLineItemMap {}", submittedLineItemMap);
613
	    model.addAttribute("submittedLineItemMap", submittedLineItemMap);
614
		    }
615
 
616
		return "purchase-pending-order-status";
617
	}
618
 
619
	@RequestMapping(value = "/getBilledOrderStatus", method = RequestMethod.GET)
620
	public String getBilledOrderStatus(HttpServletRequest request, Model model) throws Exception {
621
 
622
 
623
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
624
		int fofoId = loginDetails.getFofoId();
625
        ArrayList<in.shop2020.model.v1.order.OrderStatus> orderStatus = new ArrayList<>();
626
		orderStatus.add(in.shop2020.model.v1.order.OrderStatus.BILLED);
627
 
628
		List<Order> order =orderRepository.selectOrders(fofoId,orderStatus);	
629
	    	    List<Integer>	billedOrderIds = order.stream().filter(x -> x.getStatus() == in.shop2020.model.v1.order.OrderStatus.BILLED).map(x -> x.getId()).collect(Collectors.toList());
630
	     LOGGER.info("billedOrderIds {}", billedOrderIds);
631
	 	    model.addAttribute("billedOrderIds", billedOrderIds);
632
 
633
	    if(!billedOrderIds.isEmpty()) {
634
	    List<LineItem>  billedLineItem = lineItemRepository.selectLineItem(billedOrderIds);
635
	    Map<Integer, LineItem> billedLineItemMap = billedLineItem.stream().collect(Collectors.toMap(x -> x.getOrderId(), x -> x));
636
	    LOGGER.info("billedLineItemMap {}", billedLineItemMap);
637
	    model.addAttribute("billedLineItemMap", billedLineItemMap);
638
	    }
639
 
640
		return "purchase-billed-order-status";
641
	}
642
	@RequestMapping(value = "/getShippedOrderStatus", method = RequestMethod.GET)
643
	public String getShippedOrderStatus(HttpServletRequest request, Model model) throws Exception {
644
 
645
 
646
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
647
		int fofoId = loginDetails.getFofoId();
648
        ArrayList<in.shop2020.model.v1.order.OrderStatus> orderStatus = new ArrayList<>();
649
 
650
		orderStatus.add(in.shop2020.model.v1.order.OrderStatus.SHIPPED_FROM_WH);
651
 
652
 
653
		List<Order> order =orderRepository.selectOrders(fofoId,orderStatus);	
654
	   	    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());
655
	    	  	    model.addAttribute("shippedOrderIds", shippedOrderIds);
656
	    LOGGER.info("shippedOrderIds {}", shippedOrderIds);
657
 
658
 
659
	    if(!shippedOrderIds.isEmpty()) {
660
	    List<LineItem>  shippedLineItem = lineItemRepository.selectLineItem(shippedOrderIds);
661
	    Map<Integer, LineItem> shippedLineItemMap = shippedLineItem.stream().collect(Collectors.toMap(x -> x.getOrderId(), x -> x));
662
	    LOGGER.info("shippedLineItemMap {}", shippedLineItemMap);
663
 
664
	    model.addAttribute("shippedLineItemMap", shippedLineItemMap);
665
	    }
666
		return "purchase-shipped-order-status";
667
	}
23923 amit.gupta 668
 
28272 tejbeer 669
	@RequestMapping(value = "/getMonthsInvestment", method = RequestMethod.GET)
670
	public String getMonthsInvestment(HttpServletRequest request,
671
			@RequestParam(name = "month", required = true, defaultValue = "0") int month, Model model)
672
			throws Exception {
673
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
674
		int fofoId = loginDetails.getFofoId();
28468 tejbeer 675
		Map<String, Object> investment = fofoUser.getInvestmentsMonths(fofoId, month);
28430 tejbeer 676
 
28272 tejbeer 677
		LocalDateTime currentMonthStart = LocalDateTime.now().withDayOfMonth(1);
678
		LocalDateTime lastMonthStart = currentMonthStart.minusMonths(1);
679
		LocalDateTime currentMonthEnd = currentMonthStart.plusMonths(1).withDayOfMonth(1);
680
		double currentMonthRating = hygieneDataRepository.selectRatingAvg(loginDetails.getFofoId(), currentMonthStart,
681
				currentMonthEnd) / 2;
682
		double lastMonthRating = hygieneDataRepository.selectRatingAvg(loginDetails.getFofoId(), lastMonthStart,
683
				currentMonthStart) / 2;
684
		double ratingTillDate = hygieneDataRepository.selectRatingAvg(loginDetails.getFofoId(), LocalDateTime.MIN,
685
				currentMonthEnd) / 2;
686
		model.addAttribute("currentMonthRating", (float) Math.round(currentMonthRating * 10) / 10);
687
		model.addAttribute("lastMonthRating", (float) Math.round(lastMonthRating * 10) / 10);
688
		model.addAttribute("ratingTillDate", (float) Math.round(ratingTillDate * 10) / 10);
689
 
28430 tejbeer 690
		long hygieneCount = hygieneDataRepository.selectHygieneCount(loginDetails.getFofoId(), true,
691
				currentMonthStart.minusMonths(month), currentMonthEnd.minusMonths(month));
28272 tejbeer 692
 
693
		long invalidHygieneCount = hygieneDataRepository.selectHygieneCount(loginDetails.getFofoId(), false,
28430 tejbeer 694
				currentMonthStart.minusMonths(month), currentMonthEnd.minusMonths(month));
28272 tejbeer 695
		if (hygieneCount == 0 && invalidHygieneCount == 0) {
696
			invalidHygieneCount = 1;
697
		}
698
		Map<Integer, String> monthValueMap = new HashMap<>();
699
		for (int i = 0; i <= 5; i++) {
700
			LocalDateTime startOfMonth = LocalDateTime.now().withDayOfMonth(1).minusMonths(i);
701
			monthValueMap.put(i, startOfMonth.format(DateTimeFormatter.ofPattern("MMM''uu")));
702
		}
703
		model.addAttribute("hygienePercentage", (hygieneCount * 100) / (invalidHygieneCount + hygieneCount));
28430 tejbeer 704
		model.addAttribute("monthValueMap", monthValueMap);
28272 tejbeer 705
		model.addAttribute("investments", investment);
706
		model.addAttribute("monthDays", LocalDate.now().minusMonths(month).lengthOfMonth());
707
		model.addAttribute("dayOfMonth", LocalDate.now().minusMonths(month).lengthOfMonth());
28430 tejbeer 708
		model.addAttribute("month", month);
28272 tejbeer 709
		return "performance";
710
	}
711
 
27884 tejbeer 712
	@RequestMapping(value = "/investmentDetails", method = RequestMethod.GET)
713
	public String getInvestmentDetails(HttpServletRequest request, Model model) throws Exception {
714
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
715
		int fofoId = loginDetails.getFofoId();
28468 tejbeer 716
		ChartInvestmentModel cm = fofoUser.getInvestmentChart(fofoId);
27884 tejbeer 717
		model.addAttribute("chartPieMap", gson.toJson(cm));
718
 
719
		LOGGER.info("InvestmentChart" + gson.toJson(cm));
720
		LOGGER.info("InvestmentChart" + cm);
721
		return "investmentdetails";
722
	}
723
 
28430 tejbeer 724
	@RequestMapping(value = "/getlmsLineChart", method = RequestMethod.GET)
725
	public String getlmsLineChart(HttpServletRequest request, Model model) throws Exception {
726
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
727
		int fofoId = loginDetails.getFofoId();
28468 tejbeer 728
		ChartModel cm = fofoUser.getLmsLineChart(loginDetails.getFofoId());
28430 tejbeer 729
 
730
		LOGGER.info("linechartMap" + gson.toJson(cm));
731
		model.addAttribute("linechartMap", gson.toJson(cm));
732
		return "lmsLineChart";
733
	}
734
 
28439 tejbeer 735
	@RequestMapping(value = "/getMonthlyPurchaseLineChart", method = RequestMethod.GET)
736
	public String getMonthlyPurchaseLineChart(HttpServletRequest request, Model model) throws Exception {
737
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
738
		int fofoId = loginDetails.getFofoId();
28468 tejbeer 739
		ChartModel cm = fofoUser.getPurchaseOrderChart(fofoId);
28439 tejbeer 740
 
741
		LOGGER.info("chartMap" + gson.toJson(cm));
742
		model.addAttribute("chartMap", gson.toJson(cm));
743
 
744
		return "purchase_chart";
745
	}
746
 
28430 tejbeer 747
	@RequestMapping(value = "/getBarChart", method = RequestMethod.GET)
748
	public String getBarChart(HttpServletRequest request, Model model) throws Exception {
749
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
750
		int fofoId = loginDetails.getFofoId();
28468 tejbeer 751
		ChartModel cm = fofoUser.getBrandChart(fofoId);
28430 tejbeer 752
 
753
		LOGGER.info("chartMap" + gson.toJson(cm));
754
		model.addAttribute("chartMap", gson.toJson(cm));
755
 
756
		return "bar_chart";
757
	}
758
 
28455 tejbeer 759
	@RequestMapping(value = "/getPriceDropDetails", method = RequestMethod.GET)
760
	public String getPriceDropDetails(HttpServletRequest request,
761
			@RequestParam(name = "fofoId", required = true, defaultValue = "0") int fofoId,
762
			@RequestParam(name = "brand", required = true, defaultValue = "0") String brand,
28641 amit.gupta 763
			@RequestParam(name = "yearMonth", required = false, defaultValue = "0") String yearMonth, Model model)
28455 tejbeer 764
			throws Exception {
765
 
766
		LOGGER.info("params" + fofoId + brand + yearMonth);
767
 
768
		List<PriceDropWithDetailsByYearMonthModel> priceDropdetailsList = priceDropRepository
769
				.selectBrandPendingPriceDropWithDetailsByYearMonth(fofoId, brand, yearMonth);
770
 
771
		LOGGER.info("priceDropdetailsList" + priceDropdetailsList);
772
 
773
		model.addAttribute("priceDropdetailsList", priceDropdetailsList);
774
 
775
		return "price-drop-details";
776
	}
28825 tejbeer 777
 
28641 amit.gupta 778
	@RequestMapping(value = "/getPriceDropDetailSixMonths", method = RequestMethod.GET)
779
	public String getPriceDropDetailSixMonths(HttpServletRequest request,
780
			@RequestParam(name = "fofoId", required = true, defaultValue = "0") int fofoId,
781
			@RequestParam(name = "brand", required = true, defaultValue = "0") String brand, Model model)
782
			throws Exception {
28455 tejbeer 783
 
28641 amit.gupta 784
		LOGGER.info("params" + fofoId + brand);
785
		LocalDateTime curDate = LocalDate.now().atStartOfDay();
786
		LocalDateTime startfMonthSixMonth = curDate.withDayOfMonth(1).minusMonths(12);
787
		LocalDateTime endMonthTotal = curDate.withDayOfMonth(1).minusMonths(6);
788
 
789
		List<PriceDropWithDetailsByYearMonthModel> priceDropdetailsList = priceDropRepository
28825 tejbeer 790
				.selectBrandPendingPriceDropWithDetailsAndSixMonth(fofoId, brand, startfMonthSixMonth, endMonthTotal);
28641 amit.gupta 791
 
792
		LOGGER.info("priceDropdetailsList" + priceDropdetailsList);
793
 
794
		model.addAttribute("priceDropdetailsList", priceDropdetailsList);
795
 
796
		return "price-drop-details";
797
	}
798
 
28455 tejbeer 799
	@RequestMapping(value = "/getMonthlyPriceDrop", method = RequestMethod.GET)
800
	public String getMonthlyPriceDropTabular(HttpServletRequest request, Model model) throws Exception {
801
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
802
		int fofoId = loginDetails.getFofoId();
803
		LocalDateTime curDate = LocalDate.now().atStartOfDay();
804
 
805
		LocalDateTime startOfMonth = curDate.withDayOfMonth(1).minusMonths(6);
28641 amit.gupta 806
		LocalDateTime startfMonthTotal = curDate.withDayOfMonth(1).minusMonths(12);
807
		LocalDateTime endMonthTotal = curDate.withDayOfMonth(1).minusMonths(6);
28455 tejbeer 808
 
28641 amit.gupta 809
		List<YearMonth> yms = new ArrayList<YearMonth>();
28455 tejbeer 810
 
811
		for (int i = 1; i <= 6; i++) {
28641 amit.gupta 812
			yms.add(YearMonth.from(curDate.withDayOfMonth(1).minusMonths(i)));
28455 tejbeer 813
		}
28641 amit.gupta 814
		Collections.reverse(yms);
815
		model.addAttribute("yms", yms);
816
		LOGGER.info("ym" + yms);
28455 tejbeer 817
 
818
		List<PriceDropYearMonthModel> priceDropYearMonthModels = priceDropRepository
819
				.selectBrandPendingPriceDropByYearMonth(fofoId, startOfMonth);
820
 
28641 amit.gupta 821
		List<PriceDropBrandModel> priceDropBrandSixMonthTotals = priceDropRepository
822
				.selectSixMonthBrandPriceDropByYearMonth(fofoId, startfMonthTotal, endMonthTotal);
823
 
28455 tejbeer 824
		DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("MM-yyyy");
825
 
826
		Map<String, Map<YearMonth, Double>> brandMonthValue = new HashMap<>();
28641 amit.gupta 827
 
828
		LOGGER.info("priceDropBrandSixMonthTotals" + priceDropBrandSixMonthTotals);
28825 tejbeer 829
 
830
		Map<String, Double> priceDropBrandSixMonthMap = priceDropBrandSixMonthTotals.stream()
831
				.collect(Collectors.toMap(x -> x.getBrand(), x -> (double) x.getAmount()));
832
 
28641 amit.gupta 833
		model.addAttribute("priceDropBrandSixMonthMap", priceDropBrandSixMonthMap);
28455 tejbeer 834
		LOGGER.info("priceDropYearMonthModels" + priceDropYearMonthModels);
28641 amit.gupta 835
 
28455 tejbeer 836
		for (PriceDropYearMonthModel pdm : priceDropYearMonthModels) {
28641 amit.gupta 837
			Map<YearMonth, Double> brandValue = new HashMap<>();
28455 tejbeer 838
 
839
			if (brandMonthValue.containsKey(pdm.getBrand())) {
840
				brandValue = brandMonthValue.get(pdm.getBrand());
841
				brandValue.put(YearMonth.parse(pdm.getYearMonth(), dateTimeFormatter), (double) pdm.getAmount());
842
			} else {
843
 
844
				brandValue.put(YearMonth.parse(pdm.getYearMonth(), dateTimeFormatter), (double) pdm.getAmount());
845
 
846
			}
847
			brandMonthValue.put(pdm.getBrand(), brandValue);
848
		}
849
		List<String> brands = new ArrayList<>();
850
		brands.add("Accessories");
851
		brands.add("Oppo");
852
		brands.add("Vivo");
853
		brands.add("Samsung");
854
		brands.add("Realme");
28462 tejbeer 855
		brands.add("MI");
28455 tejbeer 856
		brands.add("Tecno");
857
		brands.add("Itel");
858
		brands.add("Nokia");
29578 tejbeer 859
 
28455 tejbeer 860
		Map<String, List<Double>> sortedBrandValue = new LinkedHashMap<>();
861
 
28825 tejbeer 862
		model.addAttribute("brands", brands);
863
 
28455 tejbeer 864
		for (String brand : brands) {
865
			Map<YearMonth, Double> yearMonthValue = brandMonthValue.get(brand);
866
			for (int i = 6; i >= 1; i--) {
867
 
868
				LocalDateTime startMonth = curDate.withDayOfMonth(1).minusMonths(i);
869
 
870
				if (yearMonthValue != null) {
871
					if (yearMonthValue.get(YearMonth.from(startMonth)) == null) {
872
						yearMonthValue.put(YearMonth.from(startMonth), 0.0);
873
					}
874
 
875
				} else {
876
					yearMonthValue = new HashMap<>();
877
					yearMonthValue.put(YearMonth.from(startMonth), 0.0);
878
				}
879
			}
880
 
881
			Map<YearMonth, Double> sortedMonthBrandValue = new TreeMap<>(yearMonthValue);
882
 
883
			brandMonthValue.put(brand, sortedMonthBrandValue);
884
 
885
			sortedBrandValue.put(brand, sortedMonthBrandValue.values().stream().collect(Collectors.toList()));
886
 
887
		}
888
 
29578 tejbeer 889
		LOGGER.info("sortedBrandValue" + sortedBrandValue);
890
		model.addAttribute("fofoId", fofoId);
28455 tejbeer 891
 
29578 tejbeer 892
		model.addAttribute("sortedBrandValue", sortedBrandValue);
28455 tejbeer 893
 
29578 tejbeer 894
		return "price-drop-tabular";
895
	}
28455 tejbeer 896
 
29578 tejbeer 897
	@RequestMapping(value = "/getMonthlyActivation", method = RequestMethod.GET)
898
	public String getMonthlyActivation(HttpServletRequest request, Model model) throws Exception {
899
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
900
		int fofoId = loginDetails.getFofoId();
28455 tejbeer 901
 
29578 tejbeer 902
		LocalDateTime curDate = LocalDate.now().atStartOfDay();
903
		LocalDateTime startOfMonth = curDate.withDayOfMonth(1).minusMonths(6);
904
 
905
		List<YearMonth> yms = new ArrayList<YearMonth>();
906
 
29580 tejbeer 907
		for (int i = 0; i <= 5; i++) {
29578 tejbeer 908
			yms.add(YearMonth.from(curDate.withDayOfMonth(1).minusMonths(i)));
909
		}
910
		Collections.reverse(yms);
911
		model.addAttribute("yms", yms);
912
		LOGGER.info("ym" + yms);
913
 
914
		List<ActivationYearMonthModel> pendingActivationModels = schemeInOutRepository
915
				.selectPendingActivationGroupByBrandYearMonth(fofoId, startOfMonth);
916
 
917
		List<ActivationBrandModel> pendingActivationBeforeSixMonth = schemeInOutRepository
918
				.selectByYearMonthActivationGroupByBrand(fofoId, startOfMonth);
919
 
920
		Map<String, Double> pendingActivationBeforeSixMonthMap = pendingActivationBeforeSixMonth.stream()
921
				.collect(Collectors.toMap(x -> x.getBrand(), x -> (double) x.getAmount()));
922
 
923
		model.addAttribute("pendingActivationBeforeSixMonthMap", pendingActivationBeforeSixMonthMap);
924
 
925
		DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("MM-yyyy");
926
 
927
		Map<String, Map<YearMonth, Double>> activationBrandMonthMap = new HashMap<>();
928
 
929
		for (ActivationYearMonthModel pam : pendingActivationModels) {
930
			Map<YearMonth, Double> brandValue = new HashMap<>();
931
 
932
			if (activationBrandMonthMap.containsKey(pam.getBrand())) {
933
				brandValue = activationBrandMonthMap.get(pam.getBrand());
934
				brandValue.put(YearMonth.parse(pam.getYearMonth(), dateTimeFormatter), (double) pam.getAmount());
935
			} else {
936
 
937
				brandValue.put(YearMonth.parse(pam.getYearMonth(), dateTimeFormatter), (double) pam.getAmount());
938
 
28455 tejbeer 939
			}
29578 tejbeer 940
			activationBrandMonthMap.put(pam.getBrand(), brandValue);
941
		}
28455 tejbeer 942
 
29578 tejbeer 943
		List<String> brands = new ArrayList<>();
944
		brands.add("Oppo");
945
		brands.add("Vivo");
946
		brands.add("Samsung");
947
		brands.add("Realme");
948
		brands.add("MI");
949
		brands.add("Tecno");
950
		brands.add("Itel");
951
		brands.add("Nokia");
952
		brands.add("Lava");
953
		Map<String, List<Double>> sortedBrandValue = new LinkedHashMap<>();
954
 
955
		model.addAttribute("brands", brands);
956
 
957
		for (String brand : brands) {
958
			Map<YearMonth, Double> yearMonthValue = activationBrandMonthMap.get(brand);
29580 tejbeer 959
			for (int i = 5; i >= 0; i--) {
29578 tejbeer 960
				LocalDateTime startMonth = curDate.withDayOfMonth(1).minusMonths(i);
961
				if (yearMonthValue != null) {
962
					if (yearMonthValue.get(YearMonth.from(startMonth)) == null) {
963
						yearMonthValue.put(YearMonth.from(startMonth), 0.0);
964
					}
965
 
966
				} else {
967
					yearMonthValue = new HashMap<>();
968
					yearMonthValue.put(YearMonth.from(startMonth), 0.0);
969
				}
970
			}
971
			Map<YearMonth, Double> sortedMonthBrandValue = new TreeMap<>(yearMonthValue);
972
			activationBrandMonthMap.put(brand, sortedMonthBrandValue);
973
			sortedBrandValue.put(brand, sortedMonthBrandValue.values().stream().collect(Collectors.toList()));
28455 tejbeer 974
		}
975
 
29580 tejbeer 976
		LOGGER.info("sortedBrandValue" + sortedBrandValue);
29578 tejbeer 977
		model.addAttribute("sortedBrandValue", sortedBrandValue);
28455 tejbeer 978
		model.addAttribute("fofoId", fofoId);
29578 tejbeer 979
		return "activation-tabular";
980
	}
28455 tejbeer 981
 
29578 tejbeer 982
	@RequestMapping(value = "/getMonthlyActivationItemDetail", method = RequestMethod.GET)
983
	public String getMonthlyActivationItemDetail(HttpServletRequest request,
984
			@RequestParam(name = "fofoId", required = true, defaultValue = "0") int fofoId,
985
			@RequestParam(name = "brand", required = true, defaultValue = "0") String brand,
986
			@RequestParam(name = "yearMonth", required = false, defaultValue = "0") String yearMonth, Model model)
987
			throws Exception {
28455 tejbeer 988
 
29578 tejbeer 989
		LOGGER.info("params" + fofoId + brand + yearMonth);
990
 
991
		List<ActivationItemDetailModel> activationItemDetails = schemeInOutRepository
992
				.selectBrandPendingActivationItemDetails(fofoId, brand, yearMonth);
993
 
994
		for (ActivationItemDetailModel activationItemDetail : activationItemDetails) {
995
 
996
			List<FofoLineItem> flis = fofoLineItemRepository
997
					.selectByInventoryItemId(activationItemDetail.getInventoryItemId());
998
 
999
			LOGGER.info("flis" + flis);
1000
 
1001
			int maxFofoOrderItemId = flis.stream().mapToInt(x -> x.getFofoOrderItemId()).max()
1002
					.orElseThrow(NoSuchElementException::new);
1003
			LOGGER.info("maxFofoOrderItemId" + maxFofoOrderItemId);
1004
 
1005
			FofoOrderItem foi = fofoOrderItemRepository.selectById(maxFofoOrderItemId);
1006
 
1007
			FofoOrder fo = fofoOrderRepository.selectByOrderId(foi.getOrderId());
1008
 
1009
			activationItemDetail.setInvoiceNumber(fo.getInvoiceNumber());
1010
 
1011
		}
1012
		LOGGER.info("activationItemDetails" + activationItemDetails);
1013
 
1014
		model.addAttribute("activationItemDetails", activationItemDetails);
1015
 
1016
		return "activation-pending-item-details";
28455 tejbeer 1017
	}
1018
 
29578 tejbeer 1019
	@RequestMapping(value = "/getMonthlyActivationBeforeSixMonthsItemDetail", method = RequestMethod.GET)
1020
	public String getMonthlyActivationItemDetail(HttpServletRequest request,
1021
			@RequestParam(name = "fofoId", required = true, defaultValue = "0") int fofoId,
1022
			@RequestParam(name = "brand", required = true, defaultValue = "0") String brand, Model model)
1023
			throws Exception {
1024
		LocalDateTime curDate = LocalDate.now().atStartOfDay();
1025
 
1026
		LocalDateTime startOfMonth = curDate.withDayOfMonth(1).minusMonths(6);
1027
 
1028
		List<ActivationItemDetailModel> activationItemDetails = schemeInOutRepository
1029
				.selectBrandPendingActivationItemDetailByYearMonth(fofoId, brand, startOfMonth);
1030
 
1031
		for (ActivationItemDetailModel activationItemDetail : activationItemDetails) {
1032
 
1033
			List<FofoLineItem> flis = fofoLineItemRepository
1034
					.selectByInventoryItemId(activationItemDetail.getInventoryItemId());
1035
			LOGGER.info("flis" + flis);
1036
 
1037
			int maxFofoOrderItemId = flis.stream().mapToInt(x -> x.getFofoOrderItemId()).max()
1038
					.orElseThrow(NoSuchElementException::new);
1039
			LOGGER.info("maxFofoOrderItemId" + maxFofoOrderItemId);
1040
 
1041
			FofoOrderItem foi = fofoOrderItemRepository.selectById(maxFofoOrderItemId);
1042
 
1043
			FofoOrder fo = fofoOrderRepository.selectByOrderId(foi.getOrderId());
1044
 
1045
			activationItemDetail.setInvoiceNumber(fo.getInvoiceNumber());
1046
 
1047
		}
1048
		LOGGER.info("activationItemDetails" + activationItemDetails);
1049
 
1050
		model.addAttribute("activationItemDetails", activationItemDetails);
1051
 
1052
		return "activation-pending-item-details";
1053
	}
1054
 
29707 tejbeer 1055
	@RequestMapping(value = "/getMonthlySamsungUpgradeOffer", method = RequestMethod.GET)
1056
	public String getMonthlySamsungUpgradeOffer(HttpServletRequest request, Model model) throws Exception {
1057
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1058
		int fofoId = loginDetails.getFofoId();
1059
 
1060
		LocalDateTime curDate = LocalDate.now().atStartOfDay();
1061
		LocalDateTime startOfMonth = curDate.withDayOfMonth(1).minusMonths(6);
1062
 
1063
		List<YearMonth> yms = new ArrayList<YearMonth>();
1064
 
1065
		for (int i = 0; i <= 5; i++) {
1066
			yms.add(YearMonth.from(curDate.withDayOfMonth(1).minusMonths(i)));
1067
		}
1068
		Collections.reverse(yms);
1069
		model.addAttribute("yms", yms);
1070
		LOGGER.info("ym" + yms);
1071
 
1072
		List<SamsungUpgradeOfferModel> suos = samsungUpgradeOfferRepository.selectUpgradeOfferGroupByYearMonth(fofoId,
1073
				UpgradeOfferStatus.approved, startOfMonth);
1074
 
1075
		LOGGER.info("suos" + suos);
1076
 
1077
		List<BrandAmountModel> beforeSixMonthOffers = samsungUpgradeOfferRepository
1078
				.selectUpgradeOfferByYearMonthGroupByBrand(fofoId, UpgradeOfferStatus.approved, startOfMonth);
1079
 
1080
		Map<String, Double> pendingUpgradeOfferBeforeSixMonthMap = beforeSixMonthOffers.stream()
1081
				.collect(Collectors.toMap(x -> x.getBrand(), x -> (double) x.getAmount()));
1082
 
1083
		model.addAttribute("pendingUpgradeOfferBeforeSixMonthMap", pendingUpgradeOfferBeforeSixMonthMap);
1084
 
1085
		DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("MM-yyyy");
1086
 
1087
		Map<String, Map<YearMonth, Double>> upgradeOfferBrandMonthMap = new HashMap<>();
1088
 
1089
		for (SamsungUpgradeOfferModel suo : suos) {
1090
			Map<YearMonth, Double> brandValue = new HashMap<>();
1091
 
1092
			if (upgradeOfferBrandMonthMap.containsKey(suo.getBrand())) {
1093
				brandValue = upgradeOfferBrandMonthMap.get(suo.getBrand());
1094
				brandValue.put(YearMonth.parse(suo.getYearMonth(), dateTimeFormatter), (double) suo.getAmount());
1095
			} else {
1096
 
1097
				brandValue.put(YearMonth.parse(suo.getYearMonth(), dateTimeFormatter), (double) suo.getAmount());
1098
 
1099
			}
1100
			upgradeOfferBrandMonthMap.put(suo.getBrand(), brandValue);
1101
		}
1102
 
1103
		Map<String, List<Double>> sortedBrandValue = new LinkedHashMap<>();
1104
		String brand = "Samsung";
1105
 
1106
		Map<YearMonth, Double> yearMonthValue = upgradeOfferBrandMonthMap.get(brand);
1107
		for (int i = 5; i >= 0; i--) {
1108
			LocalDateTime startMonth = curDate.withDayOfMonth(1).minusMonths(i);
1109
			if (yearMonthValue != null) {
1110
				if (yearMonthValue.get(YearMonth.from(startMonth)) == null) {
1111
					yearMonthValue.put(YearMonth.from(startMonth), 0.0);
1112
				}
1113
 
1114
			} else {
1115
				yearMonthValue = new HashMap<>();
1116
				yearMonthValue.put(YearMonth.from(startMonth), 0.0);
1117
			}
1118
		}
1119
		Map<YearMonth, Double> sortedMonthBrandValue = new TreeMap<>(yearMonthValue);
1120
		upgradeOfferBrandMonthMap.put(brand, sortedMonthBrandValue);
1121
		sortedBrandValue.put(brand, sortedMonthBrandValue.values().stream().collect(Collectors.toList()));
1122
		LOGGER.info("sortedBrandValue" + sortedBrandValue);
1123
 
1124
		model.addAttribute("brand", brand);
1125
		model.addAttribute("sortedBrandValue", sortedBrandValue);
1126
		model.addAttribute("fofoId", fofoId);
1127
		return "upgrade-offer-tabular";
1128
 
1129
	}
1130
 
1131
	@RequestMapping(value = "/getMonthlyUpgradeOfferItemDetail", method = RequestMethod.GET)
1132
	public String getMonthlyUpgradeOfferItemDetail(HttpServletRequest request,
1133
			@RequestParam(name = "fofoId", required = true, defaultValue = "0") int fofoId,
1134
			@RequestParam(name = "brand", required = true, defaultValue = "0") String brand,
1135
			@RequestParam(name = "yearMonth", required = false, defaultValue = "0") String yearMonth, Model model)
1136
			throws Exception {
1137
 
1138
		LOGGER.info("params" + fofoId + brand + yearMonth);
1139
		List<UpgradeOfferItemDetailModel> offerItems = samsungUpgradeOfferRepository
1140
				.selectUpgradeOfferItemDetails(fofoId, UpgradeOfferStatus.approved, brand, yearMonth);
1141
 
1142
		model.addAttribute("offerItems", offerItems);
1143
 
1144
		return "upgrade-offer-item-detail";
1145
	}
1146
 
1147
	@RequestMapping(value = "/getUpgradeOfferBeforeSixMonthItemDetail", method = RequestMethod.GET)
1148
	public String getUpgradeOfferBeforeSixMonthItemDetail(HttpServletRequest request,
1149
			@RequestParam(name = "fofoId", required = true, defaultValue = "0") int fofoId,
1150
			@RequestParam(name = "brand", required = true, defaultValue = "0") String brand, Model model)
1151
			throws Exception {
1152
		LocalDateTime curDate = LocalDate.now().atStartOfDay();
1153
 
1154
		LocalDateTime startOfMonth = curDate.withDayOfMonth(1).minusMonths(6);
1155
 
1156
		List<UpgradeOfferItemDetailModel> offerItems = samsungUpgradeOfferRepository
1157
				.selectUpgradeOfferItemDetailByYearMonth(fofoId, UpgradeOfferStatus.approved, brand, startOfMonth);
1158
 
1159
		model.addAttribute("offerItems", offerItems);
1160
 
1161
		return "upgrade-offer-item-detail";
1162
	}
1163
 
26468 amit.gupta 1164
	@RequestMapping(value = "/getAuthUserPartners", method = RequestMethod.GET)
26418 tejbeer 1165
	public String AuthUserPartnersDetail(HttpServletRequest request, Model model, @RequestParam int authId)
1166
			throws Exception {
1167
 
1168
		Map<Integer, List<Integer>> pp = csService.getAuthUserIdPartnerIdMapping();
26963 amit.gupta 1169
		Map<Integer, CustomRetailer> fofoIdAndPartnerMap = retailerService.getFofoRetailers(false);
26418 tejbeer 1170
 
26468 amit.gupta 1171
		Map<Integer, PartnerDetailModel> fofoIdAndallValues = partnerStatsService.getAllPartnerStats();
1172
		if (authId != 0) {
1173
			List<Integer> fofoIds = pp.get(authId);
1174
			fofoIdAndallValues = fofoIdAndallValues.entrySet().stream().filter(x -> fofoIds.contains(x.getKey()))
1175
					.collect(Collectors.toMap(x -> x.getKey(), x -> x.getValue()));
26474 amit.gupta 1176
		} else {
26418 tejbeer 1177
		}
1178
 
1179
		model.addAttribute("fofoIdAndallValues", fofoIdAndallValues);
1180
		model.addAttribute("fofoIdAndPartnerMap", fofoIdAndPartnerMap);
1181
 
1182
		return "auth_user_partner_detail";
26468 amit.gupta 1183
	}
26418 tejbeer 1184
 
27545 tejbeer 1185
	@RequestMapping(value = "/getWarehousePartners", method = RequestMethod.GET)
1186
	public String warehousePartnersDetail(HttpServletRequest request, Model model, @RequestParam int warehouseId)
1187
			throws Exception {
27701 tejbeer 1188
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1189
		String email = loginDetails.getEmailId();
28472 tejbeer 1190
 
1191
		Set<Integer> authfofoIds = new HashSet<>();
27701 tejbeer 1192
		Map<String, Set<Integer>> storeGuyMap = csService.getAuthUserPartnerIdMapping();
28472 tejbeer 1193
		authfofoIds = storeGuyMap.get(email);
27545 tejbeer 1194
 
28472 tejbeer 1195
		AuthUser authUser = authRepository.selectByEmailOrMobile(email);
1196
		if (authfofoIds == null) {
1197
			List<Position> positions1 = positionRepository.selectAll(authUser.getId());
1198
			if (positions1.stream().filter(x -> x.getCategoryId() == ProfitMandiConstants.TICKET_CATEGORY_MASTER)
1199
					.count() > 0) {
1200
				authfofoIds = csService.getPositionCustomRetailerMap(positions1).values().stream()
1201
						.flatMap(x -> x.stream()).map(x -> x.getPartnerId()).collect(Collectors.toSet());
1202
			}
1203
		}
27701 tejbeer 1204
		Map<Integer, List<Integer>> warehouseIdFofoIdMap = fofoStoreRepository
1205
				.selectActivePartnersByRetailerIds(new ArrayList<>(authfofoIds)).stream().collect(Collectors.groupingBy(
1206
						FofoStore::getWarehouseId, Collectors.mapping(FofoStore::getId, Collectors.toList())));
1207
 
27545 tejbeer 1208
		Map<Integer, CustomRetailer> fofoIdAndPartnerMap = retailerService.getFofoRetailers(false);
28468 tejbeer 1209
		Map<Integer, PartnerDetailModel> fofoIdAndallValues = adminUser.getPartnersStatDataFromFile();
27545 tejbeer 1210
		if (warehouseId != 0) {
27701 tejbeer 1211
			List<Integer> fofoIds = warehouseIdFofoIdMap.get(warehouseId);
1212
			/*
1213
			 * List<Integer> fofoIds =
1214
			 * fofoStoreRepository.selectActivePartnerByWarehouse(warehouseId).stream()
1215
			 * .map(x -> x.getId()).collect(Collectors.toList());
1216
			 */
27545 tejbeer 1217
			fofoIdAndallValues = fofoIdAndallValues.entrySet().stream().filter(x -> fofoIds.contains(x.getKey()))
1218
					.collect(Collectors.toMap(x -> x.getKey(), x -> x.getValue()));
1219
		} else {
28472 tejbeer 1220
 
1221
			List<Integer> fofoIds = new ArrayList<>(authfofoIds);
1222
			fofoIdAndallValues = fofoIdAndallValues.entrySet().stream().filter(x -> fofoIds.contains(x.getKey()))
27701 tejbeer 1223
					.collect(Collectors.toMap(x -> x.getKey(), x -> x.getValue()));
27545 tejbeer 1224
		}
29164 manish 1225
		ChartInvestmentModel cm = adminUser.getAllStatePartnerType(fofoIdAndallValues);
1226
		model.addAttribute("chartPieMap", gson.toJson(cm));
27545 tejbeer 1227
 
29164 manish 1228
		LOGGER.info("adminUserChart" + gson.toJson(cm));
1229
 
27545 tejbeer 1230
		model.addAttribute("fofoIdAndallValues", fofoIdAndallValues);
1231
		model.addAttribute("fofoIdAndPartnerMap", fofoIdAndPartnerMap);
1232
 
1233
		return "auth_user_partner_detail";
1234
	}
1235
 
27509 tejbeer 1236
	@RequestMapping(value = "/getWarehouseWiseBrandStock", method = RequestMethod.GET)
27701 tejbeer 1237
	public String getWarehouseWiseBrandStock(HttpServletRequest request, Model model,
1238
			@RequestParam List<Integer> warehouseId) throws Exception {
1239
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1240
		String email = loginDetails.getEmailId();
1241
		Map<String, Set<Integer>> storeGuyMap = csService.getAuthUserPartnerIdMapping();
1242
		Set<Integer> authfofoIds = storeGuyMap.get(email);
28471 tejbeer 1243
		AuthUser authUser = authRepository.selectByEmailOrMobile(email);
27509 tejbeer 1244
 
28471 tejbeer 1245
		if (authfofoIds == null) {
1246
			List<Position> positions1 = positionRepository.selectAll(authUser.getId());
1247
			if (positions1.stream().filter(x -> x.getCategoryId() == ProfitMandiConstants.TICKET_CATEGORY_MASTER)
1248
					.count() > 0) {
1249
				authfofoIds = csService.getPositionCustomRetailerMap(positions1).values().stream()
1250
						.flatMap(x -> x.stream()).map(x -> x.getPartnerId()).collect(Collectors.toSet());
1251
			}
1252
		}
1253
 
27701 tejbeer 1254
		Map<Integer, List<Integer>> warehouseIdFofoIdMap = fofoStoreRepository
1255
				.selectActivePartnersByRetailerIds(new ArrayList<>(authfofoIds)).stream().collect(Collectors.groupingBy(
1256
						FofoStore::getWarehouseId, Collectors.mapping(FofoStore::getId, Collectors.toList())));
1257
		List<WarehouseWiseBrandStockModel> warehouseWiseBrandStock = new ArrayList<>();
1258
		if (!warehouseId.contains(0)) {
1259
			warehouseWiseBrandStock = saholicInventoryCISRepository.selectGroupByWarehouseAndBrand(warehouseId);
1260
		} else {
1261
			LOGGER.info("warehouseIdFofoIdMap" + warehouseIdFofoIdMap.keySet());
1262
			warehouseWiseBrandStock = saholicInventoryCISRepository
1263
					.selectGroupByWarehouseAndBrand(new ArrayList<>(warehouseIdFofoIdMap.keySet()));
1264
 
1265
		}
27542 tejbeer 1266
		Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
27509 tejbeer 1267
		model.addAttribute("warehouseWiseBrandStock", warehouseWiseBrandStock);
27542 tejbeer 1268
		model.addAttribute("warehouseId", warehouseId);
27509 tejbeer 1269
		model.addAttribute("warehouseMap", warehouseMap);
27660 tejbeer 1270
 
27509 tejbeer 1271
		return "warehouse_brand_stock";
1272
	}
1273
 
27529 tejbeer 1274
	@RequestMapping(value = "/getWarehouseWiseData", method = RequestMethod.GET)
1275
	public String getWarehouseWiseData(HttpServletRequest request, Model model) throws Exception {
1276
		inventoryService.getItemAvailabilityAndIndent();
1277
		model.addAttribute("response", mvcResponseSender.createResponseString(true));
1278
		return "response";
1279
	}
1280
 
27628 tejbeer 1281
	@RequestMapping(value = "/getPartnersStatData", method = RequestMethod.GET)
1282
	public String getPartnersStatData(HttpServletRequest request, Model model) throws Exception {
1283
		Map<Integer, PartnerDetailModel> partnerStats = partnerStatsService.getAllPartnerStats();
1284
		ObjectOutputStream oos = null;
1285
		FileOutputStream fout = null;
1286
		try {
1287
			fout = new FileOutputStream("/tmp/partnerStat.tmp", false);
1288
			oos = new ObjectOutputStream(fout);
1289
			oos.writeObject(partnerStats);
1290
 
1291
		} catch (Exception ex) {
1292
			ex.printStackTrace();
1293
		} finally {
1294
			if (oos != null) {
1295
				oos.close();
1296
			}
1297
		}
1298
		ReporticoCacheTable rct = reporticoCacheTableRepository.selectByTableName("partnerStat");
1299
		if (rct == null) {
1300
			rct = new ReporticoCacheTable();
1301
			rct.setTableName("partnerStat");
1302
 
1303
		}
1304
		rct.setLastCreatedTimestamp(LocalDateTime.now());
1305
		reporticoCacheTableRepository.persist(rct);
1306
		model.addAttribute("response", mvcResponseSender.createResponseString(true));
1307
		return "response";
1308
	}
1309
 
27539 tejbeer 1310
	@RequestMapping(value = "/getWarehouseWiseBrandAndCategory", method = RequestMethod.GET)
1311
	public String getWarehouseWiseBrandAndCategory(HttpServletRequest request, Model model,
27538 tejbeer 1312
			@RequestParam List<Integer> warehouseId, @RequestParam List<String> brands, @RequestParam String category)
1313
			throws Exception {
27509 tejbeer 1314
 
1315
		Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
27529 tejbeer 1316
		List<String> listbrands = saholicInventoryCISRepository.selectAllBrand();
27538 tejbeer 1317
		List<String> listCategory = saholicInventoryCISRepository.selectAllSubCategory();
27539 tejbeer 1318
 
27509 tejbeer 1319
		model.addAttribute("warehouseMap", warehouseMap);
27529 tejbeer 1320
		model.addAttribute("brands", listbrands);
27538 tejbeer 1321
		model.addAttribute("listCategory", listCategory);
1322
 
27529 tejbeer 1323
		model.addAttribute("selectedBrand", brands);
27538 tejbeer 1324
		model.addAttribute("selectedWarehouse", warehouseId);
27539 tejbeer 1325
		model.addAttribute("selectedCategory", category);
1326
 
27509 tejbeer 1327
		return "warehouse_brand_item_stock";
1328
	}
1329
 
27538 tejbeer 1330
	@RequestMapping(value = "/getWarehouseWiseItemStock", method = RequestMethod.GET)
1331
	public String getWarehouseWiseItemStock(HttpServletRequest request, Model model,
1332
			@RequestParam List<Integer> warehouseId, @RequestParam List<String> brands, @RequestParam String category)
1333
			throws Exception {
27539 tejbeer 1334
		Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
1335
		if (warehouseId.contains(0)) {
1336
			warehouseId.addAll(warehouseMap.keySet());
1337
		}
27538 tejbeer 1338
		List<WarehouseWiseitemStockModel> warehouseWiseItemStock = saholicInventoryCISRepository
1339
				.selectWarehouseItemStock(warehouseId, brands, category);
27539 tejbeer 1340
 
27538 tejbeer 1341
		model.addAttribute("warehouseWiseItemStock", warehouseWiseItemStock);
1342
		model.addAttribute("warehouseMap", warehouseMap);
1343
		return "warehouse_item_details";
1344
	}
1345
 
27556 tejbeer 1346
	@RequestMapping(value = "/getWarehouseWiseBrandPartnerSale", method = RequestMethod.GET)
27591 tejbeer 1347
	public String getWarehouseWiseBrandPartnerSale(HttpServletRequest request, Model model, @RequestParam String brand)
1348
			throws Exception {
27701 tejbeer 1349
 
1350
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1351
		String email = loginDetails.getEmailId();
1352
		Map<String, Set<Integer>> storeGuyMap = csService.getAuthUserPartnerIdMapping();
1353
		Set<Integer> authfofoIds = storeGuyMap.get(email);
1354
 
28472 tejbeer 1355
		AuthUser authUser = authRepository.selectByEmailOrMobile(email);
1356
		if (authfofoIds == null) {
1357
			List<Position> positions1 = positionRepository.selectAll(authUser.getId());
1358
			if (positions1.stream().filter(x -> x.getCategoryId() == ProfitMandiConstants.TICKET_CATEGORY_MASTER)
1359
					.count() > 0) {
1360
				authfofoIds = csService.getPositionCustomRetailerMap(positions1).values().stream()
1361
						.flatMap(x -> x.stream()).map(x -> x.getPartnerId()).collect(Collectors.toSet());
1362
			}
1363
		}
1364
 
27670 tejbeer 1365
		Map<Integer, WarehouseWiseBrandSaleModel> warehouseWiseBrandPartnerSales = fofoStoreRepository
27701 tejbeer 1366
				.selectGroupByWarehouseBrandWisePartnerSale(brand, new ArrayList<>(authfofoIds)).stream()
27670 tejbeer 1367
				.collect(Collectors.toMap(x -> x.getWarehouseId(), x -> x));
1368
 
1369
		List<WarehouseWiseBrandUnbilledActivatedModel> unbilledStock = fofoStoreRepository
27701 tejbeer 1370
				.selectUnbilledActivateStockGroupByWarehouse(brand, new ArrayList<>(authfofoIds));
27670 tejbeer 1371
 
1372
		for (WarehouseWiseBrandUnbilledActivatedModel un : unbilledStock) {
1373
			WarehouseWiseBrandSaleModel bpt = warehouseWiseBrandPartnerSales.get(un.getWarehouseId());
1374
			if (bpt != null) {
1375
				bpt.setAmtd(un.getUnbilledMtd());
27676 tejbeer 1376
				bpt.setUamtdQty(un.getUnbilledQty());
27670 tejbeer 1377
			} else {
1378
				bpt = new WarehouseWiseBrandSaleModel();
1379
				bpt.setWarehouseId(un.getWarehouseId());
1380
				bpt.setAmtd(un.getUnbilledMtd());
27677 tejbeer 1381
				bpt.setUamtdQty(un.getUnbilledQty());
27670 tejbeer 1382
				bpt.setLms(0);
1383
				bpt.setLmtd(0);
1384
				bpt.setMtd(0);
1385
				bpt.setMtdQty(0);
1386
				bpt.setLmtd(0);
1387
				bpt.setLmtdQty(0);
1388
				warehouseWiseBrandPartnerSales.put(un.getWarehouseId(), bpt);
1389
			}
1390
		}
27556 tejbeer 1391
		Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
27591 tejbeer 1392
 
1393
		Set<String> brands = inventoryService.getAllTagListingBrands();
1394
		model.addAttribute("warehouseWiseBrandPartnerSales", warehouseWiseBrandPartnerSales);
27556 tejbeer 1395
		model.addAttribute("warehouseMap", warehouseMap);
27591 tejbeer 1396
		model.addAttribute("brands", brands);
1397
		model.addAttribute("selectedbrand", brand);
1398
		return "warehousewise_brand_partners_sale";
27556 tejbeer 1399
	}
1400
 
27594 tejbeer 1401
	@RequestMapping(value = "/getWarehouseWiseAccesoriesBrandPartnerSale", method = RequestMethod.GET)
1402
	public String getWarehouseWiseAccesoriesBrandPartnerSale(HttpServletRequest request, Model model,
1403
			@RequestParam String brand) throws Exception {
27701 tejbeer 1404
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1405
		String email = loginDetails.getEmailId();
1406
		Map<String, Set<Integer>> storeGuyMap = csService.getAuthUserPartnerIdMapping();
1407
		Set<Integer> authfofoIds = storeGuyMap.get(email);
28472 tejbeer 1408
 
1409
		AuthUser authUser = authRepository.selectByEmailOrMobile(email);
1410
		if (authfofoIds == null) {
1411
			List<Position> positions1 = positionRepository.selectAll(authUser.getId());
1412
			if (positions1.stream().filter(x -> x.getCategoryId() == ProfitMandiConstants.TICKET_CATEGORY_MASTER)
1413
					.count() > 0) {
1414
				authfofoIds = csService.getPositionCustomRetailerMap(positions1).values().stream()
1415
						.flatMap(x -> x.stream()).map(x -> x.getPartnerId()).collect(Collectors.toSet());
1416
			}
1417
		}
27594 tejbeer 1418
		List<WarehouseWiseBrandSaleModel> warehouseWiseBrandPartnerSales = fofoStoreRepository
27701 tejbeer 1419
				.selectGroupByWarehouseAccesoriesBrandWisePartnerSale(brand, new ArrayList<>(authfofoIds));
27594 tejbeer 1420
		Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
1421
 
1422
		Set<String> brands = inventoryService.getAllTagListingBrands();
1423
		model.addAttribute("warehouseWiseBrandPartnerSales", warehouseWiseBrandPartnerSales);
1424
		model.addAttribute("warehouseMap", warehouseMap);
1425
		model.addAttribute("brands", brands);
1426
		model.addAttribute("selectedbrand", brand);
1427
		return "warehousewise_accessoriesbrand_sale";
1428
	}
1429
 
27556 tejbeer 1430
	@RequestMapping(value = "/getWarehouseBrandWiseItemSale", method = RequestMethod.GET)
1431
	public String getWarehouseBrandWiseItemSale(HttpServletRequest request, Model model,
1432
			@RequestParam List<Integer> warehouseId, @RequestParam String brand) throws Exception {
1433
		Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
27701 tejbeer 1434
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1435
		String email = loginDetails.getEmailId();
1436
		Map<String, Set<Integer>> storeGuyMap = csService.getAuthUserPartnerIdMapping();
1437
		Set<Integer> authfofoIds = storeGuyMap.get(email);
27670 tejbeer 1438
		Map<Integer, WarehouseBrandWiseItemSaleModel> branditemSalesMap = fofoStoreRepository
27701 tejbeer 1439
				.selectWarehouseBrandItemSale(warehouseId, brand, new ArrayList<>(authfofoIds)).stream()
27670 tejbeer 1440
				.collect(Collectors.toMap(x -> x.getItemId(), x -> x));
1441
 
1442
		List<WarehouseBrandItemUnbilledActivatedModel> unbilledItems = fofoStoreRepository
27701 tejbeer 1443
				.selectWarehouseBrandItemUnbilledActivateStock(warehouseId, brand, new ArrayList<>(authfofoIds));
27670 tejbeer 1444
 
1445
		for (WarehouseBrandItemUnbilledActivatedModel un : unbilledItems) {
1446
			WarehouseBrandWiseItemSaleModel bpt = branditemSalesMap.get(un.getItemId());
1447
			if (bpt != null) {
1448
				bpt.setAmtd(un.getAmtd());
27676 tejbeer 1449
				bpt.setUamtdQty(un.getUnmtdQty());
27670 tejbeer 1450
			} else {
1451
				bpt = new WarehouseBrandWiseItemSaleModel();
1452
				bpt.setWarehouseId(un.getWarehouseId());
1453
				bpt.setItemId(un.getItemId());
1454
				bpt.setAmtd(un.getAmtd());
27677 tejbeer 1455
				bpt.setUamtdQty(un.getUnmtdQty());
27670 tejbeer 1456
				bpt.setBrand(un.getBrand());
1457
				bpt.setModelName(un.getModelName());
1458
				bpt.setModelNumber(un.getModelNumber());
1459
				bpt.setColor(un.getColor());
1460
				bpt.setLms(0);
1461
				bpt.setLmtd(0);
1462
				bpt.setMtd(0);
1463
				bpt.setMtdQty(0);
1464
				bpt.setLmtd(0);
1465
				bpt.setLmtdQty(0);
1466
				branditemSalesMap.put(un.getItemId(), bpt);
1467
			}
1468
		}
1469
		model.addAttribute("branditemSales", branditemSalesMap);
27556 tejbeer 1470
		model.addAttribute("warehouseMap", warehouseMap);
1471
		return "warehouse_partner_itemwise_sale";
1472
	}
1473
 
27594 tejbeer 1474
	@RequestMapping(value = "/getWarehouseAccesoriesBrandWiseItemSale", method = RequestMethod.GET)
1475
	public String getWarehouseAccesoriesBrandWiseItemSale(HttpServletRequest request, Model model,
1476
			@RequestParam List<Integer> warehouseId, @RequestParam String brand) throws Exception {
1477
		Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
27701 tejbeer 1478
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1479
		String email = loginDetails.getEmailId();
1480
		Map<String, Set<Integer>> storeGuyMap = csService.getAuthUserPartnerIdMapping();
1481
		Set<Integer> authfofoIds = storeGuyMap.get(email);
27594 tejbeer 1482
		List<WarehouseBrandWiseItemSaleModel> branditemSales = fofoStoreRepository
27701 tejbeer 1483
				.selectWarehouseAccesoriesBrandItemSale(warehouseId, brand, new ArrayList<>(authfofoIds));
27594 tejbeer 1484
		model.addAttribute("branditemSales", branditemSales);
1485
		model.addAttribute("warehouseMap", warehouseMap);
1486
		return "warehouse_accessories_itemwsie_sale";
1487
	}
1488
 
22354 ashik.ali 1489
	@RequestMapping(value = "/contactUs", method = RequestMethod.GET)
23923 amit.gupta 1490
	public String contactUs(HttpServletRequest request, Model model) throws Throwable {
22354 ashik.ali 1491
		model.addAttribute("appContextPath", request.getContextPath());
1492
		return "contact-us";
1493
	}
23923 amit.gupta 1494
 
25649 tejbeer 1495
	@RequestMapping(value = "/notifications", method = RequestMethod.GET)
25683 tejbeer 1496
	public String getNotificationsWithType(HttpServletRequest request,
1497
			@RequestParam(required = false) MessageType messageType,
25649 tejbeer 1498
			@RequestParam(name = "offset", defaultValue = "0") int offset,
1499
			@RequestParam(name = "limit", defaultValue = "20") int limit, Model model) throws Exception {
1500
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
26060 tejbeer 1501
		int userId = 0;
1502
		boolean isAdmin = roleManager.isAdmin(loginDetails.getRoleIds());
1503
		if (isAdmin) {
1504
			userId = loginDetails.getFofoId();
1505
		} else {
1506
			userId = userAccountRepository.selectUserIdByRetailerId(loginDetails.getFofoId());
1507
		}
25683 tejbeer 1508
		List<Notification> notifications = null;
1509
 
26086 tejbeer 1510
		List<NotificationCampaign> notificationCampaigns = notificationCampaignRepository.getNotifications(messageType,
1511
				userId, offset, limit);
1512
		LOGGER.info("messageType" + messageType);
28468 tejbeer 1513
		notifications = fofoUser.getNotifications(notificationCampaigns, messageType);
26086 tejbeer 1514
 
25683 tejbeer 1515
		model.addAttribute("notifications", notifications);
1516
 
1517
		LOGGER.info("notifications" + notifications);
1518
		return "notification-template";
1519
	}
1520
 
25651 tejbeer 1521
	@RequestMapping(value = "/notifyDocument/documentId", method = RequestMethod.GET)
1522
	public ResponseEntity<?> retailerDocumentById(HttpServletRequest request,
1523
			@RequestParam(name = ProfitMandiConstants.DOCUMENT_ID) int documentId, @RequestParam int cid)
1524
			throws ProfitMandiBusinessException {
1525
		Document document = documentRepository.selectById(documentId);
1526
		NotificationCampaign nc = notificationCampaignRepository.selectById(cid);
1527
		if (nc.getDocumentId() == null) {
1528
			throw new ProfitMandiBusinessException("cid", nc.getId(), "not available");
1529
		}
1530
		if (nc.getDocumentId() != documentId) {
1531
			throw new ProfitMandiBusinessException(ProfitMandiConstants.DOCUMENT_ID, documentId, "RTLR_1014");
1532
		}
1533
		return responseSender.ok(document);
25649 tejbeer 1534
	}
1535
 
25651 tejbeer 1536
	@RequestMapping(value = "/notifyDocument/download", method = RequestMethod.GET)
1537
	public ResponseEntity<?> downloadRetailerDocument(HttpServletRequest request, @RequestParam int cid, Model model)
1538
			throws ProfitMandiBusinessException {
1539
 
1540
		NotificationCampaign nc = notificationCampaignRepository.selectById(cid);
1541
 
1542
		if (nc.getDocumentId() == null) {
1543
			throw new ProfitMandiBusinessException("cid", nc.getId(), "not available");
1544
		}
1545
 
1546
		Document document = documentRepository.selectById(nc.getDocumentId());
1547
 
1548
		FileInputStream file = null;
1549
		try {
1550
			file = new FileInputStream(document.getPath() + File.separator + document.getName());
1551
		} catch (FileNotFoundException e) {
1552
			LOGGER.error("Retailer Document file not found : ", e);
1553
			throw new ProfitMandiBusinessException(ProfitMandiConstants.DOCUMENT_ID, document.getId(), "RTLR_1013");
1554
		}
1555
		// ByteArrayOutputStream byteArrayOutputStream = new
1556
		// ByteArrayOutputStream();
1557
		// ExcelUtils.writeSchemeModels(schemeModels, byteArrayOutputStream);
1558
 
1559
		final HttpHeaders headers = new HttpHeaders();
1560
		String contentType = "";
1561
		if (document.getContentType() == ContentType.JPEG) {
1562
			contentType = "image/jpeg";
1563
		} else if (document.getContentType() == ContentType.PNG) {
1564
			contentType = "image/png";
1565
		} else if (document.getContentType() == ContentType.PDF) {
1566
			contentType = "application/pdf";
1567
		}
1568
		headers.set("Content-Type", contentType);
1569
		headers.set("Content-disposition", "inline; filename=" + document.getName());
1570
		headers.setContentLength(document.getSize());
1571
		final InputStreamResource inputStreamResource = new InputStreamResource(file);
1572
		return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
1573
	}
26460 amit.gupta 1574
 
27579 tejbeer 1575
	@RequestMapping(value = "/getItemWiseTertiary", method = RequestMethod.GET)
1576
	public String getItemWiseTertiary(HttpServletRequest request,
1577
			@RequestParam(name = ProfitMandiConstants.FOFO_ID) int fofoId, Model model)
1578
			throws ProfitMandiBusinessException {
1579
		List<ItemWiseTertiaryModel> itemWiseTertiary = fofoOrderRepository.SelectItemWiseTertiary(fofoId);
1580
 
1581
		LOGGER.info("itemWiseTertiary" + itemWiseTertiary);
27586 tejbeer 1582
		CustomRetailer customRetailer = retailerService.getFofoRetailer(fofoId);
1583
		model.addAttribute("customRetailer", customRetailer);
27579 tejbeer 1584
		model.addAttribute("itemWiseTertiary", itemWiseTertiary);
1585
		return "item-wise-tertiary";
1586
	}
1587
 
27586 tejbeer 1588
	@RequestMapping(value = "/getItemWiseIndent", method = RequestMethod.GET)
1589
	public String getItemWiseIndent(HttpServletRequest request,
1590
			@RequestParam(name = ProfitMandiConstants.FOFO_ID) int fofoId, Model model)
1591
			throws ProfitMandiBusinessException {
1592
 
1593
		List<Order> unbilledOrders = transactionService.getInTransitOrders(fofoId);
1594
		model.addAttribute("unbilledOrders", unbilledOrders);
1595
 
1596
		return "item-wise-indent";
1597
	}
1598
 
27636 tejbeer 1599
	@RequestMapping(value = "/getPartnerInvestment", method = RequestMethod.GET)
1600
	public String getPartnerInvestment(HttpServletRequest request,
1601
			@RequestParam(name = ProfitMandiConstants.FOFO_ID) int fofoId, Model model) throws Exception {
28468 tejbeer 1602
		Map<Integer, PartnerDetailModel> partnerStats = adminUser.getPartnersStatDataFromFile();
27636 tejbeer 1603
		PartnerDetailModel partnerDetailModel = partnerStats.get(fofoId);
1604
		CustomRetailer customRetailer = retailerService.getFofoRetailer(fofoId);
1605
		model.addAttribute("partnerDetailModel", partnerDetailModel);
1606
		model.addAttribute("customRetailer", customRetailer);
1607
		return "partner-investment";
1608
	}
27727 tejbeer 1609
 
27704 amit.gupta 1610
	@RequestMapping(value = "/getPartnerPendingIndentItem", method = RequestMethod.GET)
1611
	public String getPartnerPendingIndentItem(HttpServletRequest request, @RequestParam int warehouseId,
1612
			@RequestParam int itemId, Model model) throws ProfitMandiBusinessException {
1613
		List<PartnerPendingIndentItemModel> partnerPendingIndent = fofoStoreRepository
1614
				.selectPartnerPendingIndentItem(itemId, warehouseId);
27636 tejbeer 1615
 
27704 amit.gupta 1616
		model.addAttribute("partnerPendingIndent", partnerPendingIndent);
1617
		return "partner-pending-indent-item";
1618
	}
1619
 
27636 tejbeer 1620
	@RequestMapping(value = "/getPatnerActivateStock", method = RequestMethod.GET)
1621
	public String getPartnerActivateStockItem(HttpServletRequest request,
1622
			@RequestParam(name = ProfitMandiConstants.FOFO_ID) int fofoId, Model model) throws Exception {
1623
		List<ActivateItemModel> activateStocks = new ArrayList<>();
1624
		List<InventoryItem> inventoryItems = inventoryItemRepository.selectByActivatedNotSold(fofoId);
1625
		CustomRetailer customRetailer = retailerService.getFofoRetailer(fofoId);
1626
 
1627
		for (InventoryItem inventoryItem : inventoryItems) {
1628
			TagListing tagListing = tagListingRepository.selectByItemId(inventoryItem.getItemId());
1629
			Item item = itemRepository.selectById(inventoryItem.getItemId());
1630
			ActivateItemModel aim = new ActivateItemModel();
1631
			aim.setFofoId(inventoryItem.getFofoId());
1632
			aim.setQuantity(inventoryItem.getGoodQuantity());
1633
			aim.setAmount(tagListing.getSellingPrice());
1634
			aim.setItemDescription(item.getItemDescription());
1635
			aim.setItemId(inventoryItem.getItemId());
1636
			activateStocks.add(aim);
1637
		}
1638
 
1639
		model.addAttribute("activateStocks", activateStocks);
1640
		model.addAttribute("customRetailer", customRetailer);
1641
		return "partner-activate-stock";
1642
	}
1643
 
1644
	@RequestMapping(value = "/getPatnerBrandWiseMTDSale", method = RequestMethod.GET)
1645
	public String getPatnerBrandWiseMTDSale(HttpServletRequest request,
1646
			@RequestParam(name = ProfitMandiConstants.FOFO_ID) int fofoId, Model model) throws Exception {
1647
		LocalDateTime curDate = LocalDate.now().atStartOfDay();
1648
		CustomRetailer customRetailer = retailerService.getFofoRetailer(fofoId);
1649
		Map<String, Double> brandMtdAmount = fofoOrderItemRepository
1650
				.selectSumAmountGroupByBrand(curDate.withDayOfMonth(1), curDate.with(LocalTime.MAX), fofoId);
27638 tejbeer 1651
		Map<String, Long> brandMtdQty = fofoOrderItemRepository.selectSumQuantityGroupByBrand(curDate.withDayOfMonth(1),
1652
				curDate.with(LocalTime.MAX), fofoId);
27636 tejbeer 1653
		Double accesoriesmtdsale = fofoOrderRepository.selectSumSaleGroupByFofoIdsForMobileOrAccessories(fofoId,
1654
				curDate.withDayOfMonth(1), curDate.with(LocalTime.MAX), Optional.of(false)).get(fofoId);
27638 tejbeer 1655
		Long accesoriesmtdqty = fofoOrderRepository.selectSumSaleQuantityGroupByFofoIdsForMobileOrAccessories(fofoId,
1656
				curDate.withDayOfMonth(1), curDate.with(LocalTime.MAX), Optional.of(false)).get(fofoId);
1657
 
27636 tejbeer 1658
		LOGGER.info("accesoriesmtdsale" + accesoriesmtdsale);
1659
		model.addAttribute("brandMtdAmount", brandMtdAmount);
27638 tejbeer 1660
		model.addAttribute("brandMtdQty", brandMtdQty);
27636 tejbeer 1661
		model.addAttribute("accesoriesmtdsale", accesoriesmtdsale);
27638 tejbeer 1662
		model.addAttribute("accesoriesmtdqty", accesoriesmtdqty);
1663
 
27636 tejbeer 1664
		model.addAttribute("customRetailer", customRetailer);
1665
		return "partner-brand-mtd-sale";
1666
	}
1667
 
27637 tejbeer 1668
	@RequestMapping(value = "/getPatnerBrandWiseLMTDSale", method = RequestMethod.GET)
1669
	public String getPatnerBrandWiseLMTDSale(HttpServletRequest request,
1670
			@RequestParam(name = ProfitMandiConstants.FOFO_ID) int fofoId, Model model) throws Exception {
1671
		LocalDateTime curDate = LocalDate.now().atStartOfDay();
1672
		CustomRetailer customRetailer = retailerService.getFofoRetailer(fofoId);
1673
		Map<String, Double> brandLMtdAmount = fofoOrderItemRepository.selectSumAmountGroupByBrand(
1674
				curDate.withDayOfMonth(1).minusMonths(1), curDate.with(LocalTime.MAX).minusMonths(1), fofoId);
27638 tejbeer 1675
		Map<String, Long> brandLmtdQty = fofoOrderItemRepository.selectSumQuantityGroupByBrand(
1676
				curDate.withDayOfMonth(1).minusMonths(1), curDate.with(LocalTime.MAX).minusMonths(1), fofoId);
27637 tejbeer 1677
 
1678
		Double accesorieslmtdsale = fofoOrderRepository
1679
				.selectSumSaleGroupByFofoIdsForMobileOrAccessories(fofoId, curDate.withDayOfMonth(1).minusMonths(1),
1680
						curDate.with(LocalTime.MAX).minusMonths(1), Optional.of(false))
1681
				.get(fofoId);
27638 tejbeer 1682
		Long accesorieslmtdqty = fofoOrderRepository.selectSumSaleQuantityGroupByFofoIdsForMobileOrAccessories(fofoId,
1683
				curDate.withDayOfMonth(1).minusMonths(1), curDate.with(LocalTime.MAX).minusMonths(1),
1684
				Optional.of(false)).get(fofoId);
1685
 
27637 tejbeer 1686
		model.addAttribute("brandLMtdAmount", brandLMtdAmount);
27638 tejbeer 1687
		model.addAttribute("brandLmtdQty", brandLmtdQty);
1688
		model.addAttribute("accesorieslmtdqty", accesorieslmtdqty);
27637 tejbeer 1689
		model.addAttribute("accesorieslmtdsale", accesorieslmtdsale);
1690
		model.addAttribute("customRetailer", customRetailer);
1691
		return "partner-brand-lmtd-sale";
1692
	}
1693
 
27660 tejbeer 1694
	@RequestMapping(value = "/getPatnerBrandWiseLMSSale", method = RequestMethod.GET)
1695
	public String getPatnerBrandWiseLMSSale(HttpServletRequest request,
1696
			@RequestParam(name = ProfitMandiConstants.FOFO_ID) int fofoId, Model model) throws Exception {
1697
		LocalDateTime curDate = LocalDate.now().atStartOfDay();
1698
		CustomRetailer customRetailer = retailerService.getFofoRetailer(fofoId);
1699
		int lengthOfMonth = YearMonth.from(curDate.minusMonths(1)).lengthOfMonth();
1700
 
1701
		Map<String, Double> brandLMSAmount = fofoOrderItemRepository.selectSumAmountGroupByBrand(
27893 tejbeer 1702
				curDate.withDayOfMonth(1).minusMonths(1), curDate.withDayOfMonth(1), fofoId);
27660 tejbeer 1703
		Map<String, Long> brandLmsQty = fofoOrderItemRepository.selectSumQuantityGroupByBrand(
27893 tejbeer 1704
				curDate.withDayOfMonth(1).minusMonths(1), curDate.withDayOfMonth(1), fofoId);
27660 tejbeer 1705
 
27893 tejbeer 1706
		Double accesorieslmssale = fofoOrderRepository.selectSumSaleGroupByFofoIdsForMobileOrAccessories(fofoId,
1707
				curDate.withDayOfMonth(1).minusMonths(1), curDate.withDayOfMonth(1), Optional.of(false)).get(fofoId);
27660 tejbeer 1708
		Long accesorieslmsqty = fofoOrderRepository
1709
				.selectSumSaleQuantityGroupByFofoIdsForMobileOrAccessories(fofoId,
27893 tejbeer 1710
						curDate.withDayOfMonth(1).minusMonths(1), curDate.withDayOfMonth(1), Optional.of(false))
27660 tejbeer 1711
				.get(fofoId);
1712
 
1713
		model.addAttribute("brandLMSAmount", brandLMSAmount);
1714
		model.addAttribute("brandLmsQty", brandLmsQty);
1715
		model.addAttribute("accesorieslmssale", accesorieslmssale);
1716
		model.addAttribute("accesorieslmsqty", accesorieslmsqty);
1717
		model.addAttribute("customRetailer", customRetailer);
1718
		return "partner-brand-lms-sale";
1719
	}
1720
 
27640 tejbeer 1721
	@RequestMapping(value = "/getPatnerInStock", method = RequestMethod.GET)
1722
	public String getPatnerInStock(HttpServletRequest request,
1723
			@RequestParam(name = ProfitMandiConstants.FOFO_ID) int fofoId, Model model) throws Exception {
1724
 
1725
		CustomRetailer customRetailer = retailerService.getFofoRetailer(fofoId);
1726
 
27660 tejbeer 1727
		List<InStockBrandModel> mobileStocks = currentInventorySnapshotRepository
27640 tejbeer 1728
				.selectSumInStockMobileGroupByBrand(fofoId);
27660 tejbeer 1729
		List<InStockBrandModel> accesStock = currentInventorySnapshotRepository
27640 tejbeer 1730
				.selectSumInStockAccessoriesGroupByBrand(fofoId);
1731
 
27660 tejbeer 1732
		List<InStockBrandItemModel> stockItemlist = currentInventorySnapshotRepository
1733
				.selectInStockItemsByBrand(fofoId);
1734
 
1735
		Map<String, List<InStockBrandItemModel>> stockItemMap = stockItemlist.stream()
1736
				.collect(Collectors.groupingBy(InStockBrandItemModel::getBrand));
1737
 
1738
		model.addAttribute("stockItemMap", stockItemMap);
1739
		model.addAttribute("mobileStock", mobileStocks);
1740
		model.addAttribute("accesStock", accesStock);
27640 tejbeer 1741
		model.addAttribute("customRetailer", customRetailer);
1742
		return "partner-instock-item";
1743
	}
1744
 
27660 tejbeer 1745
	@RequestMapping(value = "/getOpenTicketByFofoId", method = RequestMethod.GET)
1746
	public String getOpenTicketByFofoId(HttpServletRequest request,
1747
			@RequestParam(name = ProfitMandiConstants.FOFO_ID) int fofoId, Model model) throws Exception {
1748
		Map<Integer, AuthUser> ticketIdAuthUser = new HashMap<>();
1749
		CustomRetailer customRetailer = retailerService.getFofoRetailer(fofoId);
1750
		List<Integer> ticketIds = ticketRepository.selectAllOpenTicketByRetailer(fofoId).stream().map(x -> x.getId())
1751
				.collect(Collectors.toList());
1752
		List<TicketAssigned> ticketAssigns = ticketAssignedRepository.selectByTicketIds(ticketIds);
1753
 
1754
		for (TicketAssigned ticketAssign : ticketAssigns) {
1755
			AuthUser authUser = authRepository.selectById(ticketAssign.getAssineeId());
1756
			ticketIdAuthUser.put(ticketAssign.getTicketId(), authUser);
1757
		}
1758
		model.addAttribute("ticketIdAuthUser", ticketIdAuthUser);
1759
		model.addAttribute("ticketAssigns", ticketAssigns);
1760
		model.addAttribute("customRetailer", customRetailer);
1761
		return "open-ticket";
1762
	}
1763
 
27893 tejbeer 1764
	@RequestMapping(value = "/getPartnerSecondarySale", method = RequestMethod.GET)
1765
	public String getPartnerSecondarySale(HttpServletRequest request,
1766
			@RequestParam(name = ProfitMandiConstants.FOFO_ID) int fofoId, @RequestParam String timeValue, Model model)
1767
			throws Exception {
1768
		LocalDateTime curDate = LocalDate.now().atStartOfDay();
1769
		CustomRetailer customRetailer = retailerService.getFofoRetailer(fofoId);
1770
		int lengthOfMonth = YearMonth.from(curDate.minusMonths(1)).lengthOfMonth();
1771
		LocalDateTime startDate = null;
1772
		LocalDateTime endDate = null;
1773
		List<InStockBrandModel> secondarySale = null;
1774
		Map<String, List<InStockBrandItemModel>> secondaryItemSale = null;
1775
 
1776
		if (timeValue.equals("mtd")) {
1777
			startDate = curDate.withDayOfMonth(1);
1778
			endDate = curDate.with(LocalTime.MAX);
1779
			secondarySale = orderRepository.selectAllBilledOrderBrandByFofoId(startDate, endDate, fofoId);
1780
			secondaryItemSale = orderRepository.selectAllBilledOrderBrandItemByFofoId(startDate, endDate, fofoId)
1781
					.stream().collect(Collectors.groupingBy(InStockBrandItemModel::getBrand));
1782
			LOGGER.info("secondarySalemtd" + secondarySale);
1783
		} else if (timeValue.equals("lmtd")) {
1784
			startDate = curDate.withDayOfMonth(1).minusMonths(1);
1785
			endDate = curDate.with(LocalTime.MAX).minusMonths(1);
1786
			secondaryItemSale = orderRepository.selectAllBilledOrderBrandItemByFofoId(startDate, endDate, fofoId)
1787
					.stream().collect(Collectors.groupingBy(InStockBrandItemModel::getBrand));
1788
 
1789
			secondarySale = orderRepository.selectAllBilledOrderBrandByFofoId(startDate, endDate, fofoId);
1790
			LOGGER.info("secondarySalelmtd" + secondarySale);
1791
 
1792
		} else {
1793
			startDate = curDate.withDayOfMonth(1).minusMonths(1);
1794
			endDate = curDate.withDayOfMonth(1);
1795
			secondaryItemSale = orderRepository.selectAllBilledOrderBrandItemByFofoId(startDate, endDate, fofoId)
1796
					.stream().collect(Collectors.groupingBy(InStockBrandItemModel::getBrand));
1797
 
1798
			secondarySale = orderRepository.selectAllBilledOrderBrandByFofoId(startDate, endDate, fofoId);
1799
			LOGGER.info("secondarySalelms" + secondarySale);
1800
 
1801
		}
1802
 
1803
		LOGGER.info("secondarySale" + secondarySale);
1804
		model.addAttribute("secondarySale", secondarySale);
1805
		model.addAttribute("secondaryItemSale", secondaryItemSale);
1806
		model.addAttribute("customRetailer", customRetailer);
1807
 
1808
		return "partner-secondary-order";
1809
	}
1810
 
28451 tejbeer 1811
	@RequestMapping(value = "/getMobileBrandWise", method = RequestMethod.GET)
1812
	public String getMobileBrandWise(HttpServletRequest request, Model model) throws Exception {
1813
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1814
		String email = loginDetails.getEmailId();
1815
 
1816
		AuthUser authUser = authRepository.selectByEmailOrMobile(email);
1817
		Map<String, Set<Integer>> storeGuyMap = csService.getAuthUserPartnerIdMapping();
1818
 
1819
		Set<Integer> fofoIds = storeGuyMap.get(authUser.getEmailId());
1820
		if (emails.contains(authUser.getEmailId())) {
1821
			fofoIds = storeGuyMap.get("tarun.verma@smartdukaan.com");
1822
			LOGGER.info("fofoIds" + fofoIds);
1823
		}
1824
 
28471 tejbeer 1825
		if (fofoIds == null) {
1826
			List<Position> positions1 = positionRepository.selectAll(authUser.getId());
1827
			if (positions1.stream().filter(x -> x.getCategoryId() == ProfitMandiConstants.TICKET_CATEGORY_MASTER)
1828
					.count() > 0) {
1829
				fofoIds = csService.getPositionCustomRetailerMap(positions1).values().stream().flatMap(x -> x.stream())
1830
						.map(x -> x.getPartnerId()).collect(Collectors.toSet());
1831
			}
1832
		}
1833
 
28451 tejbeer 1834
		Map<String, BrandWisePartnerSaleModel> partnersBrandSaleMap = null;
1835
		partnersBrandSaleMap = fofoStoreRepository.selectGroupByBrandWarehousePartnerSale(new ArrayList<>(fofoIds))
1836
				.stream().collect(Collectors.toMap(x -> x.getBrand(), x -> x));
1837
 
1838
		List<BrandWiseUnbilledActivateStockModel> unbilledActivatedStock = fofoStoreRepository
1839
				.selectUnbilledActivateStockGroupByBrand(new ArrayList<>(fofoIds));
1840
		for (BrandWiseUnbilledActivateStockModel un : unbilledActivatedStock) {
1841
			BrandWisePartnerSaleModel bpt = partnersBrandSaleMap.get(un.getBrand());
1842
			if (bpt != null) {
1843
				bpt.setAmtd(un.getUnbilledMtd());
1844
				bpt.setUamtdQty(un.getUnbilledMTDQty());
1845
			} else {
1846
				bpt = new BrandWisePartnerSaleModel();
1847
				bpt.setBrand(un.getBrand());
1848
				bpt.setAmtd(un.getUnbilledMtd());
1849
				bpt.setUamtdQty(un.getUnbilledMTDQty());
1850
				bpt.setLms(0);
1851
				bpt.setLmtd(0);
1852
				bpt.setMtd(0);
1853
				bpt.setMtdQty(0);
1854
				bpt.setLmtd(0);
1855
				bpt.setLmtdQty(0);
1856
				partnersBrandSaleMap.put(un.getBrand(), bpt);
1857
			}
1858
		}
1859
 
1860
		model.addAttribute("brandSalesMap", partnersBrandSaleMap);
1861
 
1862
		return "mobile-brand-wise-report";
1863
	}
1864
 
1865
	@RequestMapping(value = "/getAccessoriesBrandWise", method = RequestMethod.GET)
1866
	public String getAccessoriesBrandWise(HttpServletRequest request, Model model) throws Exception {
1867
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1868
		String email = loginDetails.getEmailId();
1869
 
1870
		AuthUser authUser = authRepository.selectByEmailOrMobile(email);
1871
		Map<String, Set<Integer>> storeGuyMap = csService.getAuthUserPartnerIdMapping();
1872
 
1873
		Set<Integer> fofoIds = storeGuyMap.get(authUser.getEmailId());
1874
		if (emails.contains(authUser.getEmailId())) {
1875
			fofoIds = storeGuyMap.get("tarun.verma@smartdukaan.com");
1876
			LOGGER.info("fofoIds" + fofoIds);
1877
		}
1878
 
28471 tejbeer 1879
		if (fofoIds == null) {
1880
			List<Position> positions1 = positionRepository.selectAll(authUser.getId());
1881
			if (positions1.stream().filter(x -> x.getCategoryId() == ProfitMandiConstants.TICKET_CATEGORY_MASTER)
1882
					.count() > 0) {
1883
				fofoIds = csService.getPositionCustomRetailerMap(positions1).values().stream().flatMap(x -> x.stream())
1884
						.map(x -> x.getPartnerId()).collect(Collectors.toSet());
1885
			}
1886
		}
1887
 
28451 tejbeer 1888
		List<BrandWisePartnerSaleModel> accessoriesBrandSales = null;
1889
 
1890
		accessoriesBrandSales = fofoStoreRepository
1891
				.selectGroupByBrandAccesoriesWarehousePartnerSale(new ArrayList<>(fofoIds));
1892
 
1893
		model.addAttribute("accessoriesBrandSales", accessoriesBrandSales);
1894
		return "accessories-brand-wise-report";
1895
	}
1896
 
1897
	@RequestMapping(value = "/getMobileLMSGraph", method = RequestMethod.GET)
28461 tejbeer 1898
	public String getMobileLMSGraph(HttpServletRequest request, @RequestParam(required = false) int warehouseId,
28451 tejbeer 1899
			@RequestParam(required = false) LocalDate date, @RequestParam List<Integer> fofoIds, Model model)
1900
			throws Exception {
1901
		Map<Integer, List<Integer>> warehouseIdFofoIdMap = fofoStoreRepository
1902
				.selectActivePartnersByRetailerIds(new ArrayList<>(fofoIds)).stream().collect(Collectors.groupingBy(
1903
						FofoStore::getWarehouseId, Collectors.mapping(FofoStore::getId, Collectors.toList())));
1904
 
1905
		ChartModel cm;
1906
		if (warehouseId != 0) {
28468 tejbeer 1907
			cm = adminUser.getBrandWiseLms(Arrays.asList(warehouseId),
28451 tejbeer 1908
					fofoIds.stream().map(x -> x).collect(Collectors.toList()), date);
1909
		} else {
28468 tejbeer 1910
			cm = adminUser.getBrandWiseLms(new ArrayList<>(warehouseIdFofoIdMap.keySet()),
28451 tejbeer 1911
					fofoIds.stream().map(x -> x).collect(Collectors.toList()), date);
1912
 
1913
		}
1914
 
1915
		LOGGER.info("chartMap" + gson.toJson(cm));
1916
		model.addAttribute("chartMap", gson.toJson(cm));
1917
		return "brand-wise-mobile-lms-chart";
1918
	}
1919
 
28461 tejbeer 1920
	@RequestMapping(value = "/getMobileLMSFilter", method = RequestMethod.GET)
1921
	public String getMobileLMSFilter(HttpServletRequest request,
1922
			@RequestParam(required = false, defaultValue = "0") int warehouseId,
1923
			@RequestParam(required = false) LocalDate date, Model model) throws Exception {
1924
 
1925
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1926
		String email = loginDetails.getEmailId();
28468 tejbeer 1927
		Map<String, Object> map = adminUser.getFilter(warehouseId, email, date);
28461 tejbeer 1928
		model.addAttribute("warehouseId", warehouseId);
1929
		model.addAllAttributes(map);
1930
 
1931
		return "chart-filter-lms";
1932
	}
1933
 
1934
	@RequestMapping(value = "/getMobileLMPFilter", method = RequestMethod.GET)
1935
	public String getMobileLMPFilter(HttpServletRequest request,
1936
			@RequestParam(required = false, defaultValue = "0") int warehouseId,
1937
			@RequestParam(required = false) LocalDate date, Model model) throws Exception {
1938
 
1939
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1940
		String email = loginDetails.getEmailId();
28468 tejbeer 1941
		Map<String, Object> map = adminUser.getFilter(warehouseId, email, date);
28461 tejbeer 1942
		model.addAttribute("warehouseId", warehouseId);
1943
		model.addAllAttributes(map);
1944
 
1945
		return "chart-filter-lmp";
1946
	}
1947
 
1948
	@RequestMapping(value = "/getMobileLMPGraph", method = RequestMethod.GET)
1949
	public String getMobileLMPGraph(HttpServletRequest request, @RequestParam(required = false) int warehouseId,
1950
			@RequestParam(required = false) LocalDate date, @RequestParam List<Integer> fofoIds, Model model)
1951
			throws Exception {
1952
		Map<Integer, List<Integer>> warehouseIdFofoIdMap = fofoStoreRepository
1953
				.selectActivePartnersByRetailerIds(new ArrayList<>(fofoIds)).stream().collect(Collectors.groupingBy(
1954
						FofoStore::getWarehouseId, Collectors.mapping(FofoStore::getId, Collectors.toList())));
1955
 
1956
		ChartModel cm;
1957
		if (warehouseId != 0) {
28468 tejbeer 1958
			cm = adminUser.getBrandWiseLmp(Arrays.asList(warehouseId),
28461 tejbeer 1959
					fofoIds.stream().map(x -> x).collect(Collectors.toList()), date);
1960
		} else {
28468 tejbeer 1961
			cm = adminUser.getBrandWiseLmp(new ArrayList<>(warehouseIdFofoIdMap.keySet()),
28461 tejbeer 1962
					fofoIds.stream().map(x -> x).collect(Collectors.toList()), date);
1963
 
1964
		}
1965
 
1966
		LOGGER.info("chartMap" + gson.toJson(cm));
1967
		model.addAttribute("chartMap", gson.toJson(cm));
1968
		return "brand-wise-mobile-lmp-chart";
1969
	}
1970
 
28825 tejbeer 1971
	@RequestMapping(value = "/getActivatedModelWarehouseWise", method = RequestMethod.GET)
1972
	public String getActivatedModelWarehouseWise(HttpServletRequest request, Model model, @RequestParam String brand)
1973
			throws Exception {
1974
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1975
		List<Integer> fofoIds = getFofoIds(loginDetails);
1976
		List<WarehouseWiseActivatedModel> warehouseWiseActivatedModels = activatedImeiRepository
1977
				.selectActivatedModelGroupByWarehouse(brand, fofoIds);
1978
		Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
1979
 
1980
		List<DBObject> mobileBrands = mongoClient.getAllBrandsToDisplay(3);
1981
 
1982
		List<String> brands = mobileBrands.stream().map(x -> (String) x.get("name")).collect(Collectors.toList());
1983
		LOGGER.info("brands" + brands.add("Redmi"));
1984
 
1985
		model.addAttribute("warehouseWiseActivatedModels", warehouseWiseActivatedModels);
1986
		model.addAttribute("warehouseMap", warehouseMap);
1987
		model.addAttribute("brands", brands);
1988
		model.addAttribute("selectedbrand", brand);
1989
		return "warehousewise_activated_model";
1990
	}
1991
 
1992
	@RequestMapping(value = "/getActivatedModelByBrand", method = RequestMethod.GET)
1993
	public String getActivatedModelByBrand(HttpServletRequest request, Model model) throws Exception {
1994
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1995
		List<Integer> fofoIds = getFofoIds(loginDetails);
1996
		List<BrandWiseActivatedModel> activatedModels = activatedImeiRepository
1997
				.selectActivatedModelGroupByBrand(new ArrayList<>(fofoIds));
1998
		model.addAttribute("activatedModels", activatedModels);
1999
		return "activation-brandwise-report";
2000
	}
2001
 
2002
	@RequestMapping(value = "/getWarehouseBrandWiseItemActivatedModel", method = RequestMethod.GET)
2003
	public String getWarehouseBrandWiseItemActivatedModel(HttpServletRequest request, Model model,
2004
			@RequestParam List<Integer> warehouseId, @RequestParam String brand) throws Exception {
2005
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
2006
		List<Integer> fofoIds = getFofoIds(loginDetails);
2007
 
2008
		Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
2009
		List<WarehouseBrandWiseItemActivatedModel> activatedItems = activatedImeiRepository
2010
				.selectWarehouseBrandActivatedItem(warehouseId, brand, fofoIds);
2011
		model.addAttribute("warehouseMap", warehouseMap);
2012
		model.addAttribute("activatedItems", activatedItems);
2013
		return "warehouse-activated-itemwise-model";
2014
 
2015
	}
2016
 
2017
	@RequestMapping(value = "/getActivatedImeiUpdationDate", method = RequestMethod.GET)
2018
	public String getActivatedImeiUpdationDate(HttpServletRequest request, Model model) throws Exception {
2019
 
2020
		Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
2021
 
2022
		List<ActivationImeiUpdationModel> activationImeiUpdations = activatedImeiRepository
2023
				.selectActivatedUpdationDate();
2024
		model.addAttribute("warehouseMap", warehouseMap);
2025
		model.addAttribute("activationImeiUpdations", activationImeiUpdations);
2026
		return "activation-updation-timestamp";
2027
 
2028
	}
2029
 
2030
	private List<Integer> getFofoIds(LoginDetails loginDetails) throws ProfitMandiBusinessException {
2031
		String email = loginDetails.getEmailId();
2032
 
2033
		AuthUser authUser = authRepository.selectByEmailOrMobile(email);
2034
		Map<String, Set<Integer>> storeGuyMap = csService.getAuthUserPartnerIdMapping();
2035
 
2036
		Set<Integer> fofoIds = storeGuyMap.get(authUser.getEmailId());
2037
		if (emails.contains(authUser.getEmailId())) {
2038
			fofoIds = storeGuyMap.get("tarun.verma@smartdukaan.com");
2039
			LOGGER.info("fofoIds" + fofoIds);
2040
		}
2041
 
2042
		if (fofoIds == null) {
2043
			List<Position> positions1 = positionRepository.selectAll(authUser.getId());
2044
			if (positions1.stream().filter(x -> x.getCategoryId() == ProfitMandiConstants.TICKET_CATEGORY_MASTER)
2045
					.count() > 0) {
2046
				fofoIds = csService.getPositionCustomRetailerMap(positions1).values().stream().flatMap(x -> x.stream())
2047
						.map(x -> x.getPartnerId()).collect(Collectors.toSet());
2048
			}
2049
		}
2050
		return new ArrayList<>(fofoIds);
2051
	}
2052
 
21615 kshitij.so 2053
}