Subversion Repositories SmartDukaan

Rev

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

Rev 24400 Rev 24440
Line 36... Line 36...
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;
39
import com.spice.profitmandi.common.model.GadgetCopsInsuranceModel;
40
import com.spice.profitmandi.common.model.GstRate;
40
import com.spice.profitmandi.common.model.GstRate;
-
 
41
import com.spice.profitmandi.common.model.InsuranceModel;
41
import com.spice.profitmandi.common.model.ItemIdQuantityAvailability;
42
import com.spice.profitmandi.common.model.ItemIdQuantityAvailability;
42
import com.spice.profitmandi.common.model.PdfModel;
43
import com.spice.profitmandi.common.model.PdfModel;
43
import com.spice.profitmandi.common.model.PriceModel;
44
import com.spice.profitmandi.common.model.PriceModel;
44
import com.spice.profitmandi.common.model.ProfitMandiConstants;
45
import com.spice.profitmandi.common.model.ProfitMandiConstants;
45
import com.spice.profitmandi.common.model.Quantity;
46
import com.spice.profitmandi.common.model.Quantity;
46
import com.spice.profitmandi.common.model.SerialNumberDetail;
47
import com.spice.profitmandi.common.model.SerialNumberDetail;
-
 
48
import com.spice.profitmandi.common.model.WiseAppInsuaranceModel;
47
import com.spice.profitmandi.common.util.FormattingUtils;
49
import com.spice.profitmandi.common.util.FormattingUtils;
48
import com.spice.profitmandi.common.util.InsuranceUtils;
50
import com.spice.profitmandi.common.util.InsuranceUtils;
49
import com.spice.profitmandi.common.util.StringUtils;
51
import com.spice.profitmandi.common.util.StringUtils;
50
import com.spice.profitmandi.common.util.Utils;
52
import com.spice.profitmandi.common.util.Utils;
51
import com.spice.profitmandi.dao.entity.catalog.Item;
53
import com.spice.profitmandi.dao.entity.catalog.Item;
52
import com.spice.profitmandi.dao.entity.dtr.GadgetCopsInsuranceCalc;
-
 
53
import com.spice.profitmandi.dao.entity.dtr.InsurancePolicy;
54
import com.spice.profitmandi.dao.entity.dtr.InsurancePolicy;
54
import com.spice.profitmandi.dao.entity.dtr.InsuranceProvider;
-
 
55
import com.spice.profitmandi.dao.entity.dtr.PaymentOptionTransaction;
55
import com.spice.profitmandi.dao.entity.dtr.PaymentOptionTransaction;
56
import com.spice.profitmandi.dao.entity.dtr.PolicyNumberGenerationSequence;
56
import com.spice.profitmandi.dao.entity.dtr.PolicyNumberGenerationSequence;
57
import com.spice.profitmandi.dao.entity.dtr.Retailer;
57
import com.spice.profitmandi.dao.entity.dtr.Retailer;
58
import com.spice.profitmandi.dao.entity.dtr.User;
58
import com.spice.profitmandi.dao.entity.dtr.User;
59
import com.spice.profitmandi.dao.entity.fofo.CurrentInventorySnapshot;
59
import com.spice.profitmandi.dao.entity.fofo.CurrentInventorySnapshot;
Line 100... Line 100...
100
import com.spice.profitmandi.dao.repository.fofo.PurchaseReturnItemRepository;
100
import com.spice.profitmandi.dao.repository.fofo.PurchaseReturnItemRepository;
101
import com.spice.profitmandi.dao.repository.fofo.ScanRecordRepository;
101
import com.spice.profitmandi.dao.repository.fofo.ScanRecordRepository;
102
import com.spice.profitmandi.dao.repository.user.AddressRepository;
102
import com.spice.profitmandi.dao.repository.user.AddressRepository;
103
import com.spice.profitmandi.dao.repository.user.CounterRepository;
103
import com.spice.profitmandi.dao.repository.user.CounterRepository;
104
import com.spice.profitmandi.dao.repository.user.PrivateDealUserRepository;
104
import com.spice.profitmandi.dao.repository.user.PrivateDealUserRepository;
-
 
105
import com.spice.profitmandi.service.integrations.zest.MobileInsurancePlan;
-
 
106
import com.spice.profitmandi.service.integrations.zest.ZestService;
105
import com.spice.profitmandi.service.inventory.InventoryService;
107
import com.spice.profitmandi.service.inventory.InventoryService;
106
import com.spice.profitmandi.service.inventory.PurchaseReturnService;
108
import com.spice.profitmandi.service.inventory.PurchaseReturnService;
107
import com.spice.profitmandi.service.pricing.PricingService;
109
import com.spice.profitmandi.service.pricing.PricingService;
108
import com.spice.profitmandi.service.scheme.SchemeService;
110
import com.spice.profitmandi.service.scheme.SchemeService;
109
import com.spice.profitmandi.service.user.RetailerService;
111
import com.spice.profitmandi.service.user.RetailerService;
Line 132... Line 134...
132
 
134
 
133
	@Autowired
135
	@Autowired
134
	private PurchaseReturnService purchaseReturnService;
136
	private PurchaseReturnService purchaseReturnService;
135
 
137
 
136
	@Autowired
138
	@Autowired
-
 
139
	private ZestService zestService;
-
 
140
 
-
 
141
	@Autowired
137
	private RetailerService retailerService;
142
	private RetailerService retailerService;
138
 
143
 
139
	@Autowired
144
	@Autowired
140
	private CustomerRepository customerRepository;
145
	private CustomerRepository customerRepository;
141
 
146
 
Line 258... Line 263...
258
				lineItemPrice.put(customFofoOrderItem.getItemId(), customFofoOrderItem.getSellingPrice());
263
				lineItemPrice.put(customFofoOrderItem.getItemId(), customFofoOrderItem.getSellingPrice());
259
			} else {
264
			} else {
260
				totalAmount = totalAmount + customFofoOrderItem.getSellingPrice() * customFofoOrderItem.getQuantity();
265
				totalAmount = totalAmount + customFofoOrderItem.getSellingPrice() * customFofoOrderItem.getQuantity();
261
				totalAmount = totalAmount - customFofoOrderItem.getDiscountAmount() * customFofoOrderItem.getQuantity();
266
				totalAmount = totalAmount - customFofoOrderItem.getDiscountAmount() * customFofoOrderItem.getQuantity();
262
				for (SerialNumberDetail serialNumberDetail : customFofoOrderItem.getSerialNumberDetails()) {
267
				for (SerialNumberDetail serialNumberDetail : customFofoOrderItem.getSerialNumberDetails()) {
263
					if (serialNumberDetail.isInsurance() && serialNumberDetail.getAmount() > 0) {
268
					if (serialNumberDetail.getAmount() > 0) {
264
						totalAmount = totalAmount + serialNumberDetail.getAmount();
269
						totalAmount = totalAmount + serialNumberDetail.getAmount();
265
					}
270
					}
266
				}
271
				}
267
			}
272
			}
268
 
273
 
Line 298... Line 303...
298
 
303
 
299
		Map<Integer, Item> itemMap = this.toItemMap(items);
304
		Map<Integer, Item> itemMap = this.toItemMap(items);
300
 
305
 
301
		Set<Integer> nonSerializedItemIds = new HashSet<>();
306
		Set<Integer> nonSerializedItemIds = new HashSet<>();
302
		Set<String> serialNumbers = new HashSet<>();
307
		Set<String> serialNumbers = new HashSet<>();
303
		Map<String, Float> insuranceSerialNumberItemPrice = new HashMap<>();
-
 
304
		Map<String, Float> insuranceSerialNumberSaleAmount = new HashMap<>();
308
		Map<String, InsuranceModel> insuranceSerialNumberMap = new HashMap<>();
305
		Map<String, String> serialNumberModelName = new HashMap<>();
-
 
306
		Map<String, String> serialNumberBrand = new HashMap<>();
-
 
307
		for (CustomFofoOrderItem customFofoOrderItem : createOrderRequest.getFofoOrderItems()) {
309
		for (CustomFofoOrderItem customFofoOrderItem : createOrderRequest.getFofoOrderItems()) {
308
			Item item = itemMap.get(customFofoOrderItem.getItemId());
310
			Item item = itemMap.get(customFofoOrderItem.getItemId());
309
			noGST = item.getHsnCode().equals("NOGST");
311
			noGST = item.getHsnCode().equals("NOGST");
310
			if (item.getType().equals(ItemType.SERIALIZED)) {
312
			if (item.getType().equals(ItemType.SERIALIZED)) {
311
				for (SerialNumberDetail serialNumberDetail : customFofoOrderItem.getSerialNumberDetails()) {
313
				for (SerialNumberDetail serialNumberDetail : customFofoOrderItem.getSerialNumberDetails()) {
312
					serialNumbers.add(serialNumberDetail.getSerialNumber());
314
					serialNumbers.add(serialNumberDetail.getSerialNumber());
313
					if (serialNumberDetail.isInsurance()) {
315
					if (serialNumberDetail.getAmount() > 0) {
314
						insuranceSerialNumberItemPrice.put(serialNumberDetail.getSerialNumber(),
316
						InsuranceModel im = new InsuranceModel();
315
								customFofoOrderItem.getSellingPrice());
317
						im.setBrand(item.getBrand());
316
						insuranceSerialNumberSaleAmount.put(serialNumberDetail.getSerialNumber(),
318
						im.setModelName(item.getModelName());
317
								serialNumberDetail.getAmount());
319
						im.setInsuranceAmount(serialNumberDetail.getAmount());
318
						serialNumberModelName.put(serialNumberDetail.getSerialNumber(),
320
						im.setDeviceSellingPrice(customFofoOrderItem.getSellingPrice());
319
								(item.getModelName() + item.getModelNumber()).trim());
321
						im.setInsuranceId(serialNumberDetail.getInsurance() + "");
320
						serialNumberBrand.put(serialNumberDetail.getSerialNumber(), item.getBrand());
322
						insuranceSerialNumberMap.put(serialNumberDetail.getSerialNumber(), im);
321
					}
323
					}
322
				}
324
				}
323
			} else {
325
			} else {
324
				nonSerializedItemIds.add(customFofoOrderItem.getItemId());
326
				nonSerializedItemIds.add(customFofoOrderItem.getItemId());
325
			}
327
			}
Line 375... Line 377...
375
			if (item.getType().equals(ItemType.SERIALIZED)) {
377
			if (item.getType().equals(ItemType.SERIALIZED)) {
376
				// TODO:handle null
378
				// TODO:handle null
377
				if (serializedInventoryItemMap.get(item.getId()) == null
379
				if (serializedInventoryItemMap.get(item.getId()) == null
378
						|| itemIdCustomFofoOrderItemMap.get(item.getId()).getSerialNumberDetails()
380
						|| itemIdCustomFofoOrderItemMap.get(item.getId()).getSerialNumberDetails()
379
								.size() != serializedInventoryItemMap.get(item.getId()).size()) {
381
								.size() != serializedInventoryItemMap.get(item.getId()).size()) {
380
					// not enough serial numbers
-
 
381
					// LOGGER.info("serialNumbers {}", serialNumbers);
-
 
382
					// LOGGER.info("serializedInventoryItemMap {}", serializedInventoryItemMap);
-
 
-
 
382
 
383
					LOGGER.error("itemId {} => mismatch size of requested serial numbers", item.getId());
383
					LOGGER.error("itemId {} => mismatch size of requested serial numbers", item.getId());
384
					Function<SerialNumberDetail, String> serialNumberDetailToSerialNumberFunction = new Function<SerialNumberDetail, String>() {
384
					List<String> invalidSerialNumbers = itemIdCustomFofoOrderItemMap.get(item.getId())
385
						@Override
-
 
386
						public String apply(SerialNumberDetail serialNumberDetail) {
385
							.getSerialNumberDetails().stream().map(x -> x.getSerialNumber())
387
							return serialNumberDetail.getSerialNumber();
386
							.collect(Collectors.toList());
388
						}
-
 
389
					};
-
 
390
					throw new ProfitMandiBusinessException("invalidSerialNumbers",
387
					throw new ProfitMandiBusinessException("invalidSerialNumbers", invalidSerialNumbers, "FFORDR_1004");
391
							itemIdCustomFofoOrderItemMap.get(item.getId()).getSerialNumberDetails().stream()
-
 
392
									.map(serialNumberDetailToSerialNumberFunction).collect(Collectors.toList()),
-
 
393
							"FFORDR_1004");
-
 
394
				}
388
				}
395
				Set<InventoryItem> inventoryItemsSerializedserialized = serializedInventoryItemMap.get(item.getId());
389
				Set<InventoryItem> inventoryItemsSerializedserialized = serializedInventoryItemMap.get(item.getId());
396
				for (InventoryItem inventoryItem : inventoryItemsSerializedserialized) {
390
				for (InventoryItem inventoryItem : inventoryItemsSerializedserialized) {
397
					inventoryItem.setGoodQuantity(0);
391
					inventoryItem.setGoodQuantity(0);
398
					inventoryItemIdQuantityUsed.put(inventoryItem.getId(), 1);
392
					inventoryItemIdQuantityUsed.put(inventoryItem.getId(), 1);
Line 432... Line 426...
432
		} else {
426
		} else {
433
			this.validateMopPrice(itemIdMopPriceMap, itemIdCustomFofoOrderItemMap);
427
			this.validateMopPrice(itemIdMopPriceMap, itemIdCustomFofoOrderItemMap);
434
		}
428
		}
435
 
429
 
436
		String fofoStoreCode = this.getFofoStoreCode(fofoId);
430
		String fofoStoreCode = this.getFofoStoreCode(fofoId);
437
		InvoiceNumberGenerationSequence invoiceNumberGenerationSequence = null;
-
 
438
		String documentNumber = null;
431
		String documentNumber = null;
439
		if (noGST) {
432
		if (noGST) {
440
			documentNumber = this.getSecurityDepositNumber(fofoId, fofoStoreCode);
433
			documentNumber = this.getSecurityDepositNumber(fofoId, fofoStoreCode);
441
 
434
 
442
		} else {
435
		} else {
Line 479... Line 472...
479
			this.updateInventoryItemsAndScanRecord(inventoryItems, fofoId, inventoryItemIdQuantityUsed,
472
			this.updateInventoryItemsAndScanRecord(inventoryItems, fofoId, inventoryItemIdQuantityUsed,
480
					fofoOrder.getId());
473
					fofoOrder.getId());
481
		}
474
		}
482
 
475
 
483
		// insurance calculation is insurance flag is enabled
476
		// insurance calculation is insurance flag is enabled
-
 
477
		//
484
		if (!insuranceSerialNumberItemPrice.isEmpty()) {
478
		if (!insuranceSerialNumberMap.isEmpty()) {
485
			LOGGER.info("Processing for insurence for serialNumbers");
479
			LOGGER.info("Processing insurane for serialNumbers");
486
			Map<Float, GadgetCopsInsuranceCalc> insurancePricesMap = pricingService.getInsurancePrices(
-
 
487
					new HashSet<>(insuranceSerialNumberItemPrice.values()), ProfitMandiConstants.GADGET_COPS);
-
 
488
			InsuranceProvider insuranceProvider = insuranceProviderRepository
-
 
489
					.selectByName(ProfitMandiConstants.GADGET_COPS);
-
 
490
 
-
 
491
			this.validateInsuranceAmount(insuranceSerialNumberItemPrice, insuranceSerialNumberSaleAmount,
-
 
492
					insurancePricesMap);
-
 
493
 
-
 
494
			this.validateInsuranceMargin(insuranceSerialNumberItemPrice, itemIdCustomFofoOrderItemMap,
-
 
495
					itemIdMopPriceMap, insurancePricesMap, insuranceSerialNumberSaleAmount);
-
 
496
 
480
 
497
			LocalDate customerDateOfBirth = LocalDate.from(createOrderRequest.getCustomerDateOfBirth());
481
			LocalDate customerDateOfBirth = LocalDate.from(createOrderRequest.getCustomer().getDateOfBirth());
498
 
482
 
499
			for (Map.Entry<String, Float> entry : insuranceSerialNumberItemPrice.entrySet()) {
483
			for (Map.Entry<String, InsuranceModel> entry : insuranceSerialNumberMap.entrySet()) {
-
 
484
				InsuranceModel insuranceModel = entry.getValue();
500
				PolicyNumberGenerationSequence policyNumberGenerationSequence = this
485
				MobileInsurancePlan mobileInsurancePlan = zestService.getAllPlansMap()
501
						.createPolicyNumberGenerationSequence();
486
						.get(insuranceModel.getInsuranceId());
502
 
-
 
503
				InsurancePolicy insurancePolicy = this.createInsurancePolicy(fofoOrder.getInvoiceNumber(), fofoId,
487
				InsurancePolicy insurancePolicy = this.createInsurancePolicy(fofoOrder.getInvoiceNumber(), fofoId,
504
						insurancePricesMap.get(entry.getValue()).getDealerPrice(),
488
						insuranceModel.getInsuranceAmount() - mobileInsurancePlan.getPartnerCommission(),
505
						insuranceSerialNumberSaleAmount.get(entry.getKey()), entry.getValue(), entry.getKey(),
489
						insuranceModel.getInsuranceAmount(), insuranceModel.getDeviceSellingPrice(), entry.getKey(),
506
						serialNumberModelName.get(entry.getKey()), serialNumberBrand.get(entry.getKey()),
490
						insuranceModel.getModelName(), insuranceModel.getBrand(), customer, customerDateOfBirth,
507
						policyNumberGenerationSequence.getSequence(), insuranceProvider.getId(), customer,
491
						customerAddress, mobileInsurancePlan.getProductName() + " for " + mobileInsurancePlan.getDuration() + " Months");
508
						customerDateOfBirth, customerAddress);
-
 
509
 
492
 
-
 
493
				String walletDescription = null;
-
 
494
				if (mobileInsurancePlan.getProviderId().equals("0")) {
-
 
495
					insurancePolicy.setProviderId(1);
-
 
496
					int policyNumberGenerationSequence = this.createPolicyNumberGenerationSequence().getSequence();
-
 
497
					insurancePolicy.setPolicyNumber(StringUtils.generatePolicyNumber(
-
 
498
							ProfitMandiConstants.POLICY_NUMBER_PREFIX, policyNumberGenerationSequence));
510
				GadgetCopsInsuranceModel gadgetCopsInsuranceModel = this.createGadgetCopsInsuranceModel(
499
					GadgetCopsInsuranceModel gadgetCopsInsuranceModel = this.createGadgetCopsInsuranceModel(
511
						serialNumberBrand.get(entry.getKey()), serialNumberModelName.get(entry.getKey()),
500
							entry.getValue().getBrand(), entry.getValue().getModelName(), entry.getKey(),
512
						entry.getKey(), customerDateOfBirth, customer, customerAddress, insurancePolicy);
501
							customerDateOfBirth, customer, customerAddress, insurancePolicy);
-
 
502
 
-
 
503
					try {
-
 
504
						InsuranceUtils.submitToGadgetCops(gadgetCopsInsuranceModel);
-
 
505
						insurancePolicy.setPosted(true);
513
				String walletDescription = "Sale of " + insurancePolicy.getPolicyNumber() + " for "
506
						walletDescription = "Sale of " + insurancePolicy.getPolicyNumber() + " for "
-
 
507
								+ fofoOrder.getInvoiceNumber();
-
 
508
					} catch (ProfitMandiBusinessException profitMandiBusinessException) {
-
 
509
						LOGGER.info("Unable to submit insurance policy details to {}", insuranceModel.getProviderName(),
-
 
510
								profitMandiBusinessException);
-
 
511
						throw new ProfitMandiBusinessException("Insurance", mobileInsurancePlan.getProductName(),
-
 
512
								"Could not generate insurance for Gadget Cop");
-
 
513
					}
-
 
514
				} else {
-
 
515
					try {
-
 
516
						WiseAppInsuaranceModel wiseAppInsuaranceModel = this
-
 
517
								.createWiseAppInsuranceModel(mobileInsurancePlan, insurancePolicy, customCustomer);
-
 
518
						String wiseAppInsuranceCode = zestService.createInsurance(wiseAppInsuaranceModel);
-
 
519
						insurancePolicy.setPolicyNumber(wiseAppInsuranceCode);
-
 
520
						// TODO: remove hardcoding
-
 
521
						insurancePolicy.setProviderId(2);
-
 
522
						walletDescription = "Sale of " + insurancePolicy.getProductName() + " against "
514
						+ fofoOrder.getInvoiceNumber();
523
								+ fofoOrder.getInvoiceNumber();
-
 
524
					} catch (ProfitMandiBusinessException pbe) {
-
 
525
						pbe.printStackTrace();
-
 
526
						throw new ProfitMandiBusinessException("Insurance", mobileInsurancePlan.getProductName(),
-
 
527
								pbe.getMessage());
-
 
528
					}
-
 
529
				}
515
				walletService.consumeAmountFromWallet(fofoId, insurancePolicy.getId(),
530
				walletService.consumeAmountFromWallet(fofoId, insurancePolicy.getId(),
516
						WalletReferenceType.DAMAGE_PROTECTION, walletDescription, insurancePolicy.getPurchaseAmount());
531
						WalletReferenceType.DAMAGE_PROTECTION, walletDescription, insurancePolicy.getPurchaseAmount());
517
 
-
 
518
				try {
-
 
519
					InsuranceUtils.submitToGadgetCops(gadgetCopsInsuranceModel);
-
 
520
					insurancePolicy.setPosted(true);
-
 
521
				} catch (ProfitMandiBusinessException profitMandiBusinessException) {
-
 
522
					LOGGER.info("Unable to submit insurance policy details to {}", insuranceProvider.getName(),
-
 
523
							profitMandiBusinessException);
-
 
524
				}
-
 
525
				insurancePolicyRepository.persist(insurancePolicy);
532
				insurancePolicyRepository.persist(insurancePolicy);
526
			}
533
			}
527
		}
534
		}
528
		schemeService.processSchemeOut(fofoOrder.getId(), fofoId);
535
		schemeService.processSchemeOut(fofoOrder.getId(), fofoId);
529
 
-
 
530
		return fofoOrder.getId();
536
		return fofoOrder.getId();
531
	}
537
	}
532
 
538
 
-
 
539
	private WiseAppInsuaranceModel createWiseAppInsuranceModel(MobileInsurancePlan mobileInsurancePlan,
-
 
540
			InsurancePolicy insurancePolicy, CustomCustomer customer) throws ProfitMandiBusinessException {
-
 
541
		WiseAppInsuaranceModel wiseAppInsuranceModel = new WiseAppInsuaranceModel();
-
 
542
		CustomAddress address = customer.getAddress();
-
 
543
 
-
 
544
		String sAddress = (address.getLine1() + " " + address.getLine2()).replaceAll("  ", " ");
-
 
545
		wiseAppInsuranceModel.setAddress(sAddress);
-
 
546
		wiseAppInsuranceModel.setBrand(insurancePolicy.getBrand());
-
 
547
		wiseAppInsuranceModel.setBalanceType("4");
-
 
548
		wiseAppInsuranceModel.setProduct(mobileInsurancePlan.getProductId());
-
 
549
		wiseAppInsuranceModel
-
 
550
				.setName((insurancePolicy.getCustomerFirstName() + " " + insurancePolicy.getCustomerLastName()));
-
 
551
		wiseAppInsuranceModel.setCity(address.getCity());
-
 
552
		wiseAppInsuranceModel.setDob(StringUtils.toHyphenatedString(customer.getDateOfBirth()));
-
 
553
		wiseAppInsuranceModel.setDuration(mobileInsurancePlan.getDuration());
-
 
554
		wiseAppInsuranceModel.setPincode(address.getPinCode());
-
 
555
		wiseAppInsuranceModel.setEmail(customer.getEmailId());
-
 
556
		wiseAppInsuranceModel.setDeviceType(mobileInsurancePlan.getDeviceType());
-
 
557
		wiseAppInsuranceModel.setImeiNo(insurancePolicy.getSerialNumber());
-
 
558
		wiseAppInsuranceModel.setPlanValue(String.valueOf(insurancePolicy.getSaleAmount()));
-
 
559
		wiseAppInsuranceModel.setRetailerId(zestService.getWiseAppPartnerCode(insurancePolicy.getRetailerId()));
-
 
560
		wiseAppInsuranceModel.setDuration(mobileInsurancePlan.getDuration());
-
 
561
		wiseAppInsuranceModel.setGender(customer.getGender());
-
 
562
		wiseAppInsuranceModel.setInvoiceNo(insurancePolicy.getInvoiceNumber());
-
 
563
		wiseAppInsuranceModel.setNumber(insurancePolicy.getCustomerMobileNumber());
-
 
564
		wiseAppInsuranceModel
-
 
565
				.setPurchaseDate(StringUtils.toHyphenatedString(insurancePolicy.getCreateTimestamp().toLocalDate()));
-
 
566
		wiseAppInsuranceModel.setModel(insurancePolicy.getModelName());
-
 
567
		wiseAppInsuranceModel.setHandSetValue(String.valueOf(insurancePolicy.getSellingPrice()));
-
 
568
		wiseAppInsuranceModel.setInsurerCompany(mobileInsurancePlan.getProviderId());
-
 
569
		return wiseAppInsuranceModel;
-
 
570
	}
-
 
571
 
533
	private String getInvoiceNumber(int fofoId, String fofoStoreCode) {
572
	private String getInvoiceNumber(int fofoId, String fofoStoreCode) {
534
		InvoiceNumberGenerationSequence invoiceNumberGenerationSequence = null;
573
		InvoiceNumberGenerationSequence invoiceNumberGenerationSequence = null;
535
		try {
574
		try {
536
			invoiceNumberGenerationSequence = invoiceNumberGenerationSequenceRepository.selectByFofoId(fofoId);
575
			invoiceNumberGenerationSequence = invoiceNumberGenerationSequenceRepository.selectByFofoId(fofoId);
537
			invoiceNumberGenerationSequence.setSequence(invoiceNumberGenerationSequence.getSequence() + 1);
576
			invoiceNumberGenerationSequence.setSequence(invoiceNumberGenerationSequence.getSequence() + 1);
Line 959... Line 998...
959
		return gadgetCopsInsuranceModel;
998
		return gadgetCopsInsuranceModel;
960
	}
999
	}
961
 
1000
 
962
	private InsurancePolicy createInsurancePolicy(String invoiceNumber, int retailerId, float purchaseAmount,
1001
	private InsurancePolicy createInsurancePolicy(String invoiceNumber, int retailerId, float purchaseAmount,
963
			float saleAmount, float sellingPrice, String serialNumber, String modelName, String brand,
1002
			float saleAmount, float sellingPrice, String serialNumber, String modelName, String brand,
964
			int policyNumberGenerationSequence, int insuranceProviderId, Customer customer,
-
 
965
			LocalDate customerDateOfBirth, CustomerAddress customerAddress) {
1003
			Customer customer, LocalDate customerDateOfBirth, CustomerAddress customerAddress, String productName) {
966
		InsurancePolicy insurancePolicy = new InsurancePolicy();
1004
		InsurancePolicy insurancePolicy = new InsurancePolicy();
967
		insurancePolicy.setInvoiceNumber(invoiceNumber);
1005
		insurancePolicy.setInvoiceNumber(invoiceNumber);
968
		insurancePolicy.setRetailerId(retailerId);
1006
		insurancePolicy.setRetailerId(retailerId);
969
		insurancePolicy.setPurchaseAmount(purchaseAmount);
1007
		insurancePolicy.setPurchaseAmount(purchaseAmount);
970
		insurancePolicy.setSaleAmount(saleAmount);
1008
		insurancePolicy.setSaleAmount(saleAmount);
971
		insurancePolicy.setSellingPrice(sellingPrice);
1009
		insurancePolicy.setSellingPrice(sellingPrice);
972
		insurancePolicy.setSerialNumber(serialNumber);
1010
		insurancePolicy.setSerialNumber(serialNumber);
973
		insurancePolicy.setModelName(modelName);
1011
		insurancePolicy.setModelName(modelName);
974
		insurancePolicy.setBrand(brand);
1012
		insurancePolicy.setBrand(brand);
975
		insurancePolicy.setPolicyNumber(StringUtils.generatePolicyNumber(ProfitMandiConstants.POLICY_NUMBER_PREFIX,
-
 
976
				policyNumberGenerationSequence));
-
 
977
		insurancePolicy.setProviderId(insuranceProviderId);
-
 
978
		insurancePolicy.setCustomerFirstName(customer.getFirstName());
1013
		insurancePolicy.setCustomerFirstName(customer.getFirstName());
979
		insurancePolicy.setCustomerLastName(customer.getLastName());
1014
		insurancePolicy.setCustomerLastName(customer.getLastName());
980
		insurancePolicy.setCustomerMobileNumber(customer.getMobileNumber());
1015
		insurancePolicy.setCustomerMobileNumber(customer.getMobileNumber());
981
		insurancePolicy.setCustomerEmailId(customer.getEmailId());
1016
		insurancePolicy.setCustomerEmailId(customer.getEmailId());
982
		insurancePolicy.setCustomerDateOfBirth(customerDateOfBirth);
1017
		insurancePolicy.setCustomerDateOfBirth(customerDateOfBirth);
983
		insurancePolicy.setCustomerAddress1(customerAddress.getLine1());
1018
		insurancePolicy.setCustomerAddress1(customerAddress.getLine1());
984
		insurancePolicy.setCustomerAddress2(customerAddress.getLine2());
1019
		insurancePolicy.setCustomerAddress2(customerAddress.getLine2());
985
		insurancePolicy.setCustomerCity(customerAddress.getCity());
1020
		insurancePolicy.setCustomerCity(customerAddress.getCity());
986
		insurancePolicy.setCustomerPinCode(customerAddress.getPinCode());
1021
		insurancePolicy.setCustomerPinCode(customerAddress.getPinCode());
987
		insurancePolicy.setCustomerState(customerAddress.getState());
1022
		insurancePolicy.setCustomerState(customerAddress.getState());
-
 
1023
		insurancePolicy.setProductName(productName);
988
		return insurancePolicy;
1024
		return insurancePolicy;
989
	}
1025
	}
990
 
1026
 
991
	private void validateInsuranceMargin(Map<String, Float> insuranceSerialNumberItemPrice,
-
 
992
			Map<Integer, CustomFofoOrderItem> itemIdCustomFofoOrderItemMap, Map<Integer, PriceModel> itemIdMopPriceMap,
-
 
993
			Map<Float, GadgetCopsInsuranceCalc> insurancePricesMap, Map<String, Float> insuranceSerialNumberSaleAmount)
-
 
994
			throws ProfitMandiBusinessException {
-
 
995
		Map<Float, Float> invalidInsuranceMarginAmount = new HashMap<>();
-
 
996
		for (Map.Entry<String, Float> entry : insuranceSerialNumberItemPrice.entrySet()) {
-
 
997
			int itemId = this.getItemIdFromSerialNumber(itemIdCustomFofoOrderItemMap, entry.getKey());
-
 
998
			float itemPurchasePrice = itemIdMopPriceMap.get(itemId).getPrice();
-
 
999
			float itemSellingPrice = entry.getValue();
-
 
1000
			float itemMargin = itemSellingPrice - itemPurchasePrice;
-
 
1001
			float insurancePurchasePrice = insurancePricesMap.get(entry.getValue()).getDealerPrice();
-
 
1002
			float insuranceSellingPrice = insuranceSerialNumberSaleAmount.get(entry.getKey());
-
 
1003
			float insuranceMargin = insuranceSellingPrice - insurancePurchasePrice;
-
 
1004
			if (insuranceMargin < (itemMargin * 30 / 100)) {
-
 
1005
				invalidInsuranceMarginAmount.put(insuranceMargin, (itemMargin * 30 / 100));
-
 
1006
			}
-
 
1007
		}
-
 
1008
		if (!invalidInsuranceMarginAmount.isEmpty()) {
-
 
1009
			LOGGER.error(
-
 
1010
					"insurance marging should be greater than equal to item profit margin insuranceMarginItemIdMargin {}",
-
 
1011
					invalidInsuranceMarginAmount);
-
 
1012
			throw new ProfitMandiBusinessException("invalidInsuranceMarginAmount", invalidInsuranceMarginAmount,
-
 
1013
					"FFORDR_1007");
-
 
1014
		}
-
 
1015
	}
-
 
1016
 
-
 
1017
	private void validateInsuranceAmount(Map<String, Float> insuranceSerialNumberItemPrice,
-
 
1018
			Map<String, Float> insuranceSerialNumberSaleAmount, Map<Float, GadgetCopsInsuranceCalc> insurancePricesMap)
-
 
1019
			throws ProfitMandiBusinessException {
-
 
1020
		Map<Float, Float> invalidInsurancePurchaseSaleAmount = new HashMap<>();
-
 
1021
		Map<Float, Float> invalidInsuranceSalePurchaseAmount = new HashMap<>();
-
 
1022
		for (Map.Entry<String, Float> entry : insuranceSerialNumberItemPrice.entrySet()) {
-
 
1023
			if (insuranceSerialNumberSaleAmount.get(entry.getKey()) < insurancePricesMap.get(entry.getValue())
-
 
1024
					.getDealerPrice()) {
-
 
1025
				invalidInsurancePurchaseSaleAmount.put(insurancePricesMap.get(entry.getValue()).getDealerPrice(),
-
 
1026
						insuranceSerialNumberSaleAmount.get(entry.getKey()));
-
 
1027
			}
-
 
1028
 
-
 
1029
			if (insuranceSerialNumberSaleAmount.get(entry.getKey()) > insurancePricesMap.get(entry.getValue())
-
 
1030
					.getSellingPrice()) {
-
 
1031
				invalidInsuranceSalePurchaseAmount.put(insuranceSerialNumberSaleAmount.get(entry.getKey()),
-
 
1032
						insurancePricesMap.get(entry.getValue()).getDealerPrice());
-
 
1033
			}
-
 
1034
		}
-
 
1035
 
-
 
1036
		// insurance sale amount can not be lesser than insurance purchase amount
-
 
1037
		if (!invalidInsurancePurchaseSaleAmount.isEmpty()) {
-
 
1038
			LOGGER.error(
-
 
1039
					"Invalid Insurance prices [{}], insurance sale amount can not be lesser than insurance purchase amount",
-
 
1040
					invalidInsurancePurchaseSaleAmount);
-
 
1041
			throw new ProfitMandiBusinessException("invalidInsurancePurchaseSaleAmount",
-
 
1042
					invalidInsurancePurchaseSaleAmount, "FFORDR_1008");
-
 
1043
		}
-
 
1044
 
-
 
1045
		if (!invalidInsuranceSalePurchaseAmount.isEmpty()) {
-
 
1046
			LOGGER.error(
-
 
1047
					"Invalid Insurance prices [{}], insurance sale amount can not be greater than than insurance max amount",
-
 
1048
					invalidInsuranceSalePurchaseAmount);
-
 
1049
			throw new ProfitMandiBusinessException("invalidInsuranceSalePurchaseAmount",
-
 
1050
					invalidInsuranceSalePurchaseAmount, "FFORDR_1009");
-
 
1051
		}
-
 
1052
	}
-
 
1053
 
-
 
1054
	private void validateDpPrice(Map<Integer, PriceModel> itemIdMopPriceMap,
1027
	private void validateDpPrice(Map<Integer, PriceModel> itemIdMopPriceMap,
1055
			Map<Integer, CustomFofoOrderItem> itemIdCustomFofoLineItemMap) throws ProfitMandiBusinessException {
1028
			Map<Integer, CustomFofoOrderItem> itemIdCustomFofoLineItemMap) throws ProfitMandiBusinessException {
1056
		for (Map.Entry<Integer, CustomFofoOrderItem> entry : itemIdCustomFofoLineItemMap.entrySet()) {
1029
		for (Map.Entry<Integer, CustomFofoOrderItem> entry : itemIdCustomFofoLineItemMap.entrySet()) {
1057
			int itemId = entry.getKey();
1030
			int itemId = entry.getKey();
1058
			CustomFofoOrderItem customFofoOrderItem = entry.getValue();
1031
			CustomFofoOrderItem customFofoOrderItem = entry.getValue();