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