| 23365 |
ashik.ali |
1 |
package com.spice.profitmandi.service.order;
|
| 22859 |
ashik.ali |
2 |
|
| 23418 |
ashik.ali |
3 |
import java.io.IOException;
|
|
|
4 |
import java.net.URISyntaxException;
|
| 22859 |
ashik.ali |
5 |
import java.time.DateTimeException;
|
|
|
6 |
import java.time.LocalDate;
|
| 23202 |
ashik.ali |
7 |
import java.time.LocalDateTime;
|
| 22859 |
ashik.ali |
8 |
import java.util.ArrayList;
|
| 23655 |
amit.gupta |
9 |
import java.util.Arrays;
|
| 22859 |
ashik.ali |
10 |
import java.util.HashMap;
|
|
|
11 |
import java.util.HashSet;
|
|
|
12 |
import java.util.Iterator;
|
|
|
13 |
import java.util.List;
|
|
|
14 |
import java.util.Map;
|
| 23418 |
ashik.ali |
15 |
import java.util.Random;
|
| 22859 |
ashik.ali |
16 |
import java.util.Set;
|
| 22955 |
ashik.ali |
17 |
import java.util.function.Function;
|
|
|
18 |
import java.util.stream.Collectors;
|
| 22859 |
ashik.ali |
19 |
|
| 23638 |
amit.gupta |
20 |
import org.apache.logging.log4j.LogManager;
|
|
|
21 |
import org.apache.logging.log4j.Logger;
|
| 22859 |
ashik.ali |
22 |
import org.json.JSONObject;
|
|
|
23 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 23781 |
ashik.ali |
24 |
import org.springframework.beans.factory.annotation.Qualifier;
|
| 22859 |
ashik.ali |
25 |
import org.springframework.stereotype.Component;
|
|
|
26 |
|
| 23418 |
ashik.ali |
27 |
import com.spice.profitmandi.common.ResponseCodeHolder;
|
| 23202 |
ashik.ali |
28 |
import com.spice.profitmandi.common.enumuration.SearchType;
|
| 22859 |
ashik.ali |
29 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 23638 |
amit.gupta |
30 |
import com.spice.profitmandi.common.model.BadReturnRequest;
|
| 22859 |
ashik.ali |
31 |
import com.spice.profitmandi.common.model.CartFofo;
|
|
|
32 |
import com.spice.profitmandi.common.model.CreateOrderRequest;
|
| 23638 |
amit.gupta |
33 |
import com.spice.profitmandi.common.model.CreditNotePdfModel;
|
| 22859 |
ashik.ali |
34 |
import com.spice.profitmandi.common.model.CustomAddress;
|
|
|
35 |
import com.spice.profitmandi.common.model.CustomCustomer;
|
|
|
36 |
import com.spice.profitmandi.common.model.CustomFofoOrderItem;
|
|
|
37 |
import com.spice.profitmandi.common.model.CustomInsurancePolicy;
|
|
|
38 |
import com.spice.profitmandi.common.model.CustomOrderItem;
|
|
|
39 |
import com.spice.profitmandi.common.model.CustomPaymentOption;
|
|
|
40 |
import com.spice.profitmandi.common.model.CustomRetailer;
|
| 23638 |
amit.gupta |
41 |
import com.spice.profitmandi.common.model.FoiBadReturnRequest;
|
| 22859 |
ashik.ali |
42 |
import com.spice.profitmandi.common.model.GadgetCopsInsuranceModel;
|
| 23172 |
ashik.ali |
43 |
import com.spice.profitmandi.common.model.GstRate;
|
| 22859 |
ashik.ali |
44 |
import com.spice.profitmandi.common.model.ItemIdQuantityAvailability;
|
|
|
45 |
import com.spice.profitmandi.common.model.PdfModel;
|
|
|
46 |
import com.spice.profitmandi.common.model.PriceModel;
|
|
|
47 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
|
|
48 |
import com.spice.profitmandi.common.model.Quantity;
|
|
|
49 |
import com.spice.profitmandi.common.model.SerialNumberDetail;
|
| 23650 |
amit.gupta |
50 |
import com.spice.profitmandi.common.util.FormattingUtils;
|
| 22859 |
ashik.ali |
51 |
import com.spice.profitmandi.common.util.InsuranceUtils;
|
|
|
52 |
import com.spice.profitmandi.common.util.StringUtils;
|
| 23172 |
ashik.ali |
53 |
import com.spice.profitmandi.common.util.Utils;
|
| 22859 |
ashik.ali |
54 |
import com.spice.profitmandi.dao.entity.catalog.Item;
|
|
|
55 |
import com.spice.profitmandi.dao.entity.dtr.GadgetCopsInsuranceCalc;
|
|
|
56 |
import com.spice.profitmandi.dao.entity.dtr.InsurancePolicy;
|
|
|
57 |
import com.spice.profitmandi.dao.entity.dtr.InsuranceProvider;
|
| 23418 |
ashik.ali |
58 |
import com.spice.profitmandi.dao.entity.dtr.Otp;
|
| 23546 |
ashik.ali |
59 |
import com.spice.profitmandi.dao.entity.dtr.PaymentOptionTransaction;
|
| 22859 |
ashik.ali |
60 |
import com.spice.profitmandi.dao.entity.dtr.PolicyNumberGenerationSequence;
|
|
|
61 |
import com.spice.profitmandi.dao.entity.dtr.Retailer;
|
|
|
62 |
import com.spice.profitmandi.dao.entity.dtr.User;
|
|
|
63 |
import com.spice.profitmandi.dao.entity.fofo.CurrentInventorySnapshot;
|
|
|
64 |
import com.spice.profitmandi.dao.entity.fofo.Customer;
|
|
|
65 |
import com.spice.profitmandi.dao.entity.fofo.CustomerAddress;
|
| 23650 |
amit.gupta |
66 |
import com.spice.profitmandi.dao.entity.fofo.CustomerCreditNote;
|
|
|
67 |
import com.spice.profitmandi.dao.entity.fofo.CustomerReturnItem;
|
| 22859 |
ashik.ali |
68 |
import com.spice.profitmandi.dao.entity.fofo.FofoLineItem;
|
|
|
69 |
import com.spice.profitmandi.dao.entity.fofo.FofoOrder;
|
|
|
70 |
import com.spice.profitmandi.dao.entity.fofo.FofoOrderItem;
|
| 23202 |
ashik.ali |
71 |
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
|
| 22859 |
ashik.ali |
72 |
import com.spice.profitmandi.dao.entity.fofo.InventoryItem;
|
|
|
73 |
import com.spice.profitmandi.dao.entity.fofo.InvoiceNumberGenerationSequence;
|
| 23418 |
ashik.ali |
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;
|
| 22859 |
ashik.ali |
77 |
import com.spice.profitmandi.dao.entity.fofo.ScanRecord;
|
|
|
78 |
import com.spice.profitmandi.dao.entity.user.Address;
|
|
|
79 |
import com.spice.profitmandi.dao.entity.user.Counter;
|
|
|
80 |
import com.spice.profitmandi.dao.entity.user.PrivateDealUser;
|
| 23418 |
ashik.ali |
81 |
import com.spice.profitmandi.dao.enumuration.dtr.OtpType;
|
| 23546 |
ashik.ali |
82 |
import com.spice.profitmandi.dao.enumuration.dtr.PaymentOptionReferenceType;
|
| 23650 |
amit.gupta |
83 |
import com.spice.profitmandi.dao.enumuration.fofo.ReturnType;
|
| 22859 |
ashik.ali |
84 |
import com.spice.profitmandi.dao.enumuration.fofo.ScanType;
|
| 23655 |
amit.gupta |
85 |
import com.spice.profitmandi.dao.enumuration.fofo.SettlementType;
|
| 22859 |
ashik.ali |
86 |
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
|
| 23202 |
ashik.ali |
87 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
| 22859 |
ashik.ali |
88 |
import com.spice.profitmandi.dao.repository.dtr.InsurancePolicyRepository;
|
|
|
89 |
import com.spice.profitmandi.dao.repository.dtr.InsuranceProviderRepository;
|
| 23418 |
ashik.ali |
90 |
import com.spice.profitmandi.dao.repository.dtr.OtpRepository;
|
| 23552 |
amit.gupta |
91 |
import com.spice.profitmandi.dao.repository.dtr.PaymentOptionTransactionRepository;
|
| 22859 |
ashik.ali |
92 |
import com.spice.profitmandi.dao.repository.dtr.PolicyNumberGenerationSequenceRepository;
|
|
|
93 |
import com.spice.profitmandi.dao.repository.dtr.RetailerRegisteredAddressRepository;
|
|
|
94 |
import com.spice.profitmandi.dao.repository.dtr.RetailerRepository;
|
|
|
95 |
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
|
|
|
96 |
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
|
| 23650 |
amit.gupta |
97 |
import com.spice.profitmandi.dao.repository.fofo.BadInventorySnapshotRepository;
|
| 22859 |
ashik.ali |
98 |
import com.spice.profitmandi.dao.repository.fofo.CurrentInventorySnapshotRepository;
|
|
|
99 |
import com.spice.profitmandi.dao.repository.fofo.CustomerAddressRepository;
|
| 23650 |
amit.gupta |
100 |
import com.spice.profitmandi.dao.repository.fofo.CustomerCreditNoteRepository;
|
| 22859 |
ashik.ali |
101 |
import com.spice.profitmandi.dao.repository.fofo.CustomerRepository;
|
| 23650 |
amit.gupta |
102 |
import com.spice.profitmandi.dao.repository.fofo.CustomerReturnItemRepository;
|
| 22859 |
ashik.ali |
103 |
import com.spice.profitmandi.dao.repository.fofo.FofoLineItemRepository;
|
|
|
104 |
import com.spice.profitmandi.dao.repository.fofo.FofoOrderItemRepository;
|
|
|
105 |
import com.spice.profitmandi.dao.repository.fofo.FofoOrderRepository;
|
|
|
106 |
import com.spice.profitmandi.dao.repository.fofo.InventoryItemRepository;
|
|
|
107 |
import com.spice.profitmandi.dao.repository.fofo.InvoiceNumberGenerationSequenceRepository;
|
|
|
108 |
import com.spice.profitmandi.dao.repository.fofo.PaymentOptionRepository;
|
| 23418 |
ashik.ali |
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;
|
| 23566 |
amit.gupta |
112 |
import com.spice.profitmandi.dao.repository.fofo.PurchaseReturnItemRepository;
|
| 22859 |
ashik.ali |
113 |
import com.spice.profitmandi.dao.repository.fofo.ScanRecordRepository;
|
|
|
114 |
import com.spice.profitmandi.dao.repository.user.AddressRepository;
|
|
|
115 |
import com.spice.profitmandi.dao.repository.user.CounterRepository;
|
|
|
116 |
import com.spice.profitmandi.dao.repository.user.PrivateDealUserRepository;
|
| 23418 |
ashik.ali |
117 |
import com.spice.profitmandi.service.inventory.InventoryService;
|
| 23655 |
amit.gupta |
118 |
import com.spice.profitmandi.service.inventory.PurchaseReturnService;
|
| 22859 |
ashik.ali |
119 |
import com.spice.profitmandi.service.pricing.PricingService;
|
|
|
120 |
import com.spice.profitmandi.service.scheme.SchemeService;
|
| 23655 |
amit.gupta |
121 |
import com.spice.profitmandi.service.user.RetailerService;
|
| 23395 |
amit.gupta |
122 |
import com.spice.profitmandi.service.wallet.WalletService;
|
| 22859 |
ashik.ali |
123 |
|
|
|
124 |
import in.shop2020.model.v1.catalog.ItemType;
|
| 23395 |
amit.gupta |
125 |
import in.shop2020.model.v1.order.WalletReferenceType;
|
| 22859 |
ashik.ali |
126 |
|
|
|
127 |
@Component
|
|
|
128 |
public class OrderServiceImpl implements OrderService {
|
|
|
129 |
|
| 23568 |
govind |
130 |
private static final Logger LOGGER = LogManager.getLogger(OrderServiceImpl.class);
|
| 22859 |
ashik.ali |
131 |
|
|
|
132 |
@Autowired
|
| 23781 |
ashik.ali |
133 |
@Qualifier("fofoInventoryItemRepository")
|
| 22859 |
ashik.ali |
134 |
private InventoryItemRepository inventoryItemRepository;
|
| 23650 |
amit.gupta |
135 |
|
| 23395 |
amit.gupta |
136 |
@Autowired
|
|
|
137 |
private WalletService walletService;
|
| 22859 |
ashik.ali |
138 |
|
|
|
139 |
@Autowired
|
| 23781 |
ashik.ali |
140 |
@Qualifier("fofoCurrentInventorySnapshotRepository")
|
| 22859 |
ashik.ali |
141 |
private CurrentInventorySnapshotRepository currentInventorySnapshotRepository;
|
|
|
142 |
|
|
|
143 |
@Autowired
|
|
|
144 |
private InvoiceNumberGenerationSequenceRepository invoiceNumberGenerationSequenceRepository;
|
|
|
145 |
|
|
|
146 |
@Autowired
|
| 23655 |
amit.gupta |
147 |
private PurchaseReturnService purchaseReturnService;
|
|
|
148 |
|
|
|
149 |
@Autowired
|
|
|
150 |
private RetailerService retailerService;
|
|
|
151 |
|
|
|
152 |
@Autowired
|
| 22859 |
ashik.ali |
153 |
private CustomerRepository customerRepository;
|
| 23650 |
amit.gupta |
154 |
|
| 23566 |
amit.gupta |
155 |
@Autowired
|
|
|
156 |
private PurchaseReturnItemRepository purchaseReturnItemRepository;
|
| 22859 |
ashik.ali |
157 |
|
|
|
158 |
@Autowired
|
|
|
159 |
private AddressRepository addressRepository;
|
|
|
160 |
|
|
|
161 |
@Autowired
|
|
|
162 |
private FofoLineItemRepository fofoLineItemRepository;
|
|
|
163 |
|
|
|
164 |
@Autowired
|
|
|
165 |
private FofoOrderItemRepository fofoOrderItemRepository;
|
| 23650 |
amit.gupta |
166 |
|
| 22859 |
ashik.ali |
167 |
@Autowired
|
|
|
168 |
private PaymentOptionRepository paymentOptionRepository;
|
|
|
169 |
|
|
|
170 |
@Autowired
|
| 23650 |
amit.gupta |
171 |
private CustomerReturnItemRepository customerReturnItemRepository;
|
|
|
172 |
|
|
|
173 |
@Autowired
|
| 23781 |
ashik.ali |
174 |
@Qualifier("fofoScanRecordRepository")
|
| 22859 |
ashik.ali |
175 |
private ScanRecordRepository scanRecordRepository;
|
|
|
176 |
|
|
|
177 |
@Autowired
|
|
|
178 |
private FofoOrderRepository fofoOrderRepository;
|
|
|
179 |
|
|
|
180 |
@Autowired
|
|
|
181 |
private RetailerRepository retailerRepository;
|
|
|
182 |
|
|
|
183 |
@Autowired
|
|
|
184 |
private UserRepository userRepository;
|
|
|
185 |
|
|
|
186 |
@Autowired
|
| 23650 |
amit.gupta |
187 |
private BadInventorySnapshotRepository badInventorySnapshotRepository;
|
|
|
188 |
|
|
|
189 |
@Autowired
|
| 22859 |
ashik.ali |
190 |
private UserAccountRepository userAccountRepository;
|
|
|
191 |
|
|
|
192 |
@Autowired
|
|
|
193 |
private RetailerRegisteredAddressRepository retailerRegisteredAddressRepository;
|
|
|
194 |
|
|
|
195 |
@Autowired
|
|
|
196 |
private CustomerAddressRepository customerAddressRepository;
|
|
|
197 |
|
|
|
198 |
@Autowired
|
| 23781 |
ashik.ali |
199 |
@Qualifier("catalogItemRepository")
|
| 22859 |
ashik.ali |
200 |
private ItemRepository itemRepository;
|
| 23650 |
amit.gupta |
201 |
|
| 22859 |
ashik.ali |
202 |
@Autowired
|
|
|
203 |
private InsuranceProviderRepository insuranceProviderRepository;
|
| 23650 |
amit.gupta |
204 |
|
| 22859 |
ashik.ali |
205 |
@Autowired
|
|
|
206 |
private InsurancePolicyRepository insurancePolicyRepository;
|
| 23650 |
amit.gupta |
207 |
|
| 22859 |
ashik.ali |
208 |
@Autowired
|
|
|
209 |
private PolicyNumberGenerationSequenceRepository policyNumberGenerationSequenceRepository;
|
| 23650 |
amit.gupta |
210 |
|
| 22859 |
ashik.ali |
211 |
@Autowired
|
|
|
212 |
private PricingService pricingService;
|
| 23650 |
amit.gupta |
213 |
|
| 22859 |
ashik.ali |
214 |
@Autowired
|
|
|
215 |
private PrivateDealUserRepository privateDealUserRepository;
|
| 23650 |
amit.gupta |
216 |
|
| 22859 |
ashik.ali |
217 |
@Autowired
|
|
|
218 |
private CounterRepository counterRepository;
|
| 23650 |
amit.gupta |
219 |
|
| 22859 |
ashik.ali |
220 |
@Autowired
|
| 23202 |
ashik.ali |
221 |
private FofoStoreRepository fofoStoreRepository;
|
| 23650 |
amit.gupta |
222 |
|
| 23202 |
ashik.ali |
223 |
@Autowired
|
| 23546 |
ashik.ali |
224 |
private PaymentOptionTransactionRepository paymentOptionTransactionRepository;
|
| 23650 |
amit.gupta |
225 |
|
| 23365 |
ashik.ali |
226 |
@Autowired
|
| 23418 |
ashik.ali |
227 |
private PrebookingListingRepository prebookingListingRepository;
|
| 23650 |
amit.gupta |
228 |
|
| 23418 |
ashik.ali |
229 |
@Autowired
|
|
|
230 |
private PrebookingOrderRepository prebookingOrderRepository;
|
| 23650 |
amit.gupta |
231 |
|
| 23418 |
ashik.ali |
232 |
@Autowired
|
|
|
233 |
private PrebookingOrderItemRepository prebookingOrderItemRepository;
|
| 23650 |
amit.gupta |
234 |
|
| 23418 |
ashik.ali |
235 |
@Autowired
|
| 22859 |
ashik.ali |
236 |
private SchemeService schemeService;
|
| 23650 |
amit.gupta |
237 |
|
| 23418 |
ashik.ali |
238 |
@Autowired
|
| 23781 |
ashik.ali |
239 |
@Qualifier("fofoInventoryService")
|
| 23418 |
ashik.ali |
240 |
private InventoryService inventoryService;
|
| 23650 |
amit.gupta |
241 |
|
| 23418 |
ashik.ali |
242 |
@Autowired
|
| 23650 |
amit.gupta |
243 |
private CustomerCreditNoteRepository customerCreditNoteRepository;
|
|
|
244 |
|
|
|
245 |
@Autowired
|
| 23418 |
ashik.ali |
246 |
private OtpRepository otpRepository;
|
| 23650 |
amit.gupta |
247 |
|
| 22859 |
ashik.ali |
248 |
@Override
|
| 23823 |
amit.gupta |
249 |
public int createOrder(CreateOrderRequest createOrderRequest, int fofoId, boolean accessoriesDeals) throws ProfitMandiBusinessException {
|
| 23650 |
amit.gupta |
250 |
|
| 22872 |
ashik.ali |
251 |
CustomCustomer customCustomer = createOrderRequest.getCustomer();
|
|
|
252 |
|
| 23650 |
amit.gupta |
253 |
if (!StringUtils.isValidEmailAddress(customCustomer.getEmailId())) {
|
| 22872 |
ashik.ali |
254 |
LOGGER.error("invalid customer emailId {} ", customCustomer.getEmailId());
|
| 23650 |
amit.gupta |
255 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.EMAIL_ID, customCustomer.getEmailId(),
|
|
|
256 |
"VE_1016");
|
| 22872 |
ashik.ali |
257 |
}
|
|
|
258 |
|
| 23650 |
amit.gupta |
259 |
if (!StringUtils.isValidMobile(customCustomer.getMobileNumber())) {
|
| 22872 |
ashik.ali |
260 |
LOGGER.error("invalid customer mobileNumber {} ", customCustomer.getMobileNumber());
|
| 23650 |
amit.gupta |
261 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.MOBILE_NUMBER, customCustomer.getMobileNumber(),
|
|
|
262 |
"VE_1071");
|
| 22872 |
ashik.ali |
263 |
}
|
| 23650 |
amit.gupta |
264 |
|
|
|
265 |
if (!StringUtils.isValidGstNumber(customCustomer.getGstNumber())) {
|
| 23369 |
ashik.ali |
266 |
LOGGER.error("invalid customer gstNumber {} ", customCustomer.getGstNumber());
|
| 23650 |
amit.gupta |
267 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.CUSTOMER_GST_NUMBER,
|
|
|
268 |
customCustomer.getGstNumber(), "VE_1072");
|
| 23369 |
ashik.ali |
269 |
}
|
| 23650 |
amit.gupta |
270 |
|
|
|
271 |
Map<Integer, Integer> itemIdQuantity = new HashMap<>(); // this is for error
|
| 22872 |
ashik.ali |
272 |
Map<Integer, CustomFofoOrderItem> itemIdCustomFofoOrderItemMap = new HashMap<>();
|
| 23650 |
amit.gupta |
273 |
Map<Integer, Float> lineItemPrice = new HashMap<>(); // this is for pricing error
|
|
|
274 |
|
| 23418 |
ashik.ali |
275 |
Map<Integer, Integer> prebookingOrderItemIdQuantityMap = new HashMap<>(); // for prebooking order adjustment
|
| 23650 |
amit.gupta |
276 |
|
| 22859 |
ashik.ali |
277 |
float totalAmount = 0;
|
| 23650 |
amit.gupta |
278 |
for (CustomFofoOrderItem customFofoOrderItem : createOrderRequest.getFofoOrderItems()) {
|
|
|
279 |
// itemIds.add(customFofoOrderItem.getItemId());
|
|
|
280 |
if (customFofoOrderItem.isPrebookingOrder()) {
|
|
|
281 |
prebookingOrderItemIdQuantityMap.put(customFofoOrderItem.getItemId(),
|
|
|
282 |
customFofoOrderItem.getQuantity());
|
| 23418 |
ashik.ali |
283 |
}
|
| 23650 |
amit.gupta |
284 |
Set<String> serialNumbers = this
|
|
|
285 |
.serialNumberDetailsToSerialNumbers(customFofoOrderItem.getSerialNumberDetails());
|
|
|
286 |
if (!serialNumbers.isEmpty() && customFofoOrderItem.getQuantity() != serialNumbers.size()) {
|
| 22859 |
ashik.ali |
287 |
itemIdQuantity.put(customFofoOrderItem.getItemId(), customFofoOrderItem.getQuantity());
|
|
|
288 |
}
|
| 23650 |
amit.gupta |
289 |
if (!(customFofoOrderItem.getSellingPrice() > 0)) {
|
| 22859 |
ashik.ali |
290 |
lineItemPrice.put(customFofoOrderItem.getItemId(), customFofoOrderItem.getSellingPrice());
|
| 23650 |
amit.gupta |
291 |
} else {
|
| 22863 |
ashik.ali |
292 |
totalAmount = totalAmount + customFofoOrderItem.getSellingPrice() * customFofoOrderItem.getQuantity();
|
|
|
293 |
totalAmount = totalAmount - customFofoOrderItem.getDiscountAmount() * customFofoOrderItem.getQuantity();
|
| 23650 |
amit.gupta |
294 |
for (SerialNumberDetail serialNumberDetail : customFofoOrderItem.getSerialNumberDetails()) {
|
|
|
295 |
if (serialNumberDetail.isInsurance() && serialNumberDetail.getAmount() > 0) {
|
| 22859 |
ashik.ali |
296 |
totalAmount = totalAmount + serialNumberDetail.getAmount();
|
|
|
297 |
}
|
|
|
298 |
}
|
|
|
299 |
}
|
| 23650 |
amit.gupta |
300 |
|
| 22872 |
ashik.ali |
301 |
itemIdCustomFofoOrderItemMap.put(customFofoOrderItem.getItemId(), customFofoOrderItem);
|
| 22859 |
ashik.ali |
302 |
}
|
| 23650 |
amit.gupta |
303 |
if (!itemIdQuantity.isEmpty()) {
|
| 22859 |
ashik.ali |
304 |
// if item quantity does not match with given serialnumbers size
|
|
|
305 |
LOGGER.error("itemId's quantity should be equal to given serialnumber size {} ", itemIdQuantity);
|
| 22925 |
ashik.ali |
306 |
throw new ProfitMandiBusinessException("itemIdQuantity", itemIdQuantity, "FFORDR_1001");
|
| 23650 |
amit.gupta |
307 |
// return "error";
|
| 22859 |
ashik.ali |
308 |
}
|
| 23650 |
amit.gupta |
309 |
|
| 23427 |
amit.gupta |
310 |
List<PrebookingListing> prebookingListings = new ArrayList<>();
|
| 23650 |
amit.gupta |
311 |
Map<Integer, PrebookingListing> itemIdPrebookingListingMap = new HashMap<>();
|
| 23427 |
amit.gupta |
312 |
List<PrebookingOrder> prebookingOrders = new ArrayList<>();
|
|
|
313 |
float prebookingOrdersTotalAmount = 0;
|
| 23650 |
amit.gupta |
314 |
if (!prebookingOrderItemIdQuantityMap.isEmpty()) {
|
|
|
315 |
prebookingListings = prebookingListingRepository
|
|
|
316 |
.selectAllByItemIds(prebookingOrderItemIdQuantityMap.keySet());
|
| 23427 |
amit.gupta |
317 |
itemIdPrebookingListingMap = this.prebookingListingsToItemIdPrebookingListingMap(prebookingListings);
|
| 23650 |
amit.gupta |
318 |
prebookingOrders = prebookingOrderRepository.selectByFofoIdCustomerMobileNumberItemIds(fofoId,
|
|
|
319 |
customCustomer.getMobileNumber(), prebookingOrderItemIdQuantityMap.keySet());
|
|
|
320 |
prebookingOrdersTotalAmount = this.calculatePrebookingOrdersAmount(prebookingOrders,
|
|
|
321 |
prebookingOrderItemIdQuantityMap, itemIdPrebookingListingMap);
|
| 23427 |
amit.gupta |
322 |
}
|
| 23650 |
amit.gupta |
323 |
|
|
|
324 |
this.validatePaymentOptionsAndTotalAmount(createOrderRequest.getPaymentOptions(),
|
|
|
325 |
totalAmount - prebookingOrdersTotalAmount);
|
|
|
326 |
|
|
|
327 |
if (!lineItemPrice.isEmpty()) {
|
| 22859 |
ashik.ali |
328 |
// given fofo line item price must be greater than zero
|
|
|
329 |
LOGGER.error("requested itemId's selling price must greater than 0");
|
| 22925 |
ashik.ali |
330 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.PRICE, lineItemPrice, "FFORDR_1002");
|
| 22859 |
ashik.ali |
331 |
}
|
|
|
332 |
|
| 23650 |
amit.gupta |
333 |
List<CurrentInventorySnapshot> currentInventorySnapshots = currentInventorySnapshotRepository
|
|
|
334 |
.selectByFofoItemIds(fofoId, itemIdCustomFofoOrderItemMap.keySet());
|
|
|
335 |
|
| 22872 |
ashik.ali |
336 |
this.validateCurrentInventorySnapshotQuantities(currentInventorySnapshots, itemIdCustomFofoOrderItemMap);
|
| 22859 |
ashik.ali |
337 |
|
| 22872 |
ashik.ali |
338 |
List<Item> items = itemRepository.selectByIds(itemIdCustomFofoOrderItemMap.keySet());
|
| 23650 |
amit.gupta |
339 |
if (items.size() != itemIdCustomFofoOrderItemMap.keySet().size()) {
|
| 22872 |
ashik.ali |
340 |
LOGGER.error("Requested ItemIds not found in catalog");
|
| 23650 |
amit.gupta |
341 |
// invalid itemIds
|
|
|
342 |
throw new ProfitMandiBusinessException("invalidItemIds", itemIdCustomFofoOrderItemMap.keySet(),
|
|
|
343 |
"FFORDR_1003");
|
| 22872 |
ashik.ali |
344 |
}
|
| 23650 |
amit.gupta |
345 |
|
|
|
346 |
Map<Integer, Item> itemMap = this.toItemMap(items);
|
|
|
347 |
|
| 22859 |
ashik.ali |
348 |
Set<Integer> nonSerializedItemIds = new HashSet<>();
|
|
|
349 |
Set<String> serialNumbers = new HashSet<>();
|
|
|
350 |
Map<String, Float> insuranceSerialNumberItemPrice = new HashMap<>();
|
|
|
351 |
Map<String, Float> insuranceSerialNumberSaleAmount = new HashMap<>();
|
|
|
352 |
Map<String, String> serialNumberModelName = new HashMap<>();
|
|
|
353 |
Map<String, String> serialNumberBrand = new HashMap<>();
|
| 23650 |
amit.gupta |
354 |
for (CustomFofoOrderItem customFofoOrderItem : createOrderRequest.getFofoOrderItems()) {
|
| 22872 |
ashik.ali |
355 |
Item item = itemMap.get(customFofoOrderItem.getItemId());
|
| 23650 |
amit.gupta |
356 |
if (item.getType().equals(ItemType.SERIALIZED)) {
|
|
|
357 |
for (SerialNumberDetail serialNumberDetail : customFofoOrderItem.getSerialNumberDetails()) {
|
| 22859 |
ashik.ali |
358 |
serialNumbers.add(serialNumberDetail.getSerialNumber());
|
| 23650 |
amit.gupta |
359 |
if (serialNumberDetail.isInsurance()) {
|
|
|
360 |
insuranceSerialNumberItemPrice.put(serialNumberDetail.getSerialNumber(),
|
|
|
361 |
customFofoOrderItem.getSellingPrice());
|
|
|
362 |
insuranceSerialNumberSaleAmount.put(serialNumberDetail.getSerialNumber(),
|
|
|
363 |
serialNumberDetail.getAmount());
|
|
|
364 |
serialNumberModelName.put(serialNumberDetail.getSerialNumber(),
|
|
|
365 |
(item.getModelName() + item.getModelNumber()).trim());
|
| 22859 |
ashik.ali |
366 |
serialNumberBrand.put(serialNumberDetail.getSerialNumber(), item.getBrand());
|
|
|
367 |
}
|
|
|
368 |
}
|
| 23650 |
amit.gupta |
369 |
} else {
|
| 22872 |
ashik.ali |
370 |
nonSerializedItemIds.add(customFofoOrderItem.getItemId());
|
| 22859 |
ashik.ali |
371 |
}
|
|
|
372 |
}
|
| 23650 |
amit.gupta |
373 |
|
| 22859 |
ashik.ali |
374 |
Map<Integer, Set<InventoryItem>> serializedInventoryItemMap = new HashMap<>();
|
|
|
375 |
Map<Integer, Set<InventoryItem>> nonSerializedInventoryItemMap = new HashMap<>();
|
| 23650 |
amit.gupta |
376 |
// Map<String, Float> serialNumberItemPrice = new HashMap<>();
|
|
|
377 |
|
|
|
378 |
if (!serialNumbers.isEmpty()) {
|
|
|
379 |
List<InventoryItem> serializedInventoryItems = inventoryItemRepository.selectByFofoIdSerialNumbers(fofoId,
|
|
|
380 |
serialNumbers);
|
| 23397 |
amit.gupta |
381 |
LOGGER.info("serializedInventoryItems {}", serializedInventoryItems);
|
| 23650 |
amit.gupta |
382 |
for (InventoryItem inventoryItem : serializedInventoryItems) {
|
|
|
383 |
if (inventoryItem.getGoodQuantity() == 1) {
|
|
|
384 |
if (serializedInventoryItemMap.containsKey(inventoryItem.getItemId())) {
|
| 23397 |
amit.gupta |
385 |
serializedInventoryItemMap.get(inventoryItem.getItemId()).add(inventoryItem);
|
| 23650 |
amit.gupta |
386 |
} else {
|
| 23397 |
amit.gupta |
387 |
Set<InventoryItem> itemIdInventoryItems = new HashSet<>();
|
|
|
388 |
itemIdInventoryItems.add(inventoryItem);
|
|
|
389 |
serializedInventoryItemMap.put(inventoryItem.getItemId(), itemIdInventoryItems);
|
|
|
390 |
}
|
|
|
391 |
}
|
|
|
392 |
}
|
|
|
393 |
}
|
| 23418 |
ashik.ali |
394 |
|
| 23650 |
amit.gupta |
395 |
if (!nonSerializedItemIds.isEmpty()) {
|
|
|
396 |
List<InventoryItem> nonSerializedInventoryItems = inventoryItemRepository.selectByFofoIdItemIds(fofoId,
|
|
|
397 |
nonSerializedItemIds);
|
| 22872 |
ashik.ali |
398 |
LOGGER.info("nonSerializedInventoryItems {}", nonSerializedInventoryItems);
|
| 23650 |
amit.gupta |
399 |
for (InventoryItem it : nonSerializedInventoryItems) {
|
|
|
400 |
if (it.getGoodQuantity() > 0) {
|
|
|
401 |
if (nonSerializedInventoryItemMap.containsKey(it.getItemId())) {
|
| 22859 |
ashik.ali |
402 |
nonSerializedInventoryItemMap.get(it.getItemId()).add(it);
|
| 23650 |
amit.gupta |
403 |
} else {
|
| 22859 |
ashik.ali |
404 |
Set<InventoryItem> tmp = new HashSet<>();
|
|
|
405 |
tmp.add(it);
|
|
|
406 |
nonSerializedInventoryItemMap.put(it.getItemId(), tmp);
|
|
|
407 |
}
|
|
|
408 |
}
|
|
|
409 |
}
|
|
|
410 |
}
|
| 23650 |
amit.gupta |
411 |
|
| 22872 |
ashik.ali |
412 |
this.validateItemsSerializedNonSerialized(items, itemIdCustomFofoOrderItemMap);
|
| 22859 |
ashik.ali |
413 |
|
|
|
414 |
Map<Integer, Set<InventoryItem>> inventoryItemsToBill = new HashMap<>();
|
| 23650 |
amit.gupta |
415 |
Map<Integer, Integer> inventoryItemIdQuantityUsed = new HashMap<>(); // to keep track of inventoryitem quanity
|
|
|
416 |
// used for scan records insertion
|
| 22859 |
ashik.ali |
417 |
|
|
|
418 |
LOGGER.info("itemMap keys {}", itemMap.keySet());
|
| 23650 |
amit.gupta |
419 |
// Lets reduce quantity and decide what inventory items to use.
|
|
|
420 |
for (Item item : items) {
|
|
|
421 |
if (item.getType().equals(ItemType.SERIALIZED)) {
|
|
|
422 |
// TODO:handle null
|
|
|
423 |
if (serializedInventoryItemMap.get(item.getId()) == null
|
|
|
424 |
|| itemIdCustomFofoOrderItemMap.get(item.getId()).getSerialNumberDetails()
|
|
|
425 |
.size() != serializedInventoryItemMap.get(item.getId()).size()) {
|
|
|
426 |
// not enough serial numbers
|
|
|
427 |
// LOGGER.info("serialNumbers {}", serialNumbers);
|
|
|
428 |
// LOGGER.info("serializedInventoryItemMap {}", serializedInventoryItemMap);
|
| 22872 |
ashik.ali |
429 |
LOGGER.error("itemId {} => mismatch size of requested serial numbers", item.getId());
|
| 22955 |
ashik.ali |
430 |
Function<SerialNumberDetail, String> serialNumberDetailToSerialNumberFunction = new Function<SerialNumberDetail, String>() {
|
|
|
431 |
@Override
|
|
|
432 |
public String apply(SerialNumberDetail serialNumberDetail) {
|
|
|
433 |
return serialNumberDetail.getSerialNumber();
|
|
|
434 |
}
|
|
|
435 |
};
|
| 23650 |
amit.gupta |
436 |
throw new ProfitMandiBusinessException("invalidSerialNumbers",
|
|
|
437 |
itemIdCustomFofoOrderItemMap.get(item.getId()).getSerialNumberDetails().stream()
|
|
|
438 |
.map(serialNumberDetailToSerialNumberFunction).collect(Collectors.toList()),
|
|
|
439 |
"FFORDR_1004");
|
| 22872 |
ashik.ali |
440 |
}
|
| 22859 |
ashik.ali |
441 |
Set<InventoryItem> inventoryItemsSerializedserialized = serializedInventoryItemMap.get(item.getId());
|
| 23650 |
amit.gupta |
442 |
for (InventoryItem inventoryItem : inventoryItemsSerializedserialized) {
|
| 22872 |
ashik.ali |
443 |
inventoryItem.setGoodQuantity(0);
|
|
|
444 |
inventoryItemIdQuantityUsed.put(inventoryItem.getId(), 1);
|
| 22859 |
ashik.ali |
445 |
}
|
|
|
446 |
inventoryItemsToBill.put(item.getId(), inventoryItemsSerializedserialized);
|
| 23650 |
amit.gupta |
447 |
} else {
|
| 22859 |
ashik.ali |
448 |
Set<InventoryItem> inventoryItemsNonSerialized = nonSerializedInventoryItemMap.get(item.getId());
|
| 22872 |
ashik.ali |
449 |
int quantityToBill = itemIdCustomFofoOrderItemMap.get(item.getId()).getQuantity();
|
| 22859 |
ashik.ali |
450 |
int totalLeft = quantityToBill;
|
|
|
451 |
Set<InventoryItem> inventoryItemsNonSerializedUsed = new HashSet<>();
|
| 23650 |
amit.gupta |
452 |
if (inventoryItemsNonSerialized != null) {
|
|
|
453 |
for (InventoryItem inventoryItem : inventoryItemsNonSerialized) {
|
|
|
454 |
if (totalLeft > 0) {
|
| 22859 |
ashik.ali |
455 |
int toUse = Math.min(totalLeft, inventoryItem.getGoodQuantity());
|
|
|
456 |
inventoryItemIdQuantityUsed.put(inventoryItem.getId(), toUse);
|
| 23650 |
amit.gupta |
457 |
inventoryItem.setGoodQuantity(inventoryItem.getGoodQuantity() - toUse);
|
| 22859 |
ashik.ali |
458 |
totalLeft = totalLeft - toUse;
|
|
|
459 |
inventoryItemsNonSerializedUsed.add(inventoryItem);
|
|
|
460 |
}
|
|
|
461 |
}
|
|
|
462 |
}
|
| 23650 |
amit.gupta |
463 |
|
|
|
464 |
if (totalLeft > 0) {
|
|
|
465 |
// not enough quanity for non-serialized
|
| 22859 |
ashik.ali |
466 |
LOGGER.error("not enough quanity for non-serialized");
|
| 23650 |
amit.gupta |
467 |
throw new ProfitMandiBusinessException("notEnoughQuantityForNonSerialized", totalLeft,
|
|
|
468 |
"FFORDR_1005");
|
| 22859 |
ashik.ali |
469 |
}
|
|
|
470 |
inventoryItemsToBill.put(item.getId(), inventoryItemsNonSerializedUsed);
|
|
|
471 |
}
|
|
|
472 |
}
|
| 23650 |
amit.gupta |
473 |
|
|
|
474 |
Map<Integer, PriceModel> itemIdMopPriceMap = pricingService
|
|
|
475 |
.getPurchasePriceMopPriceNotFound(itemIdCustomFofoOrderItemMap.keySet(), fofoId);
|
| 23823 |
amit.gupta |
476 |
if(accessoriesDeals) {
|
|
|
477 |
this.validateDpPrice(itemIdMopPriceMap, itemIdCustomFofoOrderItemMap);
|
|
|
478 |
} else {
|
|
|
479 |
this.validateMopPrice(itemIdMopPriceMap, itemIdCustomFofoOrderItemMap);
|
|
|
480 |
}
|
| 23650 |
amit.gupta |
481 |
|
| 23202 |
ashik.ali |
482 |
String fofoStoreCode = this.getFofoStoreCode(fofoId);
|
| 22859 |
ashik.ali |
483 |
|
| 23650 |
amit.gupta |
484 |
InvoiceNumberGenerationSequence invoiceNumberGenerationSequence = this
|
|
|
485 |
.createAndGetInvoiceNumberGenerationSequence(fofoId, fofoStoreCode);
|
|
|
486 |
|
| 22859 |
ashik.ali |
487 |
Customer customer = this.createAndGetCustomer(customCustomer);
|
| 23650 |
amit.gupta |
488 |
|
| 23191 |
ashik.ali |
489 |
CustomerAddress customerAddress = this.createCustomerAddress(customCustomer.getAddress(), customer.getId());
|
| 23650 |
amit.gupta |
490 |
|
|
|
491 |
FofoOrder fofoOrder = this.createAndGetFofoOrder(customer.getId(), customCustomer.getGstNumber(), fofoId,
|
|
|
492 |
invoiceNumberGenerationSequence, totalAmount, customerAddress.getId());
|
|
|
493 |
|
| 23612 |
amit.gupta |
494 |
this.createPaymentOptions(fofoOrder, createOrderRequest.getPaymentOptions());
|
| 23650 |
amit.gupta |
495 |
|
|
|
496 |
this.processPrebookingOrders(fofoId, fofoOrder.getId(), prebookingOrders, prebookingOrderItemIdQuantityMap,
|
|
|
497 |
itemIdPrebookingListingMap);
|
|
|
498 |
|
| 23172 |
ashik.ali |
499 |
int retailerAddressId = retailerRegisteredAddressRepository.selectAddressIdByRetailerId(fofoId);
|
| 23650 |
amit.gupta |
500 |
|
| 23172 |
ashik.ali |
501 |
Address retailerAddress = addressRepository.selectById(retailerAddressId);
|
| 23650 |
amit.gupta |
502 |
|
| 23172 |
ashik.ali |
503 |
Integer stateId = null;
|
| 23650 |
amit.gupta |
504 |
if (customerAddress.getState().equals(retailerAddress.getState())) {
|
|
|
505 |
try {
|
| 23172 |
ashik.ali |
506 |
stateId = Long.valueOf(Utils.getStateInfo(customerAddress.getState()).getId()).intValue();
|
| 23650 |
amit.gupta |
507 |
} catch (Exception e) {
|
| 23172 |
ashik.ali |
508 |
LOGGER.error("Unable to get state rates");
|
|
|
509 |
}
|
|
|
510 |
}
|
| 23650 |
amit.gupta |
511 |
|
|
|
512 |
for (CustomFofoOrderItem customFofoOrderItem : createOrderRequest.getFofoOrderItems()) {
|
|
|
513 |
FofoOrderItem fofoOrderItem = this.createAndGetFofoOrderItem(customFofoOrderItem, fofoOrder.getId(),
|
|
|
514 |
itemMap, inventoryItemsToBill.get(customFofoOrderItem.getItemId()), stateId);
|
|
|
515 |
|
| 22859 |
ashik.ali |
516 |
Set<InventoryItem> inventoryItems = inventoryItemsToBill.get(customFofoOrderItem.getItemId());
|
| 23650 |
amit.gupta |
517 |
|
| 22859 |
ashik.ali |
518 |
this.createFofoLineItem(fofoOrderItem.getId(), inventoryItems, inventoryItemIdQuantityUsed);
|
| 23650 |
amit.gupta |
519 |
|
|
|
520 |
this.updateCurrentInventorySnapshot(currentInventorySnapshots, fofoId, customFofoOrderItem.getItemId(),
|
|
|
521 |
customFofoOrderItem.getQuantity());
|
|
|
522 |
|
| 22859 |
ashik.ali |
523 |
this.updateInventoryItemsAndScanRecord(inventoryItems, fofoId, inventoryItemIdQuantityUsed);
|
|
|
524 |
}
|
| 23650 |
amit.gupta |
525 |
|
| 22859 |
ashik.ali |
526 |
// insurance calculation is insurance flag is enabled
|
| 23650 |
amit.gupta |
527 |
if (!insuranceSerialNumberItemPrice.isEmpty()) {
|
| 22859 |
ashik.ali |
528 |
LOGGER.info("Processing for insurence for serialNumbers");
|
| 23650 |
amit.gupta |
529 |
Map<Float, GadgetCopsInsuranceCalc> insurancePricesMap = pricingService.getInsurancePrices(
|
|
|
530 |
new HashSet<>(insuranceSerialNumberItemPrice.values()), ProfitMandiConstants.GADGET_COPS);
|
|
|
531 |
InsuranceProvider insuranceProvider = insuranceProviderRepository
|
|
|
532 |
.selectByName(ProfitMandiConstants.GADGET_COPS);
|
|
|
533 |
|
|
|
534 |
this.validateInsuranceAmount(insuranceSerialNumberItemPrice, insuranceSerialNumberSaleAmount,
|
|
|
535 |
insurancePricesMap);
|
|
|
536 |
|
|
|
537 |
this.validateInsuranceMargin(insuranceSerialNumberItemPrice, itemIdCustomFofoOrderItemMap,
|
|
|
538 |
itemIdMopPriceMap, insurancePricesMap, insuranceSerialNumberSaleAmount);
|
|
|
539 |
|
|
|
540 |
LocalDate customerDateOfBirth = this
|
|
|
541 |
.validateCustomerDateOfBirth(createOrderRequest.getCustomerDateOfBirth());
|
|
|
542 |
|
|
|
543 |
for (Map.Entry<String, Float> entry : insuranceSerialNumberItemPrice.entrySet()) {
|
|
|
544 |
PolicyNumberGenerationSequence policyNumberGenerationSequence = this
|
|
|
545 |
.createPolicyNumberGenerationSequence();
|
|
|
546 |
|
|
|
547 |
InsurancePolicy insurancePolicy = this.createInsurancePolicy(fofoOrder.getInvoiceNumber(), fofoId,
|
| 22859 |
ashik.ali |
548 |
insurancePricesMap.get(entry.getValue()).getDealerPrice(),
|
| 23650 |
amit.gupta |
549 |
insuranceSerialNumberSaleAmount.get(entry.getKey()), entry.getValue(), entry.getKey(),
|
|
|
550 |
serialNumberModelName.get(entry.getKey()), serialNumberBrand.get(entry.getKey()),
|
|
|
551 |
policyNumberGenerationSequence.getSequence(), insuranceProvider.getId(), customer,
|
|
|
552 |
customerDateOfBirth, customerAddress);
|
|
|
553 |
|
|
|
554 |
GadgetCopsInsuranceModel gadgetCopsInsuranceModel = this.createGadgetCopsInsuranceModel(
|
|
|
555 |
serialNumberBrand.get(entry.getKey()), serialNumberModelName.get(entry.getKey()),
|
|
|
556 |
entry.getKey(), customerDateOfBirth, customer, customerAddress, insurancePolicy);
|
|
|
557 |
String walletDescription = "Sale of " + insurancePolicy.getPolicyNumber() + " for "
|
|
|
558 |
+ fofoOrder.getInvoiceNumber();
|
|
|
559 |
walletService.consumeAmountFromWallet(fofoId, insurancePolicy.getId(),
|
| 23395 |
amit.gupta |
560 |
WalletReferenceType.DAMAGE_PROTECTION, walletDescription, insurancePolicy.getPurchaseAmount());
|
| 23650 |
amit.gupta |
561 |
|
|
|
562 |
try {
|
| 22859 |
ashik.ali |
563 |
InsuranceUtils.submitToGadgetCops(gadgetCopsInsuranceModel);
|
|
|
564 |
insurancePolicy.setPosted(true);
|
| 23650 |
amit.gupta |
565 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
|
|
566 |
LOGGER.info("Unable to submit insurance policy details to {}", insuranceProvider.getName(),
|
|
|
567 |
profitMandiBusinessException);
|
| 22859 |
ashik.ali |
568 |
}
|
|
|
569 |
insurancePolicyRepository.persist(insurancePolicy);
|
|
|
570 |
}
|
|
|
571 |
}
|
| 23365 |
ashik.ali |
572 |
schemeService.processSchemeOut(fofoOrder.getId(), fofoId);
|
| 23650 |
amit.gupta |
573 |
|
| 22859 |
ashik.ali |
574 |
return fofoOrder.getId();
|
|
|
575 |
}
|
| 23650 |
amit.gupta |
576 |
|
|
|
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());
|
| 23418 |
ashik.ali |
583 |
float totalAmount = 0;
|
| 23650 |
amit.gupta |
584 |
for (PrebookingOrder prebookingOrder : prebookingOrders) {
|
| 23418 |
ashik.ali |
585 |
int requestedQuantity = prebookingOrderItemIdQuantityMap.get(prebookingOrder.getItemId());
|
|
|
586 |
PrebookingListing prebookingListing = itemIdPrebookingListingMap.get(prebookingOrder.getItemId());
|
| 23650 |
amit.gupta |
587 |
if (requestedQuantity < prebookingOrder.getAvailableQuantity()) {
|
|
|
588 |
LOGGER.info("when requestedQuantity < then requestedQuantity [{}] * advanceAmount [{}]",
|
|
|
589 |
requestedQuantity, prebookingListing.getAdvanceAmount());
|
| 23418 |
ashik.ali |
590 |
totalAmount = totalAmount + (requestedQuantity * prebookingListing.getAdvanceAmount());
|
| 23650 |
amit.gupta |
591 |
} else if (requestedQuantity >= prebookingOrder.getAvailableQuantity()) {
|
|
|
592 |
LOGGER.info("else requestedQuantity [{}] * advanceAmount [{}]", requestedQuantity,
|
|
|
593 |
prebookingListing.getAdvanceAmount());
|
|
|
594 |
totalAmount = totalAmount
|
|
|
595 |
+ (prebookingOrder.getAvailableQuantity() * prebookingListing.getAdvanceAmount());
|
| 23418 |
ashik.ali |
596 |
}
|
|
|
597 |
}
|
|
|
598 |
return totalAmount;
|
|
|
599 |
}
|
| 23650 |
amit.gupta |
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) {
|
| 23418 |
ashik.ali |
609 |
int requestedQuantity = prebookingOrderItemIdQuantityMap.get(prebookingOrder.getItemId());
|
| 23650 |
amit.gupta |
610 |
|
| 23418 |
ashik.ali |
611 |
PrebookingOrderItem prebookingOrderItem = new PrebookingOrderItem();
|
| 23650 |
amit.gupta |
612 |
if (requestedQuantity < prebookingOrder.getAvailableQuantity()) {
|
| 23418 |
ashik.ali |
613 |
prebookingOrder.setAvailableQuantity(prebookingOrder.getAvailableQuantity() - requestedQuantity);
|
|
|
614 |
prebookingOrderItem.setQuantity(requestedQuantity);
|
| 23650 |
amit.gupta |
615 |
} else if (requestedQuantity >= prebookingOrder.getAvailableQuantity()) {
|
| 23418 |
ashik.ali |
616 |
prebookingOrderItem.setQuantity(prebookingOrder.getAvailableQuantity());
|
|
|
617 |
prebookingOrder.setAvailableQuantity(0);
|
|
|
618 |
}
|
| 23650 |
amit.gupta |
619 |
if (prebookingOrder.getAvailableQuantity() == 0) {
|
| 23418 |
ashik.ali |
620 |
prebookingOrder.setCompleteTimestamp(LocalDateTime.now());
|
|
|
621 |
}
|
|
|
622 |
prebookingOrderRepository.persist(prebookingOrder);
|
| 23650 |
amit.gupta |
623 |
|
| 23418 |
ashik.ali |
624 |
prebookingOrderItem.setOrderId(orderId);
|
|
|
625 |
prebookingOrderItem.setItemId(prebookingOrder.getItemId());
|
|
|
626 |
PrebookingListing prebookingListing = itemIdPrebookingListingMap.get(prebookingOrder.getItemId());
|
|
|
627 |
prebookingOrderItem.setAdvanceAmount(prebookingListing.getAdvanceAmount());
|
| 23650 |
amit.gupta |
628 |
|
| 23418 |
ashik.ali |
629 |
prebookingOrderItemRepository.persist(prebookingOrderItem);
|
| 23650 |
amit.gupta |
630 |
|
|
|
631 |
walletService.addAmountToWallet(fofoId, prebookingOrder.getId(), WalletReferenceType.PREBOOKING_ORDER,
|
|
|
632 |
"Advance Amount credited for Prebooking Order", prebookingListing.getAdvanceAmount());
|
| 23418 |
ashik.ali |
633 |
}
|
| 23650 |
amit.gupta |
634 |
|
| 23418 |
ashik.ali |
635 |
}
|
|
|
636 |
}
|
| 23650 |
amit.gupta |
637 |
|
|
|
638 |
private Map<Integer, PrebookingListing> prebookingListingsToItemIdPrebookingListingMap(
|
|
|
639 |
List<PrebookingListing> prebookingListings) {
|
| 23418 |
ashik.ali |
640 |
Map<Integer, PrebookingListing> itemIdPrebookingListingMap = new HashMap<>();
|
| 23650 |
amit.gupta |
641 |
for (PrebookingListing prebookingListing : prebookingListings) {
|
| 23418 |
ashik.ali |
642 |
itemIdPrebookingListingMap.put(prebookingListing.getItemId(), prebookingListing);
|
|
|
643 |
}
|
|
|
644 |
return itemIdPrebookingListingMap;
|
|
|
645 |
}
|
| 23650 |
amit.gupta |
646 |
|
|
|
647 |
private Set<String> serialNumberDetailsToSerialNumbers(Set<SerialNumberDetail> serialNumberDetails) {
|
| 23377 |
ashik.ali |
648 |
Set<String> serialNumbers = new HashSet<>();
|
| 23650 |
amit.gupta |
649 |
for (SerialNumberDetail serialNumberDetail : serialNumberDetails) {
|
|
|
650 |
if (serialNumberDetail.getSerialNumber() != null && !serialNumberDetail.getSerialNumber().isEmpty()) {
|
| 23377 |
ashik.ali |
651 |
serialNumbers.add(serialNumberDetail.getSerialNumber());
|
|
|
652 |
}
|
|
|
653 |
}
|
|
|
654 |
return serialNumbers;
|
|
|
655 |
}
|
| 23650 |
amit.gupta |
656 |
|
| 22859 |
ashik.ali |
657 |
@Override
|
| 23596 |
ashik.ali |
658 |
public PdfModel getInvoicePdfModel(int orderId) throws ProfitMandiBusinessException {
|
|
|
659 |
FofoOrder fofoOrder = fofoOrderRepository.selectByOrderId(orderId);
|
|
|
660 |
return this.getInvoicePdfModel(fofoOrder);
|
|
|
661 |
}
|
| 23650 |
amit.gupta |
662 |
|
|
|
663 |
private PdfModel getInvoicePdfModel(FofoOrder fofoOrder) throws ProfitMandiBusinessException {
|
|
|
664 |
|
|
|
665 |
List<PaymentOptionTransaction> paymentOptionTransactions = paymentOptionTransactionRepository
|
|
|
666 |
.selectByReferenceIdAndType(fofoOrder.getId(), PaymentOptionReferenceType.ORDER);
|
|
|
667 |
|
| 23552 |
amit.gupta |
668 |
List<CustomPaymentOption> paymentOptions = new ArrayList<>();
|
|
|
669 |
|
| 22859 |
ashik.ali |
670 |
PdfModel pdfModel = new PdfModel();
|
| 23650 |
amit.gupta |
671 |
|
|
|
672 |
for (PaymentOptionTransaction paymentOptionTransaction : paymentOptionTransactions) {
|
| 23552 |
amit.gupta |
673 |
CustomPaymentOption cpi = new CustomPaymentOption();
|
|
|
674 |
cpi.setAmount(paymentOptionTransaction.getAmount());
|
| 23650 |
amit.gupta |
675 |
cpi.setPaymentOption(
|
|
|
676 |
paymentOptionRepository.selectById(paymentOptionTransaction.getPaymentOptionId()).getName());
|
| 23558 |
amit.gupta |
677 |
paymentOptions.add(cpi);
|
| 23552 |
amit.gupta |
678 |
}
|
|
|
679 |
pdfModel.setPaymentOptions(paymentOptions);
|
| 22859 |
ashik.ali |
680 |
pdfModel.setAuther("profitmandi");
|
|
|
681 |
pdfModel.setTitle("Retailer Invoice");
|
|
|
682 |
pdfModel.setInvoiceDate(fofoOrder.getFormattedDate());
|
| 23650 |
amit.gupta |
683 |
|
| 22859 |
ashik.ali |
684 |
// insurance calculation
|
| 23650 |
amit.gupta |
685 |
List<InsurancePolicy> insurancePolicies = insurancePolicyRepository
|
|
|
686 |
.selectByRetailerIdInvoiceNumber(fofoOrder.getFofoId(), fofoOrder.getInvoiceNumber());
|
| 22859 |
ashik.ali |
687 |
Set<CustomInsurancePolicy> customInsurancePolicies = new HashSet<>();
|
|
|
688 |
final float totalInsuranceTaxRate = 18;
|
| 23650 |
amit.gupta |
689 |
for (InsurancePolicy insurancePolicy : insurancePolicies) {
|
| 22859 |
ashik.ali |
690 |
float taxableInsurancePrice = insurancePolicy.getSaleAmount() / (1 + totalInsuranceTaxRate / 100);
|
|
|
691 |
CustomInsurancePolicy customInsurancePolicy = new CustomInsurancePolicy();
|
| 23650 |
amit.gupta |
692 |
customInsurancePolicy.setDescription("Damage Protection Plan for device IMEI #"
|
|
|
693 |
+ insurancePolicy.getSerialNumber() + "\n Certificate No. " + insurancePolicy.getPolicyNumber());
|
| 22859 |
ashik.ali |
694 |
customInsurancePolicy.setHsnCode("998716");
|
|
|
695 |
customInsurancePolicy.setRate(taxableInsurancePrice);
|
|
|
696 |
customInsurancePolicy.setIgstRate(18);
|
| 23650 |
amit.gupta |
697 |
customInsurancePolicy.setIgstAmount(taxableInsurancePrice * 18 / 100);
|
| 22936 |
amit.gupta |
698 |
customInsurancePolicy.setCgstRate(9);
|
| 23650 |
amit.gupta |
699 |
customInsurancePolicy.setCgstAmount(taxableInsurancePrice * 9 / 100);
|
| 22859 |
ashik.ali |
700 |
customInsurancePolicy.setSgstRate(9);
|
| 23650 |
amit.gupta |
701 |
customInsurancePolicy.setSgstAmount(taxableInsurancePrice * 9 / 100);
|
| 22859 |
ashik.ali |
702 |
customInsurancePolicy.setNetAmount(insurancePolicy.getSaleAmount());
|
|
|
703 |
customInsurancePolicies.add(customInsurancePolicy);
|
|
|
704 |
}
|
|
|
705 |
pdfModel.setInsurancePolicies(customInsurancePolicies);
|
| 23001 |
amit.gupta |
706 |
List<String> tncs = new ArrayList<>();
|
|
|
707 |
tncs.add("I agree that goods received are in good working condition");
|
|
|
708 |
tncs.add("Goods once sold cannot be exchanged or taken back");
|
|
|
709 |
tncs.add("Warranty for the goods received by me is the responsibility of the manufacturer only.");
|
| 23650 |
amit.gupta |
710 |
if (pdfModel.getInsurancePolicies() != null && pdfModel.getInsurancePolicies().size() > 0) {
|
|
|
711 |
tncs.add("Damage protection provided is the responisibility of Protection Provider only");
|
|
|
712 |
}
|
| 23001 |
amit.gupta |
713 |
pdfModel.setTncs(tncs);
|
| 23655 |
amit.gupta |
714 |
|
|
|
715 |
pdfModel.setCustomer(getCustomCustomer(fofoOrder));
|
| 22859 |
ashik.ali |
716 |
pdfModel.setInvoiceNumber(fofoOrder.getInvoiceNumber());
|
|
|
717 |
pdfModel.setTotalAmount(fofoOrder.getTotalAmount());
|
| 23650 |
amit.gupta |
718 |
|
| 23596 |
ashik.ali |
719 |
Retailer retailer = retailerRepository.selectById(fofoOrder.getFofoId());
|
| 22859 |
ashik.ali |
720 |
PrivateDealUser privateDealUser = null;
|
| 23650 |
amit.gupta |
721 |
try {
|
| 22859 |
ashik.ali |
722 |
privateDealUser = privateDealUserRepository.selectById(retailer.getId());
|
| 23650 |
amit.gupta |
723 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
| 22859 |
ashik.ali |
724 |
LOGGER.error("Private Deal User not found : ", profitMandiBusinessException);
|
|
|
725 |
}
|
| 23650 |
amit.gupta |
726 |
|
| 22859 |
ashik.ali |
727 |
User user = userRepository.selectById(userAccountRepository.selectUserIdByRetailerId(retailer.getId()));
|
|
|
728 |
CustomRetailer customRetailer = new CustomRetailer();
|
|
|
729 |
customRetailer.setBusinessName(retailer.getName());
|
|
|
730 |
customRetailer.setMobileNumber(user.getMobileNumber());
|
| 23650 |
amit.gupta |
731 |
// customRetailer.setTinNumber(retailer.getNumber());
|
|
|
732 |
if (privateDealUser == null) {
|
| 22859 |
ashik.ali |
733 |
customRetailer.setGstNumber(null);
|
| 23650 |
amit.gupta |
734 |
} else {
|
|
|
735 |
if (null != privateDealUser.getCounterId()) {
|
| 22859 |
ashik.ali |
736 |
Counter counter = counterRepository.selectById(privateDealUser.getCounterId());
|
|
|
737 |
customRetailer.setGstNumber(counter.getGstin());
|
| 23650 |
amit.gupta |
738 |
} else {
|
| 22859 |
ashik.ali |
739 |
customRetailer.setGstNumber(null);
|
|
|
740 |
}
|
|
|
741 |
}
|
| 23650 |
amit.gupta |
742 |
Address retailerAddress = addressRepository
|
|
|
743 |
.selectById(retailerRegisteredAddressRepository.selectAddressIdByRetailerId(retailer.getId()));
|
| 22859 |
ashik.ali |
744 |
customRetailer.setAddress(this.createCustomAddress(retailerAddress));
|
|
|
745 |
pdfModel.setRetailer(customRetailer);
|
| 22925 |
ashik.ali |
746 |
List<FofoOrderItem> fofoOrderItems = this.getByOrderId(fofoOrder.getId());
|
| 23650 |
amit.gupta |
747 |
|
| 22859 |
ashik.ali |
748 |
Set<CustomOrderItem> customerFofoOrderItems = new HashSet<>();
|
| 23650 |
amit.gupta |
749 |
for (FofoOrderItem fofoOrderItem : fofoOrderItems) {
|
| 22859 |
ashik.ali |
750 |
CustomOrderItem customFofoOrderItem = new CustomOrderItem();
|
| 23650 |
amit.gupta |
751 |
float totalTaxRate = fofoOrderItem.getIgstRate() + fofoOrderItem.getSgstRate()
|
|
|
752 |
+ fofoOrderItem.getCgstRate();
|
| 22859 |
ashik.ali |
753 |
float taxableSellingPrice = fofoOrderItem.getSellingPrice() / (1 + totalTaxRate / 100);
|
|
|
754 |
float taxableDiscountPrice = fofoOrderItem.getDiscount() / (1 + totalTaxRate / 100);
|
| 23650 |
amit.gupta |
755 |
|
| 22859 |
ashik.ali |
756 |
customFofoOrderItem.setAmount(fofoOrderItem.getQuantity() * (taxableSellingPrice - taxableDiscountPrice));
|
| 23650 |
amit.gupta |
757 |
customFofoOrderItem.setDescription(fofoOrderItem.getBrand() + " " + fofoOrderItem.getModelName() + " "
|
|
|
758 |
+ fofoOrderItem.getModelNumber() + "-" + fofoOrderItem.getColor());
|
| 23377 |
ashik.ali |
759 |
Set<String> serialNumbers = this.toSerialNumbers(fofoOrderItem.getFofoLineItems());
|
| 23650 |
amit.gupta |
760 |
// LOGGER.info("serialNumbers {}", serialNumbers);
|
|
|
761 |
// LOGGER.info("serialNumbers is empty {}", serialNumbers.isEmpty());
|
|
|
762 |
if (!serialNumbers.isEmpty()) {
|
|
|
763 |
customFofoOrderItem.setDescription(
|
|
|
764 |
customFofoOrderItem.getDescription() + "\n IMEIS - " + String.join(", ", serialNumbers));
|
| 23377 |
ashik.ali |
765 |
}
|
| 22859 |
ashik.ali |
766 |
customFofoOrderItem.setRate(taxableSellingPrice);
|
|
|
767 |
customFofoOrderItem.setDiscount(taxableDiscountPrice);
|
|
|
768 |
customFofoOrderItem.setQuantity(fofoOrderItem.getQuantity());
|
| 23650 |
amit.gupta |
769 |
customFofoOrderItem.setNetAmount(
|
|
|
770 |
(fofoOrderItem.getSellingPrice() - fofoOrderItem.getDiscount()) * fofoOrderItem.getQuantity());
|
| 22859 |
ashik.ali |
771 |
float igstAmount = (customFofoOrderItem.getAmount() * fofoOrderItem.getIgstRate()) / 100;
|
|
|
772 |
float cgstAmount = (customFofoOrderItem.getAmount() * fofoOrderItem.getCgstRate()) / 100;
|
|
|
773 |
float sgstAmount = (customFofoOrderItem.getAmount() * fofoOrderItem.getSgstRate()) / 100;
|
|
|
774 |
customFofoOrderItem.setIgstRate(fofoOrderItem.getIgstRate());
|
|
|
775 |
customFofoOrderItem.setIgstAmount(igstAmount);
|
|
|
776 |
customFofoOrderItem.setCgstRate(fofoOrderItem.getCgstRate());
|
|
|
777 |
customFofoOrderItem.setCgstAmount(cgstAmount);
|
|
|
778 |
customFofoOrderItem.setSgstRate(fofoOrderItem.getSgstRate());
|
|
|
779 |
customFofoOrderItem.setSgstAmount(sgstAmount);
|
|
|
780 |
customFofoOrderItem.setHsnCode(fofoOrderItem.getHsnCode());
|
|
|
781 |
customerFofoOrderItems.add(customFofoOrderItem);
|
|
|
782 |
}
|
|
|
783 |
pdfModel.setOrderItems(customerFofoOrderItems);
|
|
|
784 |
return pdfModel;
|
| 23650 |
amit.gupta |
785 |
|
| 22859 |
ashik.ali |
786 |
}
|
| 23650 |
amit.gupta |
787 |
|
| 23655 |
amit.gupta |
788 |
private CustomCustomer getCustomCustomer(FofoOrder fofoOrder) throws ProfitMandiBusinessException {
|
|
|
789 |
Customer customer = customerRepository.selectById(fofoOrder.getCustomerId());
|
|
|
790 |
CustomCustomer customCustomer = new CustomCustomer();
|
|
|
791 |
customCustomer.setFirstName(customer.getFirstName());
|
|
|
792 |
customCustomer.setLastName(customer.getLastName());
|
|
|
793 |
customCustomer.setEmailId(customer.getEmailId());
|
|
|
794 |
customCustomer.setMobileNumber(customer.getMobileNumber());
|
|
|
795 |
customCustomer.setGstNumber(fofoOrder.getCustomerGstNumber());
|
|
|
796 |
CustomerAddress customerAddress = customerAddressRepository.selectById(fofoOrder.getCustomerAddressId());
|
|
|
797 |
customCustomer.setAddress(this.createCustomAddress(customerAddress));
|
|
|
798 |
return customCustomer;
|
|
|
799 |
}
|
|
|
800 |
|
| 23596 |
ashik.ali |
801 |
@Override
|
|
|
802 |
public PdfModel getInvoicePdfModel(int fofoId, int orderId) throws ProfitMandiBusinessException {
|
|
|
803 |
FofoOrder fofoOrder = fofoOrderRepository.selectByFofoIdAndOrderId(fofoId, orderId);
|
|
|
804 |
return this.getInvoicePdfModel(fofoOrder);
|
|
|
805 |
}
|
| 23650 |
amit.gupta |
806 |
|
| 22859 |
ashik.ali |
807 |
public String getBillingAddress(CustomerAddress customerAddress) {
|
|
|
808 |
StringBuilder address = new StringBuilder();
|
|
|
809 |
if ((customerAddress.getLine1() != null) && (!customerAddress.getLine1().isEmpty())) {
|
|
|
810 |
address.append(customerAddress.getLine1());
|
|
|
811 |
address.append(", ");
|
|
|
812 |
}
|
|
|
813 |
|
|
|
814 |
if ((customerAddress.getLine2() != null) && (!customerAddress.getLine2().isEmpty())) {
|
|
|
815 |
address.append(customerAddress.getLine2());
|
|
|
816 |
address.append(", ");
|
|
|
817 |
}
|
|
|
818 |
|
|
|
819 |
if ((customerAddress.getLandmark() != null) && (!customerAddress.getLandmark().isEmpty())) {
|
|
|
820 |
address.append(customerAddress.getLandmark());
|
|
|
821 |
address.append(", ");
|
|
|
822 |
}
|
|
|
823 |
|
|
|
824 |
if ((customerAddress.getCity() != null) && (!customerAddress.getCity().isEmpty())) {
|
|
|
825 |
address.append(customerAddress.getCity());
|
|
|
826 |
address.append(", ");
|
|
|
827 |
}
|
|
|
828 |
|
|
|
829 |
if ((customerAddress.getState() != null) && (!customerAddress.getState().isEmpty())) {
|
|
|
830 |
address.append(customerAddress.getState());
|
|
|
831 |
}
|
|
|
832 |
|
|
|
833 |
if ((customerAddress.getPinCode() != null) && (!customerAddress.getPinCode().isEmpty())) {
|
|
|
834 |
address.append("- ");
|
|
|
835 |
address.append(customerAddress.getPinCode());
|
|
|
836 |
}
|
|
|
837 |
|
|
|
838 |
return address.toString();
|
|
|
839 |
}
|
| 23650 |
amit.gupta |
840 |
|
| 22859 |
ashik.ali |
841 |
@Override
|
| 23650 |
amit.gupta |
842 |
public List<CartFofo> cartCheckout(String cartJson) throws ProfitMandiBusinessException {
|
|
|
843 |
try {
|
| 22859 |
ashik.ali |
844 |
JSONObject cartObject = new JSONObject(cartJson);
|
|
|
845 |
Iterator<?> keys = cartObject.keys();
|
| 23650 |
amit.gupta |
846 |
|
| 22859 |
ashik.ali |
847 |
Set<Integer> itemIds = new HashSet<>();
|
|
|
848 |
List<CartFofo> cartItems = new ArrayList<CartFofo>();
|
| 23650 |
amit.gupta |
849 |
|
|
|
850 |
while (keys.hasNext()) {
|
|
|
851 |
String key = (String) keys.next();
|
|
|
852 |
if (cartObject.get(key) instanceof JSONObject) {
|
| 22859 |
ashik.ali |
853 |
LOGGER.info(cartObject.get(key).toString());
|
|
|
854 |
}
|
|
|
855 |
CartFofo cf = new CartFofo();
|
|
|
856 |
cf.setItemId(cartObject.getJSONObject(key).getInt("itemId"));
|
|
|
857 |
cf.setQuantity(cartObject.getJSONObject(key).getInt("quantity"));
|
| 23650 |
amit.gupta |
858 |
|
|
|
859 |
if (cf.getQuantity() <= 0) {
|
| 22859 |
ashik.ali |
860 |
continue;
|
|
|
861 |
}
|
|
|
862 |
cartItems.add(cf);
|
|
|
863 |
itemIds.add(cartObject.getJSONObject(key).getInt("itemId"));
|
|
|
864 |
}
|
| 23650 |
amit.gupta |
865 |
Map<Integer, Item> itemMap = new HashMap<Integer, Item>();
|
|
|
866 |
if (itemIds.size() > 0) {
|
| 22859 |
ashik.ali |
867 |
List<Item> items = itemRepository.selectByIds(itemIds);
|
| 23650 |
amit.gupta |
868 |
for (Item i : items) {
|
| 22859 |
ashik.ali |
869 |
itemMap.put(i.getId(), i);
|
|
|
870 |
}
|
| 23650 |
amit.gupta |
871 |
|
| 22859 |
ashik.ali |
872 |
}
|
| 23650 |
amit.gupta |
873 |
for (CartFofo cf : cartItems) {
|
| 22859 |
ashik.ali |
874 |
Item i = itemMap.get(cf.getItemId());
|
| 23650 |
amit.gupta |
875 |
if (i == null) {
|
| 22859 |
ashik.ali |
876 |
continue;
|
|
|
877 |
}
|
| 23650 |
amit.gupta |
878 |
cf.setDisplayName(getValidName(i.getBrand()) + " " + getValidName(i.getModelName()) + " "
|
|
|
879 |
+ getValidName(i.getModelNumber()) + " " + getValidName(i.getColor()).replaceAll("\\s+", " "));
|
| 22859 |
ashik.ali |
880 |
cf.setItemType(i.getType());
|
|
|
881 |
}
|
|
|
882 |
return cartItems;
|
| 23650 |
amit.gupta |
883 |
} catch (Exception e) {
|
| 22859 |
ashik.ali |
884 |
LOGGER.error("Unable to Prepare cart to place order...", e);
|
| 22925 |
ashik.ali |
885 |
throw new ProfitMandiBusinessException("cartData", cartJson, "FFORDR_1006");
|
| 22859 |
ashik.ali |
886 |
}
|
|
|
887 |
}
|
| 23650 |
amit.gupta |
888 |
|
| 23202 |
ashik.ali |
889 |
@Override
|
| 23650 |
amit.gupta |
890 |
public Map<String, Object> getSaleHistory(int fofoId, SearchType searchType, String searchValue,
|
| 23891 |
amit.gupta |
891 |
LocalDateTime startDate, LocalDateTime endDate, int offset, int limit) throws ProfitMandiBusinessException {
|
| 23202 |
ashik.ali |
892 |
long countItems = 0;
|
|
|
893 |
List<FofoOrder> fofoOrders = new ArrayList<>();
|
| 23650 |
amit.gupta |
894 |
|
|
|
895 |
if (searchType == SearchType.CUSTOMER_MOBILE_NUMBER && !searchValue.isEmpty()) {
|
| 23891 |
amit.gupta |
896 |
fofoOrders = fofoOrderRepository.selectByFofoIdAndCustomerMobileNumber(fofoId, searchValue, startDate,
|
|
|
897 |
endDate, offset, limit);
|
|
|
898 |
countItems = fofoOrderRepository.selectCountByCustomerMobileNumber(fofoId, searchValue, startDate,
|
|
|
899 |
endDate);
|
| 23650 |
amit.gupta |
900 |
} else if (searchType == SearchType.CUSTOMER_NAME && !searchValue.isEmpty()) {
|
| 23891 |
amit.gupta |
901 |
fofoOrders = fofoOrderRepository.selectByFofoIdAndCustomerName(fofoId, searchValue, startDate,
|
|
|
902 |
endDate, offset, limit);
|
|
|
903 |
countItems = fofoOrderRepository.selectCountByCustomerName(fofoId, searchValue, startDate, endDate);
|
| 23650 |
amit.gupta |
904 |
} else if (searchType == SearchType.IMEI && !searchValue.isEmpty()) {
|
| 23891 |
amit.gupta |
905 |
fofoOrders = fofoOrderRepository.selectByFofoIdAndSerialNumber(fofoId, searchValue, startDate,
|
|
|
906 |
endDate, offset, limit);
|
|
|
907 |
countItems = fofoOrderRepository.selectCountBySerialNumber(fofoId, searchValue, startDate, endDate);
|
| 23650 |
amit.gupta |
908 |
} else if (searchType == SearchType.ITEM_NAME && !searchValue.isEmpty()) {
|
| 23891 |
amit.gupta |
909 |
fofoOrders = fofoOrderRepository.selectByFofoIdAndItemName(fofoId, searchValue, startDate, endDate,
|
| 23650 |
amit.gupta |
910 |
offset, limit);
|
| 23891 |
amit.gupta |
911 |
countItems = fofoOrderRepository.selectCountByItemName(fofoId, searchValue, startDate, endDate);
|
| 23650 |
amit.gupta |
912 |
} else {
|
| 23891 |
amit.gupta |
913 |
fofoOrders = fofoOrderRepository.selectByFofoId(fofoId, startDate, endDate, offset, limit);
|
|
|
914 |
countItems = fofoOrderRepository.selectCountByFofoId(fofoId, startDate, endDate);
|
| 23202 |
ashik.ali |
915 |
}
|
|
|
916 |
Map<String, Object> map = new HashMap<>();
|
| 23650 |
amit.gupta |
917 |
|
| 23202 |
ashik.ali |
918 |
map.put("saleHistories", fofoOrders);
|
|
|
919 |
map.put("start", offset + 1);
|
|
|
920 |
map.put("size", countItems);
|
|
|
921 |
map.put("searchType", searchType);
|
| 23351 |
ashik.ali |
922 |
map.put("searchTypes", SearchType.values());
|
| 23891 |
amit.gupta |
923 |
map.put("startDate", startDate);
|
|
|
924 |
map.put(ProfitMandiConstants.END_TIME, endDate);
|
| 23650 |
amit.gupta |
925 |
if (fofoOrders.size() < limit) {
|
| 23202 |
ashik.ali |
926 |
map.put("end", offset + fofoOrders.size());
|
| 23650 |
amit.gupta |
927 |
} else {
|
| 23202 |
ashik.ali |
928 |
map.put("end", offset + limit);
|
|
|
929 |
}
|
|
|
930 |
return map;
|
|
|
931 |
}
|
|
|
932 |
|
|
|
933 |
@Override
|
| 23650 |
amit.gupta |
934 |
public Map<String, Object> getSaleHistoryPaginated(int fofoId, SearchType searchType, String searchValue,
|
| 23891 |
amit.gupta |
935 |
LocalDateTime startDate, LocalDateTime endDate, int offset, int limit) throws ProfitMandiBusinessException {
|
| 23202 |
ashik.ali |
936 |
List<FofoOrder> fofoOrders = new ArrayList<>();
|
| 23650 |
amit.gupta |
937 |
|
|
|
938 |
if (searchType == SearchType.CUSTOMER_MOBILE_NUMBER && !searchValue.isEmpty()) {
|
| 23891 |
amit.gupta |
939 |
fofoOrders = fofoOrderRepository.selectByFofoIdAndCustomerMobileNumber(fofoId, searchValue, startDate,
|
|
|
940 |
endDate, offset, limit);
|
| 23650 |
amit.gupta |
941 |
} else if (searchType == SearchType.CUSTOMER_NAME && !searchValue.isEmpty()) {
|
| 23891 |
amit.gupta |
942 |
fofoOrders = fofoOrderRepository.selectByFofoIdAndCustomerName(fofoId, searchValue, startDate,
|
|
|
943 |
endDate, offset, limit);
|
| 23650 |
amit.gupta |
944 |
} else if (searchType == SearchType.IMEI && !searchValue.isEmpty()) {
|
| 23891 |
amit.gupta |
945 |
fofoOrders = fofoOrderRepository.selectByFofoIdAndSerialNumber(fofoId, searchValue, startDate,
|
|
|
946 |
endDate, offset, limit);
|
| 23650 |
amit.gupta |
947 |
} else if (searchType == SearchType.ITEM_NAME && !searchValue.isEmpty()) {
|
| 23891 |
amit.gupta |
948 |
fofoOrders = fofoOrderRepository.selectByFofoIdAndItemName(fofoId, searchValue, startDate, endDate,
|
| 23650 |
amit.gupta |
949 |
offset, limit);
|
|
|
950 |
} else {
|
| 23891 |
amit.gupta |
951 |
fofoOrders = fofoOrderRepository.selectByFofoId(fofoId, startDate, endDate, offset, limit);
|
| 23202 |
ashik.ali |
952 |
}
|
|
|
953 |
Map<String, Object> map = new HashMap<>();
|
| 23650 |
amit.gupta |
954 |
|
| 23202 |
ashik.ali |
955 |
map.put("saleHistories", fofoOrders);
|
|
|
956 |
return map;
|
|
|
957 |
}
|
| 23650 |
amit.gupta |
958 |
|
|
|
959 |
private String getFofoStoreCode(int fofoId) throws ProfitMandiBusinessException {
|
| 23202 |
ashik.ali |
960 |
FofoStore fofoStore = fofoStoreRepository.selectByRetailerId(fofoId);
|
| 23370 |
ashik.ali |
961 |
return fofoStore.getCode();
|
| 23202 |
ashik.ali |
962 |
}
|
| 23650 |
amit.gupta |
963 |
|
|
|
964 |
private CustomerAddress createCustomerAddress(CustomAddress customAddress, int customerId) {
|
| 23191 |
ashik.ali |
965 |
CustomerAddress customerAddress = null;
|
| 23650 |
amit.gupta |
966 |
try {
|
|
|
967 |
// CustomAddress customAddress = customCustomer.getAddress();
|
|
|
968 |
customerAddress = customerAddressRepository.selectByParams(customAddress.getName(),
|
|
|
969 |
customAddress.getLine1(), customAddress.getLine2(), customAddress.getLandmark(),
|
|
|
970 |
customAddress.getCity(), customAddress.getPinCode(), customAddress.getState(),
|
|
|
971 |
customAddress.getPhoneNumber(), customAddress.getCountry(), customerId);
|
|
|
972 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
| 23596 |
ashik.ali |
973 |
LOGGER.warn("Customer address not found with [{}]", customAddress);
|
| 23191 |
ashik.ali |
974 |
customerAddress = new CustomerAddress();
|
|
|
975 |
this.setCustomerAddress(customerAddress, customAddress);
|
|
|
976 |
customerAddress.setCustomerId(customerId);
|
|
|
977 |
}
|
|
|
978 |
customerAddressRepository.persist(customerAddress);
|
|
|
979 |
return customerAddress;
|
|
|
980 |
}
|
| 23650 |
amit.gupta |
981 |
|
|
|
982 |
private String getValidName(String name) {
|
|
|
983 |
return name != null ? name : "";
|
| 22859 |
ashik.ali |
984 |
}
|
| 23650 |
amit.gupta |
985 |
|
|
|
986 |
private Set<String> toSerialNumbers(Set<FofoLineItem> fofoLineItems) {
|
| 23377 |
ashik.ali |
987 |
Set<String> serialNumbers = new HashSet<>();
|
| 23650 |
amit.gupta |
988 |
for (FofoLineItem fofoLineItem : fofoLineItems) {
|
|
|
989 |
if (fofoLineItem.getSerialNumber() != null && !fofoLineItem.getSerialNumber().isEmpty()) {
|
| 23377 |
ashik.ali |
990 |
serialNumbers.add(fofoLineItem.getSerialNumber());
|
| 22955 |
ashik.ali |
991 |
}
|
| 23377 |
ashik.ali |
992 |
}
|
|
|
993 |
return serialNumbers;
|
| 22859 |
ashik.ali |
994 |
}
|
| 23650 |
amit.gupta |
995 |
|
|
|
996 |
private PolicyNumberGenerationSequence createPolicyNumberGenerationSequence() {
|
| 22859 |
ashik.ali |
997 |
PolicyNumberGenerationSequence policyNumberGenerationSequence = null;
|
| 23650 |
amit.gupta |
998 |
try {
|
| 22859 |
ashik.ali |
999 |
policyNumberGenerationSequence = policyNumberGenerationSequenceRepository.select();
|
|
|
1000 |
policyNumberGenerationSequence.setSequence(policyNumberGenerationSequence.getSequence() + 1);
|
|
|
1001 |
policyNumberGenerationSequenceRepository.persist(policyNumberGenerationSequence);
|
| 23650 |
amit.gupta |
1002 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
| 22859 |
ashik.ali |
1003 |
policyNumberGenerationSequence = new PolicyNumberGenerationSequence();
|
|
|
1004 |
policyNumberGenerationSequence.setSequence(1);
|
|
|
1005 |
policyNumberGenerationSequenceRepository.persist(policyNumberGenerationSequence);
|
|
|
1006 |
}
|
|
|
1007 |
return policyNumberGenerationSequence;
|
|
|
1008 |
}
|
| 23650 |
amit.gupta |
1009 |
|
|
|
1010 |
private GadgetCopsInsuranceModel createGadgetCopsInsuranceModel(String brand, String modelName, String serialNumber,
|
|
|
1011 |
LocalDate customerDateOfBirth, Customer customer, CustomerAddress customerAddress,
|
|
|
1012 |
InsurancePolicy insurancePolicy) {
|
| 22859 |
ashik.ali |
1013 |
GadgetCopsInsuranceModel gadgetCopsInsuranceModel = new GadgetCopsInsuranceModel();
|
|
|
1014 |
gadgetCopsInsuranceModel.setBrand(brand);
|
|
|
1015 |
gadgetCopsInsuranceModel.setModelName(modelName);
|
|
|
1016 |
gadgetCopsInsuranceModel.setSerialNumber(serialNumber);
|
|
|
1017 |
gadgetCopsInsuranceModel.setCustomerFirstName(customer.getFirstName());
|
|
|
1018 |
gadgetCopsInsuranceModel.setCustomerLastName(customer.getLastName());
|
|
|
1019 |
gadgetCopsInsuranceModel.setCustomerDateOfBirth(customerDateOfBirth);
|
|
|
1020 |
gadgetCopsInsuranceModel.setCustomerMobileNumber(customer.getMobileNumber());
|
|
|
1021 |
gadgetCopsInsuranceModel.setCustomerEmailId(customer.getEmailId());
|
|
|
1022 |
gadgetCopsInsuranceModel.setCustomerAddress1(customerAddress.getLine1());
|
|
|
1023 |
gadgetCopsInsuranceModel.setCustomerAddress2(customerAddress.getLine2());
|
|
|
1024 |
gadgetCopsInsuranceModel.setCustomerCity(customerAddress.getCity());
|
|
|
1025 |
gadgetCopsInsuranceModel.setCustomerPinCode(customerAddress.getPinCode());
|
|
|
1026 |
gadgetCopsInsuranceModel.setCustomerState(customerAddress.getState());
|
|
|
1027 |
gadgetCopsInsuranceModel.setPrice(insurancePolicy.getSellingPrice());
|
|
|
1028 |
gadgetCopsInsuranceModel.setInvoiceNumber(insurancePolicy.getInvoiceNumber());
|
|
|
1029 |
gadgetCopsInsuranceModel.setPolicyNumber(insurancePolicy.getPolicyNumber());
|
|
|
1030 |
return gadgetCopsInsuranceModel;
|
|
|
1031 |
}
|
| 23650 |
amit.gupta |
1032 |
|
|
|
1033 |
private InsurancePolicy createInsurancePolicy(String invoiceNumber, int retailerId, float purchaseAmount,
|
|
|
1034 |
float saleAmount, float sellingPrice, String serialNumber, String modelName, String brand,
|
|
|
1035 |
int policyNumberGenerationSequence, int insuranceProviderId, Customer customer,
|
|
|
1036 |
LocalDate customerDateOfBirth, CustomerAddress customerAddress) {
|
| 22859 |
ashik.ali |
1037 |
InsurancePolicy insurancePolicy = new InsurancePolicy();
|
| 23394 |
amit.gupta |
1038 |
insurancePolicy.setInvoiceNumber(invoiceNumber);
|
| 22859 |
ashik.ali |
1039 |
insurancePolicy.setRetailerId(retailerId);
|
|
|
1040 |
insurancePolicy.setPurchaseAmount(purchaseAmount);
|
|
|
1041 |
insurancePolicy.setSaleAmount(saleAmount);
|
|
|
1042 |
insurancePolicy.setSellingPrice(sellingPrice);
|
|
|
1043 |
insurancePolicy.setSerialNumber(serialNumber);
|
|
|
1044 |
insurancePolicy.setModelName(modelName);
|
|
|
1045 |
insurancePolicy.setBrand(brand);
|
| 23650 |
amit.gupta |
1046 |
insurancePolicy.setPolicyNumber(StringUtils.generatePolicyNumber(ProfitMandiConstants.POLICY_NUMBER_PREFIX,
|
|
|
1047 |
policyNumberGenerationSequence));
|
| 22859 |
ashik.ali |
1048 |
insurancePolicy.setProviderId(insuranceProviderId);
|
|
|
1049 |
insurancePolicy.setCustomerFirstName(customer.getFirstName());
|
|
|
1050 |
insurancePolicy.setCustomerLastName(customer.getLastName());
|
|
|
1051 |
insurancePolicy.setCustomerMobileNumber(customer.getMobileNumber());
|
|
|
1052 |
insurancePolicy.setCustomerEmailId(customer.getEmailId());
|
|
|
1053 |
insurancePolicy.setCustomerDateOfBirth(customerDateOfBirth);
|
|
|
1054 |
insurancePolicy.setCustomerAddress1(customerAddress.getLine1());
|
|
|
1055 |
insurancePolicy.setCustomerAddress2(customerAddress.getLine2());
|
|
|
1056 |
insurancePolicy.setCustomerCity(customerAddress.getCity());
|
|
|
1057 |
insurancePolicy.setCustomerPinCode(customerAddress.getPinCode());
|
|
|
1058 |
insurancePolicy.setCustomerState(customerAddress.getState());
|
|
|
1059 |
return insurancePolicy;
|
|
|
1060 |
}
|
| 23650 |
amit.gupta |
1061 |
|
|
|
1062 |
private void validateInsuranceMargin(Map<String, Float> insuranceSerialNumberItemPrice,
|
|
|
1063 |
Map<Integer, CustomFofoOrderItem> itemIdCustomFofoOrderItemMap, Map<Integer, PriceModel> itemIdMopPriceMap,
|
|
|
1064 |
Map<Float, GadgetCopsInsuranceCalc> insurancePricesMap, Map<String, Float> insuranceSerialNumberSaleAmount)
|
|
|
1065 |
throws ProfitMandiBusinessException {
|
| 22859 |
ashik.ali |
1066 |
Map<Float, Float> invalidInsuranceMarginAmount = new HashMap<>();
|
| 23650 |
amit.gupta |
1067 |
for (Map.Entry<String, Float> entry : insuranceSerialNumberItemPrice.entrySet()) {
|
| 22872 |
ashik.ali |
1068 |
int itemId = this.getItemIdFromSerialNumber(itemIdCustomFofoOrderItemMap, entry.getKey());
|
| 22859 |
ashik.ali |
1069 |
float itemPurchasePrice = itemIdMopPriceMap.get(itemId).getPrice();
|
|
|
1070 |
float itemSellingPrice = entry.getValue();
|
|
|
1071 |
float itemMargin = itemSellingPrice - itemPurchasePrice;
|
|
|
1072 |
float insurancePurchasePrice = insurancePricesMap.get(entry.getValue()).getDealerPrice();
|
|
|
1073 |
float insuranceSellingPrice = insuranceSerialNumberSaleAmount.get(entry.getKey());
|
|
|
1074 |
float insuranceMargin = insuranceSellingPrice - insurancePurchasePrice;
|
| 23650 |
amit.gupta |
1075 |
if (insuranceMargin < (itemMargin * 30 / 100)) {
|
| 22859 |
ashik.ali |
1076 |
invalidInsuranceMarginAmount.put(insuranceMargin, (itemMargin * 30 / 100));
|
|
|
1077 |
}
|
|
|
1078 |
}
|
| 23650 |
amit.gupta |
1079 |
if (!invalidInsuranceMarginAmount.isEmpty()) {
|
|
|
1080 |
LOGGER.error(
|
|
|
1081 |
"insurance marging should be greater than equal to item profit margin insuranceMarginItemIdMargin {}",
|
|
|
1082 |
invalidInsuranceMarginAmount);
|
|
|
1083 |
throw new ProfitMandiBusinessException("invalidInsuranceMarginAmount", invalidInsuranceMarginAmount,
|
|
|
1084 |
"FFORDR_1007");
|
| 22859 |
ashik.ali |
1085 |
}
|
|
|
1086 |
}
|
| 23650 |
amit.gupta |
1087 |
|
|
|
1088 |
private void validateInsuranceAmount(Map<String, Float> insuranceSerialNumberItemPrice,
|
|
|
1089 |
Map<String, Float> insuranceSerialNumberSaleAmount, Map<Float, GadgetCopsInsuranceCalc> insurancePricesMap)
|
|
|
1090 |
throws ProfitMandiBusinessException {
|
| 22859 |
ashik.ali |
1091 |
Map<Float, Float> invalidInsurancePurchaseSaleAmount = new HashMap<>();
|
|
|
1092 |
Map<Float, Float> invalidInsuranceSalePurchaseAmount = new HashMap<>();
|
| 23650 |
amit.gupta |
1093 |
for (Map.Entry<String, Float> entry : insuranceSerialNumberItemPrice.entrySet()) {
|
|
|
1094 |
if (insuranceSerialNumberSaleAmount.get(entry.getKey()) < insurancePricesMap.get(entry.getValue())
|
|
|
1095 |
.getDealerPrice()) {
|
|
|
1096 |
invalidInsurancePurchaseSaleAmount.put(insurancePricesMap.get(entry.getValue()).getDealerPrice(),
|
|
|
1097 |
insuranceSerialNumberSaleAmount.get(entry.getKey()));
|
| 22859 |
ashik.ali |
1098 |
}
|
| 23650 |
amit.gupta |
1099 |
|
|
|
1100 |
if (insuranceSerialNumberSaleAmount.get(entry.getKey()) > insurancePricesMap.get(entry.getValue())
|
|
|
1101 |
.getSellingPrice()) {
|
|
|
1102 |
invalidInsuranceSalePurchaseAmount.put(insuranceSerialNumberSaleAmount.get(entry.getKey()),
|
|
|
1103 |
insurancePricesMap.get(entry.getValue()).getDealerPrice());
|
| 22859 |
ashik.ali |
1104 |
}
|
|
|
1105 |
}
|
| 23650 |
amit.gupta |
1106 |
|
| 22859 |
ashik.ali |
1107 |
// insurance sale amount can not be lesser than insurance purchase amount
|
| 23650 |
amit.gupta |
1108 |
if (!invalidInsurancePurchaseSaleAmount.isEmpty()) {
|
|
|
1109 |
LOGGER.error(
|
|
|
1110 |
"Invalid Insurance prices [{}], insurance sale amount can not be lesser than insurance purchase amount",
|
|
|
1111 |
invalidInsurancePurchaseSaleAmount);
|
|
|
1112 |
throw new ProfitMandiBusinessException("invalidInsurancePurchaseSaleAmount",
|
|
|
1113 |
invalidInsurancePurchaseSaleAmount, "FFORDR_1008");
|
| 22859 |
ashik.ali |
1114 |
}
|
| 23650 |
amit.gupta |
1115 |
|
|
|
1116 |
if (!invalidInsuranceSalePurchaseAmount.isEmpty()) {
|
|
|
1117 |
LOGGER.error(
|
|
|
1118 |
"Invalid Insurance prices [{}], insurance sale amount can not be greater than than insurance max amount",
|
|
|
1119 |
invalidInsuranceSalePurchaseAmount);
|
|
|
1120 |
throw new ProfitMandiBusinessException("invalidInsuranceSalePurchaseAmount",
|
|
|
1121 |
invalidInsuranceSalePurchaseAmount, "FFORDR_1009");
|
| 22859 |
ashik.ali |
1122 |
}
|
|
|
1123 |
}
|
| 23823 |
amit.gupta |
1124 |
private void validateDpPrice(Map<Integer, PriceModel> itemIdMopPriceMap,
|
|
|
1125 |
Map<Integer, CustomFofoOrderItem> itemIdCustomFofoLineItemMap) throws ProfitMandiBusinessException {
|
|
|
1126 |
for (Map.Entry<Integer, CustomFofoOrderItem> entry : itemIdCustomFofoLineItemMap.entrySet()) {
|
|
|
1127 |
int itemId = entry.getKey();
|
|
|
1128 |
CustomFofoOrderItem customFofoOrderItem = entry.getValue();
|
|
|
1129 |
PriceModel priceModel = itemIdMopPriceMap.get(itemId);
|
|
|
1130 |
if(customFofoOrderItem.getSerialNumberDetails().size() > 0) {
|
| 23857 |
amit.gupta |
1131 |
if(priceModel.getPrice() > customFofoOrderItem.getSellingPrice()) {
|
| 23823 |
amit.gupta |
1132 |
throw new ProfitMandiBusinessException("Selling Price", itemRepository.selectById(itemId).getItemDescription(), "FFORDR_1010");
|
|
|
1133 |
}
|
|
|
1134 |
} else {
|
| 23857 |
amit.gupta |
1135 |
if(priceModel.getPurchasePrice() > customFofoOrderItem.getSellingPrice()) {
|
| 23823 |
amit.gupta |
1136 |
throw new ProfitMandiBusinessException("Selling Price", itemRepository.selectById(itemId).getItemDescription(), "Selling Price should not be less than DP");
|
|
|
1137 |
}
|
|
|
1138 |
}
|
|
|
1139 |
}
|
|
|
1140 |
}
|
| 23650 |
amit.gupta |
1141 |
private void validateMopPrice(Map<Integer, PriceModel> itemIdMopPriceMap,
|
|
|
1142 |
Map<Integer, CustomFofoOrderItem> itemIdCustomFofoLineItemMap) throws ProfitMandiBusinessException {
|
| 22859 |
ashik.ali |
1143 |
Map<Integer, Float> invalidMopItemIdPriceMap = new HashMap<>();
|
|
|
1144 |
Map<Integer, Float> invalidDiscountAmountMap = new HashMap<>();
|
| 23650 |
amit.gupta |
1145 |
for (Map.Entry<Integer, PriceModel> entry : itemIdMopPriceMap.entrySet()) {
|
| 22872 |
ashik.ali |
1146 |
CustomFofoOrderItem customFofoOrderItem = itemIdCustomFofoLineItemMap.get(entry.getKey());
|
| 23650 |
amit.gupta |
1147 |
if (entry.getValue().getPrice() < Float.MAX_VALUE
|
|
|
1148 |
&& customFofoOrderItem.getSellingPrice() < entry.getValue().getPrice()) {
|
| 22872 |
ashik.ali |
1149 |
invalidMopItemIdPriceMap.put(entry.getKey(), customFofoOrderItem.getSellingPrice());
|
| 22859 |
ashik.ali |
1150 |
}
|
| 23650 |
amit.gupta |
1151 |
if (entry.getValue().isMop()
|
|
|
1152 |
&& customFofoOrderItem.getDiscountAmount() > entry.getValue().getMaxDiscountAmount()) {
|
| 22872 |
ashik.ali |
1153 |
invalidDiscountAmountMap.put(entry.getKey(), customFofoOrderItem.getDiscountAmount());
|
|
|
1154 |
}
|
| 22859 |
ashik.ali |
1155 |
}
|
| 23650 |
amit.gupta |
1156 |
|
|
|
1157 |
if (!invalidMopItemIdPriceMap.isEmpty()) {
|
|
|
1158 |
LOGGER.error("Invalid itemIds selling prices{} should be greater than mop prices {}",
|
|
|
1159 |
invalidMopItemIdPriceMap, itemIdMopPriceMap);
|
| 22925 |
ashik.ali |
1160 |
throw new ProfitMandiBusinessException("invalidMopItemIdPrice", invalidMopItemIdPriceMap, "FFORDR_1010");
|
| 22859 |
ashik.ali |
1161 |
}
|
| 23650 |
amit.gupta |
1162 |
|
| 23857 |
amit.gupta |
1163 |
if (!invalidDiscountAmountMap.isEmpty()) {
|
| 23650 |
amit.gupta |
1164 |
LOGGER.error("Invalid itemIds discount amounts {} should be less than maxDiscount prices {}",
|
|
|
1165 |
invalidDiscountAmountMap, itemIdMopPriceMap);
|
| 22925 |
ashik.ali |
1166 |
throw new ProfitMandiBusinessException("invalidMopItemIdPrice", invalidDiscountAmountMap, "FFORDR_1011");
|
| 22859 |
ashik.ali |
1167 |
}
|
|
|
1168 |
}
|
| 23650 |
amit.gupta |
1169 |
|
|
|
1170 |
private LocalDate validateCustomerDateOfBirth(String customerDateOfBirthString)
|
|
|
1171 |
throws ProfitMandiBusinessException {
|
| 22859 |
ashik.ali |
1172 |
LocalDate customerDateOfBirth = null;
|
| 23650 |
amit.gupta |
1173 |
try {
|
| 22859 |
ashik.ali |
1174 |
customerDateOfBirth = StringUtils.toDate(customerDateOfBirthString);
|
| 23650 |
amit.gupta |
1175 |
} catch (DateTimeException dateTimeException) {
|
| 23596 |
ashik.ali |
1176 |
LOGGER.error("Unable to parse dateOfBirth message {}", dateTimeException.getMessage());
|
| 22925 |
ashik.ali |
1177 |
throw new ProfitMandiBusinessException("dateOfBirth", customerDateOfBirthString, "FFORDR_1012");
|
| 22859 |
ashik.ali |
1178 |
}
|
|
|
1179 |
return customerDateOfBirth;
|
|
|
1180 |
}
|
| 23650 |
amit.gupta |
1181 |
|
|
|
1182 |
private void updateInventoryItemsAndScanRecord(Set<InventoryItem> inventoryItems, int fofoId,
|
|
|
1183 |
Map<Integer, Integer> inventoryItemQuantityUsed) {
|
|
|
1184 |
for (InventoryItem inventoryItem : inventoryItems) {
|
| 22859 |
ashik.ali |
1185 |
inventoryItem.setLastScanType(ScanType.SALE);
|
|
|
1186 |
inventoryItemRepository.persist(inventoryItem);
|
|
|
1187 |
ScanRecord scanRecord = new ScanRecord();
|
|
|
1188 |
scanRecord.setInventoryItemId(inventoryItem.getId());
|
|
|
1189 |
scanRecord.setFofoId(fofoId);
|
| 23650 |
amit.gupta |
1190 |
// correct this
|
| 22859 |
ashik.ali |
1191 |
scanRecord.setQuantity(inventoryItemQuantityUsed.get(inventoryItem.getId()));
|
|
|
1192 |
scanRecord.setType(ScanType.SALE);
|
|
|
1193 |
scanRecordRepository.persist(scanRecord);
|
| 23566 |
amit.gupta |
1194 |
purchaseReturnItemRepository.deleteById(inventoryItem.getId());
|
| 23650 |
amit.gupta |
1195 |
|
| 22859 |
ashik.ali |
1196 |
}
|
|
|
1197 |
}
|
| 23650 |
amit.gupta |
1198 |
|
|
|
1199 |
private void createFofoLineItem(int fofoOrderItemId, Set<InventoryItem> inventoryItems,
|
|
|
1200 |
Map<Integer, Integer> inventoryItemIdQuantityUsed) {
|
|
|
1201 |
for (InventoryItem inventoryItem : inventoryItems) {
|
| 22859 |
ashik.ali |
1202 |
FofoLineItem fofoLineItem = new FofoLineItem();
|
|
|
1203 |
fofoLineItem.setFofoOrderItemId(fofoOrderItemId);
|
|
|
1204 |
fofoLineItem.setSerialNumber(inventoryItem.getSerialNumber());
|
|
|
1205 |
fofoLineItem.setInventoryItemId(inventoryItem.getId());
|
|
|
1206 |
fofoLineItem.setQuantity(inventoryItemIdQuantityUsed.get(inventoryItem.getId()));
|
|
|
1207 |
fofoLineItemRepository.persist(fofoLineItem);
|
|
|
1208 |
}
|
|
|
1209 |
}
|
| 23650 |
amit.gupta |
1210 |
|
|
|
1211 |
private FofoOrderItem createAndGetFofoOrderItem(CustomFofoOrderItem customFofoOrderItem, int fofoOrderId,
|
|
|
1212 |
Map<Integer, Item> itemMap, Set<InventoryItem> inventoryItems, Integer stateId)
|
|
|
1213 |
throws ProfitMandiBusinessException {
|
| 22859 |
ashik.ali |
1214 |
FofoOrderItem fofoOrderItem = new FofoOrderItem();
|
|
|
1215 |
fofoOrderItem.setItemId(customFofoOrderItem.getItemId());
|
|
|
1216 |
fofoOrderItem.setQuantity(customFofoOrderItem.getQuantity());
|
|
|
1217 |
fofoOrderItem.setSellingPrice(customFofoOrderItem.getSellingPrice());
|
|
|
1218 |
fofoOrderItem.setOrderId(fofoOrderId);
|
|
|
1219 |
fofoOrderItem.setDp(customFofoOrderItem.getSellingPrice());
|
|
|
1220 |
fofoOrderItem.setDiscount(customFofoOrderItem.getDiscountAmount());
|
|
|
1221 |
Item item = itemMap.get(customFofoOrderItem.getItemId());
|
| 23172 |
ashik.ali |
1222 |
Map<Integer, GstRate> itemIdStateTaxRateMap = null;
|
|
|
1223 |
Map<Integer, Float> itemIdIgstTaxRateMap = null;
|
| 23650 |
amit.gupta |
1224 |
if (stateId != null) {
|
| 23172 |
ashik.ali |
1225 |
itemIdStateTaxRateMap = Utils.getStateTaxRate(new ArrayList<>(itemMap.keySet()), stateId);
|
| 23650 |
amit.gupta |
1226 |
} else {
|
| 23172 |
ashik.ali |
1227 |
itemIdIgstTaxRateMap = Utils.getIgstTaxRate(new ArrayList<>(itemMap.keySet()));
|
|
|
1228 |
}
|
| 23393 |
amit.gupta |
1229 |
float cost = 0;
|
| 23650 |
amit.gupta |
1230 |
for (InventoryItem inventoryItem : inventoryItems) {
|
|
|
1231 |
if (stateId == null) {
|
| 23172 |
ashik.ali |
1232 |
fofoOrderItem.setIgstRate(itemIdIgstTaxRateMap.get(inventoryItem.getItemId()));
|
| 23650 |
amit.gupta |
1233 |
} else {
|
| 23172 |
ashik.ali |
1234 |
fofoOrderItem.setCgstRate(itemIdStateTaxRateMap.get(inventoryItem.getItemId()).getCgstRate());
|
|
|
1235 |
fofoOrderItem.setSgstRate(itemIdStateTaxRateMap.get(inventoryItem.getItemId()).getSgstRate());
|
|
|
1236 |
}
|
| 23650 |
amit.gupta |
1237 |
|
| 22859 |
ashik.ali |
1238 |
fofoOrderItem.setHsnCode(inventoryItem.getHsnCode());
|
|
|
1239 |
break;
|
|
|
1240 |
}
|
| 23650 |
amit.gupta |
1241 |
for (InventoryItem inventoryItem : inventoryItems) {
|
|
|
1242 |
if (inventoryItem.getSerialNumber() != null) {
|
| 23393 |
amit.gupta |
1243 |
cost += inventoryItem.getUnitPrice() - inventoryItem.getPriceDropAmount();
|
|
|
1244 |
} else {
|
|
|
1245 |
cost += inventoryItem.getUnitPrice();
|
| 23382 |
amit.gupta |
1246 |
}
|
|
|
1247 |
}
|
| 23650 |
amit.gupta |
1248 |
cost = cost / customFofoOrderItem.getQuantity();
|
| 23382 |
amit.gupta |
1249 |
fofoOrderItem.setCost(cost);
|
| 22859 |
ashik.ali |
1250 |
fofoOrderItem.setBrand(item.getBrand());
|
|
|
1251 |
fofoOrderItem.setModelName(item.getModelName());
|
|
|
1252 |
fofoOrderItem.setModelNumber(item.getModelNumber());
|
|
|
1253 |
fofoOrderItem.setColor(item.getColor());
|
|
|
1254 |
fofoOrderItemRepository.persist(fofoOrderItem);
|
|
|
1255 |
return fofoOrderItem;
|
|
|
1256 |
}
|
| 23650 |
amit.gupta |
1257 |
|
|
|
1258 |
private void updateCurrentInventorySnapshot(List<CurrentInventorySnapshot> currentInventorySnapshots, int fofoId,
|
|
|
1259 |
int itemId, int quantity) throws ProfitMandiBusinessException {
|
|
|
1260 |
for (CurrentInventorySnapshot currentInventorySnapshot : currentInventorySnapshots) {
|
|
|
1261 |
if (currentInventorySnapshot.getItemId() == itemId && currentInventorySnapshot.getFofoId() == fofoId) {
|
|
|
1262 |
currentInventorySnapshotRepository.updateAvailabilityByItemIdAndFofoId(itemId, fofoId,
|
|
|
1263 |
currentInventorySnapshot.getAvailability() - quantity);
|
| 22859 |
ashik.ali |
1264 |
}
|
|
|
1265 |
}
|
|
|
1266 |
}
|
| 23650 |
amit.gupta |
1267 |
|
|
|
1268 |
private void createPaymentOptions(FofoOrder fofoOrder, Set<CustomPaymentOption> customPaymentOptions)
|
|
|
1269 |
throws ProfitMandiBusinessException {
|
|
|
1270 |
for (CustomPaymentOption customPaymentOption : customPaymentOptions) {
|
|
|
1271 |
if (customPaymentOption.getAmount() > 0) {
|
| 23546 |
ashik.ali |
1272 |
PaymentOptionTransaction paymentOptionTransaction = new PaymentOptionTransaction();
|
| 23612 |
amit.gupta |
1273 |
paymentOptionTransaction.setReferenceId(fofoOrder.getId());
|
| 23546 |
ashik.ali |
1274 |
paymentOptionTransaction.setPaymentOptionId(customPaymentOption.getPaymentOptionId());
|
|
|
1275 |
paymentOptionTransaction.setReferenceType(PaymentOptionReferenceType.ORDER);
|
|
|
1276 |
paymentOptionTransaction.setAmount(customPaymentOption.getAmount());
|
| 23612 |
amit.gupta |
1277 |
paymentOptionTransaction.setFofoId(fofoOrder.getFofoId());
|
| 23546 |
ashik.ali |
1278 |
paymentOptionTransactionRepository.persist(paymentOptionTransaction);
|
| 23371 |
ashik.ali |
1279 |
}
|
| 22859 |
ashik.ali |
1280 |
}
|
|
|
1281 |
}
|
| 23650 |
amit.gupta |
1282 |
|
|
|
1283 |
private FofoOrder createAndGetFofoOrder(int customerId, String customerGstNumber, int fofoId,
|
|
|
1284 |
InvoiceNumberGenerationSequence invoiceNumberGenerationSequence, float totalAmount, int customerAddressId) {
|
| 22859 |
ashik.ali |
1285 |
FofoOrder fofoOrder = new FofoOrder();
|
| 23369 |
ashik.ali |
1286 |
fofoOrder.setCustomerGstNumber(customerGstNumber);
|
| 22859 |
ashik.ali |
1287 |
fofoOrder.setCustomerId(customerId);
|
|
|
1288 |
fofoOrder.setFofoId(fofoId);
|
| 23650 |
amit.gupta |
1289 |
fofoOrder.setInvoiceNumber(
|
|
|
1290 |
invoiceNumberGenerationSequence.getPrefix() + "/" + invoiceNumberGenerationSequence.getSequence());
|
| 22859 |
ashik.ali |
1291 |
fofoOrder.setTotalAmount(totalAmount);
|
|
|
1292 |
fofoOrder.setCustomerAddressId(customerAddressId);
|
|
|
1293 |
fofoOrderRepository.persist(fofoOrder);
|
|
|
1294 |
return fofoOrder;
|
|
|
1295 |
}
|
| 23650 |
amit.gupta |
1296 |
|
|
|
1297 |
private Customer createAndGetCustomer(CustomCustomer customCustomer) throws ProfitMandiBusinessException {
|
| 22859 |
ashik.ali |
1298 |
Customer customer = null;
|
| 23650 |
amit.gupta |
1299 |
try {
|
| 22859 |
ashik.ali |
1300 |
customer = customerRepository.selectByMobileNumber(customCustomer.getMobileNumber());
|
| 23650 |
amit.gupta |
1301 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
| 23596 |
ashik.ali |
1302 |
LOGGER.error("Customer not found with mobileNumber [{}]", customCustomer.getMobileNumber());
|
| 22859 |
ashik.ali |
1303 |
customer = new Customer();
|
|
|
1304 |
}
|
| 23190 |
ashik.ali |
1305 |
customer.setFirstName(customCustomer.getFirstName());
|
|
|
1306 |
customer.setLastName(customCustomer.getLastName());
|
|
|
1307 |
customer.setEmailId(customCustomer.getEmailId());
|
|
|
1308 |
customer.setMobileNumber(customCustomer.getMobileNumber());
|
|
|
1309 |
customerRepository.persist(customer);
|
| 22859 |
ashik.ali |
1310 |
return customer;
|
|
|
1311 |
}
|
| 23650 |
amit.gupta |
1312 |
|
|
|
1313 |
private InvoiceNumberGenerationSequence createAndGetInvoiceNumberGenerationSequence(int fofoId,
|
|
|
1314 |
String fofoStoreCode) {
|
| 22859 |
ashik.ali |
1315 |
InvoiceNumberGenerationSequence invoiceNumberGenerationSequence = null;
|
| 23650 |
amit.gupta |
1316 |
try {
|
| 22859 |
ashik.ali |
1317 |
invoiceNumberGenerationSequence = invoiceNumberGenerationSequenceRepository.selectByFofoId(fofoId);
|
|
|
1318 |
invoiceNumberGenerationSequence.setSequence(invoiceNumberGenerationSequence.getSequence() + 1);
|
| 23650 |
amit.gupta |
1319 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
| 22859 |
ashik.ali |
1320 |
invoiceNumberGenerationSequence = new InvoiceNumberGenerationSequence();
|
|
|
1321 |
invoiceNumberGenerationSequence.setFofoId(fofoId);
|
| 23370 |
ashik.ali |
1322 |
invoiceNumberGenerationSequence.setPrefix(fofoStoreCode);
|
| 22859 |
ashik.ali |
1323 |
invoiceNumberGenerationSequence.setSequence(1);
|
|
|
1324 |
}
|
|
|
1325 |
invoiceNumberGenerationSequenceRepository.persist(invoiceNumberGenerationSequence);
|
|
|
1326 |
return invoiceNumberGenerationSequence;
|
|
|
1327 |
}
|
| 23650 |
amit.gupta |
1328 |
|
|
|
1329 |
private void validateItemsSerializedNonSerialized(List<Item> items,
|
|
|
1330 |
Map<Integer, CustomFofoOrderItem> customFofoOrderItemMap) throws ProfitMandiBusinessException {
|
|
|
1331 |
List<Integer> invalidItemIdSerialNumbers = new ArrayList<Integer>();
|
| 22859 |
ashik.ali |
1332 |
List<Integer> itemIdNonSerializedSerialNumbers = new ArrayList<Integer>();
|
| 23650 |
amit.gupta |
1333 |
for (Item i : items) {
|
| 22872 |
ashik.ali |
1334 |
CustomFofoOrderItem customFofoOrderItem = customFofoOrderItemMap.get(i.getId());
|
| 23650 |
amit.gupta |
1335 |
if (i.getType().equals(ItemType.SERIALIZED)) {
|
|
|
1336 |
if (customFofoOrderItem == null || customFofoOrderItem.getSerialNumberDetails().isEmpty()) {
|
| 22872 |
ashik.ali |
1337 |
invalidItemIdSerialNumbers.add(i.getId());
|
| 22859 |
ashik.ali |
1338 |
}
|
| 23650 |
amit.gupta |
1339 |
} else {
|
|
|
1340 |
Set<String> serialNumbers = this
|
|
|
1341 |
.serialNumberDetailsToSerialNumbers(customFofoOrderItem.getSerialNumberDetails());
|
|
|
1342 |
if (customFofoOrderItem == null || !serialNumbers.isEmpty()) {
|
| 22872 |
ashik.ali |
1343 |
itemIdNonSerializedSerialNumbers.add(i.getId());
|
| 22859 |
ashik.ali |
1344 |
}
|
|
|
1345 |
}
|
|
|
1346 |
}
|
|
|
1347 |
|
| 23650 |
amit.gupta |
1348 |
if (!invalidItemIdSerialNumbers.isEmpty()) {
|
| 22859 |
ashik.ali |
1349 |
LOGGER.error("Invalid itemId's serialNumbers for serialized{}", invalidItemIdSerialNumbers);
|
|
|
1350 |
// itemId's are serialized you are saying these are not serialized
|
| 23650 |
amit.gupta |
1351 |
throw new ProfitMandiBusinessException("invalidItemIdSerialNumbers", invalidItemIdSerialNumbers,
|
|
|
1352 |
"FFORDR_1013");
|
| 22859 |
ashik.ali |
1353 |
}
|
|
|
1354 |
|
| 23650 |
amit.gupta |
1355 |
if (!itemIdNonSerializedSerialNumbers.isEmpty()) {
|
| 22859 |
ashik.ali |
1356 |
LOGGER.error("Invalid itemId's serialNumbers for non serialized{}", itemIdNonSerializedSerialNumbers);
|
|
|
1357 |
// itemId's are non serialized you are saying these are serialized
|
| 23650 |
amit.gupta |
1358 |
throw new ProfitMandiBusinessException("itemIdNonSerializedSerialNumbers", itemIdNonSerializedSerialNumbers,
|
|
|
1359 |
"FFORDR_1014");
|
| 22859 |
ashik.ali |
1360 |
}
|
|
|
1361 |
}
|
| 23650 |
amit.gupta |
1362 |
|
|
|
1363 |
private void validateCurrentInventorySnapshotQuantities(List<CurrentInventorySnapshot> currentInventorySnapshots,
|
|
|
1364 |
Map<Integer, CustomFofoOrderItem> itemIdCustomFofoOrderItemMap) throws ProfitMandiBusinessException {
|
|
|
1365 |
if (itemIdCustomFofoOrderItemMap.keySet().size() != currentInventorySnapshots.size()) {
|
| 22859 |
ashik.ali |
1366 |
throw new ProfitMandiBusinessException("quantiiesSize", currentInventorySnapshots.size(), "");
|
|
|
1367 |
}
|
| 23650 |
amit.gupta |
1368 |
List<ItemIdQuantityAvailability> itemIdQuantityAvailabilities = new ArrayList<>(); // this is for error
|
|
|
1369 |
LOGGER.info("currentInventorySnapshots " + currentInventorySnapshots);
|
| 22872 |
ashik.ali |
1370 |
LOGGER.info("CustomFofoLineItemMap {}", itemIdCustomFofoOrderItemMap);
|
| 23650 |
amit.gupta |
1371 |
for (CurrentInventorySnapshot currentInventorySnapshot : currentInventorySnapshots) {
|
|
|
1372 |
CustomFofoOrderItem customFofoOrderItem = itemIdCustomFofoOrderItemMap
|
|
|
1373 |
.get(currentInventorySnapshot.getItemId());
|
| 22872 |
ashik.ali |
1374 |
LOGGER.info("customFofoOrderItem {}", customFofoOrderItem);
|
| 23650 |
amit.gupta |
1375 |
if (customFofoOrderItem.getQuantity() > currentInventorySnapshot.getAvailability()) {
|
|
|
1376 |
ItemIdQuantityAvailability itemIdQuantityAvailability = new ItemIdQuantityAvailability();
|
|
|
1377 |
itemIdQuantityAvailability.setItemId(customFofoOrderItem.getItemId());
|
|
|
1378 |
Quantity quantity = new Quantity();
|
|
|
1379 |
quantity.setAvailable(currentInventorySnapshot.getAvailability());
|
|
|
1380 |
quantity.setRequested(customFofoOrderItem.getQuantity());
|
|
|
1381 |
itemIdQuantityAvailability.setQuantity(quantity);
|
|
|
1382 |
itemIdQuantityAvailabilities.add(itemIdQuantityAvailability);
|
|
|
1383 |
}
|
| 22859 |
ashik.ali |
1384 |
}
|
|
|
1385 |
|
| 23650 |
amit.gupta |
1386 |
if (!itemIdQuantityAvailabilities.isEmpty()) {
|
| 22859 |
ashik.ali |
1387 |
// itemIdQuantity request is not valid
|
| 23650 |
amit.gupta |
1388 |
LOGGER.error("Requested quantities should not be greater than currently available quantities {}",
|
|
|
1389 |
itemIdQuantityAvailabilities);
|
|
|
1390 |
throw new ProfitMandiBusinessException("itemIdQuantityAvailabilities", itemIdQuantityAvailabilities,
|
|
|
1391 |
"FFORDR_1015");
|
| 22859 |
ashik.ali |
1392 |
}
|
|
|
1393 |
}
|
| 23650 |
amit.gupta |
1394 |
|
|
|
1395 |
private int getItemIdFromSerialNumber(Map<Integer, CustomFofoOrderItem> itemIdCustomFofoOrderItemMap,
|
|
|
1396 |
String serialNumber) {
|
| 22872 |
ashik.ali |
1397 |
int itemId = 0;
|
| 23650 |
amit.gupta |
1398 |
for (Map.Entry<Integer, CustomFofoOrderItem> entry : itemIdCustomFofoOrderItemMap.entrySet()) {
|
| 22872 |
ashik.ali |
1399 |
Set<SerialNumberDetail> serialNumberDetails = entry.getValue().getSerialNumberDetails();
|
| 23650 |
amit.gupta |
1400 |
for (SerialNumberDetail serialNumberDetail : serialNumberDetails) {
|
|
|
1401 |
if (serialNumberDetail.getSerialNumber().equals(serialNumber)) {
|
| 22872 |
ashik.ali |
1402 |
itemId = entry.getKey();
|
|
|
1403 |
break;
|
|
|
1404 |
}
|
| 22859 |
ashik.ali |
1405 |
}
|
|
|
1406 |
}
|
| 22872 |
ashik.ali |
1407 |
return itemId;
|
| 22859 |
ashik.ali |
1408 |
}
|
| 23650 |
amit.gupta |
1409 |
|
|
|
1410 |
private Map<Integer, Item> toItemMap(List<Item> items) {
|
| 22955 |
ashik.ali |
1411 |
Function<Item, Integer> itemIdFunction = new Function<Item, Integer>() {
|
|
|
1412 |
@Override
|
|
|
1413 |
public Integer apply(Item item) {
|
|
|
1414 |
return item.getId();
|
|
|
1415 |
}
|
|
|
1416 |
};
|
|
|
1417 |
Function<Item, Item> itemFunction = new Function<Item, Item>() {
|
|
|
1418 |
@Override
|
|
|
1419 |
public Item apply(Item item) {
|
|
|
1420 |
return item;
|
|
|
1421 |
}
|
|
|
1422 |
};
|
|
|
1423 |
return items.stream().collect(Collectors.toMap(itemIdFunction, itemFunction));
|
| 22859 |
ashik.ali |
1424 |
}
|
|
|
1425 |
|
| 23650 |
amit.gupta |
1426 |
private void setCustomerAddress(CustomerAddress customerAddress, CustomAddress customAddress) {
|
| 22859 |
ashik.ali |
1427 |
customerAddress.setName(customAddress.getName());
|
|
|
1428 |
customerAddress.setLine1(customAddress.getLine1());
|
|
|
1429 |
customerAddress.setLine2(customAddress.getLine2());
|
|
|
1430 |
customerAddress.setLandmark(customAddress.getLandmark());
|
|
|
1431 |
customerAddress.setCity(customAddress.getCity());
|
|
|
1432 |
customerAddress.setPinCode(customAddress.getPinCode());
|
|
|
1433 |
customerAddress.setState(customAddress.getState());
|
|
|
1434 |
customerAddress.setCountry(customAddress.getCountry());
|
|
|
1435 |
customerAddress.setPhoneNumber(customAddress.getPhoneNumber());
|
|
|
1436 |
}
|
|
|
1437 |
|
| 23650 |
amit.gupta |
1438 |
private CustomAddress createCustomAddress(Address address) {
|
| 22859 |
ashik.ali |
1439 |
CustomAddress customAddress = new CustomAddress();
|
|
|
1440 |
customAddress.setName(address.getName());
|
|
|
1441 |
customAddress.setLine1(address.getLine1());
|
|
|
1442 |
customAddress.setLine2(address.getLine2());
|
|
|
1443 |
customAddress.setLandmark(address.getLandmark());
|
|
|
1444 |
customAddress.setCity(address.getCity());
|
|
|
1445 |
customAddress.setPinCode(address.getPinCode());
|
|
|
1446 |
customAddress.setState(address.getState());
|
|
|
1447 |
customAddress.setCountry(address.getCountry());
|
|
|
1448 |
customAddress.setPhoneNumber(address.getPhoneNumber());
|
|
|
1449 |
return customAddress;
|
|
|
1450 |
}
|
|
|
1451 |
|
| 23650 |
amit.gupta |
1452 |
private CustomAddress createCustomAddress(CustomerAddress customerAddress) {
|
| 22859 |
ashik.ali |
1453 |
CustomAddress customAddress = new CustomAddress();
|
|
|
1454 |
customAddress.setName(customerAddress.getName());
|
|
|
1455 |
customAddress.setLine1(customerAddress.getLine1());
|
|
|
1456 |
customAddress.setLine2(customerAddress.getLine2());
|
|
|
1457 |
customAddress.setLandmark(customerAddress.getLandmark());
|
|
|
1458 |
customAddress.setCity(customerAddress.getCity());
|
|
|
1459 |
customAddress.setPinCode(customerAddress.getPinCode());
|
|
|
1460 |
customAddress.setState(customerAddress.getState());
|
|
|
1461 |
customAddress.setCountry(customerAddress.getCountry());
|
|
|
1462 |
customAddress.setPhoneNumber(customerAddress.getPhoneNumber());
|
|
|
1463 |
return customAddress;
|
|
|
1464 |
}
|
|
|
1465 |
|
| 23650 |
amit.gupta |
1466 |
private void validatePaymentOptionsAndTotalAmount(Set<CustomPaymentOption> customPaymentOptions, float totalAmount)
|
|
|
1467 |
throws ProfitMandiBusinessException {
|
| 23365 |
ashik.ali |
1468 |
Set<Integer> paymentOptionIds = new HashSet<>();
|
| 23650 |
amit.gupta |
1469 |
|
| 22859 |
ashik.ali |
1470 |
float calculatedAmount = 0;
|
| 23650 |
amit.gupta |
1471 |
for (CustomPaymentOption customPaymentOption : customPaymentOptions) {
|
| 23365 |
ashik.ali |
1472 |
paymentOptionIds.add(customPaymentOption.getPaymentOptionId());
|
|
|
1473 |
calculatedAmount = calculatedAmount + customPaymentOption.getAmount();
|
| 22859 |
ashik.ali |
1474 |
}
|
| 23650 |
amit.gupta |
1475 |
if (calculatedAmount != totalAmount) {
|
|
|
1476 |
LOGGER.warn("Error occured while validating payment options amount[{}] != TotalAmount [{}]",
|
|
|
1477 |
calculatedAmount, totalAmount);
|
|
|
1478 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.PAYMENT_OPTION_CALCULATED_AMOUNT,
|
|
|
1479 |
calculatedAmount, "FFORDR_1016");
|
| 22859 |
ashik.ali |
1480 |
}
|
| 23650 |
amit.gupta |
1481 |
|
| 23365 |
ashik.ali |
1482 |
List<Integer> foundPaymentOptionIds = paymentOptionRepository.selectIdsByIds(paymentOptionIds);
|
| 23650 |
amit.gupta |
1483 |
if (foundPaymentOptionIds.size() != paymentOptionIds.size()) {
|
| 23365 |
ashik.ali |
1484 |
paymentOptionIds.removeAll(foundPaymentOptionIds);
|
| 23650 |
amit.gupta |
1485 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.PAYMENT_OPTION_ID, paymentOptionIds,
|
|
|
1486 |
"FFORDR_1017");
|
| 23365 |
ashik.ali |
1487 |
}
|
| 22859 |
ashik.ali |
1488 |
}
|
| 23650 |
amit.gupta |
1489 |
|
| 22925 |
ashik.ali |
1490 |
@Override
|
|
|
1491 |
public List<FofoOrderItem> getByOrderId(int orderId) throws ProfitMandiBusinessException {
|
|
|
1492 |
List<FofoOrderItem> fofoOrderItems = fofoOrderItemRepository.selectByOrderId(orderId);
|
| 23650 |
amit.gupta |
1493 |
if (!fofoOrderItems.isEmpty()) {
|
| 22925 |
ashik.ali |
1494 |
List<FofoOrderItem> newFofoOrderItems = new ArrayList<>();
|
| 23650 |
amit.gupta |
1495 |
Map<Integer, Set<FofoLineItem>> fofoOrderItemIdFofoLineItemsMap = this
|
|
|
1496 |
.toFofoOrderItemIdFofoLineItems(fofoOrderItems);
|
| 22925 |
ashik.ali |
1497 |
Iterator<FofoOrderItem> fofoOrderItemsIterator = fofoOrderItems.iterator();
|
| 23650 |
amit.gupta |
1498 |
while (fofoOrderItemsIterator.hasNext()) {
|
| 22925 |
ashik.ali |
1499 |
FofoOrderItem fofoOrderItem = fofoOrderItemsIterator.next();
|
|
|
1500 |
fofoOrderItem.setFofoLineItems(fofoOrderItemIdFofoLineItemsMap.get(fofoOrderItem.getId()));
|
|
|
1501 |
newFofoOrderItems.add(fofoOrderItem);
|
|
|
1502 |
fofoOrderItemsIterator.remove();
|
|
|
1503 |
}
|
|
|
1504 |
fofoOrderItems = newFofoOrderItems;
|
|
|
1505 |
}
|
|
|
1506 |
return fofoOrderItems;
|
|
|
1507 |
}
|
| 23650 |
amit.gupta |
1508 |
|
|
|
1509 |
private Set<Integer> toFofoOrderItemIds(List<FofoOrderItem> fofoOrderItems) {
|
| 22955 |
ashik.ali |
1510 |
Function<FofoOrderItem, Integer> fofoOrderItemToFofoOrderItemIdFunction = new Function<FofoOrderItem, Integer>() {
|
|
|
1511 |
@Override
|
|
|
1512 |
public Integer apply(FofoOrderItem fofoOrderItem) {
|
|
|
1513 |
return fofoOrderItem.getId();
|
|
|
1514 |
}
|
|
|
1515 |
};
|
|
|
1516 |
return fofoOrderItems.stream().map(fofoOrderItemToFofoOrderItemIdFunction).collect(Collectors.toSet());
|
| 22925 |
ashik.ali |
1517 |
}
|
| 23650 |
amit.gupta |
1518 |
|
|
|
1519 |
private Map<Integer, Set<FofoLineItem>> toFofoOrderItemIdFofoLineItems(List<FofoOrderItem> fofoOrderItems) {
|
| 22925 |
ashik.ali |
1520 |
Set<Integer> fofoOrderItemIds = this.toFofoOrderItemIds(fofoOrderItems);
|
|
|
1521 |
List<FofoLineItem> fofoLineItems = fofoLineItemRepository.selectByFofoOrderItemIds(fofoOrderItemIds);
|
|
|
1522 |
Map<Integer, Set<FofoLineItem>> fofoOrderItemIdFofoLineItemsMap = new HashMap<>();
|
| 23650 |
amit.gupta |
1523 |
for (FofoLineItem fofoLineItem : fofoLineItems) {
|
|
|
1524 |
if (!fofoOrderItemIdFofoLineItemsMap.containsKey(fofoLineItem.getFofoOrderItemId())) {
|
| 22925 |
ashik.ali |
1525 |
Set<FofoLineItem> fofoLineItems2 = new HashSet<>();
|
|
|
1526 |
fofoLineItems2.add(fofoLineItem);
|
|
|
1527 |
fofoOrderItemIdFofoLineItemsMap.put(fofoLineItem.getFofoOrderItemId(), fofoLineItems2);
|
| 23650 |
amit.gupta |
1528 |
} else {
|
| 22925 |
ashik.ali |
1529 |
fofoOrderItemIdFofoLineItemsMap.get(fofoLineItem.getFofoOrderItemId()).add(fofoLineItem);
|
|
|
1530 |
}
|
|
|
1531 |
}
|
|
|
1532 |
return fofoOrderItemIdFofoLineItemsMap;
|
|
|
1533 |
}
|
| 23650 |
amit.gupta |
1534 |
|
|
|
1535 |
private String getOtpString() {
|
| 23418 |
ashik.ali |
1536 |
Random rndm_method = new Random();
|
| 23650 |
amit.gupta |
1537 |
String numbers = "0123456789";
|
| 23418 |
ashik.ali |
1538 |
char[] otp = new char[5];
|
| 22859 |
ashik.ali |
1539 |
|
| 23650 |
amit.gupta |
1540 |
for (int i = 0; i < 5; i++) {
|
| 23418 |
ashik.ali |
1541 |
otp[i] = numbers.charAt(rndm_method.nextInt(numbers.length()));
|
|
|
1542 |
}
|
|
|
1543 |
return String.valueOf(otp);
|
|
|
1544 |
}
|
| 23650 |
amit.gupta |
1545 |
|
|
|
1546 |
private void sendOtp(String otp_text, String phone, Map<Integer, Float> itemIdAdvanceAmount) {
|
|
|
1547 |
Map<Integer, String> itemIdDescriptionMap = inventoryService
|
|
|
1548 |
.getItemIdDescriptionMap(itemIdAdvanceAmount.keySet());
|
| 23418 |
ashik.ali |
1549 |
StringBuilder itemIdAdvanceAmountString = new StringBuilder();
|
|
|
1550 |
int index = 0;
|
| 23650 |
amit.gupta |
1551 |
for (Map.Entry<Integer, Float> itemIdAdvanceAmountEntry : itemIdAdvanceAmount.entrySet()) {
|
| 23418 |
ashik.ali |
1552 |
itemIdAdvanceAmountString.append(itemIdDescriptionMap.get(itemIdAdvanceAmountEntry.getKey()));
|
|
|
1553 |
itemIdAdvanceAmountString.append("'s Advance amount [");
|
|
|
1554 |
itemIdAdvanceAmountString.append(itemIdAdvanceAmountEntry.getValue());
|
|
|
1555 |
itemIdAdvanceAmountString.append("]");
|
| 23650 |
amit.gupta |
1556 |
if (index + 1 < itemIdAdvanceAmount.size()) {
|
| 23418 |
ashik.ali |
1557 |
itemIdAdvanceAmountString.append(", ");
|
|
|
1558 |
}
|
|
|
1559 |
index++;
|
|
|
1560 |
}
|
|
|
1561 |
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.";
|
| 23650 |
amit.gupta |
1562 |
LOGGER.info("OTP to Customer Successfully sends" + text);
|
| 23418 |
ashik.ali |
1563 |
String msg = java.text.MessageFormat.format(text, otp_text, itemIdAdvanceAmountString);
|
|
|
1564 |
try {
|
|
|
1565 |
Utils.sendSms(msg, phone);
|
|
|
1566 |
} catch (URISyntaxException e) {
|
|
|
1567 |
// TODO Auto-generated catch block
|
|
|
1568 |
e.printStackTrace();
|
|
|
1569 |
} catch (IOException e) {
|
|
|
1570 |
// TODO Auto-generated catch block
|
|
|
1571 |
e.printStackTrace();
|
|
|
1572 |
}
|
| 23650 |
amit.gupta |
1573 |
|
| 23418 |
ashik.ali |
1574 |
}
|
| 23650 |
amit.gupta |
1575 |
|
| 23418 |
ashik.ali |
1576 |
@Override
|
| 23650 |
amit.gupta |
1577 |
public int generatePrebookingOrdersOtp(String customerEmailId, String customerMobileNumber,
|
|
|
1578 |
Map<Integer, Float> itemIdAdvanceAmount) throws ProfitMandiBusinessException {
|
|
|
1579 |
if (!StringUtils.isValidEmailAddress(customerEmailId)) {
|
| 23418 |
ashik.ali |
1580 |
LOGGER.error("invalid customer emailId {} ", customerEmailId);
|
|
|
1581 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.EMAIL_ID, customerEmailId, "VE_1016");
|
|
|
1582 |
}
|
|
|
1583 |
|
| 23650 |
amit.gupta |
1584 |
if (!StringUtils.isValidMobile(customerMobileNumber)) {
|
| 23418 |
ashik.ali |
1585 |
LOGGER.error("invalid customer mobileNumber {} ", customerMobileNumber);
|
|
|
1586 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.MOBILE_NUMBER, customerMobileNumber, "VE_1071");
|
|
|
1587 |
}
|
| 23650 |
amit.gupta |
1588 |
|
| 23418 |
ashik.ali |
1589 |
List<Otp> otps = otpRepository.selectAllByEmailWithTime(customerEmailId);
|
|
|
1590 |
String otp = null;
|
| 23650 |
amit.gupta |
1591 |
if (otps.size() >= 5) {
|
|
|
1592 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.CUSTOMER_EMAIL_ID, customerEmailId,
|
|
|
1593 |
"FFORDR_1019");
|
| 23418 |
ashik.ali |
1594 |
}
|
| 23650 |
amit.gupta |
1595 |
if (!otps.isEmpty()) {
|
|
|
1596 |
if (otps.get(0).getCreatedOn().isAfter(LocalDateTime.now().minusMinutes(2))) {
|
| 23418 |
ashik.ali |
1597 |
return otps.get(0).getId();
|
| 23650 |
amit.gupta |
1598 |
} else if (otps.get(0).getCreatedOn().isAfter(LocalDateTime.now().minusMinutes(10))) {
|
| 23418 |
ashik.ali |
1599 |
otp = otps.get(0).getOtp();
|
|
|
1600 |
}
|
|
|
1601 |
}
|
| 23650 |
amit.gupta |
1602 |
if (otp == null || otp.isEmpty()) {
|
| 23418 |
ashik.ali |
1603 |
otp = getOtpString();
|
|
|
1604 |
}
|
| 23650 |
amit.gupta |
1605 |
|
| 23418 |
ashik.ali |
1606 |
this.sendOtp(otp, customerMobileNumber, itemIdAdvanceAmount);
|
| 23650 |
amit.gupta |
1607 |
|
| 23418 |
ashik.ali |
1608 |
Otp otp_bean = new Otp();
|
|
|
1609 |
otp_bean.setEmail(customerEmailId);
|
|
|
1610 |
otp_bean.setMobile(customerMobileNumber);
|
|
|
1611 |
otp_bean.setOtp(otp);
|
|
|
1612 |
otp_bean.setOtpType(OtpType.PREBOOKING_ORDER);
|
|
|
1613 |
otp_bean.setCreatedOn(LocalDateTime.now());
|
|
|
1614 |
otp_bean.setExpiryTimestamp(LocalDateTime.now().plusMinutes(10));
|
|
|
1615 |
otpRepository.persist(otp_bean);
|
| 23650 |
amit.gupta |
1616 |
|
| 23418 |
ashik.ali |
1617 |
return otp_bean.getId();
|
|
|
1618 |
}
|
| 23650 |
amit.gupta |
1619 |
|
| 23418 |
ashik.ali |
1620 |
@Override
|
|
|
1621 |
public String validateOtp(String customerEmailId, String customerMobileNumber, int otpId, String otpValue)
|
|
|
1622 |
throws ProfitMandiBusinessException {
|
|
|
1623 |
Otp otp = otpRepository.selectByIdEmailIdMobileNumber(otpId, customerEmailId, customerMobileNumber);
|
|
|
1624 |
otp.setTryCount(otp.getTryCount() + 1);
|
| 23650 |
amit.gupta |
1625 |
if (!otp.getOtp().equalsIgnoreCase(otpValue)) {
|
| 23418 |
ashik.ali |
1626 |
throw new ProfitMandiBusinessException("otpValue", otpValue, "FFORDR_1020");
|
|
|
1627 |
}
|
| 23650 |
amit.gupta |
1628 |
if (otp.isExpired() || otp.isVerified() || otp.getExpiryTimestamp().isBefore(LocalDateTime.now())) {
|
| 23418 |
ashik.ali |
1629 |
throw new ProfitMandiBusinessException("otpValue", otpValue, "FFORDR_1021");
|
|
|
1630 |
}
|
| 23650 |
amit.gupta |
1631 |
if (otp.getTryCount() > 5) {
|
| 23418 |
ashik.ali |
1632 |
throw new ProfitMandiBusinessException("otpValue", otpValue, "FFORDR_1022");
|
|
|
1633 |
}
|
|
|
1634 |
otp.setExpired(true);
|
|
|
1635 |
otp.setVerified(true);
|
|
|
1636 |
otpRepository.persist(otp);
|
| 23650 |
amit.gupta |
1637 |
|
| 23418 |
ashik.ali |
1638 |
return ResponseCodeHolder.getMessage("FFORDR_OK_1002");
|
|
|
1639 |
}
|
| 23650 |
amit.gupta |
1640 |
|
| 23582 |
ashik.ali |
1641 |
@Override
|
| 23650 |
amit.gupta |
1642 |
public void updateCustomerDetails(CustomCustomer customCustomer, String invoiceNumber)
|
|
|
1643 |
throws ProfitMandiBusinessException {
|
| 23582 |
ashik.ali |
1644 |
FofoOrder fofoOrder = fofoOrderRepository.selectByInvoiceNumber(invoiceNumber);
|
|
|
1645 |
Customer customer = customerRepository.selectById(fofoOrder.getCustomerId());
|
|
|
1646 |
customer.setFirstName(customCustomer.getFirstName());
|
|
|
1647 |
customer.setLastName(customCustomer.getLastName());
|
|
|
1648 |
customerRepository.persist(customer);
|
|
|
1649 |
CustomerAddress customerAddress = customerAddressRepository.selectById(fofoOrder.getCustomerAddressId());
|
|
|
1650 |
this.setCustomerAddress(customerAddress, customCustomer.getAddress());
|
|
|
1651 |
customerAddressRepository.persist(customerAddress);
|
|
|
1652 |
}
|
| 23418 |
ashik.ali |
1653 |
|
| 23638 |
amit.gupta |
1654 |
@Override
|
| 23655 |
amit.gupta |
1655 |
public CustomerCreditNote badReturn(int fofoId, FoiBadReturnRequest foiBadReturnRequest) throws ProfitMandiBusinessException {
|
|
|
1656 |
FofoOrderItem foi = fofoOrderItemRepository.selectById(foiBadReturnRequest.getFofoOrderItemId());
|
| 23650 |
amit.gupta |
1657 |
FofoOrder fofoOrder = fofoOrderRepository.selectByOrderId(foi.getOrderId());
|
| 23655 |
amit.gupta |
1658 |
if (fofoOrder.getFofoId() != fofoId) {
|
| 23638 |
amit.gupta |
1659 |
throw new ProfitMandiBusinessException("Partner Auth", "", "Invalid Order");
|
|
|
1660 |
}
|
| 23655 |
amit.gupta |
1661 |
int billedQty = foi.getQuantity() - customerReturnItemRepository.selectAllByOrderItemId(foi.getId()).size();
|
|
|
1662 |
if(foiBadReturnRequest.getMarkedBadArr().size() > billedQty ) {
|
|
|
1663 |
throw new ProfitMandiBusinessException("Cant bad return more than what is billed", "", "Invalid Quantity");
|
|
|
1664 |
}
|
| 23650 |
amit.gupta |
1665 |
List<CustomerReturnItem> customerReturnItems = new ArrayList<>();
|
| 23655 |
amit.gupta |
1666 |
for (BadReturnRequest badReturnRequest : foiBadReturnRequest.getMarkedBadArr()) {
|
| 23650 |
amit.gupta |
1667 |
CustomerReturnItem customerReturnItem = new CustomerReturnItem();
|
|
|
1668 |
customerReturnItem.setFofoId(fofoId);
|
| 23655 |
amit.gupta |
1669 |
customerReturnItem.setFofoOrderItemId(foiBadReturnRequest.getFofoOrderItemId());
|
|
|
1670 |
customerReturnItem.setRemarks(badReturnRequest.getRemarks());
|
| 23650 |
amit.gupta |
1671 |
customerReturnItem.setInventoryItemId(badReturnRequest.getInventoryItemId());
|
|
|
1672 |
customerReturnItem.setQuantity(1);
|
|
|
1673 |
customerReturnItem.setType(ReturnType.BAD);
|
|
|
1674 |
//customerReturnItemRepository.persist(customerReturnItem);
|
|
|
1675 |
inventoryService.saleReturnInventoryItem(customerReturnItem);
|
|
|
1676 |
customerReturnItems.add(customerReturnItem);
|
| 23638 |
amit.gupta |
1677 |
}
|
| 23655 |
amit.gupta |
1678 |
CustomerCreditNote creditNote = generateCreditNote(fofoOrder, customerReturnItems);
|
|
|
1679 |
for (CustomerReturnItem customerReturnItem: customerReturnItems) {
|
|
|
1680 |
purchaseReturnService.returnInventoryItem(fofoId, false, customerReturnItem.getInventoryItemId(), ReturnType.BAD);
|
|
|
1681 |
}
|
|
|
1682 |
return creditNote;
|
| 23638 |
amit.gupta |
1683 |
}
|
|
|
1684 |
|
| 23655 |
amit.gupta |
1685 |
private CustomerCreditNote generateCreditNote(FofoOrder fofoOrder, List<CustomerReturnItem> customerReturnItems) throws ProfitMandiBusinessException {
|
| 23650 |
amit.gupta |
1686 |
|
| 23638 |
amit.gupta |
1687 |
InvoiceNumberGenerationSequence sequence = invoiceNumberGenerationSequenceRepository
|
| 23650 |
amit.gupta |
1688 |
.selectByFofoId(fofoOrder.getFofoId());
|
|
|
1689 |
sequence.setCreditNoteSequence(sequence.getCreditNoteSequence() + 1);
|
| 23638 |
amit.gupta |
1690 |
invoiceNumberGenerationSequenceRepository.persist(sequence);
|
| 23650 |
amit.gupta |
1691 |
|
| 23655 |
amit.gupta |
1692 |
String creditNoteNumber = sequence.getPrefix() + "/" + sequence.getCreditNoteSequence();
|
| 23650 |
amit.gupta |
1693 |
CustomerCreditNote creditNote = new CustomerCreditNote();
|
|
|
1694 |
creditNote.setCreditNoteNumber(creditNoteNumber);
|
|
|
1695 |
creditNote.setFofoId(fofoOrder.getFofoId());
|
| 23655 |
amit.gupta |
1696 |
creditNote.setFofoOrderId(fofoOrder.getId());
|
|
|
1697 |
creditNote.setFofoOrderItemId(customerReturnItems.get(0).getFofoOrderItemId());
|
|
|
1698 |
creditNote.setSettlementType(SettlementType.UNSETTLED);
|
| 23650 |
amit.gupta |
1699 |
customerCreditNoteRepository.persist(creditNote);
|
|
|
1700 |
|
|
|
1701 |
for (CustomerReturnItem customerReturnItem : customerReturnItems) {
|
|
|
1702 |
customerReturnItem.setCreditNoteId(creditNote.getId());
|
|
|
1703 |
customerReturnItemRepository.persist(customerReturnItem);
|
| 23638 |
amit.gupta |
1704 |
}
|
| 23650 |
amit.gupta |
1705 |
//this.returnInventoryItems(inventoryItems, debitNote);
|
| 23638 |
amit.gupta |
1706 |
|
| 23655 |
amit.gupta |
1707 |
return creditNote;
|
| 23650 |
amit.gupta |
1708 |
}
|
|
|
1709 |
|
| 23655 |
amit.gupta |
1710 |
@Override
|
|
|
1711 |
public CreditNotePdfModel getCreditNotePdfModel(int customerCreditNoteId) throws ProfitMandiBusinessException {
|
|
|
1712 |
CustomerCreditNote creditNote = customerCreditNoteRepository.selectById(customerCreditNoteId);
|
|
|
1713 |
return getCreditNotePdfModel(creditNote);
|
|
|
1714 |
}
|
|
|
1715 |
|
|
|
1716 |
private CreditNotePdfModel getCreditNotePdfModel(CustomerCreditNote creditNote) throws ProfitMandiBusinessException {
|
|
|
1717 |
FofoOrder fofoOrder = fofoOrderRepository.selectByOrderId(creditNote.getFofoOrderId());
|
|
|
1718 |
List<CustomerReturnItem> customerReturnItems = customerReturnItemRepository.selectAllByCreditNoteId(creditNote.getId());
|
|
|
1719 |
CustomCustomer customCustomer = getCustomCustomer(fofoOrder);
|
|
|
1720 |
|
|
|
1721 |
Set<CustomOrderItem> customerFofoOrderItems = new HashSet<>();
|
|
|
1722 |
CustomRetailer customRetailer = retailerService.getFofoRetailers(Arrays.asList(fofoOrder.getFofoId())).get(fofoOrder.getFofoId());
|
|
|
1723 |
|
|
|
1724 |
FofoOrderItem fofoOrderItem = fofoOrderItemRepository.selectById(creditNote.getFofoOrderItemId());
|
|
|
1725 |
float totalTaxRate = fofoOrderItem.getIgstRate() + fofoOrderItem.getSgstRate() + fofoOrderItem.getCgstRate();
|
|
|
1726 |
float taxableSellingPrice = fofoOrderItem.getSellingPrice() / (1 + totalTaxRate / 100);
|
|
|
1727 |
float taxableDiscountPrice = fofoOrderItem.getDiscount() / (1 + totalTaxRate / 100);
|
|
|
1728 |
|
|
|
1729 |
CustomOrderItem customFofoOrderItem = new CustomOrderItem();
|
|
|
1730 |
customFofoOrderItem.setAmount(customerReturnItems.size() * (taxableSellingPrice - taxableDiscountPrice));
|
|
|
1731 |
customFofoOrderItem.setDescription(fofoOrderItem.getBrand() + " " + fofoOrderItem.getModelName() + " "
|
|
|
1732 |
+ fofoOrderItem.getModelNumber() + "-" + fofoOrderItem.getColor());
|
|
|
1733 |
|
|
|
1734 |
if(ItemType.SERIALIZED.equals(itemRepository.selectById(fofoOrderItem.getItemId()).getType())){
|
|
|
1735 |
Set<Integer> inventoryItemIds = customerReturnItems.stream().map(x -> x.getInventoryItemId())
|
|
|
1736 |
.collect(Collectors.toSet());
|
|
|
1737 |
List<String> serialNumbers = inventoryItemRepository.selectByIds(inventoryItemIds).stream()
|
|
|
1738 |
.map(x -> x.getSerialNumber()).collect(Collectors.toList());
|
|
|
1739 |
customFofoOrderItem.setDescription(
|
|
|
1740 |
customFofoOrderItem.getDescription() + "\n IMEIS - " + String.join(", ", serialNumbers));
|
|
|
1741 |
}
|
|
|
1742 |
|
|
|
1743 |
customFofoOrderItem.setRate(taxableSellingPrice);
|
|
|
1744 |
customFofoOrderItem.setDiscount(taxableDiscountPrice);
|
|
|
1745 |
customFofoOrderItem.setQuantity(customerReturnItems.size());
|
|
|
1746 |
customFofoOrderItem.setNetAmount((fofoOrderItem.getSellingPrice() - fofoOrderItem.getDiscount()) * customFofoOrderItem.getQuantity());
|
|
|
1747 |
|
|
|
1748 |
float igstAmount = (customFofoOrderItem.getAmount() * fofoOrderItem.getIgstRate()) / 100;
|
|
|
1749 |
float cgstAmount = (customFofoOrderItem.getAmount() * fofoOrderItem.getCgstRate()) / 100;
|
|
|
1750 |
float sgstAmount = (customFofoOrderItem.getAmount() * fofoOrderItem.getSgstRate()) / 100;
|
|
|
1751 |
LOGGER.info("fofoOrderItem - {}", fofoOrderItem);
|
|
|
1752 |
customFofoOrderItem.setIgstRate(fofoOrderItem.getIgstRate());
|
|
|
1753 |
customFofoOrderItem.setIgstAmount(igstAmount);
|
|
|
1754 |
customFofoOrderItem.setCgstRate(fofoOrderItem.getCgstRate());
|
|
|
1755 |
customFofoOrderItem.setCgstAmount(cgstAmount);
|
|
|
1756 |
customFofoOrderItem.setSgstRate(fofoOrderItem.getSgstRate());
|
|
|
1757 |
customFofoOrderItem.setSgstAmount(sgstAmount);
|
|
|
1758 |
customFofoOrderItem.setHsnCode(fofoOrderItem.getHsnCode());
|
| 23721 |
amit.gupta |
1759 |
customFofoOrderItem.setOrderId(1);
|
| 23655 |
amit.gupta |
1760 |
customerFofoOrderItems.add(customFofoOrderItem);
|
|
|
1761 |
|
| 23650 |
amit.gupta |
1762 |
PdfModel pdfModel = new PdfModel();
|
|
|
1763 |
pdfModel.setAuther("NSSPL");
|
| 23655 |
amit.gupta |
1764 |
pdfModel.setCustomer(customCustomer);
|
|
|
1765 |
pdfModel.setInvoiceNumber(fofoOrder.getInvoiceNumber());
|
|
|
1766 |
pdfModel.setInvoiceDate(FormattingUtils.formatDate(fofoOrder.getCreateTimestamp()));
|
|
|
1767 |
pdfModel.setTitle("Credit Note");
|
|
|
1768 |
pdfModel.setRetailer(customRetailer);
|
|
|
1769 |
pdfModel.setTotalAmount(customFofoOrderItem.getNetAmount());
|
|
|
1770 |
pdfModel.setOrderItems(customerFofoOrderItems);
|
|
|
1771 |
|
| 23650 |
amit.gupta |
1772 |
CreditNotePdfModel creditNotePdfModel = new CreditNotePdfModel();
|
|
|
1773 |
creditNotePdfModel.setCreditNoteDate(FormattingUtils.formatDate(creditNote.getCreateTimestamp()));
|
|
|
1774 |
creditNotePdfModel.setCreditNoteNumber(creditNote.getCreditNoteNumber());
|
|
|
1775 |
creditNotePdfModel.setPdfModel(pdfModel);
|
|
|
1776 |
return creditNotePdfModel;
|
|
|
1777 |
}
|
| 23638 |
amit.gupta |
1778 |
|
| 22859 |
ashik.ali |
1779 |
}
|