| Line 7... |
Line 7... |
| 7 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
7 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 8 |
import com.spice.profitmandi.common.model.UnsettledPaymentModel;
|
8 |
import com.spice.profitmandi.common.model.UnsettledPaymentModel;
|
| 9 |
import com.spice.profitmandi.common.util.*;
|
9 |
import com.spice.profitmandi.common.util.*;
|
| 10 |
import com.spice.profitmandi.dao.entity.dtr.CreditAccount;
|
10 |
import com.spice.profitmandi.dao.entity.dtr.CreditAccount;
|
| 11 |
import com.spice.profitmandi.dao.entity.transaction.*;
|
11 |
import com.spice.profitmandi.dao.entity.transaction.*;
|
| - |
|
12 |
import com.spice.profitmandi.dao.entity.user.FullStockPayment;
|
| 12 |
import com.spice.profitmandi.dao.enumuration.fofo.Gateway;
|
13 |
import com.spice.profitmandi.dao.enumuration.fofo.Gateway;
|
| - |
|
14 |
import com.spice.profitmandi.dao.enumuration.onBorading.onBoardingFormEnums.FullStockPaymentStatus;
|
| 13 |
import com.spice.profitmandi.dao.enumuration.transaction.AddWalletRequestStatus;
|
15 |
import com.spice.profitmandi.dao.enumuration.transaction.AddWalletRequestStatus;
|
| 14 |
import com.spice.profitmandi.dao.enumuration.transaction.TransactionType;
|
16 |
import com.spice.profitmandi.dao.enumuration.transaction.TransactionType;
|
| 15 |
import com.spice.profitmandi.dao.model.DateRangeModel;
|
17 |
import com.spice.profitmandi.dao.model.DateRangeModel;
|
| 16 |
import com.spice.profitmandi.dao.model.StoreTimelineModel;
|
18 |
import com.spice.profitmandi.dao.model.StoreTimelineModel;
|
| 17 |
import com.spice.profitmandi.dao.repository.catalog.AddWalletRequestRepository;
|
19 |
import com.spice.profitmandi.dao.repository.catalog.AddWalletRequestRepository;
|
| Line 20... |
Line 22... |
| 20 |
import com.spice.profitmandi.dao.repository.dtr.CreditAccountRepository;
|
22 |
import com.spice.profitmandi.dao.repository.dtr.CreditAccountRepository;
|
| 21 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
23 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
| 22 |
import com.spice.profitmandi.dao.repository.dtr.PartnerOnBoardingPanelRepository;
|
24 |
import com.spice.profitmandi.dao.repository.dtr.PartnerOnBoardingPanelRepository;
|
| 23 |
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
|
25 |
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
|
| 24 |
import com.spice.profitmandi.dao.repository.transaction.*;
|
26 |
import com.spice.profitmandi.dao.repository.transaction.*;
|
| - |
|
27 |
import com.spice.profitmandi.dao.repository.user.FullStockPaymentRepository;
|
| 25 |
import com.spice.profitmandi.dao.repository.user.LoiFormRepository;
|
28 |
import com.spice.profitmandi.dao.repository.user.LoiFormRepository;
|
| 26 |
import com.spice.profitmandi.dao.service.SidbiService;
|
29 |
import com.spice.profitmandi.dao.service.SidbiService;
|
| 27 |
import com.spice.profitmandi.service.NotificationService;
|
30 |
import com.spice.profitmandi.service.NotificationService;
|
| 28 |
import com.spice.profitmandi.service.authentication.RoleManager;
|
31 |
import com.spice.profitmandi.service.authentication.RoleManager;
|
| 29 |
import com.spice.profitmandi.service.transaction.TransactionService;
|
32 |
import com.spice.profitmandi.service.transaction.TransactionService;
|
| Line 47... |
Line 50... |
| 47 |
import org.springframework.http.HttpStatus;
|
50 |
import org.springframework.http.HttpStatus;
|
| 48 |
import org.springframework.http.ResponseEntity;
|
51 |
import org.springframework.http.ResponseEntity;
|
| 49 |
import org.springframework.mail.javamail.JavaMailSender;
|
52 |
import org.springframework.mail.javamail.JavaMailSender;
|
| 50 |
import org.springframework.mail.javamail.MimeMessageHelper;
|
53 |
import org.springframework.mail.javamail.MimeMessageHelper;
|
| 51 |
import org.springframework.stereotype.Controller;
|
54 |
import org.springframework.stereotype.Controller;
|
| - |
|
55 |
import org.springframework.transaction.annotation.Transactional;
|
| 52 |
import org.springframework.ui.Model;
|
56 |
import org.springframework.ui.Model;
|
| 53 |
import org.springframework.web.bind.annotation.*;
|
57 |
import org.springframework.web.bind.annotation.*;
|
| 54 |
import org.springframework.web.multipart.MultipartFile;
|
58 |
import org.springframework.web.multipart.MultipartFile;
|
| 55 |
|
59 |
|
| 56 |
import javax.mail.internet.InternetAddress;
|
60 |
import javax.mail.internet.InternetAddress;
|
| 57 |
import javax.mail.internet.MimeMessage;
|
61 |
import javax.mail.internet.MimeMessage;
|
| 58 |
import javax.servlet.http.HttpServletRequest;
|
62 |
import javax.servlet.http.HttpServletRequest;
|
| 59 |
import javax.swing.*;
|
63 |
import javax.swing.*;
|
| 60 |
import org.springframework.transaction.annotation.Transactional;
|
- |
|
| 61 |
import java.io.ByteArrayInputStream;
|
64 |
import java.io.ByteArrayInputStream;
|
| 62 |
import java.io.ByteArrayOutputStream;
|
65 |
import java.io.ByteArrayOutputStream;
|
| 63 |
import java.io.InputStream;
|
66 |
import java.io.InputStream;
|
| 64 |
import java.math.BigDecimal;
|
67 |
import java.math.BigDecimal;
|
| 65 |
import java.text.MessageFormat;
|
68 |
import java.text.MessageFormat;
|
| Line 163... |
Line 166... |
| 163 |
@Autowired
|
166 |
@Autowired
|
| 164 |
PartnerOnBoardingPanelRepository partnerOnBoardingPanelRepository;
|
167 |
PartnerOnBoardingPanelRepository partnerOnBoardingPanelRepository;
|
| 165 |
@Autowired
|
168 |
@Autowired
|
| 166 |
StoreTimelineTatService storeTimelineTatService;
|
169 |
StoreTimelineTatService storeTimelineTatService;
|
| 167 |
|
170 |
|
| - |
|
171 |
@Autowired
|
| - |
|
172 |
FullStockPaymentRepository fullStockPaymentRepository;
|
| - |
|
173 |
@Autowired
|
| - |
|
174 |
com.spice.profitmandi.dao.repository.auth.AuthRepository authRepository;
|
| - |
|
175 |
@Autowired
|
| - |
|
176 |
com.spice.profitmandi.dao.repository.cs.PositionRepository positionRepository;
|
| - |
|
177 |
|
| 168 |
|
178 |
|
| 169 |
@PostMapping(value = "/wallet/upload")
|
179 |
@PostMapping(value = "/wallet/upload")
|
| 170 |
public String uploadWalletBulk(HttpServletRequest request, @RequestPart("file") MultipartFile file, Model model) throws Exception {
|
180 |
public String uploadWalletBulk(HttpServletRequest request, @RequestPart("file") MultipartFile file, Model model) throws Exception {
|
| 171 |
List<WalletHistoryModel> walletHistoryModelList = ExcelUtils.parseWalletBulkCredit(file.getInputStream());
|
181 |
List<WalletHistoryModel> walletHistoryModelList = ExcelUtils.parseWalletBulkCredit(file.getInputStream());
|
| 172 |
for (WalletHistoryModel walletHistoryModel : walletHistoryModelList) {
|
182 |
for (WalletHistoryModel walletHistoryModel : walletHistoryModelList) {
|
| Line 470... |
Line 480... |
| 470 |
}
|
480 |
}
|
| 471 |
} else {
|
481 |
} else {
|
| 472 |
String rejectReason = "Entry already Approved Please reject";
|
482 |
String rejectReason = "Entry already Approved Please reject";
|
| 473 |
throw new ProfitMandiBusinessException(rejectReason, rejectReason, rejectReason);
|
483 |
throw new ProfitMandiBusinessException(rejectReason, rejectReason, rejectReason);
|
| 474 |
}
|
484 |
}
|
| - |
|
485 |
// FSP wallet addons can only be approved by Account team L3
|
| - |
|
486 |
if (addWalletRequest.getFspId() > 0) {
|
| - |
|
487 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| - |
|
488 |
String approverEmail = loginDetails.getEmailId();
|
| - |
|
489 |
com.spice.profitmandi.dao.entity.auth.AuthUser approverUser = authRepository.selectByEmailOrMobile(approverEmail);
|
| - |
|
490 |
boolean isAccountL3 = false;
|
| - |
|
491 |
if (approverUser != null) {
|
| - |
|
492 |
List<com.spice.profitmandi.dao.entity.cs.Position> positions = positionRepository.selectPositionByAuthId(approverUser.getId());
|
| - |
|
493 |
for (com.spice.profitmandi.dao.entity.cs.Position position : positions) {
|
| - |
|
494 |
if (position.getEscalationType().equals(com.spice.profitmandi.dao.enumuration.cs.EscalationType.L3)
|
| - |
|
495 |
&& position.getCategoryId() == ProfitMandiConstants.TICKET_CATEGORY_ACCOUNTS) {
|
| - |
|
496 |
isAccountL3 = true;
|
| - |
|
497 |
break;
|
| - |
|
498 |
}
|
| - |
|
499 |
}
|
| - |
|
500 |
}
|
| - |
|
501 |
if (!isAccountL3) {
|
| - |
|
502 |
throw new ProfitMandiBusinessException(
|
| - |
|
503 |
"Only Account team L3 can approve Full Stock Payment entries",
|
| - |
|
504 |
approverEmail,
|
| - |
|
505 |
"You are not authorized to approve FSP wallet requests");
|
| - |
|
506 |
}
|
| - |
|
507 |
}
|
| - |
|
508 |
|
| 475 |
if (addWalletRequest.getStatus().equals(AddWalletRequestStatus.pending)) {
|
509 |
if (addWalletRequest.getStatus().equals(AddWalletRequestStatus.pending)) {
|
| 476 |
walletService.addAmountToWallet(addWalletRequest.getRetailerId(), walletRequestid, WalletReferenceType.ADVANCE_AMOUNT, "ntfs/rgfs", addWalletRequest.getAmount(), addWalletRequest.getCreateTimestamp());
|
510 |
walletService.addAmountToWallet(addWalletRequest.getRetailerId(), walletRequestid, WalletReferenceType.ADVANCE_AMOUNT, "ntfs/rgfs", addWalletRequest.getAmount(), addWalletRequest.getCreateTimestamp());
|
| 477 |
addWalletRequest.setStatus(AddWalletRequestStatus.approved);
|
511 |
addWalletRequest.setStatus(AddWalletRequestStatus.approved);
|
| 478 |
addWalletRequest.setUpdateTimestamp(LocalDateTime.now());
|
512 |
addWalletRequest.setUpdateTimestamp(LocalDateTime.now());
|
| 479 |
unsettledPaymentsRepository.deleteById(id);
|
513 |
unsettledPaymentsRepository.deleteById(id);
|
| Line 484... |
Line 518... |
| 484 |
if (storeTimelineModel != null && storeTimelineModel.getFullStockTimestamp() == null) {
|
518 |
if (storeTimelineModel != null && storeTimelineModel.getFullStockTimestamp() == null) {
|
| 485 |
UserWallet userWallet = userWalletRepository.selectByRetailerId(addWalletRequest.getRetailerId());
|
519 |
UserWallet userWallet = userWalletRepository.selectByRetailerId(addWalletRequest.getRetailerId());
|
| 486 |
List<UserWalletHistory> userWalletHistories = userWalletHistoryRepository.selectByWalletIdAndReferenceType(userWallet.getId(), WalletReferenceType.ADVANCE_AMOUNT);
|
520 |
List<UserWalletHistory> userWalletHistories = userWalletHistoryRepository.selectByWalletIdAndReferenceType(userWallet.getId(), WalletReferenceType.ADVANCE_AMOUNT);
|
| 487 |
long totalAdvanceAmount = userWalletHistories.stream().mapToLong(x -> x.getAmount()).sum();
|
521 |
long totalAdvanceAmount = userWalletHistories.stream().mapToLong(x -> x.getAmount()).sum();
|
| 488 |
LOGGER.info("totalAdvanceAmount - " + totalAdvanceAmount);
|
522 |
LOGGER.info("totalAdvanceAmount - " + totalAdvanceAmount);
|
| 489 |
if (totalAdvanceAmount >= ProfitMandiConstants.MIN_FULL_STOCK_PAYMENT) {
|
523 |
if (totalAdvanceAmount >= ProfitMandiConstants.FSP_DIRECT_WALLET_THRESHOLD) {
|
| - |
|
524 |
storeTimelineTatService.onFullPaymentReceived(storeTimelineModel.getOnboardingId());
|
| - |
|
525 |
}
|
| - |
|
526 |
|
| - |
|
527 |
// Mark linked FullStockPayment record as APPROVED via fspId
|
| - |
|
528 |
if (addWalletRequest.getFspId() > 0) {
|
| - |
|
529 |
FullStockPayment fsp = fullStockPaymentRepository.selectById(addWalletRequest.getFspId());
|
| - |
|
530 |
if (fsp != null && fsp.getPaymentStatus() == FullStockPaymentStatus.PENDING) {
|
| - |
|
531 |
fsp.setPaymentStatus(FullStockPaymentStatus.APPROVED);
|
| - |
|
532 |
fsp.setApproveTimestamp(LocalDateTime.now());
|
| - |
|
533 |
fullStockPaymentRepository.persist(fsp);
|
| - |
|
534 |
LOGGER.info("Marked FSP id={} as APPROVED via wallet addon approval, onboardingId={}", fsp.getId(), storeTimelineModel.getOnboardingId());
|
| - |
|
535 |
}
|
| - |
|
536 |
}
|
| - |
|
537 |
|
| - |
|
538 |
// Auto-mark FULL_STOCK_PAYMENT in timeline when total approved FSP amount >= 7 lakh
|
| - |
|
539 |
double totalApprovedFsp = fullStockPaymentRepository.selectByOnboardingId(storeTimelineModel.getOnboardingId())
|
| - |
|
540 |
.stream()
|
| - |
|
541 |
.filter(p -> p.getPaymentStatus() == FullStockPaymentStatus.APPROVED)
|
| - |
|
542 |
.mapToDouble(FullStockPayment::getCollectedAmount)
|
| - |
|
543 |
.sum();
|
| - |
|
544 |
LOGGER.info("totalApprovedFsp={} for onboardingId={}", totalApprovedFsp, storeTimelineModel.getOnboardingId());
|
| - |
|
545 |
if (totalApprovedFsp >= ProfitMandiConstants.FSP_DIRECT_WALLET_THRESHOLD) {
|
| 490 |
storeTimelineTatService.onFullPaymentReceived(storeTimelineModel.getOnboardingId());
|
546 |
storeTimelineTatService.onFullPaymentReceived(storeTimelineModel.getOnboardingId());
|
| - |
|
547 |
LOGGER.info("Auto-marked FULL_STOCK_PAYMENT done for onboardingId={}, totalApprovedFsp={}", storeTimelineModel.getOnboardingId(), totalApprovedFsp);
|
| 491 |
}
|
548 |
}
|
| 492 |
}
|
549 |
}
|
| 493 |
|
550 |
|
| 494 |
model.addAttribute("response1", mvcResponseSender.createResponseString(true));
|
551 |
model.addAttribute("response1", mvcResponseSender.createResponseString(true));
|
| 495 |
CustomRetailer customRetailer = retailerService.getFofoRetailer(addWalletRequest.getRetailerId());
|
552 |
CustomRetailer customRetailer = retailerService.getFofoRetailer(addWalletRequest.getRetailerId());
|
| Line 510... |
Line 567... |
| 510 |
AddWalletRequest addWalletRequest = addWalletRequestRepository.selectById(id);
|
567 |
AddWalletRequest addWalletRequest = addWalletRequestRepository.selectById(id);
|
| 511 |
if (addWalletRequest.getStatus().equals(AddWalletRequestStatus.pending)) {
|
568 |
if (addWalletRequest.getStatus().equals(AddWalletRequestStatus.pending)) {
|
| 512 |
addWalletRequest.setStatus(AddWalletRequestStatus.rejected);
|
569 |
addWalletRequest.setStatus(AddWalletRequestStatus.rejected);
|
| 513 |
addWalletRequest.setUpdateTimestamp(LocalDateTime.now());
|
570 |
addWalletRequest.setUpdateTimestamp(LocalDateTime.now());
|
| 514 |
addWalletRequestRepository.persist(addWalletRequest);
|
571 |
addWalletRequestRepository.persist(addWalletRequest);
|
| - |
|
572 |
|
| - |
|
573 |
// Mark linked FSP as REJECTED via fspId
|
| - |
|
574 |
if (addWalletRequest.getFspId() > 0) {
|
| - |
|
575 |
try {
|
| - |
|
576 |
FullStockPayment fsp = fullStockPaymentRepository.selectById(addWalletRequest.getFspId());
|
| - |
|
577 |
if (fsp != null && fsp.getPaymentStatus() == FullStockPaymentStatus.PENDING) {
|
| - |
|
578 |
fsp.setPaymentStatus(FullStockPaymentStatus.REJECTED);
|
| - |
|
579 |
fsp.setDescription("Wallet addon request rejected");
|
| - |
|
580 |
fsp.setApproveTimestamp(LocalDateTime.now());
|
| - |
|
581 |
fullStockPaymentRepository.persist(fsp);
|
| - |
|
582 |
LOGGER.info("Marked FSP id={} as REJECTED via wallet addon rejection", fsp.getId());
|
| - |
|
583 |
}
|
| - |
|
584 |
} catch (Exception e) {
|
| - |
|
585 |
LOGGER.error("Error marking FSP as REJECTED on wallet addon rejection", e);
|
| - |
|
586 |
}
|
| - |
|
587 |
}
|
| - |
|
588 |
|
| 515 |
model.addAttribute("response1", mvcResponseSender.createResponseString(true));
|
589 |
model.addAttribute("response1", mvcResponseSender.createResponseString(true));
|
| 516 |
CustomRetailer customRetailer = retailerService.getFofoRetailer(addWalletRequest.getRetailerId());
|
590 |
CustomRetailer customRetailer = retailerService.getFofoRetailer(addWalletRequest.getRetailerId());
|
| 517 |
String subject = "Request Rejected for " + customRetailer.getBusinessName() + " of Rs." + addWalletRequest.getAmount();
|
591 |
String subject = "Request Rejected for " + customRetailer.getBusinessName() + " of Rs." + addWalletRequest.getAmount();
|
| 518 |
String messageText = MessageFormat.format("User Id - {0}\n Name -{1}\n Email -{2}\n mobile -{3}\n Reference - {4}\n Amount - Rs.{5}", new Integer(addWalletRequest.getRetailerId()), customRetailer.getBusinessName(), customRetailer.getEmail(), customRetailer.getMobileNumber(), addWalletRequest.getTransaction_reference(), new Float(addWalletRequest.getAmount()));
|
592 |
String messageText = MessageFormat.format("User Id - {0}\n Name -{1}\n Email -{2}\n mobile -{3}\n Reference - {4}\n Amount - Rs.{5}", new Integer(addWalletRequest.getRetailerId()), customRetailer.getBusinessName(), customRetailer.getEmail(), customRetailer.getMobileNumber(), addWalletRequest.getTransaction_reference(), new Float(addWalletRequest.getAmount()));
|
| 519 |
|
593 |
|