Subversion Repositories SmartDukaan

Rev

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

Rev 30390 Rev 30393
Line 236... Line 236...
236
	private ServiceConfigRepository serviceConfigRepository;
236
	private ServiceConfigRepository serviceConfigRepository;
237
 
237
 
238
	@Value("${delhivery.tracking.token}")
238
	@Value("${delhivery.tracking.token}")
239
	private String token;
239
	private String token;
240
 
240
 
241
	private static final String[] STOCK_AGEING_MAIL_LIST = new String[] { "uday.singh@smartudkaan.com",
241
	private static final String[] STOCK_AGEING_MAIL_LIST = new String[]{"uday.singh@smartudkaan.com",
242
			"mohinder.mutreja@smartdukaan.com", "ankit.bhatia@smartdukaan.com", "tarun.verma@smartdukaan.com",
242
			"mohinder.mutreja@smartdukaan.com", "ankit.bhatia@smartdukaan.com", "tarun.verma@smartdukaan.com",
243
			"kuldeep.kumar@smartdukaan.com", "manish.gupta@smartdukaan.com" };
243
			"kuldeep.kumar@smartdukaan.com", "manish.gupta@smartdukaan.com"};
244
 
244
 
245
	private static final String[] ITEMWISE_PENDING_INDENT_MAIL_LIST = new String[] { "kamini.sharma@smartdukaan.com",
245
	private static final String[] ITEMWISE_PENDING_INDENT_MAIL_LIST = new String[]{"kamini.sharma@smartdukaan.com",
246
			"tarun.verma@smartdukaan.com", "uday.singh@smartdukaan.com", "kuldeep.kumar@smartdukaan.com",
246
			"tarun.verma@smartdukaan.com", "uday.singh@smartdukaan.com", "kuldeep.kumar@smartdukaan.com",
247
			"niranjan.kala@smartdukaan.com" };
247
			"niranjan.kala@smartdukaan.com"};
248
 
248
 
249
	private static final String[] INDENT_TERTIARY_MAIL_LIST = new String[] { "uday.singh@smartdukaan.com",
249
	private static final String[] INDENT_TERTIARY_MAIL_LIST = new String[]{"uday.singh@smartdukaan.com",
250
			"kuldeep.kumar@smartdukaan.com" };
250
			"kuldeep.kumar@smartdukaan.com"};
251
 
251
 
252
	private static final String[] EMPLOYEE_ATTENDANCE_MAIL_LIST = new String[] { "jyoti.rawat@smartdukaan.com",
252
	private static final String[] EMPLOYEE_ATTENDANCE_MAIL_LIST = new String[]{"jyoti.rawat@smartdukaan.com",
253
			"sm@smartdukaan.com" };
253
			"sm@smartdukaan.com"};
254
 
254
 
255
	private List<OrderStatus> orderStatusList = Arrays.asList(OrderStatus.SUBMITTED_FOR_PROCESSING);
255
	private List<OrderStatus> orderStatusList = Arrays.asList(OrderStatus.SUBMITTED_FOR_PROCESSING);
256
 
256
 
257
	@Autowired
257
	@Autowired
258
	private ReporticoService reporticoService;
258
	private ReporticoService reporticoService;
Line 579... Line 579...
579
			}
579
			}
580
 
580
 
581
		}
581
		}
582
	}
582
	}
583
 
583
 
584
	// Temporary Method
584
	@Autowired
585
	public void evaluateExcessSchemeOut() throws Exception {
-
 
586
		Map<Integer, String> userNameMap = retailerService.getAllFofoRetailerIdNameMap();
-
 
587
		Map<Integer, Float> userAmountMap = new HashMap<>();
-
 
588
 
-
 
589
		List<List<?>> rows = new ArrayList<>();
-
 
590
		List<String> headers = Arrays.asList("Scheme", "Item", "Partner", "Amount", "Credited On", "Invoice Number",
-
 
591
				"Sale On", "Scheme Start", "Scheme End", "Active On", "Expired On");
-
 
592
		schemeRepository.selectAll().stream().forEach(x -> {
-
 
593
			if (x.getType().equals(SchemeType.OUT)) {
-
 
594
				List<SchemeInOut> sioList = schemeInOutRepository
-
 
595
						.selectBySchemeIds(new HashSet<>(Arrays.asList(x.getId())));
-
 
596
				if (x.getActiveTimestamp() != null) {
-
 
597
					LocalDateTime endDateTime = x.getEndDateTime();
-
 
598
					if (x.getExpireTimestamp() != null && x.getExpireTimestamp().isBefore(x.getEndDateTime())) {
-
 
599
						endDateTime = x.getExpireTimestamp();
-
 
600
					}
-
 
601
					for (SchemeInOut sio : sioList) {
-
 
602
						InventoryItem inventoryItem = null;
-
 
603
						inventoryItem = inventoryItemRepository.selectById(sio.getInventoryItemId());
-
 
604
						FofoOrder fofoOrder = fofoOrderRepository.selectByFofoIdAndSerialNumber(
-
 
605
								inventoryItem.getFofoId(), inventoryItem.getSerialNumber(), null, null, 0, 1).get(0);
-
 
606
						Optional<ScanRecord> record = scanRecordRepository
585
	private ReporticoCacheTableRepository reporticoCacheTableRepository;
607
								.selectByInventoryItemId(sio.getInventoryItemId()).stream()
-
 
608
								.filter(y -> y.getType().equals(ScanType.SALE)).findFirst();
-
 
609
						if (record.isPresent()) {
-
 
610
							int fofoId = record.get().getFofoId();
-
 
611
							if (record.get().getCreateTimestamp().isAfter(endDateTime)
-
 
612
									|| record.get().getCreateTimestamp().isBefore(x.getStartDateTime())) {
-
 
613
								if (!userAmountMap.containsKey(fofoId)) {
-
 
614
									userAmountMap.put(fofoId, 0f);
-
 
615
								}
-
 
616
								userAmountMap.put(fofoId, sio.getAmount() + userAmountMap.get(fofoId));
-
 
617
								try {
-
 
618
									rows.add(Arrays.asList(x.getDescription(),
-
 
619
											itemRepository.selectById(inventoryItem.getItemId()).getItemDescription(),
-
 
620
											userNameMap.get(fofoId), sio.getAmount(),
-
 
621
											FormattingUtils.formatDate(sio.getCreateTimestamp()),
-
 
622
											fofoOrder.getInvoiceNumber(),
-
 
623
											FormattingUtils.formatDate(record.get().getCreateTimestamp()),
-
 
624
											FormattingUtils.formatDate(x.getStartDateTime()),
-
 
625
											FormattingUtils.formatDate(x.getEndDateTime()),
-
 
626
											FormattingUtils.formatDate(x.getActiveTimestamp()),
-
 
627
											FormattingUtils.formatDate(x.getExpireTimestamp())));
-
 
628
								} catch (Exception e) {
-
 
629
									e.printStackTrace();
-
 
630
								}
-
 
631
							}
-
 
632
						}
-
 
633
					}
-
 
634
				}
-
 
635
			}
-
 
636
		});
-
 
637
		userAmountMap.entrySet().stream()
-
 
638
				.forEach(x -> LOGGER.info("{} to be deducted from {}({}) for wrongly disbursed due to technical error.",
-
 
639
						x.getValue(), userNameMap.get(x.getKey())));
-
 
640
 
-
 
641
		ByteArrayOutputStream baos = FileUtil.getCSVByteStream(headers, rows);
-
 
642
		Utils.sendMailWithAttachment(googleMailSender,
-
 
643
				new String[] { "amit.gupta@shop2020.in", "adeel.yazdani@smartdukaan.com" }, null,
-
 
644
				"Partner Excess Amount", "PFA", "ListofSchemes.csv", new ByteArrayResource(baos.toByteArray()));
-
 
645
 
-
 
646
	}
-
 
647
 
586
 
648
	public void processScheme(int offset, boolean dryRun) throws Exception {
587
	public void processScheme(int offset, boolean dryRun) throws Exception {
649
		LocalDateTime startDate = LocalDateTime.of(LocalDate.now(), LocalTime.MIDNIGHT).minusDays(offset);
588
		LocalDateTime startDate = LocalDateTime.of(LocalDate.now(), LocalTime.MIDNIGHT).minusDays(offset);
650
		LocalDateTime endDate = startDate.plusDays(30);
589
		LocalDateTime endDate = startDate.plusDays(30);
651
		processScheme(startDate, endDate, dryRun);
590
		processScheme(startDate, endDate, dryRun);
Line 800... Line 739...
800
		}
739
		}
801
	}
740
	}
802
 
741
 
803
	@Autowired
742
	@Autowired
804
	private PartnerStatsService partnerStatsService;
743
	private PartnerStatsService partnerStatsService;
-
 
744
 
-
 
745
	// Temporary Method
-
 
746
	public void evaluateExcessSchemeOut() throws Exception {
-
 
747
		Map<Integer, String> userNameMap = retailerService.getAllFofoRetailerIdNameMap();
-
 
748
		Map<Integer, Float> userAmountMap = new HashMap<>();
-
 
749
 
-
 
750
		List<List<?>> rows = new ArrayList<>();
-
 
751
		List<String> headers = Arrays.asList("Scheme", "Item", "Partner", "Amount", "Credited On", "Invoice Number",
-
 
752
				"Sale On", "Scheme Start", "Scheme End", "Active On", "Expired On");
-
 
753
		schemeRepository.selectAll().stream().forEach(x -> {
-
 
754
			if (x.getType().equals(SchemeType.OUT)) {
-
 
755
				List<SchemeInOut> sioList = schemeInOutRepository
-
 
756
						.selectBySchemeIds(new HashSet<>(Arrays.asList(x.getId())));
-
 
757
				if (x.getActiveTimestamp() != null) {
-
 
758
					LocalDateTime endDateTime = x.getEndDateTime();
-
 
759
					if (x.getExpireTimestamp() != null && x.getExpireTimestamp().isBefore(x.getEndDateTime())) {
-
 
760
						endDateTime = x.getExpireTimestamp();
-
 
761
					}
-
 
762
					for (SchemeInOut sio : sioList) {
-
 
763
						InventoryItem inventoryItem = null;
-
 
764
						inventoryItem = inventoryItemRepository.selectById(sio.getInventoryItemId());
-
 
765
						FofoOrder fofoOrder = fofoOrderRepository.selectByFofoIdAndSerialNumber(
-
 
766
								inventoryItem.getFofoId(), inventoryItem.getSerialNumber(), null, null, 0, 1).get(0);
805
	private ReporticoCacheTableRepository reporticoCacheTableRepository;
767
						Optional<ScanRecord> record = scanRecordRepository
-
 
768
								.selectByInventoryItemId(sio.getInventoryItemId()).stream()
-
 
769
								.filter(y -> y.getType().equals(ScanType.SALE)).findFirst();
-
 
770
						if (record.isPresent()) {
-
 
771
							int fofoId = record.get().getFofoId();
-
 
772
							if (record.get().getCreateTimestamp().isAfter(endDateTime)
-
 
773
									|| record.get().getCreateTimestamp().isBefore(x.getStartDateTime())) {
-
 
774
								if (!userAmountMap.containsKey(fofoId)) {
-
 
775
									userAmountMap.put(fofoId, 0f);
-
 
776
								}
-
 
777
								userAmountMap.put(fofoId, sio.getAmount() + userAmountMap.get(fofoId));
-
 
778
								try {
-
 
779
									rows.add(Arrays.asList(x.getDescription(),
-
 
780
											itemRepository.selectById(inventoryItem.getItemId()).getItemDescription(),
-
 
781
											userNameMap.get(fofoId), sio.getAmount(),
-
 
782
											FormattingUtils.formatDate(sio.getCreateTimestamp()),
-
 
783
											fofoOrder.getInvoiceNumber(),
-
 
784
											FormattingUtils.formatDate(record.get().getCreateTimestamp()),
-
 
785
											FormattingUtils.formatDate(x.getStartDateTime()),
-
 
786
											FormattingUtils.formatDate(x.getEndDateTime()),
-
 
787
											FormattingUtils.formatDate(x.getActiveTimestamp()),
-
 
788
											FormattingUtils.formatDate(x.getExpireTimestamp())));
-
 
789
								} catch (Exception e) {
-
 
790
									e.printStackTrace();
-
 
791
								}
-
 
792
							}
-
 
793
						}
-
 
794
					}
-
 
795
				}
-
 
796
			}
-
 
797
		});
-
 
798
		userAmountMap.entrySet().stream()
-
 
799
				.forEach(x -> LOGGER.info("{} to be deducted from {}({}) for wrongly disbursed due to technical error.",
-
 
800
						x.getValue(), userNameMap.get(x.getKey())));
-
 
801
 
-
 
802
		ByteArrayOutputStream baos = FileUtil.getCSVByteStream(headers, rows);
-
 
803
		Utils.sendMailWithAttachment(googleMailSender,
-
 
804
				new String[]{"amit.gupta@shop2020.in", "adeel.yazdani@smartdukaan.com"}, null,
-
 
805
				"Partner Excess Amount", "PFA", "ListofSchemes.csv", new ByteArrayResource(baos.toByteArray()));
-
 
806
 
-
 
807
	}
806
 
808
 
807
	public void fetchParnterStats() throws Exception {
809
	public void fetchParnterStats() throws Exception {
808
		Map<Integer, PartnerDetailModel> partnerStats = partnerStatsService.getAllPartnerStats();
810
		Map<Integer, PartnerDetailModel> partnerStats = partnerStatsService.getAllPartnerStats();
809
		ObjectOutputStream oos = null;
811
		ObjectOutputStream oos = null;
810
		FileOutputStream fout = null;
812
		FileOutputStream fout = null;
Line 822... Line 824...
822
		}
824
		}
823
		ReporticoCacheTable rct = reporticoCacheTableRepository.selectByTableName("partnerStat");
825
		ReporticoCacheTable rct = reporticoCacheTableRepository.selectByTableName("partnerStat");
824
		if (rct == null) {
826
		if (rct == null) {
825
			rct = new ReporticoCacheTable();
827
			rct = new ReporticoCacheTable();
826
			rct.setTableName("partnerStat");
828
			rct.setTableName("partnerStat");
-
 
829
			rct.setLastCreatedTimestamp(LocalDateTime.now());
-
 
830
			reporticoCacheTableRepository.persist(rct);
827
 
831
		} else {
-
 
832
			rct.setLastCreatedTimestamp(LocalDateTime.now());
828
		}
833
		}
829
		rct.setLastCreatedTimestamp(LocalDateTime.now());
-
 
830
		reporticoCacheTableRepository.persist(rct);
-
 
831
	}
834
	}
832
 
835
 
833
	private class SaleRoles {
836
	private class SaleRoles {
834
 
837
 
835
		private List<String> l1;
838
		private List<String> l1;
Line 1135... Line 1138...
1135
			InputStreamSource isr3 = reporticoService.getReportInputStreamSource(ReporticoProject.FOCO,
1138
			InputStreamSource isr3 = reporticoService.getReportInputStreamSource(ReporticoProject.FOCO,
1136
					"focostockreport.xml", params);
1139
					"focostockreport.xml", params);
1137
			Attachment attache = new Attachment(
1140
			Attachment attache = new Attachment(
1138
					"Franchise-stock-report" + FormattingUtils.formatDate(LocalDateTime.now()) + ".csv", isr3);
1141
					"Franchise-stock-report" + FormattingUtils.formatDate(LocalDateTime.now()) + ".csv", isr3);
1139
			System.out.println(storeGuyEntry.getValue());
1142
			System.out.println(storeGuyEntry.getValue());
1140
			Utils.sendMailWithAttachments(googleMailSender, new String[] { storeGuyEntry.getKey() }, null,
1143
			Utils.sendMailWithAttachments(googleMailSender, new String[]{storeGuyEntry.getKey()}, null,
1141
					"Franchise Stock Report", "PFA", attache);
1144
					"Franchise Stock Report", "PFA", attache);
1142
		}
1145
		}
1143
 
1146
 
1144
	}
1147
	}
1145
 
1148
 
Line 1186... Line 1189...
1186
				String body = String.format(
1189
				String body = String.format(
1187
						"Dear %s,\n Pls note that you haven't punched your attendance by 10:30am%s. You have been marked absent for half the day.\n\nRegards\nHR Team",
1190
						"Dear %s,\n Pls note that you haven't punched your attendance by 10:30am%s. You have been marked absent for half the day.\n\nRegards\nHR Team",
1188
						authUser.getFullName(),
1191
						authUser.getFullName(),
1189
						(employeeAttendanceOptional == null || employeeAttendanceOptional.orElse(null) == null) ? ""
1192
						(employeeAttendanceOptional == null || employeeAttendanceOptional.orElse(null) == null) ? ""
1190
								: "(Punched at "
1193
								: "(Punched at "
1191
										+ FormattingUtils.format(employeeAttendanceOptional.get().getCreateTimestamp())
1194
								+ FormattingUtils.format(employeeAttendanceOptional.get().getCreateTimestamp())
1192
										+ ")");
1195
								+ ")");
1193
 
1196
 
1194
				Utils.sendMailWithAttachments(googleMailSender, new String[] { authUser.getEmailId() },
1197
				Utils.sendMailWithAttachments(googleMailSender, new String[]{authUser.getEmailId()},
1195
						new String[] { "jyoti.rawat@smartdukaan.com" }, "Attendance Alert", body);
1198
						new String[]{"jyoti.rawat@smartdukaan.com"}, "Attendance Alert", body);
1196
 
1199
 
1197
			}
1200
			}
1198
		}
1201
		}
1199
 
1202
 
1200
	}
1203
	}
Line 1240... Line 1243...
1240
					}
1243
					}
1241
				}
1244
				}
1242
 
1245
 
1243
			}
1246
			}
1244
			if (body != null) {
1247
			if (body != null) {
1245
				Utils.sendMailWithAttachments(googleMailSender, new String[] { authUser.getEmailId() },
1248
				Utils.sendMailWithAttachments(googleMailSender, new String[]{authUser.getEmailId()},
1246
						new String[] { "jyoti.rawat@smartdukaan.com" }, "Attendance Alert", body);
1249
						new String[]{"jyoti.rawat@smartdukaan.com"}, "Attendance Alert", body);
1247
			}
1250
			}
1248
		}
1251
		}
1249
 
1252
 
1250
		this.sendMailToHR();
1253
		this.sendMailToHR();
1251
 
1254
 
Line 1276... Line 1279...
1276
 
1279
 
1277
					fofoStore.setActive(true);
1280
					fofoStore.setActive(true);
1278
					fofoStoreRepository.persist(fofoStore);
1281
					fofoStoreRepository.persist(fofoStore);
1279
					LOGGER.info("inserted into InActiveFofoStore successfully");
1282
					LOGGER.info("inserted into InActiveFofoStore successfully");
1280
 
1283
 
1281
				}
-
 
1282
 
-
 
1283
				else {
1284
				} else {
1284
					fofoStore.setActive(false);
1285
					fofoStore.setActive(false);
1285
					fofoStore.setActiveTimeStamp(null);
1286
					fofoStore.setActiveTimeStamp(null);
1286
					fofoStoreRepository.persist(fofoStore);
1287
					fofoStoreRepository.persist(fofoStore);
1287
					LOGGER.info("inserted into InActiveFofoStore successfully");
1288
					LOGGER.info("inserted into InActiveFofoStore successfully");
1288
				}
1289
				}
Line 1552... Line 1553...
1552
				rolledbackSios.stream()
1553
				rolledbackSios.stream()
1553
						.map(x -> Arrays.asList(x.getSchemeId(), x.getSchemeType(), x.getReference(), x.getStoreCode(),
1554
						.map(x -> Arrays.asList(x.getSchemeId(), x.getSchemeType(), x.getReference(), x.getStoreCode(),
1554
								x.getSerialNumber(), x.getAmount(), x.getCreateTimestamp(), x.getRolledBackTimestamp()))
1555
								x.getSerialNumber(), x.getAmount(), x.getCreateTimestamp(), x.getRolledBackTimestamp()))
1555
						.collect(Collectors.toList()));
1556
						.collect(Collectors.toList()));
1556
 
1557
 
1557
		Utils.sendMailWithAttachments(googleMailSender, new String[] { "amit.gupta@shop2020.in" }, null,
1558
		Utils.sendMailWithAttachments(googleMailSender, new String[]{"amit.gupta@shop2020.in"}, null,
1558
				"Partner Excess Amount Scheme In", "PFA",
1559
				"Partner Excess Amount Scheme In", "PFA",
1559
				new Attachment[] { new Attachment("WalletSummary.csv", new ByteArrayResource(baos.toByteArray())),
1560
				new Attachment[]{new Attachment("WalletSummary.csv", new ByteArrayResource(baos.toByteArray())),
1560
						new Attachment("SchemeInRolledback.csv", new ByteArrayResource(baosOuts.toByteArray())) });
1561
						new Attachment("SchemeInRolledback.csv", new ByteArrayResource(baosOuts.toByteArray()))});
1561
 
1562
 
1562
		throw new Exception();
1563
		throw new Exception();
1563
 
1564
 
1564
	}
1565
	}
1565
 
1566
 
Line 1663... Line 1664...
1663
				rolledbackSios.stream()
1664
				rolledbackSios.stream()
1664
						.map(x -> Arrays.asList(x.getSchemeId(), x.getSchemeType(), x.getStoreCode(),
1665
						.map(x -> Arrays.asList(x.getSchemeId(), x.getSchemeType(), x.getStoreCode(),
1665
								x.getSerialNumber(), x.getAmount(), x.getCreateTimestamp(), x.getRolledBackTimestamp()))
1666
								x.getSerialNumber(), x.getAmount(), x.getCreateTimestamp(), x.getRolledBackTimestamp()))
1666
						.collect(Collectors.toList()));
1667
						.collect(Collectors.toList()));
1667
 
1668
 
1668
		Utils.sendMailWithAttachments(googleMailSender, new String[] { "amit.gupta@shop2020.in" }, null,
1669
		Utils.sendMailWithAttachments(googleMailSender, new String[]{"amit.gupta@shop2020.in"}, null,
1669
				"Partner Excess Amount Scheme Out", "PFA",
1670
				"Partner Excess Amount Scheme Out", "PFA",
1670
				new Attachment[] { new Attachment("WalletSummary.csv", new ByteArrayResource(baos.toByteArray())),
1671
				new Attachment[]{new Attachment("WalletSummary.csv", new ByteArrayResource(baos.toByteArray())),
1671
						new Attachment("SchemeOutRolledback.csv", new ByteArrayResource(baosOuts.toByteArray())) });
1672
						new Attachment("SchemeOutRolledback.csv", new ByteArrayResource(baosOuts.toByteArray()))});
1672
 
1673
 
1673
		throw new Exception();
1674
		throw new Exception();
1674
	}
1675
	}
1675
 
1676
 
1676
	public void dryRunSchemeOutReco1() throws Exception {
1677
	public void dryRunSchemeOutReco1() throws Exception {
Line 1724... Line 1725...
1724
		});
1725
		});
1725
 
1726
 
1726
		ByteArrayOutputStream baos = FileUtil.getCSVByteStream(
1727
		ByteArrayOutputStream baos = FileUtil.getCSVByteStream(
1727
				Arrays.asList("User Id", "Reference Type", "Reference", "Amount", "Description", "Timestamp"),
1728
				Arrays.asList("User Id", "Reference Type", "Reference", "Amount", "Description", "Timestamp"),
1728
				userWalletHistory.stream().map(x -> Arrays.asList(x.getWalletId(), x.getReferenceType(),
1729
				userWalletHistory.stream().map(x -> Arrays.asList(x.getWalletId(), x.getReferenceType(),
1729
						x.getReference(), x.getAmount(), x.getDescription(), x.getTimestamp()))
1730
								x.getReference(), x.getAmount(), x.getDescription(), x.getTimestamp()))
1730
						.collect(Collectors.toList()));
1731
						.collect(Collectors.toList()));
1731
 
1732
 
1732
		ByteArrayOutputStream baosOuts = FileUtil.getCSVByteStream(
1733
		ByteArrayOutputStream baosOuts = FileUtil.getCSVByteStream(
1733
				Arrays.asList("Scheme ID", "SchemeType", "Store Code", "Serial Number", "Amount", "Created",
1734
				Arrays.asList("Scheme ID", "SchemeType", "Store Code", "Serial Number", "Amount", "Created",
1734
						"Rolledback"),
1735
						"Rolledback"),
Line 1736... Line 1737...
1736
						.map(x -> Arrays.asList(x.getSchemeId(), x.getSchemeType(), x.getStoreCode(),
1737
						.map(x -> Arrays.asList(x.getSchemeId(), x.getSchemeType(), x.getStoreCode(),
1737
								x.getSerialNumber(), x.getAmount(), x.getCreateTimestamp(), x.getRolledBackTimestamp()))
1738
								x.getSerialNumber(), x.getAmount(), x.getCreateTimestamp(), x.getRolledBackTimestamp()))
1738
						.collect(Collectors.toList()));
1739
						.collect(Collectors.toList()));
1739
 
1740
 
1740
		Utils.sendMailWithAttachments(googleMailSender,
1741
		Utils.sendMailWithAttachments(googleMailSender,
1741
				new String[] { "amit.gupta@shop2020.in", "neeraj.gupta@smartdukaan.com" }, null,
1742
				new String[]{"amit.gupta@shop2020.in", "neeraj.gupta@smartdukaan.com"}, null,
1742
				"Partner Excess Amount", "PFA",
1743
				"Partner Excess Amount", "PFA",
1743
				new Attachment[] { new Attachment("WalletSummary.csv", new ByteArrayResource(baos.toByteArray())),
1744
				new Attachment[]{new Attachment("WalletSummary.csv", new ByteArrayResource(baos.toByteArray())),
1744
						new Attachment("SchemeOutRolledback.csv", new ByteArrayResource(baosOuts.toByteArray())) });
1745
						new Attachment("SchemeOutRolledback.csv", new ByteArrayResource(baosOuts.toByteArray()))});
1745
 
1746
 
1746
		throw new Exception();
1747
		throw new Exception();
1747
 
1748
 
1748
	}
1749
	}
1749
 
1750
 
Line 1754... Line 1755...
1754
		String timeString = "Today %s";
1755
		String timeString = "Today %s";
1755
		// Send yesterday's report
1756
		// Send yesterday's report
1756
		/*
1757
		/*
1757
		 * if (now.getHour() < 13) { timeString = "Yesterday %s"; from =
1758
		 * if (now.getHour() < 13) { timeString = "Yesterday %s"; from =
1758
		 * now.minusDays(1).; now = from.with(LocalTime.MAX);
1759
		 * now.minusDays(1).; now = from.with(LocalTime.MAX);
1759
		 * 
1760
		 *
1760
		 * }
1761
		 * }
1761
		 */
1762
		 */
1762
		List<Integer> fofoIds = null;
1763
		List<Integer> fofoIds = null;
1763
		if (fofoIdInt == null) {
1764
		if (fofoIdInt == null) {
1764
			fofoIds = fofoStoreRepository.selectAll().stream().filter(x -> x.isActive()).map(x -> x.getId())
1765
			fofoIds = fofoStoreRepository.selectAll().stream().filter(x -> x.isActive()).map(x -> x.getId())
Line 1818... Line 1819...
1818
			notificationService.sendNotification(sendNotificationModel);
1819
			notificationService.sendNotification(sendNotificationModel);
1819
		}
1820
		}
1820
		// String saleReport = this.getDailySalesReportHtml(partnerSalesHeadersMap,
1821
		// String saleReport = this.getDailySalesReportHtml(partnerSalesHeadersMap,
1821
		// saleTargetReportModelMap);
1822
		// saleTargetReportModelMap);
1822
		String statewiseSaleReport = this.getStateWiseSales(saleTargetReportModelMap, partnerSalesHeadersMap);
1823
		String statewiseSaleReport = this.getStateWiseSales(saleTargetReportModelMap, partnerSalesHeadersMap);
1823
		String cc[] = { "tarun.verma@smartdukaan.com", "kamini.sharma@smartdukaan.com", "amit.babu@smartdukaan.com",
1824
		String cc[] = {"tarun.verma@smartdukaan.com", "kamini.sharma@smartdukaan.com", "amit.babu@smartdukaan.com",
1824
				"niranjan.kala@smartdukaan.com", "up.singh@smartdukaan.com", "sm@smartdukaan.com" };
1825
				"niranjan.kala@smartdukaan.com", "up.singh@smartdukaan.com", "sm@smartdukaan.com"};
1825
 
1826
 
1826
		String subject = String.format("Sale till %s", String.format(timeString, now.format(timeFormatter)));
1827
		String subject = String.format("Sale till %s", String.format(timeString, now.format(timeFormatter)));
1827
		// this.sendMailOfHtmlFomat("amit.gupta@smartukaan.com", saleReport, cc,
1828
		// this.sendMailOfHtmlFomat("amit.gupta@smartukaan.com", saleReport, cc,
1828
		// subject);
1829
		// subject);
1829
		this.sendMailOfHtmlFormat("amit.gupta@smartdukaan.com", statewiseSaleReport, cc, "Statewise" + subject);
1830
		this.sendMailOfHtmlFormat("amit.gupta@smartdukaan.com", statewiseSaleReport, cc, "Statewise" + subject);
Line 1864... Line 1865...
1864
 
1865
 
1865
						CustomRetailer customRetailer = retailerService.getFofoRetailer(po.getFofoId());
1866
						CustomRetailer customRetailer = retailerService.getFofoRetailer(po.getFofoId());
1866
						Customer customer = customerRepository.selectById(po.getCustomerId());
1867
						Customer customer = customerRepository.selectById(po.getCustomerId());
1867
						String[] customerEmail = null;
1868
						String[] customerEmail = null;
1868
						if (customer.getEmailId() != null) {
1869
						if (customer.getEmailId() != null) {
1869
							customerEmail = new String[] { customer.getEmailId() };
1870
							customerEmail = new String[]{customer.getEmailId()};
1870
						}
1871
						}
1871
						List<String> bccTo = Arrays.asList("kamini.sharma@smartdukaan.com",
1872
						List<String> bccTo = Arrays.asList("kamini.sharma@smartdukaan.com",
1872
								"tarun.verma@smartdukaan.com", "niranjan.kala@smartdukaan.com", "sm@smartdukaan.com",
1873
								"tarun.verma@smartdukaan.com", "niranjan.kala@smartdukaan.com", "sm@smartdukaan.com",
1873
								"tejbeer.kaur@shop2020.in", customRetailer.getEmail());
1874
								"tejbeer.kaur@shop2020.in", customRetailer.getEmail());
1874
						List<String> authUserEmails = csService.getAuthUserByPartnerId(customRetailer.getPartnerId());
1875
						List<String> authUserEmails = csService.getAuthUserByPartnerId(customRetailer.getPartnerId());
Line 2023... Line 2024...
2023
		}
2024
		}
2024
 
2025
 
2025
	}
2026
	}
2026
 
2027
 
2027
	private String getStateWiseSales(Map<Integer, SaleTargetReportModel> saleTargetReportModelMap,
2028
	private String getStateWiseSales(Map<Integer, SaleTargetReportModel> saleTargetReportModelMap,
2028
			Map<Integer, FofoReportingModel> partnerSalesHeadersMap) throws Exception {
2029
									 Map<Integer, FofoReportingModel> partnerSalesHeadersMap) throws Exception {
2029
		List<FofoStore> stores = fofoStoreRepository.selectActiveStores();
2030
		List<FofoStore> stores = fofoStoreRepository.selectActiveStores();
2030
		Map<String, List<Integer>> stateMap = stores.stream().collect(Collectors
2031
		Map<String, List<Integer>> stateMap = stores.stream().collect(Collectors
2031
				.groupingBy(x -> x.getCode().substring(0, 2), Collectors.mapping(x -> x.getId(), Collectors.toList())));
2032
				.groupingBy(x -> x.getCode().substring(0, 2), Collectors.mapping(x -> x.getId(), Collectors.toList())));
2032
		List<List<Serializable>> stateWiseSales = new ArrayList<>();
2033
		List<List<Serializable>> stateWiseSales = new ArrayList<>();
2033
		for (Map.Entry<String, List<Integer>> stateMapEntry : stateMap.entrySet()) {
2034
		for (Map.Entry<String, List<Integer>> stateMapEntry : stateMap.entrySet()) {
Line 2430... Line 2431...
2430
			}
2431
			}
2431
 
2432
 
2432
			/*
2433
			/*
2433
			 * if (!focusedModelShortageList.isEmpty()) { String subject = "Stock Alert";
2434
			 * if (!focusedModelShortageList.isEmpty()) { String subject = "Stock Alert";
2434
			 * String messageText = this.getMessage(focusedModelShortageList);
2435
			 * String messageText = this.getMessage(focusedModelShortageList);
2435
			 * 
2436
			 *
2436
			 * this.sendMailWithAttachments(subject, messageText,
2437
			 * this.sendMailWithAttachments(subject, messageText,
2437
			 * customRetailer.getEmail()); String notificationMessage =
2438
			 * customRetailer.getEmail()); String notificationMessage =
2438
			 * this.getNotificationMessage(focusedModelShortageList);
2439
			 * this.getNotificationMessage(focusedModelShortageList);
2439
			 * 
2440
			 *
2440
			 * LOGGER.info("notificationMessage" + notificationMessage);
2441
			 * LOGGER.info("notificationMessage" + notificationMessage);
2441
			 * 
2442
			 *
2442
			 * SendNotificationModel sendNotificationModel = new SendNotificationModel();
2443
			 * SendNotificationModel sendNotificationModel = new SendNotificationModel();
2443
			 * sendNotificationModel.setCampaignName("Stock Alert");
2444
			 * sendNotificationModel.setCampaignName("Stock Alert");
2444
			 * sendNotificationModel.setTitle("Alert");
2445
			 * sendNotificationModel.setTitle("Alert");
2445
			 * sendNotificationModel.setMessage(notificationMessage);
2446
			 * sendNotificationModel.setMessage(notificationMessage);
2446
			 * sendNotificationModel.setType("url"); sendNotificationModel.setUrl(
2447
			 * sendNotificationModel.setType("url"); sendNotificationModel.setUrl(
Line 2448... Line 2449...
2448
			 * sendNotificationModel.setExpiresat(LocalDateTime.now().plusDays(2));
2449
			 * sendNotificationModel.setExpiresat(LocalDateTime.now().plusDays(2));
2449
			 * sendNotificationModel.setMessageType(MessageType.notification); int userId =
2450
			 * sendNotificationModel.setMessageType(MessageType.notification); int userId =
2450
			 * userAccountRepository.selectUserIdByRetailerId(fofoId);
2451
			 * userAccountRepository.selectUserIdByRetailerId(fofoId);
2451
			 * sendNotificationModel.setUserIds(Arrays.asList(userId));
2452
			 * sendNotificationModel.setUserIds(Arrays.asList(userId));
2452
			 * notificationService.sendNotification(sendNotificationModel);
2453
			 * notificationService.sendNotification(sendNotificationModel);
2453
			 * 
2454
			 *
2454
			 * }
2455
			 * }
2455
			 */
2456
			 */
2456
 
2457
 
2457
		}
2458
		}
2458
		if (!focusedModelShortageReportMap.isEmpty()) {
2459
		if (!focusedModelShortageReportMap.isEmpty()) {
Line 2490... Line 2491...
2490
				try {
2491
				try {
2491
					baos = FileUtil.getCSVByteStream(headers, entry.getValue());
2492
					baos = FileUtil.getCSVByteStream(headers, entry.getValue());
2492
				} catch (Exception e2) {
2493
				} catch (Exception e2) {
2493
					e2.printStackTrace();
2494
					e2.printStackTrace();
2494
				}
2495
				}
2495
				String[] sendToArray = new String[] {
2496
				String[] sendToArray = new String[]{
2496
 
2497
 
2497
						entry.getKey()
2498
						entry.getKey()
2498
 
2499
 
2499
				};
2500
				};
2500
 
2501
 
Line 2666... Line 2667...
2666
			String subject = "Referral Request";
2667
			String subject = "Referral Request";
2667
			String messageText = this.getMessageForReferral(referrals);
2668
			String messageText = this.getMessageForReferral(referrals);
2668
 
2669
 
2669
			MimeMessage message = mailSender.createMimeMessage();
2670
			MimeMessage message = mailSender.createMimeMessage();
2670
			MimeMessageHelper helper = new MimeMessageHelper(message, true);
2671
			MimeMessageHelper helper = new MimeMessageHelper(message, true);
2671
			String[] email = { "kamini.sharma@smartdukaan.com", "tarun.verma@smartdukaan.com" };
2672
			String[] email = {"kamini.sharma@smartdukaan.com", "tarun.verma@smartdukaan.com"};
2672
			helper.setSubject(subject);
2673
			helper.setSubject(subject);
2673
			helper.setText(messageText, true);
2674
			helper.setText(messageText, true);
2674
			helper.setTo(email);
2675
			helper.setTo(email);
2675
			InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "Smartdukaan Alerts");
2676
			InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "Smartdukaan Alerts");
2676
			helper.setFrom(senderAddress);
2677
			helper.setFrom(senderAddress);
Line 2880... Line 2881...
2880
			sb.append("<td style='border:1px solid black;padding: 5px'>" + pp.getMtd() + "</td>");
2881
			sb.append("<td style='border:1px solid black;padding: 5px'>" + pp.getMtd() + "</td>");
2881
			sb.append("<td style='border:1px solid black;padding: 5px'>" + pp.getInvestment() + "</td>");
2882
			sb.append("<td style='border:1px solid black;padding: 5px'>" + pp.getInvestment() + "</td>");
2882
			sb.append("<td style='border:1px solid black;padding: 5px'>" + pp.getStockInvestment() + "</td>");
2883
			sb.append("<td style='border:1px solid black;padding: 5px'>" + pp.getStockInvestment() + "</td>");
2883
			sb.append("<td style='border:1px solid black;padding: 5px'>"
2884
			sb.append("<td style='border:1px solid black;padding: 5px'>"
2884
					+ (authUserMap.get(EscalationType.L1) == null ? "N/A"
2885
					+ (authUserMap.get(EscalationType.L1) == null ? "N/A"
2885
							: authUserMap.get(EscalationType.L1).getFirstName())
2886
					: authUserMap.get(EscalationType.L1).getFirstName())
2886
					+ " ," + (authUserMap.get(EscalationType.L2) == null ? "N/A"
2887
					+ " ," + (authUserMap.get(EscalationType.L2) == null ? "N/A"
2887
							: authUserMap.get(EscalationType.L2).getFirstName())
2888
					: authUserMap.get(EscalationType.L2).getFirstName())
2888
					+ "</td>");
2889
					+ "</td>");
2889
 
2890
 
2890
			sb.append("</tr>");
2891
			sb.append("</tr>");
2891
		}
2892
		}
2892
		sb.append("</tbody></table><br><br>");
2893
		sb.append("</tbody></table><br><br>");