Subversion Repositories SmartDukaan

Rev

Rev 31337 | Rev 31339 | 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
 
25649 tejbeer 3
import com.google.gson.Gson;
28825 tejbeer 4
import com.mongodb.DBObject;
25651 tejbeer 5
import com.spice.profitmandi.common.enumuration.ContentType;
25683 tejbeer 6
import com.spice.profitmandi.common.enumuration.MessageType;
22481 ashik.ali 7
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
31337 amit.gupta 8
import com.spice.profitmandi.common.model.*;
25651 tejbeer 9
import com.spice.profitmandi.common.web.util.ResponseSender;
26011 amit.gupta 10
import com.spice.profitmandi.dao.entity.auth.AuthUser;
27355 tejbeer 11
import com.spice.profitmandi.dao.entity.catalog.Item;
27636 tejbeer 12
import com.spice.profitmandi.dao.entity.catalog.TagListing;
28471 tejbeer 13
import com.spice.profitmandi.dao.entity.cs.Position;
27660 tejbeer 14
import com.spice.profitmandi.dao.entity.cs.TicketAssigned;
25651 tejbeer 15
import com.spice.profitmandi.dao.entity.dtr.Document;
25649 tejbeer 16
import com.spice.profitmandi.dao.entity.dtr.NotificationCampaign;
31337 amit.gupta 17
import com.spice.profitmandi.dao.entity.fofo.*;
29720 manish 18
import com.spice.profitmandi.dao.entity.transaction.LineItem;
27586 tejbeer 19
import com.spice.profitmandi.dao.entity.transaction.Order;
29707 tejbeer 20
import com.spice.profitmandi.dao.enumuration.catalog.UpgradeOfferStatus;
31259 tejbeer 21
import com.spice.profitmandi.dao.enumuration.fofo.Milestone;
28409 tejbeer 22
import com.spice.profitmandi.dao.enumuration.transaction.OrderStatus;
29707 tejbeer 23
import com.spice.profitmandi.dao.model.SamsungUpgradeOfferModel;
31337 amit.gupta 24
import com.spice.profitmandi.dao.model.*;
25976 amit.gupta 25
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
27355 tejbeer 26
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
31337 amit.gupta 27
import com.spice.profitmandi.dao.repository.catalog.OfferRepository;
29707 tejbeer 28
import com.spice.profitmandi.dao.repository.catalog.SamsungUpgradeOfferRepository;
27632 tejbeer 29
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
26090 amit.gupta 30
import com.spice.profitmandi.dao.repository.cs.CsService;
28471 tejbeer 31
import com.spice.profitmandi.dao.repository.cs.PositionRepository;
27660 tejbeer 32
import com.spice.profitmandi.dao.repository.cs.TicketAssignedRepository;
26418 tejbeer 33
import com.spice.profitmandi.dao.repository.cs.TicketRepository;
31337 amit.gupta 34
import com.spice.profitmandi.dao.repository.dtr.*;
35
import com.spice.profitmandi.dao.repository.fofo.*;
27529 tejbeer 36
import com.spice.profitmandi.dao.repository.inventory.ReporticoCacheTableRepository;
37
import com.spice.profitmandi.dao.repository.inventory.SaholicInventoryCISRepository;
29720 manish 38
import com.spice.profitmandi.dao.repository.transaction.LineItemRepository;
27893 tejbeer 39
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
28443 tejbeer 40
import com.spice.profitmandi.dao.repository.transaction.PriceDropRepository;
28468 tejbeer 41
import com.spice.profitmandi.service.AdminUser;
42
import com.spice.profitmandi.service.FofoUser;
24336 amit.gupta 43
import com.spice.profitmandi.service.PartnerInvestmentService;
26460 amit.gupta 44
import com.spice.profitmandi.service.PartnerStatsService;
23844 amit.gupta 45
import com.spice.profitmandi.service.authentication.RoleManager;
25677 amit.gupta 46
import com.spice.profitmandi.service.inventory.InventoryService;
27876 amit.gupta 47
import com.spice.profitmandi.service.offers.OfferService;
27586 tejbeer 48
import com.spice.profitmandi.service.transaction.TransactionService;
26005 amit.gupta 49
import com.spice.profitmandi.service.user.RetailerService;
22481 ashik.ali 50
import com.spice.profitmandi.web.model.LoginDetails;
51
import com.spice.profitmandi.web.util.CookiesProcessor;
27529 tejbeer 52
import com.spice.profitmandi.web.util.MVCResponseSender;
31337 amit.gupta 53
import org.apache.logging.log4j.LogManager;
54
import org.apache.logging.log4j.Logger;
55
import org.json.JSONObject;
56
import org.springframework.beans.factory.annotation.Autowired;
57
import org.springframework.beans.factory.annotation.Value;
58
import org.springframework.core.io.InputStreamResource;
59
import org.springframework.http.HttpHeaders;
60
import org.springframework.http.HttpStatus;
61
import org.springframework.http.ResponseEntity;
62
import org.springframework.stereotype.Controller;
63
import org.springframework.ui.Model;
64
import org.springframework.web.bind.annotation.PathVariable;
65
import org.springframework.web.bind.annotation.RequestMapping;
66
import org.springframework.web.bind.annotation.RequestMethod;
67
import org.springframework.web.bind.annotation.RequestParam;
22481 ashik.ali 68
 
31337 amit.gupta 69
import javax.servlet.http.HttpServletRequest;
70
import javax.transaction.Transactional;
71
import java.io.File;
72
import java.io.FileInputStream;
73
import java.io.FileNotFoundException;
74
import java.time.LocalDate;
75
import java.time.LocalDateTime;
76
import java.time.LocalTime;
77
import java.time.YearMonth;
78
import java.time.format.DateTimeFormatter;
79
import java.util.*;
80
import java.util.Map.Entry;
81
import java.util.stream.Collectors;
82
 
83
import static in.shop2020.model.v1.order.OrderStatus.*;
84
 
21615 kshitij.so 85
@Controller
25222 amit.gupta 86
@Transactional(rollbackOn = Throwable.class)
21615 kshitij.so 87
public class DashboardController {
23923 amit.gupta 88
 
27727 tejbeer 89
	List<String> emails = Arrays.asList("kamini.sharma@smartdukaan.com", "neeraj.gupta@smartdukaan.com",
31129 tejbeer 90
			"amit.gupta@smartdukaan.com", "tejbeer.kaur@smartdukaan.com", "kanan.choudhary@smartdukaan.com");
27727 tejbeer 91
 
23379 ashik.ali 92
	@Value("${web.api.host}")
93
	private String webApiHost;
23923 amit.gupta 94
 
24072 amit.gupta 95
	@Value("${web.api.scheme}")
96
	private String webApiScheme;
24288 amit.gupta 97
 
24078 amit.gupta 98
	@Value("${web.api.root}")
99
	private String webApiRoot;
100
 
23379 ashik.ali 101
	@Value("${web.api.port}")
102
	private int webApiPort;
28430 tejbeer 103
 
22481 ashik.ali 104
	@Autowired
28443 tejbeer 105
	private PriceDropRepository priceDropRepository;
106
 
107
	@Autowired
22927 ashik.ali 108
	private CookiesProcessor cookiesProcessor;
26468 amit.gupta 109
 
26460 amit.gupta 110
	@Autowired
28409 tejbeer 111
	private PendingOrderRepository pendingOrderRepository;
112
 
113
	@Autowired
26460 amit.gupta 114
	private PartnerStatsService partnerStatsService;
23923 amit.gupta 115
 
23568 govind 116
	@Autowired
26090 amit.gupta 117
	private CsService csService;
118
 
119
	@Autowired
25653 amit.gupta 120
	private ResponseSender<?> responseSender;
26012 amit.gupta 121
 
26005 amit.gupta 122
	@Autowired
123
	RetailerService retailerService;
25214 amit.gupta 124
 
125
	@Autowired
28468 tejbeer 126
	private AdminUser adminUser;
127
 
128
	@Autowired
23786 amit.gupta 129
	private RoleManager roleManager;
23923 amit.gupta 130
 
23838 ashik.ali 131
	@Autowired
132
	private FofoStoreRepository fofoStoreRepository;
23884 amit.gupta 133
 
134
	@Autowired
24880 govind 135
	private PartnerInvestmentService partnerInvestmentService;
24288 amit.gupta 136
 
23884 amit.gupta 137
	@Autowired
25653 amit.gupta 138
	DocumentRepository documentRepository;
26236 amit.gupta 139
 
26234 amit.gupta 140
	@Autowired
141
	InventoryItemRepository inventoryItemRepository;
25683 tejbeer 142
 
25677 amit.gupta 143
	@Autowired
144
	InventoryService inventoryService;
23923 amit.gupta 145
 
23884 amit.gupta 146
	@Autowired
28409 tejbeer 147
	private PendingOrderItemRepository pendingOrderItemRepository;
148
 
149
	@Autowired
24203 amit.gupta 150
	private CurrentInventorySnapshotRepository currentInventorySnapshotRepository;
151
 
24880 govind 152
	@Autowired
153
	private FofoOrderItemRepository fofoOrderItemRepository;
26012 amit.gupta 154
 
26011 amit.gupta 155
	@Autowired
25566 tejbeer 156
	private PartnerTypeChangeService partnerTypeChangeService;
25136 amit.gupta 157
 
24996 amit.gupta 158
	@Autowired
25649 tejbeer 159
	private HygieneDataRepository hygieneDataRepository;
160
 
161
	@Autowired
162
	private UserAccountRepository userAccountRepository;
163
 
164
	@Autowired
165
	private NotificationCampaignRepository notificationCampaignRepository;
166
 
167
	@Autowired
25976 amit.gupta 168
	private AuthRepository authRepository;
24880 govind 169
 
25649 tejbeer 170
	@Autowired
26071 tejbeer 171
	private FofoOrderRepository fofoOrderRepository;
172
 
173
	@Autowired
25649 tejbeer 174
	private Gson gson;
175
 
26418 tejbeer 176
	@Autowired
177
	TicketRepository ticketRepository;
178
 
179
	@Autowired
27876 amit.gupta 180
	private OfferService offerService;
181
 
182
	@Autowired
27355 tejbeer 183
	private ItemRepository itemRepository;
26588 tejbeer 184
 
27509 tejbeer 185
	@Autowired
27529 tejbeer 186
	private SaholicInventoryCISRepository saholicInventoryCISRepository;
187
 
188
	@Autowired
189
	private MVCResponseSender mvcResponseSender;
190
 
191
	@Autowired
192
	private ReporticoCacheTableRepository reporticoCacheTableRepository;
193
 
27586 tejbeer 194
	@Autowired
195
	private TransactionService transactionService;
196
 
27632 tejbeer 197
	@Autowired
198
	private TagListingRepository tagListingRepository;
199
 
27660 tejbeer 200
	@Autowired
201
	private TicketAssignedRepository ticketAssignedRepository;
202
 
27893 tejbeer 203
	@Autowired
204
	private OrderRepository orderRepository;
28468 tejbeer 205
 
206
	@Autowired
207
	private FofoUser fofoUser;
29875 tejbeer 208
 
28471 tejbeer 209
	@Autowired
28825 tejbeer 210
	private ActivatedImeiRepository activatedImeiRepository;
211
 
212
	@Autowired
213
	private Mongo mongoClient;
214
 
215
	@Autowired
29578 tejbeer 216
	private SchemeInOutRepository schemeInOutRepository;
29875 tejbeer 217
 
29578 tejbeer 218
	@Autowired
29720 manish 219
	private LineItemRepository lineItemRepository;
29875 tejbeer 220
 
29720 manish 221
	@Autowired
29578 tejbeer 222
	private FofoLineItemRepository fofoLineItemRepository;
223
 
224
	@Autowired
28471 tejbeer 225
	private PositionRepository positionRepository;
29707 tejbeer 226
 
227
	@Autowired
31211 tejbeer 228
	private MonthlyTargetRepository monthlyTargetRepository;
31285 tejbeer 229
 
31211 tejbeer 230
	@Autowired
29707 tejbeer 231
	private SamsungUpgradeOfferRepository samsungUpgradeOfferRepository;
23568 govind 232
	private static final Logger LOGGER = LogManager.getLogger(DashboardController.class);
23923 amit.gupta 233
 
25136 amit.gupta 234
	@RequestMapping(value = "/12dashboard34", method = RequestMethod.GET)
25726 amit.gupta 235
	public String dashboard1(HttpServletRequest request, Model model, @RequestParam int fofoId) throws Exception {
25740 amit.gupta 236
		boolean isAdmin = false;
237
		model.addAttribute("isAdmin", isAdmin);
238
 
239
		model.addAttribute("webApiHost", webApiHost);
240
		model.addAttribute("webApiPort", webApiPort);
241
		model.addAttribute("webApiScheme", webApiScheme);
242
		model.addAttribute("webApiRoot", webApiRoot);
243
		if (isAdmin) {
244
			return "dashboard1";
26236 amit.gupta 245
		}
246
 
247
		FofoStore fofoStore = null;
26234 amit.gupta 248
		try {
249
			CustomRetailer customRetailer = retailerService.getFofoRetailer(fofoId);
250
			fofoStore = fofoStoreRepository.selectByRetailerId(fofoId);
251
			if (!fofoStore.isActive()) {
252
				return "redirect:/login";
253
			}
25740 amit.gupta 254
 
26234 amit.gupta 255
			PartnerType partnerType = partnerTypeChangeService.getTypeOnDate(fofoStore.getId(), LocalDate.now());
256
			model.addAttribute("partnerType", partnerType);
257
			model.addAttribute("partnerTypeImage", PartnerType.imageMap.get(partnerType));
258
			model.addAttribute("fofoStore", customRetailer);
259
			model.addAttribute("partnerType", partnerType);
28468 tejbeer 260
			model.addAttribute("hasGift", fofoUser.hasGift(fofoId));
26234 amit.gupta 261
			model.addAttribute("giftItemId", ProfitMandiConstants.GIFT_ID);
25740 amit.gupta 262
 
28468 tejbeer 263
			model.addAttribute("brandStockPrices", fofoUser.getBrandStockPrices(fofoId));
264
			model.addAttribute("salesMap", fofoUser.getSales(fofoId));
26234 amit.gupta 265
			model.addAttribute("activatedImeis", inventoryItemRepository.selectCountByActivatedNotSold(fofoId));
266
			// this.setInvestments
267
			//
28272 tejbeer 268
			Map<Integer, String> monthValueMap = new HashMap<>();
269
			for (int i = 0; i <= 5; i++) {
270
				LocalDateTime startOfMonth = LocalDateTime.now().withDayOfMonth(1).minusMonths(i);
271
				monthValueMap.put(i, startOfMonth.format(DateTimeFormatter.ofPattern("MMM''uu")));
272
			}
273
			LOGGER.info("monthValueMap" + monthValueMap);
274
			model.addAttribute("monthValueMap", monthValueMap);
28468 tejbeer 275
			model.addAttribute("investments", fofoUser.getInvestments(fofoId));
26234 amit.gupta 276
			model.addAttribute("isInvestmentOk",
277
					partnerInvestmentService.isInvestmentOk(fofoId, 10, ProfitMandiConstants.CUTOFF_INVESTMENT));
278
		} catch (ProfitMandiBusinessException e) {
279
			LOGGER.error("FofoStore Code not found of fofoId {}", fofoId);
25740 amit.gupta 280
 
281
		}
282
 
28430 tejbeer 283
		return "12dashboard34";
28272 tejbeer 284
	}
25740 amit.gupta 285
 
27474 tejbeer 286
	@RequestMapping(value = "/getMonthSale", method = RequestMethod.GET)
287
	public String getMonthsale(HttpServletRequest request, Model model) throws Exception {
288
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
289
		int fofoId = loginDetails.getFofoId();
290
		Map<Integer, MonthSaleModel> monthSaleMap = new HashMap<>();
291
		LocalDateTime curDate = LocalDate.now().atStartOfDay();
292
		int dayOfMonth = curDate.getDayOfMonth();
293
		for (int i = 1; i <= 6; i++) {
294
			LocalDateTime startOfMonth = curDate.withDayOfMonth(1).minusMonths(i);
27555 tejbeer 295
			int lengthOfMonth = YearMonth.from(startOfMonth).lengthOfMonth();
29875 tejbeer 296
			LOGGER.info("Start of previous Month {}, start of next month Month {}", startOfMonth,
297
					startOfMonth.plusMonths(1));
27474 tejbeer 298
			double monthSales = fofoOrderItemRepository.selectSumMopGroupByRetailer(startOfMonth,
299
					startOfMonth.plusMonths(1), loginDetails.getFofoId(), false).get(fofoId);
300
 
27574 tejbeer 301
			double mtdSales = fofoOrderItemRepository
302
					.selectSumMopGroupByRetailer(startOfMonth,
303
							startOfMonth.plusDays(Math.min(dayOfMonth, lengthOfMonth)), loginDetails.getFofoId(), false)
304
					.get(fofoId);
27474 tejbeer 305
 
306
			PartnerType partnerType = partnerTypeChangeService.getTypeOnDate(fofoId, startOfMonth.toLocalDate());
307
 
308
			MonthSaleModel ms = new MonthSaleModel();
28468 tejbeer 309
			ms.setMtdSales(fofoUser.format((long) mtdSales));
310
			ms.setMonthlySales(fofoUser.format(((long) monthSales)));
27474 tejbeer 311
			ms.setPartnerType(partnerType);
27476 tejbeer 312
			ms.setMonth(startOfMonth.format(DateTimeFormatter.ofPattern("MMM''uu")));
27474 tejbeer 313
			monthSaleMap.put(i, ms);
29875 tejbeer 314
		}
27474 tejbeer 315
 
316
		model.addAttribute("monthSales", monthSaleMap);
317
		return "monthSales";
318
	}
319
 
21615 kshitij.so 320
	@RequestMapping(value = "/dashboard", method = RequestMethod.GET)
25653 amit.gupta 321
	public String dashboard(HttpServletRequest request, Model model) throws Exception {
22927 ashik.ali 322
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
26011 amit.gupta 323
		String email = loginDetails.getEmailId();
28430 tejbeer 324
		int fofoId = loginDetails.getFofoId();
25180 amit.gupta 325
		boolean isAdmin = roleManager.isAdmin(loginDetails.getRoleIds());
326
		model.addAttribute("isAdmin", isAdmin);
23923 amit.gupta 327
 
25274 amit.gupta 328
		model.addAttribute("webApiHost", webApiHost);
329
		model.addAttribute("webApiPort", webApiPort);
330
		model.addAttribute("webApiScheme", webApiScheme);
25544 amit.gupta 331
		model.addAttribute("webApiRoot", webApiRoot);
25183 amit.gupta 332
		if (isAdmin) {
28468 tejbeer 333
			return adminUser.adminPanel(loginDetails.getFofoId(), email, model);
25180 amit.gupta 334
		} else {
25740 amit.gupta 335
			FofoStore fofoStore = null;
25180 amit.gupta 336
			try {
337
				fofoStore = fofoStoreRepository.selectByRetailerId(loginDetails.getFofoId());
25544 amit.gupta 338
				if (!fofoStore.isActive()) {
339
					return "redirect:/login";
340
				}
30346 tejbeer 341
 
30455 amit.gupta 342
				LocalDateTime startDate = LocalDate.now().withDayOfYear(1).atStartOfDay();
343
				LocalDateTime endtDate = LocalDateTime.now();
344
				OnlineDeliveredOrderSum onlineDeliveredOrderSum = pendingOrderItemRepository
345
						.selectSumSellingPriceOnlineOrder(fofoId, startDate, endtDate);
346
				LOGGER.info("onlineDeliveredOrderSum" + onlineDeliveredOrderSum.getSellingPrice());
347
 
348
				long countOrder = pendingOrderRepository.pendingOrderCount(fofoId, OrderStatus.PROCESSING);
349
				LOGGER.info("countOrder" + countOrder);
350
 
351
				ArrayList<in.shop2020.model.v1.order.OrderStatus> orderStatus = new ArrayList<>();
352
 
353
				orderStatus.add(SUBMITTED_FOR_PROCESSING);
354
				orderStatus.add(BILLED);
355
				orderStatus.add(SHIPPED_FROM_WH);
356
				orderStatus.add(DELIVERY_SUCCESS);
357
 
358
				List<Order> openOrders = orderRepository.selectGrnTimestampNull(fofoId, orderStatus);
359
				List<LineItem> submittedLineItemIds = openOrders.stream()
30564 tejbeer 360
						.filter(x -> x.getStatus().equals(SUBMITTED_FOR_PROCESSING)).map(x -> x.getLineItem())
361
						.collect(Collectors.toList());
362
				List<LineItem> billedOrderIds = openOrders.stream().filter(x -> x.getStatus().equals(BILLED))
30455 amit.gupta 363
						.map(x -> x.getLineItem()).collect(Collectors.toList());
30564 tejbeer 364
				List<LineItem> shippedOrderIds = openOrders.stream().filter(x -> x.getStatus().equals(SHIPPED_FROM_WH))
30455 amit.gupta 365
						.map(x -> x.getLineItem()).collect(Collectors.toList());
366
				List<LineItem> grnPendingLineItemIds = openOrders.stream()
30564 tejbeer 367
						.filter(x -> x.getStatus().equals(DELIVERY_SUCCESS)).map(x -> x.getLineItem())
368
						.collect(Collectors.toList());
30455 amit.gupta 369
 
370
				long imeiActivationPendingCount = 0;
371
				long imeiActivationPendingValue = 0;
30564 tejbeer 372
				List<Integer> grnPendingOrderIds = openOrders.stream()
373
						.filter(x -> x.getStatus().equals(SHIPPED_FROM_WH) || x.getStatus().equals(DELIVERY_SUCCESS))
374
						.map(x -> x.getId()).collect(Collectors.toList());
30455 amit.gupta 375
				if (grnPendingOrderIds.size() > 0) {
30564 tejbeer 376
					List<ImeiActivationTimestampModel> imeiActivationTimestampModels = activatedImeiRepository
377
							.selectActivatedImeisByOrders(grnPendingOrderIds);
30455 amit.gupta 378
					imeiActivationPendingCount = imeiActivationTimestampModels.size();
30564 tejbeer 379
					imeiActivationPendingValue = imeiActivationTimestampModels.stream()
380
							.collect(Collectors.summingDouble(x -> x.getSellingPrice())).longValue();
30455 amit.gupta 381
				}
382
 
30564 tejbeer 383
				long grnPendingCount = grnPendingLineItemIds.stream()
384
						.collect(Collectors.summingLong(LineItem::getQuantity));
30455 amit.gupta 385
				long grnPendingValue = grnPendingLineItemIds.stream()
386
						.collect(Collectors.summingLong(x -> x.getTotalPrice().longValue()));
387
				model.addAttribute("grnPendingCount", grnPendingCount);
388
				model.addAttribute("grnPendingValue", grnPendingValue);
389
 
30564 tejbeer 390
				long submittedCount = submittedLineItemIds.stream()
391
						.collect(Collectors.summingLong(LineItem::getQuantity));
30455 amit.gupta 392
				long submittedValue = submittedLineItemIds.stream()
393
						.collect(Collectors.summingLong(x -> x.getTotalPrice().longValue()));
394
				model.addAttribute("submittedCount", submittedCount);
395
				model.addAttribute("submittedValue", submittedValue);
396
 
397
				long billedCount = billedOrderIds.stream().collect(Collectors.summingLong(LineItem::getQuantity));
30564 tejbeer 398
				long billedValue = billedOrderIds.stream()
399
						.collect(Collectors.summingLong(x -> x.getTotalPrice().longValue()));
30455 amit.gupta 400
				model.addAttribute("billedValue", billedValue);
401
				model.addAttribute("billedCount", billedCount);
402
				LOGGER.info("billedCount {}", billedCount);
403
 
404
				long shippedCount = shippedOrderIds.stream().collect(Collectors.summingLong(LineItem::getQuantity));
405
				model.addAttribute("shippedCount", shippedCount);
406
				LOGGER.info("shippedCount {}", shippedCount);
407
				long shippedValue = shippedOrderIds.stream()
408
						.collect(Collectors.summingLong(x -> x.getTotalPrice().longValue()));
409
				model.addAttribute("shippedValue", shippedValue);
410
 
411
				LocalDateTime curDate = LocalDate.now().atStartOfDay();
412
 
413
				LocalDateTime currentMonthStart = curDate.withDayOfMonth(1);
414
				LocalDateTime lastMonthStart = currentMonthStart.minusMonths(1);
415
				LocalDateTime currentMonthEnd = currentMonthStart.withDayOfMonth(1);
416
 
417
				LOGGER.info("lastMonthStart" + lastMonthStart);
418
				LOGGER.info("currentMonthEnd" + currentMonthEnd);
419
 
420
				model.addAttribute("countOrder", countOrder);
421
				model.addAttribute("onlineDeliveredOrderSum", onlineDeliveredOrderSum.getSellingPrice());
422
 
25740 amit.gupta 423
				PartnerType partnerType = partnerTypeChangeService.getTypeOnDate(fofoStore.getId(), LocalDate.now());
25566 tejbeer 424
				model.addAttribute("partnerType", partnerType);
25653 amit.gupta 425
				model.addAttribute("partnerTypeImage", PartnerType.imageMap.get(partnerType));
25180 amit.gupta 426
				model.addAttribute("fofoStore", fofoStore);
25566 tejbeer 427
				model.addAttribute("partnerType", partnerType);
28468 tejbeer 428
				model.addAttribute("hasGift", fofoUser.hasGift(loginDetails.getFofoId()));
25180 amit.gupta 429
				model.addAttribute("giftItemId", ProfitMandiConstants.GIFT_ID);
26222 tejbeer 430
				model.addAttribute("retailers", new JSONObject().append("code", fofoStore.getCode())
26162 amit.gupta 431
						.append("partnerId", fofoStore.getId()).toString());
26460 amit.gupta 432
				model.addAttribute("activatedImeis",
433
						inventoryItemRepository.selectCountByActivatedNotSold(loginDetails.getFofoId()));
30564 tejbeer 434
				model.addAttribute("imeiActivationPendingCount", imeiActivationPendingCount);
435
				model.addAttribute("imeiActivationPendingValue", imeiActivationPendingValue);
30053 manish 436
 
26071 tejbeer 437
				Map<Integer, Double> accesoriesmtdsale = fofoOrderRepository
438
						.selectSumSaleGroupByFofoIdsForMobileOrAccessories(loginDetails.getFofoId(),
439
								curDate.withDayOfMonth(1), curDate.with(LocalTime.MAX), Optional.of(false));
27701 tejbeer 440
 
26071 tejbeer 441
				Double accesoriesStock = currentInventorySnapshotRepository
442
						.selectSumStockGroupByFofoIdsForMobileOrAccessories(loginDetails.getFofoId(),
443
								Optional.of(false))
444
						.get(loginDetails.getFofoId());
25180 amit.gupta 445
 
26071 tejbeer 446
				model.addAttribute("accesoriesStock", String.format("%.0f", accesoriesStock));
28468 tejbeer 447
				model.addAttribute("brandStockPrices", fofoUser.getBrandStockPrices(loginDetails.getFofoId()));
448
				model.addAttribute("salesMap", fofoUser.getSales(loginDetails.getFofoId()));
449
				ChartModel cm = fofoUser.getBrandChart(loginDetails.getFofoId());
26055 tejbeer 450
 
451
				LOGGER.info("chartMap" + gson.toJson(cm));
452
				model.addAttribute("chartMap", gson.toJson(cm));
27701 tejbeer 453
 
27876 amit.gupta 454
				List<CreateOfferRequest> publishedOffers = offerService.getPublishedOffers(loginDetails.getFofoId(),
455
						YearMonth.from(LocalDateTime.now()));
456
				model.addAttribute("publishedOffers", publishedOffers);
28468 tejbeer 457
				model.addAttribute("investments", fofoUser.getInvestments(loginDetails.getFofoId()));
25544 amit.gupta 458
				model.addAttribute("isInvestmentOk", partnerInvestmentService.isInvestmentOk(loginDetails.getFofoId(),
459
						10, ProfitMandiConstants.CUTOFF_INVESTMENT));
26460 amit.gupta 460
 
30564 tejbeer 461
				double currentMonthRating = hygieneDataRepository.selectRatingAvg(loginDetails.getFofoId(),
462
						currentMonthStart, currentMonthEnd) / 2;
30455 amit.gupta 463
				double lastMonthRating = hygieneDataRepository.selectRatingAvg(loginDetails.getFofoId(), lastMonthStart,
464
						currentMonthStart) / 2;
30564 tejbeer 465
				double ratingTillDate = hygieneDataRepository.selectRatingAvg(loginDetails.getFofoId(),
466
						LocalDateTime.MIN, currentMonthEnd) / 2;
30455 amit.gupta 467
				model.addAttribute("currentMonthRating", (float) Math.round(currentMonthRating * 10) / 10);
468
				model.addAttribute("lastMonthRating", (float) Math.round(lastMonthRating * 10) / 10);
469
				model.addAttribute("ratingTillDate", (float) Math.round(ratingTillDate * 10) / 10);
470
 
30564 tejbeer 471
				long hygieneCount = hygieneDataRepository.selectHygieneCount(loginDetails.getFofoId(), true,
472
						currentMonthStart, currentMonthEnd);
30455 amit.gupta 473
 
474
				long invalidHygieneCount = hygieneDataRepository.selectHygieneCount(loginDetails.getFofoId(), false,
475
						currentMonthStart, currentMonthEnd);
476
				if (hygieneCount == 0 && invalidHygieneCount == 0) {
477
					invalidHygieneCount = 1;
478
				}
479
				Map<Integer, String> monthValueMap = new HashMap<>();
480
				for (int i = 0; i <= 5; i++) {
481
					LocalDateTime startOfMonth = LocalDateTime.now().withDayOfMonth(1).minusMonths(i);
482
					monthValueMap.put(i, startOfMonth.format(DateTimeFormatter.ofPattern("MMM''uu")));
483
				}
484
 
31211 tejbeer 485
				MonthlyTarget monthlyTarget = monthlyTargetRepository.selectByDateAndFofoId(YearMonth.now(), fofoId);
486
				model.addAttribute("monthlyTarget", monthlyTarget);
487
 
30455 amit.gupta 488
				model.addAttribute("monthValueMap", monthValueMap);
489
				model.addAttribute("month", 0);
490
				model.addAttribute("hygienePercentage", (hygieneCount * 100) / (invalidHygieneCount + hygieneCount));
491
				model.addAttribute("monthDays", LocalDate.now().minusDays(1).lengthOfMonth());
492
				model.addAttribute("dayOfMonth", LocalDate.now().minusDays(1).getDayOfMonth());
493
 
25180 amit.gupta 494
			} catch (ProfitMandiBusinessException e) {
495
				LOGGER.error("FofoStore Code not found of fofoId {}", loginDetails.getFofoId());
496
 
497
			}
30455 amit.gupta 498
			return "dashboard1";
22481 ashik.ali 499
		}
25649 tejbeer 500
 
21615 kshitij.so 501
	}
29875 tejbeer 502
 
29720 manish 503
	@RequestMapping(value = "/getGrnPendingOrderStatus", method = RequestMethod.GET)
504
	public String getGrnPendingOrderStatus(HttpServletRequest request, Model model) throws Exception {
29875 tejbeer 505
 
29720 manish 506
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
507
		int fofoId = loginDetails.getFofoId();
30224 tejbeer 508
		List<Order> grnPendingOrders = orderRepository.selectGrnTimestampNull(fofoId,
509
				Arrays.asList(in.shop2020.model.v1.order.OrderStatus.DELIVERY_SUCCESS));
29746 manish 510
 
29934 amit.gupta 511
		model.addAttribute("grnPendingOrders", grnPendingOrders);
29720 manish 512
		return "purchase-grn-order-status";
513
	}
29875 tejbeer 514
 
29720 manish 515
	@RequestMapping(value = "/getPendingOrderStatus", method = RequestMethod.GET)
516
	public String getPendingOrderStatus(HttpServletRequest request, Model model) throws Exception {
29875 tejbeer 517
 
29720 manish 518
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
519
		int fofoId = loginDetails.getFofoId();
29875 tejbeer 520
		ArrayList<in.shop2020.model.v1.order.OrderStatus> orderStatus = new ArrayList<>();
521
 
29720 manish 522
		orderStatus.add(in.shop2020.model.v1.order.OrderStatus.SUBMITTED_FOR_PROCESSING);
29875 tejbeer 523
 
524
		List<Order> order = orderRepository.selectOrders(fofoId, orderStatus);
525
		List<Integer> submittedOrderIds = order.stream()
526
				.filter(x -> x.getStatus() == in.shop2020.model.v1.order.OrderStatus.SUBMITTED_FOR_PROCESSING)
527
				.map(x -> x.getId()).collect(Collectors.toList());
528
		model.addAttribute("submittedOrderIds", submittedOrderIds);
529
		if (!submittedOrderIds.isEmpty()) {
530
 
531
			List<LineItem> submittedLineItem = lineItemRepository.selectLineItem(submittedOrderIds);
532
			Map<Integer, LineItem> submittedLineItemMap = submittedLineItem.stream()
533
					.collect(Collectors.toMap(x -> x.getOrderId(), x -> x));
534
			LOGGER.info("submittedLineItemMap {}", submittedLineItemMap);
535
			model.addAttribute("submittedLineItemMap", submittedLineItemMap);
536
		}
537
 
29720 manish 538
		return "purchase-pending-order-status";
539
	}
29875 tejbeer 540
 
29720 manish 541
	@RequestMapping(value = "/getBilledOrderStatus", method = RequestMethod.GET)
542
	public String getBilledOrderStatus(HttpServletRequest request, Model model) throws Exception {
29875 tejbeer 543
 
29720 manish 544
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
545
		int fofoId = loginDetails.getFofoId();
29875 tejbeer 546
		ArrayList<in.shop2020.model.v1.order.OrderStatus> orderStatus = new ArrayList<>();
29720 manish 547
		orderStatus.add(in.shop2020.model.v1.order.OrderStatus.BILLED);
29875 tejbeer 548
 
549
		List<Order> order = orderRepository.selectOrders(fofoId, orderStatus);
550
		List<Integer> billedOrderIds = order.stream()
551
				.filter(x -> x.getStatus() == in.shop2020.model.v1.order.OrderStatus.BILLED).map(x -> x.getId())
552
				.collect(Collectors.toList());
553
		LOGGER.info("billedOrderIds {}", billedOrderIds);
554
		model.addAttribute("billedOrderIds", billedOrderIds);
555
 
556
		if (!billedOrderIds.isEmpty()) {
557
			List<LineItem> billedLineItem = lineItemRepository.selectLineItem(billedOrderIds);
558
			Map<Integer, LineItem> billedLineItemMap = billedLineItem.stream()
559
					.collect(Collectors.toMap(x -> x.getOrderId(), x -> x));
560
			LOGGER.info("billedLineItemMap {}", billedLineItemMap);
561
			model.addAttribute("billedLineItemMap", billedLineItemMap);
562
		}
563
 
29720 manish 564
		return "purchase-billed-order-status";
565
	}
29875 tejbeer 566
 
29720 manish 567
	@RequestMapping(value = "/getShippedOrderStatus", method = RequestMethod.GET)
568
	public String getShippedOrderStatus(HttpServletRequest request, Model model) throws Exception {
29875 tejbeer 569
 
29720 manish 570
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
571
		int fofoId = loginDetails.getFofoId();
29875 tejbeer 572
		ArrayList<in.shop2020.model.v1.order.OrderStatus> orderStatus = new ArrayList<>();
573
 
30455 amit.gupta 574
		orderStatus.add(SHIPPED_FROM_WH);
29875 tejbeer 575
 
576
		List<Order> order = orderRepository.selectOrders(fofoId, orderStatus);
30347 tejbeer 577
		List<Integer> shippedOrderIds = order.stream().filter(x -> x.getPartnerGrnTimestamp() == null)
29875 tejbeer 578
				.map(x -> x.getId()).collect(Collectors.toList());
579
		model.addAttribute("shippedOrderIds", shippedOrderIds);
580
		LOGGER.info("shippedOrderIds {}", shippedOrderIds);
581
 
582
		if (!shippedOrderIds.isEmpty()) {
583
			List<LineItem> shippedLineItem = lineItemRepository.selectLineItem(shippedOrderIds);
584
			Map<Integer, LineItem> shippedLineItemMap = shippedLineItem.stream()
585
					.collect(Collectors.toMap(x -> x.getOrderId(), x -> x));
586
			LOGGER.info("shippedLineItemMap {}", shippedLineItemMap);
587
 
588
			model.addAttribute("shippedLineItemMap", shippedLineItemMap);
589
		}
29720 manish 590
		return "purchase-shipped-order-status";
591
	}
23923 amit.gupta 592
 
31337 amit.gupta 593
 
594
	@Autowired
595
	OfferRepository offerRepository;
596
 
30224 tejbeer 597
	@RequestMapping(value = "/partnerTotalIncomeByMonth/{yearMonth}", method = RequestMethod.GET)
598
	public String getPartnerTotalIncomeByMonth(HttpServletRequest request, @PathVariable int yearMonth, Model model)
599
			throws Exception {
600
 
601
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
602
		long pendingIncome = 0;
603
		long partnerPurchaseIn = 0;
604
		long partnerCreditedSale = 0;
605
		long partnerFrontIncome = 0;
606
 
31337 amit.gupta 607
		LocalDateTime startOfMonth = LocalDate.now().minusMonths(yearMonth).withDayOfMonth(1).atStartOfDay();
608
		LocalDateTime endOfMonth = startOfMonth.plusMonths(1).toLocalDate().atStartOfDay();
30224 tejbeer 609
 
610
		AllPurchaseInventoryModel partnerlPendingSaleAmount = schemeInOutRepository
31337 amit.gupta 611
				.selectAllPendingSaleInventoryByFofoId(loginDetails.getFofoId(), startOfMonth, endOfMonth);
30224 tejbeer 612
		AllPurchaseInventoryModel partnerCreditedSaleAmount = schemeInOutRepository
31337 amit.gupta 613
				.selectAllCreditedSaleInventoryByFofoId(loginDetails.getFofoId(), startOfMonth, endOfMonth);
30224 tejbeer 614
		AllPurchaseInventoryModel partnerPurchaseInAmount = schemeInOutRepository
31337 amit.gupta 615
				.selectAllPurchaseInventoryByFofoId(loginDetails.getFofoId(), startOfMonth, endOfMonth);
30224 tejbeer 616
 
617
		AllPurchaseInventoryModel partnerFrontIncomes = schemeInOutRepository
31337 amit.gupta 618
				.selectFrontIncomeByFofoId(loginDetails.getFofoId(), startOfMonth, endOfMonth);
30224 tejbeer 619
 
31338 amit.gupta 620
		//AllPurchaseInventoryModel partnerAdditionalIncome = offerRepository.selectPurchaseIncome(loginDetails.getFofoId(), startOfMonth, endOfMonth);
31337 amit.gupta 621
 
30224 tejbeer 622
		LOGGER.info("partnerfrontIncomes" + partnerFrontIncomes);
623
 
624
		LOGGER.info("partnerCreditedSaleAmount" + partnerCreditedSaleAmount);
625
		LOGGER.info("partnerPurchaseInAmount" + partnerPurchaseInAmount);
626
		LOGGER.info("partnerlPendingSaleAmount" + partnerlPendingSaleAmount);
627
 
628
		if (partnerlPendingSaleAmount != null) {
629
 
630
			pendingIncome = partnerlPendingSaleAmount.getAmount();
631
 
632
			LOGGER.info("pendingIncome" + pendingIncome);
633
 
634
		}
635
 
636
		if (partnerCreditedSaleAmount != null) {
637
 
638
			partnerCreditedSale = partnerCreditedSaleAmount.getAmount();
639
 
640
			LOGGER.info("partnerCreditedSale" + partnerCreditedSale);
641
 
642
		}
643
		if (partnerFrontIncomes != null) {
644
 
645
			partnerFrontIncome = partnerFrontIncomes.getAmount();
646
			LOGGER.info("partnerPurchaseIn" + partnerPurchaseIn);
647
 
648
		}
649
		if (partnerPurchaseInAmount != null) {
650
 
651
			partnerPurchaseIn = partnerPurchaseInAmount.getAmount();
652
			LOGGER.info("partnerPurchaseIn" + partnerPurchaseIn);
653
 
654
		}
655
 
656
		LOGGER.info("partnerPurchaseInTT" + partnerPurchaseIn);
657
		LOGGER.info("partnerCreditedSaleTT" + partnerCreditedSale);
658
		LOGGER.info("pendingIncomeTT" + pendingIncome);
659
 
660
		long totalIncome = partnerCreditedSale + partnerPurchaseIn + pendingIncome + partnerFrontIncome;
661
 
662
		long creditedIncome = partnerCreditedSale + partnerPurchaseIn + partnerFrontIncome;
663
 
664
		long pendingTotalIncome = pendingIncome;
665
		LOGGER.info("totalIncome" + totalIncome);
666
		LOGGER.info("creditedIncome" + creditedIncome);
667
		LOGGER.info("pendingTotalIncome" + pendingTotalIncome);
668
 
669
		model.addAttribute("totalIncome", totalIncome);
670
		model.addAttribute("creditedIncome", creditedIncome);
671
		model.addAttribute("pendingTotalIncome", pendingTotalIncome);
672
 
673
		Map<Integer, String> monthValueMap = new HashMap<>();
674
		for (int i = 0; i <= 5; i++) {
31338 amit.gupta 675
			LocalDateTime monthStart = LocalDateTime.now().withDayOfMonth(1).minusMonths(i);
676
			monthValueMap.put(i, monthStart.format(DateTimeFormatter.ofPattern("MMM''uu")));
30224 tejbeer 677
		}
678
 
679
		model.addAttribute("month", yearMonth);
680
		model.addAttribute("monthValueMap", monthValueMap);
681
 
682
		return "partner-total-income";
683
	}
684
 
28272 tejbeer 685
	@RequestMapping(value = "/getMonthsInvestment", method = RequestMethod.GET)
686
	public String getMonthsInvestment(HttpServletRequest request,
30564 tejbeer 687
			@RequestParam(name = "month", required = true, defaultValue = "0") int month, Model model)
28272 tejbeer 688
			throws Exception {
689
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
690
		int fofoId = loginDetails.getFofoId();
28468 tejbeer 691
		Map<String, Object> investment = fofoUser.getInvestmentsMonths(fofoId, month);
28430 tejbeer 692
 
28272 tejbeer 693
		LocalDateTime currentMonthStart = LocalDateTime.now().withDayOfMonth(1);
694
		LocalDateTime lastMonthStart = currentMonthStart.minusMonths(1);
695
		LocalDateTime currentMonthEnd = currentMonthStart.plusMonths(1).withDayOfMonth(1);
696
		double currentMonthRating = hygieneDataRepository.selectRatingAvg(loginDetails.getFofoId(), currentMonthStart,
697
				currentMonthEnd) / 2;
698
		double lastMonthRating = hygieneDataRepository.selectRatingAvg(loginDetails.getFofoId(), lastMonthStart,
699
				currentMonthStart) / 2;
700
		double ratingTillDate = hygieneDataRepository.selectRatingAvg(loginDetails.getFofoId(), LocalDateTime.MIN,
701
				currentMonthEnd) / 2;
702
		model.addAttribute("currentMonthRating", (float) Math.round(currentMonthRating * 10) / 10);
703
		model.addAttribute("lastMonthRating", (float) Math.round(lastMonthRating * 10) / 10);
704
		model.addAttribute("ratingTillDate", (float) Math.round(ratingTillDate * 10) / 10);
705
 
28430 tejbeer 706
		long hygieneCount = hygieneDataRepository.selectHygieneCount(loginDetails.getFofoId(), true,
707
				currentMonthStart.minusMonths(month), currentMonthEnd.minusMonths(month));
28272 tejbeer 708
 
709
		long invalidHygieneCount = hygieneDataRepository.selectHygieneCount(loginDetails.getFofoId(), false,
28430 tejbeer 710
				currentMonthStart.minusMonths(month), currentMonthEnd.minusMonths(month));
28272 tejbeer 711
		if (hygieneCount == 0 && invalidHygieneCount == 0) {
712
			invalidHygieneCount = 1;
713
		}
714
		Map<Integer, String> monthValueMap = new HashMap<>();
715
		for (int i = 0; i <= 5; i++) {
716
			LocalDateTime startOfMonth = LocalDateTime.now().withDayOfMonth(1).minusMonths(i);
717
			monthValueMap.put(i, startOfMonth.format(DateTimeFormatter.ofPattern("MMM''uu")));
718
		}
719
		model.addAttribute("hygienePercentage", (hygieneCount * 100) / (invalidHygieneCount + hygieneCount));
28430 tejbeer 720
		model.addAttribute("monthValueMap", monthValueMap);
28272 tejbeer 721
		model.addAttribute("investments", investment);
722
		model.addAttribute("monthDays", LocalDate.now().minusMonths(month).lengthOfMonth());
723
		model.addAttribute("dayOfMonth", LocalDate.now().minusMonths(month).lengthOfMonth());
28430 tejbeer 724
		model.addAttribute("month", month);
28272 tejbeer 725
		return "performance";
726
	}
727
 
27884 tejbeer 728
	@RequestMapping(value = "/investmentDetails", method = RequestMethod.GET)
729
	public String getInvestmentDetails(HttpServletRequest request, Model model) throws Exception {
730
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
731
		int fofoId = loginDetails.getFofoId();
28468 tejbeer 732
		ChartInvestmentModel cm = fofoUser.getInvestmentChart(fofoId);
27884 tejbeer 733
		model.addAttribute("chartPieMap", gson.toJson(cm));
734
 
735
		LOGGER.info("InvestmentChart" + gson.toJson(cm));
736
		LOGGER.info("InvestmentChart" + cm);
737
		return "investmentdetails";
738
	}
739
 
28430 tejbeer 740
	@RequestMapping(value = "/getlmsLineChart", method = RequestMethod.GET)
741
	public String getlmsLineChart(HttpServletRequest request, Model model) throws Exception {
742
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
743
		int fofoId = loginDetails.getFofoId();
28468 tejbeer 744
		ChartModel cm = fofoUser.getLmsLineChart(loginDetails.getFofoId());
28430 tejbeer 745
 
746
		LOGGER.info("linechartMap" + gson.toJson(cm));
747
		model.addAttribute("linechartMap", gson.toJson(cm));
748
		return "lmsLineChart";
749
	}
750
 
28439 tejbeer 751
	@RequestMapping(value = "/getMonthlyPurchaseLineChart", method = RequestMethod.GET)
752
	public String getMonthlyPurchaseLineChart(HttpServletRequest request, Model model) throws Exception {
753
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
754
		int fofoId = loginDetails.getFofoId();
28468 tejbeer 755
		ChartModel cm = fofoUser.getPurchaseOrderChart(fofoId);
28439 tejbeer 756
 
757
		LOGGER.info("chartMap" + gson.toJson(cm));
758
		model.addAttribute("chartMap", gson.toJson(cm));
759
 
760
		return "purchase_chart";
761
	}
762
 
28430 tejbeer 763
	@RequestMapping(value = "/getBarChart", method = RequestMethod.GET)
764
	public String getBarChart(HttpServletRequest request, Model model) throws Exception {
765
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
766
		int fofoId = loginDetails.getFofoId();
28468 tejbeer 767
		ChartModel cm = fofoUser.getBrandChart(fofoId);
28430 tejbeer 768
 
769
		LOGGER.info("chartMap" + gson.toJson(cm));
770
		model.addAttribute("chartMap", gson.toJson(cm));
771
 
772
		return "bar_chart";
773
	}
774
 
28455 tejbeer 775
	@RequestMapping(value = "/getPriceDropDetails", method = RequestMethod.GET)
776
	public String getPriceDropDetails(HttpServletRequest request,
30564 tejbeer 777
			@RequestParam(name = "fofoId", required = true, defaultValue = "0") int fofoId,
778
			@RequestParam(name = "brand", required = true, defaultValue = "0") String brand,
779
			@RequestParam(name = "yearMonth", required = false, defaultValue = "0") String yearMonth, Model model)
28455 tejbeer 780
			throws Exception {
781
 
782
		LOGGER.info("params" + fofoId + brand + yearMonth);
783
 
784
		List<PriceDropWithDetailsByYearMonthModel> priceDropdetailsList = priceDropRepository
785
				.selectBrandPendingPriceDropWithDetailsByYearMonth(fofoId, brand, yearMonth);
786
 
787
		LOGGER.info("priceDropdetailsList" + priceDropdetailsList);
788
 
789
		model.addAttribute("priceDropdetailsList", priceDropdetailsList);
790
 
791
		return "price-drop-details";
792
	}
28825 tejbeer 793
 
28641 amit.gupta 794
	@RequestMapping(value = "/getPriceDropDetailSixMonths", method = RequestMethod.GET)
795
	public String getPriceDropDetailSixMonths(HttpServletRequest request,
30564 tejbeer 796
			@RequestParam(name = "fofoId", required = true, defaultValue = "0") int fofoId,
797
			@RequestParam(name = "brand", required = true, defaultValue = "0") String brand, Model model)
28641 amit.gupta 798
			throws Exception {
28455 tejbeer 799
 
28641 amit.gupta 800
		LOGGER.info("params" + fofoId + brand);
801
		LocalDateTime curDate = LocalDate.now().atStartOfDay();
802
		LocalDateTime startfMonthSixMonth = curDate.withDayOfMonth(1).minusMonths(12);
803
		LocalDateTime endMonthTotal = curDate.withDayOfMonth(1).minusMonths(6);
804
 
805
		List<PriceDropWithDetailsByYearMonthModel> priceDropdetailsList = priceDropRepository
28825 tejbeer 806
				.selectBrandPendingPriceDropWithDetailsAndSixMonth(fofoId, brand, startfMonthSixMonth, endMonthTotal);
28641 amit.gupta 807
 
808
		LOGGER.info("priceDropdetailsList" + priceDropdetailsList);
809
 
810
		model.addAttribute("priceDropdetailsList", priceDropdetailsList);
811
 
812
		return "price-drop-details";
813
	}
814
 
28455 tejbeer 815
	@RequestMapping(value = "/getMonthlyPriceDrop", method = RequestMethod.GET)
816
	public String getMonthlyPriceDropTabular(HttpServletRequest request, Model model) throws Exception {
817
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
818
		int fofoId = loginDetails.getFofoId();
819
		LocalDateTime curDate = LocalDate.now().atStartOfDay();
820
 
821
		LocalDateTime startOfMonth = curDate.withDayOfMonth(1).minusMonths(6);
28641 amit.gupta 822
		LocalDateTime startfMonthTotal = curDate.withDayOfMonth(1).minusMonths(12);
29875 tejbeer 823
		LocalDateTime endMonthTotal = curDate.withDayOfMonth(1).minusMonths(5);
28455 tejbeer 824
 
29875 tejbeer 825
		LOGGER.info("startfMonthTotal" + startfMonthTotal);
826
 
827
		LOGGER.info("endMonthTotal" + endMonthTotal);
28641 amit.gupta 828
		List<YearMonth> yms = new ArrayList<YearMonth>();
28455 tejbeer 829
 
29875 tejbeer 830
		for (int i = 0; i <= 5; i++) {
28641 amit.gupta 831
			yms.add(YearMonth.from(curDate.withDayOfMonth(1).minusMonths(i)));
28455 tejbeer 832
		}
28641 amit.gupta 833
		Collections.reverse(yms);
834
		model.addAttribute("yms", yms);
835
		LOGGER.info("ym" + yms);
28455 tejbeer 836
 
837
		List<PriceDropYearMonthModel> priceDropYearMonthModels = priceDropRepository
838
				.selectBrandPendingPriceDropByYearMonth(fofoId, startOfMonth);
839
 
28641 amit.gupta 840
		List<PriceDropBrandModel> priceDropBrandSixMonthTotals = priceDropRepository
841
				.selectSixMonthBrandPriceDropByYearMonth(fofoId, startfMonthTotal, endMonthTotal);
842
 
28455 tejbeer 843
		DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("MM-yyyy");
844
 
845
		Map<String, Map<YearMonth, Double>> brandMonthValue = new HashMap<>();
28641 amit.gupta 846
 
847
		LOGGER.info("priceDropBrandSixMonthTotals" + priceDropBrandSixMonthTotals);
28825 tejbeer 848
 
849
		Map<String, Double> priceDropBrandSixMonthMap = priceDropBrandSixMonthTotals.stream()
850
				.collect(Collectors.toMap(x -> x.getBrand(), x -> (double) x.getAmount()));
851
 
28641 amit.gupta 852
		model.addAttribute("priceDropBrandSixMonthMap", priceDropBrandSixMonthMap);
28455 tejbeer 853
		LOGGER.info("priceDropYearMonthModels" + priceDropYearMonthModels);
28641 amit.gupta 854
 
28455 tejbeer 855
		for (PriceDropYearMonthModel pdm : priceDropYearMonthModels) {
28641 amit.gupta 856
			Map<YearMonth, Double> brandValue = new HashMap<>();
28455 tejbeer 857
 
858
			if (brandMonthValue.containsKey(pdm.getBrand())) {
859
				brandValue = brandMonthValue.get(pdm.getBrand());
860
				brandValue.put(YearMonth.parse(pdm.getYearMonth(), dateTimeFormatter), (double) pdm.getAmount());
861
			} else {
862
 
863
				brandValue.put(YearMonth.parse(pdm.getYearMonth(), dateTimeFormatter), (double) pdm.getAmount());
864
 
865
			}
866
			brandMonthValue.put(pdm.getBrand(), brandValue);
867
		}
868
		List<String> brands = new ArrayList<>();
869
		brands.add("Accessories");
870
		brands.add("Oppo");
871
		brands.add("Vivo");
872
		brands.add("Samsung");
873
		brands.add("Realme");
28462 tejbeer 874
		brands.add("MI");
28455 tejbeer 875
		brands.add("Tecno");
876
		brands.add("Itel");
877
		brands.add("Nokia");
29578 tejbeer 878
 
28455 tejbeer 879
		Map<String, List<Double>> sortedBrandValue = new LinkedHashMap<>();
880
 
28825 tejbeer 881
		model.addAttribute("brands", brands);
882
 
28455 tejbeer 883
		for (String brand : brands) {
884
			Map<YearMonth, Double> yearMonthValue = brandMonthValue.get(brand);
29875 tejbeer 885
			for (int i = 5; i >= 0; i--) {
28455 tejbeer 886
 
887
				LocalDateTime startMonth = curDate.withDayOfMonth(1).minusMonths(i);
888
 
889
				if (yearMonthValue != null) {
890
					if (yearMonthValue.get(YearMonth.from(startMonth)) == null) {
891
						yearMonthValue.put(YearMonth.from(startMonth), 0.0);
892
					}
893
 
894
				} else {
895
					yearMonthValue = new HashMap<>();
896
					yearMonthValue.put(YearMonth.from(startMonth), 0.0);
897
				}
898
			}
899
 
900
			Map<YearMonth, Double> sortedMonthBrandValue = new TreeMap<>(yearMonthValue);
901
 
902
			brandMonthValue.put(brand, sortedMonthBrandValue);
903
 
904
			sortedBrandValue.put(brand, sortedMonthBrandValue.values().stream().collect(Collectors.toList()));
905
 
906
		}
907
 
29578 tejbeer 908
		LOGGER.info("sortedBrandValue" + sortedBrandValue);
909
		model.addAttribute("fofoId", fofoId);
28455 tejbeer 910
 
29578 tejbeer 911
		model.addAttribute("sortedBrandValue", sortedBrandValue);
28455 tejbeer 912
 
29578 tejbeer 913
		return "price-drop-tabular";
914
	}
28455 tejbeer 915
 
29578 tejbeer 916
	@RequestMapping(value = "/getMonthlyActivation", method = RequestMethod.GET)
917
	public String getMonthlyActivation(HttpServletRequest request, Model model) throws Exception {
918
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
919
		int fofoId = loginDetails.getFofoId();
28455 tejbeer 920
 
29578 tejbeer 921
		LocalDateTime curDate = LocalDate.now().atStartOfDay();
922
		LocalDateTime startOfMonth = curDate.withDayOfMonth(1).minusMonths(6);
923
 
924
		List<YearMonth> yms = new ArrayList<YearMonth>();
925
 
29580 tejbeer 926
		for (int i = 0; i <= 5; i++) {
29578 tejbeer 927
			yms.add(YearMonth.from(curDate.withDayOfMonth(1).minusMonths(i)));
928
		}
929
		Collections.reverse(yms);
930
		model.addAttribute("yms", yms);
931
		LOGGER.info("ym" + yms);
932
 
933
		List<ActivationYearMonthModel> pendingActivationModels = schemeInOutRepository
934
				.selectPendingActivationGroupByBrandYearMonth(fofoId, startOfMonth);
935
 
936
		List<ActivationBrandModel> pendingActivationBeforeSixMonth = schemeInOutRepository
937
				.selectByYearMonthActivationGroupByBrand(fofoId, startOfMonth);
938
 
939
		Map<String, Double> pendingActivationBeforeSixMonthMap = pendingActivationBeforeSixMonth.stream()
940
				.collect(Collectors.toMap(x -> x.getBrand(), x -> (double) x.getAmount()));
941
 
942
		model.addAttribute("pendingActivationBeforeSixMonthMap", pendingActivationBeforeSixMonthMap);
943
 
944
		DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("MM-yyyy");
945
 
946
		Map<String, Map<YearMonth, Double>> activationBrandMonthMap = new HashMap<>();
947
 
948
		for (ActivationYearMonthModel pam : pendingActivationModels) {
949
			Map<YearMonth, Double> brandValue = new HashMap<>();
950
 
951
			if (activationBrandMonthMap.containsKey(pam.getBrand())) {
952
				brandValue = activationBrandMonthMap.get(pam.getBrand());
953
				brandValue.put(YearMonth.parse(pam.getYearMonth(), dateTimeFormatter), (double) pam.getAmount());
954
			} else {
955
 
956
				brandValue.put(YearMonth.parse(pam.getYearMonth(), dateTimeFormatter), (double) pam.getAmount());
957
 
28455 tejbeer 958
			}
29578 tejbeer 959
			activationBrandMonthMap.put(pam.getBrand(), brandValue);
960
		}
28455 tejbeer 961
 
29578 tejbeer 962
		List<String> brands = new ArrayList<>();
963
		brands.add("Oppo");
964
		brands.add("Vivo");
965
		brands.add("Samsung");
966
		brands.add("Realme");
967
		brands.add("MI");
968
		brands.add("Tecno");
969
		brands.add("Itel");
970
		brands.add("Nokia");
971
		brands.add("Lava");
972
		Map<String, List<Double>> sortedBrandValue = new LinkedHashMap<>();
973
 
974
		model.addAttribute("brands", brands);
975
 
976
		for (String brand : brands) {
977
			Map<YearMonth, Double> yearMonthValue = activationBrandMonthMap.get(brand);
29580 tejbeer 978
			for (int i = 5; i >= 0; i--) {
29578 tejbeer 979
				LocalDateTime startMonth = curDate.withDayOfMonth(1).minusMonths(i);
980
				if (yearMonthValue != null) {
981
					if (yearMonthValue.get(YearMonth.from(startMonth)) == null) {
982
						yearMonthValue.put(YearMonth.from(startMonth), 0.0);
983
					}
984
 
985
				} else {
986
					yearMonthValue = new HashMap<>();
987
					yearMonthValue.put(YearMonth.from(startMonth), 0.0);
988
				}
989
			}
990
			Map<YearMonth, Double> sortedMonthBrandValue = new TreeMap<>(yearMonthValue);
991
			activationBrandMonthMap.put(brand, sortedMonthBrandValue);
992
			sortedBrandValue.put(brand, sortedMonthBrandValue.values().stream().collect(Collectors.toList()));
28455 tejbeer 993
		}
994
 
29580 tejbeer 995
		LOGGER.info("sortedBrandValue" + sortedBrandValue);
29578 tejbeer 996
		model.addAttribute("sortedBrandValue", sortedBrandValue);
28455 tejbeer 997
		model.addAttribute("fofoId", fofoId);
29578 tejbeer 998
		return "activation-tabular";
999
	}
28455 tejbeer 1000
 
29578 tejbeer 1001
	@RequestMapping(value = "/getMonthlyActivationItemDetail", method = RequestMethod.GET)
1002
	public String getMonthlyActivationItemDetail(HttpServletRequest request,
30564 tejbeer 1003
			@RequestParam(name = "fofoId", required = true, defaultValue = "0") int fofoId,
1004
			@RequestParam(name = "brand", required = true, defaultValue = "0") String brand,
1005
			@RequestParam(name = "yearMonth", required = false, defaultValue = "0") String yearMonth, Model model)
29578 tejbeer 1006
			throws Exception {
28455 tejbeer 1007
 
29578 tejbeer 1008
		LOGGER.info("params" + fofoId + brand + yearMonth);
1009
 
1010
		List<ActivationItemDetailModel> activationItemDetails = schemeInOutRepository
1011
				.selectBrandPendingActivationItemDetails(fofoId, brand, yearMonth);
1012
 
1013
		for (ActivationItemDetailModel activationItemDetail : activationItemDetails) {
1014
 
1015
			List<FofoLineItem> flis = fofoLineItemRepository
1016
					.selectByInventoryItemId(activationItemDetail.getInventoryItemId());
1017
 
1018
			LOGGER.info("flis" + flis);
1019
 
1020
			int maxFofoOrderItemId = flis.stream().mapToInt(x -> x.getFofoOrderItemId()).max()
1021
					.orElseThrow(NoSuchElementException::new);
1022
			LOGGER.info("maxFofoOrderItemId" + maxFofoOrderItemId);
1023
 
1024
			FofoOrderItem foi = fofoOrderItemRepository.selectById(maxFofoOrderItemId);
1025
 
1026
			FofoOrder fo = fofoOrderRepository.selectByOrderId(foi.getOrderId());
1027
 
1028
			activationItemDetail.setInvoiceNumber(fo.getInvoiceNumber());
1029
 
1030
		}
1031
		LOGGER.info("activationItemDetails" + activationItemDetails);
1032
 
1033
		model.addAttribute("activationItemDetails", activationItemDetails);
1034
 
1035
		return "activation-pending-item-details";
28455 tejbeer 1036
	}
1037
 
29578 tejbeer 1038
	@RequestMapping(value = "/getMonthlyActivationBeforeSixMonthsItemDetail", method = RequestMethod.GET)
1039
	public String getMonthlyActivationItemDetail(HttpServletRequest request,
30564 tejbeer 1040
			@RequestParam(name = "fofoId", required = true, defaultValue = "0") int fofoId,
1041
			@RequestParam(name = "brand", required = true, defaultValue = "0") String brand, Model model)
29578 tejbeer 1042
			throws Exception {
1043
		LocalDateTime curDate = LocalDate.now().atStartOfDay();
1044
 
1045
		LocalDateTime startOfMonth = curDate.withDayOfMonth(1).minusMonths(6);
1046
 
1047
		List<ActivationItemDetailModel> activationItemDetails = schemeInOutRepository
1048
				.selectBrandPendingActivationItemDetailByYearMonth(fofoId, brand, startOfMonth);
1049
 
1050
		for (ActivationItemDetailModel activationItemDetail : activationItemDetails) {
1051
 
1052
			List<FofoLineItem> flis = fofoLineItemRepository
1053
					.selectByInventoryItemId(activationItemDetail.getInventoryItemId());
1054
			LOGGER.info("flis" + flis);
1055
 
1056
			int maxFofoOrderItemId = flis.stream().mapToInt(x -> x.getFofoOrderItemId()).max()
1057
					.orElseThrow(NoSuchElementException::new);
1058
			LOGGER.info("maxFofoOrderItemId" + maxFofoOrderItemId);
1059
 
1060
			FofoOrderItem foi = fofoOrderItemRepository.selectById(maxFofoOrderItemId);
1061
 
1062
			FofoOrder fo = fofoOrderRepository.selectByOrderId(foi.getOrderId());
1063
 
1064
			activationItemDetail.setInvoiceNumber(fo.getInvoiceNumber());
1065
 
1066
		}
1067
		LOGGER.info("activationItemDetails" + activationItemDetails);
1068
 
1069
		model.addAttribute("activationItemDetails", activationItemDetails);
1070
 
1071
		return "activation-pending-item-details";
1072
	}
1073
 
29707 tejbeer 1074
	@RequestMapping(value = "/getMonthlySamsungUpgradeOffer", method = RequestMethod.GET)
1075
	public String getMonthlySamsungUpgradeOffer(HttpServletRequest request, Model model) throws Exception {
1076
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1077
		int fofoId = loginDetails.getFofoId();
1078
 
1079
		LocalDateTime curDate = LocalDate.now().atStartOfDay();
1080
		LocalDateTime startOfMonth = curDate.withDayOfMonth(1).minusMonths(6);
1081
 
1082
		List<YearMonth> yms = new ArrayList<YearMonth>();
1083
 
1084
		for (int i = 0; i <= 5; i++) {
1085
			yms.add(YearMonth.from(curDate.withDayOfMonth(1).minusMonths(i)));
1086
		}
1087
		Collections.reverse(yms);
1088
		model.addAttribute("yms", yms);
1089
		LOGGER.info("ym" + yms);
1090
 
1091
		List<SamsungUpgradeOfferModel> suos = samsungUpgradeOfferRepository.selectUpgradeOfferGroupByYearMonth(fofoId,
1092
				UpgradeOfferStatus.approved, startOfMonth);
1093
 
1094
		LOGGER.info("suos" + suos);
1095
 
1096
		List<BrandAmountModel> beforeSixMonthOffers = samsungUpgradeOfferRepository
1097
				.selectUpgradeOfferByYearMonthGroupByBrand(fofoId, UpgradeOfferStatus.approved, startOfMonth);
1098
 
1099
		Map<String, Double> pendingUpgradeOfferBeforeSixMonthMap = beforeSixMonthOffers.stream()
1100
				.collect(Collectors.toMap(x -> x.getBrand(), x -> (double) x.getAmount()));
1101
 
1102
		model.addAttribute("pendingUpgradeOfferBeforeSixMonthMap", pendingUpgradeOfferBeforeSixMonthMap);
1103
 
1104
		DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("MM-yyyy");
1105
 
1106
		Map<String, Map<YearMonth, Double>> upgradeOfferBrandMonthMap = new HashMap<>();
1107
 
1108
		for (SamsungUpgradeOfferModel suo : suos) {
1109
			Map<YearMonth, Double> brandValue = new HashMap<>();
1110
 
1111
			if (upgradeOfferBrandMonthMap.containsKey(suo.getBrand())) {
1112
				brandValue = upgradeOfferBrandMonthMap.get(suo.getBrand());
1113
				brandValue.put(YearMonth.parse(suo.getYearMonth(), dateTimeFormatter), (double) suo.getAmount());
1114
			} else {
1115
 
1116
				brandValue.put(YearMonth.parse(suo.getYearMonth(), dateTimeFormatter), (double) suo.getAmount());
1117
 
1118
			}
1119
			upgradeOfferBrandMonthMap.put(suo.getBrand(), brandValue);
1120
		}
1121
 
1122
		Map<String, List<Double>> sortedBrandValue = new LinkedHashMap<>();
1123
		String brand = "Samsung";
1124
 
1125
		Map<YearMonth, Double> yearMonthValue = upgradeOfferBrandMonthMap.get(brand);
1126
		for (int i = 5; i >= 0; i--) {
1127
			LocalDateTime startMonth = curDate.withDayOfMonth(1).minusMonths(i);
1128
			if (yearMonthValue != null) {
1129
				if (yearMonthValue.get(YearMonth.from(startMonth)) == null) {
1130
					yearMonthValue.put(YearMonth.from(startMonth), 0.0);
1131
				}
1132
 
1133
			} else {
1134
				yearMonthValue = new HashMap<>();
1135
				yearMonthValue.put(YearMonth.from(startMonth), 0.0);
1136
			}
1137
		}
1138
		Map<YearMonth, Double> sortedMonthBrandValue = new TreeMap<>(yearMonthValue);
1139
		upgradeOfferBrandMonthMap.put(brand, sortedMonthBrandValue);
1140
		sortedBrandValue.put(brand, sortedMonthBrandValue.values().stream().collect(Collectors.toList()));
1141
		LOGGER.info("sortedBrandValue" + sortedBrandValue);
1142
 
1143
		model.addAttribute("brand", brand);
1144
		model.addAttribute("sortedBrandValue", sortedBrandValue);
1145
		model.addAttribute("fofoId", fofoId);
1146
		return "upgrade-offer-tabular";
1147
 
1148
	}
1149
 
1150
	@RequestMapping(value = "/getMonthlyUpgradeOfferItemDetail", method = RequestMethod.GET)
1151
	public String getMonthlyUpgradeOfferItemDetail(HttpServletRequest request,
30564 tejbeer 1152
			@RequestParam(name = "fofoId", required = true, defaultValue = "0") int fofoId,
1153
			@RequestParam(name = "brand", required = true, defaultValue = "0") String brand,
1154
			@RequestParam(name = "yearMonth", required = false, defaultValue = "0") String yearMonth, Model model)
29707 tejbeer 1155
			throws Exception {
1156
 
1157
		LOGGER.info("params" + fofoId + brand + yearMonth);
1158
		List<UpgradeOfferItemDetailModel> offerItems = samsungUpgradeOfferRepository
1159
				.selectUpgradeOfferItemDetails(fofoId, UpgradeOfferStatus.approved, brand, yearMonth);
1160
 
1161
		model.addAttribute("offerItems", offerItems);
1162
 
1163
		return "upgrade-offer-item-detail";
1164
	}
1165
 
1166
	@RequestMapping(value = "/getUpgradeOfferBeforeSixMonthItemDetail", method = RequestMethod.GET)
1167
	public String getUpgradeOfferBeforeSixMonthItemDetail(HttpServletRequest request,
30564 tejbeer 1168
			@RequestParam(name = "fofoId", required = true, defaultValue = "0") int fofoId,
1169
			@RequestParam(name = "brand", required = true, defaultValue = "0") String brand, Model model)
29707 tejbeer 1170
			throws Exception {
1171
		LocalDateTime curDate = LocalDate.now().atStartOfDay();
1172
 
1173
		LocalDateTime startOfMonth = curDate.withDayOfMonth(1).minusMonths(6);
1174
 
1175
		List<UpgradeOfferItemDetailModel> offerItems = samsungUpgradeOfferRepository
1176
				.selectUpgradeOfferItemDetailByYearMonth(fofoId, UpgradeOfferStatus.approved, brand, startOfMonth);
1177
 
1178
		model.addAttribute("offerItems", offerItems);
1179
 
1180
		return "upgrade-offer-item-detail";
1181
	}
1182
 
26468 amit.gupta 1183
	@RequestMapping(value = "/getAuthUserPartners", method = RequestMethod.GET)
26418 tejbeer 1184
	public String AuthUserPartnersDetail(HttpServletRequest request, Model model, @RequestParam int authId)
1185
			throws Exception {
1186
 
1187
		Map<Integer, List<Integer>> pp = csService.getAuthUserIdPartnerIdMapping();
26963 amit.gupta 1188
		Map<Integer, CustomRetailer> fofoIdAndPartnerMap = retailerService.getFofoRetailers(false);
26418 tejbeer 1189
 
26468 amit.gupta 1190
		Map<Integer, PartnerDetailModel> fofoIdAndallValues = partnerStatsService.getAllPartnerStats();
1191
		if (authId != 0) {
1192
			List<Integer> fofoIds = pp.get(authId);
1193
			fofoIdAndallValues = fofoIdAndallValues.entrySet().stream().filter(x -> fofoIds.contains(x.getKey()))
1194
					.collect(Collectors.toMap(x -> x.getKey(), x -> x.getValue()));
26474 amit.gupta 1195
		} else {
26418 tejbeer 1196
		}
1197
 
1198
		model.addAttribute("fofoIdAndallValues", fofoIdAndallValues);
1199
		model.addAttribute("fofoIdAndPartnerMap", fofoIdAndPartnerMap);
1200
 
1201
		return "auth_user_partner_detail";
26468 amit.gupta 1202
	}
26418 tejbeer 1203
 
27545 tejbeer 1204
	@RequestMapping(value = "/getWarehousePartners", method = RequestMethod.GET)
1205
	public String warehousePartnersDetail(HttpServletRequest request, Model model, @RequestParam int warehouseId)
1206
			throws Exception {
27701 tejbeer 1207
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1208
		String email = loginDetails.getEmailId();
28472 tejbeer 1209
 
1210
		Set<Integer> authfofoIds = new HashSet<>();
31152 tejbeer 1211
		authfofoIds = csService.getAuthFofoIds(email);
27701 tejbeer 1212
		Map<Integer, List<Integer>> warehouseIdFofoIdMap = fofoStoreRepository
1213
				.selectActivePartnersByRetailerIds(new ArrayList<>(authfofoIds)).stream().collect(Collectors.groupingBy(
1214
						FofoStore::getWarehouseId, Collectors.mapping(FofoStore::getId, Collectors.toList())));
1215
 
27545 tejbeer 1216
		Map<Integer, CustomRetailer> fofoIdAndPartnerMap = retailerService.getFofoRetailers(false);
28468 tejbeer 1217
		Map<Integer, PartnerDetailModel> fofoIdAndallValues = adminUser.getPartnersStatDataFromFile();
27545 tejbeer 1218
		if (warehouseId != 0) {
27701 tejbeer 1219
			List<Integer> fofoIds = warehouseIdFofoIdMap.get(warehouseId);
1220
			/*
1221
			 * List<Integer> fofoIds =
1222
			 * fofoStoreRepository.selectActivePartnerByWarehouse(warehouseId).stream()
1223
			 * .map(x -> x.getId()).collect(Collectors.toList());
1224
			 */
27545 tejbeer 1225
			fofoIdAndallValues = fofoIdAndallValues.entrySet().stream().filter(x -> fofoIds.contains(x.getKey()))
1226
					.collect(Collectors.toMap(x -> x.getKey(), x -> x.getValue()));
1227
		} else {
28472 tejbeer 1228
 
1229
			List<Integer> fofoIds = new ArrayList<>(authfofoIds);
1230
			fofoIdAndallValues = fofoIdAndallValues.entrySet().stream().filter(x -> fofoIds.contains(x.getKey()))
27701 tejbeer 1231
					.collect(Collectors.toMap(x -> x.getKey(), x -> x.getValue()));
27545 tejbeer 1232
		}
29164 manish 1233
		ChartInvestmentModel cm = adminUser.getAllStatePartnerType(fofoIdAndallValues);
1234
		model.addAttribute("chartPieMap", gson.toJson(cm));
27545 tejbeer 1235
 
29164 manish 1236
		LOGGER.info("adminUserChart" + gson.toJson(cm));
1237
 
31211 tejbeer 1238
		Map<Integer, MonthlyTarget> monthlyTargetMap = monthlyTargetRepository.selectByDate(YearMonth.now()).stream()
1239
				.collect(Collectors.toMap(x -> x.getFofoId(), x -> x));
1240
 
27545 tejbeer 1241
		model.addAttribute("fofoIdAndallValues", fofoIdAndallValues);
1242
		model.addAttribute("fofoIdAndPartnerMap", fofoIdAndPartnerMap);
31211 tejbeer 1243
		model.addAttribute("monthlyTargetMap", monthlyTargetMap);
27545 tejbeer 1244
 
31154 tejbeer 1245
		List<PartnerType> partnerTypes = Arrays.asList(PartnerType.values()).stream()
1246
				.filter(x -> !x.equals(PartnerType.ALL)).collect(Collectors.toList());
31211 tejbeer 1247
 
31154 tejbeer 1248
		model.addAttribute("partnerTypes", partnerTypes);
1249
 
27545 tejbeer 1250
		return "auth_user_partner_detail";
1251
	}
1252
 
27509 tejbeer 1253
	@RequestMapping(value = "/getWarehouseWiseBrandStock", method = RequestMethod.GET)
27701 tejbeer 1254
	public String getWarehouseWiseBrandStock(HttpServletRequest request, Model model,
30564 tejbeer 1255
			@RequestParam List<Integer> warehouseId) throws Exception {
27701 tejbeer 1256
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1257
		String email = loginDetails.getEmailId();
31152 tejbeer 1258
		Set<Integer> authfofoIds = csService.getAuthFofoIds(email);
27701 tejbeer 1259
		Map<Integer, List<Integer>> warehouseIdFofoIdMap = fofoStoreRepository
1260
				.selectActivePartnersByRetailerIds(new ArrayList<>(authfofoIds)).stream().collect(Collectors.groupingBy(
1261
						FofoStore::getWarehouseId, Collectors.mapping(FofoStore::getId, Collectors.toList())));
1262
		List<WarehouseWiseBrandStockModel> warehouseWiseBrandStock = new ArrayList<>();
1263
		if (!warehouseId.contains(0)) {
1264
			warehouseWiseBrandStock = saholicInventoryCISRepository.selectGroupByWarehouseAndBrand(warehouseId);
1265
		} else {
1266
			LOGGER.info("warehouseIdFofoIdMap" + warehouseIdFofoIdMap.keySet());
1267
			warehouseWiseBrandStock = saholicInventoryCISRepository
1268
					.selectGroupByWarehouseAndBrand(new ArrayList<>(warehouseIdFofoIdMap.keySet()));
1269
 
1270
		}
27542 tejbeer 1271
		Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
27509 tejbeer 1272
		model.addAttribute("warehouseWiseBrandStock", warehouseWiseBrandStock);
27542 tejbeer 1273
		model.addAttribute("warehouseId", warehouseId);
27509 tejbeer 1274
		model.addAttribute("warehouseMap", warehouseMap);
27660 tejbeer 1275
 
27509 tejbeer 1276
		return "warehouse_brand_stock";
1277
	}
1278
 
27529 tejbeer 1279
	@RequestMapping(value = "/getWarehouseWiseData", method = RequestMethod.GET)
1280
	public String getWarehouseWiseData(HttpServletRequest request, Model model) throws Exception {
1281
		inventoryService.getItemAvailabilityAndIndent();
31238 amit.gupta 1282
		model.addAttribute("response1", mvcResponseSender.createResponseString(true));
27529 tejbeer 1283
		return "response";
1284
	}
1285
 
27539 tejbeer 1286
	@RequestMapping(value = "/getWarehouseWiseBrandAndCategory", method = RequestMethod.GET)
1287
	public String getWarehouseWiseBrandAndCategory(HttpServletRequest request, Model model,
30564 tejbeer 1288
			@RequestParam List<Integer> warehouseId, @RequestParam List<String> brands, @RequestParam String category)
27538 tejbeer 1289
			throws Exception {
27509 tejbeer 1290
 
1291
		Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
27529 tejbeer 1292
		List<String> listbrands = saholicInventoryCISRepository.selectAllBrand();
27538 tejbeer 1293
		List<String> listCategory = saholicInventoryCISRepository.selectAllSubCategory();
27539 tejbeer 1294
 
27509 tejbeer 1295
		model.addAttribute("warehouseMap", warehouseMap);
27529 tejbeer 1296
		model.addAttribute("brands", listbrands);
27538 tejbeer 1297
		model.addAttribute("listCategory", listCategory);
1298
 
27529 tejbeer 1299
		model.addAttribute("selectedBrand", brands);
27538 tejbeer 1300
		model.addAttribute("selectedWarehouse", warehouseId);
27539 tejbeer 1301
		model.addAttribute("selectedCategory", category);
1302
 
27509 tejbeer 1303
		return "warehouse_brand_item_stock";
1304
	}
1305
 
27538 tejbeer 1306
	@RequestMapping(value = "/getWarehouseWiseItemStock", method = RequestMethod.GET)
1307
	public String getWarehouseWiseItemStock(HttpServletRequest request, Model model,
30564 tejbeer 1308
			@RequestParam List<Integer> warehouseId, @RequestParam List<String> brands, @RequestParam String category)
27538 tejbeer 1309
			throws Exception {
27539 tejbeer 1310
		Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
1311
		if (warehouseId.contains(0)) {
1312
			warehouseId.addAll(warehouseMap.keySet());
1313
		}
27538 tejbeer 1314
		List<WarehouseWiseitemStockModel> warehouseWiseItemStock = saholicInventoryCISRepository
1315
				.selectWarehouseItemStock(warehouseId, brands, category);
27539 tejbeer 1316
 
27538 tejbeer 1317
		model.addAttribute("warehouseWiseItemStock", warehouseWiseItemStock);
1318
		model.addAttribute("warehouseMap", warehouseMap);
1319
		return "warehouse_item_details";
1320
	}
1321
 
27556 tejbeer 1322
	@RequestMapping(value = "/getWarehouseWiseBrandPartnerSale", method = RequestMethod.GET)
27591 tejbeer 1323
	public String getWarehouseWiseBrandPartnerSale(HttpServletRequest request, Model model, @RequestParam String brand)
1324
			throws Exception {
27701 tejbeer 1325
 
1326
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1327
		String email = loginDetails.getEmailId();
1328
 
31152 tejbeer 1329
		Set<Integer> authfofoIds = csService.getAuthFofoIds(email);
28472 tejbeer 1330
 
27670 tejbeer 1331
		Map<Integer, WarehouseWiseBrandSaleModel> warehouseWiseBrandPartnerSales = fofoStoreRepository
27701 tejbeer 1332
				.selectGroupByWarehouseBrandWisePartnerSale(brand, new ArrayList<>(authfofoIds)).stream()
27670 tejbeer 1333
				.collect(Collectors.toMap(x -> x.getWarehouseId(), x -> x));
1334
 
1335
		List<WarehouseWiseBrandUnbilledActivatedModel> unbilledStock = fofoStoreRepository
27701 tejbeer 1336
				.selectUnbilledActivateStockGroupByWarehouse(brand, new ArrayList<>(authfofoIds));
27670 tejbeer 1337
 
1338
		for (WarehouseWiseBrandUnbilledActivatedModel un : unbilledStock) {
1339
			WarehouseWiseBrandSaleModel bpt = warehouseWiseBrandPartnerSales.get(un.getWarehouseId());
1340
			if (bpt != null) {
1341
				bpt.setAmtd(un.getUnbilledMtd());
27676 tejbeer 1342
				bpt.setUamtdQty(un.getUnbilledQty());
27670 tejbeer 1343
			} else {
1344
				bpt = new WarehouseWiseBrandSaleModel();
1345
				bpt.setWarehouseId(un.getWarehouseId());
1346
				bpt.setAmtd(un.getUnbilledMtd());
27677 tejbeer 1347
				bpt.setUamtdQty(un.getUnbilledQty());
27670 tejbeer 1348
				bpt.setLms(0);
1349
				bpt.setLmtd(0);
1350
				bpt.setMtd(0);
1351
				bpt.setMtdQty(0);
1352
				bpt.setLmtd(0);
1353
				bpt.setLmtdQty(0);
1354
				warehouseWiseBrandPartnerSales.put(un.getWarehouseId(), bpt);
1355
			}
1356
		}
27556 tejbeer 1357
		Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
27591 tejbeer 1358
 
1359
		Set<String> brands = inventoryService.getAllTagListingBrands();
1360
		model.addAttribute("warehouseWiseBrandPartnerSales", warehouseWiseBrandPartnerSales);
27556 tejbeer 1361
		model.addAttribute("warehouseMap", warehouseMap);
27591 tejbeer 1362
		model.addAttribute("brands", brands);
1363
		model.addAttribute("selectedbrand", brand);
1364
		return "warehousewise_brand_partners_sale";
27556 tejbeer 1365
	}
1366
 
27594 tejbeer 1367
	@RequestMapping(value = "/getWarehouseWiseAccesoriesBrandPartnerSale", method = RequestMethod.GET)
1368
	public String getWarehouseWiseAccesoriesBrandPartnerSale(HttpServletRequest request, Model model,
30564 tejbeer 1369
			@RequestParam String brand) throws Exception {
27701 tejbeer 1370
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1371
		String email = loginDetails.getEmailId();
1372
		Map<String, Set<Integer>> storeGuyMap = csService.getAuthUserPartnerIdMapping();
1373
		Set<Integer> authfofoIds = storeGuyMap.get(email);
28472 tejbeer 1374
 
1375
		AuthUser authUser = authRepository.selectByEmailOrMobile(email);
1376
		if (authfofoIds == null) {
1377
			List<Position> positions1 = positionRepository.selectAll(authUser.getId());
1378
			if (positions1.stream().filter(x -> x.getCategoryId() == ProfitMandiConstants.TICKET_CATEGORY_MASTER)
1379
					.count() > 0) {
1380
				authfofoIds = csService.getPositionCustomRetailerMap(positions1).values().stream()
1381
						.flatMap(x -> x.stream()).map(x -> x.getPartnerId()).collect(Collectors.toSet());
1382
			}
1383
		}
27594 tejbeer 1384
		List<WarehouseWiseBrandSaleModel> warehouseWiseBrandPartnerSales = fofoStoreRepository
27701 tejbeer 1385
				.selectGroupByWarehouseAccesoriesBrandWisePartnerSale(brand, new ArrayList<>(authfofoIds));
27594 tejbeer 1386
		Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
1387
 
1388
		Set<String> brands = inventoryService.getAllTagListingBrands();
1389
		model.addAttribute("warehouseWiseBrandPartnerSales", warehouseWiseBrandPartnerSales);
1390
		model.addAttribute("warehouseMap", warehouseMap);
1391
		model.addAttribute("brands", brands);
1392
		model.addAttribute("selectedbrand", brand);
1393
		return "warehousewise_accessoriesbrand_sale";
1394
	}
1395
 
27556 tejbeer 1396
	@RequestMapping(value = "/getWarehouseBrandWiseItemSale", method = RequestMethod.GET)
1397
	public String getWarehouseBrandWiseItemSale(HttpServletRequest request, Model model,
30564 tejbeer 1398
			@RequestParam List<Integer> warehouseId, @RequestParam String brand) throws Exception {
27556 tejbeer 1399
		Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
27701 tejbeer 1400
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1401
		String email = loginDetails.getEmailId();
31152 tejbeer 1402
		Set<Integer> authfofoIds = csService.getAuthFofoIds(email);
27670 tejbeer 1403
		Map<Integer, WarehouseBrandWiseItemSaleModel> branditemSalesMap = fofoStoreRepository
27701 tejbeer 1404
				.selectWarehouseBrandItemSale(warehouseId, brand, new ArrayList<>(authfofoIds)).stream()
27670 tejbeer 1405
				.collect(Collectors.toMap(x -> x.getItemId(), x -> x));
1406
 
1407
		List<WarehouseBrandItemUnbilledActivatedModel> unbilledItems = fofoStoreRepository
27701 tejbeer 1408
				.selectWarehouseBrandItemUnbilledActivateStock(warehouseId, brand, new ArrayList<>(authfofoIds));
27670 tejbeer 1409
 
1410
		for (WarehouseBrandItemUnbilledActivatedModel un : unbilledItems) {
1411
			WarehouseBrandWiseItemSaleModel bpt = branditemSalesMap.get(un.getItemId());
1412
			if (bpt != null) {
1413
				bpt.setAmtd(un.getAmtd());
27676 tejbeer 1414
				bpt.setUamtdQty(un.getUnmtdQty());
27670 tejbeer 1415
			} else {
1416
				bpt = new WarehouseBrandWiseItemSaleModel();
1417
				bpt.setWarehouseId(un.getWarehouseId());
1418
				bpt.setItemId(un.getItemId());
1419
				bpt.setAmtd(un.getAmtd());
27677 tejbeer 1420
				bpt.setUamtdQty(un.getUnmtdQty());
27670 tejbeer 1421
				bpt.setBrand(un.getBrand());
1422
				bpt.setModelName(un.getModelName());
1423
				bpt.setModelNumber(un.getModelNumber());
1424
				bpt.setColor(un.getColor());
1425
				bpt.setLms(0);
1426
				bpt.setLmtd(0);
1427
				bpt.setMtd(0);
1428
				bpt.setMtdQty(0);
1429
				bpt.setLmtd(0);
1430
				bpt.setLmtdQty(0);
1431
				branditemSalesMap.put(un.getItemId(), bpt);
1432
			}
1433
		}
1434
		model.addAttribute("branditemSales", branditemSalesMap);
27556 tejbeer 1435
		model.addAttribute("warehouseMap", warehouseMap);
1436
		return "warehouse_partner_itemwise_sale";
1437
	}
1438
 
27594 tejbeer 1439
	@RequestMapping(value = "/getWarehouseAccesoriesBrandWiseItemSale", method = RequestMethod.GET)
1440
	public String getWarehouseAccesoriesBrandWiseItemSale(HttpServletRequest request, Model model,
30564 tejbeer 1441
			@RequestParam List<Integer> warehouseId, @RequestParam String brand) throws Exception {
27594 tejbeer 1442
		Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
27701 tejbeer 1443
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1444
		String email = loginDetails.getEmailId();
1445
		Map<String, Set<Integer>> storeGuyMap = csService.getAuthUserPartnerIdMapping();
1446
		Set<Integer> authfofoIds = storeGuyMap.get(email);
27594 tejbeer 1447
		List<WarehouseBrandWiseItemSaleModel> branditemSales = fofoStoreRepository
27701 tejbeer 1448
				.selectWarehouseAccesoriesBrandItemSale(warehouseId, brand, new ArrayList<>(authfofoIds));
27594 tejbeer 1449
		model.addAttribute("branditemSales", branditemSales);
1450
		model.addAttribute("warehouseMap", warehouseMap);
1451
		return "warehouse_accessories_itemwsie_sale";
1452
	}
1453
 
22354 ashik.ali 1454
	@RequestMapping(value = "/contactUs", method = RequestMethod.GET)
23923 amit.gupta 1455
	public String contactUs(HttpServletRequest request, Model model) throws Throwable {
22354 ashik.ali 1456
		model.addAttribute("appContextPath", request.getContextPath());
1457
		return "contact-us";
1458
	}
23923 amit.gupta 1459
 
25649 tejbeer 1460
	@RequestMapping(value = "/notifications", method = RequestMethod.GET)
25683 tejbeer 1461
	public String getNotificationsWithType(HttpServletRequest request,
30564 tejbeer 1462
			@RequestParam(required = false) MessageType messageType,
1463
			@RequestParam(name = "offset", defaultValue = "0") int offset,
1464
			@RequestParam(name = "limit", defaultValue = "20") int limit, Model model) throws Exception {
25649 tejbeer 1465
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
26060 tejbeer 1466
		int userId = 0;
1467
		boolean isAdmin = roleManager.isAdmin(loginDetails.getRoleIds());
1468
		if (isAdmin) {
1469
			userId = loginDetails.getFofoId();
1470
		} else {
1471
			userId = userAccountRepository.selectUserIdByRetailerId(loginDetails.getFofoId());
1472
		}
25683 tejbeer 1473
		List<Notification> notifications = null;
1474
 
26086 tejbeer 1475
		List<NotificationCampaign> notificationCampaigns = notificationCampaignRepository.getNotifications(messageType,
1476
				userId, offset, limit);
1477
		LOGGER.info("messageType" + messageType);
28468 tejbeer 1478
		notifications = fofoUser.getNotifications(notificationCampaigns, messageType);
26086 tejbeer 1479
 
25683 tejbeer 1480
		model.addAttribute("notifications", notifications);
1481
 
1482
		LOGGER.info("notifications" + notifications);
1483
		return "notification-template";
1484
	}
1485
 
25651 tejbeer 1486
	@RequestMapping(value = "/notifyDocument/documentId", method = RequestMethod.GET)
1487
	public ResponseEntity<?> retailerDocumentById(HttpServletRequest request,
30564 tejbeer 1488
			@RequestParam(name = ProfitMandiConstants.DOCUMENT_ID) int documentId, @RequestParam int cid)
25651 tejbeer 1489
			throws ProfitMandiBusinessException {
1490
		Document document = documentRepository.selectById(documentId);
1491
		NotificationCampaign nc = notificationCampaignRepository.selectById(cid);
1492
		if (nc.getDocumentId() == null) {
1493
			throw new ProfitMandiBusinessException("cid", nc.getId(), "not available");
1494
		}
1495
		if (nc.getDocumentId() != documentId) {
1496
			throw new ProfitMandiBusinessException(ProfitMandiConstants.DOCUMENT_ID, documentId, "RTLR_1014");
1497
		}
1498
		return responseSender.ok(document);
25649 tejbeer 1499
	}
1500
 
25651 tejbeer 1501
	@RequestMapping(value = "/notifyDocument/download", method = RequestMethod.GET)
1502
	public ResponseEntity<?> downloadRetailerDocument(HttpServletRequest request, @RequestParam int cid, Model model)
1503
			throws ProfitMandiBusinessException {
1504
 
1505
		NotificationCampaign nc = notificationCampaignRepository.selectById(cid);
1506
 
1507
		if (nc.getDocumentId() == null) {
1508
			throw new ProfitMandiBusinessException("cid", nc.getId(), "not available");
1509
		}
1510
 
1511
		Document document = documentRepository.selectById(nc.getDocumentId());
1512
 
1513
		FileInputStream file = null;
1514
		try {
1515
			file = new FileInputStream(document.getPath() + File.separator + document.getName());
1516
		} catch (FileNotFoundException e) {
1517
			LOGGER.error("Retailer Document file not found : ", e);
1518
			throw new ProfitMandiBusinessException(ProfitMandiConstants.DOCUMENT_ID, document.getId(), "RTLR_1013");
1519
		}
1520
		// ByteArrayOutputStream byteArrayOutputStream = new
1521
		// ByteArrayOutputStream();
1522
		// ExcelUtils.writeSchemeModels(schemeModels, byteArrayOutputStream);
1523
 
1524
		final HttpHeaders headers = new HttpHeaders();
1525
		String contentType = "";
1526
		if (document.getContentType() == ContentType.JPEG) {
1527
			contentType = "image/jpeg";
1528
		} else if (document.getContentType() == ContentType.PNG) {
1529
			contentType = "image/png";
1530
		} else if (document.getContentType() == ContentType.PDF) {
1531
			contentType = "application/pdf";
1532
		}
1533
		headers.set("Content-Type", contentType);
1534
		headers.set("Content-disposition", "inline; filename=" + document.getName());
1535
		headers.setContentLength(document.getSize());
1536
		final InputStreamResource inputStreamResource = new InputStreamResource(file);
1537
		return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
1538
	}
26460 amit.gupta 1539
 
27579 tejbeer 1540
	@RequestMapping(value = "/getItemWiseTertiary", method = RequestMethod.GET)
1541
	public String getItemWiseTertiary(HttpServletRequest request,
30564 tejbeer 1542
			@RequestParam(name = ProfitMandiConstants.FOFO_ID) int fofoId, Model model)
27579 tejbeer 1543
			throws ProfitMandiBusinessException {
1544
		List<ItemWiseTertiaryModel> itemWiseTertiary = fofoOrderRepository.SelectItemWiseTertiary(fofoId);
1545
 
1546
		LOGGER.info("itemWiseTertiary" + itemWiseTertiary);
27586 tejbeer 1547
		CustomRetailer customRetailer = retailerService.getFofoRetailer(fofoId);
1548
		model.addAttribute("customRetailer", customRetailer);
27579 tejbeer 1549
		model.addAttribute("itemWiseTertiary", itemWiseTertiary);
1550
		return "item-wise-tertiary";
1551
	}
1552
 
27586 tejbeer 1553
	@RequestMapping(value = "/getItemWiseIndent", method = RequestMethod.GET)
1554
	public String getItemWiseIndent(HttpServletRequest request,
30564 tejbeer 1555
			@RequestParam(name = ProfitMandiConstants.FOFO_ID) int fofoId, Model model)
27586 tejbeer 1556
			throws ProfitMandiBusinessException {
1557
 
1558
		List<Order> unbilledOrders = transactionService.getInTransitOrders(fofoId);
1559
		model.addAttribute("unbilledOrders", unbilledOrders);
1560
 
1561
		return "item-wise-indent";
1562
	}
1563
 
27636 tejbeer 1564
	@RequestMapping(value = "/getPartnerInvestment", method = RequestMethod.GET)
1565
	public String getPartnerInvestment(HttpServletRequest request,
30564 tejbeer 1566
			@RequestParam(name = ProfitMandiConstants.FOFO_ID) int fofoId, Model model) throws Exception {
28468 tejbeer 1567
		Map<Integer, PartnerDetailModel> partnerStats = adminUser.getPartnersStatDataFromFile();
27636 tejbeer 1568
		PartnerDetailModel partnerDetailModel = partnerStats.get(fofoId);
1569
		CustomRetailer customRetailer = retailerService.getFofoRetailer(fofoId);
1570
		model.addAttribute("partnerDetailModel", partnerDetailModel);
1571
		model.addAttribute("customRetailer", customRetailer);
1572
		return "partner-investment";
1573
	}
27727 tejbeer 1574
 
27704 amit.gupta 1575
	@RequestMapping(value = "/getPartnerPendingIndentItem", method = RequestMethod.GET)
1576
	public String getPartnerPendingIndentItem(HttpServletRequest request, @RequestParam int warehouseId,
30564 tejbeer 1577
			@RequestParam int itemId, Model model) throws ProfitMandiBusinessException {
27704 amit.gupta 1578
		List<PartnerPendingIndentItemModel> partnerPendingIndent = fofoStoreRepository
1579
				.selectPartnerPendingIndentItem(itemId, warehouseId);
27636 tejbeer 1580
 
27704 amit.gupta 1581
		model.addAttribute("partnerPendingIndent", partnerPendingIndent);
1582
		return "partner-pending-indent-item";
1583
	}
1584
 
27636 tejbeer 1585
	@RequestMapping(value = "/getPatnerActivateStock", method = RequestMethod.GET)
1586
	public String getPartnerActivateStockItem(HttpServletRequest request,
30564 tejbeer 1587
			@RequestParam(name = ProfitMandiConstants.FOFO_ID) int fofoId, Model model) throws Exception {
27636 tejbeer 1588
		List<ActivateItemModel> activateStocks = new ArrayList<>();
1589
		List<InventoryItem> inventoryItems = inventoryItemRepository.selectByActivatedNotSold(fofoId);
1590
		CustomRetailer customRetailer = retailerService.getFofoRetailer(fofoId);
1591
 
1592
		for (InventoryItem inventoryItem : inventoryItems) {
1593
			TagListing tagListing = tagListingRepository.selectByItemId(inventoryItem.getItemId());
1594
			Item item = itemRepository.selectById(inventoryItem.getItemId());
1595
			ActivateItemModel aim = new ActivateItemModel();
1596
			aim.setFofoId(inventoryItem.getFofoId());
1597
			aim.setQuantity(inventoryItem.getGoodQuantity());
1598
			aim.setAmount(tagListing.getSellingPrice());
1599
			aim.setItemDescription(item.getItemDescription());
1600
			aim.setItemId(inventoryItem.getItemId());
1601
			activateStocks.add(aim);
1602
		}
1603
 
1604
		model.addAttribute("activateStocks", activateStocks);
1605
		model.addAttribute("customRetailer", customRetailer);
1606
		return "partner-activate-stock";
1607
	}
1608
 
1609
	@RequestMapping(value = "/getPatnerBrandWiseMTDSale", method = RequestMethod.GET)
1610
	public String getPatnerBrandWiseMTDSale(HttpServletRequest request,
30564 tejbeer 1611
			@RequestParam(name = ProfitMandiConstants.FOFO_ID) int fofoId, Model model) throws Exception {
27636 tejbeer 1612
		LocalDateTime curDate = LocalDate.now().atStartOfDay();
1613
		CustomRetailer customRetailer = retailerService.getFofoRetailer(fofoId);
1614
		Map<String, Double> brandMtdAmount = fofoOrderItemRepository
1615
				.selectSumAmountGroupByBrand(curDate.withDayOfMonth(1), curDate.with(LocalTime.MAX), fofoId);
27638 tejbeer 1616
		Map<String, Long> brandMtdQty = fofoOrderItemRepository.selectSumQuantityGroupByBrand(curDate.withDayOfMonth(1),
1617
				curDate.with(LocalTime.MAX), fofoId);
27636 tejbeer 1618
		Double accesoriesmtdsale = fofoOrderRepository.selectSumSaleGroupByFofoIdsForMobileOrAccessories(fofoId,
1619
				curDate.withDayOfMonth(1), curDate.with(LocalTime.MAX), Optional.of(false)).get(fofoId);
27638 tejbeer 1620
		Long accesoriesmtdqty = fofoOrderRepository.selectSumSaleQuantityGroupByFofoIdsForMobileOrAccessories(fofoId,
1621
				curDate.withDayOfMonth(1), curDate.with(LocalTime.MAX), Optional.of(false)).get(fofoId);
1622
 
27636 tejbeer 1623
		LOGGER.info("accesoriesmtdsale" + accesoriesmtdsale);
1624
		model.addAttribute("brandMtdAmount", brandMtdAmount);
27638 tejbeer 1625
		model.addAttribute("brandMtdQty", brandMtdQty);
27636 tejbeer 1626
		model.addAttribute("accesoriesmtdsale", accesoriesmtdsale);
27638 tejbeer 1627
		model.addAttribute("accesoriesmtdqty", accesoriesmtdqty);
1628
 
27636 tejbeer 1629
		model.addAttribute("customRetailer", customRetailer);
1630
		return "partner-brand-mtd-sale";
1631
	}
1632
 
27637 tejbeer 1633
	@RequestMapping(value = "/getPatnerBrandWiseLMTDSale", method = RequestMethod.GET)
1634
	public String getPatnerBrandWiseLMTDSale(HttpServletRequest request,
30564 tejbeer 1635
			@RequestParam(name = ProfitMandiConstants.FOFO_ID) int fofoId, Model model) throws Exception {
27637 tejbeer 1636
		LocalDateTime curDate = LocalDate.now().atStartOfDay();
1637
		CustomRetailer customRetailer = retailerService.getFofoRetailer(fofoId);
1638
		Map<String, Double> brandLMtdAmount = fofoOrderItemRepository.selectSumAmountGroupByBrand(
1639
				curDate.withDayOfMonth(1).minusMonths(1), curDate.with(LocalTime.MAX).minusMonths(1), fofoId);
27638 tejbeer 1640
		Map<String, Long> brandLmtdQty = fofoOrderItemRepository.selectSumQuantityGroupByBrand(
1641
				curDate.withDayOfMonth(1).minusMonths(1), curDate.with(LocalTime.MAX).minusMonths(1), fofoId);
27637 tejbeer 1642
 
1643
		Double accesorieslmtdsale = fofoOrderRepository
1644
				.selectSumSaleGroupByFofoIdsForMobileOrAccessories(fofoId, curDate.withDayOfMonth(1).minusMonths(1),
1645
						curDate.with(LocalTime.MAX).minusMonths(1), Optional.of(false))
1646
				.get(fofoId);
27638 tejbeer 1647
		Long accesorieslmtdqty = fofoOrderRepository.selectSumSaleQuantityGroupByFofoIdsForMobileOrAccessories(fofoId,
1648
				curDate.withDayOfMonth(1).minusMonths(1), curDate.with(LocalTime.MAX).minusMonths(1),
1649
				Optional.of(false)).get(fofoId);
1650
 
27637 tejbeer 1651
		model.addAttribute("brandLMtdAmount", brandLMtdAmount);
27638 tejbeer 1652
		model.addAttribute("brandLmtdQty", brandLmtdQty);
1653
		model.addAttribute("accesorieslmtdqty", accesorieslmtdqty);
27637 tejbeer 1654
		model.addAttribute("accesorieslmtdsale", accesorieslmtdsale);
1655
		model.addAttribute("customRetailer", customRetailer);
1656
		return "partner-brand-lmtd-sale";
1657
	}
1658
 
27660 tejbeer 1659
	@RequestMapping(value = "/getPatnerBrandWiseLMSSale", method = RequestMethod.GET)
1660
	public String getPatnerBrandWiseLMSSale(HttpServletRequest request,
30564 tejbeer 1661
			@RequestParam(name = ProfitMandiConstants.FOFO_ID) int fofoId, Model model) throws Exception {
27660 tejbeer 1662
		LocalDateTime curDate = LocalDate.now().atStartOfDay();
1663
		CustomRetailer customRetailer = retailerService.getFofoRetailer(fofoId);
1664
		int lengthOfMonth = YearMonth.from(curDate.minusMonths(1)).lengthOfMonth();
1665
 
1666
		Map<String, Double> brandLMSAmount = fofoOrderItemRepository.selectSumAmountGroupByBrand(
27893 tejbeer 1667
				curDate.withDayOfMonth(1).minusMonths(1), curDate.withDayOfMonth(1), fofoId);
27660 tejbeer 1668
		Map<String, Long> brandLmsQty = fofoOrderItemRepository.selectSumQuantityGroupByBrand(
27893 tejbeer 1669
				curDate.withDayOfMonth(1).minusMonths(1), curDate.withDayOfMonth(1), fofoId);
27660 tejbeer 1670
 
27893 tejbeer 1671
		Double accesorieslmssale = fofoOrderRepository.selectSumSaleGroupByFofoIdsForMobileOrAccessories(fofoId,
1672
				curDate.withDayOfMonth(1).minusMonths(1), curDate.withDayOfMonth(1), Optional.of(false)).get(fofoId);
27660 tejbeer 1673
		Long accesorieslmsqty = fofoOrderRepository
1674
				.selectSumSaleQuantityGroupByFofoIdsForMobileOrAccessories(fofoId,
27893 tejbeer 1675
						curDate.withDayOfMonth(1).minusMonths(1), curDate.withDayOfMonth(1), Optional.of(false))
27660 tejbeer 1676
				.get(fofoId);
1677
 
1678
		model.addAttribute("brandLMSAmount", brandLMSAmount);
1679
		model.addAttribute("brandLmsQty", brandLmsQty);
1680
		model.addAttribute("accesorieslmssale", accesorieslmssale);
1681
		model.addAttribute("accesorieslmsqty", accesorieslmsqty);
1682
		model.addAttribute("customRetailer", customRetailer);
1683
		return "partner-brand-lms-sale";
1684
	}
1685
 
27640 tejbeer 1686
	@RequestMapping(value = "/getPatnerInStock", method = RequestMethod.GET)
1687
	public String getPatnerInStock(HttpServletRequest request,
30564 tejbeer 1688
			@RequestParam(name = ProfitMandiConstants.FOFO_ID) int fofoId, Model model) throws Exception {
27640 tejbeer 1689
 
1690
		CustomRetailer customRetailer = retailerService.getFofoRetailer(fofoId);
1691
 
27660 tejbeer 1692
		List<InStockBrandModel> mobileStocks = currentInventorySnapshotRepository
27640 tejbeer 1693
				.selectSumInStockMobileGroupByBrand(fofoId);
27660 tejbeer 1694
		List<InStockBrandModel> accesStock = currentInventorySnapshotRepository
27640 tejbeer 1695
				.selectSumInStockAccessoriesGroupByBrand(fofoId);
1696
 
27660 tejbeer 1697
		List<InStockBrandItemModel> stockItemlist = currentInventorySnapshotRepository
1698
				.selectInStockItemsByBrand(fofoId);
1699
 
1700
		Map<String, List<InStockBrandItemModel>> stockItemMap = stockItemlist.stream()
1701
				.collect(Collectors.groupingBy(InStockBrandItemModel::getBrand));
1702
 
1703
		model.addAttribute("stockItemMap", stockItemMap);
1704
		model.addAttribute("mobileStock", mobileStocks);
1705
		model.addAttribute("accesStock", accesStock);
27640 tejbeer 1706
		model.addAttribute("customRetailer", customRetailer);
1707
		return "partner-instock-item";
1708
	}
1709
 
27660 tejbeer 1710
	@RequestMapping(value = "/getOpenTicketByFofoId", method = RequestMethod.GET)
1711
	public String getOpenTicketByFofoId(HttpServletRequest request,
30564 tejbeer 1712
			@RequestParam(name = ProfitMandiConstants.FOFO_ID) int fofoId, Model model) throws Exception {
27660 tejbeer 1713
		Map<Integer, AuthUser> ticketIdAuthUser = new HashMap<>();
1714
		CustomRetailer customRetailer = retailerService.getFofoRetailer(fofoId);
1715
		List<Integer> ticketIds = ticketRepository.selectAllOpenTicketByRetailer(fofoId).stream().map(x -> x.getId())
1716
				.collect(Collectors.toList());
1717
		List<TicketAssigned> ticketAssigns = ticketAssignedRepository.selectByTicketIds(ticketIds);
1718
 
1719
		for (TicketAssigned ticketAssign : ticketAssigns) {
1720
			AuthUser authUser = authRepository.selectById(ticketAssign.getAssineeId());
1721
			ticketIdAuthUser.put(ticketAssign.getTicketId(), authUser);
1722
		}
1723
		model.addAttribute("ticketIdAuthUser", ticketIdAuthUser);
1724
		model.addAttribute("ticketAssigns", ticketAssigns);
1725
		model.addAttribute("customRetailer", customRetailer);
1726
		return "open-ticket";
1727
	}
1728
 
27893 tejbeer 1729
	@RequestMapping(value = "/getPartnerSecondarySale", method = RequestMethod.GET)
1730
	public String getPartnerSecondarySale(HttpServletRequest request,
30564 tejbeer 1731
			@RequestParam(name = ProfitMandiConstants.FOFO_ID) int fofoId, @RequestParam String timeValue, Model model)
27893 tejbeer 1732
			throws Exception {
1733
		LocalDateTime curDate = LocalDate.now().atStartOfDay();
1734
		CustomRetailer customRetailer = retailerService.getFofoRetailer(fofoId);
1735
		int lengthOfMonth = YearMonth.from(curDate.minusMonths(1)).lengthOfMonth();
1736
		LocalDateTime startDate = null;
1737
		LocalDateTime endDate = null;
1738
		List<InStockBrandModel> secondarySale = null;
1739
		Map<String, List<InStockBrandItemModel>> secondaryItemSale = null;
1740
 
1741
		if (timeValue.equals("mtd")) {
1742
			startDate = curDate.withDayOfMonth(1);
1743
			endDate = curDate.with(LocalTime.MAX);
1744
			secondarySale = orderRepository.selectAllBilledOrderBrandByFofoId(startDate, endDate, fofoId);
1745
			secondaryItemSale = orderRepository.selectAllBilledOrderBrandItemByFofoId(startDate, endDate, fofoId)
1746
					.stream().collect(Collectors.groupingBy(InStockBrandItemModel::getBrand));
1747
			LOGGER.info("secondarySalemtd" + secondarySale);
1748
		} else if (timeValue.equals("lmtd")) {
1749
			startDate = curDate.withDayOfMonth(1).minusMonths(1);
1750
			endDate = curDate.with(LocalTime.MAX).minusMonths(1);
1751
			secondaryItemSale = orderRepository.selectAllBilledOrderBrandItemByFofoId(startDate, endDate, fofoId)
1752
					.stream().collect(Collectors.groupingBy(InStockBrandItemModel::getBrand));
1753
 
1754
			secondarySale = orderRepository.selectAllBilledOrderBrandByFofoId(startDate, endDate, fofoId);
1755
			LOGGER.info("secondarySalelmtd" + secondarySale);
1756
 
1757
		} else {
1758
			startDate = curDate.withDayOfMonth(1).minusMonths(1);
1759
			endDate = curDate.withDayOfMonth(1);
1760
			secondaryItemSale = orderRepository.selectAllBilledOrderBrandItemByFofoId(startDate, endDate, fofoId)
1761
					.stream().collect(Collectors.groupingBy(InStockBrandItemModel::getBrand));
1762
 
1763
			secondarySale = orderRepository.selectAllBilledOrderBrandByFofoId(startDate, endDate, fofoId);
1764
			LOGGER.info("secondarySalelms" + secondarySale);
1765
 
1766
		}
1767
 
1768
		LOGGER.info("secondarySale" + secondarySale);
1769
		model.addAttribute("secondarySale", secondarySale);
1770
		model.addAttribute("secondaryItemSale", secondaryItemSale);
1771
		model.addAttribute("customRetailer", customRetailer);
1772
 
1773
		return "partner-secondary-order";
1774
	}
1775
 
28451 tejbeer 1776
	@RequestMapping(value = "/getMobileBrandWise", method = RequestMethod.GET)
1777
	public String getMobileBrandWise(HttpServletRequest request, Model model) throws Exception {
1778
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1779
		String email = loginDetails.getEmailId();
1780
 
1781
		AuthUser authUser = authRepository.selectByEmailOrMobile(email);
31152 tejbeer 1782
		Set<Integer> fofoIds = csService.getAuthFofoIds(email);
28451 tejbeer 1783
 
1784
		Map<String, BrandWisePartnerSaleModel> partnersBrandSaleMap = null;
1785
		partnersBrandSaleMap = fofoStoreRepository.selectGroupByBrandWarehousePartnerSale(new ArrayList<>(fofoIds))
1786
				.stream().collect(Collectors.toMap(x -> x.getBrand(), x -> x));
1787
 
1788
		List<BrandWiseUnbilledActivateStockModel> unbilledActivatedStock = fofoStoreRepository
1789
				.selectUnbilledActivateStockGroupByBrand(new ArrayList<>(fofoIds));
1790
		for (BrandWiseUnbilledActivateStockModel un : unbilledActivatedStock) {
1791
			BrandWisePartnerSaleModel bpt = partnersBrandSaleMap.get(un.getBrand());
1792
			if (bpt != null) {
1793
				bpt.setAmtd(un.getUnbilledMtd());
1794
				bpt.setUamtdQty(un.getUnbilledMTDQty());
1795
			} else {
1796
				bpt = new BrandWisePartnerSaleModel();
1797
				bpt.setBrand(un.getBrand());
1798
				bpt.setAmtd(un.getUnbilledMtd());
1799
				bpt.setUamtdQty(un.getUnbilledMTDQty());
1800
				bpt.setLms(0);
1801
				bpt.setLmtd(0);
1802
				bpt.setMtd(0);
1803
				bpt.setMtdQty(0);
1804
				bpt.setLmtd(0);
1805
				bpt.setLmtdQty(0);
1806
				partnersBrandSaleMap.put(un.getBrand(), bpt);
1807
			}
1808
		}
1809
 
1810
		model.addAttribute("brandSalesMap", partnersBrandSaleMap);
1811
 
1812
		return "mobile-brand-wise-report";
1813
	}
1814
 
1815
	@RequestMapping(value = "/getAccessoriesBrandWise", method = RequestMethod.GET)
1816
	public String getAccessoriesBrandWise(HttpServletRequest request, Model model) throws Exception {
1817
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1818
		String email = loginDetails.getEmailId();
1819
 
31152 tejbeer 1820
		Set<Integer> fofoIds = csService.getAuthFofoIds(email);
28451 tejbeer 1821
 
1822
		List<BrandWisePartnerSaleModel> accessoriesBrandSales = null;
1823
 
1824
		accessoriesBrandSales = fofoStoreRepository
1825
				.selectGroupByBrandAccesoriesWarehousePartnerSale(new ArrayList<>(fofoIds));
1826
 
1827
		model.addAttribute("accessoriesBrandSales", accessoriesBrandSales);
1828
		return "accessories-brand-wise-report";
1829
	}
1830
 
1831
	@RequestMapping(value = "/getMobileLMSGraph", method = RequestMethod.GET)
28461 tejbeer 1832
	public String getMobileLMSGraph(HttpServletRequest request, @RequestParam(required = false) int warehouseId,
30564 tejbeer 1833
			@RequestParam(required = false) LocalDateTime date, @RequestParam(required = false) LocalDateTime endDate,
1834
			@RequestParam List<Integer> fofoIds, @RequestParam String filterType, Model model) throws Exception {
28451 tejbeer 1835
		Map<Integer, List<Integer>> warehouseIdFofoIdMap = fofoStoreRepository
1836
				.selectActivePartnersByRetailerIds(new ArrayList<>(fofoIds)).stream().collect(Collectors.groupingBy(
1837
						FofoStore::getWarehouseId, Collectors.mapping(FofoStore::getId, Collectors.toList())));
1838
 
1839
		ChartModel cm;
1840
		if (warehouseId != 0) {
28468 tejbeer 1841
			cm = adminUser.getBrandWiseLms(Arrays.asList(warehouseId),
30279 tejbeer 1842
					fofoIds.stream().map(x -> x).collect(Collectors.toList()), date.toLocalDate(),
1843
					endDate.toLocalDate(), filterType);
28451 tejbeer 1844
		} else {
28468 tejbeer 1845
			cm = adminUser.getBrandWiseLms(new ArrayList<>(warehouseIdFofoIdMap.keySet()),
30279 tejbeer 1846
					fofoIds.stream().map(x -> x).collect(Collectors.toList()), date.toLocalDate(),
1847
					endDate.toLocalDate(), filterType);
28451 tejbeer 1848
 
1849
		}
1850
 
1851
		LOGGER.info("chartMap" + gson.toJson(cm));
1852
		model.addAttribute("chartMap", gson.toJson(cm));
1853
		return "brand-wise-mobile-lms-chart";
1854
	}
1855
 
28461 tejbeer 1856
	@RequestMapping(value = "/getMobileLMSFilter", method = RequestMethod.GET)
1857
	public String getMobileLMSFilter(HttpServletRequest request,
30564 tejbeer 1858
			@RequestParam(required = false, defaultValue = "0") int warehouseId,
1859
			@RequestParam(required = false) LocalDateTime date, @RequestParam(required = false) LocalDateTime endDate,
1860
			Model model) throws Exception {
28461 tejbeer 1861
 
1862
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1863
		String email = loginDetails.getEmailId();
1864
 
30279 tejbeer 1865
		if (date == null) {
1866
			LocalDateTime curDate = LocalDate.now().atStartOfDay();
28461 tejbeer 1867
 
30279 tejbeer 1868
			LocalDateTime startOfMonth = curDate.withDayOfMonth(1).minusMonths(6);
1869
			date = startOfMonth.toLocalDate().atStartOfDay();
1870
		}
28461 tejbeer 1871
 
30279 tejbeer 1872
		if (endDate == null) {
1873
			LocalDateTime curDate = LocalDate.now().atTime(LocalTime.MAX);
1874
 
1875
			endDate = curDate;
1876
 
1877
		}
1878
 
1879
		Map<String, Object> map = adminUser.getFilter(warehouseId, email, date, endDate);
28461 tejbeer 1880
		model.addAttribute("warehouseId", warehouseId);
1881
		model.addAllAttributes(map);
1882
 
30279 tejbeer 1883
		return "chart-filter-lms";
28461 tejbeer 1884
	}
1885
 
1886
	@RequestMapping(value = "/getMobileLMPGraph", method = RequestMethod.GET)
1887
	public String getMobileLMPGraph(HttpServletRequest request, @RequestParam(required = false) int warehouseId,
30564 tejbeer 1888
			@RequestParam(required = false) LocalDateTime date, @RequestParam(required = false) LocalDateTime endDate,
1889
			@RequestParam List<Integer> fofoIds, @RequestParam String filterType, Model model) throws Exception {
28461 tejbeer 1890
		Map<Integer, List<Integer>> warehouseIdFofoIdMap = fofoStoreRepository
1891
				.selectActivePartnersByRetailerIds(new ArrayList<>(fofoIds)).stream().collect(Collectors.groupingBy(
1892
						FofoStore::getWarehouseId, Collectors.mapping(FofoStore::getId, Collectors.toList())));
1893
 
1894
		ChartModel cm;
1895
		if (warehouseId != 0) {
28468 tejbeer 1896
			cm = adminUser.getBrandWiseLmp(Arrays.asList(warehouseId),
30279 tejbeer 1897
					fofoIds.stream().map(x -> x).collect(Collectors.toList()), date.toLocalDate(),
1898
					endDate.toLocalDate(), filterType);
28461 tejbeer 1899
		} else {
28468 tejbeer 1900
			cm = adminUser.getBrandWiseLmp(new ArrayList<>(warehouseIdFofoIdMap.keySet()),
30279 tejbeer 1901
					fofoIds.stream().map(x -> x).collect(Collectors.toList()), date.toLocalDate(),
1902
					endDate.toLocalDate(), filterType);
28461 tejbeer 1903
 
1904
		}
1905
 
1906
		LOGGER.info("chartMap" + gson.toJson(cm));
1907
		model.addAttribute("chartMap", gson.toJson(cm));
1908
		return "brand-wise-mobile-lmp-chart";
1909
	}
1910
 
31273 tejbeer 1911
	@RequestMapping(value = "/getSaleCountByMilestone", method = RequestMethod.GET)
1912
	public String getSaleCountByMilestone(HttpServletRequest request,
31259 tejbeer 1913
			@RequestParam(required = false, defaultValue = "0") int warehouseId, Model model) throws Exception {
1914
 
1915
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1916
		String email = loginDetails.getEmailId();
1917
		Set<Integer> fofoIds = csService.getAuthFofoIds(email);
31273 tejbeer 1918
		Map<Integer, Double> last3MonthSale = fofoOrderItemRepository.selectSumMopGroupByRetailer(
1919
				LocalDateTime.now().withDayOfMonth(1).minusMonths(2), LocalDateTime.now(), 0, false);
31259 tejbeer 1920
 
1921
		if (fofoIds != null && fofoIds.size() > 0) {
31273 tejbeer 1922
			if (warehouseId != 0) {
1923
				fofoIds = fofoStoreRepository.selectPartnerByfofoIdAndWarehouse(new ArrayList<>(fofoIds), warehouseId)
1924
						.stream().map(x -> x).collect(Collectors.toSet());
1925
			}
31259 tejbeer 1926
			Map<Integer, PartnerDetailModel> partnerStats = adminUser.getPartnersStatDataFromFile();
1927
			if (partnerStats != null) {
31263 tejbeer 1928
				List<PartnerDetailModel> partnerDetails = fofoIds.stream().filter(x -> partnerStats.containsKey(x))
1929
						.map(x -> partnerStats.get(x)).collect(Collectors.toList());
31318 tejbeer 1930
				Map<Milestone, List<Integer>> avg3Monthlms = new HashMap<>();
31267 tejbeer 1931
				if (!last3MonthSale.isEmpty()) {
1932
					int days = 60 + LocalDateTime.now().getDayOfMonth();
1933
					for (Entry<Integer, Double> last3MonthEntry : last3MonthSale.entrySet()) {
1934
						if (fofoIds.contains(last3MonthEntry.getKey())) {
1935
							Double monthSale = last3MonthEntry.getValue();
1936
							if (monthSale == null) {
1937
								monthSale = (double) 0;
1938
 
1939
							}
1940
							double avg3MonthSale = (monthSale / days) * 30;
31269 tejbeer 1941
							Milestone milestone = Milestone.get((int) avg3MonthSale);
31318 tejbeer 1942
 
1943
							List<Integer> values = null;
31319 tejbeer 1944
 
31273 tejbeer 1945
							if (avg3Monthlms.containsKey(milestone)) {
31318 tejbeer 1946
 
1947
								values = avg3Monthlms.get(milestone);
1948
								values.add(last3MonthEntry.getKey());
1949
								avg3Monthlms.put(milestone, values);
1950
 
31267 tejbeer 1951
							} else {
31319 tejbeer 1952
								values = new ArrayList<>();
1953
 
31318 tejbeer 1954
								values.add(last3MonthEntry.getKey());
1955
								avg3Monthlms.put(milestone, values);
31267 tejbeer 1956
 
1957
							}
1958
						}
1959
 
1960
					}
1961
 
1962
				}
1963
 
31260 tejbeer 1964
				if (partnerDetails != null) {
31263 tejbeer 1965
 
31318 tejbeer 1966
					Map<Milestone, List<Integer>> mtdMap = partnerDetails.stream()
31285 tejbeer 1967
							.collect(Collectors.groupingBy(x -> Milestone.get(x.getMtd()),
1968
									Collectors.mapping(x -> x.getFofoId(), Collectors.toList())));
31318 tejbeer 1969
					Map<Milestone, List<Integer>> lmtdMap = partnerDetails.stream()
1970
							.collect(Collectors.groupingBy(x -> Milestone.get(x.getLmtd()),
1971
									Collectors.mapping(x -> x.getFofoId(), Collectors.toList())));
31285 tejbeer 1972
 
31318 tejbeer 1973
					Map<Milestone, List<Integer>> lmsMap = partnerDetails.stream()
1974
							.collect(Collectors.groupingBy(x -> Milestone.get(x.getLms()),
1975
									Collectors.mapping(x -> x.getFofoId(), Collectors.toList())));
1976
 
31260 tejbeer 1977
					model.addAttribute("mtdMap", mtdMap);
1978
					model.addAttribute("lmtdMap", lmtdMap);
31273 tejbeer 1979
					model.addAttribute("avg3Monthlms", avg3Monthlms);
31260 tejbeer 1980
					model.addAttribute("lmsMap", lmsMap);
1981
				}
1982
 
31259 tejbeer 1983
			}
1984
		}
1985
 
31267 tejbeer 1986
		model.addAttribute("warehouseMap", ProfitMandiConstants.WAREHOUSE_MAP);
31273 tejbeer 1987
		model.addAttribute("warehouseId", warehouseId);
1988
		model.addAttribute("milestones", Milestone.values());
31267 tejbeer 1989
 
31273 tejbeer 1990
		return "sale-milestone";
1991
 
1992
	}
1993
 
1994
	@RequestMapping(value = "/getPurchaseCountByMileStone", method = RequestMethod.GET)
1995
	public String getPurchaseCountByMileStone(HttpServletRequest request,
1996
			@RequestParam(required = false, defaultValue = "0") int warehouseId, Model model) throws Exception {
1997
 
1998
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1999
		String email = loginDetails.getEmailId();
2000
		Set<Integer> fofoIds = csService.getAuthFofoIds(email);
2001
		Map<Integer, Double> last3MonthS = orderRepository.selectBillingDatesBetweenSumGroupByRetailerId(
2002
				LocalDateTime.now().withDayOfMonth(1).minusMonths(2), LocalDateTime.now());
2003
 
2004
		if (fofoIds != null && fofoIds.size() > 0) {
2005
			if (warehouseId != 0) {
2006
				fofoIds = fofoStoreRepository.selectPartnerByfofoIdAndWarehouse(new ArrayList<>(fofoIds), warehouseId)
2007
						.stream().map(x -> x).collect(Collectors.toSet());
2008
			}
2009
			Map<Integer, PartnerDetailModel> partnerStats = adminUser.getPartnersStatDataFromFile();
2010
			if (partnerStats != null) {
2011
				List<PartnerDetailModel> partnerDetails = fofoIds.stream().filter(x -> partnerStats.containsKey(x))
2012
						.map(x -> partnerStats.get(x)).collect(Collectors.toList());
31320 tejbeer 2013
				Map<Milestone, List<Integer>> avg3MonthS = new HashMap<>();
31273 tejbeer 2014
				if (!last3MonthS.isEmpty()) {
2015
					int days = 60 + LocalDateTime.now().getDayOfMonth();
2016
					for (Entry<Integer, Double> last3MonthSEntry : last3MonthS.entrySet()) {
2017
						if (fofoIds.contains(last3MonthSEntry.getKey())) {
2018
							Double monthSec = last3MonthSEntry.getValue();
2019
							if (monthSec == null) {
2020
								monthSec = (double) 0;
2021
 
2022
							}
2023
							double avg3MonthSale = (monthSec / days) * 30;
2024
							Milestone milestone = Milestone.get((int) avg3MonthSale);
31320 tejbeer 2025
 
2026
							List<Integer> values = null;
31273 tejbeer 2027
							if (avg3MonthS.containsKey(milestone)) {
31320 tejbeer 2028
								values = avg3MonthS.get(milestone);
2029
								values.add(last3MonthSEntry.getKey());
2030
 
2031
								avg3MonthS.put(milestone, values);
31273 tejbeer 2032
							} else {
2033
 
31320 tejbeer 2034
								values = new ArrayList<>();
2035
 
2036
								values.add(last3MonthSEntry.getKey());
2037
 
2038
								avg3MonthS.put(milestone, values);
2039
 
31273 tejbeer 2040
							}
2041
						}
2042
 
2043
					}
2044
 
2045
				}
2046
 
2047
				if (partnerDetails != null) {
31320 tejbeer 2048
					Map<Milestone, List<Integer>> smtdMap = partnerDetails.stream()
2049
							.collect(Collectors.groupingBy(x -> Milestone.get(x.getSecondarymtd()),
2050
									Collectors.mapping(x -> x.getFofoId(), Collectors.toList())));
2051
					Map<Milestone, List<Integer>> slmtdMap = partnerDetails.stream()
2052
							.collect(Collectors.groupingBy(x -> Milestone.get(x.getSecondarylmtd()),
2053
									Collectors.mapping(x -> x.getFofoId(), Collectors.toList())));
2054
					Map<Milestone, List<Integer>> lmsMap = partnerDetails.stream()
2055
							.collect(Collectors.groupingBy(x -> Milestone.get(x.getSecondarylms()),
2056
									Collectors.mapping(x -> x.getFofoId(), Collectors.toList())));
31273 tejbeer 2057
 
2058
					model.addAttribute("smtdMap", smtdMap);
2059
					model.addAttribute("slmtdMap", slmtdMap);
2060
					model.addAttribute("avg3MonthS", avg3MonthS);
2061
					model.addAttribute("lmsMap", lmsMap);
2062
 
2063
				}
2064
 
2065
			}
31270 tejbeer 2066
		}
31267 tejbeer 2067
 
31273 tejbeer 2068
		model.addAttribute("warehouseMap", ProfitMandiConstants.WAREHOUSE_MAP);
31267 tejbeer 2069
		model.addAttribute("warehouseId", warehouseId);
31259 tejbeer 2070
		model.addAttribute("milestones", Milestone.values());
2071
 
31273 tejbeer 2072
		return "purchase-milestone";
31259 tejbeer 2073
 
2074
	}
2075
 
28825 tejbeer 2076
	@RequestMapping(value = "/getActivatedModelWarehouseWise", method = RequestMethod.GET)
2077
	public String getActivatedModelWarehouseWise(HttpServletRequest request, Model model, @RequestParam String brand)
2078
			throws Exception {
2079
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
2080
		List<Integer> fofoIds = getFofoIds(loginDetails);
2081
		List<WarehouseWiseActivatedModel> warehouseWiseActivatedModels = activatedImeiRepository
2082
				.selectActivatedModelGroupByWarehouse(brand, fofoIds);
2083
		Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
2084
 
2085
		List<DBObject> mobileBrands = mongoClient.getAllBrandsToDisplay(3);
2086
 
2087
		List<String> brands = mobileBrands.stream().map(x -> (String) x.get("name")).collect(Collectors.toList());
2088
		LOGGER.info("brands" + brands.add("Redmi"));
2089
 
2090
		model.addAttribute("warehouseWiseActivatedModels", warehouseWiseActivatedModels);
2091
		model.addAttribute("warehouseMap", warehouseMap);
2092
		model.addAttribute("brands", brands);
2093
		model.addAttribute("selectedbrand", brand);
2094
		return "warehousewise_activated_model";
2095
	}
2096
 
2097
	@RequestMapping(value = "/getActivatedModelByBrand", method = RequestMethod.GET)
2098
	public String getActivatedModelByBrand(HttpServletRequest request, Model model) throws Exception {
2099
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
31152 tejbeer 2100
		Set<Integer> fofoIds = csService.getAuthFofoIds(loginDetails.getEmailId());
2101
 
28825 tejbeer 2102
		List<BrandWiseActivatedModel> activatedModels = activatedImeiRepository
2103
				.selectActivatedModelGroupByBrand(new ArrayList<>(fofoIds));
2104
		model.addAttribute("activatedModels", activatedModels);
2105
		return "activation-brandwise-report";
2106
	}
2107
 
2108
	@RequestMapping(value = "/getWarehouseBrandWiseItemActivatedModel", method = RequestMethod.GET)
2109
	public String getWarehouseBrandWiseItemActivatedModel(HttpServletRequest request, Model model,
30564 tejbeer 2110
			@RequestParam List<Integer> warehouseId, @RequestParam String brand) throws Exception {
28825 tejbeer 2111
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
2112
		List<Integer> fofoIds = getFofoIds(loginDetails);
2113
 
2114
		Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
2115
		List<WarehouseBrandWiseItemActivatedModel> activatedItems = activatedImeiRepository
2116
				.selectWarehouseBrandActivatedItem(warehouseId, brand, fofoIds);
2117
		model.addAttribute("warehouseMap", warehouseMap);
2118
		model.addAttribute("activatedItems", activatedItems);
2119
		return "warehouse-activated-itemwise-model";
2120
 
2121
	}
2122
 
2123
	@RequestMapping(value = "/getActivatedImeiUpdationDate", method = RequestMethod.GET)
2124
	public String getActivatedImeiUpdationDate(HttpServletRequest request, Model model) throws Exception {
2125
 
2126
		Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
2127
 
2128
		List<ActivationImeiUpdationModel> activationImeiUpdations = activatedImeiRepository
2129
				.selectActivatedUpdationDate();
2130
		model.addAttribute("warehouseMap", warehouseMap);
2131
		model.addAttribute("activationImeiUpdations", activationImeiUpdations);
2132
		return "activation-updation-timestamp";
2133
 
2134
	}
2135
 
2136
	private List<Integer> getFofoIds(LoginDetails loginDetails) throws ProfitMandiBusinessException {
2137
		String email = loginDetails.getEmailId();
2138
 
2139
		AuthUser authUser = authRepository.selectByEmailOrMobile(email);
2140
		Map<String, Set<Integer>> storeGuyMap = csService.getAuthUserPartnerIdMapping();
2141
 
2142
		Set<Integer> fofoIds = storeGuyMap.get(authUser.getEmailId());
2143
		if (emails.contains(authUser.getEmailId())) {
2144
			fofoIds = storeGuyMap.get("tarun.verma@smartdukaan.com");
2145
			LOGGER.info("fofoIds" + fofoIds);
2146
		}
2147
 
2148
		if (fofoIds == null) {
2149
			List<Position> positions1 = positionRepository.selectAll(authUser.getId());
2150
			if (positions1.stream().filter(x -> x.getCategoryId() == ProfitMandiConstants.TICKET_CATEGORY_MASTER)
2151
					.count() > 0) {
2152
				fofoIds = csService.getPositionCustomRetailerMap(positions1).values().stream().flatMap(x -> x.stream())
2153
						.map(x -> x.getPartnerId()).collect(Collectors.toSet());
2154
			}
2155
		}
2156
		return new ArrayList<>(fofoIds);
2157
	}
2158
 
31285 tejbeer 2159
	@RequestMapping(value = "/getMonthWiseSale", method = RequestMethod.GET)
2160
	public String getPartnerSaleByMonth(HttpServletRequest request, @RequestParam List<Integer> fofoIds, Model model)
2161
			throws Exception {
2162
 
31287 tejbeer 2163
		YearMonth now = YearMonth.now();
2164
		YearMonth ym = YearMonth.now().minusMonths(12);
2165
		List<YearMonth> list = new ArrayList<>();
31315 tejbeer 2166
		while (!now.isBefore(ym)) {
2167
			list.add(now);
2168
			now = now.minusMonths(1);
31287 tejbeer 2169
		}
2170
 
2171
		model.addAttribute("yearMonth", list);
2172
 
31285 tejbeer 2173
		List<PartnerMonthlySaleModel> partnerMonthlySaleModels = fofoOrderItemRepository
31301 tejbeer 2174
				.selectPartnerMonthlySale(fofoIds, LocalDateTime.now().minusMonths(12).withDayOfMonth(1));
31287 tejbeer 2175
		DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("MM-yyyy");
2176
		Map<Integer, Map<YearMonth, Double>> partnerMonthSaleMap = new HashMap<>();
2177
		if (!partnerMonthlySaleModels.isEmpty()) {
2178
 
2179
			partnerMonthSaleMap = partnerMonthlySaleModels.stream()
2180
					.collect(Collectors.groupingBy(x -> x.getFofoId(), Collectors.toMap(
2181
							x -> YearMonth.parse(x.getYearMonth(), dateTimeFormatter), x -> (double) x.getAmount())));
2182
		}
2183
 
2184
		Map<Integer, CustomRetailer> customRetailerMap = retailerService.getFofoRetailerUserId(fofoIds);
2185
 
2186
		model.addAttribute("customRetailerMap", customRetailerMap);
2187
 
2188
		model.addAttribute("customRetailerMap", customRetailerMap);
2189
 
2190
		model.addAttribute("partnerMonthSaleMap", partnerMonthSaleMap);
2191
		return "monthly-partner-sale";
2192
 
31285 tejbeer 2193
	}
31297 tejbeer 2194
 
2195
	@RequestMapping(value = "/getMonthWisePurchase", method = RequestMethod.GET)
2196
	public String getMonthWisePurchase(HttpServletRequest request, @RequestParam List<Integer> fofoIds, Model model)
2197
			throws Exception {
2198
 
2199
		YearMonth now = YearMonth.now();
2200
		YearMonth ym = YearMonth.now().minusMonths(12);
2201
		List<YearMonth> list = new ArrayList<>();
31315 tejbeer 2202
		while (!now.isBefore(ym)) {
2203
			list.add(now);
2204
			now = now.minusMonths(1);
31297 tejbeer 2205
		}
2206
 
2207
		model.addAttribute("yearMonth", list);
2208
		ArrayList<in.shop2020.model.v1.order.OrderStatus> orderStatus = new ArrayList<>();
2209
 
2210
		orderStatus.add(SUBMITTED_FOR_PROCESSING);
2211
		orderStatus.add(BILLED);
2212
		orderStatus.add(SHIPPED_FROM_WH);
2213
		orderStatus.add(DELIVERY_SUCCESS);
31301 tejbeer 2214
		List<Order> orders = orderRepository.selectOrders(fofoIds, orderStatus,
2215
				LocalDateTime.now().minusMonths(12).withDayOfMonth(1), LocalDateTime.now().plusDays(1));
31297 tejbeer 2216
 
31299 tejbeer 2217
		Map<Integer, Map<YearMonth, Double>> partnerMonthPurchaseMap = orders.stream()
31297 tejbeer 2218
				.collect(Collectors.groupingBy(x -> x.getRetailerId(),
2219
						Collectors.groupingBy(x -> YearMonth.from(x.getCreateTimestamp()),
31308 tejbeer 2220
								Collectors.summingDouble(x -> Math.round(x.getTotalAmount().doubleValue())))));
31297 tejbeer 2221
 
31300 tejbeer 2222
		LOGGER.info("orders" + orders);
31297 tejbeer 2223
 
2224
		Map<Integer, CustomRetailer> customRetailerMap = retailerService.getFofoRetailerUserId(fofoIds);
2225
 
2226
		model.addAttribute("customRetailerMap", customRetailerMap);
2227
 
2228
		model.addAttribute("customRetailerMap", customRetailerMap);
2229
 
2230
		model.addAttribute("partnerMonthPurchaseMap", partnerMonthPurchaseMap);
2231
		return "monthly-partner-purchase";
2232
 
2233
	}
21615 kshitij.so 2234
}