Subversion Repositories SmartDukaan

Rev

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

Rev 27504 Rev 27678
Line 22... Line 22...
22
import java.util.stream.Collectors;
22
import java.util.stream.Collectors;
23
 
23
 
24
import javax.mail.MessagingException;
24
import javax.mail.MessagingException;
25
import javax.mail.internet.InternetAddress;
25
import javax.mail.internet.InternetAddress;
26
import javax.mail.internet.MimeMessage;
26
import javax.mail.internet.MimeMessage;
-
 
27
import javax.xml.bind.DatatypeConverter;
27
 
28
 
28
import org.apache.commons.io.output.ByteArrayOutputStream;
29
import org.apache.commons.io.output.ByteArrayOutputStream;
29
import org.apache.commons.lang.StringUtils;
30
import org.apache.commons.lang.StringUtils;
30
import org.apache.http.client.methods.CloseableHttpResponse;
31
import org.apache.http.client.methods.CloseableHttpResponse;
31
import org.apache.http.client.methods.HttpPost;
32
import org.apache.http.client.methods.HttpPost;
Line 46... Line 47...
46
import org.springframework.transaction.annotation.Transactional;
47
import org.springframework.transaction.annotation.Transactional;
47
 
48
 
48
import com.google.common.collect.Lists;
49
import com.google.common.collect.Lists;
49
import com.google.gson.Gson;
50
import com.google.gson.Gson;
50
import com.google.gson.GsonBuilder;
51
import com.google.gson.GsonBuilder;
51
import com.mongodb.connection.Stream;
-
 
52
import com.spice.profitmandi.common.enumuration.MessageType;
52
import com.spice.profitmandi.common.enumuration.MessageType;
53
import com.spice.profitmandi.common.enumuration.RechargeStatus;
53
import com.spice.profitmandi.common.enumuration.RechargeStatus;
54
import com.spice.profitmandi.common.enumuration.ReporticoProject;
54
import com.spice.profitmandi.common.enumuration.ReporticoProject;
55
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
55
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
56
import com.spice.profitmandi.common.model.CustomRetailer;
56
import com.spice.profitmandi.common.model.CustomRetailer;
57
import com.spice.profitmandi.common.model.FocusedModelShortageModel;
57
import com.spice.profitmandi.common.model.FocusedModelShortageModel;
58
import com.spice.profitmandi.common.model.GstRate;
58
import com.spice.profitmandi.common.model.GstRate;
-
 
59
import com.spice.profitmandi.common.model.PdfModel;
59
import com.spice.profitmandi.common.model.ProfitMandiConstants;
60
import com.spice.profitmandi.common.model.ProfitMandiConstants;
60
import com.spice.profitmandi.common.model.RechargeCredential;
61
import com.spice.profitmandi.common.model.RechargeCredential;
61
import com.spice.profitmandi.common.model.SendNotificationModel;
62
import com.spice.profitmandi.common.model.SendNotificationModel;
62
import com.spice.profitmandi.common.services.ReporticoService;
63
import com.spice.profitmandi.common.services.ReporticoService;
63
import com.spice.profitmandi.common.util.FileUtil;
64
import com.spice.profitmandi.common.util.FileUtil;
64
import com.spice.profitmandi.common.util.FormattingUtils;
65
import com.spice.profitmandi.common.util.FormattingUtils;
-
 
66
import com.spice.profitmandi.common.util.PdfUtils;
65
import com.spice.profitmandi.common.util.Utils;
67
import com.spice.profitmandi.common.util.Utils;
66
import com.spice.profitmandi.common.util.Utils.Attachment;
68
import com.spice.profitmandi.common.util.Utils.Attachment;
67
import com.spice.profitmandi.dao.Interface.Campaign;
69
import com.spice.profitmandi.dao.Interface.Campaign;
68
import com.spice.profitmandi.dao.convertor.LocalDateTimeJsonConverter;
70
import com.spice.profitmandi.dao.convertor.LocalDateTimeJsonConverter;
69
import com.spice.profitmandi.dao.entity.auth.AuthUser;
71
import com.spice.profitmandi.dao.entity.auth.AuthUser;
Line 71... Line 73...
71
import com.spice.profitmandi.dao.entity.catalog.Item;
73
import com.spice.profitmandi.dao.entity.catalog.Item;
72
import com.spice.profitmandi.dao.entity.catalog.Scheme;
74
import com.spice.profitmandi.dao.entity.catalog.Scheme;
73
import com.spice.profitmandi.dao.entity.cs.Position;
75
import com.spice.profitmandi.dao.entity.cs.Position;
74
import com.spice.profitmandi.dao.entity.cs.Ticket;
76
import com.spice.profitmandi.dao.entity.cs.Ticket;
75
import com.spice.profitmandi.dao.entity.dtr.DailyRecharge;
77
import com.spice.profitmandi.dao.entity.dtr.DailyRecharge;
-
 
78
import com.spice.profitmandi.dao.entity.dtr.InsurancePolicy;
76
import com.spice.profitmandi.dao.entity.dtr.NotificationCampaign;
79
import com.spice.profitmandi.dao.entity.dtr.NotificationCampaign;
77
import com.spice.profitmandi.dao.entity.dtr.PaymentOptionTransaction;
-
 
78
import com.spice.profitmandi.dao.entity.dtr.PushNotifications;
80
import com.spice.profitmandi.dao.entity.dtr.PushNotifications;
79
import com.spice.profitmandi.dao.entity.dtr.RechargeProvider;
81
import com.spice.profitmandi.dao.entity.dtr.RechargeProvider;
80
import com.spice.profitmandi.dao.entity.dtr.RechargeProviderCreditWalletHistory;
82
import com.spice.profitmandi.dao.entity.dtr.RechargeProviderCreditWalletHistory;
81
import com.spice.profitmandi.dao.entity.dtr.RechargeTransaction;
83
import com.spice.profitmandi.dao.entity.dtr.RechargeTransaction;
82
import com.spice.profitmandi.dao.entity.dtr.User;
-
 
83
import com.spice.profitmandi.dao.entity.fofo.ActivityType;
84
import com.spice.profitmandi.dao.entity.fofo.ActivityType;
84
import com.spice.profitmandi.dao.entity.fofo.CustomerAddress;
85
import com.spice.profitmandi.dao.entity.fofo.CustomerAddress;
85
import com.spice.profitmandi.dao.entity.fofo.FofoLineItem;
86
import com.spice.profitmandi.dao.entity.fofo.FofoLineItem;
86
import com.spice.profitmandi.dao.entity.fofo.FofoOrder;
87
import com.spice.profitmandi.dao.entity.fofo.FofoOrder;
87
import com.spice.profitmandi.dao.entity.fofo.FofoOrderItem;
88
import com.spice.profitmandi.dao.entity.fofo.FofoOrderItem;
Line 102... Line 103...
102
import com.spice.profitmandi.dao.entity.user.FranchiseeVisit;
103
import com.spice.profitmandi.dao.entity.user.FranchiseeVisit;
103
import com.spice.profitmandi.dao.entity.user.Lead;
104
import com.spice.profitmandi.dao.entity.user.Lead;
104
import com.spice.profitmandi.dao.entity.user.Refferal;
105
import com.spice.profitmandi.dao.entity.user.Refferal;
105
import com.spice.profitmandi.dao.enumuration.catalog.SchemeType;
106
import com.spice.profitmandi.dao.enumuration.catalog.SchemeType;
106
import com.spice.profitmandi.dao.enumuration.cs.EscalationType;
107
import com.spice.profitmandi.dao.enumuration.cs.EscalationType;
107
import com.spice.profitmandi.dao.enumuration.dtr.PaymentOptionReferenceType;
-
 
108
import com.spice.profitmandi.dao.enumuration.dtr.RefferalStatus;
108
import com.spice.profitmandi.dao.enumuration.dtr.RefferalStatus;
109
import com.spice.profitmandi.dao.enumuration.fofo.ScanType;
109
import com.spice.profitmandi.dao.enumuration.fofo.ScanType;
110
import com.spice.profitmandi.dao.enumuration.transaction.PriceDropImeiStatus;
110
import com.spice.profitmandi.dao.enumuration.transaction.PriceDropImeiStatus;
111
import com.spice.profitmandi.dao.model.SimpleCampaign;
111
import com.spice.profitmandi.dao.model.SimpleCampaign;
112
import com.spice.profitmandi.dao.model.SimpleCampaignParams;
112
import com.spice.profitmandi.dao.model.SimpleCampaignParams;
Line 167... Line 167...
167
import com.spice.profitmandi.service.order.OrderService;
167
import com.spice.profitmandi.service.order.OrderService;
168
import com.spice.profitmandi.service.pricing.PriceDropService;
168
import com.spice.profitmandi.service.pricing.PriceDropService;
169
import com.spice.profitmandi.service.recharge.provider.OxigenRechargeProviderService;
169
import com.spice.profitmandi.service.recharge.provider.OxigenRechargeProviderService;
170
import com.spice.profitmandi.service.recharge.provider.ThinkWalnutDigitalRechargeProviderService;
170
import com.spice.profitmandi.service.recharge.provider.ThinkWalnutDigitalRechargeProviderService;
171
import com.spice.profitmandi.service.scheme.SchemeService;
171
import com.spice.profitmandi.service.scheme.SchemeService;
172
import com.spice.profitmandi.service.slab.TargetSlabService;
-
 
173
import com.spice.profitmandi.service.transaction.TransactionService;
172
import com.spice.profitmandi.service.transaction.TransactionService;
174
import com.spice.profitmandi.service.user.RetailerService;
173
import com.spice.profitmandi.service.user.RetailerService;
175
import com.spice.profitmandi.service.wallet.WalletService;
174
import com.spice.profitmandi.service.wallet.WalletService;
176
 
175
 
177
import in.shop2020.model.v1.order.OrderStatus;
176
import in.shop2020.model.v1.order.OrderStatus;
Line 349... Line 348...
349
	private DailyRechargeRepository dailyRechargeRepository;
348
	private DailyRechargeRepository dailyRechargeRepository;
350
 
349
 
351
	@Autowired
350
	@Autowired
352
	private FofoStoreRepository fofoStoreRepository;
351
	private FofoStoreRepository fofoStoreRepository;
353
 
352
 
354
	@Autowired
-
 
355
	private TargetSlabService targetService;
-
 
356
 
-
 
357
	@Value("${prod}")
353
	@Value("${prod}")
358
	private boolean prod;
354
	private boolean prod;
359
 
355
 
360
	@Autowired
356
	@Autowired
361
	private StateGstRateRepository stateGstRateRepository;
357
	private StateGstRateRepository stateGstRateRepository;
Line 990... Line 986...
990
 
986
 
991
	public void sendPartnerInvestmentDetails() throws Exception {
987
	public void sendPartnerInvestmentDetails() throws Exception {
992
		this.sendPartnerInvestmentDetails(null);
988
		this.sendPartnerInvestmentDetails(null);
993
	}
989
	}
994
 
990
 
995
	public void sendTargetVsSalesReport(List<String> sendTo) throws Exception {
-
 
996
 
-
 
997
		if (sendTo == null) {
-
 
998
			sendTo = Arrays.asList("tarun.verma@smartdukaan.com", "kamini.sharma@smartdukaan.com",
-
 
999
					"amit.gupta@shop2020.in", "hemant.kaura@smartdukaan.com", "amit.babu@smartdukaan.com",
-
 
1000
					"manish.gupta@smartdukaan.com");
-
 
1001
		}
-
 
1002
		Map<Integer, List<Serializable>> partnerSalesTargetRowsMap = targetService.getDailySaleReportVsTarget();
-
 
1003
 
-
 
1004
		Map<Integer, FofoReportingModel> partnerIdSalesHeadersMap = this.getPartnerIdSalesHeaders();
-
 
1005
 
-
 
1006
		List<String> headers = Arrays.asList("Code", "Firm Name", "State Manager", "Teritory Manager",
-
 
1007
				"Current Category", "Target Value", "Target Achieved", "Achived Percentage", "Remaining Target",
-
 
1008
				"Today's Target", "Today's achievement");
-
 
1009
 
-
 
1010
		List<List<?>> rows = new ArrayList<>();
-
 
1011
		Map<Integer, List<? extends Serializable>> partnerRowMap = new HashMap<>();
-
 
1012
		for (Map.Entry<Integer, List<Serializable>> partnerSalesTargetRowEntry : partnerSalesTargetRowsMap.entrySet()) {
-
 
1013
			FofoReportingModel fofoReportingModel = partnerIdSalesHeadersMap.get(partnerSalesTargetRowEntry.getKey());
-
 
1014
			if (fofoReportingModel == null) {
-
 
1015
				LOGGER.warn("Could not find headers for partner ID - {}", partnerSalesTargetRowEntry.getKey());
-
 
1016
				continue;
-
 
1017
			}
-
 
1018
			List<Serializable> row = Arrays.asList(fofoReportingModel.getCode(), fofoReportingModel.getBusinessName(),
-
 
1019
					fofoReportingModel.getRegionalManager(), fofoReportingModel.getTerritoryManager());
-
 
1020
			row.addAll(partnerSalesTargetRowEntry.getValue());
-
 
1021
			partnerRowMap.put(partnerSalesTargetRowEntry.getKey(), row);
-
 
1022
			rows.add(row);
-
 
1023
		}
-
 
1024
 
-
 
1025
		String fileName = "TargetVsSales-" + FormattingUtils.formatDate(LocalDateTime.now()) + ".csv";
-
 
1026
		Map<String, Set<String>> storeGuysMap = csService.getAuthUserPartnerEmailMapping();
-
 
1027
		for (Map.Entry<String, Set<String>> storeGuyEntry : storeGuysMap.entrySet()) {
-
 
1028
			if (storeGuyEntry.getValue().size() == 0)
-
 
1029
				continue;
-
 
1030
			List<List<?>> storeGuyRows = storeGuyEntry.getValue().stream().filter(x -> partnerRowMap.containsKey(x))
-
 
1031
					.map(x -> partnerRowMap.get(x)).collect(Collectors.toList());
-
 
1032
			ByteArrayOutputStream authUserStream = FileUtil.getCSVByteStream(headers, storeGuyRows);
-
 
1033
			Attachment attache = new Attachment(fileName, new ByteArrayResource(authUserStream.toByteArray()));
-
 
1034
			System.out.println(storeGuyEntry.getValue());
-
 
1035
			Utils.sendMailWithAttachments(googleMailSender, new String[] { storeGuyEntry.getKey() }, null,
-
 
1036
					"Franchise Stock Report", "PFA", attache);
-
 
1037
		}
-
 
1038
 
-
 
1039
		ByteArrayOutputStream baos = FileUtil.getCSVByteStream(headers, rows);
-
 
1040
		String[] sendToArray = sendTo.toArray(new String[sendTo.size()]);
-
 
1041
		Utils.sendMailWithAttachment(googleMailSender, sendToArray, null, "Target vs Sales Summary", "PFA", fileName,
-
 
1042
				new ByteArrayResource(baos.toByteArray()));
-
 
1043
	}
-
 
1044
 
-
 
1045
	public void sendAgeingReport(String... sendTo) throws Exception {
991
	public void sendAgeingReport(String... sendTo) throws Exception {
1046
 
992
 
1047
		InputStreamSource isr = reporticoService.getReportInputStreamSource(ReporticoProject.WAREHOUSENEW,
993
		InputStreamSource isr = reporticoService.getReportInputStreamSource(ReporticoProject.WAREHOUSENEW,
1048
				"itemstockageing.xml");
994
				"itemstockageing.xml");
1049
		InputStreamSource isr1 = reporticoService.getReportInputStreamSource(ReporticoProject.FOCO,
995
		InputStreamSource isr1 = reporticoService.getReportInputStreamSource(ReporticoProject.FOCO,
Line 1923... Line 1869...
1923
				insurancePolicyRepository.selectQtyGroupByRetailerId(LocalDateTime.MIN, LocalDateTime.MAX));
1869
				insurancePolicyRepository.selectQtyGroupByRetailerId(LocalDateTime.MIN, LocalDateTime.MAX));
1924
		LOGGER.info("SmartPhone Amount Summary --- {}",
1870
		LOGGER.info("SmartPhone Amount Summary --- {}",
1925
				fofoOrderItemRepository.selectSumAmountGroupByRetailer(LocalDateTime.MIN, LocalDateTime.MAX, 0, true));
1871
				fofoOrderItemRepository.selectSumAmountGroupByRetailer(LocalDateTime.MIN, LocalDateTime.MAX, 0, true));
1926
		LOGGER.info("Smartphone Qty Summary --- {}",
1872
		LOGGER.info("Smartphone Qty Summary --- {}",
1927
				fofoOrderItemRepository.selectQtyGroupByRetailer(LocalDateTime.MIN, LocalDateTime.MAX, 0, true));
1873
				fofoOrderItemRepository.selectQtyGroupByRetailer(LocalDateTime.MIN, LocalDateTime.MAX, 0, true));
-
 
1874
		List<InsurancePolicy> insurancePolicies = insurancePolicyRepository.selectAllByProviderId(3, Optional.of(false));
1928
		// LOGGER.info("{}", toffeeService.getAuthToken());
1875
		for(InsurancePolicy insurancePolicy : insurancePolicies) {
1929
		/*
-
 
1930
		 * LOGGER.info("{}", toffeeService.getProducts()); // LOGGER.info("{}",
1876
			String invoiceNumber = insurancePolicy.getInvoiceNumber();
1931
		 * toffeeService.getPincodes("36103000PR")); PremiumCalculationRequestModel pcrm
1877
			FofoOrder fofoOrder = fofoOrderRepository.selectByInvoiceNumber(invoiceNumber);
1932
		 * = new PremiumCalculationRequestModel(); pcrm.setProductDetails("36103000PR");
1878
			PdfModel pdfModel = orderService.getInvoicePdfModel(fofoOrder.getId());
1933
		 * // pcrm.setProductDetails("36103000PR");
1879
			java.io.ByteArrayOutputStream byteArrayOutputStream = new java.io.ByteArrayOutputStream();
1934
		 * pcrm.setDurations(Arrays.asList("3 Months", "6 Months", "1 Year"));
1880
			PdfUtils.generateAndWrite(Arrays.asList(pdfModel), byteArrayOutputStream);
-
 
1881
			String pdfInvoiceString = "data:application/pdf;base64," + DatatypeConverter.printHexBinary(byteArrayOutputStream.toByteArray());
-
 
1882
			boolean attached = toffeeService.attachInvoice(insurancePolicy.getPolicyNumber().split("#")[1], pdfInvoiceString);
1935
		 * pcrm.setSumInsured("15000");
1883
			if(attached) {
1936
		 * System.out.println(toffeeService.getPremiumCalculation(pcrm));
1884
				insurancePolicy.setPosted(true);
1937
		 */
1885
			}
-
 
1886
		}
1938
	}
1887
	}
1939
 
1888
 
1940
	public void schemeRollback(List<String> schemeIds) throws Exception {
1889
	public void schemeRollback(List<String> schemeIds) throws Exception {
1941
		List<Integer> schemeIdsInt = schemeIds.stream().map(x -> Integer.parseInt(x)).collect(Collectors.toList());
1890
		List<Integer> schemeIdsInt = schemeIds.stream().map(x -> Integer.parseInt(x)).collect(Collectors.toList());
1942
		Map<Integer, Scheme> schemesMap = schemeRepository.selectBySchemeIds(schemeIdsInt, 0, schemeIds.size()).stream()
1891
		Map<Integer, Scheme> schemesMap = schemeRepository.selectBySchemeIds(schemeIdsInt, 0, schemeIds.size()).stream()