Subversion Repositories SmartDukaan

Rev

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