Subversion Repositories SmartDukaan

Rev

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

Rev 29237 Rev 29515
Line 27... Line 27...
27
import org.hibernate.Session;
27
import org.hibernate.Session;
28
import org.hibernate.SessionFactory;
28
import org.hibernate.SessionFactory;
29
import org.json.JSONObject;
29
import org.json.JSONObject;
30
import org.springframework.beans.factory.annotation.Autowired;
30
import org.springframework.beans.factory.annotation.Autowired;
31
import org.springframework.beans.factory.annotation.Qualifier;
31
import org.springframework.beans.factory.annotation.Qualifier;
-
 
32
import org.springframework.beans.factory.annotation.Value;
32
import org.springframework.cache.annotation.Cacheable;
33
import org.springframework.cache.annotation.Cacheable;
33
import org.springframework.stereotype.Component;
34
import org.springframework.stereotype.Component;
34
 
35
 
35
import com.spice.profitmandi.common.enumuration.ItemType;
36
import com.spice.profitmandi.common.enumuration.ItemType;
36
import com.spice.profitmandi.common.enumuration.SearchType;
37
import com.spice.profitmandi.common.enumuration.SearchType;
Line 56... Line 57...
56
import com.spice.profitmandi.common.model.Quantity;
57
import com.spice.profitmandi.common.model.Quantity;
57
import com.spice.profitmandi.common.model.SerialNumberDetail;
58
import com.spice.profitmandi.common.model.SerialNumberDetail;
58
import com.spice.profitmandi.common.util.FormattingUtils;
59
import com.spice.profitmandi.common.util.FormattingUtils;
59
import com.spice.profitmandi.common.util.StringUtils;
60
import com.spice.profitmandi.common.util.StringUtils;
60
import com.spice.profitmandi.common.util.Utils;
61
import com.spice.profitmandi.common.util.Utils;
-
 
62
import com.spice.profitmandi.common.web.client.RestClient;
61
import com.spice.profitmandi.dao.entity.catalog.Item;
63
import com.spice.profitmandi.dao.entity.catalog.Item;
62
import com.spice.profitmandi.dao.entity.catalog.TagListing;
64
import com.spice.profitmandi.dao.entity.catalog.TagListing;
63
import com.spice.profitmandi.dao.entity.dtr.InsurancePolicy;
65
import com.spice.profitmandi.dao.entity.dtr.InsurancePolicy;
64
import com.spice.profitmandi.dao.entity.dtr.PaymentOptionTransaction;
66
import com.spice.profitmandi.dao.entity.dtr.PaymentOptionTransaction;
65
import com.spice.profitmandi.dao.entity.dtr.Retailer;
67
import com.spice.profitmandi.dao.entity.dtr.Retailer;
-
 
68
import com.spice.profitmandi.dao.entity.dtr.ScratchOffer;
66
import com.spice.profitmandi.dao.entity.dtr.User;
69
import com.spice.profitmandi.dao.entity.dtr.User;
67
import com.spice.profitmandi.dao.entity.fofo.CurrentInventorySnapshot;
70
import com.spice.profitmandi.dao.entity.fofo.CurrentInventorySnapshot;
68
import com.spice.profitmandi.dao.entity.fofo.Customer;
71
import com.spice.profitmandi.dao.entity.fofo.Customer;
69
import com.spice.profitmandi.dao.entity.fofo.CustomerAddress;
72
import com.spice.profitmandi.dao.entity.fofo.CustomerAddress;
70
import com.spice.profitmandi.dao.entity.fofo.CustomerCreditNote;
73
import com.spice.profitmandi.dao.entity.fofo.CustomerCreditNote;
Line 89... Line 92...
89
import com.spice.profitmandi.dao.enumuration.catalog.SchemeType;
92
import com.spice.profitmandi.dao.enumuration.catalog.SchemeType;
90
import com.spice.profitmandi.dao.enumuration.dtr.PaymentOptionReferenceType;
93
import com.spice.profitmandi.dao.enumuration.dtr.PaymentOptionReferenceType;
91
import com.spice.profitmandi.dao.enumuration.fofo.ReturnType;
94
import com.spice.profitmandi.dao.enumuration.fofo.ReturnType;
92
import com.spice.profitmandi.dao.enumuration.fofo.ScanType;
95
import com.spice.profitmandi.dao.enumuration.fofo.ScanType;
93
import com.spice.profitmandi.dao.enumuration.fofo.SettlementType;
96
import com.spice.profitmandi.dao.enumuration.fofo.SettlementType;
-
 
97
import com.spice.profitmandi.dao.enumuration.inventory.ScratchedGift;
94
import com.spice.profitmandi.dao.enumuration.transaction.OrderStatus;
98
import com.spice.profitmandi.dao.enumuration.transaction.OrderStatus;
95
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
99
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
96
import com.spice.profitmandi.dao.repository.catalog.StateGstRateRepository;
100
import com.spice.profitmandi.dao.repository.catalog.StateGstRateRepository;
97
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
101
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
98
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
102
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
Line 101... Line 105...
101
import com.spice.profitmandi.dao.repository.dtr.Mongo;
105
import com.spice.profitmandi.dao.repository.dtr.Mongo;
102
import com.spice.profitmandi.dao.repository.dtr.PaymentOptionTransactionRepository;
106
import com.spice.profitmandi.dao.repository.dtr.PaymentOptionTransactionRepository;
103
import com.spice.profitmandi.dao.repository.dtr.PolicyNumberGenerationSequenceRepository;
107
import com.spice.profitmandi.dao.repository.dtr.PolicyNumberGenerationSequenceRepository;
104
import com.spice.profitmandi.dao.repository.dtr.RetailerRegisteredAddressRepository;
108
import com.spice.profitmandi.dao.repository.dtr.RetailerRegisteredAddressRepository;
105
import com.spice.profitmandi.dao.repository.dtr.RetailerRepository;
109
import com.spice.profitmandi.dao.repository.dtr.RetailerRepository;
-
 
110
import com.spice.profitmandi.dao.repository.dtr.ScratchOfferRepository;
106
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
111
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
107
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
112
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
108
import com.spice.profitmandi.dao.repository.fofo.CurrentInventorySnapshotRepository;
113
import com.spice.profitmandi.dao.repository.fofo.CurrentInventorySnapshotRepository;
109
import com.spice.profitmandi.dao.repository.fofo.CustomerAddressRepository;
114
import com.spice.profitmandi.dao.repository.fofo.CustomerAddressRepository;
110
import com.spice.profitmandi.dao.repository.fofo.CustomerCreditNoteRepository;
115
import com.spice.profitmandi.dao.repository.fofo.CustomerCreditNoteRepository;
Line 287... Line 292...
287
	private PendingOrderRepository pendingOrderRepository;
292
	private PendingOrderRepository pendingOrderRepository;
288
 
293
 
289
	@Autowired
294
	@Autowired
290
	private PendingOrderItemRepository pendingOrderItemRepository;
295
	private PendingOrderItemRepository pendingOrderItemRepository;
291
 
296
 
-
 
297
	@Autowired
-
 
298
	private ScratchOfferRepository scratchOfferRepository;
-
 
299
 
-
 
300
	@Autowired
-
 
301
	RestClient restClient;
-
 
302
 
-
 
303
	@Value("${prod}")
-
 
304
	private boolean prodEnv;
-
 
305
 
-
 
306
	private static final String SMS_GATEWAY = "http://api.pinnacle.in/index.php/sms/send";
-
 
307
	private static final String SENDER = "SMTDKN";
-
 
308
 
-
 
309
	public static final String APP_DOWNLOAD_BILLING_TEMPLATE_ID = "1507163542403945677";
-
 
310
 
-
 
311
	public static final String APP_DOWNLOAD_BILLING_OFFER = "Dear Customer, Thank you for purchasing from SmartDukaan pls click %s to download our app to see you invoice and special offers. SmartDukaan";
-
 
312
 
292
	@Override
313
	@Override
293
	public int createOrder(CreateOrderRequest createOrderRequest, int fofoId, boolean accessoriesDeals)
314
	public int createOrder(CreateOrderRequest createOrderRequest, int fofoId, boolean accessoriesDeals)
294
			throws ProfitMandiBusinessException {
315
			throws ProfitMandiBusinessException {
295
		LOGGER.info("fofoId -- {} Order Request -- {}", fofoId, createOrderRequest);
316
		LOGGER.info("fofoId -- {} Order Request -- {}", fofoId, createOrderRequest);
296
		CustomCustomer customCustomer = createOrderRequest.getCustomer();
317
		CustomCustomer customCustomer = createOrderRequest.getCustomer();
Line 573... Line 594...
573
			po.setBilledAmount(po.getBilledAmount() + totalAmount);
594
			po.setBilledAmount(po.getBilledAmount() + totalAmount);
574
			PendingOrderItem poi = pendingOrderItemRepository.selectById(createOrderRequest.getPoItemId());
595
			PendingOrderItem poi = pendingOrderItemRepository.selectById(createOrderRequest.getPoItemId());
575
			poi.setStatus(OrderStatus.BILLED);
596
			poi.setStatus(OrderStatus.BILLED);
576
			poi.setBilledTimestamp(LocalDateTime.now());
597
			poi.setBilledTimestamp(LocalDateTime.now());
577
		}
598
		}
-
 
599
 
-
 
600
		LocalDate startDate = LocalDate.of(2021, 10, 29);
-
 
601
		LocalDate endDate = LocalDate.of(2021, 11, 8);
-
 
602
 
-
 
603
		if (LocalDateTime.now().isAfter(startDate.atStartOfDay())
-
 
604
				&& LocalDateTime.now().isBefore(endDate.atStartOfDay())) {
-
 
605
 
-
 
606
			try {
-
 
607
				this.sendAppDownloadBillingOffer(customer.getMobileNumber());
-
 
608
			} catch (Exception e) {
-
 
609
				// TODO Auto-generated catch block
-
 
610
				e.printStackTrace();
-
 
611
			}
-
 
612
			this.createScratchOffer(fofoOrder.getInvoiceNumber(), fofoOrder.getCustomerId());
-
 
613
		}
578
		return fofoOrder.getId();
614
		return fofoOrder.getId();
579
	}
615
	}
580
 
616
 
-
 
617
	public void sendAppDownloadBillingOffer(String mobileNumber) throws Exception {
-
 
618
		// In case of Cant receive SMS?
-
 
619
		// String mailMessage = java.text.MessageFormat.format(text, otp.getOtp());
-
 
620
		String sdurl = "http://surl.li/anhfn";
-
 
621
		try {
-
 
622
			if (prodEnv) {
-
 
623
				this.sendSms(APP_DOWNLOAD_BILLING_TEMPLATE_ID, String.format(APP_DOWNLOAD_BILLING_OFFER, sdurl),
-
 
624
						mobileNumber);
-
 
625
			}
-
 
626
		} catch (Exception e) {
-
 
627
			e.printStackTrace();
-
 
628
		}
-
 
629
 
-
 
630
	}
-
 
631
 
-
 
632
	public void sendSms(String dltTemplateId, String message, String mobileNumber) throws Exception {
-
 
633
		Map<String, String> map = new HashMap<>();
-
 
634
 
-
 
635
		map.put("sender", SENDER);
-
 
636
		map.put("messagetype", "TXT");
-
 
637
		map.put("apikey", "b866f7-c6c483-682ff5-054420-ad9e2c");
-
 
638
 
-
 
639
		map.put("numbers", "91" + mobileNumber);
-
 
640
		LOGGER.info("Message {}", message);
-
 
641
		// OTP Message Template
-
 
642
		map.put("message", message);
-
 
643
		map.put("dlttempid", dltTemplateId);
-
 
644
 
-
 
645
		String response = restClient.post(SMS_GATEWAY, map, new HashMap<>());
-
 
646
		LOGGER.info(response);
-
 
647
 
-
 
648
	}
-
 
649
 
-
 
650
	private void createScratchOffer(String invoiceNumber, int customerId) {
-
 
651
 
-
 
652
		ScratchOffer so = new ScratchOffer();
-
 
653
		so.setInvoiceNumber(invoiceNumber);
-
 
654
		so.setOfferName(ScratchedGift.OTSR);
-
 
655
		so.setScratched(false);
-
 
656
		so.setCreatedTimestamp(LocalDateTime.now());
-
 
657
		so.setExpiredTimestamp(so.getCreatedTimestamp().plusDays(1));
-
 
658
		so.setUnlockedAt(LocalDateTime.now());
-
 
659
		so.setCustomerId(customerId);
-
 
660
		scratchOfferRepository.persist(so);
-
 
661
		LOGGER.info("ddd" + so);
-
 
662
 
-
 
663
		ScratchOffer so2 = new ScratchOffer();
-
 
664
		so2.setInvoiceNumber(invoiceNumber);
-
 
665
		so2.setScratched(false);
-
 
666
		so2.setCreatedTimestamp(LocalDateTime.now());
-
 
667
		so2.setExpiredTimestamp(so.getCreatedTimestamp().plusDays(1));
-
 
668
 
-
 
669
		so2.setCustomerId(customerId);
-
 
670
		so2.setUnlockedAt(LocalDate.now().plusDays(1).atStartOfDay());
-
 
671
		scratchOfferRepository.persist(so2);
-
 
672
		LOGGER.info("so2" + so2);
-
 
673
 
-
 
674
		ScratchOffer so3 = new ScratchOffer();
-
 
675
		so3.setInvoiceNumber(invoiceNumber);
-
 
676
		so3.setOfferName(ScratchedGift.DMTL);
-
 
677
		so3.setScratched(false);
-
 
678
		so3.setExpiredTimestamp(so.getCreatedTimestamp().plusDays(2));
-
 
679
 
-
 
680
		so3.setCreatedTimestamp(LocalDateTime.now());
-
 
681
		so3.setUnlockedAt(LocalDateTime.now());
-
 
682
		so3.setCustomerId(customerId);
-
 
683
		scratchOfferRepository.persist(so3);
-
 
684
		LOGGER.info("so3" + so3);
-
 
685
 
-
 
686
	}
-
 
687
 
581
	private HygieneData createAndGetHygieneData(int id, int fofoId) {
688
	private HygieneData createAndGetHygieneData(int id, int fofoId) {
582
		HygieneData hygieneData = new HygieneData();
689
		HygieneData hygieneData = new HygieneData();
583
		hygieneData.setOrderId(id);
690
		hygieneData.setOrderId(id);
584
		hygieneData.setFofoId(fofoId);
691
		hygieneData.setFofoId(fofoId);
585
		hygieneData.setCreatedTimestamp(LocalDateTime.now());
692
		hygieneData.setCreatedTimestamp(LocalDateTime.now());
Line 1740... Line 1847...
1740
								fofoOrder.getFofoId());
1847
								fofoOrder.getFofoId());
1741
						inventoryItems.add(inventoryItemRepository.selectById(y.getInventoryItemId()));
1848
						inventoryItems.add(inventoryItemRepository.selectById(y.getInventoryItemId()));
1742
					});
1849
					});
1743
				});
1850
				});
1744
				String reversalReason = "Order Rolledback/Cancelled for Invoice Number " + invoiceNumber;
1851
				String reversalReason = "Order Rolledback/Cancelled for Invoice Number " + invoiceNumber;
1745
				schemeService.reverseSchemes(inventoryItems, fofoOrder.getId(), reversalReason, SchemeService.OUT_SCHEME_TYPES);
1852
				schemeService.reverseSchemes(inventoryItems, fofoOrder.getId(), reversalReason,
-
 
1853
						SchemeService.OUT_SCHEME_TYPES);
1746
				schemeService.reverseSchemes(inventoryItems, fofoOrder.getId(), reversalReason, Arrays.asList(SchemeType.INVESTMENT));
1854
				schemeService.reverseSchemes(inventoryItems, fofoOrder.getId(), reversalReason,
-
 
1855
						Arrays.asList(SchemeType.INVESTMENT));
1747
				schemeService.reverseSchemes(inventoryItems, fofoOrder.getId(), reversalReason, Arrays.asList(SchemeType.ACTIVATION));
1856
				schemeService.reverseSchemes(inventoryItems, fofoOrder.getId(), reversalReason,
-
 
1857
						Arrays.asList(SchemeType.ACTIVATION));
1748
			}
1858
			}
1749
		}
1859
		}
1750
	}
1860
	}
1751
 
1861
 
1752
	@Override
1862
	@Override