Subversion Repositories SmartDukaan

Rev

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