| Line 1... |
Line 1... |
| 1 |
package com.spice.profitmandi.service.inventory;
|
1 |
package com.spice.profitmandi.service.order;
|
| 2 |
|
2 |
|
| 3 |
import java.time.DateTimeException;
|
3 |
import java.time.DateTimeException;
|
| 4 |
import java.time.LocalDate;
|
4 |
import java.time.LocalDate;
|
| 5 |
import java.time.LocalDateTime;
|
5 |
import java.time.LocalDateTime;
|
| 6 |
import java.util.ArrayList;
|
6 |
import java.util.ArrayList;
|
| Line 52... |
Line 52... |
| 52 |
import com.spice.profitmandi.dao.entity.fofo.Customer;
|
52 |
import com.spice.profitmandi.dao.entity.fofo.Customer;
|
| 53 |
import com.spice.profitmandi.dao.entity.fofo.CustomerAddress;
|
53 |
import com.spice.profitmandi.dao.entity.fofo.CustomerAddress;
|
| 54 |
import com.spice.profitmandi.dao.entity.fofo.FofoLineItem;
|
54 |
import com.spice.profitmandi.dao.entity.fofo.FofoLineItem;
|
| 55 |
import com.spice.profitmandi.dao.entity.fofo.FofoOrder;
|
55 |
import com.spice.profitmandi.dao.entity.fofo.FofoOrder;
|
| 56 |
import com.spice.profitmandi.dao.entity.fofo.FofoOrderItem;
|
56 |
import com.spice.profitmandi.dao.entity.fofo.FofoOrderItem;
|
| - |
|
57 |
import com.spice.profitmandi.dao.entity.fofo.FofoOrderPaymentOption;
|
| 57 |
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
|
58 |
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
|
| 58 |
import com.spice.profitmandi.dao.entity.fofo.InventoryItem;
|
59 |
import com.spice.profitmandi.dao.entity.fofo.InventoryItem;
|
| 59 |
import com.spice.profitmandi.dao.entity.fofo.InvoiceNumberGenerationSequence;
|
60 |
import com.spice.profitmandi.dao.entity.fofo.InvoiceNumberGenerationSequence;
|
| 60 |
import com.spice.profitmandi.dao.entity.fofo.PaymentOption;
|
- |
|
| 61 |
import com.spice.profitmandi.dao.entity.fofo.ScanRecord;
|
61 |
import com.spice.profitmandi.dao.entity.fofo.ScanRecord;
|
| 62 |
import com.spice.profitmandi.dao.entity.user.Address;
|
62 |
import com.spice.profitmandi.dao.entity.user.Address;
|
| 63 |
import com.spice.profitmandi.dao.entity.user.Counter;
|
63 |
import com.spice.profitmandi.dao.entity.user.Counter;
|
| 64 |
import com.spice.profitmandi.dao.entity.user.PrivateDealUser;
|
64 |
import com.spice.profitmandi.dao.entity.user.PrivateDealUser;
|
| 65 |
import com.spice.profitmandi.dao.enumuration.fofo.PaymentOptionType;
|
- |
|
| 66 |
import com.spice.profitmandi.dao.enumuration.fofo.ScanType;
|
65 |
import com.spice.profitmandi.dao.enumuration.fofo.ScanType;
|
| 67 |
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
|
66 |
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
|
| 68 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
67 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
| 69 |
import com.spice.profitmandi.dao.repository.dtr.InsurancePolicyRepository;
|
68 |
import com.spice.profitmandi.dao.repository.dtr.InsurancePolicyRepository;
|
| 70 |
import com.spice.profitmandi.dao.repository.dtr.InsuranceProviderRepository;
|
69 |
import com.spice.profitmandi.dao.repository.dtr.InsuranceProviderRepository;
|
| Line 76... |
Line 75... |
| 76 |
import com.spice.profitmandi.dao.repository.fofo.CurrentInventorySnapshotRepository;
|
75 |
import com.spice.profitmandi.dao.repository.fofo.CurrentInventorySnapshotRepository;
|
| 77 |
import com.spice.profitmandi.dao.repository.fofo.CustomerAddressRepository;
|
76 |
import com.spice.profitmandi.dao.repository.fofo.CustomerAddressRepository;
|
| 78 |
import com.spice.profitmandi.dao.repository.fofo.CustomerRepository;
|
77 |
import com.spice.profitmandi.dao.repository.fofo.CustomerRepository;
|
| 79 |
import com.spice.profitmandi.dao.repository.fofo.FofoLineItemRepository;
|
78 |
import com.spice.profitmandi.dao.repository.fofo.FofoLineItemRepository;
|
| 80 |
import com.spice.profitmandi.dao.repository.fofo.FofoOrderItemRepository;
|
79 |
import com.spice.profitmandi.dao.repository.fofo.FofoOrderItemRepository;
|
| - |
|
80 |
import com.spice.profitmandi.dao.repository.fofo.FofoOrderPaymentOptionRepository;
|
| 81 |
import com.spice.profitmandi.dao.repository.fofo.FofoOrderRepository;
|
81 |
import com.spice.profitmandi.dao.repository.fofo.FofoOrderRepository;
|
| 82 |
import com.spice.profitmandi.dao.repository.fofo.InventoryItemRepository;
|
82 |
import com.spice.profitmandi.dao.repository.fofo.InventoryItemRepository;
|
| 83 |
import com.spice.profitmandi.dao.repository.fofo.InvoiceNumberGenerationSequenceRepository;
|
83 |
import com.spice.profitmandi.dao.repository.fofo.InvoiceNumberGenerationSequenceRepository;
|
| 84 |
import com.spice.profitmandi.dao.repository.fofo.PaymentOptionRepository;
|
84 |
import com.spice.profitmandi.dao.repository.fofo.PaymentOptionRepository;
|
| 85 |
import com.spice.profitmandi.dao.repository.fofo.ScanRecordRepository;
|
85 |
import com.spice.profitmandi.dao.repository.fofo.ScanRecordRepository;
|
| Line 164... |
Line 164... |
| 164 |
|
164 |
|
| 165 |
@Autowired
|
165 |
@Autowired
|
| 166 |
private FofoStoreRepository fofoStoreRepository;
|
166 |
private FofoStoreRepository fofoStoreRepository;
|
| 167 |
|
167 |
|
| 168 |
@Autowired
|
168 |
@Autowired
|
| - |
|
169 |
private FofoOrderPaymentOptionRepository fofoOrderPaymentOptionRepository;
|
| - |
|
170 |
|
| - |
|
171 |
@Autowired
|
| 169 |
private SchemeService schemeService;
|
172 |
private SchemeService schemeService;
|
| 170 |
|
173 |
|
| 171 |
@Override
|
174 |
@Override
|
| 172 |
public int createOrder(CreateOrderRequest createOrderRequest, int fofoId) throws ProfitMandiBusinessException {
|
175 |
public int createOrder(CreateOrderRequest createOrderRequest, int fofoId) throws ProfitMandiBusinessException {
|
| 173 |
|
176 |
|
| Line 433... |
Line 436... |
| 433 |
LOGGER.info("Unable to submit insurance policy details to {}", insuranceProvider.getName(), profitMandiBusinessException);
|
436 |
LOGGER.info("Unable to submit insurance policy details to {}", insuranceProvider.getName(), profitMandiBusinessException);
|
| 434 |
}
|
437 |
}
|
| 435 |
insurancePolicyRepository.persist(insurancePolicy);
|
438 |
insurancePolicyRepository.persist(insurancePolicy);
|
| 436 |
}
|
439 |
}
|
| 437 |
}
|
440 |
}
|
| 438 |
float cashback = schemeService.processSchemeOut(fofoOrder.getId(), fofoId);
|
441 |
schemeService.processSchemeOut(fofoOrder.getId(), fofoId);
|
| 439 |
if(cashback > 0){
|
- |
|
| 440 |
fofoOrder.setCashback(cashback);
|
- |
|
| 441 |
fofoOrderRepository.persist(fofoOrder);
|
- |
|
| 442 |
}
|
442 |
|
| 443 |
return fofoOrder.getId();
|
443 |
return fofoOrder.getId();
|
| 444 |
}
|
444 |
}
|
| 445 |
|
445 |
|
| 446 |
@Override
|
446 |
@Override
|
| 447 |
public PdfModel getInvoicePdfModel(int fofoId, int orderId) throws ProfitMandiBusinessException {
|
447 |
public PdfModel getInvoicePdfModel(int fofoId, int orderId) throws ProfitMandiBusinessException {
|
| Line 954... |
Line 954... |
| 954 |
currentInventorySnapshotRepository.updateAvailabilityByItemIdAndFofoId(itemId, fofoId, currentInventorySnapshot.getAvailability() - quantity);
|
954 |
currentInventorySnapshotRepository.updateAvailabilityByItemIdAndFofoId(itemId, fofoId, currentInventorySnapshot.getAvailability() - quantity);
|
| 955 |
}
|
955 |
}
|
| 956 |
}
|
956 |
}
|
| 957 |
}
|
957 |
}
|
| 958 |
|
958 |
|
| 959 |
private void createPaymentOptions(int fofoOrderId, Set<CustomPaymentOption> customPaymentOptions){
|
959 |
private void createPaymentOptions(int fofoOrderId, Set<CustomPaymentOption> customPaymentOptions) throws ProfitMandiBusinessException{
|
| 960 |
for(CustomPaymentOption customPaymentOption : customPaymentOptions){
|
960 |
for(CustomPaymentOption customPaymentOption : customPaymentOptions){
|
| 961 |
if(customPaymentOption.getAmount() > 0){
|
- |
|
| 962 |
PaymentOption paymentOption = new PaymentOption();
|
961 |
FofoOrderPaymentOption fofoOrderPaymentOption = new FofoOrderPaymentOption();
|
| 963 |
paymentOption.setOrderId(fofoOrderId);
|
962 |
fofoOrderPaymentOption.setFofoOrderId(fofoOrderId);
|
| 964 |
paymentOption.setAmount(customPaymentOption.getAmount());
|
963 |
fofoOrderPaymentOption.setPaymentOptionId(customPaymentOption.getPaymentOptionId());
|
| 965 |
paymentOption.setType(PaymentOptionType.valueOf(customPaymentOption.getType()));
|
964 |
fofoOrderPaymentOption.setAmount(customPaymentOption.getAmount());
|
| 966 |
paymentOptionRepository.persist(paymentOption);
|
965 |
fofoOrderPaymentOptionRepository.persist(fofoOrderPaymentOption);
|
| 967 |
}
|
- |
|
| 968 |
}
|
966 |
}
|
| 969 |
}
|
967 |
}
|
| 970 |
|
968 |
|
| 971 |
private FofoOrder createAndGetFofoOrder(int customerId, int fofoId, InvoiceNumberGenerationSequence invoiceNumberGenerationSequence, float totalAmount, int customerAddressId){
|
969 |
private FofoOrder createAndGetFofoOrder(int customerId, int fofoId, InvoiceNumberGenerationSequence invoiceNumberGenerationSequence, float totalAmount, int customerAddressId){
|
| 972 |
FofoOrder fofoOrder = new FofoOrder();
|
970 |
FofoOrder fofoOrder = new FofoOrder();
|
| Line 1140... |
Line 1138... |
| 1140 |
return customAddress;
|
1138 |
return customAddress;
|
| 1141 |
}
|
1139 |
}
|
| 1142 |
|
1140 |
|
| 1143 |
private void validatePaymentOptionsAndTotalAmount(Set<CustomPaymentOption> customPaymentOptions, float totalAmount) throws ProfitMandiBusinessException
|
1141 |
private void validatePaymentOptionsAndTotalAmount(Set<CustomPaymentOption> customPaymentOptions, float totalAmount) throws ProfitMandiBusinessException
|
| 1144 |
{
|
1142 |
{
|
| - |
|
1143 |
Set<Integer> paymentOptionIds = new HashSet<>();
|
| - |
|
1144 |
Set<Integer> invalidPaymentOptionIdAmounts = new HashSet<>();
|
| - |
|
1145 |
|
| 1145 |
float calculatedAmount = 0;
|
1146 |
float calculatedAmount = 0;
|
| 1146 |
Set<String> paymentOptionTypes = new HashSet<>();
|
- |
|
| 1147 |
for(CustomPaymentOption customPaymentOption : customPaymentOptions){
|
1147 |
for(CustomPaymentOption customPaymentOption : customPaymentOptions){
|
| 1148 |
if(paymentOptionTypes.contains(PaymentOptionType.valueOf(customPaymentOption.getType()))){
|
- |
|
| 1149 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.PAYMENT_OPTION_TYPE, customPaymentOption.getType(), "");
|
- |
|
| 1150 |
}else{
|
- |
|
| 1151 |
paymentOptionTypes.add(customPaymentOption.getType());
|
1148 |
if(customPaymentOption.getAmount() <= 0) {
|
| 1152 |
calculatedAmount = calculatedAmount + customPaymentOption.getAmount();
|
1149 |
invalidPaymentOptionIdAmounts.add(customPaymentOption.getPaymentOptionId());
|
| 1153 |
}
|
1150 |
}
|
| - |
|
1151 |
paymentOptionIds.add(customPaymentOption.getPaymentOptionId());
|
| - |
|
1152 |
calculatedAmount = calculatedAmount + customPaymentOption.getAmount();
|
| 1154 |
}
|
1153 |
}
|
| 1155 |
if(calculatedAmount != totalAmount){
|
1154 |
if(calculatedAmount != totalAmount){
|
| 1156 |
LOGGER.warn("Error occured while validating payment options amount[{}] != TotalAmount [{}]", calculatedAmount, totalAmount);
|
1155 |
LOGGER.warn("Error occured while validating payment options amount[{}] != TotalAmount [{}]", calculatedAmount, totalAmount);
|
| 1157 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.PAYMENT_OPTION_CALCULATED_AMOUNT, calculatedAmount, "FFORDR_1016");
|
1156 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.PAYMENT_OPTION_CALCULATED_AMOUNT, calculatedAmount, "FFORDR_1016");
|
| 1158 |
}
|
1157 |
}
|
| - |
|
1158 |
|
| - |
|
1159 |
if(!invalidPaymentOptionIdAmounts.isEmpty()) {
|
| - |
|
1160 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.PAYMENT_OPTION_ID, invalidPaymentOptionIdAmounts, "FFORDR_1018");
|
| - |
|
1161 |
}
|
| - |
|
1162 |
List<Integer> foundPaymentOptionIds = paymentOptionRepository.selectIdsByIds(paymentOptionIds);
|
| - |
|
1163 |
if(foundPaymentOptionIds.size() != paymentOptionIds.size()) {
|
| - |
|
1164 |
paymentOptionIds.removeAll(foundPaymentOptionIds);
|
| - |
|
1165 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.PAYMENT_OPTION_ID, paymentOptionIds, "FFORDR_1017");
|
| - |
|
1166 |
}
|
| 1159 |
}
|
1167 |
}
|
| 1160 |
|
1168 |
|
| 1161 |
@Override
|
1169 |
@Override
|
| 1162 |
public List<FofoOrderItem> getByOrderId(int orderId) throws ProfitMandiBusinessException {
|
1170 |
public List<FofoOrderItem> getByOrderId(int orderId) throws ProfitMandiBusinessException {
|
| 1163 |
List<FofoOrderItem> fofoOrderItems = fofoOrderItemRepository.selectByOrderId(orderId);
|
1171 |
List<FofoOrderItem> fofoOrderItems = fofoOrderItemRepository.selectByOrderId(orderId);
|