Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
23755 amit.gupta 1
package com.smartdukaan.cron.migrations;
2
 
24819 amit.gupta 3
import java.io.Serializable;
23824 amit.gupta 4
import java.time.LocalDate;
23755 amit.gupta 5
import java.time.LocalDateTime;
23824 amit.gupta 6
import java.time.LocalTime;
24819 amit.gupta 7
import java.util.ArrayList;
23755 amit.gupta 8
import java.util.Arrays;
23827 amit.gupta 9
import java.util.Collections;
24002 amit.gupta 10
import java.util.HashMap;
24005 amit.gupta 11
import java.util.HashSet;
23755 amit.gupta 12
import java.util.List;
24002 amit.gupta 13
import java.util.Map;
25749 amit.gupta 14
import java.util.Set;
15
import java.util.concurrent.TimeUnit;
24641 amit.gupta 16
import java.util.stream.Collectors;
23755 amit.gupta 17
 
24819 amit.gupta 18
import org.apache.commons.io.output.ByteArrayOutputStream;
23755 amit.gupta 19
import org.apache.commons.lang.StringUtils;
20
import org.apache.logging.log4j.LogManager;
21
import org.apache.logging.log4j.Logger;
25749 amit.gupta 22
import org.openqa.selenium.OutputType;
23
import org.openqa.selenium.TakesScreenshot;
24
import org.openqa.selenium.WebDriver;
25
import org.openqa.selenium.chrome.ChromeDriver;
25752 amit.gupta 26
import org.openqa.selenium.chrome.ChromeOptions;
23755 amit.gupta 27
import org.springframework.beans.factory.annotation.Autowired;
24819 amit.gupta 28
import org.springframework.core.io.ByteArrayResource;
24767 amit.gupta 29
import org.springframework.mail.javamail.JavaMailSender;
23755 amit.gupta 30
import org.springframework.stereotype.Component;
31
import org.springframework.transaction.annotation.Transactional;
32
 
25043 amit.gupta 33
import com.smartdukaan.cron.scheduled.ScheduledTasks;
24819 amit.gupta 34
import com.spice.profitmandi.common.util.FileUtil;
25749 amit.gupta 35
import com.spice.profitmandi.common.util.FormattingUtils;
24819 amit.gupta 36
import com.spice.profitmandi.common.util.Utils;
25021 amit.gupta 37
import com.spice.profitmandi.dao.entity.catalog.Scheme;
24716 amit.gupta 38
import com.spice.profitmandi.dao.entity.fofo.CurrentInventorySnapshot;
24806 amit.gupta 39
import com.spice.profitmandi.dao.entity.fofo.FofoOrder;
40
import com.spice.profitmandi.dao.entity.fofo.FofoOrderItem;
25530 amit.gupta 41
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
24005 amit.gupta 42
import com.spice.profitmandi.dao.entity.fofo.InventoryItem;
24883 amit.gupta 43
import com.spice.profitmandi.dao.entity.fofo.PartnerTargetDetails;
23898 amit.gupta 44
import com.spice.profitmandi.dao.entity.fofo.Purchase;
24716 amit.gupta 45
import com.spice.profitmandi.dao.entity.fofo.ScanRecord;
25034 amit.gupta 46
import com.spice.profitmandi.dao.entity.fofo.SchemeInOut;
25021 amit.gupta 47
import com.spice.profitmandi.dao.entity.fofo.SchemeItem;
24883 amit.gupta 48
import com.spice.profitmandi.dao.entity.fofo.TargetSlab;
24953 amit.gupta 49
import com.spice.profitmandi.dao.entity.inventory.SaholicInventorySnapshot;
23824 amit.gupta 50
import com.spice.profitmandi.dao.entity.transaction.LineItem;
23755 amit.gupta 51
import com.spice.profitmandi.dao.entity.transaction.LineItemImei;
52
import com.spice.profitmandi.dao.entity.transaction.Order;
24802 amit.gupta 53
import com.spice.profitmandi.dao.entity.transaction.SellerWarehouse;
25046 amit.gupta 54
import com.spice.profitmandi.dao.entity.transaction.UserWallet;
25034 amit.gupta 55
import com.spice.profitmandi.dao.entity.transaction.UserWalletHistory;
25530 amit.gupta 56
import com.spice.profitmandi.dao.entity.user.Address;
57
import com.spice.profitmandi.dao.entity.user.User;
25021 amit.gupta 58
import com.spice.profitmandi.dao.enumuration.catalog.AmountType;
25522 amit.gupta 59
import com.spice.profitmandi.dao.enumuration.catalog.SchemeType;
24716 amit.gupta 60
import com.spice.profitmandi.dao.repository.GenericRepository;
25034 amit.gupta 61
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
25021 amit.gupta 62
import com.spice.profitmandi.dao.repository.catalog.SchemeRepository;
25749 amit.gupta 63
import com.spice.profitmandi.dao.repository.cs.CsService;
23899 amit.gupta 64
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
24716 amit.gupta 65
import com.spice.profitmandi.dao.repository.fofo.CurrentInventorySnapshotRepository;
24002 amit.gupta 66
import com.spice.profitmandi.dao.repository.fofo.DebitNoteRepository;
24806 amit.gupta 67
import com.spice.profitmandi.dao.repository.fofo.FofoOrderItemRepository;
68
import com.spice.profitmandi.dao.repository.fofo.FofoOrderRepository;
24002 amit.gupta 69
import com.spice.profitmandi.dao.repository.fofo.InventoryItemRepository;
24806 amit.gupta 70
import com.spice.profitmandi.dao.repository.fofo.InvoiceNumberGenerationSequenceRepository;
24883 amit.gupta 71
import com.spice.profitmandi.dao.repository.fofo.PartnerTargetRepository;
23898 amit.gupta 72
import com.spice.profitmandi.dao.repository.fofo.PurchaseRepository;
24716 amit.gupta 73
import com.spice.profitmandi.dao.repository.fofo.ScanRecordRepository;
24002 amit.gupta 74
import com.spice.profitmandi.dao.repository.fofo.SchemeInOutRepository;
25021 amit.gupta 75
import com.spice.profitmandi.dao.repository.fofo.SchemeItemRepository;
24883 amit.gupta 76
import com.spice.profitmandi.dao.repository.fofo.TargetSlabRepository;
77
import com.spice.profitmandi.dao.repository.fofo.TargetSlabRepositoryImpl;
24953 amit.gupta 78
import com.spice.profitmandi.dao.repository.inventory.SaholicInventorySnapshotRepository;
79
import com.spice.profitmandi.dao.repository.inventory.SaholicReservationInventorySnapshotRepository;
23755 amit.gupta 80
import com.spice.profitmandi.dao.repository.transaction.LineItemImeisRepository;
23824 amit.gupta 81
import com.spice.profitmandi.dao.repository.transaction.LineItemRepository;
23755 amit.gupta 82
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
24772 amit.gupta 83
import com.spice.profitmandi.dao.repository.transaction.ReturnOrderRepository;
24802 amit.gupta 84
import com.spice.profitmandi.dao.repository.transaction.SellerWarehouseRepository;
24767 amit.gupta 85
import com.spice.profitmandi.dao.repository.transaction.UserWalletHistoryRepository;
86
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
25530 amit.gupta 87
import com.spice.profitmandi.dao.repository.user.AddressRepository;
24002 amit.gupta 88
import com.spice.profitmandi.dao.repository.user.UserRepository;
23899 amit.gupta 89
import com.spice.profitmandi.service.inventory.InventoryService;
24266 amit.gupta 90
import com.spice.profitmandi.service.order.OrderService;
24005 amit.gupta 91
import com.spice.profitmandi.service.pricing.PriceDropService;
92
import com.spice.profitmandi.service.scheme.SchemeService;
23899 amit.gupta 93
import com.spice.profitmandi.service.transaction.TransactionService;
94
import com.spice.profitmandi.service.user.RetailerService;
95
import com.spice.profitmandi.service.wallet.WalletService;
23755 amit.gupta 96
 
24953 amit.gupta 97
import in.shop2020.model.v1.order.OrderStatus;
24002 amit.gupta 98
import in.shop2020.model.v1.order.WalletReferenceType;
99
 
23755 amit.gupta 100
@Component
101
@Transactional(rollbackFor = Throwable.class)
102
public class RunOnceTasks {
103
 
104
	private static final Logger LOGGER = LogManager.getLogger(RunOnceTasks.class);
105
 
106
	@Autowired
23824 amit.gupta 107
	private LineItemRepository lineItemRepository;
24711 amit.gupta 108
 
23905 amit.gupta 109
	@Autowired
24953 amit.gupta 110
	private SaholicInventorySnapshotRepository saholicInventorySnapshotRepository;
25752 amit.gupta 111
 
25749 amit.gupta 112
	@Autowired
113
	private CsService csService;
24953 amit.gupta 114
 
115
	@Autowired
116
	private SaholicReservationInventorySnapshotRepository saholicReservationInventorySnapshotRepository;
117
 
118
	@Autowired
24883 amit.gupta 119
	private TargetSlabRepository targetSlabRepository;
120
 
121
	@Autowired
122
	private PartnerTargetRepository partnerTargetRepository;
123
 
124
	@Autowired
24802 amit.gupta 125
	private SellerWarehouseRepository sellerWarehouseRepository;
24814 amit.gupta 126
 
24802 amit.gupta 127
	@Autowired
24806 amit.gupta 128
	private FofoOrderItemRepository fofoOrderItemRepository;
24814 amit.gupta 129
 
24806 amit.gupta 130
	@Autowired
131
	private FofoOrderRepository fofoOrderRepository;
24814 amit.gupta 132
 
24806 amit.gupta 133
	@Autowired
24767 amit.gupta 134
	private UserWalletRepository userWalletRepository;
135
 
136
	@Autowired
137
	private UserWalletHistoryRepository userWalletHistoryRepository;
138
 
139
	@Autowired
24002 amit.gupta 140
	private UserRepository userRepository;
24711 amit.gupta 141
 
24002 amit.gupta 142
	@Autowired
23899 amit.gupta 143
	private WalletService walletService;
144
 
145
	@Autowired
25034 amit.gupta 146
	private ItemRepository itemRepository;
147
 
148
	@Autowired
23899 amit.gupta 149
	private InventoryService inventoryService;
150
 
151
	@Autowired
152
	private TransactionService transactionService;
153
 
24711 amit.gupta 154
	// Service for Tertiary/Partner Orders
24266 amit.gupta 155
	@Autowired
156
	private OrderService orderService;
23767 amit.gupta 157
 
23755 amit.gupta 158
	@Autowired
25021 amit.gupta 159
	private SchemeRepository schemeRepository;
25516 amit.gupta 160
 
25043 amit.gupta 161
	@Autowired
25530 amit.gupta 162
	private AddressRepository addressRepository;
25749 amit.gupta 163
 
25530 amit.gupta 164
	@Autowired
25043 amit.gupta 165
	private ScheduledTasks scheduledTasks;
25034 amit.gupta 166
 
25021 amit.gupta 167
	@Autowired
168
	private SchemeItemRepository schemeItemRepository;
169
 
170
	@Autowired
24772 amit.gupta 171
	private ReturnOrderRepository returnOrderRepository;
172
 
173
	@Autowired
23899 amit.gupta 174
	private FofoStoreRepository fofoStoreRepository;
175
 
176
	@Autowired
23755 amit.gupta 177
	private LineItemImeisRepository lineItemImeisRepository;
24711 amit.gupta 178
 
24002 amit.gupta 179
	@Autowired
180
	private InventoryItemRepository inventoryItemRepository;
24814 amit.gupta 181
 
24806 amit.gupta 182
	@Autowired
183
	private InvoiceNumberGenerationSequenceRepository invoiceNumberGenerationSequenceRepository;
23901 amit.gupta 184
 
23898 amit.gupta 185
	@Autowired
23899 amit.gupta 186
	private RetailerService retailerService;
24711 amit.gupta 187
 
24002 amit.gupta 188
	@Autowired
189
	private SchemeInOutRepository schemeInOutRepository;
24711 amit.gupta 190
 
24002 amit.gupta 191
	@Autowired
192
	private DebitNoteRepository debitNoteRepository;
23899 amit.gupta 193
 
194
	@Autowired
24716 amit.gupta 195
	private GenericRepository genericRepository;
196
 
197
	@Autowired
23898 amit.gupta 198
	private PurchaseRepository purchaseRepository;
24711 amit.gupta 199
 
24005 amit.gupta 200
	@Autowired
201
	private PriceDropService priceDropService;
24883 amit.gupta 202
 
24819 amit.gupta 203
	@Autowired
204
	private JavaMailSender googleMailSender;
24711 amit.gupta 205
 
24005 amit.gupta 206
	@Autowired
207
	private SchemeService schemeService;
24711 amit.gupta 208
 
24716 amit.gupta 209
	@Autowired
210
	private CurrentInventorySnapshotRepository currentInventorySnapshotRepository;
211
 
212
	@Autowired
24767 amit.gupta 213
	private OrderRepository orderRepository;
214
 
215
	@Autowired
24716 amit.gupta 216
	private ScanRecordRepository scanRecordRepository;
217
 
24767 amit.gupta 218
	@Autowired
219
	private JavaMailSender mailSender;
220
 
24005 amit.gupta 221
	public void dropCorrection() throws Exception {
222
 
24711 amit.gupta 223
		walletService.rollbackAmountFromWallet(175128034, 274, 4, WalletReferenceType.PRICE_DROP,
224
				"Scheme  differential for Price Drop of Rs.712 on Samsung J6 J600GG, on 01-08-2018 for missing 1pc");
225
		walletService.rollbackAmountFromWallet(175128034, -259, 4, WalletReferenceType.PRICE_DROP,
226
				"Scheme  differential for Price Drop of Rs.712 on Samsung J6 J600GG, on 01-08-2018 for missing 1pc");
227
		List<InventoryItem> iis = inventoryItemRepository.selectByIds(new HashSet<>(Arrays.asList(3518, 3516)));
228
		schemeService.reverseSchemes(iis, 8,
229
				"Scheme  differential for Price Drop of Rs.712 on Samsung J6 J600GG, on 01-08-2018. Total 2 item(s)");
230
		List<InventoryItem> iis1 = inventoryItemRepository.selectByIds(new HashSet<>(Arrays.asList(3502, 3334, 3503)));
231
		schemeService.reverseSchemes(iis1, 13,
232
				"Scheme  differential for Price Drop of Rs.485 on Samsung Galaxy J4 J400FD, on 18-07-2018. Total 3 item(s)");
233
 
234
		List<InventoryItem> iis2 = inventoryItemRepository.selectByIds(new HashSet<>(Arrays.asList(3319)));
235
		schemeService.reverseSchemes(iis2, 13,
236
				"Scheme  differential for Price Drop of Rs.485 on Samsung Galaxy J4 J400FD, on 18-07-2018. Total 1 item(s)");
24005 amit.gupta 237
	}
24711 amit.gupta 238
 
25268 amit.gupta 239
	public void schemeRollback() throws Exception {
24002 amit.gupta 240
		Map<Integer, Float> fofoIdAmount = new HashMap<>();
24003 amit.gupta 241
		fofoIdAmount.put(175135218, 1942f);
242
		String description = "Price drop/differential rolled out as, they were already returned, Total 2pcs.";
24711 amit.gupta 243
		for (Map.Entry<Integer, Float> fofoIdAmountEntry : fofoIdAmount.entrySet()) {
244
			Integer fofoId = fofoIdAmountEntry.getKey();
24002 amit.gupta 245
			Float amount = fofoIdAmountEntry.getValue();
24003 amit.gupta 246
			walletService.rollbackAmountFromWallet(fofoId, amount, 4, WalletReferenceType.PRICE_DROP, description);
24002 amit.gupta 247
		}
24004 amit.gupta 248
		fofoIdAmount.put(175135218, 438f);
24711 amit.gupta 249
		for (Map.Entry<Integer, Float> fofoIdAmountEntry : fofoIdAmount.entrySet()) {
250
			Integer fofoId = fofoIdAmountEntry.getKey();
24004 amit.gupta 251
			Float amount = fofoIdAmountEntry.getValue();
252
			walletService.rollbackAmountFromWallet(fofoId, amount, 4, WalletReferenceType.PRICE_DROP, description);
253
		}
24002 amit.gupta 254
	}
23755 amit.gupta 255
 
23898 amit.gupta 256
	public void populateGrnTimestamp() {
257
		List<Purchase> allPurchases = purchaseRepository.selectAll();
23899 amit.gupta 258
		for (Purchase p : allPurchases) {
23898 amit.gupta 259
			String invoiceNumber = p.getPurchaseReference();
23899 amit.gupta 260
			if (p.getCompleteTimestamp() == null) {
23898 amit.gupta 261
				LOGGER.info("GRN for invoice {} is delivered but partially Completed.", p.getPurchaseReference());
262
			} else {
263
				List<Order> orders = orderRepository.selectByAirwayBillOrInvoiceNumber(invoiceNumber, p.getFofoId());
23899 amit.gupta 264
				for (Order order : orders) {
23902 amit.gupta 265
					if (order.getPartnerGrnTimestamp() == null) {
266
						order.setPartnerGrnTimestamp(p.getCompleteTimestamp());
23898 amit.gupta 267
						orderRepository.persist(order);
268
					}
269
				}
270
			}
271
		}
23899 amit.gupta 272
 
23898 amit.gupta 273
	}
23899 amit.gupta 274
 
24716 amit.gupta 275
	public void migarateLineItemsToNewTable() throws Exception {
23755 amit.gupta 276
		LOGGER.info("Before Migrated LineItems Successfully");
23824 amit.gupta 277
		int lineItemImeiId = 0;
278
		LocalDateTime startDate = null;
279
		try {
280
			lineItemImeiId = lineItemImeisRepository.selectMaxId();
23899 amit.gupta 281
			LineItem lineItem = lineItemRepository
282
					.selectById(lineItemImeisRepository.selectById(lineItemImeiId).getLineItemId());
23824 amit.gupta 283
			Order order = orderRepository.selectById(lineItem.getOrderId());
284
			startDate = order.getBillingTimestamp();
285
		} catch (Exception e) {
286
			LOGGER.info("Running before first time");
23826 amit.gupta 287
			startDate = LocalDateTime.of(LocalDate.of(2017, 7, 1), LocalTime.MIDNIGHT);
23824 amit.gupta 288
		}
289
		List<Order> orders = orderRepository.selectAllByBillingDatesBetween(startDate, LocalDateTime.now());
23827 amit.gupta 290
		Collections.reverse(orders);
23899 amit.gupta 291
 
23755 amit.gupta 292
		for (Order order : orders) {
23824 amit.gupta 293
			try {
23767 amit.gupta 294
				String serialNumbers = order.getLineItem().getSerialNumber();
295
				if (!StringUtils.isEmpty(serialNumbers)) {
296
					List<String> serialNumberList = Arrays.asList(serialNumbers.split(","));
297
					for (String serialNumber : serialNumberList) {
298
						int lineItemId = order.getLineItem().getId();
299
						LineItemImei lineItemImei = new LineItemImei();
300
						lineItemImei.setSerialNumber(serialNumber);
301
						lineItemImei.setLineItemId(lineItemId);
302
						lineItemImeisRepository.persist(lineItemImei);
303
					}
304
				} else {
305
					LOGGER.info("Serial Numbers dont exist for Order {}", order.getId());
23755 amit.gupta 306
				}
23824 amit.gupta 307
			} catch (Exception e) {
23899 amit.gupta 308
				LOGGER.info("Error occurred while creating lineitem imei {}, because of {}", order.getId(),
309
						e.getMessage());
23755 amit.gupta 310
			}
311
		}
312
		LOGGER.info("Migrated LineItems Successfully");
313
	}
24266 amit.gupta 314
 
315
	public void cancelOrder(List<String> invoiceNumbers) throws Exception {
316
		orderService.cancelOrder(invoiceNumbers);
317
	}
24711 amit.gupta 318
 
24722 amit.gupta 319
	public void migratePurchase() throws Exception {
24641 amit.gupta 320
		List<Purchase> purchases = purchaseRepository.selectPurchaseAllPurchasesLessThanZero();
24706 amit.gupta 321
		System.out.printf("Total Purchases count is %s", purchases.size());
24711 amit.gupta 322
		for (Purchase purchase : purchases) {
323
			List<InventoryItem> inventoryItems = inventoryItemRepository.selectByPurchaseId(purchase.getId());
324
			Map<Integer, List<InventoryItem>> itemIdInventoryMap = inventoryItems.stream()
325
					.collect(Collectors.groupingBy(InventoryItem::getItemId));
326
			List<Order> orders = orderRepository.selectByAirwayBillOrInvoiceNumber(purchase.getPurchaseReference(),
327
					purchase.getFofoId());
328
			Map<Integer, Integer> ourSaleItemQtyMap = orders.stream().collect(Collectors.groupingBy(
329
					x -> x.getLineItem().getItemId(), Collectors.summingInt(x -> x.getLineItem().getQuantity())));
330
			Map<Integer, Integer> theirPurchaseItemQtyMap = inventoryItems.stream().collect(Collectors
331
					.groupingBy(InventoryItem::getItemId, Collectors.summingInt(InventoryItem::getInitialQuantity)));
24709 amit.gupta 332
			for (Map.Entry<Integer, Integer> itemQtyEntry : theirPurchaseItemQtyMap.entrySet()) {
24711 amit.gupta 333
				if (!ourSaleItemQtyMap.containsKey(itemQtyEntry.getKey())) {
334
					LOGGER.info("Cannot find in Invoice {} item {}", purchase.getPurchaseReference(),
335
							itemQtyEntry.getKey());
24646 amit.gupta 336
					continue;
24645 amit.gupta 337
				}
24709 amit.gupta 338
				int ourSale = ourSaleItemQtyMap.get(itemQtyEntry.getKey());
24713 amit.gupta 339
				int quantityToReduce = itemQtyEntry.getValue() - ourSale;
24716 amit.gupta 340
				List<InventoryItem> itemIis = itemIdInventoryMap.get(itemQtyEntry.getKey());
341
				if (itemIdInventoryMap != null) {
342
					for (InventoryItem ii : itemIis) {
24915 amit.gupta 343
						if (ii.getSerialNumber() == null && ii.getGoodQuantity() == ii.getInitialQuantity()
344
								&& quantityToReduce >= ii.getInitialQuantity()) {
24734 amit.gupta 345
							LOGGER.info("Changed in inventoryItems {}, {}, {}, {}, {}, {}",
24716 amit.gupta 346
									purchase.getPurchaseReference(), ii.getId(), ii.getItemId(),
24734 amit.gupta 347
									ii.getInitialQuantity(), ii.getGoodQuantity(), quantityToReduce);
24912 amit.gupta 348
							List<ScanRecord> scanRecords = scanRecordRepository.selectByInventoryItemId(ii.getId());
349
							for (ScanRecord scanRecord : scanRecords) {
24915 amit.gupta 350
								CurrentInventorySnapshot cis = currentInventorySnapshotRepository
351
										.selectByItemIdAndFofoId(itemQtyEntry.getKey(), purchase.getFofoId());
352
								scanRecord.setQuantity(0);
353
								ii.setGoodQuantity(0);
354
								quantityToReduce = quantityToReduce - ii.getInitialQuantity();
355
								cis.setAvailability(cis.getAvailability() - ii.getInitialQuantity());
356
								purchase.setUnfullfilledNonSerializedQuantity(
357
										purchase.getUnfullfilledNonSerializedQuantity() + quantityToReduce);
358
								LOGGER.info("Rectified {}, {}, {}, {}, {}, {}", purchase.getPurchaseReference(),
359
										ii.getId(), ii.getItemId(), ii.getInitialQuantity(), ii.getGoodQuantity(),
360
										quantityToReduce);
24711 amit.gupta 361
							}
24641 amit.gupta 362
						}
363
					}
364
				}
365
			}
366
		}
24953 amit.gupta 367
		// throw new Exception();
24641 amit.gupta 368
	}
24767 amit.gupta 369
 
24802 amit.gupta 370
	public void migrateChallansToInvoices() throws Exception {
24814 amit.gupta 371
		Map<String, List<Order>> invoiceOrdersMap = orderRepository.selectAllChallans().stream()
372
				.filter(x -> !x.getLineItem().getHsnCode().equals("NOGST"))
24794 amit.gupta 373
				.collect(Collectors.groupingBy(Order::getInvoiceNumber, Collectors.toList()));
24814 amit.gupta 374
 
24819 amit.gupta 375
		List<List<? extends Serializable>> rows = new ArrayList<>();
24814 amit.gupta 376
		for (String invoice : invoiceOrdersMap.keySet()) {
24794 amit.gupta 377
			Order oneOrder = invoiceOrdersMap.get(invoice).get(0);
378
			int totalOrders = invoiceOrdersMap.get(invoice).size();
379
			LineItem lineItem = oneOrder.getLineItem();
24802 amit.gupta 380
			oneOrder.setBillingTimestamp(LocalDateTime.now());
381
			oneOrder.setInvoiceNumber(getInvoiceNumber(oneOrder));
24819 amit.gupta 382
			rows.add(Arrays.asList(oneOrder.getId(), invoice, oneOrder.getInvoiceNumber(), lineItem.getQuantity()));
24883 amit.gupta 383
			LOGGER.info(invoice + "\t" + oneOrder.getInvoiceNumber() + oneOrder.getId() + "\t",
384
					"\t" + totalOrders + "\t" + lineItem.getQuantity());
24814 amit.gupta 385
			Purchase p = null;
386
			try {
387
				p = purchaseRepository.selectByPurchaseReferenceAndFofoId(invoice, oneOrder.getRetailerId());
388
			} catch (Exception e) {
24815 amit.gupta 389
				LOGGER.info("Could not find purchase for invoice {}", invoice);
24812 amit.gupta 390
			}
24814 amit.gupta 391
			if (p != null) {
392
				List<InventoryItem> inventoryItems = inventoryItemRepository.selectByPurchaseId(p.getId());
393
				for (InventoryItem inventoryItem : inventoryItems) {
24815 amit.gupta 394
					LOGGER.info(inventoryItem.getItemId() + " " + inventoryItem.getGoodQuantity() + " "
24883 amit.gupta 395
							+ inventoryItem.getHsnCode() + " " + inventoryItem.getSerialNumber() + " "
396
							+ p.getPurchaseReference());
24814 amit.gupta 397
				}
398
			}
399
 
24794 amit.gupta 400
		}
24818 amit.gupta 401
		changePartnerInvoices();
24883 amit.gupta 402
		ByteArrayOutputStream baos = FileUtil
403
				.getCSVByteStream(Arrays.asList("Order id", "Challan", "Invoice", "Quantity"), rows);
404
 
24819 amit.gupta 405
		Utils.sendMailWithAttachment(googleMailSender,
406
				new String[] { "amit.gupta@shop2020.in", "sunny.yadav@smartdukaan.com" }, null,
24883 amit.gupta 407
				"Challans Converted to Invoice", "PFA", "Challans-To-Invoice.csv",
408
				new ByteArrayResource(baos.toByteArray()));
24916 amit.gupta 409
		throw new Exception();
24794 amit.gupta 410
	}
24767 amit.gupta 411
 
24802 amit.gupta 412
	private String getInvoiceNumber(Order oneOrder) {
24805 amit.gupta 413
		String prefix = oneOrder.getInvoiceNumber().split("-")[1].replaceAll("\\d*", "");
24803 amit.gupta 414
		System.out.println("Prefix is " + prefix);
24802 amit.gupta 415
		SellerWarehouse sellerWarehouse = sellerWarehouseRepository.selectByPrefix(prefix);
416
		int newSequence = sellerWarehouse.getInvoiceSequence() + 1;
417
		sellerWarehouse.setInvoiceSequence(newSequence);
24814 amit.gupta 418
		return prefix + newSequence;
24802 amit.gupta 419
	}
24814 amit.gupta 420
 
24806 amit.gupta 421
	private void changePartnerInvoices() throws Exception {
24814 amit.gupta 422
		List<FofoOrder> fofoOrders = fofoOrderRepository.selectByInvoiceNumberLike("%SEC%");
423
		for (FofoOrder fofoOrder : fofoOrders) {
24806 amit.gupta 424
			FofoOrderItem fofoOrderItem = fofoOrderItemRepository.selectByOrderId(fofoOrder.getId()).get(0);
24814 amit.gupta 425
			if (fofoOrderItem.getBrand().equals("Vivo")) {
24806 amit.gupta 426
				String challanString = fofoOrder.getInvoiceNumber();
24814 amit.gupta 427
				String storeCode = invoiceNumberGenerationSequenceRepository.selectByFofoId(fofoOrder.getFofoId())
428
						.getPrefix();
24806 amit.gupta 429
				String invoiceNumber = orderService.getInvoiceNumber(fofoOrder.getFofoId(), storeCode);
430
				fofoOrder.setInvoiceNumber(invoiceNumber);
431
				fofoOrder.setCreateTimestamp(LocalDateTime.now());
24818 amit.gupta 432
				LOGGER.info(challanString + "\t" + invoiceNumber + "\t" + fofoOrderItem.getQuantity());
24806 amit.gupta 433
			}
24814 amit.gupta 434
 
24806 amit.gupta 435
		}
436
	}
24802 amit.gupta 437
 
24883 amit.gupta 438
	public void createMonthlyTargets() throws Exception {
439
		Map<String, List<TargetSlab>> defaultSlabs = targetSlabRepository.getAllDefaultSlabs();
440
		for (String memberType : defaultSlabs.keySet()) {
441
			PartnerTargetDetails ptd = new PartnerTargetDetails();
442
			ptd.setBrandName(null);
443
 
444
			LocalDate startDate = LocalDate.now().withDayOfMonth(1);
445
			int totalDays = startDate.lengthOfMonth();
446
			String monthName = startDate.getMonth().toString();
447
			ptd.setStartDate(startDate.atStartOfDay());
448
			ptd.setEndDate(startDate.plusDays(totalDays - 1).atTime(LocalTime.MAX));
449
			ptd.setTargetName(String.format("%s Sales Target for %s Partners", monthName, memberType));
450
			partnerTargetRepository.persist(ptd);
451
			TargetSlabRepositoryImpl.TYPE_PARTNER_MAPPING.get(memberType).forEach(x -> {
452
				x.setTargetId(ptd.getId());
453
				partnerTargetRepository.persist(x);
454
			});
455
 
456
			List<TargetSlab> slabs = defaultSlabs.get(memberType);
457
			slabs.stream().forEach(x -> {
458
				x.setTargetId(ptd.getId());
459
				targetSlabRepository.persist(x);
460
			});
461
		}
462
	}
463
 
25023 amit.gupta 464
	public void populateSchemes() {
25021 amit.gupta 465
		List<Integer> list05 = Arrays.asList(29093, 29094, 29095, 29096, 29097, 29098, 29099, 29101, 29102);
466
		List<Integer> list10 = Arrays.asList(29187, 29188);
467
		List<Integer> list13 = Arrays.asList(28095, 28097, 28098, 28101, 28102, 28104, 28106, 28107, 28108, 28227,
468
				28228, 28229, 28231, 29055, 29056, 29066, 29079);
469
		List<Integer> list15 = Arrays.asList(20891, 27938, 27939, 27940, 27941, 27943, 27947, 27948, 27953, 27954,
470
				27955, 28220, 28467, 29020, 29033, 29034, 29035, 29592, 29886, 29890, 29891, 29941, 29942, 27445, 27958,
471
				27960, 27961);
472
		List<Integer> list18 = Arrays.asList(28137, 28138, 28140, 28157, 28158, 28161, 28162, 28163, 28164, 28176,
473
				28177, 28178, 28199, 28200, 28208, 28209, 28210, 28211, 28215, 28216, 28217, 28230, 28380, 28381, 28382,
474
				28383, 28384, 28385, 28386, 28387, 28388, 28389, 28390, 28391, 28392, 28395, 28461, 28462, 28463, 28464,
475
				28465, 28466, 28488, 28489, 28490, 28491, 28564, 28565, 28762, 28773, 28871, 28872, 28873, 28874, 28880,
476
				28881, 28914, 28915, 28916, 28917, 28918, 28919, 28920, 29046, 29047, 29048, 29068, 29069, 29110, 29111,
477
				29112, 29113, 29114, 29115, 29116, 29117, 29207, 29208, 29217, 29218, 29225, 29474, 29475, 29476, 29477,
478
				29478, 29479, 29483, 29485, 29486, 29487, 29488, 29739, 29740, 29741, 29742, 29743, 29744, 29745, 29746,
479
				29747, 29748, 29749, 29753, 29756, 29757, 29758, 29760, 29761, 29762, 29763, 29764, 29765, 29766, 29767,
480
				29779, 29780, 29781, 29792, 29793, 29828, 29829, 29830, 29879, 29880, 29881, 29882, 29951);
481
		List<Integer> list20 = Arrays.asList(27975, 27976, 28091, 28363, 29023, 29024, 29025);
482
		List<Integer> list25 = Arrays.asList(28763, 28764, 28765, 29152, 29154, 29157, 29209, 29210, 29601, 29602,
483
				29720, 29721, 29722, 29723, 29725, 29726, 29727);
484
		List<Integer> list30 = Arrays.asList(27962, 27963, 27964, 27965, 27966, 27968, 27969, 28328, 28362, 28566,
485
				28567, 28568, 28571, 28572, 29073, 29074, 29075, 29080, 29081, 29120, 29121, 29122, 29124, 29189, 29190,
486
				29191, 29192, 29193, 29194, 29196, 29197, 29198, 29199, 29515, 29516, 29517, 29675, 29676, 29677, 29678,
487
				29679, 29707, 29708, 29794, 29795, 29883, 29884, 29885, 29887, 29888, 29889, 29931, 29932, 29935, 29936,
488
				29937, 29938, 29939, 29940);
489
		List<Integer> list35 = Arrays.asList(27996, 27998, 29067, 29071, 29643, 29644, 29945, 29946, 29987, 29052,
490
				29053, 29078, 29085, 29086, 29567, 29568, 29569, 29570, 29797, 29914, 29915, 29930, 28877, 28878, 29604,
491
				29605, 29606, 29775, 29776, 29777, 29778, 28862, 28863, 28864, 29026, 29103, 29104, 29105, 28979, 28980,
492
				28981, 28982, 28983, 29002, 29003, 29004, 29834, 29835, 29836, 29837, 29943);
493
		List<Integer> list40 = Arrays.asList(29082, 29083, 28766, 28767, 28768, 28769, 28771);
494
		List<Integer> list45 = Arrays.asList(28026, 28027, 28028, 29528, 29529, 29530, 29534, 29535, 29536, 29538,
495
				29755);
496
		List<Integer> list55 = Arrays.asList(28010, 28011, 28015, 28016, 28019, 28240, 28469, 28470, 28471, 28569,
497
				28570, 28674, 28759, 28761, 28909, 28910, 28911, 28912, 28913, 29108, 29109, 29143, 29144, 29145, 29146,
498
				29211, 29212, 29213, 29214, 29482, 29511, 29512, 29521, 29525, 29526, 29527, 29574, 29575, 29576, 29611,
499
				29612, 29616, 29641, 29642, 29728, 29729, 29750, 29771, 29782, 29783, 29784, 29923, 29924, 29944, 29953,
500
				29992, 29994, 27977, 27978, 28092, 28325, 28326, 28327, 28486, 28487, 29148, 29149, 29150, 29151, 29384,
501
				29385, 29386, 29427, 29489, 29518, 29519, 29520, 29577, 29578, 29579, 29580, 29586, 29660, 29661, 29662,
502
				29663, 29769, 29770, 29790, 29791, 29796, 29928, 29929, 29947, 29948, 28093, 28094, 28556, 28557, 28673,
503
				28867, 28868, 28870, 29089, 29090, 29091, 29106, 29107);
504
		List<Integer> list65 = Arrays.asList(28058, 28223, 28224, 28225, 28226, 28329, 29201, 29202, 29203, 29204,
505
				29205, 29206, 29466, 29467, 29468, 29469, 29470, 29471, 29472, 29573);
506
		Map<Float, List<Integer>> m = new HashMap<>();
507
		m.put(0.5f, list05);
508
		m.put(1.0f, list10);
509
		m.put(1.3f, list13);
510
		m.put(1.5f, list15);
511
		m.put(1.8f, list18);
512
		m.put(2.0f, list20);
513
		m.put(2.5f, list25);
514
		m.put(3.0f, list30);
515
		m.put(3.5f, list35);
516
		m.put(4.0f, list40);
517
		m.put(4.5f, list45);
518
		m.put(5.5f, list55);
519
		m.put(6.5f, list65);
520
		for (Map.Entry<Float, List<Integer>> itemsListEntry : m.entrySet()) {
521
			Scheme s1 = getScheme();
522
			s1.setAmount(itemsListEntry.getKey());
523
			schemeRepository.persist(s1);
25034 amit.gupta 524
			for (Integer itemId : itemsListEntry.getValue()) {
25021 amit.gupta 525
				SchemeItem schemeItem = new SchemeItem();
526
				schemeItem.setItemId(itemId);
527
				schemeItem.setSchemeId(s1.getId());
528
				schemeItemRepository.persist(schemeItem);
529
			}
530
		}
25034 amit.gupta 531
 
25021 amit.gupta 532
	}
533
 
534
	private Scheme getScheme() {
535
		Scheme s = new Scheme();
536
		s.setName("List Price Margin");
537
		s.setDescription("List Price Margin");
538
		s.setActiveTimestamp(null);
539
		s.setStartDateTime(LocalDate.of(2019, 6, 1).atStartOfDay());
540
		s.setEndDateTime(LocalDate.of(2019, 7, 1).atStartOfDay());
541
		s.setAmountType(AmountType.PERCENTAGE);
542
		s.setCreateTimestamp(LocalDateTime.now());
543
		s.setExpireTimestamp(null);
544
		s.setCreatedBy(175120474);
545
		return s;
546
	}
547
 
24957 amit.gupta 548
	public void findMismatchesInIndent() throws Exception {
25021 amit.gupta 549
		/*
550
		 * List<SaholicInventorySnapshot> saholicInventorySnapshots =
551
		 * saholicInventorySnapshotRepository.selectAll(); Map<Integer, Integer>
552
		 * itemReservedMap = saholicInventorySnapshots.stream().filter(x ->
553
		 * x.getReserved() > 0)
554
		 * .collect(Collectors.groupingBy(SaholicInventorySnapshot::getItemId,
555
		 * Collectors.summingInt(SaholicInventorySnapshot::getReserved)));
556
		 */
24957 amit.gupta 557
		List<Order> allInProcessOrders = orderRepository.selectAllOrder(OrderStatus.SUBMITTED_FOR_PROCESSING);
24967 amit.gupta 558
 
25021 amit.gupta 559
		/*
560
		 * Map<Integer, Integer> lineItemQtyMap = allInProcessOrders
561
		 * .stream().collect(Collectors.groupingBy(y -> y.getLineItem().getItemId(),
562
		 * Collectors.summingInt(y -> y.getLineItem().getQuantity())));
563
		 */
564
 
565
		/*
566
		 * Map<Integer, Order> orderMap =
567
		 * allInProcessOrders.stream().collect(Collectors.toMap(Order::getId, x->x));
568
		 * Map<Integer, List<Order>> itemOrdersMap = allInProcessOrders.stream()
569
		 * .collect(Collectors.groupingBy(o->o.getLineItem().getItemId(),
570
		 * Collectors.toList()));
571
		 */
572
 
573
		Map<String, Integer> lineItemWhQtyMap = allInProcessOrders.stream()
25734 amit.gupta 574
				.collect(Collectors.groupingBy(y -> y.getLineItem().getItemId() + "-" + y.getFulfilmentWarehouseId(),
24967 amit.gupta 575
						Collectors.summingInt(y -> y.getLineItem().getQuantity())));
25021 amit.gupta 576
 
577
		/*
578
		 * itemReservedMap.forEach((itemId, reserved)->{
579
		 * if(lineItemQtyMap.containsKey(itemId)) { int orderedQty =
580
		 * lineItemQtyMap.get(itemId); System.out.printf("%d\t%d\t%d\n",itemId,
581
		 * orderedQty, reserved); } else {
582
		 * saholicInventorySnapshotRepository.removeAllReservations(itemId);
583
		 * System.out.printf("%d\t%d\t%d\n",itemId, 0, reserved); } });
584
		 */
585
 
586
		lineItemWhQtyMap.forEach((key, value) -> {
587
 
24967 amit.gupta 588
			int itemId = Integer.parseInt(key.split("-")[0]);
589
			int warehouseId = Integer.parseInt(key.split("-")[1]);
25021 amit.gupta 590
			System.out.printf("%d\t%d\t%d\n", itemId, warehouseId, value);
591
			SaholicInventorySnapshot cis = saholicInventorySnapshotRepository.selectByWarehouseIdandItemId(warehouseId,
592
					itemId);
593
			if (cis == null) {
24970 amit.gupta 594
				cis = new SaholicInventorySnapshot();
595
				cis.setItemId(itemId);
596
				cis.setWarehouseId(warehouseId);
597
				cis.setAvailability(0);
598
				saholicInventorySnapshotRepository.persist(cis);
599
			}
24967 amit.gupta 600
			cis.setReserved(value);
601
		});
24964 amit.gupta 602
		/*
25021 amit.gupta 603
		 * List<SaholicReservationInventorySnapshot> reservationInventorySnapshots =
604
		 * saholicReservationInventorySnapshotRepository.selectAll(); Map<Integer,
605
		 * SaholicReservationInventorySnapshot> reservationInventorySnapshotsMap
606
		 * =reservationInventorySnapshots.stream()
607
		 * .collect(Collectors.toMap(x->x.getOrderId(), x->x));
608
		 * 
609
		 * List<Integer> orderIds =
610
		 * reservationInventorySnapshots.stream().map(x->x.getOrderId()).collect(
611
		 * Collectors.toList()); List<Order> orders =
612
		 * orderRepository.selectByOrderIds(orderIds);
613
		 * orders.stream().filter(x->Arrays.asList(OrderStatus.PAYMENT_PENDING,
614
		 * OrderStatus.PAYMENT_FAILED). contains(x.getStatus())).forEach(x->{
615
		 * SaholicReservationInventorySnapshot snapshot =
616
		 * reservationInventorySnapshotsMap.get(x.getId()); try {
617
		 * saholicInventorySnapshotRepository.reduceReservationCount(snapshot.getItemId(
618
		 * ), snapshot.getWarehouseId(), snapshot.getReserved(), snapshot.getOrderId());
619
		 * System.out.printf("%d Reduced by %d for Order Id %d\n",snapshot.getItemId(),
620
		 * snapshot.getReserved(), snapshot.getOrderId()); }
621
		 * catch(ProfitMandiBusinessException e) {
622
		 * LOGGER.info("Problem whiile reducing count for Order Id - {}",
623
		 * snapshot.getOrderId()); } });
624
		 */
625
		// throw new Exception();
24953 amit.gupta 626
	}
627
 
25034 amit.gupta 628
	public void fixSchemePayouts() throws Exception {
25524 amit.gupta 629
		LOGGER.info("In fix scheme Payouts");
25522 amit.gupta 630
		LocalDateTime startDate = LocalDate.of(2019, 9, 1).atStartOfDay();
631
		List<SchemeInOut> sios = schemeInOutRepository.selectAllByCreateDate(startDate, LocalDateTime.now());
25530 amit.gupta 632
 
25034 amit.gupta 633
		for (SchemeInOut sio : sios) {
25530 amit.gupta 634
			if (sio.getSchemeId() != 347) {
25523 amit.gupta 635
				LOGGER.info("Skipping {}", sio.getSchemeId());
25522 amit.gupta 636
				continue;
637
			}
25043 amit.gupta 638
			genericRepository.delete(sio);
25522 amit.gupta 639
			InventoryItem ii = inventoryItemRepository.selectById(sio.getInventoryItemId());
640
			UserWallet userWallet = userWalletRepository.selectByRetailerId(ii.getFofoId());
641
			Scheme scheme = schemeRepository.selectById(sio.getSchemeId());
642
			if (scheme.getType().equals(SchemeType.IN)) {
643
				List<UserWalletHistory> historyList = userWalletHistoryRepository
644
						.selectAllByreferenceIdandreferenceType(ii.getPurchaseId(), WalletReferenceType.SCHEME_IN);
645
				for (UserWalletHistory uwh : historyList) {
25530 amit.gupta 646
					if (uwh.getTimestamp().isAfter(startDate)) {
25522 amit.gupta 647
						genericRepository.delete(uwh);
648
						userWallet.setAmount(userWallet.getAmount() - uwh.getAmount());
649
					}
650
				}
651
			} else {
652
				List<ScanRecord> scanRecords = scanRecordRepository.selectByInventoryItemId(ii.getId());
653
				int orderId = scanRecords.get(0).getOrderId();
654
				List<UserWalletHistory> historyList = userWalletHistoryRepository
655
						.selectAllByreferenceIdandreferenceType(orderId, WalletReferenceType.SCHEME_OUT);
656
				for (UserWalletHistory uwh : historyList) {
25530 amit.gupta 657
					if (uwh.getTimestamp().isAfter(startDate)) {
25522 amit.gupta 658
						userWallet.setAmount(userWallet.getAmount() - uwh.getAmount());
659
						genericRepository.delete(uwh);
660
					}
661
				}
662
				List<UserWalletHistory> historyListBroken = userWalletHistoryRepository
25530 amit.gupta 663
						.selectAllByreferenceIdandreferenceType(ii.getPurchaseId(), WalletReferenceType.SCHEME_OUT);
25522 amit.gupta 664
				for (UserWalletHistory uwh : historyListBroken) {
25530 amit.gupta 665
					if (uwh.getTimestamp().isAfter(startDate)) {
25522 amit.gupta 666
						genericRepository.delete(uwh);
667
						userWallet.setAmount(userWallet.getAmount() - uwh.getAmount());
668
					}
669
				}
670
			}
671
 
25530 amit.gupta 672
			// System.out.println("Total Amount Rolled Back is " + totalRollbackAmount);
25516 amit.gupta 673
		}
25589 amit.gupta 674
		scheduledTasks.processScheme(startDate, startDate.plusDays(10), true);
25030 amit.gupta 675
	}
25530 amit.gupta 676
 
677
	public void fixWallet() throws Exception {
678
		List<FofoStore> fofoStores = fofoStoreRepository.selectAll();
25536 amit.gupta 679
		System.out.println("id\tcode\tactive\tname\tcity\tstate\twallet amount\tsum\twallet amount-sum");
25530 amit.gupta 680
		for (FofoStore fofoStore : fofoStores) {
681
			UserWallet uw = userWalletRepository.selectByRetailerId(fofoStore.getId());
682
			User user = userRepository.selectById(fofoStore.getId());
25749 amit.gupta 683
			if (user == null) {
25533 amit.gupta 684
				LOGGER.info("store does not exist", fofoStore.getCode());
25535 amit.gupta 685
				continue;
25533 amit.gupta 686
			}
25536 amit.gupta 687
			Address address = null;
688
			try {
689
				address = addressRepository.selectById(user.getAddressId());
25749 amit.gupta 690
			} catch (Exception e) {
25536 amit.gupta 691
				LOGGER.info("Could not find address for Store", fofoStore.getCode());
692
				address = new Address();
693
			}
25539 amit.gupta 694
			double sum = userWalletHistoryRepository.selectSumByWallet(uw.getId());
25749 amit.gupta 695
			int calculated = (int) sum;
696
			System.out.printf("%d\t%s\t%b\t%s\t%s\t%s\t%d\t%d\t%d%n", fofoStore.getId(), fofoStore.getCode(),
697
					fofoStore.isActive(), address.getName(), address.getCity(), address.getState(), uw.getAmount(),
698
					calculated, uw.getAmount() - calculated);
25530 amit.gupta 699
		}
700
	}
25749 amit.gupta 701
 
25734 amit.gupta 702
	public void changeWarehouse() throws Exception {
703
		transactionService.moveWarehouses();
704
	}
25749 amit.gupta 705
 
706
	public void mailDashboardScreenshots() throws Exception {
707
		System.setProperty("webdriver.chrome.driver", "/usr/bin/chromedriver");
708
 
25752 amit.gupta 709
 
710
 
711
 
712
		ChromeOptions options = new ChromeOptions();
713
		options.addArguments("--headless");
714
		options.addArguments("--no-sandbox");
715
		options.addArguments("start-maximized");
716
		options.addArguments("disable-infobars");
717
		options.addArguments("--disable-extensions");
718
 
25749 amit.gupta 719
		WebDriver driver = new ChromeDriver();
720
		driver.manage().window().maximize();
25752 amit.gupta 721
		// Deleting all the cookies
25749 amit.gupta 722
		driver.manage().deleteAllCookies();
25752 amit.gupta 723
		// Specifiying pageLoadTimeout and Implicit wait
25749 amit.gupta 724
		driver.manage().timeouts().pageLoadTimeout(40, TimeUnit.SECONDS);
725
		driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
25752 amit.gupta 726
 
727
 
25749 amit.gupta 728
		Map<String, Set<Integer>> authUserPartnerIdMapping = csService.getAuthUserPartnerIdMapping();
729
		Set<Integer> allPartners = new HashSet<>();
730
		Map<Integer, String> partnerSnapshotMap = new HashMap<>();
25752 amit.gupta 731
		authUserPartnerIdMapping.values().stream().forEach(x -> allPartners.addAll(x));
25749 amit.gupta 732
		System.out.println(allPartners.size());
25752 amit.gupta 733
		for (int fofoId : allPartners) {
25749 amit.gupta 734
			driver.get("https://partners.smartdukaan.com/12dashboard34?fofoId=" + fofoId);
25752 amit.gupta 735
			String base64Image = ((TakesScreenshot) driver).getScreenshotAs(OutputType.BASE64);
25749 amit.gupta 736
			partnerSnapshotMap.put(fofoId, base64Image);
25752 amit.gupta 737
 
25749 amit.gupta 738
		}
25752 amit.gupta 739
		for (Map.Entry<String, Set<Integer>> entry : authUserPartnerIdMapping.entrySet()) {
25749 amit.gupta 740
			String email = entry.getKey();
741
			Set<Integer> partnerIds = entry.getValue();
742
			StringBuffer body = new StringBuffer();
25752 amit.gupta 743
			for (int fofoId : partnerIds) {
25749 amit.gupta 744
				body.append(String.format("<br><image src=\"%s\" />", partnerSnapshotMap.get(fofoId)));
745
			}
25752 amit.gupta 746
			Utils.sendHtmlMailWithAttachments(mailSender, new String[] { "amit.gupta@shop2020.in" }, new String[] {},
747
					String.format("Franchise Screenshots - %s", FormattingUtils.formatDate(LocalDateTime.now())),
748
					body.toString());
25749 amit.gupta 749
		}
750
		driver.quit();
751
	}
25043 amit.gupta 752
}
753
 
754
//7015845171