Subversion Repositories SmartDukaan

Rev

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