| Line 17... |
Line 17... |
| 17 |
import com.spice.profitmandi.dao.enumuration.cs.EscalationType;
|
17 |
import com.spice.profitmandi.dao.enumuration.cs.EscalationType;
|
| 18 |
import com.spice.profitmandi.dao.enumuration.transaction.TransactionApprovalStatus;
|
18 |
import com.spice.profitmandi.dao.enumuration.transaction.TransactionApprovalStatus;
|
| 19 |
import com.spice.profitmandi.dao.model.CartItem;
|
19 |
import com.spice.profitmandi.dao.model.CartItem;
|
| 20 |
import com.spice.profitmandi.dao.model.UserCart;
|
20 |
import com.spice.profitmandi.dao.model.UserCart;
|
| 21 |
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
|
21 |
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
|
| - |
|
22 |
import com.spice.profitmandi.dao.repository.catalog.BidRepository;
|
| - |
|
23 |
import com.spice.profitmandi.dao.repository.catalog.LiquidationRepository;
|
| 22 |
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
|
24 |
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
|
| 23 |
import com.spice.profitmandi.dao.repository.cs.CsService;
|
25 |
import com.spice.profitmandi.dao.repository.cs.CsService;
|
| 24 |
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
|
26 |
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
|
| 25 |
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
|
27 |
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
|
| 26 |
import com.spice.profitmandi.dao.repository.transaction.SDCreditRequirementRepository;
|
28 |
import com.spice.profitmandi.dao.repository.transaction.SDCreditRequirementRepository;
|
| 27 |
import com.spice.profitmandi.dao.repository.transaction.TransactionApprovalRepository;
|
29 |
import com.spice.profitmandi.dao.repository.transaction.TransactionApprovalRepository;
|
| 28 |
import com.spice.profitmandi.dao.repository.transaction.TransactionRepository;
|
30 |
import com.spice.profitmandi.dao.repository.transaction.TransactionRepository;
|
| 29 |
import com.spice.profitmandi.dao.repository.user.AddressRepository;
|
31 |
import com.spice.profitmandi.dao.repository.user.AddressRepository;
|
| - |
|
32 |
import com.spice.profitmandi.dao.service.BidService;
|
| - |
|
33 |
import com.spice.profitmandi.service.AuthService;
|
| 30 |
import com.spice.profitmandi.service.transaction.SDCreditService;
|
34 |
import com.spice.profitmandi.service.transaction.SDCreditService;
|
| 31 |
import com.spice.profitmandi.service.transaction.TransactionService;
|
35 |
import com.spice.profitmandi.service.transaction.TransactionService;
|
| 32 |
import com.spice.profitmandi.service.wallet.CommonPaymentService;
|
36 |
import com.spice.profitmandi.service.wallet.CommonPaymentService;
|
| 33 |
import com.spice.profitmandi.service.wallet.WalletService;
|
37 |
import com.spice.profitmandi.service.wallet.WalletService;
|
| 34 |
import org.apache.logging.log4j.LogManager;
|
38 |
import org.apache.logging.log4j.LogManager;
|
| Line 43... |
Line 47... |
| 43 |
import org.springframework.stereotype.Service;
|
47 |
import org.springframework.stereotype.Service;
|
| 44 |
import org.springframework.transaction.annotation.Transactional;
|
48 |
import org.springframework.transaction.annotation.Transactional;
|
| 45 |
import org.springframework.web.multipart.MultipartFile;
|
49 |
import org.springframework.web.multipart.MultipartFile;
|
| 46 |
|
50 |
|
| 47 |
import java.math.BigDecimal;
|
51 |
import java.math.BigDecimal;
|
| - |
|
52 |
import java.nio.charset.StandardCharsets;
|
| 48 |
import java.util.ArrayList;
|
53 |
import java.util.ArrayList;
|
| 49 |
import java.util.List;
|
54 |
import java.util.List;
|
| 50 |
import java.util.Map;
|
55 |
import java.util.Map;
|
| 51 |
import java.util.stream.Collectors;
|
56 |
import java.util.stream.Collectors;
|
| 52 |
|
57 |
|
| Line 80... |
Line 85... |
| 80 |
@Autowired
|
85 |
@Autowired
|
| 81 |
SDCreditService sdCreditService;
|
86 |
SDCreditService sdCreditService;
|
| 82 |
@Autowired
|
87 |
@Autowired
|
| 83 |
private CsService csService;
|
88 |
private CsService csService;
|
| 84 |
@Autowired
|
89 |
@Autowired
|
| 85 |
private JavaMailSender mailSender;
|
- |
|
| 86 |
@Autowired
|
- |
|
| 87 |
private AuthRepository authRepository;
|
90 |
private AuthRepository authRepository;
|
| - |
|
91 |
@Autowired
|
| - |
|
92 |
private BidRepository bidRepository;
|
| - |
|
93 |
@Autowired
|
| - |
|
94 |
private BidService bidService;
|
| - |
|
95 |
@Autowired
|
| - |
|
96 |
private LiquidationRepository liquidationRepository;
|
| 88 |
|
97 |
|
| 89 |
|
98 |
|
| 90 |
public void parseBulkOrders(MultipartFile file, int creatorId) throws Exception, ProfitMandiBusinessException {
|
99 |
public void parseBulkOrders(MultipartFile file, int creatorId) throws Exception {
|
| 91 |
XSSFWorkbook myWorkBook = new XSSFWorkbook(file.getInputStream());
|
100 |
XSSFWorkbook myWorkBook = new XSSFWorkbook(file.getInputStream());
|
| 92 |
|
101 |
|
| 93 |
myWorkBook.setMissingCellPolicy(Row.MissingCellPolicy.RETURN_BLANK_AS_NULL);
|
102 |
myWorkBook.setMissingCellPolicy(Row.MissingCellPolicy.RETURN_BLANK_AS_NULL);
|
| 94 |
// Return first sheet from the XLSX workbook
|
103 |
// Return first sheet from the XLSX workbook
|
| 95 |
XSSFSheet mySheet = myWorkBook.getSheetAt(0);
|
104 |
XSSFSheet mySheet = myWorkBook.getSheetAt(0);
|
| Line 104... |
Line 113... |
| 104 |
bulkOrderModels.add(bulkOrderModel);
|
113 |
bulkOrderModels.add(bulkOrderModel);
|
| 105 |
} else {
|
114 |
} else {
|
| 106 |
break;
|
115 |
break;
|
| 107 |
}
|
116 |
}
|
| 108 |
}
|
117 |
}
|
| 109 |
this.generatePurchaseOrder(bulkOrderModels, creatorId, ProfitMandiConstants.PO_TYPE.MANUAL);
|
118 |
this.generatePurchaseOrder(bulkOrderModels, creatorId, ProfitMandiConstants.PO_TYPE.MANUAL, ProfitMandiConstants.BID_CRON_ENUM.TODAY);
|
| 110 |
}
|
119 |
}
|
| 111 |
|
120 |
|
| 112 |
public void generatePurchaseOrder(List<BulkOrderModel> bulkOrderModels, int creatorId, ProfitMandiConstants.PO_TYPE type) throws Exception,ProfitMandiBusinessException {
|
121 |
public void generatePurchaseOrder(List<BulkOrderModel> bulkOrderModels, int creatorId, ProfitMandiConstants.PO_TYPE type, ProfitMandiConstants.BID_CRON_ENUM scheduleType) throws Exception {
|
| 113 |
Map<Integer, List<BulkOrderModel>> fofoBulkOrdersMap = bulkOrderModels.stream().collect(Collectors.groupingBy(x -> x.getFofoId()));
|
122 |
Map<Integer, List<BulkOrderModel>> fofoBulkOrdersMap = bulkOrderModels.stream().collect(Collectors.groupingBy(x -> x.getFofoId()));
|
| 114 |
boolean approvalRequired = false;
|
123 |
boolean approvalRequired = false;
|
| 115 |
for (Map.Entry<Integer, List<BulkOrderModel>> fofoBulkOrderEntry : fofoBulkOrdersMap.entrySet()) {
|
124 |
for (Map.Entry<Integer, List<BulkOrderModel>> fofoBulkOrderEntry : fofoBulkOrdersMap.entrySet()) {
|
| 116 |
int fofoId = fofoBulkOrderEntry.getKey();
|
125 |
int fofoId = fofoBulkOrderEntry.getKey();
|
| 117 |
List<BulkOrderModel> fofoBulkOrderModels = fofoBulkOrderEntry.getValue();
|
126 |
List<BulkOrderModel> fofoBulkOrderModels = fofoBulkOrderEntry.getValue();
|
| Line 163... |
Line 172... |
| 163 |
BigDecimal creditAvailability = sdCreditService.getAvailableAmount(fofoId);
|
172 |
BigDecimal creditAvailability = sdCreditService.getAvailableAmount(fofoId);
|
| 164 |
|
173 |
|
| 165 |
double netAmountInHand = creditAvailability.doubleValue() + walletAmount;
|
174 |
double netAmountInHand = creditAvailability.doubleValue() + walletAmount;
|
| 166 |
LOGGER.info("netAmountInHand - " + netAmountInHand);
|
175 |
LOGGER.info("netAmountInHand - " + netAmountInHand);
|
| 167 |
if (totalPayableAmount > ProfitMandiConstants.MAX_NEGATIVE_WALLET_VALUE && netAmountInHand < totalPayableAmount) {
|
176 |
if (totalPayableAmount > ProfitMandiConstants.MAX_NEGATIVE_WALLET_VALUE && netAmountInHand < totalPayableAmount) {
|
| 168 |
if (type == ProfitMandiConstants.PO_TYPE.MANUAL) {
|
177 |
if (type.equals(ProfitMandiConstants.PO_TYPE.MANUAL)) {
|
| 169 |
throw new ProfitMandiBusinessException("Skipping order due to insufficient balance for id - ", fofoId, " ,Check wallet Balance once");
|
178 |
throw new ProfitMandiBusinessException("Skipping order due to insufficient balance for id - ", fofoId, " ,Check wallet Balance once");
|
| 170 |
} else {
|
179 |
} else {
|
| - |
|
180 |
if (scheduleType.equals(ProfitMandiConstants.BID_CRON_ENUM.TODAY)) {
|
| 171 |
this.notifyPartnerRBM(netAmountInHand, totalPayableAmount, fofoId);
|
181 |
bidService.sendMailToRBM(netAmountInHand, totalPayableAmount, fofoId);
|
| - |
|
182 |
throw new ProfitMandiBusinessException("Skipping order due to insufficient balance for id - ", fofoId, " ,Sending mail to RBM");
|
| - |
|
183 |
} else {
|
| - |
|
184 |
bidService.cancelYesterdayProcessBid(fofoBulkOrderModels.get(0).getRowIndex());
|
| - |
|
185 |
throw new ProfitMandiBusinessException("Skipping order due to insufficient balance for id - ", fofoId, " ,Cancelling the BID");
|
| - |
|
186 |
}
|
| 172 |
}
|
187 |
}
|
| 173 |
}
|
188 |
}
|
| 174 |
UserCart userCart = cartService.setCartItems(fofoId, cartItems);
|
189 |
UserCart userCart = cartService.setCartItems(fofoId, cartItems);
|
| 175 |
// createtransactionInternally set the value in transaction table
|
190 |
// createtransactionInternally set the value in transaction table
|
| 176 |
|
191 |
|
| Line 263... |
Line 278... |
| 263 |
|
278 |
|
| 264 |
}
|
279 |
}
|
| 265 |
return approvalModelList;
|
280 |
return approvalModelList;
|
| 266 |
}
|
281 |
}
|
| 267 |
|
282 |
|
| 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 |
|
- |
|
| 290 |
|
- |
|
| 291 |
}
|
283 |
}
|