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