| Line 1... |
Line 1... |
| 1 |
package com.spice.profitmandi.service.order;
|
1 |
package com.spice.profitmandi.service.order;
|
| 2 |
|
2 |
|
| 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.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.TransactionApprovalModel;
|
7 |
import com.spice.profitmandi.common.model.TransactionApprovalModel;
|
| 7 |
import com.spice.profitmandi.common.util.ExcelUtils;
|
8 |
import com.spice.profitmandi.common.util.ExcelUtils;
|
| 8 |
import com.spice.profitmandi.dao.cart.CartService;
|
9 |
import com.spice.profitmandi.dao.cart.CartService;
|
| 9 |
import com.spice.profitmandi.dao.entity.auth.AuthUser;
|
10 |
import com.spice.profitmandi.dao.entity.auth.AuthUser;
|
| 10 |
import com.spice.profitmandi.dao.entity.catalog.TagListing;
|
11 |
import com.spice.profitmandi.dao.entity.catalog.TagListing;
|
| Line 85... |
Line 86... |
| 85 |
myWorkBook.setMissingCellPolicy(Row.MissingCellPolicy.RETURN_BLANK_AS_NULL);
|
86 |
myWorkBook.setMissingCellPolicy(Row.MissingCellPolicy.RETURN_BLANK_AS_NULL);
|
| 86 |
// Return first sheet from the XLSX workbook
|
87 |
// Return first sheet from the XLSX workbook
|
| 87 |
XSSFSheet mySheet = myWorkBook.getSheetAt(0);
|
88 |
XSSFSheet mySheet = myWorkBook.getSheetAt(0);
|
| 88 |
LOGGER.info("rowCellNum {}", mySheet.getLastRowNum());
|
89 |
LOGGER.info("rowCellNum {}", mySheet.getLastRowNum());
|
| 89 |
List<BulkOrderModel> bulkOrderModels = new ArrayList<>();
|
90 |
List<BulkOrderModel> bulkOrderModels = new ArrayList<>();
|
| - |
|
91 |
LOGGER.info("mySheet.getLastRowNum() - {}", mySheet.getLastRowNum());
|
| 90 |
for (int rowNumber = 1; rowNumber <= mySheet.getLastRowNum(); rowNumber++) {
|
92 |
for (int rowNumber = 1; rowNumber <= mySheet.getLastRowNum(); rowNumber++) {
|
| 91 |
XSSFRow row = mySheet.getRow(rowNumber);
|
93 |
XSSFRow row = mySheet.getRow(rowNumber);
|
| - |
|
94 |
LOGGER.info("Row - {}", row);
|
| - |
|
95 |
if (row != null) {
|
| 92 |
BulkOrderModel bulkOrderModel = this.createBulkModel(row);
|
96 |
BulkOrderModel bulkOrderModel = this.createBulkModel(row);
|
| 93 |
bulkOrderModels.add(bulkOrderModel);
|
97 |
bulkOrderModels.add(bulkOrderModel);
|
| - |
|
98 |
} else {
|
| - |
|
99 |
break;
|
| - |
|
100 |
}
|
| 94 |
}
|
101 |
}
|
| 95 |
Map<Integer, List<BulkOrderModel>> fofoBulkOrdersMap = bulkOrderModels.stream().collect(Collectors.groupingBy(x -> x.getFofoId()));
|
102 |
Map<Integer, List<BulkOrderModel>> fofoBulkOrdersMap = bulkOrderModels.stream().collect(Collectors.groupingBy(x -> x.getFofoId()));
|
| 96 |
boolean approvalNotRequired = true;
|
103 |
boolean approvalNotRequired = true;
|
| 97 |
for (Map.Entry<Integer, List<BulkOrderModel>> fofoBulkOrderEntry : fofoBulkOrdersMap.entrySet()) {
|
104 |
for (Map.Entry<Integer, List<BulkOrderModel>> fofoBulkOrderEntry : fofoBulkOrdersMap.entrySet()) {
|
| 98 |
int fofoId = fofoBulkOrderEntry.getKey();
|
105 |
int fofoId = fofoBulkOrderEntry.getKey();
|
| Line 139... |
Line 146... |
| 139 |
|
146 |
|
| 140 |
BigDecimal creditAvailability = sdCreditService.getAvailableAmount(fofoId);
|
147 |
BigDecimal creditAvailability = sdCreditService.getAvailableAmount(fofoId);
|
| 141 |
|
148 |
|
| 142 |
double netAmountInHand = creditAvailability.doubleValue() + walletAmount;
|
149 |
double netAmountInHand = creditAvailability.doubleValue() + walletAmount;
|
| 143 |
LOGGER.info("netAmountInHand - " + netAmountInHand);
|
150 |
LOGGER.info("netAmountInHand - " + netAmountInHand);
|
| 144 |
if (totalPayableAmount > 20 && netAmountInHand < totalPayableAmount) {
|
151 |
if (totalPayableAmount > ProfitMandiConstants.MAX_NEGATIVE_WALLET_VALUE && netAmountInHand < totalPayableAmount) {
|
| 145 |
throw new ProfitMandiBusinessException("Skipping order due to insufficient balance for id - ", fofoId, " ,Check wallet Balance once");
|
152 |
throw new ProfitMandiBusinessException("Skipping order due to insufficient balance for id - ", fofoId, " ,Check wallet Balance once");
|
| 146 |
}
|
153 |
}
|
| 147 |
UserCart userCart = cartService.setCartItems(fofoId, cartItems);
|
154 |
UserCart userCart = cartService.setCartItems(fofoId, cartItems);
|
| 148 |
// createtransactionInternally set the value in transaction table
|
155 |
// createtransactionInternally set the value in transaction table
|
| 149 |
|
156 |
|
| 150 |
double creditAmountRequired = totalPayableAmount - walletAmount;
|
157 |
double creditAmountRequired = totalPayableAmount - walletAmount;
|
| 151 |
if (creditAmountRequired > 20) {
|
158 |
if (creditAmountRequired > ProfitMandiConstants.MAX_NEGATIVE_WALLET_VALUE) {
|
| 152 |
sdCreditService.createLoan(userCart.getUserId(), creditAmountRequired, 0);
|
159 |
sdCreditService.createLoan(userCart.getUserId(), creditAmountRequired, 0);
|
| 153 |
}
|
160 |
}
|
| 154 |
//return this.createLoan(userCart.getUserId(), creditAmountRequired);
|
161 |
//return this.createLoan(userCart.getUserId(), creditAmountRequired);
|
| 155 |
int transactionId = transactionService.createTransactionInternally(userCart, totalPayableAmount, 0);
|
162 |
int transactionId = transactionService.createTransactionInternally(userCart, totalPayableAmount, 0);
|
| 156 |
//Set here created by
|
163 |
//Set here created by
|