Subversion Repositories SmartDukaan

Rev

Rev 28808 | Rev 28811 | 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
 
28557 amit.gupta 41
import com.google.gson.Gson;
26214 amit.gupta 42
import com.smartdukaan.cron.scheduled.SamsungIMEIActivationService;
25043 amit.gupta 43
import com.smartdukaan.cron.scheduled.ScheduledTasks;
26095 amit.gupta 44
import com.spice.profitmandi.common.enumuration.ItemType;
26033 amit.gupta 45
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
27450 tejbeer 46
import com.spice.profitmandi.common.model.CustomRetailer;
24819 amit.gupta 47
import com.spice.profitmandi.common.util.FileUtil;
25749 amit.gupta 48
import com.spice.profitmandi.common.util.FormattingUtils;
24819 amit.gupta 49
import com.spice.profitmandi.common.util.Utils;
26033 amit.gupta 50
import com.spice.profitmandi.dao.entity.catalog.Item;
28557 amit.gupta 51
import com.spice.profitmandi.dao.entity.catalog.Offer;
25021 amit.gupta 52
import com.spice.profitmandi.dao.entity.catalog.Scheme;
26579 amit.gupta 53
import com.spice.profitmandi.dao.entity.catalog.TagListing;
27286 amit.gupta 54
import com.spice.profitmandi.dao.entity.dtr.PaymentOptionTransaction;
24716 amit.gupta 55
import com.spice.profitmandi.dao.entity.fofo.CurrentInventorySnapshot;
26759 amit.gupta 56
import com.spice.profitmandi.dao.entity.fofo.DebitNote;
27286 amit.gupta 57
import com.spice.profitmandi.dao.entity.fofo.FofoLineItem;
24806 amit.gupta 58
import com.spice.profitmandi.dao.entity.fofo.FofoOrder;
59
import com.spice.profitmandi.dao.entity.fofo.FofoOrderItem;
25530 amit.gupta 60
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
24005 amit.gupta 61
import com.spice.profitmandi.dao.entity.fofo.InventoryItem;
28808 amit.gupta 62
import com.spice.profitmandi.dao.entity.fofo.PartnerDailyInvestment;
26928 amit.gupta 63
import com.spice.profitmandi.dao.entity.fofo.PartnerType;
26033 amit.gupta 64
import com.spice.profitmandi.dao.entity.fofo.PrebookingOrder;
23898 amit.gupta 65
import com.spice.profitmandi.dao.entity.fofo.Purchase;
26759 amit.gupta 66
import com.spice.profitmandi.dao.entity.fofo.PurchaseReturnItem;
24716 amit.gupta 67
import com.spice.profitmandi.dao.entity.fofo.ScanRecord;
25034 amit.gupta 68
import com.spice.profitmandi.dao.entity.fofo.SchemeInOut;
25021 amit.gupta 69
import com.spice.profitmandi.dao.entity.fofo.SchemeItem;
24953 amit.gupta 70
import com.spice.profitmandi.dao.entity.inventory.SaholicInventorySnapshot;
28736 amit.gupta 71
import com.spice.profitmandi.dao.entity.inventory.SaholicReservationSnapshot;
28735 amit.gupta 72
import com.spice.profitmandi.dao.entity.inventory.VendorItemPricing;
28731 amit.gupta 73
import com.spice.profitmandi.dao.entity.inventory.Warehouse;
27721 amit.gupta 74
import com.spice.profitmandi.dao.entity.transaction.HdfcPayment;
23824 amit.gupta 75
import com.spice.profitmandi.dao.entity.transaction.LineItem;
23755 amit.gupta 76
import com.spice.profitmandi.dao.entity.transaction.LineItemImei;
28624 amit.gupta 77
import com.spice.profitmandi.dao.entity.transaction.ManualPaymentType;
23755 amit.gupta 78
import com.spice.profitmandi.dao.entity.transaction.Order;
24802 amit.gupta 79
import com.spice.profitmandi.dao.entity.transaction.SellerWarehouse;
25046 amit.gupta 80
import com.spice.profitmandi.dao.entity.transaction.UserWallet;
25034 amit.gupta 81
import com.spice.profitmandi.dao.entity.transaction.UserWalletHistory;
25530 amit.gupta 82
import com.spice.profitmandi.dao.entity.user.Address;
83
import com.spice.profitmandi.dao.entity.user.User;
27511 amit.gupta 84
import com.spice.profitmandi.dao.entity.warehouse.WarehouseInventoryItem;
28038 amit.gupta 85
import com.spice.profitmandi.dao.entity.warehouse.WarehouseScan;
25021 amit.gupta 86
import com.spice.profitmandi.dao.enumuration.catalog.AmountType;
25522 amit.gupta 87
import com.spice.profitmandi.dao.enumuration.catalog.SchemeType;
27286 amit.gupta 88
import com.spice.profitmandi.dao.enumuration.dtr.PaymentOptionReferenceType;
26759 amit.gupta 89
import com.spice.profitmandi.dao.enumuration.fofo.ScanType;
26579 amit.gupta 90
import com.spice.profitmandi.dao.model.ContentPojo;
27948 amit.gupta 91
import com.spice.profitmandi.dao.model.CreateOfferRequest;
26579 amit.gupta 92
import com.spice.profitmandi.dao.model.MediaPojo;
24716 amit.gupta 93
import com.spice.profitmandi.dao.repository.GenericRepository;
25034 amit.gupta 94
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
28624 amit.gupta 95
import com.spice.profitmandi.dao.repository.catalog.ManualPaymentRequestRepository;
28557 amit.gupta 96
import com.spice.profitmandi.dao.repository.catalog.OfferRepository;
25021 amit.gupta 97
import com.spice.profitmandi.dao.repository.catalog.SchemeRepository;
26579 amit.gupta 98
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
25749 amit.gupta 99
import com.spice.profitmandi.dao.repository.cs.CsService;
23899 amit.gupta 100
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
27221 amit.gupta 101
import com.spice.profitmandi.dao.repository.dtr.LeadRepository;
26579 amit.gupta 102
import com.spice.profitmandi.dao.repository.dtr.Mongo;
27286 amit.gupta 103
import com.spice.profitmandi.dao.repository.dtr.PaymentOptionTransactionRepository;
24716 amit.gupta 104
import com.spice.profitmandi.dao.repository.fofo.CurrentInventorySnapshotRepository;
24002 amit.gupta 105
import com.spice.profitmandi.dao.repository.fofo.DebitNoteRepository;
27286 amit.gupta 106
import com.spice.profitmandi.dao.repository.fofo.FofoLineItemRepository;
24806 amit.gupta 107
import com.spice.profitmandi.dao.repository.fofo.FofoOrderItemRepository;
108
import com.spice.profitmandi.dao.repository.fofo.FofoOrderRepository;
24002 amit.gupta 109
import com.spice.profitmandi.dao.repository.fofo.InventoryItemRepository;
24806 amit.gupta 110
import com.spice.profitmandi.dao.repository.fofo.InvoiceNumberGenerationSequenceRepository;
28808 amit.gupta 111
import com.spice.profitmandi.dao.repository.fofo.PartnerDailyInvestmentRepository;
24883 amit.gupta 112
import com.spice.profitmandi.dao.repository.fofo.PartnerTargetRepository;
26033 amit.gupta 113
import com.spice.profitmandi.dao.repository.fofo.PrebookingOrderRepository;
23898 amit.gupta 114
import com.spice.profitmandi.dao.repository.fofo.PurchaseRepository;
26759 amit.gupta 115
import com.spice.profitmandi.dao.repository.fofo.PurchaseReturnItemRepository;
24716 amit.gupta 116
import com.spice.profitmandi.dao.repository.fofo.ScanRecordRepository;
24002 amit.gupta 117
import com.spice.profitmandi.dao.repository.fofo.SchemeInOutRepository;
25021 amit.gupta 118
import com.spice.profitmandi.dao.repository.fofo.SchemeItemRepository;
24953 amit.gupta 119
import com.spice.profitmandi.dao.repository.inventory.SaholicInventorySnapshotRepository;
26928 amit.gupta 120
import com.spice.profitmandi.dao.repository.inventory.SaholicReservationSnapshotRepository;
28675 amit.gupta 121
import com.spice.profitmandi.dao.repository.inventory.VendorItemPricingRepository;
28708 amit.gupta 122
import com.spice.profitmandi.dao.repository.inventory.WarehouseRepository;
27721 amit.gupta 123
import com.spice.profitmandi.dao.repository.transaction.HdfcPaymentRepository;
23755 amit.gupta 124
import com.spice.profitmandi.dao.repository.transaction.LineItemImeisRepository;
23824 amit.gupta 125
import com.spice.profitmandi.dao.repository.transaction.LineItemRepository;
23755 amit.gupta 126
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
24772 amit.gupta 127
import com.spice.profitmandi.dao.repository.transaction.ReturnOrderRepository;
24802 amit.gupta 128
import com.spice.profitmandi.dao.repository.transaction.SellerWarehouseRepository;
24767 amit.gupta 129
import com.spice.profitmandi.dao.repository.transaction.UserWalletHistoryRepository;
130
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
25530 amit.gupta 131
import com.spice.profitmandi.dao.repository.user.AddressRepository;
24002 amit.gupta 132
import com.spice.profitmandi.dao.repository.user.UserRepository;
27511 amit.gupta 133
import com.spice.profitmandi.dao.repository.warehouse.WarehouseInventoryItemRepository;
28038 amit.gupta 134
import com.spice.profitmandi.dao.repository.warehouse.WarehouseScanRepository;
23899 amit.gupta 135
import com.spice.profitmandi.service.inventory.InventoryService;
26033 amit.gupta 136
import com.spice.profitmandi.service.inventory.PurchaseService;
28736 amit.gupta 137
import com.spice.profitmandi.service.inventory.SaholicInventoryService;
27948 amit.gupta 138
import com.spice.profitmandi.service.offers.OfferService;
28557 amit.gupta 139
import com.spice.profitmandi.service.offers.PartnerCriteria;
24266 amit.gupta 140
import com.spice.profitmandi.service.order.OrderService;
24005 amit.gupta 141
import com.spice.profitmandi.service.pricing.PriceDropService;
142
import com.spice.profitmandi.service.scheme.SchemeService;
23899 amit.gupta 143
import com.spice.profitmandi.service.transaction.TransactionService;
144
import com.spice.profitmandi.service.user.RetailerService;
145
import com.spice.profitmandi.service.wallet.WalletService;
28046 amit.gupta 146
import com.spice.profitmandi.service.warehouse.WarehouseInventoryService;
23755 amit.gupta 147
 
24953 amit.gupta 148
import in.shop2020.model.v1.order.OrderStatus;
24002 amit.gupta 149
import in.shop2020.model.v1.order.WalletReferenceType;
27450 tejbeer 150
import okhttp3.OkHttpClient;
151
import okhttp3.Request;
152
import okhttp3.Response;
24002 amit.gupta 153
 
23755 amit.gupta 154
@Component
155
@Transactional(rollbackFor = Throwable.class)
156
public class RunOnceTasks {
157
 
158
	private static final Logger LOGGER = LogManager.getLogger(RunOnceTasks.class);
159
	@Autowired
23824 amit.gupta 160
	private LineItemRepository lineItemRepository;
24711 amit.gupta 161
 
23905 amit.gupta 162
	@Autowired
27221 amit.gupta 163
	private LeadRepository leadRepository;
28731 amit.gupta 164
 
28675 amit.gupta 165
	@Autowired
166
	private VendorItemPricingRepository vendorItemPricingRepository;
28731 amit.gupta 167
 
28708 amit.gupta 168
	@Autowired
169
	private WarehouseRepository warehouseRepository;
27277 amit.gupta 170
 
27221 amit.gupta 171
	@Autowired
26759 amit.gupta 172
	private PurchaseReturnItemRepository purchaseReturnItemRepository;
26928 amit.gupta 173
 
26759 amit.gupta 174
	@Autowired
24953 amit.gupta 175
	private SaholicInventorySnapshotRepository saholicInventorySnapshotRepository;
25752 amit.gupta 176
 
25749 amit.gupta 177
	@Autowired
178
	private CsService csService;
28660 amit.gupta 179
 
28557 amit.gupta 180
	@Autowired
28624 amit.gupta 181
	private ManualPaymentRequestRepository manualPaymentRequestRepository;
182
 
183
	@Autowired
28557 amit.gupta 184
	private OfferRepository offerRepository;
26299 amit.gupta 185
 
26033 amit.gupta 186
	@Autowired
26579 amit.gupta 187
	private Mongo mongoClient;
27787 amit.gupta 188
 
27286 amit.gupta 189
	@Autowired
28557 amit.gupta 190
	private Gson gson;
28624 amit.gupta 191
 
28557 amit.gupta 192
	@Autowired
27286 amit.gupta 193
	private PaymentOptionTransactionRepository paymentOptionTransactionRepository;
26579 amit.gupta 194
 
195
	@Autowired
26195 amit.gupta 196
	private SamsungIMEIActivationService samsungActivationService;
26299 amit.gupta 197
 
26195 amit.gupta 198
	@Autowired
26033 amit.gupta 199
	private PrebookingOrderRepository prebookingOrderRepository;
24953 amit.gupta 200
 
201
	@Autowired
24883 amit.gupta 202
	private PartnerTargetRepository partnerTargetRepository;
203
 
204
	@Autowired
24802 amit.gupta 205
	private SellerWarehouseRepository sellerWarehouseRepository;
24814 amit.gupta 206
 
24802 amit.gupta 207
	@Autowired
24806 amit.gupta 208
	private FofoOrderItemRepository fofoOrderItemRepository;
27787 amit.gupta 209
 
27286 amit.gupta 210
	@Autowired
211
	private FofoLineItemRepository fofoLineItemRepository;
24814 amit.gupta 212
 
24806 amit.gupta 213
	@Autowired
214
	private FofoOrderRepository fofoOrderRepository;
24814 amit.gupta 215
 
24806 amit.gupta 216
	@Autowired
24767 amit.gupta 217
	private UserWalletRepository userWalletRepository;
218
 
219
	@Autowired
220
	private UserWalletHistoryRepository userWalletHistoryRepository;
221
 
222
	@Autowired
24002 amit.gupta 223
	private UserRepository userRepository;
24711 amit.gupta 224
 
24002 amit.gupta 225
	@Autowired
23899 amit.gupta 226
	private WalletService walletService;
227
 
228
	@Autowired
25034 amit.gupta 229
	private ItemRepository itemRepository;
230
 
231
	@Autowired
23899 amit.gupta 232
	private InventoryService inventoryService;
233
 
234
	@Autowired
235
	private TransactionService transactionService;
26299 amit.gupta 236
 
26033 amit.gupta 237
	@Autowired
238
	private PurchaseService purchaseService;
23899 amit.gupta 239
 
24711 amit.gupta 240
	// Service for Tertiary/Partner Orders
24266 amit.gupta 241
	@Autowired
242
	private OrderService orderService;
23767 amit.gupta 243
 
23755 amit.gupta 244
	@Autowired
25021 amit.gupta 245
	private SchemeRepository schemeRepository;
25516 amit.gupta 246
 
25043 amit.gupta 247
	@Autowired
25530 amit.gupta 248
	private AddressRepository addressRepository;
25749 amit.gupta 249
 
25530 amit.gupta 250
	@Autowired
25043 amit.gupta 251
	private ScheduledTasks scheduledTasks;
25034 amit.gupta 252
 
25021 amit.gupta 253
	@Autowired
254
	private SchemeItemRepository schemeItemRepository;
255
 
256
	@Autowired
24772 amit.gupta 257
	private ReturnOrderRepository returnOrderRepository;
258
 
259
	@Autowired
23899 amit.gupta 260
	private FofoStoreRepository fofoStoreRepository;
261
 
262
	@Autowired
23755 amit.gupta 263
	private LineItemImeisRepository lineItemImeisRepository;
24711 amit.gupta 264
 
24002 amit.gupta 265
	@Autowired
266
	private InventoryItemRepository inventoryItemRepository;
24814 amit.gupta 267
 
24806 amit.gupta 268
	@Autowired
26579 amit.gupta 269
	private TagListingRepository tagListingRepository;
270
 
271
	@Autowired
24806 amit.gupta 272
	private InvoiceNumberGenerationSequenceRepository invoiceNumberGenerationSequenceRepository;
23901 amit.gupta 273
 
23898 amit.gupta 274
	@Autowired
23899 amit.gupta 275
	private RetailerService retailerService;
24711 amit.gupta 276
 
24002 amit.gupta 277
	@Autowired
278
	private SchemeInOutRepository schemeInOutRepository;
24711 amit.gupta 279
 
24002 amit.gupta 280
	@Autowired
281
	private DebitNoteRepository debitNoteRepository;
28624 amit.gupta 282
 
27948 amit.gupta 283
	@Autowired
284
	private OfferService offerService;
23899 amit.gupta 285
 
286
	@Autowired
24716 amit.gupta 287
	private GenericRepository genericRepository;
288
 
289
	@Autowired
23898 amit.gupta 290
	private PurchaseRepository purchaseRepository;
24711 amit.gupta 291
 
24005 amit.gupta 292
	@Autowired
293
	private PriceDropService priceDropService;
24883 amit.gupta 294
 
24819 amit.gupta 295
	@Autowired
296
	private JavaMailSender googleMailSender;
24711 amit.gupta 297
 
24005 amit.gupta 298
	@Autowired
299
	private SchemeService schemeService;
24711 amit.gupta 300
 
24716 amit.gupta 301
	@Autowired
302
	private CurrentInventorySnapshotRepository currentInventorySnapshotRepository;
303
 
304
	@Autowired
24767 amit.gupta 305
	private OrderRepository orderRepository;
28731 amit.gupta 306
 
24767 amit.gupta 307
	@Autowired
24716 amit.gupta 308
	private ScanRecordRepository scanRecordRepository;
309
 
24767 amit.gupta 310
	@Autowired
311
	private JavaMailSender mailSender;
27451 tejbeer 312
 
27450 tejbeer 313
	private static final String ACCOUNT_ID = "aZ6flHhrgPIEl18buHdPBdueEN4";
314
	private static final String SECRET_KEY = "a7rsX5B4UNNfTTx1-IJ19qdH48BT4YvBKlQJg3n3_KKNe7WWych55g";
24767 amit.gupta 315
 
27511 amit.gupta 316
	@Autowired
317
	private WarehouseInventoryItemRepository warehouseInventoryItemRepository;
27787 amit.gupta 318
 
23898 amit.gupta 319
	public void populateGrnTimestamp() {
320
		List<Purchase> allPurchases = purchaseRepository.selectAll();
23899 amit.gupta 321
		for (Purchase p : allPurchases) {
23898 amit.gupta 322
			String invoiceNumber = p.getPurchaseReference();
23899 amit.gupta 323
			if (p.getCompleteTimestamp() == null) {
23898 amit.gupta 324
				LOGGER.info("GRN for invoice {} is delivered but partially Completed.", p.getPurchaseReference());
325
			} else {
326
				List<Order> orders = orderRepository.selectByAirwayBillOrInvoiceNumber(invoiceNumber, p.getFofoId());
23899 amit.gupta 327
				for (Order order : orders) {
23902 amit.gupta 328
					if (order.getPartnerGrnTimestamp() == null) {
329
						order.setPartnerGrnTimestamp(p.getCompleteTimestamp());
23898 amit.gupta 330
					}
331
				}
332
			}
333
		}
23899 amit.gupta 334
 
23898 amit.gupta 335
	}
23899 amit.gupta 336
 
26408 amit.gupta 337
	public void fetchImeiActivation(int ym) throws Exception {
27787 amit.gupta 338
		LocalDate startDate = null;
339
		LocalDate endDate = null;
340
		if (ym == 0) {
341
			startDate = LocalDate.now().minusDays(30);
342
			endDate = LocalDate.now();
343
		} else {
344
			startDate = LocalDate.now().minusMonths(ym);
345
			endDate = startDate.plusMonths(1);
346
		}
347
		samsungActivationService.getActivationsBetweenNew(startDate, endDate);
26195 amit.gupta 348
	}
26299 amit.gupta 349
 
24716 amit.gupta 350
	public void migarateLineItemsToNewTable() throws Exception {
23755 amit.gupta 351
		LOGGER.info("Before Migrated LineItems Successfully");
23824 amit.gupta 352
		int lineItemImeiId = 0;
353
		LocalDateTime startDate = null;
354
		try {
355
			lineItemImeiId = lineItemImeisRepository.selectMaxId();
23899 amit.gupta 356
			LineItem lineItem = lineItemRepository
357
					.selectById(lineItemImeisRepository.selectById(lineItemImeiId).getLineItemId());
23824 amit.gupta 358
			Order order = orderRepository.selectById(lineItem.getOrderId());
359
			startDate = order.getBillingTimestamp();
360
		} catch (Exception e) {
361
			LOGGER.info("Running before first time");
23826 amit.gupta 362
			startDate = LocalDateTime.of(LocalDate.of(2017, 7, 1), LocalTime.MIDNIGHT);
23824 amit.gupta 363
		}
364
		List<Order> orders = orderRepository.selectAllByBillingDatesBetween(startDate, LocalDateTime.now());
23827 amit.gupta 365
		Collections.reverse(orders);
23899 amit.gupta 366
 
23755 amit.gupta 367
		for (Order order : orders) {
23824 amit.gupta 368
			try {
23767 amit.gupta 369
				String serialNumbers = order.getLineItem().getSerialNumber();
370
				if (!StringUtils.isEmpty(serialNumbers)) {
371
					List<String> serialNumberList = Arrays.asList(serialNumbers.split(","));
372
					for (String serialNumber : serialNumberList) {
373
						int lineItemId = order.getLineItem().getId();
374
						LineItemImei lineItemImei = new LineItemImei();
375
						lineItemImei.setSerialNumber(serialNumber);
376
						lineItemImei.setLineItemId(lineItemId);
377
						lineItemImeisRepository.persist(lineItemImei);
378
					}
379
				} else {
380
					LOGGER.info("Serial Numbers dont exist for Order {}", order.getId());
23755 amit.gupta 381
				}
23824 amit.gupta 382
			} catch (Exception e) {
23899 amit.gupta 383
				LOGGER.info("Error occurred while creating lineitem imei {}, because of {}", order.getId(),
384
						e.getMessage());
23755 amit.gupta 385
			}
386
		}
387
		LOGGER.info("Migrated LineItems Successfully");
388
	}
24266 amit.gupta 389
 
390
	public void cancelOrder(List<String> invoiceNumbers) throws Exception {
391
		orderService.cancelOrder(invoiceNumbers);
392
	}
27787 amit.gupta 393
 
394
	@Autowired
395
	HdfcPaymentRepository hdfcPaymentRepository;
396
 
27721 amit.gupta 397
	public void addPayment() throws Exception {
27722 amit.gupta 398
		List<Integer> paymentIds = Arrays.asList(3777);
27721 amit.gupta 399
		for (int hdfcPaymentId : paymentIds) {
400
			HdfcPayment hdfcPayment = hdfcPaymentRepository.selectById(hdfcPaymentId);
401
			String virtualAccount = hdfcPayment.getVirtualAccount();
402
			String retailerIdString = virtualAccount.substring(6);
403
			int retailerId = Integer.parseInt(retailerIdString);
404
			String description = String.format("Advance payment received through %s, Utr# %s",
405
					hdfcPayment.getTransferMode(), hdfcPayment.getUtr());
406
			walletService.addAmountToWallet(retailerId, hdfcPayment.getId(), WalletReferenceType.AUTOMATED_ADVANCE,
407
					description, (float) hdfcPayment.getAmount(), hdfcPayment.getCreditTimestamp());
408
		}
409
	}
24711 amit.gupta 410
 
24722 amit.gupta 411
	public void migratePurchase() throws Exception {
24641 amit.gupta 412
		List<Purchase> purchases = purchaseRepository.selectPurchaseAllPurchasesLessThanZero();
24706 amit.gupta 413
		System.out.printf("Total Purchases count is %s", purchases.size());
24711 amit.gupta 414
		for (Purchase purchase : purchases) {
415
			List<InventoryItem> inventoryItems = inventoryItemRepository.selectByPurchaseId(purchase.getId());
416
			Map<Integer, List<InventoryItem>> itemIdInventoryMap = inventoryItems.stream()
417
					.collect(Collectors.groupingBy(InventoryItem::getItemId));
418
			List<Order> orders = orderRepository.selectByAirwayBillOrInvoiceNumber(purchase.getPurchaseReference(),
419
					purchase.getFofoId());
420
			Map<Integer, Integer> ourSaleItemQtyMap = orders.stream().collect(Collectors.groupingBy(
421
					x -> x.getLineItem().getItemId(), Collectors.summingInt(x -> x.getLineItem().getQuantity())));
422
			Map<Integer, Integer> theirPurchaseItemQtyMap = inventoryItems.stream().collect(Collectors
423
					.groupingBy(InventoryItem::getItemId, Collectors.summingInt(InventoryItem::getInitialQuantity)));
24709 amit.gupta 424
			for (Map.Entry<Integer, Integer> itemQtyEntry : theirPurchaseItemQtyMap.entrySet()) {
24711 amit.gupta 425
				if (!ourSaleItemQtyMap.containsKey(itemQtyEntry.getKey())) {
426
					LOGGER.info("Cannot find in Invoice {} item {}", purchase.getPurchaseReference(),
427
							itemQtyEntry.getKey());
24646 amit.gupta 428
					continue;
24645 amit.gupta 429
				}
24709 amit.gupta 430
				int ourSale = ourSaleItemQtyMap.get(itemQtyEntry.getKey());
24713 amit.gupta 431
				int quantityToReduce = itemQtyEntry.getValue() - ourSale;
24716 amit.gupta 432
				List<InventoryItem> itemIis = itemIdInventoryMap.get(itemQtyEntry.getKey());
433
				if (itemIdInventoryMap != null) {
434
					for (InventoryItem ii : itemIis) {
24915 amit.gupta 435
						if (ii.getSerialNumber() == null && ii.getGoodQuantity() == ii.getInitialQuantity()
436
								&& quantityToReduce >= ii.getInitialQuantity()) {
24734 amit.gupta 437
							LOGGER.info("Changed in inventoryItems {}, {}, {}, {}, {}, {}",
24716 amit.gupta 438
									purchase.getPurchaseReference(), ii.getId(), ii.getItemId(),
24734 amit.gupta 439
									ii.getInitialQuantity(), ii.getGoodQuantity(), quantityToReduce);
24912 amit.gupta 440
							List<ScanRecord> scanRecords = scanRecordRepository.selectByInventoryItemId(ii.getId());
441
							for (ScanRecord scanRecord : scanRecords) {
24915 amit.gupta 442
								CurrentInventorySnapshot cis = currentInventorySnapshotRepository
443
										.selectByItemIdAndFofoId(itemQtyEntry.getKey(), purchase.getFofoId());
444
								scanRecord.setQuantity(0);
445
								ii.setGoodQuantity(0);
446
								quantityToReduce = quantityToReduce - ii.getInitialQuantity();
447
								cis.setAvailability(cis.getAvailability() - ii.getInitialQuantity());
448
								purchase.setUnfullfilledNonSerializedQuantity(
449
										purchase.getUnfullfilledNonSerializedQuantity() + quantityToReduce);
450
								LOGGER.info("Rectified {}, {}, {}, {}, {}, {}", purchase.getPurchaseReference(),
451
										ii.getId(), ii.getItemId(), ii.getInitialQuantity(), ii.getGoodQuantity(),
452
										quantityToReduce);
24711 amit.gupta 453
							}
24641 amit.gupta 454
						}
455
					}
456
				}
457
			}
458
		}
24953 amit.gupta 459
		// throw new Exception();
24641 amit.gupta 460
	}
24767 amit.gupta 461
 
24802 amit.gupta 462
	public void migrateChallansToInvoices() throws Exception {
24814 amit.gupta 463
		Map<String, List<Order>> invoiceOrdersMap = orderRepository.selectAllChallans().stream()
464
				.filter(x -> !x.getLineItem().getHsnCode().equals("NOGST"))
24794 amit.gupta 465
				.collect(Collectors.groupingBy(Order::getInvoiceNumber, Collectors.toList()));
24814 amit.gupta 466
 
25837 amit.gupta 467
		List<List<?>> rows = new ArrayList<>();
24814 amit.gupta 468
		for (String invoice : invoiceOrdersMap.keySet()) {
24794 amit.gupta 469
			Order oneOrder = invoiceOrdersMap.get(invoice).get(0);
470
			int totalOrders = invoiceOrdersMap.get(invoice).size();
471
			LineItem lineItem = oneOrder.getLineItem();
24802 amit.gupta 472
			oneOrder.setBillingTimestamp(LocalDateTime.now());
473
			oneOrder.setInvoiceNumber(getInvoiceNumber(oneOrder));
24819 amit.gupta 474
			rows.add(Arrays.asList(oneOrder.getId(), invoice, oneOrder.getInvoiceNumber(), lineItem.getQuantity()));
24883 amit.gupta 475
			LOGGER.info(invoice + "\t" + oneOrder.getInvoiceNumber() + oneOrder.getId() + "\t",
476
					"\t" + totalOrders + "\t" + lineItem.getQuantity());
24814 amit.gupta 477
			Purchase p = null;
478
			try {
479
				p = purchaseRepository.selectByPurchaseReferenceAndFofoId(invoice, oneOrder.getRetailerId());
480
			} catch (Exception e) {
24815 amit.gupta 481
				LOGGER.info("Could not find purchase for invoice {}", invoice);
24812 amit.gupta 482
			}
24814 amit.gupta 483
			if (p != null) {
484
				List<InventoryItem> inventoryItems = inventoryItemRepository.selectByPurchaseId(p.getId());
485
				for (InventoryItem inventoryItem : inventoryItems) {
24815 amit.gupta 486
					LOGGER.info(inventoryItem.getItemId() + " " + inventoryItem.getGoodQuantity() + " "
24883 amit.gupta 487
							+ inventoryItem.getHsnCode() + " " + inventoryItem.getSerialNumber() + " "
488
							+ p.getPurchaseReference());
24814 amit.gupta 489
				}
490
			}
491
 
24794 amit.gupta 492
		}
24818 amit.gupta 493
		changePartnerInvoices();
24883 amit.gupta 494
		ByteArrayOutputStream baos = FileUtil
495
				.getCSVByteStream(Arrays.asList("Order id", "Challan", "Invoice", "Quantity"), rows);
496
 
24819 amit.gupta 497
		Utils.sendMailWithAttachment(googleMailSender,
498
				new String[] { "amit.gupta@shop2020.in", "sunny.yadav@smartdukaan.com" }, null,
24883 amit.gupta 499
				"Challans Converted to Invoice", "PFA", "Challans-To-Invoice.csv",
500
				new ByteArrayResource(baos.toByteArray()));
24916 amit.gupta 501
		throw new Exception();
24794 amit.gupta 502
	}
24767 amit.gupta 503
 
24802 amit.gupta 504
	private String getInvoiceNumber(Order oneOrder) {
24805 amit.gupta 505
		String prefix = oneOrder.getInvoiceNumber().split("-")[1].replaceAll("\\d*", "");
24803 amit.gupta 506
		System.out.println("Prefix is " + prefix);
24802 amit.gupta 507
		SellerWarehouse sellerWarehouse = sellerWarehouseRepository.selectByPrefix(prefix);
508
		int newSequence = sellerWarehouse.getInvoiceSequence() + 1;
509
		sellerWarehouse.setInvoiceSequence(newSequence);
24814 amit.gupta 510
		return prefix + newSequence;
24802 amit.gupta 511
	}
24814 amit.gupta 512
 
24806 amit.gupta 513
	private void changePartnerInvoices() throws Exception {
24814 amit.gupta 514
		List<FofoOrder> fofoOrders = fofoOrderRepository.selectByInvoiceNumberLike("%SEC%");
515
		for (FofoOrder fofoOrder : fofoOrders) {
24806 amit.gupta 516
			FofoOrderItem fofoOrderItem = fofoOrderItemRepository.selectByOrderId(fofoOrder.getId()).get(0);
24814 amit.gupta 517
			if (fofoOrderItem.getBrand().equals("Vivo")) {
24806 amit.gupta 518
				String challanString = fofoOrder.getInvoiceNumber();
24814 amit.gupta 519
				String storeCode = invoiceNumberGenerationSequenceRepository.selectByFofoId(fofoOrder.getFofoId())
520
						.getPrefix();
24806 amit.gupta 521
				String invoiceNumber = orderService.getInvoiceNumber(fofoOrder.getFofoId(), storeCode);
522
				fofoOrder.setInvoiceNumber(invoiceNumber);
523
				fofoOrder.setCreateTimestamp(LocalDateTime.now());
24818 amit.gupta 524
				LOGGER.info(challanString + "\t" + invoiceNumber + "\t" + fofoOrderItem.getQuantity());
24806 amit.gupta 525
			}
24814 amit.gupta 526
 
24806 amit.gupta 527
		}
528
	}
24802 amit.gupta 529
 
25023 amit.gupta 530
	public void populateSchemes() {
25021 amit.gupta 531
		List<Integer> list05 = Arrays.asList(29093, 29094, 29095, 29096, 29097, 29098, 29099, 29101, 29102);
532
		List<Integer> list10 = Arrays.asList(29187, 29188);
533
		List<Integer> list13 = Arrays.asList(28095, 28097, 28098, 28101, 28102, 28104, 28106, 28107, 28108, 28227,
534
				28228, 28229, 28231, 29055, 29056, 29066, 29079);
535
		List<Integer> list15 = Arrays.asList(20891, 27938, 27939, 27940, 27941, 27943, 27947, 27948, 27953, 27954,
536
				27955, 28220, 28467, 29020, 29033, 29034, 29035, 29592, 29886, 29890, 29891, 29941, 29942, 27445, 27958,
537
				27960, 27961);
538
		List<Integer> list18 = Arrays.asList(28137, 28138, 28140, 28157, 28158, 28161, 28162, 28163, 28164, 28176,
539
				28177, 28178, 28199, 28200, 28208, 28209, 28210, 28211, 28215, 28216, 28217, 28230, 28380, 28381, 28382,
540
				28383, 28384, 28385, 28386, 28387, 28388, 28389, 28390, 28391, 28392, 28395, 28461, 28462, 28463, 28464,
541
				28465, 28466, 28488, 28489, 28490, 28491, 28564, 28565, 28762, 28773, 28871, 28872, 28873, 28874, 28880,
542
				28881, 28914, 28915, 28916, 28917, 28918, 28919, 28920, 29046, 29047, 29048, 29068, 29069, 29110, 29111,
543
				29112, 29113, 29114, 29115, 29116, 29117, 29207, 29208, 29217, 29218, 29225, 29474, 29475, 29476, 29477,
544
				29478, 29479, 29483, 29485, 29486, 29487, 29488, 29739, 29740, 29741, 29742, 29743, 29744, 29745, 29746,
545
				29747, 29748, 29749, 29753, 29756, 29757, 29758, 29760, 29761, 29762, 29763, 29764, 29765, 29766, 29767,
546
				29779, 29780, 29781, 29792, 29793, 29828, 29829, 29830, 29879, 29880, 29881, 29882, 29951);
547
		List<Integer> list20 = Arrays.asList(27975, 27976, 28091, 28363, 29023, 29024, 29025);
548
		List<Integer> list25 = Arrays.asList(28763, 28764, 28765, 29152, 29154, 29157, 29209, 29210, 29601, 29602,
549
				29720, 29721, 29722, 29723, 29725, 29726, 29727);
550
		List<Integer> list30 = Arrays.asList(27962, 27963, 27964, 27965, 27966, 27968, 27969, 28328, 28362, 28566,
551
				28567, 28568, 28571, 28572, 29073, 29074, 29075, 29080, 29081, 29120, 29121, 29122, 29124, 29189, 29190,
552
				29191, 29192, 29193, 29194, 29196, 29197, 29198, 29199, 29515, 29516, 29517, 29675, 29676, 29677, 29678,
553
				29679, 29707, 29708, 29794, 29795, 29883, 29884, 29885, 29887, 29888, 29889, 29931, 29932, 29935, 29936,
554
				29937, 29938, 29939, 29940);
555
		List<Integer> list35 = Arrays.asList(27996, 27998, 29067, 29071, 29643, 29644, 29945, 29946, 29987, 29052,
556
				29053, 29078, 29085, 29086, 29567, 29568, 29569, 29570, 29797, 29914, 29915, 29930, 28877, 28878, 29604,
557
				29605, 29606, 29775, 29776, 29777, 29778, 28862, 28863, 28864, 29026, 29103, 29104, 29105, 28979, 28980,
558
				28981, 28982, 28983, 29002, 29003, 29004, 29834, 29835, 29836, 29837, 29943);
559
		List<Integer> list40 = Arrays.asList(29082, 29083, 28766, 28767, 28768, 28769, 28771);
560
		List<Integer> list45 = Arrays.asList(28026, 28027, 28028, 29528, 29529, 29530, 29534, 29535, 29536, 29538,
561
				29755);
562
		List<Integer> list55 = Arrays.asList(28010, 28011, 28015, 28016, 28019, 28240, 28469, 28470, 28471, 28569,
563
				28570, 28674, 28759, 28761, 28909, 28910, 28911, 28912, 28913, 29108, 29109, 29143, 29144, 29145, 29146,
564
				29211, 29212, 29213, 29214, 29482, 29511, 29512, 29521, 29525, 29526, 29527, 29574, 29575, 29576, 29611,
565
				29612, 29616, 29641, 29642, 29728, 29729, 29750, 29771, 29782, 29783, 29784, 29923, 29924, 29944, 29953,
566
				29992, 29994, 27977, 27978, 28092, 28325, 28326, 28327, 28486, 28487, 29148, 29149, 29150, 29151, 29384,
567
				29385, 29386, 29427, 29489, 29518, 29519, 29520, 29577, 29578, 29579, 29580, 29586, 29660, 29661, 29662,
568
				29663, 29769, 29770, 29790, 29791, 29796, 29928, 29929, 29947, 29948, 28093, 28094, 28556, 28557, 28673,
569
				28867, 28868, 28870, 29089, 29090, 29091, 29106, 29107);
570
		List<Integer> list65 = Arrays.asList(28058, 28223, 28224, 28225, 28226, 28329, 29201, 29202, 29203, 29204,
571
				29205, 29206, 29466, 29467, 29468, 29469, 29470, 29471, 29472, 29573);
572
		Map<Float, List<Integer>> m = new HashMap<>();
573
		m.put(0.5f, list05);
574
		m.put(1.0f, list10);
575
		m.put(1.3f, list13);
576
		m.put(1.5f, list15);
577
		m.put(1.8f, list18);
578
		m.put(2.0f, list20);
579
		m.put(2.5f, list25);
580
		m.put(3.0f, list30);
581
		m.put(3.5f, list35);
582
		m.put(4.0f, list40);
583
		m.put(4.5f, list45);
584
		m.put(5.5f, list55);
585
		m.put(6.5f, list65);
586
		for (Map.Entry<Float, List<Integer>> itemsListEntry : m.entrySet()) {
587
			Scheme s1 = getScheme();
588
			s1.setAmount(itemsListEntry.getKey());
589
			schemeRepository.persist(s1);
25034 amit.gupta 590
			for (Integer itemId : itemsListEntry.getValue()) {
25021 amit.gupta 591
				SchemeItem schemeItem = new SchemeItem();
592
				schemeItem.setItemId(itemId);
593
				schemeItem.setSchemeId(s1.getId());
594
				schemeItemRepository.persist(schemeItem);
595
			}
596
		}
25034 amit.gupta 597
 
25021 amit.gupta 598
	}
599
 
600
	private Scheme getScheme() {
601
		Scheme s = new Scheme();
602
		s.setName("List Price Margin");
603
		s.setDescription("List Price Margin");
604
		s.setActiveTimestamp(null);
605
		s.setStartDateTime(LocalDate.of(2019, 6, 1).atStartOfDay());
606
		s.setEndDateTime(LocalDate.of(2019, 7, 1).atStartOfDay());
607
		s.setAmountType(AmountType.PERCENTAGE);
608
		s.setCreateTimestamp(LocalDateTime.now());
609
		s.setExpireTimestamp(null);
610
		s.setCreatedBy(175120474);
611
		return s;
612
	}
613
 
24957 amit.gupta 614
	public void findMismatchesInIndent() throws Exception {
615
		List<Order> allInProcessOrders = orderRepository.selectAllOrder(OrderStatus.SUBMITTED_FOR_PROCESSING);
24967 amit.gupta 616
 
25021 amit.gupta 617
		Map<String, Integer> lineItemWhQtyMap = allInProcessOrders.stream()
25734 amit.gupta 618
				.collect(Collectors.groupingBy(y -> y.getLineItem().getItemId() + "-" + y.getFulfilmentWarehouseId(),
24967 amit.gupta 619
						Collectors.summingInt(y -> y.getLineItem().getQuantity())));
25021 amit.gupta 620
 
621
		lineItemWhQtyMap.forEach((key, value) -> {
622
 
24967 amit.gupta 623
			int itemId = Integer.parseInt(key.split("-")[0]);
624
			int warehouseId = Integer.parseInt(key.split("-")[1]);
25021 amit.gupta 625
			System.out.printf("%d\t%d\t%d\n", itemId, warehouseId, value);
626
			SaholicInventorySnapshot cis = saholicInventorySnapshotRepository.selectByWarehouseIdandItemId(warehouseId,
627
					itemId);
628
			if (cis == null) {
24970 amit.gupta 629
				cis = new SaholicInventorySnapshot();
630
				cis.setItemId(itemId);
631
				cis.setWarehouseId(warehouseId);
632
				cis.setAvailability(0);
633
				saholicInventorySnapshotRepository.persist(cis);
634
			}
24967 amit.gupta 635
			cis.setReserved(value);
636
		});
24953 amit.gupta 637
	}
638
 
25034 amit.gupta 639
	public void fixSchemePayouts() throws Exception {
25524 amit.gupta 640
		LOGGER.info("In fix scheme Payouts");
25522 amit.gupta 641
		LocalDateTime startDate = LocalDate.of(2019, 9, 1).atStartOfDay();
642
		List<SchemeInOut> sios = schemeInOutRepository.selectAllByCreateDate(startDate, LocalDateTime.now());
25530 amit.gupta 643
 
25034 amit.gupta 644
		for (SchemeInOut sio : sios) {
25530 amit.gupta 645
			if (sio.getSchemeId() != 347) {
25523 amit.gupta 646
				LOGGER.info("Skipping {}", sio.getSchemeId());
25522 amit.gupta 647
				continue;
648
			}
25043 amit.gupta 649
			genericRepository.delete(sio);
25522 amit.gupta 650
			InventoryItem ii = inventoryItemRepository.selectById(sio.getInventoryItemId());
651
			UserWallet userWallet = userWalletRepository.selectByRetailerId(ii.getFofoId());
652
			Scheme scheme = schemeRepository.selectById(sio.getSchemeId());
653
			if (scheme.getType().equals(SchemeType.IN)) {
654
				List<UserWalletHistory> historyList = userWalletHistoryRepository
655
						.selectAllByreferenceIdandreferenceType(ii.getPurchaseId(), WalletReferenceType.SCHEME_IN);
656
				for (UserWalletHistory uwh : historyList) {
25530 amit.gupta 657
					if (uwh.getTimestamp().isAfter(startDate)) {
25522 amit.gupta 658
						genericRepository.delete(uwh);
659
						userWallet.setAmount(userWallet.getAmount() - uwh.getAmount());
660
					}
661
				}
662
			} else {
663
				List<ScanRecord> scanRecords = scanRecordRepository.selectByInventoryItemId(ii.getId());
664
				int orderId = scanRecords.get(0).getOrderId();
665
				List<UserWalletHistory> historyList = userWalletHistoryRepository
666
						.selectAllByreferenceIdandreferenceType(orderId, WalletReferenceType.SCHEME_OUT);
667
				for (UserWalletHistory uwh : historyList) {
25530 amit.gupta 668
					if (uwh.getTimestamp().isAfter(startDate)) {
25522 amit.gupta 669
						userWallet.setAmount(userWallet.getAmount() - uwh.getAmount());
670
						genericRepository.delete(uwh);
671
					}
672
				}
673
				List<UserWalletHistory> historyListBroken = userWalletHistoryRepository
25530 amit.gupta 674
						.selectAllByreferenceIdandreferenceType(ii.getPurchaseId(), WalletReferenceType.SCHEME_OUT);
25522 amit.gupta 675
				for (UserWalletHistory uwh : historyListBroken) {
25530 amit.gupta 676
					if (uwh.getTimestamp().isAfter(startDate)) {
25522 amit.gupta 677
						genericRepository.delete(uwh);
678
						userWallet.setAmount(userWallet.getAmount() - uwh.getAmount());
679
					}
680
				}
681
			}
682
 
25530 amit.gupta 683
			// System.out.println("Total Amount Rolled Back is " + totalRollbackAmount);
25516 amit.gupta 684
		}
25589 amit.gupta 685
		scheduledTasks.processScheme(startDate, startDate.plusDays(10), true);
25030 amit.gupta 686
	}
25530 amit.gupta 687
 
688
	public void fixWallet() throws Exception {
689
		List<FofoStore> fofoStores = fofoStoreRepository.selectAll();
25536 amit.gupta 690
		System.out.println("id\tcode\tactive\tname\tcity\tstate\twallet amount\tsum\twallet amount-sum");
25530 amit.gupta 691
		for (FofoStore fofoStore : fofoStores) {
692
			UserWallet uw = userWalletRepository.selectByRetailerId(fofoStore.getId());
693
			User user = userRepository.selectById(fofoStore.getId());
25749 amit.gupta 694
			if (user == null) {
25533 amit.gupta 695
				LOGGER.info("store does not exist", fofoStore.getCode());
25535 amit.gupta 696
				continue;
25533 amit.gupta 697
			}
25536 amit.gupta 698
			Address address = null;
699
			try {
700
				address = addressRepository.selectById(user.getAddressId());
25749 amit.gupta 701
			} catch (Exception e) {
25536 amit.gupta 702
				LOGGER.info("Could not find address for Store", fofoStore.getCode());
703
				address = new Address();
704
			}
25539 amit.gupta 705
			double sum = userWalletHistoryRepository.selectSumByWallet(uw.getId());
25749 amit.gupta 706
			int calculated = (int) sum;
707
			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(),
708
					fofoStore.isActive(), address.getName(), address.getCity(), address.getState(), uw.getAmount(),
709
					calculated, uw.getAmount() - calculated);
25530 amit.gupta 710
		}
711
	}
25749 amit.gupta 712
 
25734 amit.gupta 713
	public void changeWarehouse() throws Exception {
714
		transactionService.moveWarehouses();
715
	}
25749 amit.gupta 716
 
717
	public void mailDashboardScreenshots() throws Exception {
718
		System.setProperty("webdriver.chrome.driver", "/usr/bin/chromedriver");
719
 
25752 amit.gupta 720
		ChromeOptions options = new ChromeOptions();
721
		options.addArguments("--headless");
722
		options.addArguments("--no-sandbox");
723
		options.addArguments("start-maximized");
724
		options.addArguments("disable-infobars");
725
		options.addArguments("--disable-extensions");
726
 
25753 amit.gupta 727
		WebDriver driver = new ChromeDriver(options);
25774 amit.gupta 728
		driver.manage().window().setSize(new Dimension(1600, 900));
25749 amit.gupta 729
		driver.manage().window().maximize();
25752 amit.gupta 730
		// Deleting all the cookies
25749 amit.gupta 731
		driver.manage().deleteAllCookies();
25752 amit.gupta 732
		// Specifiying pageLoadTimeout and Implicit wait
25749 amit.gupta 733
		driver.manage().timeouts().pageLoadTimeout(40, TimeUnit.SECONDS);
734
		driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
25752 amit.gupta 735
 
25749 amit.gupta 736
		Map<String, Set<Integer>> authUserPartnerIdMapping = csService.getAuthUserPartnerIdMapping();
737
		Set<Integer> allPartners = new HashSet<>();
25765 amit.gupta 738
		Map<Integer, File> partnerSnapshotMap = new HashMap<>();
25752 amit.gupta 739
		authUserPartnerIdMapping.values().stream().forEach(x -> allPartners.addAll(x));
25749 amit.gupta 740
		System.out.println(allPartners.size());
25752 amit.gupta 741
		for (int fofoId : allPartners) {
25749 amit.gupta 742
			driver.get("https://partners.smartdukaan.com/12dashboard34?fofoId=" + fofoId);
25765 amit.gupta 743
			File file = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
744
			partnerSnapshotMap.put(fofoId, file);
25752 amit.gupta 745
 
25749 amit.gupta 746
		}
25752 amit.gupta 747
		for (Map.Entry<String, Set<Integer>> entry : authUserPartnerIdMapping.entrySet()) {
25749 amit.gupta 748
			String email = entry.getKey();
25996 amit.gupta 749
			LOGGER.info("Sending mail start to {}", email);
25749 amit.gupta 750
			Set<Integer> partnerIds = entry.getValue();
751
			StringBuffer body = new StringBuffer();
25769 amit.gupta 752
			Map<Integer, File> emailSnapshotMap = new HashMap<>();
25752 amit.gupta 753
			for (int fofoId : partnerIds) {
25769 amit.gupta 754
				body.append(String.format("<br/><img src=\"cid:%d\"/>", fofoId));
755
				emailSnapshotMap.put(fofoId, partnerSnapshotMap.get(fofoId));
25749 amit.gupta 756
			}
25837 amit.gupta 757
			Utils.sendEmbeddedHtmlMail(mailSender, new String[] { email }, new String[] {},
25752 amit.gupta 758
					String.format("Franchise Screenshots - %s", FormattingUtils.formatDate(LocalDateTime.now())),
25837 amit.gupta 759
					body.toString(), emailSnapshotMap);
25996 amit.gupta 760
			LOGGER.info("Sent mail to {}", email);
25749 amit.gupta 761
		}
762
		driver.quit();
763
	}
26033 amit.gupta 764
 
26299 amit.gupta 765
	// Rollout prebooking orders amount in case the order is grned.
26033 amit.gupta 766
	public void pbfix() throws ProfitMandiBusinessException {
767
		List<Item> items = itemRepository.selectAllByCatalogItemId(1022304);
26299 amit.gupta 768
		for (Item item : items) {
26033 amit.gupta 769
			List<InventoryItem> inventoryItems = inventoryItemRepository.selectByItemId(item.getId(), 0, 500);
26299 amit.gupta 770
			for (InventoryItem inventoryItem : inventoryItems) {
26033 amit.gupta 771
				List<PrebookingOrder> prebookingOrders = prebookingOrderRepository
26299 amit.gupta 772
						.selectByFofoIdAndCatalogIds(inventoryItem.getFofoId(), item.getCatalogItemId()).stream()
773
						.collect(Collectors.toList());
774
				if (prebookingOrders.size() > 0) {
775
					purchaseService.sendPrebookingNotifyMessage(prebookingOrders.get(0));
26033 amit.gupta 776
				}
26299 amit.gupta 777
				// inventoryItem.getFofoId()
26033 amit.gupta 778
			}
779
		}
26299 amit.gupta 780
		// throw new ProfitMandiBusinessException("", "", "");
781
		// prebookingOrderRepository.select
26033 amit.gupta 782
		// TODO Auto-generated method stub
26299 amit.gupta 783
 
26033 amit.gupta 784
	}
26092 amit.gupta 785
 
26299 amit.gupta 786
	public void fixGrn() throws Exception {
26092 amit.gupta 787
		List<Purchase> incompletePurchases = purchaseRepository.selectIncompletePurchase();
26299 amit.gupta 788
		for (Purchase incompletePurchase : incompletePurchases) {
789
			List<Order> orders = orderRepository.selectByAirwayBillOrInvoiceNumber(
790
					incompletePurchase.getPurchaseReference(), incompletePurchase.getFofoId());
26093 amit.gupta 791
			List<InventoryItem> inventoryItems = inventoryItemRepository.selectByPurchaseId(incompletePurchase.getId());
792
			Map<Integer, Integer> grnedItems = inventoryItems.stream().collect(
26299 amit.gupta 793
					Collectors.groupingBy(x -> x.getItemId(), Collectors.summingInt(x -> x.getInitialQuantity())));
794
			Map<Integer, Integer> billedItems = orders.stream().collect(Collectors.groupingBy(
795
					x -> x.getLineItem().getItemId(), Collectors.summingInt(x -> x.getLineItem().getQuantity())));
796
			for (Integer billedItemId : billedItems.keySet()) {
797
				if (grnedItems.containsKey(billedItemId)) {
798
					if (grnedItems.get(billedItemId) > billedItems.get(billedItemId)) {
799
						LOGGER.info("Billed Qty {} ---- Grned {}, ItemId {}, Invoice Number {}({}), Grn Date {}",
800
								billedItems.get(billedItemId), grnedItems.get(billedItemId), billedItemId,
801
								incompletePurchase.getPurchaseReference(), incompletePurchase.getId(),
802
								incompletePurchase.getCreateTimestamp());
26095 amit.gupta 803
						Item item = itemRepository.selectById(billedItemId);
26299 amit.gupta 804
						if (item.getType().equals(ItemType.SERIALIZED)) {
805
 
26096 amit.gupta 806
						} else {
26299 amit.gupta 807
							for (InventoryItem inventoryItem : inventoryItems) {
808
								if (inventoryItem.getItemId() == billedItemId && inventoryItem.getGoodQuantity() == 0) {
809
									List<ScanRecord> scanRecords = scanRecordRepository
810
											.selectByInventoryItemId(inventoryItem.getId());
811
									if (scanRecords.size() == 1 && scanRecords.get(0).getQuantity() == 0) {
26096 amit.gupta 812
										LOGGER.info("Safe to remove InventoryItem Id {}", inventoryItem.getId());
26101 amit.gupta 813
										scanRecordRepository.delete(scanRecords.get(0));
814
										inventoryItemRepository.delete(inventoryItem);
26299 amit.gupta 815
										incompletePurchase.setUnfullfilledNonSerializedQuantity(
816
												incompletePurchase.getUnfullfilledNonSerializedQuantity()
817
														+ inventoryItem.getInitialQuantity());
26096 amit.gupta 818
									}
819
								}
820
							}
26095 amit.gupta 821
						}
26093 amit.gupta 822
					}
823
				}
26092 amit.gupta 824
			}
26299 amit.gupta 825
 
26092 amit.gupta 826
		}
26299 amit.gupta 827
 
26092 amit.gupta 828
	}
26265 amit.gupta 829
 
830
	public void fixDupGrns() throws Exception {
26412 amit.gupta 831
		List<Integer> duplicatePurchaseIds = Arrays.asList(14984);
26299 amit.gupta 832
		for (int duplicatePurchaseId : duplicatePurchaseIds) {
26265 amit.gupta 833
			Purchase purchase = purchaseRepository.selectById(duplicatePurchaseId);
834
			List<InventoryItem> inventoryItems = inventoryItemRepository.selectByPurchaseId(duplicatePurchaseId);
26299 amit.gupta 835
			if (inventoryItems.size() == 0) {
26266 amit.gupta 836
				LOGGER.info("Could not find InventoryItems for {}", duplicatePurchaseId);
837
				continue;
838
			}
26299 amit.gupta 839
			schemeService.rollbackSchemes(inventoryItems.stream().map(x -> x.getId()).collect(Collectors.toList()),
840
					duplicatePurchaseId,
841
					"Rolled back duplicate grn for Purchase Invoice " + purchase.getPurchaseReference());
842
			for (InventoryItem inventoryItem : inventoryItems) {
26265 amit.gupta 843
				inventoryItemRepository.delete(inventoryItem);
844
				List<ScanRecord> scanRecords = scanRecordRepository.selectByInventoryItemId(inventoryItem.getId());
26299 amit.gupta 845
				for (ScanRecord scanRecord : scanRecords) {
26265 amit.gupta 846
					scanRecordRepository.delete(scanRecord);
847
				}
26299 amit.gupta 848
				List<SchemeInOut> sios = schemeInOutRepository
849
						.selectByInventoryItemIds(new HashSet<>(Arrays.asList(inventoryItem.getId())));
850
				for (SchemeInOut sio : sios) {
26265 amit.gupta 851
					LOGGER.info("SIO - {}", sio);
852
					schemeInOutRepository.delete(sio);
853
				}
26299 amit.gupta 854
 
26265 amit.gupta 855
			}
856
		}
26299 amit.gupta 857
		// throw new Exception();
26265 amit.gupta 858
	}
26579 amit.gupta 859
 
860
	public void mongom() {
861
		List<TagListing> tls = tagListingRepository.selectAll(false);
862
		Set<Integer> itemIds = tls.stream().map(x -> x.getItemId()).collect(Collectors.toSet());
863
		Set<Integer> catalogIds = itemRepository.selectByIds(itemIds).stream().map(x -> x.getCatalogItemId())
864
				.collect(Collectors.toSet());
865
		for (int catalogId : catalogIds) {
866
			try {
867
				ContentPojo cp = mongoClient.getEntityById(catalogId);
26580 amit.gupta 868
				try {
869
					cp.setIconImageUrl(cp.getIconImageUrl().replace("saholic", "smartdukaan"));
26759 amit.gupta 870
				} catch (Exception e) {
871
 
26580 amit.gupta 872
				}
26759 amit.gupta 873
 
26580 amit.gupta 874
				try {
875
					cp.setThumbnailImageUrl(cp.getThumbnailImageUrl().replace("saholic", "smartdukaan"));
26759 amit.gupta 876
				} catch (Exception e) {
877
 
26580 amit.gupta 878
				}
26759 amit.gupta 879
 
26579 amit.gupta 880
				cp.setDefaultImageUrl(cp.getDefaultImageUrl().replace("saholic", "smartdukaan"));
881
				List<MediaPojo> mPojos = cp.getImages();
26759 amit.gupta 882
				if (mPojos != null) {
26580 amit.gupta 883
					mPojos.stream().forEach(mPojo -> {
884
						mPojo.setUrl(mPojo.getUrl().replace("saholic", "smartdukaan"));
885
					});
886
				}
26579 amit.gupta 887
				mongoClient.persistEntity(cp);
888
			} catch (Exception e) {
889
				continue;
890
			}
891
		}
892
	}
26759 amit.gupta 893
 
894
	public void cancelDn(String debitNoteNumber) throws Exception {
895
		DebitNote debitNote = debitNoteRepository.selectDebitNoteByNumber(debitNoteNumber);
26928 amit.gupta 896
 
897
		List<PurchaseReturnItem> purchaseReturnItems = purchaseReturnItemRepository
898
				.selectAllByDebitNoteId(debitNote.getId());
26759 amit.gupta 899
		// Select all inventory Item
900
		Set<Integer> inventoryItemIds = purchaseReturnItems.stream().map(x -> x.getInventoryItemId())
901
				.collect(Collectors.toSet());
902
		List<InventoryItem> inventoryItems = inventoryItemRepository.selectByIds(inventoryItemIds);
903
		for (InventoryItem inventoryItem : inventoryItems) {
904
			if (!StringUtils.isEmpty(inventoryItem.getSerialNumber())) {
905
				inventoryItem.setGoodQuantity(1);
906
				inventoryItem.setLastScanType(ScanType.PURCHASE);
907
				ScanRecord sr = scanRecordRepository.selectByInventoryItemId(inventoryItem.getId()).stream()
908
						.filter(x -> x.getType().equals(ScanType.PURCHASE_RET)).findFirst().get();
909
				scanRecordRepository.delete(sr);
910
				CurrentInventorySnapshot cis = currentInventorySnapshotRepository
911
						.selectByItemAndFofoId(inventoryItem.getItemId(), inventoryItem.getFofoId());
912
				if (cis == null) {
913
					cis = new CurrentInventorySnapshot();
914
					cis.setFofoId(inventoryItem.getFofoId());
915
					cis.setItemId(inventoryItem.getId());
916
					currentInventorySnapshotRepository.persist(cis);
917
				}
918
				cis.setAvailability(cis.getAvailability() + 1);
919
				schemeService.processSchemeIn(inventoryItem.getPurchaseId(), inventoryItem.getFofoId());
920
			}
26928 amit.gupta 921
		}
922
		purchaseReturnItems.stream().forEach(x -> purchaseReturnItemRepository.delete(x));
26759 amit.gupta 923
	}
26799 amit.gupta 924
 
925
	public void processPd(int priceDropId) throws ProfitMandiBusinessException {
27079 amit.gupta 926
		priceDropService.processPriceDrop(priceDropId, false);
26799 amit.gupta 927
	}
26928 amit.gupta 928
 
929
	public void fixScheme() throws Exception {
26936 amit.gupta 930
		LOGGER.info("Partner Types found\tPartnerType To Remove\tAmout to Rollback");
26928 amit.gupta 931
		final Map<Integer, Scheme> schemesMap = schemeRepository.selectAll().stream()
932
				.collect(Collectors.toMap(x -> x.getId(), x -> x));
933
		List<SchemeInOut> sios = schemeInOutRepository.selectAllByCreateDate(LocalDate.of(2019, 9, 1).atTime(0, 0),
934
				LocalDateTime.now());
27221 amit.gupta 935
		Map<SioTuple, Map<PartnerType, List<SchemeInOut>>> schemeTupleMap = sios.stream()
936
				.filter(x -> x.getRolledBackTimestamp() == null)
26928 amit.gupta 937
				.filter(x -> schemesMap.get(x.getSchemeId()).getPartnerType() != PartnerType.ALL)
938
				.collect(Collectors.groupingBy(
939
						x -> new SioTuple(x.getInventoryItemId(), schemesMap.get(x.getSchemeId()).getType()),
27221 amit.gupta 940
						Collectors.groupingBy(x -> schemesMap.get(x.getSchemeId()).getPartnerType(),
941
								Collectors.mapping(x -> x, Collectors.toList()))));
942
 
943
		schemeTupleMap.entrySet().stream().filter(x -> x.getValue().size() > 1).forEach(x -> {
26929 amit.gupta 944
			Map<PartnerType, List<SchemeInOut>> partnerTypeSchemeMap = x.getValue();
27221 amit.gupta 945
			PartnerType partnerTypeToRemove = partnerTypeSchemeMap.keySet().stream()
946
					.min(Comparator.comparing(y -> PartnerType.PartnerTypeRankMap.get(y))).get();
947
			LOGGER.info("{}\t{}\t{}\t{}\t{}\t{}", partnerTypeSchemeMap.keySet(), partnerTypeToRemove,
948
					partnerTypeSchemeMap.get(partnerTypeToRemove).stream()
949
							.collect(Collectors.summingDouble(SchemeInOut::getAmount)),
950
					FormattingUtils.formatDate(partnerTypeSchemeMap.get(partnerTypeToRemove).stream()
951
							.map(y -> y.getCreateTimestamp()).findFirst().get()));
952
 
26928 amit.gupta 953
		});
954
	}
955
 
956
	private class SioTuple {
957
		int inventoryId;
958
		SchemeType schemeType;
959
 
960
		public SioTuple(int inventoryItemId, SchemeType schemeType) {
961
			this.inventoryId = inventoryItemId;
962
			this.schemeType = schemeType;
963
		}
964
 
965
		public int getInventoryId() {
966
			return inventoryId;
967
		}
968
 
969
		public void setInventoryId(int inventoryId) {
970
			this.inventoryId = inventoryId;
971
		}
972
 
973
		public SchemeType getSchemeType() {
974
			return schemeType;
975
		}
976
 
977
		public void setSchemeType(SchemeType schemeType) {
978
			this.schemeType = schemeType;
979
		}
980
 
981
		@Override
982
		public int hashCode() {
983
			final int prime = 31;
984
			int result = 1;
985
			result = prime * result + getOuterType().hashCode();
986
			result = prime * result + inventoryId;
987
			result = prime * result + ((schemeType == null) ? 0 : schemeType.hashCode());
988
			return result;
989
		}
990
 
991
		@Override
992
		public boolean equals(Object obj) {
993
			if (this == obj)
994
				return true;
995
			if (obj == null)
996
				return false;
997
			if (getClass() != obj.getClass())
998
				return false;
999
			SioTuple other = (SioTuple) obj;
1000
			if (!getOuterType().equals(other.getOuterType()))
1001
				return false;
1002
			if (inventoryId != other.inventoryId)
1003
				return false;
1004
			if (schemeType != other.schemeType)
1005
				return false;
1006
			return true;
1007
		}
1008
 
1009
		private RunOnceTasks getOuterType() {
1010
			return RunOnceTasks.this;
1011
		}
1012
 
1013
	}
27221 amit.gupta 1014
 
1015
	public void printPendingLeads() {
27277 amit.gupta 1016
		LOGGER.info("PENDING LEADES {}", leadRepository
1017
				.selectLeadsScheduledBetweenDate(LocalDateTime.now().minusDays(15), LocalDateTime.now().plusHours(4)));
27221 amit.gupta 1018
	}
27277 amit.gupta 1019
 
27286 amit.gupta 1020
	public void removeDuplicateOrders() throws Exception {
27451 tejbeer 1021
		List<String> invoiceNumbers = Arrays.asList(/*
1022
													 * "DLWE066/1108", "DLWE066/299", "DLWE066/348", "HRFB004/242",
1023
													 * "HRFB004/243", "HRFB004/514", "HRFTB155/29", "HRJND076/1146",
1024
													 * "HRJND076/966", "HRKA134/295", "HRKA134/421", "HRKK091/381",
1025
													 * "HRMGH106/576", "HRSP056/139", "HRYN030/103", "UPGZ019/395",
1026
													 * "UPHRD130/1299", "UPHRD130/456", "UPHRD130/634", "UPLKO063/897",
1027
													 * "UPMRT149/54", "UPSJP119/748", "UPSJP119/980", "UPSTP065/1218",
1028
													 * "UPSTP065/2039", "UPSTP090/437", "UPSTP120/164",
1029
													 */
27312 amit.gupta 1030
				"HRMGH106/1576");
27451 tejbeer 1031
 
27288 amit.gupta 1032
		int totalAmount = 0;
1033
		float saleAmount = 0;
27289 amit.gupta 1034
		float schemeReverseAmount = 0;
27451 tejbeer 1035
		for (String invoiceNumber : invoiceNumbers) {
27281 amit.gupta 1036
			List<FofoOrder> orders = fofoOrderRepository.selectByInvoiceNumberLike(invoiceNumber);
27283 amit.gupta 1037
			orders = orders.stream().skip(1).collect(Collectors.toList());
27286 amit.gupta 1038
			for (FofoOrder fofoOrder : orders) {
27295 amit.gupta 1039
				LOGGER.info("Fofo Order Id - {}, Invoice {}", fofoOrder.getId(), invoiceNumber);
27286 amit.gupta 1040
				int inventoryItemId = 0;
27288 amit.gupta 1041
				saleAmount += fofoOrder.getTotalAmount();
27297 amit.gupta 1042
				fofoOrderRepository.delete(fofoOrder);
27302 amit.gupta 1043
				LOGGER.info("Fofo Order Id - {}, Invoice {}", fofoOrder.getId(), invoiceNumber);
27286 amit.gupta 1044
				List<FofoOrderItem> fofoOrderItems = fofoOrderItemRepository.selectByOrderId(fofoOrder.getId());
27451 tejbeer 1045
				List<PaymentOptionTransaction> paymentOptionTransactions = paymentOptionTransactionRepository
1046
						.selectByReferenceIdAndType(fofoOrder.getId(), PaymentOptionReferenceType.ORDER);
1047
				for (PaymentOptionTransaction paymentOptionTransaction : paymentOptionTransactions) {
27297 amit.gupta 1048
					paymentOptionTransactionRepository.delete(paymentOptionTransaction);
27286 amit.gupta 1049
				}
27451 tejbeer 1050
				for (FofoOrderItem foi : fofoOrderItems) {
27302 amit.gupta 1051
					List<FofoLineItem> flis = fofoLineItemRepository.selectByFofoOrderItemId(foi.getId());
27297 amit.gupta 1052
					fofoOrderItemRepository.delete(foi);
27451 tejbeer 1053
					for (FofoLineItem fli : flis) {
27302 amit.gupta 1054
						inventoryItemId = fli.getInventoryItemId();
27297 amit.gupta 1055
						fofoLineItemRepository.delete(fli);
27286 amit.gupta 1056
					}
1057
				}
27451 tejbeer 1058
				// Rollback entry with reversal reason
1059
				if (fofoOrder.getCreateTimestamp().isAfter(LocalDate.of(2020, 4, 1).atStartOfDay())) {
27293 amit.gupta 1060
					float invoiceSchemeReversalAmount = 0;
27451 tejbeer 1061
					List<UserWalletHistory> userWalletHistory = userWalletHistoryRepository
1062
							.selectAllByreferenceIdandreferenceType(fofoOrder.getId(), WalletReferenceType.SCHEME_OUT);
1063
					float invoiceWalletAmount = userWalletHistory.stream()
1064
							.collect(Collectors.summingInt(y -> y.getAmount()));
27303 amit.gupta 1065
					totalAmount += invoiceWalletAmount;
27299 amit.gupta 1066
					try {
27451 tejbeer 1067
						walletService.rollbackAmountFromWallet(fofoOrder.getFofoId(), invoiceWalletAmount,
1068
								fofoOrder.getId(), WalletReferenceType.SCHEME_OUT,
1069
								"Same order for Invoice-" + invoiceNumber + "created twice, duplicate invoice rollback",
1070
								fofoOrder.getCancelledTimestamp());
27299 amit.gupta 1071
					} catch (Exception e) {
1072
						LOGGER.info("Failed wallet update Reson [{}]", e.getMessage());
1073
					}
27301 amit.gupta 1074
					LOGGER.info("inventoryItemId - {}", inventoryItemId);
27451 tejbeer 1075
					List<SchemeInOut> schemeInOuts = schemeInOutRepository
1076
							.selectByInventoryItemIds(new HashSet<>(Arrays.asList(inventoryItemId)));
27292 amit.gupta 1077
					Set<Integer> schemeIds = new HashSet<>();
27298 amit.gupta 1078
					Set<Integer> schemeIdsRolledback = new HashSet<>();
27451 tejbeer 1079
					for (SchemeInOut sio : schemeInOuts) {
1080
						if (Math.abs(sio.getCreateTimestamp().until(fofoOrder.getCreateTimestamp(),
1081
								ChronoUnit.MINUTES)) <= 35 && sio.getRolledBackTimestamp() == null) {
27289 amit.gupta 1082
							LOGGER.info(sio);
27451 tejbeer 1083
							if (!schemeIds.contains(sio.getSchemeId())) {
27292 amit.gupta 1084
								schemeIds.add(sio.getSchemeId());
27298 amit.gupta 1085
							} else if (!schemeIdsRolledback.contains(sio.getSchemeId())) {
1086
								schemeIdsRolledback.add(sio.getSchemeId());
27297 amit.gupta 1087
								sio.setRolledBackTimestamp(LocalDateTime.now());
27292 amit.gupta 1088
								schemeReverseAmount += sio.getAmount();
27293 amit.gupta 1089
								invoiceSchemeReversalAmount += sio.getAmount();
27292 amit.gupta 1090
							}
27289 amit.gupta 1091
						}
27286 amit.gupta 1092
					}
27451 tejbeer 1093
					if (Math.abs(invoiceWalletAmount - invoiceSchemeReversalAmount) > 3) {
27303 amit.gupta 1094
						LOGGER.info("No Matchhhh");
1095
					}
27451 tejbeer 1096
					LOGGER.info("invoiceWalletAmount - {}, invoiceSchemeReversalAmount {}", invoiceWalletAmount,
1097
							invoiceSchemeReversalAmount);
1098
				}
27283 amit.gupta 1099
			}
27277 amit.gupta 1100
		}
27451 tejbeer 1101
		LOGGER.info(
1102
				"Total Sale Amount Reversal - {}, Total Wallet Amount Reversal {}, Total Scheme Reversal Amount - {}",
1103
				saleAmount, totalAmount, schemeReverseAmount);
1104
		// throw new Exception();
27277 amit.gupta 1105
	}
27430 amit.gupta 1106
 
27450 tejbeer 1107
	public void createGeofence() throws IOException, ProfitMandiBusinessException {
1108
 
27486 tejbeer 1109
		// List<FofoStore> fofoStores = fofoStoreRepository.selectActiveStores();
1110
		// for (FofoStore fofoStore : fofoStores) {
1111
		// if (fofoStore.getLatitude() != null && fofoStore.getLongitude() != null) {
27503 tejbeer 1112
		CustomRetailer customRetailer = retailerService.getFofoRetailer(175138812);
27486 tejbeer 1113
		OkHttpClient client = new OkHttpClient();
1114
		okhttp3.MediaType mediaType = okhttp3.MediaType.parse("application/json");
1115
		JSONObject geofe = new JSONObject();
1116
		JSONArray geofences = new JSONArray();
1117
		JSONObject geometry = new JSONObject();
1118
		JSONObject geo = new JSONObject();
1119
		JSONArray coordinates = new JSONArray();
1120
		ArrayList<Double> crds = new ArrayList<>();
1121
		// crds.add(Double.parseDouble(fofoStore.getLongitude()));
1122
		// crds.add(Double.parseDouble(fofoStore.getLatitude()));
27503 tejbeer 1123
		crds.add(79.739197);
1124
		crds.add(27.961215);
27486 tejbeer 1125
		// crds.add(77.08596155373755);
1126
		// crds.add(28.64944201113976);
1127
		// coordinates.put(fofoStore.getLongitude());
1128
		// coordinates.put(fofoStore.getLatitude());
1129
		geo.put("type", "Point");
1130
		geo.put("coordinates", crds);
1131
		geometry.put("geometry", geo);
1132
		JSONObject metadata = new JSONObject();
27503 tejbeer 1133
		metadata.put("name", customRetailer.getBusinessName());
1134
		metadata.put("city", customRetailer.getAddress().getCity());
1135
		metadata.put("Code", customRetailer.getCode());
27487 tejbeer 1136
		geometry.put("metadata", metadata);
27486 tejbeer 1137
		geometry.put("radius", 200);
27451 tejbeer 1138
 
27486 tejbeer 1139
		geofences.put(geometry);
1140
		geofe.put("geofences", geofences);
1141
		okhttp3.RequestBody body = okhttp3.RequestBody.create(mediaType, geofe.toString());
1142
		String authString = "Basic "
1143
				+ Base64.getEncoder().encodeToString(String.format("%s:%s", ACCOUNT_ID, SECRET_KEY).getBytes());
27450 tejbeer 1144
 
27486 tejbeer 1145
		Request request1 = new Request.Builder().url("https://v3.api.hypertrack.com/geofences").post(body)
1146
				.addHeader("Authorization", authString).build();
27450 tejbeer 1147
 
27486 tejbeer 1148
		Response response = client.newCall(request1).execute();
27450 tejbeer 1149
 
27486 tejbeer 1150
		JSONArray ja = new JSONArray(response.body().string());
1151
		LOGGER.info("geofence" + ja);
1152
		LOGGER.info("jalength" + ja.length());
1153
		/*
1154
		 * for (int i = 0; i < ja.length(); i++) { JSONObject c = ja.getJSONObject(i);
1155
		 * String geofenceId = c.getString("geofence_id"); LOGGER.info("geofenceId" +
1156
		 * geofenceId); FofoStoreGeofence fsg = new FofoStoreGeofence();
1157
		 * fsg.setFofoId(customRetailer.getPartnerId()); fsg.setGeofenceId(geofenceId);
1158
		 * fofoStoreGeofenceRepository.persist(fsg); }
1159
		 * 
1160
		 * }
1161
		 * 
1162
		 * }
1163
		 */
27482 tejbeer 1164
 
27462 tejbeer 1165
	}
1166
 
27451 tejbeer 1167
	public void getAllGeofences() throws IOException, ProfitMandiBusinessException {
27450 tejbeer 1168
 
1169
		OkHttpClient client = new OkHttpClient();
1170
 
1171
		String authString = "Basic "
1172
				+ Base64.getEncoder().encodeToString(String.format("%s:%s", ACCOUNT_ID, SECRET_KEY).getBytes());
1173
 
1174
		// Get geofences created for all app users
1175
		Request request1 = new Request.Builder().url("https://v3.api.hypertrack.com/geofences")
1176
				.addHeader("Authorization", authString).build();
1177
 
1178
		Response response = client.newCall(request1).execute();
27451 tejbeer 1179
 
27450 tejbeer 1180
		LOGGER.info("response" + response.body().string());
1181
	}
1182
 
27457 tejbeer 1183
	public void deleteGeofences(List<String> geofenceIds) throws IOException, ProfitMandiBusinessException {
1184
		OkHttpClient client = new OkHttpClient();
1185
 
1186
		String authString = "Basic "
1187
				+ Base64.getEncoder().encodeToString(String.format("%s:%s", ACCOUNT_ID, SECRET_KEY).getBytes());
1188
 
1189
		for (String geofenceId : geofenceIds) {
27460 tejbeer 1190
			Request request1 = new Request.Builder().url("https://v3.api.hypertrack.com/geofences/" + geofenceId)
27457 tejbeer 1191
					.delete().addHeader("Authorization", authString).build();
1192
			LOGGER.info("geofenceId" + geofenceId);
1193
			Response response = client.newCall(request1).execute();
1194
 
27460 tejbeer 1195
			LOGGER.info("response" + response.body().string());
27457 tejbeer 1196
		}
1197
 
1198
	}
1199
 
27430 amit.gupta 1200
	public void processSchemeOut(int fofoId, int orderId) throws Exception {
1201
		schemeService.processSchemeOut(orderId, fofoId);
27451 tejbeer 1202
 
27430 amit.gupta 1203
	}
27511 amit.gupta 1204
 
1205
	public void createDummyInvoices() {
27787 amit.gupta 1206
		List<WarehouseInventoryItem> lavaInventoryItems = warehouseInventoryItemRepository.getSerialNumbers("Lava",
1207
				LocalDate.of(2020, Month.SEPTEMBER, 1).atStartOfDay(), LocalDateTime.now());
27511 amit.gupta 1208
		LOGGER.info("Lava Inventory Size is {}", lavaInventoryItems.size());
1209
	}
28624 amit.gupta 1210
 
27948 amit.gupta 1211
	public void createOffers(int offerId) throws Exception {
28042 amit.gupta 1212
		Map<List<Integer>, List<Integer>> targetMap = new HashMap<>();
28624 amit.gupta 1213
		targetMap.put(Arrays.asList(175138805, 175138733, 175138821, 175138886, 175138853, 175138799),
1214
				Arrays.asList(300000, 330000, 375000));
1215
		targetMap.put(Arrays.asList(175138895, 175138877, 175138854, 175138857, 175138870, 175138862, 175138873),
1216
				Arrays.asList(350000, 400000, 450000));
1217
		targetMap.put(Arrays.asList(175138878), Arrays.asList(380000, 418000, 475000));
1218
		targetMap.put(Arrays.asList(175138922, 175138833, 175138893, 175138939, 175138832, 175138949, 175138882,
1219
				175138876, 175138834, 175138930, 175138911, 175138522, 175138871, 175138934, 175138900, 4149607,
1220
				175138835, 175138941, 175138917, 175138855, 175138825, 175138896, 175138866, 175138174, 175138887,
1221
				175138816, 175138892, 175135376, 175138918, 175138845, 175138946, 175138920, 175138903, 175138813,
1222
				175138901, 175138899, 175136389, 175138913, 175138919, 175138923, 175138926, 175138950, 175138953,
1223
				175138954, 175138955), Arrays.asList(400000, 500000, 600000));
1224
		targetMap.put(Arrays.asList(175138839), Arrays.asList(412000, 453200, 515000));
1225
		targetMap.put(Arrays.asList(175138716), Arrays.asList(450000, 495000, 562500));
1226
		targetMap.put(Arrays.asList(175138812), Arrays.asList(465000, 511500, 581250));
1227
		targetMap.put(Arrays.asList(175138859, 175138906, 175138874, 175138940, 175138916, 175136207, 175138851,
1228
				175138844, 175138929), Arrays.asList(500000, 600000, 700000));
1229
		targetMap.put(Arrays.asList(175138804, 175138910), Arrays.asList(550000, 600000, 650000));
1230
		targetMap.put(Arrays.asList(175127215, 175138879), Arrays.asList(555000, 610500, 693750));
1231
		targetMap.put(
1232
				Arrays.asList(175138869, 175138902, 175138909, 175138914, 175138824, 157112773, 175138897, 175138801),
1233
				Arrays.asList(600000, 730000, 840000));
1234
		targetMap.put(Arrays.asList(172157716), Arrays.asList(616000, 677600, 770000));
1235
		targetMap.put(Arrays.asList(175138674, 175138840), Arrays.asList(650000, 715000, 812500));
1236
		targetMap.put(Arrays.asList(175138936, 175138952, 175138907, 156232687, 175138856, 175138836, 175138942),
1237
				Arrays.asList(700000, 800000, 900000));
1238
		targetMap.put(Arrays.asList(175138868), Arrays.asList(775000, 852500, 968750));
1239
		targetMap.put(Arrays.asList(175138820), Arrays.asList(780000, 850000, 1050000));
1240
		targetMap.put(Arrays.asList(175138864, 175138863, 175138867, 175138823, 175135227),
1241
				Arrays.asList(800000, 900000, 1000000));
1242
		targetMap.put(Arrays.asList(175138408), Arrays.asList(850000, 900000, 950000));
1243
		targetMap.put(Arrays.asList(175135923, 175138888), Arrays.asList(900000, 990000, 1125000));
1244
		targetMap.put(Arrays.asList(175138908), Arrays.asList(1000000, 1200000, 1350000));
1245
		targetMap.put(Arrays.asList(175138843), Arrays.asList(1100000, 1200000, 1350000));
1246
		targetMap.put(Arrays.asList(175138827), Arrays.asList(1150000, 1265000, 1437500));
1247
		targetMap.put(Arrays.asList(175138883, 175135707), Arrays.asList(1200000, 1300000, 1400000));
1248
		targetMap.put(Arrays.asList(175138814, 175138829), Arrays.asList(1300000, 1500000, 1650000));
1249
		targetMap.put(Arrays.asList(175138842, 175138875), Arrays.asList(1500000, 1650000, 1800000));
1250
		targetMap.put(Arrays.asList(175138541), Arrays.asList(1600000, 1700000, 1850000));
1251
		targetMap.put(Arrays.asList(175138372), Arrays.asList(1890000, 2079000, 2362500));
1252
		targetMap.put(Arrays.asList(175138885), Arrays.asList(2100000, 2400000, 2600000));
1253
 
27948 amit.gupta 1254
		CreateOfferRequest createOfferRequest = offerService.getOffer(offerId);
28624 amit.gupta 1255
		for (Map.Entry<List<Integer>, List<Integer>> targetEntry : targetMap.entrySet()) {
27948 amit.gupta 1256
			List<Integer> targets = targetEntry.getValue();
28042 amit.gupta 1257
 
1258
			createOfferRequest.getPartnerCriteria().setFofoIds(targetEntry.getKey());
27948 amit.gupta 1259
			int counter = 0;
28624 amit.gupta 1260
			for (com.spice.profitmandi.dao.model.TargetSlab targetSlab : createOfferRequest.getTargetSlabs()) {
27948 amit.gupta 1261
				targetSlab.setOnwardsAmount(targets.get(counter));
1262
				counter++;
1263
			}
1264
			offerService.addOfferService(createOfferRequest);
1265
		}
1266
	}
27747 amit.gupta 1267
 
28038 amit.gupta 1268
	@Autowired
1269
	private WarehouseScanRepository warehouseScanRepository;
28046 amit.gupta 1270
 
1271
	@Autowired
1272
	private WarehouseInventoryService warehouseInventoryService;
28624 amit.gupta 1273
 
28038 amit.gupta 1274
	public void fixScans() {
1275
		Map<Integer, Integer> inventoryOrderMap = new HashMap<>();
28624 amit.gupta 1276
		inventoryOrderMap.put(348795, 1628598);
1277
		inventoryOrderMap.put(348796, 1628599);
1278
		inventoryOrderMap.put(329854, 1628600);
1279
		inventoryOrderMap.put(334197, 1628602);
1280
		inventoryOrderMap.put(330110, 1628603);
1281
		inventoryOrderMap.put(330111, 1628604);
1282
		inventoryOrderMap.put(332843, 1628605);
1283
		inventoryOrderMap.put(338067, 1628606);
1284
		inventoryOrderMap.put(338974, 1628609);
1285
		inventoryOrderMap.put(338975, 1628610);
1286
		inventoryOrderMap.put(338971, 1628612);
1287
		inventoryOrderMap.put(338588, 1628615);
1288
		inventoryOrderMap.put(368205, 1631619);
1289
		inventoryOrderMap.put(368206, 1631620);
1290
		inventoryOrderMap.put(368207, 1631621);
1291
		inventoryOrderMap.put(368208, 1631622);
1292
		inventoryOrderMap.put(368209, 1631623);
1293
		inventoryOrderMap.put(368211, 1631625);
1294
		inventoryOrderMap.put(368213, 1631627);
1295
		inventoryOrderMap.put(368214, 1631628);
1296
		inventoryOrderMap.put(368203, 1631629);
1297
		inventoryOrderMap.put(368216, 1631630);
1298
		inventoryOrderMap.put(368217, 1631631);
1299
		inventoryOrderMap.put(368218, 1631632);
1300
		inventoryOrderMap.put(368219, 1631633);
1301
		inventoryOrderMap.put(368222, 1631635);
1302
		List<WarehouseScan> scans = warehouseScanRepository
1303
				.selectAllByInventoryItemIds(new ArrayList<>(inventoryOrderMap.keySet()));
1304
		Map<Integer, List<WarehouseScan>> inventoryScansMap = scans.stream()
1305
				.collect(Collectors.groupingBy(WarehouseScan::getInventoryItemId));
1306
 
1307
		for (Map.Entry<Integer, List<WarehouseScan>> mapEntry : inventoryScansMap.entrySet()) {
28038 amit.gupta 1308
			int inventoryItemId = mapEntry.getKey();
28624 amit.gupta 1309
			List<WarehouseScan> duplicateScans = mapEntry.getValue().stream().filter(
1310
					x -> x.getOrderId() != null && x.getOrderId().equals(inventoryOrderMap.get(inventoryItemId)))
1311
					.collect(Collectors.toList());
28047 amit.gupta 1312
			WarehouseScan duplicateScan = duplicateScans.stream().skip(1).findFirst().get();
28046 amit.gupta 1313
			warehouseScanRepository.delete(duplicateScan);
1314
			warehouseInventoryService.addQuantity(duplicateScan.getInventoryItemId(), duplicateScan.getQuantity());
28624 amit.gupta 1315
 
28038 amit.gupta 1316
		}
28624 amit.gupta 1317
 
28038 amit.gupta 1318
	}
1319
 
28561 amit.gupta 1320
	public void fixOffer() throws Exception {
28624 amit.gupta 1321
		List<Integer> offerIds = Arrays.asList(228, 241, 242, 243, 244, 253);
1322
		List<Integer> fofoIds = fofoStoreRepository.selectAll().stream().filter(x -> x.getWarehouseId() == 7678)
1323
				.map(x -> x.getId()).collect(Collectors.toList());
28563 amit.gupta 1324
		LOGGER.info("UP West Partner Ids - {}", fofoIds);
28624 amit.gupta 1325
		for (int offerId : offerIds) {
1326
			Offer offer = offerRepository.selectById(offerId);
1327
 
28557 amit.gupta 1328
			PartnerCriteria partnerCriteria = gson.fromJson(offer.getPartnerCriteria(), PartnerCriteria.class);
28563 amit.gupta 1329
			LOGGER.info("Offer Partner Ids - {}", partnerCriteria.getFofoIds());
28560 amit.gupta 1330
			for (Integer fofoId : fofoIds) {
28624 amit.gupta 1331
				if (partnerCriteria.getFofoIds().contains(fofoId)) {
1332
					// This shoud be removed
1333
					LOGGER.info("This shoud be removed FofoStore Code - {}",
1334
							fofoStoreRepository.selectByRetailerId(fofoId).getCode());
28557 amit.gupta 1335
					partnerCriteria.getFofoIds().remove(fofoId);
1336
				}
1337
			}
1338
			offer.setPartnerCriteria(gson.toJson(partnerCriteria));
1339
		}
1340
	}
28624 amit.gupta 1341
 
28622 amit.gupta 1342
	public void reverseMaa() throws Exception {
28624 amit.gupta 1343
		Purchase purchase = purchaseRepository.selectById(28877);
1344
		Set<Integer> inventoryItemIds = inventoryItemRepository.selectByPurchaseId(28877).stream().map(x -> x.getId())
1345
				.collect(Collectors.toSet());
1346
		double totalAmount = schemeInOutRepository.selectByInventoryItemIds(inventoryItemIds).stream()
28625 amit.gupta 1347
				/*
1348
				 * .filter(x -> x.getRolledBackTimestamp() == null ||
1349
				 * x.getStatusDescription().contains("investment")) .map(x -> {
1350
				 * x.setRolledBackTimestamp(LocalDateTime.now());
1351
				 * x.setStatus(SchemePayoutStatus.REJECTED); x.
1352
				 * setStatusDescription("Invoice-NSLCK3350 was cancelled, hence all schemes were rolled back"
1353
				 * ); return x; })
1354
				 */
28624 amit.gupta 1355
				.collect(Collectors.summingDouble(x -> x.getAmount()));
1356
		WalletReferenceType walletReferenceType = WalletReferenceType.OTHERS;
1357
		ManualPaymentType paymentType = manualPaymentRequestRepository.selectByReferenceType(walletReferenceType);
1358
		if (paymentType == null) {
1359
			paymentType = new ManualPaymentType();
1360
			paymentType.setReferenceType(walletReferenceType);
1361
			manualPaymentRequestRepository.persist(paymentType);
1362
		}
1363
		paymentType.setCounter(paymentType.getCounter() + 1);
1364
		int reference = paymentType.getCounter();
28660 amit.gupta 1365
		walletService.consumeAmountFromWallet(purchase.getFofoId(), reference, WalletReferenceType.OTHERS,
1366
				"Invoice-NSLCK3350 was cancelled, hence all schemes were rolled back", (int) totalAmount,
1367
				LocalDateTime.now());
28624 amit.gupta 1368
		LOGGER.info("Total Deduction is around Rs. {}", totalAmount);
28622 amit.gupta 1369
	}
28557 amit.gupta 1370
 
28660 amit.gupta 1371
	public void opporeno() {
1372
		List<Integer> offerIds = Arrays.asList(270, 269, 267, 265, 264, 257, 253, 244, 243, 242, 241, 240, 239, 228,
1373
				227, 226, 225);
1374
		for (Integer offerId : offerIds) {
1375
			Offer offer = offerRepository.selectById(offerId);
1376
			com.spice.profitmandi.service.offers.ItemCriteria itemCriteria = gson.fromJson(offer.getItemCriteria(),
1377
					com.spice.profitmandi.service.offers.ItemCriteria.class);
1378
			if (itemCriteria.getExcludeCatalogIds().contains(1022950)) {
1379
				System.out.println("Excludes reno");
1380
			} else {
1381
				System.out.println("Does not excludes reno.. excluding it");
1382
				itemCriteria.getExcludeCatalogIds().add(1022950);
1383
				offer.setItemCriteria(gson.toJson(itemCriteria));
1384
			}
1385
 
1386
		}
1387
	}
28810 amit.gupta 1388
 
28736 amit.gupta 1389
	@Autowired
1390
	SaholicReservationSnapshotRepository saholicReservationSnapshotRepository;
28810 amit.gupta 1391
 
28736 amit.gupta 1392
	@Autowired
1393
	SaholicInventoryService saholicInventoryService;
28660 amit.gupta 1394
 
28736 amit.gupta 1395
	public void fixReservations() throws Exception {
28810 amit.gupta 1396
		// Clear all Reservations
1397
		saholicInventorySnapshotRepository.selectAll().stream().forEach(x -> x.setReserved(0));
1398
		saholicReservationSnapshotRepository.selectAll().forEach(x -> saholicReservationSnapshotRepository.delete(x));
28736 amit.gupta 1399
		List<Order> orders = orderRepository.selectAllOrderDatesBetweenByStatus(
1400
				LocalDate.now().minusDays(40).atStartOfDay(), LocalDateTime.now(),
1401
				OrderStatus.SUBMITTED_FOR_PROCESSING);
28810 amit.gupta 1402
		for (Order order : orders) {
1403
			SaholicReservationSnapshot saholicReservationSnapshot = saholicReservationSnapshotRepository
1404
					.selectByOrderId(order.getId());
1405
			if (saholicReservationSnapshot == null) {
1406
				saholicInventoryService.addReservationCount(order.getLineItem().getItemId(),
1407
						order.getFulfilmentWarehouseId(), order.getLineItem().getQuantity(), order.getId());
28736 amit.gupta 1408
			}
28810 amit.gupta 1409
		}
28736 amit.gupta 1410
	}
1411
 
28675 amit.gupta 1412
	public void fixOrders() throws Exception {
28736 amit.gupta 1413
		List<Order> orders = orderRepository.selectAllOrderDatesBetweenByStatus(
1414
				LocalDate.now().minusDays(10).atStartOfDay(), LocalDateTime.now(),
1415
				OrderStatus.SUBMITTED_FOR_PROCESSING);
28731 amit.gupta 1416
		orders = orders.stream().filter(x -> x.getCreateTimestamp().isAfter(LocalDateTime.of(2021, 7, 21, 0, 0, 0)))
1417
				.collect(Collectors.toList());
1418
		for (Order order : orders) {
1419
 
28736 amit.gupta 1420
			LineItem lineItem = lineItemRepository.selectById(order.getLineItem().getId());
1421
			if (order.getOrderType() == null) {
1422
				order.setProductCondition(0);
1423
				order.setOrderType(0);
1424
				int itemId = order.getLineItem().getItemId();
1425
				int fulfillmentWarehouseId = order.getFulfilmentWarehouseId();
1426
				System.out.println("Item id " + itemId);
1427
				Item item = itemRepository.selectById(itemId);
1428
 
1429
				VendorItemPricing vendorItemPricing = vendorItemPricingRepository.selectByItemIdAndVendorId(itemId,
1430
						fulfillmentWarehouseId);
1431
				if (vendorItemPricing == null) {
1432
					vendorItemPricing = vendorItemPricingRepository.selectAll(itemId).get(0);
1433
				}
1434
				System.out.println("vendorItemPricing " + vendorItemPricing);
1435
				lineItem.setProductGoup(item.getProductGroup());
1436
				lineItem.setColor(item.getColor());
1437
				lineItem.setNlc(vendorItemPricing.getNlc());
1438
				lineItem.setTransferPrice(vendorItemPricing.getTp());
1439
				lineItem.setLogisticsCost(0f);
1440
				lineItem.setCodCollectionCharges(0f);
1441
 
1442
			}
1443
 
28731 amit.gupta 1444
			int warehouseTo = fofoStoreRepository.selectByRetailerId(order.getRetailerId()).getWarehouseId();
1445
			int itemId = order.getLineItem().getItemId();
28736 amit.gupta 1446
			Warehouse warehouse = transactionService.getFulfilmentWarehouseMap(Arrays.asList(itemId), warehouseTo)
1447
					.get(itemId);
1448
			LOGGER.info(
1449
					"Order Id - {}, WarehouseTo - {}, Item Id - {}, Warehouse From - {}, Fulfilment Warehouse Id - {}",
28732 amit.gupta 1450
					order.getId(), warehouseTo, itemId, warehouse.getBillingWarehouseId(), warehouse.getId());
28733 amit.gupta 1451
			order.setWarehouseId(warehouse.getBillingWarehouseId());
1452
			order.setFulfilmentWarehouseId(warehouse.getId());
28731 amit.gupta 1453
 
28675 amit.gupta 1454
		}
28731 amit.gupta 1455
 
28675 amit.gupta 1456
	}
28810 amit.gupta 1457
 
28808 amit.gupta 1458
	@Autowired
1459
	PartnerDailyInvestmentRepository partnerDailyInvestmentRepository;
28675 amit.gupta 1460
 
28808 amit.gupta 1461
	public void addInvestment() {
1462
		List<LocalDate> dates = Arrays.asList(LocalDate.of(2021, 7, 13), LocalDate.of(2021, 7, 31));
28810 amit.gupta 1463
		List<Integer> fofoIds = Arrays.asList(175136207, 175138910, 175138967, 175138990, 175138999);
1464
		for (LocalDate date : dates) {
28808 amit.gupta 1465
			LOGGER.info("Date - {}", date);
28810 amit.gupta 1466
			Map<Integer, Boolean> investmentMap = partnerDailyInvestmentRepository.selectAll(date.plusDays(1)).stream()
1467
					.collect(Collectors.toMap(x -> x.getFofoId(), x -> x.getShortPercentage() <= 10));
28808 amit.gupta 1468
			List<PartnerDailyInvestment> investments = partnerDailyInvestmentRepository.selectAll(date.minusDays(1));
28810 amit.gupta 1469
			for (PartnerDailyInvestment investment : investments) {
1470
				if (investmentMap.get(investment.getFofoId()) == null
1471
						|| (investmentMap.get(investment.getFofoId()) == investment.getShortPercentage() <= 10)) {
1472
					// Do nothing
1473
				} else if(fofoIds.contains(investment.getFofoId())){
28808 amit.gupta 1474
					LOGGER.info("Problem with fofo id => {}", investment.getFofoId());
1475
				}
1476
			}
1477
		}
1478
	}
1479
 
25043 amit.gupta 1480
}
1481
 
1482
//7015845171