Subversion Repositories SmartDukaan

Rev

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

Rev 34468 Rev 34492
Line 164... Line 164...
164
 
164
 
165
                }
165
                }
166
                totalPayableAmount += cartItem.getSellingPrice() * cartItem.getQuantity();
166
                totalPayableAmount += cartItem.getSellingPrice() * cartItem.getQuantity();
167
                cartItems.add(cartItem);
167
                cartItems.add(cartItem);
168
            }
168
            }
-
 
169
            Bid bid = bidRepository.selectById(fofoBulkOrderModels.get(0).getRowIndex());
169
            LOGGER.info("totalAmount of item " + totalPayableAmount);
170
            LOGGER.info("totalAmount of item " + totalPayableAmount);
170
            double walletAmount = walletService.getWalletAmount(fofoId);
171
            double walletAmount = walletService.getWalletAmount(fofoId);
171
 
172
 
172
            BigDecimal creditAvailability = sdCreditService.getAvailableAmount(fofoId);
173
            BigDecimal creditAvailability = sdCreditService.getAvailableAmount(fofoId);
173
 
174
 
Line 177... Line 178...
177
                if (type.equals(ProfitMandiConstants.PO_TYPE.MANUAL)) {
178
                if (type.equals(ProfitMandiConstants.PO_TYPE.MANUAL)) {
178
                    throw new ProfitMandiBusinessException("Skipping order due to insufficient balance for id - ", fofoId, " ,Check wallet Balance once");
179
                    throw new ProfitMandiBusinessException("Skipping order due to insufficient balance for id - ", fofoId, " ,Check wallet Balance once");
179
                } else {
180
                } else {
180
                    if (scheduleType.equals(ProfitMandiConstants.BID_CRON_ENUM.TODAY)) {
181
                    if (scheduleType.equals(ProfitMandiConstants.BID_CRON_ENUM.TODAY)) {
181
                        bidService.sendMailToRBM(netAmountInHand, totalPayableAmount, fofoId);
182
                        bidService.sendMailToRBM(netAmountInHand, totalPayableAmount, fofoId);
-
 
183
                        bid.setStatus(ProfitMandiConstants.BID_ENUM.PROCESSING);
182
                        throw new ProfitMandiBusinessException("Skipping order due to insufficient balance for id - ", fofoId, " ,Sending mail to RBM");
184
                        throw new ProfitMandiBusinessException("Skipping order due to insufficient balance for id - ", fofoId, " ,Sending mail to RBM");
183
                    } else {
185
                    } else {
184
                        bidService.cancelYesterdayProcessBid(fofoBulkOrderModels.get(0).getRowIndex());
186
                        bidService.cancelYesterdayProcessBid(bid);
185
                        throw new ProfitMandiBusinessException("Skipping order due to insufficient balance for id - ", fofoId, " ,Cancelling the BID");
187
                        throw new ProfitMandiBusinessException("Skipping order due to insufficient balance for id - ", fofoId, " ,Cancelling the BID");
186
                    }
188
                    }
187
                }
189
                }
188
            }
190
            }
189
            UserCart userCart = cartService.setCartItems(fofoId, cartItems);
191
            UserCart userCart = cartService.setCartItems(fofoId, cartItems);
190
            // createtransactionInternally set the value in transaction table
192
            // createtransactionInternally set the value in transaction table
191
 
193
 
192
            double creditAmountRequired = totalPayableAmount - walletAmount;
194
            double creditAmountRequired = totalPayableAmount - walletAmount;
193
            int loanId = 0;
195
            int loanId = 0;
-
 
196
            try {
194
            if (creditAmountRequired > ProfitMandiConstants.MAX_NEGATIVE_WALLET_VALUE) {
197
                if (creditAmountRequired > ProfitMandiConstants.MAX_NEGATIVE_WALLET_VALUE) {
195
                Loan loan = sdCreditService.createLoan(userCart.getUserId(), creditAmountRequired, 365, "Credit limit assigned via SD Credit");
198
                    Loan loan = sdCreditService.createLoan(userCart.getUserId(), creditAmountRequired, 365, "Credit limit assigned via SD Credit");
196
                loanId = loan.getId();
199
                    loanId = loan.getId();
-
 
200
                }
-
 
201
            } catch (Exception exception){
-
 
202
                bidService.sendMailToRBM(netAmountInHand, totalPayableAmount, fofoId);
-
 
203
                bid.setStatus(ProfitMandiConstants.BID_ENUM.PROCESSING);
-
 
204
                throw new ProfitMandiBusinessException("Skipping order unable to create load for id - ", fofoId, " ,Sending mail to RBM");
197
            }
205
            }
198
 
206
 
199
            int transactionId = transactionService.createTransactionInternally(userCart, totalPayableAmount, 0);
207
            int transactionId = transactionService.createTransactionInternally(userCart, totalPayableAmount, 0);
200
            //Set here created by
208
            //Set here created by
201
            Transaction transaction = transactionRepository.selectById(transactionId);
209
            Transaction transaction = transactionRepository.selectById(transactionId);
202
            transaction.setCreatedBy(creatorId);
210
            transaction.setCreatedBy(creatorId);
203
            LOGGER.info("transaction  created by {}", transaction.getCreatedBy());
211
            LOGGER.info("transaction  created by {}", transaction.getCreatedBy());
204
            commonPaymentService.payThroughWallet(transactionId);
212
            commonPaymentService.payThroughWallet(transactionId);
-
 
213
            bid.setStatus(ProfitMandiConstants.BID_ENUM.CLOSED);
205
            if (approvalRequired) {
214
            if (approvalRequired) {
206
                this.createApproval(transactionId);
215
                this.createApproval(transactionId);
207
            } else {
216
            } else {
208
                transactionService.processTransaction(transactionId,loanId);
217
                transactionService.processTransaction(transactionId,loanId);
209
            }
218
            }