| 22551 |
ashik.ali |
1 |
package com.spice.profitmandi.web.controller;
|
|
|
2 |
|
| 30859 |
tejbeer |
3 |
import com.spice.profitmandi.common.enumuration.MessageType;
|
| 22551 |
ashik.ali |
4 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 23936 |
tejbeer |
5 |
import com.spice.profitmandi.common.model.CustomRetailer;
|
| 22551 |
ashik.ali |
6 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 24089 |
tejbeer |
7 |
import com.spice.profitmandi.common.model.UnsettledPaymentModel;
|
| 31238 |
amit.gupta |
8 |
import com.spice.profitmandi.common.util.*;
|
| 29811 |
tejbeer |
9 |
import com.spice.profitmandi.dao.entity.dtr.CreditAccount;
|
| 29962 |
tejbeer |
10 |
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
|
| 31238 |
amit.gupta |
11 |
import com.spice.profitmandi.dao.entity.transaction.*;
|
| 23936 |
tejbeer |
12 |
import com.spice.profitmandi.dao.enumuration.transaction.AddWalletRequestStatus;
|
| 24876 |
tejbeer |
13 |
import com.spice.profitmandi.dao.enumuration.transaction.TransactionType;
|
| 23936 |
tejbeer |
14 |
import com.spice.profitmandi.dao.repository.catalog.AddWalletRequestRepository;
|
| 24876 |
tejbeer |
15 |
import com.spice.profitmandi.dao.repository.catalog.ManualPaymentRequestRepository;
|
| 24089 |
tejbeer |
16 |
import com.spice.profitmandi.dao.repository.catalog.UnsettledPaymentsRepository;
|
| 29811 |
tejbeer |
17 |
import com.spice.profitmandi.dao.repository.dtr.CreditAccountRepository;
|
| 24876 |
tejbeer |
18 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
| 23985 |
tejbeer |
19 |
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
|
| 28515 |
amit.gupta |
20 |
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
|
|
|
21 |
import com.spice.profitmandi.dao.repository.transaction.StatementDetailModel;
|
| 24876 |
tejbeer |
22 |
import com.spice.profitmandi.dao.repository.transaction.UserWalletHistoryRepository;
|
| 22551 |
ashik.ali |
23 |
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
|
| 30859 |
tejbeer |
24 |
import com.spice.profitmandi.service.NotificationService;
|
| 24523 |
amit.gupta |
25 |
import com.spice.profitmandi.service.authentication.RoleManager;
|
| 29070 |
amit.gupta |
26 |
import com.spice.profitmandi.service.transaction.TransactionService;
|
| 23936 |
tejbeer |
27 |
import com.spice.profitmandi.service.user.RetailerService;
|
| 22551 |
ashik.ali |
28 |
import com.spice.profitmandi.service.wallet.WalletService;
|
|
|
29 |
import com.spice.profitmandi.web.model.LoginDetails;
|
|
|
30 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
| 23936 |
tejbeer |
31 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
|
|
32 |
import in.shop2020.model.v1.order.WalletReferenceType;
|
| 31238 |
amit.gupta |
33 |
import org.apache.logging.log4j.LogManager;
|
|
|
34 |
import org.apache.logging.log4j.Logger;
|
|
|
35 |
import org.apache.poi.ss.usermodel.Cell;
|
|
|
36 |
import org.apache.poi.ss.usermodel.CellStyle;
|
|
|
37 |
import org.apache.poi.ss.usermodel.CreationHelper;
|
|
|
38 |
import org.apache.poi.ss.usermodel.Sheet;
|
|
|
39 |
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
40 |
import org.json.JSONObject;
|
|
|
41 |
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
42 |
import org.springframework.core.io.InputStreamResource;
|
|
|
43 |
import org.springframework.http.HttpHeaders;
|
|
|
44 |
import org.springframework.http.HttpStatus;
|
|
|
45 |
import org.springframework.http.ResponseEntity;
|
|
|
46 |
import org.springframework.mail.javamail.JavaMailSender;
|
|
|
47 |
import org.springframework.mail.javamail.MimeMessageHelper;
|
|
|
48 |
import org.springframework.stereotype.Controller;
|
|
|
49 |
import org.springframework.ui.Model;
|
|
|
50 |
import org.springframework.web.bind.annotation.*;
|
|
|
51 |
import org.springframework.web.multipart.MultipartFile;
|
| 23936 |
tejbeer |
52 |
|
| 31238 |
amit.gupta |
53 |
import javax.mail.internet.InternetAddress;
|
|
|
54 |
import javax.mail.internet.MimeMessage;
|
|
|
55 |
import javax.servlet.http.HttpServletRequest;
|
|
|
56 |
import javax.swing.*;
|
|
|
57 |
import javax.transaction.Transactional;
|
|
|
58 |
import java.io.ByteArrayInputStream;
|
|
|
59 |
import java.io.ByteArrayOutputStream;
|
|
|
60 |
import java.io.InputStream;
|
|
|
61 |
import java.text.MessageFormat;
|
|
|
62 |
import java.time.LocalDate;
|
|
|
63 |
import java.time.LocalDateTime;
|
|
|
64 |
import java.time.ZoneId;
|
|
|
65 |
import java.util.*;
|
|
|
66 |
import java.util.stream.Collectors;
|
|
|
67 |
|
| 22551 |
ashik.ali |
68 |
@Controller
|
| 25251 |
amit.gupta |
69 |
@Transactional(rollbackOn = Throwable.class)
|
| 22551 |
ashik.ali |
70 |
public class WalletController {
|
|
|
71 |
|
| 28515 |
amit.gupta |
72 |
private static final int IDX_PERIOD = 1;
|
|
|
73 |
private static final int OPENING_BALANCE = 2;
|
|
|
74 |
private static final int ACTIVATION_SCHEME = 4;
|
|
|
75 |
private static final int ADVANCE_AMOUNT = 5;
|
|
|
76 |
private static final int AUTOMATED_ADVANCE = 6;
|
|
|
77 |
private static final int BRAND_PAYOUT = 7;
|
|
|
78 |
private static final int INVESTMENT_PAYOUT = 8;
|
|
|
79 |
private static final int OTHERS = 9;
|
|
|
80 |
private static final int PREBOOKING_ORDER = 10;
|
|
|
81 |
private static final int PRICE_DROP = 11;
|
|
|
82 |
private static final int PURCHASE = 12;
|
|
|
83 |
private static final int PURCHASE_BILLED = 13;
|
|
|
84 |
private static final int PURCHASE_PENDING_BILLING = 14;
|
|
|
85 |
private static final int PURCHASE_CANCELLED = 15;
|
|
|
86 |
private static final int RECHARGE = 16;
|
|
|
87 |
private static final int REFUND = 17;
|
|
|
88 |
private static final int SCHEME_IN = 18;
|
|
|
89 |
private static final int SCHEME_OUT = 19;
|
|
|
90 |
private static final Map<WalletReferenceType, Integer> walletReferenceMap = new HashMap<>();
|
|
|
91 |
static {
|
|
|
92 |
walletReferenceMap.put(WalletReferenceType.ACTIVATION_SCHEME, ACTIVATION_SCHEME);
|
|
|
93 |
walletReferenceMap.put(WalletReferenceType.ADVANCE_AMOUNT, ADVANCE_AMOUNT);
|
|
|
94 |
walletReferenceMap.put(WalletReferenceType.AUTOMATED_ADVANCE, AUTOMATED_ADVANCE);
|
|
|
95 |
walletReferenceMap.put(WalletReferenceType.BRAND_PAYOUT, BRAND_PAYOUT);
|
|
|
96 |
walletReferenceMap.put(WalletReferenceType.INVESTMENT_PAYOUT, INVESTMENT_PAYOUT);
|
|
|
97 |
walletReferenceMap.put(WalletReferenceType.OTHERS, OTHERS);
|
|
|
98 |
walletReferenceMap.put(WalletReferenceType.PREBOOKING_ORDER, PREBOOKING_ORDER);
|
|
|
99 |
walletReferenceMap.put(WalletReferenceType.PRICE_DROP, PRICE_DROP);
|
|
|
100 |
walletReferenceMap.put(WalletReferenceType.PURCHASE, PURCHASE);
|
|
|
101 |
walletReferenceMap.put(WalletReferenceType.RECHARGE, RECHARGE);
|
|
|
102 |
walletReferenceMap.put(WalletReferenceType.REFUND, REFUND);
|
|
|
103 |
walletReferenceMap.put(WalletReferenceType.SCHEME_IN, SCHEME_IN);
|
|
|
104 |
walletReferenceMap.put(WalletReferenceType.SCHEME_OUT, SCHEME_OUT);
|
|
|
105 |
|
|
|
106 |
}
|
|
|
107 |
private static final int GRAND_TOTAL = 20;
|
|
|
108 |
|
|
|
109 |
private static final int CLOSING_BALANCE = 22;
|
|
|
110 |
private static final int PENDING_GRN = 23;
|
|
|
111 |
private static final int ACTIVATED_IMEIS = 24;
|
|
|
112 |
|
| 22551 |
ashik.ali |
113 |
@Autowired
|
| 22927 |
ashik.ali |
114 |
private CookiesProcessor cookiesProcessor;
|
| 23993 |
tejbeer |
115 |
|
| 22551 |
ashik.ali |
116 |
@Autowired
|
| 22927 |
ashik.ali |
117 |
private WalletService walletService;
|
| 23993 |
tejbeer |
118 |
|
| 22551 |
ashik.ali |
119 |
@Autowired
|
| 22927 |
ashik.ali |
120 |
private UserWalletRepository userWalletRepository;
|
| 23993 |
tejbeer |
121 |
|
| 23936 |
tejbeer |
122 |
@Autowired
|
| 24876 |
tejbeer |
123 |
private UserWalletHistoryRepository userWalletHistoryRepository;
|
|
|
124 |
|
|
|
125 |
@Autowired
|
| 23936 |
tejbeer |
126 |
private MVCResponseSender mvcResponseSender;
|
| 23993 |
tejbeer |
127 |
|
| 23936 |
tejbeer |
128 |
@Autowired
|
| 23985 |
tejbeer |
129 |
private UserAccountRepository userAccountRepository;
|
|
|
130 |
|
|
|
131 |
@Autowired
|
| 28515 |
amit.gupta |
132 |
private OrderRepository orderRepository;
|
|
|
133 |
|
|
|
134 |
@Autowired
|
| 23985 |
tejbeer |
135 |
JavaMailSender mailSender;
|
| 23993 |
tejbeer |
136 |
|
| 23985 |
tejbeer |
137 |
@Autowired
|
| 24089 |
tejbeer |
138 |
private UnsettledPaymentsRepository unsettledPaymentsRepository;
|
|
|
139 |
|
|
|
140 |
@Autowired
|
| 23936 |
tejbeer |
141 |
private RetailerService retailerService;
|
| 24876 |
tejbeer |
142 |
|
| 24523 |
amit.gupta |
143 |
@Autowired
|
|
|
144 |
private RoleManager roleManager;
|
| 23936 |
tejbeer |
145 |
|
|
|
146 |
@Autowired
|
| 24876 |
tejbeer |
147 |
private FofoStoreRepository fofoStoreRepository;
|
|
|
148 |
|
|
|
149 |
@Autowired
|
|
|
150 |
private ManualPaymentRequestRepository manualPaymentRequestRepository;
|
|
|
151 |
|
|
|
152 |
@Autowired
|
| 23936 |
tejbeer |
153 |
AddWalletRequestRepository addWalletRequestRepository;
|
| 24876 |
tejbeer |
154 |
|
|
|
155 |
@Autowired
|
| 29811 |
tejbeer |
156 |
private CreditAccountRepository creditAccountRepository;
|
| 30859 |
tejbeer |
157 |
|
|
|
158 |
@Autowired
|
|
|
159 |
private NotificationService notificationService;
|
| 23568 |
govind |
160 |
private static final Logger LOGGER = LogManager.getLogger(WalletController.class);
|
| 28515 |
amit.gupta |
161 |
|
| 27067 |
amit.gupta |
162 |
@PostMapping(value = "/wallet/upload")
|
| 27345 |
amit.gupta |
163 |
public String uploadWalletBulk(HttpServletRequest request, @RequestPart("file") MultipartFile file, Model model)
|
| 27067 |
amit.gupta |
164 |
throws Exception {
|
|
|
165 |
List<WalletHistoryModel> walletHistoryModelList = ExcelUtils.parseWalletBulkCredit(file.getInputStream());
|
| 28515 |
amit.gupta |
166 |
for (WalletHistoryModel walletHistoryModel : walletHistoryModelList) {
|
|
|
167 |
if (walletHistoryModel.getReference() == 0) {
|
|
|
168 |
ManualPaymentType paymentType = manualPaymentRequestRepository
|
|
|
169 |
.selectByReferenceType(walletHistoryModel.getWalletReferenceType());
|
| 27344 |
amit.gupta |
170 |
if (paymentType == null) {
|
|
|
171 |
paymentType = new ManualPaymentType();
|
|
|
172 |
paymentType.setReferenceType(walletHistoryModel.getWalletReferenceType());
|
| 28781 |
amit.gupta |
173 |
manualPaymentRequestRepository.persist(paymentType);
|
| 27344 |
amit.gupta |
174 |
}
|
|
|
175 |
paymentType.setCounter(paymentType.getCounter() + 1);
|
|
|
176 |
int reference = paymentType.getCounter();
|
| 28515 |
amit.gupta |
177 |
walletService.addAmountToWallet(walletHistoryModel.getFofoId(), reference,
|
|
|
178 |
walletHistoryModel.getWalletReferenceType(), walletHistoryModel.getDescription(),
|
|
|
179 |
(float) walletHistoryModel.getAmount(), walletHistoryModel.getBusinessDate());
|
|
|
180 |
} else {
|
|
|
181 |
walletService.addAmountToWallet(walletHistoryModel.getFofoId(), walletHistoryModel.getReference(),
|
|
|
182 |
walletHistoryModel.getWalletReferenceType(), walletHistoryModel.getDescription(),
|
|
|
183 |
(float) walletHistoryModel.getAmount(), walletHistoryModel.getBusinessDate());
|
| 27067 |
amit.gupta |
184 |
}
|
|
|
185 |
}
|
| 23993 |
tejbeer |
186 |
|
| 31238 |
amit.gupta |
187 |
model.addAttribute("response1", mvcResponseSender.createResponseString(true));
|
| 27067 |
amit.gupta |
188 |
return "response";
|
|
|
189 |
}
|
|
|
190 |
|
| 22551 |
ashik.ali |
191 |
@RequestMapping(value = "/walletDetails", method = RequestMethod.GET)
|
| 23993 |
tejbeer |
192 |
public String dashboard(HttpServletRequest request,
|
|
|
193 |
@RequestParam(name = ProfitMandiConstants.START_TIME, required = false) String startTimeString,
|
|
|
194 |
@RequestParam(name = ProfitMandiConstants.END_TIME, required = false) String endTimeString,
|
|
|
195 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
| 29888 |
amit.gupta |
196 |
@RequestParam(name = "limit", defaultValue = "100") int limit, Model model)
|
| 23993 |
tejbeer |
197 |
throws ProfitMandiBusinessException {
|
| 24876 |
tejbeer |
198 |
/*
|
|
|
199 |
* boolean underMaintainance = true; if(underMaintainance) { throw new
|
|
|
200 |
* ProfitMandiBusinessException("Wallet", "Wallet",
|
|
|
201 |
* "Wallet is under Maintenance"); }
|
|
|
202 |
*/
|
| 22927 |
ashik.ali |
203 |
LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
|
| 24523 |
amit.gupta |
204 |
boolean isAdmin = roleManager.isAdmin(fofoDetails.getRoleIds());
|
| 25250 |
amit.gupta |
205 |
UserWallet userWallet = walletService.getUserWallet(fofoDetails.getFofoId());
|
| 23993 |
tejbeer |
206 |
|
| 22551 |
ashik.ali |
207 |
LocalDateTime startDateTime = StringUtils.toDateTime(startTimeString);
|
|
|
208 |
LocalDateTime endDateTime = StringUtils.toDateTime(endTimeString);
|
| 23993 |
tejbeer |
209 |
|
| 22551 |
ashik.ali |
210 |
List<UserWalletHistory> userWalletHistories = new ArrayList<>();
|
| 23993 |
tejbeer |
211 |
try {
|
|
|
212 |
userWalletHistories = walletService.getPaginatedUserWalletHistoryByRetailerId(fofoDetails.getFofoId(),
|
|
|
213 |
startDateTime, endDateTime, offset, limit);
|
|
|
214 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
| 22551 |
ashik.ali |
215 |
LOGGER.error("UserWallet History not found : ", profitMandiBusinessException);
|
|
|
216 |
}
|
| 23993 |
tejbeer |
217 |
|
| 22551 |
ashik.ali |
218 |
long countItems = 0;
|
| 23993 |
tejbeer |
219 |
try {
|
| 22551 |
ashik.ali |
220 |
countItems = walletService.getSizeByRetailerId(fofoDetails.getFofoId(), startDateTime, endDateTime);
|
| 23993 |
tejbeer |
221 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
|
|
222 |
LOGGER.error("UserWallet not found : ", profitMandiBusinessException);
|
| 22551 |
ashik.ali |
223 |
}
|
|
|
224 |
model.addAttribute("userWallet", userWallet);
|
|
|
225 |
model.addAttribute("walletHistories", userWalletHistories);
|
|
|
226 |
model.addAttribute("start", offset + 1);
|
| 23993 |
tejbeer |
227 |
model.addAttribute("size", countItems);
|
| 24523 |
amit.gupta |
228 |
model.addAttribute("isAdmin", isAdmin);
|
| 22551 |
ashik.ali |
229 |
model.addAttribute(ProfitMandiConstants.START_TIME, startTimeString);
|
|
|
230 |
model.addAttribute(ProfitMandiConstants.END_TIME, endTimeString);
|
| 23993 |
tejbeer |
231 |
if (userWalletHistories.size() < limit) {
|
| 22551 |
ashik.ali |
232 |
model.addAttribute("end", offset + userWalletHistories.size());
|
| 23993 |
tejbeer |
233 |
} else {
|
| 22551 |
ashik.ali |
234 |
model.addAttribute("end", offset + limit);
|
|
|
235 |
}
|
|
|
236 |
return "wallet-details";
|
|
|
237 |
}
|
| 23993 |
tejbeer |
238 |
|
| 22551 |
ashik.ali |
239 |
@RequestMapping(value = "/getPaginatedWalletHistory")
|
| 23993 |
tejbeer |
240 |
public String getSaleHistoryPaginated(HttpServletRequest request,
|
|
|
241 |
@RequestParam(name = ProfitMandiConstants.START_TIME, required = false) String startTimeString,
|
|
|
242 |
@RequestParam(name = ProfitMandiConstants.END_TIME, required = false) String endTimeString,
|
|
|
243 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
244 |
@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
|
|
|
245 |
throws ProfitMandiBusinessException {
|
| 22927 |
ashik.ali |
246 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 23993 |
tejbeer |
247 |
|
| 22551 |
ashik.ali |
248 |
LocalDateTime startDateTime = StringUtils.toDateTime(startTimeString);
|
|
|
249 |
LocalDateTime endDateTime = StringUtils.toDateTime(endTimeString);
|
|
|
250 |
|
|
|
251 |
List<UserWalletHistory> userWalletHistories = new ArrayList<>();
|
| 23993 |
tejbeer |
252 |
try {
|
|
|
253 |
userWalletHistories = walletService.getPaginatedUserWalletHistoryByRetailerId(loginDetails.getFofoId(),
|
|
|
254 |
startDateTime, endDateTime, offset, limit);
|
|
|
255 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
| 22551 |
ashik.ali |
256 |
LOGGER.error("UserWallet History not found : ", profitMandiBusinessException);
|
|
|
257 |
}
|
| 23993 |
tejbeer |
258 |
|
| 22551 |
ashik.ali |
259 |
model.addAttribute("walletHistories", userWalletHistories);
|
|
|
260 |
return "wallet-history-paginated";
|
|
|
261 |
}
|
| 23993 |
tejbeer |
262 |
|
| 23936 |
tejbeer |
263 |
@RequestMapping(value = "/getAddWalletRequest", method = RequestMethod.GET)
|
|
|
264 |
public String getAddwalletRequest(HttpServletRequest request,
|
|
|
265 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
| 23993 |
tejbeer |
266 |
@RequestParam(name = "limit", defaultValue = "10") int limit, Model model) throws Exception {
|
| 23936 |
tejbeer |
267 |
List<AddWalletRequest> walletRequest = null;
|
|
|
268 |
long size = 0;
|
| 23993 |
tejbeer |
269 |
walletRequest = addWalletRequestRepository.selectAllByStatus(offset, limit, AddWalletRequestStatus.pending);
|
|
|
270 |
LOGGER.info("walletRequest" + walletRequest);
|
| 23936 |
tejbeer |
271 |
size = addWalletRequestRepository.selectCountByStatus(AddWalletRequestStatus.pending);
|
| 23993 |
tejbeer |
272 |
if (!walletRequest.isEmpty()) {
|
|
|
273 |
List<Integer> fofoIds = this.getFofoIdsFromWalletRequest(walletRequest);
|
| 23936 |
tejbeer |
274 |
|
| 30426 |
tejbeer |
275 |
Map<Integer, CustomRetailer> customRetailerMap = retailerService.getAllFofoRetailers();
|
|
|
276 |
|
|
|
277 |
Map<Integer, CustomRetailer> fofoIdsAndRetailerName = fofoIds.stream().map(x -> customRetailerMap.get(x))
|
| 30437 |
amit.gupta |
278 |
.filter(x -> x != null).collect(Collectors.toMap(x -> x.getPartnerId(), x -> x));
|
| 30426 |
tejbeer |
279 |
|
| 23993 |
tejbeer |
280 |
model.addAttribute("fofoIdsAndRetailerName", fofoIdsAndRetailerName);
|
|
|
281 |
model.addAttribute("walletRequest", walletRequest);
|
|
|
282 |
model.addAttribute("rStatus", "pending");
|
|
|
283 |
model.addAttribute("start", offset + 1);
|
|
|
284 |
model.addAttribute("size", size);
|
|
|
285 |
model.addAttribute("url", "/getPaginatedWalletRequest");
|
|
|
286 |
|
|
|
287 |
if (walletRequest.size() < limit) {
|
|
|
288 |
model.addAttribute("end", offset + walletRequest.size());
|
|
|
289 |
} else {
|
|
|
290 |
model.addAttribute("end", offset + limit);
|
|
|
291 |
}
|
|
|
292 |
|
| 23936 |
tejbeer |
293 |
} else {
|
| 23993 |
tejbeer |
294 |
|
|
|
295 |
model.addAttribute("walletRequest", walletRequest);
|
|
|
296 |
model.addAttribute("size", size);
|
|
|
297 |
|
| 23936 |
tejbeer |
298 |
}
|
|
|
299 |
return "add-wallet-request";
|
|
|
300 |
}
|
|
|
301 |
|
|
|
302 |
@RequestMapping(value = "/getPaginatedWalletRequest", method = RequestMethod.GET)
|
|
|
303 |
public String getPaginatedWalletRequest(HttpServletRequest request,
|
|
|
304 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
| 23993 |
tejbeer |
305 |
@RequestParam(name = "limit", defaultValue = "10") int limit, Model model) throws Exception {
|
|
|
306 |
LOGGER.info("requested offset=[{}], limit = [{}]", offset, limit);
|
| 23936 |
tejbeer |
307 |
List<AddWalletRequest> walletRequest = null;
|
| 23993 |
tejbeer |
308 |
walletRequest = addWalletRequestRepository.selectAllByStatus(offset, limit, AddWalletRequestStatus.pending);
|
| 23936 |
tejbeer |
309 |
LOGGER.info("walletRequest" + walletRequest);
|
| 23993 |
tejbeer |
310 |
if (!walletRequest.isEmpty()) {
|
|
|
311 |
List<Integer> fofoIds = this.getFofoIdsFromWalletRequest(walletRequest);
|
| 30426 |
tejbeer |
312 |
Map<Integer, CustomRetailer> customRetailerMap = retailerService.getAllFofoRetailers();
|
| 23936 |
tejbeer |
313 |
|
| 30426 |
tejbeer |
314 |
Map<Integer, CustomRetailer> fofoIdsAndRetailerName = fofoIds.stream().map(x -> customRetailerMap.get(x))
|
|
|
315 |
.filter(x -> x != null).collect(Collectors.toList()).stream()
|
|
|
316 |
.collect(Collectors.toMap(x -> x.getPartnerId(), x -> x));
|
|
|
317 |
|
| 23993 |
tejbeer |
318 |
model.addAttribute("fofoIdsAndRetailerName", fofoIdsAndRetailerName);
|
|
|
319 |
model.addAttribute("walletRequest", walletRequest);
|
|
|
320 |
model.addAttribute("rStatus", "pending");
|
|
|
321 |
model.addAttribute("url", "/getPaginatedWalletRequest");
|
|
|
322 |
|
|
|
323 |
} else {
|
|
|
324 |
model.addAttribute("walletRequest", walletRequest);
|
|
|
325 |
|
|
|
326 |
}
|
|
|
327 |
|
| 23936 |
tejbeer |
328 |
return "add-wallet-request-paginated";
|
|
|
329 |
}
|
| 23993 |
tejbeer |
330 |
|
| 23936 |
tejbeer |
331 |
@RequestMapping(value = "/getAddWalletApproved", method = RequestMethod.GET)
|
|
|
332 |
public String getAddwalletRequestApproved(HttpServletRequest request,
|
|
|
333 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
334 |
@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
|
|
|
335 |
throws ProfitMandiBusinessException {
|
|
|
336 |
List<AddWalletRequest> walletRequest = null;
|
| 23993 |
tejbeer |
337 |
|
| 23936 |
tejbeer |
338 |
long size = 0;
|
| 23993 |
tejbeer |
339 |
walletRequest = addWalletRequestRepository.selectAllByStatus(offset, limit, AddWalletRequestStatus.approved);
|
| 23936 |
tejbeer |
340 |
size = addWalletRequestRepository.selectCountByStatus(AddWalletRequestStatus.approved);
|
|
|
341 |
LOGGER.info("walletRequest" + walletRequest);
|
| 23993 |
tejbeer |
342 |
if (!walletRequest.isEmpty()) {
|
|
|
343 |
List<Integer> fofoIds = this.getFofoIdsFromWalletRequest(walletRequest);
|
| 30426 |
tejbeer |
344 |
Map<Integer, CustomRetailer> customRetailerMap = retailerService.getAllFofoRetailers();
|
| 23936 |
tejbeer |
345 |
|
| 30426 |
tejbeer |
346 |
Map<Integer, CustomRetailer> fofoIdsAndRetailerName = fofoIds.stream().map(x -> customRetailerMap.get(x))
|
|
|
347 |
.filter(x -> x != null).collect(Collectors.toList()).stream()
|
|
|
348 |
.collect(Collectors.toMap(x -> x.getPartnerId(), x -> x));
|
|
|
349 |
|
| 23993 |
tejbeer |
350 |
model.addAttribute("fofoIdsAndRetailerName", fofoIdsAndRetailerName);
|
|
|
351 |
model.addAttribute("walletRequest", walletRequest);
|
|
|
352 |
model.addAttribute("start", offset + 1);
|
|
|
353 |
model.addAttribute("size", size);
|
|
|
354 |
model.addAttribute("url", "/getPaginatedWalletApproved");
|
|
|
355 |
|
|
|
356 |
if (walletRequest.size() < limit) {
|
|
|
357 |
model.addAttribute("end", offset + walletRequest.size());
|
|
|
358 |
} else {
|
|
|
359 |
model.addAttribute("end", offset + limit);
|
|
|
360 |
}
|
| 23936 |
tejbeer |
361 |
} else {
|
| 23993 |
tejbeer |
362 |
|
|
|
363 |
model.addAttribute("walletRequest", walletRequest);
|
|
|
364 |
model.addAttribute("size", size);
|
|
|
365 |
|
| 23936 |
tejbeer |
366 |
}
|
|
|
367 |
return "add-wallet-request";
|
|
|
368 |
}
|
|
|
369 |
|
|
|
370 |
@RequestMapping(value = "/getPaginatedWalletApproved", method = RequestMethod.GET)
|
|
|
371 |
public String getPaginatedWalletApproved(HttpServletRequest request,
|
|
|
372 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
373 |
@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
|
|
|
374 |
throws ProfitMandiBusinessException {
|
| 23993 |
tejbeer |
375 |
LOGGER.info("requested offset=[{}], limit = [{}]", offset, limit);
|
| 23936 |
tejbeer |
376 |
List<AddWalletRequest> walletRequest = null;
|
|
|
377 |
walletRequest = addWalletRequestRepository.selectAllByStatus(offset, limit, AddWalletRequestStatus.approved);
|
|
|
378 |
LOGGER.info("walletRequest" + walletRequest);
|
| 23993 |
tejbeer |
379 |
if (!walletRequest.isEmpty()) {
|
|
|
380 |
List<Integer> fofoIds = this.getFofoIdsFromWalletRequest(walletRequest);
|
| 30426 |
tejbeer |
381 |
Map<Integer, CustomRetailer> customRetailerMap = retailerService.getAllFofoRetailers();
|
| 23936 |
tejbeer |
382 |
|
| 30426 |
tejbeer |
383 |
Map<Integer, CustomRetailer> fofoIdsAndRetailerName = fofoIds.stream().map(x -> customRetailerMap.get(x))
|
|
|
384 |
.filter(x -> x != null).collect(Collectors.toList()).stream()
|
|
|
385 |
.collect(Collectors.toMap(x -> x.getPartnerId(), x -> x));
|
|
|
386 |
|
| 23993 |
tejbeer |
387 |
model.addAttribute("fofoIdsAndRetailerName", fofoIdsAndRetailerName);
|
|
|
388 |
model.addAttribute("walletRequest", walletRequest);
|
|
|
389 |
model.addAttribute("url", "/getPaginatedWalletApproved");
|
|
|
390 |
} else {
|
|
|
391 |
model.addAttribute("walletRequest", walletRequest);
|
|
|
392 |
|
|
|
393 |
}
|
| 23936 |
tejbeer |
394 |
return "add-wallet-request-paginated";
|
|
|
395 |
}
|
| 23993 |
tejbeer |
396 |
|
| 23985 |
tejbeer |
397 |
@RequestMapping(value = "/getAddWalletRequestRejected", method = RequestMethod.GET)
|
|
|
398 |
public String getAddwalletRequestRejected(HttpServletRequest request,
|
|
|
399 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
400 |
@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
|
|
|
401 |
throws ProfitMandiBusinessException {
|
|
|
402 |
List<AddWalletRequest> walletRequest = null;
|
| 23993 |
tejbeer |
403 |
|
| 23985 |
tejbeer |
404 |
long size = 0;
|
| 23993 |
tejbeer |
405 |
walletRequest = addWalletRequestRepository.selectAllByStatus(offset, limit, AddWalletRequestStatus.rejected);
|
| 23985 |
tejbeer |
406 |
size = addWalletRequestRepository.selectCountByStatus(AddWalletRequestStatus.rejected);
|
|
|
407 |
LOGGER.info("walletRequest" + walletRequest);
|
| 23993 |
tejbeer |
408 |
if (!walletRequest.isEmpty()) {
|
|
|
409 |
List<Integer> fofoIds = this.getFofoIdsFromWalletRequest(walletRequest);
|
| 30426 |
tejbeer |
410 |
Map<Integer, CustomRetailer> customRetailerMap = retailerService.getAllFofoRetailers();
|
| 23985 |
tejbeer |
411 |
|
| 30426 |
tejbeer |
412 |
Map<Integer, CustomRetailer> fofoIdsAndRetailerName = fofoIds.stream().map(x -> customRetailerMap.get(x))
|
|
|
413 |
.filter(x -> x != null).collect(Collectors.toList()).stream()
|
|
|
414 |
.collect(Collectors.toMap(x -> x.getPartnerId(), x -> x));
|
|
|
415 |
|
| 23993 |
tejbeer |
416 |
model.addAttribute("fofoIdsAndRetailerName", fofoIdsAndRetailerName);
|
|
|
417 |
model.addAttribute("walletRequest", walletRequest);
|
|
|
418 |
model.addAttribute("start", offset + 1);
|
|
|
419 |
model.addAttribute("size", size);
|
|
|
420 |
model.addAttribute("url", "/getPaginatedWalletRequestRejected");
|
|
|
421 |
|
|
|
422 |
if (walletRequest.size() < limit) {
|
|
|
423 |
model.addAttribute("end", offset + walletRequest.size());
|
|
|
424 |
} else {
|
|
|
425 |
model.addAttribute("end", offset + limit);
|
|
|
426 |
}
|
| 23985 |
tejbeer |
427 |
} else {
|
| 23993 |
tejbeer |
428 |
model.addAttribute("walletRequest", walletRequest);
|
|
|
429 |
model.addAttribute("size", size);
|
| 23985 |
tejbeer |
430 |
}
|
|
|
431 |
|
|
|
432 |
return "add-wallet-request";
|
|
|
433 |
}
|
| 23993 |
tejbeer |
434 |
|
| 23985 |
tejbeer |
435 |
@RequestMapping(value = "/getPaginatedWalletRequestRejected", method = RequestMethod.GET)
|
|
|
436 |
public String getPaginatedWalletRequestRejected(HttpServletRequest request,
|
|
|
437 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
438 |
@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
|
|
|
439 |
throws ProfitMandiBusinessException {
|
| 23993 |
tejbeer |
440 |
LOGGER.info("requested offset=[{}], limit = [{}]", offset, limit);
|
| 23985 |
tejbeer |
441 |
List<AddWalletRequest> walletRequest = null;
|
|
|
442 |
walletRequest = addWalletRequestRepository.selectAllByStatus(offset, limit, AddWalletRequestStatus.rejected);
|
|
|
443 |
LOGGER.info("walletRequest" + walletRequest);
|
| 23993 |
tejbeer |
444 |
if (!walletRequest.isEmpty()) {
|
|
|
445 |
List<Integer> fofoIds = this.getFofoIdsFromWalletRequest(walletRequest);
|
| 30426 |
tejbeer |
446 |
Map<Integer, CustomRetailer> customRetailerMap = retailerService.getAllFofoRetailers();
|
| 23985 |
tejbeer |
447 |
|
| 30426 |
tejbeer |
448 |
Map<Integer, CustomRetailer> fofoIdsAndRetailerName = fofoIds.stream().map(x -> customRetailerMap.get(x))
|
|
|
449 |
.filter(x -> x != null).collect(Collectors.toList()).stream()
|
|
|
450 |
.collect(Collectors.toMap(x -> x.getPartnerId(), x -> x));
|
| 23993 |
tejbeer |
451 |
model.addAttribute("fofoIdsAndRetailerName", fofoIdsAndRetailerName);
|
|
|
452 |
model.addAttribute("walletRequest", walletRequest);
|
|
|
453 |
model.addAttribute("url", "/getPaginatedWalletRequestRejected");
|
|
|
454 |
} else {
|
|
|
455 |
model.addAttribute("walletRequest", walletRequest);
|
|
|
456 |
|
|
|
457 |
}
|
|
|
458 |
|
| 23985 |
tejbeer |
459 |
return "add-wallet-request-paginated";
|
|
|
460 |
}
|
| 23993 |
tejbeer |
461 |
|
| 23936 |
tejbeer |
462 |
@RequestMapping(value = "/addAmountToWallet", method = RequestMethod.PUT)
|
| 23993 |
tejbeer |
463 |
public String addAmountToWallet(HttpServletRequest request, @RequestParam(name = "id", defaultValue = "0") int id,
|
| 24089 |
tejbeer |
464 |
@RequestParam(name = "walletRequestid", defaultValue = "0") int walletRequestid, Model model)
|
|
|
465 |
throws Exception {
|
| 23993 |
tejbeer |
466 |
|
| 24089 |
tejbeer |
467 |
AddWalletRequest addWalletRequest = addWalletRequestRepository.selectById(walletRequestid);
|
| 23993 |
tejbeer |
468 |
if (addWalletRequest.getStatus().equals(AddWalletRequestStatus.pending)) {
|
| 24089 |
tejbeer |
469 |
walletService.addAmountToWallet(addWalletRequest.getRetailerId(), walletRequestid,
|
| 28515 |
amit.gupta |
470 |
WalletReferenceType.ADVANCE_AMOUNT, "ntfs/rgfs", addWalletRequest.getAmount(),
|
|
|
471 |
addWalletRequest.getCreateTimestamp());
|
| 23993 |
tejbeer |
472 |
addWalletRequest.setStatus(AddWalletRequestStatus.approved);
|
|
|
473 |
addWalletRequest.setUpdateTimestamp(LocalDateTime.now());
|
|
|
474 |
addWalletRequestRepository.persist(addWalletRequest);
|
| 24089 |
tejbeer |
475 |
unsettledPaymentsRepository.deleteById(id);
|
| 31238 |
amit.gupta |
476 |
model.addAttribute("response1", mvcResponseSender.createResponseString(true));
|
| 23993 |
tejbeer |
477 |
CustomRetailer customRetailer = retailerService.getFofoRetailer(addWalletRequest.getRetailerId());
|
|
|
478 |
String subject = "Request Approved for " + customRetailer.getBusinessName() + " of Rs."
|
|
|
479 |
+ addWalletRequest.getAmount();
|
|
|
480 |
String messageText = MessageFormat.format(
|
|
|
481 |
"User Id - {0}\n Name -{1}\n Email -{2}\n mobile -{3}\n Reference - {4}\n Amount - Rs.{5}",
|
|
|
482 |
new Integer(addWalletRequest.getRetailerId()), customRetailer.getBusinessName(),
|
|
|
483 |
customRetailer.getEmail(), customRetailer.getMobileNumber(),
|
|
|
484 |
addWalletRequest.getTransaction_reference(), new Float(addWalletRequest.getAmount()));
|
|
|
485 |
|
|
|
486 |
this.sendMailWithAttachments(subject, messageText);
|
|
|
487 |
return "response";
|
|
|
488 |
} else {
|
| 31238 |
amit.gupta |
489 |
model.addAttribute("response1", mvcResponseSender.createResponseString(false));
|
| 23993 |
tejbeer |
490 |
return "response";
|
|
|
491 |
}
|
| 23936 |
tejbeer |
492 |
}
|
| 23993 |
tejbeer |
493 |
|
| 23985 |
tejbeer |
494 |
@RequestMapping(value = "/addAmountToWalletRequestRejected", method = RequestMethod.PUT)
|
| 23993 |
tejbeer |
495 |
public String addAmountToWalletRequestRejected(HttpServletRequest request,
|
|
|
496 |
@RequestParam(name = "id", defaultValue = "0") int id, Model model) throws Exception {
|
|
|
497 |
|
|
|
498 |
AddWalletRequest addWalletRequest = addWalletRequestRepository.selectById(id);
|
|
|
499 |
if (addWalletRequest.getStatus().equals(AddWalletRequestStatus.pending)) {
|
|
|
500 |
addWalletRequest.setStatus(AddWalletRequestStatus.rejected);
|
|
|
501 |
addWalletRequest.setUpdateTimestamp(LocalDateTime.now());
|
|
|
502 |
addWalletRequestRepository.persist(addWalletRequest);
|
| 31238 |
amit.gupta |
503 |
model.addAttribute("response1", mvcResponseSender.createResponseString(true));
|
| 23993 |
tejbeer |
504 |
CustomRetailer customRetailer = retailerService.getFofoRetailer(addWalletRequest.getRetailerId());
|
|
|
505 |
String subject = "Request Rejected for " + customRetailer.getBusinessName() + " of Rs."
|
|
|
506 |
+ addWalletRequest.getAmount();
|
|
|
507 |
String messageText = MessageFormat.format(
|
|
|
508 |
"User Id - {0}\n Name -{1}\n Email -{2}\n mobile -{3}\n Reference - {4}\n Amount - Rs.{5}",
|
|
|
509 |
new Integer(addWalletRequest.getRetailerId()), customRetailer.getBusinessName(),
|
|
|
510 |
customRetailer.getEmail(), customRetailer.getMobileNumber(),
|
|
|
511 |
addWalletRequest.getTransaction_reference(), new Float(addWalletRequest.getAmount()));
|
|
|
512 |
|
|
|
513 |
this.sendMailWithAttachments(subject, messageText);
|
|
|
514 |
return "response";
|
|
|
515 |
} else {
|
| 31238 |
amit.gupta |
516 |
model.addAttribute("response1", mvcResponseSender.createResponseString(false));
|
| 23993 |
tejbeer |
517 |
return "response";
|
|
|
518 |
}
|
| 23985 |
tejbeer |
519 |
}
|
| 23993 |
tejbeer |
520 |
|
| 23985 |
tejbeer |
521 |
private void sendMailWithAttachments(String subject, String messageText) throws Exception {
|
|
|
522 |
MimeMessage message = mailSender.createMimeMessage();
|
|
|
523 |
MimeMessageHelper helper = new MimeMessageHelper(message, true);
|
| 24089 |
tejbeer |
524 |
String[] email = { "neerajgupta2021@gmail.com", "adeel.yazdani@smartdukaan.com",
|
|
|
525 |
"kamini.sharma@smartdukaan.com", "care@smartdukaan.com", "mohinder.mutreja@smartdukaan.com" };
|
| 23985 |
tejbeer |
526 |
helper.setSubject(subject);
|
|
|
527 |
helper.setText(messageText);
|
|
|
528 |
helper.setTo(email);
|
| 26041 |
amit.gupta |
529 |
InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "Smartdukaan Alerts");
|
| 23985 |
tejbeer |
530 |
helper.setFrom(senderAddress);
|
|
|
531 |
mailSender.send(message);
|
|
|
532 |
|
|
|
533 |
}
|
| 23993 |
tejbeer |
534 |
|
|
|
535 |
private List<Integer> getFofoIdsFromWalletRequest(List<AddWalletRequest> walletRequest) {
|
| 30436 |
amit.gupta |
536 |
return walletRequest.stream().map(x -> x.getRetailerId()).distinct().collect(Collectors.toList());
|
| 23993 |
tejbeer |
537 |
}
|
| 23936 |
tejbeer |
538 |
|
| 24089 |
tejbeer |
539 |
@RequestMapping(value = "/getcreateUnsettledPayments", method = RequestMethod.GET)
|
|
|
540 |
public String getcreateUnsettledPayment(HttpServletRequest request,
|
|
|
541 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
542 |
@RequestParam(name = "limit", defaultValue = "15") int limit, Model model) throws Exception {
|
|
|
543 |
List<UnsettledPayment> up = null;
|
|
|
544 |
|
|
|
545 |
long size = 0;
|
|
|
546 |
up = unsettledPaymentsRepository.selectAllById(offset, limit);
|
|
|
547 |
|
|
|
548 |
size = unsettledPaymentsRepository.selectAllCount();
|
|
|
549 |
if (!up.isEmpty()) {
|
|
|
550 |
model.addAttribute("unsettledPayment", up);
|
|
|
551 |
model.addAttribute("start", offset + 1);
|
|
|
552 |
model.addAttribute("size", size);
|
|
|
553 |
model.addAttribute("url", "/getPaginatedUnsettledPayments");
|
|
|
554 |
|
|
|
555 |
if (up.size() < limit) {
|
|
|
556 |
model.addAttribute("end", offset + up.size());
|
|
|
557 |
} else {
|
|
|
558 |
model.addAttribute("end", offset + limit);
|
|
|
559 |
}
|
|
|
560 |
} else {
|
|
|
561 |
model.addAttribute("unsettledPayment", up);
|
|
|
562 |
model.addAttribute("size", size);
|
|
|
563 |
}
|
|
|
564 |
|
|
|
565 |
LOGGER.info("unsettledPaymentList" + up);
|
|
|
566 |
return "unsettled-payments";
|
|
|
567 |
}
|
|
|
568 |
|
|
|
569 |
@RequestMapping(value = "/getUnsettledPaymentsByAmount", method = RequestMethod.GET)
|
|
|
570 |
public String getUnsettledPaymentByAmount(HttpServletRequest request,
|
|
|
571 |
@RequestParam(name = "amount", defaultValue = "0") float amount,
|
|
|
572 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
573 |
@RequestParam(name = "limit", defaultValue = "10") int limit, Model model) throws Exception {
|
|
|
574 |
List<UnsettledPayment> up = null;
|
|
|
575 |
|
|
|
576 |
long size = 0;
|
|
|
577 |
up = unsettledPaymentsRepository.selectAllByAmount(amount, offset, limit);
|
|
|
578 |
|
|
|
579 |
size = unsettledPaymentsRepository.selectAllCount();
|
|
|
580 |
if (!up.isEmpty()) {
|
|
|
581 |
model.addAttribute("unsettledPayment", up);
|
|
|
582 |
model.addAttribute("start", offset + 1);
|
|
|
583 |
model.addAttribute("size", size);
|
|
|
584 |
model.addAttribute("url", "/getPaginatedUnsettledPayments");
|
|
|
585 |
|
|
|
586 |
if (up.size() < limit) {
|
|
|
587 |
model.addAttribute("end", offset + up.size());
|
|
|
588 |
} else {
|
|
|
589 |
model.addAttribute("end", offset + limit);
|
|
|
590 |
}
|
|
|
591 |
return "unsettle-payment-modal";
|
|
|
592 |
} else {
|
|
|
593 |
model.addAttribute("unsettledPayment", up);
|
|
|
594 |
model.addAttribute("size", size);
|
|
|
595 |
}
|
|
|
596 |
|
|
|
597 |
return "unsettle-payment-modal";
|
|
|
598 |
}
|
|
|
599 |
|
|
|
600 |
@RequestMapping(value = "/createUnsettledPaymentsEntries", method = RequestMethod.POST)
|
|
|
601 |
public String createUnsettledPaymentsEntries(HttpServletRequest request,
|
|
|
602 |
@RequestBody UnsettledPaymentModel unsettledPaymentModel, Model model) throws Exception {
|
|
|
603 |
|
|
|
604 |
UnsettledPayment up = new UnsettledPayment();
|
|
|
605 |
up.setTransaction_reference(unsettledPaymentModel.getTransactionReference());
|
|
|
606 |
up.setAmount(unsettledPaymentModel.getAmount());
|
|
|
607 |
up.setDescription(unsettledPaymentModel.getDescription());
|
|
|
608 |
up.setReference_date(unsettledPaymentModel.getReferenceDate());
|
|
|
609 |
LOGGER.info("uppaynments" + up);
|
|
|
610 |
unsettledPaymentsRepository.persist(up);
|
| 31238 |
amit.gupta |
611 |
model.addAttribute("response1", mvcResponseSender.createResponseString(true));
|
| 24089 |
tejbeer |
612 |
return "response";
|
|
|
613 |
}
|
|
|
614 |
|
|
|
615 |
@RequestMapping(value = "/removeUnsettledPaymentsEntries", method = RequestMethod.DELETE)
|
|
|
616 |
public String removeUnsettledPaymentsEntries(HttpServletRequest request,
|
|
|
617 |
@RequestParam(name = "id", defaultValue = "0") int id, Model model) throws Exception {
|
|
|
618 |
|
|
|
619 |
unsettledPaymentsRepository.deleteById(id);
|
|
|
620 |
|
| 31238 |
amit.gupta |
621 |
model.addAttribute("response1", mvcResponseSender.createResponseString(true));
|
| 24089 |
tejbeer |
622 |
return "response";
|
|
|
623 |
}
|
|
|
624 |
|
| 24509 |
amit.gupta |
625 |
@RequestMapping(value = "/wallet/statement", method = RequestMethod.GET)
|
| 24523 |
amit.gupta |
626 |
public String getWalletStatement(HttpServletRequest request, @RequestParam LocalDateTime startDate,
|
| 24876 |
tejbeer |
627 |
@RequestParam LocalDateTime endDate, Model model, @RequestParam(defaultValue = "0") int fofoId)
|
|
|
628 |
throws Exception {
|
| 24523 |
amit.gupta |
629 |
boolean isAdmin = roleManager.isAdmin(cookiesProcessor.getCookiesObject(request).getRoleIds());
|
| 24876 |
tejbeer |
630 |
if (fofoId > 0) {
|
|
|
631 |
if (!isAdmin) {
|
| 24523 |
amit.gupta |
632 |
throw new ProfitMandiBusinessException("Unauthorised access", "PartnerId", "Permission Denied");
|
|
|
633 |
}
|
|
|
634 |
} else {
|
|
|
635 |
fofoId = cookiesProcessor.getCookiesObject(request).getFofoId();
|
|
|
636 |
}
|
|
|
637 |
float openingBalance = walletService.getOpeningTill(fofoId, startDate);
|
|
|
638 |
float closingBalance = walletService.getOpeningTill(fofoId, endDate);
|
| 24876 |
tejbeer |
639 |
List<UserWalletHistory> uwhList = walletService.getPaginatedUserWalletHistoryByRetailerId(fofoId, startDate,
|
|
|
640 |
endDate, 0, 0);
|
| 24511 |
amit.gupta |
641 |
Collections.reverse(uwhList);
|
| 24509 |
amit.gupta |
642 |
model.addAttribute("opening", openingBalance);
|
|
|
643 |
model.addAttribute("closing", closingBalance);
|
|
|
644 |
model.addAttribute("history", uwhList);
|
|
|
645 |
model.addAttribute("startDate", startDate);
|
|
|
646 |
model.addAttribute("endDate", endDate);
|
|
|
647 |
return "walletStatement";
|
|
|
648 |
}
|
|
|
649 |
|
| 29070 |
amit.gupta |
650 |
@Autowired
|
|
|
651 |
TransactionService transactionService;
|
| 29811 |
tejbeer |
652 |
|
| 29070 |
amit.gupta |
653 |
@RequestMapping(value = "/account/reco", method = RequestMethod.GET)
|
| 29811 |
tejbeer |
654 |
public ResponseEntity<?> accountReco(HttpServletRequest request, @RequestParam LocalDate closingDate, Model model)
|
|
|
655 |
throws Exception {
|
| 29070 |
amit.gupta |
656 |
boolean isAdmin = roleManager.isAdmin(cookiesProcessor.getCookiesObject(request).getRoleIds());
|
|
|
657 |
if (!isAdmin) {
|
|
|
658 |
throw new ProfitMandiBusinessException("Unauthorised access", "PartnerId", "Permission Denied");
|
|
|
659 |
}
|
|
|
660 |
LocalDateTime closingDateTime = LocalDate.now().atStartOfDay().plusDays(1);
|
|
|
661 |
Map<Integer, CustomRetailer> customRetailerMap = retailerService.getAllFofoRetailers();
|
|
|
662 |
Set<Integer> retailersSet = customRetailerMap.keySet();
|
|
|
663 |
|
|
|
664 |
Map<Integer, Float> closingPurchaseMap = orderRepository.selectOpeningAmount(closingDateTime, retailersSet);
|
|
|
665 |
|
|
|
666 |
Map<Integer, UserWallet> retailerWalletMap = walletService.getRetailerIdUserWalletMap(retailersSet);
|
| 29811 |
tejbeer |
667 |
Map<Integer, Integer> walletRetailerMap = retailerWalletMap.entrySet().stream()
|
|
|
668 |
.collect(Collectors.toMap(x -> x.getValue().getId(), x -> x.getKey()));
|
|
|
669 |
|
| 29070 |
amit.gupta |
670 |
Set<Integer> walletSet = walletRetailerMap.keySet();
|
| 29811 |
tejbeer |
671 |
Map<Integer, Float> closingBalanceMap = userWalletHistoryRepository
|
|
|
672 |
.getSumTillDateExcludingPurchase(closingDateTime, walletSet);
|
| 29070 |
amit.gupta |
673 |
Map<Integer, Float> closingWalletMap = userWalletHistoryRepository.getSumTillDate(closingDateTime, walletSet);
|
| 29083 |
amit.gupta |
674 |
Map<Integer, Float> peindingIndentMap = transactionService.getPendingIndentValueMap();
|
| 29811 |
tejbeer |
675 |
|
| 29070 |
amit.gupta |
676 |
List<List<?>> rows = new ArrayList<>();
|
|
|
677 |
for (Map.Entry<Integer, Float> closingBalance : closingBalanceMap.entrySet()) {
|
|
|
678 |
int walletId = closingBalance.getKey();
|
|
|
679 |
int retailerId = walletRetailerMap.get(walletId);
|
| 29811 |
tejbeer |
680 |
|
| 29070 |
amit.gupta |
681 |
float accountClosing = 0f;
|
|
|
682 |
if (!closingPurchaseMap.containsKey(retailerId)) {
|
|
|
683 |
accountClosing = closingBalance.getValue();
|
|
|
684 |
} else {
|
|
|
685 |
accountClosing = closingBalance.getValue() - closingPurchaseMap.get(retailerId);
|
|
|
686 |
}
|
| 29811 |
tejbeer |
687 |
|
| 29070 |
amit.gupta |
688 |
CustomRetailer cr = customRetailerMap.get(retailerId);
|
|
|
689 |
|
|
|
690 |
rows.add(Arrays.asList(retailerId, cr.getBusinessName(), cr.getAddress().getCity(),
|
| 29811 |
tejbeer |
691 |
cr.getAddress().getState(), accountClosing, closingWalletMap.get(walletId),
|
|
|
692 |
peindingIndentMap.get(retailerId)));
|
| 29070 |
amit.gupta |
693 |
}
|
|
|
694 |
|
| 29811 |
tejbeer |
695 |
org.apache.commons.io.output.ByteArrayOutputStream byteArrayOutputStream = FileUtil.getCSVByteStream(
|
|
|
696 |
Arrays.asList("Id", "Partner Name", "City", "State", "Closing Balance", "Closing Wallet", "In Transit"),
|
|
|
697 |
rows);
|
| 29070 |
amit.gupta |
698 |
final HttpHeaders headers = new HttpHeaders();
|
|
|
699 |
headers.set("Content-Type", "text/csv");
|
|
|
700 |
headers.set("Content-disposition",
|
|
|
701 |
"inline; filename=account-statement-closing-." + StringUtils.toHyphenatedString(closingDate) + ".csv");
|
|
|
702 |
headers.setContentLength(byteArrayOutputStream.toByteArray().length);
|
|
|
703 |
|
|
|
704 |
final InputStream inputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
|
|
|
705 |
final InputStreamResource inputStreamResource = new InputStreamResource(inputStream);
|
|
|
706 |
return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
|
|
|
707 |
}
|
|
|
708 |
|
| 28597 |
amit.gupta |
709 |
@RequestMapping(value = "/account/closing-statements", method = RequestMethod.GET)
|
|
|
710 |
public ResponseEntity<?> getAccountStatement(HttpServletRequest request, @RequestParam LocalDate closingDate,
|
|
|
711 |
Model model) throws Exception {
|
|
|
712 |
boolean isAdmin = roleManager.isAdmin(cookiesProcessor.getCookiesObject(request).getRoleIds());
|
|
|
713 |
if (!isAdmin) {
|
|
|
714 |
throw new ProfitMandiBusinessException("Unauthorised access", "PartnerId", "Permission Denied");
|
|
|
715 |
}
|
|
|
716 |
LocalDateTime closingDateTime = closingDate.atStartOfDay().plusDays(1);
|
| 29811 |
tejbeer |
717 |
|
| 28597 |
amit.gupta |
718 |
Map<Integer, CustomRetailer> customRetailerMap = retailerService.getAllFofoRetailers();
|
|
|
719 |
Set<Integer> retailersSet = customRetailerMap.keySet();
|
|
|
720 |
|
|
|
721 |
Map<Integer, Float> closingPurchaseMap = orderRepository.selectOpeningAmount(closingDateTime, retailersSet);
|
|
|
722 |
|
|
|
723 |
Map<Integer, UserWallet> retailerWalletMap = walletService.getRetailerIdUserWalletMap(retailersSet);
|
| 29811 |
tejbeer |
724 |
Map<Integer, Integer> walletRetailerMap = retailerWalletMap.entrySet().stream()
|
|
|
725 |
.collect(Collectors.toMap(x -> x.getValue().getId(), x -> x.getKey()));
|
|
|
726 |
|
| 28597 |
amit.gupta |
727 |
Set<Integer> walletSet = walletRetailerMap.keySet();
|
| 29811 |
tejbeer |
728 |
Map<Integer, Float> closingBalanceMap = userWalletHistoryRepository
|
|
|
729 |
.getSumTillDateExcludingPurchase(closingDateTime, walletSet);
|
|
|
730 |
|
| 28597 |
amit.gupta |
731 |
List<List<?>> rows = new ArrayList<>();
|
|
|
732 |
for (Map.Entry<Integer, Float> closingWalletBalance : closingBalanceMap.entrySet()) {
|
|
|
733 |
int walletId = closingWalletBalance.getKey();
|
|
|
734 |
int retailerId = walletRetailerMap.get(walletId);
|
|
|
735 |
if (!closingPurchaseMap.containsKey(retailerId)) {
|
|
|
736 |
closingPurchaseMap.put(retailerId, closingWalletBalance.getValue());
|
|
|
737 |
} else {
|
|
|
738 |
closingPurchaseMap.put(retailerId,
|
|
|
739 |
closingWalletBalance.getValue() - closingPurchaseMap.get(retailerId));
|
|
|
740 |
}
|
|
|
741 |
float closingValue = closingPurchaseMap.get(retailerId);
|
|
|
742 |
CustomRetailer cr = customRetailerMap.get(retailerId);
|
|
|
743 |
|
|
|
744 |
rows.add(Arrays.asList(retailerId, cr.getBusinessName(), cr.getAddress().getCity(),
|
|
|
745 |
cr.getAddress().getState(), closingValue));
|
|
|
746 |
}
|
|
|
747 |
|
|
|
748 |
org.apache.commons.io.output.ByteArrayOutputStream byteArrayOutputStream = FileUtil
|
|
|
749 |
.getCSVByteStream(Arrays.asList("Id", "Partner Name", "City", "State", "Closing Balance"), rows);
|
|
|
750 |
final HttpHeaders headers = new HttpHeaders();
|
|
|
751 |
headers.set("Content-Type", "text/csv");
|
|
|
752 |
headers.set("Content-disposition",
|
|
|
753 |
"inline; filename=account-statement-closing-." + StringUtils.toHyphenatedString(closingDate) + ".csv");
|
|
|
754 |
headers.setContentLength(byteArrayOutputStream.toByteArray().length);
|
|
|
755 |
|
|
|
756 |
final InputStream inputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
|
|
|
757 |
final InputStreamResource inputStreamResource = new InputStreamResource(inputStream);
|
|
|
758 |
|
|
|
759 |
return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
|
|
|
760 |
|
|
|
761 |
}
|
|
|
762 |
|
| 28515 |
amit.gupta |
763 |
@RequestMapping(value = "/account/statement", method = RequestMethod.GET)
|
|
|
764 |
public ResponseEntity<?> getAccountStatement(HttpServletRequest request, @RequestParam LocalDateTime startDate,
|
|
|
765 |
@RequestParam LocalDateTime endDate, Model model, @RequestParam(defaultValue = "0") int fofoId)
|
|
|
766 |
throws Exception {
|
|
|
767 |
boolean isAdmin = roleManager.isAdmin(cookiesProcessor.getCookiesObject(request).getRoleIds());
|
|
|
768 |
if (fofoId > 0) {
|
|
|
769 |
if (!isAdmin) {
|
|
|
770 |
throw new ProfitMandiBusinessException("Unauthorised access", "PartnerId", "Permission Denied");
|
|
|
771 |
}
|
|
|
772 |
} else {
|
|
|
773 |
fofoId = cookiesProcessor.getCookiesObject(request).getFofoId();
|
|
|
774 |
}
|
|
|
775 |
float openingBalance = walletService.getOpeningTillExcludingPurchase(fofoId, startDate);
|
|
|
776 |
float closingBalance = walletService.getOpeningTillExcludingPurchase(fofoId, endDate);
|
| 28538 |
amit.gupta |
777 |
UserWallet uw = walletService.getUserWallet(fofoId);
|
| 28597 |
amit.gupta |
778 |
List<UserWalletHistory> history = userWalletHistoryRepository.selectPaginatedByWalletId(uw.getId(), startDate,
|
|
|
779 |
endDate, 0, 0);
|
| 28538 |
amit.gupta |
780 |
history = history.stream().filter(x -> !x.getReferenceType().equals(WalletReferenceType.PURCHASE))
|
| 28515 |
amit.gupta |
781 |
.collect(Collectors.toList());
|
|
|
782 |
InputStream is = getClass().getClassLoader().getResourceAsStream("account-statement.xlsx");
|
|
|
783 |
String partnerName = retailerService.getAllFofoRetailerIdNameMap().get(fofoId);
|
|
|
784 |
List<StatementDetailModel> details = orderRepository.selectDetailsBetween(fofoId, startDate, endDate);
|
|
|
785 |
float openingAmount = orderRepository.selectOpeningAmount(fofoId, startDate);
|
|
|
786 |
float closingAmount = orderRepository.selectOpeningAmount(fofoId, endDate);
|
|
|
787 |
LOGGER.info("Opening - {}, Closing - {}", openingAmount, closingAmount);
|
|
|
788 |
ByteArrayOutputStream byteArrayOutputStream = this.populateData(is, openingBalance - openingAmount,
|
| 28538 |
amit.gupta |
789 |
closingBalance - closingAmount, partnerName, history, startDate, endDate, details);
|
| 28515 |
amit.gupta |
790 |
|
|
|
791 |
final HttpHeaders headers = new HttpHeaders();
|
|
|
792 |
headers.set("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
|
|
793 |
headers.set("Content-disposition",
|
|
|
794 |
"inline; filename=account-statement." + StringUtils.toHyphenatedString(startDate.toLocalDate()) + "-"
|
|
|
795 |
+ StringUtils.toHyphenatedString(endDate.toLocalDate()) + ".xlsx");
|
|
|
796 |
headers.setContentLength(byteArrayOutputStream.toByteArray().length);
|
|
|
797 |
|
|
|
798 |
final InputStream inputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
|
|
|
799 |
final InputStreamResource inputStreamResource = new InputStreamResource(inputStream);
|
|
|
800 |
|
|
|
801 |
return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
|
|
|
802 |
|
|
|
803 |
}
|
|
|
804 |
|
|
|
805 |
private ByteArrayOutputStream populateData(InputStream is, float openingBalance, float closingBalance,
|
| 28597 |
amit.gupta |
806 |
String partnerName, List<UserWalletHistory> history, LocalDateTime startDate, LocalDateTime endDate,
|
|
|
807 |
List<StatementDetailModel> invoiceDetails) throws Exception {
|
| 28515 |
amit.gupta |
808 |
XSSFWorkbook workbook = new XSSFWorkbook(is);
|
|
|
809 |
CreationHelper creationHelper = workbook.getCreationHelper();
|
|
|
810 |
CellStyle style2 = workbook.createCellStyle();
|
| 28597 |
amit.gupta |
811 |
style2.setDataFormat(creationHelper.createDataFormat().getFormat("mm/dd/yyyy hh:mm:ss"));
|
|
|
812 |
|
| 28515 |
amit.gupta |
813 |
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
|
|
814 |
Sheet sheet = workbook.getSheetAt(0);
|
|
|
815 |
sheet.getRow(0).getCell(0).setCellValue(partnerName);
|
|
|
816 |
sheet.getRow(1).getCell(1)
|
|
|
817 |
.setCellValue(new Date(startDate.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli()));
|
|
|
818 |
sheet.getRow(1).getCell(2)
|
|
|
819 |
.setCellValue(new Date(endDate.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli()));
|
|
|
820 |
sheet.getRow(2).getCell(2).setCellValue(openingBalance);
|
|
|
821 |
long grandTotalDebit = 0l;
|
|
|
822 |
long grandTotalCredit = 0l;
|
|
|
823 |
int row = 4;
|
| 28538 |
amit.gupta |
824 |
for (UserWalletHistory walletEntry : history) {
|
| 28555 |
amit.gupta |
825 |
Cell dateCell = sheet.createRow(row).createCell(0);
|
| 28597 |
amit.gupta |
826 |
dateCell.setCellValue(
|
|
|
827 |
new Date(walletEntry.getTimestamp().atZone(ZoneId.systemDefault()).toInstant().toEpochMilli()));
|
| 28540 |
amit.gupta |
828 |
dateCell.setCellStyle(style2);
|
| 28555 |
amit.gupta |
829 |
sheet.getRow(row).createCell(1).setCellValue(walletEntry.getReferenceType().toString());
|
| 28597 |
amit.gupta |
830 |
if (walletEntry.getAmount() > 0) {
|
| 28540 |
amit.gupta |
831 |
sheet.getRow(row).createCell(2).setCellValue(0);
|
|
|
832 |
sheet.getRow(row).createCell(3).setCellValue(walletEntry.getAmount());
|
| 28538 |
amit.gupta |
833 |
grandTotalCredit += walletEntry.getAmount();
|
|
|
834 |
} else {
|
| 28781 |
amit.gupta |
835 |
sheet.getRow(row).createCell(2).setCellValue(-walletEntry.getAmount());
|
| 28540 |
amit.gupta |
836 |
sheet.getRow(row).createCell(3).setCellValue(0);
|
| 29005 |
amit.gupta |
837 |
grandTotalDebit -= walletEntry.getAmount();
|
| 28538 |
amit.gupta |
838 |
}
|
| 28540 |
amit.gupta |
839 |
sheet.getRow(row).createCell(4).setCellValue(walletEntry.getDescription());
|
|
|
840 |
sheet.getRow(row).createCell(5).setCellValue(walletEntry.getReference());
|
| 28515 |
amit.gupta |
841 |
row++;
|
|
|
842 |
}
|
|
|
843 |
for (StatementDetailModel statementDetailModel : invoiceDetails) {
|
| 28564 |
amit.gupta |
844 |
Cell dateCell = sheet.createRow(row).createCell(0);
|
| 28540 |
amit.gupta |
845 |
dateCell.setCellValue(statementDetailModel.getOnDate());
|
|
|
846 |
dateCell.setCellStyle(style2);
|
| 28564 |
amit.gupta |
847 |
sheet.getRow(row).createCell(1).setCellValue("BILLING");
|
| 28515 |
amit.gupta |
848 |
if (statementDetailModel.getAmount() > 0) {
|
| 28540 |
amit.gupta |
849 |
sheet.getRow(row).createCell(2).setCellValue(statementDetailModel.getAmount());
|
|
|
850 |
sheet.getRow(row).createCell(3).setCellValue(0);
|
| 28597 |
amit.gupta |
851 |
grandTotalDebit += statementDetailModel.getAmount();
|
| 28515 |
amit.gupta |
852 |
} else {
|
| 28540 |
amit.gupta |
853 |
sheet.getRow(row).createCell(2).setCellValue(0);
|
|
|
854 |
sheet.getRow(row).createCell(3).setCellValue(-statementDetailModel.getAmount());
|
| 28597 |
amit.gupta |
855 |
grandTotalCredit += -statementDetailModel.getAmount();
|
| 28515 |
amit.gupta |
856 |
}
|
| 28597 |
amit.gupta |
857 |
|
| 28538 |
amit.gupta |
858 |
sheet.getRow(row).createCell(4).setCellValue(statementDetailModel.getReferenceType());
|
|
|
859 |
sheet.getRow(row).createCell(5).setCellValue(statementDetailModel.getInvoiceNumber());
|
| 28515 |
amit.gupta |
860 |
|
|
|
861 |
row += 1;
|
|
|
862 |
}
|
|
|
863 |
sheet.createRow(row).createCell(0).setCellValue("Grand Total");
|
| 29006 |
amit.gupta |
864 |
sheet.getRow(row).createCell(2).setCellValue(grandTotalDebit);
|
|
|
865 |
sheet.getRow(row).createCell(3).setCellValue(grandTotalCredit);
|
| 28515 |
amit.gupta |
866 |
row += 2;
|
|
|
867 |
sheet.createRow(row).createCell(0).setCellValue("Closing Balance");
|
| 29006 |
amit.gupta |
868 |
sheet.getRow(row).createCell(3).setCellValue(closingBalance);
|
| 28515 |
amit.gupta |
869 |
row++;
|
|
|
870 |
/*
|
|
|
871 |
* sheet.createRow(row).createCell(0).setCellValue("Pending Grns");
|
|
|
872 |
* sheet.getRow(row).createCell(2).setCellValue(closingBalance); row++;
|
|
|
873 |
*/
|
|
|
874 |
try {
|
|
|
875 |
workbook.write(bos);
|
|
|
876 |
} finally {
|
|
|
877 |
workbook.close();
|
|
|
878 |
bos.close();
|
|
|
879 |
}
|
|
|
880 |
|
|
|
881 |
return bos;
|
|
|
882 |
}
|
|
|
883 |
|
| 24876 |
tejbeer |
884 |
@RequestMapping(value = "/manualPayment", method = RequestMethod.GET)
|
|
|
885 |
public String ManualPayment(HttpServletRequest request, Model model) throws Exception {
|
|
|
886 |
|
|
|
887 |
List<Integer> fofoIds = fofoStoreRepository.selectAll().stream().map(x -> x.getId())
|
|
|
888 |
.collect(Collectors.toList());
|
| 30426 |
tejbeer |
889 |
Map<Integer, CustomRetailer> customRetailerMap = retailerService.getAllFofoRetailers();
|
|
|
890 |
|
|
|
891 |
Map<Integer, CustomRetailer> customRetailersMap = fofoIds.stream().map(x -> customRetailerMap.get(x))
|
|
|
892 |
.filter(x -> x != null).collect(Collectors.toList()).stream()
|
|
|
893 |
.collect(Collectors.toMap(x -> x.getPartnerId(), x -> x));
|
| 24876 |
tejbeer |
894 |
String customRetailers = JSONObject.valueToString(customRetailersMap.values());
|
|
|
895 |
model.addAttribute("customRetailers", customRetailers);
|
|
|
896 |
|
|
|
897 |
model.addAttribute("referenceTypes", WalletReferenceType.referenceType);
|
|
|
898 |
model.addAttribute("transactionTypes", TransactionType.values());
|
|
|
899 |
return "wallet-edit";
|
|
|
900 |
|
|
|
901 |
}
|
|
|
902 |
|
|
|
903 |
@RequestMapping(value = "/getWalletHistory", method = RequestMethod.GET)
|
|
|
904 |
public String getWalletHistory(HttpServletRequest request,
|
|
|
905 |
@RequestParam(name = "reference", defaultValue = "0") int reference,
|
|
|
906 |
@RequestParam WalletReferenceType referenceType, Model model) throws Exception {
|
|
|
907 |
|
|
|
908 |
LOGGER.info("type" + referenceType);
|
|
|
909 |
List<UserWalletHistory> userWalletHistory = userWalletHistoryRepository
|
|
|
910 |
.selectAllByreferenceIdandreferenceType(reference, referenceType);
|
| 25018 |
tejbeer |
911 |
|
|
|
912 |
if (userWalletHistory.isEmpty()) {
|
|
|
913 |
throw new ProfitMandiBusinessException("RefrenceId", reference, "Reference Id not found");
|
|
|
914 |
}
|
|
|
915 |
|
|
|
916 |
UserWallet userWallet = userWalletRepository.selectById(userWalletHistory.get(0).getWalletId());
|
|
|
917 |
|
|
|
918 |
LOGGER.info("userWallet" + userWallet);
|
|
|
919 |
CustomRetailer customretailer = retailerService.getFofoRetailer(userWallet.getUserId());
|
|
|
920 |
|
|
|
921 |
model.addAttribute("userWallet", userWallet);
|
|
|
922 |
model.addAttribute("customretailer", customretailer);
|
|
|
923 |
|
| 24876 |
tejbeer |
924 |
model.addAttribute("wallethistory", userWalletHistory);
|
|
|
925 |
|
| 31238 |
amit.gupta |
926 |
model.addAttribute("response1", mvcResponseSender.createResponseString(true));
|
| 24876 |
tejbeer |
927 |
return "wallet-history";
|
|
|
928 |
|
|
|
929 |
}
|
|
|
930 |
|
| 24905 |
amit.gupta |
931 |
@RequestMapping(value = "/getWalletHistoryByPartner", method = RequestMethod.GET)
|
| 25018 |
tejbeer |
932 |
public String getWalletHistoryByPartner(HttpServletRequest request, int fofoId,
|
|
|
933 |
@RequestParam(name = "referenceType", required = false) WalletReferenceType referenceType,
|
|
|
934 |
@RequestParam(name = "offset", required = false, defaultValue = "0") int offset,
|
|
|
935 |
@RequestParam(name = "limit", required = false, defaultValue = "30") int limit, Model model)
|
|
|
936 |
throws Exception {
|
|
|
937 |
|
| 24905 |
amit.gupta |
938 |
UserWallet userWallet = userWalletRepository.selectByRetailerId(fofoId);
|
| 26485 |
amit.gupta |
939 |
List<UserWalletHistory> userWalletHistory = userWalletHistoryRepository.selectPaginatedByWalletIdReferenceType(
|
|
|
940 |
userWallet.getId(), referenceType, SortOrder.DESCENDING, offset, limit);
|
| 25018 |
tejbeer |
941 |
|
|
|
942 |
CustomRetailer customretailer = retailerService.getFofoRetailer(fofoId);
|
|
|
943 |
|
|
|
944 |
model.addAttribute("userWallet", userWallet);
|
|
|
945 |
model.addAttribute("customretailer", customretailer);
|
| 24905 |
amit.gupta |
946 |
model.addAttribute("wallethistory", userWalletHistory);
|
| 25018 |
tejbeer |
947 |
|
| 31238 |
amit.gupta |
948 |
model.addAttribute("response1", mvcResponseSender.createResponseString(true));
|
| 24905 |
amit.gupta |
949 |
return "wallet-history";
|
| 25018 |
tejbeer |
950 |
|
| 24905 |
amit.gupta |
951 |
}
|
| 30426 |
tejbeer |
952 |
|
| 24876 |
tejbeer |
953 |
@RequestMapping(value = "/getPartnerName", method = RequestMethod.GET)
|
|
|
954 |
public String getPartnerName(HttpServletRequest request,
|
|
|
955 |
@RequestParam(name = "reference", defaultValue = "0") int reference,
|
|
|
956 |
@RequestParam WalletReferenceType referenceType, Model model) throws Exception {
|
|
|
957 |
|
|
|
958 |
List<UserWalletHistory> userWalletHistory = userWalletHistoryRepository
|
|
|
959 |
.selectAllByreferenceIdandreferenceType(reference, referenceType);
|
| 24905 |
amit.gupta |
960 |
if (userWalletHistory.isEmpty()) {
|
| 24876 |
tejbeer |
961 |
throw new ProfitMandiBusinessException("RefrenceId", reference, "Reference Id not found");
|
|
|
962 |
}
|
|
|
963 |
UserWallet userWallet = userWalletRepository.selectById(userWalletHistory.get(0).getWalletId());
|
| 24905 |
amit.gupta |
964 |
|
| 24876 |
tejbeer |
965 |
CustomRetailer retailer = retailerService.getFofoRetailer(userWallet.getUserId());
|
| 24905 |
amit.gupta |
966 |
|
| 31238 |
amit.gupta |
967 |
model.addAttribute("response1", mvcResponseSender.createResponseString(retailer));
|
| 24905 |
amit.gupta |
968 |
|
| 24876 |
tejbeer |
969 |
return "response";
|
|
|
970 |
|
|
|
971 |
}
|
|
|
972 |
|
| 30678 |
amit.gupta |
973 |
@RequestMapping(value = "/reset-wallet/9990381", method = RequestMethod.GET)
|
| 30677 |
amit.gupta |
974 |
public String walletUpdate(Model model) throws Exception {
|
|
|
975 |
walletService.resetWallet();
|
| 31238 |
amit.gupta |
976 |
model.addAttribute("response1", mvcResponseSender.createResponseString(true));
|
| 30677 |
amit.gupta |
977 |
return "response";
|
|
|
978 |
}
|
|
|
979 |
|
| 24876 |
tejbeer |
980 |
@RequestMapping(value = "/walletUpdate", method = RequestMethod.POST)
|
|
|
981 |
public String walletUpdate(HttpServletRequest request,
|
| 30859 |
tejbeer |
982 |
@RequestParam(name = "reference", defaultValue = "0") int reference, @RequestParam int referenceTypeValue,
|
|
|
983 |
@RequestParam TransactionType transactiontype, @RequestParam int amount, @RequestParam String description,
|
|
|
984 |
@RequestParam int retailerId, Model model, @RequestParam LocalDateTime businessTimestamp) throws Exception {
|
| 26517 |
amit.gupta |
985 |
WalletReferenceType referenceType = WalletReferenceType.findByValue(referenceTypeValue);
|
| 28515 |
amit.gupta |
986 |
if (reference == 0 && referenceType.getValue() >= WalletReferenceType.INCENTIVES.getValue()) {
|
| 25018 |
tejbeer |
987 |
LOGGER.error("referenceType: " + referenceType);
|
| 24876 |
tejbeer |
988 |
ManualPaymentType paymentType = manualPaymentRequestRepository.selectByReferenceType(referenceType);
|
|
|
989 |
|
|
|
990 |
if (paymentType == null) {
|
|
|
991 |
paymentType = new ManualPaymentType();
|
| 27067 |
amit.gupta |
992 |
paymentType.setReferenceType(referenceType);
|
| 24876 |
tejbeer |
993 |
}
|
| 26485 |
amit.gupta |
994 |
paymentType.setCounter(paymentType.getCounter() + 1);
|
| 24876 |
tejbeer |
995 |
manualPaymentRequestRepository.persist(paymentType);
|
| 26485 |
amit.gupta |
996 |
reference = paymentType.getCounter();
|
| 28515 |
amit.gupta |
997 |
|
|
|
998 |
} else if (reference == 0) {
|
| 26485 |
amit.gupta |
999 |
throw new ProfitMandiBusinessException("RefrenceId", reference,
|
|
|
1000 |
"System specific reference type cant be used manually");
|
|
|
1001 |
}
|
| 28515 |
amit.gupta |
1002 |
|
| 26485 |
amit.gupta |
1003 |
List<UserWalletHistory> userWalletHistoryList = userWalletHistoryRepository
|
|
|
1004 |
.selectAllByreferenceIdandreferenceType(reference, referenceType);
|
|
|
1005 |
UserWallet userWallet = userWalletRepository.selectByRetailerId(retailerId);
|
|
|
1006 |
int walletId = userWallet.getId();
|
|
|
1007 |
int walletAmount = walletService.getWalletAmount(retailerId);
|
| 24876 |
tejbeer |
1008 |
|
| 26485 |
amit.gupta |
1009 |
int returnReference = 0;
|
|
|
1010 |
UserWalletHistory newUserWalletHistory = new UserWalletHistory();
|
| 24876 |
tejbeer |
1011 |
|
| 26485 |
amit.gupta |
1012 |
if (!userWalletHistoryList.isEmpty()) {
|
| 28515 |
amit.gupta |
1013 |
long validRetailerEntries = userWalletHistoryList.stream().filter(x -> x.getWalletId() == walletId).count();
|
|
|
1014 |
if (validRetailerEntries == 0) {
|
| 26485 |
amit.gupta |
1015 |
throw new ProfitMandiBusinessException("RefrenceId", reference,
|
|
|
1016 |
"Reference Id assign to Other partner");
|
| 24876 |
tejbeer |
1017 |
}
|
| 24942 |
tejbeer |
1018 |
}
|
| 28515 |
amit.gupta |
1019 |
|
| 26485 |
amit.gupta |
1020 |
if (TransactionType.DEBIT.equals(transactiontype)) {
|
|
|
1021 |
amount = -amount;
|
|
|
1022 |
}
|
| 28515 |
amit.gupta |
1023 |
|
| 26485 |
amit.gupta |
1024 |
userWallet.setAmount(walletAmount + amount);
|
|
|
1025 |
newUserWalletHistory.setAmount(amount);
|
|
|
1026 |
newUserWalletHistory.setBusinessTimestamp(businessTimestamp);
|
|
|
1027 |
newUserWalletHistory.setDescription(description);
|
|
|
1028 |
newUserWalletHistory.setReference(reference);
|
|
|
1029 |
newUserWalletHistory.setWalletId(userWallet.getId());
|
|
|
1030 |
newUserWalletHistory.setReferenceType(referenceType);
|
|
|
1031 |
newUserWalletHistory.setTimestamp(LocalDateTime.now());
|
|
|
1032 |
userWalletHistoryRepository.persist(newUserWalletHistory);
|
|
|
1033 |
|
| 31238 |
amit.gupta |
1034 |
model.addAttribute("response1", mvcResponseSender.createResponseString(reference));
|
| 24876 |
tejbeer |
1035 |
return "response";
|
|
|
1036 |
|
|
|
1037 |
}
|
| 25018 |
tejbeer |
1038 |
|
| 24951 |
tejbeer |
1039 |
@RequestMapping(value = "/addMoney", method = RequestMethod.POST)
|
| 25018 |
tejbeer |
1040 |
public String addMoney(HttpServletRequest request, @RequestParam float amount,
|
|
|
1041 |
@RequestParam String transactionReference, @RequestParam LocalDateTime referenceTime,
|
|
|
1042 |
@RequestParam String bankName, @RequestParam int fofoId, Model model) throws Exception {
|
|
|
1043 |
|
| 24951 |
tejbeer |
1044 |
AddWalletRequest addWalletRequest = new AddWalletRequest();
|
|
|
1045 |
addWalletRequest.setRetailerId(fofoId);
|
|
|
1046 |
addWalletRequest.setAmount(amount);
|
|
|
1047 |
addWalletRequest.setTransaction_reference(transactionReference);
|
|
|
1048 |
addWalletRequest.setCreateTimestamp(LocalDateTime.now());
|
|
|
1049 |
addWalletRequest.setBank_name(bankName);
|
|
|
1050 |
addWalletRequest.setReference_date(referenceTime.toLocalDate());
|
|
|
1051 |
addWalletRequest.setStatus(AddWalletRequestStatus.pending);
|
| 25018 |
tejbeer |
1052 |
|
|
|
1053 |
LOGGER.info("info" + addWalletRequest);
|
|
|
1054 |
|
| 24951 |
tejbeer |
1055 |
addWalletRequestRepository.persist(addWalletRequest);
|
| 31238 |
amit.gupta |
1056 |
model.addAttribute("response1", mvcResponseSender.createResponseString(true));
|
| 24951 |
tejbeer |
1057 |
return "response";
|
|
|
1058 |
}
|
| 29811 |
tejbeer |
1059 |
|
|
|
1060 |
@RequestMapping(value = "/getCreditDetail", method = RequestMethod.GET)
|
|
|
1061 |
public String getCreditDetail(HttpServletRequest request, Model model) throws Exception {
|
|
|
1062 |
List<CreditAccount> creditAccounts = creditAccountRepository.selectAll();
|
|
|
1063 |
Map<Integer, CustomRetailer> customRetailers = retailerService.getAllFofoRetailers();
|
|
|
1064 |
|
| 29962 |
tejbeer |
1065 |
Map<Integer, FofoStore> fofoStoreMap = fofoStoreRepository
|
|
|
1066 |
.selectByRetailerIds(new ArrayList<>(customRetailers.keySet())).stream()
|
|
|
1067 |
.collect(Collectors.toMap(x -> x.getId(), x -> x));
|
|
|
1068 |
|
| 29811 |
tejbeer |
1069 |
model.addAttribute("creditAccounts", creditAccounts);
|
| 29962 |
tejbeer |
1070 |
model.addAttribute("fofoStoreMap", fofoStoreMap);
|
| 29811 |
tejbeer |
1071 |
model.addAttribute("customRetailers", customRetailers);
|
|
|
1072 |
return "partner-credit-detail";
|
|
|
1073 |
}
|
|
|
1074 |
|
|
|
1075 |
@RequestMapping(value = "/activateKred", method = RequestMethod.POST)
|
| 29813 |
tejbeer |
1076 |
public String activateKred(HttpServletRequest request, @RequestParam int id, Model model) throws Exception {
|
|
|
1077 |
CreditAccount creditAccount = creditAccountRepository.selectById(id);
|
| 29811 |
tejbeer |
1078 |
|
|
|
1079 |
creditAccount.setActive(true);
|
|
|
1080 |
|
|
|
1081 |
Map<Integer, CustomRetailer> customRetailers = retailerService.getAllFofoRetailers();
|
|
|
1082 |
|
| 30859 |
tejbeer |
1083 |
String title = "Loan Approved";
|
|
|
1084 |
String url = "http://app.smartdukaan.com/pages/home/credit";
|
| 30873 |
tejbeer |
1085 |
String message = "Congratulations! Your Credit Limit is approved for Rs."
|
| 30859 |
tejbeer |
1086 |
+ FormattingUtils.formatDecimal(creditAccount.getSanctionedAmount());
|
|
|
1087 |
notificationService.sendNotification(creditAccount.getFofoId(), "Loan", MessageType.notification, title,
|
|
|
1088 |
message, url);
|
|
|
1089 |
|
| 29811 |
tejbeer |
1090 |
model.addAttribute("creditAccount", creditAccount);
|
|
|
1091 |
model.addAttribute("customRetailers", customRetailers);
|
|
|
1092 |
return "partner-credit-detail-row";
|
|
|
1093 |
}
|
|
|
1094 |
|
|
|
1095 |
@RequestMapping(value = "/deactivateKred", method = RequestMethod.POST)
|
| 29813 |
tejbeer |
1096 |
public String deactivateKred(HttpServletRequest request, @RequestParam int id, Model model) throws Exception {
|
|
|
1097 |
CreditAccount creditAccount = creditAccountRepository.selectById(id);
|
| 29811 |
tejbeer |
1098 |
|
|
|
1099 |
creditAccount.setActive(false);
|
|
|
1100 |
|
|
|
1101 |
Map<Integer, CustomRetailer> customRetailers = retailerService.getAllFofoRetailers();
|
|
|
1102 |
|
|
|
1103 |
model.addAttribute("creditAccount", creditAccount);
|
|
|
1104 |
model.addAttribute("customRetailers", customRetailers);
|
|
|
1105 |
return "partner-credit-detail-row";
|
|
|
1106 |
}
|
|
|
1107 |
|
| 22551 |
ashik.ali |
1108 |
}
|