Subversion Repositories SmartDukaan

Rev

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

Rev 24677 Rev 24681
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.HttpResponse;
33
import org.apache.logging.log4j.LogManager;
34
import org.apache.logging.log4j.LogManager;
34
import org.apache.logging.log4j.Logger;
35
import org.apache.logging.log4j.Logger;
35
import org.apache.poi.EncryptedDocumentException;
36
import org.apache.poi.EncryptedDocumentException;
36
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
37
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
37
import org.springframework.beans.factory.annotation.Autowired;
38
import org.springframework.beans.factory.annotation.Autowired;
38
import org.springframework.beans.factory.annotation.Qualifier;
39
import org.springframework.beans.factory.annotation.Qualifier;
39
import org.springframework.beans.factory.annotation.Value;
40
import org.springframework.beans.factory.annotation.Value;
40
import org.springframework.core.io.ByteArrayResource;
41
import org.springframework.core.io.ByteArrayResource;
-
 
42
import org.springframework.core.io.InputStreamResource;
41
import org.springframework.mail.javamail.JavaMailSender;
43
import org.springframework.mail.javamail.JavaMailSender;
42
import org.springframework.mail.javamail.MimeMessageHelper;
44
import org.springframework.mail.javamail.MimeMessageHelper;
43
import org.springframework.stereotype.Component;
45
import org.springframework.stereotype.Component;
44
import org.springframework.transaction.annotation.Transactional;
46
import org.springframework.transaction.annotation.Transactional;
45
 
47
 
46
import com.google.common.collect.Lists;
48
import com.google.common.collect.Lists;
47
import com.spice.profitmandi.common.enumuration.RechargeStatus;
49
import com.spice.profitmandi.common.enumuration.RechargeStatus;
-
 
50
import com.spice.profitmandi.common.enumuration.ReporticoProject;
48
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
51
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
49
import com.spice.profitmandi.common.model.CustomRetailer;
52
import com.spice.profitmandi.common.model.CustomRetailer;
50
import com.spice.profitmandi.common.model.GstRate;
53
import com.spice.profitmandi.common.model.GstRate;
51
import com.spice.profitmandi.common.model.RechargeCredential;
54
import com.spice.profitmandi.common.model.RechargeCredential;
-
 
55
import com.spice.profitmandi.common.services.ReporticoService;
52
import com.spice.profitmandi.common.util.FileUtil;
56
import com.spice.profitmandi.common.util.FileUtil;
53
import com.spice.profitmandi.common.util.FormattingUtils;
57
import com.spice.profitmandi.common.util.FormattingUtils;
54
import com.spice.profitmandi.common.util.Utils;
58
import com.spice.profitmandi.common.util.Utils;
55
import com.spice.profitmandi.common.util.Utils.Attachment;
59
import com.spice.profitmandi.common.util.Utils.Attachment;
56
import com.spice.profitmandi.dao.entity.auth.AuthUser;
60
import com.spice.profitmandi.dao.entity.auth.AuthUser;
Line 68... Line 72...
68
import com.spice.profitmandi.dao.entity.fofo.FofoOrder;
72
import com.spice.profitmandi.dao.entity.fofo.FofoOrder;
69
import com.spice.profitmandi.dao.entity.fofo.FofoOrderItem;
73
import com.spice.profitmandi.dao.entity.fofo.FofoOrderItem;
70
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
74
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
71
import com.spice.profitmandi.dao.entity.fofo.InventoryItem;
75
import com.spice.profitmandi.dao.entity.fofo.InventoryItem;
72
import com.spice.profitmandi.dao.entity.fofo.PartnerDailyInvestment;
76
import com.spice.profitmandi.dao.entity.fofo.PartnerDailyInvestment;
73
import com.spice.profitmandi.dao.entity.fofo.PartnerTarget;
-
 
74
import com.spice.profitmandi.dao.entity.fofo.PartnerTargetDetails;
77
import com.spice.profitmandi.dao.entity.fofo.PartnerTargetDetails;
75
import com.spice.profitmandi.dao.entity.fofo.Purchase;
78
import com.spice.profitmandi.dao.entity.fofo.Purchase;
76
import com.spice.profitmandi.dao.entity.fofo.SaleHeadDetails;
79
import com.spice.profitmandi.dao.entity.fofo.SaleHeadDetails;
77
import com.spice.profitmandi.dao.entity.fofo.ScanRecord;
80
import com.spice.profitmandi.dao.entity.fofo.ScanRecord;
78
import com.spice.profitmandi.dao.entity.fofo.SchemeInOut;
81
import com.spice.profitmandi.dao.entity.fofo.SchemeInOut;
Line 173... Line 176...
173
	@Autowired
176
	@Autowired
174
	private PurchaseRepository purchaseRepository;
177
	private PurchaseRepository purchaseRepository;
175
 
178
 
176
	@Autowired
179
	@Autowired
177
	private SchemeService schemeService;
180
	private SchemeService schemeService;
-
 
181
	
-
 
182
	@Autowired
-
 
183
	private ReporticoService reporticoService;
178
 
184
 
179
	@Autowired
185
	@Autowired
180
	private PartnerInvestmentService partnerInvestmentService;
186
	private PartnerInvestmentService partnerInvestmentService;
181
 
187
 
182
	@Autowired
188
	@Autowired
Line 691... Line 697...
691
			this.sendMailWithAttachmentsForPartners(fofoIdsAndCustomRetailer.get(fofoId).getEmail(), message, subject,
697
			this.sendMailWithAttachmentsForPartners(fofoIdsAndCustomRetailer.get(fofoId).getEmail(), message, subject,
692
					is);
698
					is);
693
 
699
 
694
		}
700
		}
695
	}
701
	}
-
 
702
	
-
 
703
	public void sendAgeingReport() throws Exception {
-
 
704
		HttpResponse response = reporticoService.getReportFile(ReporticoProject.WAREHOUSENEW, "itemstockageing.xml");
-
 
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"};
-
 
706
		Attachment attachment = new Attachment("aeging-report-" + FormattingUtils.formatDate(LocalDateTime.now().minusDays(1)), 
-
 
707
				new InputStreamResource(response.getEntity().getContent()));
-
 
708
		Utils.sendMailWithAttachments(googleMailSender, to, null, "Stock Aeging Report", "PFA", attachment);
-
 
709
	}
696
 
710
 
697
	public void moveImeisToPriceDropImeis() throws Exception {
711
	public void moveImeisToPriceDropImeis() throws Exception {
698
		List<PriceDrop> priceDrops = priceDropRepository.selectAll();
712
		List<PriceDrop> priceDrops = priceDropRepository.selectAll();
699
		for (PriceDrop priceDrop : priceDrops) {
713
		for (PriceDrop priceDrop : priceDrops) {
700
			priceDropService.priceDropStatus(priceDrop.getId());
714
			priceDropService.priceDropStatus(priceDrop.getId());
Line 910... Line 924...
910
 
924
 
911
		LocalDateTime startDate = LocalDate.of(2018, 9, 1).atStartOfDay();
925
		LocalDateTime startDate = LocalDate.of(2018, 9, 1).atStartOfDay();
912
		LocalDateTime endDate = LocalDate.now().atStartOfDay();
926
		LocalDateTime endDate = LocalDate.now().atStartOfDay();
913
		List<Purchase> purchases = purchaseRepository.selectAllBetweenPurchaseDate(startDate, endDate);
927
		List<Purchase> purchases = purchaseRepository.selectAllBetweenPurchaseDate(startDate, endDate);
914
 
928
 
-
 
929
		Map<Integer, String> storeNameMap = fofoStoreRepository.getStoresMap(); 
915
		purchases.stream().forEach(purchase -> {
930
		purchases.stream().forEach(purchase -> {
916
			float amountToRollback = 0;
931
			float amountToRollback = 0;
917
			String description = "Adjustment of Duplicate Scheme for Purchase Invoice "
932
			String description = "Adjustment of Duplicate Scheme for Purchase Invoice "
918
					+ purchase.getPurchaseReference();
933
					+ purchase.getPurchaseReference();
919
			Map<Integer, String> inventorySerialNumberMap = inventoryItemRepository.selectByPurchaseId(purchase.getId())
934
			Map<Integer, String> inventorySerialNumberMap = inventoryItemRepository.selectByPurchaseId(purchase.getId())
Line 955... Line 970...
955
							}
970
							}
956
							sio.setRolledBackTimestamp(LocalDateTime.now());
971
							sio.setRolledBackTimestamp(LocalDateTime.now());
957
							amountToRollback += sio.getAmount();
972
							amountToRollback += sio.getAmount();
958
							// sio.setSchemeType(SchemeType.OUT);
973
							// sio.setSchemeType(SchemeType.OUT);
959
							sio.setSerialNumber(serialNumber);
974
							sio.setSerialNumber(serialNumber);
-
 
975
							sio.setStoreCode(storeNameMap.get(purchase.getFofoId()));
-
 
976
							sio.setReference(purchase.getId());
960
							rolledbackSios.add(sio);
977
							rolledbackSios.add(sio);
961
						}
978
						}
962
					}
979
					}
963
 
980
 
964
				}
981
				}
965
			}
982
			}
966
			if (amountToRollback > 0) {
983
			if (amountToRollback > 0) {
967
				Address address = addressRepository.selectAllByRetailerId(purchase.getFofoId(), 0, 10).get(0);
984
				//Address address = addressRepository.selectAllByRetailerId(purchase.getFofoId(), 0, 10).get(0);
968
				UserWalletHistory uwh = new UserWalletHistory();
985
				UserWalletHistory uwh = new UserWalletHistory();
969
				uwh.setAmount(Math.round(amountToRollback));
986
				uwh.setAmount(Math.round(amountToRollback));
970
				uwh.setDescription(description);
987
				uwh.setDescription(description);
971
				uwh.setTimestamp(LocalDateTime.now());
988
				uwh.setTimestamp(LocalDateTime.now());
972
				uwh.setReferenceType(WalletReferenceType.SCHEME_OUT);
989
				uwh.setReferenceType(WalletReferenceType.SCHEME_IN);
973
				uwh.setReference(purchase.getId());
990
				uwh.setReference(purchase.getId());
974
				uwh.setWalletId(userWalletMap.get(purchase.getFofoId()));
991
				uwh.setWalletId(userWalletMap.get(purchase.getFofoId()));
975
				uwh.setFofoId(purchase.getFofoId());
992
				uwh.setFofoId(purchase.getFofoId());
976
				uwh.setStoreCode(address.getName());
993
				uwh.setStoreCode(storeNameMap.get(purchase.getFofoId()));
977
				userWalletHistory.add(uwh);
994
				userWalletHistory.add(uwh);
978
			}
995
			}
979
		});
996
		});
980
		ByteArrayOutputStream baos = FileUtil.getCSVByteStream(
997
		ByteArrayOutputStream baos = FileUtil.getCSVByteStream(
981
				Arrays.asList("User Id", "Store Code", "Reference Type", "Reference", "Amount", "Description",
998
				Arrays.asList("User Id", "Store Code", "Reference Type", "Reference", "Amount", "Description",
Line 984... Line 1001...
984
						.map(x -> Arrays.asList(x.getWalletId(), x.getStoreCode(), x.getReferenceType(),
1001
						.map(x -> Arrays.asList(x.getWalletId(), x.getStoreCode(), x.getReferenceType(),
985
								x.getReference(), x.getAmount(), x.getDescription(), x.getTimestamp()))
1002
								x.getReference(), x.getAmount(), x.getDescription(), x.getTimestamp()))
986
						.collect(Collectors.toList()));
1003
						.collect(Collectors.toList()));
987
 
1004
 
988
		ByteArrayOutputStream baosOuts = FileUtil.getCSVByteStream(
1005
		ByteArrayOutputStream baosOuts = FileUtil.getCSVByteStream(
989
				Arrays.asList("Scheme ID", "SchemeType", "Store Code", "Serial Number", "Amount", "Created",
1006
				Arrays.asList("Scheme ID", "SchemeType", "Reference", "Store Code", "Serial Number", "Amount", "Created",
990
						"Rolledback"),
1007
						"Rolledback"),
991
				rolledbackSios.stream()
1008
				rolledbackSios.stream()
992
						.map(x -> Arrays.asList(x.getSchemeId(), x.getSchemeType(), x.getStoreCode(),
1009
						.map(x -> Arrays.asList(x.getSchemeId(), x.getSchemeType(), x.getReference(), x.getStoreCode(),
993
								x.getSerialNumber(), x.getAmount(), x.getCreateTimestamp(), x.getRolledBackTimestamp()))
1010
								x.getSerialNumber(), x.getAmount(), x.getCreateTimestamp(), x.getRolledBackTimestamp()))
994
						.collect(Collectors.toList()));
1011
						.collect(Collectors.toList()));
995
 
1012
 
996
		Utils.sendMailWithAttachments(googleMailSender,
1013
		Utils.sendMailWithAttachments(googleMailSender,
997
				new String[] { "amit.gupta@shop2020.in", "neeraj.gupta@smartdukaan.com" }, null,
1014
				new String[] { "amit.gupta@shop2020.in", "neeraj.gupta@smartdukaan.com" }, null,
Line 1043... Line 1060...
1043
							sio.setRolledBackTimestamp(LocalDateTime.now());
1060
							sio.setRolledBackTimestamp(LocalDateTime.now());
1044
							amountToRollback += sio.getAmount();
1061
							amountToRollback += sio.getAmount();
1045
							// sio.setSchemeType(SchemeType.OUT);
1062
							// sio.setSchemeType(SchemeType.OUT);
1046
							sio.setSerialNumber(serialNumber);
1063
							sio.setSerialNumber(serialNumber);
1047
							sio.setStoreCode(fofoOrder.getInvoiceNumber().split("/")[0]);
1064
							sio.setStoreCode(fofoOrder.getInvoiceNumber().split("/")[0]);
-
 
1065
							sio.setReference(fofoOrder.getId());
1048
							rolledbackSios.add(sio);
1066
							rolledbackSios.add(sio);
1049
						}
1067
						}
1050
						description = description.concat(" " + serialNumber + " ");
1068
						description = description.concat(" " + serialNumber + " ");
1051
					} else {
1069
					} else {
1052
						serialNumbersConsidered.add(serialNumber);
1070
						serialNumbersConsidered.add(serialNumber);
Line 1063... Line 1081...
1063
								continue;
1081
								continue;
1064
							}
1082
							}
1065
							sio.setRolledBackTimestamp(LocalDateTime.now());
1083
							sio.setRolledBackTimestamp(LocalDateTime.now());
1066
							amountToRollback += sio.getAmount();
1084
							amountToRollback += sio.getAmount();
1067
							// sio.setSchemeType(SchemeType.OUT);
1085
							// sio.setSchemeType(SchemeType.OUT);
-
 
1086
							sio.setReference(fofoOrder.getId());
1068
							sio.setSerialNumber(serialNumber);
1087
							sio.setSerialNumber(serialNumber);
1069
							sio.setStoreCode(fofoOrder.getInvoiceNumber().split("/")[0]);
1088
							sio.setStoreCode(fofoOrder.getInvoiceNumber().split("/")[0]);
1070
							rolledbackSios.add(sio);
1089
							rolledbackSios.add(sio);
1071
						}
1090
						}
1072
					}
1091
					}
Line 1086... Line 1105...
1086
				userWalletHistory.add(uwh);
1105
				userWalletHistory.add(uwh);
1087
			}
1106
			}
1088
		});
1107
		});
1089
 
1108
 
1090
		ByteArrayOutputStream baos = FileUtil.getCSVByteStream(
1109
		ByteArrayOutputStream baos = FileUtil.getCSVByteStream(
1091
				Arrays.asList("User Id", "Store Code", "Reference Type", "Reference", "Amount", "Description",
1110
				Arrays.asList("Wallet Id", "Store Code", "Reference Type", "Reference", "Amount", "Description",
1092
						"Timestamp"),
1111
						"Timestamp"),
1093
				userWalletHistory.stream()
1112
				userWalletHistory.stream()
1094
						.map(x -> Arrays.asList(x.getWalletId(), x.getStoreCode(), x.getReferenceType(),
1113
						.map(x -> Arrays.asList(x.getWalletId(), x.getStoreCode(), x.getReferenceType(),
1095
								x.getReference(), x.getAmount(), x.getDescription(), x.getTimestamp()))
1114
								x.getReference(), x.getAmount(), x.getDescription(), x.getTimestamp()))
1096
						.collect(Collectors.toList()));
1115
						.collect(Collectors.toList()));
Line 1103... Line 1122...
1103
								x.getSerialNumber(), x.getAmount(), x.getCreateTimestamp(), x.getRolledBackTimestamp()))
1122
								x.getSerialNumber(), x.getAmount(), x.getCreateTimestamp(), x.getRolledBackTimestamp()))
1104
						.collect(Collectors.toList()));
1123
						.collect(Collectors.toList()));
1105
 
1124
 
1106
		Utils.sendMailWithAttachments(googleMailSender,
1125
		Utils.sendMailWithAttachments(googleMailSender,
1107
				new String[] { "amit.gupta@shop2020.in", "neeraj.gupta@smartdukaan.com" }, null,
1126
				new String[] { "amit.gupta@shop2020.in", "neeraj.gupta@smartdukaan.com" }, null,
1108
				"Partner Excess Amount", "PFA",
1127
				"Partner Excess Amount Scheme Out", "PFA",
1109
				new Attachment[] { new Attachment("WalletSummary.csv", new ByteArrayResource(baos.toByteArray())),
1128
				new Attachment[] { new Attachment("WalletSummary.csv", new ByteArrayResource(baos.toByteArray())),
1110
						new Attachment("SchemeOutRolledback.csv", new ByteArrayResource(baosOuts.toByteArray())) });
1129
						new Attachment("SchemeOutRolledback.csv", new ByteArrayResource(baosOuts.toByteArray())) });
1111
 
1130
 
1112
		throw new Exception();
1131
		throw new Exception();
1113
	}
1132
	}