Subversion Repositories SmartDukaan

Rev

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

Rev 29658 Rev 29662
Line 275... Line 275...
275
		}
275
		}
276
 
276
 
277
	}
277
	}
278
 
278
 
279
	@RequestMapping(value = "/evaluateActualInvestmentPayout", method = RequestMethod.GET)
279
	@RequestMapping(value = "/evaluateActualInvestmentPayout", method = RequestMethod.GET)
280
	public ResponseEntity<?> evaluateActualInvestmentPayout(HttpServletRequest request, Model model) throws Exception {
280
	   public ResponseEntity<?> evaluateActualInvestmentPayout(HttpServletRequest request,Model model) throws Exception {
281
 
281
			
282
		List<List<?>> rows = new ArrayList<>();
282
			List<List<?>> rows = new ArrayList<>();
283
		LocalDate firstDateOfCurrentMonth = LocalDateTime.now().withDayOfMonth(1).toLocalDate();
283
			LocalDate firstDateOfCurrentMonth = LocalDateTime.now().withDayOfMonth(1).toLocalDate();
284
		LocalDate startOfPreviousMonth = firstDateOfCurrentMonth.minusMonths(1);
284
			LocalDate startOfPreviousMonth = firstDateOfCurrentMonth.minusMonths(1);
285
		LocalDate lastOfPreviousMonth = firstDateOfCurrentMonth.minusDays(1);
285
			LocalDate lastOfPreviousMonth = firstDateOfCurrentMonth.minusDays(1);
286
		List<PartnerDailyInvestment> partnerDailyInvestments = partnerDailyInvestmentRepository
286
			List<PartnerDailyInvestment> partnerDailyInvestments = partnerDailyInvestmentRepository
287
				.selectAll(startOfPreviousMonth, lastOfPreviousMonth);
287
					.selectAll(firstDateOfCurrentMonth.atStartOfDay().toLocalDate(), LocalDateTime.now().minusDays(1).toLocalDate());
-
 
288
			
288
		Map<Integer, Long> investmentMaintainedDaysMap = partnerDailyInvestments.stream()
289
			Map<Integer, Long> investmentMaintainedDaysMap = partnerDailyInvestments.stream()
289
				.filter(x -> x.getShortPercentage() <= 10)
290
					.filter(x -> x.getShortPercentage() <= 10)
290
				.collect(Collectors.groupingBy(x -> x.getFofoId(), Collectors.counting()));
291
					.collect(Collectors.groupingBy(x -> x.getFofoId(), Collectors.counting()));
291
		LOGGER.info("investmentMaintainedDaysMap {}", investmentMaintainedDaysMap);
292
			LOGGER.info("investmentMaintainedDaysMap {}", investmentMaintainedDaysMap);
-
 
293
		
292
		List<SchemeInOut> schemeInOuts = schemeInOutRepository.selectAllPending(SchemeType.INVESTMENT,
294
			List<SchemeInOut> schemeInOuts = schemeInOutRepository.selectAllPending(SchemeType.INVESTMENT,
293
				startOfPreviousMonth.atStartOfDay(), firstDateOfCurrentMonth.atStartOfDay());
295
					firstDateOfCurrentMonth.atStartOfDay(),LocalDateTime.now().minusDays(1) );
-
 
296
			
294
		Map<Integer, List<SchemeInOut>> inventoryItemIdSchemeMap = schemeInOuts.stream()
297
			Map<Integer, List<SchemeInOut>> inventoryItemIdSchemeMap = schemeInOuts.stream()
295
				.collect(Collectors.groupingBy(x -> x.getInventoryItemId()));
298
					.collect(Collectors.groupingBy(x -> x.getInventoryItemId()));
296
		List<InventoryItem> inventoryItems = inventoryItemRepository.selectByIds(inventoryItemIdSchemeMap.keySet());
299
			List<InventoryItem> inventoryItems = inventoryItemRepository.selectByIds(inventoryItemIdSchemeMap.keySet());
297
		Map<Integer, List<Integer>> retailerInventoryItemIdMap = inventoryItems.stream().collect(
300
			Map<Integer, List<Integer>> retailerInventoryItemIdMap = inventoryItems.stream().collect(
298
				Collectors.groupingBy(x -> x.getFofoId(), Collectors.mapping(x -> x.getId(), Collectors.toList())));
301
					Collectors.groupingBy(x -> x.getFofoId(), Collectors.mapping(x -> x.getId(), Collectors.toList())));
299
		System.out.println("Fofo Id\tInvestment Maintained Days\tEligible payout");
302
			System.out.println("Fofo Id\tInvestment Maintained Days\tEligible payout");
300
		for (Map.Entry<Integer, List<Integer>> retailerEntry : retailerInventoryItemIdMap.entrySet()) {
303
			for (Map.Entry<Integer, List<Integer>> retailerEntry : retailerInventoryItemIdMap.entrySet()) {
301
			int fofoId = retailerEntry.getKey();
304
				int fofoId = retailerEntry.getKey();
302
			List<SchemeInOut> schemeInouts = retailerEntry.getValue().stream().map(x -> inventoryItemIdSchemeMap.get(x))
305
				List<SchemeInOut> schemeInouts = retailerEntry.getValue().stream().map(x -> inventoryItemIdSchemeMap.get(x))
303
					.flatMap(List::stream).collect(Collectors.toList());
306
						.flatMap(List::stream).collect(Collectors.toList());
304
			double totalAmount = schemeInouts.stream().filter(x -> x.getRolledBackTimestamp() == null)
307
				double totalAmount = schemeInouts.stream().filter(x -> x.getRolledBackTimestamp() == null)
305
					.collect(Collectors.summingDouble(x -> x.getAmount()));
308
						.collect(Collectors.summingDouble(x -> x.getAmount()));
306
			long investmentMaintainedDays = investmentMaintainedDaysMap.get(fofoId) == null ? 0
309
				long investmentMaintainedDays = investmentMaintainedDaysMap.get(fofoId) == null ? 0
307
					: investmentMaintainedDaysMap.get(fofoId);
310
						: investmentMaintainedDaysMap.get(fofoId);
308
			if (investmentMaintainedDays < 8) {
311
				if (investmentMaintainedDays < 8) {
309
				totalAmount = 0;
312
					totalAmount = 0;
310
			} else if (investmentMaintainedDays < 12) {
313
				} else if (investmentMaintainedDays < 12) {
311
				totalAmount = totalAmount / 2;
314
					totalAmount = totalAmount / 2;
-
 
315
				}
-
 
316
				System.out.printf("%d\t%d\t%f%n", fofoId, investmentMaintainedDays, totalAmount);
-
 
317
				CustomRetailer customRetailer= retailerService.getFofoRetailer(fofoId);
-
 
318
				
-
 
319
				 rows.add(Arrays.asList(fofoId,customRetailer.getBusinessName(),customRetailer.getCode(),investmentMaintainedDays,totalAmount));
312
			}
320
			}
-
 
321
		
-
 
322
			
-
 
323
					org.apache.commons.io.output.ByteArrayOutputStream baos = FileUtil
313
			System.out.printf("%d\t%d\t%f%n", fofoId, investmentMaintainedDays, totalAmount);
324
					.getCSVByteStream(Arrays.asList("fofoId","Name", "Code", "investmentMaintainedDays","totalAmount"), rows);
-
 
325
 
-
 
326
			final HttpHeaders headers = new HttpHeaders();
-
 
327
			headers.set("Content-Type", "text/csv");
314
			CustomRetailer customRetailer = retailerService.getFofoRetailer(fofoId);
328
			headers.set("Content-disposition", "inline; filename=investmentMaintainedDays.csv");
-
 
329
			headers.setContentLength(baos.toByteArray().length);
315
 
330
 
316
			rows.add(Arrays.asList(fofoId, customRetailer.getBusinessName(), customRetailer.getCode(),
331
			final InputStream inputStream = new ByteArrayInputStream(baos.toByteArray());
317
					investmentMaintainedDays, totalAmount));
332
			final InputStreamResource inputStreamResource = new InputStreamResource(inputStream);
-
 
333
		
-
 
334
			return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
-
 
335
			
318
		}
336
		}
319
 
337
 
320
		org.apache.commons.io.output.ByteArrayOutputStream baos = FileUtil.getCSVByteStream(
-
 
321
				Arrays.asList("fofoId", "Name", "Code", "investmentMaintainedDays", "totalAmount"), rows);
-
 
322
 
-
 
323
		final HttpHeaders headers = new HttpHeaders();
-
 
324
		headers.set("Content-Type", "text/csv");
-
 
325
		headers.set("Content-disposition", "inline; filename=investmentMaintainedDays.csv");
-
 
326
		headers.setContentLength(baos.toByteArray().length);
-
 
327
 
-
 
328
		final InputStream inputStream = new ByteArrayInputStream(baos.toByteArray());
-
 
329
		final InputStreamResource inputStreamResource = new InputStreamResource(inputStream);
-
 
330
 
-
 
331
		return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
-
 
332
 
-
 
333
	}
-
 
334
 
-
 
335
	@RequestMapping(value = "/processInvestmentDryRun", method = RequestMethod.GET)
338
	@RequestMapping(value = "/processInvestmentDryRun", method = RequestMethod.GET)
336
	public ResponseEntity<?> processInvestmentDryRun(HttpServletRequest request, Model model) throws Exception {
339
	public ResponseEntity<?> processInvestmentDryRun(HttpServletRequest request, Model model) throws Exception {
337
 
340
 
338
		LocalDate firstDateOfCurrentMonth = LocalDateTime.now().withDayOfMonth(1).toLocalDate();
341
		LocalDate firstDateOfCurrentMonth = LocalDateTime.now().withDayOfMonth(1).toLocalDate();
339
		LocalDate startOfPreviousMonth = firstDateOfCurrentMonth.minusMonths(1);
342
		LocalDate startOfPreviousMonth = firstDateOfCurrentMonth.minusMonths(1);