Subversion Repositories SmartDukaan

Rev

Rev 28472 | Rev 28641 | 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);
28485 amit.gupta 376
				model.addAttribute("maa", loginDetails.getFofoId()==175138885);
377
 
28468 tejbeer 378
				model.addAttribute("hasGift", fofoUser.hasGift(loginDetails.getFofoId()));
25180 amit.gupta 379
				model.addAttribute("giftItemId", ProfitMandiConstants.GIFT_ID);
26222 tejbeer 380
				model.addAttribute("retailers", new JSONObject().append("code", fofoStore.getCode())
26162 amit.gupta 381
						.append("partnerId", fofoStore.getId()).toString());
26460 amit.gupta 382
				model.addAttribute("activatedImeis",
383
						inventoryItemRepository.selectCountByActivatedNotSold(loginDetails.getFofoId()));
26071 tejbeer 384
				LocalDateTime curDate = LocalDate.now().atStartOfDay();
385
				Map<Integer, Double> accesoriesmtdsale = fofoOrderRepository
386
						.selectSumSaleGroupByFofoIdsForMobileOrAccessories(loginDetails.getFofoId(),
387
								curDate.withDayOfMonth(1), curDate.with(LocalTime.MAX), Optional.of(false));
27701 tejbeer 388
 
26071 tejbeer 389
				Double accesoriesStock = currentInventorySnapshotRepository
390
						.selectSumStockGroupByFofoIdsForMobileOrAccessories(loginDetails.getFofoId(),
391
								Optional.of(false))
392
						.get(loginDetails.getFofoId());
25180 amit.gupta 393
 
26071 tejbeer 394
				model.addAttribute("accesoriesStock", String.format("%.0f", accesoriesStock));
28468 tejbeer 395
				model.addAttribute("brandStockPrices", fofoUser.getBrandStockPrices(loginDetails.getFofoId()));
396
				model.addAttribute("salesMap", fofoUser.getSales(loginDetails.getFofoId()));
397
				ChartModel cm = fofoUser.getBrandChart(loginDetails.getFofoId());
26055 tejbeer 398
 
399
				LOGGER.info("chartMap" + gson.toJson(cm));
400
				model.addAttribute("chartMap", gson.toJson(cm));
27701 tejbeer 401
 
27876 amit.gupta 402
				List<CreateOfferRequest> publishedOffers = offerService.getPublishedOffers(loginDetails.getFofoId(),
403
						YearMonth.from(LocalDateTime.now()));
404
				model.addAttribute("publishedOffers", publishedOffers);
28468 tejbeer 405
				model.addAttribute("investments", fofoUser.getInvestments(loginDetails.getFofoId()));
25544 amit.gupta 406
				model.addAttribute("isInvestmentOk", partnerInvestmentService.isInvestmentOk(loginDetails.getFofoId(),
407
						10, ProfitMandiConstants.CUTOFF_INVESTMENT));
26460 amit.gupta 408
 
25180 amit.gupta 409
			} catch (ProfitMandiBusinessException e) {
410
				LOGGER.error("FofoStore Code not found of fofoId {}", loginDetails.getFofoId());
411
 
412
			}
22481 ashik.ali 413
		}
25649 tejbeer 414
 
415
		LocalDateTime currentMonthStart = LocalDateTime.now().withDayOfMonth(1);
25747 amit.gupta 416
		LocalDateTime lastMonthStart = currentMonthStart.minusMonths(1);
25653 amit.gupta 417
		LocalDateTime currentMonthEnd = currentMonthStart.plusMonths(1).withDayOfMonth(1);
418
		double currentMonthRating = hygieneDataRepository.selectRatingAvg(loginDetails.getFofoId(), currentMonthStart,
25677 amit.gupta 419
				currentMonthEnd) / 2;
25747 amit.gupta 420
		double lastMonthRating = hygieneDataRepository.selectRatingAvg(loginDetails.getFofoId(), lastMonthStart,
421
				currentMonthStart) / 2;
422
		double ratingTillDate = hygieneDataRepository.selectRatingAvg(loginDetails.getFofoId(), LocalDateTime.MIN,
25677 amit.gupta 423
				currentMonthEnd) / 2;
424
		model.addAttribute("currentMonthRating", (float) Math.round(currentMonthRating * 10) / 10);
425
		model.addAttribute("lastMonthRating", (float) Math.round(lastMonthRating * 10) / 10);
426
		model.addAttribute("ratingTillDate", (float) Math.round(ratingTillDate * 10) / 10);
25649 tejbeer 427
 
25653 amit.gupta 428
		long hygieneCount = hygieneDataRepository.selectHygieneCount(loginDetails.getFofoId(), true, currentMonthStart,
429
				currentMonthEnd);
25651 tejbeer 430
 
25653 amit.gupta 431
		long invalidHygieneCount = hygieneDataRepository.selectHygieneCount(loginDetails.getFofoId(), false,
432
				currentMonthStart, currentMonthEnd);
433
		if (hygieneCount == 0 && invalidHygieneCount == 0) {
434
			invalidHygieneCount = 1;
435
		}
28272 tejbeer 436
		Map<Integer, String> monthValueMap = new HashMap<>();
437
		for (int i = 0; i <= 5; i++) {
438
			LocalDateTime startOfMonth = LocalDateTime.now().withDayOfMonth(1).minusMonths(i);
439
			monthValueMap.put(i, startOfMonth.format(DateTimeFormatter.ofPattern("MMM''uu")));
440
		}
441
 
442
		model.addAttribute("monthValueMap", monthValueMap);
443
		model.addAttribute("month", 0);
444
 
25653 amit.gupta 445
		model.addAttribute("hygienePercentage", (hygieneCount * 100) / (invalidHygieneCount + hygieneCount));
25651 tejbeer 446
 
25197 amit.gupta 447
		model.addAttribute("monthDays", LocalDate.now().minusDays(1).lengthOfMonth());
448
		model.addAttribute("dayOfMonth", LocalDate.now().minusDays(1).getDayOfMonth());
27884 tejbeer 449
		/*
450
		 * if (loginDetails.isReadOnly()) { return "dashboard-readonly"; } else { }
451
		 */
28430 tejbeer 452
 
27882 amit.gupta 453
		return "dashboard1";
28272 tejbeer 454
 
21615 kshitij.so 455
	}
23923 amit.gupta 456
 
28272 tejbeer 457
	@RequestMapping(value = "/getMonthsInvestment", method = RequestMethod.GET)
458
	public String getMonthsInvestment(HttpServletRequest request,
459
			@RequestParam(name = "month", required = true, defaultValue = "0") int month, Model model)
460
			throws Exception {
461
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
462
		int fofoId = loginDetails.getFofoId();
28468 tejbeer 463
		Map<String, Object> investment = fofoUser.getInvestmentsMonths(fofoId, month);
28430 tejbeer 464
 
28272 tejbeer 465
		LocalDateTime currentMonthStart = LocalDateTime.now().withDayOfMonth(1);
466
		LocalDateTime lastMonthStart = currentMonthStart.minusMonths(1);
467
		LocalDateTime currentMonthEnd = currentMonthStart.plusMonths(1).withDayOfMonth(1);
468
		double currentMonthRating = hygieneDataRepository.selectRatingAvg(loginDetails.getFofoId(), currentMonthStart,
469
				currentMonthEnd) / 2;
470
		double lastMonthRating = hygieneDataRepository.selectRatingAvg(loginDetails.getFofoId(), lastMonthStart,
471
				currentMonthStart) / 2;
472
		double ratingTillDate = hygieneDataRepository.selectRatingAvg(loginDetails.getFofoId(), LocalDateTime.MIN,
473
				currentMonthEnd) / 2;
474
		model.addAttribute("currentMonthRating", (float) Math.round(currentMonthRating * 10) / 10);
475
		model.addAttribute("lastMonthRating", (float) Math.round(lastMonthRating * 10) / 10);
476
		model.addAttribute("ratingTillDate", (float) Math.round(ratingTillDate * 10) / 10);
477
 
28430 tejbeer 478
		long hygieneCount = hygieneDataRepository.selectHygieneCount(loginDetails.getFofoId(), true,
479
				currentMonthStart.minusMonths(month), currentMonthEnd.minusMonths(month));
28272 tejbeer 480
 
481
		long invalidHygieneCount = hygieneDataRepository.selectHygieneCount(loginDetails.getFofoId(), false,
28430 tejbeer 482
				currentMonthStart.minusMonths(month), currentMonthEnd.minusMonths(month));
28272 tejbeer 483
		if (hygieneCount == 0 && invalidHygieneCount == 0) {
484
			invalidHygieneCount = 1;
485
		}
486
		Map<Integer, String> monthValueMap = new HashMap<>();
487
		for (int i = 0; i <= 5; i++) {
488
			LocalDateTime startOfMonth = LocalDateTime.now().withDayOfMonth(1).minusMonths(i);
489
			monthValueMap.put(i, startOfMonth.format(DateTimeFormatter.ofPattern("MMM''uu")));
490
		}
491
		model.addAttribute("hygienePercentage", (hygieneCount * 100) / (invalidHygieneCount + hygieneCount));
28430 tejbeer 492
		model.addAttribute("monthValueMap", monthValueMap);
28272 tejbeer 493
		model.addAttribute("investments", investment);
494
		model.addAttribute("monthDays", LocalDate.now().minusMonths(month).lengthOfMonth());
495
		model.addAttribute("dayOfMonth", LocalDate.now().minusMonths(month).lengthOfMonth());
28430 tejbeer 496
		model.addAttribute("month", month);
28272 tejbeer 497
		return "performance";
498
	}
499
 
27884 tejbeer 500
	@RequestMapping(value = "/investmentDetails", method = RequestMethod.GET)
501
	public String getInvestmentDetails(HttpServletRequest request, Model model) throws Exception {
502
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
503
		int fofoId = loginDetails.getFofoId();
28468 tejbeer 504
		ChartInvestmentModel cm = fofoUser.getInvestmentChart(fofoId);
27884 tejbeer 505
		model.addAttribute("chartPieMap", gson.toJson(cm));
506
 
507
		LOGGER.info("InvestmentChart" + gson.toJson(cm));
508
		LOGGER.info("InvestmentChart" + cm);
509
		return "investmentdetails";
510
	}
511
 
28430 tejbeer 512
	@RequestMapping(value = "/getlmsLineChart", method = RequestMethod.GET)
513
	public String getlmsLineChart(HttpServletRequest request, Model model) throws Exception {
514
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
515
		int fofoId = loginDetails.getFofoId();
28468 tejbeer 516
		ChartModel cm = fofoUser.getLmsLineChart(loginDetails.getFofoId());
28430 tejbeer 517
 
518
		LOGGER.info("linechartMap" + gson.toJson(cm));
519
		model.addAttribute("linechartMap", gson.toJson(cm));
520
		return "lmsLineChart";
521
	}
522
 
28439 tejbeer 523
	@RequestMapping(value = "/getMonthlyPurchaseLineChart", method = RequestMethod.GET)
524
	public String getMonthlyPurchaseLineChart(HttpServletRequest request, Model model) throws Exception {
525
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
526
		int fofoId = loginDetails.getFofoId();
28468 tejbeer 527
		ChartModel cm = fofoUser.getPurchaseOrderChart(fofoId);
28439 tejbeer 528
 
529
		LOGGER.info("chartMap" + gson.toJson(cm));
530
		model.addAttribute("chartMap", gson.toJson(cm));
531
 
532
		return "purchase_chart";
533
	}
534
 
28430 tejbeer 535
	@RequestMapping(value = "/getBarChart", method = RequestMethod.GET)
536
	public String getBarChart(HttpServletRequest request, Model model) throws Exception {
537
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
538
		int fofoId = loginDetails.getFofoId();
28468 tejbeer 539
		ChartModel cm = fofoUser.getBrandChart(fofoId);
28430 tejbeer 540
 
541
		LOGGER.info("chartMap" + gson.toJson(cm));
542
		model.addAttribute("chartMap", gson.toJson(cm));
543
 
544
		return "bar_chart";
545
	}
546
 
28455 tejbeer 547
	@RequestMapping(value = "/getPriceDropDetails", method = RequestMethod.GET)
548
	public String getPriceDropDetails(HttpServletRequest request,
549
			@RequestParam(name = "fofoId", required = true, defaultValue = "0") int fofoId,
550
			@RequestParam(name = "brand", required = true, defaultValue = "0") String brand,
551
			@RequestParam(name = "yearMonth", required = true, defaultValue = "0") String yearMonth, Model model)
552
			throws Exception {
553
 
554
		LOGGER.info("params" + fofoId + brand + yearMonth);
555
 
556
		List<PriceDropWithDetailsByYearMonthModel> priceDropdetailsList = priceDropRepository
557
				.selectBrandPendingPriceDropWithDetailsByYearMonth(fofoId, brand, yearMonth);
558
 
559
		LOGGER.info("priceDropdetailsList" + priceDropdetailsList);
560
 
561
		model.addAttribute("priceDropdetailsList", priceDropdetailsList);
562
 
563
		return "price-drop-details";
564
	}
565
 
566
	@RequestMapping(value = "/getMonthlyPriceDrop", method = RequestMethod.GET)
567
	public String getMonthlyPriceDropTabular(HttpServletRequest request, Model model) throws Exception {
568
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
569
		int fofoId = loginDetails.getFofoId();
570
		LocalDateTime curDate = LocalDate.now().atStartOfDay();
571
 
572
		LocalDateTime startOfMonth = curDate.withDayOfMonth(1).minusMonths(6);
573
 
574
		List<YearMonth> ym = new ArrayList<YearMonth>();
575
 
576
		for (int i = 1; i <= 6; i++) {
577
			ym.add(YearMonth.from(curDate.withDayOfMonth(1).minusMonths(i)));
578
		}
579
		Collections.reverse(ym);
580
		model.addAttribute("ym", ym);
581
		LOGGER.info("ym" + ym);
582
 
583
		List<PriceDropYearMonthModel> priceDropYearMonthModels = priceDropRepository
584
				.selectBrandPendingPriceDropByYearMonth(fofoId, startOfMonth);
585
 
586
		DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("MM-yyyy");
587
 
588
		Map<String, Map<YearMonth, Double>> brandMonthValue = new HashMap<>();
589
		LOGGER.info("priceDropYearMonthModels" + priceDropYearMonthModels);
590
		for (PriceDropYearMonthModel pdm : priceDropYearMonthModels) {
591
 
592
			Map<YearMonth, Double> brandValue = new HashMap<>();
593
			if (brandMonthValue.containsKey(pdm.getBrand())) {
594
				brandValue = brandMonthValue.get(pdm.getBrand());
595
				brandValue.put(YearMonth.parse(pdm.getYearMonth(), dateTimeFormatter), (double) pdm.getAmount());
596
			} else {
597
 
598
				brandValue.put(YearMonth.parse(pdm.getYearMonth(), dateTimeFormatter), (double) pdm.getAmount());
599
 
600
			}
601
			brandMonthValue.put(pdm.getBrand(), brandValue);
602
		}
603
		List<String> brands = new ArrayList<>();
604
		brands.add("Accessories");
605
		brands.add("Oppo");
606
		brands.add("Vivo");
607
		brands.add("Samsung");
608
		brands.add("Realme");
28462 tejbeer 609
		brands.add("MI");
28455 tejbeer 610
		brands.add("Tecno");
611
		brands.add("Itel");
612
		brands.add("Nokia");
613
		Map<String, List<Double>> sortedBrandValue = new LinkedHashMap<>();
614
 
615
		for (String brand : brands) {
616
			Map<YearMonth, Double> yearMonthValue = brandMonthValue.get(brand);
617
			for (int i = 6; i >= 1; i--) {
618
 
619
				LocalDateTime startMonth = curDate.withDayOfMonth(1).minusMonths(i);
620
 
621
				if (yearMonthValue != null) {
622
					if (yearMonthValue.get(YearMonth.from(startMonth)) == null) {
623
						yearMonthValue.put(YearMonth.from(startMonth), 0.0);
624
					}
625
 
626
				} else {
627
					yearMonthValue = new HashMap<>();
628
					yearMonthValue.put(YearMonth.from(startMonth), 0.0);
629
				}
630
			}
631
 
632
			Map<YearMonth, Double> sortedMonthBrandValue = new TreeMap<>(yearMonthValue);
633
 
634
			brandMonthValue.put(brand, sortedMonthBrandValue);
635
 
636
			sortedBrandValue.put(brand, sortedMonthBrandValue.values().stream().collect(Collectors.toList()));
637
 
638
		}
639
 
640
		Map<String, List<Double>> brandValues = new LinkedHashMap<>();
641
 
642
		for (Entry<String, List<Double>> vv : sortedBrandValue.entrySet()) {
643
 
644
			Double total = vv.getValue().stream().mapToDouble(x -> x.doubleValue()).sum();
645
 
646
			if (total != 0.0) {
647
				brandValues.put(vv.getKey(), vv.getValue());
648
 
649
			}
650
 
651
			LOGGER.info("total" + total);
652
		}
653
 
654
		LOGGER.info("sortedBrandValue" + brandValues);
655
		model.addAttribute("fofoId", fofoId);
656
 
657
		model.addAttribute("sortedBrandValue", brandValues);
658
 
659
		return "price-drop-tabular";
660
	}
661
 
26468 amit.gupta 662
	@RequestMapping(value = "/getAuthUserPartners", method = RequestMethod.GET)
26418 tejbeer 663
	public String AuthUserPartnersDetail(HttpServletRequest request, Model model, @RequestParam int authId)
664
			throws Exception {
665
 
666
		Map<Integer, List<Integer>> pp = csService.getAuthUserIdPartnerIdMapping();
26963 amit.gupta 667
		Map<Integer, CustomRetailer> fofoIdAndPartnerMap = retailerService.getFofoRetailers(false);
26418 tejbeer 668
 
26468 amit.gupta 669
		Map<Integer, PartnerDetailModel> fofoIdAndallValues = partnerStatsService.getAllPartnerStats();
670
		if (authId != 0) {
671
			List<Integer> fofoIds = pp.get(authId);
672
			fofoIdAndallValues = fofoIdAndallValues.entrySet().stream().filter(x -> fofoIds.contains(x.getKey()))
673
					.collect(Collectors.toMap(x -> x.getKey(), x -> x.getValue()));
26474 amit.gupta 674
		} else {
26418 tejbeer 675
		}
676
 
677
		model.addAttribute("fofoIdAndallValues", fofoIdAndallValues);
678
		model.addAttribute("fofoIdAndPartnerMap", fofoIdAndPartnerMap);
679
 
680
		return "auth_user_partner_detail";
26468 amit.gupta 681
	}
26418 tejbeer 682
 
27545 tejbeer 683
	@RequestMapping(value = "/getWarehousePartners", method = RequestMethod.GET)
684
	public String warehousePartnersDetail(HttpServletRequest request, Model model, @RequestParam int warehouseId)
685
			throws Exception {
27701 tejbeer 686
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
687
		String email = loginDetails.getEmailId();
28472 tejbeer 688
 
689
		Set<Integer> authfofoIds = new HashSet<>();
27701 tejbeer 690
		Map<String, Set<Integer>> storeGuyMap = csService.getAuthUserPartnerIdMapping();
28472 tejbeer 691
		authfofoIds = storeGuyMap.get(email);
27545 tejbeer 692
 
28472 tejbeer 693
		AuthUser authUser = authRepository.selectByEmailOrMobile(email);
694
		if (authfofoIds == null) {
695
			List<Position> positions1 = positionRepository.selectAll(authUser.getId());
696
			if (positions1.stream().filter(x -> x.getCategoryId() == ProfitMandiConstants.TICKET_CATEGORY_MASTER)
697
					.count() > 0) {
698
				authfofoIds = csService.getPositionCustomRetailerMap(positions1).values().stream()
699
						.flatMap(x -> x.stream()).map(x -> x.getPartnerId()).collect(Collectors.toSet());
700
			}
701
		}
27701 tejbeer 702
		Map<Integer, List<Integer>> warehouseIdFofoIdMap = fofoStoreRepository
703
				.selectActivePartnersByRetailerIds(new ArrayList<>(authfofoIds)).stream().collect(Collectors.groupingBy(
704
						FofoStore::getWarehouseId, Collectors.mapping(FofoStore::getId, Collectors.toList())));
705
 
27545 tejbeer 706
		Map<Integer, CustomRetailer> fofoIdAndPartnerMap = retailerService.getFofoRetailers(false);
28468 tejbeer 707
		Map<Integer, PartnerDetailModel> fofoIdAndallValues = adminUser.getPartnersStatDataFromFile();
27545 tejbeer 708
		if (warehouseId != 0) {
27701 tejbeer 709
			List<Integer> fofoIds = warehouseIdFofoIdMap.get(warehouseId);
710
			/*
711
			 * List<Integer> fofoIds =
712
			 * fofoStoreRepository.selectActivePartnerByWarehouse(warehouseId).stream()
713
			 * .map(x -> x.getId()).collect(Collectors.toList());
714
			 */
27545 tejbeer 715
			fofoIdAndallValues = fofoIdAndallValues.entrySet().stream().filter(x -> fofoIds.contains(x.getKey()))
716
					.collect(Collectors.toMap(x -> x.getKey(), x -> x.getValue()));
717
		} else {
28472 tejbeer 718
 
719
			List<Integer> fofoIds = new ArrayList<>(authfofoIds);
720
			fofoIdAndallValues = fofoIdAndallValues.entrySet().stream().filter(x -> fofoIds.contains(x.getKey()))
27701 tejbeer 721
					.collect(Collectors.toMap(x -> x.getKey(), x -> x.getValue()));
27545 tejbeer 722
		}
723
 
724
		model.addAttribute("fofoIdAndallValues", fofoIdAndallValues);
725
		model.addAttribute("fofoIdAndPartnerMap", fofoIdAndPartnerMap);
726
 
727
		return "auth_user_partner_detail";
728
	}
729
 
27509 tejbeer 730
	@RequestMapping(value = "/getWarehouseWiseBrandStock", method = RequestMethod.GET)
27701 tejbeer 731
	public String getWarehouseWiseBrandStock(HttpServletRequest request, Model model,
732
			@RequestParam List<Integer> warehouseId) throws Exception {
733
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
734
		String email = loginDetails.getEmailId();
735
		Map<String, Set<Integer>> storeGuyMap = csService.getAuthUserPartnerIdMapping();
736
		Set<Integer> authfofoIds = storeGuyMap.get(email);
28471 tejbeer 737
		AuthUser authUser = authRepository.selectByEmailOrMobile(email);
27509 tejbeer 738
 
28471 tejbeer 739
		if (authfofoIds == null) {
740
			List<Position> positions1 = positionRepository.selectAll(authUser.getId());
741
			if (positions1.stream().filter(x -> x.getCategoryId() == ProfitMandiConstants.TICKET_CATEGORY_MASTER)
742
					.count() > 0) {
743
				authfofoIds = csService.getPositionCustomRetailerMap(positions1).values().stream()
744
						.flatMap(x -> x.stream()).map(x -> x.getPartnerId()).collect(Collectors.toSet());
745
			}
746
		}
747
 
27701 tejbeer 748
		Map<Integer, List<Integer>> warehouseIdFofoIdMap = fofoStoreRepository
749
				.selectActivePartnersByRetailerIds(new ArrayList<>(authfofoIds)).stream().collect(Collectors.groupingBy(
750
						FofoStore::getWarehouseId, Collectors.mapping(FofoStore::getId, Collectors.toList())));
751
		List<WarehouseWiseBrandStockModel> warehouseWiseBrandStock = new ArrayList<>();
752
		if (!warehouseId.contains(0)) {
753
			warehouseWiseBrandStock = saholicInventoryCISRepository.selectGroupByWarehouseAndBrand(warehouseId);
754
		} else {
755
			LOGGER.info("warehouseIdFofoIdMap" + warehouseIdFofoIdMap.keySet());
756
			warehouseWiseBrandStock = saholicInventoryCISRepository
757
					.selectGroupByWarehouseAndBrand(new ArrayList<>(warehouseIdFofoIdMap.keySet()));
758
 
759
		}
27542 tejbeer 760
		Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
27509 tejbeer 761
		model.addAttribute("warehouseWiseBrandStock", warehouseWiseBrandStock);
27542 tejbeer 762
		model.addAttribute("warehouseId", warehouseId);
27509 tejbeer 763
		model.addAttribute("warehouseMap", warehouseMap);
27660 tejbeer 764
 
27509 tejbeer 765
		return "warehouse_brand_stock";
766
	}
767
 
27529 tejbeer 768
	@RequestMapping(value = "/getWarehouseWiseData", method = RequestMethod.GET)
769
	public String getWarehouseWiseData(HttpServletRequest request, Model model) throws Exception {
770
		inventoryService.getItemAvailabilityAndIndent();
771
		model.addAttribute("response", mvcResponseSender.createResponseString(true));
772
		return "response";
773
	}
774
 
27628 tejbeer 775
	@RequestMapping(value = "/getPartnersStatData", method = RequestMethod.GET)
776
	public String getPartnersStatData(HttpServletRequest request, Model model) throws Exception {
777
		Map<Integer, PartnerDetailModel> partnerStats = partnerStatsService.getAllPartnerStats();
778
		ObjectOutputStream oos = null;
779
		FileOutputStream fout = null;
780
		try {
781
			fout = new FileOutputStream("/tmp/partnerStat.tmp", false);
782
			oos = new ObjectOutputStream(fout);
783
			oos.writeObject(partnerStats);
784
 
785
		} catch (Exception ex) {
786
			ex.printStackTrace();
787
		} finally {
788
			if (oos != null) {
789
				oos.close();
790
			}
791
		}
792
		ReporticoCacheTable rct = reporticoCacheTableRepository.selectByTableName("partnerStat");
793
		if (rct == null) {
794
			rct = new ReporticoCacheTable();
795
			rct.setTableName("partnerStat");
796
 
797
		}
798
		rct.setLastCreatedTimestamp(LocalDateTime.now());
799
		reporticoCacheTableRepository.persist(rct);
800
		model.addAttribute("response", mvcResponseSender.createResponseString(true));
801
		return "response";
802
	}
803
 
27539 tejbeer 804
	@RequestMapping(value = "/getWarehouseWiseBrandAndCategory", method = RequestMethod.GET)
805
	public String getWarehouseWiseBrandAndCategory(HttpServletRequest request, Model model,
27538 tejbeer 806
			@RequestParam List<Integer> warehouseId, @RequestParam List<String> brands, @RequestParam String category)
807
			throws Exception {
27509 tejbeer 808
 
809
		Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
27529 tejbeer 810
		List<String> listbrands = saholicInventoryCISRepository.selectAllBrand();
27538 tejbeer 811
		List<String> listCategory = saholicInventoryCISRepository.selectAllSubCategory();
27539 tejbeer 812
 
27509 tejbeer 813
		model.addAttribute("warehouseMap", warehouseMap);
27529 tejbeer 814
		model.addAttribute("brands", listbrands);
27538 tejbeer 815
		model.addAttribute("listCategory", listCategory);
816
 
27529 tejbeer 817
		model.addAttribute("selectedBrand", brands);
27538 tejbeer 818
		model.addAttribute("selectedWarehouse", warehouseId);
27539 tejbeer 819
		model.addAttribute("selectedCategory", category);
820
 
27509 tejbeer 821
		return "warehouse_brand_item_stock";
822
	}
823
 
27538 tejbeer 824
	@RequestMapping(value = "/getWarehouseWiseItemStock", method = RequestMethod.GET)
825
	public String getWarehouseWiseItemStock(HttpServletRequest request, Model model,
826
			@RequestParam List<Integer> warehouseId, @RequestParam List<String> brands, @RequestParam String category)
827
			throws Exception {
27539 tejbeer 828
		Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
829
		if (warehouseId.contains(0)) {
830
			warehouseId.addAll(warehouseMap.keySet());
831
		}
27538 tejbeer 832
		List<WarehouseWiseitemStockModel> warehouseWiseItemStock = saholicInventoryCISRepository
833
				.selectWarehouseItemStock(warehouseId, brands, category);
27539 tejbeer 834
 
27538 tejbeer 835
		model.addAttribute("warehouseWiseItemStock", warehouseWiseItemStock);
836
		model.addAttribute("warehouseMap", warehouseMap);
837
		return "warehouse_item_details";
838
	}
839
 
27556 tejbeer 840
	@RequestMapping(value = "/getWarehouseWiseBrandPartnerSale", method = RequestMethod.GET)
27591 tejbeer 841
	public String getWarehouseWiseBrandPartnerSale(HttpServletRequest request, Model model, @RequestParam String brand)
842
			throws Exception {
27701 tejbeer 843
 
844
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
845
		String email = loginDetails.getEmailId();
846
		Map<String, Set<Integer>> storeGuyMap = csService.getAuthUserPartnerIdMapping();
847
		Set<Integer> authfofoIds = storeGuyMap.get(email);
848
 
28472 tejbeer 849
		AuthUser authUser = authRepository.selectByEmailOrMobile(email);
850
		if (authfofoIds == null) {
851
			List<Position> positions1 = positionRepository.selectAll(authUser.getId());
852
			if (positions1.stream().filter(x -> x.getCategoryId() == ProfitMandiConstants.TICKET_CATEGORY_MASTER)
853
					.count() > 0) {
854
				authfofoIds = csService.getPositionCustomRetailerMap(positions1).values().stream()
855
						.flatMap(x -> x.stream()).map(x -> x.getPartnerId()).collect(Collectors.toSet());
856
			}
857
		}
858
 
27670 tejbeer 859
		Map<Integer, WarehouseWiseBrandSaleModel> warehouseWiseBrandPartnerSales = fofoStoreRepository
27701 tejbeer 860
				.selectGroupByWarehouseBrandWisePartnerSale(brand, new ArrayList<>(authfofoIds)).stream()
27670 tejbeer 861
				.collect(Collectors.toMap(x -> x.getWarehouseId(), x -> x));
862
 
863
		List<WarehouseWiseBrandUnbilledActivatedModel> unbilledStock = fofoStoreRepository
27701 tejbeer 864
				.selectUnbilledActivateStockGroupByWarehouse(brand, new ArrayList<>(authfofoIds));
27670 tejbeer 865
 
866
		for (WarehouseWiseBrandUnbilledActivatedModel un : unbilledStock) {
867
			WarehouseWiseBrandSaleModel bpt = warehouseWiseBrandPartnerSales.get(un.getWarehouseId());
868
			if (bpt != null) {
869
				bpt.setAmtd(un.getUnbilledMtd());
27676 tejbeer 870
				bpt.setUamtdQty(un.getUnbilledQty());
27670 tejbeer 871
			} else {
872
				bpt = new WarehouseWiseBrandSaleModel();
873
				bpt.setWarehouseId(un.getWarehouseId());
874
				bpt.setAmtd(un.getUnbilledMtd());
27677 tejbeer 875
				bpt.setUamtdQty(un.getUnbilledQty());
27670 tejbeer 876
				bpt.setLms(0);
877
				bpt.setLmtd(0);
878
				bpt.setMtd(0);
879
				bpt.setMtdQty(0);
880
				bpt.setLmtd(0);
881
				bpt.setLmtdQty(0);
882
				warehouseWiseBrandPartnerSales.put(un.getWarehouseId(), bpt);
883
			}
884
		}
27556 tejbeer 885
		Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
27591 tejbeer 886
 
887
		Set<String> brands = inventoryService.getAllTagListingBrands();
888
		model.addAttribute("warehouseWiseBrandPartnerSales", warehouseWiseBrandPartnerSales);
27556 tejbeer 889
		model.addAttribute("warehouseMap", warehouseMap);
27591 tejbeer 890
		model.addAttribute("brands", brands);
891
		model.addAttribute("selectedbrand", brand);
892
		return "warehousewise_brand_partners_sale";
27556 tejbeer 893
	}
894
 
27594 tejbeer 895
	@RequestMapping(value = "/getWarehouseWiseAccesoriesBrandPartnerSale", method = RequestMethod.GET)
896
	public String getWarehouseWiseAccesoriesBrandPartnerSale(HttpServletRequest request, Model model,
897
			@RequestParam String brand) throws Exception {
27701 tejbeer 898
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
899
		String email = loginDetails.getEmailId();
900
		Map<String, Set<Integer>> storeGuyMap = csService.getAuthUserPartnerIdMapping();
901
		Set<Integer> authfofoIds = storeGuyMap.get(email);
28472 tejbeer 902
 
903
		AuthUser authUser = authRepository.selectByEmailOrMobile(email);
904
		if (authfofoIds == null) {
905
			List<Position> positions1 = positionRepository.selectAll(authUser.getId());
906
			if (positions1.stream().filter(x -> x.getCategoryId() == ProfitMandiConstants.TICKET_CATEGORY_MASTER)
907
					.count() > 0) {
908
				authfofoIds = csService.getPositionCustomRetailerMap(positions1).values().stream()
909
						.flatMap(x -> x.stream()).map(x -> x.getPartnerId()).collect(Collectors.toSet());
910
			}
911
		}
27594 tejbeer 912
		List<WarehouseWiseBrandSaleModel> warehouseWiseBrandPartnerSales = fofoStoreRepository
27701 tejbeer 913
				.selectGroupByWarehouseAccesoriesBrandWisePartnerSale(brand, new ArrayList<>(authfofoIds));
27594 tejbeer 914
		Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
915
 
916
		Set<String> brands = inventoryService.getAllTagListingBrands();
917
		model.addAttribute("warehouseWiseBrandPartnerSales", warehouseWiseBrandPartnerSales);
918
		model.addAttribute("warehouseMap", warehouseMap);
919
		model.addAttribute("brands", brands);
920
		model.addAttribute("selectedbrand", brand);
921
		return "warehousewise_accessoriesbrand_sale";
922
	}
923
 
27556 tejbeer 924
	@RequestMapping(value = "/getWarehouseBrandWiseItemSale", method = RequestMethod.GET)
925
	public String getWarehouseBrandWiseItemSale(HttpServletRequest request, Model model,
926
			@RequestParam List<Integer> warehouseId, @RequestParam String brand) throws Exception {
927
		Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
27701 tejbeer 928
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
929
		String email = loginDetails.getEmailId();
930
		Map<String, Set<Integer>> storeGuyMap = csService.getAuthUserPartnerIdMapping();
931
		Set<Integer> authfofoIds = storeGuyMap.get(email);
27670 tejbeer 932
		Map<Integer, WarehouseBrandWiseItemSaleModel> branditemSalesMap = fofoStoreRepository
27701 tejbeer 933
				.selectWarehouseBrandItemSale(warehouseId, brand, new ArrayList<>(authfofoIds)).stream()
27670 tejbeer 934
				.collect(Collectors.toMap(x -> x.getItemId(), x -> x));
935
 
936
		List<WarehouseBrandItemUnbilledActivatedModel> unbilledItems = fofoStoreRepository
27701 tejbeer 937
				.selectWarehouseBrandItemUnbilledActivateStock(warehouseId, brand, new ArrayList<>(authfofoIds));
27670 tejbeer 938
 
939
		for (WarehouseBrandItemUnbilledActivatedModel un : unbilledItems) {
940
			WarehouseBrandWiseItemSaleModel bpt = branditemSalesMap.get(un.getItemId());
941
			if (bpt != null) {
942
				bpt.setAmtd(un.getAmtd());
27676 tejbeer 943
				bpt.setUamtdQty(un.getUnmtdQty());
27670 tejbeer 944
			} else {
945
				bpt = new WarehouseBrandWiseItemSaleModel();
946
				bpt.setWarehouseId(un.getWarehouseId());
947
				bpt.setItemId(un.getItemId());
948
				bpt.setAmtd(un.getAmtd());
27677 tejbeer 949
				bpt.setUamtdQty(un.getUnmtdQty());
27670 tejbeer 950
				bpt.setBrand(un.getBrand());
951
				bpt.setModelName(un.getModelName());
952
				bpt.setModelNumber(un.getModelNumber());
953
				bpt.setColor(un.getColor());
954
				bpt.setLms(0);
955
				bpt.setLmtd(0);
956
				bpt.setMtd(0);
957
				bpt.setMtdQty(0);
958
				bpt.setLmtd(0);
959
				bpt.setLmtdQty(0);
960
				branditemSalesMap.put(un.getItemId(), bpt);
961
			}
962
		}
963
		model.addAttribute("branditemSales", branditemSalesMap);
27556 tejbeer 964
		model.addAttribute("warehouseMap", warehouseMap);
965
		return "warehouse_partner_itemwise_sale";
966
	}
967
 
27594 tejbeer 968
	@RequestMapping(value = "/getWarehouseAccesoriesBrandWiseItemSale", method = RequestMethod.GET)
969
	public String getWarehouseAccesoriesBrandWiseItemSale(HttpServletRequest request, Model model,
970
			@RequestParam List<Integer> warehouseId, @RequestParam String brand) throws Exception {
971
		Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
27701 tejbeer 972
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
973
		String email = loginDetails.getEmailId();
974
		Map<String, Set<Integer>> storeGuyMap = csService.getAuthUserPartnerIdMapping();
975
		Set<Integer> authfofoIds = storeGuyMap.get(email);
27594 tejbeer 976
		List<WarehouseBrandWiseItemSaleModel> branditemSales = fofoStoreRepository
27701 tejbeer 977
				.selectWarehouseAccesoriesBrandItemSale(warehouseId, brand, new ArrayList<>(authfofoIds));
27594 tejbeer 978
		model.addAttribute("branditemSales", branditemSales);
979
		model.addAttribute("warehouseMap", warehouseMap);
980
		return "warehouse_accessories_itemwsie_sale";
981
	}
982
 
22354 ashik.ali 983
	@RequestMapping(value = "/contactUs", method = RequestMethod.GET)
23923 amit.gupta 984
	public String contactUs(HttpServletRequest request, Model model) throws Throwable {
22354 ashik.ali 985
		model.addAttribute("appContextPath", request.getContextPath());
986
		return "contact-us";
987
	}
23923 amit.gupta 988
 
25649 tejbeer 989
	@RequestMapping(value = "/notifications", method = RequestMethod.GET)
25683 tejbeer 990
	public String getNotificationsWithType(HttpServletRequest request,
991
			@RequestParam(required = false) MessageType messageType,
25649 tejbeer 992
			@RequestParam(name = "offset", defaultValue = "0") int offset,
993
			@RequestParam(name = "limit", defaultValue = "20") int limit, Model model) throws Exception {
994
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
26060 tejbeer 995
		int userId = 0;
996
		boolean isAdmin = roleManager.isAdmin(loginDetails.getRoleIds());
997
		if (isAdmin) {
998
			userId = loginDetails.getFofoId();
999
		} else {
1000
			userId = userAccountRepository.selectUserIdByRetailerId(loginDetails.getFofoId());
1001
		}
25683 tejbeer 1002
		List<Notification> notifications = null;
1003
 
26086 tejbeer 1004
		List<NotificationCampaign> notificationCampaigns = notificationCampaignRepository.getNotifications(messageType,
1005
				userId, offset, limit);
1006
		LOGGER.info("messageType" + messageType);
28468 tejbeer 1007
		notifications = fofoUser.getNotifications(notificationCampaigns, messageType);
26086 tejbeer 1008
 
25683 tejbeer 1009
		model.addAttribute("notifications", notifications);
1010
 
1011
		LOGGER.info("notifications" + notifications);
1012
		return "notification-template";
1013
	}
1014
 
25651 tejbeer 1015
	@RequestMapping(value = "/notifyDocument/documentId", method = RequestMethod.GET)
1016
	public ResponseEntity<?> retailerDocumentById(HttpServletRequest request,
1017
			@RequestParam(name = ProfitMandiConstants.DOCUMENT_ID) int documentId, @RequestParam int cid)
1018
			throws ProfitMandiBusinessException {
1019
		Document document = documentRepository.selectById(documentId);
1020
		NotificationCampaign nc = notificationCampaignRepository.selectById(cid);
1021
		if (nc.getDocumentId() == null) {
1022
			throw new ProfitMandiBusinessException("cid", nc.getId(), "not available");
1023
		}
1024
		if (nc.getDocumentId() != documentId) {
1025
			throw new ProfitMandiBusinessException(ProfitMandiConstants.DOCUMENT_ID, documentId, "RTLR_1014");
1026
		}
1027
		return responseSender.ok(document);
25649 tejbeer 1028
	}
1029
 
25651 tejbeer 1030
	@RequestMapping(value = "/notifyDocument/download", method = RequestMethod.GET)
1031
	public ResponseEntity<?> downloadRetailerDocument(HttpServletRequest request, @RequestParam int cid, Model model)
1032
			throws ProfitMandiBusinessException {
1033
 
1034
		NotificationCampaign nc = notificationCampaignRepository.selectById(cid);
1035
 
1036
		if (nc.getDocumentId() == null) {
1037
			throw new ProfitMandiBusinessException("cid", nc.getId(), "not available");
1038
		}
1039
 
1040
		Document document = documentRepository.selectById(nc.getDocumentId());
1041
 
1042
		FileInputStream file = null;
1043
		try {
1044
			file = new FileInputStream(document.getPath() + File.separator + document.getName());
1045
		} catch (FileNotFoundException e) {
1046
			LOGGER.error("Retailer Document file not found : ", e);
1047
			throw new ProfitMandiBusinessException(ProfitMandiConstants.DOCUMENT_ID, document.getId(), "RTLR_1013");
1048
		}
1049
		// ByteArrayOutputStream byteArrayOutputStream = new
1050
		// ByteArrayOutputStream();
1051
		// ExcelUtils.writeSchemeModels(schemeModels, byteArrayOutputStream);
1052
 
1053
		final HttpHeaders headers = new HttpHeaders();
1054
		String contentType = "";
1055
		if (document.getContentType() == ContentType.JPEG) {
1056
			contentType = "image/jpeg";
1057
		} else if (document.getContentType() == ContentType.PNG) {
1058
			contentType = "image/png";
1059
		} else if (document.getContentType() == ContentType.PDF) {
1060
			contentType = "application/pdf";
1061
		}
1062
		headers.set("Content-Type", contentType);
1063
		headers.set("Content-disposition", "inline; filename=" + document.getName());
1064
		headers.setContentLength(document.getSize());
1065
		final InputStreamResource inputStreamResource = new InputStreamResource(file);
1066
		return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
1067
	}
26460 amit.gupta 1068
 
27579 tejbeer 1069
	@RequestMapping(value = "/getItemWiseTertiary", method = RequestMethod.GET)
1070
	public String getItemWiseTertiary(HttpServletRequest request,
1071
			@RequestParam(name = ProfitMandiConstants.FOFO_ID) int fofoId, Model model)
1072
			throws ProfitMandiBusinessException {
1073
		List<ItemWiseTertiaryModel> itemWiseTertiary = fofoOrderRepository.SelectItemWiseTertiary(fofoId);
1074
 
1075
		LOGGER.info("itemWiseTertiary" + itemWiseTertiary);
27586 tejbeer 1076
		CustomRetailer customRetailer = retailerService.getFofoRetailer(fofoId);
1077
		model.addAttribute("customRetailer", customRetailer);
27579 tejbeer 1078
		model.addAttribute("itemWiseTertiary", itemWiseTertiary);
1079
		return "item-wise-tertiary";
1080
	}
1081
 
27586 tejbeer 1082
	@RequestMapping(value = "/getItemWiseIndent", method = RequestMethod.GET)
1083
	public String getItemWiseIndent(HttpServletRequest request,
1084
			@RequestParam(name = ProfitMandiConstants.FOFO_ID) int fofoId, Model model)
1085
			throws ProfitMandiBusinessException {
1086
 
1087
		List<Order> unbilledOrders = transactionService.getInTransitOrders(fofoId);
1088
		model.addAttribute("unbilledOrders", unbilledOrders);
1089
 
1090
		return "item-wise-indent";
1091
	}
1092
 
27636 tejbeer 1093
	@RequestMapping(value = "/getPartnerInvestment", method = RequestMethod.GET)
1094
	public String getPartnerInvestment(HttpServletRequest request,
1095
			@RequestParam(name = ProfitMandiConstants.FOFO_ID) int fofoId, Model model) throws Exception {
28468 tejbeer 1096
		Map<Integer, PartnerDetailModel> partnerStats = adminUser.getPartnersStatDataFromFile();
27636 tejbeer 1097
		PartnerDetailModel partnerDetailModel = partnerStats.get(fofoId);
1098
		CustomRetailer customRetailer = retailerService.getFofoRetailer(fofoId);
1099
		model.addAttribute("partnerDetailModel", partnerDetailModel);
1100
		model.addAttribute("customRetailer", customRetailer);
1101
		return "partner-investment";
1102
	}
27727 tejbeer 1103
 
27704 amit.gupta 1104
	@RequestMapping(value = "/getPartnerPendingIndentItem", method = RequestMethod.GET)
1105
	public String getPartnerPendingIndentItem(HttpServletRequest request, @RequestParam int warehouseId,
1106
			@RequestParam int itemId, Model model) throws ProfitMandiBusinessException {
1107
		List<PartnerPendingIndentItemModel> partnerPendingIndent = fofoStoreRepository
1108
				.selectPartnerPendingIndentItem(itemId, warehouseId);
27636 tejbeer 1109
 
27704 amit.gupta 1110
		model.addAttribute("partnerPendingIndent", partnerPendingIndent);
1111
		return "partner-pending-indent-item";
1112
	}
1113
 
27636 tejbeer 1114
	@RequestMapping(value = "/getPatnerActivateStock", method = RequestMethod.GET)
1115
	public String getPartnerActivateStockItem(HttpServletRequest request,
1116
			@RequestParam(name = ProfitMandiConstants.FOFO_ID) int fofoId, Model model) throws Exception {
1117
		List<ActivateItemModel> activateStocks = new ArrayList<>();
1118
		List<InventoryItem> inventoryItems = inventoryItemRepository.selectByActivatedNotSold(fofoId);
1119
		CustomRetailer customRetailer = retailerService.getFofoRetailer(fofoId);
1120
 
1121
		for (InventoryItem inventoryItem : inventoryItems) {
1122
			TagListing tagListing = tagListingRepository.selectByItemId(inventoryItem.getItemId());
1123
			Item item = itemRepository.selectById(inventoryItem.getItemId());
1124
			ActivateItemModel aim = new ActivateItemModel();
1125
			aim.setFofoId(inventoryItem.getFofoId());
1126
			aim.setQuantity(inventoryItem.getGoodQuantity());
1127
			aim.setAmount(tagListing.getSellingPrice());
1128
			aim.setItemDescription(item.getItemDescription());
1129
			aim.setItemId(inventoryItem.getItemId());
1130
			activateStocks.add(aim);
1131
		}
1132
 
1133
		model.addAttribute("activateStocks", activateStocks);
1134
		model.addAttribute("customRetailer", customRetailer);
1135
		return "partner-activate-stock";
1136
	}
1137
 
1138
	@RequestMapping(value = "/getPatnerBrandWiseMTDSale", method = RequestMethod.GET)
1139
	public String getPatnerBrandWiseMTDSale(HttpServletRequest request,
1140
			@RequestParam(name = ProfitMandiConstants.FOFO_ID) int fofoId, Model model) throws Exception {
1141
		LocalDateTime curDate = LocalDate.now().atStartOfDay();
1142
		CustomRetailer customRetailer = retailerService.getFofoRetailer(fofoId);
1143
		Map<String, Double> brandMtdAmount = fofoOrderItemRepository
1144
				.selectSumAmountGroupByBrand(curDate.withDayOfMonth(1), curDate.with(LocalTime.MAX), fofoId);
27638 tejbeer 1145
		Map<String, Long> brandMtdQty = fofoOrderItemRepository.selectSumQuantityGroupByBrand(curDate.withDayOfMonth(1),
1146
				curDate.with(LocalTime.MAX), fofoId);
27636 tejbeer 1147
		Double accesoriesmtdsale = fofoOrderRepository.selectSumSaleGroupByFofoIdsForMobileOrAccessories(fofoId,
1148
				curDate.withDayOfMonth(1), curDate.with(LocalTime.MAX), Optional.of(false)).get(fofoId);
27638 tejbeer 1149
		Long accesoriesmtdqty = fofoOrderRepository.selectSumSaleQuantityGroupByFofoIdsForMobileOrAccessories(fofoId,
1150
				curDate.withDayOfMonth(1), curDate.with(LocalTime.MAX), Optional.of(false)).get(fofoId);
1151
 
27636 tejbeer 1152
		LOGGER.info("accesoriesmtdsale" + accesoriesmtdsale);
1153
		model.addAttribute("brandMtdAmount", brandMtdAmount);
27638 tejbeer 1154
		model.addAttribute("brandMtdQty", brandMtdQty);
27636 tejbeer 1155
		model.addAttribute("accesoriesmtdsale", accesoriesmtdsale);
27638 tejbeer 1156
		model.addAttribute("accesoriesmtdqty", accesoriesmtdqty);
1157
 
27636 tejbeer 1158
		model.addAttribute("customRetailer", customRetailer);
1159
		return "partner-brand-mtd-sale";
1160
	}
1161
 
27637 tejbeer 1162
	@RequestMapping(value = "/getPatnerBrandWiseLMTDSale", method = RequestMethod.GET)
1163
	public String getPatnerBrandWiseLMTDSale(HttpServletRequest request,
1164
			@RequestParam(name = ProfitMandiConstants.FOFO_ID) int fofoId, Model model) throws Exception {
1165
		LocalDateTime curDate = LocalDate.now().atStartOfDay();
1166
		CustomRetailer customRetailer = retailerService.getFofoRetailer(fofoId);
1167
		Map<String, Double> brandLMtdAmount = fofoOrderItemRepository.selectSumAmountGroupByBrand(
1168
				curDate.withDayOfMonth(1).minusMonths(1), curDate.with(LocalTime.MAX).minusMonths(1), fofoId);
27638 tejbeer 1169
		Map<String, Long> brandLmtdQty = fofoOrderItemRepository.selectSumQuantityGroupByBrand(
1170
				curDate.withDayOfMonth(1).minusMonths(1), curDate.with(LocalTime.MAX).minusMonths(1), fofoId);
27637 tejbeer 1171
 
1172
		Double accesorieslmtdsale = fofoOrderRepository
1173
				.selectSumSaleGroupByFofoIdsForMobileOrAccessories(fofoId, curDate.withDayOfMonth(1).minusMonths(1),
1174
						curDate.with(LocalTime.MAX).minusMonths(1), Optional.of(false))
1175
				.get(fofoId);
27638 tejbeer 1176
		Long accesorieslmtdqty = fofoOrderRepository.selectSumSaleQuantityGroupByFofoIdsForMobileOrAccessories(fofoId,
1177
				curDate.withDayOfMonth(1).minusMonths(1), curDate.with(LocalTime.MAX).minusMonths(1),
1178
				Optional.of(false)).get(fofoId);
1179
 
27637 tejbeer 1180
		model.addAttribute("brandLMtdAmount", brandLMtdAmount);
27638 tejbeer 1181
		model.addAttribute("brandLmtdQty", brandLmtdQty);
1182
		model.addAttribute("accesorieslmtdqty", accesorieslmtdqty);
27637 tejbeer 1183
		model.addAttribute("accesorieslmtdsale", accesorieslmtdsale);
1184
		model.addAttribute("customRetailer", customRetailer);
1185
		return "partner-brand-lmtd-sale";
1186
	}
1187
 
27660 tejbeer 1188
	@RequestMapping(value = "/getPatnerBrandWiseLMSSale", method = RequestMethod.GET)
1189
	public String getPatnerBrandWiseLMSSale(HttpServletRequest request,
1190
			@RequestParam(name = ProfitMandiConstants.FOFO_ID) int fofoId, Model model) throws Exception {
1191
		LocalDateTime curDate = LocalDate.now().atStartOfDay();
1192
		CustomRetailer customRetailer = retailerService.getFofoRetailer(fofoId);
1193
		int lengthOfMonth = YearMonth.from(curDate.minusMonths(1)).lengthOfMonth();
1194
 
1195
		Map<String, Double> brandLMSAmount = fofoOrderItemRepository.selectSumAmountGroupByBrand(
27893 tejbeer 1196
				curDate.withDayOfMonth(1).minusMonths(1), curDate.withDayOfMonth(1), fofoId);
27660 tejbeer 1197
		Map<String, Long> brandLmsQty = fofoOrderItemRepository.selectSumQuantityGroupByBrand(
27893 tejbeer 1198
				curDate.withDayOfMonth(1).minusMonths(1), curDate.withDayOfMonth(1), fofoId);
27660 tejbeer 1199
 
27893 tejbeer 1200
		Double accesorieslmssale = fofoOrderRepository.selectSumSaleGroupByFofoIdsForMobileOrAccessories(fofoId,
1201
				curDate.withDayOfMonth(1).minusMonths(1), curDate.withDayOfMonth(1), Optional.of(false)).get(fofoId);
27660 tejbeer 1202
		Long accesorieslmsqty = fofoOrderRepository
1203
				.selectSumSaleQuantityGroupByFofoIdsForMobileOrAccessories(fofoId,
27893 tejbeer 1204
						curDate.withDayOfMonth(1).minusMonths(1), curDate.withDayOfMonth(1), Optional.of(false))
27660 tejbeer 1205
				.get(fofoId);
1206
 
1207
		model.addAttribute("brandLMSAmount", brandLMSAmount);
1208
		model.addAttribute("brandLmsQty", brandLmsQty);
1209
		model.addAttribute("accesorieslmssale", accesorieslmssale);
1210
		model.addAttribute("accesorieslmsqty", accesorieslmsqty);
1211
		model.addAttribute("customRetailer", customRetailer);
1212
		return "partner-brand-lms-sale";
1213
	}
1214
 
27640 tejbeer 1215
	@RequestMapping(value = "/getPatnerInStock", method = RequestMethod.GET)
1216
	public String getPatnerInStock(HttpServletRequest request,
1217
			@RequestParam(name = ProfitMandiConstants.FOFO_ID) int fofoId, Model model) throws Exception {
1218
 
1219
		CustomRetailer customRetailer = retailerService.getFofoRetailer(fofoId);
1220
 
27660 tejbeer 1221
		List<InStockBrandModel> mobileStocks = currentInventorySnapshotRepository
27640 tejbeer 1222
				.selectSumInStockMobileGroupByBrand(fofoId);
27660 tejbeer 1223
		List<InStockBrandModel> accesStock = currentInventorySnapshotRepository
27640 tejbeer 1224
				.selectSumInStockAccessoriesGroupByBrand(fofoId);
1225
 
27660 tejbeer 1226
		List<InStockBrandItemModel> stockItemlist = currentInventorySnapshotRepository
1227
				.selectInStockItemsByBrand(fofoId);
1228
 
1229
		Map<String, List<InStockBrandItemModel>> stockItemMap = stockItemlist.stream()
1230
				.collect(Collectors.groupingBy(InStockBrandItemModel::getBrand));
1231
 
1232
		model.addAttribute("stockItemMap", stockItemMap);
1233
		model.addAttribute("mobileStock", mobileStocks);
1234
		model.addAttribute("accesStock", accesStock);
27640 tejbeer 1235
		model.addAttribute("customRetailer", customRetailer);
1236
		return "partner-instock-item";
1237
	}
1238
 
27660 tejbeer 1239
	@RequestMapping(value = "/getOpenTicketByFofoId", method = RequestMethod.GET)
1240
	public String getOpenTicketByFofoId(HttpServletRequest request,
1241
			@RequestParam(name = ProfitMandiConstants.FOFO_ID) int fofoId, Model model) throws Exception {
1242
		Map<Integer, AuthUser> ticketIdAuthUser = new HashMap<>();
1243
		CustomRetailer customRetailer = retailerService.getFofoRetailer(fofoId);
1244
		List<Integer> ticketIds = ticketRepository.selectAllOpenTicketByRetailer(fofoId).stream().map(x -> x.getId())
1245
				.collect(Collectors.toList());
1246
		List<TicketAssigned> ticketAssigns = ticketAssignedRepository.selectByTicketIds(ticketIds);
1247
 
1248
		for (TicketAssigned ticketAssign : ticketAssigns) {
1249
			AuthUser authUser = authRepository.selectById(ticketAssign.getAssineeId());
1250
			ticketIdAuthUser.put(ticketAssign.getTicketId(), authUser);
1251
		}
1252
		model.addAttribute("ticketIdAuthUser", ticketIdAuthUser);
1253
		model.addAttribute("ticketAssigns", ticketAssigns);
1254
		model.addAttribute("customRetailer", customRetailer);
1255
		return "open-ticket";
1256
	}
1257
 
27893 tejbeer 1258
	@RequestMapping(value = "/getPartnerSecondarySale", method = RequestMethod.GET)
1259
	public String getPartnerSecondarySale(HttpServletRequest request,
1260
			@RequestParam(name = ProfitMandiConstants.FOFO_ID) int fofoId, @RequestParam String timeValue, Model model)
1261
			throws Exception {
1262
		LocalDateTime curDate = LocalDate.now().atStartOfDay();
1263
		CustomRetailer customRetailer = retailerService.getFofoRetailer(fofoId);
1264
		int lengthOfMonth = YearMonth.from(curDate.minusMonths(1)).lengthOfMonth();
1265
		LocalDateTime startDate = null;
1266
		LocalDateTime endDate = null;
1267
		List<InStockBrandModel> secondarySale = null;
1268
		Map<String, List<InStockBrandItemModel>> secondaryItemSale = null;
1269
 
1270
		if (timeValue.equals("mtd")) {
1271
			startDate = curDate.withDayOfMonth(1);
1272
			endDate = curDate.with(LocalTime.MAX);
1273
			secondarySale = orderRepository.selectAllBilledOrderBrandByFofoId(startDate, endDate, fofoId);
1274
			secondaryItemSale = orderRepository.selectAllBilledOrderBrandItemByFofoId(startDate, endDate, fofoId)
1275
					.stream().collect(Collectors.groupingBy(InStockBrandItemModel::getBrand));
1276
			LOGGER.info("secondarySalemtd" + secondarySale);
1277
		} else if (timeValue.equals("lmtd")) {
1278
			startDate = curDate.withDayOfMonth(1).minusMonths(1);
1279
			endDate = curDate.with(LocalTime.MAX).minusMonths(1);
1280
			secondaryItemSale = orderRepository.selectAllBilledOrderBrandItemByFofoId(startDate, endDate, fofoId)
1281
					.stream().collect(Collectors.groupingBy(InStockBrandItemModel::getBrand));
1282
 
1283
			secondarySale = orderRepository.selectAllBilledOrderBrandByFofoId(startDate, endDate, fofoId);
1284
			LOGGER.info("secondarySalelmtd" + secondarySale);
1285
 
1286
		} else {
1287
			startDate = curDate.withDayOfMonth(1).minusMonths(1);
1288
			endDate = curDate.withDayOfMonth(1);
1289
			secondaryItemSale = orderRepository.selectAllBilledOrderBrandItemByFofoId(startDate, endDate, fofoId)
1290
					.stream().collect(Collectors.groupingBy(InStockBrandItemModel::getBrand));
1291
 
1292
			secondarySale = orderRepository.selectAllBilledOrderBrandByFofoId(startDate, endDate, fofoId);
1293
			LOGGER.info("secondarySalelms" + secondarySale);
1294
 
1295
		}
1296
 
1297
		LOGGER.info("secondarySale" + secondarySale);
1298
		model.addAttribute("secondarySale", secondarySale);
1299
		model.addAttribute("secondaryItemSale", secondaryItemSale);
1300
		model.addAttribute("customRetailer", customRetailer);
1301
 
1302
		return "partner-secondary-order";
1303
	}
1304
 
28451 tejbeer 1305
	@RequestMapping(value = "/getMobileBrandWise", method = RequestMethod.GET)
1306
	public String getMobileBrandWise(HttpServletRequest request, Model model) throws Exception {
1307
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1308
		String email = loginDetails.getEmailId();
1309
 
1310
		AuthUser authUser = authRepository.selectByEmailOrMobile(email);
1311
		Map<String, Set<Integer>> storeGuyMap = csService.getAuthUserPartnerIdMapping();
1312
 
1313
		Set<Integer> fofoIds = storeGuyMap.get(authUser.getEmailId());
1314
		if (emails.contains(authUser.getEmailId())) {
1315
			fofoIds = storeGuyMap.get("tarun.verma@smartdukaan.com");
1316
			LOGGER.info("fofoIds" + fofoIds);
1317
		}
1318
 
28471 tejbeer 1319
		if (fofoIds == null) {
1320
			List<Position> positions1 = positionRepository.selectAll(authUser.getId());
1321
			if (positions1.stream().filter(x -> x.getCategoryId() == ProfitMandiConstants.TICKET_CATEGORY_MASTER)
1322
					.count() > 0) {
1323
				fofoIds = csService.getPositionCustomRetailerMap(positions1).values().stream().flatMap(x -> x.stream())
1324
						.map(x -> x.getPartnerId()).collect(Collectors.toSet());
1325
			}
1326
		}
1327
 
28451 tejbeer 1328
		Map<String, BrandWisePartnerSaleModel> partnersBrandSaleMap = null;
1329
		partnersBrandSaleMap = fofoStoreRepository.selectGroupByBrandWarehousePartnerSale(new ArrayList<>(fofoIds))
1330
				.stream().collect(Collectors.toMap(x -> x.getBrand(), x -> x));
1331
 
1332
		List<BrandWiseUnbilledActivateStockModel> unbilledActivatedStock = fofoStoreRepository
1333
				.selectUnbilledActivateStockGroupByBrand(new ArrayList<>(fofoIds));
1334
		for (BrandWiseUnbilledActivateStockModel un : unbilledActivatedStock) {
1335
			BrandWisePartnerSaleModel bpt = partnersBrandSaleMap.get(un.getBrand());
1336
			if (bpt != null) {
1337
				bpt.setAmtd(un.getUnbilledMtd());
1338
				bpt.setUamtdQty(un.getUnbilledMTDQty());
1339
			} else {
1340
				bpt = new BrandWisePartnerSaleModel();
1341
				bpt.setBrand(un.getBrand());
1342
				bpt.setAmtd(un.getUnbilledMtd());
1343
				bpt.setUamtdQty(un.getUnbilledMTDQty());
1344
				bpt.setLms(0);
1345
				bpt.setLmtd(0);
1346
				bpt.setMtd(0);
1347
				bpt.setMtdQty(0);
1348
				bpt.setLmtd(0);
1349
				bpt.setLmtdQty(0);
1350
				partnersBrandSaleMap.put(un.getBrand(), bpt);
1351
			}
1352
		}
1353
 
1354
		model.addAttribute("brandSalesMap", partnersBrandSaleMap);
1355
 
1356
		return "mobile-brand-wise-report";
1357
	}
1358
 
1359
	@RequestMapping(value = "/getAccessoriesBrandWise", method = RequestMethod.GET)
1360
	public String getAccessoriesBrandWise(HttpServletRequest request, Model model) throws Exception {
1361
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1362
		String email = loginDetails.getEmailId();
1363
 
1364
		AuthUser authUser = authRepository.selectByEmailOrMobile(email);
1365
		Map<String, Set<Integer>> storeGuyMap = csService.getAuthUserPartnerIdMapping();
1366
 
1367
		Set<Integer> fofoIds = storeGuyMap.get(authUser.getEmailId());
1368
		if (emails.contains(authUser.getEmailId())) {
1369
			fofoIds = storeGuyMap.get("tarun.verma@smartdukaan.com");
1370
			LOGGER.info("fofoIds" + fofoIds);
1371
		}
1372
 
28471 tejbeer 1373
		if (fofoIds == null) {
1374
			List<Position> positions1 = positionRepository.selectAll(authUser.getId());
1375
			if (positions1.stream().filter(x -> x.getCategoryId() == ProfitMandiConstants.TICKET_CATEGORY_MASTER)
1376
					.count() > 0) {
1377
				fofoIds = csService.getPositionCustomRetailerMap(positions1).values().stream().flatMap(x -> x.stream())
1378
						.map(x -> x.getPartnerId()).collect(Collectors.toSet());
1379
			}
1380
		}
1381
 
28451 tejbeer 1382
		List<BrandWisePartnerSaleModel> accessoriesBrandSales = null;
1383
 
1384
		accessoriesBrandSales = fofoStoreRepository
1385
				.selectGroupByBrandAccesoriesWarehousePartnerSale(new ArrayList<>(fofoIds));
1386
 
1387
		model.addAttribute("accessoriesBrandSales", accessoriesBrandSales);
1388
		return "accessories-brand-wise-report";
1389
	}
1390
 
1391
	@RequestMapping(value = "/getMobileLMSGraph", method = RequestMethod.GET)
28461 tejbeer 1392
	public String getMobileLMSGraph(HttpServletRequest request, @RequestParam(required = false) int warehouseId,
28451 tejbeer 1393
			@RequestParam(required = false) LocalDate date, @RequestParam List<Integer> fofoIds, Model model)
1394
			throws Exception {
1395
		Map<Integer, List<Integer>> warehouseIdFofoIdMap = fofoStoreRepository
1396
				.selectActivePartnersByRetailerIds(new ArrayList<>(fofoIds)).stream().collect(Collectors.groupingBy(
1397
						FofoStore::getWarehouseId, Collectors.mapping(FofoStore::getId, Collectors.toList())));
1398
 
1399
		ChartModel cm;
1400
		if (warehouseId != 0) {
28468 tejbeer 1401
			cm = adminUser.getBrandWiseLms(Arrays.asList(warehouseId),
28451 tejbeer 1402
					fofoIds.stream().map(x -> x).collect(Collectors.toList()), date);
1403
		} else {
28468 tejbeer 1404
			cm = adminUser.getBrandWiseLms(new ArrayList<>(warehouseIdFofoIdMap.keySet()),
28451 tejbeer 1405
					fofoIds.stream().map(x -> x).collect(Collectors.toList()), date);
1406
 
1407
		}
1408
 
1409
		LOGGER.info("chartMap" + gson.toJson(cm));
1410
		model.addAttribute("chartMap", gson.toJson(cm));
1411
		return "brand-wise-mobile-lms-chart";
1412
	}
1413
 
28461 tejbeer 1414
	@RequestMapping(value = "/getMobileLMSFilter", method = RequestMethod.GET)
1415
	public String getMobileLMSFilter(HttpServletRequest request,
1416
			@RequestParam(required = false, defaultValue = "0") int warehouseId,
1417
			@RequestParam(required = false) LocalDate date, Model model) throws Exception {
1418
 
1419
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1420
		String email = loginDetails.getEmailId();
28468 tejbeer 1421
		Map<String, Object> map = adminUser.getFilter(warehouseId, email, date);
28461 tejbeer 1422
		model.addAttribute("warehouseId", warehouseId);
1423
		model.addAllAttributes(map);
1424
 
1425
		return "chart-filter-lms";
1426
	}
1427
 
1428
	@RequestMapping(value = "/getMobileLMPFilter", method = RequestMethod.GET)
1429
	public String getMobileLMPFilter(HttpServletRequest request,
1430
			@RequestParam(required = false, defaultValue = "0") int warehouseId,
1431
			@RequestParam(required = false) LocalDate date, Model model) throws Exception {
1432
 
1433
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1434
		String email = loginDetails.getEmailId();
28468 tejbeer 1435
		Map<String, Object> map = adminUser.getFilter(warehouseId, email, date);
28461 tejbeer 1436
		model.addAttribute("warehouseId", warehouseId);
1437
		model.addAllAttributes(map);
1438
 
1439
		return "chart-filter-lmp";
1440
	}
1441
 
1442
	@RequestMapping(value = "/getMobileLMPGraph", method = RequestMethod.GET)
1443
	public String getMobileLMPGraph(HttpServletRequest request, @RequestParam(required = false) int warehouseId,
1444
			@RequestParam(required = false) LocalDate date, @RequestParam List<Integer> fofoIds, Model model)
1445
			throws Exception {
1446
		Map<Integer, List<Integer>> warehouseIdFofoIdMap = fofoStoreRepository
1447
				.selectActivePartnersByRetailerIds(new ArrayList<>(fofoIds)).stream().collect(Collectors.groupingBy(
1448
						FofoStore::getWarehouseId, Collectors.mapping(FofoStore::getId, Collectors.toList())));
1449
 
1450
		ChartModel cm;
1451
		if (warehouseId != 0) {
28468 tejbeer 1452
			cm = adminUser.getBrandWiseLmp(Arrays.asList(warehouseId),
28461 tejbeer 1453
					fofoIds.stream().map(x -> x).collect(Collectors.toList()), date);
1454
		} else {
28468 tejbeer 1455
			cm = adminUser.getBrandWiseLmp(new ArrayList<>(warehouseIdFofoIdMap.keySet()),
28461 tejbeer 1456
					fofoIds.stream().map(x -> x).collect(Collectors.toList()), date);
1457
 
1458
		}
1459
 
1460
		LOGGER.info("chartMap" + gson.toJson(cm));
1461
		model.addAttribute("chartMap", gson.toJson(cm));
1462
		return "brand-wise-mobile-lmp-chart";
1463
	}
1464
 
21615 kshitij.so 1465
}