| Line 4... |
Line 4... |
| 4 |
import com.spice.profitmandi.common.model.BulkOrderModel;
|
4 |
import com.spice.profitmandi.common.model.BulkOrderModel;
|
| 5 |
import com.spice.profitmandi.common.model.LineItemModel;
|
5 |
import com.spice.profitmandi.common.model.LineItemModel;
|
| 6 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
6 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 7 |
import com.spice.profitmandi.common.model.TransactionApprovalModel;
|
7 |
import com.spice.profitmandi.common.model.TransactionApprovalModel;
|
| 8 |
import com.spice.profitmandi.common.util.ExcelUtils;
|
8 |
import com.spice.profitmandi.common.util.ExcelUtils;
|
| - |
|
9 |
import com.spice.profitmandi.common.util.Utils;
|
| 9 |
import com.spice.profitmandi.dao.cart.CartService;
|
10 |
import com.spice.profitmandi.dao.cart.CartService;
|
| 10 |
import com.spice.profitmandi.dao.entity.auth.AuthUser;
|
11 |
import com.spice.profitmandi.dao.entity.auth.AuthUser;
|
| - |
|
12 |
import com.spice.profitmandi.dao.entity.catalog.Bid;
|
| - |
|
13 |
import com.spice.profitmandi.dao.entity.catalog.Liquidation;
|
| 11 |
import com.spice.profitmandi.dao.entity.catalog.TagListing;
|
14 |
import com.spice.profitmandi.dao.entity.catalog.TagListing;
|
| - |
|
15 |
import com.spice.profitmandi.dao.entity.dtr.User;
|
| 12 |
import com.spice.profitmandi.dao.entity.transaction.*;
|
16 |
import com.spice.profitmandi.dao.entity.transaction.*;
|
| - |
|
17 |
import com.spice.profitmandi.dao.enumuration.cs.EscalationType;
|
| 13 |
import com.spice.profitmandi.dao.enumuration.transaction.TransactionApprovalStatus;
|
18 |
import com.spice.profitmandi.dao.enumuration.transaction.TransactionApprovalStatus;
|
| 14 |
import com.spice.profitmandi.dao.model.CartItem;
|
19 |
import com.spice.profitmandi.dao.model.CartItem;
|
| 15 |
import com.spice.profitmandi.dao.model.UserCart;
|
20 |
import com.spice.profitmandi.dao.model.UserCart;
|
| 16 |
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
|
21 |
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
|
| 17 |
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
|
22 |
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
|
| - |
|
23 |
import com.spice.profitmandi.dao.repository.cs.CsService;
|
| 18 |
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
|
24 |
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
|
| 19 |
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
|
25 |
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
|
| 20 |
import com.spice.profitmandi.dao.repository.transaction.SDCreditRequirementRepository;
|
26 |
import com.spice.profitmandi.dao.repository.transaction.SDCreditRequirementRepository;
|
| 21 |
import com.spice.profitmandi.dao.repository.transaction.TransactionApprovalRepository;
|
27 |
import com.spice.profitmandi.dao.repository.transaction.TransactionApprovalRepository;
|
| 22 |
import com.spice.profitmandi.dao.repository.transaction.TransactionRepository;
|
28 |
import com.spice.profitmandi.dao.repository.transaction.TransactionRepository;
|
| Line 31... |
Line 37... |
| 31 |
import org.apache.poi.ss.usermodel.Row;
|
37 |
import org.apache.poi.ss.usermodel.Row;
|
| 32 |
import org.apache.poi.xssf.usermodel.XSSFRow;
|
38 |
import org.apache.poi.xssf.usermodel.XSSFRow;
|
| 33 |
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
39 |
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
| 34 |
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
40 |
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
| 35 |
import org.springframework.beans.factory.annotation.Autowired;
|
41 |
import org.springframework.beans.factory.annotation.Autowired;
|
| - |
|
42 |
import org.springframework.mail.javamail.JavaMailSender;
|
| 36 |
import org.springframework.stereotype.Service;
|
43 |
import org.springframework.stereotype.Service;
|
| 37 |
import org.springframework.transaction.annotation.Transactional;
|
44 |
import org.springframework.transaction.annotation.Transactional;
|
| 38 |
import org.springframework.web.multipart.MultipartFile;
|
45 |
import org.springframework.web.multipart.MultipartFile;
|
| 39 |
|
46 |
|
| 40 |
import java.math.BigDecimal;
|
47 |
import java.math.BigDecimal;
|
| Line 65... |
Line 72... |
| 65 |
TransactionApprovalRepository transactionApprovalRepository;
|
72 |
TransactionApprovalRepository transactionApprovalRepository;
|
| 66 |
@Autowired
|
73 |
@Autowired
|
| 67 |
AddressRepository addressRepository;
|
74 |
AddressRepository addressRepository;
|
| 68 |
@Autowired
|
75 |
@Autowired
|
| 69 |
OrderRepository orderRepository;
|
76 |
OrderRepository orderRepository;
|
| 70 |
@Autowired
|
- |
|
| 71 |
AuthRepository authRepository;
|
77 |
//TODO:Tejus need to check
|
| 72 |
@Autowired
|
78 |
@Autowired
|
| 73 |
SDCreditRequirementRepository sdCreditRequirementRepository;
|
79 |
SDCreditRequirementRepository sdCreditRequirementRepository;
|
| 74 |
//TODO:Tejus need to check
|
- |
|
| 75 |
|
- |
|
| 76 |
@Autowired
|
80 |
@Autowired
|
| 77 |
SDCreditService sdCreditService;
|
81 |
SDCreditService sdCreditService;
|
| - |
|
82 |
@Autowired
|
| - |
|
83 |
private CsService csService;
|
| - |
|
84 |
@Autowired
|
| - |
|
85 |
private JavaMailSender mailSender;
|
| - |
|
86 |
@Autowired
|
| - |
|
87 |
private AuthRepository authRepository;
|
| 78 |
|
88 |
|
| 79 |
|
89 |
|
| 80 |
public void parseBulkOrders(MultipartFile file, int creatorId) throws Exception {
|
90 |
public void parseBulkOrders(MultipartFile file, int creatorId) throws Exception, ProfitMandiBusinessException {
|
| 81 |
XSSFWorkbook myWorkBook = new XSSFWorkbook(file.getInputStream());
|
91 |
XSSFWorkbook myWorkBook = new XSSFWorkbook(file.getInputStream());
|
| 82 |
|
92 |
|
| 83 |
myWorkBook.setMissingCellPolicy(Row.MissingCellPolicy.RETURN_BLANK_AS_NULL);
|
93 |
myWorkBook.setMissingCellPolicy(Row.MissingCellPolicy.RETURN_BLANK_AS_NULL);
|
| 84 |
// Return first sheet from the XLSX workbook
|
94 |
// Return first sheet from the XLSX workbook
|
| 85 |
XSSFSheet mySheet = myWorkBook.getSheetAt(0);
|
95 |
XSSFSheet mySheet = myWorkBook.getSheetAt(0);
|
| Line 94... |
Line 104... |
| 94 |
bulkOrderModels.add(bulkOrderModel);
|
104 |
bulkOrderModels.add(bulkOrderModel);
|
| 95 |
} else {
|
105 |
} else {
|
| 96 |
break;
|
106 |
break;
|
| 97 |
}
|
107 |
}
|
| 98 |
}
|
108 |
}
|
| - |
|
109 |
this.generatePurchaseOrder(bulkOrderModels, creatorId, ProfitMandiConstants.PO_TYPE.MANUAL);
|
| - |
|
110 |
}
|
| - |
|
111 |
|
| - |
|
112 |
public void generatePurchaseOrder(List<BulkOrderModel> bulkOrderModels, int creatorId, ProfitMandiConstants.PO_TYPE type) throws Exception,ProfitMandiBusinessException {
|
| 99 |
Map<Integer, List<BulkOrderModel>> fofoBulkOrdersMap = bulkOrderModels.stream().collect(Collectors.groupingBy(x -> x.getFofoId()));
|
113 |
Map<Integer, List<BulkOrderModel>> fofoBulkOrdersMap = bulkOrderModels.stream().collect(Collectors.groupingBy(x -> x.getFofoId()));
|
| 100 |
boolean approvalNotRequired = true;
|
114 |
boolean approvalRequired = false;
|
| 101 |
for (Map.Entry<Integer, List<BulkOrderModel>> fofoBulkOrderEntry : fofoBulkOrdersMap.entrySet()) {
|
115 |
for (Map.Entry<Integer, List<BulkOrderModel>> fofoBulkOrderEntry : fofoBulkOrdersMap.entrySet()) {
|
| 102 |
int fofoId = fofoBulkOrderEntry.getKey();
|
116 |
int fofoId = fofoBulkOrderEntry.getKey();
|
| 103 |
List<BulkOrderModel> fofoBulkOrderModels = fofoBulkOrderEntry.getValue();
|
117 |
List<BulkOrderModel> fofoBulkOrderModels = fofoBulkOrderEntry.getValue();
|
| 104 |
Map<Integer, Long> orderItemCountMap = fofoBulkOrderModels.stream().collect(Collectors.groupingBy(x -> x.getItemId(), Collectors.counting()));
|
118 |
Map<Integer, Long> orderItemCountMap = fofoBulkOrderModels.stream().collect(Collectors.groupingBy(x -> x.getItemId(), Collectors.counting()));
|
| 105 |
|
119 |
|
| Line 131... |
Line 145... |
| 131 |
if (isPriceZero || isActualPrice) {
|
145 |
if (isPriceZero || isActualPrice) {
|
| 132 |
cartItem.setSellingPrice(itemSellingPrice);
|
146 |
cartItem.setSellingPrice(itemSellingPrice);
|
| 133 |
} else {
|
147 |
} else {
|
| 134 |
if (customSellingPrice <= tagListing.getMrp() || customSellingPrice <= tagListing.getMop()) {
|
148 |
if (customSellingPrice <= tagListing.getMrp() || customSellingPrice <= tagListing.getMop()) {
|
| 135 |
cartItem.setSellingPrice(customSellingPrice);
|
149 |
cartItem.setSellingPrice(customSellingPrice);
|
| 136 |
approvalNotRequired = false;
|
150 |
approvalRequired = true;
|
| 137 |
|
151 |
|
| 138 |
} else {
|
152 |
} else {
|
| 139 |
throw new ProfitMandiBusinessException("Given price is greater than selling price for item Id - ", itemId, " it should be less or equal of DP");
|
153 |
throw new ProfitMandiBusinessException("Given price is greater than selling price for item Id - ", itemId, " it should be less or equal of DP");
|
| 140 |
}
|
154 |
}
|
| 141 |
|
155 |
|
| Line 149... |
Line 163... |
| 149 |
BigDecimal creditAvailability = sdCreditService.getAvailableAmount(fofoId);
|
163 |
BigDecimal creditAvailability = sdCreditService.getAvailableAmount(fofoId);
|
| 150 |
|
164 |
|
| 151 |
double netAmountInHand = creditAvailability.doubleValue() + walletAmount;
|
165 |
double netAmountInHand = creditAvailability.doubleValue() + walletAmount;
|
| 152 |
LOGGER.info("netAmountInHand - " + netAmountInHand);
|
166 |
LOGGER.info("netAmountInHand - " + netAmountInHand);
|
| 153 |
if (totalPayableAmount > ProfitMandiConstants.MAX_NEGATIVE_WALLET_VALUE && netAmountInHand < totalPayableAmount) {
|
167 |
if (totalPayableAmount > ProfitMandiConstants.MAX_NEGATIVE_WALLET_VALUE && netAmountInHand < totalPayableAmount) {
|
| - |
|
168 |
if (type == ProfitMandiConstants.PO_TYPE.MANUAL) {
|
| 154 |
throw new ProfitMandiBusinessException("Skipping order due to insufficient balance for id - ", fofoId, " ,Check wallet Balance once");
|
169 |
throw new ProfitMandiBusinessException("Skipping order due to insufficient balance for id - ", fofoId, " ,Check wallet Balance once");
|
| - |
|
170 |
} else {
|
| - |
|
171 |
this.notifyPartnerRBM(netAmountInHand, totalPayableAmount, fofoId);
|
| - |
|
172 |
}
|
| 155 |
}
|
173 |
}
|
| 156 |
UserCart userCart = cartService.setCartItems(fofoId, cartItems);
|
174 |
UserCart userCart = cartService.setCartItems(fofoId, cartItems);
|
| 157 |
// createtransactionInternally set the value in transaction table
|
175 |
// createtransactionInternally set the value in transaction table
|
| 158 |
|
176 |
|
| 159 |
double creditAmountRequired = totalPayableAmount - walletAmount;
|
177 |
double creditAmountRequired = totalPayableAmount - walletAmount;
|
| 160 |
int loanId = 0;
|
178 |
int loanId = 0;
|
| 161 |
if (creditAmountRequired > ProfitMandiConstants.MAX_NEGATIVE_WALLET_VALUE) {
|
179 |
if (creditAmountRequired > ProfitMandiConstants.MAX_NEGATIVE_WALLET_VALUE) {
|
| 162 |
Loan loan = sdCreditService.createLoan(userCart.getUserId(), creditAmountRequired, 365, "Credit limit assigned via SD Credit");
|
180 |
Loan loan = sdCreditService.createLoan(userCart.getUserId(), creditAmountRequired, 365, "Credit limit assigned via SD Credit");
|
| 163 |
loanId = loan.getId();
|
181 |
loanId = loan.getId();
|
| 164 |
}
|
182 |
}
|
| 165 |
//return this.createLoan(userCart.getUserId(), creditAmountRequired);
|
- |
|
| - |
|
183 |
|
| 166 |
int transactionId = transactionService.createTransactionInternally(userCart, totalPayableAmount, 0);
|
184 |
int transactionId = transactionService.createTransactionInternally(userCart, totalPayableAmount, 0);
|
| 167 |
//Set here created by
|
185 |
//Set here created by
|
| 168 |
Transaction transaction = transactionRepository.selectById(transactionId);
|
186 |
Transaction transaction = transactionRepository.selectById(transactionId);
|
| 169 |
transaction.setCreatedBy(creatorId);
|
187 |
transaction.setCreatedBy(creatorId);
|
| 170 |
LOGGER.info("transaction created by {}", transaction.getCreatedBy());
|
188 |
LOGGER.info("transaction created by {}", transaction.getCreatedBy());
|
| 171 |
commonPaymentService.payThroughWallet(transactionId);
|
189 |
commonPaymentService.payThroughWallet(transactionId);
|
| 172 |
if (approvalNotRequired) {
|
190 |
if (approvalRequired) {
|
| 173 |
transactionService.processTransaction(transactionId,loanId);
|
- |
|
| 174 |
} else {
|
- |
|
| 175 |
this.createApproval(transactionId);
|
191 |
this.createApproval(transactionId);
|
| - |
|
192 |
} else {
|
| - |
|
193 |
transactionService.processTransaction(transactionId,loanId);
|
| 176 |
}
|
194 |
}
|
| 177 |
|
195 |
|
| 178 |
}
|
196 |
}
|
| 179 |
|
- |
|
| 180 |
}
|
197 |
}
|
| 181 |
|
198 |
|
| 182 |
public void createApproval(int transactionId) {
|
199 |
public void createApproval(int transactionId) {
|
| 183 |
TransactionApproval transactionApproval = new TransactionApproval();
|
200 |
TransactionApproval transactionApproval = new TransactionApproval();
|
| 184 |
transactionApproval.setId(transactionId);
|
201 |
transactionApproval.setId(transactionId);
|
| Line 246... |
Line 263... |
| 246 |
|
263 |
|
| 247 |
}
|
264 |
}
|
| 248 |
return approvalModelList;
|
265 |
return approvalModelList;
|
| 249 |
}
|
266 |
}
|
| 250 |
|
267 |
|
| - |
|
268 |
public void notifyPartnerRBM(double netAmountInHand, double totalPayableAmount, int fofoId) throws Exception, ProfitMandiBusinessException {
|
| - |
|
269 |
User user = userRepository.selectById(fofoId);
|
| - |
|
270 |
int rbmId = csService.getAuthUserId(ProfitMandiConstants.TICKET_CATEGORY_RBM, EscalationType.L1, fofoId);
|
| - |
|
271 |
AuthUser authUser = authRepository.selectById(rbmId);
|
| - |
|
272 |
|
| - |
|
273 |
//String[] emailTo = new String[] { authUser.getEmailId() };
|
| - |
|
274 |
String[] emailTo = new String[] { "vjangra856@gmail.com" };
|
| - |
|
275 |
|
| - |
|
276 |
String[] ccTo = {"vikas.jangra@smartdukaan.com"};
|
| - |
|
277 |
String subject = "Dispatch On Hold(Bidding)";
|
| - |
|
278 |
String message = String.format(
|
| - |
|
279 |
"Dear Team, \n"
|
| - |
|
280 |
+ "This is to inform you that the material for %s with the value Rs.%s "
|
| - |
|
281 |
+ "purchase is hold till the money against the stock will receive. Kindly inform the partner "
|
| - |
|
282 |
+ "about wallet topup with amount of Rs.%s. The material will be dispatched.",
|
| - |
|
283 |
user.getFirstName(), totalPayableAmount, (totalPayableAmount - netAmountInHand)
|
| - |
|
284 |
);
|
| - |
|
285 |
|
| - |
|
286 |
LOGGER.info("mailMessage: {}",message);
|
| - |
|
287 |
Utils.sendMailWithAttachments(mailSender, emailTo, ccTo, subject, message);
|
| - |
|
288 |
}
|
| - |
|
289 |
|
| 251 |
|
290 |
|
| 252 |
}
|
291 |
}
|