Subversion Repositories SmartDukaan

Rev

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

Rev 30699 Rev 30768
Line 26... Line 26...
26
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
26
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
27
import com.spice.profitmandi.dao.repository.dtr.Mongo;
27
import com.spice.profitmandi.dao.repository.dtr.Mongo;
28
import com.spice.profitmandi.dao.repository.fofo.*;
28
import com.spice.profitmandi.dao.repository.fofo.*;
29
import com.spice.profitmandi.dao.repository.transaction.PriceDropIMEIRepository;
29
import com.spice.profitmandi.dao.repository.transaction.PriceDropIMEIRepository;
30
import com.spice.profitmandi.dao.repository.transaction.PriceDropRepository;
30
import com.spice.profitmandi.dao.repository.transaction.PriceDropRepository;
-
 
31
import com.spice.profitmandi.dao.repository.transaction.TransactionRepository;
31
import com.spice.profitmandi.service.authentication.RoleManager;
32
import com.spice.profitmandi.service.authentication.RoleManager;
32
import com.spice.profitmandi.service.inventory.InventoryService;
33
import com.spice.profitmandi.service.inventory.InventoryService;
33
import com.spice.profitmandi.service.offers.OfferService;
34
import com.spice.profitmandi.service.offers.OfferService;
34
import com.spice.profitmandi.service.scheme.SchemeService;
35
import com.spice.profitmandi.service.scheme.SchemeService;
35
import com.spice.profitmandi.service.user.RetailerService;
36
import com.spice.profitmandi.service.user.RetailerService;
Line 240... Line 241...
240
			throw new ProfitMandiBusinessException("User", loginDetails.getEmailId(), "Unauthorised access");
241
			throw new ProfitMandiBusinessException("User", loginDetails.getEmailId(), "Unauthorised access");
241
		}
242
		}
242
		return "update-schemes-page";
243
		return "update-schemes-page";
243
	}
244
	}
244
 
245
 
-
 
246
	@Autowired
-
 
247
	TransactionRepository transactionRepository;
-
 
248
 
245
	@RequestMapping(value = "/payMonthlyInvestment", method = RequestMethod.POST)
249
	@RequestMapping(value = "/payMonthlyInvestment", method = RequestMethod.POST)
246
	public void payMonthlyInvestment(HttpServletRequest request, Model model) throws ProfitMandiBusinessException {
250
	public void payMonthlyInvestment(HttpServletRequest request, Model model) throws ProfitMandiBusinessException {
247
 
251
 
248
		LocalDate firstDateOfCurrentMonth = LocalDateTime.now().withDayOfMonth(1).toLocalDate();
252
		LocalDate firstDateOfCurrentMonth = LocalDateTime.now().withDayOfMonth(1).toLocalDate();
249
		LocalDate startOfPreviousMonth = firstDateOfCurrentMonth.minusMonths(1);
253
		LocalDate startOfPreviousMonth = firstDateOfCurrentMonth.minusMonths(1);
Line 272... Line 276...
272
			int fofoId = retailerEntry.getKey();
276
			int fofoId = retailerEntry.getKey();
273
			long investmentMaintainedDays = investmentMaintainedDaysMap.get(fofoId) == null ? 0
277
			long investmentMaintainedDays = investmentMaintainedDaysMap.get(fofoId) == null ? 0
274
					: investmentMaintainedDaysMap.get(fofoId);
278
					: investmentMaintainedDaysMap.get(fofoId);
275
 
279
 
276
			List<SchemeInOut> schemeInouts = retailerEntry.getValue().stream().map(x -> inventoryItemIdSchemeMap.get(x))
280
			List<SchemeInOut> schemeInouts = retailerEntry.getValue().stream().map(x -> inventoryItemIdSchemeMap.get(x))
277
					.flatMap(List::stream).filter(x -> x.getRolledBackTimestamp() == null).collect(Collectors.toList());
281
					.flatMap(List::stream).filter(x -> x.getStatus().equals(SchemePayoutStatus.PENDING) && x.getRolledBackTimestamp() == null).collect(Collectors.toList());
278
			float totalAmount = 0;
282
			float totalAmount = 0;
-
 
283
			LocalDateTime firstBillingDate = transactionRepository.getFirstBillingDate(fofoId);
-
 
284
			boolean sameYearMonth = firstBillingDate.getMonth() == startOfPreviousMonth.getMonth() && firstBillingDate.getYear() == startOfPreviousMonth.getYear();
279
			for (SchemeInOut sio : schemeInouts) {
285
			for (SchemeInOut sio : schemeInouts) {
280
 
-
 
281
				if (investmentMaintainedDays < 8) {
286
				if (sameYearMonth) {
282
					sio.setStatus(SchemePayoutStatus.REJECTED);
-
 
283
					// sio.setRolledBackTimestamp(LocalDateTime.now());
-
 
284
					sio.setStatusDescription("Investment maintained for " + investmentMaintainedDays + "(< 8) days");
287
					sio.setStatusDescription("Investment payout fully disbursed for first month");
285
				} else if (investmentMaintainedDays < 12) {
-
 
286
					sio.setStatus(SchemePayoutStatus.CREDITED);
288
					sio.setStatus(SchemePayoutStatus.CREDITED);
287
					sio.setAmount(sio.getAmount() / 2);
-
 
288
					sio.setCreditTimestamp(LocalDateTime.now());
289
					sio.setCreditTimestamp(LocalDateTime.now());
289
					sio.setStatusDescription("Investment maintained for " + investmentMaintainedDays + "(< 12) days");
-
 
290
					totalAmount += sio.getAmount();
290
					totalAmount += sio.getAmount();
291
				} else {
291
				} else {
-
 
292
					if (investmentMaintainedDays < 8) {
-
 
293
						sio.setStatus(SchemePayoutStatus.REJECTED);
-
 
294
						//sio.setRolledBackTimestamp(LocalDateTime.now());
-
 
295
						sio.setStatusDescription("Investment maintained for " + investmentMaintainedDays + "(< 8) days");
-
 
296
					} else if (investmentMaintainedDays < 12) {
292
					sio.setStatus(SchemePayoutStatus.CREDITED);
297
						sio.setStatus(SchemePayoutStatus.CREDITED);
-
 
298
						sio.setAmount(sio.getAmount() / 2);
-
 
299
						sio.setCreditTimestamp(LocalDateTime.now());
-
 
300
						sio.setStatusDescription("Investment maintained for " + investmentMaintainedDays + "(< 12) days");
-
 
301
						totalAmount += sio.getAmount();
-
 
302
					} else {
-
 
303
						sio.setStatus(SchemePayoutStatus.CREDITED);
293
					sio.setCreditTimestamp(LocalDateTime.now());
304
						sio.setCreditTimestamp(LocalDateTime.now());
294
					totalAmount += sio.getAmount();
305
						totalAmount += sio.getAmount();
-
 
306
					}
295
				}
307
				}
296
			}
308
			}
297
			if (totalAmount > 0) {
309
			if (totalAmount > 0) {
298
				String description = "Investment margin paid for "
310
				String description = "Investment margin paid for "
299
						+ FormattingUtils.formatYearMonth(startOfPreviousMonth.atStartOfDay());
311
						+ FormattingUtils.formatYearMonth(startOfPreviousMonth.atStartOfDay());
Line 301... Line 313...
301
					description += ", as maintained for " + investmentMaintainedDays + "(< 12) days";
313
					description += ", as maintained for " + investmentMaintainedDays + "(< 12) days";
302
				}
314
				}
303
				walletService.addAmountToWallet(fofoId, referenceId, WalletReferenceType.INVESTMENT_PAYOUT, description,
315
				walletService.addAmountToWallet(fofoId, referenceId, WalletReferenceType.INVESTMENT_PAYOUT, description,
304
						totalAmount, lastOfPreviousMonth.atTime(LocalTime.MAX));
316
						totalAmount, lastOfPreviousMonth.atTime(LocalTime.MAX));
305
			}
317
			}
-
 
318
			//Its ok to process Margins Pending for activation
-
 
319
			schemeService.processActivation();
306
			System.out.printf("%d\t%d\t%f%n", fofoId, investmentMaintainedDays, totalAmount);
320
			System.out.printf("%d\t%d\t%f%n", fofoId, investmentMaintainedDays, totalAmount);
307
		}
321
		}
308
 
322
 
-
 
323
 
309
	}
324
	}
310
 
325
 
311
	@RequestMapping(value = "/evaluateActualInvestmentPayout", method = RequestMethod.GET)
326
	@RequestMapping(value = "/evaluateActualInvestmentPayout", method = RequestMethod.GET)
312
	public ResponseEntity<?> evaluateActualInvestmentPayout(HttpServletRequest request, Model model) throws Exception {
327
	public ResponseEntity<?> evaluateActualInvestmentPayout(HttpServletRequest request, Model model) throws Exception {
313
 
328