Subversion Repositories SmartDukaan

Rev

Rev 32494 | Rev 32512 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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