Subversion Repositories SmartDukaan

Rev

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