Subversion Repositories SmartDukaan

Rev

Rev 21612 | Rev 21689 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 21612 Rev 21680
Line 1... Line 1...
1
package com.spice.profitmandi.web.controller;
1
package com.spice.profitmandi.web.controller;
2
 
2
 
-
 
3
import java.util.ArrayList;
-
 
4
import java.util.HashMap;
3
import java.util.HashSet;
5
import java.util.HashSet;
-
 
6
import java.util.List;
-
 
7
import java.util.Map;
4
import java.util.Set;
8
import java.util.Set;
5
 
9
 
6
import javax.servlet.http.HttpServletRequest;
10
import javax.servlet.http.HttpServletRequest;
-
 
11
import javax.transaction.Transactional;
7
 
12
 
8
import org.slf4j.Logger;
13
import org.slf4j.Logger;
9
import org.slf4j.LoggerFactory;
14
import org.slf4j.LoggerFactory;
10
import org.springframework.beans.factory.annotation.Autowired;
15
import org.springframework.beans.factory.annotation.Autowired;
11
import org.springframework.stereotype.Controller;
16
import org.springframework.stereotype.Controller;
12
import org.springframework.ui.Model;
-
 
13
import org.springframework.web.bind.annotation.RequestBody;
17
import org.springframework.web.bind.annotation.RequestBody;
14
import org.springframework.web.bind.annotation.RequestMapping;
18
import org.springframework.web.bind.annotation.RequestMapping;
15
import org.springframework.web.bind.annotation.RequestMethod;
19
import org.springframework.web.bind.annotation.RequestMethod;
16
 
20
 
17
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
21
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
-
 
22
import com.spice.profitmandi.common.model.CustomAddress;
18
import com.spice.profitmandi.common.model.ProfitMandiConstants;
23
import com.spice.profitmandi.common.model.ProfitMandiConstants;
-
 
24
import com.spice.profitmandi.common.util.StringUtils;
-
 
25
import com.spice.profitmandi.dao.entity.Address;
-
 
26
import com.spice.profitmandi.dao.entity.CurrentInventorySnapshot;
-
 
27
import com.spice.profitmandi.dao.entity.Customer;
-
 
28
import com.spice.profitmandi.dao.entity.FofoLineItem;
-
 
29
import com.spice.profitmandi.dao.entity.FofoLineItemSerialNumber;
-
 
30
import com.spice.profitmandi.dao.entity.FofoOrder;
-
 
31
import com.spice.profitmandi.dao.entity.InventoryItem;
-
 
32
import com.spice.profitmandi.dao.entity.InvoiceNumberGenerationSequence;
-
 
33
import com.spice.profitmandi.dao.entity.Item;
-
 
34
import com.spice.profitmandi.dao.entity.LineItem;
-
 
35
import com.spice.profitmandi.dao.entity.Order;
-
 
36
import com.spice.profitmandi.dao.entity.PaymentOption;
-
 
37
import com.spice.profitmandi.dao.entity.ScanRecord;
-
 
38
import com.spice.profitmandi.dao.enumuration.ScanType;
-
 
39
import com.spice.profitmandi.dao.repository.AddressRepository;
-
 
40
import com.spice.profitmandi.dao.repository.CurrentInventorySnapshotRepository;
-
 
41
import com.spice.profitmandi.dao.repository.CustomerRepository;
-
 
42
import com.spice.profitmandi.dao.repository.FofoLineItemRepository;
-
 
43
import com.spice.profitmandi.dao.repository.FofoLineItemSerialNumberRepository;
-
 
44
import com.spice.profitmandi.dao.repository.FofoOrderRepository;
19
import com.spice.profitmandi.dao.repository.InventoryItemRepository;
45
import com.spice.profitmandi.dao.repository.InventoryItemRepository;
-
 
46
import com.spice.profitmandi.dao.repository.InvoiceNumberGenerationSequenceRepository;
20
import com.spice.profitmandi.dao.repository.OrderRepository;
47
import com.spice.profitmandi.dao.repository.OrderRepository;
-
 
48
import com.spice.profitmandi.dao.repository.PaymentOptionRepository;
-
 
49
import com.spice.profitmandi.dao.repository.ScanRecordRepository;
21
import com.spice.profitmandi.web.model.FofoDetails;
50
import com.spice.profitmandi.web.model.FofoDetails;
22
import com.spice.profitmandi.web.request.CreateOrderRequest;
51
import com.spice.profitmandi.web.request.CreateOrderRequest;
-
 
52
import com.spice.profitmandi.web.request.CustomCustomer;
-
 
53
import com.spice.profitmandi.web.request.CustomFofoLineItem;
23
import com.spice.profitmandi.web.request.CustomPaymentOption;
54
import com.spice.profitmandi.web.request.CustomPaymentOption;
-
 
55
import com.spice.profitmandi.web.response.ItemIdQuantityAvailability;
-
 
56
import com.spice.profitmandi.web.response.Quantity;
24
import com.spice.profitmandi.web.util.CookiesFetcher;
57
import com.spice.profitmandi.web.util.CookiesFetcher;
25
import com.spice.profitmandi.web.util.MVCResponseSender;
58
import com.spice.profitmandi.web.util.MVCResponseSender;
26
 
59
 
27
@Controller
60
@Controller
-
 
61
@Transactional
28
public class OrderController {
62
public class OrderController {
29
 
63
 
30
	private static final Logger LOGGER = LoggerFactory.getLogger(OrderController.class);
64
	private static final Logger LOGGER = LoggerFactory.getLogger(OrderController.class);
31
	
65
	
32
	@Autowired
66
	@Autowired
Line 34... Line 68...
34
	
68
	
35
	@Autowired
69
	@Autowired
36
	InventoryItemRepository inventoryItemRepository;
70
	InventoryItemRepository inventoryItemRepository;
37
	
71
	
38
	@Autowired
72
	@Autowired
-
 
73
	CurrentInventorySnapshotRepository currentInventorySnapshotRepository;
-
 
74
	
-
 
75
	@Autowired
-
 
76
	InvoiceNumberGenerationSequenceRepository invoiceNumberGenerationSequenceRepository;
-
 
77
	
-
 
78
	@Autowired
-
 
79
	CustomerRepository customerRepository;
-
 
80
	
-
 
81
	@Autowired
-
 
82
	AddressRepository addressRepository;
-
 
83
	
-
 
84
	@Autowired
-
 
85
	FofoLineItemSerialNumberRepository fofoLineItemSerialNumberRepository;
-
 
86
	
-
 
87
	@Autowired
-
 
88
	FofoLineItemRepository fofoLineItemRepository;
-
 
89
	
-
 
90
	@Autowired
-
 
91
	PaymentOptionRepository paymentOptionRepository;
-
 
92
	
-
 
93
	@Autowired
-
 
94
	ScanRecordRepository scanRecordRepository;
-
 
95
	
-
 
96
	@Autowired
-
 
97
	FofoOrderRepository fofoOrderRepository;
-
 
98
	
-
 
99
	@Autowired
39
	MVCResponseSender mvcResponseSender;
100
	MVCResponseSender mvcResponseSender;
40
	
101
	
41
	@Autowired
102
	@Autowired
42
	CookiesFetcher cookiesFetcher;
103
	CookiesFetcher cookiesFetcher;
43
	
104
	
44
	@RequestMapping(value = "/order", method = RequestMethod.POST)
105
	@RequestMapping(value = "/order", method = RequestMethod.POST)
45
	public String createOrder(HttpServletRequest request, @RequestBody CreateOrderRequest createOrderRequest, Model model)  throws Throwable{
106
	public String createOrder(HttpServletRequest request, @RequestBody CreateOrderRequest createOrderRequest)  throws Throwable{
46
		FofoDetails fofoDetails = cookiesFetcher.getCookiesObject(request);
107
		//FofoDetails fofoDetails = cookiesFetcher.getCookiesObject(request);
-
 
108
		LOGGER.info("/order request {}", createOrderRequest);
-
 
109
		FofoDetails fofoDetails = new FofoDetails();
-
 
110
		fofoDetails.setFofoId(963490);
-
 
111
		Set<CustomFofoLineItem> fofoLineItems = createOrderRequest.getFofoLineItems();
-
 
112
		Set<Integer> itemIds = new HashSet<>();
-
 
113
		Set<Integer> nonSerializedItemIds = new HashSet<>();
-
 
114
		Map<Integer, Integer> itemIdQuantity = new HashMap<>();
-
 
115
		for(CustomFofoLineItem fofoLineItem : fofoLineItems){
-
 
116
			itemIds.add(fofoLineItem.getItemId());
-
 
117
			if(fofoLineItem.getSerialNumbers().size() > 0 && fofoLineItem.getQuantity() != fofoLineItem.getSerialNumbers().size()){
-
 
118
				itemIdQuantity.put(fofoLineItem.getItemId(), fofoLineItem.getQuantity());
-
 
119
			}
-
 
120
			if(fofoLineItem.getSerialNumbers().isEmpty()){
-
 
121
				nonSerializedItemIds.add(fofoLineItem.getItemId());
-
 
122
			}
-
 
123
		}
-
 
124
		if(!itemIdQuantity.isEmpty()){
-
 
125
			// if item quantity does not match with given serialnumbers size
-
 
126
			LOGGER.error("itemId's quantity should be equal to given serialnumber size {} ", itemIdQuantity);
-
 
127
			return "error";
-
 
128
		}
-
 
129
		float totalAmount = 0;
-
 
130
		Map<Integer, Float> lineItemPrice = new HashMap<>();
-
 
131
		List<CurrentInventorySnapshot> currentInventorySnapshots = currentInventorySnapshotRepository.selectByFofoItemIds(fofoDetails.getFofoId(), itemIds);
-
 
132
		List<ItemIdQuantityAvailability> itemIdQuantityAvailabilities = new ArrayList<>(); 
-
 
133
		for(CurrentInventorySnapshot currentInventorySnapshot : currentInventorySnapshots){
-
 
134
			for(CustomFofoLineItem fofoLineItem : fofoLineItems){
-
 
135
				if(currentInventorySnapshot.getId().getItemId() == fofoLineItem.getItemId()){
-
 
136
					if(fofoLineItem.getQuantity() > currentInventorySnapshot.getAvailability()){
-
 
137
						ItemIdQuantityAvailability itemIdQuantityAvailability = new ItemIdQuantityAvailability();
-
 
138
						itemIdQuantityAvailability.setItemId(fofoLineItem.getItemId());
-
 
139
						Quantity quantity = new Quantity();
-
 
140
						quantity.setAvailable(currentInventorySnapshot.getAvailability());
-
 
141
						quantity.setRequested(fofoLineItem.getQuantity());
-
 
142
						itemIdQuantityAvailability.setQuantity(quantity);
-
 
143
						itemIdQuantityAvailabilities.add(itemIdQuantityAvailability);
-
 
144
					}
-
 
145
				}
-
 
146
				if(!(fofoLineItem.getSellingPrice() > 0)){
-
 
147
					lineItemPrice.put(fofoLineItem.getItemId(), fofoLineItem.getSellingPrice());
-
 
148
				}else{
-
 
149
					totalAmount = totalAmount + fofoLineItem.getSellingPrice();
-
 
150
				}
-
 
151
			}
-
 
152
		}
-
 
153
		
-
 
154
		try{
-
 
155
			this.validatePaymentOptionsAndTotalAmount(createOrderRequest.getPaymentOptions(), totalAmount);
-
 
156
		}catch(ProfitMandiBusinessException profitMandiBusinessException){
-
 
157
			LOGGER.error("Error occured while validating payment options : ", profitMandiBusinessException);
-
 
158
			return "error";
-
 
159
		}
-
 
160
		if(!itemIdQuantityAvailabilities.isEmpty()){
-
 
161
			// itemIdQuantity request is not valid
-
 
162
			LOGGER.error("Requested quantities should not be greater than currently available quantities {}", itemIdQuantityAvailabilities);
-
 
163
			return "error";
-
 
164
		}
-
 
165
		
-
 
166
		if(!lineItemPrice.isEmpty()){
-
 
167
			// given fofo line item price must be greater than zero
-
 
168
			LOGGER.error("requested itemId's selling price must greater thant 0");
-
 
169
			return "error";
-
 
170
		}
-
 
171
		
-
 
172
		Set<Integer> invalidItemIdSerialNumbers = new HashSet<>();
-
 
173
		Map<Integer, Set<String>> itemIdSerialNumbers = new HashMap<>();
-
 
174
		List<InventoryItem> inventoryItems = inventoryItemRepository.selectByFofoIdItemIds(fofoDetails.getFofoId(), itemIds);
-
 
175
		if(inventoryItems.isEmpty()){
-
 
176
			// invalid item ids
-
 
177
			LOGGER.error("Requested itemId's are not available in inventoryItem");
-
 
178
			return "error";
-
 
179
		}
47
		
180
		
-
 
181
		for(InventoryItem inventoryItem : inventoryItems){
-
 
182
			for(CustomFofoLineItem fofoLineItem : fofoLineItems){
-
 
183
				if(inventoryItem.getItemId() == fofoLineItem.getItemId()){
-
 
184
					if(fofoLineItem.getSerialNumbers().isEmpty()){
-
 
185
						if(!(inventoryItem.getSerialNumber() == null && inventoryItem.getSerialNumber().equals(""))){
-
 
186
							invalidItemIdSerialNumbers.add(inventoryItem.getItemId());
-
 
187
						}
-
 
188
					}
-
 
189
					if(!fofoLineItem.getSerialNumbers().isEmpty()){
-
 
190
						if(!fofoLineItem.getSerialNumbers().contains(inventoryItem.getSerialNumber())){
-
 
191
							if(!itemIdSerialNumbers.containsKey(fofoLineItem.getItemId())){
-
 
192
								Set<String> serialNumbers = new HashSet<>();
-
 
193
								serialNumbers.add(inventoryItem.getSerialNumber());
-
 
194
								itemIdSerialNumbers.put(fofoLineItem.getItemId(), serialNumbers);
-
 
195
							}else{
-
 
196
								itemIdSerialNumbers.get(fofoLineItem.getItemId()).add(inventoryItem.getSerialNumber());
-
 
197
							}
-
 
198
						}
-
 
199
					}
-
 
200
				}
-
 
201
			}
-
 
202
		}
-
 
203
		
-
 
204
		if(!invalidItemIdSerialNumbers.isEmpty()){
-
 
205
			LOGGER.error("Invalid itemId's serialNumbers {}", invalidItemIdSerialNumbers);
-
 
206
			// itemId's are serialized you are saying these are not serialized
-
 
207
			return "error";
-
 
208
		}
-
 
209
		
-
 
210
		if(!itemIdSerialNumbers.isEmpty()){
-
 
211
			LOGGER.error("Invalid itemId's serialNumbers {}", itemIdSerialNumbers);
-
 
212
			// itemId's are non serialized you are saying these are serialized
-
 
213
			return "error";
-
 
214
		}
-
 
215
		InvoiceNumberGenerationSequence invoiceNumberGenerationSequence = null;
-
 
216
		try{
-
 
217
			invoiceNumberGenerationSequence = invoiceNumberGenerationSequenceRepository.selectByFofoId(fofoDetails.getFofoId());
-
 
218
			invoiceNumberGenerationSequence.setSequence(invoiceNumberGenerationSequence.getSequence() + 1);
-
 
219
			invoiceNumberGenerationSequenceRepository.persist(invoiceNumberGenerationSequence);
-
 
220
		}catch(ProfitMandiBusinessException profitMandiBusinessException){
-
 
221
			invoiceNumberGenerationSequence = new InvoiceNumberGenerationSequence();
-
 
222
			invoiceNumberGenerationSequence.setFofoId(fofoDetails.getFofoId());
-
 
223
			invoiceNumberGenerationSequence.setPrefix("INVOICE");
-
 
224
			invoiceNumberGenerationSequenceRepository.persist(invoiceNumberGenerationSequence);
-
 
225
		}
-
 
226
		
-
 
227
		CustomCustomer customCustomer = createOrderRequest.getCustomer();
-
 
228
		
-
 
229
		if(!StringUtils.isValidEmailAddress(customCustomer.getEmailId())){
-
 
230
			LOGGER.error("invalid customer emailId {} ", customCustomer.getEmailId());
-
 
231
			return "error";
-
 
232
		}
-
 
233
		
-
 
234
		if(!StringUtils.isValidMobile(customCustomer.getMobileNumber())){
-
 
235
			LOGGER.error("invalid customer mobileNumber {} ", customCustomer.getMobileNumber());
-
 
236
			return "error";
-
 
237
		}
-
 
238
		
-
 
239
		Address address = this.createAddress(customCustomer.getAddress());
-
 
240
		addressRepository.persist(address);
-
 
241
		
-
 
242
		
-
 
243
		Customer customer = null;
-
 
244
		try{
-
 
245
			customer = customerRepository.selectByEmailIdAndMobileNumber(customCustomer.getEmailId(), customCustomer.getMobileNumber());
-
 
246
		}catch(ProfitMandiBusinessException profitMandiBusinessException){
-
 
247
			LOGGER.error("Error : ", profitMandiBusinessException);
-
 
248
			customer = new Customer();
-
 
249
			customer.setEmailId(customCustomer.getEmailId());
-
 
250
			customer.setMobileNumber(customCustomer.getMobileNumber());
-
 
251
			customer.setAddressId(address.getId());
-
 
252
			customerRepository.persist(customer);
-
 
253
		}
-
 
254
		
-
 
255
		
-
 
256
			/*InvoiceNumberGenerationSequence invoiceNumberGenerationSequence = */
-
 
257
		
-
 
258
		
-
 
259
		FofoOrder fofoOrder = new FofoOrder();
-
 
260
		fofoOrder.setCustomerId(customer.getId());
-
 
261
		fofoOrder.setFofoId(fofoDetails.getFofoId());
-
 
262
		fofoOrder.setInvoiceNumber(invoiceNumberGenerationSequence.getPrefix() + invoiceNumberGenerationSequence.getSequence());
-
 
263
		fofoOrder.setTotalAmount(totalAmount);
-
 
264
		fofoOrderRepository.persist(fofoOrder);
-
 
265
		
-
 
266
		for(CustomPaymentOption customPaymentOption : createOrderRequest.getPaymentOptions()){
-
 
267
			PaymentOption paymentOption = new PaymentOption();
-
 
268
			paymentOption.setOrderId(fofoOrder.getId());
-
 
269
			paymentOption.setAmount(customPaymentOption.getAmount());
-
 
270
			paymentOption.setType(customPaymentOption.getType());
-
 
271
			paymentOptionRepository.persist(paymentOption);
-
 
272
		}
-
 
273
		
-
 
274
		List<Order> orders = orderRepository.selectByRetailerIdItemIds(fofoDetails.getFofoId(), itemIds);
-
 
275
		
-
 
276
		Set<Item> items = new HashSet<>(itemIds.size());
-
 
277
		for(Order order : orders){
-
 
278
			LineItem lineItem = order.getLineItem();
-
 
279
			items.add(lineItem.getItem());
-
 
280
		}
-
 
281
		
-
 
282
		if(items.size() != itemIds.size()){
-
 
283
			LOGGER.error("Requested ItemIds not found in catalog");
-
 
284
			// invalid itemIds 
-
 
285
			return "error";
-
 
286
		}
-
 
287
		
-
 
288
		Map<Integer, Map<String, String>> itemIdDetails = this.toMap(items);
-
 
289
		
-
 
290
		for(CustomFofoLineItem customFofoLineItem : createOrderRequest.getFofoLineItems()){
-
 
291
			FofoLineItem fofoLineItem = new FofoLineItem();
-
 
292
			fofoLineItem.setItemId(customFofoLineItem.getItemId());
-
 
293
			fofoLineItem.setQuantity(customFofoLineItem.getQuantity());
-
 
294
			fofoLineItem.setSellingPrice(customFofoLineItem.getSellingPrice() * customFofoLineItem.getQuantity());
-
 
295
			fofoLineItem.setOrderId(fofoOrder.getId());
-
 
296
			fofoLineItem.setDp(customFofoLineItem.getSellingPrice());
-
 
297
			Map<String, String> itemIdDetail = itemIdDetails.get(customFofoLineItem.getItemId());
-
 
298
			fofoLineItem.setBrand(itemIdDetail.get(ProfitMandiConstants.BRAND));
-
 
299
			fofoLineItem.setModelName(itemIdDetail.get(ProfitMandiConstants.MODEL_NAME));
-
 
300
			fofoLineItem.setModelNumber(itemIdDetail.get(ProfitMandiConstants.MODEL_NUMBER));
-
 
301
			fofoLineItem.setColor(itemIdDetail.get(ProfitMandiConstants.COLOR));
-
 
302
			fofoLineItemRepository.persist(fofoLineItem);
-
 
303
			LOGGER.info("\n\n");
-
 
304
			if(!customFofoLineItem.getSerialNumbers().isEmpty()){
-
 
305
				for(String serialNumber : customFofoLineItem.getSerialNumbers()){
-
 
306
					FofoLineItemSerialNumber fofoLineItemSerialNumber = new FofoLineItemSerialNumber();
-
 
307
					fofoLineItemSerialNumber.setFofoLineItemId(fofoLineItem.getId());
-
 
308
					fofoLineItemSerialNumber.setSerialNumber(serialNumber);
-
 
309
					fofoLineItemSerialNumberRepository.persist(fofoLineItemSerialNumber);
-
 
310
				}
-
 
311
			}
-
 
312
			
-
 
313
			
-
 
314
			
-
 
315
			
-
 
316
			for(InventoryItem inventoryItem : inventoryItems){
-
 
317
				if(inventoryItem.getItemId() == fofoLineItem.getItemId()){
-
 
318
					if(inventoryItem.getSerialNumber() == null || inventoryItem.getSerialNumber().isEmpty()){
-
 
319
						if(fofoLineItem.getQuantity() > 0)
-
 
320
						if(fofoLineItem.getQuantity() <= inventoryItem.getGoodQuantity()){
-
 
321
							inventoryItem.setGoodQuantity(inventoryItem.getGoodQuantity() - fofoLineItem.getQuantity());
-
 
322
							inventoryItem.setLastScanType(ScanType.SALE);
-
 
323
							inventoryItemRepository.persist(inventoryItem);
-
 
324
							ScanRecord scanRecord = new ScanRecord();
-
 
325
							scanRecord.setInventoryItemId(inventoryItem.getId());
-
 
326
							scanRecord.setFofoId(fofoDetails.getFofoId());
-
 
327
							scanRecord.setQuantity(fofoLineItem.getQuantity());
-
 
328
							scanRecord.setType(ScanType.SALE);
-
 
329
							scanRecordRepository.persist(scanRecord);
-
 
330
						}else{
-
 
331
							int availableGoodQuantity = inventoryItem.getGoodQuantity();
-
 
332
							inventoryItem.setGoodQuantity(0);
-
 
333
							fofoLineItem.setQuantity(fofoLineItem.getQuantity() - availableGoodQuantity);
-
 
334
							inventoryItem.setLastScanType(ScanType.SALE);
-
 
335
							inventoryItemRepository.persist(inventoryItem);
-
 
336
							ScanRecord scanRecord = new ScanRecord();
-
 
337
							scanRecord.setInventoryItemId(inventoryItem.getId());
-
 
338
							scanRecord.setFofoId(fofoDetails.getFofoId());
-
 
339
							scanRecord.setQuantity(availableGoodQuantity);
-
 
340
							scanRecord.setType(ScanType.SALE);
-
 
341
							scanRecordRepository.persist(scanRecord);
-
 
342
						}
-
 
343
					}else{
-
 
344
						inventoryItem.setGoodQuantity(0);
-
 
345
						inventoryItem.setLastScanType(ScanType.SALE);
-
 
346
						inventoryItemRepository.persist(inventoryItem);
-
 
347
						ScanRecord scanRecord = new ScanRecord();
-
 
348
						scanRecord.setInventoryItemId(inventoryItem.getId());
-
 
349
						scanRecord.setFofoId(fofoDetails.getFofoId());
-
 
350
						scanRecord.setQuantity(1);
-
 
351
						scanRecord.setType(ScanType.SALE);
-
 
352
						scanRecordRepository.persist(scanRecord);
-
 
353
					}
-
 
354
				}
-
 
355
			}
-
 
356
					
-
 
357
		}
48
		return null;
358
		return null;
49
	}
359
	}
50
	
360
	
-
 
361
	
-
 
362
	private Map<Integer, Map<String, String>> toMap(Set<Item> items){
-
 
363
		Map<Integer, Map<String, String>> map = new HashMap<>();
-
 
364
		for(Item item : items){
-
 
365
			Map<String, String> detailMap = new HashMap<>();
-
 
366
			detailMap.put(ProfitMandiConstants.BRAND, item.getBrand());
-
 
367
			detailMap.put(ProfitMandiConstants.MODEL_NAME, item.getModelName());
-
 
368
			detailMap.put(ProfitMandiConstants.MODEL_NUMBER, item.getModelNumber());
-
 
369
			detailMap.put(ProfitMandiConstants.COLOR, item.getColor());
-
 
370
			map.put(item.getId(), detailMap);
-
 
371
		}
-
 
372
		return map;
-
 
373
	}
-
 
374
	
-
 
375
	private Address createAddress(CustomAddress customAddress){
-
 
376
		Address address = new Address();
-
 
377
		address.setName(customAddress.getName());
-
 
378
		address.setLine1(customAddress.getLine1());
-
 
379
		address.setLine2(customAddress.getLine2());
-
 
380
		address.setLandmark(customAddress.getLandmark());
-
 
381
		address.setCity(customAddress.getCity());
-
 
382
		address.setPinCode(customAddress.getPinCode());
-
 
383
		address.setState(customAddress.getState());
-
 
384
		address.setCountry(customAddress.getCountry());
-
 
385
		address.setPhoneNumber(customAddress.getPhoneNumber());
-
 
386
		address.setEnabled(true);
-
 
387
		return address;
-
 
388
	}
-
 
389
	
-
 
390
	private void validateCreateOrderRequest(CreateOrderRequest createOrderRequest){
-
 
391
		Set<CustomPaymentOption> customPaymentOptions = createOrderRequest.getPaymentOptions();
-
 
392
		
-
 
393
	}
-
 
394
	
-
 
395
	
51
	private void validatePaymentOptions(Set<CustomPaymentOption> customPaymentOptions, float totalAmount) throws ProfitMandiBusinessException
396
	private void validatePaymentOptionsAndTotalAmount(Set<CustomPaymentOption> customPaymentOptions, float totalAmount) throws ProfitMandiBusinessException
52
	{
397
	{
53
		float calculatedAmount = 0;
398
		float calculatedAmount = 0;
54
		Set<String> paymentOptionTypes = new HashSet<>();
399
		Set<String> paymentOptionTypes = new HashSet<>();
55
		for(CustomPaymentOption customPaymentOption : customPaymentOptions){
400
		for(CustomPaymentOption customPaymentOption : customPaymentOptions){
56
			if(!paymentOptionTypes.add(customPaymentOption.getType().name())){
401
			if(paymentOptionTypes.contains(customPaymentOption.getType().name())){
57
				throw new ProfitMandiBusinessException(ProfitMandiConstants.PAYMENT_OPTION_TYPE, customPaymentOption.getType().name(), "");
402
				throw new ProfitMandiBusinessException(ProfitMandiConstants.PAYMENT_OPTION_TYPE, customPaymentOption.getType().name(), "");
-
 
403
			}else{
-
 
404
				paymentOptionTypes.add(customPaymentOption.getType().name());
-
 
405
				calculatedAmount = calculatedAmount + customPaymentOption.getAmount();
58
			}
406
			}
59
			calculatedAmount = calculatedAmount + customPaymentOption.getAmount();
-
 
60
		}
407
		}
61
		if(calculatedAmount != totalAmount){
408
		if(calculatedAmount != totalAmount){
62
			throw new ProfitMandiBusinessException(ProfitMandiConstants.PAYMENT_OPTION_CALCULATED_AMOUNT, calculatedAmount, "");
409
			throw new ProfitMandiBusinessException(ProfitMandiConstants.PAYMENT_OPTION_CALCULATED_AMOUNT, calculatedAmount, "");
63
		}
410
		}
64
	}
411
	}