| Line 1... |
Line 1... |
| 1 |
package com.spice.profitmandi.service.order;
|
1 |
package com.spice.profitmandi.service.order;
|
| 2 |
|
2 |
|
| 3 |
import java.io.IOException;
|
- |
|
| 4 |
import java.net.URISyntaxException;
|
- |
|
| 5 |
import java.time.DateTimeException;
|
3 |
import java.time.DateTimeException;
|
| 6 |
import java.time.LocalDate;
|
4 |
import java.time.LocalDate;
|
| 7 |
import java.time.LocalDateTime;
|
5 |
import java.time.LocalDateTime;
|
| 8 |
import java.util.ArrayList;
|
6 |
import java.util.ArrayList;
|
| 9 |
import java.util.Arrays;
|
7 |
import java.util.Arrays;
|
| 10 |
import java.util.HashMap;
|
8 |
import java.util.HashMap;
|
| 11 |
import java.util.HashSet;
|
9 |
import java.util.HashSet;
|
| 12 |
import java.util.Iterator;
|
10 |
import java.util.Iterator;
|
| 13 |
import java.util.List;
|
11 |
import java.util.List;
|
| 14 |
import java.util.Map;
|
12 |
import java.util.Map;
|
| 15 |
import java.util.Random;
|
- |
|
| 16 |
import java.util.Set;
|
13 |
import java.util.Set;
|
| 17 |
import java.util.function.Function;
|
14 |
import java.util.function.Function;
|
| 18 |
import java.util.stream.Collectors;
|
15 |
import java.util.stream.Collectors;
|
| 19 |
|
16 |
|
| 20 |
import org.apache.logging.log4j.LogManager;
|
17 |
import org.apache.logging.log4j.LogManager;
|
| Line 22... |
Line 19... |
| 22 |
import org.json.JSONObject;
|
19 |
import org.json.JSONObject;
|
| 23 |
import org.springframework.beans.factory.annotation.Autowired;
|
20 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 24 |
import org.springframework.beans.factory.annotation.Qualifier;
|
21 |
import org.springframework.beans.factory.annotation.Qualifier;
|
| 25 |
import org.springframework.stereotype.Component;
|
22 |
import org.springframework.stereotype.Component;
|
| 26 |
|
23 |
|
| 27 |
import com.spice.profitmandi.common.ResponseCodeHolder;
|
- |
|
| 28 |
import com.spice.profitmandi.common.enumuration.SearchType;
|
24 |
import com.spice.profitmandi.common.enumuration.SearchType;
|
| 29 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
25 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 30 |
import com.spice.profitmandi.common.model.BadReturnRequest;
|
26 |
import com.spice.profitmandi.common.model.BadReturnRequest;
|
| 31 |
import com.spice.profitmandi.common.model.CartFofo;
|
27 |
import com.spice.profitmandi.common.model.CartFofo;
|
| 32 |
import com.spice.profitmandi.common.model.CreateOrderRequest;
|
28 |
import com.spice.profitmandi.common.model.CreateOrderRequest;
|
| Line 53... |
Line 49... |
| 53 |
import com.spice.profitmandi.common.util.Utils;
|
49 |
import com.spice.profitmandi.common.util.Utils;
|
| 54 |
import com.spice.profitmandi.dao.entity.catalog.Item;
|
50 |
import com.spice.profitmandi.dao.entity.catalog.Item;
|
| 55 |
import com.spice.profitmandi.dao.entity.dtr.GadgetCopsInsuranceCalc;
|
51 |
import com.spice.profitmandi.dao.entity.dtr.GadgetCopsInsuranceCalc;
|
| 56 |
import com.spice.profitmandi.dao.entity.dtr.InsurancePolicy;
|
52 |
import com.spice.profitmandi.dao.entity.dtr.InsurancePolicy;
|
| 57 |
import com.spice.profitmandi.dao.entity.dtr.InsuranceProvider;
|
53 |
import com.spice.profitmandi.dao.entity.dtr.InsuranceProvider;
|
| 58 |
import com.spice.profitmandi.dao.entity.dtr.Otp;
|
- |
|
| 59 |
import com.spice.profitmandi.dao.entity.dtr.PaymentOptionTransaction;
|
54 |
import com.spice.profitmandi.dao.entity.dtr.PaymentOptionTransaction;
|
| 60 |
import com.spice.profitmandi.dao.entity.dtr.PolicyNumberGenerationSequence;
|
55 |
import com.spice.profitmandi.dao.entity.dtr.PolicyNumberGenerationSequence;
|
| 61 |
import com.spice.profitmandi.dao.entity.dtr.Retailer;
|
56 |
import com.spice.profitmandi.dao.entity.dtr.Retailer;
|
| 62 |
import com.spice.profitmandi.dao.entity.dtr.User;
|
57 |
import com.spice.profitmandi.dao.entity.dtr.User;
|
| 63 |
import com.spice.profitmandi.dao.entity.fofo.CurrentInventorySnapshot;
|
58 |
import com.spice.profitmandi.dao.entity.fofo.CurrentInventorySnapshot;
|
| Line 69... |
Line 64... |
| 69 |
import com.spice.profitmandi.dao.entity.fofo.FofoOrder;
|
64 |
import com.spice.profitmandi.dao.entity.fofo.FofoOrder;
|
| 70 |
import com.spice.profitmandi.dao.entity.fofo.FofoOrderItem;
|
65 |
import com.spice.profitmandi.dao.entity.fofo.FofoOrderItem;
|
| 71 |
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
|
66 |
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
|
| 72 |
import com.spice.profitmandi.dao.entity.fofo.InventoryItem;
|
67 |
import com.spice.profitmandi.dao.entity.fofo.InventoryItem;
|
| 73 |
import com.spice.profitmandi.dao.entity.fofo.InvoiceNumberGenerationSequence;
|
68 |
import com.spice.profitmandi.dao.entity.fofo.InvoiceNumberGenerationSequence;
|
| 74 |
import com.spice.profitmandi.dao.entity.fofo.PrebookingListing;
|
- |
|
| 75 |
import com.spice.profitmandi.dao.entity.fofo.PrebookingOrder;
|
- |
|
| 76 |
import com.spice.profitmandi.dao.entity.fofo.PrebookingOrderItem;
|
- |
|
| 77 |
import com.spice.profitmandi.dao.entity.fofo.ScanRecord;
|
69 |
import com.spice.profitmandi.dao.entity.fofo.ScanRecord;
|
| 78 |
import com.spice.profitmandi.dao.entity.user.Address;
|
70 |
import com.spice.profitmandi.dao.entity.user.Address;
|
| 79 |
import com.spice.profitmandi.dao.entity.user.Counter;
|
71 |
import com.spice.profitmandi.dao.entity.user.Counter;
|
| 80 |
import com.spice.profitmandi.dao.entity.user.PrivateDealUser;
|
72 |
import com.spice.profitmandi.dao.entity.user.PrivateDealUser;
|
| 81 |
import com.spice.profitmandi.dao.enumuration.dtr.OtpType;
|
- |
|
| 82 |
import com.spice.profitmandi.dao.enumuration.dtr.PaymentOptionReferenceType;
|
73 |
import com.spice.profitmandi.dao.enumuration.dtr.PaymentOptionReferenceType;
|
| 83 |
import com.spice.profitmandi.dao.enumuration.fofo.ReturnType;
|
74 |
import com.spice.profitmandi.dao.enumuration.fofo.ReturnType;
|
| 84 |
import com.spice.profitmandi.dao.enumuration.fofo.ScanType;
|
75 |
import com.spice.profitmandi.dao.enumuration.fofo.ScanType;
|
| 85 |
import com.spice.profitmandi.dao.enumuration.fofo.SettlementType;
|
76 |
import com.spice.profitmandi.dao.enumuration.fofo.SettlementType;
|
| 86 |
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
|
77 |
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
|
| 87 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
78 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
| 88 |
import com.spice.profitmandi.dao.repository.dtr.InsurancePolicyRepository;
|
79 |
import com.spice.profitmandi.dao.repository.dtr.InsurancePolicyRepository;
|
| 89 |
import com.spice.profitmandi.dao.repository.dtr.InsuranceProviderRepository;
|
80 |
import com.spice.profitmandi.dao.repository.dtr.InsuranceProviderRepository;
|
| 90 |
import com.spice.profitmandi.dao.repository.dtr.OtpRepository;
|
- |
|
| 91 |
import com.spice.profitmandi.dao.repository.dtr.PaymentOptionTransactionRepository;
|
81 |
import com.spice.profitmandi.dao.repository.dtr.PaymentOptionTransactionRepository;
|
| 92 |
import com.spice.profitmandi.dao.repository.dtr.PolicyNumberGenerationSequenceRepository;
|
82 |
import com.spice.profitmandi.dao.repository.dtr.PolicyNumberGenerationSequenceRepository;
|
| 93 |
import com.spice.profitmandi.dao.repository.dtr.RetailerRegisteredAddressRepository;
|
83 |
import com.spice.profitmandi.dao.repository.dtr.RetailerRegisteredAddressRepository;
|
| 94 |
import com.spice.profitmandi.dao.repository.dtr.RetailerRepository;
|
84 |
import com.spice.profitmandi.dao.repository.dtr.RetailerRepository;
|
| 95 |
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
|
85 |
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
|
| 96 |
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
|
86 |
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
|
| 97 |
import com.spice.profitmandi.dao.repository.fofo.BadInventorySnapshotRepository;
|
- |
|
| 98 |
import com.spice.profitmandi.dao.repository.fofo.CurrentInventorySnapshotRepository;
|
87 |
import com.spice.profitmandi.dao.repository.fofo.CurrentInventorySnapshotRepository;
|
| 99 |
import com.spice.profitmandi.dao.repository.fofo.CustomerAddressRepository;
|
88 |
import com.spice.profitmandi.dao.repository.fofo.CustomerAddressRepository;
|
| 100 |
import com.spice.profitmandi.dao.repository.fofo.CustomerCreditNoteRepository;
|
89 |
import com.spice.profitmandi.dao.repository.fofo.CustomerCreditNoteRepository;
|
| 101 |
import com.spice.profitmandi.dao.repository.fofo.CustomerRepository;
|
90 |
import com.spice.profitmandi.dao.repository.fofo.CustomerRepository;
|
| 102 |
import com.spice.profitmandi.dao.repository.fofo.CustomerReturnItemRepository;
|
91 |
import com.spice.profitmandi.dao.repository.fofo.CustomerReturnItemRepository;
|
| Line 104... |
Line 93... |
| 104 |
import com.spice.profitmandi.dao.repository.fofo.FofoOrderItemRepository;
|
93 |
import com.spice.profitmandi.dao.repository.fofo.FofoOrderItemRepository;
|
| 105 |
import com.spice.profitmandi.dao.repository.fofo.FofoOrderRepository;
|
94 |
import com.spice.profitmandi.dao.repository.fofo.FofoOrderRepository;
|
| 106 |
import com.spice.profitmandi.dao.repository.fofo.InventoryItemRepository;
|
95 |
import com.spice.profitmandi.dao.repository.fofo.InventoryItemRepository;
|
| 107 |
import com.spice.profitmandi.dao.repository.fofo.InvoiceNumberGenerationSequenceRepository;
|
96 |
import com.spice.profitmandi.dao.repository.fofo.InvoiceNumberGenerationSequenceRepository;
|
| 108 |
import com.spice.profitmandi.dao.repository.fofo.PaymentOptionRepository;
|
97 |
import com.spice.profitmandi.dao.repository.fofo.PaymentOptionRepository;
|
| 109 |
import com.spice.profitmandi.dao.repository.fofo.PrebookingListingRepository;
|
- |
|
| 110 |
import com.spice.profitmandi.dao.repository.fofo.PrebookingOrderItemRepository;
|
- |
|
| 111 |
import com.spice.profitmandi.dao.repository.fofo.PrebookingOrderRepository;
|
- |
|
| 112 |
import com.spice.profitmandi.dao.repository.fofo.PurchaseReturnItemRepository;
|
98 |
import com.spice.profitmandi.dao.repository.fofo.PurchaseReturnItemRepository;
|
| 113 |
import com.spice.profitmandi.dao.repository.fofo.ScanRecordRepository;
|
99 |
import com.spice.profitmandi.dao.repository.fofo.ScanRecordRepository;
|
| 114 |
import com.spice.profitmandi.dao.repository.user.AddressRepository;
|
100 |
import com.spice.profitmandi.dao.repository.user.AddressRepository;
|
| 115 |
import com.spice.profitmandi.dao.repository.user.CounterRepository;
|
101 |
import com.spice.profitmandi.dao.repository.user.CounterRepository;
|
| 116 |
import com.spice.profitmandi.dao.repository.user.PrivateDealUserRepository;
|
102 |
import com.spice.profitmandi.dao.repository.user.PrivateDealUserRepository;
|
| Line 182... |
Line 168... |
| 182 |
|
168 |
|
| 183 |
@Autowired
|
169 |
@Autowired
|
| 184 |
private UserRepository userRepository;
|
170 |
private UserRepository userRepository;
|
| 185 |
|
171 |
|
| 186 |
@Autowired
|
172 |
@Autowired
|
| 187 |
private BadInventorySnapshotRepository badInventorySnapshotRepository;
|
- |
|
| 188 |
|
- |
|
| 189 |
@Autowired
|
- |
|
| 190 |
private UserAccountRepository userAccountRepository;
|
173 |
private UserAccountRepository userAccountRepository;
|
| 191 |
|
174 |
|
| 192 |
@Autowired
|
175 |
@Autowired
|
| 193 |
private RetailerRegisteredAddressRepository retailerRegisteredAddressRepository;
|
176 |
private RetailerRegisteredAddressRepository retailerRegisteredAddressRepository;
|
| 194 |
|
177 |
|
| Line 222... |
Line 205... |
| 222 |
|
205 |
|
| 223 |
@Autowired
|
206 |
@Autowired
|
| 224 |
private PaymentOptionTransactionRepository paymentOptionTransactionRepository;
|
207 |
private PaymentOptionTransactionRepository paymentOptionTransactionRepository;
|
| 225 |
|
208 |
|
| 226 |
@Autowired
|
209 |
@Autowired
|
| 227 |
private PrebookingListingRepository prebookingListingRepository;
|
- |
|
| 228 |
|
- |
|
| 229 |
@Autowired
|
- |
|
| 230 |
private PrebookingOrderRepository prebookingOrderRepository;
|
- |
|
| 231 |
|
- |
|
| 232 |
@Autowired
|
- |
|
| 233 |
private PrebookingOrderItemRepository prebookingOrderItemRepository;
|
- |
|
| 234 |
|
- |
|
| 235 |
@Autowired
|
- |
|
| 236 |
private SchemeService schemeService;
|
210 |
private SchemeService schemeService;
|
| 237 |
|
211 |
|
| 238 |
@Autowired
|
212 |
@Autowired
|
| 239 |
@Qualifier("fofoInventoryService")
|
213 |
@Qualifier("fofoInventoryService")
|
| 240 |
private InventoryService inventoryService;
|
214 |
private InventoryService inventoryService;
|
| 241 |
|
215 |
|
| 242 |
@Autowired
|
216 |
@Autowired
|
| 243 |
private CustomerCreditNoteRepository customerCreditNoteRepository;
|
217 |
private CustomerCreditNoteRepository customerCreditNoteRepository;
|
| 244 |
|
218 |
|
| 245 |
@Autowired
|
- |
|
| 246 |
private OtpRepository otpRepository;
|
- |
|
| 247 |
|
- |
|
| 248 |
@Override
|
219 |
@Override
|
| 249 |
public int createOrder(CreateOrderRequest createOrderRequest, int fofoId, boolean accessoriesDeals) throws ProfitMandiBusinessException {
|
220 |
public int createOrder(CreateOrderRequest createOrderRequest, int fofoId, boolean accessoriesDeals) throws ProfitMandiBusinessException {
|
| 250 |
|
221 |
|
| 251 |
CustomCustomer customCustomer = createOrderRequest.getCustomer();
|
222 |
CustomCustomer customCustomer = createOrderRequest.getCustomer();
|
| 252 |
|
223 |
|
| Line 270... |
Line 241... |
| 270 |
|
241 |
|
| 271 |
Map<Integer, Integer> itemIdQuantity = new HashMap<>(); // this is for error
|
242 |
Map<Integer, Integer> itemIdQuantity = new HashMap<>(); // this is for error
|
| 272 |
Map<Integer, CustomFofoOrderItem> itemIdCustomFofoOrderItemMap = new HashMap<>();
|
243 |
Map<Integer, CustomFofoOrderItem> itemIdCustomFofoOrderItemMap = new HashMap<>();
|
| 273 |
Map<Integer, Float> lineItemPrice = new HashMap<>(); // this is for pricing error
|
244 |
Map<Integer, Float> lineItemPrice = new HashMap<>(); // this is for pricing error
|
| 274 |
|
245 |
|
| 275 |
Map<Integer, Integer> prebookingOrderItemIdQuantityMap = new HashMap<>(); // for prebooking order adjustment
|
- |
|
| 276 |
|
246 |
|
| 277 |
float totalAmount = 0;
|
247 |
float totalAmount = 0;
|
| 278 |
for (CustomFofoOrderItem customFofoOrderItem : createOrderRequest.getFofoOrderItems()) {
|
248 |
for (CustomFofoOrderItem customFofoOrderItem : createOrderRequest.getFofoOrderItems()) {
|
| 279 |
// itemIds.add(customFofoOrderItem.getItemId());
|
249 |
// itemIds.add(customFofoOrderItem.getItemId());
|
| 280 |
if (customFofoOrderItem.isPrebookingOrder()) {
|
- |
|
| 281 |
prebookingOrderItemIdQuantityMap.put(customFofoOrderItem.getItemId(),
|
- |
|
| 282 |
customFofoOrderItem.getQuantity());
|
- |
|
| 283 |
}
|
- |
|
| 284 |
Set<String> serialNumbers = this
|
250 |
Set<String> serialNumbers = this
|
| 285 |
.serialNumberDetailsToSerialNumbers(customFofoOrderItem.getSerialNumberDetails());
|
251 |
.serialNumberDetailsToSerialNumbers(customFofoOrderItem.getSerialNumberDetails());
|
| 286 |
if (!serialNumbers.isEmpty() && customFofoOrderItem.getQuantity() != serialNumbers.size()) {
|
252 |
if (!serialNumbers.isEmpty() && customFofoOrderItem.getQuantity() != serialNumbers.size()) {
|
| 287 |
itemIdQuantity.put(customFofoOrderItem.getItemId(), customFofoOrderItem.getQuantity());
|
253 |
itemIdQuantity.put(customFofoOrderItem.getItemId(), customFofoOrderItem.getQuantity());
|
| 288 |
}
|
254 |
}
|
| Line 305... |
Line 271... |
| 305 |
LOGGER.error("itemId's quantity should be equal to given serialnumber size {} ", itemIdQuantity);
|
271 |
LOGGER.error("itemId's quantity should be equal to given serialnumber size {} ", itemIdQuantity);
|
| 306 |
throw new ProfitMandiBusinessException("itemIdQuantity", itemIdQuantity, "FFORDR_1001");
|
272 |
throw new ProfitMandiBusinessException("itemIdQuantity", itemIdQuantity, "FFORDR_1001");
|
| 307 |
// return "error";
|
273 |
// return "error";
|
| 308 |
}
|
274 |
}
|
| 309 |
|
275 |
|
| 310 |
List<PrebookingListing> prebookingListings = new ArrayList<>();
|
- |
|
| 311 |
Map<Integer, PrebookingListing> itemIdPrebookingListingMap = new HashMap<>();
|
- |
|
| 312 |
List<PrebookingOrder> prebookingOrders = new ArrayList<>();
|
- |
|
| 313 |
float prebookingOrdersTotalAmount = 0;
|
- |
|
| 314 |
if (!prebookingOrderItemIdQuantityMap.isEmpty()) {
|
- |
|
| 315 |
prebookingListings = prebookingListingRepository
|
- |
|
| 316 |
.selectAllByItemIds(prebookingOrderItemIdQuantityMap.keySet());
|
- |
|
| 317 |
itemIdPrebookingListingMap = this.prebookingListingsToItemIdPrebookingListingMap(prebookingListings);
|
- |
|
| 318 |
prebookingOrders = prebookingOrderRepository.selectByFofoIdCustomerMobileNumberItemIds(fofoId,
|
- |
|
| 319 |
customCustomer.getMobileNumber(), prebookingOrderItemIdQuantityMap.keySet());
|
- |
|
| 320 |
prebookingOrdersTotalAmount = this.calculatePrebookingOrdersAmount(prebookingOrders,
|
- |
|
| 321 |
prebookingOrderItemIdQuantityMap, itemIdPrebookingListingMap);
|
- |
|
| 322 |
}
|
- |
|
| 323 |
|
276 |
|
| 324 |
this.validatePaymentOptionsAndTotalAmount(createOrderRequest.getPaymentOptions(),
|
277 |
this.validatePaymentOptionsAndTotalAmount(createOrderRequest.getPaymentOptions(),
|
| 325 |
totalAmount - prebookingOrdersTotalAmount);
|
278 |
totalAmount);
|
| 326 |
|
279 |
|
| 327 |
if (!lineItemPrice.isEmpty()) {
|
280 |
if (!lineItemPrice.isEmpty()) {
|
| 328 |
// given fofo line item price must be greater than zero
|
281 |
// given fofo line item price must be greater than zero
|
| 329 |
LOGGER.error("requested itemId's selling price must greater than 0");
|
282 |
LOGGER.error("requested itemId's selling price must greater than 0");
|
| 330 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.PRICE, lineItemPrice, "FFORDR_1002");
|
283 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.PRICE, lineItemPrice, "FFORDR_1002");
|
| Line 491... |
Line 444... |
| 491 |
FofoOrder fofoOrder = this.createAndGetFofoOrder(customer.getId(), customCustomer.getGstNumber(), fofoId,
|
444 |
FofoOrder fofoOrder = this.createAndGetFofoOrder(customer.getId(), customCustomer.getGstNumber(), fofoId,
|
| 492 |
invoiceNumberGenerationSequence, totalAmount, customerAddress.getId());
|
445 |
invoiceNumberGenerationSequence, totalAmount, customerAddress.getId());
|
| 493 |
|
446 |
|
| 494 |
this.createPaymentOptions(fofoOrder, createOrderRequest.getPaymentOptions());
|
447 |
this.createPaymentOptions(fofoOrder, createOrderRequest.getPaymentOptions());
|
| 495 |
|
448 |
|
| 496 |
this.processPrebookingOrders(fofoId, fofoOrder.getId(), prebookingOrders, prebookingOrderItemIdQuantityMap,
|
- |
|
| 497 |
itemIdPrebookingListingMap);
|
- |
|
| 498 |
|
- |
|
| 499 |
int retailerAddressId = retailerRegisteredAddressRepository.selectAddressIdByRetailerId(fofoId);
|
449 |
int retailerAddressId = retailerRegisteredAddressRepository.selectAddressIdByRetailerId(fofoId);
|
| 500 |
|
450 |
|
| 501 |
Address retailerAddress = addressRepository.selectById(retailerAddressId);
|
451 |
Address retailerAddress = addressRepository.selectById(retailerAddressId);
|
| 502 |
|
452 |
|
| 503 |
Integer stateId = null;
|
453 |
Integer stateId = null;
|
| Line 572... |
Line 522... |
| 572 |
schemeService.processSchemeOut(fofoOrder.getId(), fofoId);
|
522 |
schemeService.processSchemeOut(fofoOrder.getId(), fofoId);
|
| 573 |
|
523 |
|
| 574 |
return fofoOrder.getId();
|
524 |
return fofoOrder.getId();
|
| 575 |
}
|
525 |
}
|
| 576 |
|
526 |
|
| 577 |
private float calculatePrebookingOrdersAmount(List<PrebookingOrder> prebookingOrders,
|
- |
|
| 578 |
Map<Integer, Integer> prebookingOrderItemIdQuantityMap,
|
- |
|
| 579 |
Map<Integer, PrebookingListing> itemIdPrebookingListingMap) {
|
- |
|
| 580 |
// List<PrebookingOrder> prebookingOrders =
|
- |
|
| 581 |
// prebookingOrderRepository.selectByFofoIdCustomerMobileNumberItemIds(fofoId,
|
- |
|
| 582 |
// customerMobileNumber, prebookingOrderItemIdQuantityMap.keySet());
|
- |
|
| 583 |
float totalAmount = 0;
|
- |
|
| 584 |
for (PrebookingOrder prebookingOrder : prebookingOrders) {
|
- |
|
| 585 |
int requestedQuantity = prebookingOrderItemIdQuantityMap.get(prebookingOrder.getItemId());
|
- |
|
| 586 |
PrebookingListing prebookingListing = itemIdPrebookingListingMap.get(prebookingOrder.getItemId());
|
- |
|
| 587 |
if (requestedQuantity < prebookingOrder.getAvailableQuantity()) {
|
- |
|
| 588 |
LOGGER.info("when requestedQuantity < then requestedQuantity [{}] * advanceAmount [{}]",
|
- |
|
| 589 |
requestedQuantity, prebookingListing.getAdvanceAmount());
|
- |
|
| 590 |
totalAmount = totalAmount + (requestedQuantity * prebookingListing.getAdvanceAmount());
|
- |
|
| 591 |
} else if (requestedQuantity >= prebookingOrder.getAvailableQuantity()) {
|
- |
|
| 592 |
LOGGER.info("else requestedQuantity [{}] * advanceAmount [{}]", requestedQuantity,
|
- |
|
| 593 |
prebookingListing.getAdvanceAmount());
|
- |
|
| 594 |
totalAmount = totalAmount
|
- |
|
| 595 |
+ (prebookingOrder.getAvailableQuantity() * prebookingListing.getAdvanceAmount());
|
- |
|
| 596 |
}
|
- |
|
| 597 |
}
|
- |
|
| 598 |
return totalAmount;
|
- |
|
| 599 |
}
|
- |
|
| 600 |
|
- |
|
| 601 |
private void processPrebookingOrders(int fofoId, int orderId, List<PrebookingOrder> prebookingOrders,
|
- |
|
| 602 |
Map<Integer, Integer> prebookingOrderItemIdQuantityMap,
|
- |
|
| 603 |
Map<Integer, PrebookingListing> itemIdPrebookingListingMap) throws ProfitMandiBusinessException {
|
- |
|
| 604 |
// Map<Integer, PrebookingOrder> prebookingOrderIdPrebookingOrderMap =
|
- |
|
| 605 |
// this.prebookingOrdersToPrebookingOrderIdPrebookingOrderMap(prebookingOrders);
|
- |
|
| 606 |
|
- |
|
| 607 |
for (PrebookingOrder prebookingOrder : prebookingOrders) {
|
- |
|
| 608 |
if (prebookingOrder.getCompleteTimestamp() == null) {
|
- |
|
| 609 |
int requestedQuantity = prebookingOrderItemIdQuantityMap.get(prebookingOrder.getItemId());
|
- |
|
| 610 |
|
- |
|
| 611 |
PrebookingOrderItem prebookingOrderItem = new PrebookingOrderItem();
|
- |
|
| 612 |
if (requestedQuantity < prebookingOrder.getAvailableQuantity()) {
|
- |
|
| 613 |
prebookingOrder.setAvailableQuantity(prebookingOrder.getAvailableQuantity() - requestedQuantity);
|
- |
|
| 614 |
prebookingOrderItem.setQuantity(requestedQuantity);
|
- |
|
| 615 |
} else if (requestedQuantity >= prebookingOrder.getAvailableQuantity()) {
|
- |
|
| 616 |
prebookingOrderItem.setQuantity(prebookingOrder.getAvailableQuantity());
|
- |
|
| 617 |
prebookingOrder.setAvailableQuantity(0);
|
- |
|
| 618 |
}
|
- |
|
| 619 |
if (prebookingOrder.getAvailableQuantity() == 0) {
|
- |
|
| 620 |
prebookingOrder.setCompleteTimestamp(LocalDateTime.now());
|
- |
|
| 621 |
}
|
- |
|
| 622 |
prebookingOrderRepository.persist(prebookingOrder);
|
- |
|
| 623 |
|
- |
|
| 624 |
prebookingOrderItem.setOrderId(orderId);
|
- |
|
| 625 |
prebookingOrderItem.setItemId(prebookingOrder.getItemId());
|
- |
|
| 626 |
PrebookingListing prebookingListing = itemIdPrebookingListingMap.get(prebookingOrder.getItemId());
|
- |
|
| 627 |
prebookingOrderItem.setAdvanceAmount(prebookingListing.getAdvanceAmount());
|
- |
|
| 628 |
|
- |
|
| 629 |
prebookingOrderItemRepository.persist(prebookingOrderItem);
|
- |
|
| 630 |
|
- |
|
| 631 |
walletService.addAmountToWallet(fofoId, prebookingOrder.getId(), WalletReferenceType.PREBOOKING_ORDER,
|
- |
|
| 632 |
"Advance Amount credited for Prebooking Order", prebookingListing.getAdvanceAmount());
|
- |
|
| 633 |
}
|
- |
|
| 634 |
|
- |
|
| 635 |
}
|
- |
|
| 636 |
}
|
- |
|
| 637 |
|
- |
|
| 638 |
private Map<Integer, PrebookingListing> prebookingListingsToItemIdPrebookingListingMap(
|
- |
|
| 639 |
List<PrebookingListing> prebookingListings) {
|
- |
|
| 640 |
Map<Integer, PrebookingListing> itemIdPrebookingListingMap = new HashMap<>();
|
- |
|
| 641 |
for (PrebookingListing prebookingListing : prebookingListings) {
|
- |
|
| 642 |
itemIdPrebookingListingMap.put(prebookingListing.getItemId(), prebookingListing);
|
- |
|
| 643 |
}
|
- |
|
| 644 |
return itemIdPrebookingListingMap;
|
- |
|
| 645 |
}
|
- |
|
| 646 |
|
- |
|
| 647 |
private Set<String> serialNumberDetailsToSerialNumbers(Set<SerialNumberDetail> serialNumberDetails) {
|
527 |
private Set<String> serialNumberDetailsToSerialNumbers(Set<SerialNumberDetail> serialNumberDetails) {
|
| 648 |
Set<String> serialNumbers = new HashSet<>();
|
528 |
Set<String> serialNumbers = new HashSet<>();
|
| 649 |
for (SerialNumberDetail serialNumberDetail : serialNumberDetails) {
|
529 |
for (SerialNumberDetail serialNumberDetail : serialNumberDetails) {
|
| 650 |
if (serialNumberDetail.getSerialNumber() != null && !serialNumberDetail.getSerialNumber().isEmpty()) {
|
530 |
if (serialNumberDetail.getSerialNumber() != null && !serialNumberDetail.getSerialNumber().isEmpty()) {
|
| 651 |
serialNumbers.add(serialNumberDetail.getSerialNumber());
|
531 |
serialNumbers.add(serialNumberDetail.getSerialNumber());
|
| Line 1539... |
Line 1419... |
| 1539 |
}
|
1419 |
}
|
| 1540 |
}
|
1420 |
}
|
| 1541 |
return fofoOrderItemIdFofoLineItemsMap;
|
1421 |
return fofoOrderItemIdFofoLineItemsMap;
|
| 1542 |
}
|
1422 |
}
|
| 1543 |
|
1423 |
|
| 1544 |
private String getOtpString() {
|
- |
|
| 1545 |
Random rndm_method = new Random();
|
- |
|
| 1546 |
String numbers = "0123456789";
|
- |
|
| 1547 |
char[] otp = new char[5];
|
- |
|
| 1548 |
|
- |
|
| 1549 |
for (int i = 0; i < 5; i++) {
|
- |
|
| 1550 |
otp[i] = numbers.charAt(rndm_method.nextInt(numbers.length()));
|
- |
|
| 1551 |
}
|
- |
|
| 1552 |
return String.valueOf(otp);
|
- |
|
| 1553 |
}
|
- |
|
| 1554 |
|
- |
|
| 1555 |
private void sendOtp(String otp_text, String phone, Map<Integer, Float> itemIdAdvanceAmount) {
|
- |
|
| 1556 |
Map<Integer, String> itemIdDescriptionMap = inventoryService
|
- |
|
| 1557 |
.getItemIdDescriptionMap(itemIdAdvanceAmount.keySet());
|
- |
|
| 1558 |
StringBuilder itemIdAdvanceAmountString = new StringBuilder();
|
- |
|
| 1559 |
int index = 0;
|
- |
|
| 1560 |
for (Map.Entry<Integer, Float> itemIdAdvanceAmountEntry : itemIdAdvanceAmount.entrySet()) {
|
- |
|
| 1561 |
itemIdAdvanceAmountString.append(itemIdDescriptionMap.get(itemIdAdvanceAmountEntry.getKey()));
|
- |
|
| 1562 |
itemIdAdvanceAmountString.append("'s Advance amount [");
|
- |
|
| 1563 |
itemIdAdvanceAmountString.append(itemIdAdvanceAmountEntry.getValue());
|
- |
|
| 1564 |
itemIdAdvanceAmountString.append("]");
|
- |
|
| 1565 |
if (index + 1 < itemIdAdvanceAmount.size()) {
|
- |
|
| 1566 |
itemIdAdvanceAmountString.append(", ");
|
- |
|
| 1567 |
}
|
- |
|
| 1568 |
index++;
|
- |
|
| 1569 |
}
|
- |
|
| 1570 |
String text = "Dear Customer, {0} is the OTP that you have requested for prebooking orders for items {1} Don't share your OTP with anyone.";
|
- |
|
| 1571 |
LOGGER.info("OTP to Customer Successfully sends" + text);
|
- |
|
| 1572 |
String msg = java.text.MessageFormat.format(text, otp_text, itemIdAdvanceAmountString);
|
- |
|
| 1573 |
try {
|
- |
|
| 1574 |
Utils.sendSms(msg, phone);
|
- |
|
| 1575 |
} catch (URISyntaxException e) {
|
- |
|
| 1576 |
// TODO Auto-generated catch block
|
- |
|
| 1577 |
e.printStackTrace();
|
- |
|
| 1578 |
} catch (IOException e) {
|
- |
|
| 1579 |
// TODO Auto-generated catch block
|
- |
|
| 1580 |
e.printStackTrace();
|
- |
|
| 1581 |
}
|
- |
|
| 1582 |
|
- |
|
| 1583 |
}
|
- |
|
| 1584 |
|
- |
|
| 1585 |
@Override
|
- |
|
| 1586 |
public int generatePrebookingOrdersOtp(String customerEmailId, String customerMobileNumber,
|
- |
|
| 1587 |
Map<Integer, Float> itemIdAdvanceAmount) throws ProfitMandiBusinessException {
|
- |
|
| 1588 |
if (!StringUtils.isValidEmailAddress(customerEmailId)) {
|
- |
|
| 1589 |
LOGGER.error("invalid customer emailId {} ", customerEmailId);
|
- |
|
| 1590 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.EMAIL_ID, customerEmailId, "VE_1016");
|
- |
|
| 1591 |
}
|
- |
|
| 1592 |
|
- |
|
| 1593 |
if (!StringUtils.isValidMobile(customerMobileNumber)) {
|
- |
|
| 1594 |
LOGGER.error("invalid customer mobileNumber {} ", customerMobileNumber);
|
- |
|
| 1595 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.MOBILE_NUMBER, customerMobileNumber, "VE_1071");
|
- |
|
| 1596 |
}
|
- |
|
| 1597 |
|
- |
|
| 1598 |
List<Otp> otps = otpRepository.selectAllByEmailWithTime(customerEmailId);
|
- |
|
| 1599 |
String otp = null;
|
- |
|
| 1600 |
if (otps.size() >= 5) {
|
- |
|
| 1601 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.CUSTOMER_EMAIL_ID, customerEmailId,
|
- |
|
| 1602 |
"FFORDR_1019");
|
- |
|
| 1603 |
}
|
- |
|
| 1604 |
if (!otps.isEmpty()) {
|
- |
|
| 1605 |
if (otps.get(0).getCreatedOn().isAfter(LocalDateTime.now().minusMinutes(2))) {
|
- |
|
| 1606 |
return otps.get(0).getId();
|
- |
|
| 1607 |
} else if (otps.get(0).getCreatedOn().isAfter(LocalDateTime.now().minusMinutes(10))) {
|
- |
|
| 1608 |
otp = otps.get(0).getOtp();
|
- |
|
| 1609 |
}
|
- |
|
| 1610 |
}
|
- |
|
| 1611 |
if (otp == null || otp.isEmpty()) {
|
- |
|
| 1612 |
otp = getOtpString();
|
- |
|
| 1613 |
}
|
- |
|
| 1614 |
|
- |
|
| 1615 |
this.sendOtp(otp, customerMobileNumber, itemIdAdvanceAmount);
|
- |
|
| 1616 |
|
- |
|
| 1617 |
Otp otp_bean = new Otp();
|
- |
|
| 1618 |
otp_bean.setEmail(customerEmailId);
|
- |
|
| 1619 |
otp_bean.setMobile(customerMobileNumber);
|
- |
|
| 1620 |
otp_bean.setOtp(otp);
|
- |
|
| 1621 |
otp_bean.setOtpType(OtpType.PREBOOKING_ORDER);
|
- |
|
| 1622 |
otp_bean.setCreatedOn(LocalDateTime.now());
|
- |
|
| 1623 |
otp_bean.setExpiryTimestamp(LocalDateTime.now().plusMinutes(10));
|
- |
|
| 1624 |
otpRepository.persist(otp_bean);
|
- |
|
| 1625 |
|
- |
|
| 1626 |
return otp_bean.getId();
|
- |
|
| 1627 |
}
|
- |
|
| 1628 |
|
- |
|
| 1629 |
@Override
|
- |
|
| 1630 |
public String validateOtp(String customerEmailId, String customerMobileNumber, int otpId, String otpValue)
|
- |
|
| 1631 |
throws ProfitMandiBusinessException {
|
- |
|
| 1632 |
Otp otp = otpRepository.selectByIdEmailIdMobileNumber(otpId, customerEmailId, customerMobileNumber);
|
- |
|
| 1633 |
otp.setTryCount(otp.getTryCount() + 1);
|
- |
|
| 1634 |
if (!otp.getOtp().equalsIgnoreCase(otpValue)) {
|
- |
|
| 1635 |
throw new ProfitMandiBusinessException("otpValue", otpValue, "FFORDR_1020");
|
- |
|
| 1636 |
}
|
- |
|
| 1637 |
if (otp.isExpired() || otp.isVerified() || otp.getExpiryTimestamp().isBefore(LocalDateTime.now())) {
|
- |
|
| 1638 |
throw new ProfitMandiBusinessException("otpValue", otpValue, "FFORDR_1021");
|
- |
|
| 1639 |
}
|
- |
|
| 1640 |
if (otp.getTryCount() > 5) {
|
- |
|
| 1641 |
throw new ProfitMandiBusinessException("otpValue", otpValue, "FFORDR_1022");
|
- |
|
| 1642 |
}
|
- |
|
| 1643 |
otp.setExpired(true);
|
- |
|
| 1644 |
otp.setVerified(true);
|
- |
|
| 1645 |
otpRepository.persist(otp);
|
- |
|
| 1646 |
|
- |
|
| 1647 |
return ResponseCodeHolder.getMessage("FFORDR_OK_1002");
|
- |
|
| 1648 |
}
|
- |
|
| 1649 |
|
- |
|
| 1650 |
@Override
|
1424 |
@Override
|
| 1651 |
public void updateCustomerDetails(CustomCustomer customCustomer, String invoiceNumber)
|
1425 |
public void updateCustomerDetails(CustomCustomer customCustomer, String invoiceNumber)
|
| 1652 |
throws ProfitMandiBusinessException {
|
1426 |
throws ProfitMandiBusinessException {
|
| 1653 |
FofoOrder fofoOrder = fofoOrderRepository.selectByInvoiceNumber(invoiceNumber);
|
1427 |
FofoOrder fofoOrder = fofoOrderRepository.selectByInvoiceNumber(invoiceNumber);
|
| 1654 |
Customer customer = customerRepository.selectById(fofoOrder.getCustomerId());
|
1428 |
Customer customer = customerRepository.selectById(fofoOrder.getCustomerId());
|