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