Subversion Repositories SmartDukaan

Rev

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

Rev 21701 Rev 21711
Line 12... Line 12...
12
 
12
 
13
import javax.servlet.http.HttpServletRequest;
13
import javax.servlet.http.HttpServletRequest;
14
import javax.servlet.http.HttpServletResponse;
14
import javax.servlet.http.HttpServletResponse;
15
import javax.transaction.Transactional;
15
import javax.transaction.Transactional;
16
 
16
 
17
import org.apache.commons.lang.WordUtils;
-
 
18
import org.slf4j.Logger;
17
import org.slf4j.Logger;
19
import org.slf4j.LoggerFactory;
18
import org.slf4j.LoggerFactory;
20
import org.springframework.beans.factory.annotation.Autowired;
19
import org.springframework.beans.factory.annotation.Autowired;
21
import org.springframework.core.io.InputStreamResource;
20
import org.springframework.core.io.InputStreamResource;
22
import org.springframework.http.HttpHeaders;
21
import org.springframework.http.HttpHeaders;
Line 40... Line 39...
40
import com.spice.profitmandi.common.util.PdfUtils;
39
import com.spice.profitmandi.common.util.PdfUtils;
41
import com.spice.profitmandi.common.util.StringUtils;
40
import com.spice.profitmandi.common.util.StringUtils;
42
import com.spice.profitmandi.dao.entity.Address;
41
import com.spice.profitmandi.dao.entity.Address;
43
import com.spice.profitmandi.dao.entity.CurrentInventorySnapshot;
42
import com.spice.profitmandi.dao.entity.CurrentInventorySnapshot;
44
import com.spice.profitmandi.dao.entity.Customer;
43
import com.spice.profitmandi.dao.entity.Customer;
-
 
44
import com.spice.profitmandi.dao.entity.CustomerAddress;
45
import com.spice.profitmandi.dao.entity.FofoLineItem;
45
import com.spice.profitmandi.dao.entity.FofoLineItem;
46
import com.spice.profitmandi.dao.entity.FofoLineItemSerialNumber;
46
import com.spice.profitmandi.dao.entity.FofoLineItemSerialNumber;
47
import com.spice.profitmandi.dao.entity.FofoOrder;
47
import com.spice.profitmandi.dao.entity.FofoOrder;
48
import com.spice.profitmandi.dao.entity.InventoryItem;
48
import com.spice.profitmandi.dao.entity.InventoryItem;
49
import com.spice.profitmandi.dao.entity.InvoiceNumberGenerationSequence;
49
import com.spice.profitmandi.dao.entity.InvoiceNumberGenerationSequence;
Line 55... Line 55...
55
import com.spice.profitmandi.dao.entity.ScanRecord;
55
import com.spice.profitmandi.dao.entity.ScanRecord;
56
import com.spice.profitmandi.dao.entity.User;
56
import com.spice.profitmandi.dao.entity.User;
57
import com.spice.profitmandi.dao.enumuration.ScanType;
57
import com.spice.profitmandi.dao.enumuration.ScanType;
58
import com.spice.profitmandi.dao.repository.AddressRepository;
58
import com.spice.profitmandi.dao.repository.AddressRepository;
59
import com.spice.profitmandi.dao.repository.CurrentInventorySnapshotRepository;
59
import com.spice.profitmandi.dao.repository.CurrentInventorySnapshotRepository;
-
 
60
import com.spice.profitmandi.dao.repository.CustomerAddressRepository;
60
import com.spice.profitmandi.dao.repository.CustomerRepository;
61
import com.spice.profitmandi.dao.repository.CustomerRepository;
61
import com.spice.profitmandi.dao.repository.FofoLineItemRepository;
62
import com.spice.profitmandi.dao.repository.FofoLineItemRepository;
62
import com.spice.profitmandi.dao.repository.FofoLineItemSerialNumberRepository;
63
import com.spice.profitmandi.dao.repository.FofoLineItemSerialNumberRepository;
63
import com.spice.profitmandi.dao.repository.FofoOrderRepository;
64
import com.spice.profitmandi.dao.repository.FofoOrderRepository;
64
import com.spice.profitmandi.dao.repository.InventoryItemRepository;
65
import com.spice.profitmandi.dao.repository.InventoryItemRepository;
Line 128... Line 129...
128
	
129
	
129
	@Autowired
130
	@Autowired
130
	RetailerRegisteredAddressRepository retailerRegisteredAddressRepository;
131
	RetailerRegisteredAddressRepository retailerRegisteredAddressRepository;
131
	
132
	
132
	@Autowired
133
	@Autowired
-
 
134
	CustomerAddressRepository customerAddressRepository;
-
 
135
	
-
 
136
	@Autowired
133
	MVCResponseSender mvcResponseSender;
137
	MVCResponseSender mvcResponseSender;
134
	
138
	
135
	@Autowired
139
	@Autowired
136
	CookiesFetcher cookiesFetcher;
140
	CookiesFetcher cookiesFetcher;
137
	
141
	
Line 210... Line 214...
210
			// invalid item ids
214
			// invalid item ids
211
			LOGGER.error("Requested itemId's are not available in inventoryItem");
215
			LOGGER.error("Requested itemId's are not available in inventoryItem");
212
			return "error";
216
			return "error";
213
		}
217
		}
214
		
218
		
-
 
219
		Map<Integer, Float> itemIdPriceDropAmount = new HashMap<>();
-
 
220
		
215
		for(InventoryItem inventoryItem : inventoryItems){
221
		for(InventoryItem inventoryItem : inventoryItems){
216
			for(CustomFofoLineItem fofoLineItem : fofoLineItems){
222
			for(CustomFofoLineItem fofoLineItem : fofoLineItems){
217
				if(inventoryItem.getItemId() == fofoLineItem.getItemId()){
223
				if(inventoryItem.getItemId() == fofoLineItem.getItemId()){
218
					if(fofoLineItem.getSerialNumbers().isEmpty()){
224
					if(fofoLineItem.getSerialNumbers().isEmpty()){
219
						if(!(inventoryItem.getSerialNumber() == null && inventoryItem.getSerialNumber().equals(""))){
225
						if(!(inventoryItem.getSerialNumber() == null && inventoryItem.getSerialNumber().equals(""))){
Line 229... Line 235...
229
							}else{
235
							}else{
230
								itemIdSerialNumbers.get(fofoLineItem.getItemId()).add(inventoryItem.getSerialNumber());
236
								itemIdSerialNumbers.get(fofoLineItem.getItemId()).add(inventoryItem.getSerialNumber());
231
							}
237
							}
232
						}
238
						}
233
					}
239
					}
-
 
240
					itemIdPriceDropAmount.put(inventoryItem.getItemId(), inventoryItem.getUnitPrice() - inventoryItem.getPriceDropAmount());
234
				}
241
				}
235
			}
242
			}
236
		}
243
		}
237
		
244
		
238
		if(!invalidItemIdSerialNumbers.isEmpty()){
245
		if(!invalidItemIdSerialNumbers.isEmpty()){
Line 268... Line 275...
268
		if(!StringUtils.isValidMobile(customCustomer.getMobileNumber())){
275
		if(!StringUtils.isValidMobile(customCustomer.getMobileNumber())){
269
			LOGGER.error("invalid customer mobileNumber {} ", customCustomer.getMobileNumber());
276
			LOGGER.error("invalid customer mobileNumber {} ", customCustomer.getMobileNumber());
270
			return "error";
277
			return "error";
271
		}
278
		}
272
		
279
		
273
		Address address = this.createAddress(customCustomer.getAddress());
-
 
274
		addressRepository.persist(address);
-
 
275
		
-
 
276
		
-
 
277
		Customer customer = null;
280
		Customer customer = null;
278
		try{
281
		try{
279
			customer = customerRepository.selectByEmailIdAndMobileNumber(customCustomer.getEmailId(), customCustomer.getMobileNumber());
282
			customer = customerRepository.selectByEmailIdAndMobileNumber(customCustomer.getEmailId(), customCustomer.getMobileNumber());
280
		}catch(ProfitMandiBusinessException profitMandiBusinessException){
283
		}catch(ProfitMandiBusinessException profitMandiBusinessException){
281
			LOGGER.error("Error : ", profitMandiBusinessException);
284
			LOGGER.error("Error : ", profitMandiBusinessException);
282
			customer = new Customer();
285
			customer = new Customer();
283
			customCustomer.setName(customCustomer.getName());
286
			customCustomer.setName(customCustomer.getName());
284
			customer.setEmailId(customCustomer.getEmailId());
287
			customer.setEmailId(customCustomer.getEmailId());
285
			customer.setMobileNumber(customCustomer.getMobileNumber());
288
			customer.setMobileNumber(customCustomer.getMobileNumber());
286
			customer.setAddressId(address.getId());
-
 
287
			customerRepository.persist(customer);
289
			customerRepository.persist(customer);
288
		}
290
		}
289
		
-
 
-
 
291
		CustomerAddress customerAddress = this.createCustomerAddress(customCustomer.getAddress());
-
 
292
		customerAddress.setCustomerId(customer.getId());
-
 
293
		customerAddressRepository.persist(customerAddress);
290
		
294
		
291
			/*InvoiceNumberGenerationSequence invoiceNumberGenerationSequence = */
295
			/*InvoiceNumberGenerationSequence invoiceNumberGenerationSequence = */
292
		
296
		
293
		
297
		
294
		FofoOrder fofoOrder = new FofoOrder();
298
		FofoOrder fofoOrder = new FofoOrder();
Line 329... Line 333...
329
			fofoLineItem.setSellingPrice(customFofoLineItem.getSellingPrice());
333
			fofoLineItem.setSellingPrice(customFofoLineItem.getSellingPrice());
330
			fofoLineItem.setOrderId(fofoOrder.getId());
334
			fofoLineItem.setOrderId(fofoOrder.getId());
331
			fofoLineItem.setDp(customFofoLineItem.getSellingPrice());
335
			fofoLineItem.setDp(customFofoLineItem.getSellingPrice());
332
			fofoLineItem.setTax(0);
336
			fofoLineItem.setTax(0);
333
			fofoLineItem.setTaxRate(0);
337
			fofoLineItem.setTaxRate(0);
-
 
338
			fofoLineItem.setCost(itemIdPriceDropAmount.get(customFofoLineItem.getItemId()));
334
			Map<String, String> itemIdDetail = itemIdDetails.get(customFofoLineItem.getItemId());
339
			Map<String, String> itemIdDetail = itemIdDetails.get(customFofoLineItem.getItemId());
335
			fofoLineItem.setBrand(itemIdDetail.get(ProfitMandiConstants.BRAND));
340
			fofoLineItem.setBrand(itemIdDetail.get(ProfitMandiConstants.BRAND));
336
			fofoLineItem.setModelName(itemIdDetail.get(ProfitMandiConstants.MODEL_NAME));
341
			fofoLineItem.setModelName(itemIdDetail.get(ProfitMandiConstants.MODEL_NAME));
337
			fofoLineItem.setModelNumber(itemIdDetail.get(ProfitMandiConstants.MODEL_NUMBER));
342
			fofoLineItem.setModelNumber(itemIdDetail.get(ProfitMandiConstants.MODEL_NUMBER));
338
			fofoLineItem.setColor(itemIdDetail.get(ProfitMandiConstants.COLOR));
343
			fofoLineItem.setColor(itemIdDetail.get(ProfitMandiConstants.COLOR));
Line 407... Line 412...
407
			map.put(item.getId(), detailMap);
412
			map.put(item.getId(), detailMap);
408
		}
413
		}
409
		return map;
414
		return map;
410
	}
415
	}
411
	
416
	
412
	private Address createAddress(CustomAddress customAddress){
417
	/*private Address createAddress(CustomAddress customAddress){
413
		Address address = new Address();
418
		Address address = new Address();
414
		address.setName(customAddress.getName());
419
		address.setName(customAddress.getName());
415
		address.setLine1(customAddress.getLine1());
420
		address.setLine1(customAddress.getLine1());
416
		address.setLine2(customAddress.getLine2());
421
		address.setLine2(customAddress.getLine2());
417
		address.setLandmark(customAddress.getLandmark());
422
		address.setLandmark(customAddress.getLandmark());
Line 420... Line 425...
420
		address.setState(customAddress.getState());
425
		address.setState(customAddress.getState());
421
		address.setCountry(customAddress.getCountry());
426
		address.setCountry(customAddress.getCountry());
422
		address.setPhoneNumber(customAddress.getPhoneNumber());
427
		address.setPhoneNumber(customAddress.getPhoneNumber());
423
		address.setEnabled(true);
428
		address.setEnabled(true);
424
		return address;
429
		return address;
-
 
430
	}*/
-
 
431
	
-
 
432
	private CustomerAddress createCustomerAddress(CustomAddress customAddress){
-
 
433
		CustomerAddress customerAddress = new CustomerAddress();
-
 
434
		customerAddress.setName(customAddress.getName());
-
 
435
		customerAddress.setLine1(customAddress.getLine1());
-
 
436
		customerAddress.setLine2(customAddress.getLine2());
-
 
437
		customerAddress.setLandmark(customAddress.getLandmark());
-
 
438
		customerAddress.setCity(customAddress.getCity());
-
 
439
		customerAddress.setPinCode(customAddress.getPinCode());
-
 
440
		customerAddress.setState(customAddress.getState());
-
 
441
		customerAddress.setCountry(customAddress.getCountry());
-
 
442
		customerAddress.setPhoneNumber(customAddress.getPhoneNumber());
-
 
443
		return customerAddress;
425
	}
444
	}
426
	
445
	
427
	private CustomAddress createCustomAddress(Address address){
446
	private CustomAddress createCustomAddress(Address address){
428
		CustomAddress customAddress = new CustomAddress();
447
		CustomAddress customAddress = new CustomAddress();
429
		customAddress.setName(address.getName());
448
		customAddress.setName(address.getName());
Line 436... Line 455...
436
		customAddress.setCountry(address.getCountry());
455
		customAddress.setCountry(address.getCountry());
437
		customAddress.setPhoneNumber(address.getPhoneNumber());
456
		customAddress.setPhoneNumber(address.getPhoneNumber());
438
		return customAddress;
457
		return customAddress;
439
	}
458
	}
440
	
459
	
-
 
460
	private CustomAddress createCustomAddress(CustomerAddress customerAddress){
-
 
461
		CustomAddress customAddress = new CustomAddress();
-
 
462
		customAddress.setName(customerAddress.getName());
-
 
463
		customAddress.setLine1(customerAddress.getLine1());
-
 
464
		customAddress.setLine2(customerAddress.getLine2());
-
 
465
		customAddress.setLandmark(customerAddress.getLandmark());
-
 
466
		customAddress.setCity(customerAddress.getCity());
-
 
467
		customAddress.setPinCode(customerAddress.getPinCode());
-
 
468
		customAddress.setState(customerAddress.getState());
-
 
469
		customAddress.setCountry(customerAddress.getCountry());
-
 
470
		customAddress.setPhoneNumber(customerAddress.getPhoneNumber());
-
 
471
		return customAddress;
-
 
472
	}
-
 
473
	
441
	private void validatePaymentOptionsAndTotalAmount(Set<CustomPaymentOption> customPaymentOptions, float totalAmount) throws ProfitMandiBusinessException
474
	private void validatePaymentOptionsAndTotalAmount(Set<CustomPaymentOption> customPaymentOptions, float totalAmount) throws ProfitMandiBusinessException
442
	{
475
	{
443
		float calculatedAmount = 0;
476
		float calculatedAmount = 0;
444
		Set<String> paymentOptionTypes = new HashSet<>();
477
		Set<String> paymentOptionTypes = new HashSet<>();
445
		for(CustomPaymentOption customPaymentOption : customPaymentOptions){
478
		for(CustomPaymentOption customPaymentOption : customPaymentOptions){
Line 470... Line 503...
470
		Customer customer = customerRepository.selectById(fofoOrder.getCustomerId());
503
		Customer customer = customerRepository.selectById(fofoOrder.getCustomerId());
471
		CustomCustomer customCustomer = new CustomCustomer();
504
		CustomCustomer customCustomer = new CustomCustomer();
472
		customCustomer.setName(customer.getName());
505
		customCustomer.setName(customer.getName());
473
		customCustomer.setEmailId(customer.getEmailId());
506
		customCustomer.setEmailId(customer.getEmailId());
474
		customCustomer.setMobileNumber(customer.getMobileNumber());
507
		customCustomer.setMobileNumber(customer.getMobileNumber());
475
		Address customerAddress = addressRepository.selectById(customer.getAddressId()); 
508
		CustomerAddress customerAddress = customerAddressRepository.selectById(fofoOrder.getCustomerAddressId()); 
476
		customCustomer.setAddress(this.createCustomAddress(customerAddress));
509
		customCustomer.setAddress(this.createCustomAddress(customerAddress));
477
		pdfModel.setCustomer(customCustomer);
510
		pdfModel.setCustomer(customCustomer);
478
		pdfModel.setInvoiceNumber(fofoOrder.getInvoiceNumber());
511
		pdfModel.setInvoiceNumber(fofoOrder.getInvoiceNumber());
479
		pdfModel.setTotalAmount(fofoOrder.getTotalAmount());
512
		pdfModel.setTotalAmount(fofoOrder.getTotalAmount());
480
		
513