Subversion Repositories SmartDukaan

Rev

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

Rev 31361 Rev 31466
Line 80... Line 80...
80
import java.util.Map.Entry;
80
import java.util.Map.Entry;
81
import java.util.stream.Collectors;
81
import java.util.stream.Collectors;
82
 
82
 
83
import static in.shop2020.model.v1.order.OrderStatus.*;
83
import static in.shop2020.model.v1.order.OrderStatus.*;
84
 
84
 
85
 
-
 
86
@Controller
85
@Controller
87
@Transactional(rollbackOn = Throwable.class)
86
@Transactional(rollbackOn = Throwable.class)
88
public class DashboardController {
87
public class DashboardController {
89
 
88
 
90
	List<String> emails = Arrays.asList("kamini.sharma@smartdukaan.com", "neeraj.gupta@smartdukaan.com",
89
	List<String> emails = Arrays.asList("kamini.sharma@smartdukaan.com", "neeraj.gupta@smartdukaan.com",
Line 589... Line 588...
589
			model.addAttribute("shippedLineItemMap", shippedLineItemMap);
588
			model.addAttribute("shippedLineItemMap", shippedLineItemMap);
590
		}
589
		}
591
		return "purchase-shipped-order-status";
590
		return "purchase-shipped-order-status";
592
	}
591
	}
593
 
592
 
594
 
-
 
595
	@Autowired
593
	@Autowired
596
	OfferRepository offerRepository;
594
	OfferRepository offerRepository;
597
 
595
 
598
	@Autowired
596
	@Autowired
599
	OfferPayoutRepository offerPayoutRepository;
597
	OfferPayoutRepository offerPayoutRepository;
Line 619... Line 617...
619
				.selectAllPurchaseInventoryByFofoId(loginDetails.getFofoId(), startOfMonth, endOfMonth);
617
				.selectAllPurchaseInventoryByFofoId(loginDetails.getFofoId(), startOfMonth, endOfMonth);
620
 
618
 
621
		AllPurchaseInventoryModel partnerFrontIncomes = schemeInOutRepository
619
		AllPurchaseInventoryModel partnerFrontIncomes = schemeInOutRepository
622
				.selectFrontIncomeByFofoId(loginDetails.getFofoId(), startOfMonth, endOfMonth);
620
				.selectFrontIncomeByFofoId(loginDetails.getFofoId(), startOfMonth, endOfMonth);
623
 
621
 
624
		List<OfferPayoutImeiIncomeModel> offerPayoutImeiIncomeModels = offerPayoutRepository.getTotalPayoutsByPartnerPeriod(
622
		List<OfferPayoutImeiIncomeModel> offerPayoutImeiIncomeModels = offerPayoutRepository
625
				YearMonth.of(startOfMonth.getYear(), startOfMonth.getMonth()), loginDetails.getFofoId(), null, null);
623
				.getTotalPayoutsByPartnerPeriod(YearMonth.of(startOfMonth.getYear(), startOfMonth.getMonth()),
-
 
624
						loginDetails.getFofoId(), null, null);
626
 
625
 
-
 
626
		long additionalIncome = offerPayoutImeiIncomeModels.stream()
627
		long additionalIncome = offerPayoutImeiIncomeModels.stream().collect(Collectors.summingDouble(x -> x.getSalePayout() + x.getPurchasePayout())).longValue();
627
				.collect(Collectors.summingDouble(x -> x.getSalePayout() + x.getPurchasePayout())).longValue();
-
 
628
		// AllPurchaseInventoryModel partnerAdditionalIncome =
628
		//AllPurchaseInventoryModel partnerAdditionalIncome = offerRepository.selectPurchaseIncome(loginDetails.getFofoId(), startOfMonth, endOfMonth);
629
		// offerRepository.selectPurchaseIncome(loginDetails.getFofoId(), startOfMonth,
-
 
630
		// endOfMonth);
629
 
631
 
630
		LOGGER.info("partnerfrontIncomes" + partnerFrontIncomes);
632
		LOGGER.info("partnerfrontIncomes" + partnerFrontIncomes);
631
 
633
 
632
		LOGGER.info("partnerCreditedSaleAmount" + partnerCreditedSaleAmount);
634
		LOGGER.info("partnerCreditedSaleAmount" + partnerCreditedSaleAmount);
633
		LOGGER.info("partnerPurchaseInAmount" + partnerPurchaseInAmount);
635
		LOGGER.info("partnerPurchaseInAmount" + partnerPurchaseInAmount);
Line 663... Line 665...
663
 
665
 
664
		LOGGER.info("partnerPurchaseInTT" + partnerPurchaseIn);
666
		LOGGER.info("partnerPurchaseInTT" + partnerPurchaseIn);
665
		LOGGER.info("partnerCreditedSaleTT" + partnerCreditedSale);
667
		LOGGER.info("partnerCreditedSaleTT" + partnerCreditedSale);
666
		LOGGER.info("pendingIncomeTT" + pendingIncome);
668
		LOGGER.info("pendingIncomeTT" + pendingIncome);
667
 
669
 
668
		long totalIncome = partnerCreditedSale + partnerPurchaseIn + pendingIncome + partnerFrontIncome + additionalIncome;
670
		long totalIncome = partnerCreditedSale + partnerPurchaseIn + pendingIncome + partnerFrontIncome
-
 
671
				+ additionalIncome;
669
 
672
 
670
		long creditedIncome = partnerCreditedSale + partnerPurchaseIn + partnerFrontIncome + additionalIncome;
673
		long creditedIncome = partnerCreditedSale + partnerPurchaseIn + partnerFrontIncome + additionalIncome;
671
 
674
 
672
		long pendingTotalIncome = pendingIncome;
675
		long pendingTotalIncome = pendingIncome;
673
		LOGGER.info("totalIncome" + totalIncome);
676
		LOGGER.info("totalIncome" + totalIncome);
Line 1214... Line 1217...
1214
			throws Exception {
1217
			throws Exception {
1215
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1218
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1216
		String email = loginDetails.getEmailId();
1219
		String email = loginDetails.getEmailId();
1217
 
1220
 
1218
		Set<Integer> authfofoIds = new HashSet<>();
1221
		Set<Integer> authfofoIds = new HashSet<>();
1219
		authfofoIds = csService.getAuthFofoIds(email);
1222
		authfofoIds = csService.getAuthFofoIds(email, true);
1220
		Map<Integer, List<Integer>> warehouseIdFofoIdMap = fofoStoreRepository
1223
		Map<Integer, List<Integer>> warehouseIdFofoIdMap = fofoStoreRepository
1221
				.selectActivePartnersByRetailerIds(new ArrayList<>(authfofoIds)).stream().collect(Collectors.groupingBy(
1224
				.selectActivePartnersByRetailerIds(new ArrayList<>(authfofoIds)).stream().collect(Collectors.groupingBy(
1222
						FofoStore::getWarehouseId, Collectors.mapping(FofoStore::getId, Collectors.toList())));
1225
						FofoStore::getWarehouseId, Collectors.mapping(FofoStore::getId, Collectors.toList())));
1223
 
1226
 
1224
		Map<Integer, CustomRetailer> fofoIdAndPartnerMap = retailerService.getFofoRetailers(false);
1227
		Map<Integer, CustomRetailer> fofoIdAndPartnerMap = retailerService.getFofoRetailers(false);
Line 1261... Line 1264...
1261
	@RequestMapping(value = "/getWarehouseWiseBrandStock", method = RequestMethod.GET)
1264
	@RequestMapping(value = "/getWarehouseWiseBrandStock", method = RequestMethod.GET)
1262
	public String getWarehouseWiseBrandStock(HttpServletRequest request, Model model,
1265
	public String getWarehouseWiseBrandStock(HttpServletRequest request, Model model,
1263
			@RequestParam List<Integer> warehouseId) throws Exception {
1266
			@RequestParam List<Integer> warehouseId) throws Exception {
1264
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1267
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1265
		String email = loginDetails.getEmailId();
1268
		String email = loginDetails.getEmailId();
1266
		Set<Integer> authfofoIds = csService.getAuthFofoIds(email);
1269
		Set<Integer> authfofoIds = csService.getAuthFofoIds(email, true);
1267
		Map<Integer, List<Integer>> warehouseIdFofoIdMap = fofoStoreRepository
1270
		Map<Integer, List<Integer>> warehouseIdFofoIdMap = fofoStoreRepository
1268
				.selectActivePartnersByRetailerIds(new ArrayList<>(authfofoIds)).stream().collect(Collectors.groupingBy(
1271
				.selectActivePartnersByRetailerIds(new ArrayList<>(authfofoIds)).stream().collect(Collectors.groupingBy(
1269
						FofoStore::getWarehouseId, Collectors.mapping(FofoStore::getId, Collectors.toList())));
1272
						FofoStore::getWarehouseId, Collectors.mapping(FofoStore::getId, Collectors.toList())));
1270
		List<WarehouseWiseBrandStockModel> warehouseWiseBrandStock = new ArrayList<>();
1273
		List<WarehouseWiseBrandStockModel> warehouseWiseBrandStock = new ArrayList<>();
1271
		if (!warehouseId.contains(0)) {
1274
		if (!warehouseId.contains(0)) {
Line 1332... Line 1335...
1332
			throws Exception {
1335
			throws Exception {
1333
 
1336
 
1334
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1337
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1335
		String email = loginDetails.getEmailId();
1338
		String email = loginDetails.getEmailId();
1336
 
1339
 
1337
		Set<Integer> authfofoIds = csService.getAuthFofoIds(email);
1340
		Set<Integer> authfofoIds = csService.getAuthFofoIds(email, true);
1338
 
1341
 
1339
		Map<Integer, WarehouseWiseBrandSaleModel> warehouseWiseBrandPartnerSales = fofoStoreRepository
1342
		Map<Integer, WarehouseWiseBrandSaleModel> warehouseWiseBrandPartnerSales = fofoStoreRepository
1340
				.selectGroupByWarehouseBrandWisePartnerSale(brand, new ArrayList<>(authfofoIds)).stream()
1343
				.selectGroupByWarehouseBrandWisePartnerSale(brand, new ArrayList<>(authfofoIds)).stream()
1341
				.collect(Collectors.toMap(x -> x.getWarehouseId(), x -> x));
1344
				.collect(Collectors.toMap(x -> x.getWarehouseId(), x -> x));
1342
 
1345
 
Line 1405... Line 1408...
1405
	public String getWarehouseBrandWiseItemSale(HttpServletRequest request, Model model,
1408
	public String getWarehouseBrandWiseItemSale(HttpServletRequest request, Model model,
1406
			@RequestParam List<Integer> warehouseId, @RequestParam String brand) throws Exception {
1409
			@RequestParam List<Integer> warehouseId, @RequestParam String brand) throws Exception {
1407
		Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
1410
		Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
1408
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1411
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1409
		String email = loginDetails.getEmailId();
1412
		String email = loginDetails.getEmailId();
1410
		Set<Integer> authfofoIds = csService.getAuthFofoIds(email);
1413
		Set<Integer> authfofoIds = csService.getAuthFofoIds(email, true);
1411
		Map<Integer, WarehouseBrandWiseItemSaleModel> branditemSalesMap = fofoStoreRepository
1414
		Map<Integer, WarehouseBrandWiseItemSaleModel> branditemSalesMap = fofoStoreRepository
1412
				.selectWarehouseBrandItemSale(warehouseId, brand, new ArrayList<>(authfofoIds)).stream()
1415
				.selectWarehouseBrandItemSale(warehouseId, brand, new ArrayList<>(authfofoIds)).stream()
1413
				.collect(Collectors.toMap(x -> x.getItemId(), x -> x));
1416
				.collect(Collectors.toMap(x -> x.getItemId(), x -> x));
1414
 
1417
 
1415
		List<WarehouseBrandItemUnbilledActivatedModel> unbilledItems = fofoStoreRepository
1418
		List<WarehouseBrandItemUnbilledActivatedModel> unbilledItems = fofoStoreRepository
Line 1785... Line 1788...
1785
	public String getMobileBrandWise(HttpServletRequest request, Model model) throws Exception {
1788
	public String getMobileBrandWise(HttpServletRequest request, Model model) throws Exception {
1786
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1789
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1787
		String email = loginDetails.getEmailId();
1790
		String email = loginDetails.getEmailId();
1788
 
1791
 
1789
		AuthUser authUser = authRepository.selectByEmailOrMobile(email);
1792
		AuthUser authUser = authRepository.selectByEmailOrMobile(email);
1790
		Set<Integer> fofoIds = csService.getAuthFofoIds(email);
1793
		Set<Integer> fofoIds = csService.getAuthFofoIds(email, true);
1791
 
1794
 
1792
		Map<String, BrandWisePartnerSaleModel> partnersBrandSaleMap = null;
1795
		Map<String, BrandWisePartnerSaleModel> partnersBrandSaleMap = null;
1793
		partnersBrandSaleMap = fofoStoreRepository.selectGroupByBrandWarehousePartnerSale(new ArrayList<>(fofoIds))
1796
		partnersBrandSaleMap = fofoStoreRepository.selectGroupByBrandWarehousePartnerSale(new ArrayList<>(fofoIds))
1794
				.stream().collect(Collectors.toMap(x -> x.getBrand(), x -> x));
1797
				.stream().collect(Collectors.toMap(x -> x.getBrand(), x -> x));
1795
 
1798
 
Line 1823... Line 1826...
1823
	@RequestMapping(value = "/getAccessoriesBrandWise", method = RequestMethod.GET)
1826
	@RequestMapping(value = "/getAccessoriesBrandWise", method = RequestMethod.GET)
1824
	public String getAccessoriesBrandWise(HttpServletRequest request, Model model) throws Exception {
1827
	public String getAccessoriesBrandWise(HttpServletRequest request, Model model) throws Exception {
1825
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1828
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1826
		String email = loginDetails.getEmailId();
1829
		String email = loginDetails.getEmailId();
1827
 
1830
 
1828
		Set<Integer> fofoIds = csService.getAuthFofoIds(email);
1831
		Set<Integer> fofoIds = csService.getAuthFofoIds(email, true);
1829
 
1832
 
1830
		List<BrandWisePartnerSaleModel> accessoriesBrandSales = null;
1833
		List<BrandWisePartnerSaleModel> accessoriesBrandSales = null;
1831
 
1834
 
1832
		accessoriesBrandSales = fofoStoreRepository
1835
		accessoriesBrandSales = fofoStoreRepository
1833
				.selectGroupByBrandAccesoriesWarehousePartnerSale(new ArrayList<>(fofoIds));
1836
				.selectGroupByBrandAccesoriesWarehousePartnerSale(new ArrayList<>(fofoIds));
Line 1920... Line 1923...
1920
	public String getSaleCountByMilestone(HttpServletRequest request,
1923
	public String getSaleCountByMilestone(HttpServletRequest request,
1921
			@RequestParam(required = false, defaultValue = "0") int warehouseId, Model model) throws Exception {
1924
			@RequestParam(required = false, defaultValue = "0") int warehouseId, Model model) throws Exception {
1922
 
1925
 
1923
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1926
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1924
		String email = loginDetails.getEmailId();
1927
		String email = loginDetails.getEmailId();
1925
		Set<Integer> fofoIds = csService.getAuthFofoIds(email);
1928
		Set<Integer> fofoIds = csService.getAuthFofoIds(email, true);
1926
		Map<Integer, Double> last3MonthSale = fofoOrderItemRepository.selectSumMopGroupByRetailer(
1929
		Map<Integer, Double> last3MonthSale = fofoOrderItemRepository.selectSumMopGroupByRetailer(
1927
				LocalDateTime.now().withDayOfMonth(1).minusMonths(2), LocalDateTime.now(), 0, false);
1930
				LocalDateTime.now().withDayOfMonth(1).minusMonths(2), LocalDateTime.now(), 0, false);
1928
 
1931
 
1929
		if (fofoIds != null && fofoIds.size() > 0) {
1932
		if (fofoIds != null && fofoIds.size() > 0) {
1930
			if (warehouseId != 0) {
1933
			if (warehouseId != 0) {
Line 2003... Line 2006...
2003
	public String getPurchaseCountByMileStone(HttpServletRequest request,
2006
	public String getPurchaseCountByMileStone(HttpServletRequest request,
2004
			@RequestParam(required = false, defaultValue = "0") int warehouseId, Model model) throws Exception {
2007
			@RequestParam(required = false, defaultValue = "0") int warehouseId, Model model) throws Exception {
2005
 
2008
 
2006
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
2009
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
2007
		String email = loginDetails.getEmailId();
2010
		String email = loginDetails.getEmailId();
2008
		Set<Integer> fofoIds = csService.getAuthFofoIds(email);
2011
		Set<Integer> fofoIds = csService.getAuthFofoIds(email, true);
2009
		Map<Integer, Double> last3MonthS = orderRepository.selectBillingDatesBetweenSumGroupByRetailerId(
2012
		Map<Integer, Double> last3MonthS = orderRepository.selectBillingDatesBetweenSumGroupByRetailerId(
2010
				LocalDateTime.now().withDayOfMonth(1).minusMonths(2), LocalDateTime.now());
2013
				LocalDateTime.now().withDayOfMonth(1).minusMonths(2), LocalDateTime.now());
2011
 
2014
 
2012
		if (fofoIds != null && fofoIds.size() > 0) {
2015
		if (fofoIds != null && fofoIds.size() > 0) {
2013
			if (warehouseId != 0) {
2016
			if (warehouseId != 0) {
Line 2103... Line 2106...
2103
	}
2106
	}
2104
 
2107
 
2105
	@RequestMapping(value = "/getActivatedModelByBrand", method = RequestMethod.GET)
2108
	@RequestMapping(value = "/getActivatedModelByBrand", method = RequestMethod.GET)
2106
	public String getActivatedModelByBrand(HttpServletRequest request, Model model) throws Exception {
2109
	public String getActivatedModelByBrand(HttpServletRequest request, Model model) throws Exception {
2107
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
2110
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
2108
		Set<Integer> fofoIds = csService.getAuthFofoIds(loginDetails.getEmailId());
2111
		Set<Integer> fofoIds = csService.getAuthFofoIds(loginDetails.getEmailId(), true);
2109
 
2112
 
2110
		List<BrandWiseActivatedModel> activatedModels = activatedImeiRepository
2113
		List<BrandWiseActivatedModel> activatedModels = activatedImeiRepository
2111
				.selectActivatedModelGroupByBrand(new ArrayList<>(fofoIds));
2114
				.selectActivatedModelGroupByBrand(new ArrayList<>(fofoIds));
2112
		model.addAttribute("activatedModels", activatedModels);
2115
		model.addAttribute("activatedModels", activatedModels);
2113
		return "activation-brandwise-report";
2116
		return "activation-brandwise-report";
Line 2214... Line 2217...
2214
			now = now.minusMonths(1);
2217
			now = now.minusMonths(1);
2215
		}
2218
		}
2216
 
2219
 
2217
		model.addAttribute("yearMonth", list);
2220
		model.addAttribute("yearMonth", list);
2218
 
2221
 
2219
		List<PartnerMonthlySaleModel> partnerMonthlySaleModels = orderRepository.selectSecondaryGroupByYearMonth(fofoIds, LocalDate.now().withDayOfMonth(1).atStartOfDay().minusMonths(12));
2222
		List<PartnerMonthlySaleModel> partnerMonthlySaleModels = orderRepository.selectSecondaryGroupByYearMonth(
-
 
2223
				fofoIds, LocalDate.now().withDayOfMonth(1).atStartOfDay().minusMonths(12));
2220
		Map<Integer, Map<YearMonth, Double>> partnerMonthPurchaseMap = partnerMonthlySaleModels.stream()
2224
		Map<Integer, Map<YearMonth, Double>> partnerMonthPurchaseMap = partnerMonthlySaleModels.stream()
-
 
2225
				.collect(Collectors.groupingBy(x -> x.getFofoId(),
-
 
2226
						Collectors.groupingBy(
2221
				.collect(Collectors.groupingBy(x -> x.getFofoId(), Collectors.groupingBy(y -> YearMonth.parse(y.getYearMonth(), DateTimeFormatter.ofPattern("MM-yyyy")),
2227
								y -> YearMonth.parse(y.getYearMonth(), DateTimeFormatter.ofPattern("MM-yyyy")),
2222
						Collectors.summingDouble(x -> x.getAmount()))));
2228
								Collectors.summingDouble(x -> x.getAmount()))));
2223
 
2229
 
2224
		Map<Integer, CustomRetailer> customRetailerMap = retailerService.getAllFofoRetailers().entrySet().stream()
2230
		Map<Integer, CustomRetailer> customRetailerMap = retailerService.getAllFofoRetailers().entrySet().stream()
2225
				.filter(x -> fofoIds.contains(x.getKey()))
2231
				.filter(x -> fofoIds.contains(x.getKey()))
2226
				.collect(Collectors.toMap(x -> x.getKey(), x -> x.getValue()));
2232
				.collect(Collectors.toMap(x -> x.getKey(), x -> x.getValue()));
2227
		model.addAttribute("customRetailerMap", customRetailerMap);
2233
		model.addAttribute("customRetailerMap", customRetailerMap);