| 30859 |
tejbeer |
1 |
package com.spice.profitmandi.web.controller;
|
|
|
2 |
|
|
|
3 |
import com.spice.profitmandi.common.enumuration.MessageType;
|
|
|
4 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
|
|
5 |
import com.spice.profitmandi.common.model.CustomRetailer;
|
|
|
6 |
import com.spice.profitmandi.common.model.SendNotificationModel;
|
| 31020 |
tejbeer |
7 |
import com.spice.profitmandi.common.util.Utils;
|
| 30859 |
tejbeer |
8 |
import com.spice.profitmandi.dao.entity.auth.AuthUser;
|
|
|
9 |
import com.spice.profitmandi.dao.entity.dtr.CreditAccount;
|
|
|
10 |
import com.spice.profitmandi.dao.entity.dtr.CreditStatus;
|
| 30913 |
tejbeer |
11 |
import com.spice.profitmandi.dao.entity.fofo.CurrentPartnerDailyInvestment;
|
| 35274 |
amit |
12 |
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
|
| 30859 |
tejbeer |
13 |
import com.spice.profitmandi.dao.entity.fofo.PartnerDailyInvestment;
|
| 32681 |
amit.gupta |
14 |
import com.spice.profitmandi.dao.entity.transaction.*;
|
| 30989 |
tejbeer |
15 |
import com.spice.profitmandi.dao.entity.user.Address;
|
| 30859 |
tejbeer |
16 |
import com.spice.profitmandi.dao.enumuration.fofo.Gateway;
|
| 32197 |
jai.hind |
17 |
import com.spice.profitmandi.dao.enumuration.transaction.LoanSummaryType;
|
| 30859 |
tejbeer |
18 |
import com.spice.profitmandi.dao.enumuration.transaction.SanctionStatus;
|
| 32681 |
amit.gupta |
19 |
import com.spice.profitmandi.dao.model.*;
|
| 30859 |
tejbeer |
20 |
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
|
| 30936 |
tejbeer |
21 |
import com.spice.profitmandi.dao.repository.cs.CsService;
|
| 31666 |
amit.gupta |
22 |
import com.spice.profitmandi.dao.repository.cs.CsService1;
|
| 30859 |
tejbeer |
23 |
import com.spice.profitmandi.dao.repository.dtr.CreditAccountRepository;
|
|
|
24 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
|
|
25 |
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
|
| 30913 |
tejbeer |
26 |
import com.spice.profitmandi.dao.repository.fofo.CurrentPartnerDailyInvestmentRepository;
|
| 32528 |
tejbeer |
27 |
import com.spice.profitmandi.dao.repository.fofo.FofoOrderItemRepository;
|
| 30859 |
tejbeer |
28 |
import com.spice.profitmandi.dao.repository.fofo.PartnerDailyInvestmentRepository;
|
| 32681 |
amit.gupta |
29 |
import com.spice.profitmandi.dao.repository.transaction.*;
|
| 30989 |
tejbeer |
30 |
import com.spice.profitmandi.dao.repository.user.AddressRepository;
|
| 30859 |
tejbeer |
31 |
import com.spice.profitmandi.service.NotificationService;
|
|
|
32 |
import com.spice.profitmandi.service.transaction.SDCreditService;
|
|
|
33 |
import com.spice.profitmandi.service.user.RetailerService;
|
| 32197 |
jai.hind |
34 |
import com.spice.profitmandi.service.user.UserService;
|
| 30936 |
tejbeer |
35 |
import com.spice.profitmandi.web.model.LoginDetails;
|
|
|
36 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
| 31020 |
tejbeer |
37 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
| 32681 |
amit.gupta |
38 |
import org.apache.logging.log4j.LogManager;
|
|
|
39 |
import org.apache.logging.log4j.Logger;
|
|
|
40 |
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
41 |
import org.springframework.mail.javamail.JavaMailSender;
|
|
|
42 |
import org.springframework.stereotype.Controller;
|
|
|
43 |
import org.springframework.ui.Model;
|
| 33858 |
ranu |
44 |
import org.springframework.web.bind.annotation.*;
|
| 30859 |
tejbeer |
45 |
|
| 32681 |
amit.gupta |
46 |
import javax.servlet.http.HttpServletRequest;
|
| 35458 |
amit |
47 |
import org.springframework.transaction.annotation.Transactional;
|
| 32681 |
amit.gupta |
48 |
import java.math.BigDecimal;
|
|
|
49 |
import java.math.RoundingMode;
|
|
|
50 |
import java.time.Duration;
|
|
|
51 |
import java.time.LocalDate;
|
|
|
52 |
import java.time.LocalDateTime;
|
|
|
53 |
import java.time.LocalTime;
|
|
|
54 |
import java.util.*;
|
|
|
55 |
import java.util.Map.Entry;
|
|
|
56 |
import java.util.stream.Collectors;
|
|
|
57 |
|
| 30859 |
tejbeer |
58 |
@Controller
|
| 35458 |
amit |
59 |
@Transactional(rollbackFor = Throwable.class)
|
| 30859 |
tejbeer |
60 |
public class SDCreditController {
|
|
|
61 |
|
| 32052 |
tejbeer |
62 |
@Autowired
|
|
|
63 |
private RetailerService retailerService;
|
| 32439 |
tejbeer |
64 |
|
| 32197 |
jai.hind |
65 |
@Autowired
|
|
|
66 |
private UserService userService;
|
| 30859 |
tejbeer |
67 |
|
| 32052 |
tejbeer |
68 |
@Autowired
|
|
|
69 |
SDCreditRequirementRepository sdCreditRequirementRepository;
|
| 30859 |
tejbeer |
70 |
|
| 32052 |
tejbeer |
71 |
@Autowired
|
|
|
72 |
SanctionRequestRepository sanctionRequestRepository;
|
| 30859 |
tejbeer |
73 |
|
| 32052 |
tejbeer |
74 |
@Autowired
|
|
|
75 |
PartnerDailyInvestmentRepository partnerDailyInvestmentRepository;
|
| 30859 |
tejbeer |
76 |
|
| 32052 |
tejbeer |
77 |
@Autowired
|
|
|
78 |
private FofoStoreRepository fofoStoreRepository;
|
| 30859 |
tejbeer |
79 |
|
| 32052 |
tejbeer |
80 |
@Autowired
|
|
|
81 |
private CreditAccountRepository creditAccountRepository;
|
| 30859 |
tejbeer |
82 |
|
| 32052 |
tejbeer |
83 |
@Autowired
|
|
|
84 |
private SDCreditService sdCreditService;
|
| 30859 |
tejbeer |
85 |
|
| 32052 |
tejbeer |
86 |
@Autowired
|
|
|
87 |
private CsService1 csService1;
|
| 31666 |
amit.gupta |
88 |
|
| 32052 |
tejbeer |
89 |
@Autowired
|
|
|
90 |
private NotificationService notificationService;
|
| 30859 |
tejbeer |
91 |
|
| 32052 |
tejbeer |
92 |
@Autowired
|
|
|
93 |
private AuthRepository authRepository;
|
| 30859 |
tejbeer |
94 |
|
| 32052 |
tejbeer |
95 |
@Autowired
|
|
|
96 |
private UserRepository userRepository;
|
| 30859 |
tejbeer |
97 |
|
| 32052 |
tejbeer |
98 |
@Autowired
|
|
|
99 |
private CurrentPartnerDailyInvestmentRepository currentPartnerDailyInvestmentRepository;
|
| 30913 |
tejbeer |
100 |
|
| 32052 |
tejbeer |
101 |
@Autowired
|
|
|
102 |
private UserWalletRepository userWalletRepository;
|
| 30929 |
tejbeer |
103 |
|
| 32052 |
tejbeer |
104 |
@Autowired
|
|
|
105 |
LoanRepository loanRepository;
|
| 30929 |
tejbeer |
106 |
|
| 32052 |
tejbeer |
107 |
@Autowired
|
|
|
108 |
private CookiesProcessor cookiesProcessor;
|
| 30936 |
tejbeer |
109 |
|
| 32052 |
tejbeer |
110 |
@Autowired
|
|
|
111 |
private CsService csService;
|
| 30936 |
tejbeer |
112 |
|
| 32052 |
tejbeer |
113 |
@Autowired
|
|
|
114 |
AddressRepository addressRepository;
|
| 30989 |
tejbeer |
115 |
|
| 32052 |
tejbeer |
116 |
@Autowired
|
|
|
117 |
OrderRepository orderRepository;
|
| 31020 |
tejbeer |
118 |
|
| 32052 |
tejbeer |
119 |
@Autowired
|
|
|
120 |
private LoanStatementRepository loanStatementRepository;
|
| 31020 |
tejbeer |
121 |
|
| 32052 |
tejbeer |
122 |
@Autowired
|
|
|
123 |
private com.spice.profitmandi.dao.repository.user.UserRepository userUserRepository;
|
| 30989 |
tejbeer |
124 |
|
| 32052 |
tejbeer |
125 |
@Autowired
|
|
|
126 |
private JavaMailSender mailSender;
|
| 31020 |
tejbeer |
127 |
|
| 32052 |
tejbeer |
128 |
@Autowired
|
|
|
129 |
private MVCResponseSender mvcResponseSender;
|
| 31020 |
tejbeer |
130 |
|
| 32528 |
tejbeer |
131 |
@Autowired
|
|
|
132 |
private FofoOrderItemRepository fofoOrderItemRepository;
|
|
|
133 |
|
| 35534 |
amit |
134 |
@Autowired
|
|
|
135 |
private com.spice.profitmandi.service.transaction.CreditBlockedExceptionPartnersRepository creditBlockedExceptionPartnersRepository;
|
|
|
136 |
|
| 32052 |
tejbeer |
137 |
private static final Logger LOGGER = LogManager.getLogger(SDCreditController.class);
|
| 30859 |
tejbeer |
138 |
|
| 32052 |
tejbeer |
139 |
@RequestMapping(value = "/getSDCreditReq", method = RequestMethod.GET)
|
|
|
140 |
public String getSDCreditReq(HttpServletRequest request, Model model) throws ProfitMandiBusinessException {
|
| 33854 |
tejus.loha |
141 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 34969 |
ranu |
142 |
boolean isTarun = loginDetails.getEmailId().equals("tarun.verma@smartdukaan.com") || loginDetails.getEmailId().equals("kamini.sharma@smartdukaan.com");
|
| 30859 |
tejbeer |
143 |
|
| 32052 |
tejbeer |
144 |
Map<Integer, CustomRetailer> customRetailerMap = retailerService.getFofoRetailers(true);
|
| 30859 |
tejbeer |
145 |
|
| 32052 |
tejbeer |
146 |
Map<Integer, SDCreditRequirement> sdCreditRequirementMap = sdCreditRequirementRepository.selectAll().stream().collect(Collectors.toMap(x -> x.getFofoId(), x -> x));
|
|
|
147 |
for (Entry<Integer, CustomRetailer> customRetailerEntry : customRetailerMap.entrySet()) {
|
|
|
148 |
int fofoId = customRetailerEntry.getKey();
|
| 30859 |
tejbeer |
149 |
|
| 32052 |
tejbeer |
150 |
SDCreditRequirement sdCreditRequirement = sdCreditRequirementMap.get(customRetailerEntry.getKey());
|
| 30859 |
tejbeer |
151 |
|
| 32052 |
tejbeer |
152 |
if (sdCreditRequirement != null) {
|
| 30913 |
tejbeer |
153 |
|
| 35395 |
amit |
154 |
BigDecimal utilizedLimit = sdCreditService.getUtilizationAmount(fofoId);
|
| 30910 |
tejbeer |
155 |
|
| 32052 |
tejbeer |
156 |
BigDecimal availableLimit = sdCreditRequirement.getLimit().subtract(utilizedLimit);
|
| 30910 |
tejbeer |
157 |
|
| 32052 |
tejbeer |
158 |
LOGGER.info("utilizedLimit {} ", utilizedLimit);
|
| 30910 |
tejbeer |
159 |
|
| 32052 |
tejbeer |
160 |
LOGGER.info("availableLimit {} ", availableLimit);
|
| 30910 |
tejbeer |
161 |
|
| 32052 |
tejbeer |
162 |
sdCreditRequirement.setUtilizedAmount(utilizedLimit);
|
| 30910 |
tejbeer |
163 |
|
| 32052 |
tejbeer |
164 |
sdCreditRequirement.setUpdateTimestamp(LocalDateTime.now());
|
|
|
165 |
}
|
| 30859 |
tejbeer |
166 |
|
| 32052 |
tejbeer |
167 |
}
|
| 30859 |
tejbeer |
168 |
|
| 32052 |
tejbeer |
169 |
model.addAttribute("customRetailerMap", customRetailerMap);
|
|
|
170 |
model.addAttribute("sdCreditRequirementMap", sdCreditRequirementMap);
|
| 33854 |
tejus.loha |
171 |
model.addAttribute("isTarun", isTarun);
|
| 32052 |
tejbeer |
172 |
return "sd-credit";
|
|
|
173 |
}
|
| 30921 |
tejbeer |
174 |
|
| 32052 |
tejbeer |
175 |
@RequestMapping(value = "/creditRequirement", method = RequestMethod.POST)
|
|
|
176 |
public String sdCredit(HttpServletRequest request, @RequestBody SdCreditRequirementModel sdCreditRequirementModel, Model model) throws Exception {
|
| 30859 |
tejbeer |
177 |
|
| 32052 |
tejbeer |
178 |
LOGGER.info("sdCreditRequirementModel {} ", sdCreditRequirementModel);
|
| 30859 |
tejbeer |
179 |
|
| 32052 |
tejbeer |
180 |
int fofoId = sdCreditRequirementModel.getFofoId();
|
| 30859 |
tejbeer |
181 |
|
| 32052 |
tejbeer |
182 |
SDCreditRequirement sdCreditRequirement = sdCreditRequirementRepository.selectByFofoId(sdCreditRequirementModel.getFofoId());
|
| 30859 |
tejbeer |
183 |
|
| 33854 |
tejus.loha |
184 |
// sdCreditRequirement.setSecurityCheck(2);
|
| 32052 |
tejbeer |
185 |
sdCreditRequirement.setSecurityCheck(sdCreditRequirementModel.getSecurityCheck());
|
| 30859 |
tejbeer |
186 |
|
| 33854 |
tejus.loha |
187 |
|
|
|
188 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 34969 |
ranu |
189 |
boolean isTarun = loginDetails.getEmailId().equals("tarun.verma@smartdukaan.com") || loginDetails.getEmailId().equals("kamini.sharma@smartdukaan.com");
|
| 35313 |
amit |
190 |
sdCreditRequirement.setInterestRate(sdCreditRequirementModel.getInterest());
|
|
|
191 |
sdCreditRequirement.setFreeDays(sdCreditRequirementModel.getFreeDays());
|
| 35395 |
amit |
192 |
BigDecimal utilizedLimit = sdCreditService.getUtilizationAmount(fofoId);
|
| 35313 |
amit |
193 |
BigDecimal availableLimit = sdCreditRequirement.getLimit().subtract(utilizedLimit);
|
|
|
194 |
sdCreditRequirement.setUtilizedAmount(utilizedLimit);
|
| 33854 |
tejus.loha |
195 |
if (isTarun) {
|
|
|
196 |
if (sdCreditRequirement.getLimit() != sdCreditRequirementModel.getLimit()) {
|
| 35318 |
amit |
197 |
sdCreditRequirement.setLimit(sdCreditRequirementModel.getLimit());
|
| 33854 |
tejus.loha |
198 |
sdCreditRequirement.setHardLimit(true);
|
| 35158 |
amit |
199 |
sdCreditService.updateMinInvestmentForHardLimit(sdCreditRequirement, true);
|
| 33854 |
tejus.loha |
200 |
}
|
|
|
201 |
}
|
|
|
202 |
|
| 35318 |
amit |
203 |
sdCreditRequirement.setLimit(sdCreditRequirementModel.getLimit());
|
| 32052 |
tejbeer |
204 |
sdCreditRequirement.setCreditDays(15);
|
|
|
205 |
sdCreditRequirement.setUpdateTimestamp(LocalDateTime.now());
|
| 30859 |
tejbeer |
206 |
|
| 32052 |
tejbeer |
207 |
if (sdCreditRequirement.getSecurityCheck() > 0) {
|
| 30859 |
tejbeer |
208 |
|
| 32052 |
tejbeer |
209 |
CreditAccount creditAccount = creditAccountRepository.selectByFofoIdAndGateway(sdCreditRequirementModel.getFofoId(), Gateway.SDDIRECT);
|
|
|
210 |
if (creditAccount == null) {
|
|
|
211 |
creditAccount = new CreditAccount();
|
|
|
212 |
creditAccount.setFofoId(sdCreditRequirementModel.getFofoId());
|
|
|
213 |
creditAccount.setGateway(Gateway.SDDIRECT);
|
|
|
214 |
creditAccount.setCreditStatus(CreditStatus.SANCTIONED);
|
|
|
215 |
creditAccount.setActive(false);
|
| 30859 |
tejbeer |
216 |
|
| 32052 |
tejbeer |
217 |
creditAccount.setUpdatedOn(LocalDateTime.now());
|
| 30859 |
tejbeer |
218 |
|
| 32052 |
tejbeer |
219 |
creditAccountRepository.persist(creditAccount);
|
|
|
220 |
}
|
|
|
221 |
creditAccount.setInterestRate(sdCreditRequirement.getInterestRate().floatValue());
|
|
|
222 |
creditAccount.setSanctionedAmount(sdCreditRequirement.getLimit().floatValue());
|
|
|
223 |
creditAccount.setAvailableAmount(availableLimit.floatValue());
|
|
|
224 |
creditAccount.setFreeDays(sdCreditRequirement.getFreeDays());
|
|
|
225 |
creditAccount.setUpdatedOn(LocalDateTime.now());
|
|
|
226 |
}
|
|
|
227 |
LOGGER.info("sdCreditRequirement {} ", sdCreditRequirement);
|
| 30859 |
tejbeer |
228 |
|
| 32052 |
tejbeer |
229 |
CustomRetailer customRetailer = retailerService.getFofoRetailer(sdCreditRequirementModel.getFofoId());
|
| 30859 |
tejbeer |
230 |
|
| 32052 |
tejbeer |
231 |
sdCreditRequirement = sdCreditRequirementRepository.selectByFofoId(sdCreditRequirementModel.getFofoId());
|
| 30865 |
tejbeer |
232 |
|
| 32052 |
tejbeer |
233 |
Map<Integer, SDCreditRequirement> sdCreditRequirementMap = new HashMap<>();
|
|
|
234 |
sdCreditRequirementMap.put(sdCreditRequirement.getFofoId(), sdCreditRequirement);
|
|
|
235 |
model.addAttribute("sdCreditRequirementMap", sdCreditRequirementMap);
|
|
|
236 |
model.addAttribute("customRetailer", customRetailer);
|
| 33854 |
tejus.loha |
237 |
model.addAttribute("isTarun", isTarun);
|
| 30859 |
tejbeer |
238 |
|
| 32052 |
tejbeer |
239 |
return "sd-credit-requirement-row";
|
| 30859 |
tejbeer |
240 |
|
| 32052 |
tejbeer |
241 |
}
|
| 30859 |
tejbeer |
242 |
|
| 33854 |
tejus.loha |
243 |
@RequestMapping(value = "/resetHardLimit", method = RequestMethod.PUT)
|
|
|
244 |
public String resetHardLimit(HttpServletRequest request, @RequestParam int id, Model model) throws Exception {
|
|
|
245 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 34969 |
ranu |
246 |
if (loginDetails.getEmailId().equals("tarun.verma@smartdukaan.com") || loginDetails.getEmailId().equals("kamini.sharma@smartdukaan.com")) {
|
| 33854 |
tejus.loha |
247 |
SDCreditRequirement sdCreditRequirement = sdCreditRequirementRepository.selectById(id);
|
| 35274 |
amit |
248 |
sdCreditRequirement.setHardLimit(false);
|
| 35286 |
amit |
249 |
FofoStore fofoStore = fofoStoreRepository.selectByRetailerId(sdCreditRequirement.getFofoId());
|
| 35301 |
amit |
250 |
fofoStore.setMinimumInvestment(fofoStore.getMinimumInvestmentOld());
|
| 35139 |
amit |
251 |
sdCreditRequirement.setLimit(sdCreditRequirement.getSuggestedLimit());
|
| 33854 |
tejus.loha |
252 |
}
|
|
|
253 |
model.addAttribute("response1", mvcResponseSender.createResponseString(true));
|
|
|
254 |
return "response";
|
|
|
255 |
}
|
|
|
256 |
|
| 35534 |
amit |
257 |
@RequestMapping(value = "/addCreditBlockedException", method = RequestMethod.POST)
|
|
|
258 |
public String addCreditBlockedException(HttpServletRequest request, @RequestParam int fofoId, Model model) throws Exception {
|
|
|
259 |
LOGGER.info("Adding credit blocked exception for fofoId: {} for today", fofoId);
|
|
|
260 |
|
|
|
261 |
CreditBlockedExceptionPartner existingException = creditBlockedExceptionPartnersRepository.select(fofoId);
|
|
|
262 |
if (existingException != null && existingException.getOnDate().equals(LocalDate.now())) {
|
|
|
263 |
LOGGER.info("Exception already exists for fofoId: {} for today", fofoId);
|
|
|
264 |
model.addAttribute("response1", mvcResponseSender.createResponseString(true));
|
|
|
265 |
return "response";
|
|
|
266 |
}
|
|
|
267 |
|
|
|
268 |
CreditBlockedExceptionPartner exception = new CreditBlockedExceptionPartner();
|
|
|
269 |
exception.setFofoId(fofoId);
|
|
|
270 |
exception.setOnDate(LocalDate.now());
|
|
|
271 |
creditBlockedExceptionPartnersRepository.persist(exception);
|
|
|
272 |
|
|
|
273 |
LOGGER.info("Credit blocked exception added successfully for fofoId: {}", fofoId);
|
|
|
274 |
model.addAttribute("response1", mvcResponseSender.createResponseString(true));
|
|
|
275 |
return "response";
|
|
|
276 |
}
|
|
|
277 |
|
| 32052 |
tejbeer |
278 |
@RequestMapping(value = "/getSanctionRequest", method = RequestMethod.GET)
|
|
|
279 |
public String getSanctionRequest(HttpServletRequest request, Model model) throws ProfitMandiBusinessException {
|
| 30859 |
tejbeer |
280 |
|
| 34355 |
ranu |
281 |
List<SanctionRequest> sanctionRequests = sanctionRequestRepository.getL2ApprovedByDate(LocalDate.now(), SanctionStatus.APPROVED);
|
| 30859 |
tejbeer |
282 |
|
| 32041 |
amit.gupta |
283 |
|
| 32052 |
tejbeer |
284 |
if (!sanctionRequests.isEmpty()) {
|
| 30859 |
tejbeer |
285 |
|
| 32053 |
tejbeer |
286 |
List<Integer> authIds = sanctionRequests.stream().map(x -> x.getAuthId()).collect(Collectors.toList());
|
|
|
287 |
|
| 35395 |
amit |
288 |
Map<Integer, String> authMap = authRepository.selectByIds(authIds).stream().collect(Collectors.toMap(x -> x.getId(), x -> x.getFullName()));
|
| 32053 |
tejbeer |
289 |
|
|
|
290 |
|
| 32052 |
tejbeer |
291 |
List<Integer> fofoIds = sanctionRequests.stream().map(x -> x.getFofoId()).collect(Collectors.toList());
|
| 30859 |
tejbeer |
292 |
|
| 32052 |
tejbeer |
293 |
Map<Integer, Long> partnerCreditDaysMap = new HashMap<>();
|
| 31110 |
tejbeer |
294 |
|
| 32052 |
tejbeer |
295 |
Map<Integer, Integer> partnerActiveLoanMap = new HashMap<>();
|
| 32681 |
amit.gupta |
296 |
Map<Integer, Integer> partnerAverageCreditDaysMap = new HashMap<>();
|
| 31110 |
tejbeer |
297 |
|
| 32528 |
tejbeer |
298 |
LocalDateTime curDate = LocalDate.now().atStartOfDay();
|
|
|
299 |
|
| 33505 |
amit.gupta |
300 |
/*Map<Integer, Double> lmtdSale = fofoOrderItemRepository.selectSumMopGroupByRetailer(
|
| 32528 |
tejbeer |
301 |
curDate.withDayOfMonth(1).minusMonths(1), curDate.with(LocalTime.MAX).minusMonths(1), 0, false);
|
|
|
302 |
|
|
|
303 |
Map<Integer, Double> mtdSale = fofoOrderItemRepository.selectSumMopGroupByRetailer(curDate.withDayOfMonth(1), curDate.with(LocalTime.MAX), 0, false);
|
|
|
304 |
|
|
|
305 |
Map<Integer, Double> lmsSale = fofoOrderItemRepository.selectSumMopGroupByRetailer(
|
| 33505 |
amit.gupta |
306 |
curDate.withDayOfMonth(1).minusMonths(1), curDate.withDayOfMonth(1), 0, false);*/
|
| 32528 |
tejbeer |
307 |
|
| 33505 |
amit.gupta |
308 |
Map<Integer, Double> secondaryMtd = orderRepository
|
|
|
309 |
.selectBillingDatesBetweenSumGroupByRetailerId(curDate.withDayOfMonth(1), curDate.with(LocalTime.MAX));
|
|
|
310 |
Map<Integer, Double> secondaryLmtd = orderRepository.selectBillingDatesBetweenSumGroupByRetailerId(
|
|
|
311 |
curDate.withDayOfMonth(1).minusMonths(1), curDate.with(LocalTime.MAX).minusMonths(1));
|
|
|
312 |
Map<Integer, Double> secondaryLms = orderRepository.selectBillingDatesBetweenSumGroupByRetailerId(
|
|
|
313 |
curDate.withDayOfMonth(1).minusMonths(1), curDate.withDayOfMonth(1));
|
|
|
314 |
|
| 32681 |
amit.gupta |
315 |
List<Loan> loans = loanRepository.selectAllLoans(fofoIds, DateRangeModel.withStartDate(curDate.minusYears(2)));
|
| 33205 |
amit.gupta |
316 |
Map<Integer, List<Loan>> partnerClosedLoansMap = loans.stream().filter(x -> x.getPendingAmount().compareTo(BigDecimal.ZERO) == 0)
|
| 32740 |
amit.gupta |
317 |
.collect(Collectors.groupingBy(x -> x.getFofoId()));
|
| 32528 |
tejbeer |
318 |
|
| 31110 |
tejbeer |
319 |
|
| 32740 |
amit.gupta |
320 |
Map<Integer, List<Loan>> activeLoansMap = loans.stream().filter(x -> x.getPendingAmount().compareTo(BigDecimal.ZERO) == 1).collect(Collectors.groupingBy(x -> x.getFofoId()));
|
| 32528 |
tejbeer |
321 |
|
| 32681 |
amit.gupta |
322 |
for (Integer fofoId : fofoIds) {
|
| 32693 |
amit.gupta |
323 |
LOGGER.info("Fofo Id - {}", fofoId);
|
| 32681 |
amit.gupta |
324 |
List<Loan> activeLoans = activeLoansMap.get(fofoId);
|
|
|
325 |
if (activeLoans != null) {
|
|
|
326 |
partnerActiveLoanMap.put(fofoId, activeLoans.size());
|
| 32742 |
amit.gupta |
327 |
Loan loan = activeLoans.stream().sorted(Comparator.comparing(Loan::getCreatedOn)).findFirst().get();
|
| 32052 |
tejbeer |
328 |
long daysBetween = Duration.between(loan.getCreatedOn(), LocalDateTime.now()).toDays();
|
|
|
329 |
partnerCreditDaysMap.put(fofoId, daysBetween);
|
|
|
330 |
}
|
| 32681 |
amit.gupta |
331 |
List<Loan> closedLoans = partnerClosedLoansMap.get(fofoId);
|
|
|
332 |
if (closedLoans != null) {
|
|
|
333 |
long averageCreditDays = Math.round(closedLoans.stream().mapToLong(x -> Duration.between(x.getCreatedOn(),
|
| 32683 |
amit.gupta |
334 |
x.getSettledOn() == null ? x.getCreatedOn().plusDays(10) : x.getSettledOn()).toDays() + 1).average().orElse(0.0));
|
| 32681 |
amit.gupta |
335 |
partnerAverageCreditDaysMap.put(fofoId, (int) averageCreditDays);
|
|
|
336 |
}
|
| 31110 |
tejbeer |
337 |
|
| 32052 |
tejbeer |
338 |
}
|
| 32681 |
amit.gupta |
339 |
model.addAttribute("partnerActiveLoanMap", partnerActiveLoanMap);
|
|
|
340 |
model.addAttribute("partnerCreditDaysMap", partnerCreditDaysMap);
|
|
|
341 |
model.addAttribute("partnerAverageCreditDaysMap", partnerAverageCreditDaysMap);
|
| 31110 |
tejbeer |
342 |
|
| 32052 |
tejbeer |
343 |
Map<Integer, SDCreditRequirement> sdCreditRequirementMap = sdCreditRequirementRepository.selectAll().stream().collect(Collectors.toMap(x -> x.getFofoId(), x -> x));
|
| 30967 |
tejbeer |
344 |
|
| 32052 |
tejbeer |
345 |
Map<Integer, UserWallet> userWalletMap = userWalletRepository.selectByRetailerIds(new HashSet<>(fofoIds)).stream().collect(Collectors.toMap(x -> x.getUserId(), x -> x));
|
| 30859 |
tejbeer |
346 |
|
| 32052 |
tejbeer |
347 |
Map<Integer, CustomRetailer> customRetailerMap = retailerService.getFofoRetailers(fofoIds);
|
|
|
348 |
Map<Integer, PartnerDailyInvestment> partnerDailyInvestmentMap = partnerDailyInvestmentRepository.selectAll(fofoIds, LocalDate.now().minusDays(1)).stream().collect(Collectors.toMap(x -> x.getFofoId(), x -> x));
|
| 35216 |
ranu |
349 |
LOGGER.info("partnerDailyInvestmentMap {}", partnerDailyInvestmentMap);
|
| 30859 |
tejbeer |
350 |
|
| 32052 |
tejbeer |
351 |
model.addAttribute("customRetailerMap", customRetailerMap);
|
| 30859 |
tejbeer |
352 |
|
| 32052 |
tejbeer |
353 |
model.addAttribute("partnerDailyInvestmentMap", partnerDailyInvestmentMap);
|
|
|
354 |
model.addAttribute("sdCreditRequirementMap", sdCreditRequirementMap);
|
| 30859 |
tejbeer |
355 |
|
| 32052 |
tejbeer |
356 |
model.addAttribute("userWalletMap", userWalletMap);
|
| 32053 |
tejbeer |
357 |
model.addAttribute("authMap", authMap);
|
| 33505 |
amit.gupta |
358 |
model.addAttribute("secondaryMtd", secondaryMtd);
|
|
|
359 |
model.addAttribute("secondarylmtd", secondaryLmtd);
|
|
|
360 |
model.addAttribute("secondarylms", secondaryLms);
|
| 31020 |
tejbeer |
361 |
|
| 33354 |
amit.gupta |
362 |
List<CreditAccount> creditAccounts = creditAccountRepository.selectByFofoIds(fofoIds);
|
| 33854 |
tejus.loha |
363 |
model.addAttribute("creditAccounts", creditAccounts.stream().collect(Collectors.toMap(x -> x.getFofoId(), x -> x.getGateway())));
|
| 32052 |
tejbeer |
364 |
}
|
| 30859 |
tejbeer |
365 |
|
| 32052 |
tejbeer |
366 |
model.addAttribute("sanctionRequests", sanctionRequests);
|
| 30859 |
tejbeer |
367 |
|
| 32052 |
tejbeer |
368 |
model.addAttribute("sanctionStatus", SanctionStatus.values());
|
|
|
369 |
return "sanction-request";
|
| 30859 |
tejbeer |
370 |
|
| 32052 |
tejbeer |
371 |
}
|
| 30859 |
tejbeer |
372 |
|
| 34355 |
ranu |
373 |
|
|
|
374 |
@RequestMapping(value = "/getRbmL2SanctionRequest", method = RequestMethod.GET)
|
|
|
375 |
public String getRbmL2SanctionRequest(HttpServletRequest request, Model model) throws ProfitMandiBusinessException {
|
|
|
376 |
|
|
|
377 |
List<SanctionRequest> sanctionRequests = sanctionRequestRepository.selectByDate(LocalDate.now());
|
|
|
378 |
|
|
|
379 |
|
|
|
380 |
if (!sanctionRequests.isEmpty()) {
|
|
|
381 |
|
|
|
382 |
List<Integer> authIds = sanctionRequests.stream().map(x -> x.getAuthId()).collect(Collectors.toList());
|
|
|
383 |
|
| 35395 |
amit |
384 |
Map<Integer, String> authMap = authRepository.selectByIds(authIds).stream().collect(Collectors.toMap(x -> x.getId(), x -> x.getFullName()));
|
| 34355 |
ranu |
385 |
|
|
|
386 |
|
|
|
387 |
List<Integer> fofoIds = sanctionRequests.stream().map(x -> x.getFofoId()).collect(Collectors.toList());
|
|
|
388 |
|
|
|
389 |
Map<Integer, Long> partnerCreditDaysMap = new HashMap<>();
|
|
|
390 |
|
|
|
391 |
Map<Integer, Integer> partnerActiveLoanMap = new HashMap<>();
|
|
|
392 |
Map<Integer, Integer> partnerAverageCreditDaysMap = new HashMap<>();
|
|
|
393 |
|
|
|
394 |
LocalDateTime curDate = LocalDate.now().atStartOfDay();
|
|
|
395 |
|
|
|
396 |
Map<Integer, Double> secondaryMtd = orderRepository
|
|
|
397 |
.selectBillingDatesBetweenSumGroupByRetailerId(curDate.withDayOfMonth(1), curDate.with(LocalTime.MAX));
|
|
|
398 |
Map<Integer, Double> secondaryLmtd = orderRepository.selectBillingDatesBetweenSumGroupByRetailerId(
|
|
|
399 |
curDate.withDayOfMonth(1).minusMonths(1), curDate.with(LocalTime.MAX).minusMonths(1));
|
|
|
400 |
Map<Integer, Double> secondaryLms = orderRepository.selectBillingDatesBetweenSumGroupByRetailerId(
|
|
|
401 |
curDate.withDayOfMonth(1).minusMonths(1), curDate.withDayOfMonth(1));
|
|
|
402 |
|
|
|
403 |
List<Loan> loans = loanRepository.selectAllLoans(fofoIds, DateRangeModel.withStartDate(curDate.minusYears(2)));
|
|
|
404 |
Map<Integer, List<Loan>> partnerClosedLoansMap = loans.stream().filter(x -> x.getPendingAmount().compareTo(BigDecimal.ZERO) == 0)
|
|
|
405 |
.collect(Collectors.groupingBy(x -> x.getFofoId()));
|
|
|
406 |
|
|
|
407 |
|
|
|
408 |
Map<Integer, List<Loan>> activeLoansMap = loans.stream().filter(x -> x.getPendingAmount().compareTo(BigDecimal.ZERO) == 1).collect(Collectors.groupingBy(x -> x.getFofoId()));
|
|
|
409 |
|
|
|
410 |
for (Integer fofoId : fofoIds) {
|
|
|
411 |
LOGGER.info("Fofo Id - {}", fofoId);
|
|
|
412 |
List<Loan> activeLoans = activeLoansMap.get(fofoId);
|
|
|
413 |
if (activeLoans != null) {
|
|
|
414 |
partnerActiveLoanMap.put(fofoId, activeLoans.size());
|
|
|
415 |
Loan loan = activeLoans.stream().sorted(Comparator.comparing(Loan::getCreatedOn)).findFirst().get();
|
|
|
416 |
long daysBetween = Duration.between(loan.getCreatedOn(), LocalDateTime.now()).toDays();
|
|
|
417 |
partnerCreditDaysMap.put(fofoId, daysBetween);
|
|
|
418 |
}
|
|
|
419 |
List<Loan> closedLoans = partnerClosedLoansMap.get(fofoId);
|
|
|
420 |
if (closedLoans != null) {
|
|
|
421 |
long averageCreditDays = Math.round(closedLoans.stream().mapToLong(x -> Duration.between(x.getCreatedOn(),
|
|
|
422 |
x.getSettledOn() == null ? x.getCreatedOn().plusDays(10) : x.getSettledOn()).toDays() + 1).average().orElse(0.0));
|
|
|
423 |
partnerAverageCreditDaysMap.put(fofoId, (int) averageCreditDays);
|
|
|
424 |
}
|
|
|
425 |
|
|
|
426 |
}
|
|
|
427 |
model.addAttribute("partnerActiveLoanMap", partnerActiveLoanMap);
|
|
|
428 |
model.addAttribute("partnerCreditDaysMap", partnerCreditDaysMap);
|
|
|
429 |
model.addAttribute("partnerAverageCreditDaysMap", partnerAverageCreditDaysMap);
|
|
|
430 |
|
|
|
431 |
Map<Integer, SDCreditRequirement> sdCreditRequirementMap = sdCreditRequirementRepository.selectAll().stream().collect(Collectors.toMap(x -> x.getFofoId(), x -> x));
|
|
|
432 |
|
|
|
433 |
Map<Integer, UserWallet> userWalletMap = userWalletRepository.selectByRetailerIds(new HashSet<>(fofoIds)).stream().collect(Collectors.toMap(x -> x.getUserId(), x -> x));
|
|
|
434 |
|
|
|
435 |
Map<Integer, CustomRetailer> customRetailerMap = retailerService.getFofoRetailers(fofoIds);
|
|
|
436 |
Map<Integer, PartnerDailyInvestment> partnerDailyInvestmentMap = partnerDailyInvestmentRepository.selectAll(fofoIds, LocalDate.now().minusDays(1)).stream().collect(Collectors.toMap(x -> x.getFofoId(), x -> x));
|
|
|
437 |
|
|
|
438 |
model.addAttribute("customRetailerMap", customRetailerMap);
|
|
|
439 |
|
|
|
440 |
model.addAttribute("partnerDailyInvestmentMap", partnerDailyInvestmentMap);
|
|
|
441 |
model.addAttribute("sdCreditRequirementMap", sdCreditRequirementMap);
|
|
|
442 |
|
|
|
443 |
model.addAttribute("userWalletMap", userWalletMap);
|
|
|
444 |
model.addAttribute("authMap", authMap);
|
|
|
445 |
model.addAttribute("secondaryMtd", secondaryMtd);
|
|
|
446 |
model.addAttribute("secondarylmtd", secondaryLmtd);
|
|
|
447 |
model.addAttribute("secondarylms", secondaryLms);
|
|
|
448 |
|
|
|
449 |
List<CreditAccount> creditAccounts = creditAccountRepository.selectByFofoIds(fofoIds);
|
|
|
450 |
model.addAttribute("creditAccounts", creditAccounts.stream().collect(Collectors.toMap(x -> x.getFofoId(), x -> x.getGateway())));
|
|
|
451 |
}
|
|
|
452 |
|
|
|
453 |
model.addAttribute("sanctionRequests", sanctionRequests);
|
|
|
454 |
|
|
|
455 |
model.addAttribute("sanctionStatus", SanctionStatus.values());
|
|
|
456 |
return "sanction-request-l2";
|
|
|
457 |
|
|
|
458 |
}
|
|
|
459 |
|
| 32052 |
tejbeer |
460 |
@RequestMapping(value = "/sanctionRequest", method = RequestMethod.POST)
|
|
|
461 |
public String sanctionRequest(HttpServletRequest request, @RequestBody SanctionRequestModel sanctionRequestModel, Model model) throws Exception {
|
| 30859 |
tejbeer |
462 |
|
| 32052 |
tejbeer |
463 |
LOGGER.info("sanctionRequestModel {} ", sanctionRequestModel);
|
|
|
464 |
Map<Integer, SDCreditRequirement> sdCreditRequirementMap = sdCreditRequirementRepository.selectAll().stream().collect(Collectors.toMap(x -> x.getFofoId(), x -> x));
|
| 30859 |
tejbeer |
465 |
|
| 32052 |
tejbeer |
466 |
SanctionRequest sanctionRequest = sanctionRequestRepository.selectById(sanctionRequestModel.getId());
|
| 30859 |
tejbeer |
467 |
|
| 33205 |
amit.gupta |
468 |
Map<Integer, String> authMap = new HashMap<>();
|
| 32052 |
tejbeer |
469 |
AuthUser authUser = authRepository.selectById(sanctionRequest.getAuthId());
|
| 30859 |
tejbeer |
470 |
|
| 32052 |
tejbeer |
471 |
authMap.put(authUser.getId(), authUser.getFullName());
|
| 30859 |
tejbeer |
472 |
|
| 32052 |
tejbeer |
473 |
model.addAttribute("authMap", authMap);
|
|
|
474 |
List<Integer> fofoIds = sanctionRequestRepository.selectByDate(LocalDate.now()).stream().map(x -> x.getFofoId()).collect(Collectors.toList());
|
| 30859 |
tejbeer |
475 |
|
| 32052 |
tejbeer |
476 |
Map<Integer, CustomRetailer> customRetailerMap = retailerService.getFofoRetailers(fofoIds);
|
| 30859 |
tejbeer |
477 |
|
| 32052 |
tejbeer |
478 |
LOGGER.info("freeDays {} ", sdCreditRequirementMap.get(sanctionRequest.getFofoId()).getFreeDays());
|
| 30989 |
tejbeer |
479 |
|
| 32052 |
tejbeer |
480 |
if (sanctionRequestModel.getStatus().equals(SanctionStatus.APPROVED)) {
|
|
|
481 |
CustomRetailer customRetailer = customRetailerMap.get(sanctionRequest.getFofoId());
|
|
|
482 |
sanctionRequest.setApprovalTimestamp(LocalDateTime.now());
|
|
|
483 |
BigDecimal availableAmount = sdCreditService.getAvailableAmount(sanctionRequest.getFofoId());
|
| 30989 |
tejbeer |
484 |
|
| 32052 |
tejbeer |
485 |
String title = "Sanction Request Approved";
|
|
|
486 |
String url = "http://app.smartdukaan.com/pages/home/credit";
|
|
|
487 |
String message = "Congratulations! Your credit limit is increased for today Rs." + sanctionRequest.getApprovalAmount().setScale(2, RoundingMode.HALF_UP) + ". Your total available limit is Rs." + availableAmount.setScale(2, RoundingMode.HALF_UP) + ".";
|
|
|
488 |
notificationService.sendNotification(sanctionRequest.getFofoId(), title, MessageType.notification, title, message, url);
|
|
|
489 |
com.spice.profitmandi.dao.entity.user.User user = userUserRepository.selectById(sanctionRequest.getFofoId());
|
| 30859 |
tejbeer |
490 |
|
| 32052 |
tejbeer |
491 |
Address address = addressRepository.selectById(user.getAddressId());
|
| 32777 |
amit.gupta |
492 |
//TODO-Whatsapp
|
|
|
493 |
//notificationService.sendWhatsappMessage(message, title, address.getPhoneNumber());
|
| 30859 |
tejbeer |
494 |
|
| 35210 |
vikas |
495 |
String empMessage = "Congratulations! Your Partner " + customRetailer.getBusinessName() + " credit limit is increased for today by Rs." + sanctionRequest.getApprovalAmount().setScale(2, RoundingMode.HALF_UP) + " and now the new total available limit is Rs." + availableAmount.setScale(2, RoundingMode.HALF_UP) + ".";
|
| 32052 |
tejbeer |
496 |
SendNotificationModel sendNotificationModel = new SendNotificationModel();
|
|
|
497 |
sendNotificationModel.setCampaignName("Sanction Request");
|
|
|
498 |
sendNotificationModel.setTitle("title");
|
|
|
499 |
sendNotificationModel.setMessage(empMessage);
|
|
|
500 |
sendNotificationModel.setType("url");
|
|
|
501 |
sendNotificationModel.setUrl("https://app.smartdukaan.com/pages/home/credit");
|
|
|
502 |
sendNotificationModel.setExpiresat(LocalDateTime.now().plusDays(2));
|
|
|
503 |
sendNotificationModel.setMessageType(MessageType.notification);
|
|
|
504 |
sendNotificationModel.setUserIds(Arrays.asList(userRepository.selectByEmailId(authUser.getEmailId()).getId()));
|
|
|
505 |
System.out.println(sendNotificationModel);
|
|
|
506 |
notificationService.sendNotification(sendNotificationModel);
|
| 30859 |
tejbeer |
507 |
|
| 32840 |
amit.gupta |
508 |
//notificationService.sendWhatsappMessage(empMessage, title, authUser.getMobileNumber());
|
| 30859 |
tejbeer |
509 |
|
| 32052 |
tejbeer |
510 |
}
|
| 30859 |
tejbeer |
511 |
|
| 32135 |
tejbeer |
512 |
sanctionRequest.setFreeDays(sanctionRequestModel.getFreeDays());
|
| 30967 |
tejbeer |
513 |
|
| 34125 |
ranu |
514 |
sanctionRequest.setApprovalAmount(sanctionRequestModel.getApprovalAmount());
|
|
|
515 |
if (sanctionRequestModel.getApprovalAmount() == null) {
|
|
|
516 |
sanctionRequest.setStatus(SanctionStatus.REJECTED);
|
| 34355 |
ranu |
517 |
sanctionRequest.setRbmL2ApprovalStatus(SanctionStatus.REJECTED);
|
| 34125 |
ranu |
518 |
} else {
|
|
|
519 |
sanctionRequest.setStatus(sanctionRequestModel.getStatus());
|
|
|
520 |
}
|
| 32135 |
tejbeer |
521 |
|
| 32052 |
tejbeer |
522 |
sanctionRequest.setStockHold(sanctionRequestModel.isStockHold());
|
| 32683 |
amit.gupta |
523 |
|
| 32528 |
tejbeer |
524 |
LocalDateTime curDate = LocalDate.now().atStartOfDay();
|
| 30967 |
tejbeer |
525 |
|
| 33505 |
amit.gupta |
526 |
/*Map<Integer, Double> lmtdSale = fofoOrderItemRepository.selectSumMopGroupByRetailer(
|
| 32528 |
tejbeer |
527 |
curDate.withDayOfMonth(1).minusMonths(1), curDate.with(LocalTime.MAX).minusMonths(1), sanctionRequest.getFofoId(), false);
|
|
|
528 |
|
|
|
529 |
Map<Integer, Double> mtdSale = fofoOrderItemRepository.selectSumMopGroupByRetailer(curDate.withDayOfMonth(1), curDate.with(LocalTime.MAX), sanctionRequest.getFofoId(), false);
|
|
|
530 |
|
|
|
531 |
Map<Integer, Double> lmsSale = fofoOrderItemRepository.selectSumMopGroupByRetailer(
|
| 33505 |
amit.gupta |
532 |
curDate.withDayOfMonth(1).minusMonths(1), curDate.withDayOfMonth(1), sanctionRequest.getFofoId(), false);*/
|
| 32528 |
tejbeer |
533 |
|
| 33505 |
amit.gupta |
534 |
Map<Integer, Double> secondaryMtd = orderRepository
|
|
|
535 |
.selectBillingDatesBetweenSumGroupByRetailerId(curDate.withDayOfMonth(1), curDate.with(LocalTime.MAX));
|
|
|
536 |
Map<Integer, Double> secondarylmtd = orderRepository.selectBillingDatesBetweenSumGroupByRetailerId(
|
|
|
537 |
curDate.withDayOfMonth(1).minusMonths(1), curDate.with(LocalTime.MAX).minusMonths(1));
|
|
|
538 |
Map<Integer, Double> secondarylms = orderRepository.selectBillingDatesBetweenSumGroupByRetailerId(
|
|
|
539 |
curDate.withDayOfMonth(1).minusMonths(1), curDate.withDayOfMonth(1));
|
| 32528 |
tejbeer |
540 |
|
| 32052 |
tejbeer |
541 |
Map<Integer, PartnerDailyInvestment> partnerDailyInvestmentMap = partnerDailyInvestmentRepository.selectAll(fofoIds, LocalDate.now().minusDays(1)).stream().collect(Collectors.toMap(x -> x.getFofoId(), x -> x));
|
| 30859 |
tejbeer |
542 |
|
| 32052 |
tejbeer |
543 |
Map<Integer, UserWallet> userWalletMap = userWalletRepository.selectByRetailerIds(new HashSet<>(fofoIds)).stream().collect(Collectors.toMap(x -> x.getUserId(), x -> x));
|
| 30859 |
tejbeer |
544 |
|
| 32052 |
tejbeer |
545 |
sanctionRequest = sanctionRequestRepository.selectById(sanctionRequestModel.getId());
|
|
|
546 |
model.addAttribute("customRetailerMap", customRetailerMap);
|
|
|
547 |
model.addAttribute("sanctionRequest", sanctionRequest);
|
|
|
548 |
model.addAttribute("partnerDailyInvestmentMap", partnerDailyInvestmentMap);
|
|
|
549 |
model.addAttribute("sdCreditRequirementMap", sdCreditRequirementMap);
|
|
|
550 |
model.addAttribute("userWalletMap", userWalletMap);
|
| 30859 |
tejbeer |
551 |
|
| 32052 |
tejbeer |
552 |
model.addAttribute("sanctionStatus", SanctionStatus.values());
|
| 32683 |
amit.gupta |
553 |
|
| 33505 |
amit.gupta |
554 |
model.addAttribute("secondarylmtd", secondarylmtd);
|
|
|
555 |
model.addAttribute("secondaryMtd", secondaryMtd);
|
|
|
556 |
model.addAttribute("secondarylms", secondarylms);
|
| 30859 |
tejbeer |
557 |
|
| 33354 |
amit.gupta |
558 |
List<CreditAccount> creditAccounts = creditAccountRepository.selectByFofoIds(Arrays.asList(sanctionRequest.getFofoId()));
|
| 33854 |
tejus.loha |
559 |
model.addAttribute("creditAccounts", creditAccounts.stream().collect(Collectors.toMap(x -> x.getFofoId(), x -> x.getGateway())));
|
| 32052 |
tejbeer |
560 |
return "sanction-request-row";
|
| 30936 |
tejbeer |
561 |
|
| 32052 |
tejbeer |
562 |
}
|
| 30929 |
tejbeer |
563 |
|
| 34355 |
ranu |
564 |
@RequestMapping(value = "/rbmL2ApprovalSanctionRequest", method = RequestMethod.POST)
|
|
|
565 |
public String rbmL2ApprovalSanctionRequest(HttpServletRequest request, @RequestBody SanctionRequestModel sanctionRequestModel, Model model) throws Exception {
|
| 34357 |
ranu |
566 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
567 |
AuthUser approverAuthUser = authRepository.selectByEmailOrMobile(loginDetails.getEmailId());
|
| 34355 |
ranu |
568 |
LOGGER.info("sanctionRequestModel {} ", sanctionRequestModel);
|
|
|
569 |
Map<Integer, SDCreditRequirement> sdCreditRequirementMap = sdCreditRequirementRepository.selectAll().stream().collect(Collectors.toMap(x -> x.getFofoId(), x -> x));
|
|
|
570 |
|
|
|
571 |
SanctionRequest sanctionRequest = sanctionRequestRepository.selectById(sanctionRequestModel.getId());
|
|
|
572 |
|
|
|
573 |
Map<Integer, String> authMap = new HashMap<>();
|
| 34357 |
ranu |
574 |
|
| 34355 |
ranu |
575 |
AuthUser authUser = authRepository.selectById(sanctionRequest.getAuthId());
|
|
|
576 |
|
|
|
577 |
authMap.put(authUser.getId(), authUser.getFullName());
|
|
|
578 |
|
|
|
579 |
model.addAttribute("authMap", authMap);
|
|
|
580 |
List<Integer> fofoIds = sanctionRequestRepository.selectByDate(LocalDate.now()).stream().map(x -> x.getFofoId()).collect(Collectors.toList());
|
|
|
581 |
|
|
|
582 |
Map<Integer, CustomRetailer> customRetailerMap = retailerService.getFofoRetailers(fofoIds);
|
|
|
583 |
|
|
|
584 |
LOGGER.info("freeDays {} ", sdCreditRequirementMap.get(sanctionRequest.getFofoId()).getFreeDays());
|
|
|
585 |
|
|
|
586 |
if (sanctionRequestModel.getStatus().equals(SanctionStatus.APPROVED)) {
|
|
|
587 |
sanctionRequest.setRbmL2ApprovalTimestamp(LocalDateTime.now());
|
| 34357 |
ranu |
588 |
sanctionRequest.setRbmL2ApproverEmail(approverAuthUser.getEmailId());
|
| 34355 |
ranu |
589 |
}
|
|
|
590 |
|
|
|
591 |
sanctionRequest.setFreeDays(sanctionRequestModel.getFreeDays());
|
|
|
592 |
|
|
|
593 |
sanctionRequest.setApprovalAmount(sanctionRequestModel.getApprovalAmount());
|
|
|
594 |
if (sanctionRequestModel.getApprovalAmount() == null) {
|
|
|
595 |
|
|
|
596 |
sanctionRequest.setStatus(SanctionStatus.REJECTED);
|
|
|
597 |
|
|
|
598 |
sanctionRequest.setRbmL2ApprovalStatus(SanctionStatus.REJECTED);
|
|
|
599 |
sanctionRequest.setRbmL2ApprovalTimestamp(LocalDateTime.now());
|
| 34357 |
ranu |
600 |
sanctionRequest.setRbmL2ApproverEmail(approverAuthUser.getEmailId());
|
| 34355 |
ranu |
601 |
} else {
|
|
|
602 |
sanctionRequest.setRbmL2ApprovalStatus(sanctionRequestModel.getStatus());
|
|
|
603 |
}
|
|
|
604 |
|
|
|
605 |
sanctionRequest.setStockHold(sanctionRequestModel.isStockHold());
|
|
|
606 |
|
|
|
607 |
LocalDateTime curDate = LocalDate.now().atStartOfDay();
|
|
|
608 |
|
|
|
609 |
|
|
|
610 |
Map<Integer, Double> secondaryMtd = orderRepository
|
|
|
611 |
.selectBillingDatesBetweenSumGroupByRetailerId(curDate.withDayOfMonth(1), curDate.with(LocalTime.MAX));
|
|
|
612 |
Map<Integer, Double> secondarylmtd = orderRepository.selectBillingDatesBetweenSumGroupByRetailerId(
|
|
|
613 |
curDate.withDayOfMonth(1).minusMonths(1), curDate.with(LocalTime.MAX).minusMonths(1));
|
|
|
614 |
Map<Integer, Double> secondarylms = orderRepository.selectBillingDatesBetweenSumGroupByRetailerId(
|
|
|
615 |
curDate.withDayOfMonth(1).minusMonths(1), curDate.withDayOfMonth(1));
|
|
|
616 |
|
|
|
617 |
Map<Integer, PartnerDailyInvestment> partnerDailyInvestmentMap = partnerDailyInvestmentRepository.selectAll(fofoIds, LocalDate.now().minusDays(1)).stream().collect(Collectors.toMap(x -> x.getFofoId(), x -> x));
|
|
|
618 |
|
|
|
619 |
Map<Integer, UserWallet> userWalletMap = userWalletRepository.selectByRetailerIds(new HashSet<>(fofoIds)).stream().collect(Collectors.toMap(x -> x.getUserId(), x -> x));
|
|
|
620 |
|
|
|
621 |
sanctionRequest = sanctionRequestRepository.selectById(sanctionRequestModel.getId());
|
|
|
622 |
model.addAttribute("customRetailerMap", customRetailerMap);
|
|
|
623 |
model.addAttribute("sanctionRequest", sanctionRequest);
|
|
|
624 |
model.addAttribute("partnerDailyInvestmentMap", partnerDailyInvestmentMap);
|
|
|
625 |
model.addAttribute("sdCreditRequirementMap", sdCreditRequirementMap);
|
|
|
626 |
model.addAttribute("userWalletMap", userWalletMap);
|
|
|
627 |
|
|
|
628 |
model.addAttribute("sanctionStatus", SanctionStatus.values());
|
|
|
629 |
|
|
|
630 |
model.addAttribute("secondarylmtd", secondarylmtd);
|
|
|
631 |
model.addAttribute("secondaryMtd", secondaryMtd);
|
|
|
632 |
model.addAttribute("secondarylms", secondarylms);
|
|
|
633 |
|
|
|
634 |
List<CreditAccount> creditAccounts = creditAccountRepository.selectByFofoIds(Arrays.asList(sanctionRequest.getFofoId()));
|
|
|
635 |
model.addAttribute("creditAccounts", creditAccounts.stream().collect(Collectors.toMap(x -> x.getFofoId(), x -> x.getGateway())));
|
|
|
636 |
return "rbm-l2-pending-sanction-request";
|
|
|
637 |
|
|
|
638 |
}
|
|
|
639 |
|
| 32052 |
tejbeer |
640 |
List<String> emails = Arrays.asList("kamini.sharma@smartdukaan.com", "neeraj.gupta@smartdukaan.com", "amit.gupta@smartdukaan.com");
|
| 30929 |
tejbeer |
641 |
|
| 32052 |
tejbeer |
642 |
@RequestMapping(value = "/getLoans", method = RequestMethod.GET)
|
|
|
643 |
public String getLoans(HttpServletRequest request, Model model) throws ProfitMandiBusinessException {
|
| 30936 |
tejbeer |
644 |
|
| 32052 |
tejbeer |
645 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
646 |
String email = loginDetails.getEmailId();
|
| 30936 |
tejbeer |
647 |
|
| 32052 |
tejbeer |
648 |
AuthUser authUser = authRepository.selectByEmailOrMobile(email);
|
|
|
649 |
Set<Integer> fofoIds = csService1.getAuthFofoIds(email, false);
|
| 30936 |
tejbeer |
650 |
|
| 32052 |
tejbeer |
651 |
LOGGER.info("fofoIds" + fofoIds);
|
|
|
652 |
if (fofoIds == null) {
|
|
|
653 |
throw new ProfitMandiBusinessException("you are not authorized", "", "you are not authorized" + " " + "");
|
|
|
654 |
}
|
| 30936 |
tejbeer |
655 |
|
| 33827 |
ranu |
656 |
List<LoanCountByFofoIdModel> loanCountByFofoIdModels = loanRepository.getAllLoanCountByFofoId(fofoIds);
|
|
|
657 |
Map<Integer, Long> loanCountMap = loanCountByFofoIdModels.stream().collect(Collectors.toMap(LoanCountByFofoIdModel::getFofoId, LoanCountByFofoIdModel::getLoanCount));
|
| 30929 |
tejbeer |
658 |
|
| 33827 |
ranu |
659 |
// List<Loan> loans = loanRepository.selectAllLoans(new ArrayList<>(fofoIds));
|
| 30929 |
tejbeer |
660 |
|
| 33827 |
ranu |
661 |
List<Integer> loanFofoIds = loanCountByFofoIdModels.stream().map(x -> x.getFofoId()).collect(Collectors.toList());
|
|
|
662 |
|
| 32052 |
tejbeer |
663 |
List<SDCreditRequirement> sdCreditRequirements = sdCreditRequirementRepository.selectByFofoIds(new ArrayList<>(loanFofoIds));
|
| 30929 |
tejbeer |
664 |
|
| 33827 |
ranu |
665 |
// Map<Integer, Long> loanCountMap = loans.stream().collect(Collectors.groupingBy(x -> x.getFofoId(), Collectors.counting()));
|
|
|
666 |
// LOGGER.info("loanCountMap" + loanCountMap);
|
| 30929 |
tejbeer |
667 |
|
| 32052 |
tejbeer |
668 |
Map<Integer, UserWallet> userWalletMap = userWalletRepository.selectByRetailerIds(fofoIds).stream().collect(Collectors.toMap(x -> x.getUserId(), x -> x));
|
|
|
669 |
Map<Integer, CurrentPartnerDailyInvestment> currentPartnerDailyInvestmentMap = currentPartnerDailyInvestmentRepository.selectAll().stream().collect(Collectors.toMap(x -> x.getFofoId(), x -> x));
|
| 30929 |
tejbeer |
670 |
|
| 32052 |
tejbeer |
671 |
model.addAttribute("userWalletMap", userWalletMap);
|
| 30929 |
tejbeer |
672 |
|
| 32052 |
tejbeer |
673 |
model.addAttribute("currentPartnerDailyInvestmentMap", currentPartnerDailyInvestmentMap);
|
| 30929 |
tejbeer |
674 |
|
| 32052 |
tejbeer |
675 |
Map<Integer, CustomRetailer> customRetailerMap = retailerService.getFofoRetailers(new ArrayList<>(fofoIds));
|
|
|
676 |
model.addAttribute("sdCreditRequirements", sdCreditRequirements);
|
|
|
677 |
model.addAttribute("loanCountMap", loanCountMap);
|
|
|
678 |
model.addAttribute("customRetailerMap", customRetailerMap);
|
|
|
679 |
return "loan-summary";
|
| 30929 |
tejbeer |
680 |
|
| 32052 |
tejbeer |
681 |
}
|
| 32439 |
tejbeer |
682 |
|
| 32197 |
jai.hind |
683 |
@RequestMapping(value = "/getPartnerWiseLoanSummary", method = RequestMethod.GET)
|
|
|
684 |
public String getPartnerWiseLoanSummary(HttpServletRequest request, @RequestParam LoanSummaryType loanSummaryType, Model model) throws ProfitMandiBusinessException {
|
|
|
685 |
Map<Integer, FofoReportingModel> fofoReportingModelMap = csService.getPartnerIdSalesHeaders();
|
| 33533 |
amit.gupta |
686 |
List<Loan> loans = loanRepository.selectAllActiveLoan();
|
|
|
687 |
if (loanSummaryType.equals(LoanSummaryType.DEFAULT_LOAN)) {
|
| 33854 |
tejus.loha |
688 |
loans = loans.stream().filter(x -> x.isDefault()).collect(Collectors.toList());
|
| 32197 |
jai.hind |
689 |
} else if (loanSummaryType.equals(LoanSummaryType.DUE_LOAN)) {
|
| 33854 |
tejus.loha |
690 |
loans = loans.stream().filter(x -> x.isOverdue()).collect(Collectors.toList());
|
| 32197 |
jai.hind |
691 |
}
|
| 32439 |
tejbeer |
692 |
List<Integer> fofoIds = loans.stream().map(x -> x.getFofoId()).collect(Collectors.toList());
|
|
|
693 |
Map<Integer, Double> fofoIdLoansMap = loans.stream().collect(Collectors.groupingBy(x -> x.getFofoId(), Collectors.summingDouble(x -> x.getPendingAmount().doubleValue())));
|
| 32197 |
jai.hind |
694 |
Map<Integer, CustomRetailer> customRetailerMap = retailerService.getFofoRetailers(fofoIds);
|
| 32528 |
tejbeer |
695 |
Map<Integer, Long> loanCountMap = loans.stream().collect(Collectors.groupingBy(x -> x.getFofoId(), Collectors.counting()));
|
| 32197 |
jai.hind |
696 |
model.addAttribute("customRetailerMap", customRetailerMap);
|
|
|
697 |
model.addAttribute("loans", loans);
|
|
|
698 |
model.addAttribute("fofoReportingModelMap", fofoReportingModelMap);
|
|
|
699 |
model.addAttribute("fofoIdLoansMap", fofoIdLoansMap);
|
| 32456 |
jai.hind |
700 |
model.addAttribute("loanCountMap", loanCountMap);
|
| 32197 |
jai.hind |
701 |
return "partner-wise-loan-summary";
|
|
|
702 |
}
|
|
|
703 |
|
| 35320 |
ranu |
704 |
@RequestMapping(value = "/getPartnerStateWiseLoanSummary", method = RequestMethod.GET)
|
| 35335 |
ranu |
705 |
public String getPartnerStateWiseLoanSummary(HttpServletRequest request, @RequestParam LoanSummaryType loanSummaryType, @RequestParam String stateName, @RequestParam(required = false) Integer fromDays, @RequestParam(required = false) Integer toDays, Model model) throws ProfitMandiBusinessException {
|
| 35320 |
ranu |
706 |
Map<Integer, FofoReportingModel> fofoReportingModelMap = csService.getPartnerIdSalesHeaders();
|
|
|
707 |
List<Loan> loans = loanRepository.selectAllStateWiseActiveLoan(stateName);
|
|
|
708 |
if (loanSummaryType.equals(LoanSummaryType.DEFAULT_LOAN)) {
|
|
|
709 |
loans = loans.stream().filter(x -> x.isDefault()).collect(Collectors.toList());
|
|
|
710 |
} else if (loanSummaryType.equals(LoanSummaryType.DUE_LOAN)) {
|
|
|
711 |
loans = loans.stream().filter(x -> x.isOverdue()).collect(Collectors.toList());
|
|
|
712 |
}
|
|
|
713 |
|
| 35335 |
ranu |
714 |
// Apply aging filter
|
|
|
715 |
if (fromDays != null && toDays != null) {
|
| 35320 |
ranu |
716 |
loans = loans.stream()
|
| 35335 |
ranu |
717 |
.filter(x -> x.getLoanAgeInDays() >= fromDays &&
|
|
|
718 |
x.getLoanAgeInDays() <= toDays)
|
| 35320 |
ranu |
719 |
.collect(Collectors.toList());
|
| 35335 |
ranu |
720 |
|
|
|
721 |
} else if (fromDays != null) {
|
|
|
722 |
loans = loans.stream()
|
|
|
723 |
.filter(x -> x.getLoanAgeInDays() >= fromDays)
|
|
|
724 |
.collect(Collectors.toList());
|
|
|
725 |
|
| 35320 |
ranu |
726 |
}
|
|
|
727 |
|
|
|
728 |
List<Integer> fofoIds = loans.stream().map(x -> x.getFofoId()).collect(Collectors.toList());
|
|
|
729 |
Map<Integer, Double> fofoIdLoansMap = loans.stream().collect(Collectors.groupingBy(x -> x.getFofoId(), Collectors.summingDouble(x -> x.getPendingAmount().doubleValue())));
|
|
|
730 |
Map<Integer, CustomRetailer> customRetailerMap = retailerService.getFofoRetailers(fofoIds);
|
|
|
731 |
Map<Integer, Long> loanCountMap = loans.stream().collect(Collectors.groupingBy(x -> x.getFofoId(), Collectors.counting()));
|
|
|
732 |
model.addAttribute("customRetailerMap", customRetailerMap);
|
|
|
733 |
model.addAttribute("loans", loans);
|
|
|
734 |
model.addAttribute("fofoReportingModelMap", fofoReportingModelMap);
|
|
|
735 |
model.addAttribute("fofoIdLoansMap", fofoIdLoansMap);
|
|
|
736 |
model.addAttribute("loanCountMap", loanCountMap);
|
|
|
737 |
return "partner-wise-loan-summary";
|
|
|
738 |
}
|
|
|
739 |
|
| 32052 |
tejbeer |
740 |
@RequestMapping(value = "/getLoanSummary", method = RequestMethod.GET)
|
|
|
741 |
public String getLoanSummary(HttpServletRequest request, @RequestParam int fofoId, Model model) throws ProfitMandiBusinessException {
|
| 30929 |
tejbeer |
742 |
|
| 32052 |
tejbeer |
743 |
SDCreditResponseOut sdCreditResponseOut = sdCreditService.sdDirectService(fofoId);
|
|
|
744 |
CustomRetailer customRetailer = retailerService.getFofoRetailer(fofoId);
|
| 30929 |
tejbeer |
745 |
|
| 32052 |
tejbeer |
746 |
model.addAttribute("customRetailer", customRetailer);
|
|
|
747 |
model.addAttribute("loanSummary", sdCreditResponseOut.getLoans());
|
| 30929 |
tejbeer |
748 |
|
| 32052 |
tejbeer |
749 |
return "loan-summary-detail";
|
| 31020 |
tejbeer |
750 |
|
| 32052 |
tejbeer |
751 |
}
|
| 31020 |
tejbeer |
752 |
|
| 32439 |
tejbeer |
753 |
@RequestMapping(value = "/getSanctionUnholdOrder", method = RequestMethod.GET)
|
|
|
754 |
public String getSanctionUnholdOrder(HttpServletRequest request, Model model) throws ProfitMandiBusinessException {
|
| 31020 |
tejbeer |
755 |
|
| 32052 |
tejbeer |
756 |
List<Order> allOrders = orderRepository.selectHoldOrder();
|
| 31020 |
tejbeer |
757 |
|
| 32439 |
tejbeer |
758 |
List<SanctionRequest> sanctionRequests = sanctionRequestRepository.selectHoldSanction();
|
| 31020 |
tejbeer |
759 |
|
| 32442 |
tejbeer |
760 |
|
|
|
761 |
Map<Integer, CustomRetailer> customRetailerMap = retailerService.getAllFofoRetailers();
|
| 32052 |
tejbeer |
762 |
if (!allOrders.isEmpty()) {
|
|
|
763 |
Map<Integer, Double> transactionAmountMap = allOrders.stream().collect(
|
|
|
764 |
Collectors.groupingBy(Order::getTransactionId, Collectors.summingDouble(x -> x.getTotalAmount())));
|
| 31020 |
tejbeer |
765 |
|
| 32052 |
tejbeer |
766 |
Map<Integer, List<Order>> transactionOrdersMap = allOrders.stream().collect(Collectors.groupingBy(Order::getTransactionId, Collectors.toList()));
|
| 31020 |
tejbeer |
767 |
|
|
|
768 |
|
| 32052 |
tejbeer |
769 |
model.addAttribute("transactionAmountMap", transactionAmountMap);
|
| 31020 |
tejbeer |
770 |
|
| 32052 |
tejbeer |
771 |
model.addAttribute("transactionOrdersMap", transactionOrdersMap);
|
| 31020 |
tejbeer |
772 |
|
| 32439 |
tejbeer |
773 |
}
|
|
|
774 |
model.addAttribute("sanctionRequests", sanctionRequests);
|
| 31020 |
tejbeer |
775 |
|
| 32442 |
tejbeer |
776 |
model.addAttribute("customRetailerMap", customRetailerMap);
|
| 31020 |
tejbeer |
777 |
|
| 32442 |
tejbeer |
778 |
|
| 32439 |
tejbeer |
779 |
return "sanction-order-unhold";
|
| 31020 |
tejbeer |
780 |
|
| 32439 |
tejbeer |
781 |
}
|
| 31020 |
tejbeer |
782 |
|
|
|
783 |
|
| 32439 |
tejbeer |
784 |
@RequestMapping(value = "/getSanctionHoldOrder", method = RequestMethod.GET)
|
|
|
785 |
public String getSanctionHoldOrder(HttpServletRequest request, Model model) throws ProfitMandiBusinessException {
|
| 31020 |
tejbeer |
786 |
|
| 32439 |
tejbeer |
787 |
List<Order> allOrders = orderRepository.selectHoldOrder();
|
| 31020 |
tejbeer |
788 |
|
| 32439 |
tejbeer |
789 |
List<SanctionRequest> sanctionRequests = sanctionRequestRepository.selectHoldSanction();
|
| 32442 |
tejbeer |
790 |
Map<Integer, CustomRetailer> customRetailerMap = retailerService.getAllFofoRetailers();
|
| 31020 |
tejbeer |
791 |
|
| 32439 |
tejbeer |
792 |
if (!allOrders.isEmpty()) {
|
|
|
793 |
Map<Integer, Double> transactionAmountMap = allOrders.stream().collect(
|
|
|
794 |
Collectors.groupingBy(Order::getTransactionId, Collectors.summingDouble(x -> x.getTotalAmount())));
|
| 31020 |
tejbeer |
795 |
|
| 32439 |
tejbeer |
796 |
Map<Integer, List<Order>> transactionOrdersMap = allOrders.stream().collect(Collectors.groupingBy(Order::getTransactionId, Collectors.toList()));
|
|
|
797 |
|
|
|
798 |
|
|
|
799 |
model.addAttribute("transactionAmountMap", transactionAmountMap);
|
|
|
800 |
|
|
|
801 |
model.addAttribute("transactionOrdersMap", transactionOrdersMap);
|
|
|
802 |
|
| 32052 |
tejbeer |
803 |
}
|
| 32439 |
tejbeer |
804 |
model.addAttribute("sanctionRequests", sanctionRequests);
|
| 32442 |
tejbeer |
805 |
model.addAttribute("customRetailerMap", customRetailerMap);
|
| 31020 |
tejbeer |
806 |
|
| 32439 |
tejbeer |
807 |
|
| 32052 |
tejbeer |
808 |
return "sanction-order-hold";
|
| 31020 |
tejbeer |
809 |
|
| 32052 |
tejbeer |
810 |
}
|
| 31020 |
tejbeer |
811 |
|
| 32052 |
tejbeer |
812 |
@RequestMapping(value = "/unholdOrder", method = RequestMethod.POST)
|
|
|
813 |
public String unholdOrder(HttpServletRequest request, @RequestParam int transactionId, Model model) throws Exception {
|
| 31020 |
tejbeer |
814 |
|
| 32052 |
tejbeer |
815 |
List<Order> orders = orderRepository.selectAllByTransactionId(transactionId);
|
| 31020 |
tejbeer |
816 |
|
| 32455 |
tejbeer |
817 |
SanctionRequest sanctionRequest = sanctionRequestRepository.selectByTransactionId(transactionId);
|
|
|
818 |
|
|
|
819 |
|
| 32052 |
tejbeer |
820 |
LOGGER.info("orders" + orders);
|
| 31020 |
tejbeer |
821 |
|
| 32455 |
tejbeer |
822 |
if (sanctionRequest != null) {
|
|
|
823 |
sanctionRequest.setPendingAmount(BigDecimal.ZERO);
|
|
|
824 |
}
|
|
|
825 |
|
| 32052 |
tejbeer |
826 |
if (!orders.isEmpty()) {
|
|
|
827 |
orders.forEach(x -> x.setShipmentHold(false));
|
|
|
828 |
}
|
| 31020 |
tejbeer |
829 |
|
| 32052 |
tejbeer |
830 |
double totalAmount = orders.stream().collect(Collectors.summingDouble(x -> x.getTotalAmount()));
|
| 31020 |
tejbeer |
831 |
|
| 32052 |
tejbeer |
832 |
try {
|
| 31020 |
tejbeer |
833 |
|
| 32052 |
tejbeer |
834 |
List<String> authUserEmail = csService.getAuthUserIdByPartnerId(orders.get(0).getRetailerId()).stream().map(x -> x.getEmailId()).collect(Collectors.toList());
|
| 31020 |
tejbeer |
835 |
|
| 32052 |
tejbeer |
836 |
authUserEmail.add("vinay.p@smartdukaan.com");
|
|
|
837 |
authUserEmail.add("shivam.gupta@smartdukaan.com");
|
| 31020 |
tejbeer |
838 |
|
| 32052 |
tejbeer |
839 |
String[] emailTo = authUserEmail.toArray(new String[authUserEmail.size()]);
|
| 31020 |
tejbeer |
840 |
|
| 32052 |
tejbeer |
841 |
String[] ccTo = {"tarun.verma@smartdukaan.com", "kamini.sharma@smartdukaan.com"};
|
| 31020 |
tejbeer |
842 |
|
| 32052 |
tejbeer |
843 |
String subject = "Dispatched " + (orders.get(0).getRetailerName());
|
|
|
844 |
String message = String.format("Dear Team, \n" + "Kindly note the meterial for the " + orders.get(0).getRetailerName() + "of Rs." + totalAmount + " is dispatched.");
|
| 31020 |
tejbeer |
845 |
|
| 32052 |
tejbeer |
846 |
LOGGER.info("message" + message);
|
| 31020 |
tejbeer |
847 |
|
| 32052 |
tejbeer |
848 |
Utils.sendMailWithAttachments(mailSender, emailTo, ccTo, subject, message);
|
|
|
849 |
} catch (Exception e) {
|
| 31020 |
tejbeer |
850 |
|
| 32052 |
tejbeer |
851 |
e.printStackTrace();
|
| 31020 |
tejbeer |
852 |
|
| 32052 |
tejbeer |
853 |
}
|
| 31020 |
tejbeer |
854 |
|
| 32052 |
tejbeer |
855 |
model.addAttribute("response1", mvcResponseSender.createResponseString(true));
|
| 31020 |
tejbeer |
856 |
|
| 32052 |
tejbeer |
857 |
return "response";
|
|
|
858 |
|
|
|
859 |
}
|
|
|
860 |
|
| 33851 |
ranu |
861 |
|
|
|
862 |
// adjusting loan for specific loan if loan is not adjusting and other loan is adjusting
|
|
|
863 |
|
| 33858 |
ranu |
864 |
@RequestMapping(value = "/settle-loan/{fofoId}/{loanId}", method = RequestMethod.GET)
|
|
|
865 |
public String settleAndCreateLoanById(HttpServletRequest request, @PathVariable int loanId, @PathVariable int fofoId, Model model) throws Exception {
|
| 33852 |
ranu |
866 |
Loan loan = loanRepository.selectByLoanId(loanId);
|
|
|
867 |
double loanAmount = loan.getPendingAmount().doubleValue();
|
| 33851 |
ranu |
868 |
|
|
|
869 |
if (loanAmount > 0) {
|
|
|
870 |
sdCreditService.createLoan(fofoId, loanAmount, 0, "Amount added for loan adjustment");
|
| 33852 |
ranu |
871 |
sdCreditService.settleLoan(loan);
|
| 33851 |
ranu |
872 |
}
|
|
|
873 |
|
|
|
874 |
|
|
|
875 |
model.addAttribute("response1", mvcResponseSender.createResponseString(true));
|
|
|
876 |
|
|
|
877 |
return "response";
|
|
|
878 |
|
|
|
879 |
}
|
|
|
880 |
|
| 34588 |
ranu |
881 |
@RequestMapping(value = "/settle-negative-wallet/{fofoId}", method = RequestMethod.GET)
|
|
|
882 |
public String settleNegativeWalletCreateLoanById(HttpServletRequest request, @PathVariable int fofoId, Model model) throws Exception {
|
|
|
883 |
this.sdCreditService.fundWallet(fofoId);
|
| 33851 |
ranu |
884 |
|
| 34588 |
ranu |
885 |
model.addAttribute("response1", mvcResponseSender.createResponseString(true));
|
|
|
886 |
|
|
|
887 |
return "response";
|
|
|
888 |
|
|
|
889 |
}
|
|
|
890 |
|
| 33851 |
ranu |
891 |
private void sendUnholdEmail(List<Order> orders) throws Exception {
|
|
|
892 |
|
|
|
893 |
|
|
|
894 |
orders.forEach(x -> x.setShipmentHold(false));
|
|
|
895 |
orders = orders.stream().filter(x -> x.getRefundTimestamp() != null).collect(Collectors.toList());
|
|
|
896 |
if (orders.size() > 0) {
|
|
|
897 |
|
|
|
898 |
double totalAmount = orders.stream().collect(Collectors.summingDouble(x -> x.getTotalAmount()));
|
|
|
899 |
|
|
|
900 |
List<String> authUserEmail = csService.getAuthUserIdByPartnerId(orders.get(0).getRetailerId()).stream().map(x -> x.getEmailId()).collect(Collectors.toList());
|
|
|
901 |
authUserEmail.add("vinay.p@smartdukaan.com");
|
|
|
902 |
authUserEmail.add("shivam.gupta@smartdukaan.com");
|
|
|
903 |
|
|
|
904 |
String[] emailTo = authUserEmail.toArray(new String[authUserEmail.size()]);
|
|
|
905 |
|
|
|
906 |
String[] ccTo = {"tarun.verma@smartdukaan.com", "kamini.sharma@smartdukaan.com"};
|
|
|
907 |
|
|
|
908 |
String subject = "Dispatch held orders of - " + (orders.get(0).getRetailerName());
|
|
|
909 |
String message = String.format("Dear Team, \n" + "kindly note the material for the " + orders.get(0).getRetailerName() + "of Rs." + totalAmount + "is unhold now and needs to be dispatched.");
|
|
|
910 |
Utils.sendMailWithAttachments(mailSender, emailTo, ccTo, subject, message);
|
|
|
911 |
}
|
|
|
912 |
|
|
|
913 |
|
|
|
914 |
}
|
|
|
915 |
|
| 30859 |
tejbeer |
916 |
}
|