Subversion Repositories SmartDukaan

Rev

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

Rev 33219 Rev 33338
Line 3... Line 3...
3
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
3
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
4
import com.spice.profitmandi.common.model.BulkOrderModel;
4
import com.spice.profitmandi.common.model.BulkOrderModel;
5
import com.spice.profitmandi.common.util.ExcelUtils;
5
import com.spice.profitmandi.common.util.ExcelUtils;
6
import com.spice.profitmandi.dao.cart.CartService;
6
import com.spice.profitmandi.dao.cart.CartService;
7
import com.spice.profitmandi.dao.entity.catalog.TagListing;
7
import com.spice.profitmandi.dao.entity.catalog.TagListing;
-
 
8
import com.spice.profitmandi.dao.entity.transaction.SDCreditRequirement;
8
import com.spice.profitmandi.dao.entity.transaction.Transaction;
9
import com.spice.profitmandi.dao.entity.transaction.Transaction;
9
import com.spice.profitmandi.dao.entity.transaction.TransactionApproval;
10
import com.spice.profitmandi.dao.entity.transaction.TransactionApproval;
10
import com.spice.profitmandi.dao.enumuration.transaction.TransactionApprovalStatus;
11
import com.spice.profitmandi.dao.enumuration.transaction.TransactionApprovalStatus;
11
import com.spice.profitmandi.dao.model.CartItem;
12
import com.spice.profitmandi.dao.model.CartItem;
12
import com.spice.profitmandi.dao.model.UserCart;
13
import com.spice.profitmandi.dao.model.UserCart;
13
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
14
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
14
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
15
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
-
 
16
import com.spice.profitmandi.dao.repository.transaction.SDCreditRequirementRepository;
15
import com.spice.profitmandi.dao.repository.transaction.TransactionApprovalRepository;
17
import com.spice.profitmandi.dao.repository.transaction.TransactionApprovalRepository;
16
import com.spice.profitmandi.dao.repository.transaction.TransactionRepository;
18
import com.spice.profitmandi.dao.repository.transaction.TransactionRepository;
17
import com.spice.profitmandi.dao.repository.user.AddressRepository;
19
import com.spice.profitmandi.dao.repository.user.AddressRepository;
-
 
20
import com.spice.profitmandi.service.transaction.SDCreditService;
18
import com.spice.profitmandi.service.transaction.TransactionService;
21
import com.spice.profitmandi.service.transaction.TransactionService;
19
import com.spice.profitmandi.service.wallet.CommonPaymentService;
22
import com.spice.profitmandi.service.wallet.CommonPaymentService;
20
import com.spice.profitmandi.service.wallet.WalletService;
23
import com.spice.profitmandi.service.wallet.WalletService;
21
import org.apache.logging.log4j.LogManager;
24
import org.apache.logging.log4j.LogManager;
22
import org.apache.logging.log4j.Logger;
25
import org.apache.logging.log4j.Logger;
Line 28... Line 31...
28
import org.springframework.beans.factory.annotation.Autowired;
31
import org.springframework.beans.factory.annotation.Autowired;
29
import org.springframework.stereotype.Service;
32
import org.springframework.stereotype.Service;
30
import org.springframework.transaction.annotation.Transactional;
33
import org.springframework.transaction.annotation.Transactional;
31
import org.springframework.web.multipart.MultipartFile;
34
import org.springframework.web.multipart.MultipartFile;
32
 
35
 
-
 
36
import java.math.BigDecimal;
33
import java.util.ArrayList;
37
import java.util.ArrayList;
34
import java.util.List;
38
import java.util.List;
35
import java.util.Map;
39
import java.util.Map;
36
import java.util.stream.Collectors;
40
import java.util.stream.Collectors;
37
 
41
 
Line 57... Line 61...
57
    TransactionApprovalRepository transactionApprovalRepository;
61
    TransactionApprovalRepository transactionApprovalRepository;
58
    @Autowired
62
    @Autowired
59
    AddressRepository addressRepository;
63
    AddressRepository addressRepository;
60
    //TODO:Tejus need to check
64
    //TODO:Tejus need to check
61
 
65
 
-
 
66
    @Autowired
-
 
67
    SDCreditService sdCreditService;
-
 
68
 
-
 
69
 
62
    public void parseBulkOrders(MultipartFile file, int creatorId) throws Exception {
70
    public void parseBulkOrders(MultipartFile file, int creatorId) throws Exception {
63
        XSSFWorkbook myWorkBook = new XSSFWorkbook(file.getInputStream());
71
        XSSFWorkbook myWorkBook = new XSSFWorkbook(file.getInputStream());
64
 
72
 
65
        myWorkBook.setMissingCellPolicy(Row.MissingCellPolicy.RETURN_BLANK_AS_NULL);
73
        myWorkBook.setMissingCellPolicy(Row.MissingCellPolicy.RETURN_BLANK_AS_NULL);
66
        // Return first sheet from the XLSX workbook
74
        // Return first sheet from the XLSX workbook
Line 87... Line 95...
87
            if (hasZeroQuantity) {
95
            if (hasZeroQuantity) {
88
                throw new ProfitMandiBusinessException("Item Quantity", "", "Should be greater than 0");
96
                throw new ProfitMandiBusinessException("Item Quantity", "", "Should be greater than 0");
89
            }
97
            }
90
 
98
 
91
            List<CartItem> cartItems = new ArrayList<>();
99
            List<CartItem> cartItems = new ArrayList<>();
92
            double totalAmount = 0;
100
            double totalPayableAmount = 0;
93
            for (BulkOrderModel fofoBulkOrderModel : fofoBulkOrderModels) {
101
            for (BulkOrderModel fofoBulkOrderModel : fofoBulkOrderModels) {
94
                CartItem cartItem = new CartItem();
102
                CartItem cartItem = new CartItem();
95
                cartItem.setQuantity(fofoBulkOrderModel.getQuantity());
103
                cartItem.setQuantity(fofoBulkOrderModel.getQuantity());
96
                cartItem.setItemId(fofoBulkOrderModel.getItemId());
104
                cartItem.setItemId(fofoBulkOrderModel.getItemId());
97
                boolean isPriceZero = fofoBulkOrderModel.getItemPrice() == 0.0;
105
                boolean isPriceZero = fofoBulkOrderModel.getItemPrice() == 0.0;
Line 109... Line 117...
109
                    } else {
117
                    } else {
110
                        throw new ProfitMandiBusinessException("Given price is greater than selling price for item Id - ", itemId, " it should be less or equal of DP");
118
                        throw new ProfitMandiBusinessException("Given price is greater than selling price for item Id - ", itemId, " it should be less or equal of DP");
111
                    }
119
                    }
112
 
120
 
113
                }
121
                }
114
                totalAmount += cartItem.getSellingPrice() * cartItem.getQuantity();
122
                totalPayableAmount += cartItem.getSellingPrice() * cartItem.getQuantity();
115
                cartItems.add(cartItem);
123
                cartItems.add(cartItem);
116
            }
124
            }
117
            LOGGER.info("totalAmount of item " + totalAmount);
125
            LOGGER.info("totalAmount of item " + totalPayableAmount);
118
            double walletAmount = walletService.getWalletAmount(fofoId);
126
            double walletAmount = walletService.getWalletAmount(fofoId);
-
 
127
 
-
 
128
            BigDecimal creditAvailability = sdCreditService.getAvailableAmount(fofoId);
-
 
129
 
-
 
130
            double netAmountInHand = creditAvailability.doubleValue() + walletAmount;
119
            if (totalAmount > 20 && walletAmount < totalAmount) {
131
            if (totalPayableAmount > 20 && walletAmount < netAmountInHand) {
120
                throw new ProfitMandiBusinessException("Skippin order due to insufficent balance for id - ", fofoId, " ,Check wallet Balance ones");
132
                throw new ProfitMandiBusinessException("Skippin order due to insufficent balance for id - ", fofoId, " ,Check wallet Balance ones");
121
            }
133
            }
122
            UserCart userCart = cartService.setCartItems(fofoId, cartItems);
134
            UserCart userCart = cartService.setCartItems(fofoId, cartItems);
123
            // createtransactionInternally set the value in transaction table
135
            // createtransactionInternally set the value in transaction table
-
 
136
 
-
 
137
            double creditAmountRequired = totalPayableAmount - walletAmount - 20;
-
 
138
            if (creditAmountRequired > 0d) {
-
 
139
                sdCreditService.createLoan(userCart.getUserId(), creditAmountRequired, 0);
-
 
140
            }
-
 
141
            //return this.createLoan(userCart.getUserId(), creditAmountRequired);
124
            int transactionId = transactionService.createTransactionInternally(userCart, totalAmount, 0);
142
            int transactionId = transactionService.createTransactionInternally(userCart, totalPayableAmount, 0);
125
            //Set here created by
143
            //Set here created by
126
            Transaction transaction = transactionRepository.selectById(transactionId);
144
            Transaction transaction = transactionRepository.selectById(transactionId);
127
            transaction.setCreatedBy(creatorId);
145
            transaction.setCreatedBy(creatorId);
128
            LOGGER.info("transaction  created by {}", transaction.getCreatedBy());
146
            LOGGER.info("transaction  created by {}", transaction.getCreatedBy());
129
            commonPaymentService.payThroughWallet(transactionId);
147
            commonPaymentService.payThroughWallet(transactionId);