Subversion Repositories SmartDukaan

Rev

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

Rev 36064 Rev 36242
Line 234... Line 234...
234
        BigDecimal availableLimit = creditSummary.getAvailableLimit();
234
        BigDecimal availableLimit = creditSummary.getAvailableLimit();
235
        BigDecimal creditlimit = sdCreditRequirement.getLimit();
235
        BigDecimal creditlimit = sdCreditRequirement.getLimit();
236
        BigDecimal totalDue = creditSummary.getTotalDue();
236
        BigDecimal totalDue = creditSummary.getTotalDue();
237
        model.addAttribute("userWallet", userWallet);
237
        model.addAttribute("userWallet", userWallet);
238
        model.addAttribute("walletHistories", userWalletHistories);
238
        model.addAttribute("walletHistories", userWalletHistories);
-
 
239
        model.addAttribute("walletAttachmentMap", buildWalletHistoryAttachmentMap(userWalletHistories));
239
        model.addAttribute("start", offset + 1);
240
        model.addAttribute("start", offset + 1);
240
        model.addAttribute("size", countItems);
241
        model.addAttribute("size", countItems);
241
        model.addAttribute("isAdmin", isAdmin);
242
        model.addAttribute("isAdmin", isAdmin);
242
        model.addAttribute("loans", loans);
243
        model.addAttribute("loans", loans);
243
        model.addAttribute("totalDue", totalDue);
244
        model.addAttribute("totalDue", totalDue);
Line 268... Line 269...
268
        } catch (ProfitMandiBusinessException profitMandiBusinessException) {
269
        } catch (ProfitMandiBusinessException profitMandiBusinessException) {
269
            LOGGER.error("UserWallet History not found : ", profitMandiBusinessException);
270
            LOGGER.error("UserWallet History not found : ", profitMandiBusinessException);
270
        }
271
        }
271
 
272
 
272
        model.addAttribute("walletHistories", userWalletHistories);
273
        model.addAttribute("walletHistories", userWalletHistories);
-
 
274
        model.addAttribute("walletAttachmentMap", buildWalletHistoryAttachmentMap(userWalletHistories));
273
        return "wallet-history-paginated";
275
        return "wallet-history-paginated";
274
    }
276
    }
275
 
277
 
276
    @RequestMapping(value = "/getAddWalletRequest", method = RequestMethod.GET)
278
    @RequestMapping(value = "/getAddWalletRequest", method = RequestMethod.GET)
277
    public String getAddwalletRequest(HttpServletRequest request, @RequestParam(name = "offset", defaultValue = "0") int offset, @RequestParam(name = "limit", defaultValue = "10") int limit, Model model) throws Exception {
279
    public String getAddwalletRequest(HttpServletRequest request, @RequestParam(name = "offset", defaultValue = "0") int offset, @RequestParam(name = "limit", defaultValue = "10") int limit, Model model) throws Exception {
Line 287... Line 289...
287
 
289
 
288
            Map<Integer, CustomRetailer> fofoIdsAndRetailerName = fofoIds.stream().map(x -> customRetailerMap.get(x)).filter(x -> x != null).collect(Collectors.toMap(x -> x.getPartnerId(), x -> x));
290
            Map<Integer, CustomRetailer> fofoIdsAndRetailerName = fofoIds.stream().map(x -> customRetailerMap.get(x)).filter(x -> x != null).collect(Collectors.toMap(x -> x.getPartnerId(), x -> x));
289
 
291
 
290
            model.addAttribute("fofoIdsAndRetailerName", fofoIdsAndRetailerName);
292
            model.addAttribute("fofoIdsAndRetailerName", fofoIdsAndRetailerName);
291
            model.addAttribute("walletRequest", walletRequest);
293
            model.addAttribute("walletRequest", walletRequest);
-
 
294
            model.addAttribute("fspAttachmentMap", buildFspAttachmentMap(walletRequest));
292
            model.addAttribute("rStatus", "pending");
295
            model.addAttribute("rStatus", "pending");
293
            model.addAttribute("start", offset + 1);
296
            model.addAttribute("start", offset + 1);
294
            model.addAttribute("size", size);
297
            model.addAttribute("size", size);
295
            model.addAttribute("url", "/getPaginatedWalletRequest");
298
            model.addAttribute("url", "/getPaginatedWalletRequest");
296
 
299
 
Line 321... Line 324...
321
 
324
 
322
            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));
325
            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));
323
 
326
 
324
            model.addAttribute("fofoIdsAndRetailerName", fofoIdsAndRetailerName);
327
            model.addAttribute("fofoIdsAndRetailerName", fofoIdsAndRetailerName);
325
            model.addAttribute("walletRequest", walletRequest);
328
            model.addAttribute("walletRequest", walletRequest);
-
 
329
            model.addAttribute("fspAttachmentMap", buildFspAttachmentMap(walletRequest));
326
            model.addAttribute("rStatus", "pending");
330
            model.addAttribute("rStatus", "pending");
327
            model.addAttribute("url", "/getPaginatedWalletRequest");
331
            model.addAttribute("url", "/getPaginatedWalletRequest");
328
 
332
 
329
        } else {
333
        } else {
330
            model.addAttribute("walletRequest", walletRequest);
334
            model.addAttribute("walletRequest", walletRequest);
Line 355... Line 359...
355
 
359
 
356
            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));
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));
357
 
361
 
358
            model.addAttribute("fofoIdsAndRetailerName", fofoIdsAndRetailerName);
362
            model.addAttribute("fofoIdsAndRetailerName", fofoIdsAndRetailerName);
359
            model.addAttribute("walletRequest", walletRequest);
363
            model.addAttribute("walletRequest", walletRequest);
-
 
364
            model.addAttribute("fspAttachmentMap", buildFspAttachmentMap(walletRequest));
360
            model.addAttribute("start", offset + 1);
365
            model.addAttribute("start", offset + 1);
361
            model.addAttribute("size", size);
366
            model.addAttribute("size", size);
362
            model.addAttribute("url", "/getPaginatedWalletApproved");
367
            model.addAttribute("url", "/getPaginatedWalletApproved");
363
 
368
 
364
            if (walletRequest.size() < limit) {
369
            if (walletRequest.size() < limit) {
Line 391... Line 396...
391
 
396
 
392
            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));
397
            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));
393
 
398
 
394
            model.addAttribute("fofoIdsAndRetailerName", fofoIdsAndRetailerName);
399
            model.addAttribute("fofoIdsAndRetailerName", fofoIdsAndRetailerName);
395
            model.addAttribute("walletRequest", walletRequest);
400
            model.addAttribute("walletRequest", walletRequest);
-
 
401
            model.addAttribute("fspAttachmentMap", buildFspAttachmentMap(walletRequest));
396
            model.addAttribute("url", "/getPaginatedWalletApproved");
402
            model.addAttribute("url", "/getPaginatedWalletApproved");
397
        } else {
403
        } else {
398
            model.addAttribute("walletRequest", walletRequest);
404
            model.addAttribute("walletRequest", walletRequest);
399
 
405
 
400
        }
406
        }
Line 422... Line 428...
422
 
428
 
423
            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));
429
            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));
424
 
430
 
425
            model.addAttribute("fofoIdsAndRetailerName", fofoIdsAndRetailerName);
431
            model.addAttribute("fofoIdsAndRetailerName", fofoIdsAndRetailerName);
426
            model.addAttribute("walletRequest", walletRequest);
432
            model.addAttribute("walletRequest", walletRequest);
-
 
433
            model.addAttribute("fspAttachmentMap", buildFspAttachmentMap(walletRequest));
427
            model.addAttribute("start", offset + 1);
434
            model.addAttribute("start", offset + 1);
428
            model.addAttribute("size", size);
435
            model.addAttribute("size", size);
429
            model.addAttribute("url", "/getPaginatedWalletRequestRejected");
436
            model.addAttribute("url", "/getPaginatedWalletRequestRejected");
430
 
437
 
431
            if (walletRequest.size() < limit) {
438
            if (walletRequest.size() < limit) {
Line 453... Line 460...
453
            Map<Integer, CustomRetailer> customRetailerMap = retailerService.getAllFofoRetailers();
460
            Map<Integer, CustomRetailer> customRetailerMap = retailerService.getAllFofoRetailers();
454
 
461
 
455
            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));
462
            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));
456
            model.addAttribute("fofoIdsAndRetailerName", fofoIdsAndRetailerName);
463
            model.addAttribute("fofoIdsAndRetailerName", fofoIdsAndRetailerName);
457
            model.addAttribute("walletRequest", walletRequest);
464
            model.addAttribute("walletRequest", walletRequest);
-
 
465
            model.addAttribute("fspAttachmentMap", buildFspAttachmentMap(walletRequest));
458
            model.addAttribute("url", "/getPaginatedWalletRequestRejected");
466
            model.addAttribute("url", "/getPaginatedWalletRequestRejected");
459
        } else {
467
        } else {
460
            model.addAttribute("walletRequest", walletRequest);
468
            model.addAttribute("walletRequest", walletRequest);
461
 
469
 
462
        }
470
        }
Line 619... Line 627...
619
 
627
 
620
    private List<Integer> getFofoIdsFromWalletRequest(List<AddWalletRequest> walletRequest) {
628
    private List<Integer> getFofoIdsFromWalletRequest(List<AddWalletRequest> walletRequest) {
621
        return walletRequest.stream().map(x -> x.getRetailerId()).distinct().collect(Collectors.toList());
629
        return walletRequest.stream().map(x -> x.getRetailerId()).distinct().collect(Collectors.toList());
622
    }
630
    }
623
 
631
 
-
 
632
    /**
-
 
633
     * Builds a map of AddWalletRequest.id -> FullStockPayment.attachment for requests linked to FSP.
-
 
634
     */
-
 
635
    private Map<Integer, Integer> buildFspAttachmentMap(List<AddWalletRequest> walletRequests) {
-
 
636
        Map<Integer, Integer> attachmentMap = new HashMap<>();
-
 
637
        List<Integer> fspIds = walletRequests.stream()
-
 
638
                .filter(r -> r.getFspId() > 0)
-
 
639
                .map(AddWalletRequest::getFspId)
-
 
640
                .distinct()
-
 
641
                .collect(Collectors.toList());
-
 
642
        if (fspIds.isEmpty()) {
-
 
643
            return attachmentMap;
-
 
644
        }
-
 
645
        List<FullStockPayment> fspList = fullStockPaymentRepository.selectByIds(fspIds);
-
 
646
        Map<Integer, Integer> fspIdToAttachment = fspList.stream()
-
 
647
                .filter(f -> f.getAttachment() > 0)
-
 
648
                .collect(Collectors.toMap(FullStockPayment::getId, FullStockPayment::getAttachment));
-
 
649
        for (AddWalletRequest r : walletRequests) {
-
 
650
            if (r.getFspId() > 0 && fspIdToAttachment.containsKey(r.getFspId())) {
-
 
651
                attachmentMap.put(r.getId(), fspIdToAttachment.get(r.getFspId()));
-
 
652
            }
-
 
653
        }
-
 
654
        return attachmentMap;
-
 
655
    }
-
 
656
 
-
 
657
    /**
-
 
658
     * Builds a map of UserWalletHistory.id -> FullStockPayment.attachment for ADVANCE_AMOUNT entries linked to FSP.
-
 
659
     */
-
 
660
    private Map<Integer, Integer> buildWalletHistoryAttachmentMap(List<UserWalletHistory> histories) {
-
 
661
        Map<Integer, Integer> attachmentMap = new HashMap<>();
-
 
662
        List<Integer> awrIds = histories.stream()
-
 
663
                .filter(h -> h.getReferenceType() == WalletReferenceType.ADVANCE_AMOUNT && h.getReference() > 0)
-
 
664
                .map(UserWalletHistory::getReference)
-
 
665
                .distinct()
-
 
666
                .collect(Collectors.toList());
-
 
667
        if (awrIds.isEmpty()) {
-
 
668
            return attachmentMap;
-
 
669
        }
-
 
670
        List<AddWalletRequest> awrList = addWalletRequestRepository.selectByIds(awrIds);
-
 
671
        Map<Integer, Integer> awrIdToFspId = awrList.stream()
-
 
672
                .filter(r -> r.getFspId() > 0)
-
 
673
                .collect(Collectors.toMap(AddWalletRequest::getId, AddWalletRequest::getFspId));
-
 
674
        List<Integer> fspIds = awrIdToFspId.values().stream().distinct().collect(Collectors.toList());
-
 
675
        if (fspIds.isEmpty()) {
-
 
676
            return attachmentMap;
-
 
677
        }
-
 
678
        List<FullStockPayment> fspList = fullStockPaymentRepository.selectByIds(fspIds);
-
 
679
        Map<Integer, Integer> fspIdToAttachment = fspList.stream()
-
 
680
                .filter(f -> f.getAttachment() > 0)
-
 
681
                .collect(Collectors.toMap(FullStockPayment::getId, FullStockPayment::getAttachment));
-
 
682
        for (UserWalletHistory h : histories) {
-
 
683
            if (h.getReferenceType() == WalletReferenceType.ADVANCE_AMOUNT && h.getReference() > 0) {
-
 
684
                Integer fspId = awrIdToFspId.get(h.getReference());
-
 
685
                if (fspId != null && fspIdToAttachment.containsKey(fspId)) {
-
 
686
                    attachmentMap.put(h.getId(), fspIdToAttachment.get(fspId));
-
 
687
                }
-
 
688
            }
-
 
689
        }
-
 
690
        return attachmentMap;
-
 
691
    }
-
 
692
 
624
    @RequestMapping(value = "/getcreateUnsettledPayments", method = RequestMethod.GET)
693
    @RequestMapping(value = "/getcreateUnsettledPayments", method = RequestMethod.GET)
625
    public String getcreateUnsettledPayment(HttpServletRequest request, @RequestParam(name = "offset", defaultValue = "0") int offset, @RequestParam(name = "limit", defaultValue = "15") int limit, Model model) throws Exception {
694
    public String getcreateUnsettledPayment(HttpServletRequest request, @RequestParam(name = "offset", defaultValue = "0") int offset, @RequestParam(name = "limit", defaultValue = "15") int limit, Model model) throws Exception {
626
        List<UnsettledPayment> up = null;
695
        List<UnsettledPayment> up = null;
627
 
696
 
628
        long size = 0;
697
        long size = 0;