Subversion Repositories SmartDukaan

Rev

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

Rev 26940 Rev 26941
Line 1378... Line 1378...
1378
		} else {
1378
		} else {
1379
			fofoIds = Arrays.asList(fofoIdInt);
1379
			fofoIds = Arrays.asList(fofoIdInt);
1380
		}
1380
		}
1381
		DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("h:m a");
1381
		DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("h:m a");
1382
 
1382
 
1383
		Map<Integer, Double> salesByFofoIdMap = new HashMap<>();
-
 
1384
		Map<Integer, Float> partnerPolicyAmountMap = insurancePolicyRepository.selectAmountSumGroupByRetailerId(now,
1383
		Map<Integer, Float> partnerPolicyAmountMap = insurancePolicyRepository.selectAmountSumGroupByRetailerId(now,
1385
				null);
1384
				null);
1386
		Map<Integer, Long> partnerPolicyQtyMap = insurancePolicyRepository.selectQtyGroupByRetailerId(now, null);
1385
		Map<Integer, Long> partnerPolicyQtyMap = insurancePolicyRepository.selectQtyGroupByRetailerId(now, null);
-
 
1386
		
1387
		Map<Integer, Double> partnerOrderAmountMap = fofoOrderItemRepository.selectSumAmountGroupByRetailer(from, now,
1387
		Map<Integer, Double> spPartnerOrderValMap = fofoOrderItemRepository.selectSumAmountGroupByRetailer(from, now,
1388
				0, true);
1388
				0, true);
1389
		Map<Integer, Long> partnerOrderQtyMap = fofoOrderItemRepository.selectQtyGroupByRetailer(from, now, 0, true);
1389
		Map<Integer, Long> spPartnerOrderQtyMap = fofoOrderItemRepository.selectQtyGroupByRetailer(from, now, 0, true);
-
 
1390
 
-
 
1391
		Map<Integer, Double> partnerOrderValMap = fofoOrderItemRepository.selectSumAmountGroupByRetailer(from, now,
-
 
1392
				0, false);
-
 
1393
		Map<Integer, Long> partnerOrderQtyMap = fofoOrderItemRepository.selectQtyGroupByRetailer(from, now, 0, false);
-
 
1394
		
1390
		Map<Integer, SaleTargetReportModel> saleTargetReportModelMap = new HashMap<>();
1395
		Map<Integer, SaleTargetReportModel> saleTargetReportModelMap = new HashMap<>();
1391
		for (int fofoId : fofoIds) {
1396
		for (int fofoId : fofoIds) {
1392
			SaleTargetReportModel model = new SaleTargetReportModel();
1397
			SaleTargetReportModel model = new SaleTargetReportModel();
1393
			model.setInsuranceSale(
1398
			model.setInsuranceSale(
1394
					partnerPolicyAmountMap.containsKey(fofoId) ? partnerPolicyAmountMap.get(fofoId).doubleValue() : 0);
1399
					partnerPolicyAmountMap.containsKey(fofoId) ? partnerPolicyAmountMap.get(fofoId).doubleValue() : 0);
1395
			model.setInsruanceQty(partnerPolicyQtyMap.containsKey(fofoId) ? partnerPolicyQtyMap.get(fofoId) : 0);
1400
			model.setInsruanceQty(partnerPolicyQtyMap.containsKey(fofoId) ? partnerPolicyQtyMap.get(fofoId) : 0);
1396
			model.setSmartphoneSale(partnerOrderAmountMap.containsKey(fofoId) ? partnerOrderAmountMap.get(fofoId) : 0);
1401
			model.setSmartphoneSale(spPartnerOrderValMap.containsKey(fofoId) ? spPartnerOrderValMap.get(fofoId) : 0);
1397
			model.setSmartphoneQty(partnerOrderQtyMap.containsKey(fofoId) ? partnerOrderQtyMap.get(fofoId) : 0);
1402
			model.setSmartphoneQty(spPartnerOrderQtyMap.containsKey(fofoId) ? spPartnerOrderQtyMap.get(fofoId) : 0);
1398
			model.setTotalSale(salesByFofoIdMap.containsKey(fofoId) ? salesByFofoIdMap.get(fofoId) : 0);
1403
			model.setTotalSale(partnerOrderValMap.containsKey(fofoId) ? partnerOrderValMap.get(fofoId) : 0);
-
 
1404
			model.setTotalQty(partnerOrderQtyMap.containsKey(fofoId) ? partnerOrderQtyMap.get(fofoId) : 0);
1399
			model.setFofoId(fofoId);
1405
			model.setFofoId(fofoId);
1400
			saleTargetReportModelMap.put(fofoId, model);
1406
			saleTargetReportModelMap.put(fofoId, model);
1401
		}
1407
		}
1402
 
1408
 
1403
		Map<Integer, List<Serializable>> partnerSalesHeadersMap = this.getPartnerIdSalesHeaders();
1409
		Map<Integer, List<Serializable>> partnerSalesHeadersMap = this.getPartnerIdSalesHeaders();
Line 1417... Line 1423...
1417
			int userId = userAccountRepository.selectUserIdByRetailerId(fofoId);
1423
			int userId = userAccountRepository.selectUserIdByRetailerId(fofoId);
1418
			sendNotificationModel.setUserIds(Arrays.asList(userId));
1424
			sendNotificationModel.setUserIds(Arrays.asList(userId));
1419
			notificationService.sendNotification(sendNotificationModel);
1425
			notificationService.sendNotification(sendNotificationModel);
1420
		}
1426
		}
1421
		String saleReport = this.getDailySalesReportHtml(partnerSalesHeadersMap, saleTargetReportModelMap);
1427
		String saleReport = this.getDailySalesReportHtml(partnerSalesHeadersMap, saleTargetReportModelMap);
1422
		String statewiseSaleReport = this.getStateWiseSales(partnerOrderQtyMap, partnerOrderAmountMap);
1428
		String statewiseSaleReport = this.getStateWiseSales(saleTargetReportModelMap);
1423
		LOGGER.info(saleReport);
1429
		LOGGER.info(saleReport);
1424
		String cc[] = { "tarun.verma@smartdukaan.com", "kamini.sharma@smartdukaan.com", "prakash.rai@smartdukaan.com",
1430
		String cc[] = { "tarun.verma@smartdukaan.com", "kamini.sharma@smartdukaan.com", "prakash.rai@smartdukaan.com",
1425
				"niranjan.kala@smartdukaan.com", "up.singh@smartdukaan.com", "shankar.mushra@smartdukaan.com" };
1431
				"niranjan.kala@smartdukaan.com", "up.singh@smartdukaan.com", "shankar.mushra@smartdukaan.com" };
1426
 
1432
 
1427
		String subject = String.format("Sale till %s", String.format(timeString, now.format(timeFormatter)));
1433
		String subject = String.format("Sale till %s", String.format(timeString, now.format(timeFormatter)));
Line 1429... Line 1435...
1429
		this.sendMailOfHtmlFomat("amit.gupta@smartdukaan.com", statewiseSaleReport, cc, "Statewise" + subject);
1435
		this.sendMailOfHtmlFomat("amit.gupta@smartdukaan.com", statewiseSaleReport, cc, "Statewise" + subject);
1430
	}
1436
	}
1431
 
1437
 
1432
	public static class SaleTargetReportModel {
1438
	public static class SaleTargetReportModel {
1433
		private double totalSale;
1439
		private double totalSale;
-
 
1440
		private long totalQty;
1434
		private int fofoId;
1441
		private int fofoId;
1435
 
1442
 
1436
		public int getFofoId() {
1443
		public int getFofoId() {
1437
			return fofoId;
1444
			return fofoId;
1438
		}
1445
		}
Line 1444... Line 1451...
1444
		private double smartphoneSale;
1451
		private double smartphoneSale;
1445
		private long smartphoneQty;
1452
		private long smartphoneQty;
1446
		private double insuranceSale;
1453
		private double insuranceSale;
1447
		private long insruanceQty;
1454
		private long insruanceQty;
1448
 
1455
 
-
 
1456
		
-
 
1457
		public long getTotalQty() {
-
 
1458
			return totalQty;
-
 
1459
		}
-
 
1460
 
-
 
1461
		public void setTotalQty(long totalQty) {
-
 
1462
			this.totalQty = totalQty;
-
 
1463
		}
-
 
1464
 
1449
		@Override
1465
		@Override
1450
		public int hashCode() {
1466
		public int hashCode() {
1451
			final int prime = 31;
1467
			final int prime = 31;
1452
			int result = 1;
1468
			int result = 1;
1453
			result = prime * result + fofoId;
1469
			result = prime * result + fofoId;
Line 1456... Line 1472...
1456
			temp = Double.doubleToLongBits(insuranceSale);
1472
			temp = Double.doubleToLongBits(insuranceSale);
1457
			result = prime * result + (int) (temp ^ (temp >>> 32));
1473
			result = prime * result + (int) (temp ^ (temp >>> 32));
1458
			result = prime * result + (int) (smartphoneQty ^ (smartphoneQty >>> 32));
1474
			result = prime * result + (int) (smartphoneQty ^ (smartphoneQty >>> 32));
1459
			temp = Double.doubleToLongBits(smartphoneSale);
1475
			temp = Double.doubleToLongBits(smartphoneSale);
1460
			result = prime * result + (int) (temp ^ (temp >>> 32));
1476
			result = prime * result + (int) (temp ^ (temp >>> 32));
-
 
1477
			result = prime * result + (int) (totalQty ^ (totalQty >>> 32));
1461
			temp = Double.doubleToLongBits(totalSale);
1478
			temp = Double.doubleToLongBits(totalSale);
1462
			result = prime * result + (int) (temp ^ (temp >>> 32));
1479
			result = prime * result + (int) (temp ^ (temp >>> 32));
1463
			return result;
1480
			return result;
1464
		}
1481
		}
1465
 
1482
 
Line 1480... Line 1497...
1480
				return false;
1497
				return false;
1481
			if (smartphoneQty != other.smartphoneQty)
1498
			if (smartphoneQty != other.smartphoneQty)
1482
				return false;
1499
				return false;
1483
			if (Double.doubleToLongBits(smartphoneSale) != Double.doubleToLongBits(other.smartphoneSale))
1500
			if (Double.doubleToLongBits(smartphoneSale) != Double.doubleToLongBits(other.smartphoneSale))
1484
				return false;
1501
				return false;
-
 
1502
			if (totalQty != other.totalQty)
-
 
1503
				return false;
1485
			if (Double.doubleToLongBits(totalSale) != Double.doubleToLongBits(other.totalSale))
1504
			if (Double.doubleToLongBits(totalSale) != Double.doubleToLongBits(other.totalSale))
1486
				return false;
1505
				return false;
1487
			return true;
1506
			return true;
1488
		}
1507
		}
1489
 
1508
 
Line 1527... Line 1546...
1527
			this.insruanceQty = insruanceQty;
1546
			this.insruanceQty = insruanceQty;
1528
		}
1547
		}
1529
 
1548
 
1530
		@Override
1549
		@Override
1531
		public String toString() {
1550
		public String toString() {
1532
			return "SaleTargetReportModel [totalSale=" + totalSale + ", fofoId=" + fofoId + ", smartphoneSale="
1551
			return "SaleTargetReportModel [totalSale=" + totalSale + ", totalQty=" + totalQty + ", fofoId=" + fofoId
1533
					+ smartphoneSale + ", smartphoneQty=" + smartphoneQty + ", insuranceSale=" + insuranceSale
1552
					+ ", smartphoneSale=" + smartphoneSale + ", smartphoneQty=" + smartphoneQty + ", insuranceSale="
1534
					+ ", insruanceQty=" + insruanceQty + "]";
1553
					+ insuranceSale + ", insruanceQty=" + insruanceQty + "]";
1535
		}
1554
		}
1536
 
1555
 
1537
	}
1556
	}
1538
 
1557
 
1539
	private String getStateWiseSales(Map<Integer, Long> partnerOrderQtyMap, Map<Integer, Double> partnerOrderAmountMap) {
1558
	private String getStateWiseSales(Map<Integer, SaleTargetReportModel> saleTargetReportModelMap) {
1540
		List<FofoStore> stores = fofoStoreRepository.selectActiveStores();
1559
		List<FofoStore> stores = fofoStoreRepository.selectActiveStores();
1541
		Map<String, List<Integer>> stateMap = stores.stream().collect(Collectors.groupingBy(
1560
		Map<String, List<Integer>> stateMap = stores.stream().collect(Collectors.groupingBy(
1542
									x->x.getCode().substring(0,1), 
1561
									x->x.getCode().substring(0,1), 
1543
									Collectors.mapping(x->x.getId(), Collectors.toList())));
1562
									Collectors.mapping(x->x.getId(), Collectors.toList())));
1544
		List<List<Serializable>> stateWiseSales = new ArrayList<>();
1563
		List<List<Serializable>> stateWiseSales = new ArrayList<>();
1545
		for (Map.Entry<String, List<Integer>> stateMapEntry : stateMap.entrySet()) {
1564
		for (Map.Entry<String, List<Integer>> stateMapEntry : stateMap.entrySet()) {
1546
			long totalQty = stateMapEntry.getValue().stream().collect(Collectors.summingLong(x->partnerOrderQtyMap.get(x)));
1565
			long totalQty = stateMapEntry.getValue().stream().collect(Collectors.summingLong(x->saleTargetReportModelMap.get(x).getTotalQty()));
1547
			double totalSale = stateMapEntry.getValue().stream().collect(Collectors.summingDouble(x->partnerOrderAmountMap.get(x)));
1566
			double totalSale = stateMapEntry.getValue().stream().collect(Collectors.summingDouble(x->saleTargetReportModelMap.get(x).getTotalSale()));
-
 
1567
			long smartPhoneQty = stateMapEntry.getValue().stream().collect(Collectors.summingLong(x->saleTargetReportModelMap.get(x).getSmartphoneQty()));
-
 
1568
			double smartPhoneSale = stateMapEntry.getValue().stream().collect(Collectors.summingDouble(x->saleTargetReportModelMap.get(x).getSmartphoneSale()));
1548
			stateWiseSales.add(Arrays.asList(stateMapEntry.getKey(), totalQty, totalSale));
1569
			stateWiseSales.add(Arrays.asList(stateMapEntry.getKey(), smartPhoneQty, smartPhoneSale, totalQty, totalSale));
1549
		}
1570
		}
1550
		StringBuilder sb = new StringBuilder();
1571
		StringBuilder sb = new StringBuilder();
1551
		sb.append("<html><body><p>Statewise Sale Report:</p><br/><table style='border:1px solid black';cellspacing=0>");
1572
		sb.append("<html><body><p>Statewise Sale Report:</p><br/><table style='border:1px solid black';cellspacing=0>");
1552
		sb.append("<tbody>\n" + "	    <tr>"
1573
		sb.append("<tbody>\n" + "	    <tr>"
1553
				+ "	    					<th style='border:1px solid black;padding: 5px'>State</th>"
1574
				+ "	    					<th style='border:1px solid black;padding: 5px'>State</th>"
-
 
1575
				+ "	    					<th style='border:1px solid black;padding: 5px'>SmartPhone Qty</th>"
-
 
1576
				+ "	    					<th style='border:1px solid black;padding: 5px'>SmartPhone Value</th>"
1554
				+ "	    					<th style='border:1px solid black;padding: 5px'>Sale Qty</th>"
1577
				+ "	    					<th style='border:1px solid black;padding: 5px'>Total Qty</th>"
1555
				+ "	    					<th style='border:1px solid black;padding: 5px'>Sale Value</th>"
1578
				+ "	    					<th style='border:1px solid black;padding: 5px'>Total Value</th>"
1556
				+ "	    				</tr>");
1579
				+ "	    				</tr>");
1557
		for (List<Serializable> stateSale : stateWiseSales) {
1580
		for (List<Serializable> stateSale : stateWiseSales) {
1558
			sb.append("<tr>");
1581
			sb.append("<tr>");
1559
			sb.append("<td style='border:1px solid black;padding: 5px'>" + stateSale.get(0) + "</td>");
1582
			sb.append("<td style='border:1px solid black;padding: 5px'>" + stateSale.get(0) + "</td>");
1560
			sb.append("<td style='border:1px solid black;padding: 5px'>" + stateSale.get(1) + "</td>");
1583
			sb.append("<td style='border:1px solid black;padding: 5px'>" + stateSale.get(1) + "</td>");
1561
			sb.append("<td style='border:1px solid black;padding: 5px'>" + stateSale.get(2) + "</td>");
1584
			sb.append("<td style='border:1px solid black;padding: 5px'>" + stateSale.get(2) + "</td>");
-
 
1585
			sb.append("<td style='border:1px solid black;padding: 5px'>" + stateSale.get(3) + "</td>");
-
 
1586
			sb.append("<td style='border:1px solid black;padding: 5px'>" + stateSale.get(4) + "</td>");
1562
			sb.append("</tr>");
1587
			sb.append("</tr>");
1563
		}
1588
		}
1564
		sb.append("</tbody></table></body></html>");
1589
		sb.append("</tbody></table></body></html>");
1565
		return sb.toString();
1590
		return sb.toString();
1566
	}
1591
	}