Subversion Repositories SmartDukaan

Rev

Rev 27638 | Rev 27660 | 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.ObjectInputStream;
8
import java.io.ObjectOutputStream;
24288 amit.gupta 9
import java.time.LocalDate;
24276 amit.gupta 10
import java.time.LocalDateTime;
24880 govind 11
import java.time.LocalTime;
27555 tejbeer 12
import java.time.YearMonth;
25649 tejbeer 13
import java.time.ZoneOffset;
27474 tejbeer 14
import java.time.format.DateTimeFormatter;
24339 amit.gupta 15
import java.util.ArrayList;
26027 amit.gupta 16
import java.util.Arrays;
26011 amit.gupta 17
import java.util.HashMap;
26090 amit.gupta 18
import java.util.HashSet;
25136 amit.gupta 19
import java.util.LinkedHashMap;
23884 amit.gupta 20
import java.util.List;
24880 govind 21
import java.util.Map;
26055 tejbeer 22
import java.util.Map.Entry;
26071 tejbeer 23
import java.util.Optional;
26090 amit.gupta 24
import java.util.Set;
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;
25677 amit.gupta 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;
26065 amit.gupta 49
import com.spice.profitmandi.common.enumuration.ReporticoProject;
22481 ashik.ali 50
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
27636 tejbeer 51
import com.spice.profitmandi.common.model.ActivateItemModel;
25677 amit.gupta 52
import com.spice.profitmandi.common.model.BrandStockPrice;
26055 tejbeer 53
import com.spice.profitmandi.common.model.ChartModel;
26005 amit.gupta 54
import com.spice.profitmandi.common.model.CustomRetailer;
26055 tejbeer 55
import com.spice.profitmandi.common.model.DataModel;
56
import com.spice.profitmandi.common.model.DatasetModel;
57
import com.spice.profitmandi.common.model.LegendModel;
25649 tejbeer 58
import com.spice.profitmandi.common.model.Notification;
26055 tejbeer 59
import com.spice.profitmandi.common.model.OptionsModel;
24203 amit.gupta 60
import com.spice.profitmandi.common.model.ProfitMandiConstants;
26055 tejbeer 61
import com.spice.profitmandi.common.model.TitleModel;
25651 tejbeer 62
import com.spice.profitmandi.common.web.util.ResponseSender;
25649 tejbeer 63
import com.spice.profitmandi.dao.Interface.Campaign;
26011 amit.gupta 64
import com.spice.profitmandi.dao.entity.auth.AuthUser;
65
import com.spice.profitmandi.dao.entity.auth.Menu;
27355 tejbeer 66
import com.spice.profitmandi.dao.entity.catalog.Item;
26674 tejbeer 67
import com.spice.profitmandi.dao.entity.catalog.Offer;
68
import com.spice.profitmandi.dao.entity.catalog.OfferPartner;
69
import com.spice.profitmandi.dao.entity.catalog.Offermargin;
27636 tejbeer 70
import com.spice.profitmandi.dao.entity.catalog.TagListing;
26011 amit.gupta 71
import com.spice.profitmandi.dao.entity.cs.Position;
25651 tejbeer 72
import com.spice.profitmandi.dao.entity.dtr.Document;
25649 tejbeer 73
import com.spice.profitmandi.dao.entity.dtr.NotificationCampaign;
22654 ashik.ali 74
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
27636 tejbeer 75
import com.spice.profitmandi.dao.entity.fofo.InventoryItem;
24288 amit.gupta 76
import com.spice.profitmandi.dao.entity.fofo.PartnerDailyInvestment;
25214 amit.gupta 77
import com.spice.profitmandi.dao.entity.fofo.PartnerTargetDetails;
25566 tejbeer 78
import com.spice.profitmandi.dao.entity.fofo.PartnerType;
27529 tejbeer 79
import com.spice.profitmandi.dao.entity.inventory.ReporticoCacheTable;
27586 tejbeer 80
import com.spice.profitmandi.dao.entity.transaction.Order;
26418 tejbeer 81
import com.spice.profitmandi.dao.entity.user.Lead;
27355 tejbeer 82
import com.spice.profitmandi.dao.enumuration.catalog.ItemCriteriaType;
26024 amit.gupta 83
import com.spice.profitmandi.dao.enumuration.cs.EscalationType;
26418 tejbeer 84
import com.spice.profitmandi.dao.enumuration.dtr.LeadStatus;
27628 tejbeer 85
import com.spice.profitmandi.dao.model.BrandWisePartnerSaleModel;
26674 tejbeer 86
import com.spice.profitmandi.dao.model.CreateOfferRequest;
27640 tejbeer 87
import com.spice.profitmandi.dao.model.InStockBrandModel;
27355 tejbeer 88
import com.spice.profitmandi.dao.model.ItemTypeParams;
27579 tejbeer 89
import com.spice.profitmandi.dao.model.ItemWiseTertiaryModel;
27474 tejbeer 90
import com.spice.profitmandi.dao.model.MonthSaleModel;
26418 tejbeer 91
import com.spice.profitmandi.dao.model.PartnerDetailModel;
27599 tejbeer 92
import com.spice.profitmandi.dao.model.PartnerPendingIndentItemModel;
25649 tejbeer 93
import com.spice.profitmandi.dao.model.SimpleCampaign;
94
import com.spice.profitmandi.dao.model.SimpleCampaignParams;
27556 tejbeer 95
import com.spice.profitmandi.dao.model.WarehouseBrandWiseItemSaleModel;
27628 tejbeer 96
import com.spice.profitmandi.dao.model.WarehouseWiseBrandSaleModel;
27591 tejbeer 97
import com.spice.profitmandi.dao.model.WarehouseWiseBrandStockModel;
27509 tejbeer 98
import com.spice.profitmandi.dao.model.WarehouseWiseStockModel;
99
import com.spice.profitmandi.dao.model.WarehouseWiseitemStockModel;
25976 amit.gupta 100
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
26011 amit.gupta 101
import com.spice.profitmandi.dao.repository.auth.MenuCategoryRepository;
102
import com.spice.profitmandi.dao.repository.auth.MenuRepository;
27355 tejbeer 103
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
26588 tejbeer 104
import com.spice.profitmandi.dao.repository.catalog.OfferMarginRepository;
105
import com.spice.profitmandi.dao.repository.catalog.OfferPartnerRepository;
106
import com.spice.profitmandi.dao.repository.catalog.OfferRepository;
27632 tejbeer 107
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
26090 amit.gupta 108
import com.spice.profitmandi.dao.repository.cs.CsService;
26418 tejbeer 109
import com.spice.profitmandi.dao.repository.cs.PartnersPositionRepository;
26011 amit.gupta 110
import com.spice.profitmandi.dao.repository.cs.PositionRepository;
111
import com.spice.profitmandi.dao.repository.cs.TicketCategoryRepository;
26418 tejbeer 112
import com.spice.profitmandi.dao.repository.cs.TicketRepository;
25651 tejbeer 113
import com.spice.profitmandi.dao.repository.dtr.DocumentRepository;
22481 ashik.ali 114
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
26418 tejbeer 115
import com.spice.profitmandi.dao.repository.dtr.LeadRepository;
24996 amit.gupta 116
import com.spice.profitmandi.dao.repository.dtr.Mongo;
25649 tejbeer 117
import com.spice.profitmandi.dao.repository.dtr.NotificationCampaignRepository;
118
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
119
import com.spice.profitmandi.dao.repository.dtr.UserCampaignRepository;
24203 amit.gupta 120
import com.spice.profitmandi.dao.repository.fofo.CurrentInventorySnapshotRepository;
24880 govind 121
import com.spice.profitmandi.dao.repository.fofo.FofoOrderItemRepository;
26071 tejbeer 122
import com.spice.profitmandi.dao.repository.fofo.FofoOrderRepository;
25649 tejbeer 123
import com.spice.profitmandi.dao.repository.fofo.HygieneDataRepository;
26234 amit.gupta 124
import com.spice.profitmandi.dao.repository.fofo.InventoryItemRepository;
24288 amit.gupta 125
import com.spice.profitmandi.dao.repository.fofo.PartnerDailyInvestmentRepository;
25214 amit.gupta 126
import com.spice.profitmandi.dao.repository.fofo.PartnerTargetRepository;
27474 tejbeer 127
import com.spice.profitmandi.dao.repository.fofo.PartnerTypeChangeRepository;
25566 tejbeer 128
import com.spice.profitmandi.dao.repository.fofo.PartnerTypeChangeService;
27529 tejbeer 129
import com.spice.profitmandi.dao.repository.inventory.ReporticoCacheTableRepository;
130
import com.spice.profitmandi.dao.repository.inventory.SaholicInventoryCISRepository;
27509 tejbeer 131
import com.spice.profitmandi.dao.repository.inventory.SaholicInventorySnapshotRepository;
24336 amit.gupta 132
import com.spice.profitmandi.service.PartnerInvestmentService;
26460 amit.gupta 133
import com.spice.profitmandi.service.PartnerStatsService;
23844 amit.gupta 134
import com.spice.profitmandi.service.authentication.RoleManager;
25677 amit.gupta 135
import com.spice.profitmandi.service.inventory.InventoryService;
27586 tejbeer 136
import com.spice.profitmandi.service.transaction.TransactionService;
26005 amit.gupta 137
import com.spice.profitmandi.service.user.RetailerService;
22481 ashik.ali 138
import com.spice.profitmandi.web.model.LoginDetails;
139
import com.spice.profitmandi.web.util.CookiesProcessor;
27529 tejbeer 140
import com.spice.profitmandi.web.util.MVCResponseSender;
22481 ashik.ali 141
 
21615 kshitij.so 142
@Controller
25222 amit.gupta 143
@Transactional(rollbackOn = Throwable.class)
21615 kshitij.so 144
public class DashboardController {
23923 amit.gupta 145
 
26460 amit.gupta 146
	private static final double ONE_LAC = 1 * 1000 * 100;
147
	private static final double TWO_LAC = 2 * 1000 * 100;
148
	private static final double FOUR_LAC = 4 * 1000 * 100;
149
 
23379 ashik.ali 150
	@Value("${web.api.host}")
151
	private String webApiHost;
23923 amit.gupta 152
 
24072 amit.gupta 153
	@Value("${web.api.scheme}")
154
	private String webApiScheme;
24288 amit.gupta 155
 
24078 amit.gupta 156
	@Value("${web.api.root}")
157
	private String webApiRoot;
158
 
23379 ashik.ali 159
	@Value("${web.api.port}")
160
	private int webApiPort;
21615 kshitij.so 161
 
22481 ashik.ali 162
	@Autowired
22927 ashik.ali 163
	private CookiesProcessor cookiesProcessor;
26468 amit.gupta 164
 
26460 amit.gupta 165
	@Autowired
166
	private PartnerStatsService partnerStatsService;
23923 amit.gupta 167
 
23568 govind 168
	@Autowired
26011 amit.gupta 169
	private MenuRepository menuRepository;
26012 amit.gupta 170
 
26011 amit.gupta 171
	@Autowired
172
	private MenuCategoryRepository menuCategoryRepository;
173
 
174
	@Autowired
26090 amit.gupta 175
	private CsService csService;
176
 
177
	@Autowired
25214 amit.gupta 178
	private PartnerTargetRepository partnerTargetRepository;
179
 
180
	@Autowired
25653 amit.gupta 181
	private ResponseSender<?> responseSender;
26012 amit.gupta 182
 
26005 amit.gupta 183
	@Autowired
184
	RetailerService retailerService;
25214 amit.gupta 185
 
186
	@Autowired
23786 amit.gupta 187
	private RoleManager roleManager;
23923 amit.gupta 188
 
23838 ashik.ali 189
	@Autowired
190
	private FofoStoreRepository fofoStoreRepository;
23884 amit.gupta 191
 
192
	@Autowired
24880 govind 193
	private PartnerDailyInvestmentRepository partnerDailyInvestmentRepository;
23923 amit.gupta 194
 
23884 amit.gupta 195
	@Autowired
24880 govind 196
	private PartnerInvestmentService partnerInvestmentService;
24288 amit.gupta 197
 
23884 amit.gupta 198
	@Autowired
25653 amit.gupta 199
	DocumentRepository documentRepository;
26236 amit.gupta 200
 
26234 amit.gupta 201
	@Autowired
202
	InventoryItemRepository inventoryItemRepository;
25683 tejbeer 203
 
25677 amit.gupta 204
	@Autowired
205
	InventoryService inventoryService;
23923 amit.gupta 206
 
23884 amit.gupta 207
	@Autowired
24203 amit.gupta 208
	private CurrentInventorySnapshotRepository currentInventorySnapshotRepository;
209
 
24880 govind 210
	@Autowired
211
	private FofoOrderItemRepository fofoOrderItemRepository;
26012 amit.gupta 212
 
26011 amit.gupta 213
	@Autowired
214
	private TicketCategoryRepository ticketCategoryRepository;
24880 govind 215
 
216
	@Autowired
25566 tejbeer 217
	private PartnerTypeChangeService partnerTypeChangeService;
25136 amit.gupta 218
 
24996 amit.gupta 219
	@Autowired
25649 tejbeer 220
	private HygieneDataRepository hygieneDataRepository;
221
 
222
	@Autowired
223
	private UserCampaignRepository userCampaignRepository;
26012 amit.gupta 224
 
26011 amit.gupta 225
	@Autowired
226
	private PositionRepository positionRepository;
27474 tejbeer 227
	@Autowired
228
	private PartnerTypeChangeRepository partnerTypeChangeRepository;
25649 tejbeer 229
 
230
	@Autowired
26418 tejbeer 231
	private PartnersPositionRepository partnerPositionRepository;
232
 
233
	@Autowired
25649 tejbeer 234
	private UserAccountRepository userAccountRepository;
235
 
236
	@Autowired
237
	private NotificationCampaignRepository notificationCampaignRepository;
238
 
239
	@Autowired
24996 amit.gupta 240
	private Mongo mongoClient;
26012 amit.gupta 241
 
25976 amit.gupta 242
	@Autowired
243
	private AuthRepository authRepository;
24880 govind 244
 
25649 tejbeer 245
	@Autowired
26071 tejbeer 246
	private FofoOrderRepository fofoOrderRepository;
247
 
248
	@Autowired
25649 tejbeer 249
	private Gson gson;
250
 
26418 tejbeer 251
	@Autowired
252
	TicketRepository ticketRepository;
253
 
254
	@Autowired
255
	private LeadRepository leadRepository;
256
 
26588 tejbeer 257
	@Autowired
258
	private OfferRepository offerRepository;
259
 
260
	@Autowired
261
	private OfferPartnerRepository offerPartnerRepository;
262
 
263
	@Autowired
264
	private OfferMarginRepository offerMarginRepository;
27529 tejbeer 265
 
27355 tejbeer 266
	@Autowired
267
	private ItemRepository itemRepository;
26588 tejbeer 268
 
27509 tejbeer 269
	@Autowired
270
	private SaholicInventorySnapshotRepository saholicInventorySnapshotRepository;
27529 tejbeer 271
 
272
	@Autowired
273
	private SaholicInventoryCISRepository saholicInventoryCISRepository;
274
 
275
	@Autowired
276
	private MVCResponseSender mvcResponseSender;
277
 
278
	@Autowired
279
	private ReporticoCacheTableRepository reporticoCacheTableRepository;
280
 
27586 tejbeer 281
	@Autowired
282
	private TransactionService transactionService;
283
 
27632 tejbeer 284
	@Autowired
285
	private TagListingRepository tagListingRepository;
286
 
23568 govind 287
	private static final Logger LOGGER = LogManager.getLogger(DashboardController.class);
23923 amit.gupta 288
 
25136 amit.gupta 289
	@RequestMapping(value = "/12dashboard34", method = RequestMethod.GET)
25726 amit.gupta 290
	public String dashboard1(HttpServletRequest request, Model model, @RequestParam int fofoId) throws Exception {
25740 amit.gupta 291
		boolean isAdmin = false;
292
		model.addAttribute("isAdmin", isAdmin);
293
 
294
		model.addAttribute("webApiHost", webApiHost);
295
		model.addAttribute("webApiPort", webApiPort);
296
		model.addAttribute("webApiScheme", webApiScheme);
297
		model.addAttribute("webApiRoot", webApiRoot);
298
		if (isAdmin) {
299
			return "dashboard1";
26236 amit.gupta 300
		}
301
 
302
		FofoStore fofoStore = null;
26234 amit.gupta 303
		try {
304
			CustomRetailer customRetailer = retailerService.getFofoRetailer(fofoId);
305
			fofoStore = fofoStoreRepository.selectByRetailerId(fofoId);
306
			if (!fofoStore.isActive()) {
307
				return "redirect:/login";
308
			}
25740 amit.gupta 309
 
26234 amit.gupta 310
			PartnerType partnerType = partnerTypeChangeService.getTypeOnDate(fofoStore.getId(), LocalDate.now());
311
			model.addAttribute("partnerType", partnerType);
312
			model.addAttribute("partnerTypeImage", PartnerType.imageMap.get(partnerType));
313
			model.addAttribute("fofoStore", customRetailer);
314
			model.addAttribute("partnerType", partnerType);
315
			model.addAttribute("hasGift", hasGift(fofoId));
316
			model.addAttribute("giftItemId", ProfitMandiConstants.GIFT_ID);
25740 amit.gupta 317
 
27628 tejbeer 318
			// model.addAttribute("brandStockPrices", this.getBrandStockPrices(fofoId));
26234 amit.gupta 319
			model.addAttribute("salesMap", this.getSales(fofoId));
320
			model.addAttribute("activatedImeis", inventoryItemRepository.selectCountByActivatedNotSold(fofoId));
321
			// this.setInvestments
322
			//
323
			model.addAttribute("investments", this.getInvestments(fofoId));
324
			model.addAttribute("isInvestmentOk",
325
					partnerInvestmentService.isInvestmentOk(fofoId, 10, ProfitMandiConstants.CUTOFF_INVESTMENT));
326
		} catch (ProfitMandiBusinessException e) {
327
			LOGGER.error("FofoStore Code not found of fofoId {}", fofoId);
25740 amit.gupta 328
 
329
		}
330
 
331
		LocalDateTime currentMonthStart = LocalDateTime.now().withDayOfMonth(1);
332
		LocalDateTime currentMonthEnd = currentMonthStart.plusMonths(1).withDayOfMonth(1);
26012 amit.gupta 333
		double currentMonthRating = hygieneDataRepository.selectRatingAvg(fofoId, currentMonthStart, currentMonthEnd)
334
				/ 2;
335
		double lastMonthRating = hygieneDataRepository.selectRatingAvg(fofoId, currentMonthStart, currentMonthEnd) / 2;
336
		double ratingTillDate = hygieneDataRepository.selectRatingAvg(fofoId, currentMonthStart, currentMonthEnd) / 2;
25740 amit.gupta 337
		model.addAttribute("currentMonthRating", (float) Math.round(currentMonthRating * 10) / 10);
338
		model.addAttribute("lastMonthRating", (float) Math.round(lastMonthRating * 10) / 10);
339
		model.addAttribute("ratingTillDate", (float) Math.round(ratingTillDate * 10) / 10);
340
 
26012 amit.gupta 341
		long hygieneCount = hygieneDataRepository.selectHygieneCount(fofoId, true, currentMonthStart, currentMonthEnd);
342
 
343
		long invalidHygieneCount = hygieneDataRepository.selectHygieneCount(fofoId, false, currentMonthStart,
25740 amit.gupta 344
				currentMonthEnd);
345
		if (hygieneCount == 0 && invalidHygieneCount == 0) {
346
			invalidHygieneCount = 1;
347
		}
348
		model.addAttribute("hygienePercentage", (hygieneCount * 100) / (invalidHygieneCount + hygieneCount));
26460 amit.gupta 349
 
25740 amit.gupta 350
		model.addAttribute("monthDays", LocalDate.now().minusDays(1).lengthOfMonth());
351
		model.addAttribute("dayOfMonth", LocalDate.now().minusDays(1).getDayOfMonth());
352
		return "12dashboard34";
25136 amit.gupta 353
	}
354
 
355
	private Map<String, Object> getInvestments(int fofoId) throws Exception {
356
		Map<String, Object> investments = new LinkedHashMap<>();
26233 amit.gupta 357
		PartnerDailyInvestment investment = partnerInvestmentService.getInvestment(fofoId, 0);
25649 tejbeer 358
		LocalDate currentMonthStart = LocalDate.now().withDayOfMonth(1);
25136 amit.gupta 359
		LocalDate yesterDate = LocalDate.now().minusDays(1);
360
		PartnerDailyInvestment yesterdayInvestment = partnerDailyInvestmentRepository.select(fofoId, yesterDate);
361
		if (yesterdayInvestment == null) {
362
			yesterdayInvestment = new PartnerDailyInvestment();
363
		}
364
 
365
		List<PartnerDailyInvestment> currentMonthInvestments = partnerDailyInvestmentRepository.selectAll(fofoId,
366
				currentMonthStart, currentMonthStart.withDayOfMonth(currentMonthStart.lengthOfMonth()));
367
 
25140 amit.gupta 368
		long okInvestmentDays = currentMonthInvestments.stream().filter(x -> x.getShortPercentage() <= 10)
25136 amit.gupta 369
				.collect(Collectors.counting());
25140 amit.gupta 370
		investments.put("today", investment.getTotalInvestment());
371
		investments.put("investment", investment);
372
		investments.put("inStock", investment.getInStockAmount());
25182 amit.gupta 373
		investments.put("minimum", investment.getMinInvestmentString());
25140 amit.gupta 374
		investments.put("short", investment.getShortPercentage());
26267 amit.gupta 375
		investments.put("activated_stock", investment.getActivatedStockAmount());
25649 tejbeer 376
		investments.put("okDays", okInvestmentDays);
25136 amit.gupta 377
		return investments;
378
	}
379
 
25221 amit.gupta 380
	private Map<String, Object> getSales(int fofoId) {
25653 amit.gupta 381
 
25221 amit.gupta 382
		Map<String, Object> salesMap = new LinkedHashMap<>();
25140 amit.gupta 383
		LocalDateTime curDate = LocalDate.now().atStartOfDay();
25214 amit.gupta 384
		int monthLength = LocalDate.now().lengthOfMonth();
26012 amit.gupta 385
		Double todaySale = fofoOrderItemRepository
27084 amit.gupta 386
				.selectSumMopGroupByRetailer(curDate, curDate.with(LocalTime.MAX), fofoId, false).get(fofoId);
26012 amit.gupta 387
		Double mtdSale = fofoOrderItemRepository
27084 amit.gupta 388
				.selectSumMopGroupByRetailer(curDate.withDayOfMonth(1), curDate.with(LocalTime.MAX), fofoId, false)
26012 amit.gupta 389
				.get(fofoId);
27352 tejbeer 390
		Double lmtdSale = fofoOrderItemRepository.selectSumMopGroupByRetailer(curDate.withDayOfMonth(1).minusMonths(1),
391
				curDate.with(LocalTime.MAX).minusMonths(1), fofoId, false).get(fofoId);
25214 amit.gupta 392
 
393
		List<PartnerTargetDetails> partnerTargetDetails = partnerTargetRepository
394
				.selectAllGeEqAndLeEqStartDateAndEndDate(LocalDateTime.now());
25544 amit.gupta 395
		if (partnerTargetDetails.isEmpty()) {
25372 tejbeer 396
			partnerTargetDetails = partnerTargetRepository
25653 amit.gupta 397
					.selectAllGeEqAndLeEqStartDateAndEndDate(LocalDateTime.now().minusMonths(3));
25372 tejbeer 398
		}
25214 amit.gupta 399
 
25653 amit.gupta 400
		PartnerType partnerType = partnerTypeChangeService.getTypeOnDate(fofoId, LocalDate.now());
25214 amit.gupta 401
 
25664 amit.gupta 402
		int currentRate = (int) (mtdSale / curDate.getDayOfMonth());
25653 amit.gupta 403
 
404
		salesMap.put("requiredType", partnerType.next());
405
		float reqdAmount = partnerTypeChangeService.getMinimumAmount(partnerType.next());
406
		int requiredRate = (int) ((reqdAmount - mtdSale) / (monthLength - curDate.getDayOfMonth()));
407
		salesMap.put("requiredRate", requiredRate);
408
		salesMap.put("requiredTypeImage", PartnerType.imageMap.get(partnerType.next()));
409
 
25858 amit.gupta 410
		salesMap.put("todaySale", todaySale == null ? 0 : todaySale);
411
		salesMap.put("mtdSale", mtdSale == null ? 0 : mtdSale);
26012 amit.gupta 412
		salesMap.put("lmtdSale", lmtdSale == null ? 0 : lmtdSale);
26065 amit.gupta 413
 
27352 tejbeer 414
		PartnerType currentType = partnerTypeChangeService.getPartnerTypeByAmount(currentRate * monthLength);
25653 amit.gupta 415
		salesMap.put("currentRate", currentRate);
416
		salesMap.put("currentType", currentType);
417
		salesMap.put("currentTypeImage", PartnerType.imageMap.get(currentType));
25136 amit.gupta 418
		return salesMap;
419
	}
420
 
27474 tejbeer 421
	@RequestMapping(value = "/getMonthSale", method = RequestMethod.GET)
422
	public String getMonthsale(HttpServletRequest request, Model model) throws Exception {
423
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
424
		int fofoId = loginDetails.getFofoId();
425
		Map<Integer, MonthSaleModel> monthSaleMap = new HashMap<>();
426
		LocalDateTime curDate = LocalDate.now().atStartOfDay();
427
		int dayOfMonth = curDate.getDayOfMonth();
428
		for (int i = 1; i <= 6; i++) {
429
			LocalDateTime startOfMonth = curDate.withDayOfMonth(1).minusMonths(i);
27555 tejbeer 430
			int lengthOfMonth = YearMonth.from(startOfMonth).lengthOfMonth();
27474 tejbeer 431
			double monthSales = fofoOrderItemRepository.selectSumMopGroupByRetailer(startOfMonth,
432
					startOfMonth.plusMonths(1), loginDetails.getFofoId(), false).get(fofoId);
433
 
27574 tejbeer 434
			double mtdSales = fofoOrderItemRepository
435
					.selectSumMopGroupByRetailer(startOfMonth,
436
							startOfMonth.plusDays(Math.min(dayOfMonth, lengthOfMonth)), loginDetails.getFofoId(), false)
437
					.get(fofoId);
27474 tejbeer 438
 
439
			PartnerType partnerType = partnerTypeChangeService.getTypeOnDate(fofoId, startOfMonth.toLocalDate());
440
 
441
			MonthSaleModel ms = new MonthSaleModel();
442
			ms.setMtdSales(this.format((long) mtdSales));
443
			ms.setMonthlySales(this.format(((long) monthSales)));
444
			ms.setPartnerType(partnerType);
27476 tejbeer 445
			ms.setMonth(startOfMonth.format(DateTimeFormatter.ofPattern("MMM''uu")));
27474 tejbeer 446
			monthSaleMap.put(i, ms);
447
 
448
		}
449
		model.addAttribute("monthSales", monthSaleMap);
450
		return "monthSales";
451
	}
452
 
453
	private String format(long value) {
454
		String finalval = null;
455
 
456
		if (value >= 100000 && value < 10000000) {
457
			long reminder = value / 100000;
458
			long quitonent = value % 100000;
459
			finalval = reminder + "." + quitonent;
460
			String secondval = String.valueOf(quitonent);
461
			if (secondval.length() >= 2) {
462
				secondval = secondval.substring(0, 2);
463
				finalval = reminder + "." + secondval;
464
			}
465
			return String.valueOf(finalval) + " Lacs";
466
		} else if (value >= 1000 && value < 100000) {
467
			long reminder = value / 1000;
468
			long quitonent = value % 1000;
469
			finalval = reminder + "." + quitonent;
470
			String secondval = String.valueOf(quitonent);
471
			if (secondval.length() >= 2) {
472
				secondval = secondval.substring(0, 2);
473
				finalval = reminder + "." + secondval;
474
			}
475
			return String.valueOf(finalval) + " K";
476
		} else if (value >= 10000000 && value < 1000000000) {
477
			long reminder = value / 10000000;
478
			long quitonent = value % 10000000;
479
			finalval = reminder + "." + quitonent;
480
			String secondval = String.valueOf(quitonent);
481
			if (secondval.length() >= 2) {
482
				secondval = secondval.substring(0, 2);
483
				finalval = reminder + "." + secondval;
484
			}
485
			return String.valueOf(finalval) + " Cr";
486
		}
487
		return String.valueOf(finalval);
488
 
489
	}
490
 
25677 amit.gupta 491
	private List<BrandStockPrice> getBrandStockPrices(int fofoId) throws Exception {
492
		Map<String, BrandStockPrice> brandStockPricesMap = inventoryService.getBrandWiseStockValue(fofoId);
25175 amit.gupta 493
 
26309 amit.gupta 494
		List<DBObject> mobileBrands = mongoClient.getAllBrandsToDisplay(3);
25677 amit.gupta 495
		List<BrandStockPrice> brandStockPrices = new ArrayList<>();
496
 
497
		mobileBrands.stream().forEach(x -> {
498
			String brand = (String) x.get("name");
499
			if (brandStockPricesMap.containsKey(brand)) {
500
				BrandStockPrice brandStockPrice = brandStockPricesMap.get(brand);
501
				brandStockPrice.setBrandUrl((String) x.get("url"));
502
				brandStockPrice.setRank(((Double) x.get("rank")).intValue());
503
				brandStockPrices.add(brandStockPrice);
504
			}
505
		});
506
 
507
		return brandStockPrices.stream().filter(x -> x.getTotalQty() > 0).sorted((x, y) -> x.getRank() - y.getRank())
508
				.collect(Collectors.toList());
509
	}
510
 
21615 kshitij.so 511
	@RequestMapping(value = "/dashboard", method = RequestMethod.GET)
25653 amit.gupta 512
	public String dashboard(HttpServletRequest request, Model model) throws Exception {
22927 ashik.ali 513
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
26011 amit.gupta 514
		String email = loginDetails.getEmailId();
25180 amit.gupta 515
		boolean isAdmin = roleManager.isAdmin(loginDetails.getRoleIds());
516
		model.addAttribute("isAdmin", isAdmin);
23923 amit.gupta 517
 
25274 amit.gupta 518
		model.addAttribute("webApiHost", webApiHost);
519
		model.addAttribute("webApiPort", webApiPort);
520
		model.addAttribute("webApiScheme", webApiScheme);
25544 amit.gupta 521
		model.addAttribute("webApiRoot", webApiRoot);
25183 amit.gupta 522
		if (isAdmin) {
26011 amit.gupta 523
			return adminPanel(loginDetails.getFofoId(), email, model);
25180 amit.gupta 524
		} else {
25740 amit.gupta 525
			FofoStore fofoStore = null;
25180 amit.gupta 526
			try {
527
				fofoStore = fofoStoreRepository.selectByRetailerId(loginDetails.getFofoId());
25544 amit.gupta 528
				if (!fofoStore.isActive()) {
529
					return "redirect:/login";
530
				}
25649 tejbeer 531
 
25740 amit.gupta 532
				PartnerType partnerType = partnerTypeChangeService.getTypeOnDate(fofoStore.getId(), LocalDate.now());
25566 tejbeer 533
				model.addAttribute("partnerType", partnerType);
25653 amit.gupta 534
				model.addAttribute("partnerTypeImage", PartnerType.imageMap.get(partnerType));
25180 amit.gupta 535
				model.addAttribute("fofoStore", fofoStore);
25566 tejbeer 536
				model.addAttribute("partnerType", partnerType);
25180 amit.gupta 537
				model.addAttribute("hasGift", hasGift(loginDetails.getFofoId()));
538
				model.addAttribute("giftItemId", ProfitMandiConstants.GIFT_ID);
26222 tejbeer 539
				model.addAttribute("retailers", new JSONObject().append("code", fofoStore.getCode())
26162 amit.gupta 540
						.append("partnerId", fofoStore.getId()).toString());
26460 amit.gupta 541
				model.addAttribute("activatedImeis",
542
						inventoryItemRepository.selectCountByActivatedNotSold(loginDetails.getFofoId()));
26071 tejbeer 543
				LocalDateTime curDate = LocalDate.now().atStartOfDay();
544
				Map<Integer, Double> accesoriesmtdsale = fofoOrderRepository
545
						.selectSumSaleGroupByFofoIdsForMobileOrAccessories(loginDetails.getFofoId(),
546
								curDate.withDayOfMonth(1), curDate.with(LocalTime.MAX), Optional.of(false));
547
				LOGGER.info("accesoriesmtdsale" + accesoriesmtdsale);
548
				Double accesoriesStock = currentInventorySnapshotRepository
549
						.selectSumStockGroupByFofoIdsForMobileOrAccessories(loginDetails.getFofoId(),
550
								Optional.of(false))
551
						.get(loginDetails.getFofoId());
25180 amit.gupta 552
 
26071 tejbeer 553
				model.addAttribute("accesoriesStock", String.format("%.0f", accesoriesStock));
26065 amit.gupta 554
				model.addAttribute("brandStockPrices", this.getBrandStockPrices(loginDetails.getFofoId()));
25180 amit.gupta 555
				model.addAttribute("salesMap", this.getSales(loginDetails.getFofoId()));
26055 tejbeer 556
				ChartModel cm = this.getBrandChart(loginDetails.getFofoId());
557
 
558
				LOGGER.info("chartMap" + gson.toJson(cm));
559
				model.addAttribute("chartMap", gson.toJson(cm));
25544 amit.gupta 560
				// this.setInvestments
561
				//
25180 amit.gupta 562
				model.addAttribute("investments", this.getInvestments(loginDetails.getFofoId()));
25544 amit.gupta 563
				model.addAttribute("isInvestmentOk", partnerInvestmentService.isInvestmentOk(loginDetails.getFofoId(),
564
						10, ProfitMandiConstants.CUTOFF_INVESTMENT));
26460 amit.gupta 565
 
566
				// Hardcoded for valentine
567
				// Hardcoded for valentine
26588 tejbeer 568
 
26694 tejbeer 569
				List<Offer> offers = offerRepository.selectOfferByStatus(true);
26588 tejbeer 570
				if (!offers.isEmpty()) {
571
					List<CreateOfferRequest> cors = new ArrayList<>();
572
					for (Offer offer : offers) {
573
 
574
						List<OfferPartner> offerPartners = offerPartnerRepository.selectByOfferId(offer.getId());
575
 
576
						for (OfferPartner offerPartner : offerPartners) {
577
 
578
							if (offerPartner.getFofoId() == loginDetails.getFofoId()) {
27352 tejbeer 579
								/*
580
								 * if (LocalDateTime.now().isAfter(offer.getStartDateTime()) &&
581
								 * LocalDateTime.now().isBefore(offer.getEndDateTime())) {
582
								 */
27398 tejbeer 583
								int todayMonth = LocalDateTime.now().getMonthValue();
584
								if (todayMonth == offer.getStartDateTime().getMonthValue()
585
										|| todayMonth == offer.getEndDateTime().getMonthValue()) {
26674 tejbeer 586
									LocalDateTime cur = LocalDate.now().minusMonths(2).atStartOfDay();
26619 tejbeer 587
									LOGGER.info("value" + cur);
26588 tejbeer 588
									Map<Integer, Double> value = offerRepository.selectSumOfferByRetailer(
26675 tejbeer 589
											offer.getStartDateTime(), offer.getEndDateTime(), loginDetails.getFofoId(),
590
											offer, true);
26588 tejbeer 591
									CreateOfferRequest createOfferRequest = new CreateOfferRequest();
592
									List<Offermargin> offerMargins = offerMarginRepository
593
											.selectByOfferId(offer.getId());
594
									LOGGER.info("value" + offer.getId());
595
									LOGGER.info("value" + value);
596
									for (Offermargin om : offerMargins) {
26619 tejbeer 597
										if (value.get(loginDetails.getFofoId()) <= om.getValue()) {
26588 tejbeer 598
											createOfferRequest.setMargin(om.getMargin());
26694 tejbeer 599
											createOfferRequest.setValue(om.getValue());
26588 tejbeer 600
											createOfferRequest.setShortAmount(
601
													om.getValue() - value.get(loginDetails.getFofoId()));
26674 tejbeer 602
 
26588 tejbeer 603
											break;
604
										} else {
605
											createOfferRequest.setMargin(om.getMargin());
26675 tejbeer 606
 
26588 tejbeer 607
										}
608
 
609
									}
27360 tejbeer 610
									createOfferRequest.setId(offer.getId());
26588 tejbeer 611
 
612
									createOfferRequest.setName(offer.getName());
613
									createOfferRequest.setDescription(offer.getDescription());
614
									createOfferRequest.setTargetType(offer.getTargetType());
615
									createOfferRequest.setAmountType(offer.getAmountType());
26694 tejbeer 616
									createOfferRequest.setStartDateTime(offer.getStartDateTime().toLocalDate());
617
									createOfferRequest.setEndDateTime(offer.getEndDateTime().toLocalDate());
26588 tejbeer 618
									createOfferRequest.setTotalSale(value.get(loginDetails.getFofoId()));
27352 tejbeer 619
									createOfferRequest.setOfferMargin(offerMargins);
26588 tejbeer 620
									cors.add(createOfferRequest);
621
 
622
									model.addAttribute("sales", value.get(loginDetails.getFofoId()));
623
								}
624
							}
625
 
626
						}
26327 amit.gupta 627
					}
26588 tejbeer 628
					model.addAttribute("offers", cors);
629
 
26674 tejbeer 630
				}
26588 tejbeer 631
 
25180 amit.gupta 632
			} catch (ProfitMandiBusinessException e) {
633
				LOGGER.error("FofoStore Code not found of fofoId {}", loginDetails.getFofoId());
634
 
635
			}
22481 ashik.ali 636
		}
25649 tejbeer 637
 
638
		LocalDateTime currentMonthStart = LocalDateTime.now().withDayOfMonth(1);
25747 amit.gupta 639
		LocalDateTime lastMonthStart = currentMonthStart.minusMonths(1);
25653 amit.gupta 640
		LocalDateTime currentMonthEnd = currentMonthStart.plusMonths(1).withDayOfMonth(1);
641
		double currentMonthRating = hygieneDataRepository.selectRatingAvg(loginDetails.getFofoId(), currentMonthStart,
25677 amit.gupta 642
				currentMonthEnd) / 2;
25747 amit.gupta 643
		double lastMonthRating = hygieneDataRepository.selectRatingAvg(loginDetails.getFofoId(), lastMonthStart,
644
				currentMonthStart) / 2;
645
		double ratingTillDate = hygieneDataRepository.selectRatingAvg(loginDetails.getFofoId(), LocalDateTime.MIN,
25677 amit.gupta 646
				currentMonthEnd) / 2;
647
		model.addAttribute("currentMonthRating", (float) Math.round(currentMonthRating * 10) / 10);
648
		model.addAttribute("lastMonthRating", (float) Math.round(lastMonthRating * 10) / 10);
649
		model.addAttribute("ratingTillDate", (float) Math.round(ratingTillDate * 10) / 10);
25649 tejbeer 650
 
25653 amit.gupta 651
		long hygieneCount = hygieneDataRepository.selectHygieneCount(loginDetails.getFofoId(), true, currentMonthStart,
652
				currentMonthEnd);
25651 tejbeer 653
 
25653 amit.gupta 654
		long invalidHygieneCount = hygieneDataRepository.selectHygieneCount(loginDetails.getFofoId(), false,
655
				currentMonthStart, currentMonthEnd);
656
		if (hygieneCount == 0 && invalidHygieneCount == 0) {
657
			invalidHygieneCount = 1;
658
		}
659
		model.addAttribute("hygienePercentage", (hygieneCount * 100) / (invalidHygieneCount + hygieneCount));
25651 tejbeer 660
 
25197 amit.gupta 661
		model.addAttribute("monthDays", LocalDate.now().minusDays(1).lengthOfMonth());
662
		model.addAttribute("dayOfMonth", LocalDate.now().minusDays(1).getDayOfMonth());
27352 tejbeer 663
		if (loginDetails.isReadOnly()) {
27229 amit.gupta 664
			return "dashboard-readonly";
665
		} else {
666
			return "dashboard1";
667
		}
21615 kshitij.so 668
	}
23923 amit.gupta 669
 
27355 tejbeer 670
	@RequestMapping(value = "/getOfferMargins", method = RequestMethod.GET)
671
	public String getOfferMargins(HttpServletRequest request,
672
			@RequestParam(name = "offerId", defaultValue = "0") int offerId, Model model) throws Exception {
673
		Offer offer = offerRepository.selectById(offerId);
674
 
675
		LOGGER.info("offerId" + offer.getId());
676
 
677
		Map<Integer, Double> value = offerRepository.selectSumOfferByRetailer(offer.getStartDateTime(),
678
				offer.getEndDateTime(), 0, offer, true);
679
 
680
		LOGGER.info("value" + value);
681
		List<Offermargin> offerMargin = offerMarginRepository.selectByOfferId(offerId);
682
 
683
		ItemTypeParams scp = gson.fromJson(offer.getItemParam(), ItemTypeParams.class);
684
		if (offer.getItemCriteria().equals(ItemCriteriaType.Multiple_Brand)) {
685
			List<String> brands = scp.getBrands();
686
			model.addAttribute("brands", brands);
687
		}
688
		if (offer.getItemCriteria().equals(ItemCriteriaType.Item_Model)) {
689
			List<Integer> catalogIds = scp.getCatalogId();
690
			List<Item> newList = new ArrayList<>();
691
			Set<Integer> catalogId = new HashSet<>();
692
			List<Item> items = itemRepository.selectAllByCatalogIds(catalogIds.stream().collect(Collectors.toSet()));
693
			for (Item item : items) {
694
				if (catalogId.add(item.getCatalogItemId())) {
695
					newList.add(item);
696
				}
697
			}
698
			model.addAttribute("items", newList);
699
		}
700
 
701
		model.addAttribute("offerMargin", offerMargin);
702
		model.addAttribute("offer", offer);
703
 
704
		return "offer_margin_detail_partner";
705
 
706
	}
707
 
26055 tejbeer 708
	private ChartModel getBrandChart(int fofoId) {
709
 
710
		LocalDateTime curDate = LocalDate.now().atStartOfDay();
711
 
712
		LOGGER.info("cur Date" + curDate.withDayOfMonth(1));
713
 
714
		LOGGER.info("curDateYear" + curDate.with(LocalTime.MAX));
715
 
716
		Map<String, Double> brandwisesale = fofoOrderItemRepository
717
				.selectSumAmountGroupByBrand(curDate.withDayOfMonth(1), curDate.with(LocalTime.MAX), fofoId);
26244 tejbeer 718
 
719
		Map<Integer, Double> accesoriesmtdsale = fofoOrderRepository.selectSumSaleGroupByFofoIdsForMobileOrAccessories(
720
				fofoId, curDate.withDayOfMonth(1), curDate.with(LocalTime.MAX), Optional.of(false));
721
 
722
		LOGGER.info("accesoriesmtdsale" + accesoriesmtdsale);
723
 
26055 tejbeer 724
		LOGGER.info("brandwisesale" + brandwisesale);
725
 
726
		Map<String, Double> lmtdBrandWiseSale = fofoOrderItemRepository.selectSumAmountGroupByBrand(
727
				curDate.withDayOfMonth(1).minusMonths(1), curDate.with(LocalTime.MAX).minusMonths(1), fofoId);
728
 
26244 tejbeer 729
		Map<Integer, Double> accesorieslmtdsale = fofoOrderRepository.selectSumSaleGroupByFofoIdsForMobileOrAccessories(
730
				fofoId, curDate.withDayOfMonth(1).minusMonths(1), curDate.with(LocalTime.MAX).minusMonths(1),
731
				Optional.of(false));
732
		LOGGER.info("accesorieslmtdsale" + accesorieslmtdsale);
26055 tejbeer 733
		ChartModel cm = new ChartModel();
734
 
735
		List<String> labels = new ArrayList<>();
736
		labels.addAll(brandwisesale.keySet());
26244 tejbeer 737
		labels.add("accessories");
26055 tejbeer 738
		List<Double> values = new ArrayList<>();
739
		values.addAll(brandwisesale.values());
26244 tejbeer 740
		values.addAll(accesoriesmtdsale.values());
26055 tejbeer 741
 
742
		List<Double> lmtdValues = new ArrayList<>();
743
		lmtdValues.addAll(lmtdBrandWiseSale.values());
26244 tejbeer 744
		lmtdValues.addAll(accesorieslmtdsale.values());
26055 tejbeer 745
 
746
		DatasetModel dsm = new DatasetModel();
747
		dsm.setLabel("mtd sales");
748
 
749
		List<String> backgroundColor = new ArrayList<>();
750
		for (Entry<String, Double> bs : brandwisesale.entrySet()) {
751
			backgroundColor.add("#3e95cd");
752
		}
26244 tejbeer 753
		backgroundColor.add("#3e95cd");
26055 tejbeer 754
		dsm.setBackgroundColor(backgroundColor);
755
		dsm.setData(values);
756
 
757
		DatasetModel lmtddsm = new DatasetModel();
758
		lmtddsm.setLabel("lmtd sales");
759
 
760
		List<String> background = new ArrayList<>();
761
		for (Entry<String, Double> bs : lmtdBrandWiseSale.entrySet()) {
762
			background.add("#8e5ea2");
763
		}
26244 tejbeer 764
		background.add("#8e5ea2");
26055 tejbeer 765
		lmtddsm.setBackgroundColor(background);
766
		lmtddsm.setData(lmtdValues);
767
 
768
		List<DatasetModel> datasets = new ArrayList<>();
769
		datasets.add(dsm);
770
		datasets.add(lmtddsm);
771
 
772
		DataModel dm = new DataModel();
773
		dm.setDatasets(datasets);
774
		dm.setLabels(labels);
775
 
776
		LegendModel lm = new LegendModel();
777
		lm.setDisplay(true);
778
 
779
		TitleModel tm = new TitleModel();
780
		tm.setText("Brand Wise Sale Graph");
781
		tm.setDisplay(true);
782
 
783
		OptionsModel om = new OptionsModel();
784
		om.setLegend(lm);
785
		om.setTitle(tm);
786
 
787
		cm.setType("bar");
788
		cm.setData(dm);
789
		cm.setOptions(om);
790
 
791
		return cm;
792
 
793
	}
794
 
26418 tejbeer 795
	private String adminPanel(int fofoId, String email, Model model) throws Exception {
26022 amit.gupta 796
		List<Menu> menus = null;
26011 amit.gupta 797
		try {
798
			AuthUser authUser = authRepository.selectByEmailOrMobile(email);
799
			List<Position> positions = positionRepository.selectAll(authUser.getId());
27545 tejbeer 800
			Map<Integer, PartnerDetailModel> warehousePartnerDetailMap = null;
27628 tejbeer 801
			ReporticoCacheTable rctSaholic = null;
802
			ReporticoCacheTable rctPartneStat = null;
803
 
27509 tejbeer 804
			Map<Integer, WarehouseWiseStockModel> warehouseStockMap = new HashMap<>();
805
			Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
27539 tejbeer 806
			LinkedHashMap<Integer, String> wm = new LinkedHashMap<Integer, String>();
807
 
27591 tejbeer 808
			List<BrandWisePartnerSaleModel> partnersBrandSale = null;
27594 tejbeer 809
 
810
			List<BrandWisePartnerSaleModel> accessoriesBrandSales = null;
27539 tejbeer 811
			for (Map.Entry<Integer, String> entry : warehouseMap.entrySet()) {
812
				wm.put(entry.getKey(), entry.getValue());
813
			}
814
 
815
			wm.put(0, "Total Values");
816
			long stockValue = 0;
817
			long stockQty = 0;
818
			long pendingIndent = 0;
27542 tejbeer 819
			long tertiary = 0;
26418 tejbeer 820
			if (positions.size() > 0) {
27352 tejbeer 821
				if (positions.stream()
822
						.filter(x -> x.getEscalationType().equals(EscalationType.L3)
823
								|| x.getEscalationType().equals(EscalationType.L4)
824
								|| x.getEscalationType().equals(EscalationType.L5))
825
						.count() > 0) {
26418 tejbeer 826
 
27556 tejbeer 827
					List<WarehouseWiseStockModel> warehouseStocks = saholicInventoryCISRepository
828
							.selectGroupByWarehouse();
829
 
830
					warehouseStockMap = warehouseStocks.stream()
27509 tejbeer 831
							.collect(Collectors.toMap(x -> x.getWarehouseId(), x -> x));
27352 tejbeer 832
 
27539 tejbeer 833
					if (!warehouseStocks.isEmpty()) {
834
						for (WarehouseWiseStockModel warehouseStock : warehouseStocks) {
835
							stockValue += warehouseStock.getStockValue();
836
							stockQty += warehouseStock.getStockQty();
837
							pendingIndent += warehouseStock.getPendingIndent();
27542 tejbeer 838
							tertiary += warehouseStock.getTertiary();
27539 tejbeer 839
						}
840
						WarehouseWiseStockModel ws = new WarehouseWiseStockModel();
841
						ws.setStockQty(stockQty);
842
						ws.setStockValue(stockValue);
843
						ws.setPendingIndent(pendingIndent);
27542 tejbeer 844
						ws.setTertiary(tertiary);
27539 tejbeer 845
						ws.setWarehouseId(0);
846
						warehouseStockMap.put(0, ws);
847
 
848
					}
27591 tejbeer 849
 
850
					warehousePartnerDetailMap = this.getWarehousePartnerDetail();
27628 tejbeer 851
					LOGGER.info("warehousePartnerDetailMap" + warehousePartnerDetailMap);
852
					rctSaholic = reporticoCacheTableRepository.selectByTableName("SaholicInventoryCIS");
853
					rctPartneStat = reporticoCacheTableRepository.selectByTableName("partnerStat");
27591 tejbeer 854
					partnersBrandSale = fofoStoreRepository.selectGroupByBrandWarehousePartnerSale();
27594 tejbeer 855
					accessoriesBrandSales = fofoStoreRepository.selectGroupByBrandAccesoriesWarehousePartnerSale();
26418 tejbeer 856
				}
857
			}
858
 
27415 tejbeer 859
			if (Arrays.asList("amit.gupta@shop2020.in", "tejbeer.kaur@shop2020.in", "manish.tiwari@smartdukaan.com")
860
					.contains(email)) {
26029 amit.gupta 861
				menus = menuRepository.selectAll();
862
			} else if (positions.size() > 0) {
27108 amit.gupta 863
				if (positions.stream().filter(x -> x.getEscalationType().equals(EscalationType.L5)).count() > 0) {
26028 amit.gupta 864
					menus = menuRepository.selectAll();
865
				} else {
866
					List<Integer> menuIds = menuCategoryRepository.selectAllByPositions(positions).stream()
867
							.map(x -> x.getMenuId()).collect(Collectors.toList());
868
					LOGGER.info("Menu Ids are {}", menuIds);
869
					if (menuIds.size() > 0) {
870
						menus = menuRepository.selectAllByIds(menuIds);
871
					}
26022 amit.gupta 872
				}
26090 amit.gupta 873
				List<Position> salesPositions = positions.stream()
874
						.filter(x -> x.getCategoryId() == ProfitMandiConstants.TICKET_CATEGORY_SALES)
875
						.collect(Collectors.toList());
876
				if (salesPositions.size() > 0) {
877
					Set<CustomRetailer> positionRetailers = new HashSet<>();
26100 amit.gupta 878
					csService.getPositionCustomRetailerMap(salesPositions).values().forEach(customRetailers -> {
26090 amit.gupta 879
						positionRetailers.addAll(customRetailers);
880
					});
881
					model.addAttribute("retailers", gson.toJson(positionRetailers));
882
					model.addAttribute("reporticoProjectMap", ReporticoProject.salesReporticoProjectMap);
26152 amit.gupta 883
					model.addAttribute("warehouses", getWarehouses(positionRetailers));
26090 amit.gupta 884
				}
26114 amit.gupta 885
				List<Position> warehousePositions = positions.stream()
886
						.filter(x -> x.getCategoryId() == ProfitMandiConstants.TICKET_CATEGORY_WAREHOUSE)
887
						.collect(Collectors.toList());
888
				if (warehousePositions.size() > 0) {
889
					Set<CustomRetailer> positionRetailers = new HashSet<>();
26123 amit.gupta 890
					csService.getPositionCustomRetailerMap(warehousePositions).values().forEach(customRetailers -> {
26114 amit.gupta 891
						positionRetailers.addAll(customRetailers);
892
					});
893
					model.addAttribute("reporticoProjectMap", ReporticoProject.warehouseReporticoMap);
894
					model.addAttribute("retailers", gson.toJson(positionRetailers));
26123 amit.gupta 895
					model.addAttribute("warehouses", getWarehouses(positionRetailers));
26114 amit.gupta 896
				}
26142 amit.gupta 897
				model.addAttribute("authId", authUser.getId());
26028 amit.gupta 898
 
26022 amit.gupta 899
			}
27628 tejbeer 900
			model.addAttribute("rctPartneStat", rctPartneStat);
901
 
902
			model.addAttribute("reporticoDate", rctSaholic);
27545 tejbeer 903
			model.addAttribute("warehousePartnerDetailMap", warehousePartnerDetailMap);
27539 tejbeer 904
			model.addAttribute("warehouseMap", wm);
27509 tejbeer 905
			model.addAttribute("warehouseStockMap", warehouseStockMap);
27591 tejbeer 906
			model.addAttribute("brandSales", partnersBrandSale);
27556 tejbeer 907
 
27594 tejbeer 908
			model.addAttribute("accessoriesBrandSales", accessoriesBrandSales);
909
 
26012 amit.gupta 910
		} catch (ProfitMandiBusinessException e) {
26011 amit.gupta 911
		}
26028 amit.gupta 912
		List<Menu> menuList = (menus != null) ? this.prepareMenu(menus) : new ArrayList<>();
26422 tejbeer 913
		LOGGER.info("menu" + menuList);
26022 amit.gupta 914
		model.addAttribute("menu", menuList);
26012 amit.gupta 915
		return "admin";
916
	}
917
 
26468 amit.gupta 918
	/*
919
	 * @RequestMapping(value = "/getL1AuthUser", method = RequestMethod.GET) public
920
	 * String L1AuthUsersDetail(HttpServletRequest request, Model
921
	 * model, @RequestParam int authId) throws Exception {
922
	 * 
923
	 * Map<Integer, List<Integer>> pp = csService.getAuthUserIdPartnerIdMapping();
924
	 * 
925
	 * LocalDateTime curDate = LocalDate.now().atStartOfDay(); Map<Integer, Double>
926
	 * lmtdSale = fofoOrderItemRepository.selectSumAmountGroupByRetailer(
927
	 * curDate.withDayOfMonth(1).minusMonths(1),
928
	 * curDate.with(LocalTime.MAX).minusMonths(1), 0, false); Map<Integer, Double>
929
	 * mtdSale =
930
	 * fofoOrderItemRepository.selectSumAmountGroupByRetailer(curDate.withDayOfMonth
931
	 * (1), curDate.with(LocalTime.MAX), 0, false); Map<Integer, List<Integer>>
932
	 * L2L1Mapping = csService.getL1L2Mapping();
933
	 * 
934
	 * LOGGER.info("L2L1Mapping" + L2L1Mapping); List<Integer> l1authIds =
935
	 * L2L1Mapping.get(authId);
936
	 * 
937
	 * Map<Integer, Object> authIdAndallValues = new LinkedHashMap<>(); Map<Integer,
938
	 * Object> authIdAndAuthUserMap = new LinkedHashMap<>();
939
	 * 
940
	 * Map<Integer, Long> ticketMap =
941
	 * ticketRepository.selectAllNotClosedTicketsGroupByRetailer(); for (Integer
942
	 * l1AuthId : l1authIds) {
943
	 * 
944
	 * double totallmtdAmount = 0; double totalmtdAmount = 0; int totalTicketCount =
945
	 * 0; float totalTodayInvestment = 0; float totalStockInInvestment = 0; double
946
	 * currentMonthRatingAllPartners = 0; Map<Integer, Long> leadCount =
947
	 * leadRepository.selectByAssignAuthIdAndStatus(l1AuthId, LeadStatus.followUp)
948
	 * .stream().collect(Collectors.groupingBy(Lead::getAssignTo,
949
	 * Collectors.counting()));
950
	 * 
951
	 * AuthUser authUser = authRepository.selectById(l1AuthId);
952
	 * 
953
	 * authIdAndAuthUserMap.put(l1AuthId, authUser);
954
	 * 
955
	 * List<Integer> fofoIds = pp.get(l1AuthId);
956
	 * 
957
	 * Map<Integer, PartnerDailyInvestment> partnerInvestentMap =
958
	 * partnerInvestmentService .getInvestment(fofoIds,
959
	 * 0).stream().collect(Collectors.toMap(x -> x.getFofoId(), x -> x));
960
	 * 
961
	 * for (Integer fId : fofoIds) { try { PartnerDailyInvestment investment =
962
	 * partnerInvestentMap.get(fId); totalTodayInvestment +=
963
	 * investment.getTotalInvestment(); totalStockInInvestment +=
964
	 * investment.getInStockAmount(); } catch (Exception e) { }
965
	 * 
966
	 * double currentMonthRating = hygieneDataRepository.selectRatingAvg(fId,
967
	 * curDate.withDayOfMonth(1).minusMonths(1),
968
	 * curDate.plusMonths(1).withDayOfMonth(1));
969
	 * 
970
	 * currentMonthRatingAllPartners += currentMonthRating;
971
	 * 
972
	 * fofoIds.size();
973
	 * 
974
	 * Double lmtdAmount = lmtdSale.get(fId); Double mtdAmount = mtdSale.get(fId);
975
	 * Long ticketCount = ticketMap.get(fId); if (ticketCount != null) {
976
	 * totalTicketCount += ticketCount; }
977
	 * 
978
	 * if (lmtdAmount != null) { totallmtdAmount += lmtdAmount; }
979
	 * 
980
	 * if (mtdAmount != null) { totalmtdAmount += mtdAmount; }
981
	 * 
982
	 * } LOGGER.info("currentMonthRatingAllPartners" +
983
	 * currentMonthRatingAllPartners); LOGGER.info("size" + fofoIds.size()); double
984
	 * totalHygieneRating = currentMonthRatingAllPartners / fofoIds.size();
985
	 * 
986
	 * LOGGER.info("totalHygieneRating" + totalHygieneRating);
987
	 * 
988
	 * PartnerDetailModel pm = new PartnerDetailModel();
989
	 * pm.setLmtd(totallmtdAmount); pm.setMtd(totalmtdAmount); if
990
	 * (leadCount.get(l1AuthId) != null) {
991
	 * pm.setLeads(leadCount.get(l1AuthId).intValue()); } else { pm.setLeads(0); }
992
	 * 
993
	 * pm.setInvestment(totalTodayInvestment);
994
	 * pm.setStockInInvestment(totalStockInInvestment);
995
	 * pm.setTicket(totalTicketCount); pm.setHygiene((double)
996
	 * Math.round(totalHygieneRating)); authIdAndallValues.put(l1AuthId, pm);
997
	 * 
998
	 * } model.addAttribute("authIdAndallValues", authIdAndallValues);
999
	 * model.addAttribute("authIdAndAuthUserMap", authIdAndAuthUserMap);
1000
	 * LOGGER.info("authIdAndallValues" + authIdAndallValues);
1001
	 * 
1002
	 * return "auth_user_detail"; }
1003
	 */
26418 tejbeer 1004
 
26468 amit.gupta 1005
	@RequestMapping(value = "/getAuthUserPartners", method = RequestMethod.GET)
26418 tejbeer 1006
	public String AuthUserPartnersDetail(HttpServletRequest request, Model model, @RequestParam int authId)
1007
			throws Exception {
1008
 
1009
		Map<Integer, List<Integer>> pp = csService.getAuthUserIdPartnerIdMapping();
26963 amit.gupta 1010
		Map<Integer, CustomRetailer> fofoIdAndPartnerMap = retailerService.getFofoRetailers(false);
26418 tejbeer 1011
 
26468 amit.gupta 1012
		Map<Integer, PartnerDetailModel> fofoIdAndallValues = partnerStatsService.getAllPartnerStats();
1013
		if (authId != 0) {
1014
			List<Integer> fofoIds = pp.get(authId);
1015
			fofoIdAndallValues = fofoIdAndallValues.entrySet().stream().filter(x -> fofoIds.contains(x.getKey()))
1016
					.collect(Collectors.toMap(x -> x.getKey(), x -> x.getValue()));
26474 amit.gupta 1017
		} else {
26418 tejbeer 1018
		}
1019
 
1020
		model.addAttribute("fofoIdAndallValues", fofoIdAndallValues);
1021
		model.addAttribute("fofoIdAndPartnerMap", fofoIdAndPartnerMap);
1022
 
1023
		return "auth_user_partner_detail";
26468 amit.gupta 1024
	}
26418 tejbeer 1025
 
27545 tejbeer 1026
	@RequestMapping(value = "/getWarehousePartners", method = RequestMethod.GET)
1027
	public String warehousePartnersDetail(HttpServletRequest request, Model model, @RequestParam int warehouseId)
1028
			throws Exception {
1029
 
1030
		Map<Integer, CustomRetailer> fofoIdAndPartnerMap = retailerService.getFofoRetailers(false);
27628 tejbeer 1031
		Map<Integer, PartnerDetailModel> fofoIdAndallValues = this.getPartnersStatDataFromFile();
27545 tejbeer 1032
		if (warehouseId != 0) {
1033
 
1034
			List<Integer> fofoIds = fofoStoreRepository.selectActivePartnerByWarehouse(warehouseId).stream()
1035
					.map(x -> x.getId()).collect(Collectors.toList());
1036
			fofoIdAndallValues = fofoIdAndallValues.entrySet().stream().filter(x -> fofoIds.contains(x.getKey()))
1037
					.collect(Collectors.toMap(x -> x.getKey(), x -> x.getValue()));
1038
		} else {
1039
		}
1040
 
1041
		model.addAttribute("fofoIdAndallValues", fofoIdAndallValues);
1042
		model.addAttribute("fofoIdAndPartnerMap", fofoIdAndPartnerMap);
1043
 
1044
		return "auth_user_partner_detail";
1045
	}
1046
 
27509 tejbeer 1047
	@RequestMapping(value = "/getWarehouseWiseBrandStock", method = RequestMethod.GET)
27542 tejbeer 1048
	public String getWarehouseWiseBrandStock(HttpServletRequest request, Model model, @RequestParam int warehouseId)
1049
			throws Exception {
27509 tejbeer 1050
 
27529 tejbeer 1051
		List<WarehouseWiseBrandStockModel> warehouseWiseBrandStock = saholicInventoryCISRepository
27509 tejbeer 1052
				.selectGroupByWarehouseAndBrand(warehouseId);
27542 tejbeer 1053
		Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
27509 tejbeer 1054
		model.addAttribute("warehouseWiseBrandStock", warehouseWiseBrandStock);
27542 tejbeer 1055
		model.addAttribute("warehouseId", warehouseId);
27509 tejbeer 1056
		model.addAttribute("warehouseMap", warehouseMap);
1057
		LOGGER.info("warehouseWiseBrandStock" + warehouseWiseBrandStock);
1058
		return "warehouse_brand_stock";
1059
	}
1060
 
27529 tejbeer 1061
	@RequestMapping(value = "/getWarehouseWiseData", method = RequestMethod.GET)
1062
	public String getWarehouseWiseData(HttpServletRequest request, Model model) throws Exception {
1063
		inventoryService.getItemAvailabilityAndIndent();
1064
		model.addAttribute("response", mvcResponseSender.createResponseString(true));
1065
		return "response";
1066
	}
1067
 
27628 tejbeer 1068
	public Map<Integer, PartnerDetailModel> getWarehousePartnerDetail() throws Exception {
1069
 
1070
		Map<Integer, PartnerDetailModel> warehouseIdAndallValues = new LinkedHashMap<>();
1071
		Map<Integer, List<FofoStore>> warehousePartnerMap = fofoStoreRepository.getWarehousePartnerMap();
1072
		Map<Integer, PartnerDetailModel> partnerStats = this.getPartnersStatDataFromFile();
1073
		if (partnerStats != null) {
1074
			for (Entry<Integer, List<FofoStore>> warehouse : warehousePartnerMap.entrySet()) {
1075
				List<Integer> fofoIds = warehouse.getValue().stream().map(x -> x.getId()).collect(Collectors.toList());
1076
				List<PartnerDetailModel> partnerDetails = fofoIds.stream().map(x -> partnerStats.get(x))
1077
						.collect(Collectors.toList());
27632 tejbeer 1078
				LOGGER.info("partnerDetails1" + partnerDetails);
27634 tejbeer 1079
				if (partnerDetails != null && !partnerDetails.isEmpty()) {
1080
					PartnerDetailModel partnerDetailModel = partnerStatsService.getAggregateStats(partnerDetails);
1081
					warehouseIdAndallValues.put(warehouse.getKey(), partnerDetailModel);
1082
				}
27628 tejbeer 1083
 
1084
			}
1085
			LOGGER.info("warehouseIdAndallValues" + warehouseIdAndallValues);
1086
			PartnerDetailModel partnerDetailModel = partnerStatsService
1087
					.getAggregateStats(new ArrayList<>(partnerStats.values()));
1088
			warehouseIdAndallValues.put(0, partnerDetailModel);
1089
		}
1090
		return warehouseIdAndallValues;
1091
	}
1092
 
1093
	@RequestMapping(value = "/getPartnersStatData", method = RequestMethod.GET)
1094
	public String getPartnersStatData(HttpServletRequest request, Model model) throws Exception {
1095
		Map<Integer, PartnerDetailModel> partnerStats = partnerStatsService.getAllPartnerStats();
1096
		ObjectOutputStream oos = null;
1097
		FileOutputStream fout = null;
1098
		try {
1099
			fout = new FileOutputStream("/tmp/partnerStat.tmp", false);
1100
			oos = new ObjectOutputStream(fout);
1101
			oos.writeObject(partnerStats);
1102
 
1103
		} catch (Exception ex) {
1104
			ex.printStackTrace();
1105
		} finally {
1106
			if (oos != null) {
1107
				oos.close();
1108
			}
1109
		}
1110
		ReporticoCacheTable rct = reporticoCacheTableRepository.selectByTableName("partnerStat");
1111
		if (rct == null) {
1112
			rct = new ReporticoCacheTable();
1113
			rct.setTableName("partnerStat");
1114
 
1115
		}
1116
		rct.setLastCreatedTimestamp(LocalDateTime.now());
1117
		reporticoCacheTableRepository.persist(rct);
1118
		model.addAttribute("response", mvcResponseSender.createResponseString(true));
1119
		return "response";
1120
	}
1121
 
1122
	public Map<Integer, PartnerDetailModel> getPartnersStatDataFromFile() throws Exception {
1123
		ObjectInputStream objectinputstream = null;
1124
		Map<Integer, PartnerDetailModel> partnerStat = null;
1125
		try {
1126
			FileInputStream streamIn = new FileInputStream("/tmp/partnerStat.tmp");
1127
			objectinputstream = new ObjectInputStream(streamIn);
1128
			partnerStat = (Map<Integer, PartnerDetailModel>) objectinputstream.readObject();
1129
 
1130
			LOGGER.info("partnerStat" + partnerStat);
1131
			objectinputstream.close();
1132
 
1133
		} catch (Exception e) {
1134
			LOGGER.info("exceptionddd" + e);
1135
 
1136
			e.printStackTrace();
1137
 
1138
		} finally {
1139
			if (objectinputstream != null) {
1140
				objectinputstream.close();
1141
				LOGGER.info("clofddd" + partnerStat);
1142
 
1143
			}
1144
		}
1145
		return partnerStat;
1146
 
1147
	}
1148
 
27539 tejbeer 1149
	@RequestMapping(value = "/getWarehouseWiseBrandAndCategory", method = RequestMethod.GET)
1150
	public String getWarehouseWiseBrandAndCategory(HttpServletRequest request, Model model,
27538 tejbeer 1151
			@RequestParam List<Integer> warehouseId, @RequestParam List<String> brands, @RequestParam String category)
1152
			throws Exception {
27509 tejbeer 1153
 
1154
		Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
27529 tejbeer 1155
		List<String> listbrands = saholicInventoryCISRepository.selectAllBrand();
27538 tejbeer 1156
		List<String> listCategory = saholicInventoryCISRepository.selectAllSubCategory();
27539 tejbeer 1157
 
27509 tejbeer 1158
		model.addAttribute("warehouseMap", warehouseMap);
27529 tejbeer 1159
		model.addAttribute("brands", listbrands);
27538 tejbeer 1160
		model.addAttribute("listCategory", listCategory);
1161
 
27529 tejbeer 1162
		model.addAttribute("selectedBrand", brands);
27538 tejbeer 1163
		model.addAttribute("selectedWarehouse", warehouseId);
27539 tejbeer 1164
		model.addAttribute("selectedCategory", category);
1165
 
27509 tejbeer 1166
		return "warehouse_brand_item_stock";
1167
	}
1168
 
27538 tejbeer 1169
	@RequestMapping(value = "/getWarehouseWiseItemStock", method = RequestMethod.GET)
1170
	public String getWarehouseWiseItemStock(HttpServletRequest request, Model model,
1171
			@RequestParam List<Integer> warehouseId, @RequestParam List<String> brands, @RequestParam String category)
1172
			throws Exception {
27539 tejbeer 1173
		Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
1174
		if (warehouseId.contains(0)) {
1175
			warehouseId.addAll(warehouseMap.keySet());
1176
		}
27538 tejbeer 1177
		List<WarehouseWiseitemStockModel> warehouseWiseItemStock = saholicInventoryCISRepository
1178
				.selectWarehouseItemStock(warehouseId, brands, category);
27539 tejbeer 1179
 
27538 tejbeer 1180
		model.addAttribute("warehouseWiseItemStock", warehouseWiseItemStock);
1181
		model.addAttribute("warehouseMap", warehouseMap);
1182
 
1183
		LOGGER.info("warehouseWiseItemStock" + warehouseWiseItemStock);
1184
		return "warehouse_item_details";
1185
	}
1186
 
26114 amit.gupta 1187
	private String getWarehouses(Set<CustomRetailer> positionRetailers) {
1188
		Map<Integer, String> warehouses = new HashMap<>();
26222 tejbeer 1189
		positionRetailers.stream().forEach(x -> {
1190
			if (x.getWarehouseId() != 0) {
26171 amit.gupta 1191
				warehouses.put(x.getWarehouseId(), ProfitMandiConstants.WAREHOUSE_MAP.get(x.getWarehouseId()));
1192
			}
1193
		});
26114 amit.gupta 1194
		return gson.toJson(warehouses);
1195
 
1196
	}
1197
 
27556 tejbeer 1198
	@RequestMapping(value = "/getWarehouseWiseBrandPartnerSale", method = RequestMethod.GET)
27591 tejbeer 1199
	public String getWarehouseWiseBrandPartnerSale(HttpServletRequest request, Model model, @RequestParam String brand)
1200
			throws Exception {
1201
		List<WarehouseWiseBrandSaleModel> warehouseWiseBrandPartnerSales = fofoStoreRepository
1202
				.selectGroupByWarehouseBrandWisePartnerSale(brand);
27556 tejbeer 1203
		Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
27591 tejbeer 1204
 
1205
		Set<String> brands = inventoryService.getAllTagListingBrands();
1206
		model.addAttribute("warehouseWiseBrandPartnerSales", warehouseWiseBrandPartnerSales);
27556 tejbeer 1207
		model.addAttribute("warehouseMap", warehouseMap);
27591 tejbeer 1208
		model.addAttribute("brands", brands);
1209
		model.addAttribute("selectedbrand", brand);
1210
 
1211
		LOGGER.info("warehouseWiseBrandPartnerSales" + warehouseWiseBrandPartnerSales);
1212
		return "warehousewise_brand_partners_sale";
27556 tejbeer 1213
	}
1214
 
27594 tejbeer 1215
	@RequestMapping(value = "/getWarehouseWiseAccesoriesBrandPartnerSale", method = RequestMethod.GET)
1216
	public String getWarehouseWiseAccesoriesBrandPartnerSale(HttpServletRequest request, Model model,
1217
			@RequestParam String brand) throws Exception {
1218
		List<WarehouseWiseBrandSaleModel> warehouseWiseBrandPartnerSales = fofoStoreRepository
1219
				.selectGroupByWarehouseAccesoriesBrandWisePartnerSale(brand);
1220
		Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
1221
 
1222
		Set<String> brands = inventoryService.getAllTagListingBrands();
1223
		model.addAttribute("warehouseWiseBrandPartnerSales", warehouseWiseBrandPartnerSales);
1224
		model.addAttribute("warehouseMap", warehouseMap);
1225
		model.addAttribute("brands", brands);
1226
		model.addAttribute("selectedbrand", brand);
1227
 
1228
		LOGGER.info("warehouseWiseBrandPartnerSales" + warehouseWiseBrandPartnerSales);
1229
		return "warehousewise_accessoriesbrand_sale";
1230
	}
1231
 
27556 tejbeer 1232
	@RequestMapping(value = "/getWarehouseBrandWiseItemSale", method = RequestMethod.GET)
1233
	public String getWarehouseBrandWiseItemSale(HttpServletRequest request, Model model,
1234
			@RequestParam List<Integer> warehouseId, @RequestParam String brand) throws Exception {
1235
		Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
1236
		List<WarehouseBrandWiseItemSaleModel> branditemSales = fofoStoreRepository
1237
				.selectWarehouseBrandItemSale(warehouseId, brand);
1238
		model.addAttribute("branditemSales", branditemSales);
1239
		model.addAttribute("warehouseMap", warehouseMap);
1240
		return "warehouse_partner_itemwise_sale";
1241
	}
1242
 
27594 tejbeer 1243
	@RequestMapping(value = "/getWarehouseAccesoriesBrandWiseItemSale", method = RequestMethod.GET)
1244
	public String getWarehouseAccesoriesBrandWiseItemSale(HttpServletRequest request, Model model,
1245
			@RequestParam List<Integer> warehouseId, @RequestParam String brand) throws Exception {
1246
		Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
1247
		List<WarehouseBrandWiseItemSaleModel> branditemSales = fofoStoreRepository
1248
				.selectWarehouseAccesoriesBrandItemSale(warehouseId, brand);
1249
		model.addAttribute("branditemSales", branditemSales);
1250
		model.addAttribute("warehouseMap", warehouseMap);
1251
		return "warehouse_accessories_itemwsie_sale";
1252
	}
1253
 
26012 amit.gupta 1254
	private List<Menu> prepareMenu(List<Menu> menus) {
1255
		List<Menu> returnMenu = new ArrayList<>();
1256
		Map<Menu, List<Menu>> subMenuMap = new HashMap<Menu, List<Menu>>();
1257
		for (Menu menu : menus) {
1258
			if (menu.get_parent() == null) {
26014 amit.gupta 1259
				if (!subMenuMap.containsKey(menu)) {
26012 amit.gupta 1260
					subMenuMap.put(menu, new ArrayList<>());
26011 amit.gupta 1261
				}
1262
			} else {
26012 amit.gupta 1263
				Menu parentMenu = menu.get_parent();
1264
				if (!subMenuMap.containsKey(parentMenu)) {
1265
					subMenuMap.put(parentMenu, new ArrayList<>());
26011 amit.gupta 1266
				}
26012 amit.gupta 1267
				subMenuMap.get(parentMenu).add(menu);
26011 amit.gupta 1268
			}
1269
		}
26012 amit.gupta 1270
		subMenuMap.entrySet().stream().forEach(entry -> {
1271
			entry.getKey().setSubMenus(entry.getValue());
1272
			returnMenu.add(entry.getKey());
1273
		});
1274
		return returnMenu;
26005 amit.gupta 1275
	}
1276
 
24288 amit.gupta 1277
	// This method is currently hardcoded to faciliate watches sold as gift.
24203 amit.gupta 1278
	private boolean hasGift(int fofoId) {
1279
		try {
24288 amit.gupta 1280
			return currentInventorySnapshotRepository.selectByItemIdAndFofoId(ProfitMandiConstants.GIFT_ID, fofoId)
1281
					.getAvailability() > 0;
24203 amit.gupta 1282
		} catch (ProfitMandiBusinessException e) {
1283
			return false;
1284
		}
1285
	}
24288 amit.gupta 1286
 
22354 ashik.ali 1287
	@RequestMapping(value = "/contactUs", method = RequestMethod.GET)
23923 amit.gupta 1288
	public String contactUs(HttpServletRequest request, Model model) throws Throwable {
22354 ashik.ali 1289
		model.addAttribute("appContextPath", request.getContextPath());
1290
		return "contact-us";
1291
	}
23923 amit.gupta 1292
 
25649 tejbeer 1293
	@RequestMapping(value = "/notifications", method = RequestMethod.GET)
25683 tejbeer 1294
	public String getNotificationsWithType(HttpServletRequest request,
1295
			@RequestParam(required = false) MessageType messageType,
25649 tejbeer 1296
			@RequestParam(name = "offset", defaultValue = "0") int offset,
1297
			@RequestParam(name = "limit", defaultValue = "20") int limit, Model model) throws Exception {
1298
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
26060 tejbeer 1299
		int userId = 0;
1300
		boolean isAdmin = roleManager.isAdmin(loginDetails.getRoleIds());
1301
		if (isAdmin) {
1302
			userId = loginDetails.getFofoId();
1303
		} else {
1304
			userId = userAccountRepository.selectUserIdByRetailerId(loginDetails.getFofoId());
1305
		}
25683 tejbeer 1306
		List<Notification> notifications = null;
1307
 
26086 tejbeer 1308
		List<NotificationCampaign> notificationCampaigns = notificationCampaignRepository.getNotifications(messageType,
1309
				userId, offset, limit);
1310
		LOGGER.info("messageType" + messageType);
1311
		notifications = getNotifications(notificationCampaigns, messageType);
1312
 
25683 tejbeer 1313
		model.addAttribute("notifications", notifications);
1314
 
1315
		LOGGER.info("notifications" + notifications);
1316
		return "notification-template";
1317
	}
1318
 
1319
	public List<Notification> getNotifications(List<NotificationCampaign> nc, MessageType messageType)
1320
			throws ProfitMandiBusinessException {
1321
		List<Notification> notifications = new ArrayList<>();
1322
		Document document = null;
1323
		if (messageType != null) {
1324
			for (NotificationCampaign notificationCampaign : nc) {
1325
				if (notificationCampaign.getMessageType() == messageType) {
25649 tejbeer 1326
					Notification ns = new Notification();
1327
					SimpleCampaignParams scp = gson.fromJson(notificationCampaign.getImplementationParams(),
1328
							SimpleCampaignParams.class);
1329
					Campaign campaign = new SimpleCampaign(scp);
1330
					LocalDateTime expire = campaign.getExpireTimestamp();
1331
					ns.setCid(Integer.toString(notificationCampaign.getId()));
1332
					ns.setType(campaign.getType());
1333
					ns.setMessage(campaign.getMessage());
1334
					ns.setTitle(campaign.getTitle());
25651 tejbeer 1335
					if (notificationCampaign.getDocumentId() != null) {
1336
						document = documentRepository.selectById(notificationCampaign.getDocumentId());
1337
						ns.setDocumentName(document.getDisplayName());
1338
					}
25683 tejbeer 1339
					ns.setUrl(campaign.getUrl());
25649 tejbeer 1340
					ns.setShowImage(campaign.getShowImage());
1341
					ns.setImageUrl(campaign.getImageUrl());
25683 tejbeer 1342
					ns.setDocumentId(notificationCampaign.getDocumentId());
1343
					ns.setMessageType(notificationCampaign.getMessageType());
25649 tejbeer 1344
					ns.setCreated(
1345
							notificationCampaign.getCreatedTimestamp().toEpochSecond(ZoneOffset.ofHoursMinutes(5, 30))
1346
									* 1000);
1347
					if (LocalDateTime.now().isAfter(expire)) {
1348
						ns.setExpired(true);
1349
					} else {
1350
						ns.setExpired(false);
1351
					}
1352
					notifications.add(ns);
1353
				}
1354
			}
25683 tejbeer 1355
		} else {
1356
			for (NotificationCampaign notificationCampaign : nc) {
1357
 
1358
				Notification ns = new Notification();
1359
				SimpleCampaignParams scp = gson.fromJson(notificationCampaign.getImplementationParams(),
1360
						SimpleCampaignParams.class);
1361
				Campaign campaign = new SimpleCampaign(scp);
1362
				LocalDateTime expire = campaign.getExpireTimestamp();
1363
				ns.setCid(Integer.toString(notificationCampaign.getId()));
1364
				ns.setType(campaign.getType());
1365
				ns.setMessage(campaign.getMessage());
1366
				ns.setTitle(campaign.getTitle());
1367
				if (notificationCampaign.getDocumentId() != null) {
1368
					document = documentRepository.selectById(notificationCampaign.getDocumentId());
1369
					ns.setDocumentName(document.getDisplayName());
1370
				}
1371
				ns.setUrl(campaign.getUrl());
1372
				ns.setShowImage(campaign.getShowImage());
1373
				ns.setImageUrl(campaign.getImageUrl());
1374
				ns.setDocumentId(notificationCampaign.getDocumentId());
1375
				ns.setMessageType(notificationCampaign.getMessageType());
1376
				ns.setCreated(notificationCampaign.getCreatedTimestamp().toEpochSecond(ZoneOffset.ofHoursMinutes(5, 30))
1377
						* 1000);
1378
				if (LocalDateTime.now().isAfter(expire)) {
1379
					ns.setExpired(true);
1380
				} else {
1381
					ns.setExpired(false);
1382
				}
1383
				notifications.add(ns);
1384
			}
1385
 
25649 tejbeer 1386
		}
25683 tejbeer 1387
		return notifications;
25651 tejbeer 1388
 
1389
	}
25649 tejbeer 1390
 
25651 tejbeer 1391
	@RequestMapping(value = "/notifyDocument/documentId", method = RequestMethod.GET)
1392
	public ResponseEntity<?> retailerDocumentById(HttpServletRequest request,
1393
			@RequestParam(name = ProfitMandiConstants.DOCUMENT_ID) int documentId, @RequestParam int cid)
1394
			throws ProfitMandiBusinessException {
1395
		Document document = documentRepository.selectById(documentId);
1396
		NotificationCampaign nc = notificationCampaignRepository.selectById(cid);
1397
		if (nc.getDocumentId() == null) {
1398
			throw new ProfitMandiBusinessException("cid", nc.getId(), "not available");
1399
		}
1400
		if (nc.getDocumentId() != documentId) {
1401
			throw new ProfitMandiBusinessException(ProfitMandiConstants.DOCUMENT_ID, documentId, "RTLR_1014");
1402
		}
1403
		return responseSender.ok(document);
25649 tejbeer 1404
	}
1405
 
25651 tejbeer 1406
	@RequestMapping(value = "/notifyDocument/download", method = RequestMethod.GET)
1407
	public ResponseEntity<?> downloadRetailerDocument(HttpServletRequest request, @RequestParam int cid, Model model)
1408
			throws ProfitMandiBusinessException {
1409
 
1410
		NotificationCampaign nc = notificationCampaignRepository.selectById(cid);
1411
 
1412
		if (nc.getDocumentId() == null) {
1413
			throw new ProfitMandiBusinessException("cid", nc.getId(), "not available");
1414
		}
1415
 
1416
		Document document = documentRepository.selectById(nc.getDocumentId());
1417
 
1418
		FileInputStream file = null;
1419
		try {
1420
			file = new FileInputStream(document.getPath() + File.separator + document.getName());
1421
		} catch (FileNotFoundException e) {
1422
			LOGGER.error("Retailer Document file not found : ", e);
1423
			throw new ProfitMandiBusinessException(ProfitMandiConstants.DOCUMENT_ID, document.getId(), "RTLR_1013");
1424
		}
1425
		// ByteArrayOutputStream byteArrayOutputStream = new
1426
		// ByteArrayOutputStream();
1427
		// ExcelUtils.writeSchemeModels(schemeModels, byteArrayOutputStream);
1428
 
1429
		final HttpHeaders headers = new HttpHeaders();
1430
		String contentType = "";
1431
		if (document.getContentType() == ContentType.JPEG) {
1432
			contentType = "image/jpeg";
1433
		} else if (document.getContentType() == ContentType.PNG) {
1434
			contentType = "image/png";
1435
		} else if (document.getContentType() == ContentType.PDF) {
1436
			contentType = "application/pdf";
1437
		}
1438
		headers.set("Content-Type", contentType);
1439
		headers.set("Content-disposition", "inline; filename=" + document.getName());
1440
		headers.setContentLength(document.getSize());
1441
		final InputStreamResource inputStreamResource = new InputStreamResource(file);
1442
		return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
1443
	}
26460 amit.gupta 1444
 
1445
	public Map<Integer, PartnerDetailModel> getL2AuthUserPartnerDetail() throws Exception {
26445 amit.gupta 1446
		LOGGER.info("getL2AuthUserPartnerDetail Started");
26460 amit.gupta 1447
		Map<Integer, List<Integer>> L2L1Mapping = csService.getL2L1Mapping();
26422 tejbeer 1448
		Map<Integer, Integer> authIdAndleadsCountMap = new HashMap<>();
1449
		for (Entry<Integer, List<Integer>> l2l1 : L2L1Mapping.entrySet()) {
1450
			List<Integer> authIds = l2l1.getValue();
1451
			authIds.add(l2l1.getKey());
1452
 
1453
			List<Lead> leads = leadRepository.selectByAssignAuthIdsAndStatus(authIds, LeadStatus.followUp);
26433 tejbeer 1454
			LOGGER.info("authIdAndleadsCountMap" + authIdAndleadsCountMap);
26422 tejbeer 1455
			AuthUser auth = authRepository.selectById(l2l1.getKey());
26431 tejbeer 1456
			if (!leads.isEmpty()) {
1457
				authIdAndleadsCountMap.put(auth.getId(), leads.size());
1458
			} else {
1459
				authIdAndleadsCountMap.put(auth.getId(), 0);
1460
			}
26422 tejbeer 1461
		}
26468 amit.gupta 1462
 
26460 amit.gupta 1463
		Map<Integer, PartnerDetailModel> partnerStats = partnerStatsService.getAllPartnerStats();
27352 tejbeer 1464
		List<Integer> unmappedPartners = partnerStats.entrySet().stream().map(x -> x.getKey())
1465
				.collect(Collectors.toList());
26433 tejbeer 1466
		LOGGER.info("authIdAndleadsCountMap" + authIdAndleadsCountMap);
26422 tejbeer 1467
 
26460 amit.gupta 1468
		Map<Integer, PartnerDetailModel> authIdAndallValues = new LinkedHashMap<>();
26422 tejbeer 1469
 
26460 amit.gupta 1470
		Map<Integer, List<Integer>> pp = csService.getAuthUserIdPartnerIdMapping();
1471
		for (int authUserId : pp.keySet()) {
1472
			if (L2L1Mapping.keySet().contains(authUserId)) {
1473
				List<Integer> fofoIds = pp.get(authUserId);
26997 amit.gupta 1474
				unmappedPartners.removeAll(fofoIds);
26468 amit.gupta 1475
				List<PartnerDetailModel> partnerDetails = fofoIds.stream().map(x -> partnerStats.get(x))
1476
						.collect(Collectors.toList());
27632 tejbeer 1477
				LOGGER.info("authUserId {}, partnerDetails2 {}" + authUserId, partnerDetails);
26460 amit.gupta 1478
				PartnerDetailModel partnerDetailModel = partnerStatsService.getAggregateStats(partnerDetails);
1479
				authIdAndallValues.put(authUserId, partnerDetailModel);
26422 tejbeer 1480
			}
1481
		}
26997 amit.gupta 1482
		List<PartnerDetailModel> unmappedPartnerDetails = unmappedPartners.stream().map(x -> partnerStats.get(x))
1483
				.collect(Collectors.toList());
26468 amit.gupta 1484
		PartnerDetailModel partnerDetailModel = partnerStatsService
1485
				.getAggregateStats(new ArrayList<>(partnerStats.values()));
27000 amit.gupta 1486
		authIdAndallValues.put(-1, partnerStatsService.getAggregateStats(unmappedPartnerDetails));
26460 amit.gupta 1487
		authIdAndallValues.put(0, partnerDetailModel);
26422 tejbeer 1488
		return authIdAndallValues;
1489
	}
1490
 
27579 tejbeer 1491
	@RequestMapping(value = "/getItemWiseTertiary", method = RequestMethod.GET)
1492
	public String getItemWiseTertiary(HttpServletRequest request,
1493
			@RequestParam(name = ProfitMandiConstants.FOFO_ID) int fofoId, Model model)
1494
			throws ProfitMandiBusinessException {
1495
		List<ItemWiseTertiaryModel> itemWiseTertiary = fofoOrderRepository.SelectItemWiseTertiary(fofoId);
1496
 
1497
		LOGGER.info("itemWiseTertiary" + itemWiseTertiary);
27586 tejbeer 1498
		CustomRetailer customRetailer = retailerService.getFofoRetailer(fofoId);
1499
		model.addAttribute("customRetailer", customRetailer);
27579 tejbeer 1500
		model.addAttribute("itemWiseTertiary", itemWiseTertiary);
1501
		return "item-wise-tertiary";
1502
	}
1503
 
27586 tejbeer 1504
	@RequestMapping(value = "/getItemWiseIndent", method = RequestMethod.GET)
1505
	public String getItemWiseIndent(HttpServletRequest request,
1506
			@RequestParam(name = ProfitMandiConstants.FOFO_ID) int fofoId, Model model)
1507
			throws ProfitMandiBusinessException {
1508
 
1509
		List<Order> unbilledOrders = transactionService.getInTransitOrders(fofoId);
1510
		model.addAttribute("unbilledOrders", unbilledOrders);
1511
 
1512
		return "item-wise-indent";
1513
	}
1514
 
27599 tejbeer 1515
	@RequestMapping(value = "/getPartnerPendingIndentItem", method = RequestMethod.GET)
1516
	public String getPartnerPendingIndentItem(HttpServletRequest request, @RequestParam int warehouseId,
1517
			@RequestParam int itemId, Model model) throws ProfitMandiBusinessException {
1518
		List<PartnerPendingIndentItemModel> partnerPendingIndent = fofoStoreRepository
1519
				.selectPartnerPendingIndentItem(itemId, warehouseId);
1520
 
1521
		model.addAttribute("partnerPendingIndent", partnerPendingIndent);
1522
		return "partner-pending-indent-item";
1523
	}
1524
 
27636 tejbeer 1525
	@RequestMapping(value = "/getPartnerInvestment", method = RequestMethod.GET)
1526
	public String getPartnerInvestment(HttpServletRequest request,
1527
			@RequestParam(name = ProfitMandiConstants.FOFO_ID) int fofoId, Model model) throws Exception {
1528
		Map<Integer, PartnerDetailModel> partnerStats = this.getPartnersStatDataFromFile();
1529
		PartnerDetailModel partnerDetailModel = partnerStats.get(fofoId);
1530
		CustomRetailer customRetailer = retailerService.getFofoRetailer(fofoId);
1531
		model.addAttribute("partnerDetailModel", partnerDetailModel);
1532
		model.addAttribute("customRetailer", customRetailer);
1533
		return "partner-investment";
1534
	}
1535
 
1536
	@RequestMapping(value = "/getPatnerActivateStock", method = RequestMethod.GET)
1537
	public String getPartnerActivateStockItem(HttpServletRequest request,
1538
			@RequestParam(name = ProfitMandiConstants.FOFO_ID) int fofoId, Model model) throws Exception {
1539
		List<ActivateItemModel> activateStocks = new ArrayList<>();
1540
		List<InventoryItem> inventoryItems = inventoryItemRepository.selectByActivatedNotSold(fofoId);
1541
		CustomRetailer customRetailer = retailerService.getFofoRetailer(fofoId);
1542
 
1543
		for (InventoryItem inventoryItem : inventoryItems) {
1544
			TagListing tagListing = tagListingRepository.selectByItemId(inventoryItem.getItemId());
1545
			Item item = itemRepository.selectById(inventoryItem.getItemId());
1546
			ActivateItemModel aim = new ActivateItemModel();
1547
			aim.setFofoId(inventoryItem.getFofoId());
1548
			aim.setQuantity(inventoryItem.getGoodQuantity());
1549
			aim.setAmount(tagListing.getSellingPrice());
1550
			aim.setItemDescription(item.getItemDescription());
1551
			aim.setItemId(inventoryItem.getItemId());
1552
			activateStocks.add(aim);
1553
		}
1554
 
1555
		model.addAttribute("activateStocks", activateStocks);
1556
		model.addAttribute("customRetailer", customRetailer);
1557
		return "partner-activate-stock";
1558
	}
1559
 
1560
	@RequestMapping(value = "/getPatnerBrandWiseMTDSale", method = RequestMethod.GET)
1561
	public String getPatnerBrandWiseMTDSale(HttpServletRequest request,
1562
			@RequestParam(name = ProfitMandiConstants.FOFO_ID) int fofoId, Model model) throws Exception {
1563
		LocalDateTime curDate = LocalDate.now().atStartOfDay();
1564
		CustomRetailer customRetailer = retailerService.getFofoRetailer(fofoId);
1565
		Map<String, Double> brandMtdAmount = fofoOrderItemRepository
1566
				.selectSumAmountGroupByBrand(curDate.withDayOfMonth(1), curDate.with(LocalTime.MAX), fofoId);
27638 tejbeer 1567
		Map<String, Long> brandMtdQty = fofoOrderItemRepository.selectSumQuantityGroupByBrand(curDate.withDayOfMonth(1),
1568
				curDate.with(LocalTime.MAX), fofoId);
27636 tejbeer 1569
		Double accesoriesmtdsale = fofoOrderRepository.selectSumSaleGroupByFofoIdsForMobileOrAccessories(fofoId,
1570
				curDate.withDayOfMonth(1), curDate.with(LocalTime.MAX), Optional.of(false)).get(fofoId);
27638 tejbeer 1571
		Long accesoriesmtdqty = fofoOrderRepository.selectSumSaleQuantityGroupByFofoIdsForMobileOrAccessories(fofoId,
1572
				curDate.withDayOfMonth(1), curDate.with(LocalTime.MAX), Optional.of(false)).get(fofoId);
1573
 
27636 tejbeer 1574
		LOGGER.info("accesoriesmtdsale" + accesoriesmtdsale);
1575
		model.addAttribute("brandMtdAmount", brandMtdAmount);
27638 tejbeer 1576
		model.addAttribute("brandMtdQty", brandMtdQty);
27636 tejbeer 1577
		model.addAttribute("accesoriesmtdsale", accesoriesmtdsale);
27638 tejbeer 1578
		model.addAttribute("accesoriesmtdqty", accesoriesmtdqty);
1579
 
27636 tejbeer 1580
		model.addAttribute("customRetailer", customRetailer);
1581
		return "partner-brand-mtd-sale";
1582
	}
1583
 
27637 tejbeer 1584
	@RequestMapping(value = "/getPatnerBrandWiseLMTDSale", method = RequestMethod.GET)
1585
	public String getPatnerBrandWiseLMTDSale(HttpServletRequest request,
1586
			@RequestParam(name = ProfitMandiConstants.FOFO_ID) int fofoId, Model model) throws Exception {
1587
		LocalDateTime curDate = LocalDate.now().atStartOfDay();
1588
		CustomRetailer customRetailer = retailerService.getFofoRetailer(fofoId);
1589
		Map<String, Double> brandLMtdAmount = fofoOrderItemRepository.selectSumAmountGroupByBrand(
1590
				curDate.withDayOfMonth(1).minusMonths(1), curDate.with(LocalTime.MAX).minusMonths(1), fofoId);
27638 tejbeer 1591
		Map<String, Long> brandLmtdQty = fofoOrderItemRepository.selectSumQuantityGroupByBrand(
1592
				curDate.withDayOfMonth(1).minusMonths(1), curDate.with(LocalTime.MAX).minusMonths(1), fofoId);
27637 tejbeer 1593
 
1594
		Double accesorieslmtdsale = fofoOrderRepository
1595
				.selectSumSaleGroupByFofoIdsForMobileOrAccessories(fofoId, curDate.withDayOfMonth(1).minusMonths(1),
1596
						curDate.with(LocalTime.MAX).minusMonths(1), Optional.of(false))
1597
				.get(fofoId);
27638 tejbeer 1598
		Long accesorieslmtdqty = fofoOrderRepository.selectSumSaleQuantityGroupByFofoIdsForMobileOrAccessories(fofoId,
1599
				curDate.withDayOfMonth(1).minusMonths(1), curDate.with(LocalTime.MAX).minusMonths(1),
1600
				Optional.of(false)).get(fofoId);
1601
 
27637 tejbeer 1602
		model.addAttribute("brandLMtdAmount", brandLMtdAmount);
27638 tejbeer 1603
		model.addAttribute("brandLmtdQty", brandLmtdQty);
1604
		model.addAttribute("accesorieslmtdqty", accesorieslmtdqty);
27637 tejbeer 1605
		model.addAttribute("accesorieslmtdsale", accesorieslmtdsale);
1606
		model.addAttribute("customRetailer", customRetailer);
1607
		return "partner-brand-lmtd-sale";
1608
	}
1609
 
27640 tejbeer 1610
	@RequestMapping(value = "/getPatnerInStock", method = RequestMethod.GET)
1611
	public String getPatnerInStock(HttpServletRequest request,
1612
			@RequestParam(name = ProfitMandiConstants.FOFO_ID) int fofoId, Model model) throws Exception {
1613
 
1614
		CustomRetailer customRetailer = retailerService.getFofoRetailer(fofoId);
1615
 
1616
		List<InStockBrandModel> mobileStock = currentInventorySnapshotRepository
1617
				.selectSumInStockMobileGroupByBrand(fofoId);
1618
 
1619
		List<InStockBrandModel> assStock = currentInventorySnapshotRepository
1620
				.selectSumInStockAccessoriesGroupByBrand(fofoId);
1621
 
1622
		model.addAttribute("mobileStock", mobileStock);
1623
		model.addAttribute("assStock", assStock);
1624
		model.addAttribute("customRetailer", customRetailer);
1625
		return "partner-instock-item";
1626
	}
1627
 
21615 kshitij.so 1628
}