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