Subversion Repositories SmartDukaan

Rev

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