Subversion Repositories SmartDukaan

Rev

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

Rev 37539 Rev 37590
Line 854... Line 854...
854
            int walletId = closingWalletEntry.getKey();
854
            int walletId = closingWalletEntry.getKey();
855
            int retailerId = walletRetailerMap.get(walletId);
855
            int retailerId = walletRetailerMap.get(walletId);
856
 
856
 
857
            float wallet = closingWalletEntry.getValue() == null ? 0f : closingWalletEntry.getValue();
857
            float wallet = closingWalletEntry.getValue() == null ? 0f : closingWalletEntry.getValue();
858
            float pendingIndent = peindingIndentMap.getOrDefault(retailerId, 0f);
858
            float pendingIndent = peindingIndentMap.getOrDefault(retailerId, 0f);
859
            float loanOutstanding = loanOutstandingMap.getOrDefault(retailerId, 0f);
859
        float loanOutstanding = loanOutstandingMap.getOrDefault(retailerId, 0f);
860
            float accountClosing = wallet + pendingIndent;
860
            float accountClosing = wallet + pendingIndent;
861
 
861
 
862
            CustomRetailer cr = customRetailerMap.get(retailerId);
862
            CustomRetailer cr = customRetailerMap.get(retailerId);
863
 
863
 
864
            rows.add(Arrays.asList(retailerId, cr.getBusinessName(), cr.getAddress().getCity(), cr.getAddress().getState(), accountClosing, wallet, pendingIndent, loanOutstanding));
864
            rows.add(Arrays.asList(retailerId, cr.getBusinessName(), cr.getAddress().getCity(), cr.getAddress().getState(), accountClosing, wallet, pendingIndent, loanOutstanding));
Line 1338... Line 1338...
1338
    }
1338
    }
1339
 
1339
 
1340
    @RequestMapping(value = "/walletUpdate", method = RequestMethod.POST)
1340
    @RequestMapping(value = "/walletUpdate", method = RequestMethod.POST)
1341
    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 {
1341
    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 {
1342
        WalletReferenceType referenceType = WalletReferenceType.findByValue(referenceTypeValue);
1342
        WalletReferenceType referenceType = WalletReferenceType.findByValue(referenceTypeValue);
1343
        if (reference == 0 && referenceType.getValue() >= WalletReferenceType.INCENTIVES.getValue()) {
-
 
1344
            LOGGER.error("referenceType: " + referenceType);
-
 
1345
            ManualPaymentType paymentType = manualPaymentRequestRepository.selectByReferenceType(referenceType);
1343
        int usedReference = walletService.applyManualAdjustment(retailerId, reference, referenceType,
1346
 
-
 
1347
            if (paymentType == null) {
-
 
1348
                paymentType = new ManualPaymentType();
-
 
1349
                paymentType.setReferenceType(referenceType);
-
 
1350
            }
-
 
1351
            paymentType.setCounter(paymentType.getCounter() + 1);
-
 
1352
            manualPaymentRequestRepository.persist(paymentType);
-
 
1353
            reference = paymentType.getCounter();
-
 
1354
 
-
 
1355
        } else if (reference == 0) {
-
 
1356
            throw new ProfitMandiBusinessException("RefrenceId", reference, "System specific reference type cant be used manually");
-
 
1357
        }
-
 
1358
 
-
 
1359
        List<UserWalletHistory> userWalletHistoryList = userWalletHistoryRepository.selectAllByreferenceIdandreferenceType(reference, referenceType);
-
 
1360
        UserWallet userWallet = userWalletRepository.selectByRetailerId(retailerId);
-
 
1361
        int walletId = userWallet.getId();
-
 
1362
        int walletAmount = walletService.getWalletAmount(retailerId);
-
 
1363
 
-
 
1364
        int returnReference = 0;
-
 
1365
        UserWalletHistory newUserWalletHistory = new UserWalletHistory();
-
 
1366
 
-
 
1367
        if (!userWalletHistoryList.isEmpty()) {
-
 
1368
            long validRetailerEntries = userWalletHistoryList.stream().filter(x -> x.getWalletId() == walletId).count();
-
 
1369
            if (validRetailerEntries == 0) {
-
 
1370
                throw new ProfitMandiBusinessException("RefrenceId", reference, "Reference Id assign to Other  partner");
-
 
1371
            }
-
 
1372
        }
-
 
1373
 
-
 
1374
        if (TransactionType.DEBIT.equals(transactiontype)) {
-
 
1375
            amount = -amount;
-
 
1376
        }
-
 
1377
 
-
 
1378
        userWallet.setAmount(walletAmount + amount);
-
 
1379
        newUserWalletHistory.setAmount(amount);
-
 
1380
        newUserWalletHistory.setBusinessTimestamp(businessTimestamp);
1344
                transactiontype, amount, description, businessTimestamp);
1381
        newUserWalletHistory.setDescription(description);
-
 
1382
        newUserWalletHistory.setReference(reference);
-
 
1383
        newUserWalletHistory.setWalletId(userWallet.getId());
-
 
1384
        newUserWalletHistory.setReferenceType(referenceType);
-
 
1385
        newUserWalletHistory.setTimestamp(LocalDateTime.now());
-
 
1386
        newUserWalletHistory.setRunningBalance(userWallet.getAmount());
-
 
1387
        userWalletHistoryRepository.persist(newUserWalletHistory);
-
 
1388
 
1345
 
1389
        model.addAttribute("response1", mvcResponseSender.createResponseString(reference));
1346
        model.addAttribute("response1", mvcResponseSender.createResponseString(usedReference));
1390
        return "response";
1347
        return "response";
1391
 
1348
 
1392
    }
1349
    }
1393
 
1350
 
1394
    @RequestMapping(value = "/addMoney", method = RequestMethod.POST)
1351
    @RequestMapping(value = "/addMoney", method = RequestMethod.POST)