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