Subversion Repositories SmartDukaan

Rev

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

Rev 24681 Rev 24683
Line 28... Line 28...
28
import javax.mail.internet.MimeMessage;
28
import javax.mail.internet.MimeMessage;
29
 
29
 
30
import org.apache.commons.codec.CharEncoding;
30
import org.apache.commons.codec.CharEncoding;
31
import org.apache.commons.io.IOUtils;
31
import org.apache.commons.io.IOUtils;
32
import org.apache.commons.io.output.ByteArrayOutputStream;
32
import org.apache.commons.io.output.ByteArrayOutputStream;
-
 
33
import org.apache.http.HttpEntity;
33
import org.apache.http.HttpResponse;
34
import org.apache.http.HttpResponse;
34
import org.apache.logging.log4j.LogManager;
35
import org.apache.logging.log4j.LogManager;
35
import org.apache.logging.log4j.Logger;
36
import org.apache.logging.log4j.Logger;
36
import org.apache.poi.EncryptedDocumentException;
37
import org.apache.poi.EncryptedDocumentException;
37
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
38
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
38
import org.springframework.beans.factory.annotation.Autowired;
39
import org.springframework.beans.factory.annotation.Autowired;
39
import org.springframework.beans.factory.annotation.Qualifier;
40
import org.springframework.beans.factory.annotation.Qualifier;
40
import org.springframework.beans.factory.annotation.Value;
41
import org.springframework.beans.factory.annotation.Value;
41
import org.springframework.core.io.ByteArrayResource;
42
import org.springframework.core.io.ByteArrayResource;
42
import org.springframework.core.io.InputStreamResource;
-
 
43
import org.springframework.mail.javamail.JavaMailSender;
43
import org.springframework.mail.javamail.JavaMailSender;
44
import org.springframework.mail.javamail.MimeMessageHelper;
44
import org.springframework.mail.javamail.MimeMessageHelper;
45
import org.springframework.stereotype.Component;
45
import org.springframework.stereotype.Component;
46
import org.springframework.transaction.annotation.Transactional;
46
import org.springframework.transaction.annotation.Transactional;
47
 
47
 
Line 176... Line 176...
176
	@Autowired
176
	@Autowired
177
	private PurchaseRepository purchaseRepository;
177
	private PurchaseRepository purchaseRepository;
178
 
178
 
179
	@Autowired
179
	@Autowired
180
	private SchemeService schemeService;
180
	private SchemeService schemeService;
181
	
181
 
182
	@Autowired
182
	@Autowired
183
	private ReporticoService reporticoService;
183
	private ReporticoService reporticoService;
184
 
184
 
185
	@Autowired
185
	@Autowired
186
	private PartnerInvestmentService partnerInvestmentService;
186
	private PartnerInvestmentService partnerInvestmentService;
Line 294... Line 294...
294
	@Autowired
294
	@Autowired
295
	private TicketSubCategoryRepository ticketSubCategoryRepository;
295
	private TicketSubCategoryRepository ticketSubCategoryRepository;
296
 
296
 
297
	@Autowired
297
	@Autowired
298
	private Mongo mongoClient;
298
	private Mongo mongoClient;
299
	
299
 
300
	@Autowired
300
	@Autowired
301
	private UserAccountRepository userAccountRepository;
301
	private UserAccountRepository userAccountRepository;
302
 
302
 
303
	private static final Logger LOGGER = LogManager.getLogger(ScheduledTasks.class);
303
	private static final Logger LOGGER = LogManager.getLogger(ScheduledTasks.class);
304
 
304
 
Line 697... Line 697...
697
			this.sendMailWithAttachmentsForPartners(fofoIdsAndCustomRetailer.get(fofoId).getEmail(), message, subject,
697
			this.sendMailWithAttachmentsForPartners(fofoIdsAndCustomRetailer.get(fofoId).getEmail(), message, subject,
698
					is);
698
					is);
699
 
699
 
700
		}
700
		}
701
	}
701
	}
702
	
702
 
703
	public void sendAgeingReport() throws Exception {
703
	public void sendAgeingReport() throws Exception {
704
		HttpResponse response = reporticoService.getReportFile(ReporticoProject.WAREHOUSENEW, "itemstockageing.xml");
704
		HttpResponse response = reporticoService.getReportFile(ReporticoProject.WAREHOUSENEW, "itemstockageing.xml");
-
 
705
		HttpEntity respsonseEntity = response.getEntity();
-
 
706
		byte[] responseBytes = new byte[(int) respsonseEntity.getContentLength()];
-
 
707
		respsonseEntity.getContent().read(responseBytes);
705
		String [] to = {"amod.sen@smartdukaan.com", "adeel.yazdani@smartdukaan.com", "kamini.sharma@smartdukaan.com", "tarun.verma@smartdukaan.com", "chaitnaya.vats@smartdukaan.com", "mohinder.mutreja@smartdukaan.com"};
708
		String[] to = { "amod.sen@smartdukaan.com", "adeel.yazdani@smartdukaan.com", "kamini.sharma@smartdukaan.com",
-
 
709
				"tarun.verma@smartdukaan.com", "chaitnaya.vats@smartdukaan.com", "mohinder.mutreja@smartdukaan.com" };
-
 
710
		Attachment attachment = new Attachment(
706
		Attachment attachment = new Attachment("aeging-report-" + FormattingUtils.formatDate(LocalDateTime.now().minusDays(1)), 
711
				"aeging-report-" + FormattingUtils.formatDate(LocalDateTime.now().minusDays(1)),
707
				new InputStreamResource(response.getEntity().getContent()));
712
				new ByteArrayResource(responseBytes));
708
		Utils.sendMailWithAttachments(googleMailSender, to, null, "Stock Aeging Report", "PFA", attachment);
713
		Utils.sendMailWithAttachments(googleMailSender, to, null, "Stock Aeging Report", "PFA", attachment);
709
	}
714
	}
710
 
715
 
711
	public void moveImeisToPriceDropImeis() throws Exception {
716
	public void moveImeisToPriceDropImeis() throws Exception {
712
		List<PriceDrop> priceDrops = priceDropRepository.selectAll();
717
		List<PriceDrop> priceDrops = priceDropRepository.selectAll();
Line 924... Line 929...
924
 
929
 
925
		LocalDateTime startDate = LocalDate.of(2018, 9, 1).atStartOfDay();
930
		LocalDateTime startDate = LocalDate.of(2018, 9, 1).atStartOfDay();
926
		LocalDateTime endDate = LocalDate.now().atStartOfDay();
931
		LocalDateTime endDate = LocalDate.now().atStartOfDay();
927
		List<Purchase> purchases = purchaseRepository.selectAllBetweenPurchaseDate(startDate, endDate);
932
		List<Purchase> purchases = purchaseRepository.selectAllBetweenPurchaseDate(startDate, endDate);
928
 
933
 
929
		Map<Integer, String> storeNameMap = fofoStoreRepository.getStoresMap(); 
934
		Map<Integer, String> storeNameMap = fofoStoreRepository.getStoresMap();
930
		purchases.stream().forEach(purchase -> {
935
		purchases.stream().forEach(purchase -> {
931
			float amountToRollback = 0;
936
			float amountToRollback = 0;
932
			String description = "Adjustment of Duplicate Scheme for Purchase Invoice "
937
			String description = "Adjustment of Duplicate Scheme for Purchase Invoice "
933
					+ purchase.getPurchaseReference();
938
					+ purchase.getPurchaseReference();
934
			Map<Integer, String> inventorySerialNumberMap = inventoryItemRepository.selectByPurchaseId(purchase.getId())
939
			Map<Integer, String> inventorySerialNumberMap = inventoryItemRepository.selectByPurchaseId(purchase.getId())
Line 979... Line 984...
979
					}
984
					}
980
 
985
 
981
				}
986
				}
982
			}
987
			}
983
			if (amountToRollback > 0) {
988
			if (amountToRollback > 0) {
-
 
989
				// Address address =
984
				//Address address = addressRepository.selectAllByRetailerId(purchase.getFofoId(), 0, 10).get(0);
990
				// addressRepository.selectAllByRetailerId(purchase.getFofoId(), 0, 10).get(0);
985
				UserWalletHistory uwh = new UserWalletHistory();
991
				UserWalletHistory uwh = new UserWalletHistory();
986
				uwh.setAmount(Math.round(amountToRollback));
992
				uwh.setAmount(Math.round(amountToRollback));
987
				uwh.setDescription(description);
993
				uwh.setDescription(description);
988
				uwh.setTimestamp(LocalDateTime.now());
994
				uwh.setTimestamp(LocalDateTime.now());
989
				uwh.setReferenceType(WalletReferenceType.SCHEME_IN);
995
				uwh.setReferenceType(WalletReferenceType.SCHEME_IN);
Line 1001... Line 1007...
1001
						.map(x -> Arrays.asList(x.getWalletId(), x.getStoreCode(), x.getReferenceType(),
1007
						.map(x -> Arrays.asList(x.getWalletId(), x.getStoreCode(), x.getReferenceType(),
1002
								x.getReference(), x.getAmount(), x.getDescription(), x.getTimestamp()))
1008
								x.getReference(), x.getAmount(), x.getDescription(), x.getTimestamp()))
1003
						.collect(Collectors.toList()));
1009
						.collect(Collectors.toList()));
1004
 
1010
 
1005
		ByteArrayOutputStream baosOuts = FileUtil.getCSVByteStream(
1011
		ByteArrayOutputStream baosOuts = FileUtil.getCSVByteStream(
1006
				Arrays.asList("Scheme ID", "SchemeType", "Reference", "Store Code", "Serial Number", "Amount", "Created",
1012
				Arrays.asList("Scheme ID", "SchemeType", "Reference", "Store Code", "Serial Number", "Amount",
1007
						"Rolledback"),
1013
						"Created", "Rolledback"),
1008
				rolledbackSios.stream()
1014
				rolledbackSios.stream()
1009
						.map(x -> Arrays.asList(x.getSchemeId(), x.getSchemeType(), x.getReference(), x.getStoreCode(),
1015
						.map(x -> Arrays.asList(x.getSchemeId(), x.getSchemeType(), x.getReference(), x.getStoreCode(),
1010
								x.getSerialNumber(), x.getAmount(), x.getCreateTimestamp(), x.getRolledBackTimestamp()))
1016
								x.getSerialNumber(), x.getAmount(), x.getCreateTimestamp(), x.getRolledBackTimestamp()))
1011
						.collect(Collectors.toList()));
1017
						.collect(Collectors.toList()));
1012
 
1018
 
Line 1284... Line 1290...
1284
		MimeMessage message = mailSender.createMimeMessage();
1290
		MimeMessage message = mailSender.createMimeMessage();
1285
		MimeMessageHelper helper = new MimeMessageHelper(message);
1291
		MimeMessageHelper helper = new MimeMessageHelper(message);
1286
		helper.setSubject(subject);
1292
		helper.setSubject(subject);
1287
		helper.setText(body, true);
1293
		helper.setText(body, true);
1288
		helper.setTo(email);
1294
		helper.setTo(email);
1289
		if(cc!=null) {
1295
		if (cc != null) {
1290
		helper.setCc(cc);
1296
			helper.setCc(cc);
1291
		}
1297
		}
1292
		InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "Smart Dukaan");
1298
		InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "Smart Dukaan");
1293
		helper.setFrom(senderAddress);
1299
		helper.setFrom(senderAddress);
1294
		mailSender.send(message);
1300
		mailSender.send(message);
1295
	}
1301
	}
Line 1300... Line 1306...
1300
		LocalDateTime from = LocalDateTime.of(now.getYear(), now.getMonth(), now.getDayOfMonth(), 00, 00);
1306
		LocalDateTime from = LocalDateTime.of(now.getYear(), now.getMonth(), now.getDayOfMonth(), 00, 00);
1301
		Map<Integer, Double> salesByFofoIdMap = new HashMap<>();
1307
		Map<Integer, Double> salesByFofoIdMap = new HashMap<>();
1302
		List<Integer> fofoIds = targetService.getfofoIdsFromfofoStore();
1308
		List<Integer> fofoIds = targetService.getfofoIdsFromfofoStore();
1303
		List<PartnerTargetDetails> partnerTargetDetails = partnerTargetRepository
1309
		List<PartnerTargetDetails> partnerTargetDetails = partnerTargetRepository
1304
				.selectAllGeEqAndLeEqStartDateAndEndDate(now);
1310
				.selectAllGeEqAndLeEqStartDateAndEndDate(now);
1305
		DateTimeFormatter timeFormatter = DateTimeFormatter
1311
		DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("h a");
1306
	            .ofPattern("h a");
-
 
1307
		
1312
 
1308
		Map<Integer,Float> dailyTarget=new HashMap<>();
1313
		Map<Integer, Float> dailyTarget = new HashMap<>();
1309
		for (Integer fofoId : fofoIds) {
1314
		for (Integer fofoId : fofoIds) {
1310
			Map<Integer,Float> dailyAverageSale=null;
1315
			Map<Integer, Float> dailyAverageSale = null;
1311
			double sale = fofoOrderRepository.selectTotalSaleSumByFofoIdBrtweenDate(fofoId, from, now);
1316
			double sale = fofoOrderRepository.selectTotalSaleSumByFofoIdBrtweenDate(fofoId, from, now);
1312
			for (PartnerTargetDetails partnerTargetDetail : partnerTargetDetails) {
1317
			for (PartnerTargetDetails partnerTargetDetail : partnerTargetDetails) {
1313
				Map<Integer, Float> targetValues = targetService.getTargetValueByFofoIdAndTargetId(fofoId,
1318
				Map<Integer, Float> targetValues = targetService.getTargetValueByFofoIdAndTargetId(fofoId,
1314
						partnerTargetDetail.getId());
1319
						partnerTargetDetail.getId());
1315
				if (targetValues.size() == 0) {
1320
				if (targetValues.size() == 0) {
Line 1324... Line 1329...
1324
					break;
1329
					break;
1325
				}
1330
				}
1326
			}
1331
			}
1327
			NotificationCampaigns notification = new NotificationCampaigns();
1332
			NotificationCampaigns notification = new NotificationCampaigns();
1328
			notification.setName("Today's Sale");
1333
			notification.setName("Today's Sale");
1329
			if(dailyAverageSale!=null && dailyAverageSale.get(fofoId)!=null) {
1334
			if (dailyAverageSale != null && dailyAverageSale.get(fofoId) != null) {
1330
				LOGGER.info("Your today sale till" + " " + now.format(timeFormatter) +" "+ "is" + " " + sale+" "+"vs" +" "+"daily target="+dailyAverageSale.get(fofoId));
1335
				LOGGER.info("Your today sale till" + " " + now.format(timeFormatter) + " " + "is" + " " + sale + " "
-
 
1336
						+ "vs" + " " + "daily target=" + dailyAverageSale.get(fofoId));
1331
			notification.setTitle("Your today sale till" + " " + now.format(timeFormatter) +" "+ "is" + " " + sale+" "+"vs" +" "+"daily target="+dailyAverageSale.get(fofoId));
1337
				notification.setTitle("Your today sale till" + " " + now.format(timeFormatter) + " " + "is" + " " + sale
1332
			}
-
 
-
 
1338
						+ " " + "vs" + " " + "daily target=" + dailyAverageSale.get(fofoId));
1333
			else
1339
			} else {
1334
			{
-
 
1335
				notification.setTitle("Your today sale till" + " " + now.format(timeFormatter) +" "+"is" + " " + sale+" "+"vs" +" "+"daily target = 0.0");
1340
				notification.setTitle("Your today sale till" + " " + now.format(timeFormatter) + " " + "is" + " " + sale
-
 
1341
						+ " " + "vs" + " " + "daily target = 0.0");
1336
				LOGGER.info("Your today sale till" + " " + now.format(timeFormatter) +" "+ "is" + " " + sale+" "+"vs" +" "+"daily target = 0.0");
1342
				LOGGER.info("Your today sale till" + " " + now.format(timeFormatter) + " " + "is" + " " + sale + " "
-
 
1343
						+ "vs" + " " + "daily target = 0.0");
1337
			}
1344
			}
1338
			//notification.setMessage("Your sale is "+salesbyfofoId.get(fofoId));
1345
			// notification.setMessage("Your sale is "+salesbyfofoId.get(fofoId));
1339
			notification.setType("Url");
1346
			notification.setType("Url");
1340
			notification.setUrl("http://app.profitmandi.com/pages/home/dashboard");
1347
			notification.setUrl("http://app.profitmandi.com/pages/home/dashboard");
1341
			LOGGER.info("UserID" +userAccountRepository.selectUserIdByRetailerId(fofoId));
1348
			LOGGER.info("UserID" + userAccountRepository.selectUserIdByRetailerId(fofoId));
1342
			notification
-
 
1343
					.setSql("SELECT distinct d1.user_id from devices d1 left join devices d2 on"
1349
			notification.setSql("SELECT distinct d1.user_id from devices d1 left join devices d2 on"
1344
							+ "(d1.imeinumber = d2.imeinumber and d1.created < d2.created) "
1350
					+ "(d1.imeinumber = d2.imeinumber and d1.created < d2.created) "
-
 
1351
					+ " where d2.id is null and d1.user_id = "
1345
							+ " where d2.id is null and d1.user_id = "+userAccountRepository.selectUserIdByRetailerId(fofoId));
1352
					+ userAccountRepository.selectUserIdByRetailerId(fofoId));
1346
			LOGGER.info("SELECT distinct d1.user_id from devices d1 left join devices d2 on"
1353
			LOGGER.info("SELECT distinct d1.user_id from devices d1 left join devices d2 on"
1347
							+ "(d1.imeinumber = d2.imeinumber and d1.created < d2.created) "
1354
					+ "(d1.imeinumber = d2.imeinumber and d1.created < d2.created) "
-
 
1355
					+ " where d2.id is null and d1.user_id = "
1348
							+ " where d2.id is null and d1.user_id = "+userAccountRepository.selectUserIdByRetailerId(fofoId));
1356
					+ userAccountRepository.selectUserIdByRetailerId(fofoId));
1349
			notification.setExpiresat(LocalDateTime.now().plusDays(1).toEpochSecond(ZoneOffset.UTC) * 1000);
1357
			notification.setExpiresat(LocalDateTime.now().plusDays(1).toEpochSecond(ZoneOffset.UTC) * 1000);
1350
			notification.setStatus("active");
1358
			notification.setStatus("active");
1351
			notification.setSmsprocessed(0);
1359
			notification.setSmsprocessed(0);
1352
			notification.setNotification_processed(0);
1360
			notification.setNotification_processed(0);
1353
			notification.setNotification_type("GENERAL_NOTIFICATION");
1361
			notification.setNotification_type("GENERAL_NOTIFICATION");
1354
			mongoClient.persistNotificationCmpInfo(notification);
1362
			mongoClient.persistNotificationCmpInfo(notification);
1355
			salesByFofoIdMap.put(fofoId, sale);
1363
			salesByFofoIdMap.put(fofoId, sale);
1356
			LOGGER.info(sale);
1364
			LOGGER.info(sale);
1357
		}
1365
		}
1358
		String saleReport = this.getDailySalesReportByPartnerId(salesByFofoIdMap,dailyTarget);
1366
		String saleReport = this.getDailySalesReportByPartnerId(salesByFofoIdMap, dailyTarget);
1359
		LOGGER.info(saleReport);
1367
		LOGGER.info(saleReport);
1360
		String cc[] = { "Tarun.verma@smartdukaan.com", "Kamini.sharma@smartdukaan.com",
1368
		String cc[] = { "Tarun.verma@smartdukaan.com", "Kamini.sharma@smartdukaan.com",
1361
				"chaitnaya.vats@smartdukaan.com","adeel.yazdani@smartdukaan.com","mohinder.mutreja@smartdukaan.com"};
1369
				"chaitnaya.vats@smartdukaan.com", "adeel.yazdani@smartdukaan.com", "mohinder.mutreja@smartdukaan.com" };
1362
		String subject = "sale report till" + " " + now.format(timeFormatter);
1370
		String subject = "sale report till" + " " + now.format(timeFormatter);
1363
		this.sendMailOfHtmlFomat("amod.sen@smartdukaan.com", saleReport, cc, subject);
1371
		this.sendMailOfHtmlFomat("amod.sen@smartdukaan.com", saleReport, cc, subject);
1364
	}
1372
	}
1365
 
1373
 
1366
	public String getDailySalesReportByPartnerId(Map<Integer, Double> salesByFofoIdMap,Map<Integer, Float> dailyTarget)
1374
	public String getDailySalesReportByPartnerId(Map<Integer, Double> salesByFofoIdMap, Map<Integer, Float> dailyTarget)
1367
			throws ProfitMandiBusinessException {
1375
			throws ProfitMandiBusinessException {
1368
		StringBuilder sb = new StringBuilder();
1376
		StringBuilder sb = new StringBuilder();
1369
		sb.append("<html><body><p>Sale Report:</p><br/><table style='border:1px solid black ;padding: 5px';>");
1377
		sb.append("<html><body><p>Sale Report:</p><br/><table style='border:1px solid black ;padding: 5px';>");
1370
		sb.append("<tbody>\n" + "	    				<tr>\n"
1378
		sb.append("<tbody>\n" + "	    				<tr>\n"
1371
				+ "	    					<th style='border:1px solid black;padding: 5px'>Partner</th>\n"
1379
				+ "	    					<th style='border:1px solid black;padding: 5px'>Partner</th>\n"
Line 1374... Line 1382...
1374
				+ "	    				</tr>");
1382
				+ "	    				</tr>");
1375
		for (Integer fofoId : salesByFofoIdMap.keySet()) {
1383
		for (Integer fofoId : salesByFofoIdMap.keySet()) {
1376
			sb.append("<tr>");
1384
			sb.append("<tr>");
1377
			sb.append("<td style='border:1px solid black;padding: 5px'>"
1385
			sb.append("<td style='border:1px solid black;padding: 5px'>"
1378
					+ retailerService.getFofoRetailer(fofoId).getBusinessName() + "</td>");
1386
					+ retailerService.getFofoRetailer(fofoId).getBusinessName() + "</td>");
1379
			if(dailyTarget!=null && dailyTarget.get(fofoId)!=null) {
1387
			if (dailyTarget != null && dailyTarget.get(fofoId) != null) {
1380
			sb.append("<td style='border:1px solid black;padding: 5px'>" + dailyTarget.get(fofoId) + "</td>");
1388
				sb.append("<td style='border:1px solid black;padding: 5px'>" + dailyTarget.get(fofoId) + "</td>");
1381
			}
-
 
1382
			else
1389
			} else {
1383
			{
-
 
1384
				sb.append("<td style='border:1px solid black;padding: 5px'>" +0.0+ "</td>");
1390
				sb.append("<td style='border:1px solid black;padding: 5px'>" + 0.0 + "</td>");
1385
			}
1391
			}
1386
			sb.append("<td style='border:1px solid black;padding: 5px'>" + salesByFofoIdMap.get(fofoId) + "</td>");
1392
			sb.append("<td style='border:1px solid black;padding: 5px'>" + salesByFofoIdMap.get(fofoId) + "</td>");
1387
 
1393
 
1388
			sb.append("</tr>");
1394
			sb.append("</tr>");
1389
		}
1395
		}
1390
		
1396
 
1391
		sb.append("</tbody></table></body></html>");
1397
		sb.append("</tbody></table></body></html>");
1392
		return sb.toString();
1398
		return sb.toString();
1393
	}
1399
	}
1394
}
1400
}
1395
 
1401