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