| Line 1... |
Line 1... |
| 1 |
package com.spice.profitmandi.service.order;
|
1 |
package com.spice.profitmandi.service.order;
|
| 2 |
|
2 |
|
| 3 |
import java.io.ByteArrayInputStream;
|
- |
|
| 4 |
import java.io.InputStream;
|
- |
|
| 5 |
import java.time.LocalDate;
|
- |
|
| 6 |
import java.time.LocalDateTime;
|
- |
|
| 7 |
import java.time.LocalTime;
|
- |
|
| 8 |
import java.util.AbstractMap.SimpleEntry;
|
- |
|
| 9 |
import java.util.ArrayList;
|
- |
|
| 10 |
import java.util.Arrays;
|
- |
|
| 11 |
import java.util.HashMap;
|
- |
|
| 12 |
import java.util.HashSet;
|
- |
|
| 13 |
import java.util.Iterator;
|
- |
|
| 14 |
import java.util.List;
|
- |
|
| 15 |
import java.util.Map;
|
- |
|
| 16 |
import java.util.Optional;
|
- |
|
| 17 |
import java.util.Random;
|
- |
|
| 18 |
import java.util.Set;
|
- |
|
| 19 |
import java.util.function.Function;
|
- |
|
| 20 |
import java.util.stream.Collectors;
|
- |
|
| 21 |
|
- |
|
| 22 |
import javax.persistence.criteria.CriteriaBuilder;
|
- |
|
| 23 |
import javax.persistence.criteria.CriteriaQuery;
|
- |
|
| 24 |
import javax.persistence.criteria.Predicate;
|
- |
|
| 25 |
import javax.persistence.criteria.Root;
|
- |
|
| 26 |
|
- |
|
| 27 |
import org.apache.logging.log4j.LogManager;
|
- |
|
| 28 |
import org.apache.logging.log4j.Logger;
|
- |
|
| 29 |
import org.hibernate.Session;
|
- |
|
| 30 |
import org.hibernate.SessionFactory;
|
- |
|
| 31 |
import org.json.JSONObject;
|
- |
|
| 32 |
import org.springframework.beans.factory.annotation.Autowired;
|
- |
|
| 33 |
import org.springframework.beans.factory.annotation.Qualifier;
|
- |
|
| 34 |
import org.springframework.beans.factory.annotation.Value;
|
- |
|
| 35 |
import org.springframework.cache.annotation.Cacheable;
|
- |
|
| 36 |
import org.springframework.core.io.InputStreamResource;
|
- |
|
| 37 |
import org.springframework.http.HttpHeaders;
|
- |
|
| 38 |
import org.springframework.http.HttpStatus;
|
- |
|
| 39 |
import org.springframework.http.ResponseEntity;
|
- |
|
| 40 |
import org.springframework.stereotype.Component;
|
- |
|
| 41 |
|
- |
|
| 42 |
import com.spice.profitmandi.common.enumuration.ItemType;
|
3 |
import com.spice.profitmandi.common.enumuration.ItemType;
|
| 43 |
import com.spice.profitmandi.common.enumuration.SearchType;
|
4 |
import com.spice.profitmandi.common.enumuration.SearchType;
|
| 44 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
5 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 45 |
import com.spice.profitmandi.common.model.BadReturnRequest;
|
- |
|
| 46 |
import com.spice.profitmandi.common.model.CartFofo;
|
- |
|
| 47 |
import com.spice.profitmandi.common.model.CreateOrderRequest;
|
- |
|
| 48 |
import com.spice.profitmandi.common.model.CreditNotePdfModel;
|
- |
|
| 49 |
import com.spice.profitmandi.common.model.CustomAddress;
|
- |
|
| 50 |
import com.spice.profitmandi.common.model.CustomCustomer;
|
- |
|
| 51 |
import com.spice.profitmandi.common.model.CustomFofoOrderItem;
|
- |
|
| 52 |
import com.spice.profitmandi.common.model.CustomInsurancePolicy;
|
- |
|
| 53 |
import com.spice.profitmandi.common.model.CustomOrderItem;
|
- |
|
| 54 |
import com.spice.profitmandi.common.model.CustomPaymentOption;
|
- |
|
| 55 |
import com.spice.profitmandi.common.model.CustomRetailer;
|
- |
|
| 56 |
import com.spice.profitmandi.common.model.FoiBadReturnRequest;
|
- |
|
| 57 |
import com.spice.profitmandi.common.model.GstRate;
|
6 |
import com.spice.profitmandi.common.model.*;
|
| 58 |
import com.spice.profitmandi.common.model.InsuranceModel;
|
- |
|
| 59 |
import com.spice.profitmandi.common.model.InvoicePdfModel;
|
- |
|
| 60 |
import com.spice.profitmandi.common.model.ItemIdQuantityAvailability;
|
- |
|
| 61 |
import com.spice.profitmandi.common.model.PriceModel;
|
- |
|
| 62 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
- |
|
| 63 |
import com.spice.profitmandi.common.model.Quantity;
|
- |
|
| 64 |
import com.spice.profitmandi.common.model.SerialNumberDetail;
|
- |
|
| 65 |
import com.spice.profitmandi.common.util.FormattingUtils;
|
7 |
import com.spice.profitmandi.common.util.FormattingUtils;
|
| 66 |
import com.spice.profitmandi.common.util.StringUtils;
|
8 |
import com.spice.profitmandi.common.util.StringUtils;
|
| 67 |
import com.spice.profitmandi.common.util.Utils;
|
9 |
import com.spice.profitmandi.common.util.Utils;
|
| 68 |
import com.spice.profitmandi.common.web.client.RestClient;
|
10 |
import com.spice.profitmandi.common.web.client.RestClient;
|
| 69 |
import com.spice.profitmandi.dao.entity.catalog.Item;
|
11 |
import com.spice.profitmandi.dao.entity.catalog.Item;
|
| 70 |
import com.spice.profitmandi.dao.entity.catalog.TagListing;
|
12 |
import com.spice.profitmandi.dao.entity.catalog.TagListing;
|
| 71 |
import com.spice.profitmandi.dao.entity.dtr.InsurancePolicy;
|
- |
|
| 72 |
import com.spice.profitmandi.dao.entity.dtr.PaymentOptionTransaction;
|
- |
|
| 73 |
import com.spice.profitmandi.dao.entity.dtr.Retailer;
|
- |
|
| 74 |
import com.spice.profitmandi.dao.entity.dtr.ScratchOffer;
|
- |
|
| 75 |
import com.spice.profitmandi.dao.entity.dtr.User;
|
13 |
import com.spice.profitmandi.dao.entity.dtr.*;
|
| 76 |
import com.spice.profitmandi.dao.entity.fofo.CurrentInventorySnapshot;
|
- |
|
| 77 |
import com.spice.profitmandi.dao.entity.fofo.Customer;
|
14 |
import com.spice.profitmandi.dao.entity.fofo.*;
|
| 78 |
import com.spice.profitmandi.dao.entity.fofo.CustomerAddress;
|
- |
|
| 79 |
import com.spice.profitmandi.dao.entity.fofo.CustomerCreditNote;
|
- |
|
| 80 |
import com.spice.profitmandi.dao.entity.fofo.CustomerReturnItem;
|
- |
|
| 81 |
import com.spice.profitmandi.dao.entity.fofo.FofoLineItem;
|
- |
|
| 82 |
import com.spice.profitmandi.dao.entity.fofo.FofoOrder;
|
- |
|
| 83 |
import com.spice.profitmandi.dao.entity.fofo.FofoOrderItem;
|
- |
|
| 84 |
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
|
- |
|
| 85 |
import com.spice.profitmandi.dao.entity.fofo.HygieneData;
|
- |
|
| 86 |
import com.spice.profitmandi.dao.entity.fofo.InventoryItem;
|
- |
|
| 87 |
import com.spice.profitmandi.dao.entity.fofo.InvoiceNumberGenerationSequence;
|
- |
|
| 88 |
import com.spice.profitmandi.dao.entity.fofo.LiveDemoSerialNumber;
|
- |
|
| 89 |
import com.spice.profitmandi.dao.entity.fofo.PendingOrder;
|
- |
|
| 90 |
import com.spice.profitmandi.dao.entity.fofo.PendingOrderItem;
|
- |
|
| 91 |
import com.spice.profitmandi.dao.entity.fofo.ScanRecord;
|
- |
|
| 92 |
import com.spice.profitmandi.dao.entity.inventory.State;
|
15 |
import com.spice.profitmandi.dao.entity.inventory.State;
|
| 93 |
import com.spice.profitmandi.dao.entity.transaction.Order;
|
16 |
import com.spice.profitmandi.dao.entity.transaction.Order;
|
| 94 |
import com.spice.profitmandi.dao.entity.user.Address;
|
17 |
import com.spice.profitmandi.dao.entity.user.Address;
|
| 95 |
import com.spice.profitmandi.dao.entity.user.Counter;
|
18 |
import com.spice.profitmandi.dao.entity.user.Counter;
|
| 96 |
import com.spice.profitmandi.dao.entity.user.PrivateDealUser;
|
19 |
import com.spice.profitmandi.dao.entity.user.PrivateDealUser;
|
| Line 103... |
Line 26... |
| 103 |
import com.spice.profitmandi.dao.enumuration.inventory.ScratchedGift;
|
26 |
import com.spice.profitmandi.dao.enumuration.inventory.ScratchedGift;
|
| 104 |
import com.spice.profitmandi.dao.enumuration.transaction.OrderStatus;
|
27 |
import com.spice.profitmandi.dao.enumuration.transaction.OrderStatus;
|
| 105 |
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
|
28 |
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
|
| 106 |
import com.spice.profitmandi.dao.repository.catalog.StateGstRateRepository;
|
29 |
import com.spice.profitmandi.dao.repository.catalog.StateGstRateRepository;
|
| 107 |
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
|
30 |
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
|
| 108 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
- |
|
| 109 |
import com.spice.profitmandi.dao.repository.dtr.InsurancePolicyRepository;
|
- |
|
| 110 |
import com.spice.profitmandi.dao.repository.dtr.InsuranceProviderRepository;
|
- |
|
| 111 |
import com.spice.profitmandi.dao.repository.dtr.Mongo;
|
31 |
import com.spice.profitmandi.dao.repository.dtr.*;
|
| 112 |
import com.spice.profitmandi.dao.repository.dtr.PaymentOptionTransactionRepository;
|
- |
|
| 113 |
import com.spice.profitmandi.dao.repository.dtr.PolicyNumberGenerationSequenceRepository;
|
- |
|
| 114 |
import com.spice.profitmandi.dao.repository.dtr.RetailerRegisteredAddressRepository;
|
- |
|
| 115 |
import com.spice.profitmandi.dao.repository.dtr.RetailerRepository;
|
- |
|
| 116 |
import com.spice.profitmandi.dao.repository.dtr.ScratchOfferRepository;
|
- |
|
| 117 |
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
|
- |
|
| 118 |
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
|
32 |
import com.spice.profitmandi.dao.repository.fofo.*;
|
| 119 |
import com.spice.profitmandi.dao.repository.fofo.CurrentInventorySnapshotRepository;
|
- |
|
| 120 |
import com.spice.profitmandi.dao.repository.fofo.CustomerAddressRepository;
|
- |
|
| 121 |
import com.spice.profitmandi.dao.repository.fofo.CustomerCreditNoteRepository;
|
- |
|
| 122 |
import com.spice.profitmandi.dao.repository.fofo.CustomerRepository;
|
- |
|
| 123 |
import com.spice.profitmandi.dao.repository.fofo.CustomerReturnItemRepository;
|
- |
|
| 124 |
import com.spice.profitmandi.dao.repository.fofo.FofoLineItemRepository;
|
- |
|
| 125 |
import com.spice.profitmandi.dao.repository.fofo.FofoOrderItemRepository;
|
- |
|
| 126 |
import com.spice.profitmandi.dao.repository.fofo.FofoOrderRepository;
|
- |
|
| 127 |
import com.spice.profitmandi.dao.repository.fofo.HygieneDataRepository;
|
- |
|
| 128 |
import com.spice.profitmandi.dao.repository.fofo.InventoryItemRepository;
|
- |
|
| 129 |
import com.spice.profitmandi.dao.repository.fofo.InvoiceNumberGenerationSequenceRepository;
|
- |
|
| 130 |
import com.spice.profitmandi.dao.repository.fofo.LiveDemoBillingRespository;
|
- |
|
| 131 |
import com.spice.profitmandi.dao.repository.fofo.PaymentOptionRepository;
|
- |
|
| 132 |
import com.spice.profitmandi.dao.repository.fofo.PendingOrderItemRepository;
|
- |
|
| 133 |
import com.spice.profitmandi.dao.repository.fofo.PendingOrderRepository;
|
- |
|
| 134 |
import com.spice.profitmandi.dao.repository.fofo.PurchaseReturnItemRepository;
|
- |
|
| 135 |
import com.spice.profitmandi.dao.repository.fofo.ScanRecordRepository;
|
- |
|
| 136 |
import com.spice.profitmandi.dao.repository.inventory.StateRepository;
|
33 |
import com.spice.profitmandi.dao.repository.inventory.StateRepository;
|
| 137 |
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
|
34 |
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
|
| 138 |
import com.spice.profitmandi.dao.repository.user.AddressRepository;
|
35 |
import com.spice.profitmandi.dao.repository.user.AddressRepository;
|
| 139 |
import com.spice.profitmandi.dao.repository.user.CounterRepository;
|
36 |
import com.spice.profitmandi.dao.repository.user.CounterRepository;
|
| 140 |
import com.spice.profitmandi.dao.repository.user.PrivateDealUserRepository;
|
37 |
import com.spice.profitmandi.dao.repository.user.PrivateDealUserRepository;
|
| Line 147... |
Line 44... |
| 147 |
import com.spice.profitmandi.service.offers.ItemCriteria;
|
44 |
import com.spice.profitmandi.service.offers.ItemCriteria;
|
| 148 |
import com.spice.profitmandi.service.pricing.PricingService;
|
45 |
import com.spice.profitmandi.service.pricing.PricingService;
|
| 149 |
import com.spice.profitmandi.service.scheme.SchemeService;
|
46 |
import com.spice.profitmandi.service.scheme.SchemeService;
|
| 150 |
import com.spice.profitmandi.service.user.RetailerService;
|
47 |
import com.spice.profitmandi.service.user.RetailerService;
|
| 151 |
import com.spice.profitmandi.service.wallet.WalletService;
|
48 |
import com.spice.profitmandi.service.wallet.WalletService;
|
| - |
|
49 |
import org.apache.logging.log4j.LogManager;
|
| - |
|
50 |
import org.apache.logging.log4j.Logger;
|
| - |
|
51 |
import org.hibernate.Session;
|
| - |
|
52 |
import org.hibernate.SessionFactory;
|
| - |
|
53 |
import org.json.JSONObject;
|
| - |
|
54 |
import org.springframework.beans.factory.annotation.Autowired;
|
| - |
|
55 |
import org.springframework.beans.factory.annotation.Qualifier;
|
| - |
|
56 |
import org.springframework.beans.factory.annotation.Value;
|
| - |
|
57 |
import org.springframework.cache.annotation.Cacheable;
|
| - |
|
58 |
import org.springframework.core.io.InputStreamResource;
|
| - |
|
59 |
import org.springframework.http.HttpHeaders;
|
| - |
|
60 |
import org.springframework.http.HttpStatus;
|
| - |
|
61 |
import org.springframework.http.ResponseEntity;
|
| - |
|
62 |
import org.springframework.stereotype.Component;
|
| - |
|
63 |
|
| - |
|
64 |
import javax.persistence.criteria.CriteriaBuilder;
|
| - |
|
65 |
import javax.persistence.criteria.CriteriaQuery;
|
| - |
|
66 |
import javax.persistence.criteria.Predicate;
|
| - |
|
67 |
import javax.persistence.criteria.Root;
|
| - |
|
68 |
import java.io.ByteArrayInputStream;
|
| - |
|
69 |
import java.io.InputStream;
|
| - |
|
70 |
import java.time.LocalDate;
|
| - |
|
71 |
import java.time.LocalDateTime;
|
| - |
|
72 |
import java.time.LocalTime;
|
| - |
|
73 |
import java.util.AbstractMap.SimpleEntry;
|
| - |
|
74 |
import java.util.*;
|
| - |
|
75 |
import java.util.function.Function;
|
| - |
|
76 |
import java.util.stream.Collectors;
|
| 152 |
|
77 |
|
| 153 |
@Component
|
78 |
@Component
|
| 154 |
public class OrderServiceImpl implements OrderService {
|
79 |
public class OrderServiceImpl implements OrderService {
|
| 155 |
|
80 |
|
| 156 |
private static final Logger LOGGER = LogManager.getLogger(OrderServiceImpl.class);
|
81 |
private static final Logger LOGGER = LogManager.getLogger(OrderServiceImpl.class);
|
| Line 533... |
Line 458... |
| 533 |
}
|
458 |
}
|
| 534 |
|
459 |
|
| 535 |
Map<Integer, PriceModel> itemIdMopPriceMap = pricingService.getPurchasePriceMopPriceNotFound(itemIdCustomFofoOrderItemMap.keySet(), fofoId);
|
460 |
Map<Integer, PriceModel> itemIdMopPriceMap = pricingService.getPurchasePriceMopPriceNotFound(itemIdCustomFofoOrderItemMap.keySet(), fofoId);
|
| 536 |
LOGGER.info("itemIdMopMap {}", itemIdMopPriceMap);
|
461 |
LOGGER.info("itemIdMopMap {}", itemIdMopPriceMap);
|
| 537 |
if (accessoriesDeals) {
|
462 |
if (accessoriesDeals) {
|
| 538 |
this.validateDpPrice(itemIdMopPriceMap, itemIdCustomFofoOrderItemMap);
|
463 |
this.validateDpPrice(fofoId, itemIdMopPriceMap, itemIdCustomFofoOrderItemMap);
|
| 539 |
} else {
|
464 |
} else {
|
| 540 |
this.validateMopPrice(itemIdMopPriceMap, itemIdCustomFofoOrderItemMap);
|
465 |
this.validateMopPrice(fofoId, itemIdMopPriceMap, itemIdCustomFofoOrderItemMap);
|
| 541 |
}
|
466 |
}
|
| 542 |
|
467 |
|
| 543 |
String fofoStoreCode = this.getFofoStoreCode(fofoId);
|
468 |
String fofoStoreCode = this.getFofoStoreCode(fofoId);
|
| 544 |
String documentNumber = null;
|
469 |
String documentNumber = null;
|
| 545 |
if (noGST) {
|
470 |
if (noGST) {
|
| Line 1341... |
Line 1266... |
| 1341 |
}
|
1266 |
}
|
| 1342 |
}
|
1267 |
}
|
| 1343 |
return serialNumbers;
|
1268 |
return serialNumbers;
|
| 1344 |
}
|
1269 |
}
|
| 1345 |
|
1270 |
|
| 1346 |
private void validateDpPrice(Map<Integer, PriceModel> itemIdMopPriceMap, Map<Integer, CustomFofoOrderItem> itemIdCustomFofoLineItemMap) throws ProfitMandiBusinessException {
|
1271 |
private void validateDpPrice(int fofoId, Map<Integer, PriceModel> itemIdMopPriceMap, Map<Integer, CustomFofoOrderItem> itemIdCustomFofoLineItemMap) throws ProfitMandiBusinessException {
|
| - |
|
1272 |
if (pricingService.getMopVoilatedRetailerIds().contains(fofoId)) return;
|
| 1347 |
for (Map.Entry<Integer, CustomFofoOrderItem> entry : itemIdCustomFofoLineItemMap.entrySet()) {
|
1273 |
for (Map.Entry<Integer, CustomFofoOrderItem> entry : itemIdCustomFofoLineItemMap.entrySet()) {
|
| 1348 |
int itemId = entry.getKey();
|
1274 |
int itemId = entry.getKey();
|
| 1349 |
CustomFofoOrderItem customFofoOrderItem = entry.getValue();
|
1275 |
CustomFofoOrderItem customFofoOrderItem = entry.getValue();
|
| 1350 |
LOGGER.info("CustomFofoOrderItem -- {}", customFofoOrderItem);
|
1276 |
LOGGER.info("CustomFofoOrderItem -- {}", customFofoOrderItem);
|
| 1351 |
PriceModel priceModel = itemIdMopPriceMap.get(itemId);
|
1277 |
PriceModel priceModel = itemIdMopPriceMap.get(itemId);
|
| Line 1360... |
Line 1286... |
| 1360 |
}
|
1286 |
}
|
| 1361 |
}
|
1287 |
}
|
| 1362 |
}
|
1288 |
}
|
| 1363 |
}
|
1289 |
}
|
| 1364 |
|
1290 |
|
| 1365 |
private void validateMopPrice(Map<Integer, PriceModel> itemIdMopPriceMap, Map<Integer, CustomFofoOrderItem> itemIdCustomFofoLineItemMap) throws ProfitMandiBusinessException {
|
1291 |
private void validateMopPrice(int fofoId, Map<Integer, PriceModel> itemIdMopPriceMap, Map<Integer, CustomFofoOrderItem> itemIdCustomFofoLineItemMap) throws ProfitMandiBusinessException {
|
| - |
|
1292 |
if (pricingService.getMopVoilatedRetailerIds().contains(fofoId)) return;
|
| 1366 |
Map<Integer, Float> invalidMopItemIdPriceMap = new HashMap<>();
|
1293 |
Map<Integer, Float> invalidMopItemIdPriceMap = new HashMap<>();
|
| 1367 |
for (Map.Entry<Integer, PriceModel> entry : itemIdMopPriceMap.entrySet()) {
|
1294 |
for (Map.Entry<Integer, PriceModel> entry : itemIdMopPriceMap.entrySet()) {
|
| 1368 |
CustomFofoOrderItem customFofoOrderItem = itemIdCustomFofoLineItemMap.get(entry.getKey());
|
1295 |
CustomFofoOrderItem customFofoOrderItem = itemIdCustomFofoLineItemMap.get(entry.getKey());
|
| 1369 |
Item item = itemRepository.selectById(customFofoOrderItem.getItemId());
|
1296 |
Item item = itemRepository.selectById(customFofoOrderItem.getItemId());
|
| 1370 |
if (!(item.getBrand().equals("Live Demo") || item.getCategoryId() != ProfitMandiConstants.MOBILE_CATEGORY_ID || item.getCategoryId() != ProfitMandiConstants.TABLET_CATEGORY_ID) && customFofoOrderItem.getSellingPrice() + customFofoOrderItem.getDiscountAmount() < entry.getValue().getPrice()) {
|
1297 |
if (!(item.getBrand().equals("Live Demo") || item.getCategoryId() != ProfitMandiConstants.MOBILE_CATEGORY_ID || item.getCategoryId() != ProfitMandiConstants.TABLET_CATEGORY_ID) && customFofoOrderItem.getSellingPrice() + customFofoOrderItem.getDiscountAmount() < entry.getValue().getPrice()) {
|