Subversion Repositories SmartDukaan

Rev

Rev 25300 | Rev 25314 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
23724 amit.gupta 1
package com.smartdukaan.cron.scheduled;
23723 amit.gupta 2
 
24121 govind 3
import java.io.IOException;
4
import java.io.InputStream;
24807 amit.gupta 5
import java.io.Serializable;
23739 amit.gupta 6
import java.sql.Timestamp;
23724 amit.gupta 7
import java.time.LocalDate;
8
import java.time.LocalDateTime;
24256 amit.gupta 9
import java.time.LocalTime;
24653 govind 10
import java.time.ZoneOffset;
11
import java.time.format.DateTimeFormatter;
23724 amit.gupta 12
import java.time.temporal.ChronoUnit;
13
import java.util.ArrayList;
14
import java.util.Arrays;
24627 amit.gupta 15
import java.util.Collections;
23723 amit.gupta 16
import java.util.HashMap;
24241 amit.gupta 17
import java.util.HashSet;
23724 amit.gupta 18
import java.util.List;
23723 amit.gupta 19
import java.util.Map;
24242 amit.gupta 20
import java.util.Optional;
24542 amit.gupta 21
import java.util.Set;
23724 amit.gupta 22
import java.util.stream.Collectors;
23723 amit.gupta 23
 
24121 govind 24
import javax.mail.MessagingException;
25
import javax.mail.internet.InternetAddress;
26
import javax.mail.internet.MimeMessage;
27
 
28
import org.apache.commons.codec.CharEncoding;
29
import org.apache.commons.io.IOUtils;
23929 amit.gupta 30
import org.apache.commons.io.output.ByteArrayOutputStream;
25300 tejbeer 31
import org.apache.http.client.methods.CloseableHttpResponse;
32
import org.apache.http.client.methods.HttpPost;
33
import org.apache.http.entity.StringEntity;
34
import org.apache.http.impl.client.CloseableHttpClient;
35
import org.apache.http.impl.client.HttpClients;
23755 amit.gupta 36
import org.apache.logging.log4j.LogManager;
37
import org.apache.logging.log4j.Logger;
25300 tejbeer 38
import org.json.JSONObject;
23723 amit.gupta 39
import org.springframework.beans.factory.annotation.Autowired;
23933 amit.gupta 40
import org.springframework.beans.factory.annotation.Qualifier;
23724 amit.gupta 41
import org.springframework.beans.factory.annotation.Value;
23929 amit.gupta 42
import org.springframework.core.io.ByteArrayResource;
24692 amit.gupta 43
import org.springframework.core.io.InputStreamSource;
23929 amit.gupta 44
import org.springframework.mail.javamail.JavaMailSender;
24121 govind 45
import org.springframework.mail.javamail.MimeMessageHelper;
23723 amit.gupta 46
import org.springframework.stereotype.Component;
23724 amit.gupta 47
import org.springframework.transaction.annotation.Transactional;
23723 amit.gupta 48
 
24542 amit.gupta 49
import com.google.common.collect.Lists;
25300 tejbeer 50
import com.google.gson.Gson;
51
import com.google.gson.GsonBuilder;
23724 amit.gupta 52
import com.spice.profitmandi.common.enumuration.RechargeStatus;
24681 amit.gupta 53
import com.spice.profitmandi.common.enumuration.ReporticoProject;
24121 govind 54
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
23929 amit.gupta 55
import com.spice.profitmandi.common.model.CustomRetailer;
24542 amit.gupta 56
import com.spice.profitmandi.common.model.GstRate;
23724 amit.gupta 57
import com.spice.profitmandi.common.model.RechargeCredential;
24681 amit.gupta 58
import com.spice.profitmandi.common.services.ReporticoService;
24002 amit.gupta 59
import com.spice.profitmandi.common.util.FileUtil;
23929 amit.gupta 60
import com.spice.profitmandi.common.util.FormattingUtils;
61
import com.spice.profitmandi.common.util.Utils;
24592 amit.gupta 62
import com.spice.profitmandi.common.util.Utils.Attachment;
25300 tejbeer 63
import com.spice.profitmandi.dao.Interface.Campaign;
64
import com.spice.profitmandi.dao.convertor.LocalDateTimeJsonConverter;
24590 amit.gupta 65
import com.spice.profitmandi.dao.entity.catalog.Scheme;
23724 amit.gupta 66
import com.spice.profitmandi.dao.entity.dtr.DailyRecharge;
25300 tejbeer 67
import com.spice.profitmandi.dao.entity.dtr.NotificationCampaign;
24653 govind 68
import com.spice.profitmandi.dao.entity.dtr.NotificationCampaigns;
25300 tejbeer 69
import com.spice.profitmandi.dao.entity.dtr.PushNotifications;
23724 amit.gupta 70
import com.spice.profitmandi.dao.entity.dtr.RechargeProvider;
71
import com.spice.profitmandi.dao.entity.dtr.RechargeProviderCreditWalletHistory;
72
import com.spice.profitmandi.dao.entity.dtr.RechargeTransaction;
24542 amit.gupta 73
import com.spice.profitmandi.dao.entity.fofo.CustomerAddress;
24590 amit.gupta 74
import com.spice.profitmandi.dao.entity.fofo.FofoLineItem;
23724 amit.gupta 75
import com.spice.profitmandi.dao.entity.fofo.FofoOrder;
24542 amit.gupta 76
import com.spice.profitmandi.dao.entity.fofo.FofoOrderItem;
23929 amit.gupta 77
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
24249 amit.gupta 78
import com.spice.profitmandi.dao.entity.fofo.InventoryItem;
24277 amit.gupta 79
import com.spice.profitmandi.dao.entity.fofo.PartnerDailyInvestment;
24174 govind 80
import com.spice.profitmandi.dao.entity.fofo.PartnerTargetDetails;
23724 amit.gupta 81
import com.spice.profitmandi.dao.entity.fofo.Purchase;
24242 amit.gupta 82
import com.spice.profitmandi.dao.entity.fofo.ScanRecord;
24241 amit.gupta 83
import com.spice.profitmandi.dao.entity.fofo.SchemeInOut;
24431 amit.gupta 84
import com.spice.profitmandi.dao.entity.transaction.PriceDrop;
24587 amit.gupta 85
import com.spice.profitmandi.dao.entity.transaction.UserWallet;
24580 amit.gupta 86
import com.spice.profitmandi.dao.entity.transaction.UserWalletHistory;
24542 amit.gupta 87
import com.spice.profitmandi.dao.entity.user.Address;
25300 tejbeer 88
import com.spice.profitmandi.dao.entity.user.Device;
24250 amit.gupta 89
import com.spice.profitmandi.dao.enumuration.catalog.SchemeType;
24242 amit.gupta 90
import com.spice.profitmandi.dao.enumuration.fofo.ScanType;
25300 tejbeer 91
import com.spice.profitmandi.dao.model.SimpleCampaign;
92
import com.spice.profitmandi.dao.model.SimpleCampaignParams;
93
import com.spice.profitmandi.dao.repository.catalog.DeviceRepository;
24249 amit.gupta 94
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
24241 amit.gupta 95
import com.spice.profitmandi.dao.repository.catalog.SchemeRepository;
23724 amit.gupta 96
import com.spice.profitmandi.dao.repository.dtr.DailyRechargeRepository;
23929 amit.gupta 97
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
24653 govind 98
import com.spice.profitmandi.dao.repository.dtr.Mongo;
25300 tejbeer 99
import com.spice.profitmandi.dao.repository.dtr.NotificationCampaignRepository;
100
import com.spice.profitmandi.dao.repository.dtr.PushNotificationRepository;
23724 amit.gupta 101
import com.spice.profitmandi.dao.repository.dtr.RechargeProviderCreditWalletHistoryRepository;
102
import com.spice.profitmandi.dao.repository.dtr.RechargeProviderRepository;
103
import com.spice.profitmandi.dao.repository.dtr.RechargeTransactionRepository;
24542 amit.gupta 104
import com.spice.profitmandi.dao.repository.dtr.RetailerRegisteredAddressRepository;
24669 govind 105
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
24542 amit.gupta 106
import com.spice.profitmandi.dao.repository.fofo.CustomerAddressRepository;
24590 amit.gupta 107
import com.spice.profitmandi.dao.repository.fofo.FofoLineItemRepository;
24542 amit.gupta 108
import com.spice.profitmandi.dao.repository.fofo.FofoOrderItemRepository;
23724 amit.gupta 109
import com.spice.profitmandi.dao.repository.fofo.FofoOrderRepository;
24249 amit.gupta 110
import com.spice.profitmandi.dao.repository.fofo.InventoryItemRepository;
24277 amit.gupta 111
import com.spice.profitmandi.dao.repository.fofo.PartnerDailyInvestmentRepository;
24174 govind 112
import com.spice.profitmandi.dao.repository.fofo.PartnerTargetRepository;
23724 amit.gupta 113
import com.spice.profitmandi.dao.repository.fofo.PurchaseRepository;
24242 amit.gupta 114
import com.spice.profitmandi.dao.repository.fofo.ScanRecordRepository;
24241 amit.gupta 115
import com.spice.profitmandi.dao.repository.fofo.SchemeInOutRepository;
23929 amit.gupta 116
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
24431 amit.gupta 117
import com.spice.profitmandi.dao.repository.transaction.PriceDropRepository;
24580 amit.gupta 118
import com.spice.profitmandi.dao.repository.transaction.UserWalletHistoryRepository;
24587 amit.gupta 119
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
24542 amit.gupta 120
import com.spice.profitmandi.dao.repository.user.AddressRepository;
24337 amit.gupta 121
import com.spice.profitmandi.service.PartnerInvestmentService;
23929 amit.gupta 122
import com.spice.profitmandi.service.inventory.InventoryService;
24431 amit.gupta 123
import com.spice.profitmandi.service.pricing.PriceDropService;
23724 amit.gupta 124
import com.spice.profitmandi.service.recharge.provider.OxigenRechargeProviderService;
125
import com.spice.profitmandi.service.recharge.provider.ThinkWalnutDigitalRechargeProviderService;
126
import com.spice.profitmandi.service.scheme.SchemeService;
24121 govind 127
import com.spice.profitmandi.service.slab.TargetSlabService;
23929 amit.gupta 128
import com.spice.profitmandi.service.transaction.TransactionService;
129
import com.spice.profitmandi.service.user.RetailerService;
23739 amit.gupta 130
import com.spice.profitmandi.service.wallet.WalletService;
23723 amit.gupta 131
 
24197 amit.gupta 132
import in.shop2020.model.v1.order.WalletReferenceType;;
23739 amit.gupta 133
 
23723 amit.gupta 134
@Component
23724 amit.gupta 135
@Transactional(rollbackFor = Throwable.class)
23723 amit.gupta 136
public class ScheduledTasks {
137
 
23724 amit.gupta 138
	@Value("${oxigen.recharge.transaction.url}")
139
	private String oxigenRechargeTransactionUrl;
23723 amit.gupta 140
 
23724 amit.gupta 141
	@Value("${oxigen.recharge.enquiry.url}")
142
	private String oxigenRechargeEnquiryUrl;
24533 govind 143
 
24431 amit.gupta 144
	@Autowired
145
	private PriceDropService priceDropService;
23723 amit.gupta 146
 
23724 amit.gupta 147
	@Value("${oxigen.recharge.auth.key}")
148
	private String oxigenRechargeAuthKey;
149
 
150
	@Value("${oxigen.recharge.validation.url}")
151
	private String oxigenRechargeValidationUrl;
152
 
153
	@Value("${oxigen.recharge.validation.auth.key}")
154
	private String oxigenRechargeValidationAuthKey;
155
 
156
	@Value("${think.walnut.digital.recharge.transaction.mobile.url}")
157
	private String thinkWalnutDigitalRechargeTransactionMobileUrl;
158
 
159
	@Value("${think.walnut.digital.recharge.transaction.dth.url}")
160
	private String thinkWalnutDigitalRechargeTransactionDthUrl;
161
 
162
	@Value("${think.walnut.digital.recharge.enquiry.url}")
163
	private String thinkWalnutDigitalRechargeEnquiryUrl;
164
 
165
	@Value("${think.walnut.digital.recharge.balance.url}")
166
	private String thinkWalnutDigitalRechargeBalanceUrl;
167
 
168
	@Value("${think.walnut.digital.recharge.username}")
169
	private String thinkWalnutDigitalRechargeUserName;
170
 
171
	@Value("${think.walnut.digital.recharge.password}")
172
	private String thinkWalnutDigitalRechargePassword;
173
 
174
	@Value("${think.walnut.digital.recharge.auth.key}")
175
	private String thinkWalnutDigitalRechargeAuthKey;
176
 
23723 amit.gupta 177
	@Autowired
23724 amit.gupta 178
	private PurchaseRepository purchaseRepository;
179
 
180
	@Autowired
181
	private SchemeService schemeService;
24683 amit.gupta 182
 
24681 amit.gupta 183
	@Autowired
184
	private ReporticoService reporticoService;
23724 amit.gupta 185
 
186
	@Autowired
24337 amit.gupta 187
	private PartnerInvestmentService partnerInvestmentService;
188
 
189
	@Autowired
24542 amit.gupta 190
	private FofoOrderItemRepository fofoOrderItemRepository;
191
 
192
	@Autowired
24277 amit.gupta 193
	private PartnerDailyInvestmentRepository partnerDailyInvestmentRepository;
194
 
195
	@Autowired
24241 amit.gupta 196
	private SchemeInOutRepository schemeInOutRepository;
197
 
198
	@Autowired
23724 amit.gupta 199
	private RechargeTransactionRepository rechargeTransactionRepository;
200
 
201
	@Autowired
24542 amit.gupta 202
	private CustomerAddressRepository customerAddressRepository;
203
 
204
	@Autowired
23724 amit.gupta 205
	private RechargeProviderCreditWalletHistoryRepository rechargeProviderCreditWalletHistoryRepository;
206
 
207
	@Autowired
24590 amit.gupta 208
	private FofoLineItemRepository fofoLineItemRepository;
209
 
210
	@Autowired
23724 amit.gupta 211
	private FofoOrderRepository fofoOrderRepository;
24587 amit.gupta 212
 
24580 amit.gupta 213
	@Autowired
214
	private UserWalletHistoryRepository userWalletHistoryRepository;
24250 amit.gupta 215
 
24249 amit.gupta 216
	@Autowired
24587 amit.gupta 217
	private UserWalletRepository userWalletRepository;
218
 
219
	@Autowired
24249 amit.gupta 220
	private InventoryItemRepository inventoryItemRepository;
23929 amit.gupta 221
 
23739 amit.gupta 222
	@Autowired
223
	private WalletService walletService;
23724 amit.gupta 224
 
225
	@Autowired
226
	private ThinkWalnutDigitalRechargeProviderService thinkWalnutDigitalRechargeProviderService;
227
 
228
	@Autowired
229
	private OxigenRechargeProviderService oxigenRechargeProviderService;
230
 
231
	@Autowired
232
	private RechargeProviderRepository rechargeProviderRepository;
233
 
234
	@Autowired
24242 amit.gupta 235
	private ScanRecordRepository scanRecordRepository;
236
 
237
	@Autowired
23724 amit.gupta 238
	private DailyRechargeRepository dailyRechargeRepository;
239
 
23929 amit.gupta 240
	@Autowired
241
	private FofoStoreRepository fofoStoreRepository;
24177 govind 242
 
24121 govind 243
	@Autowired
244
	private TargetSlabService targetService;
23929 amit.gupta 245
 
23724 amit.gupta 246
	@Value("${prod}")
247
	private boolean prod;
248
 
23929 amit.gupta 249
	@Autowired
250
	private RetailerService retailerService;
251
 
252
	@Autowired
253
	private TransactionService transactionService;
24250 amit.gupta 254
 
24249 amit.gupta 255
	@Autowired
256
	private ItemRepository itemRepository;
23929 amit.gupta 257
 
258
	@Autowired
259
	private OrderRepository orderRepository;
260
 
261
	@Autowired
24241 amit.gupta 262
	private SchemeRepository schemeRepository;
263
 
264
	@Autowired
23929 amit.gupta 265
	private JavaMailSender mailSender;
24177 govind 266
 
24174 govind 267
	@Autowired
24431 amit.gupta 268
	private PriceDropRepository priceDropRepository;
269
 
270
	@Autowired
24174 govind 271
	private PartnerTargetRepository partnerTargetRepository;
24002 amit.gupta 272
 
273
	@Autowired
274
	@Qualifier(value = "googleMailSender")
23932 amit.gupta 275
	private JavaMailSender googleMailSender;
23929 amit.gupta 276
 
277
	@Autowired
278
	private InventoryService inventoryService;
279
 
24533 govind 280
	@Autowired
24542 amit.gupta 281
	private AddressRepository addressRepository;
282
 
283
	@Autowired
284
	private RetailerRegisteredAddressRepository retailerRegisteredAddressRepository;
285
 
24653 govind 286
	@Autowired
287
	private Mongo mongoClient;
24683 amit.gupta 288
 
24669 govind 289
	@Autowired
25300 tejbeer 290
	private DeviceRepository deviceRepository;
291
 
292
	@Autowired
293
	private PushNotificationRepository pushNotificationRepository;
294
 
295
	@Autowired
296
	private NotificationCampaignRepository notificationCampaignRepository;
297
 
298
	@Autowired
24669 govind 299
	private UserAccountRepository userAccountRepository;
24653 govind 300
 
23755 amit.gupta 301
	private static final Logger LOGGER = LogManager.getLogger(ScheduledTasks.class);
23724 amit.gupta 302
 
25300 tejbeer 303
	private String FCM_URL = "https://fcm.googleapis.com/fcm/send";
304
	private String FCM_API_KEY = "AAAASAjNcn4:APA91bG6fWRIgYJI0L9gCjP5ynaXz2hJHYKtD9dfH7Depdv31Nd9APJwhx-OPkAJ1WSz4BGNYG8lHThLFSjDGFxIwUZv241YcAJEGDLgt86mxq9FXJe-yBRu-S0_ZwHqmX-QaVKl5F_A";
305
 
23724 amit.gupta 306
	public void generateDailyRecharge() {
307
		List<RechargeProviderCreditWalletHistory> allCreditHistory = rechargeProviderCreditWalletHistoryRepository
308
				.selectAll(0, 2000);
309
		List<RechargeProvider> rechargeProviders = rechargeProviderRepository.selectAll();
310
		rechargeProviders.stream().forEach(x -> x.setAmount(0));
311
 
312
		rechargeProviders.stream().forEach(x -> {
313
			Map<LocalDate, List<RechargeProviderCreditWalletHistory>> dateWiseProviderCreditsMap = allCreditHistory
314
					.stream().filter(z -> z.getProviderId() == x.getId())
315
					.collect(Collectors.groupingBy(x1 -> x1.getReceiveTimestamp().toLocalDate()));
316
 
317
			LOGGER.info("dateWiseProviderCreditsMap -- {}", dateWiseProviderCreditsMap);
318
			LocalDate endDate = LocalDate.now().plusDays(1);
319
			float previousDayClosing = 0;
320
			LocalDate date = LocalDate.of(2018, 4, 6);
321
			while (date.isBefore(endDate)) {
322
				List<RechargeTransaction> dateWiseRechargeTransactions = rechargeTransactionRepository
323
						.selectAllBetweenTimestamp(Arrays.asList(RechargeStatus.values()), date.atStartOfDay(),
324
								date.plusDays(1).atStartOfDay());
325
 
326
				List<RechargeTransaction> successfulTransactions = dateWiseRechargeTransactions.stream()
327
						.filter(y -> y.getStatus().equals(RechargeStatus.SUCCESS)).collect(Collectors.toList());
328
 
329
				float dailyAmount = 0;
330
				float totalCommission = 0;
331
				for (RechargeTransaction rechargeTransaction : successfulTransactions) {
332
					if (rechargeTransaction.getProviderId() == x.getId()) {
333
						dailyAmount += rechargeTransaction.getAmount();
334
						totalCommission += rechargeTransaction.getCommission();
335
					}
336
				}
337
 
338
				List<RechargeProviderCreditWalletHistory> rechargeHistoryList = dateWiseProviderCreditsMap.get(date);
339
				float dailyWalletRecharge = 0;
340
				if (rechargeHistoryList != null) {
341
					for (RechargeProviderCreditWalletHistory rechargeProviderCreditWalletHistory : rechargeHistoryList) {
342
						if (rechargeProviderCreditWalletHistory.getProviderId() == x.getId()) {
343
							dailyWalletRecharge += rechargeProviderCreditWalletHistory.getAmount();
344
						}
345
					}
346
				}
347
				if (dailyAmount > 0 || dailyWalletRecharge > 0) {
348
					DailyRecharge dailyRecharge = null;
349
					try {
350
						dailyRecharge = dailyRechargeRepository.selectByProviderIdAndCreateDate(x.getId(), date);
351
					} catch (Exception e) {
352
						LOGGER.info("Could not find Recharge entry");
353
					}
354
					if (dailyRecharge == null) {
355
						dailyRecharge = new DailyRecharge();
356
						dailyRecharge.setCreateDate(date);
357
					}
358
					dailyRecharge.setOpeningBalance(previousDayClosing);
359
					dailyRecharge.setProviderId(x.getId());
360
					dailyRecharge.setWalletRechargeAmount(dailyWalletRecharge);
361
					dailyRecharge.setTotalAmount(dailyAmount);
362
					dailyRecharge.setTotalCommission(totalCommission);
363
					float closingBalance = dailyRecharge.getOpeningBalance() + dailyWalletRecharge - dailyAmount;
364
					dailyRecharge.setClosingBalance(closingBalance);
365
					dailyRechargeRepository.persist(dailyRecharge);
366
					x.setAmount(x.getAmount() + dailyRecharge.getClosingBalance() - dailyRecharge.getOpeningBalance());
367
					previousDayClosing = dailyRecharge.getClosingBalance();
368
				}
369
				date = date.plusDays(1);
370
			}
371
			rechargeProviderRepository.persist(x);
372
		});
23761 amit.gupta 373
		LOGGER.info("finished generating daily recharge");
23724 amit.gupta 374
	}
375
 
23738 amit.gupta 376
	public void reconcileRecharge() throws Exception {
23724 amit.gupta 377
		LocalDateTime fromDate = LocalDateTime.now().truncatedTo(ChronoUnit.DAYS).minusDays(30);
378
		LocalDateTime toDate = LocalDateTime.now().truncatedTo(ChronoUnit.DAYS);
379
		List<RechargeStatus> nonSuccessRechargeStatuses = new ArrayList<>(Arrays.asList(RechargeStatus.values()));
380
		LOGGER.info("nonSuccessRechargeStatuses {} ", nonSuccessRechargeStatuses);
381
		nonSuccessRechargeStatuses.remove(RechargeStatus.SUCCESS);
382
		nonSuccessRechargeStatuses.remove(RechargeStatus.FAILED);
383
		RechargeCredential thinkWalnutDigitalRechargeEnquiryCredential = new RechargeCredential();
384
		thinkWalnutDigitalRechargeEnquiryCredential.setRechargeUrl(thinkWalnutDigitalRechargeEnquiryUrl);
385
		thinkWalnutDigitalRechargeEnquiryCredential.setRechargeUserName(thinkWalnutDigitalRechargeUserName);
386
		thinkWalnutDigitalRechargeEnquiryCredential.setRechargePassword(thinkWalnutDigitalRechargePassword);
387
		thinkWalnutDigitalRechargeEnquiryCredential.setRechargeAuthKey(thinkWalnutDigitalRechargeAuthKey);
388
		Map<String, RechargeStatus> requestRechargeStatusChanged = new HashMap<>();
389
		List<RechargeTransaction> rechargeTransactions = rechargeTransactionRepository
390
				.selectAllBetweenTimestamp(nonSuccessRechargeStatuses, fromDate, toDate);
391
		for (RechargeTransaction rechargeTransaction : rechargeTransactions) {
392
			try {
393
				int providerId = rechargeTransaction.getProviderId();
394
				if (providerId == 1) {
395
					oxigenRechargeProviderService.doCheckStatusRequest(oxigenRechargeEnquiryUrl, oxigenRechargeAuthKey,
396
							rechargeTransaction);
397
				} else if (providerId == 2) {
398
					thinkWalnutDigitalRechargeProviderService
399
							.doCheckStatusRequest(thinkWalnutDigitalRechargeEnquiryCredential, rechargeTransaction);
400
				}
401
				if (rechargeTransaction.getStatus().equals(RechargeStatus.SUCCESS)
402
						|| rechargeTransaction.getStatus().equals(RechargeStatus.FAILED)) {
403
					requestRechargeStatusChanged.put(rechargeTransaction.getRequestId(),
404
							rechargeTransaction.getStatus());
405
				}
406
			} catch (Exception e) {
407
				LOGGER.info("Could not check status for Request {}", rechargeTransaction.getRequestId());
408
			}
409
		}
23738 amit.gupta 410
		LOGGER.info("Reconcile recharge ran successfully");
23724 amit.gupta 411
	}
24240 amit.gupta 412
 
413
	// TemporaryMethod
24237 amit.gupta 414
	public void migrateInvoice() {
415
		List<FofoOrder> fofoOrders = fofoOrderRepository.selectFromSaleDate(LocalDateTime.now().minusDays(3));
416
		Map<Integer, List<FofoOrder>> partnerOrdersMap = new HashMap<>();
24241 amit.gupta 417
		partnerOrdersMap = fofoOrders.stream()
418
				.collect(Collectors.groupingBy(FofoOrder::getFofoId, Collectors.toList()));
24237 amit.gupta 419
		for (List<FofoOrder> orderList : partnerOrdersMap.values()) {
24240 amit.gupta 420
			int sequence = 0;
421
			String prefix = "";
24241 amit.gupta 422
			List<FofoOrder> sortedList = orderList.stream().sorted((x1, x2) -> x1.getId() - x2.getId())
423
					.collect(Collectors.toList());
424
			for (FofoOrder order : sortedList) {
425
 
24240 amit.gupta 426
				LOGGER.info("Order Id is {}, partner Id is {}", order.getId(), order.getFofoId());
24241 amit.gupta 427
				if (!order.getInvoiceNumber().contains("SEC")) {
24240 amit.gupta 428
					sequence = Integer.parseInt(order.getInvoiceNumber().split("/")[1]);
429
					prefix = order.getInvoiceNumber().split("/")[0];
430
				} else {
431
					sequence += 1;
24241 amit.gupta 432
					String invoiceNumber = prefix + "/" + sequence;
24240 amit.gupta 433
					order.setInvoiceNumber(invoiceNumber);
434
					fofoOrderRepository.persist(order);
435
				}
436
			}
24241 amit.gupta 437
 
24237 amit.gupta 438
		}
439
	}
23724 amit.gupta 440
 
24241 amit.gupta 441
	// Temporary Method
24252 amit.gupta 442
	public void evaluateExcessSchemeOut() throws Exception {
24244 amit.gupta 443
		Map<Integer, String> userNameMap = retailerService.getAllFofoRetailerIdNameMap();
444
		Map<Integer, Float> userAmountMap = new HashMap<>();
24252 amit.gupta 445
 
24807 amit.gupta 446
		List<List<? extends Serializable>> rows = new ArrayList<>();
24271 amit.gupta 447
		List<String> headers = Arrays.asList("Scheme", "Item", "Partner", "Amount", "Credited On", "Invoice Number",
448
				"Sale On", "Scheme Start", "Scheme End", "Active On", "Expired On");
24241 amit.gupta 449
		schemeRepository.selectAll().stream().forEach(x -> {
24250 amit.gupta 450
			if (x.getType().equals(SchemeType.OUT)) {
451
				List<SchemeInOut> sioList = schemeInOutRepository
452
						.selectBySchemeIds(new HashSet<>(Arrays.asList(x.getId())));
453
				if (x.getActiveTimestamp() != null) {
454
					LocalDateTime endDateTime = x.getEndDateTime();
455
					if (x.getExpireTimestamp() != null && x.getExpireTimestamp().isBefore(x.getEndDateTime())) {
456
						endDateTime = x.getExpireTimestamp();
24249 amit.gupta 457
					}
24250 amit.gupta 458
					for (SchemeInOut sio : sioList) {
459
						InventoryItem inventoryItem = null;
24266 amit.gupta 460
						inventoryItem = inventoryItemRepository.selectById(sio.getInventoryItemId());
24271 amit.gupta 461
						FofoOrder fofoOrder = fofoOrderRepository.selectByFofoIdAndSerialNumber(
462
								inventoryItem.getFofoId(), inventoryItem.getSerialNumber(), null, null, 0, 1).get(0);
24250 amit.gupta 463
						Optional<ScanRecord> record = scanRecordRepository
464
								.selectByInventoryItemId(sio.getInventoryItemId()).stream()
465
								.filter(y -> y.getType().equals(ScanType.SALE)).findFirst();
466
						if (record.isPresent()) {
467
							int fofoId = record.get().getFofoId();
468
							if (record.get().getCreateTimestamp().isAfter(endDateTime)
469
									|| record.get().getCreateTimestamp().isBefore(x.getStartDateTime())) {
470
								if (!userAmountMap.containsKey(fofoId)) {
471
									userAmountMap.put(fofoId, 0f);
472
								}
473
								userAmountMap.put(fofoId, sio.getAmount() + userAmountMap.get(fofoId));
474
								try {
24252 amit.gupta 475
									rows.add(Arrays.asList(x.getDescription(),
24250 amit.gupta 476
											itemRepository.selectById(inventoryItem.getItemId()).getItemDescription(),
24252 amit.gupta 477
											userNameMap.get(fofoId), sio.getAmount(),
24253 amit.gupta 478
											FormattingUtils.formatDate(sio.getCreateTimestamp()),
479
											fofoOrder.getInvoiceNumber(),
480
											FormattingUtils.formatDate(record.get().getCreateTimestamp()),
481
											FormattingUtils.formatDate(x.getStartDateTime()),
482
											FormattingUtils.formatDate(x.getEndDateTime()),
483
											FormattingUtils.formatDate(x.getActiveTimestamp()),
484
											FormattingUtils.formatDate(x.getExpireTimestamp())));
24250 amit.gupta 485
								} catch (Exception e) {
486
									e.printStackTrace();
487
								}
24242 amit.gupta 488
							}
24241 amit.gupta 489
						}
490
					}
491
				}
492
			}
493
		});
24246 amit.gupta 494
		userAmountMap.entrySet().stream()
495
				.forEach(x -> LOGGER.info("{} to be deducted from {}({}) for wrongly disbursed due to technical error.",
496
						x.getValue(), userNameMap.get(x.getKey())));
24241 amit.gupta 497
 
24252 amit.gupta 498
		ByteArrayOutputStream baos = FileUtil.getCSVByteStream(headers, rows);
24271 amit.gupta 499
		Utils.sendMailWithAttachment(googleMailSender,
500
				new String[] { "amit.gupta@shop2020.in", "adeel.yazdani@smartdukaan.com" }, null,
501
				"Partner Excess Amount", "PFA", "ListofSchemes.csv", new ByteArrayResource(baos.toByteArray()));
24252 amit.gupta 502
 
24241 amit.gupta 503
	}
24271 amit.gupta 504
 
24256 amit.gupta 505
	public void processScheme(int offset) throws Exception {
24462 amit.gupta 506
		LocalDateTime startDate = LocalDateTime.of(LocalDate.now(), LocalTime.MIDNIGHT).minusDays(offset);
24259 amit.gupta 507
		LocalDateTime endDate = startDate.plusDays(30);
24258 amit.gupta 508
		processScheme(startDate, endDate);
24256 amit.gupta 509
	}
24533 govind 510
 
24461 amit.gupta 511
	public void processScheme(int offset, int durationDays) throws Exception {
24462 amit.gupta 512
		LocalDateTime startDate = LocalDateTime.of(LocalDate.now(), LocalTime.MIDNIGHT).minusDays(offset);
24461 amit.gupta 513
		LocalDateTime endDate = startDate.plusDays(durationDays);
514
		processScheme(startDate, endDate);
515
	}
24271 amit.gupta 516
 
23738 amit.gupta 517
	public void processScheme() throws Exception {
24256 amit.gupta 518
		LocalDateTime fromDate = LocalDateTime.now().minusDays(30);
519
		processScheme(fromDate, LocalDateTime.now());
520
	}
24271 amit.gupta 521
 
24256 amit.gupta 522
	public void processScheme(LocalDateTime startDate, LocalDateTime endDate) throws Exception {
23724 amit.gupta 523
		LOGGER.info("Started execution at {}", LocalDateTime.now());
25312 amit.gupta 524
		System.out.println(
525
				"InventoryId\tSerialNumber\tItem Id\tScheme Id\tScheme Name\tScheme Type\tAmount Type\tDP\tTaxable\tScheme Amount\tAmount Paid");
24561 amit.gupta 526
		try {
24587 amit.gupta 527
			List<Purchase> purchases = purchaseRepository.selectAllBetweenPurchaseDate(startDate, endDate);
528
			for (Purchase purchase : purchases) {
529
				schemeService.processSchemeIn(purchase.getId(), purchase.getFofoId());
530
			}
24271 amit.gupta 531
 
24587 amit.gupta 532
			List<FofoOrder> fofoOrders = fofoOrderRepository.selectBetweenSaleDate(startDate, endDate);
533
			for (FofoOrder fofoOrder : fofoOrders) {
534
				schemeService.processSchemeOut(fofoOrder.getId(), fofoOrder.getFofoId());
535
			}
536
		} catch (Exception e) {
24561 amit.gupta 537
			e.printStackTrace();
24565 amit.gupta 538
			throw e;
24561 amit.gupta 539
		}
25312 amit.gupta 540
		List<UserWalletHistory> uwhs = userWalletHistoryRepository.selectAllByDateType(startDate, endDate,
541
				Arrays.asList(WalletReferenceType.SCHEME_IN, WalletReferenceType.SCHEME_OUT));
25043 amit.gupta 542
		System.out.println("Amount\tReference\tReferenceType\tTimestamp\tDescription");
25312 amit.gupta 543
		for (UserWalletHistory uwh : uwhs) {
544
			System.out.println(String.format("%d\t%d\t%s\t%s\t%s", uwh.getAmount(), uwh.getReference(),
545
					uwh.getReferenceType(), uwh.getTimestamp().toString(), uwh.getDescription()));
25043 amit.gupta 546
		}
23724 amit.gupta 547
		LOGGER.info("Schemes process successfully.");
25312 amit.gupta 548
		// throw new Exception();
23724 amit.gupta 549
	}
23929 amit.gupta 550
 
23739 amit.gupta 551
	public void processRechargeCashback() throws Throwable {
23761 amit.gupta 552
		LocalDateTime cashbackTime = LocalDateTime.now();
23929 amit.gupta 553
		int referenceId = (int) Timestamp.valueOf(cashbackTime).getTime() / 1000;
554
		List<RechargeTransaction> pendingTransactions = rechargeTransactionRepository
555
				.getPendingCashBackRehargeTransactions();
556
		Map<Object, Double> totalRetailerCashbacks = pendingTransactions.stream().collect(
557
				Collectors.groupingBy(x -> x.getRetailerId(), Collectors.summingDouble(x -> x.getCommission())));
558
		for (Map.Entry<Object, Double> totalRetailerCashback : totalRetailerCashbacks.entrySet()) {
559
			int retailerId = (Integer) totalRetailerCashback.getKey();
23739 amit.gupta 560
			float amount = totalRetailerCashback.getValue().floatValue();
23929 amit.gupta 561
			if (Math.round(amount) > 0) {
562
				walletService.addAmountToWallet(retailerId, referenceId, WalletReferenceType.CASHBACK,
563
						"Recharge Cashback", Math.round(amount));
23762 amit.gupta 564
			}
23739 amit.gupta 565
		}
23929 amit.gupta 566
		for (RechargeTransaction rt : pendingTransactions) {
23761 amit.gupta 567
			rt.setCashbackTimestamp(cashbackTime);
568
			rt.setCashbackReference(referenceId);
569
			rechargeTransactionRepository.persist(rt);
570
		}
23739 amit.gupta 571
		LOGGER.info("Cashbacks for Recharge processed Successfully");
572
	}
23724 amit.gupta 573
 
24271 amit.gupta 574
	public void sendPartnerInvestmentDetails(List<String> sendTo) throws Exception {
25312 amit.gupta 575
		if (sendTo == null) {
576
			sendTo = Arrays.asList("tarun.verma@smartdukaan.com", "kamini.sharma@smartdukaan.com",
577
					"amit.gupta@shop2020.in");
578
		}
24277 amit.gupta 579
		LocalDate yesterDay = LocalDate.now().minusDays(1);
25267 amit.gupta 580
		List<FofoStore> fofoStores = fofoStoreRepository.selectActiveStores();
23929 amit.gupta 581
		Map<Integer, CustomRetailer> customRetailerMap = retailerService
582
				.getFofoRetailers(fofoStores.stream().map(x -> x.getId()).collect(Collectors.toList()));
583
 
25312 amit.gupta 584
		List<String> headers = Arrays.asList("Code", "Store Name", "Firm Name", "State Manager", "Teritory Manager",
585
				"Team Leader", "Wallet Amount", "In Stock Amount", "Return In Transit Stock", "Unbilled Amount",
24271 amit.gupta 586
				"Grn Pending Amount", "Min Investment", "Investment Amount", "Investment Short");
24807 amit.gupta 587
		List<List<? extends Serializable>> rows = new ArrayList<>();
25312 amit.gupta 588
		Map<String, List<? extends Serializable>> partnerRow = new HashMap<>();
24002 amit.gupta 589
		for (FofoStore fofoStore : fofoStores) {
590
			CustomRetailer retailer = customRetailerMap.get(fofoStore.getId());
591
			if (retailer == null) {
592
				LOGGER.info("Could not find retailer with retailer Id {}", fofoStore.getId());
593
				continue;
594
			}
24533 govind 595
			PartnerDailyInvestment partnerDailyInvestment = partnerInvestmentService.getInvestment(fofoStore.getId(),
596
					1);
24337 amit.gupta 597
			partnerDailyInvestment.setDate(yesterDay);
598
			partnerDailyInvestmentRepository.persist(partnerDailyInvestment);
24533 govind 599
 
25312 amit.gupta 600
			List<? extends Serializable> row = Arrays.asList(fofoStore.getCode(),
601
					"SmartDukaan-" + fofoStore.getCode().substring(5), retailer.getBusinessName(),
602
					storeManagerMap.get(retailer.getEmail()).get(2), storeManagerMap.get(retailer.getEmail()).get(1),
603
					storeManagerMap.get(retailer.getEmail()).get(0), partnerDailyInvestment.getWalletAmount(), 0,
24415 amit.gupta 604
					partnerDailyInvestment.getUnbilledAmount(), partnerDailyInvestment.getGrnPendingAmount(),
24533 govind 605
					partnerDailyInvestment.getMinInvestment(), partnerDailyInvestment.getTotalInvestment(),
606
					partnerDailyInvestment.getShortInvestment());
25312 amit.gupta 607
			partnerRow.put(retailer.getEmail(), row);
24002 amit.gupta 608
			rows.add(row);
609
 
23929 amit.gupta 610
		}
25312 amit.gupta 611
		Map<String, Set<String>> storeGuyMap = new HashMap<>();
612
		for (Map.Entry<String, List<String>> entry : storeManagerMap.entrySet()) {
613
			String storeEmail = entry.getKey();
614
			List<String> storeGuys = entry.getValue();
615
			for (String storeGuy : storeGuys) {
616
				if (!storeGuyMap.containsKey(storeGuy)) {
617
					storeGuyMap.put(storeGuy, new HashSet<>());
618
				}
619
				storeGuyMap.get(storeGuy).add(storeEmail);
620
			}
621
		}
622
 
24271 amit.gupta 623
		String fileName = "InvestmentSummary-" + FormattingUtils.formatDate(LocalDateTime.now()) + ".csv";
25312 amit.gupta 624
		for (Map.Entry<String, Set<String>> storeGuyEntry : storeGuyMap.entrySet()) {
625
			List<List<? extends Serializable>> filteredRows = storeGuyEntry.getValue().stream()
626
					.map(x -> partnerRow.get(x)).collect(Collectors.toList());
627
			ByteArrayOutputStream baos = FileUtil.getCSVByteStream(headers, filteredRows);
628
			String[] sendToArray = new String[] { storeGuyEntry.getKey() };
629
			Utils.sendMailWithAttachment(googleMailSender, sendToArray, null, "Partner Investment Summary", "PFA",
630
					fileName, new ByteArrayResource(baos.toByteArray()));
631
		}
632
 
24002 amit.gupta 633
		ByteArrayOutputStream baos = FileUtil.getCSVByteStream(headers, rows);
24271 amit.gupta 634
		String[] sendToArray = sendTo.toArray(new String[sendTo.size()]);
635
		Utils.sendMailWithAttachment(googleMailSender, sendToArray, null, "Partner Investment Summary", "PFA", fileName,
636
				new ByteArrayResource(baos.toByteArray()));
637
 
23929 amit.gupta 638
	}
24177 govind 639
 
24271 amit.gupta 640
	public void sendPartnerInvestmentDetails() throws Exception {
25312 amit.gupta 641
		this.sendPartnerInvestmentDetails(null);
24271 amit.gupta 642
 
643
	}
644
 
24177 govind 645
	private void sendMailWithAttachments(String[] email, String[] ccEmails, String body, String subject,
24187 govind 646
			Map<String, InputStream> inputStreams)
24177 govind 647
			throws MessagingException, ProfitMandiBusinessException, IOException {
24121 govind 648
		MimeMessage message = mailSender.createMimeMessage();
24177 govind 649
		MimeMessageHelper helper = new MimeMessageHelper(message, true, CharEncoding.UTF_8);
650
		helper.setSubject(subject);
651
		helper.setText(body);
652
		if (ccEmails != null) {
653
			helper.setCc(ccEmails);
654
		}
24240 amit.gupta 655
		for (String attachment : inputStreams.keySet()) {
656
			helper.addAttachment(attachment + "_" + LocalDate.now() + ".xls",
657
					new ByteArrayResource(IOUtils.toByteArray(inputStreams.get(attachment))));
24187 govind 658
		}
24177 govind 659
		helper.setTo(email);
24195 govind 660
		InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "Smart Dukaan");
24177 govind 661
		helper.setFrom(senderAddress);
662
		mailSender.send(message);
24135 govind 663
	}
24240 amit.gupta 664
 
25312 amit.gupta 665
	public void sendTargetVsSalesReport(List<String> sendTo) throws Exception {
24177 govind 666
 
25312 amit.gupta 667
		if (sendTo == null) {
668
			sendTo = Arrays.asList("tarun.verma@smartdukaan.com", "kamini.sharma@smartdukaan.com",
669
					"amit.gupta@shop2020.in");
670
		}
24177 govind 671
		List<PartnerTargetDetails> partnerTargetDetails = partnerTargetRepository
672
				.selectAllGeEqAndLeEqStartDateAndEndDate(LocalDateTime.now());
25312 amit.gupta 673
		Map<String, List<? extends Serializable>> partnerSalesTargetRowsMap = new HashMap<>();
24177 govind 674
		for (PartnerTargetDetails partnerTargetDetail : partnerTargetDetails) {
25312 amit.gupta 675
			partnerSalesTargetRowsMap.putAll(targetService.getDailySaleReportVsTarget(partnerTargetDetail));
24174 govind 676
		}
25312 amit.gupta 677
		List<FofoStore> fofoStores = fofoStoreRepository.selectActiveStores();
678
		Map<Integer, CustomRetailer> customRetailerMap = retailerService
679
				.getFofoRetailers(fofoStores.stream().map(x -> x.getId()).collect(Collectors.toList()));
24177 govind 680
 
25312 amit.gupta 681
		List<String> headers = Arrays.asList("Code", "Store Name", "Firm Name", "State Manager", "Teritory Manager",
682
				"Team Leader", "Target Name", "Target Value", "Target Achieved", "Today Achievement Percentage",
683
				"Daily target", "Today's achievement", "Remaining Target");
24177 govind 684
 
25312 amit.gupta 685
		List<List<? extends Serializable>> rows = new ArrayList<>();
686
		Map<String, List<Serializable>> partnerRowMap = new HashMap<>();
687
		for (FofoStore fofoStore : fofoStores) {
688
			CustomRetailer retailer = customRetailerMap.get(fofoStore.getId());
689
			if (retailer == null) {
690
				LOGGER.info("Could not find retailer with retailer Id {}", fofoStore.getId());
691
				continue;
24271 amit.gupta 692
			}
25312 amit.gupta 693
			Serializable code = fofoStore.getCode();
694
			Serializable storeName = "SmartDukaan-" + fofoStore.getCode().substring(5);
695
			Serializable stateManager = storeManagerMap.get(retailer.getEmail()).get(2);
696
			Serializable territoryManager = storeManagerMap.get(retailer.getEmail()).get(1);
697
			Serializable teamLeader = storeManagerMap.get(retailer.getEmail()).get(0);
698
			List<Serializable> row = Arrays.asList(fofoStore.getCode(),
699
					"SmartDukaan-" + fofoStore.getCode().substring(5), retailer.getBusinessName(), stateManager,
700
					territoryManager, teamLeader);
701
			row.addAll(0, partnerSalesTargetRowsMap.get(retailer.getEmail()));
702
			partnerRowMap.put(retailer.getEmail(), row);
703
			rows.add(row);
704
 
24177 govind 705
		}
706
 
25312 amit.gupta 707
		Map<String, Set<String>> storeGuyMap = new HashMap<>();
708
		for (Map.Entry<String, List<String>> entry : storeManagerMap.entrySet()) {
709
			String storeEmail = entry.getKey();
710
			List<String> storeGuys = entry.getValue();
711
			for (String storeGuy : storeGuys) {
712
				if (!storeGuyMap.containsKey(storeGuy)) {
713
					storeGuyMap.put(storeGuy, new HashSet<>());
714
				}
715
				storeGuyMap.get(storeGuy).add(storeEmail);
24192 govind 716
			}
25312 amit.gupta 717
		}
24240 amit.gupta 718
 
25312 amit.gupta 719
		String fileName = "InvestmentSummary-" + FormattingUtils.formatDate(LocalDateTime.now()) + ".csv";
720
		for (Map.Entry<String, Set<String>> storeGuyEntry : storeGuyMap.entrySet()) {
721
			List<List<? extends Serializable>> filteredRows = storeGuyEntry.getValue().stream()
722
					.map(x -> partnerRowMap.get(x)).collect(Collectors.toList());
723
			ByteArrayOutputStream baos = FileUtil.getCSVByteStream(headers, filteredRows);
724
			String[] sendToArray = new String[] { storeGuyEntry.getKey() };
725
			Utils.sendMailWithAttachment(googleMailSender, sendToArray, null, "Target vs Sales Summary", "PFA",
726
					fileName, new ByteArrayResource(baos.toByteArray()));
727
		}
24240 amit.gupta 728
 
25312 amit.gupta 729
		ByteArrayOutputStream baos = FileUtil.getCSVByteStream(headers, rows);
730
		String[] sendToArray = sendTo.toArray(new String[sendTo.size()]);
731
		Utils.sendMailWithAttachment(googleMailSender, sendToArray, null, "Target vs Sales Summary", "PFA", fileName,
732
				new ByteArrayResource(baos.toByteArray()));
24174 govind 733
	}
24683 amit.gupta 734
 
24697 amit.gupta 735
	public void sendAgeingReport(String... sendTo) throws Exception {
24692 amit.gupta 736
 
737
		InputStreamSource isr = reporticoService.getReportInputStreamSource(ReporticoProject.WAREHOUSENEW,
738
				"itemstockageing.xml");
24708 amit.gupta 739
		InputStreamSource isr1 = reporticoService.getReportInputStreamSource(ReporticoProject.FOCO,
24754 amit.gupta 740
				"ItemwiseOverallPendingIndent.xml");
24683 amit.gupta 741
		Attachment attachment = new Attachment(
24692 amit.gupta 742
				"aeging-report-" + FormattingUtils.formatDate(LocalDateTime.now().minusDays(1)) + ".csv", isr);
24707 amit.gupta 743
		Attachment attachment1 = new Attachment(
744
				"aeging-report-" + FormattingUtils.formatDate(LocalDateTime.now().minusDays(1)) + ".csv", isr1);
24841 govind 745
		Utils.sendMailWithAttachments(googleMailSender, sendTo, null, "Stock Aeging Report", "PFA", attachment,
746
				attachment1);
24681 amit.gupta 747
	}
24533 govind 748
 
24697 amit.gupta 749
	public void sendAgeingReport() throws Exception {
750
		sendAgeingReport("amod.sen@smartdukaan.com", "adeel.yazdani@smartdukaan.com", "kamini.sharma@smartdukaan.com",
751
				"tarun.verma@smartdukaan.com", "chaitnaya.vats@smartdukaan.com", "mohinder.mutreja@smartdukaan.com");
752
	}
753
 
24533 govind 754
	public void moveImeisToPriceDropImeis() throws Exception {
24431 amit.gupta 755
		List<PriceDrop> priceDrops = priceDropRepository.selectAll();
24533 govind 756
		for (PriceDrop priceDrop : priceDrops) {
24431 amit.gupta 757
			priceDropService.priceDropStatus(priceDrop.getId());
758
		}
759
	}
23929 amit.gupta 760
 
24542 amit.gupta 761
	public void walletmismatch() throws Exception {
762
		LocalDate curDate = LocalDate.now();
24553 amit.gupta 763
		List<PartnerDailyInvestment> pdis = partnerDailyInvestmentRepository.selectAll(curDate.minusDays(2));
24552 amit.gupta 764
		System.out.println(pdis.size());
24542 amit.gupta 765
		for (PartnerDailyInvestment pdi : pdis) {
24549 amit.gupta 766
			int fofoId = pdi.getFofoId();
24542 amit.gupta 767
			for (PartnerDailyInvestment investment : Lists
768
					.reverse(partnerDailyInvestmentRepository.selectAll(fofoId, null, null))) {
24552 amit.gupta 769
				float statementAmount = walletService.getOpeningTill(fofoId,
24555 amit.gupta 770
						investment.getDate().plusDays(1).atTime(LocalTime.of(4, 0)));
24552 amit.gupta 771
				CustomRetailer retailer = retailerService.getFofoRetailer(fofoId);
24841 govind 772
				LOGGER.info("{}\t{}\t{}\t{}\t{}", fofoId, retailer.getBusinessName(), retailer.getMobileNumber(),
773
						investment.getDate().toString(), investment.getWalletAmount(), statementAmount);
24551 amit.gupta 774
 
24542 amit.gupta 775
			}
24549 amit.gupta 776
		}
24542 amit.gupta 777
 
778
	}
779
 
780
	public void gst() throws Exception {
24548 amit.gupta 781
		List<FofoOrder> fofoOrders = fofoOrderRepository.selectBetweenSaleDate(LocalDate.of(2019, 1, 26).atStartOfDay(),
782
				LocalDate.of(2019, 1, 27).atTime(LocalTime.MAX));
783
		for (FofoOrder fofoOrder : fofoOrders) {
784
			int retailerAddressId = retailerRegisteredAddressRepository
785
					.selectAddressIdByRetailerId(fofoOrder.getFofoId());
24542 amit.gupta 786
 
787
			Address retailerAddress = addressRepository.selectById(retailerAddressId);
788
			CustomerAddress customerAddress = customerAddressRepository.selectById(fofoOrder.getCustomerAddressId());
789
			Integer stateId = null;
790
			if (customerAddress.getState().equals(retailerAddress.getState())) {
791
				try {
792
					stateId = Long.valueOf(Utils.getStateInfo(customerAddress.getState()).getId()).intValue();
793
				} catch (Exception e) {
794
					LOGGER.error("Unable to get state rates");
795
				}
796
			}
797
			Map<Integer, GstRate> itemIdStateTaxRateMap = null;
798
			Map<Integer, Float> itemIdIgstTaxRateMap = null;
24548 amit.gupta 799
 
800
			List<FofoOrderItem> fofoOrderItems = fofoOrderItemRepository.selectByOrderId(fofoOrder.getId());
801
			Set<Integer> itemIds = fofoOrderItems.stream().map(x -> x.getItemId()).collect(Collectors.toSet());
24542 amit.gupta 802
			if (stateId != null) {
803
				itemIdStateTaxRateMap = Utils.getStateTaxRate(new ArrayList<>(itemIds), stateId);
804
			} else {
805
				itemIdIgstTaxRateMap = Utils.getIgstTaxRate(new ArrayList<>(itemIds));
806
			}
807
 
24548 amit.gupta 808
			for (FofoOrderItem foi : fofoOrderItems) {
24542 amit.gupta 809
				if (stateId == null) {
810
					foi.setIgstRate(itemIdIgstTaxRateMap.get(foi.getItemId()));
811
				} else {
812
					foi.setCgstRate(itemIdStateTaxRateMap.get(foi.getItemId()).getCgstRate());
813
					foi.setSgstRate(itemIdStateTaxRateMap.get(foi.getItemId()).getSgstRate());
814
				}
815
				fofoOrderItemRepository.persist(foi);
816
			}
817
		}
24548 amit.gupta 818
 
24542 amit.gupta 819
	}
820
 
24580 amit.gupta 821
	public void schemewalletmismatch() {
822
		LocalDate dateToReconcile = LocalDate.of(2018, 4, 1);
24587 amit.gupta 823
		while (dateToReconcile.isBefore(LocalDate.now())) {
24580 amit.gupta 824
			reconcileSchemes(dateToReconcile);
24587 amit.gupta 825
			// reconcileOrders(dateTime);
826
			// reconcileRecharges(dateTime);
24580 amit.gupta 827
			dateToReconcile = dateToReconcile.plusDays(1);
828
		}
829
	}
830
 
831
	private void reconcileSchemes(LocalDate date) {
832
		LocalDateTime startDate = date.atStartOfDay();
833
		LocalDateTime endDate = startDate.plusDays(1);
834
		List<SchemeInOut> siosCreated = schemeInOutRepository.selectAllByCreateDate(startDate, endDate);
835
		List<SchemeInOut> siosRefunded = schemeInOutRepository.selectAllByRefundDate(startDate, endDate);
24587 amit.gupta 836
		double totalSchemeDisbursed = siosCreated.stream().mapToDouble(x -> x.getAmount()).sum();
837
		double totalSchemeRolledback = siosRefunded.stream().mapToDouble(x -> x.getAmount()).sum();
24580 amit.gupta 838
		double netSchemeDisbursed = totalSchemeDisbursed - totalSchemeRolledback;
24587 amit.gupta 839
		List<WalletReferenceType> walletReferenceTypes = Arrays.asList(WalletReferenceType.SCHEME_IN,
840
				WalletReferenceType.SCHEME_OUT);
841
		List<UserWalletHistory> history = userWalletHistoryRepository.selectAllByDateType(startDate, endDate,
842
				walletReferenceTypes);
843
		double schemeAmountWalletTotal = history.stream().mapToDouble(x -> x.getAmount()).sum();
844
		if (Math.abs(netSchemeDisbursed - schemeAmountWalletTotal) > 10d) {
24580 amit.gupta 845
			LOGGER.info("Scheme Amount mismatched for Date {}", date);
24587 amit.gupta 846
 
847
			Map<Integer, Double> inventoryItemSchemeIO = siosCreated.stream().collect(Collectors
848
					.groupingBy(x -> x.getInventoryItemId(), Collectors.summingDouble(SchemeInOut::getAmount)));
849
 
850
			Map<Integer, Double> userSchemeMap = inventoryItemRepository.selectByIds(inventoryItemSchemeIO.keySet())
851
					.stream().collect(Collectors.groupingBy(x -> x.getFofoId(),
852
							Collectors.summingDouble(x -> inventoryItemSchemeIO.get(x.getId()))));
853
 
854
			Map<Integer, Double> inventoryItemSchemeIORefunded = siosRefunded.stream().collect(Collectors
855
					.groupingBy(x -> x.getInventoryItemId(), Collectors.summingDouble(SchemeInOut::getAmount)));
856
 
857
			Map<Integer, Double> userSchemeRefundedMap = inventoryItemRepository
858
					.selectByIds(inventoryItemSchemeIORefunded.keySet()).stream()
859
					.collect(Collectors.groupingBy(x -> x.getFofoId(),
860
							Collectors.summingDouble(x -> inventoryItemSchemeIORefunded.get(x.getId()))));
861
 
862
			Map<Integer, Double> finalUserSchemeAmountMap = new HashMap<>();
863
			for (Map.Entry<Integer, Double> schemeAmount : userSchemeMap.entrySet()) {
864
			}
865
			for (Map.Entry<Integer, Double> schemeAmount : userSchemeRefundedMap.entrySet()) {
866
				if (!finalUserSchemeAmountMap.containsKey(schemeAmount.getKey())) {
867
					finalUserSchemeAmountMap.put(schemeAmount.getKey(), schemeAmount.getValue());
868
				} else {
869
					finalUserSchemeAmountMap.put(schemeAmount.getKey(),
870
							finalUserSchemeAmountMap.get(schemeAmount.getKey()) + schemeAmount.getValue());
871
				}
872
			}
24590 amit.gupta 873
			Map<Integer, Integer> userWalletMap = userWalletRepository
874
					.selectByRetailerIds(finalUserSchemeAmountMap.keySet()).stream()
875
					.collect(Collectors.toMap(UserWallet::getUserId, UserWallet::getId));
876
 
24587 amit.gupta 877
			Map<Integer, Double> walletAmountMap = history.stream().collect(Collectors.groupingBy(
878
					UserWalletHistory::getWalletId, Collectors.summingDouble((UserWalletHistory::getAmount))));
879
			for (Map.Entry<Integer, Double> userAmount : walletAmountMap.entrySet()) {
880
				double diff = Math.abs(finalUserSchemeAmountMap.get(userAmount.getKey()) - userAmount.getValue());
881
				if (diff > 5) {
882
					LOGGER.info("Partner scheme mismatched for Userid {}", userWalletMap.get(userAmount.getKey()));
883
				}
884
			}
24580 amit.gupta 885
		}
24587 amit.gupta 886
 
24580 amit.gupta 887
	}
24590 amit.gupta 888
 
24592 amit.gupta 889
	public void dryRunSchemeReco() throws Exception {
24635 amit.gupta 890
		Map<Integer, Integer> userWalletMap = userWalletRepository.selectAll().stream()
891
				.collect(Collectors.toMap(UserWallet::getUserId, UserWallet::getId));
892
 
24592 amit.gupta 893
		List<UserWalletHistory> userWalletHistory = new ArrayList<>();
894
		List<SchemeInOut> rolledbackSios = new ArrayList<>();
24635 amit.gupta 895
		Map<Integer, SchemeType> schemeTypeMap = schemeRepository.selectAll().stream()
896
				.collect(Collectors.toMap(Scheme::getId, Scheme::getType));
897
		Set<String> serialNumbersConsidered = new HashSet<>();
898
 
25096 amit.gupta 899
		LocalDateTime startDate = LocalDate.of(2018, 3, 1).atStartOfDay();
24635 amit.gupta 900
		LocalDateTime endDate = LocalDate.now().atStartOfDay();
901
		List<Purchase> purchases = purchaseRepository.selectAllBetweenPurchaseDate(startDate, endDate);
902
 
24683 amit.gupta 903
		Map<Integer, String> storeNameMap = fofoStoreRepository.getStoresMap();
24635 amit.gupta 904
		purchases.stream().forEach(purchase -> {
905
			float amountToRollback = 0;
906
			String description = "Adjustment of Duplicate Scheme for Purchase Invoice "
907
					+ purchase.getPurchaseReference();
908
			Map<Integer, String> inventorySerialNumberMap = inventoryItemRepository.selectByPurchaseId(purchase.getId())
909
					.stream().filter(ii -> ii.getSerialNumber() != null)
910
					.collect(Collectors.toMap(InventoryItem::getId, InventoryItem::getSerialNumber));
911
			if (inventorySerialNumberMap.size() > 0) {
912
				for (Map.Entry<Integer, String> inventorySerialNumberEntry : inventorySerialNumberMap.entrySet()) {
913
					String serialNumber = inventorySerialNumberEntry.getValue();
914
					int inventoryItemId = inventorySerialNumberEntry.getKey();
915
					if (serialNumbersConsidered.contains(serialNumber)) {
916
						// This will rollback scheme for differenct orders for same serial
917
						List<SchemeInOut> sios = schemeInOutRepository
918
								.selectByInventoryItemIds(new HashSet<>(Arrays.asList(inventoryItemId))).stream()
919
								.filter(x -> x.getRolledBackTimestamp() == null
920
										&& schemeTypeMap.get(x.getSchemeId()).equals(SchemeType.IN))
921
								.collect(Collectors.toList());
922
						Collections.reverse(sios);
923
						for (SchemeInOut sio : sios) {
924
							sio.setRolledBackTimestamp(LocalDateTime.now());
925
							amountToRollback += sio.getAmount();
926
							// sio.setSchemeType(SchemeType.OUT);
927
							sio.setSerialNumber(serialNumber);
928
							rolledbackSios.add(sio);
929
						}
930
						description = description.concat(" " + serialNumber + " ");
931
					} else {
932
						serialNumbersConsidered.add(serialNumber);
933
						List<Integer> schemesConsidered = new ArrayList<>();
934
						List<SchemeInOut> sios = schemeInOutRepository
935
								.selectByInventoryItemIds(new HashSet<>(Arrays.asList(inventoryItemId))).stream()
936
								.filter(x -> x.getRolledBackTimestamp() == null
937
										&& schemeTypeMap.get(x.getSchemeId()).equals(SchemeType.IN))
938
								.collect(Collectors.toList());
939
						Collections.reverse(sios);
940
						for (SchemeInOut sio : sios) {
941
							if (!schemesConsidered.contains(sio.getSchemeId())) {
942
								schemesConsidered.add(sio.getSchemeId());
943
								continue;
944
							}
945
							sio.setRolledBackTimestamp(LocalDateTime.now());
946
							amountToRollback += sio.getAmount();
947
							// sio.setSchemeType(SchemeType.OUT);
948
							sio.setSerialNumber(serialNumber);
24681 amit.gupta 949
							sio.setStoreCode(storeNameMap.get(purchase.getFofoId()));
950
							sio.setReference(purchase.getId());
24635 amit.gupta 951
							rolledbackSios.add(sio);
952
						}
953
					}
954
 
955
				}
956
			}
957
			if (amountToRollback > 0) {
24683 amit.gupta 958
				// Address address =
959
				// addressRepository.selectAllByRetailerId(purchase.getFofoId(), 0, 10).get(0);
24635 amit.gupta 960
				UserWalletHistory uwh = new UserWalletHistory();
961
				uwh.setAmount(Math.round(amountToRollback));
962
				uwh.setDescription(description);
963
				uwh.setTimestamp(LocalDateTime.now());
24681 amit.gupta 964
				uwh.setReferenceType(WalletReferenceType.SCHEME_IN);
24635 amit.gupta 965
				uwh.setReference(purchase.getId());
966
				uwh.setWalletId(userWalletMap.get(purchase.getFofoId()));
967
				uwh.setFofoId(purchase.getFofoId());
24681 amit.gupta 968
				uwh.setStoreCode(storeNameMap.get(purchase.getFofoId()));
24635 amit.gupta 969
				userWalletHistory.add(uwh);
970
			}
971
		});
972
		ByteArrayOutputStream baos = FileUtil.getCSVByteStream(
973
				Arrays.asList("User Id", "Store Code", "Reference Type", "Reference", "Amount", "Description",
974
						"Timestamp"),
975
				userWalletHistory.stream()
976
						.map(x -> Arrays.asList(x.getWalletId(), x.getStoreCode(), x.getReferenceType(),
977
								x.getReference(), x.getAmount(), x.getDescription(), x.getTimestamp()))
978
						.collect(Collectors.toList()));
979
 
980
		ByteArrayOutputStream baosOuts = FileUtil.getCSVByteStream(
24683 amit.gupta 981
				Arrays.asList("Scheme ID", "SchemeType", "Reference", "Store Code", "Serial Number", "Amount",
982
						"Created", "Rolledback"),
24635 amit.gupta 983
				rolledbackSios.stream()
24681 amit.gupta 984
						.map(x -> Arrays.asList(x.getSchemeId(), x.getSchemeType(), x.getReference(), x.getStoreCode(),
24635 amit.gupta 985
								x.getSerialNumber(), x.getAmount(), x.getCreateTimestamp(), x.getRolledBackTimestamp()))
986
						.collect(Collectors.toList()));
987
 
25043 amit.gupta 988
		Utils.sendMailWithAttachments(googleMailSender, new String[] { "amit.gupta@shop2020.in" }, null,
24636 amit.gupta 989
				"Partner Excess Amount Scheme In", "PFA",
24635 amit.gupta 990
				new Attachment[] { new Attachment("WalletSummary.csv", new ByteArrayResource(baos.toByteArray())),
24636 amit.gupta 991
						new Attachment("SchemeInRolledback.csv", new ByteArrayResource(baosOuts.toByteArray())) });
24635 amit.gupta 992
 
25096 amit.gupta 993
		throw new Exception();
24635 amit.gupta 994
 
995
	}
996
 
997
	public void dryRunOutSchemeReco() throws Exception {
998
		List<UserWalletHistory> userWalletHistory = new ArrayList<>();
999
		List<SchemeInOut> rolledbackSios = new ArrayList<>();
24606 amit.gupta 1000
		Map<Integer, Integer> userWalletMap = userWalletRepository.selectAll().stream()
1001
				.collect(Collectors.toMap(UserWallet::getUserId, UserWallet::getId));
24590 amit.gupta 1002
		Map<Integer, SchemeType> schemeTypeMap = schemeRepository.selectAll().stream()
1003
				.collect(Collectors.toMap(Scheme::getId, Scheme::getType));
25028 amit.gupta 1004
		LocalDateTime startDate = LocalDate.of(2019, 5, 1).atStartOfDay();
24632 amit.gupta 1005
		LocalDateTime endDate = LocalDate.now().atStartOfDay();
24631 amit.gupta 1006
		List<FofoOrder> allOrders = fofoOrderRepository.selectBetweenSaleDate(startDate, endDate);
1007
		// Collections.reverse(allOrders);
1008
		// List<FofoOrder> allOrders =
24653 govind 1009
		// List<FofoOrder> allOrders =
24631 amit.gupta 1010
		// Arrays.asList(fofoOrderRepository.selectByInvoiceNumber("UPGZ019/25"));
24625 amit.gupta 1011
		Set<String> serialNumbersConsidered = new HashSet<>();
24590 amit.gupta 1012
		allOrders.stream().forEach(fofoOrder -> {
24592 amit.gupta 1013
			String description = "Adjustment of Duplicate Scheme for Sale Invoice " + fofoOrder.getInvoiceNumber();
24598 amit.gupta 1014
			Map<Integer, String> inventorySerialNumberMap = new HashMap<>();
24592 amit.gupta 1015
			float amountToRollback = 0;
24590 amit.gupta 1016
			List<FofoOrderItem> orderItems = fofoOrderItemRepository.selectByOrderId(fofoOrder.getId());
1017
			orderItems.forEach(x -> {
24606 amit.gupta 1018
				inventorySerialNumberMap.putAll(x.getFofoLineItems().stream().filter(li -> li.getSerialNumber() != null)
24598 amit.gupta 1019
						.collect(Collectors.toMap(FofoLineItem::getInventoryItemId, FofoLineItem::getSerialNumber)));
24590 amit.gupta 1020
			});
24606 amit.gupta 1021
			if (inventorySerialNumberMap.size() > 0) {
24631 amit.gupta 1022
				for (Map.Entry<Integer, String> inventorySerialNumberEntry : inventorySerialNumberMap.entrySet()) {
1023
					String serialNumber = inventorySerialNumberEntry.getValue();
1024
					int inventoryItemId = inventorySerialNumberEntry.getKey();
1025
					if (serialNumbersConsidered.contains(serialNumber)) {
1026
						// This will rollback scheme for differenct orders for same serial
1027
						List<SchemeInOut> sios = schemeInOutRepository
24633 amit.gupta 1028
								.selectByInventoryItemIds(new HashSet<>(Arrays.asList(inventoryItemId))).stream()
24635 amit.gupta 1029
								.filter(x -> x.getRolledBackTimestamp() == null
1030
										&& schemeTypeMap.get(x.getSchemeId()).equals(SchemeType.OUT))
24631 amit.gupta 1031
								.collect(Collectors.toList());
1032
						Collections.reverse(sios);
1033
						for (SchemeInOut sio : sios) {
1034
							sio.setRolledBackTimestamp(LocalDateTime.now());
1035
							amountToRollback += sio.getAmount();
1036
							// sio.setSchemeType(SchemeType.OUT);
1037
							sio.setSerialNumber(serialNumber);
1038
							sio.setStoreCode(fofoOrder.getInvoiceNumber().split("/")[0]);
24681 amit.gupta 1039
							sio.setReference(fofoOrder.getId());
24631 amit.gupta 1040
							rolledbackSios.add(sio);
24623 amit.gupta 1041
						}
24635 amit.gupta 1042
						description = description.concat(" " + serialNumber + " ");
24631 amit.gupta 1043
					} else {
1044
						serialNumbersConsidered.add(serialNumber);
1045
						List<Integer> schemesConsidered = new ArrayList<>();
1046
						List<SchemeInOut> sios = schemeInOutRepository
24633 amit.gupta 1047
								.selectByInventoryItemIds(new HashSet<>(Arrays.asList(inventoryItemId))).stream()
24635 amit.gupta 1048
								.filter(x -> x.getRolledBackTimestamp() == null
1049
										&& schemeTypeMap.get(x.getSchemeId()).equals(SchemeType.OUT))
24631 amit.gupta 1050
								.collect(Collectors.toList());
1051
						Collections.reverse(sios);
1052
						for (SchemeInOut sio : sios) {
1053
							if (!schemesConsidered.contains(sio.getSchemeId())) {
1054
								schemesConsidered.add(sio.getSchemeId());
1055
								continue;
1056
							}
1057
							sio.setRolledBackTimestamp(LocalDateTime.now());
1058
							amountToRollback += sio.getAmount();
1059
							// sio.setSchemeType(SchemeType.OUT);
24681 amit.gupta 1060
							sio.setReference(fofoOrder.getId());
24631 amit.gupta 1061
							sio.setSerialNumber(serialNumber);
1062
							sio.setStoreCode(fofoOrder.getInvoiceNumber().split("/")[0]);
1063
							rolledbackSios.add(sio);
1064
						}
24615 amit.gupta 1065
					}
24631 amit.gupta 1066
 
24604 amit.gupta 1067
				}
24590 amit.gupta 1068
			}
24631 amit.gupta 1069
			if (amountToRollback > 0) {
1070
				UserWalletHistory uwh = new UserWalletHistory();
1071
				uwh.setAmount(Math.round(amountToRollback));
1072
				uwh.setDescription(description);
1073
				uwh.setTimestamp(LocalDateTime.now());
1074
				uwh.setReferenceType(WalletReferenceType.SCHEME_OUT);
1075
				uwh.setReference(fofoOrder.getId());
1076
				uwh.setWalletId(userWalletMap.get(fofoOrder.getFofoId()));
1077
				uwh.setFofoId(fofoOrder.getFofoId());
1078
				uwh.setStoreCode(fofoOrder.getInvoiceNumber().split("/")[0]);
1079
				userWalletHistory.add(uwh);
1080
			}
24590 amit.gupta 1081
		});
24598 amit.gupta 1082
 
24592 amit.gupta 1083
		ByteArrayOutputStream baos = FileUtil.getCSVByteStream(
24681 amit.gupta 1084
				Arrays.asList("Wallet Id", "Store Code", "Reference Type", "Reference", "Amount", "Description",
24615 amit.gupta 1085
						"Timestamp"),
1086
				userWalletHistory.stream()
1087
						.map(x -> Arrays.asList(x.getWalletId(), x.getStoreCode(), x.getReferenceType(),
1088
								x.getReference(), x.getAmount(), x.getDescription(), x.getTimestamp()))
24592 amit.gupta 1089
						.collect(Collectors.toList()));
1090
 
1091
		ByteArrayOutputStream baosOuts = FileUtil.getCSVByteStream(
1092
				Arrays.asList("Scheme ID", "SchemeType", "Store Code", "Serial Number", "Amount", "Created",
1093
						"Rolledback"),
1094
				rolledbackSios.stream()
1095
						.map(x -> Arrays.asList(x.getSchemeId(), x.getSchemeType(), x.getStoreCode(),
1096
								x.getSerialNumber(), x.getAmount(), x.getCreateTimestamp(), x.getRolledBackTimestamp()))
1097
						.collect(Collectors.toList()));
1098
 
25043 amit.gupta 1099
		Utils.sendMailWithAttachments(googleMailSender, new String[] { "amit.gupta@shop2020.in" }, null,
24681 amit.gupta 1100
				"Partner Excess Amount Scheme Out", "PFA",
24598 amit.gupta 1101
				new Attachment[] { new Attachment("WalletSummary.csv", new ByteArrayResource(baos.toByteArray())),
1102
						new Attachment("SchemeOutRolledback.csv", new ByteArrayResource(baosOuts.toByteArray())) });
24631 amit.gupta 1103
 
25267 amit.gupta 1104
		throw new Exception();
24590 amit.gupta 1105
	}
24615 amit.gupta 1106
 
24611 amit.gupta 1107
	public void dryRunSchemeOutReco1() throws Exception {
24615 amit.gupta 1108
		List<Integer> references = Arrays.asList(6744, 7347, 8320, 8891, 9124, 9217, 9263, 9379);
24611 amit.gupta 1109
		List<UserWalletHistory> userWalletHistory = new ArrayList<>();
1110
		List<SchemeInOut> rolledbackSios = new ArrayList<>();
1111
		Map<Integer, Integer> userWalletMap = userWalletRepository.selectAll().stream()
1112
				.collect(Collectors.toMap(UserWallet::getUserId, UserWallet::getId));
1113
		Map<Integer, SchemeType> schemeTypeMap = schemeRepository.selectAll().stream()
1114
				.collect(Collectors.toMap(Scheme::getId, Scheme::getType));
1115
		references.stream().forEach(reference -> {
1116
			FofoOrder fofoOrder = null;
1117
			try {
1118
				fofoOrder = fofoOrderRepository.selectByOrderId(reference);
24615 amit.gupta 1119
			} catch (Exception e) {
1120
 
24611 amit.gupta 1121
			}
1122
			String description = "Adjustment of Duplicate Scheme for Sale Invoice " + fofoOrder.getInvoiceNumber();
1123
			Map<Integer, String> inventorySerialNumberMap = new HashMap<>();
1124
			float amountToRollback = 0;
1125
			List<FofoOrderItem> orderItems = fofoOrderItemRepository.selectByOrderId(fofoOrder.getId());
1126
			orderItems.forEach(x -> {
1127
				inventorySerialNumberMap.putAll(x.getFofoLineItems().stream().filter(li -> li.getSerialNumber() != null)
1128
						.collect(Collectors.toMap(FofoLineItem::getInventoryItemId, FofoLineItem::getSerialNumber)));
1129
			});
1130
			if (inventorySerialNumberMap.size() > 0) {
24615 amit.gupta 1131
				List<SchemeInOut> sios = schemeInOutRepository
1132
						.selectByInventoryItemIds(inventorySerialNumberMap.keySet()).stream()
1133
						.filter(x -> schemeTypeMap.get(x.getSchemeId()).equals(SchemeType.OUT))
24611 amit.gupta 1134
						.collect(Collectors.toList());
1135
				LOGGER.info("Found {} duplicate schemeouts for Orderid {}", sios.size(), fofoOrder.getId());
1136
				UserWalletHistory uwh = new UserWalletHistory();
24615 amit.gupta 1137
				Map<Integer, List<SchemeInOut>> inventoryIdSouts = sios.stream()
1138
						.collect(Collectors.groupingBy(SchemeInOut::getInventoryItemId, Collectors.toList()));
24611 amit.gupta 1139
				for (Map.Entry<Integer, List<SchemeInOut>> inventorySioEntry : inventoryIdSouts.entrySet()) {
1140
					List<SchemeInOut> outList = inventorySioEntry.getValue();
24615 amit.gupta 1141
					if (outList.size() > 1) {
1142
 
24611 amit.gupta 1143
					}
1144
				}
1145
				uwh.setAmount(Math.round(amountToRollback));
1146
				uwh.setDescription(description);
1147
				uwh.setTimestamp(LocalDateTime.now());
1148
				uwh.setReferenceType(WalletReferenceType.SCHEME_OUT);
1149
				uwh.setReference(fofoOrder.getId());
1150
				uwh.setWalletId(userWalletMap.get(fofoOrder.getFofoId()));
1151
				uwh.setFofoId(fofoOrder.getFofoId());
1152
				uwh.setStoreCode(fofoOrder.getInvoiceNumber().split("/")[0]);
1153
				userWalletHistory.add(uwh);
1154
			}
1155
		});
24615 amit.gupta 1156
 
24611 amit.gupta 1157
		ByteArrayOutputStream baos = FileUtil.getCSVByteStream(
1158
				Arrays.asList("User Id", "Reference Type", "Reference", "Amount", "Description", "Timestamp"),
1159
				userWalletHistory.stream().map(x -> Arrays.asList(x.getWalletId(), x.getReferenceType(),
1160
						x.getReference(), x.getAmount(), x.getDescription(), x.getTimestamp()))
24615 amit.gupta 1161
						.collect(Collectors.toList()));
1162
 
24611 amit.gupta 1163
		ByteArrayOutputStream baosOuts = FileUtil.getCSVByteStream(
1164
				Arrays.asList("Scheme ID", "SchemeType", "Store Code", "Serial Number", "Amount", "Created",
1165
						"Rolledback"),
1166
				rolledbackSios.stream()
24615 amit.gupta 1167
						.map(x -> Arrays.asList(x.getSchemeId(), x.getSchemeType(), x.getStoreCode(),
1168
								x.getSerialNumber(), x.getAmount(), x.getCreateTimestamp(), x.getRolledBackTimestamp()))
1169
						.collect(Collectors.toList()));
1170
 
24623 amit.gupta 1171
		Utils.sendMailWithAttachments(googleMailSender,
1172
				new String[] { "amit.gupta@shop2020.in", "neeraj.gupta@smartdukaan.com" }, null,
24611 amit.gupta 1173
				"Partner Excess Amount", "PFA",
1174
				new Attachment[] { new Attachment("WalletSummary.csv", new ByteArrayResource(baos.toByteArray())),
1175
						new Attachment("SchemeOutRolledback.csv", new ByteArrayResource(baosOuts.toByteArray())) });
24631 amit.gupta 1176
 
24628 amit.gupta 1177
		throw new Exception();
24615 amit.gupta 1178
 
24611 amit.gupta 1179
	}
24615 amit.gupta 1180
 
24855 amit.gupta 1181
	public void sendDailySalesReportNotificationToPartner(Integer fofoIdInt)
24653 govind 1182
			throws ProfitMandiBusinessException, MessagingException, IOException {
1183
		LocalDateTime now = LocalDateTime.now();
1184
		LocalDateTime from = LocalDateTime.of(now.getYear(), now.getMonth(), now.getDayOfMonth(), 00, 00);
1185
		Map<Integer, Double> salesByFofoIdMap = new HashMap<>();
24855 amit.gupta 1186
		List<Integer> fofoIds = null;
25043 amit.gupta 1187
		if (fofoIdInt == null) {
1188
			fofoIds = fofoStoreRepository.selectAll().stream().filter(x -> x.isActive()).map(x -> x.getId())
1189
					.collect(Collectors.toList());
24856 amit.gupta 1190
		} else {
24855 amit.gupta 1191
			fofoIds = Arrays.asList(fofoIdInt);
1192
		}
24653 govind 1193
		List<PartnerTargetDetails> partnerTargetDetails = partnerTargetRepository
1194
				.selectAllGeEqAndLeEqStartDateAndEndDate(now);
24683 amit.gupta 1195
		DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("h a");
1196
 
1197
		Map<Integer, Float> dailyTarget = new HashMap<>();
24653 govind 1198
		for (Integer fofoId : fofoIds) {
24683 amit.gupta 1199
			Map<Integer, Float> dailyAverageSale = null;
24653 govind 1200
			double sale = fofoOrderRepository.selectTotalSaleSumByFofoIdBrtweenDate(fofoId, from, now);
1201
			for (PartnerTargetDetails partnerTargetDetail : partnerTargetDetails) {
1202
				Map<Integer, Float> targetValues = targetService.getTargetValueByFofoIdAndTargetId(fofoId,
1203
						partnerTargetDetail.getId());
1204
				if (targetValues.size() == 0) {
1205
					continue;
1206
				} else {
1207
					List<Integer> partnerIds = new ArrayList<>();
1208
					partnerIds.add(fofoId);
1209
					dailyAverageSale = targetService.getDailyAverageSaleForCurrentForSingleFofoIdAndBrand(partnerIds,
1210
							targetValues, partnerTargetDetail.getStartDate(), partnerTargetDetail.getEndDate(),
1211
							partnerTargetDetail.getBrandName());
1212
					dailyTarget.put(fofoId, dailyAverageSale.get(fofoId));
1213
					break;
1214
				}
1215
			}
1216
			NotificationCampaigns notification = new NotificationCampaigns();
24847 amit.gupta 1217
			notification.setName("Daily Sales");
1218
			notification.setTitle("Daily Sale Update");
24683 amit.gupta 1219
			if (dailyAverageSale != null && dailyAverageSale.get(fofoId) != null) {
24864 amit.gupta 1220
				notification.setMessage(String.format("Rs.%.0f till %s. Today's Target is Rs.%.0f", sale,
24847 amit.gupta 1221
						now.format(timeFormatter), dailyAverageSale.get(fofoId)));
24683 amit.gupta 1222
			} else {
25043 amit.gupta 1223
				notification.setMessage(String.format("Rs.%.0f till %s", sale, now.format(timeFormatter)));
24653 govind 1224
			}
24683 amit.gupta 1225
			// notification.setMessage("Your sale is "+salesbyfofoId.get(fofoId));
24989 tejbeer 1226
			notification.setType("url");
24863 govind 1227
			notification.setUrl("http://app.profitmandi.com/pages/home/notifications");
24683 amit.gupta 1228
			LOGGER.info("UserID" + userAccountRepository.selectUserIdByRetailerId(fofoId));
1229
			notification.setSql("SELECT distinct d1.user_id from devices d1 left join devices d2 on"
1230
					+ "(d1.imeinumber = d2.imeinumber and d1.created < d2.created) "
1231
					+ " where d2.id is null and d1.user_id = "
1232
					+ userAccountRepository.selectUserIdByRetailerId(fofoId));
24676 govind 1233
			LOGGER.info("SELECT distinct d1.user_id from devices d1 left join devices d2 on"
24683 amit.gupta 1234
					+ "(d1.imeinumber = d2.imeinumber and d1.created < d2.created) "
1235
					+ " where d2.id is null and d1.user_id = "
1236
					+ userAccountRepository.selectUserIdByRetailerId(fofoId));
24667 govind 1237
			notification.setExpiresat(LocalDateTime.now().plusDays(1).toEpochSecond(ZoneOffset.UTC) * 1000);
24653 govind 1238
			notification.setStatus("active");
1239
			notification.setSmsprocessed(0);
1240
			notification.setNotification_processed(0);
1241
			notification.setNotification_type("GENERAL_NOTIFICATION");
24657 govind 1242
			mongoClient.persistNotificationCmpInfo(notification);
24653 govind 1243
			salesByFofoIdMap.put(fofoId, sale);
1244
			LOGGER.info(sale);
1245
		}
24683 amit.gupta 1246
		String saleReport = this.getDailySalesReportByPartnerId(salesByFofoIdMap, dailyTarget);
24653 govind 1247
		LOGGER.info(saleReport);
1248
		String cc[] = { "Tarun.verma@smartdukaan.com", "Kamini.sharma@smartdukaan.com",
24697 amit.gupta 1249
				"chaitnaya.vats@smartdukaan.com", "adeel.yazdani@smartdukaan.com", "mohinder.mutreja@smartdukaan.com" };
24653 govind 1250
		String subject = "sale report till" + " " + now.format(timeFormatter);
24677 govind 1251
		this.sendMailOfHtmlFomat("amod.sen@smartdukaan.com", saleReport, cc, subject);
24653 govind 1252
	}
1253
 
24683 amit.gupta 1254
	public String getDailySalesReportByPartnerId(Map<Integer, Double> salesByFofoIdMap, Map<Integer, Float> dailyTarget)
24653 govind 1255
			throws ProfitMandiBusinessException {
1256
		StringBuilder sb = new StringBuilder();
1257
		sb.append("<html><body><p>Sale Report:</p><br/><table style='border:1px solid black ;padding: 5px';>");
1258
		sb.append("<tbody>\n" + "	    				<tr>\n"
1259
				+ "	    					<th style='border:1px solid black;padding: 5px'>Partner</th>\n"
1260
				+ "	    					<th style='border:1px solid black;padding: 5px'>Daily Target</th>\n"
1261
				+ "	    					<th style='border:1px solid black;padding: 5px'>Sale</th>\n"
1262
				+ "	    				</tr>");
1263
		for (Integer fofoId : salesByFofoIdMap.keySet()) {
25043 amit.gupta 1264
			try {
1265
				String PartnerName = retailerService.getFofoRetailer(fofoId).getBusinessName();
1266
				sb.append("<tr>");
1267
				sb.append("<td style='border:1px solid black;padding: 5px'>" + PartnerName + "</td>");
1268
				if (dailyTarget != null && dailyTarget.get(fofoId) != null) {
1269
					sb.append("<td style='border:1px solid black;padding: 5px'>" + dailyTarget.get(fofoId) + "</td>");
1270
				} else {
1271
					sb.append("<td style='border:1px solid black;padding: 5px'>" + 0.0 + "</td>");
1272
				}
1273
				sb.append("<td style='border:1px solid black;padding: 5px'>" + salesByFofoIdMap.get(fofoId) + "</td>");
24653 govind 1274
 
25043 amit.gupta 1275
				sb.append("</tr>");
1276
			} catch (Exception e) {
24842 govind 1277
				e.printStackTrace();
1278
			}
25043 amit.gupta 1279
 
24653 govind 1280
		}
24683 amit.gupta 1281
 
24653 govind 1282
		sb.append("</tbody></table></body></html>");
1283
		return sb.toString();
1284
	}
24841 govind 1285
 
1286
	private void sendMailOfHtmlFomat(String email, String body, String cc[], String subject)
1287
			throws MessagingException, ProfitMandiBusinessException, IOException {
1288
		MimeMessage message = mailSender.createMimeMessage();
1289
		MimeMessageHelper helper = new MimeMessageHelper(message);
1290
		helper.setSubject(subject);
1291
		helper.setText(body, true);
1292
		helper.setTo(email);
1293
		if (cc != null) {
1294
			helper.setCc(cc);
1295
		}
1296
		InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "Smart Dukaan");
1297
		helper.setFrom(senderAddress);
1298
		mailSender.send(message);
1299
	}
25300 tejbeer 1300
 
1301
	public void sendNotification() throws IOException {
1302
		List<PushNotifications> pushNotifications = pushNotificationRepository.selectAllByTimestamp();
1303
		if (!pushNotifications.isEmpty()) {
1304
			for (PushNotifications pushNotification : pushNotifications) {
1305
				Device devices = deviceRepository.selectById(pushNotification.getDeviceId());
1306
				NotificationCampaign notificationCampaign = notificationCampaignRepository
1307
						.selectById(pushNotification.getNotificationCampaignid());
1308
				Gson gson = new GsonBuilder().setPrettyPrinting().serializeNulls()
1309
						.registerTypeAdapter(LocalDateTime.class, new LocalDateTimeJsonConverter()).create();
1310
 
1311
				SimpleCampaignParams scp = gson.fromJson(notificationCampaign.getImplementationParams(),
1312
						SimpleCampaignParams.class);
1313
				Campaign campaign = new SimpleCampaign(scp);
1314
				String result_url = campaign.getUrl() + "&user_id=" + devices.getUser_id();
1315
				JSONObject json = new JSONObject();
1316
				json.put("to", devices.getFcmId());
1317
				JSONObject jsonObj = new JSONObject();
1318
				jsonObj.put("message", campaign.getMessage());
1319
				jsonObj.put("title", campaign.getTitle());
1320
				jsonObj.put("type", campaign.getType());
1321
				jsonObj.put("url", result_url);
1322
				jsonObj.put("time_to_live", campaign.getExpireTimestamp());
1323
				jsonObj.put("image", campaign.getImageUrl());
1324
				jsonObj.put("largeIcon", "large_icon");
1325
				jsonObj.put("smallIcon", "small_icon");
1326
				jsonObj.put("vibrate", 1);
1327
				jsonObj.put("pid", pushNotification.getId());
1328
				jsonObj.put("sound", 1);
1329
				jsonObj.put("priority", "high");
1330
				json.put("data", jsonObj);
1331
 
1332
				CloseableHttpClient client = HttpClients.createDefault();
1333
				HttpPost httpPost = new HttpPost(FCM_URL);
1334
 
1335
				httpPost.setHeader("Content-Type", "application/json; utf-8");
1336
				httpPost.setHeader("authorization", "key=" + FCM_API_KEY);
1337
				StringEntity entity = new StringEntity(json.toString());
1338
				httpPost.setEntity(entity);
1339
				CloseableHttpResponse response = client.execute(httpPost);
1340
				LOGGER.info("response" + response);
1341
 
1342
				if (response.getStatusLine().getStatusCode() == 200) {
1343
 
1344
					pushNotification.setSentTimestamp(LocalDateTime.now());
1345
				}
1346
 
1347
				else {
1348
 
1349
					LOGGER.info("message" + "not sent");
1350
				}
1351
 
1352
			}
1353
		}
1354
	}
1355
 
25312 amit.gupta 1356
	public static final Map<String, String> nameEmail = new HashMap<>();
1357
 
1358
	public static final Map<String, List<String>> storeManagerMap = new HashMap<>();
1359
 
1360
	static {
1361
		nameEmail.put("Amod", "amod.sen@smartdukaan.com");
1362
		nameEmail.put("Pramod", "pk957415@gmail.com");
1363
		nameEmail.put("Anis", "md.anis@smartdukaan.com");
1364
		nameEmail.put("Manoj", "mspatwal545@gmail.com");
1365
		nameEmail.put("Adeel", "adeel.yazdani@smartdukaan.com");
1366
		nameEmail.put("Mohinder", "mohinder.mutreja@smartdukaan.coms");
1367
		nameEmail.put("Dharmendar", "dharmender.verma@smartdukaan.com");
1368
		nameEmail.put("Rajat", "rajat.gupta@smartdukaan.com");
1369
		nameEmail.put("Ankit", "ankit.bhatia@smartdukaan.com");
1370
		nameEmail.put("Rajit", "rajit.alag@smartdukaan.com");
1371
		nameEmail.put("Gulshan", "gul9711251125@gmail.com");
1372
		nameEmail.put("PramodSharma", "prmdretail@gmail.com");
1373
		// nameEmail.put("Gulshan","");
1374
		storeManagerMap.put("themobileplanet03@gmail.com", Arrays.asList("Amod", "", "Adeel"));
1375
		storeManagerMap.put("mobileplanet7599@gmail.com", Arrays.asList("Pramod", "Dharmendar", "Mohinder"));
1376
		storeManagerMap.put("robintelecom.snp@gmail.com", Arrays.asList("Pramod", "Dharmendar", "Mohinder"));
1377
		storeManagerMap.put("smartconnect4141@gmail.com", Arrays.asList("Amod", "", "Adeel"));
1378
		storeManagerMap.put("bhimsain919@gmail.com", Arrays.asList("Pramod", "Dharmendar", "Mohinder"));
1379
		storeManagerMap.put("babitaranirk@gmail.com", Arrays.asList("Pramod", "", "Mohinder"));
1380
		storeManagerMap.put("dharmendery079@gmail.com", Arrays.asList("Manoj", "", "Adeel"));
1381
		storeManagerMap.put("kkv.enterprises1@gmail.com", Arrays.asList("Pramod", "", "Mohinder"));
1382
		storeManagerMap.put("gulshersaifi74226@gmail.com", Arrays.asList("Amod", "", "Adeel"));
1383
		storeManagerMap.put("deepak.lalwani1985@gmail.com", Arrays.asList("Manoj", "", "Adeel"));
1384
		storeManagerMap.put("gupta.smartdukaan@gmail.com", Arrays.asList("Amod", "", "Adeel"));
1385
		storeManagerMap.put("sachinindri2006@gmail.com", Arrays.asList("Pramod", "Dharmendar", "Mohinder"));
1386
		storeManagerMap.put("kambojanil83@gmail.com", Arrays.asList("Pramod", "", "Mohinder"));
1387
		storeManagerMap.put("uppal.neeraj82@gmail.com", Arrays.asList("", "Ankit", "Mohinder"));
1388
		storeManagerMap.put("thefonehousekarnal@gmail.com", Arrays.asList("Pramod", "Dharmendar", "Mohinder"));
1389
		storeManagerMap.put("richa9910763006@gmail.com", Arrays.asList("Manoj", "", "Adeel"));
1390
		storeManagerMap.put("smartdukangzb@gmail.com", Arrays.asList("Manoj", "", "Adeel"));
1391
		storeManagerMap.put("lovelymobile183@gmail.com", Arrays.asList("Manoj", "", "Adeel"));
1392
		storeManagerMap.put("smartdukaan.sonepat@gmail.com", Arrays.asList("Pramod", "Dharmendar", "Mohinder"));
1393
		storeManagerMap.put("arunmittal299@gmail.com", Arrays.asList("Pramod", "Dharmendar", "Mohinder"));
1394
		storeManagerMap.put("gtc01100@gmail.com", Arrays.asList("Pramod", "Dharmendar", "Mohinder"));
1395
		storeManagerMap.put("sumittyagi1975@gmail.com", Arrays.asList("Manoj", "", "Adeel"));
1396
		storeManagerMap.put("metrofurniture342@gmail.com", Arrays.asList("Pramod", "Dharmendar", "Mohinder"));
1397
		storeManagerMap.put("suryaelectronicskaithal@gmail.com", Arrays.asList("Pramod", "", "Mohinder"));
1398
		storeManagerMap.put("mmtelecomsec16@gmail.com", Arrays.asList("Amod", "", "Adeel"));
1399
		storeManagerMap.put("omsonsindia08@gmail.com", Arrays.asList("Pramod", "Dharmendar", "Mohinder"));
1400
		storeManagerMap.put("smartenterprisespv@gmail.com", Arrays.asList("Amod", "", "Adeel"));
1401
		storeManagerMap.put("cachaitnya@gmail.com", Arrays.asList("Amod", "", "Adeel"));
1402
		storeManagerMap.put("ajaykumarkansal03@gmail.com", Arrays.asList("Manoj", "", "Adeel"));
1403
		storeManagerMap.put("spurwar73@gmail.com", Arrays.asList("Anis", "Rajat", "Adeel"));
1404
		storeManagerMap.put("Shreemobile.ind@gmail.com", Arrays.asList("Anis", "Rajat", "Adeel"));
1405
		storeManagerMap.put("felixenterprises2017@rediffmail.com", Arrays.asList("", "Dharmendar", "Mohinder"));
1406
		storeManagerMap.put("nareandergupta@gmail.com", Arrays.asList("", "Dharmendar", "Mohinder"));
1407
		storeManagerMap.put("shreebalajielectronic2019@gmail.com", Arrays.asList("Manoj", "", "Adeel"));
1408
		storeManagerMap.put("saranshary@gmail.com", Arrays.asList("", "Dharmendar", "Mohinder"));
1409
		storeManagerMap.put("gambhirsmartphone@gmail.com", Arrays.asList("", "Gulshan", "Adeel"));
1410
		storeManagerMap.put("Priyankaenterprises9910@gmail.com", Arrays.asList("Manoj", "", "Adeel"));
1411
		storeManagerMap.put("pawan.dhimaan@gmail.com", Arrays.asList("", "Dharmendar", "Mohinder"));
1412
		storeManagerMap.put("lakshaydhulla62@gmail.com", Arrays.asList("Pramod", "Dharmendar", "Mohinder"));
1413
		storeManagerMap.put("parastelecom.stp@gmail.com", Arrays.asList("Anis", "Rajat", "Adeel"));
1414
		storeManagerMap.put("talwarmukesh298@gmail.com", Arrays.asList("Pramod", "Dharmendar", "Mohinder"));
1415
		storeManagerMap.put("sahilnarang0009@gmail.com", Arrays.asList("Pramod", "", "Mohinder"));
1416
		storeManagerMap.put("supertelecomjind@gmail.com", Arrays.asList("", "Ankit", "Mohinder"));
1417
		storeManagerMap.put("saketnagpal@gmail.com", Arrays.asList("", "Rajit", "Mohinder"));
1418
		storeManagerMap.put("DEEPAKGOYAL702.DG@GMAIL.COM", Arrays.asList("", "Ankit", "Mohinder"));
1419
		storeManagerMap.put("sambhav350@gmail.com", Arrays.asList("Pramod", "Dharmendar", "Mohinder"));
1420
		storeManagerMap.put("mayankarora98133@gmail.com", Arrays.asList("", "Ankit", "Mohinder"));
1421
		storeManagerMap.put("vijaymobilityandmoew@gmail.com", Arrays.asList("Manoj", "", "Adeel"));
1422
		storeManagerMap.put("amitv70003@gmail.com", Arrays.asList("", "Ankit", "Mohinder"));
1423
		storeManagerMap.put("newagelucknow.123@gmail.com", Arrays.asList("Anis", "Rajat", "Adeel"));
1424
		storeManagerMap.put("Newagetechnologygomtinagar@gmail.com", Arrays.asList("Anis", "Rajat", "Adeel"));
1425
		storeManagerMap.put("rohitbatra106@gmail.com", Arrays.asList("Pramod", "Dharmendar", "Mohinder"));
1426
		storeManagerMap.put("sonisunil9050873061@gmail.com", Arrays.asList("", "Ankit", "Mohinder"));
1427
		storeManagerMap.put("moderncohsr@gmail.com", Arrays.asList("", "Ankit", "Mohinder"));
1428
		storeManagerMap.put("raghubir.ngh@gmail.com", Arrays.asList("", "Ankit", "Mohinder"));
1429
		storeManagerMap.put("aman007singla@gmail.com", Arrays.asList("", "Rajit", "Mohinder"));
1430
	}
24587 amit.gupta 1431
}