| Line 595... |
Line 595... |
| 595 |
@RequestParam(name = "offset", required = false, defaultValue = "0") int offset,
|
595 |
@RequestParam(name = "offset", required = false, defaultValue = "0") int offset,
|
| 596 |
@RequestParam(name = "limit", required = false, defaultValue = "30") int limit, Model model)
|
596 |
@RequestParam(name = "limit", required = false, defaultValue = "30") int limit, Model model)
|
| 597 |
throws Exception {
|
597 |
throws Exception {
|
| 598 |
|
598 |
|
| 599 |
UserWallet userWallet = userWalletRepository.selectByRetailerId(fofoId);
|
599 |
UserWallet userWallet = userWalletRepository.selectByRetailerId(fofoId);
|
| 600 |
List<UserWalletHistory> userWalletHistory = userWalletHistoryRepository
|
600 |
List<UserWalletHistory> userWalletHistory = userWalletHistoryRepository.selectPaginatedByWalletIdReferenceType(
|
| 601 |
.selectPaginatedByWalletIdReferenceType(userWallet.getId(), referenceType, SortOrder.DESCENDING, offset, limit);
|
601 |
userWallet.getId(), referenceType, SortOrder.DESCENDING, offset, limit);
|
| 602 |
|
602 |
|
| 603 |
CustomRetailer customretailer = retailerService.getFofoRetailer(fofoId);
|
603 |
CustomRetailer customretailer = retailerService.getFofoRetailer(fofoId);
|
| 604 |
|
604 |
|
| 605 |
model.addAttribute("userWallet", userWallet);
|
605 |
model.addAttribute("userWallet", userWallet);
|
| 606 |
model.addAttribute("customretailer", customretailer);
|
606 |
model.addAttribute("customretailer", customretailer);
|
| Line 633... |
Line 633... |
| 633 |
|
633 |
|
| 634 |
@RequestMapping(value = "/walletUpdate", method = RequestMethod.POST)
|
634 |
@RequestMapping(value = "/walletUpdate", method = RequestMethod.POST)
|
| 635 |
public String walletUpdate(HttpServletRequest request,
|
635 |
public String walletUpdate(HttpServletRequest request,
|
| 636 |
@RequestParam(name = "reference", defaultValue = "0") int reference,
|
636 |
@RequestParam(name = "reference", defaultValue = "0") int reference,
|
| 637 |
@RequestParam WalletReferenceType referenceType, @RequestParam TransactionType transactiontype,
|
637 |
@RequestParam WalletReferenceType referenceType, @RequestParam TransactionType transactiontype,
|
| 638 |
@RequestParam int amount, @RequestParam String description, @RequestParam int retailerId, Model model)
|
638 |
@RequestParam int amount, @RequestParam String description, @RequestParam int retailerId, Model model,
|
| - |
|
639 |
@RequestParam LocalDateTime businessTimestamp)
|
| 639 |
throws Exception {
|
640 |
throws Exception {
|
| 640 |
|
- |
|
| 641 |
List<UserWalletHistory> userWalletHistory = userWalletHistoryRepository
|
- |
|
| 642 |
.selectAllByreferenceIdandreferenceType(reference, referenceType);
|
- |
|
| 643 |
UserWallet userWallet = userWalletRepository.selectByRetailerId(retailerId);
|
- |
|
| 644 |
int walletAmount = walletService.getWalletAmount(retailerId);
|
- |
|
| 645 |
|
- |
|
| 646 |
if (!userWalletHistory.isEmpty()) {
|
- |
|
| 647 |
int WalletId = userWalletHistory.get(0).getWalletId();
|
- |
|
| 648 |
UserWallet user = userWalletRepository.selectById(WalletId);
|
- |
|
| 649 |
if (retailerId != user.getUserId()) {
|
- |
|
| 650 |
throw new ProfitMandiBusinessException("RefrenceId", reference,
|
- |
|
| 651 |
"Reference Id assign to Other partner");
|
- |
|
| 652 |
}
|
- |
|
| 653 |
UserWalletHistory history = new UserWalletHistory();
|
- |
|
| 654 |
if (TransactionType.CREDIT.equals(transactiontype)) {
|
- |
|
| 655 |
userWallet.setAmount(walletAmount + amount);
|
- |
|
| 656 |
history.setAmount(amount);
|
- |
|
| 657 |
history.setDescription(description);
|
- |
|
| 658 |
history.setReference(reference);
|
- |
|
| 659 |
history.setWalletId(userWallet.getId());
|
- |
|
| 660 |
history.setReferenceType(referenceType);
|
- |
|
| 661 |
history.setTimestamp(LocalDateTime.now());
|
- |
|
| 662 |
|
- |
|
| 663 |
} else if (TransactionType.DEBIT.equals(transactiontype)) {
|
- |
|
| 664 |
userWallet.setAmount(walletAmount - amount);
|
- |
|
| 665 |
history.setAmount(-amount);
|
- |
|
| 666 |
history.setDescription(description);
|
- |
|
| 667 |
history.setWalletId(userWallet.getId());
|
- |
|
| 668 |
history.setReference(reference);
|
- |
|
| 669 |
history.setReferenceType(referenceType);
|
- |
|
| 670 |
history.setTimestamp(LocalDateTime.now());
|
- |
|
| 671 |
|
- |
|
| 672 |
}
|
- |
|
| 673 |
userWalletHistoryRepository.persist(history);
|
- |
|
| 674 |
model.addAttribute("response", mvcResponseSender.createResponseString(history.getReference()));
|
- |
|
| 675 |
} else if (referenceType.getValue()>= WalletReferenceType.INCENTIVES.getValue()) {
|
641 |
if (reference==0 && referenceType.getValue()>= WalletReferenceType.INCENTIVES.getValue()) {
|
| 676 |
LOGGER.error("referenceType: " + referenceType);
|
642 |
LOGGER.error("referenceType: " + referenceType);
|
| 677 |
ManualPaymentType paymentType = manualPaymentRequestRepository.selectByReferenceType(referenceType);
|
643 |
ManualPaymentType paymentType = manualPaymentRequestRepository.selectByReferenceType(referenceType);
|
| 678 |
|
644 |
|
| 679 |
if (paymentType == null) {
|
645 |
if (paymentType == null) {
|
| 680 |
paymentType = new ManualPaymentType();
|
646 |
paymentType = new ManualPaymentType();
|
| 681 |
}
|
647 |
}
|
| 682 |
|
- |
|
| 683 |
paymentType.setReferenceType(referenceType);
|
648 |
paymentType.setReferenceType(referenceType);
|
| 684 |
try {
|
- |
|
| 685 |
paymentType.setCounter(paymentType.getCounter() + 1);
|
649 |
paymentType.setCounter(paymentType.getCounter() + 1);
|
| 686 |
} catch (Exception e) {
|
- |
|
| 687 |
paymentType.setCounter(1);
|
- |
|
| 688 |
}
|
- |
|
| 689 |
manualPaymentRequestRepository.persist(paymentType);
|
650 |
manualPaymentRequestRepository.persist(paymentType);
|
| - |
|
651 |
reference = paymentType.getCounter();
|
| - |
|
652 |
|
| - |
|
653 |
} else if(reference==0){
|
| - |
|
654 |
throw new ProfitMandiBusinessException("RefrenceId", reference,
|
| - |
|
655 |
"System specific reference type cant be used manually");
|
| - |
|
656 |
}
|
| - |
|
657 |
|
| - |
|
658 |
List<UserWalletHistory> userWalletHistoryList = userWalletHistoryRepository
|
| - |
|
659 |
.selectAllByreferenceIdandreferenceType(reference, referenceType);
|
| - |
|
660 |
UserWallet userWallet = userWalletRepository.selectByRetailerId(retailerId);
|
| - |
|
661 |
int walletId = userWallet.getId();
|
| - |
|
662 |
int walletAmount = walletService.getWalletAmount(retailerId);
|
| 690 |
|
663 |
|
| 691 |
UserWalletHistory history = new UserWalletHistory();
|
- |
|
| 692 |
|
- |
|
| 693 |
if (TransactionType.CREDIT.equals(transactiontype)) {
|
- |
|
| 694 |
userWallet.setAmount(userWallet.getAmount() + amount);
|
- |
|
| 695 |
history.setAmount(amount);
|
- |
|
| 696 |
history.setDescription(description);
|
- |
|
| 697 |
history.setReference(paymentType.getCounter());
|
- |
|
| 698 |
history.setWalletId(userWallet.getId());
|
- |
|
| 699 |
history.setReferenceType(referenceType);
|
664 |
int returnReference = 0;
|
| 700 |
history.setTimestamp(LocalDateTime.now());
|
- |
|
| 701 |
|
- |
|
| 702 |
} else if (TransactionType.DEBIT.equals(transactiontype)) {
|
- |
|
| 703 |
userWallet.setAmount(userWallet.getAmount() - amount);
|
665 |
UserWalletHistory newUserWalletHistory = new UserWalletHistory();
|
| 704 |
history.setAmount(-amount);
|
- |
|
| 705 |
history.setDescription(description);
|
- |
|
| 706 |
history.setWalletId(userWallet.getId());
|
- |
|
| 707 |
history.setReference(paymentType.getCounter());
|
- |
|
| 708 |
history.setReferenceType(referenceType);
|
- |
|
| 709 |
history.setTimestamp(LocalDateTime.now());
|
- |
|
| 710 |
|
666 |
|
| - |
|
667 |
if (!userWalletHistoryList.isEmpty()) {
|
| - |
|
668 |
long validRetailerEntries = userWalletHistoryList.stream()
|
| - |
|
669 |
.filter(x-> x.getWalletId() == walletId)
|
| - |
|
670 |
.count();
|
| - |
|
671 |
if(validRetailerEntries == 0) {
|
| - |
|
672 |
throw new ProfitMandiBusinessException("RefrenceId", reference,
|
| - |
|
673 |
"Reference Id assign to Other partner");
|
| 711 |
}
|
674 |
}
|
| 712 |
userWalletHistoryRepository.persist(history);
|
- |
|
| 713 |
model.addAttribute("response", mvcResponseSender.createResponseString(history.getReference()));
|
- |
|
| 714 |
} else {
|
- |
|
| 715 |
model.addAttribute("response", mvcResponseSender.createResponseString(0));
|
- |
|
| 716 |
}
|
675 |
}
|
| - |
|
676 |
|
| - |
|
677 |
if (TransactionType.DEBIT.equals(transactiontype)) {
|
| - |
|
678 |
amount = -amount;
|
| - |
|
679 |
}
|
| - |
|
680 |
|
| - |
|
681 |
userWallet.setAmount(walletAmount + amount);
|
| - |
|
682 |
newUserWalletHistory.setAmount(amount);
|
| - |
|
683 |
newUserWalletHistory.setBusinessTimestamp(businessTimestamp);
|
| - |
|
684 |
newUserWalletHistory.setDescription(description);
|
| - |
|
685 |
newUserWalletHistory.setReference(reference);
|
| - |
|
686 |
newUserWalletHistory.setWalletId(userWallet.getId());
|
| - |
|
687 |
newUserWalletHistory.setReferenceType(referenceType);
|
| - |
|
688 |
newUserWalletHistory.setTimestamp(LocalDateTime.now());
|
| - |
|
689 |
userWalletHistoryRepository.persist(newUserWalletHistory);
|
| - |
|
690 |
|
| - |
|
691 |
model.addAttribute("response", mvcResponseSender.createResponseString(returnReference));
|
| 717 |
return "response";
|
692 |
return "response";
|
| 718 |
|
693 |
|
| 719 |
}
|
694 |
}
|
| 720 |
|
695 |
|
| 721 |
@RequestMapping(value = "/addMoney", method = RequestMethod.POST)
|
696 |
@RequestMapping(value = "/addMoney", method = RequestMethod.POST)
|