Subversion Repositories SmartDukaan

Rev

Rev 30564 | Rev 30668 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 30564 Rev 30664
Line 12... Line 12...
12
import com.spice.profitmandi.dao.entity.auth.AuthUser;
12
import com.spice.profitmandi.dao.entity.auth.AuthUser;
13
import com.spice.profitmandi.dao.entity.catalog.Category;
13
import com.spice.profitmandi.dao.entity.catalog.Category;
14
import com.spice.profitmandi.dao.entity.catalog.FocusedModel;
14
import com.spice.profitmandi.dao.entity.catalog.FocusedModel;
15
import com.spice.profitmandi.dao.entity.catalog.Item;
15
import com.spice.profitmandi.dao.entity.catalog.Item;
16
import com.spice.profitmandi.dao.entity.catalog.TagListing;
16
import com.spice.profitmandi.dao.entity.catalog.TagListing;
17
import com.spice.profitmandi.dao.entity.cs.Position;
-
 
18
import com.spice.profitmandi.dao.entity.cs.Region;
17
import com.spice.profitmandi.dao.entity.cs.Region;
19
import com.spice.profitmandi.dao.entity.fofo.*;
18
import com.spice.profitmandi.dao.entity.fofo.*;
20
import com.spice.profitmandi.dao.entity.inventory.SaholicCIS;
19
import com.spice.profitmandi.dao.entity.inventory.SaholicCISTable;
21
import com.spice.profitmandi.dao.entity.inventory.SaholicPOItem;
20
import com.spice.profitmandi.dao.entity.inventory.SaholicPOItem;
22
import com.spice.profitmandi.dao.entity.transaction.Order;
21
import com.spice.profitmandi.dao.entity.transaction.Order;
23
import com.spice.profitmandi.dao.entity.transaction.UserWallet;
22
import com.spice.profitmandi.dao.entity.transaction.UserWallet;
24
import com.spice.profitmandi.dao.entity.user.User;
23
import com.spice.profitmandi.dao.entity.user.User;
25
import com.spice.profitmandi.dao.entity.warehouse.BrandRegionMapping;
24
import com.spice.profitmandi.dao.entity.warehouse.BrandRegionMapping;
Line 39... Line 38...
39
import com.spice.profitmandi.dao.repository.dtr.BrandLimitRepository;
38
import com.spice.profitmandi.dao.repository.dtr.BrandLimitRepository;
40
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
39
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
41
import com.spice.profitmandi.dao.repository.dtr.Mongo;
40
import com.spice.profitmandi.dao.repository.dtr.Mongo;
42
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
41
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
43
import com.spice.profitmandi.dao.repository.fofo.*;
42
import com.spice.profitmandi.dao.repository.fofo.*;
-
 
43
import com.spice.profitmandi.dao.repository.inventory.SaholicCISTableRepository;
44
import com.spice.profitmandi.dao.repository.inventory.SaholicInventoryCISRepository;
44
import com.spice.profitmandi.dao.repository.inventory.SaholicInventoryCISRepository;
45
import com.spice.profitmandi.dao.repository.inventory.WarehouseRepository;
45
import com.spice.profitmandi.dao.repository.inventory.WarehouseRepository;
46
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
46
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
47
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
47
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
48
import com.spice.profitmandi.dao.repository.user.UserRepository;
48
import com.spice.profitmandi.dao.repository.user.UserRepository;
Line 218... Line 218...
218
	@Autowired
218
	@Autowired
219
	private PartnerDailyInvestmentRepository partnerDailyInvestmentRepository;
219
	private PartnerDailyInvestmentRepository partnerDailyInvestmentRepository;
220
	@Autowired
220
	@Autowired
221
	private SuggestedPoDetailRepository suggestedPoDetailRepository;
221
	private SuggestedPoDetailRepository suggestedPoDetailRepository;
222
 
222
 
-
 
223
	@Autowired
-
 
224
	SaholicCISTableRepository saholicCISTableRepository;
-
 
225
 
223
	@RequestMapping(value = "/open-indent/save", method = RequestMethod.POST)
226
	@RequestMapping(value = "/open-indent/save", method = RequestMethod.POST)
224
	public String saveOpenIndent(HttpServletRequest request, Model model, @RequestParam int catalogId,
227
	public String saveOpenIndent(HttpServletRequest request, Model model, @RequestParam int catalogId,
225
			@RequestParam int itemQty, @RequestParam int fofoId) throws Exception {
228
								 @RequestParam int itemQty, @RequestParam int fofoId) throws Exception {
226
		if (fofoId == 0) {
229
		if (fofoId == 0) {
227
 
230
 
228
			LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
231
			LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
229
			fofoId = loginDetails.getFofoId();
232
			fofoId = loginDetails.getFofoId();
230
 
233
 
Line 242... Line 245...
242
		model.addAttribute("response", mvcResponseSender.createResponseString(false));
245
		model.addAttribute("response", mvcResponseSender.createResponseString(false));
243
		return "response";
246
		return "response";
244
	}
247
	}
245
 
248
 
246
	private void saveMonthlyPlanned(MonthlyPlanned monthlyPlanned, int fofoId, LocalDate currentMonthDate,
249
	private void saveMonthlyPlanned(MonthlyPlanned monthlyPlanned, int fofoId, LocalDate currentMonthDate,
247
			int catalogId, int itemQty) {
250
									int catalogId, int itemQty) {
248
		if (monthlyPlanned == null) {
251
		if (monthlyPlanned == null) {
249
			monthlyPlanned = new MonthlyPlanned();
252
			monthlyPlanned = new MonthlyPlanned();
250
			monthlyPlanned.setFofoId(fofoId);
253
			monthlyPlanned.setFofoId(fofoId);
251
			monthlyPlanned.setYearMonth(currentMonthDate);
254
			monthlyPlanned.setYearMonth(currentMonthDate);
252
			monthlyPlannedRepository.persist(monthlyPlanned);
255
			monthlyPlannedRepository.persist(monthlyPlanned);
Line 280... Line 283...
280
 
283
 
281
	}
284
	}
282
 
285
 
283
	@RequestMapping(value = "/open-indent/confirm", method = RequestMethod.POST)
286
	@RequestMapping(value = "/open-indent/confirm", method = RequestMethod.POST)
284
	public String confirmOpenIndent(HttpServletRequest request,
287
	public String confirmOpenIndent(HttpServletRequest request,
285
			@RequestParam(required = false, defaultValue = "0") int fofoId, Model model) throws Exception {
288
									@RequestParam(required = false, defaultValue = "0") int fofoId, Model model) throws Exception {
286
 
289
 
287
		if (fofoId == 0) {
290
		if (fofoId == 0) {
288
			LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
291
			LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
289
			fofoId = loginDetails.getFofoId();
292
			fofoId = loginDetails.getFofoId();
290
		}
293
		}
Line 336... Line 339...
336
				Arrays.asList("Partner Id", "Partner Name", "Model Name", "Qty"),
339
				Arrays.asList("Partner Id", "Partner Name", "Model Name", "Qty"),
337
				plannedModel.stream()
340
				plannedModel.stream()
338
						.map(x -> Arrays.asList(x.getFofoId(), x.getStoreName(), x.getItemDescription(), x.getQty()))
341
						.map(x -> Arrays.asList(x.getFofoId(), x.getStoreName(), x.getItemDescription(), x.getQty()))
339
						.collect(Collectors.toList()));
342
						.collect(Collectors.toList()));
340
		LOGGER.info("baos" + baos);
343
		LOGGER.info("baos" + baos);
341
		Utils.sendMailWithAttachments(googleMailSender, new String[] { customRetailer.getEmail() },
344
		Utils.sendMailWithAttachments(googleMailSender, new String[]{customRetailer.getEmail()},
342
				ccemails.toArray(new String[ccemails.size()]), bccemails.toArray(new String[bccemails.size()]),
345
				ccemails.toArray(new String[ccemails.size()]), bccemails.toArray(new String[bccemails.size()]),
343
				"Planned Indent", "PFA",
346
				"Planned Indent", "PFA",
344
				new Attachment[] { new Attachment("PlannedIndent.csv", new ByteArrayResource(baos.toByteArray())), });
347
				new Attachment[]{new Attachment("PlannedIndent.csv", new ByteArrayResource(baos.toByteArray())),});
345
 
348
 
346
	}
349
	}
347
 
350
 
348
	@RequestMapping(value = "/indent/download", method = RequestMethod.GET)
351
	@RequestMapping(value = "/indent/download", method = RequestMethod.GET)
349
	public ResponseEntity<ByteArrayResource> downloadIndent(HttpServletRequest request, Model model,
352
	public ResponseEntity<ByteArrayResource> downloadIndent(HttpServletRequest request, Model model,
350
			@RequestParam(required = false, defaultValue = "0") int fofoId,
353
															@RequestParam(required = false, defaultValue = "0") int fofoId,
351
			@RequestParam(defaultValue = "TEN_LAC") CounterSize counterSize) throws Exception {
354
															@RequestParam(defaultValue = "TEN_LAC") CounterSize counterSize) throws Exception {
352
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
355
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
353
		Set<Integer> roleIds = loginDetails.getRoleIds();
356
		Set<Integer> roleIds = loginDetails.getRoleIds();
354
		LOGGER.info("Counter size is {}", counterSize);
357
		LOGGER.info("Counter size is {}", counterSize);
355
		LOGGER.info("Fofo Id is {}", fofoId);
358
		LOGGER.info("Fofo Id is {}", fofoId);
356
 
359
 
Line 462... Line 465...
462
 
465
 
463
	}
466
	}
464
 
467
 
465
	@RequestMapping(value = "/itemsByCatalogId")
468
	@RequestMapping(value = "/itemsByCatalogId")
466
	public String getItemsByCatalogId(HttpServletRequest request, Model model,
469
	public String getItemsByCatalogId(HttpServletRequest request, Model model,
467
			@RequestParam(required = false) int catalogId, @RequestParam(required = false) int itemId)
470
									  @RequestParam(required = false) int catalogId, @RequestParam(required = false) int itemId)
468
			throws ProfitMandiBusinessException {
471
			throws ProfitMandiBusinessException {
469
		if (catalogId == 0) {
472
		if (catalogId == 0) {
470
			catalogId = itemRepository.selectById(itemId).getCatalogItemId();
473
			catalogId = itemRepository.selectById(itemId).getCatalogItemId();
471
		}
474
		}
472
		List<Item> items = itemRepository.selectAllByCatalogItemId(catalogId);
475
		List<Item> items = itemRepository.selectAllByCatalogItemId(catalogId);
Line 487... Line 490...
487
 
490
 
488
	}
491
	}
489
 
492
 
490
	@RequestMapping(value = "/hotdealsitemsByCatalogId")
493
	@RequestMapping(value = "/hotdealsitemsByCatalogId")
491
	public String getHotdealsitemsByCatalogId(HttpServletRequest request, Model model,
494
	public String getHotdealsitemsByCatalogId(HttpServletRequest request, Model model,
492
			@RequestParam(required = false) int catalogId, @RequestParam(required = false) int itemId)
495
											  @RequestParam(required = false) int catalogId, @RequestParam(required = false) int itemId)
493
			throws ProfitMandiBusinessException {
496
			throws ProfitMandiBusinessException {
494
		if (catalogId == 0) {
497
		if (catalogId == 0) {
495
			catalogId = itemRepository.selectById(itemId).getCatalogItemId();
498
			catalogId = itemRepository.selectById(itemId).getCatalogItemId();
496
		}
499
		}
497
		List<Item> items = itemRepository.selectAllByCatalogItemId(catalogId);
500
		List<Item> items = itemRepository.selectAllByCatalogItemId(catalogId);
Line 510... Line 513...
510
		model.addAttribute("response", response.toString());
513
		model.addAttribute("response", response.toString());
511
		return "response";
514
		return "response";
512
 
515
 
513
	}
516
	}
514
 
517
 
-
 
518
	private List<Order> filterValidOrders(List<Order> lastOrdersList) {
-
 
519
		int orderRemovedCount = 0;
-
 
520
		Iterator<Order> orderIterator = lastOrdersList.iterator();
-
 
521
		while (orderIterator.hasNext()) {
-
 
522
			Order o = orderIterator.next();
-
 
523
			if (o.getInvoiceNumber() != null) {
-
 
524
				try {
-
 
525
					purchaseRepository.selectByPurchaseReferenceAndFofoId(o.getInvoiceNumber(), o.getRetailerId());
-
 
526
					orderIterator.remove();
-
 
527
					orderRemovedCount++;
-
 
528
				} catch (Exception e) {
-
 
529
 
-
 
530
				}
-
 
531
			}
-
 
532
		}
-
 
533
		LOGGER.info("Order removed count is {}", orderRemovedCount);
-
 
534
		return lastOrdersList;
-
 
535
	}
-
 
536
 
-
 
537
	@RequestMapping(value = "/indent/confirm-pause", method = RequestMethod.POST)
-
 
538
	public String raisePO(HttpServletRequest request, Model model, @RequestBody String jsonArrayString)
-
 
539
			throws Exception {
-
 
540
		JSONArray jsonArray = new JSONArray(jsonArrayString);
-
 
541
		for (int i = 0; i < jsonArray.length(); i++) {
-
 
542
			JSONObject obj = jsonArray.getJSONObject(i);
-
 
543
 
-
 
544
			TagListing tl = tagListingRepository.selectByItemId(obj.getInt("id"));
-
 
545
			if (tl == null) {
-
 
546
				continue;
-
 
547
			} else {
-
 
548
				tl.setActive(obj.getBoolean("active"));
-
 
549
				tagListingRepository.persist(tl);
-
 
550
			}
-
 
551
		}
-
 
552
		model.addAttribute("response", true);
-
 
553
		return "response";
-
 
554
	}
-
 
555
 
-
 
556
	@RequestMapping(value = "/indent/confirm-hotdeals-pause", method = RequestMethod.POST)
-
 
557
	public String hotdealUpdate(HttpServletRequest request, Model model, @RequestBody String jsonArrayString)
-
 
558
			throws Exception {
-
 
559
		JSONArray jsonArray = new JSONArray(jsonArrayString);
-
 
560
		for (int i = 0; i < jsonArray.length(); i++) {
-
 
561
			JSONObject obj = jsonArray.getJSONObject(i);
-
 
562
 
-
 
563
			TagListing tl = tagListingRepository.selectByItemId(obj.getInt("id"));
-
 
564
			if (tl == null) {
-
 
565
				continue;
-
 
566
			} else {
-
 
567
				tl.setHotDeals(obj.getBoolean("hotDeals"));
-
 
568
				tagListingRepository.persist(tl);
-
 
569
			}
-
 
570
		}
-
 
571
		model.addAttribute("response", true);
-
 
572
		return "response";
-
 
573
	}
-
 
574
 
-
 
575
	@RequestMapping(value = "/indent/create-po", method = RequestMethod.POST)
-
 
576
	public String raisePO(HttpServletRequest request, Model model) throws Exception {
-
 
577
		boolean success = false;
-
 
578
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
-
 
579
		int fofoId = loginDetails.getFofoId();
-
 
580
		List<ItemPriceQuantity> itemQuantities = this.getItemQuantities(fofoId);
-
 
581
		CustomRetailer customRetailer = retailerService.getFofoRetailer(fofoId);
-
 
582
		Client userClient = new UserClient().getClient();
-
 
583
		double totalAmount = itemQuantities.stream().mapToDouble(x -> x.getQty() * x.getPrice()).sum();
-
 
584
 
-
 
585
		if (totalAmount > 0) {
-
 
586
			userClient.addItemPricingToCart(customRetailer.getCartId(), itemQuantities);
-
 
587
			User user = userRepository.selectById(loginDetails.getFofoId());
-
 
588
			userClient = new UserClient().getClient();
-
 
589
			LOGGER.info("Setting wallet amount in cart");
-
 
590
			long transactionId = userClient.createOrders(user.getActiveCartId(), "", 0, "", 0, loginDetails.getFofoId(),
-
 
591
					7890, OrderSource.WEBSITE.getValue(), true);
-
 
592
			LOGGER.info("Creating wallet payment for transactionId - {}", transactionId);
-
 
593
			createPayment(user, totalAmount, transactionId);
-
 
594
			TransactionService.Client transactionClient = new TransactionClient().getClient();
-
 
595
			transactionClient.changeTransactionStatus(transactionId, TransactionStatus.AUTHORIZED,
-
 
596
					"Payment received for the order", PickUpType.RUNNER.getValue(), OrderType.B2B, OrderSource.WEBSITE);
-
 
597
			transactionClient.changeTransactionStatus(Long.valueOf(transactionId), TransactionStatus.IN_PROCESS,
-
 
598
					"Paid fully through wallet", PickUpType.RUNNER.getValue(), OrderType.B2B, OrderSource.WEBSITE);
-
 
599
			LOGGER.info("Successfully created transaction: " + transactionId + " for amount: " + totalAmount);
-
 
600
			transactionClient = new TransactionClient().getClient();
-
 
601
			transactionClient.markOrderForRegisteredGstInvoice(Collections.singletonList(Long.valueOf(transactionId)));
-
 
602
			try {
-
 
603
				transactionClient.enqueueTransactionInfoEmail(transactionId);
-
 
604
			} catch (Exception e1) {
-
 
605
				e1.printStackTrace();
-
 
606
				LOGGER.error("Unable to update status of transaction. Thrift Exception:", e1);
-
 
607
			}
-
 
608
			resetCart(transactionClient.getTransaction(transactionId));
-
 
609
		}
-
 
610
		model.addAttribute("response", mvcResponseSender.createResponseString(success));
-
 
611
		return "response";
-
 
612
	}
-
 
613
 
-
 
614
	private void createPayment(User user, double totalAmount, long transactionId)
-
 
615
			throws NumberFormatException, PaymentException, TException {
-
 
616
		List<Attribute> paymentAttributes = new ArrayList<Attribute>();
-
 
617
		in.shop2020.payments.PaymentService.Client paymentClient = new PaymentClient().getClient();
-
 
618
		paymentAttributes.add(new Attribute("payMethod", "7890"));
-
 
619
		long paymentId = paymentClient.createPayment(user.getId(), totalAmount, WALLET_GATEWAY_ID, transactionId,
-
 
620
				false);
-
 
621
		paymentClient.updatePaymentDetails(paymentId, null, null, null, null, null, null, null, null,
-
 
622
				PaymentStatus.SUCCESS, null, paymentAttributes);
-
 
623
	}
-
 
624
 
515
	@RequestMapping(value = "/indent/loadIndent")
625
	@RequestMapping(value = "/indent/loadIndent")
516
	public String loadOpenIndent(HttpServletRequest request, Model model,
626
	public String loadOpenIndent(HttpServletRequest request, Model model,
517
			@RequestParam(required = false, defaultValue = "0") int fofoId,
627
								 @RequestParam(required = false, defaultValue = "0") int fofoId,
518
			@RequestParam(defaultValue = "TEN_LAC") CounterSize counterSize) throws Exception {
628
								 @RequestParam(defaultValue = "TEN_LAC") CounterSize counterSize) throws Exception {
519
 
629
 
520
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
630
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
521
		Set<Integer> roleIds = loginDetails.getRoleIds();
631
		Set<Integer> roleIds = loginDetails.getRoleIds();
522
		LOGGER.info("Counter size is {}", counterSize);
632
		LOGGER.info("Counter size is {}", counterSize);
523
		LOGGER.info("Fofo Id is {}", fofoId);
633
		LOGGER.info("Fofo Id is {}", fofoId);
Line 600... Line 710...
600
		if (LocalDate.now().isAfter(LocalDate.now().withDayOfMonth(PLANNING_OPEN_DAY))) {
710
		if (LocalDate.now().isAfter(LocalDate.now().withDayOfMonth(PLANNING_OPEN_DAY))) {
601
			planningMonthDate = LocalDate.now().plusMonths(1).withDayOfMonth(1);
711
			planningMonthDate = LocalDate.now().plusMonths(1).withDayOfMonth(1);
602
			monthlyPlanned = monthlyPlannedRepository.selectByFofoIdYearMonth(fofoId, planningMonthDate);
712
			monthlyPlanned = monthlyPlannedRepository.selectByFofoIdYearMonth(fofoId, planningMonthDate);
603
			LOGGER.info("monthlyPlanned2" + monthlyPlanned);
713
			LOGGER.info("monthlyPlanned2" + monthlyPlanned);
604
			fofoOrderIds = fofoOrderRepository.selectByFofoIdBetweenCreatedTimeStamp(loginDetails.getFofoId(),
714
			fofoOrderIds = fofoOrderRepository.selectByFofoIdBetweenCreatedTimeStamp(loginDetails.getFofoId(),
605
					LocalDateTime.now().minusDays(15), LocalDateTime.now()).stream().map(x -> x.getId())
715
							LocalDateTime.now().minusDays(15), LocalDateTime.now()).stream().map(x -> x.getId())
606
					.collect(Collectors.toList());
716
					.collect(Collectors.toList());
607
 
717
 
608
			model.addAttribute("planningMonth", LocalDate.now().plusMonths(1).getMonth());
718
			model.addAttribute("planningMonth", LocalDate.now().plusMonths(1).getMonth());
609
		} else {
719
		} else {
610
			planningMonthDate = LocalDate.now().withDayOfMonth(1);
720
			planningMonthDate = LocalDate.now().withDayOfMonth(1);
Line 612... Line 722...
612
			monthlyPlanned = monthlyPlannedRepository.selectByFofoIdYearMonth(fofoId, planningMonthDate);
722
			monthlyPlanned = monthlyPlannedRepository.selectByFofoIdYearMonth(fofoId, planningMonthDate);
613
			model.addAttribute("planningMonth", planningMonthDate.getMonth());
723
			model.addAttribute("planningMonth", planningMonthDate.getMonth());
614
			model.addAttribute("mtd", true);
724
			model.addAttribute("mtd", true);
615
			model.addAttribute("freezed", true);
725
			model.addAttribute("freezed", true);
616
			fofoOrderIds = fofoOrderRepository.selectByFofoIdBetweenCreatedTimeStamp(loginDetails.getFofoId(),
726
			fofoOrderIds = fofoOrderRepository.selectByFofoIdBetweenCreatedTimeStamp(loginDetails.getFofoId(),
617
					curDate.withDayOfMonth(1), curDate.with(LocalTime.MAX)).stream().map(x -> x.getId())
727
							curDate.withDayOfMonth(1), curDate.with(LocalTime.MAX)).stream().map(x -> x.getId())
618
					.collect(Collectors.toList());
728
					.collect(Collectors.toList());
619
			LOGGER.info("monthlyPlanned1" + monthlyPlanned);
729
			LOGGER.info("monthlyPlanned1" + monthlyPlanned);
620
		}
730
		}
621
 
731
 
622
		Map<Integer, Integer> plannedDetailMap = null;
732
		Map<Integer, Integer> plannedDetailMap = null;
Line 760... Line 870...
760
		model.addAttribute("totalPcs", totalPcs);
870
		model.addAttribute("totalPcs", totalPcs);
761
		return "open-indent";
871
		return "open-indent";
762
 
872
 
763
	}
873
	}
764
 
874
 
765
	private List<Order> filterValidOrders(List<Order> lastOrdersList) {
875
	private long resetCart(Transaction transaction) {
766
		int orderRemovedCount = 0;
876
		long sum = 0;
767
		Iterator<Order> orderIterator = lastOrdersList.iterator();
877
		Map<Long, Double> items = new HashMap<Long, Double>();
768
		while (orderIterator.hasNext()) {
878
		for (in.shop2020.model.v1.order.Order order : transaction.getOrders()) {
769
			Order o = orderIterator.next();
879
			sum += order.getGvAmount();
770
			if (o.getInvoiceNumber() != null) {
880
			for (LineItem lineitem : order.getLineitems()) {
771
				try {
881
				Long itemId = lineitem.getItem_id();
772
					purchaseRepository.selectByPurchaseReferenceAndFofoId(o.getInvoiceNumber(), o.getRetailerId());
882
				Double quantity = items.get(itemId);
773
					orderIterator.remove();
883
				if (quantity == null) {
774
					orderRemovedCount++;
884
					quantity = lineitem.getQuantity();
775
				} catch (Exception e) {
885
				} else {
776
 
-
 
-
 
886
					quantity = quantity + lineitem.getQuantity();
777
				}
887
				}
-
 
888
				items.put(itemId, quantity);
778
			}
889
			}
779
		}
890
		}
780
		LOGGER.info("Order removed count is {}", orderRemovedCount);
-
 
781
		return lastOrdersList;
-
 
782
	}
-
 
783
 
-
 
784
	@RequestMapping(value = "/indent/confirm-pause", method = RequestMethod.POST)
-
 
785
	public String raisePO(HttpServletRequest request, Model model, @RequestBody String jsonArrayString)
-
 
786
			throws Exception {
-
 
787
		JSONArray jsonArray = new JSONArray(jsonArrayString);
-
 
788
		for (int i = 0; i < jsonArray.length(); i++) {
-
 
789
			JSONObject obj = jsonArray.getJSONObject(i);
-
 
790
 
-
 
791
			TagListing tl = tagListingRepository.selectByItemId(obj.getInt("id"));
-
 
792
			if (tl == null) {
-
 
793
				continue;
-
 
794
			} else {
-
 
795
				tl.setActive(obj.getBoolean("active"));
-
 
796
				tagListingRepository.persist(tl);
-
 
797
			}
-
 
798
		}
-
 
799
		model.addAttribute("response", true);
-
 
800
		return "response";
-
 
801
	}
-
 
802
 
891
 
803
	@RequestMapping(value = "/indent/confirm-hotdeals-pause", method = RequestMethod.POST)
-
 
804
	public String hotdealUpdate(HttpServletRequest request, Model model, @RequestBody String jsonArrayString)
-
 
805
			throws Exception {
-
 
806
		JSONArray jsonArray = new JSONArray(jsonArrayString);
892
		LOGGER.debug("Items to reset in cart are: " + items);
807
		for (int i = 0; i < jsonArray.length(); i++) {
-
 
808
			JSONObject obj = jsonArray.getJSONObject(i);
-
 
809
 
893
 
-
 
894
		try {
810
			TagListing tl = tagListingRepository.selectByItemId(obj.getInt("id"));
895
			Client userClient = new UserClient().getClient();
811
			if (tl == null) {
896
			userClient.resetCart(transaction.getShoppingCartid(), items);
812
				continue;
897
		} catch (TException e) {
-
 
898
			LOGGER.error("Error while updating information in payment database.", e);
813
			} else {
899
		} catch (ShoppingCartException e) {
814
				tl.setHotDeals(obj.getBoolean("hotDeals"));
900
			LOGGER.error("Error while reseting the cart in cart database.", e);
-
 
901
		} catch (Exception e) {
815
				tagListingRepository.persist(tl);
902
			LOGGER.error("Unexpected exception", e);
816
			}
-
 
817
		}
903
		}
818
		model.addAttribute("response", true);
-
 
819
		return "response";
904
		return sum;
820
	}
905
	}
821
 
906
 
822
	@RequestMapping(value = "/indent/create-po", method = RequestMethod.POST)
907
	private List<ItemPriceQuantity> getItemQuantities(int fofoId) throws ProfitMandiBusinessException {
823
	public String raisePO(HttpServletRequest request, Model model) throws Exception {
908
		List<ItemPriceQuantity> itemQuantities = new ArrayList<>();
-
 
909
		/*
824
		boolean success = false;
910
		 * Map<Integer, ItemIdAvailability> itemCisMap = null; List<ItemIdAvailability>
825
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
911
		 * currentInventorySnapshots = currentInventorySnapshotRepository
826
		int fofoId = loginDetails.getFofoId();
912
		 * .selectItemsStock(fofoId); itemCisMap =
827
		List<ItemPriceQuantity> itemQuantities = this.getItemQuantities(fofoId);
913
		 * currentInventorySnapshots.stream().filter(x -> x.getAvailability() > 0)
828
		CustomRetailer customRetailer = retailerService.getFofoRetailer(fofoId);
914
		 * .collect(Collectors.toMap(x -> x.getItemId(), x -> x));
829
		Client userClient = new UserClient().getClient();
915
		 * List<StockAllocationModel> stockAllocationList =
830
		double totalAmount = itemQuantities.stream().mapToDouble(x -> x.getQty() * x.getPrice()).sum();
916
		 * stockAllocationService.getStockAllocation(fofoId, true);
831
 
917
		 *
832
		if (totalAmount > 0) {
918
		 * Map<Integer, StockAllocationModel> itemStockAllocationMap =
833
			userClient.addItemPricingToCart(customRetailer.getCartId(), itemQuantities);
919
		 * stockAllocationList.stream() .collect(Collectors.toMap(x -> x.catalogId(), x
834
			User user = userRepository.selectById(loginDetails.getFofoId());
920
		 * -> x)); Map<Integer, Integer> itemsInTransit = null;
835
			userClient = new UserClient().getClient();
921
		 * LOGGER.info("Item Stock Allocation Model Map {}", itemStockAllocationMap);
836
			LOGGER.info("Setting wallet amount in cart");
922
		 * List<TagListing> tagListings = tagListingRepository.selectAll(false);
837
			long transactionId = userClient.createOrders(user.getActiveCartId(), "", 0, "", 0, loginDetails.getFofoId(),
923
		 * List<Order> inTransitOrders = orderRepository.selectOrders(fofoId,
838
					7890, OrderSource.WEBSITE.getValue(), true);
924
		 * validOrderStatusList); inTransitOrders =
839
			LOGGER.info("Creating wallet payment for transactionId - {}", transactionId);
925
		 * this.filterValidOrders(inTransitOrders); itemsInTransit =
-
 
926
		 * inTransitOrders.stream().collect(Collectors.groupingBy(x ->
840
			createPayment(user, totalAmount, transactionId);
927
		 * x.getLineItem().getItemId(), Collectors.summingInt(x ->
-
 
928
		 * x.getLineItem().getQuantity())));
-
 
929
		 *
841
			TransactionService.Client transactionClient = new TransactionClient().getClient();
930
		 * Iterator<TagListing> iterator = tagListings.iterator();
-
 
931
		 *
842
			transactionClient.changeTransactionStatus(transactionId, TransactionStatus.AUTHORIZED,
932
		 * int toBeOrdered = 0; while (iterator.hasNext()) { TagListing tagListing =
843
					"Payment received for the order", PickUpType.RUNNER.getValue(), OrderType.B2B, OrderSource.WEBSITE);
933
		 * iterator.next(); LOGGER.info(" tagListing.setAllocatedQuantity {}",
-
 
934
		 * tagListing.getAllocatedQuantity()); if
844
			transactionClient.changeTransactionStatus(Long.valueOf(transactionId), TransactionStatus.IN_PROCESS,
935
		 * (!itemCisMap.containsKey(tagListing.getItemId()) &&
845
					"Paid fully through wallet", PickUpType.RUNNER.getValue(), OrderType.B2B, OrderSource.WEBSITE);
936
		 * !itemStockAllocationMap.containsKey(tagListing.getItemId())) {
846
			LOGGER.info("Successfully created transaction: " + transactionId + " for amount: " + totalAmount);
937
		 * iterator.remove(); continue; } ItemIdAvailability itemIdAvailability =
847
			transactionClient = new TransactionClient().getClient();
938
		 * itemCisMap.get(tagListing.getItemId());
-
 
939
		 * tagListing.setStockInHand(itemIdAvailability == null ? 0 :
-
 
940
		 * itemIdAvailability.getAvailability()); StockAllocationModel
848
			transactionClient.markOrderForRegisteredGstInvoice(Collections.singletonList(Long.valueOf(transactionId)));
941
		 * stockAllocationModel = itemStockAllocationMap.get(tagListing.getItemId());
849
			try {
942
		 *
-
 
943
		 * if (itemsInTransit.containsKey(tagListing.getItemId())) {
-
 
944
		 * tagListing.setInTransitQuantity(itemsInTransit.get(tagListing.getItemId()));
850
				transactionClient.enqueueTransactionInfoEmail(transactionId);
945
		 * } else { tagListing.setInTransitQuantity(0); } if (stockAllocationModel !=
-
 
946
		 * null) { tagListing.setAllocatedQuantity(stockAllocationModel.getQuantity());
851
			} catch (Exception e1) {
947
		 * toBeOrdered = Math.max(tagListing.getAllocatedQuantity() -
852
				e1.printStackTrace();
948
		 * tagListing.getInTransitQuantity() - tagListing.getStockInHand(), 0); if
853
				LOGGER.error("Unable to update status of transaction. Thrift Exception:", e1);
949
		 * (toBeOrdered > 0) { ItemPriceQuantity ipq = new ItemPriceQuantity();
854
			}
-
 
855
			resetCart(transactionClient.getTransaction(transactionId));
950
		 * ipq.setItemId(tagListing.getItemId()); ipq.setQty((long) toBeOrdered);
-
 
951
		 * ipq.setPrice(tagListing.getSellingPrice()); itemQuantities.add(ipq); } } }
856
		}
952
		 */
857
		model.addAttribute("response", mvcResponseSender.createResponseString(success));
-
 
858
		return "response";
953
		return itemQuantities;
859
	}
-
 
860
 
954
 
861
	private void createPayment(User user, double totalAmount, long transactionId)
-
 
862
			throws NumberFormatException, PaymentException, TException {
-
 
863
		List<Attribute> paymentAttributes = new ArrayList<Attribute>();
-
 
864
		in.shop2020.payments.PaymentService.Client paymentClient = new PaymentClient().getClient();
-
 
865
		paymentAttributes.add(new Attribute("payMethod", "7890"));
-
 
866
		long paymentId = paymentClient.createPayment(user.getId(), totalAmount, WALLET_GATEWAY_ID, transactionId,
-
 
867
				false);
-
 
868
		paymentClient.updatePaymentDetails(paymentId, null, null, null, null, null, null, null, null,
-
 
869
				PaymentStatus.SUCCESS, null, paymentAttributes);
-
 
870
	}
955
	}
871
 
956
 
872
	@RequestMapping(value = "/indent/loadIndentPreviousMonth")
957
	@RequestMapping(value = "/indent/loadIndentPreviousMonth")
873
	public String previousMonthLoadOpenIndent(HttpServletRequest request, Model model,
958
	public String previousMonthLoadOpenIndent(HttpServletRequest request, Model model,
874
			@RequestParam(required = false, defaultValue = "0") int fofoId,
959
											  @RequestParam(required = false, defaultValue = "0") int fofoId,
875
			@RequestParam(defaultValue = "TEN_LAC") CounterSize counterSize) throws Exception {
960
											  @RequestParam(defaultValue = "TEN_LAC") CounterSize counterSize) throws Exception {
876
		LocalDate planMonthStart = null;
961
		LocalDate planMonthStart = null;
877
		if (LocalDate.now().isAfter(LocalDate.now().withDayOfMonth(PLANNING_OPEN_DAY))) {
962
		if (LocalDate.now().isAfter(LocalDate.now().withDayOfMonth(PLANNING_OPEN_DAY))) {
878
			planMonthStart = LocalDate.now().plusMonths(1).withDayOfMonth(1);
963
			planMonthStart = LocalDate.now().plusMonths(1).withDayOfMonth(1);
879
		} else {
964
		} else {
880
			planMonthStart = LocalDate.now().withDayOfMonth(1);
965
			planMonthStart = LocalDate.now().withDayOfMonth(1);
Line 1091... Line 1176...
1091
		model.addAttribute("totalPcs", totalPcs);
1176
		model.addAttribute("totalPcs", totalPcs);
1092
		return "open-indent";
1177
		return "open-indent";
1093
 
1178
 
1094
	}
1179
	}
1095
 
1180
 
1096
	private long resetCart(Transaction transaction) {
1181
	private Map<Integer, Item> getItemByCatalogId(List<FocusedModel> focusedModels) {
1097
		long sum = 0;
-
 
1098
		Map<Long, Double> items = new HashMap<Long, Double>();
1182
		Map<Integer, Item> itemMap = new HashMap<>();
1099
		for (in.shop2020.model.v1.order.Order order : transaction.getOrders()) {
1183
		for (FocusedModel focusedModel : focusedModels) {
1100
			sum += order.getGvAmount();
-
 
1101
			for (LineItem lineitem : order.getLineitems()) {
-
 
1102
				Long itemId = lineitem.getItem_id();
-
 
1103
				Double quantity = items.get(itemId);
-
 
1104
				if (quantity == null) {
-
 
1105
					quantity = lineitem.getQuantity();
-
 
1106
				} else {
-
 
1107
					quantity = quantity + lineitem.getQuantity();
1184
			List<Item> items = itemRepository.selectAllByCatalogItemId(focusedModel.getCatalogId());
1108
				}
-
 
1109
				items.put(itemId, quantity);
1185
			itemMap.put(items.get(0).getCatalogItemId(), items.get(0));
1110
			}
-
 
1111
		}
1186
		}
1112
 
1187
 
1113
		LOGGER.debug("Items to reset in cart are: " + items);
-
 
1114
 
-
 
1115
		try {
-
 
1116
			Client userClient = new UserClient().getClient();
-
 
1117
			userClient.resetCart(transaction.getShoppingCartid(), items);
-
 
1118
		} catch (TException e) {
-
 
1119
			LOGGER.error("Error while updating information in payment database.", e);
-
 
1120
		} catch (ShoppingCartException e) {
-
 
1121
			LOGGER.error("Error while reseting the cart in cart database.", e);
-
 
1122
		} catch (Exception e) {
-
 
1123
			LOGGER.error("Unexpected exception", e);
-
 
1124
		}
-
 
1125
		return sum;
1188
		return itemMap;
1126
	}
1189
	}
1127
 
1190
 
1128
	private List<ItemPriceQuantity> getItemQuantities(int fofoId) throws ProfitMandiBusinessException {
1191
	private Map<Integer, Region> getRegionByRegionId(List<FocusedModel> focusedModels) {
1129
		List<ItemPriceQuantity> itemQuantities = new ArrayList<>();
1192
		Map<Integer, Region> regionMap = new HashMap<>();
1130
		/*
-
 
1131
		 * Map<Integer, ItemIdAvailability> itemCisMap = null; List<ItemIdAvailability>
-
 
1132
		 * currentInventorySnapshots = currentInventorySnapshotRepository
-
 
1133
		 * .selectItemsStock(fofoId); itemCisMap =
-
 
1134
		 * currentInventorySnapshots.stream().filter(x -> x.getAvailability() > 0)
-
 
1135
		 * .collect(Collectors.toMap(x -> x.getItemId(), x -> x));
-
 
1136
		 * List<StockAllocationModel> stockAllocationList =
1193
		for (FocusedModel focusedModel : focusedModels) {
1137
		 * stockAllocationService.getStockAllocation(fofoId, true);
-
 
1138
		 *
-
 
1139
		 * Map<Integer, StockAllocationModel> itemStockAllocationMap =
-
 
1140
		 * stockAllocationList.stream() .collect(Collectors.toMap(x -> x.catalogId(), x
-
 
1141
		 * -> x)); Map<Integer, Integer> itemsInTransit = null;
-
 
1142
		 * LOGGER.info("Item Stock Allocation Model Map {}", itemStockAllocationMap);
-
 
1143
		 * List<TagListing> tagListings = tagListingRepository.selectAll(false);
1194
			Region region = regionRepository.selectById(focusedModel.getRegionId());
1144
		 * List<Order> inTransitOrders = orderRepository.selectOrders(fofoId,
-
 
1145
		 * validOrderStatusList); inTransitOrders =
-
 
1146
		 * this.filterValidOrders(inTransitOrders); itemsInTransit =
-
 
1147
		 * inTransitOrders.stream().collect(Collectors.groupingBy(x ->
-
 
1148
		 * x.getLineItem().getItemId(), Collectors.summingInt(x ->
-
 
1149
		 * x.getLineItem().getQuantity())));
-
 
1150
		 *
-
 
1151
		 * Iterator<TagListing> iterator = tagListings.iterator();
-
 
1152
		 *
-
 
1153
		 * int toBeOrdered = 0; while (iterator.hasNext()) { TagListing tagListing =
-
 
1154
		 * iterator.next(); LOGGER.info(" tagListing.setAllocatedQuantity {}",
-
 
1155
		 * tagListing.getAllocatedQuantity()); if
-
 
1156
		 * (!itemCisMap.containsKey(tagListing.getItemId()) &&
-
 
1157
		 * !itemStockAllocationMap.containsKey(tagListing.getItemId())) {
-
 
1158
		 * iterator.remove(); continue; } ItemIdAvailability itemIdAvailability =
-
 
1159
		 * itemCisMap.get(tagListing.getItemId());
1195
			regionMap.put(region.getId(), region);
1160
		 * tagListing.setStockInHand(itemIdAvailability == null ? 0 :
-
 
1161
		 * itemIdAvailability.getAvailability()); StockAllocationModel
-
 
1162
		 * stockAllocationModel = itemStockAllocationMap.get(tagListing.getItemId());
-
 
1163
		 *
1196
		}
1164
		 * if (itemsInTransit.containsKey(tagListing.getItemId())) {
-
 
1165
		 * tagListing.setInTransitQuantity(itemsInTransit.get(tagListing.getItemId()));
-
 
1166
		 * } else { tagListing.setInTransitQuantity(0); } if (stockAllocationModel !=
-
 
1167
		 * null) { tagListing.setAllocatedQuantity(stockAllocationModel.getQuantity());
-
 
1168
		 * toBeOrdered = Math.max(tagListing.getAllocatedQuantity() -
-
 
1169
		 * tagListing.getInTransitQuantity() - tagListing.getStockInHand(), 0); if
-
 
1170
		 * (toBeOrdered > 0) { ItemPriceQuantity ipq = new ItemPriceQuantity();
-
 
1171
		 * ipq.setItemId(tagListing.getItemId()); ipq.setQty((long) toBeOrdered);
-
 
1172
		 * ipq.setPrice(tagListing.getSellingPrice()); itemQuantities.add(ipq); } } }
-
 
1173
		 */
-
 
1174
		return itemQuantities;
-
 
1175
 
1197
 
-
 
1198
		return regionMap;
1176
	}
1199
	}
1177
 
1200
 
1178
	@RequestMapping(value = "/getFocusedModel", method = RequestMethod.GET)
1201
	@RequestMapping(value = "/getFocusedModel", method = RequestMethod.GET)
1179
	public String getFocusedModel(HttpServletRequest request,
1202
	public String getFocusedModel(HttpServletRequest request,
1180
			@RequestParam(name = "offset", defaultValue = "0") int offset,
1203
								  @RequestParam(name = "offset", defaultValue = "0") int offset,
1181
			@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
1204
								  @RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
1182
			throws ProfitMandiBusinessException {
1205
			throws ProfitMandiBusinessException {
1183
 
1206
 
1184
		long size = 0;
1207
		long size = 0;
1185
		List<FocusedModel> focusedModels = focusedModelRepository.selectAll(offset, limit);
1208
		List<FocusedModel> focusedModels = focusedModelRepository.selectAll(offset, limit);
1186
 
1209
 
Line 1214... Line 1237...
1214
		model.addAttribute("regions", regions);
1237
		model.addAttribute("regions", regions);
1215
 
1238
 
1216
		return "focused_model";
1239
		return "focused_model";
1217
	}
1240
	}
1218
 
1241
 
1219
	private Map<Integer, Item> getItemByCatalogId(List<FocusedModel> focusedModels) {
-
 
1220
		Map<Integer, Item> itemMap = new HashMap<>();
-
 
1221
		for (FocusedModel focusedModel : focusedModels) {
-
 
1222
			List<Item> items = itemRepository.selectAllByCatalogItemId(focusedModel.getCatalogId());
-
 
1223
			itemMap.put(items.get(0).getCatalogItemId(), items.get(0));
-
 
1224
		}
-
 
1225
 
-
 
1226
		return itemMap;
-
 
1227
	}
-
 
1228
 
-
 
1229
	private Map<Integer, Region> getRegionByRegionId(List<FocusedModel> focusedModels) {
-
 
1230
		Map<Integer, Region> regionMap = new HashMap<>();
-
 
1231
		for (FocusedModel focusedModel : focusedModels) {
-
 
1232
			Region region = regionRepository.selectById(focusedModel.getRegionId());
-
 
1233
			regionMap.put(region.getId(), region);
-
 
1234
		}
-
 
1235
 
-
 
1236
		return regionMap;
-
 
1237
	}
-
 
1238
 
-
 
1239
	@RequestMapping(value = "/getPaginatedFocusedModel", method = RequestMethod.GET)
1242
	@RequestMapping(value = "/getPaginatedFocusedModel", method = RequestMethod.GET)
1240
	public String getPaginatedFocusedModel(HttpServletRequest request,
1243
	public String getPaginatedFocusedModel(HttpServletRequest request,
1241
			@RequestParam(name = "offset", defaultValue = "0") int offset,
1244
										   @RequestParam(name = "offset", defaultValue = "0") int offset,
1242
			@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
1245
										   @RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
1243
			throws ProfitMandiBusinessException {
1246
			throws ProfitMandiBusinessException {
1244
		LOGGER.info("requested offset=[{}], limit = [{}]", offset, limit);
1247
		LOGGER.info("requested offset=[{}], limit = [{}]", offset, limit);
1245
		List<FocusedModel> focusedModels = focusedModelRepository.selectAll(offset, limit);
1248
		List<FocusedModel> focusedModels = focusedModelRepository.selectAll(offset, limit);
1246
 
1249
 
1247
		if (!focusedModels.isEmpty()) {
1250
		if (!focusedModels.isEmpty()) {
Line 1260... Line 1263...
1260
 
1263
 
1261
		model.addAttribute("regions", regions);
1264
		model.addAttribute("regions", regions);
1262
		return "focused-model-paginated";
1265
		return "focused-model-paginated";
1263
	}
1266
	}
1264
 
1267
 
1265
	@RequestMapping(value = "/focusedModel", method = RequestMethod.POST)
-
 
1266
	public String focusedModel(HttpServletRequest request, @RequestParam int catalogId,
-
 
1267
			@RequestParam(name = "recommended", defaultValue = "0") int recommended,
-
 
1268
			@RequestParam(name = "minimumQty", defaultValue = "0") int minimumQty,
-
 
1269
			@RequestParam(name = "obvrecommend", defaultValue = "0") int obvrecommend,
-
 
1270
			@RequestParam(name = "obvminimum", defaultValue = "0") int obvminimum, @RequestParam int regionId,
-
 
1271
			Model model) throws ProfitMandiBusinessException {
-
 
1272
 
-
 
1273
		FocusedModel fm = new FocusedModel();
-
 
1274
		fm.setCatalogId(catalogId);
-
 
1275
		fm.setMinimumQty(minimumQty);
-
 
1276
		fm.setRecommendedQty(recommended);
-
 
1277
		fm.setRegionId(regionId);
-
 
1278
		fm.setObsRecommendedQty(obvrecommend);
-
 
1279
		fm.setObsMinimumQty(obvminimum);
-
 
1280
		fm.setCreatedTimestamp(LocalDateTime.now());
-
 
1281
		focusedModelRepository.persist(fm);
-
 
1282
		return "focused_model";
-
 
1283
	}
-
 
1284
 
-
 
1285
	private List<BrandStockPrice> getBrandStockPrices(int fofoId) throws Exception {
1268
	private List<BrandStockPrice> getBrandStockPrices(int fofoId) throws Exception {
1286
		Map<String, BrandStockPrice> brandStockPricesMap = inventoryService.getBrandWiseStockValue(fofoId);
1269
		Map<String, BrandStockPrice> brandStockPricesMap = inventoryService.getBrandWiseStockValue(fofoId);
1287
 
1270
 
1288
		List<DBObject> mobileBrands = mongoClient.getMongoBrands(fofoId, "", 3);
1271
		List<DBObject> mobileBrands = mongoClient.getMongoBrands(fofoId, "", 3);
1289
		List<BrandStockPrice> brandStockPrices = new ArrayList<>();
1272
		List<BrandStockPrice> brandStockPrices = new ArrayList<>();
Line 1340... Line 1323...
1340
 
1323
 
1341
		return "partner-po";
1324
		return "partner-po";
1342
 
1325
 
1343
	}
1326
	}
1344
 
1327
 
-
 
1328
	@RequestMapping(value = "/focusedModel", method = RequestMethod.POST)
-
 
1329
	public String focusedModel(HttpServletRequest request, @RequestParam int catalogId,
-
 
1330
							   @RequestParam(name = "recommended", defaultValue = "0") int recommended,
-
 
1331
							   @RequestParam(name = "minimumQty", defaultValue = "0") int minimumQty,
-
 
1332
							   @RequestParam(name = "obvrecommend", defaultValue = "0") int obvrecommend,
-
 
1333
							   @RequestParam(name = "obvminimum", defaultValue = "0") int obvminimum, @RequestParam int regionId,
-
 
1334
							   Model model) throws ProfitMandiBusinessException {
-
 
1335
 
-
 
1336
		FocusedModel fm = new FocusedModel();
-
 
1337
		fm.setCatalogId(catalogId);
-
 
1338
		fm.setMinimumQty(minimumQty);
-
 
1339
		fm.setRecommendedQty(recommended);
-
 
1340
		fm.setRegionId(regionId);
-
 
1341
		fm.setObsRecommendedQty(obvrecommend);
-
 
1342
		fm.setObsMinimumQty(obvminimum);
-
 
1343
		fm.setCreatedTimestamp(LocalDateTime.now());
-
 
1344
		focusedModelRepository.persist(fm);
-
 
1345
		return "focused_model";
-
 
1346
	}
-
 
1347
 
1345
	@RequestMapping(value = "/removeItem", method = RequestMethod.DELETE)
1348
	@RequestMapping(value = "/removeItem", method = RequestMethod.DELETE)
1346
	public String removeFocusedModelItem(HttpServletRequest request,
1349
	public String removeFocusedModelItem(HttpServletRequest request,
1347
			@RequestParam(name = "id", defaultValue = "0") int id, Model model) throws Exception {
1350
										 @RequestParam(name = "id", defaultValue = "0") int id, Model model) throws Exception {
1348
 
1351
 
1349
		focusedModelRepository.deleteById(id);
1352
		focusedModelRepository.deleteById(id);
1350
		model.addAttribute("response", mvcResponseSender.createResponseString(true));
1353
		model.addAttribute("response", mvcResponseSender.createResponseString(true));
1351
		return "response";
1354
		return "response";
1352
	}
1355
	}
1353
 
1356
 
1354
	@RequestMapping(value = "/getPartnerloadContent")
1357
	@RequestMapping(value = "/getPartnerloadContent")
1355
	public String getPartnerloadContent(HttpServletRequest request, Model model,
1358
	public String getPartnerloadContent(HttpServletRequest request, Model model,
1356
			@RequestParam(required = false, defaultValue = "0") int fofoId,
1359
										@RequestParam(required = false, defaultValue = "0") int fofoId,
1357
			@RequestParam(defaultValue = "TEN_LAC") CounterSize counterSize) throws Exception {
1360
										@RequestParam(defaultValue = "TEN_LAC") CounterSize counterSize) throws Exception {
1358
 
1361
 
1359
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1362
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1360
		Set<Integer> roleIds = loginDetails.getRoleIds();
1363
		Set<Integer> roleIds = loginDetails.getRoleIds();
1361
		LOGGER.info("Counter size is {}", counterSize);
1364
		LOGGER.info("Counter size is {}", counterSize);
1362
		LOGGER.info("Fofo Id is {}", fofoId);
1365
		LOGGER.info("Fofo Id is {}", fofoId);
Line 1440... Line 1443...
1440
		if (LocalDate.now().isAfter(LocalDate.now().withDayOfMonth(PLANNING_OPEN_DAY))) {
1443
		if (LocalDate.now().isAfter(LocalDate.now().withDayOfMonth(PLANNING_OPEN_DAY))) {
1441
			currentMonthDate = LocalDate.now().plusMonths(1).withDayOfMonth(1);
1444
			currentMonthDate = LocalDate.now().plusMonths(1).withDayOfMonth(1);
1442
			monthlyPlanned = monthlyPlannedRepository.selectByFofoIdYearMonth(fofoId, currentMonthDate);
1445
			monthlyPlanned = monthlyPlannedRepository.selectByFofoIdYearMonth(fofoId, currentMonthDate);
1443
			LOGGER.info("monthlyPlanned2" + monthlyPlanned);
1446
			LOGGER.info("monthlyPlanned2" + monthlyPlanned);
1444
			fofoOrderIds = fofoOrderRepository.selectByFofoIdBetweenCreatedTimeStamp(loginDetails.getFofoId(),
1447
			fofoOrderIds = fofoOrderRepository.selectByFofoIdBetweenCreatedTimeStamp(loginDetails.getFofoId(),
1445
					LocalDateTime.now().minusDays(15), LocalDateTime.now()).stream().map(x -> x.getId())
1448
							LocalDateTime.now().minusDays(15), LocalDateTime.now()).stream().map(x -> x.getId())
1446
					.collect(Collectors.toList());
1449
					.collect(Collectors.toList());
1447
 
1450
 
1448
			model.addAttribute("planningMonth", LocalDate.now().plusMonths(1).getMonth());
1451
			model.addAttribute("planningMonth", LocalDate.now().plusMonths(1).getMonth());
1449
		} else {
1452
		} else {
1450
			currentMonthDate = LocalDate.now().withDayOfMonth(1);
1453
			currentMonthDate = LocalDate.now().withDayOfMonth(1);
Line 1452... Line 1455...
1452
			monthlyPlanned = monthlyPlannedRepository.selectByFofoIdYearMonth(fofoId, currentMonthDate);
1455
			monthlyPlanned = monthlyPlannedRepository.selectByFofoIdYearMonth(fofoId, currentMonthDate);
1453
			model.addAttribute("planningMonth", currentMonthDate.getMonth());
1456
			model.addAttribute("planningMonth", currentMonthDate.getMonth());
1454
			model.addAttribute("mtd", true);
1457
			model.addAttribute("mtd", true);
1455
			model.addAttribute("freezed", true);
1458
			model.addAttribute("freezed", true);
1456
			fofoOrderIds = fofoOrderRepository.selectByFofoIdBetweenCreatedTimeStamp(loginDetails.getFofoId(),
1459
			fofoOrderIds = fofoOrderRepository.selectByFofoIdBetweenCreatedTimeStamp(loginDetails.getFofoId(),
1457
					curDate.withDayOfMonth(1), curDate.with(LocalTime.MAX)).stream().map(x -> x.getId())
1460
							curDate.withDayOfMonth(1), curDate.with(LocalTime.MAX)).stream().map(x -> x.getId())
1458
					.collect(Collectors.toList());
1461
					.collect(Collectors.toList());
1459
			LOGGER.info("monthlyPlanned1" + monthlyPlanned);
1462
			LOGGER.info("monthlyPlanned1" + monthlyPlanned);
1460
		}
1463
		}
1461
 
1464
 
1462
		Map<Integer, Integer> plannedDetailMap = null;
1465
		Map<Integer, Integer> plannedDetailMap = null;
Line 1491... Line 1494...
1491
		Map<String, Object> equalsItemJoinMap = new HashMap<>();
1494
		Map<String, Object> equalsItemJoinMap = new HashMap<>();
1492
		equalsItemJoinMap.put("active", 1);
1495
		equalsItemJoinMap.put("active", 1);
1493
		List<IntegerIdAggregateValue> tagListingCatalogIds = itemRepository.selectItems(TagListing.class, "id",
1496
		List<IntegerIdAggregateValue> tagListingCatalogIds = itemRepository.selectItems(TagListing.class, "id",
1494
				"itemId", equalsMap, notEqualsMap, equalsItemJoinMap, notEqualsJoinMap, "tagId");
1497
				"itemId", equalsMap, notEqualsMap, equalsItemJoinMap, notEqualsJoinMap, "tagId");
1495
		Map<Integer, Integer> ourStockAvailability = new HashMap<>();
1498
		Map<Integer, Integer> ourStockAvailability = new HashMap<>();
1496
		Map<Integer, List<SaholicCIS>> itemAvailabilityMap = saholicInventoryService.getSaholicStock()
-
 
1497
				.get(fofoStore.getWarehouseId());
-
 
1498
 
1499
 
1499
		Map<Integer, List<Integer>> catalogItemIdMap = itemRepository
1500
		Map<Integer, List<Integer>> catalogItemIdMap = itemRepository
1500
				.selectAllByCatalogIds(new HashSet<>(
1501
				.selectAllByCatalogIds(new HashSet<>(
1501
						tagListingCatalogIds.stream().map(x -> x.getCatalogId()).collect(Collectors.toList())))
1502
						tagListingCatalogIds.stream().map(x -> x.getCatalogId()).collect(Collectors.toList())))
1502
				.stream().collect(Collectors.groupingBy(x -> x.getCatalogItemId(),
1503
				.stream().collect(Collectors.groupingBy(x -> x.getCatalogItemId(),
1503
						Collectors.mapping(y -> y.getId(), Collectors.toList())));
1504
						Collectors.mapping(y -> y.getId(), Collectors.toList())));
1504
		for (Entry<Integer, List<Integer>> catalogItem : catalogItemIdMap.entrySet()) {
1505
		for (Entry<Integer, List<Integer>> catalogItem : catalogItemIdMap.entrySet()) {
1505
			List<Integer> itemIds = catalogItem.getValue();
1506
			List<Integer> itemIds = catalogItem.getValue();
1506
			int availability = 0;
1507
			int availability = 0;
1507
			for (Integer itemId : itemIds) {
1508
			for (Integer itemId : itemIds) {
1508
				List<SaholicCIS> scis = itemAvailabilityMap.get(itemId);
1509
				List<SaholicCISTable> saholicCISTableList = saholicCISTableRepository.selectByItemWarehouse(itemId, fofoStore.getWarehouseId());
1509
				if (scis != null) {
1510
				if (saholicCISTableList != null) {
1510
					availability += scis.stream().collect(Collectors.summingInt(x -> x.getAvailability()));
1511
					availability += saholicCISTableList.stream().collect(Collectors.summingInt(x -> x.getAvailability()));
1511
				}
1512
				}
1512
			}
1513
			}
1513
			Integer catalogItemId = catalogItem.getKey();
1514
			Integer catalogItemId = catalogItem.getKey();
1514
			ourStockAvailability.put(catalogItemId, availability);
1515
			ourStockAvailability.put(catalogItemId, availability);
1515
		}
1516
		}
Line 1848... Line 1849...
1848
		return "partner-brandwise-detail";
1849
		return "partner-brandwise-detail";
1849
	}
1850
	}
1850
 
1851
 
1851
	@RequestMapping(value = "/changeActivationType", method = RequestMethod.POST)
1852
	@RequestMapping(value = "/changeActivationType", method = RequestMethod.POST)
1852
	public String changeActivationType(HttpServletRequest request, @RequestParam String code,
1853
	public String changeActivationType(HttpServletRequest request, @RequestParam String code,
1853
			@RequestParam ActivationType activationType, Model model) throws Exception {
1854
									   @RequestParam ActivationType activationType, Model model) throws Exception {
1854
 
1855
 
1855
		FofoStore fofoStore = fofoStoreRepository.selectByStoreCode(code);
1856
		FofoStore fofoStore = fofoStoreRepository.selectByStoreCode(code);
1856
 
1857
 
1857
		fofoStore.setActivationType(activationType);
1858
		fofoStore.setActivationType(activationType);
1858
 
1859
 
Line 1898... Line 1899...
1898
		return "response";
1899
		return "response";
1899
	}
1900
	}
1900
 
1901
 
1901
	@RequestMapping(value = "/getPartnerShortageStock", method = RequestMethod.GET)
1902
	@RequestMapping(value = "/getPartnerShortageStock", method = RequestMethod.GET)
1902
	public String getPartnerShortageStock(HttpServletRequest request,
1903
	public String getPartnerShortageStock(HttpServletRequest request,
1903
			@RequestParam(required = false, defaultValue = "") String brand, @RequestParam int fofoId, Model model)
1904
										  @RequestParam(required = false, defaultValue = "") String brand, @RequestParam int fofoId, Model model)
1904
			throws Exception {
1905
			throws Exception {
1905
 
1906
 
1906
		Map<Integer, Map<Integer, List<SaholicCIS>>> warehouseItemAvailabilityMap = saholicInventoryService
-
 
1907
				.getSaholicStock();
-
 
1908
 
1907
 
1909
		Map<Integer, Map<Integer, List<SaholicPOItem>>> warehousePoItemAvailabilityMap = saholicInventoryService
1908
		Map<Integer, Map<Integer, List<SaholicPOItem>>> warehousePoItemAvailabilityMap = saholicInventoryService
1910
				.getSaholicPOItems();
1909
				.getSaholicPOItems();
1911
 
1910
 
1912
		List<FocusedModelShortageModel> focusedModelShortageList = new ArrayList<>();
1911
		List<FocusedModelShortageModel> focusedModelShortageList = new ArrayList<>();
Line 1992... Line 1991...
1992
			List<Item> items = itemRepository.selectAllByCatalogItemId(entry.getKey());
1991
			List<Item> items = itemRepository.selectAllByCatalogItemId(entry.getKey());
1993
 
1992
 
1994
			if (brand.equals("undefined") || items.get(0).getBrand().equals(brand)) {
1993
			if (brand.equals("undefined") || items.get(0).getBrand().equals(brand)) {
1995
 
1994
 
1996
				FocusedModelShortageModel fm = this.getFocusedModelShortage(entry.getValue().get(), entry.getKey(),
1995
				FocusedModelShortageModel fm = this.getFocusedModelShortage(entry.getValue().get(), entry.getKey(),
1997
						processingOrderMap, grnPendingOrdersMap, catalogIdAndQtyMap, fofoId,
-
 
1998
						warehouseItemAvailabilityMap, warehousePoItemAvailabilityMap, items, customRetailer);
1996
						processingOrderMap, grnPendingOrdersMap, catalogIdAndQtyMap, fofoId, warehousePoItemAvailabilityMap, items, customRetailer);
1999
 
1997
 
2000
				focusedModelShortageList.add(fm);
1998
				focusedModelShortageList.add(fm);
2001
			} else if (brand.equals("accessories")) {
1999
			} else if (brand.equals("accessories")) {
2002
 
2000
 
2003
				if (items.get(0).getCategoryId() != ProfitMandiConstants.MOBILE_CATEGORY_ID) {
2001
				if (items.get(0).getCategoryId() != ProfitMandiConstants.MOBILE_CATEGORY_ID) {
2004
					if (items.get(0).getCategoryId() != 0) {
2002
					if (items.get(0).getCategoryId() != 0) {
2005
						Category category = categoryRepository.selectById(items.get(0).getCategoryId());
2003
						Category category = categoryRepository.selectById(items.get(0).getCategoryId());
2006
 
2004
 
2007
						if (category.getParentCategoryId() == 10011) {
2005
						if (category.getParentCategoryId() == 10011) {
2008
							FocusedModelShortageModel fm = this.getFocusedModelShortage(entry.getValue().get(),
2006
							FocusedModelShortageModel fm = this.getFocusedModelShortage(entry.getValue().get(),
2009
									entry.getKey(), processingOrderMap, grnPendingOrdersMap, catalogIdAndQtyMap, fofoId,
2007
									entry.getKey(), processingOrderMap, grnPendingOrdersMap, catalogIdAndQtyMap, fofoId
2010
									warehouseItemAvailabilityMap, warehousePoItemAvailabilityMap, items,
2008
									, warehousePoItemAvailabilityMap, items,
2011
									customRetailer);
2009
									customRetailer);
2012
 
2010
 
2013
							focusedModelShortageList.add(fm);
2011
							focusedModelShortageList.add(fm);
2014
 
2012
 
2015
						}
2013
						}
Line 2026... Line 2024...
2026
						Category category = categoryRepository.selectById(items.get(0).getCategoryId());
2024
						Category category = categoryRepository.selectById(items.get(0).getCategoryId());
2027
 
2025
 
2028
						if (category.getParentCategoryId() == 14200) {
2026
						if (category.getParentCategoryId() == 14200) {
2029
							FocusedModelShortageModel fm = this.getFocusedModelShortage(entry.getValue().get(),
2027
							FocusedModelShortageModel fm = this.getFocusedModelShortage(entry.getValue().get(),
2030
									entry.getKey(), processingOrderMap, grnPendingOrdersMap, catalogIdAndQtyMap, fofoId,
2028
									entry.getKey(), processingOrderMap, grnPendingOrdersMap, catalogIdAndQtyMap, fofoId,
2031
									warehouseItemAvailabilityMap, warehousePoItemAvailabilityMap, items,
2029
									warehousePoItemAvailabilityMap, items,
2032
									customRetailer);
2030
									customRetailer);
2033
 
2031
 
2034
							focusedModelShortageList.add(fm);
2032
							focusedModelShortageList.add(fm);
2035
 
2033
 
2036
						}
2034
						}
Line 2088... Line 2086...
2088
		return "partner-stock";
2086
		return "partner-stock";
2089
 
2087
 
2090
	}
2088
	}
2091
 
2089
 
2092
	private List<PartnerStockDescriptionModel> getBrandItemwiseDescription(String brand,
2090
	private List<PartnerStockDescriptionModel> getBrandItemwiseDescription(String brand,
2093
			Map<Integer, Integer> catalogIdAndQtyMap) throws ProfitMandiBusinessException {
2091
																		   Map<Integer, Integer> catalogIdAndQtyMap) throws ProfitMandiBusinessException {
2094
		List<PartnerStockDescriptionModel> inStocks = new ArrayList<>();
2092
		List<PartnerStockDescriptionModel> inStocks = new ArrayList<>();
2095
 
2093
 
2096
		for (Entry<Integer, Integer> inStock : catalogIdAndQtyMap.entrySet()) {
2094
		for (Entry<Integer, Integer> inStock : catalogIdAndQtyMap.entrySet()) {
2097
			List<Item> items = itemRepository.selectAllByCatalogItemId(inStock.getKey());
2095
			List<Item> items = itemRepository.selectAllByCatalogItemId(inStock.getKey());
2098
 
2096
 
Line 2145... Line 2143...
2145
 
2143
 
2146
		return inStocks;
2144
		return inStocks;
2147
	}
2145
	}
2148
 
2146
 
2149
	private FocusedModelShortageModel getFocusedModelShortage(int qty, int catalogId,
2147
	private FocusedModelShortageModel getFocusedModelShortage(int qty, int catalogId,
2150
			Map<Integer, Integer> processingOrderMap, Map<Integer, Integer> grnPendingOrdersMap,
2148
															  Map<Integer, Integer> processingOrderMap, Map<Integer, Integer> grnPendingOrdersMap,
2151
			Map<Integer, Integer> catalogIdAndQtyMap, int fofoId,
2149
															  Map<Integer, Integer> catalogIdAndQtyMap, int fofoId,
2152
			Map<Integer, Map<Integer, List<SaholicCIS>>> warehouseItemAvailabilityMap,
-
 
2153
			Map<Integer, Map<Integer, List<SaholicPOItem>>> warehousePoItemAvailabilityMap, List<Item> items,
2150
															  Map<Integer, Map<Integer, List<SaholicPOItem>>> warehousePoItemAvailabilityMap, List<Item> items,
2154
			CustomRetailer customRetailer) throws ProfitMandiBusinessException {
2151
															  CustomRetailer customRetailer) throws ProfitMandiBusinessException {
2155
 
2152
 
2156
		int minQty = qty;
2153
		int minQty = qty;
2157
		int inStockQty = 0;
2154
		int inStockQty = 0;
2158
		int processingQty = 0;
2155
		int processingQty = 0;
2159
		int grnPendingQty = 0;
2156
		int grnPendingQty = 0;
Line 2176... Line 2173...
2176
		int totalQty = processingQty + grnPendingQty + inStockQty;
2173
		int totalQty = processingQty + grnPendingQty + inStockQty;
2177
 
2174
 
2178
		int shortageQty = minQty - totalQty;
2175
		int shortageQty = minQty - totalQty;
2179
		FofoStore fofoStore = fofoStoreRepository.selectByRetailerId(fofoId);
2176
		FofoStore fofoStore = fofoStoreRepository.selectByRetailerId(fofoId);
2180
 
2177
 
2181
		Map<Integer, List<SaholicCIS>> itemAvailabilityMap = warehouseItemAvailabilityMap
-
 
2182
				.get(fofoStore.getWarehouseId());
-
 
2183
 
2178
 
2184
		Map<Integer, List<SaholicPOItem>> poItemAvailabilityMap = warehousePoItemAvailabilityMap
2179
		Map<Integer, List<SaholicPOItem>> poItemAvailabilityMap = warehousePoItemAvailabilityMap
2185
				.get(fofoStore.getWarehouseId());
2180
				.get(fofoStore.getWarehouseId());
2186
 
2181
 
2187
		for (Item it : items) {
2182
		for (Item it : items) {
2188
			List<SaholicCIS> currentAvailability = null;
2183
			List<SaholicCISTable> currentAvailability = saholicCISTableRepository.selectByItemWarehouse(it.getId(), fofoStore.getWarehouseId());
2189
			List<SaholicPOItem> poItemAvailability = null;
2184
			List<SaholicPOItem> poItemAvailability = null;
2190
			if (itemAvailabilityMap != null) {
-
 
2191
				currentAvailability = itemAvailabilityMap.get(it.getId());
-
 
2192
			}
-
 
2193
 
2185
 
2194
			if (poItemAvailabilityMap != null) {
2186
			if (poItemAvailabilityMap != null) {
2195
				poItemAvailability = poItemAvailabilityMap.get(it.getId());
2187
				poItemAvailability = poItemAvailabilityMap.get(it.getId());
2196
			}
2188
			}
2197
			if (currentAvailability != null) {
2189
			if (currentAvailability != null) {
2198
				allColorNetAvailability += currentAvailability.stream()
2190
				allColorNetAvailability += currentAvailability.stream()
2199
						.collect(Collectors.summingInt(SaholicCIS::getNetavailability));
2191
						.collect(Collectors.summingInt(SaholicCISTable::getNetAvailability));
2200
			}
2192
			}
2201
 
2193
 
2202
			if (poItemAvailability != null) {
2194
			if (poItemAvailability != null) {
2203
				allColorPoAvailability += poItemAvailability.stream()
2195
				allColorPoAvailability += poItemAvailability.stream()
2204
						.collect(Collectors.summingInt(SaholicPOItem::getUnfulfilledQty));
2196
						.collect(Collectors.summingInt(SaholicPOItem::getUnfulfilledQty));
Line 2229... Line 2221...
2229
		return "send-po-notification";
2221
		return "send-po-notification";
2230
	}
2222
	}
2231
 
2223
 
2232
	@RequestMapping(value = "/indent/send-po-notification", method = RequestMethod.POST)
2224
	@RequestMapping(value = "/indent/send-po-notification", method = RequestMethod.POST)
2233
	public String sendPONotification(HttpServletRequest request, @RequestBody POItemWarehouseModel poItemWarehouseModel,
2225
	public String sendPONotification(HttpServletRequest request, @RequestBody POItemWarehouseModel poItemWarehouseModel,
2234
			Model model) throws Exception {
2226
									 Model model) throws Exception {
2235
 
2227
 
2236
		Map<Integer, Item> selectedCatalogItemMap = itemRepository
2228
		Map<Integer, Item> selectedCatalogItemMap = itemRepository
2237
				.selectAllByCatalogIds(new HashSet<>(poItemWarehouseModel.getCatalogIds())).stream()
2229
				.selectAllByCatalogIds(new HashSet<>(poItemWarehouseModel.getCatalogIds())).stream()
2238
				.collect(Collectors.toMap(x -> x.getCatalogItemId(), x -> x, (existing, replacement) -> existing));
2230
				.collect(Collectors.toMap(x -> x.getCatalogItemId(), x -> x, (existing, replacement) -> existing));
2239
 
2231