Subversion Repositories SmartDukaan

Rev

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

Rev 25856 Rev 25865
Line 230... Line 230...
230
	private static final String[] ITEMWISE_PENDING_INDENT_MAIL_LIST = new String[] { "kamini.sharma@smartdukaan.com",
230
	private static final String[] ITEMWISE_PENDING_INDENT_MAIL_LIST = new String[] { "kamini.sharma@smartdukaan.com",
231
			"prakash.rai@smartdukaan.com", "tarun.verma@smartdukaan.com", "chaitnaya.vats@smartdukaan.com",
231
			"prakash.rai@smartdukaan.com", "tarun.verma@smartdukaan.com", "chaitnaya.vats@smartdukaan.com",
232
			"kuldeep.kumar@smartdukaan.com" };
232
			"kuldeep.kumar@smartdukaan.com" };
233
 
233
 
234
	private List<OrderStatus> orderStatusList = Arrays.asList(OrderStatus.SUBMITTED_FOR_PROCESSING);
234
	private List<OrderStatus> orderStatusList = Arrays.asList(OrderStatus.SUBMITTED_FOR_PROCESSING);
-
 
235
	
-
 
236
	private List<String> REPORT_HEADERS = Arrays.asList("Store Code", "Firm Name", "Store Name", "State Manager", "Teritory Manager");
235
 
237
 
236
	@Autowired
238
	@Autowired
237
	private ReporticoService reporticoService;
239
	private ReporticoService reporticoService;
238
 
240
 
239
	@Autowired
241
	@Autowired
Line 242... Line 244...
242
	@Autowired
244
	@Autowired
243
	private PositionRepository positionRepository;
245
	private PositionRepository positionRepository;
244
 
246
 
245
	@Autowired
247
	@Autowired
246
	private FofoOrderItemRepository fofoOrderItemRepository;
248
	private FofoOrderItemRepository fofoOrderItemRepository;
247
	
249
 
248
	@Autowired
250
	@Autowired
249
	private NotificationService notificationService;
251
	private NotificationService notificationService;
250
 
252
 
251
	@Autowired
253
	@Autowired
252
	private PartnerDailyInvestmentRepository partnerDailyInvestmentRepository;
254
	private PartnerDailyInvestmentRepository partnerDailyInvestmentRepository;
Line 761... Line 763...
761
 
763
 
762
		Map<Integer, List<Serializable>> partnerIdSalesHeadersMap = new HashMap<>();
764
		Map<Integer, List<Serializable>> partnerIdSalesHeadersMap = new HashMap<>();
763
 
765
 
764
		for (CustomRetailer cr : allCrList) {
766
		for (CustomRetailer cr : allCrList) {
765
			FofoStore fofoStore = fofoStoresMap.get(cr.getPartnerId());
767
			FofoStore fofoStore = fofoStoresMap.get(cr.getPartnerId());
766
			String code = fofoStore.getCode();
768
			String code = fofoStore.getCode() + "";
767
			String storeName = "SmartDukaan-" + fofoStore.getCode().replaceAll("[a-zA-Z]", "");
769
			String storeName = "SmartDukaan-" + fofoStore.getCode().replaceAll("[a-zA-Z]", "");
768
			String businessName = cr.getBusinessName();
770
			String businessName = cr.getBusinessName();
769
			try {
771
			try {
770
				String stateManager = StringUtils.join(partnerEmailSalesMap.get(cr.getEmail()).getL2(), ", ");
772
				String stateManager = StringUtils.join(partnerEmailSalesMap.get(cr.getEmail()).getL2(), ", ");
771
				String territoryManager = StringUtils.join(partnerEmailSalesMap.get(cr.getEmail()).getL1(), ", ");
773
				String territoryManager = StringUtils.join(partnerEmailSalesMap.get(cr.getEmail()).getL1(), ", ");
Line 1300... Line 1302...
1300
 
1302
 
1301
	public void sendDailySalesNotificationToPartner(Integer fofoIdInt)
1303
	public void sendDailySalesNotificationToPartner(Integer fofoIdInt)
1302
			throws ProfitMandiBusinessException, MessagingException, IOException {
1304
			throws ProfitMandiBusinessException, MessagingException, IOException {
1303
		LocalDateTime now = LocalDateTime.now();
1305
		LocalDateTime now = LocalDateTime.now();
1304
		LocalDateTime from = now.with(LocalTime.MIN);
1306
		LocalDateTime from = now.with(LocalTime.MIN);
1305
		Map<Integer, Double> salesByFofoIdMap = new HashMap<>();
-
 
1306
		List<Integer> fofoIds = null;
1307
		List<Integer> fofoIds = null;
1307
		if (fofoIdInt == null) {
1308
		if (fofoIdInt == null) {
1308
			fofoIds = fofoStoreRepository.selectAll().stream().filter(x -> x.isActive()).map(x -> x.getId())
1309
			fofoIds = fofoStoreRepository.selectAll().stream().filter(x -> x.isActive()).map(x -> x.getId())
1309
					.collect(Collectors.toList());
1310
					.collect(Collectors.toList());
1310
		} else {
1311
		} else {
1311
			fofoIds = Arrays.asList(fofoIdInt);
1312
			fofoIds = Arrays.asList(fofoIdInt);
1312
		}
1313
		}
1313
		DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("h a");
1314
		DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("h a");
1314
 
1315
 
1315
		Map<Integer, Float> dailyTarget = new HashMap<>();
1316
		Map<Integer, Double> salesByFofoIdMap = new HashMap<>();
-
 
1317
		Map<Integer, Float> partnerPolicyAmountMap = insurancePolicyRepository.selectAmountSumGroupByRetailerId(now,
-
 
1318
				null);
-
 
1319
		Map<Integer, Long> partnerPolicyQtyMap = insurancePolicyRepository.selectQtyGroupByRetailerId(now, null);
-
 
1320
		Map<Integer, Double> partnerOrderAmountMap = fofoOrderItemRepository.selectSumAmountGroupByRetailer(from, now,
-
 
1321
				0, true);
-
 
1322
		Map<Integer, Long> partnerOrderQtyMap = fofoOrderItemRepository.selectQtyGroupByRetailer(from, now, 0, true);
-
 
1323
		Map<Integer, SaleTargetReportModel> saleTargetReportModelMap = new HashMap<>();
-
 
1324
		for (int fofoId : fofoIds) {
-
 
1325
			SaleTargetReportModel model = new SaleTargetReportModel();
-
 
1326
			model.setInsuranceSale(partnerPolicyAmountMap.containsKey(fofoId) ? partnerPolicyAmountMap.get(fofoId) : 0);
-
 
1327
			model.setInsruanceQty(partnerPolicyQtyMap.containsKey(fofoId) ? partnerPolicyQtyMap.get(fofoId) : 0);
-
 
1328
			model.setSmartphoneSale(partnerOrderAmountMap.containsKey(fofoId) ? partnerOrderAmountMap.get(fofoId) : 0);
-
 
1329
			model.setSmartphoneQty(partnerOrderQtyMap.containsKey(fofoId) ? partnerOrderQtyMap.get(fofoId) : 0);
-
 
1330
			model.setTotalSale(salesByFofoIdMap.containsKey(fofoId) ? salesByFofoIdMap.get(fofoId) : 0);
-
 
1331
			saleTargetReportModelMap.put(fofoId, model);
-
 
1332
		}
-
 
1333
		
-
 
1334
		Map<Integer, List<Serializable>> partnerSalesHeadersMap = this.getPartnerIdSalesHeaders();
1316
		for (Integer fofoId : fofoIds) {
1335
		for (Integer fofoId : fofoIds) {
1317
			double sale = fofoOrderRepository.selectTotalSaleSumByFofoIdBetweenDate(fofoId, from, now);
1336
			SaleTargetReportModel model = saleTargetReportModelMap.get(fofoId);
1318
 
-
 
1319
			SendNotificationModel sendNotificationModel = new SendNotificationModel();
1337
			SendNotificationModel sendNotificationModel = new SendNotificationModel();
1320
			sendNotificationModel.setCampaignName("Sales update alert");
1338
			sendNotificationModel.setCampaignName("Sales update alert");
1321
			sendNotificationModel.setMessage(String.format(
1339
			sendNotificationModel.setMessage(String.format(
1322
					"Smartphones Rs.%.0f, Insurance Rs.%.0f, Total Rs.%.0f till %s.", sale, now.format(timeFormatter)));
1340
					"Smartphones Rs.%.0f, Insurance Rs.%.0f, Total Rs.%.0f till %s.", model.getSmartphoneSale(),
-
 
1341
					model.getInsuranceSale(), model.getTotalSale(), now.format(timeFormatter)));
1323
			sendNotificationModel.setType("url");
1342
			sendNotificationModel.setType("url");
1324
			sendNotificationModel.setUrl("http://app.profitmandi.com/pages/home/notifications");
1343
			sendNotificationModel.setUrl("http://app.profitmandi.com/pages/home/notifications");
1325
			sendNotificationModel.setExpiresat(LocalDateTime.now().plusDays(1));
1344
			sendNotificationModel.setExpiresat(LocalDateTime.now().plusDays(1));
1326
			sendNotificationModel.setMessageType(MessageType.notification);
1345
			sendNotificationModel.setMessageType(MessageType.notification);
-
 
1346
			sendNotificationModel.setUserIds(Arrays.asList(fofoId));
1327
			notificationService.sendNotification(sendNotificationModel);
1347
			notificationService.sendNotification(sendNotificationModel);
1328
			salesByFofoIdMap.put(fofoId, sale);
-
 
1329
			LOGGER.info(sale);
-
 
1330
		}
1348
		}
1331
		Map<Integer, Float> parternPolicyAmountMap = insurancePolicyRepository.selectAmountSumGroupByRetailerId(now,
-
 
1332
				null);
-
 
1333
		Map<Integer, Long> parternPolicyQtyMap = insurancePolicyRepository.selectQtyGroupByRetailerId(now, null);
-
 
1334
		Map<Integer, Long> parternOrderQtyMap = insurancePolicyRepository.selectQtyGroupByRetailerId(now, null);
-
 
1335
		String saleReport = this.getDailySalesReportByPartnerId(salesByFofoIdMap, dailyTarget);
1349
		String saleReport = this.getDailySalesReportHtml(partnerSalesHeadersMap, saleTargetReportModelMap);
1336
		LOGGER.info(saleReport);
1350
		LOGGER.info(saleReport);
1337
		String cc[] = { "tarun.verma@smartdukaan.com", "kamini.sharma@smartdukaan.com", "prakash.rai@smartdukaan.com",
1351
		String cc[] = { "tarun.verma@smartdukaan.com", "kamini.sharma@smartdukaan.com", "prakash.rai@smartdukaan.com",
1338
				"chaitnaya.vats@smartdukaan.com" };
1352
				"chaitnaya.vats@smartdukaan.com" };
1339
 
1353
 
1340
		String subject = String.format("Sale till %s", now.format(timeFormatter));
1354
		String subject = String.format("Sale till %s", now.format(timeFormatter));
1341
		this.sendMailOfHtmlFomat("amit.gupta@shop2020.in", saleReport, cc, subject);
1355
		this.sendMailOfHtmlFomat("amit.gupta@shop2020.in", saleReport, cc, subject);
1342
	}
1356
	}
1343
 
1357
 
-
 
1358
	public static class SaleTargetReportModel {
-
 
1359
		private double totalSale;
-
 
1360
		private double smartphoneSale;
-
 
1361
		private long smartphoneQty;
-
 
1362
		private double insuranceSale;
-
 
1363
		private long insruanceQty;
-
 
1364
 
-
 
1365
		@Override
-
 
1366
		public int hashCode() {
-
 
1367
			final int prime = 31;
-
 
1368
			int result = 1;
-
 
1369
			result = prime * result + (int) (insruanceQty ^ (insruanceQty >>> 32));
-
 
1370
			long temp;
-
 
1371
			temp = Double.doubleToLongBits(insuranceSale);
-
 
1372
			result = prime * result + (int) (temp ^ (temp >>> 32));
-
 
1373
			result = prime * result + (int) (smartphoneQty ^ (smartphoneQty >>> 32));
-
 
1374
			temp = Double.doubleToLongBits(smartphoneSale);
-
 
1375
			result = prime * result + (int) (temp ^ (temp >>> 32));
-
 
1376
			temp = Double.doubleToLongBits(totalSale);
-
 
1377
			result = prime * result + (int) (temp ^ (temp >>> 32));
-
 
1378
			return result;
-
 
1379
		}
-
 
1380
 
-
 
1381
		@Override
-
 
1382
		public boolean equals(Object obj) {
-
 
1383
			if (this == obj)
-
 
1384
				return true;
-
 
1385
			if (obj == null)
-
 
1386
				return false;
-
 
1387
			if (getClass() != obj.getClass())
-
 
1388
				return false;
-
 
1389
			SaleTargetReportModel other = (SaleTargetReportModel) obj;
-
 
1390
			if (insruanceQty != other.insruanceQty)
-
 
1391
				return false;
-
 
1392
			if (Double.doubleToLongBits(insuranceSale) != Double.doubleToLongBits(other.insuranceSale))
-
 
1393
				return false;
-
 
1394
			if (smartphoneQty != other.smartphoneQty)
-
 
1395
				return false;
-
 
1396
			if (Double.doubleToLongBits(smartphoneSale) != Double.doubleToLongBits(other.smartphoneSale))
-
 
1397
				return false;
-
 
1398
			if (Double.doubleToLongBits(totalSale) != Double.doubleToLongBits(other.totalSale))
-
 
1399
				return false;
-
 
1400
			return true;
-
 
1401
		}
-
 
1402
 
-
 
1403
		public double getTotalSale() {
-
 
1404
			return totalSale;
-
 
1405
		}
-
 
1406
 
-
 
1407
		public void setTotalSale(double totalSale) {
-
 
1408
			this.totalSale = totalSale;
-
 
1409
		}
-
 
1410
 
-
 
1411
		public double getSmartphoneSale() {
-
 
1412
			return smartphoneSale;
-
 
1413
		}
-
 
1414
 
-
 
1415
		public void setSmartphoneSale(double smartphoneSale) {
-
 
1416
			this.smartphoneSale = smartphoneSale;
-
 
1417
		}
-
 
1418
 
-
 
1419
		public long getSmartphoneQty() {
-
 
1420
			return smartphoneQty;
-
 
1421
		}
-
 
1422
 
-
 
1423
		public void setSmartphoneQty(long smartphoneQty) {
-
 
1424
			this.smartphoneQty = smartphoneQty;
-
 
1425
		}
-
 
1426
 
-
 
1427
		public double getInsuranceSale() {
-
 
1428
			return insuranceSale;
-
 
1429
		}
-
 
1430
 
-
 
1431
		public void setInsuranceSale(double insuranceSale) {
-
 
1432
			this.insuranceSale = insuranceSale;
-
 
1433
		}
-
 
1434
 
-
 
1435
		public long getInsruanceQty() {
-
 
1436
			return insruanceQty;
-
 
1437
		}
-
 
1438
 
-
 
1439
		public void setInsruanceQty(long insruanceQty) {
-
 
1440
			this.insruanceQty = insruanceQty;
-
 
1441
		}
-
 
1442
 
-
 
1443
		@Override
-
 
1444
		public String toString() {
-
 
1445
			return "SaleTargetReportModel [totalSale=" + totalSale + ", smartphoneSale=" + smartphoneSale
-
 
1446
					+ ", smartphoneQty=" + smartphoneQty + ", insuranceSale=" + insuranceSale + ", insruanceQty="
-
 
1447
					+ insruanceQty + "]";
-
 
1448
		}
-
 
1449
 
-
 
1450
	}
-
 
1451
 
1344
	private String getDailySalesReportByPartnerId(Map<Integer, Double> salesByFofoIdMap,
1452
	private String getDailySalesReportHtml(Map<Integer, List<Serializable>> partnerSalesHeadersMap,
-
 
1453
			Map<Integer, SaleTargetReportModel> saleReportTargetMap)
1345
			Map<Integer, Float> dailyTarget) throws ProfitMandiBusinessException {
1454
			throws ProfitMandiBusinessException {
1346
		StringBuilder sb = new StringBuilder();
1455
		StringBuilder sb = new StringBuilder();
-
 
1456
		
1347
		sb.append("<html><body><p>Sale Report:</p><br/><table style='border:1px solid black';cellspacing=0>");
1457
		sb.append("<html><body><p>Sale Report:</p><br/><table style='border:1px solid black';cellspacing=0>");
1348
		sb.append("<tbody>\n" + "	    				<tr>\n"
1458
		sb.append("<tbody>\n" + "	    				<tr>\n"
-
 
1459
				+ "	    					<th style='border:1px solid black;padding: 5px'>%s</th>\n"
1349
				+ "	    					<th style='border:1px solid black;padding: 5px'>Partner</th>\n"
1460
				+ "	    					<th style='border:1px solid black;padding: 5px'>%s</th>\n"
-
 
1461
				+ "	    					<th style='border:1px solid black;padding: 5px'>%s</th>\n"
-
 
1462
				+ "	    					<th style='border:1px solid black;padding: 5px'>%s</th>\n"
1350
				+ "	    					<th style='border:1px solid black;padding: 5px'>Daily Target</th>\n"
1463
				+ "	    					<th style='border:1px solid black;padding: 5px'>%s</th>\n"
1351
				+ "	    					<th style='border:1px solid black;padding: 5px'>Sale</th>\n"
1464
				+ "	    					<th style='border:1px solid black;padding: 5px'>Sale</th>\n"
-
 
1465
				+ "	    					<th style='border:1px solid black;padding: 5px'>Smartphone Sale</th>\n"
-
 
1466
				+ "	    					<th style='border:1px solid black;padding: 5px'>SmartPhone Qty</th>\n"
-
 
1467
				+ "	    					<th style='border:1px solid black;padding: 5px'>Insurance Sale</th>\n"
-
 
1468
				+ "	    					<th style='border:1px solid black;padding: 5px'>Insurance Qty</th>\n"
1352
				+ "	    				</tr>");
1469
				+ "	    				</tr>");
1353
		for (Integer fofoId : salesByFofoIdMap.keySet()) {
1470
		for (Integer fofoId : saleReportTargetMap.keySet()) {
1354
			try {
-
 
1355
				String PartnerName = retailerService.getFofoRetailer(fofoId).getBusinessName();
-
 
1356
				sb.append("<tr>");
1471
			sb.append("<tr>");
1357
				sb.append("<td style='border:1px solid black;padding: 5px'>" + PartnerName + "</td>");
1472
			sb.append("<td style='border:1px solid black;padding: 5px'>" + partnerSalesHeadersMap.get(fofoId).get(0) + "</td>");
1358
				if (dailyTarget != null && dailyTarget.get(fofoId) != null) {
1473
			sb.append("<td style='border:1px solid black;padding: 5px'>" + partnerSalesHeadersMap.get(fofoId).get(1) + "</td>");
1359
					sb.append("<td style='border:1px solid black;padding: 5px'>" + dailyTarget.get(fofoId) + "</td>");
1474
			sb.append("<td style='border:1px solid black;padding: 5px'>" + partnerSalesHeadersMap.get(fofoId).get(2) + "</td>");
1360
				} else {
-
 
1361
					sb.append("<td style='border:1px solid black;padding: 5px'>" + 0.0 + "</td>");
1475
			sb.append("<td style='border:1px solid black;padding: 5px'>" + partnerSalesHeadersMap.get(fofoId).get(3) + "</td>");
1362
				}
-
 
1363
				sb.append("<td style='border:1px solid black;padding: 5px'>" + salesByFofoIdMap.get(fofoId) + "</td>");
1476
			sb.append("<td style='border:1px solid black;padding: 5px'>" + partnerSalesHeadersMap.get(fofoId).get(4) + "</td>");
1364
 
-
 
-
 
1477
			sb.append("<td style='border:1px solid black;padding: 5px'>" + saleReportTargetMap.get(fofoId).getTotalSale() + "</td>");
-
 
1478
			sb.append("<td style='border:1px solid black;padding: 5px'>" + saleReportTargetMap.get(fofoId).getSmartphoneSale() + "</td>");
-
 
1479
			sb.append("<td style='border:1px solid black;padding: 5px'>" + saleReportTargetMap.get(fofoId).getSmartphoneQty() + "</td>");
-
 
1480
			sb.append("<td style='border:1px solid black;padding: 5px'>" + saleReportTargetMap.get(fofoId).getInsuranceSale() + "</td>");
-
 
1481
			sb.append("<td style='border:1px solid black;padding: 5px'>" + saleReportTargetMap.get(fofoId).getInsruanceQty() + "</td>");
1365
				sb.append("</tr>");
1482
			sb.append("</tr>");
1366
			} catch (Exception e) {
-
 
1367
				e.printStackTrace();
-
 
1368
			}
-
 
1369
 
1483
 
1370
		}
1484
		}
1371
 
1485
 
1372
		sb.append("</tbody></table></body></html>");
1486
		sb.append("</tbody></table></body></html>");
1373
		return sb.toString();
1487
		return String.format(sb.toString(), REPORT_HEADERS);
1374
	}
1488
	}
1375
 
1489
 
1376
	private void sendMailOfHtmlFomat(String email, String body, String cc[], String subject)
1490
	private void sendMailOfHtmlFomat(String email, String body, String cc[], String subject)
1377
			throws MessagingException, ProfitMandiBusinessException, IOException {
1491
			throws MessagingException, ProfitMandiBusinessException, IOException {
1378
		MimeMessage message = mailSender.createMimeMessage();
1492
		MimeMessage message = mailSender.createMimeMessage();