Subversion Repositories SmartDukaan

Rev

Rev 29580 | Rev 29707 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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