Subversion Repositories SmartDukaan

Rev

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

Rev 30768 Rev 30831
Line 160... Line 160...
160
 
160
 
161
	@Autowired
161
	@Autowired
162
	private CategoryRepository categoryRepository;
162
	private CategoryRepository categoryRepository;
163
 
163
 
164
	List<String> adminEmail = Arrays.asList("tarun.verma@smartdukaan.com", "neeraj.gupta@smartdukaan.com",
164
	List<String> adminEmail = Arrays.asList("tarun.verma@smartdukaan.com", "neeraj.gupta@smartdukaan.com",
165
			"amit.gupta@smartdukaan.com", "tejbeer.kaur@smartdukaan.com");
165
			"amit.gupta@smartdukaan.com", "tejbeer.kaur@smartdukaan.com", "raksha.vyas@smartdukaan.com");
166
 
166
 
167
	@RequestMapping(value = "/createScheme", method = RequestMethod.GET)
167
	@RequestMapping(value = "/createScheme", method = RequestMethod.GET)
168
	public String createScheme(HttpServletRequest request, Model model) throws ProfitMandiBusinessException {
168
	public String createScheme(HttpServletRequest request, Model model) throws ProfitMandiBusinessException {
169
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
169
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
170
 
170
 
Line 214... Line 214...
214
 
214
 
215
	}
215
	}
216
 
216
 
217
	@RequestMapping(value = "/getCatalogDescriptionByBrands", method = RequestMethod.GET)
217
	@RequestMapping(value = "/getCatalogDescriptionByBrands", method = RequestMethod.GET)
218
	public String getTagListingItemsByBrand(HttpServletRequest request, @RequestParam int categoryId,
218
	public String getTagListingItemsByBrand(HttpServletRequest request, @RequestParam int categoryId,
219
											@RequestParam List<String> brands, Model model) throws Exception {
219
			@RequestParam List<String> brands, Model model) throws Exception {
220
		Map<Integer, String> catalogIdItemDescriptionMap = inventoryService.getModelDescriptionMap(categoryId, brands);
220
		Map<Integer, String> catalogIdItemDescriptionMap = inventoryService.getModelDescriptionMap(categoryId, brands);
221
		model.addAttribute("catalogIdItemDescriptionMap", catalogIdItemDescriptionMap);
221
		model.addAttribute("catalogIdItemDescriptionMap", catalogIdItemDescriptionMap);
222
		// model.addAttribute("brands", inventoryService.getAllBrands());
222
		// model.addAttribute("brands", inventoryService.getAllBrands());
223
 
223
 
224
		return "tag-listing-items-description";
224
		return "tag-listing-items-description";
Line 276... Line 276...
276
			int fofoId = retailerEntry.getKey();
276
			int fofoId = retailerEntry.getKey();
277
			long investmentMaintainedDays = investmentMaintainedDaysMap.get(fofoId) == null ? 0
277
			long investmentMaintainedDays = investmentMaintainedDaysMap.get(fofoId) == null ? 0
278
					: investmentMaintainedDaysMap.get(fofoId);
278
					: investmentMaintainedDaysMap.get(fofoId);
279
 
279
 
280
			List<SchemeInOut> schemeInouts = retailerEntry.getValue().stream().map(x -> inventoryItemIdSchemeMap.get(x))
280
			List<SchemeInOut> schemeInouts = retailerEntry.getValue().stream().map(x -> inventoryItemIdSchemeMap.get(x))
-
 
281
					.flatMap(List::stream)
281
					.flatMap(List::stream).filter(x -> x.getStatus().equals(SchemePayoutStatus.PENDING) && x.getRolledBackTimestamp() == null).collect(Collectors.toList());
282
					.filter(x -> x.getStatus().equals(SchemePayoutStatus.PENDING) && x.getRolledBackTimestamp() == null)
-
 
283
					.collect(Collectors.toList());
282
			float totalAmount = 0;
284
			float totalAmount = 0;
283
			LocalDateTime firstBillingDate = transactionRepository.getFirstBillingDate(fofoId);
285
			LocalDateTime firstBillingDate = transactionRepository.getFirstBillingDate(fofoId);
284
			boolean sameYearMonth = firstBillingDate.getMonth() == startOfPreviousMonth.getMonth() && firstBillingDate.getYear() == startOfPreviousMonth.getYear();
286
			boolean sameYearMonth = firstBillingDate.getMonth() == startOfPreviousMonth.getMonth()
-
 
287
					&& firstBillingDate.getYear() == startOfPreviousMonth.getYear();
285
			for (SchemeInOut sio : schemeInouts) {
288
			for (SchemeInOut sio : schemeInouts) {
286
				if (sameYearMonth) {
289
				if (sameYearMonth) {
287
					sio.setStatusDescription("Investment payout fully disbursed for first month");
290
					sio.setStatusDescription("Investment payout fully disbursed for first month");
288
					sio.setStatus(SchemePayoutStatus.CREDITED);
291
					sio.setStatus(SchemePayoutStatus.CREDITED);
289
					sio.setCreditTimestamp(LocalDateTime.now());
292
					sio.setCreditTimestamp(LocalDateTime.now());
290
					totalAmount += sio.getAmount();
293
					totalAmount += sio.getAmount();
291
				} else {
294
				} else {
292
					if (investmentMaintainedDays < 8) {
295
					if (investmentMaintainedDays < 8) {
293
						sio.setStatus(SchemePayoutStatus.REJECTED);
296
						sio.setStatus(SchemePayoutStatus.REJECTED);
294
						//sio.setRolledBackTimestamp(LocalDateTime.now());
297
						// sio.setRolledBackTimestamp(LocalDateTime.now());
-
 
298
						sio.setStatusDescription(
295
						sio.setStatusDescription("Investment maintained for " + investmentMaintainedDays + "(< 8) days");
299
								"Investment maintained for " + investmentMaintainedDays + "(< 8) days");
296
					} else if (investmentMaintainedDays < 12) {
300
					} else if (investmentMaintainedDays < 12) {
297
						sio.setStatus(SchemePayoutStatus.CREDITED);
301
						sio.setStatus(SchemePayoutStatus.CREDITED);
298
						sio.setAmount(sio.getAmount() / 2);
302
						sio.setAmount(sio.getAmount() / 2);
299
						sio.setCreditTimestamp(LocalDateTime.now());
303
						sio.setCreditTimestamp(LocalDateTime.now());
-
 
304
						sio.setStatusDescription(
300
						sio.setStatusDescription("Investment maintained for " + investmentMaintainedDays + "(< 12) days");
305
								"Investment maintained for " + investmentMaintainedDays + "(< 12) days");
301
						totalAmount += sio.getAmount();
306
						totalAmount += sio.getAmount();
302
					} else {
307
					} else {
303
						sio.setStatus(SchemePayoutStatus.CREDITED);
308
						sio.setStatus(SchemePayoutStatus.CREDITED);
304
						sio.setCreditTimestamp(LocalDateTime.now());
309
						sio.setCreditTimestamp(LocalDateTime.now());
305
						totalAmount += sio.getAmount();
310
						totalAmount += sio.getAmount();
Line 313... Line 318...
313
					description += ", as maintained for " + investmentMaintainedDays + "(< 12) days";
318
					description += ", as maintained for " + investmentMaintainedDays + "(< 12) days";
314
				}
319
				}
315
				walletService.addAmountToWallet(fofoId, referenceId, WalletReferenceType.INVESTMENT_PAYOUT, description,
320
				walletService.addAmountToWallet(fofoId, referenceId, WalletReferenceType.INVESTMENT_PAYOUT, description,
316
						totalAmount, lastOfPreviousMonth.atTime(LocalTime.MAX));
321
						totalAmount, lastOfPreviousMonth.atTime(LocalTime.MAX));
317
			}
322
			}
318
			//Its ok to process Margins Pending for activation
323
			// Its ok to process Margins Pending for activation
319
			schemeService.processActivation();
324
			schemeService.processActivation();
320
			System.out.printf("%d\t%d\t%f%n", fofoId, investmentMaintainedDays, totalAmount);
325
			System.out.printf("%d\t%d\t%f%n", fofoId, investmentMaintainedDays, totalAmount);
321
		}
326
		}
322
 
327
 
323
 
-
 
324
	}
328
	}
325
 
329
 
326
	@RequestMapping(value = "/evaluateActualInvestmentPayout", method = RequestMethod.GET)
330
	@RequestMapping(value = "/evaluateActualInvestmentPayout", method = RequestMethod.GET)
327
	public ResponseEntity<?> evaluateActualInvestmentPayout(HttpServletRequest request, Model model) throws Exception {
331
	public ResponseEntity<?> evaluateActualInvestmentPayout(HttpServletRequest request, Model model) throws Exception {
328
 
332
 
Line 497... Line 501...
497
		return "response";
501
		return "response";
498
	}
502
	}
499
 
503
 
500
	@RequestMapping(value = "/schemes/delete", method = RequestMethod.DELETE)
504
	@RequestMapping(value = "/schemes/delete", method = RequestMethod.DELETE)
501
	public String deleteShcemes(HttpServletRequest request,
505
	public String deleteShcemes(HttpServletRequest request,
502
								@RequestParam(name = "schemeId", required = false, defaultValue = "0") int schemeId,
506
			@RequestParam(name = "schemeId", required = false, defaultValue = "0") int schemeId,
503
								@RequestParam(name = "catalogId", required = false, defaultValue = "0") int catalogId, Model model)
507
			@RequestParam(name = "catalogId", required = false, defaultValue = "0") int catalogId, Model model)
504
			throws Exception {
508
			throws Exception {
505
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
509
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
506
		if (schemeId > 0 && catalogId > 0) {
510
		if (schemeId > 0 && catalogId > 0) {
507
			schemeItemRepository.deleteByCatalogIdsAndSchemeIds(catalogId, schemeId);
511
			schemeItemRepository.deleteByCatalogIdsAndSchemeIds(catalogId, schemeId);
508
 
512
 
Line 533... Line 537...
533
	}
537
	}
534
 
538
 
535
	@RequestMapping(value = "/extendSchemeById", method = RequestMethod.POST)
539
	@RequestMapping(value = "/extendSchemeById", method = RequestMethod.POST)
536
	public String extendSchemeById(HttpServletRequest request,
540
	public String extendSchemeById(HttpServletRequest request,
537
 
541
 
538
								   @RequestParam(name = ProfitMandiConstants.SCHEME_ID) int schemeId,
542
			@RequestParam(name = ProfitMandiConstants.SCHEME_ID) int schemeId,
539
								   @RequestBody LocalDateTime extendDatetime, Model model) throws Exception {
543
			@RequestBody LocalDateTime extendDatetime, Model model) throws Exception {
540
		Scheme scheme = schemeRepository.selectById(schemeId);
544
		Scheme scheme = schemeRepository.selectById(schemeId);
541
		if ((!(scheme.getActiveTimestamp() == null)) && scheme.getExpireTimestamp() == null) {
545
		if ((!(scheme.getActiveTimestamp() == null)) && scheme.getExpireTimestamp() == null) {
542
			scheme.setEndDateTime(extendDatetime);
546
			scheme.setEndDateTime(extendDatetime);
543
			schemeRepository.persist(scheme);
547
			schemeRepository.persist(scheme);
544
			model.addAttribute("response", mvcResponseSender.createResponseString(true));
548
			model.addAttribute("response", mvcResponseSender.createResponseString(true));
Line 548... Line 552...
548
		return "response";
552
		return "response";
549
	}
553
	}
550
 
554
 
551
	@RequestMapping(value = "/createScheme", method = RequestMethod.POST)
555
	@RequestMapping(value = "/createScheme", method = RequestMethod.POST)
552
	public String createScheme(HttpServletRequest request, @RequestBody CreateSchemeRequest createSchemeRequest,
556
	public String createScheme(HttpServletRequest request, @RequestBody CreateSchemeRequest createSchemeRequest,
553
							   Model model) throws ProfitMandiBusinessException {
557
			Model model) throws ProfitMandiBusinessException {
554
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
558
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
555
		LOGGER.info("CreateSchemeRequest {}", createSchemeRequest);
559
		LOGGER.info("CreateSchemeRequest {}", createSchemeRequest);
556
		schemeService.saveScheme(loginDetails.getFofoId(), createSchemeRequest);
560
		schemeService.saveScheme(loginDetails.getFofoId(), createSchemeRequest);
557
		return getDefaultSchemes(request, model);
561
		return getDefaultSchemes(request, model);
558
	}
562
	}
Line 573... Line 577...
573
	}
577
	}
574
 
578
 
575
	// Show 20 recents
579
	// Show 20 recents
576
	@RequestMapping(value = "/getSchemes", method = RequestMethod.GET)
580
	@RequestMapping(value = "/getSchemes", method = RequestMethod.GET)
577
	public String getSchemes(HttpServletRequest request, @RequestParam(name = "offset", defaultValue = "0") int offset,
581
	public String getSchemes(HttpServletRequest request, @RequestParam(name = "offset", defaultValue = "0") int offset,
578
							 @RequestParam(required = false) LocalDate date,
582
			@RequestParam(required = false) LocalDate date,
579
							 @RequestParam(name = "limit", required = false, defaultValue = "30") int limit,
583
			@RequestParam(name = "limit", required = false, defaultValue = "30") int limit,
580
							 @RequestParam(name = "searchModel", required = false, defaultValue = "0") int searchModel,
584
			@RequestParam(name = "searchModel", required = false, defaultValue = "0") int searchModel,
581
							 @RequestParam(name = "searchScheme", required = false, defaultValue = "0") int searchScheme,
585
			@RequestParam(name = "searchScheme", required = false, defaultValue = "0") int searchScheme,
582
							 @RequestParam(name = "partnerType", required = false, defaultValue = "ALL") PartnerType partnerType,
586
			@RequestParam(name = "partnerType", required = false, defaultValue = "ALL") PartnerType partnerType,
583
							 @RequestParam(name = "searchImei", required = false, defaultValue = "") String searchImei, Model model)
587
			@RequestParam(name = "searchImei", required = false, defaultValue = "") String searchImei, Model model)
584
			throws ProfitMandiBusinessException {
588
			throws ProfitMandiBusinessException {
585
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
589
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
586
		boolean isAdmin = roleManager.isAdmin(loginDetails.getRoleIds());
590
		boolean isAdmin = roleManager.isAdmin(loginDetails.getRoleIds());
587
		if (date != null) {
591
		if (date != null) {
588
			date = date.isAfter(LocalDate.now()) ? LocalDate.now() : date;
592
			date = date.isAfter(LocalDate.now()) ? LocalDate.now() : date;
Line 678... Line 682...
678
					loginDetails.getFofoId());
682
					loginDetails.getFofoId());
679
			Item item = itemRepository.selectById(inventoryItem.getItemId());
683
			Item item = itemRepository.selectById(inventoryItem.getItemId());
680
			Map<Integer, Scheme> schemeMap = new HashMap<>();
684
			Map<Integer, Scheme> schemeMap = new HashMap<>();
681
			double netEarnings = 0;
685
			double netEarnings = 0;
682
			if (inventoryItem != null) {
686
			if (inventoryItem != null) {
683
				//Offer payout
687
				// Offer payout
684
				List<OfferPayout> offerPayouts = offerPayoutRepository.selectAllBySerialNumber(loginDetails.getFofoId(), searchImei);
688
				List<OfferPayout> offerPayouts = offerPayoutRepository.selectAllBySerialNumber(loginDetails.getFofoId(),
-
 
689
						searchImei);
-
 
690
				Map<Integer, CreateOfferRequest> offerRequestMap = offerPayouts.stream()
685
				Map<Integer, CreateOfferRequest> offerRequestMap = offerPayouts.stream().map(x -> offerService.getOffer(loginDetails.getFofoId(), (int) x.getOfferId())).collect(Collectors.toMap(x -> x.getId(), x -> x));
691
						.map(x -> offerService.getOffer(loginDetails.getFofoId(), (int) x.getOfferId()))
686
 
-
 
-
 
692
						.collect(Collectors.toMap(x -> x.getId(), x -> x));
687
 
693
 
-
 
694
				schemeInOuts = schemeInOutRepository
688
				schemeInOuts = schemeInOutRepository.selectByInventoryItemIds(new HashSet<>(Arrays.asList(inventoryItem.getId())));
695
						.selectByInventoryItemIds(new HashSet<>(Arrays.asList(inventoryItem.getId())));
689
 
696
 
690
				if (!schemeInOuts.isEmpty()) {
697
				if (!schemeInOuts.isEmpty()) {
691
					netEarnings += schemeInOuts.stream().filter(x -> x.getStatus().equals(SchemePayoutStatus.CREDITED)).collect(Collectors.summingDouble(x -> x.getAmount()));
698
					netEarnings += schemeInOuts.stream().filter(x -> x.getStatus().equals(SchemePayoutStatus.CREDITED))
-
 
699
							.collect(Collectors.summingDouble(x -> x.getAmount()));
692
					List<Integer> schemeIds = schemeInOuts.stream().map(x -> x.getSchemeId()).collect(Collectors.toList());
700
					List<Integer> schemeIds = schemeInOuts.stream().map(x -> x.getSchemeId())
-
 
701
							.collect(Collectors.toList());
693
 
702
 
694
					schemes = schemeRepository.selectBySchemeIds(schemeIds);
703
					schemes = schemeRepository.selectBySchemeIds(schemeIds);
695
					for (Scheme scheme : schemes) {
704
					for (Scheme scheme : schemes) {
696
						if (scheme.getAmountType().equals(AmountType.PERCENTAGE)) {
705
						if (scheme.getAmountType().equals(AmountType.PERCENTAGE)) {
697
							scheme.setAmountModel(scheme.getAmount() + "%");
706
							scheme.setAmountModel(scheme.getAmount() + "%");
Line 923... Line 932...
923
		return "last-month-credited-income";
932
		return "last-month-credited-income";
924
	}
933
	}
925
 
934
 
926
	@RequestMapping(value = "/getLastMonthImeiWiseIncome", method = RequestMethod.GET)
935
	@RequestMapping(value = "/getLastMonthImeiWiseIncome", method = RequestMethod.GET)
927
	public String getLastMonthImeiWiseIncome(HttpServletRequest request,
936
	public String getLastMonthImeiWiseIncome(HttpServletRequest request,
928
											 @RequestParam(name = "catalogItemId", required = false, defaultValue = "") int catalogItemId,
937
			@RequestParam(name = "catalogItemId", required = false, defaultValue = "") int catalogItemId,
929
											 @RequestParam(name = "month", required = false, defaultValue = "") int month, Model model)
938
			@RequestParam(name = "month", required = false, defaultValue = "") int month, Model model)
930
			throws Exception {
939
			throws Exception {
931
 
940
 
932
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
941
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
933
 
942
 
934
		LocalDateTime lastMonthStart = LocalDate.now().minusMonths(month).withDayOfMonth(1).atStartOfDay();
943
		LocalDateTime lastMonthStart = LocalDate.now().minusMonths(month).withDayOfMonth(1).atStartOfDay();
Line 971... Line 980...
971
		LOGGER.info("lastMonthFrontEndImei {}", lastMonthFrontEndImeis);
980
		LOGGER.info("lastMonthFrontEndImei {}", lastMonthFrontEndImeis);
972
		LOGGER.info("lastMonthPurchaseInImei {}", lastMonthPurchaseInImeis);
981
		LOGGER.info("lastMonthPurchaseInImei {}", lastMonthPurchaseInImeis);
973
		LOGGER.info("lastMonthCreditedImei {}", lastMonthCreditedImeis);
982
		LOGGER.info("lastMonthCreditedImei {}", lastMonthCreditedImeis);
974
 
983
 
975
		Map<String, Double> imeiWisePendingSaleAmount = lastMonthCreditedImeis.stream()
984
		Map<String, Double> imeiWisePendingSaleAmount = lastMonthCreditedImeis.stream()
976
				.filter(x -> x.getStatus().equals(SchemePayoutStatus.PENDING))
985
				.filter(x -> x.getStatus().equals(SchemePayoutStatus.PENDING)).collect(Collectors
977
				.collect(Collectors.groupingBy(x -> x.getImei(), Collectors.summingDouble(x -> x.getPendingSaleAmount())));
986
						.groupingBy(x -> x.getImei(), Collectors.summingDouble(x -> x.getPendingSaleAmount())));
978
 
987
 
979
		Map<IncomeImeiDate, Map<String, Double>> lastMonthPurchaseInMapPairMap = lastMonthPurchaseInImeis.stream()
988
		Map<IncomeImeiDate, Map<String, Double>> lastMonthPurchaseInMapPairMap = lastMonthPurchaseInImeis.stream()
980
				.collect(Collectors.groupingBy(x -> new IncomeImeiDate(x.getImei(), x.getCreateTimeStamp()),
989
				.collect(Collectors.groupingBy(x -> new IncomeImeiDate(x.getImei(), x.getCreateTimeStamp()),
981
						Collectors.groupingBy(x -> x.getDescription(), Collectors.summingDouble(x -> x.getAmount()))));
990
						Collectors.groupingBy(x -> x.getDescription(), Collectors.summingDouble(x -> x.getAmount()))));
982
 
991
 
Line 1072... Line 1081...
1072
		return "last-month-imei-wise-income";
1081
		return "last-month-imei-wise-income";
1073
	}
1082
	}
1074
 
1083
 
1075
	@RequestMapping(value = "/brandWiseIncome", method = RequestMethod.GET)
1084
	@RequestMapping(value = "/brandWiseIncome", method = RequestMethod.GET)
1076
	public String getBrandWiseIncome(HttpServletRequest request,
1085
	public String getBrandWiseIncome(HttpServletRequest request,
1077
									 @RequestParam(name = "brand", required = false, defaultValue = "") String brand,
1086
			@RequestParam(name = "brand", required = false, defaultValue = "") String brand,
1078
									 @RequestParam(name = "status", required = false, defaultValue = "") String status,
1087
			@RequestParam(name = "status", required = false, defaultValue = "") String status,
1079
									 @RequestParam(name = "month", required = false, defaultValue = "") int month, Model model)
1088
			@RequestParam(name = "month", required = false, defaultValue = "") int month, Model model)
1080
			throws ProfitMandiBusinessException {
1089
			throws ProfitMandiBusinessException {
1081
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1090
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1082
		LOGGER.info("loginDetails {}", loginDetails);
1091
		LOGGER.info("loginDetails {}", loginDetails);
1083
		LOGGER.info("brand" + brand);
1092
		LOGGER.info("brand" + brand);
1084
		LOGGER.info("month {}", month);
1093
		LOGGER.info("month {}", month);
Line 1271... Line 1280...
1271
		return "schemes-download";
1280
		return "schemes-download";
1272
	}
1281
	}
1273
 
1282
 
1274
	@RequestMapping(value = "/schemes/download", method = RequestMethod.GET)
1283
	@RequestMapping(value = "/schemes/download", method = RequestMethod.GET)
1275
	public ResponseEntity<?> downloadInventoryItemAgingByInterval(HttpServletRequest request,
1284
	public ResponseEntity<?> downloadInventoryItemAgingByInterval(HttpServletRequest request,
1276
																  @RequestParam LocalDateTime startDateTime, @RequestParam LocalDateTime endDateTime)
1285
			@RequestParam LocalDateTime startDateTime, @RequestParam LocalDateTime endDateTime)
1277
			throws ProfitMandiBusinessException {
1286
			throws ProfitMandiBusinessException {
1278
 
1287
 
1279
		List<SchemeModel> schemeModels = schemeService.getAllSchemeModels(startDateTime, endDateTime);
1288
		List<SchemeModel> schemeModels = schemeService.getAllSchemeModels(startDateTime, endDateTime);
1280
 
1289
 
1281
		ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
1290
		ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
Line 1290... Line 1299...
1290
		return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
1299
		return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
1291
	}
1300
	}
1292
 
1301
 
1293
	@RequestMapping(value = "/getSchemeById", method = RequestMethod.GET)
1302
	@RequestMapping(value = "/getSchemeById", method = RequestMethod.GET)
1294
	public String getSchemeById(HttpServletRequest request,
1303
	public String getSchemeById(HttpServletRequest request,
1295
								@RequestParam(name = ProfitMandiConstants.SCHEME_ID) int schemeId, Model model)
1304
			@RequestParam(name = ProfitMandiConstants.SCHEME_ID) int schemeId, Model model)
1296
			throws ProfitMandiBusinessException {
1305
			throws ProfitMandiBusinessException {
1297
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1306
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1298
 
1307
 
1299
		boolean fullAccess = this.getAccess(loginDetails.getEmailId());
1308
		boolean fullAccess = this.getAccess(loginDetails.getEmailId());
1300
		Scheme scheme = schemeService.getSchemeById(schemeId);
1309
		Scheme scheme = schemeService.getSchemeById(schemeId);
Line 1304... Line 1313...
1304
		return "scheme-details";
1313
		return "scheme-details";
1305
	}
1314
	}
1306
 
1315
 
1307
	@RequestMapping(value = "/activeSchemeById", method = RequestMethod.PUT)
1316
	@RequestMapping(value = "/activeSchemeById", method = RequestMethod.PUT)
1308
	public String activeSchemeById(HttpServletRequest request,
1317
	public String activeSchemeById(HttpServletRequest request,
1309
								   @RequestParam(name = ProfitMandiConstants.SCHEME_ID) int schemeId,
1318
			@RequestParam(name = ProfitMandiConstants.SCHEME_ID) int schemeId,
1310
								   @RequestParam(name = "offset", defaultValue = "0") int offset,
1319
			@RequestParam(name = "offset", defaultValue = "0") int offset,
1311
								   @RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
1320
			@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
1312
			throws ProfitMandiBusinessException {
1321
			throws ProfitMandiBusinessException {
1313
		schemeService.activeSchemeById(schemeId);
1322
		schemeService.activeSchemeById(schemeId);
1314
		List<Scheme> schemes = schemeRepository.selectAll(offset, limit);
1323
		List<Scheme> schemes = schemeRepository.selectAll(offset, limit);
1315
		for (Scheme scheme : schemes) {
1324
		for (Scheme scheme : schemes) {
1316
			if (scheme.getAmountType().equals(AmountType.PERCENTAGE)) {
1325
			if (scheme.getAmountType().equals(AmountType.PERCENTAGE)) {
Line 1322... Line 1331...
1322
		return "schemes";
1331
		return "schemes";
1323
	}
1332
	}
1324
 
1333
 
1325
	@RequestMapping(value = "/expireSchemeById", method = RequestMethod.PUT)
1334
	@RequestMapping(value = "/expireSchemeById", method = RequestMethod.PUT)
1326
	public String expireSchemeById(HttpServletRequest request,
1335
	public String expireSchemeById(HttpServletRequest request,
1327
								   @RequestParam(name = ProfitMandiConstants.SCHEME_ID) int schemeId,
1336
			@RequestParam(name = ProfitMandiConstants.SCHEME_ID) int schemeId,
1328
								   @RequestParam(name = ProfitMandiConstants.EXPIRE_TIMESTAMP) LocalDateTime expiryTimestamp, Model model)
1337
			@RequestParam(name = ProfitMandiConstants.EXPIRE_TIMESTAMP) LocalDateTime expiryTimestamp, Model model)
1329
			throws ProfitMandiBusinessException {
1338
			throws ProfitMandiBusinessException {
1330
		schemeService.expireSchemeById(schemeId, expiryTimestamp);
1339
		schemeService.expireSchemeById(schemeId, expiryTimestamp);
1331
		return getDefaultSchemes(request, model);
1340
		return getDefaultSchemes(request, model);
1332
	}
1341
	}
1333
 
1342
 
1334
	@RequestMapping(value = "/getSchemesJson", method = RequestMethod.GET)
1343
	@RequestMapping(value = "/getSchemesJson", method = RequestMethod.GET)
1335
	public ResponseEntity<?> getSchemesJson(HttpServletRequest request,
1344
	public ResponseEntity<?> getSchemesJson(HttpServletRequest request,
1336
											@RequestParam(name = "offset", defaultValue = "0") int offset,
1345
			@RequestParam(name = "offset", defaultValue = "0") int offset,
1337
											@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
1346
			@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
1338
			throws ProfitMandiBusinessException {
1347
			throws ProfitMandiBusinessException {
1339
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1348
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1340
		return responseSender.ok(schemeService.getSchemes(loginDetails.getRoleIds(), offset, limit));
1349
		return responseSender.ok(schemeService.getSchemes(loginDetails.getRoleIds(), offset, limit));
1341
	}
1350
	}
1342
 
1351
 
Line 1350... Line 1359...
1350
 
1359
 
1351
	}
1360
	}
1352
 
1361
 
1353
	@RequestMapping(value = "/createCustomerOffer", method = RequestMethod.POST)
1362
	@RequestMapping(value = "/createCustomerOffer", method = RequestMethod.POST)
1354
	public String createCustomerOffer(HttpServletRequest request, @RequestParam String offerName,
1363
	public String createCustomerOffer(HttpServletRequest request, @RequestParam String offerName,
1355
									  @RequestParam LocalDateTime startDate, @RequestParam LocalDateTime endDate, Model model) throws Exception {
1364
			@RequestParam LocalDateTime startDate, @RequestParam LocalDateTime endDate, Model model) throws Exception {
1356
 
1365
 
1357
		CustomerOffer co = new CustomerOffer();
1366
		CustomerOffer co = new CustomerOffer();
1358
		co.setOfferName(offerName);
1367
		co.setOfferName(offerName);
1359
		co.setStartDate(startDate);
1368
		co.setStartDate(startDate);
1360
		co.setEndDate(endDate);
1369
		co.setEndDate(endDate);
Line 1386... Line 1395...
1386
 
1395
 
1387
	}
1396
	}
1388
 
1397
 
1389
	@RequestMapping(value = "/customerOfferItem/upload", method = RequestMethod.POST)
1398
	@RequestMapping(value = "/customerOfferItem/upload", method = RequestMethod.POST)
1390
	public String uploadCustomerOfferItem(HttpServletRequest request, Model model, @RequestParam int offerId,
1399
	public String uploadCustomerOfferItem(HttpServletRequest request, Model model, @RequestParam int offerId,
1391
										  HttpServletResponse response, @RequestPart MultipartFile file) throws Throwable {
1400
			HttpServletResponse response, @RequestPart MultipartFile file) throws Throwable {
1392
 
1401
 
1393
		List<CSVRecord> records = FileUtil.readFile(file);
1402
		List<CSVRecord> records = FileUtil.readFile(file);
1394
 
1403
 
1395
		for (CSVRecord record : records) {
1404
		for (CSVRecord record : records) {
1396
			if (Integer.parseInt(record.get(0)) == 0) {
1405
			if (Integer.parseInt(record.get(0)) == 0) {
Line 1443... Line 1452...
1443
 
1452
 
1444
	}
1453
	}
1445
 
1454
 
1446
	@RequestMapping(value = "/extendCustomerOffer", method = RequestMethod.POST)
1455
	@RequestMapping(value = "/extendCustomerOffer", method = RequestMethod.POST)
1447
	public String extendCustomerOffer(HttpServletRequest request, @RequestParam int id,
1456
	public String extendCustomerOffer(HttpServletRequest request, @RequestParam int id,
1448
									  @RequestParam LocalDateTime endDate, Model model) throws ProfitMandiBusinessException {
1457
			@RequestParam LocalDateTime endDate, Model model) throws ProfitMandiBusinessException {
1449
 
1458
 
1450
		CustomerOffer co = customerOfferRepository.selectById(id);
1459
		CustomerOffer co = customerOfferRepository.selectById(id);
1451
		co.setEndDate(endDate);
1460
		co.setEndDate(endDate);
1452
		co.setUpdatedTimestamp(LocalDateTime.now());
1461
		co.setUpdatedTimestamp(LocalDateTime.now());
1453
 
1462