Subversion Repositories SmartDukaan

Rev

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