Subversion Repositories SmartDukaan

Rev

Rev 27511 | Rev 27721 | 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
 
25765 amit.gupta 3
import java.io.File;
27450 tejbeer 4
import java.io.IOException;
23824 amit.gupta 5
import java.time.LocalDate;
23755 amit.gupta 6
import java.time.LocalDateTime;
23824 amit.gupta 7
import java.time.LocalTime;
27511 amit.gupta 8
import java.time.Month;
27310 amit.gupta 9
import java.time.temporal.ChronoUnit;
24819 amit.gupta 10
import java.util.ArrayList;
23755 amit.gupta 11
import java.util.Arrays;
27450 tejbeer 12
import java.util.Base64;
23827 amit.gupta 13
import java.util.Collections;
26928 amit.gupta 14
import java.util.Comparator;
24002 amit.gupta 15
import java.util.HashMap;
24005 amit.gupta 16
import java.util.HashSet;
23755 amit.gupta 17
import java.util.List;
24002 amit.gupta 18
import java.util.Map;
25749 amit.gupta 19
import java.util.Set;
20
import java.util.concurrent.TimeUnit;
24641 amit.gupta 21
import java.util.stream.Collectors;
23755 amit.gupta 22
 
24819 amit.gupta 23
import org.apache.commons.io.output.ByteArrayOutputStream;
23755 amit.gupta 24
import org.apache.commons.lang.StringUtils;
25
import org.apache.logging.log4j.LogManager;
26
import org.apache.logging.log4j.Logger;
27450 tejbeer 27
import org.json.JSONArray;
28
import org.json.JSONObject;
25773 amit.gupta 29
import org.openqa.selenium.Dimension;
25749 amit.gupta 30
import org.openqa.selenium.OutputType;
31
import org.openqa.selenium.TakesScreenshot;
32
import org.openqa.selenium.WebDriver;
33
import org.openqa.selenium.chrome.ChromeDriver;
25752 amit.gupta 34
import org.openqa.selenium.chrome.ChromeOptions;
23755 amit.gupta 35
import org.springframework.beans.factory.annotation.Autowired;
24819 amit.gupta 36
import org.springframework.core.io.ByteArrayResource;
24767 amit.gupta 37
import org.springframework.mail.javamail.JavaMailSender;
23755 amit.gupta 38
import org.springframework.stereotype.Component;
39
import org.springframework.transaction.annotation.Transactional;
40
 
26214 amit.gupta 41
import com.smartdukaan.cron.scheduled.SamsungIMEIActivationService;
25043 amit.gupta 42
import com.smartdukaan.cron.scheduled.ScheduledTasks;
26095 amit.gupta 43
import com.spice.profitmandi.common.enumuration.ItemType;
26033 amit.gupta 44
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
27450 tejbeer 45
import com.spice.profitmandi.common.model.CustomRetailer;
24819 amit.gupta 46
import com.spice.profitmandi.common.util.FileUtil;
25749 amit.gupta 47
import com.spice.profitmandi.common.util.FormattingUtils;
24819 amit.gupta 48
import com.spice.profitmandi.common.util.Utils;
26033 amit.gupta 49
import com.spice.profitmandi.dao.entity.catalog.Item;
25021 amit.gupta 50
import com.spice.profitmandi.dao.entity.catalog.Scheme;
26579 amit.gupta 51
import com.spice.profitmandi.dao.entity.catalog.TagListing;
27286 amit.gupta 52
import com.spice.profitmandi.dao.entity.dtr.PaymentOptionTransaction;
24716 amit.gupta 53
import com.spice.profitmandi.dao.entity.fofo.CurrentInventorySnapshot;
26759 amit.gupta 54
import com.spice.profitmandi.dao.entity.fofo.DebitNote;
27286 amit.gupta 55
import com.spice.profitmandi.dao.entity.fofo.FofoLineItem;
24806 amit.gupta 56
import com.spice.profitmandi.dao.entity.fofo.FofoOrder;
57
import com.spice.profitmandi.dao.entity.fofo.FofoOrderItem;
25530 amit.gupta 58
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
24005 amit.gupta 59
import com.spice.profitmandi.dao.entity.fofo.InventoryItem;
26928 amit.gupta 60
import com.spice.profitmandi.dao.entity.fofo.PartnerType;
26033 amit.gupta 61
import com.spice.profitmandi.dao.entity.fofo.PrebookingOrder;
23898 amit.gupta 62
import com.spice.profitmandi.dao.entity.fofo.Purchase;
26759 amit.gupta 63
import com.spice.profitmandi.dao.entity.fofo.PurchaseReturnItem;
24716 amit.gupta 64
import com.spice.profitmandi.dao.entity.fofo.ScanRecord;
25034 amit.gupta 65
import com.spice.profitmandi.dao.entity.fofo.SchemeInOut;
25021 amit.gupta 66
import com.spice.profitmandi.dao.entity.fofo.SchemeItem;
24953 amit.gupta 67
import com.spice.profitmandi.dao.entity.inventory.SaholicInventorySnapshot;
23824 amit.gupta 68
import com.spice.profitmandi.dao.entity.transaction.LineItem;
23755 amit.gupta 69
import com.spice.profitmandi.dao.entity.transaction.LineItemImei;
70
import com.spice.profitmandi.dao.entity.transaction.Order;
24802 amit.gupta 71
import com.spice.profitmandi.dao.entity.transaction.SellerWarehouse;
25046 amit.gupta 72
import com.spice.profitmandi.dao.entity.transaction.UserWallet;
25034 amit.gupta 73
import com.spice.profitmandi.dao.entity.transaction.UserWalletHistory;
25530 amit.gupta 74
import com.spice.profitmandi.dao.entity.user.Address;
75
import com.spice.profitmandi.dao.entity.user.User;
27511 amit.gupta 76
import com.spice.profitmandi.dao.entity.warehouse.WarehouseInventoryItem;
25021 amit.gupta 77
import com.spice.profitmandi.dao.enumuration.catalog.AmountType;
25522 amit.gupta 78
import com.spice.profitmandi.dao.enumuration.catalog.SchemeType;
27286 amit.gupta 79
import com.spice.profitmandi.dao.enumuration.dtr.PaymentOptionReferenceType;
26759 amit.gupta 80
import com.spice.profitmandi.dao.enumuration.fofo.ScanType;
26579 amit.gupta 81
import com.spice.profitmandi.dao.model.ContentPojo;
82
import com.spice.profitmandi.dao.model.MediaPojo;
24716 amit.gupta 83
import com.spice.profitmandi.dao.repository.GenericRepository;
25034 amit.gupta 84
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
25021 amit.gupta 85
import com.spice.profitmandi.dao.repository.catalog.SchemeRepository;
26579 amit.gupta 86
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
25749 amit.gupta 87
import com.spice.profitmandi.dao.repository.cs.CsService;
23899 amit.gupta 88
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
27221 amit.gupta 89
import com.spice.profitmandi.dao.repository.dtr.LeadRepository;
26579 amit.gupta 90
import com.spice.profitmandi.dao.repository.dtr.Mongo;
27286 amit.gupta 91
import com.spice.profitmandi.dao.repository.dtr.PaymentOptionTransactionRepository;
24716 amit.gupta 92
import com.spice.profitmandi.dao.repository.fofo.CurrentInventorySnapshotRepository;
24002 amit.gupta 93
import com.spice.profitmandi.dao.repository.fofo.DebitNoteRepository;
27286 amit.gupta 94
import com.spice.profitmandi.dao.repository.fofo.FofoLineItemRepository;
24806 amit.gupta 95
import com.spice.profitmandi.dao.repository.fofo.FofoOrderItemRepository;
96
import com.spice.profitmandi.dao.repository.fofo.FofoOrderRepository;
24002 amit.gupta 97
import com.spice.profitmandi.dao.repository.fofo.InventoryItemRepository;
24806 amit.gupta 98
import com.spice.profitmandi.dao.repository.fofo.InvoiceNumberGenerationSequenceRepository;
24883 amit.gupta 99
import com.spice.profitmandi.dao.repository.fofo.PartnerTargetRepository;
26033 amit.gupta 100
import com.spice.profitmandi.dao.repository.fofo.PrebookingOrderRepository;
23898 amit.gupta 101
import com.spice.profitmandi.dao.repository.fofo.PurchaseRepository;
26759 amit.gupta 102
import com.spice.profitmandi.dao.repository.fofo.PurchaseReturnItemRepository;
24716 amit.gupta 103
import com.spice.profitmandi.dao.repository.fofo.ScanRecordRepository;
24002 amit.gupta 104
import com.spice.profitmandi.dao.repository.fofo.SchemeInOutRepository;
25021 amit.gupta 105
import com.spice.profitmandi.dao.repository.fofo.SchemeItemRepository;
24953 amit.gupta 106
import com.spice.profitmandi.dao.repository.inventory.SaholicInventorySnapshotRepository;
26928 amit.gupta 107
import com.spice.profitmandi.dao.repository.inventory.SaholicReservationSnapshotRepository;
23755 amit.gupta 108
import com.spice.profitmandi.dao.repository.transaction.LineItemImeisRepository;
23824 amit.gupta 109
import com.spice.profitmandi.dao.repository.transaction.LineItemRepository;
23755 amit.gupta 110
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
24772 amit.gupta 111
import com.spice.profitmandi.dao.repository.transaction.ReturnOrderRepository;
24802 amit.gupta 112
import com.spice.profitmandi.dao.repository.transaction.SellerWarehouseRepository;
24767 amit.gupta 113
import com.spice.profitmandi.dao.repository.transaction.UserWalletHistoryRepository;
114
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
25530 amit.gupta 115
import com.spice.profitmandi.dao.repository.user.AddressRepository;
24002 amit.gupta 116
import com.spice.profitmandi.dao.repository.user.UserRepository;
27511 amit.gupta 117
import com.spice.profitmandi.dao.repository.warehouse.WarehouseInventoryItemRepository;
23899 amit.gupta 118
import com.spice.profitmandi.service.inventory.InventoryService;
26033 amit.gupta 119
import com.spice.profitmandi.service.inventory.PurchaseService;
24266 amit.gupta 120
import com.spice.profitmandi.service.order.OrderService;
24005 amit.gupta 121
import com.spice.profitmandi.service.pricing.PriceDropService;
122
import com.spice.profitmandi.service.scheme.SchemeService;
23899 amit.gupta 123
import com.spice.profitmandi.service.transaction.TransactionService;
124
import com.spice.profitmandi.service.user.RetailerService;
125
import com.spice.profitmandi.service.wallet.WalletService;
23755 amit.gupta 126
 
24953 amit.gupta 127
import in.shop2020.model.v1.order.OrderStatus;
24002 amit.gupta 128
import in.shop2020.model.v1.order.WalletReferenceType;
27450 tejbeer 129
import okhttp3.OkHttpClient;
130
import okhttp3.Request;
131
import okhttp3.Response;
24002 amit.gupta 132
 
23755 amit.gupta 133
@Component
134
@Transactional(rollbackFor = Throwable.class)
135
public class RunOnceTasks {
136
 
137
	private static final Logger LOGGER = LogManager.getLogger(RunOnceTasks.class);
138
 
139
	@Autowired
23824 amit.gupta 140
	private LineItemRepository lineItemRepository;
24711 amit.gupta 141
 
23905 amit.gupta 142
	@Autowired
27221 amit.gupta 143
	private LeadRepository leadRepository;
27277 amit.gupta 144
 
27221 amit.gupta 145
	@Autowired
26759 amit.gupta 146
	private PurchaseReturnItemRepository purchaseReturnItemRepository;
26928 amit.gupta 147
 
26759 amit.gupta 148
	@Autowired
24953 amit.gupta 149
	private SaholicInventorySnapshotRepository saholicInventorySnapshotRepository;
25752 amit.gupta 150
 
25749 amit.gupta 151
	@Autowired
152
	private CsService csService;
26299 amit.gupta 153
 
26033 amit.gupta 154
	@Autowired
26579 amit.gupta 155
	private Mongo mongoClient;
27511 amit.gupta 156
 
27286 amit.gupta 157
	@Autowired
158
	private PaymentOptionTransactionRepository paymentOptionTransactionRepository;
26579 amit.gupta 159
 
160
	@Autowired
26195 amit.gupta 161
	private SamsungIMEIActivationService samsungActivationService;
26299 amit.gupta 162
 
26195 amit.gupta 163
	@Autowired
26033 amit.gupta 164
	private PrebookingOrderRepository prebookingOrderRepository;
24953 amit.gupta 165
 
166
	@Autowired
26928 amit.gupta 167
	private SaholicReservationSnapshotRepository saholicReservationInventorySnapshotRepository;
24953 amit.gupta 168
 
169
	@Autowired
24883 amit.gupta 170
	private PartnerTargetRepository partnerTargetRepository;
171
 
172
	@Autowired
24802 amit.gupta 173
	private SellerWarehouseRepository sellerWarehouseRepository;
24814 amit.gupta 174
 
24802 amit.gupta 175
	@Autowired
24806 amit.gupta 176
	private FofoOrderItemRepository fofoOrderItemRepository;
27511 amit.gupta 177
 
27286 amit.gupta 178
	@Autowired
179
	private FofoLineItemRepository fofoLineItemRepository;
24814 amit.gupta 180
 
24806 amit.gupta 181
	@Autowired
182
	private FofoOrderRepository fofoOrderRepository;
24814 amit.gupta 183
 
24806 amit.gupta 184
	@Autowired
24767 amit.gupta 185
	private UserWalletRepository userWalletRepository;
186
 
187
	@Autowired
188
	private UserWalletHistoryRepository userWalletHistoryRepository;
189
 
190
	@Autowired
24002 amit.gupta 191
	private UserRepository userRepository;
24711 amit.gupta 192
 
24002 amit.gupta 193
	@Autowired
23899 amit.gupta 194
	private WalletService walletService;
195
 
196
	@Autowired
25034 amit.gupta 197
	private ItemRepository itemRepository;
198
 
199
	@Autowired
23899 amit.gupta 200
	private InventoryService inventoryService;
201
 
202
	@Autowired
203
	private TransactionService transactionService;
26299 amit.gupta 204
 
26033 amit.gupta 205
	@Autowired
206
	private PurchaseService purchaseService;
23899 amit.gupta 207
 
24711 amit.gupta 208
	// Service for Tertiary/Partner Orders
24266 amit.gupta 209
	@Autowired
210
	private OrderService orderService;
23767 amit.gupta 211
 
23755 amit.gupta 212
	@Autowired
25021 amit.gupta 213
	private SchemeRepository schemeRepository;
25516 amit.gupta 214
 
25043 amit.gupta 215
	@Autowired
25530 amit.gupta 216
	private AddressRepository addressRepository;
25749 amit.gupta 217
 
25530 amit.gupta 218
	@Autowired
25043 amit.gupta 219
	private ScheduledTasks scheduledTasks;
25034 amit.gupta 220
 
25021 amit.gupta 221
	@Autowired
222
	private SchemeItemRepository schemeItemRepository;
223
 
224
	@Autowired
24772 amit.gupta 225
	private ReturnOrderRepository returnOrderRepository;
226
 
227
	@Autowired
23899 amit.gupta 228
	private FofoStoreRepository fofoStoreRepository;
229
 
230
	@Autowired
23755 amit.gupta 231
	private LineItemImeisRepository lineItemImeisRepository;
24711 amit.gupta 232
 
24002 amit.gupta 233
	@Autowired
234
	private InventoryItemRepository inventoryItemRepository;
24814 amit.gupta 235
 
24806 amit.gupta 236
	@Autowired
26579 amit.gupta 237
	private TagListingRepository tagListingRepository;
238
 
239
	@Autowired
24806 amit.gupta 240
	private InvoiceNumberGenerationSequenceRepository invoiceNumberGenerationSequenceRepository;
23901 amit.gupta 241
 
23898 amit.gupta 242
	@Autowired
23899 amit.gupta 243
	private RetailerService retailerService;
24711 amit.gupta 244
 
24002 amit.gupta 245
	@Autowired
246
	private SchemeInOutRepository schemeInOutRepository;
24711 amit.gupta 247
 
24002 amit.gupta 248
	@Autowired
249
	private DebitNoteRepository debitNoteRepository;
23899 amit.gupta 250
 
251
	@Autowired
24716 amit.gupta 252
	private GenericRepository genericRepository;
253
 
254
	@Autowired
23898 amit.gupta 255
	private PurchaseRepository purchaseRepository;
24711 amit.gupta 256
 
24005 amit.gupta 257
	@Autowired
258
	private PriceDropService priceDropService;
24883 amit.gupta 259
 
24819 amit.gupta 260
	@Autowired
261
	private JavaMailSender googleMailSender;
24711 amit.gupta 262
 
24005 amit.gupta 263
	@Autowired
264
	private SchemeService schemeService;
24711 amit.gupta 265
 
24716 amit.gupta 266
	@Autowired
267
	private CurrentInventorySnapshotRepository currentInventorySnapshotRepository;
268
 
269
	@Autowired
24767 amit.gupta 270
	private OrderRepository orderRepository;
271
 
272
	@Autowired
24716 amit.gupta 273
	private ScanRecordRepository scanRecordRepository;
274
 
24767 amit.gupta 275
	@Autowired
276
	private JavaMailSender mailSender;
27451 tejbeer 277
 
27450 tejbeer 278
	private static final String ACCOUNT_ID = "aZ6flHhrgPIEl18buHdPBdueEN4";
279
	private static final String SECRET_KEY = "a7rsX5B4UNNfTTx1-IJ19qdH48BT4YvBKlQJg3n3_KKNe7WWych55g";
24767 amit.gupta 280
 
27511 amit.gupta 281
	@Autowired
282
	private WarehouseInventoryItemRepository warehouseInventoryItemRepository;
283
 
23898 amit.gupta 284
	public void populateGrnTimestamp() {
285
		List<Purchase> allPurchases = purchaseRepository.selectAll();
23899 amit.gupta 286
		for (Purchase p : allPurchases) {
23898 amit.gupta 287
			String invoiceNumber = p.getPurchaseReference();
23899 amit.gupta 288
			if (p.getCompleteTimestamp() == null) {
23898 amit.gupta 289
				LOGGER.info("GRN for invoice {} is delivered but partially Completed.", p.getPurchaseReference());
290
			} else {
291
				List<Order> orders = orderRepository.selectByAirwayBillOrInvoiceNumber(invoiceNumber, p.getFofoId());
23899 amit.gupta 292
				for (Order order : orders) {
23902 amit.gupta 293
					if (order.getPartnerGrnTimestamp() == null) {
294
						order.setPartnerGrnTimestamp(p.getCompleteTimestamp());
23898 amit.gupta 295
						orderRepository.persist(order);
296
					}
297
				}
298
			}
299
		}
23899 amit.gupta 300
 
23898 amit.gupta 301
	}
23899 amit.gupta 302
 
26408 amit.gupta 303
	public void fetchImeiActivation(int ym) throws Exception {
304
		LocalDate endDate = LocalDate.now().minusMonths(ym);
26579 amit.gupta 305
		samsungActivationService.getActivationsBetweenNew(endDate.withDayOfMonth(1),
306
				endDate.withDayOfMonth(endDate.lengthOfMonth()));
26195 amit.gupta 307
	}
26299 amit.gupta 308
 
24716 amit.gupta 309
	public void migarateLineItemsToNewTable() throws Exception {
23755 amit.gupta 310
		LOGGER.info("Before Migrated LineItems Successfully");
23824 amit.gupta 311
		int lineItemImeiId = 0;
312
		LocalDateTime startDate = null;
313
		try {
314
			lineItemImeiId = lineItemImeisRepository.selectMaxId();
23899 amit.gupta 315
			LineItem lineItem = lineItemRepository
316
					.selectById(lineItemImeisRepository.selectById(lineItemImeiId).getLineItemId());
23824 amit.gupta 317
			Order order = orderRepository.selectById(lineItem.getOrderId());
318
			startDate = order.getBillingTimestamp();
319
		} catch (Exception e) {
320
			LOGGER.info("Running before first time");
23826 amit.gupta 321
			startDate = LocalDateTime.of(LocalDate.of(2017, 7, 1), LocalTime.MIDNIGHT);
23824 amit.gupta 322
		}
323
		List<Order> orders = orderRepository.selectAllByBillingDatesBetween(startDate, LocalDateTime.now());
23827 amit.gupta 324
		Collections.reverse(orders);
23899 amit.gupta 325
 
23755 amit.gupta 326
		for (Order order : orders) {
23824 amit.gupta 327
			try {
23767 amit.gupta 328
				String serialNumbers = order.getLineItem().getSerialNumber();
329
				if (!StringUtils.isEmpty(serialNumbers)) {
330
					List<String> serialNumberList = Arrays.asList(serialNumbers.split(","));
331
					for (String serialNumber : serialNumberList) {
332
						int lineItemId = order.getLineItem().getId();
333
						LineItemImei lineItemImei = new LineItemImei();
334
						lineItemImei.setSerialNumber(serialNumber);
335
						lineItemImei.setLineItemId(lineItemId);
336
						lineItemImeisRepository.persist(lineItemImei);
337
					}
338
				} else {
339
					LOGGER.info("Serial Numbers dont exist for Order {}", order.getId());
23755 amit.gupta 340
				}
23824 amit.gupta 341
			} catch (Exception e) {
23899 amit.gupta 342
				LOGGER.info("Error occurred while creating lineitem imei {}, because of {}", order.getId(),
343
						e.getMessage());
23755 amit.gupta 344
			}
345
		}
346
		LOGGER.info("Migrated LineItems Successfully");
347
	}
24266 amit.gupta 348
 
349
	public void cancelOrder(List<String> invoiceNumbers) throws Exception {
350
		orderService.cancelOrder(invoiceNumbers);
351
	}
24711 amit.gupta 352
 
24722 amit.gupta 353
	public void migratePurchase() throws Exception {
24641 amit.gupta 354
		List<Purchase> purchases = purchaseRepository.selectPurchaseAllPurchasesLessThanZero();
24706 amit.gupta 355
		System.out.printf("Total Purchases count is %s", purchases.size());
24711 amit.gupta 356
		for (Purchase purchase : purchases) {
357
			List<InventoryItem> inventoryItems = inventoryItemRepository.selectByPurchaseId(purchase.getId());
358
			Map<Integer, List<InventoryItem>> itemIdInventoryMap = inventoryItems.stream()
359
					.collect(Collectors.groupingBy(InventoryItem::getItemId));
360
			List<Order> orders = orderRepository.selectByAirwayBillOrInvoiceNumber(purchase.getPurchaseReference(),
361
					purchase.getFofoId());
362
			Map<Integer, Integer> ourSaleItemQtyMap = orders.stream().collect(Collectors.groupingBy(
363
					x -> x.getLineItem().getItemId(), Collectors.summingInt(x -> x.getLineItem().getQuantity())));
364
			Map<Integer, Integer> theirPurchaseItemQtyMap = inventoryItems.stream().collect(Collectors
365
					.groupingBy(InventoryItem::getItemId, Collectors.summingInt(InventoryItem::getInitialQuantity)));
24709 amit.gupta 366
			for (Map.Entry<Integer, Integer> itemQtyEntry : theirPurchaseItemQtyMap.entrySet()) {
24711 amit.gupta 367
				if (!ourSaleItemQtyMap.containsKey(itemQtyEntry.getKey())) {
368
					LOGGER.info("Cannot find in Invoice {} item {}", purchase.getPurchaseReference(),
369
							itemQtyEntry.getKey());
24646 amit.gupta 370
					continue;
24645 amit.gupta 371
				}
24709 amit.gupta 372
				int ourSale = ourSaleItemQtyMap.get(itemQtyEntry.getKey());
24713 amit.gupta 373
				int quantityToReduce = itemQtyEntry.getValue() - ourSale;
24716 amit.gupta 374
				List<InventoryItem> itemIis = itemIdInventoryMap.get(itemQtyEntry.getKey());
375
				if (itemIdInventoryMap != null) {
376
					for (InventoryItem ii : itemIis) {
24915 amit.gupta 377
						if (ii.getSerialNumber() == null && ii.getGoodQuantity() == ii.getInitialQuantity()
378
								&& quantityToReduce >= ii.getInitialQuantity()) {
24734 amit.gupta 379
							LOGGER.info("Changed in inventoryItems {}, {}, {}, {}, {}, {}",
24716 amit.gupta 380
									purchase.getPurchaseReference(), ii.getId(), ii.getItemId(),
24734 amit.gupta 381
									ii.getInitialQuantity(), ii.getGoodQuantity(), quantityToReduce);
24912 amit.gupta 382
							List<ScanRecord> scanRecords = scanRecordRepository.selectByInventoryItemId(ii.getId());
383
							for (ScanRecord scanRecord : scanRecords) {
24915 amit.gupta 384
								CurrentInventorySnapshot cis = currentInventorySnapshotRepository
385
										.selectByItemIdAndFofoId(itemQtyEntry.getKey(), purchase.getFofoId());
386
								scanRecord.setQuantity(0);
387
								ii.setGoodQuantity(0);
388
								quantityToReduce = quantityToReduce - ii.getInitialQuantity();
389
								cis.setAvailability(cis.getAvailability() - ii.getInitialQuantity());
390
								purchase.setUnfullfilledNonSerializedQuantity(
391
										purchase.getUnfullfilledNonSerializedQuantity() + quantityToReduce);
392
								LOGGER.info("Rectified {}, {}, {}, {}, {}, {}", purchase.getPurchaseReference(),
393
										ii.getId(), ii.getItemId(), ii.getInitialQuantity(), ii.getGoodQuantity(),
394
										quantityToReduce);
24711 amit.gupta 395
							}
24641 amit.gupta 396
						}
397
					}
398
				}
399
			}
400
		}
24953 amit.gupta 401
		// throw new Exception();
24641 amit.gupta 402
	}
24767 amit.gupta 403
 
24802 amit.gupta 404
	public void migrateChallansToInvoices() throws Exception {
24814 amit.gupta 405
		Map<String, List<Order>> invoiceOrdersMap = orderRepository.selectAllChallans().stream()
406
				.filter(x -> !x.getLineItem().getHsnCode().equals("NOGST"))
24794 amit.gupta 407
				.collect(Collectors.groupingBy(Order::getInvoiceNumber, Collectors.toList()));
24814 amit.gupta 408
 
25837 amit.gupta 409
		List<List<?>> rows = new ArrayList<>();
24814 amit.gupta 410
		for (String invoice : invoiceOrdersMap.keySet()) {
24794 amit.gupta 411
			Order oneOrder = invoiceOrdersMap.get(invoice).get(0);
412
			int totalOrders = invoiceOrdersMap.get(invoice).size();
413
			LineItem lineItem = oneOrder.getLineItem();
24802 amit.gupta 414
			oneOrder.setBillingTimestamp(LocalDateTime.now());
415
			oneOrder.setInvoiceNumber(getInvoiceNumber(oneOrder));
24819 amit.gupta 416
			rows.add(Arrays.asList(oneOrder.getId(), invoice, oneOrder.getInvoiceNumber(), lineItem.getQuantity()));
24883 amit.gupta 417
			LOGGER.info(invoice + "\t" + oneOrder.getInvoiceNumber() + oneOrder.getId() + "\t",
418
					"\t" + totalOrders + "\t" + lineItem.getQuantity());
24814 amit.gupta 419
			Purchase p = null;
420
			try {
421
				p = purchaseRepository.selectByPurchaseReferenceAndFofoId(invoice, oneOrder.getRetailerId());
422
			} catch (Exception e) {
24815 amit.gupta 423
				LOGGER.info("Could not find purchase for invoice {}", invoice);
24812 amit.gupta 424
			}
24814 amit.gupta 425
			if (p != null) {
426
				List<InventoryItem> inventoryItems = inventoryItemRepository.selectByPurchaseId(p.getId());
427
				for (InventoryItem inventoryItem : inventoryItems) {
24815 amit.gupta 428
					LOGGER.info(inventoryItem.getItemId() + " " + inventoryItem.getGoodQuantity() + " "
24883 amit.gupta 429
							+ inventoryItem.getHsnCode() + " " + inventoryItem.getSerialNumber() + " "
430
							+ p.getPurchaseReference());
24814 amit.gupta 431
				}
432
			}
433
 
24794 amit.gupta 434
		}
24818 amit.gupta 435
		changePartnerInvoices();
24883 amit.gupta 436
		ByteArrayOutputStream baos = FileUtil
437
				.getCSVByteStream(Arrays.asList("Order id", "Challan", "Invoice", "Quantity"), rows);
438
 
24819 amit.gupta 439
		Utils.sendMailWithAttachment(googleMailSender,
440
				new String[] { "amit.gupta@shop2020.in", "sunny.yadav@smartdukaan.com" }, null,
24883 amit.gupta 441
				"Challans Converted to Invoice", "PFA", "Challans-To-Invoice.csv",
442
				new ByteArrayResource(baos.toByteArray()));
24916 amit.gupta 443
		throw new Exception();
24794 amit.gupta 444
	}
24767 amit.gupta 445
 
24802 amit.gupta 446
	private String getInvoiceNumber(Order oneOrder) {
24805 amit.gupta 447
		String prefix = oneOrder.getInvoiceNumber().split("-")[1].replaceAll("\\d*", "");
24803 amit.gupta 448
		System.out.println("Prefix is " + prefix);
24802 amit.gupta 449
		SellerWarehouse sellerWarehouse = sellerWarehouseRepository.selectByPrefix(prefix);
450
		int newSequence = sellerWarehouse.getInvoiceSequence() + 1;
451
		sellerWarehouse.setInvoiceSequence(newSequence);
24814 amit.gupta 452
		return prefix + newSequence;
24802 amit.gupta 453
	}
24814 amit.gupta 454
 
24806 amit.gupta 455
	private void changePartnerInvoices() throws Exception {
24814 amit.gupta 456
		List<FofoOrder> fofoOrders = fofoOrderRepository.selectByInvoiceNumberLike("%SEC%");
457
		for (FofoOrder fofoOrder : fofoOrders) {
24806 amit.gupta 458
			FofoOrderItem fofoOrderItem = fofoOrderItemRepository.selectByOrderId(fofoOrder.getId()).get(0);
24814 amit.gupta 459
			if (fofoOrderItem.getBrand().equals("Vivo")) {
24806 amit.gupta 460
				String challanString = fofoOrder.getInvoiceNumber();
24814 amit.gupta 461
				String storeCode = invoiceNumberGenerationSequenceRepository.selectByFofoId(fofoOrder.getFofoId())
462
						.getPrefix();
24806 amit.gupta 463
				String invoiceNumber = orderService.getInvoiceNumber(fofoOrder.getFofoId(), storeCode);
464
				fofoOrder.setInvoiceNumber(invoiceNumber);
465
				fofoOrder.setCreateTimestamp(LocalDateTime.now());
24818 amit.gupta 466
				LOGGER.info(challanString + "\t" + invoiceNumber + "\t" + fofoOrderItem.getQuantity());
24806 amit.gupta 467
			}
24814 amit.gupta 468
 
24806 amit.gupta 469
		}
470
	}
24802 amit.gupta 471
 
25023 amit.gupta 472
	public void populateSchemes() {
25021 amit.gupta 473
		List<Integer> list05 = Arrays.asList(29093, 29094, 29095, 29096, 29097, 29098, 29099, 29101, 29102);
474
		List<Integer> list10 = Arrays.asList(29187, 29188);
475
		List<Integer> list13 = Arrays.asList(28095, 28097, 28098, 28101, 28102, 28104, 28106, 28107, 28108, 28227,
476
				28228, 28229, 28231, 29055, 29056, 29066, 29079);
477
		List<Integer> list15 = Arrays.asList(20891, 27938, 27939, 27940, 27941, 27943, 27947, 27948, 27953, 27954,
478
				27955, 28220, 28467, 29020, 29033, 29034, 29035, 29592, 29886, 29890, 29891, 29941, 29942, 27445, 27958,
479
				27960, 27961);
480
		List<Integer> list18 = Arrays.asList(28137, 28138, 28140, 28157, 28158, 28161, 28162, 28163, 28164, 28176,
481
				28177, 28178, 28199, 28200, 28208, 28209, 28210, 28211, 28215, 28216, 28217, 28230, 28380, 28381, 28382,
482
				28383, 28384, 28385, 28386, 28387, 28388, 28389, 28390, 28391, 28392, 28395, 28461, 28462, 28463, 28464,
483
				28465, 28466, 28488, 28489, 28490, 28491, 28564, 28565, 28762, 28773, 28871, 28872, 28873, 28874, 28880,
484
				28881, 28914, 28915, 28916, 28917, 28918, 28919, 28920, 29046, 29047, 29048, 29068, 29069, 29110, 29111,
485
				29112, 29113, 29114, 29115, 29116, 29117, 29207, 29208, 29217, 29218, 29225, 29474, 29475, 29476, 29477,
486
				29478, 29479, 29483, 29485, 29486, 29487, 29488, 29739, 29740, 29741, 29742, 29743, 29744, 29745, 29746,
487
				29747, 29748, 29749, 29753, 29756, 29757, 29758, 29760, 29761, 29762, 29763, 29764, 29765, 29766, 29767,
488
				29779, 29780, 29781, 29792, 29793, 29828, 29829, 29830, 29879, 29880, 29881, 29882, 29951);
489
		List<Integer> list20 = Arrays.asList(27975, 27976, 28091, 28363, 29023, 29024, 29025);
490
		List<Integer> list25 = Arrays.asList(28763, 28764, 28765, 29152, 29154, 29157, 29209, 29210, 29601, 29602,
491
				29720, 29721, 29722, 29723, 29725, 29726, 29727);
492
		List<Integer> list30 = Arrays.asList(27962, 27963, 27964, 27965, 27966, 27968, 27969, 28328, 28362, 28566,
493
				28567, 28568, 28571, 28572, 29073, 29074, 29075, 29080, 29081, 29120, 29121, 29122, 29124, 29189, 29190,
494
				29191, 29192, 29193, 29194, 29196, 29197, 29198, 29199, 29515, 29516, 29517, 29675, 29676, 29677, 29678,
495
				29679, 29707, 29708, 29794, 29795, 29883, 29884, 29885, 29887, 29888, 29889, 29931, 29932, 29935, 29936,
496
				29937, 29938, 29939, 29940);
497
		List<Integer> list35 = Arrays.asList(27996, 27998, 29067, 29071, 29643, 29644, 29945, 29946, 29987, 29052,
498
				29053, 29078, 29085, 29086, 29567, 29568, 29569, 29570, 29797, 29914, 29915, 29930, 28877, 28878, 29604,
499
				29605, 29606, 29775, 29776, 29777, 29778, 28862, 28863, 28864, 29026, 29103, 29104, 29105, 28979, 28980,
500
				28981, 28982, 28983, 29002, 29003, 29004, 29834, 29835, 29836, 29837, 29943);
501
		List<Integer> list40 = Arrays.asList(29082, 29083, 28766, 28767, 28768, 28769, 28771);
502
		List<Integer> list45 = Arrays.asList(28026, 28027, 28028, 29528, 29529, 29530, 29534, 29535, 29536, 29538,
503
				29755);
504
		List<Integer> list55 = Arrays.asList(28010, 28011, 28015, 28016, 28019, 28240, 28469, 28470, 28471, 28569,
505
				28570, 28674, 28759, 28761, 28909, 28910, 28911, 28912, 28913, 29108, 29109, 29143, 29144, 29145, 29146,
506
				29211, 29212, 29213, 29214, 29482, 29511, 29512, 29521, 29525, 29526, 29527, 29574, 29575, 29576, 29611,
507
				29612, 29616, 29641, 29642, 29728, 29729, 29750, 29771, 29782, 29783, 29784, 29923, 29924, 29944, 29953,
508
				29992, 29994, 27977, 27978, 28092, 28325, 28326, 28327, 28486, 28487, 29148, 29149, 29150, 29151, 29384,
509
				29385, 29386, 29427, 29489, 29518, 29519, 29520, 29577, 29578, 29579, 29580, 29586, 29660, 29661, 29662,
510
				29663, 29769, 29770, 29790, 29791, 29796, 29928, 29929, 29947, 29948, 28093, 28094, 28556, 28557, 28673,
511
				28867, 28868, 28870, 29089, 29090, 29091, 29106, 29107);
512
		List<Integer> list65 = Arrays.asList(28058, 28223, 28224, 28225, 28226, 28329, 29201, 29202, 29203, 29204,
513
				29205, 29206, 29466, 29467, 29468, 29469, 29470, 29471, 29472, 29573);
514
		Map<Float, List<Integer>> m = new HashMap<>();
515
		m.put(0.5f, list05);
516
		m.put(1.0f, list10);
517
		m.put(1.3f, list13);
518
		m.put(1.5f, list15);
519
		m.put(1.8f, list18);
520
		m.put(2.0f, list20);
521
		m.put(2.5f, list25);
522
		m.put(3.0f, list30);
523
		m.put(3.5f, list35);
524
		m.put(4.0f, list40);
525
		m.put(4.5f, list45);
526
		m.put(5.5f, list55);
527
		m.put(6.5f, list65);
528
		for (Map.Entry<Float, List<Integer>> itemsListEntry : m.entrySet()) {
529
			Scheme s1 = getScheme();
530
			s1.setAmount(itemsListEntry.getKey());
531
			schemeRepository.persist(s1);
25034 amit.gupta 532
			for (Integer itemId : itemsListEntry.getValue()) {
25021 amit.gupta 533
				SchemeItem schemeItem = new SchemeItem();
534
				schemeItem.setItemId(itemId);
535
				schemeItem.setSchemeId(s1.getId());
536
				schemeItemRepository.persist(schemeItem);
537
			}
538
		}
25034 amit.gupta 539
 
25021 amit.gupta 540
	}
541
 
542
	private Scheme getScheme() {
543
		Scheme s = new Scheme();
544
		s.setName("List Price Margin");
545
		s.setDescription("List Price Margin");
546
		s.setActiveTimestamp(null);
547
		s.setStartDateTime(LocalDate.of(2019, 6, 1).atStartOfDay());
548
		s.setEndDateTime(LocalDate.of(2019, 7, 1).atStartOfDay());
549
		s.setAmountType(AmountType.PERCENTAGE);
550
		s.setCreateTimestamp(LocalDateTime.now());
551
		s.setExpireTimestamp(null);
552
		s.setCreatedBy(175120474);
553
		return s;
554
	}
555
 
24957 amit.gupta 556
	public void findMismatchesInIndent() throws Exception {
557
		List<Order> allInProcessOrders = orderRepository.selectAllOrder(OrderStatus.SUBMITTED_FOR_PROCESSING);
24967 amit.gupta 558
 
25021 amit.gupta 559
		Map<String, Integer> lineItemWhQtyMap = allInProcessOrders.stream()
25734 amit.gupta 560
				.collect(Collectors.groupingBy(y -> y.getLineItem().getItemId() + "-" + y.getFulfilmentWarehouseId(),
24967 amit.gupta 561
						Collectors.summingInt(y -> y.getLineItem().getQuantity())));
25021 amit.gupta 562
 
563
		lineItemWhQtyMap.forEach((key, value) -> {
564
 
24967 amit.gupta 565
			int itemId = Integer.parseInt(key.split("-")[0]);
566
			int warehouseId = Integer.parseInt(key.split("-")[1]);
25021 amit.gupta 567
			System.out.printf("%d\t%d\t%d\n", itemId, warehouseId, value);
568
			SaholicInventorySnapshot cis = saholicInventorySnapshotRepository.selectByWarehouseIdandItemId(warehouseId,
569
					itemId);
570
			if (cis == null) {
24970 amit.gupta 571
				cis = new SaholicInventorySnapshot();
572
				cis.setItemId(itemId);
573
				cis.setWarehouseId(warehouseId);
574
				cis.setAvailability(0);
575
				saholicInventorySnapshotRepository.persist(cis);
576
			}
24967 amit.gupta 577
			cis.setReserved(value);
578
		});
24953 amit.gupta 579
	}
580
 
25034 amit.gupta 581
	public void fixSchemePayouts() throws Exception {
25524 amit.gupta 582
		LOGGER.info("In fix scheme Payouts");
25522 amit.gupta 583
		LocalDateTime startDate = LocalDate.of(2019, 9, 1).atStartOfDay();
584
		List<SchemeInOut> sios = schemeInOutRepository.selectAllByCreateDate(startDate, LocalDateTime.now());
25530 amit.gupta 585
 
25034 amit.gupta 586
		for (SchemeInOut sio : sios) {
25530 amit.gupta 587
			if (sio.getSchemeId() != 347) {
25523 amit.gupta 588
				LOGGER.info("Skipping {}", sio.getSchemeId());
25522 amit.gupta 589
				continue;
590
			}
25043 amit.gupta 591
			genericRepository.delete(sio);
25522 amit.gupta 592
			InventoryItem ii = inventoryItemRepository.selectById(sio.getInventoryItemId());
593
			UserWallet userWallet = userWalletRepository.selectByRetailerId(ii.getFofoId());
594
			Scheme scheme = schemeRepository.selectById(sio.getSchemeId());
595
			if (scheme.getType().equals(SchemeType.IN)) {
596
				List<UserWalletHistory> historyList = userWalletHistoryRepository
597
						.selectAllByreferenceIdandreferenceType(ii.getPurchaseId(), WalletReferenceType.SCHEME_IN);
598
				for (UserWalletHistory uwh : historyList) {
25530 amit.gupta 599
					if (uwh.getTimestamp().isAfter(startDate)) {
25522 amit.gupta 600
						genericRepository.delete(uwh);
601
						userWallet.setAmount(userWallet.getAmount() - uwh.getAmount());
602
					}
603
				}
604
			} else {
605
				List<ScanRecord> scanRecords = scanRecordRepository.selectByInventoryItemId(ii.getId());
606
				int orderId = scanRecords.get(0).getOrderId();
607
				List<UserWalletHistory> historyList = userWalletHistoryRepository
608
						.selectAllByreferenceIdandreferenceType(orderId, WalletReferenceType.SCHEME_OUT);
609
				for (UserWalletHistory uwh : historyList) {
25530 amit.gupta 610
					if (uwh.getTimestamp().isAfter(startDate)) {
25522 amit.gupta 611
						userWallet.setAmount(userWallet.getAmount() - uwh.getAmount());
612
						genericRepository.delete(uwh);
613
					}
614
				}
615
				List<UserWalletHistory> historyListBroken = userWalletHistoryRepository
25530 amit.gupta 616
						.selectAllByreferenceIdandreferenceType(ii.getPurchaseId(), WalletReferenceType.SCHEME_OUT);
25522 amit.gupta 617
				for (UserWalletHistory uwh : historyListBroken) {
25530 amit.gupta 618
					if (uwh.getTimestamp().isAfter(startDate)) {
25522 amit.gupta 619
						genericRepository.delete(uwh);
620
						userWallet.setAmount(userWallet.getAmount() - uwh.getAmount());
621
					}
622
				}
623
			}
624
 
25530 amit.gupta 625
			// System.out.println("Total Amount Rolled Back is " + totalRollbackAmount);
25516 amit.gupta 626
		}
25589 amit.gupta 627
		scheduledTasks.processScheme(startDate, startDate.plusDays(10), true);
25030 amit.gupta 628
	}
25530 amit.gupta 629
 
630
	public void fixWallet() throws Exception {
631
		List<FofoStore> fofoStores = fofoStoreRepository.selectAll();
25536 amit.gupta 632
		System.out.println("id\tcode\tactive\tname\tcity\tstate\twallet amount\tsum\twallet amount-sum");
25530 amit.gupta 633
		for (FofoStore fofoStore : fofoStores) {
634
			UserWallet uw = userWalletRepository.selectByRetailerId(fofoStore.getId());
635
			User user = userRepository.selectById(fofoStore.getId());
25749 amit.gupta 636
			if (user == null) {
25533 amit.gupta 637
				LOGGER.info("store does not exist", fofoStore.getCode());
25535 amit.gupta 638
				continue;
25533 amit.gupta 639
			}
25536 amit.gupta 640
			Address address = null;
641
			try {
642
				address = addressRepository.selectById(user.getAddressId());
25749 amit.gupta 643
			} catch (Exception e) {
25536 amit.gupta 644
				LOGGER.info("Could not find address for Store", fofoStore.getCode());
645
				address = new Address();
646
			}
25539 amit.gupta 647
			double sum = userWalletHistoryRepository.selectSumByWallet(uw.getId());
25749 amit.gupta 648
			int calculated = (int) sum;
649
			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(),
650
					fofoStore.isActive(), address.getName(), address.getCity(), address.getState(), uw.getAmount(),
651
					calculated, uw.getAmount() - calculated);
25530 amit.gupta 652
		}
653
	}
25749 amit.gupta 654
 
25734 amit.gupta 655
	public void changeWarehouse() throws Exception {
656
		transactionService.moveWarehouses();
657
	}
25749 amit.gupta 658
 
659
	public void mailDashboardScreenshots() throws Exception {
660
		System.setProperty("webdriver.chrome.driver", "/usr/bin/chromedriver");
661
 
25752 amit.gupta 662
		ChromeOptions options = new ChromeOptions();
663
		options.addArguments("--headless");
664
		options.addArguments("--no-sandbox");
665
		options.addArguments("start-maximized");
666
		options.addArguments("disable-infobars");
667
		options.addArguments("--disable-extensions");
668
 
25753 amit.gupta 669
		WebDriver driver = new ChromeDriver(options);
25774 amit.gupta 670
		driver.manage().window().setSize(new Dimension(1600, 900));
25749 amit.gupta 671
		driver.manage().window().maximize();
25752 amit.gupta 672
		// Deleting all the cookies
25749 amit.gupta 673
		driver.manage().deleteAllCookies();
25752 amit.gupta 674
		// Specifiying pageLoadTimeout and Implicit wait
25749 amit.gupta 675
		driver.manage().timeouts().pageLoadTimeout(40, TimeUnit.SECONDS);
676
		driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
25752 amit.gupta 677
 
25749 amit.gupta 678
		Map<String, Set<Integer>> authUserPartnerIdMapping = csService.getAuthUserPartnerIdMapping();
679
		Set<Integer> allPartners = new HashSet<>();
25765 amit.gupta 680
		Map<Integer, File> partnerSnapshotMap = new HashMap<>();
25752 amit.gupta 681
		authUserPartnerIdMapping.values().stream().forEach(x -> allPartners.addAll(x));
25749 amit.gupta 682
		System.out.println(allPartners.size());
25752 amit.gupta 683
		for (int fofoId : allPartners) {
25749 amit.gupta 684
			driver.get("https://partners.smartdukaan.com/12dashboard34?fofoId=" + fofoId);
25765 amit.gupta 685
			File file = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
686
			partnerSnapshotMap.put(fofoId, file);
25752 amit.gupta 687
 
25749 amit.gupta 688
		}
25752 amit.gupta 689
		for (Map.Entry<String, Set<Integer>> entry : authUserPartnerIdMapping.entrySet()) {
25749 amit.gupta 690
			String email = entry.getKey();
25996 amit.gupta 691
			LOGGER.info("Sending mail start to {}", email);
25749 amit.gupta 692
			Set<Integer> partnerIds = entry.getValue();
693
			StringBuffer body = new StringBuffer();
25769 amit.gupta 694
			Map<Integer, File> emailSnapshotMap = new HashMap<>();
25752 amit.gupta 695
			for (int fofoId : partnerIds) {
25769 amit.gupta 696
				body.append(String.format("<br/><img src=\"cid:%d\"/>", fofoId));
697
				emailSnapshotMap.put(fofoId, partnerSnapshotMap.get(fofoId));
25749 amit.gupta 698
			}
25837 amit.gupta 699
			Utils.sendEmbeddedHtmlMail(mailSender, new String[] { email }, new String[] {},
25752 amit.gupta 700
					String.format("Franchise Screenshots - %s", FormattingUtils.formatDate(LocalDateTime.now())),
25837 amit.gupta 701
					body.toString(), emailSnapshotMap);
25996 amit.gupta 702
			LOGGER.info("Sent mail to {}", email);
25749 amit.gupta 703
		}
704
		driver.quit();
705
	}
26033 amit.gupta 706
 
26299 amit.gupta 707
	// Rollout prebooking orders amount in case the order is grned.
26033 amit.gupta 708
	public void pbfix() throws ProfitMandiBusinessException {
709
		List<Item> items = itemRepository.selectAllByCatalogItemId(1022304);
26299 amit.gupta 710
		for (Item item : items) {
26033 amit.gupta 711
			List<InventoryItem> inventoryItems = inventoryItemRepository.selectByItemId(item.getId(), 0, 500);
26299 amit.gupta 712
			for (InventoryItem inventoryItem : inventoryItems) {
26033 amit.gupta 713
				List<PrebookingOrder> prebookingOrders = prebookingOrderRepository
26299 amit.gupta 714
						.selectByFofoIdAndCatalogIds(inventoryItem.getFofoId(), item.getCatalogItemId()).stream()
715
						.collect(Collectors.toList());
716
				if (prebookingOrders.size() > 0) {
717
					purchaseService.sendPrebookingNotifyMessage(prebookingOrders.get(0));
26033 amit.gupta 718
				}
26299 amit.gupta 719
				// inventoryItem.getFofoId()
26033 amit.gupta 720
			}
721
		}
26299 amit.gupta 722
		// throw new ProfitMandiBusinessException("", "", "");
723
		// prebookingOrderRepository.select
26033 amit.gupta 724
		// TODO Auto-generated method stub
26299 amit.gupta 725
 
26033 amit.gupta 726
	}
26092 amit.gupta 727
 
26299 amit.gupta 728
	public void fixGrn() throws Exception {
26092 amit.gupta 729
		List<Purchase> incompletePurchases = purchaseRepository.selectIncompletePurchase();
26299 amit.gupta 730
		for (Purchase incompletePurchase : incompletePurchases) {
731
			List<Order> orders = orderRepository.selectByAirwayBillOrInvoiceNumber(
732
					incompletePurchase.getPurchaseReference(), incompletePurchase.getFofoId());
26093 amit.gupta 733
			List<InventoryItem> inventoryItems = inventoryItemRepository.selectByPurchaseId(incompletePurchase.getId());
734
			Map<Integer, Integer> grnedItems = inventoryItems.stream().collect(
26299 amit.gupta 735
					Collectors.groupingBy(x -> x.getItemId(), Collectors.summingInt(x -> x.getInitialQuantity())));
736
			Map<Integer, Integer> billedItems = orders.stream().collect(Collectors.groupingBy(
737
					x -> x.getLineItem().getItemId(), Collectors.summingInt(x -> x.getLineItem().getQuantity())));
738
			for (Integer billedItemId : billedItems.keySet()) {
739
				if (grnedItems.containsKey(billedItemId)) {
740
					if (grnedItems.get(billedItemId) > billedItems.get(billedItemId)) {
741
						LOGGER.info("Billed Qty {} ---- Grned {}, ItemId {}, Invoice Number {}({}), Grn Date {}",
742
								billedItems.get(billedItemId), grnedItems.get(billedItemId), billedItemId,
743
								incompletePurchase.getPurchaseReference(), incompletePurchase.getId(),
744
								incompletePurchase.getCreateTimestamp());
26095 amit.gupta 745
						Item item = itemRepository.selectById(billedItemId);
26299 amit.gupta 746
						if (item.getType().equals(ItemType.SERIALIZED)) {
747
 
26096 amit.gupta 748
						} else {
26299 amit.gupta 749
							for (InventoryItem inventoryItem : inventoryItems) {
750
								if (inventoryItem.getItemId() == billedItemId && inventoryItem.getGoodQuantity() == 0) {
751
									List<ScanRecord> scanRecords = scanRecordRepository
752
											.selectByInventoryItemId(inventoryItem.getId());
753
									if (scanRecords.size() == 1 && scanRecords.get(0).getQuantity() == 0) {
26096 amit.gupta 754
										LOGGER.info("Safe to remove InventoryItem Id {}", inventoryItem.getId());
26101 amit.gupta 755
										scanRecordRepository.delete(scanRecords.get(0));
756
										inventoryItemRepository.delete(inventoryItem);
26299 amit.gupta 757
										incompletePurchase.setUnfullfilledNonSerializedQuantity(
758
												incompletePurchase.getUnfullfilledNonSerializedQuantity()
759
														+ inventoryItem.getInitialQuantity());
26096 amit.gupta 760
									}
761
								}
762
							}
26095 amit.gupta 763
						}
26093 amit.gupta 764
					}
765
				}
26092 amit.gupta 766
			}
26299 amit.gupta 767
 
26092 amit.gupta 768
		}
26299 amit.gupta 769
 
26092 amit.gupta 770
	}
26265 amit.gupta 771
 
772
	public void fixDupGrns() throws Exception {
26412 amit.gupta 773
		List<Integer> duplicatePurchaseIds = Arrays.asList(14984);
26299 amit.gupta 774
		for (int duplicatePurchaseId : duplicatePurchaseIds) {
26265 amit.gupta 775
			Purchase purchase = purchaseRepository.selectById(duplicatePurchaseId);
776
			List<InventoryItem> inventoryItems = inventoryItemRepository.selectByPurchaseId(duplicatePurchaseId);
26299 amit.gupta 777
			if (inventoryItems.size() == 0) {
26266 amit.gupta 778
				LOGGER.info("Could not find InventoryItems for {}", duplicatePurchaseId);
779
				continue;
780
			}
26299 amit.gupta 781
			schemeService.rollbackSchemes(inventoryItems.stream().map(x -> x.getId()).collect(Collectors.toList()),
782
					duplicatePurchaseId,
783
					"Rolled back duplicate grn for Purchase Invoice " + purchase.getPurchaseReference());
784
			for (InventoryItem inventoryItem : inventoryItems) {
26265 amit.gupta 785
				inventoryItemRepository.delete(inventoryItem);
786
				List<ScanRecord> scanRecords = scanRecordRepository.selectByInventoryItemId(inventoryItem.getId());
26299 amit.gupta 787
				for (ScanRecord scanRecord : scanRecords) {
26265 amit.gupta 788
					scanRecordRepository.delete(scanRecord);
789
				}
26299 amit.gupta 790
				List<SchemeInOut> sios = schemeInOutRepository
791
						.selectByInventoryItemIds(new HashSet<>(Arrays.asList(inventoryItem.getId())));
792
				for (SchemeInOut sio : sios) {
26265 amit.gupta 793
					LOGGER.info("SIO - {}", sio);
794
					schemeInOutRepository.delete(sio);
795
				}
26299 amit.gupta 796
 
26265 amit.gupta 797
			}
798
		}
26299 amit.gupta 799
		// throw new Exception();
26265 amit.gupta 800
	}
26579 amit.gupta 801
 
802
	public void mongom() {
803
		List<TagListing> tls = tagListingRepository.selectAll(false);
804
		Set<Integer> itemIds = tls.stream().map(x -> x.getItemId()).collect(Collectors.toSet());
805
		Set<Integer> catalogIds = itemRepository.selectByIds(itemIds).stream().map(x -> x.getCatalogItemId())
806
				.collect(Collectors.toSet());
807
		for (int catalogId : catalogIds) {
808
			try {
809
				ContentPojo cp = mongoClient.getEntityById(catalogId);
26580 amit.gupta 810
				try {
811
					cp.setIconImageUrl(cp.getIconImageUrl().replace("saholic", "smartdukaan"));
26759 amit.gupta 812
				} catch (Exception e) {
813
 
26580 amit.gupta 814
				}
26759 amit.gupta 815
 
26580 amit.gupta 816
				try {
817
					cp.setThumbnailImageUrl(cp.getThumbnailImageUrl().replace("saholic", "smartdukaan"));
26759 amit.gupta 818
				} catch (Exception e) {
819
 
26580 amit.gupta 820
				}
26759 amit.gupta 821
 
26579 amit.gupta 822
				cp.setDefaultImageUrl(cp.getDefaultImageUrl().replace("saholic", "smartdukaan"));
823
				List<MediaPojo> mPojos = cp.getImages();
26759 amit.gupta 824
				if (mPojos != null) {
26580 amit.gupta 825
					mPojos.stream().forEach(mPojo -> {
826
						mPojo.setUrl(mPojo.getUrl().replace("saholic", "smartdukaan"));
827
					});
828
				}
26579 amit.gupta 829
				mongoClient.persistEntity(cp);
830
			} catch (Exception e) {
831
				continue;
832
			}
833
		}
834
	}
26759 amit.gupta 835
 
836
	public void cancelDn(String debitNoteNumber) throws Exception {
837
		DebitNote debitNote = debitNoteRepository.selectDebitNoteByNumber(debitNoteNumber);
26928 amit.gupta 838
 
839
		List<PurchaseReturnItem> purchaseReturnItems = purchaseReturnItemRepository
840
				.selectAllByDebitNoteId(debitNote.getId());
26759 amit.gupta 841
		// Select all inventory Item
842
		Set<Integer> inventoryItemIds = purchaseReturnItems.stream().map(x -> x.getInventoryItemId())
843
				.collect(Collectors.toSet());
844
		List<InventoryItem> inventoryItems = inventoryItemRepository.selectByIds(inventoryItemIds);
845
		for (InventoryItem inventoryItem : inventoryItems) {
846
			if (!StringUtils.isEmpty(inventoryItem.getSerialNumber())) {
847
				inventoryItem.setGoodQuantity(1);
848
				inventoryItem.setLastScanType(ScanType.PURCHASE);
849
				ScanRecord sr = scanRecordRepository.selectByInventoryItemId(inventoryItem.getId()).stream()
850
						.filter(x -> x.getType().equals(ScanType.PURCHASE_RET)).findFirst().get();
851
				scanRecordRepository.delete(sr);
852
				CurrentInventorySnapshot cis = currentInventorySnapshotRepository
853
						.selectByItemAndFofoId(inventoryItem.getItemId(), inventoryItem.getFofoId());
854
				if (cis == null) {
855
					cis = new CurrentInventorySnapshot();
856
					cis.setFofoId(inventoryItem.getFofoId());
857
					cis.setItemId(inventoryItem.getId());
858
					currentInventorySnapshotRepository.persist(cis);
859
				}
860
				cis.setAvailability(cis.getAvailability() + 1);
861
				schemeService.processSchemeIn(inventoryItem.getPurchaseId(), inventoryItem.getFofoId());
862
			}
26928 amit.gupta 863
		}
864
		purchaseReturnItems.stream().forEach(x -> purchaseReturnItemRepository.delete(x));
26759 amit.gupta 865
	}
26799 amit.gupta 866
 
867
	public void processPd(int priceDropId) throws ProfitMandiBusinessException {
27079 amit.gupta 868
		priceDropService.processPriceDrop(priceDropId, false);
26799 amit.gupta 869
	}
26928 amit.gupta 870
 
871
	public void fixScheme() throws Exception {
26936 amit.gupta 872
		LOGGER.info("Partner Types found\tPartnerType To Remove\tAmout to Rollback");
26928 amit.gupta 873
		final Map<Integer, Scheme> schemesMap = schemeRepository.selectAll().stream()
874
				.collect(Collectors.toMap(x -> x.getId(), x -> x));
875
		List<SchemeInOut> sios = schemeInOutRepository.selectAllByCreateDate(LocalDate.of(2019, 9, 1).atTime(0, 0),
876
				LocalDateTime.now());
27221 amit.gupta 877
		Map<SioTuple, Map<PartnerType, List<SchemeInOut>>> schemeTupleMap = sios.stream()
878
				.filter(x -> x.getRolledBackTimestamp() == null)
26928 amit.gupta 879
				.filter(x -> schemesMap.get(x.getSchemeId()).getPartnerType() != PartnerType.ALL)
880
				.collect(Collectors.groupingBy(
881
						x -> new SioTuple(x.getInventoryItemId(), schemesMap.get(x.getSchemeId()).getType()),
27221 amit.gupta 882
						Collectors.groupingBy(x -> schemesMap.get(x.getSchemeId()).getPartnerType(),
883
								Collectors.mapping(x -> x, Collectors.toList()))));
884
 
885
		schemeTupleMap.entrySet().stream().filter(x -> x.getValue().size() > 1).forEach(x -> {
26929 amit.gupta 886
			Map<PartnerType, List<SchemeInOut>> partnerTypeSchemeMap = x.getValue();
27221 amit.gupta 887
			PartnerType partnerTypeToRemove = partnerTypeSchemeMap.keySet().stream()
888
					.min(Comparator.comparing(y -> PartnerType.PartnerTypeRankMap.get(y))).get();
889
			LOGGER.info("{}\t{}\t{}\t{}\t{}\t{}", partnerTypeSchemeMap.keySet(), partnerTypeToRemove,
890
					partnerTypeSchemeMap.get(partnerTypeToRemove).stream()
891
							.collect(Collectors.summingDouble(SchemeInOut::getAmount)),
892
					FormattingUtils.formatDate(partnerTypeSchemeMap.get(partnerTypeToRemove).stream()
893
							.map(y -> y.getCreateTimestamp()).findFirst().get()));
894
 
26928 amit.gupta 895
		});
896
	}
897
 
898
	private class SioTuple {
899
		int inventoryId;
900
		SchemeType schemeType;
901
 
902
		public SioTuple(int inventoryItemId, SchemeType schemeType) {
903
			this.inventoryId = inventoryItemId;
904
			this.schemeType = schemeType;
905
		}
906
 
907
		public int getInventoryId() {
908
			return inventoryId;
909
		}
910
 
911
		public void setInventoryId(int inventoryId) {
912
			this.inventoryId = inventoryId;
913
		}
914
 
915
		public SchemeType getSchemeType() {
916
			return schemeType;
917
		}
918
 
919
		public void setSchemeType(SchemeType schemeType) {
920
			this.schemeType = schemeType;
921
		}
922
 
923
		@Override
924
		public int hashCode() {
925
			final int prime = 31;
926
			int result = 1;
927
			result = prime * result + getOuterType().hashCode();
928
			result = prime * result + inventoryId;
929
			result = prime * result + ((schemeType == null) ? 0 : schemeType.hashCode());
930
			return result;
931
		}
932
 
933
		@Override
934
		public boolean equals(Object obj) {
935
			if (this == obj)
936
				return true;
937
			if (obj == null)
938
				return false;
939
			if (getClass() != obj.getClass())
940
				return false;
941
			SioTuple other = (SioTuple) obj;
942
			if (!getOuterType().equals(other.getOuterType()))
943
				return false;
944
			if (inventoryId != other.inventoryId)
945
				return false;
946
			if (schemeType != other.schemeType)
947
				return false;
948
			return true;
949
		}
950
 
951
		private RunOnceTasks getOuterType() {
952
			return RunOnceTasks.this;
953
		}
954
 
955
	}
27221 amit.gupta 956
 
957
	public void printPendingLeads() {
27277 amit.gupta 958
		LOGGER.info("PENDING LEADES {}", leadRepository
959
				.selectLeadsScheduledBetweenDate(LocalDateTime.now().minusDays(15), LocalDateTime.now().plusHours(4)));
27221 amit.gupta 960
	}
27277 amit.gupta 961
 
27286 amit.gupta 962
	public void removeDuplicateOrders() throws Exception {
27451 tejbeer 963
		List<String> invoiceNumbers = Arrays.asList(/*
964
													 * "DLWE066/1108", "DLWE066/299", "DLWE066/348", "HRFB004/242",
965
													 * "HRFB004/243", "HRFB004/514", "HRFTB155/29", "HRJND076/1146",
966
													 * "HRJND076/966", "HRKA134/295", "HRKA134/421", "HRKK091/381",
967
													 * "HRMGH106/576", "HRSP056/139", "HRYN030/103", "UPGZ019/395",
968
													 * "UPHRD130/1299", "UPHRD130/456", "UPHRD130/634", "UPLKO063/897",
969
													 * "UPMRT149/54", "UPSJP119/748", "UPSJP119/980", "UPSTP065/1218",
970
													 * "UPSTP065/2039", "UPSTP090/437", "UPSTP120/164",
971
													 */
27312 amit.gupta 972
				"HRMGH106/1576");
27451 tejbeer 973
 
27288 amit.gupta 974
		int totalAmount = 0;
975
		float saleAmount = 0;
27289 amit.gupta 976
		float schemeReverseAmount = 0;
27451 tejbeer 977
		for (String invoiceNumber : invoiceNumbers) {
27281 amit.gupta 978
			List<FofoOrder> orders = fofoOrderRepository.selectByInvoiceNumberLike(invoiceNumber);
27283 amit.gupta 979
			orders = orders.stream().skip(1).collect(Collectors.toList());
27286 amit.gupta 980
			for (FofoOrder fofoOrder : orders) {
27295 amit.gupta 981
				LOGGER.info("Fofo Order Id - {}, Invoice {}", fofoOrder.getId(), invoiceNumber);
27286 amit.gupta 982
				int inventoryItemId = 0;
27288 amit.gupta 983
				saleAmount += fofoOrder.getTotalAmount();
27297 amit.gupta 984
				fofoOrderRepository.delete(fofoOrder);
27302 amit.gupta 985
				LOGGER.info("Fofo Order Id - {}, Invoice {}", fofoOrder.getId(), invoiceNumber);
27286 amit.gupta 986
				List<FofoOrderItem> fofoOrderItems = fofoOrderItemRepository.selectByOrderId(fofoOrder.getId());
27451 tejbeer 987
				List<PaymentOptionTransaction> paymentOptionTransactions = paymentOptionTransactionRepository
988
						.selectByReferenceIdAndType(fofoOrder.getId(), PaymentOptionReferenceType.ORDER);
989
				for (PaymentOptionTransaction paymentOptionTransaction : paymentOptionTransactions) {
27297 amit.gupta 990
					paymentOptionTransactionRepository.delete(paymentOptionTransaction);
27286 amit.gupta 991
				}
27451 tejbeer 992
				for (FofoOrderItem foi : fofoOrderItems) {
27302 amit.gupta 993
					List<FofoLineItem> flis = fofoLineItemRepository.selectByFofoOrderItemId(foi.getId());
27297 amit.gupta 994
					fofoOrderItemRepository.delete(foi);
27451 tejbeer 995
					for (FofoLineItem fli : flis) {
27302 amit.gupta 996
						inventoryItemId = fli.getInventoryItemId();
27297 amit.gupta 997
						fofoLineItemRepository.delete(fli);
27286 amit.gupta 998
					}
999
				}
27451 tejbeer 1000
				// Rollback entry with reversal reason
1001
				if (fofoOrder.getCreateTimestamp().isAfter(LocalDate.of(2020, 4, 1).atStartOfDay())) {
27293 amit.gupta 1002
					float invoiceSchemeReversalAmount = 0;
27451 tejbeer 1003
					List<UserWalletHistory> userWalletHistory = userWalletHistoryRepository
1004
							.selectAllByreferenceIdandreferenceType(fofoOrder.getId(), WalletReferenceType.SCHEME_OUT);
1005
					float invoiceWalletAmount = userWalletHistory.stream()
1006
							.collect(Collectors.summingInt(y -> y.getAmount()));
27303 amit.gupta 1007
					totalAmount += invoiceWalletAmount;
27299 amit.gupta 1008
					try {
27451 tejbeer 1009
						walletService.rollbackAmountFromWallet(fofoOrder.getFofoId(), invoiceWalletAmount,
1010
								fofoOrder.getId(), WalletReferenceType.SCHEME_OUT,
1011
								"Same order for Invoice-" + invoiceNumber + "created twice, duplicate invoice rollback",
1012
								fofoOrder.getCancelledTimestamp());
27299 amit.gupta 1013
					} catch (Exception e) {
1014
						LOGGER.info("Failed wallet update Reson [{}]", e.getMessage());
1015
					}
27301 amit.gupta 1016
					LOGGER.info("inventoryItemId - {}", inventoryItemId);
27451 tejbeer 1017
					List<SchemeInOut> schemeInOuts = schemeInOutRepository
1018
							.selectByInventoryItemIds(new HashSet<>(Arrays.asList(inventoryItemId)));
27292 amit.gupta 1019
					Set<Integer> schemeIds = new HashSet<>();
27298 amit.gupta 1020
					Set<Integer> schemeIdsRolledback = new HashSet<>();
27451 tejbeer 1021
					for (SchemeInOut sio : schemeInOuts) {
1022
						if (Math.abs(sio.getCreateTimestamp().until(fofoOrder.getCreateTimestamp(),
1023
								ChronoUnit.MINUTES)) <= 35 && sio.getRolledBackTimestamp() == null) {
27289 amit.gupta 1024
							LOGGER.info(sio);
27451 tejbeer 1025
							if (!schemeIds.contains(sio.getSchemeId())) {
27292 amit.gupta 1026
								schemeIds.add(sio.getSchemeId());
27298 amit.gupta 1027
							} else if (!schemeIdsRolledback.contains(sio.getSchemeId())) {
1028
								schemeIdsRolledback.add(sio.getSchemeId());
27297 amit.gupta 1029
								sio.setRolledBackTimestamp(LocalDateTime.now());
27292 amit.gupta 1030
								schemeReverseAmount += sio.getAmount();
27293 amit.gupta 1031
								invoiceSchemeReversalAmount += sio.getAmount();
27292 amit.gupta 1032
							}
27289 amit.gupta 1033
						}
27286 amit.gupta 1034
					}
27451 tejbeer 1035
					if (Math.abs(invoiceWalletAmount - invoiceSchemeReversalAmount) > 3) {
27303 amit.gupta 1036
						LOGGER.info("No Matchhhh");
1037
					}
27451 tejbeer 1038
					LOGGER.info("invoiceWalletAmount - {}, invoiceSchemeReversalAmount {}", invoiceWalletAmount,
1039
							invoiceSchemeReversalAmount);
1040
				}
27283 amit.gupta 1041
			}
27277 amit.gupta 1042
		}
27451 tejbeer 1043
		LOGGER.info(
1044
				"Total Sale Amount Reversal - {}, Total Wallet Amount Reversal {}, Total Scheme Reversal Amount - {}",
1045
				saleAmount, totalAmount, schemeReverseAmount);
1046
		// throw new Exception();
27277 amit.gupta 1047
	}
27430 amit.gupta 1048
 
27450 tejbeer 1049
	public void createGeofence() throws IOException, ProfitMandiBusinessException {
1050
 
27486 tejbeer 1051
		// List<FofoStore> fofoStores = fofoStoreRepository.selectActiveStores();
1052
		// for (FofoStore fofoStore : fofoStores) {
1053
		// if (fofoStore.getLatitude() != null && fofoStore.getLongitude() != null) {
27503 tejbeer 1054
		CustomRetailer customRetailer = retailerService.getFofoRetailer(175138812);
27486 tejbeer 1055
		OkHttpClient client = new OkHttpClient();
1056
		okhttp3.MediaType mediaType = okhttp3.MediaType.parse("application/json");
1057
		JSONObject geofe = new JSONObject();
1058
		JSONArray geofences = new JSONArray();
1059
		JSONObject geometry = new JSONObject();
1060
		JSONObject geo = new JSONObject();
1061
		JSONArray coordinates = new JSONArray();
1062
		ArrayList<Double> crds = new ArrayList<>();
1063
		// crds.add(Double.parseDouble(fofoStore.getLongitude()));
1064
		// crds.add(Double.parseDouble(fofoStore.getLatitude()));
27503 tejbeer 1065
		crds.add(79.739197);
1066
		crds.add(27.961215);
27486 tejbeer 1067
		// crds.add(77.08596155373755);
1068
		// crds.add(28.64944201113976);
1069
		// coordinates.put(fofoStore.getLongitude());
1070
		// coordinates.put(fofoStore.getLatitude());
1071
		geo.put("type", "Point");
1072
		geo.put("coordinates", crds);
1073
		geometry.put("geometry", geo);
1074
		JSONObject metadata = new JSONObject();
27503 tejbeer 1075
		metadata.put("name", customRetailer.getBusinessName());
1076
		metadata.put("city", customRetailer.getAddress().getCity());
1077
		metadata.put("Code", customRetailer.getCode());
27487 tejbeer 1078
		geometry.put("metadata", metadata);
27486 tejbeer 1079
		geometry.put("radius", 200);
27451 tejbeer 1080
 
27486 tejbeer 1081
		geofences.put(geometry);
1082
		geofe.put("geofences", geofences);
1083
		okhttp3.RequestBody body = okhttp3.RequestBody.create(mediaType, geofe.toString());
1084
		String authString = "Basic "
1085
				+ Base64.getEncoder().encodeToString(String.format("%s:%s", ACCOUNT_ID, SECRET_KEY).getBytes());
27450 tejbeer 1086
 
27486 tejbeer 1087
		Request request1 = new Request.Builder().url("https://v3.api.hypertrack.com/geofences").post(body)
1088
				.addHeader("Authorization", authString).build();
27450 tejbeer 1089
 
27486 tejbeer 1090
		Response response = client.newCall(request1).execute();
27450 tejbeer 1091
 
27486 tejbeer 1092
		JSONArray ja = new JSONArray(response.body().string());
1093
		LOGGER.info("geofence" + ja);
1094
		LOGGER.info("jalength" + ja.length());
1095
		/*
1096
		 * for (int i = 0; i < ja.length(); i++) { JSONObject c = ja.getJSONObject(i);
1097
		 * String geofenceId = c.getString("geofence_id"); LOGGER.info("geofenceId" +
1098
		 * geofenceId); FofoStoreGeofence fsg = new FofoStoreGeofence();
1099
		 * fsg.setFofoId(customRetailer.getPartnerId()); fsg.setGeofenceId(geofenceId);
1100
		 * fofoStoreGeofenceRepository.persist(fsg); }
1101
		 * 
1102
		 * }
1103
		 * 
1104
		 * }
1105
		 */
27482 tejbeer 1106
 
27462 tejbeer 1107
	}
1108
 
27451 tejbeer 1109
	public void getAllGeofences() throws IOException, ProfitMandiBusinessException {
27450 tejbeer 1110
 
1111
		OkHttpClient client = new OkHttpClient();
1112
 
1113
		String authString = "Basic "
1114
				+ Base64.getEncoder().encodeToString(String.format("%s:%s", ACCOUNT_ID, SECRET_KEY).getBytes());
1115
 
1116
		// Get geofences created for all app users
1117
		Request request1 = new Request.Builder().url("https://v3.api.hypertrack.com/geofences")
1118
				.addHeader("Authorization", authString).build();
1119
 
1120
		Response response = client.newCall(request1).execute();
27451 tejbeer 1121
 
27450 tejbeer 1122
		LOGGER.info("response" + response.body().string());
1123
	}
1124
 
27457 tejbeer 1125
	public void deleteGeofences(List<String> geofenceIds) throws IOException, ProfitMandiBusinessException {
1126
		OkHttpClient client = new OkHttpClient();
1127
 
1128
		String authString = "Basic "
1129
				+ Base64.getEncoder().encodeToString(String.format("%s:%s", ACCOUNT_ID, SECRET_KEY).getBytes());
1130
 
1131
		for (String geofenceId : geofenceIds) {
27460 tejbeer 1132
			Request request1 = new Request.Builder().url("https://v3.api.hypertrack.com/geofences/" + geofenceId)
27457 tejbeer 1133
					.delete().addHeader("Authorization", authString).build();
1134
			LOGGER.info("geofenceId" + geofenceId);
1135
			Response response = client.newCall(request1).execute();
1136
 
27460 tejbeer 1137
			LOGGER.info("response" + response.body().string());
27457 tejbeer 1138
		}
1139
 
1140
	}
1141
 
27430 amit.gupta 1142
	public void processSchemeOut(int fofoId, int orderId) throws Exception {
1143
		schemeService.processSchemeOut(orderId, fofoId);
27451 tejbeer 1144
 
27430 amit.gupta 1145
	}
27511 amit.gupta 1146
 
1147
	public void createDummyInvoices() {
1148
		List<WarehouseInventoryItem> lavaInventoryItems = warehouseInventoryItemRepository.getSerialNumbers("Lava", LocalDate.of(2020,Month.SEPTEMBER, 1).atStartOfDay(), LocalDateTime.now()); 
1149
		LOGGER.info("Lava Inventory Size is {}", lavaInventoryItems.size());
1150
	}
25043 amit.gupta 1151
}
1152
 
1153
//7015845171