Subversion Repositories SmartDukaan

Rev

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

Rev 26637 Rev 26817
Line 34... Line 34...
34
import com.spice.profitmandi.common.model.CustomInsurancePolicy;
34
import com.spice.profitmandi.common.model.CustomInsurancePolicy;
35
import com.spice.profitmandi.common.model.CustomOrderItem;
35
import com.spice.profitmandi.common.model.CustomOrderItem;
36
import com.spice.profitmandi.common.model.CustomPaymentOption;
36
import com.spice.profitmandi.common.model.CustomPaymentOption;
37
import com.spice.profitmandi.common.model.CustomRetailer;
37
import com.spice.profitmandi.common.model.CustomRetailer;
38
import com.spice.profitmandi.common.model.FoiBadReturnRequest;
38
import com.spice.profitmandi.common.model.FoiBadReturnRequest;
39
import com.spice.profitmandi.common.model.GadgetCopsInsuranceModel;
-
 
40
import com.spice.profitmandi.common.model.GstRate;
39
import com.spice.profitmandi.common.model.GstRate;
41
import com.spice.profitmandi.common.model.InsuranceModel;
40
import com.spice.profitmandi.common.model.InsuranceModel;
42
import com.spice.profitmandi.common.model.ItemIdQuantityAvailability;
41
import com.spice.profitmandi.common.model.ItemIdQuantityAvailability;
43
import com.spice.profitmandi.common.model.PdfModel;
42
import com.spice.profitmandi.common.model.PdfModel;
44
import com.spice.profitmandi.common.model.PriceModel;
43
import com.spice.profitmandi.common.model.PriceModel;
Line 50... Line 49...
50
import com.spice.profitmandi.common.util.Utils;
49
import com.spice.profitmandi.common.util.Utils;
51
import com.spice.profitmandi.dao.entity.catalog.Item;
50
import com.spice.profitmandi.dao.entity.catalog.Item;
52
import com.spice.profitmandi.dao.entity.catalog.TagListing;
51
import com.spice.profitmandi.dao.entity.catalog.TagListing;
53
import com.spice.profitmandi.dao.entity.dtr.InsurancePolicy;
52
import com.spice.profitmandi.dao.entity.dtr.InsurancePolicy;
54
import com.spice.profitmandi.dao.entity.dtr.PaymentOptionTransaction;
53
import com.spice.profitmandi.dao.entity.dtr.PaymentOptionTransaction;
55
import com.spice.profitmandi.dao.entity.dtr.PolicyNumberGenerationSequence;
-
 
56
import com.spice.profitmandi.dao.entity.dtr.Retailer;
54
import com.spice.profitmandi.dao.entity.dtr.Retailer;
57
import com.spice.profitmandi.dao.entity.dtr.User;
55
import com.spice.profitmandi.dao.entity.dtr.User;
58
import com.spice.profitmandi.dao.entity.fofo.CurrentInventorySnapshot;
56
import com.spice.profitmandi.dao.entity.fofo.CurrentInventorySnapshot;
59
import com.spice.profitmandi.dao.entity.fofo.Customer;
57
import com.spice.profitmandi.dao.entity.fofo.Customer;
60
import com.spice.profitmandi.dao.entity.fofo.CustomerAddress;
58
import com.spice.profitmandi.dao.entity.fofo.CustomerAddress;
Line 77... Line 75...
77
import com.spice.profitmandi.dao.enumuration.dtr.PaymentOptionReferenceType;
75
import com.spice.profitmandi.dao.enumuration.dtr.PaymentOptionReferenceType;
78
import com.spice.profitmandi.dao.enumuration.fofo.ReturnType;
76
import com.spice.profitmandi.dao.enumuration.fofo.ReturnType;
79
import com.spice.profitmandi.dao.enumuration.fofo.ScanType;
77
import com.spice.profitmandi.dao.enumuration.fofo.ScanType;
80
import com.spice.profitmandi.dao.enumuration.fofo.SettlementType;
78
import com.spice.profitmandi.dao.enumuration.fofo.SettlementType;
81
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
79
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
-
 
80
import com.spice.profitmandi.dao.repository.catalog.StateGstRateRepository;
82
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
81
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
83
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
82
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
84
import com.spice.profitmandi.dao.repository.dtr.InsurancePolicyRepository;
83
import com.spice.profitmandi.dao.repository.dtr.InsurancePolicyRepository;
85
import com.spice.profitmandi.dao.repository.dtr.InsuranceProviderRepository;
84
import com.spice.profitmandi.dao.repository.dtr.InsuranceProviderRepository;
86
import com.spice.profitmandi.dao.repository.dtr.PaymentOptionTransactionRepository;
85
import com.spice.profitmandi.dao.repository.dtr.PaymentOptionTransactionRepository;
Line 123... Line 122...
123
	private static final Logger LOGGER = LogManager.getLogger(OrderServiceImpl.class);
122
	private static final Logger LOGGER = LogManager.getLogger(OrderServiceImpl.class);
124
 
123
 
125
	@Autowired
124
	@Autowired
126
	@Qualifier("fofoInventoryItemRepository")
125
	@Qualifier("fofoInventoryItemRepository")
127
	private InventoryItemRepository inventoryItemRepository;
126
	private InventoryItemRepository inventoryItemRepository;
-
 
127
	
-
 
128
	@Autowired
-
 
129
	private StateGstRateRepository stateGstRateRepository;
128
 
130
 
129
	@Autowired
131
	@Autowired
130
	private LiveDemoBillingRespository liveDemoBillingRespository;
132
	private LiveDemoBillingRespository liveDemoBillingRespository;
131
 
133
 
132
	@Autowired
134
	@Autowired
Line 245... Line 247...
245
	public int createOrder(CreateOrderRequest createOrderRequest, int fofoId, boolean accessoriesDeals)
247
	public int createOrder(CreateOrderRequest createOrderRequest, int fofoId, boolean accessoriesDeals)
246
			throws ProfitMandiBusinessException {
248
			throws ProfitMandiBusinessException {
247
		LOGGER.info("fofoId -- {} Order Request -- {}", fofoId, createOrderRequest);
249
		LOGGER.info("fofoId -- {} Order Request -- {}", fofoId, createOrderRequest);
248
		CustomCustomer customCustomer = createOrderRequest.getCustomer();
250
		CustomCustomer customCustomer = createOrderRequest.getCustomer();
249
 
251
 
250
		if (!StringUtils.isValidEmailAddress(customCustomer.getEmailId())) {
-
 
251
			LOGGER.error("invalid customer emailId {} ", customCustomer.getEmailId());
-
 
252
			throw new ProfitMandiBusinessException(ProfitMandiConstants.EMAIL_ID, customCustomer.getEmailId(),
-
 
253
					"VE_1016");
-
 
254
		}
-
 
255
 
-
 
256
		if (!StringUtils.isValidMobile(customCustomer.getMobileNumber())) {
-
 
257
			LOGGER.error("invalid customer mobileNumber {} ", customCustomer.getMobileNumber());
-
 
258
			throw new ProfitMandiBusinessException(ProfitMandiConstants.MOBILE_NUMBER, customCustomer.getMobileNumber(),
-
 
259
					"VE_1071");
-
 
260
		}
-
 
261
 
-
 
262
		if (!StringUtils.isValidGstNumber(customCustomer.getGstNumber())) {
252
		if (!StringUtils.isValidGstNumber(customCustomer.getGstNumber())) {
263
			LOGGER.error("invalid customer gstNumber {} ", customCustomer.getGstNumber());
253
			LOGGER.error("invalid customer gstNumber {} ", customCustomer.getGstNumber());
264
			throw new ProfitMandiBusinessException(ProfitMandiConstants.CUSTOMER_GST_NUMBER,
254
			throw new ProfitMandiBusinessException(ProfitMandiConstants.CUSTOMER_GST_NUMBER,
265
					customCustomer.getGstNumber(), "VE_1072");
255
					customCustomer.getGstNumber(), "VE_1072");
266
		}
256
		}
Line 464... Line 454...
464
 
454
 
465
		} else {
455
		} else {
466
			documentNumber = this.getInvoiceNumber(fofoId, fofoStoreCode);
456
			documentNumber = this.getInvoiceNumber(fofoId, fofoStoreCode);
467
		}
457
		}
468
 
458
 
469
		Customer customer = this.createAndGetCustomer(customCustomer);
459
		Customer customer = customerRepository.selectById(customCustomer.getCustomerId());
470
 
460
 
471
		CustomerAddress customerAddress = this.createCustomerAddress(customCustomer.getAddress(), customer.getId());
461
		CustomerAddress customerAddress = customer.getCustomerAddress().stream().filter(x->x.getId()==customCustomer.getCustomerAddressId())
-
 
462
				.findFirst().get();
472
 
463
 
473
		FofoOrder fofoOrder = this.createAndGetFofoOrder(customer.getId(), customCustomer.getGstNumber(), fofoId,
464
		FofoOrder fofoOrder = this.createAndGetFofoOrder(customer.getId(), customCustomer.getGstNumber(), fofoId,
474
				documentNumber, totalAmount, customerAddress.getId());
465
				documentNumber, totalAmount, customerAddress.getId());
475
 
466
 
476
		this.createPaymentOptions(fofoOrder, createOrderRequest.getPaymentOptions());
467
		this.createPaymentOptions(fofoOrder, createOrderRequest.getPaymentOptions());
Line 909... Line 900...
909
	private String getFofoStoreCode(int fofoId) throws ProfitMandiBusinessException {
900
	private String getFofoStoreCode(int fofoId) throws ProfitMandiBusinessException {
910
		FofoStore fofoStore = fofoStoreRepository.selectByRetailerId(fofoId);
901
		FofoStore fofoStore = fofoStoreRepository.selectByRetailerId(fofoId);
911
		return fofoStore.getCode();
902
		return fofoStore.getCode();
912
	}
903
	}
913
 
904
 
914
	private CustomerAddress createCustomerAddress(CustomAddress customAddress, int customerId) {
-
 
915
		CustomerAddress customerAddress = null;
-
 
916
		try {
-
 
917
			// CustomAddress customAddress = customCustomer.getAddress();
-
 
918
			customerAddress = customerAddressRepository.selectByParams(customAddress.getName(),
-
 
919
					customAddress.getLine1(), customAddress.getLine2(), customAddress.getLandmark(),
-
 
920
					customAddress.getCity(), customAddress.getPinCode(), customAddress.getState(),
-
 
921
					customAddress.getPhoneNumber(), customAddress.getCountry(), customerId);
-
 
922
		} catch (ProfitMandiBusinessException profitMandiBusinessException) {
-
 
923
			LOGGER.warn("Customer address not found with [{}]", customAddress);
-
 
924
			customerAddress = new CustomerAddress();
-
 
925
			this.setCustomerAddress(customerAddress, customAddress);
-
 
926
			customerAddress.setCustomerId(customerId);
-
 
927
			customerAddressRepository.persist(customerAddress);
-
 
928
		}
-
 
929
		return customerAddress;
-
 
930
	}
-
 
931
 
-
 
932
	private String getValidName(String name) {
905
	private String getValidName(String name) {
933
		return name != null ? name : "";
906
		return name != null ? name : "";
934
	}
907
	}
935
 
908
 
936
	private Set<String> toSerialNumbers(Set<FofoLineItem> fofoLineItems) {
909
	private Set<String> toSerialNumbers(Set<FofoLineItem> fofoLineItems) {
Line 1035... Line 1008...
1035
 
1008
 
1036
		Item item = itemMap.get(customFofoOrderItem.getItemId());
1009
		Item item = itemMap.get(customFofoOrderItem.getItemId());
1037
		Map<Integer, GstRate> itemIdStateTaxRateMap = null;
1010
		Map<Integer, GstRate> itemIdStateTaxRateMap = null;
1038
		Map<Integer, Float> itemIdIgstTaxRateMap = null;
1011
		Map<Integer, Float> itemIdIgstTaxRateMap = null;
1039
		if (stateId != null) {
1012
		if (stateId != null) {
1040
			itemIdStateTaxRateMap = Utils.getStateTaxRate(new ArrayList<>(itemMap.keySet()), stateId);
1013
			itemIdStateTaxRateMap = stateGstRateRepository.getStateTaxRate(new ArrayList<>(itemMap.keySet()), stateId);
1041
		} else {
1014
		} else {
1042
			itemIdIgstTaxRateMap = Utils.getIgstTaxRate(new ArrayList<>(itemMap.keySet()));
1015
			itemIdIgstTaxRateMap = stateGstRateRepository.getIgstTaxRate(new ArrayList<>(itemMap.keySet()));
1043
		}
1016
		}
1044
		for (InventoryItem inventoryItem : inventoryItems) {
1017
		for (InventoryItem inventoryItem : inventoryItems) {
1045
			if (stateId == null) {
1018
			if (stateId == null) {
1046
				fofoOrderItem.setIgstRate(itemIdIgstTaxRateMap.get(inventoryItem.getItemId()));
1019
				fofoOrderItem.setIgstRate(itemIdIgstTaxRateMap.get(inventoryItem.getItemId()));
1047
			} else {
1020
			} else {
Line 1096... Line 1069...
1096
		fofoOrder.setCustomerAddressId(customerAddressId);
1069
		fofoOrder.setCustomerAddressId(customerAddressId);
1097
		fofoOrderRepository.persist(fofoOrder);
1070
		fofoOrderRepository.persist(fofoOrder);
1098
		return fofoOrder;
1071
		return fofoOrder;
1099
	}
1072
	}
1100
 
1073
 
1101
	private Customer createAndGetCustomer(CustomCustomer customCustomer) throws ProfitMandiBusinessException {
-
 
1102
		List<Customer> customers = customerRepository.selectAllByMobileNumber(customCustomer.getMobileNumber());
-
 
1103
		List<Customer> filtered = customers.stream()
-
 
1104
				.filter(x -> x.getEmailId().equals(customCustomer.getEmailId())
-
 
1105
						&& x.getFirstName().equals(customCustomer.getFirstName())
-
 
1106
						&& x.getLastName().equals(customCustomer.getLastName()))
-
 
1107
				.collect(Collectors.toList());
-
 
1108
		if (filtered.size() > 0) {
-
 
1109
			return filtered.get(0);
-
 
1110
		}
-
 
1111
		Customer customer = new Customer();
-
 
1112
		customer.setFirstName(customCustomer.getFirstName());
-
 
1113
		customer.setLastName(customCustomer.getLastName());
-
 
1114
		customer.setEmailId(customCustomer.getEmailId());
-
 
1115
		customer.setMobileNumber(customCustomer.getMobileNumber());
-
 
1116
		customerRepository.persist(customer);
-
 
1117
		return customer;
-
 
1118
	}
-
 
1119
 
-
 
1120
	private void validateItemsSerializedNonSerialized(List<Item> items,
1074
	private void validateItemsSerializedNonSerialized(List<Item> items,
1121
			Map<Integer, CustomFofoOrderItem> customFofoOrderItemMap) throws ProfitMandiBusinessException {
1075
			Map<Integer, CustomFofoOrderItem> customFofoOrderItemMap) throws ProfitMandiBusinessException {
1122
		List<Integer> invalidItemIdSerialNumbers = new ArrayList<Integer>();
1076
		List<Integer> invalidItemIdSerialNumbers = new ArrayList<Integer>();
1123
		List<Integer> itemIdNonSerializedSerialNumbers = new ArrayList<Integer>();
1077
		List<Integer> itemIdNonSerializedSerialNumbers = new ArrayList<Integer>();
1124
		for (Item i : items) {
1078
		for (Item i : items) {
Line 1241... Line 1195...
1241
	}
1195
	}
1242
 
1196
 
1243
	private CustomAddress createCustomAddress(CustomerAddress customerAddress) {
1197
	private CustomAddress createCustomAddress(CustomerAddress customerAddress) {
1244
		CustomAddress customAddress = new CustomAddress();
1198
		CustomAddress customAddress = new CustomAddress();
1245
		customAddress.setName(customerAddress.getName());
1199
		customAddress.setName(customerAddress.getName());
-
 
1200
		customAddress.setLastName(customerAddress.getLastName());
1246
		customAddress.setLine1(customerAddress.getLine1());
1201
		customAddress.setLine1(customerAddress.getLine1());
1247
		customAddress.setLine2(customerAddress.getLine2());
1202
		customAddress.setLine2(customerAddress.getLine2());
1248
		customAddress.setLandmark(customerAddress.getLandmark());
1203
		customAddress.setLandmark(customerAddress.getLandmark());
1249
		customAddress.setCity(customerAddress.getCity());
1204
		customAddress.setCity(customerAddress.getCity());
1250
		customAddress.setPinCode(customerAddress.getPinCode());
1205
		customAddress.setPinCode(customerAddress.getPinCode());
Line 1358... Line 1313...
1358
			}
1313
			}
1359
		}
1314
		}
1360
		List<Integer> itemIds = fofoOrderItems.stream().map(x -> x.getItemId()).collect(Collectors.toList());
1315
		List<Integer> itemIds = fofoOrderItems.stream().map(x -> x.getItemId()).collect(Collectors.toList());
1361
		final Map<Integer, GstRate> gstRates;
1316
		final Map<Integer, GstRate> gstRates;
1362
		if (stateId != null) {
1317
		if (stateId != null) {
1363
			gstRates = Utils.getStateTaxRate(itemIds, stateId);
1318
			gstRates = stateGstRateRepository.getStateTaxRate(itemIds, stateId);
1364
		} else {
1319
		} else {
1365
			gstRates = new HashMap<>();
1320
			gstRates = new HashMap<>();
1366
			Utils.getIgstTaxRate(itemIds).entrySet().forEach(x -> {
1321
			stateGstRateRepository.getIgstTaxRate(itemIds).entrySet().forEach(x -> {
1367
				GstRate gstRate = new GstRate();
1322
				GstRate gstRate = new GstRate();
1368
				gstRate.setIgstRate(x.getValue());
1323
				gstRate.setIgstRate(x.getValue());
1369
				gstRate.setCgstRate(0f);
1324
				gstRate.setCgstRate(0f);
1370
				gstRate.setSgstRate(0f);
1325
				gstRate.setSgstRate(0f);
1371
				gstRates.put(x.getKey(), gstRate);
1326
				gstRates.put(x.getKey(), gstRate);