| Line 20... |
Line 20... |
| 20 |
import org.springframework.beans.factory.annotation.Autowired;
|
20 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 21 |
import org.springframework.core.io.ByteArrayResource;
|
21 |
import org.springframework.core.io.ByteArrayResource;
|
| 22 |
import org.springframework.mail.javamail.JavaMailSender;
|
22 |
import org.springframework.mail.javamail.JavaMailSender;
|
| 23 |
import org.springframework.stereotype.Component;
|
23 |
import org.springframework.stereotype.Component;
|
| 24 |
import org.springframework.transaction.annotation.Transactional;
|
24 |
import org.springframework.transaction.annotation.Transactional;
|
| 25 |
import org.w3c.dom.stylesheets.LinkStyle;
|
- |
|
| 26 |
|
25 |
|
| 27 |
import com.itextpdf.text.log.SysoCounter;
|
26 |
import com.smartdukaan.cron.scheduled.ScheduledTasks;
|
| 28 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
- |
|
| 29 |
import com.spice.profitmandi.common.util.FileUtil;
|
27 |
import com.spice.profitmandi.common.util.FileUtil;
|
| 30 |
import com.spice.profitmandi.common.util.Utils;
|
28 |
import com.spice.profitmandi.common.util.Utils;
|
| 31 |
import com.spice.profitmandi.dao.entity.catalog.Scheme;
|
29 |
import com.spice.profitmandi.dao.entity.catalog.Scheme;
|
| 32 |
import com.spice.profitmandi.dao.entity.fofo.CurrentInventorySnapshot;
|
30 |
import com.spice.profitmandi.dao.entity.fofo.CurrentInventorySnapshot;
|
| 33 |
import com.spice.profitmandi.dao.entity.fofo.FofoOrder;
|
31 |
import com.spice.profitmandi.dao.entity.fofo.FofoOrder;
|
| Line 38... |
Line 36... |
| 38 |
import com.spice.profitmandi.dao.entity.fofo.ScanRecord;
|
36 |
import com.spice.profitmandi.dao.entity.fofo.ScanRecord;
|
| 39 |
import com.spice.profitmandi.dao.entity.fofo.SchemeInOut;
|
37 |
import com.spice.profitmandi.dao.entity.fofo.SchemeInOut;
|
| 40 |
import com.spice.profitmandi.dao.entity.fofo.SchemeItem;
|
38 |
import com.spice.profitmandi.dao.entity.fofo.SchemeItem;
|
| 41 |
import com.spice.profitmandi.dao.entity.fofo.TargetSlab;
|
39 |
import com.spice.profitmandi.dao.entity.fofo.TargetSlab;
|
| 42 |
import com.spice.profitmandi.dao.entity.inventory.SaholicInventorySnapshot;
|
40 |
import com.spice.profitmandi.dao.entity.inventory.SaholicInventorySnapshot;
|
| 43 |
import com.spice.profitmandi.dao.entity.inventory.SaholicReservationInventorySnapshot;
|
- |
|
| 44 |
import com.spice.profitmandi.dao.entity.transaction.LineItem;
|
41 |
import com.spice.profitmandi.dao.entity.transaction.LineItem;
|
| 45 |
import com.spice.profitmandi.dao.entity.transaction.LineItemImei;
|
42 |
import com.spice.profitmandi.dao.entity.transaction.LineItemImei;
|
| 46 |
import com.spice.profitmandi.dao.entity.transaction.Order;
|
43 |
import com.spice.profitmandi.dao.entity.transaction.Order;
|
| 47 |
import com.spice.profitmandi.dao.entity.transaction.SellerWarehouse;
|
44 |
import com.spice.profitmandi.dao.entity.transaction.SellerWarehouse;
|
| 48 |
import com.spice.profitmandi.dao.entity.transaction.UserWallet;
|
- |
|
| 49 |
import com.spice.profitmandi.dao.entity.transaction.UserWalletHistory;
|
45 |
import com.spice.profitmandi.dao.entity.transaction.UserWalletHistory;
|
| 50 |
import com.spice.profitmandi.dao.enumuration.catalog.AmountType;
|
46 |
import com.spice.profitmandi.dao.enumuration.catalog.AmountType;
|
| 51 |
import com.spice.profitmandi.dao.enumuration.catalog.SchemeType;
|
47 |
import com.spice.profitmandi.dao.enumuration.catalog.SchemeType;
|
| 52 |
import com.spice.profitmandi.dao.repository.GenericRepository;
|
48 |
import com.spice.profitmandi.dao.repository.GenericRepository;
|
| 53 |
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
|
49 |
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
|
| Line 142... |
Line 138... |
| 142 |
@Autowired
|
138 |
@Autowired
|
| 143 |
private OrderService orderService;
|
139 |
private OrderService orderService;
|
| 144 |
|
140 |
|
| 145 |
@Autowired
|
141 |
@Autowired
|
| 146 |
private SchemeRepository schemeRepository;
|
142 |
private SchemeRepository schemeRepository;
|
| - |
|
143 |
|
| - |
|
144 |
@Autowired
|
| - |
|
145 |
private ScheduledTasks scheduledTasks;
|
| 147 |
|
146 |
|
| 148 |
@Autowired
|
147 |
@Autowired
|
| 149 |
private SchemeItemRepository schemeItemRepository;
|
148 |
private SchemeItemRepository schemeItemRepository;
|
| 150 |
|
149 |
|
| 151 |
@Autowired
|
150 |
@Autowired
|
| Line 609... |
Line 608... |
| 609 |
|
608 |
|
| 610 |
public void fixSchemePayouts() throws Exception {
|
609 |
public void fixSchemePayouts() throws Exception {
|
| 611 |
|
610 |
|
| 612 |
LocalDateTime startDate = LocalDate.of(2019, 6, 1).atStartOfDay();
|
611 |
LocalDateTime startDate = LocalDate.of(2019, 6, 1).atStartOfDay();
|
| 613 |
List<SchemeInOut> sios = schemeInOutRepository.selectAllByCreateDate(startDate, startDate.plusDays(15));
|
612 |
List<SchemeInOut> sios = schemeInOutRepository.selectAllByCreateDate(startDate, startDate.plusDays(15));
|
| 614 |
Float totalRollbackAmount = 0f;
|
- |
|
| - |
|
613 |
|
| 615 |
for (SchemeInOut sio : sios) {
|
614 |
for (SchemeInOut sio : sios) {
|
| - |
|
615 |
genericRepository.delete(sio);
|
| 616 |
InventoryItem ii = inventoryItemRepository.selectById(sio.getInventoryItemId());
|
616 |
InventoryItem ii = inventoryItemRepository.selectById(sio.getInventoryItemId());
|
| 617 |
Purchase purchase = purchaseRepository.selectByIdAndFofoId(ii.getPurchaseId(), ii.getFofoId());
|
617 |
Scheme scheme = schemeRepository.selectById(sio.getSchemeId());
|
| 618 |
int schemeId = sio.getSchemeId();
|
618 |
if (scheme.getType().equals(SchemeType.IN)) {
|
| 619 |
Scheme scheme = schemeRepository.selectById(schemeId);
|
619 |
Purchase purchase = purchaseRepository.selectByIdAndFofoId(ii.getPurchaseId(), ii.getFofoId());
|
| 620 |
if (schemeId < 280 && scheme.getType().equals(SchemeType.IN)
|
620 |
List<UserWalletHistory> historyList = userWalletHistoryRepository
|
| 621 |
&& scheme.getAmountType().equals(AmountType.PERCENTAGE)) {
|
621 |
.selectAllByreferenceIdandreferenceType(purchase.getId(), WalletReferenceType.SCHEME_IN);
|
| 622 |
sio.setRolledBackTimestamp(LocalDateTime.now());
|
622 |
for (UserWalletHistory uwh : historyList) {
|
| 623 |
String rollbackDescription = String.format(
|
623 |
if(uwh.getTimestamp().isAfter(startDate)) {
|
| 624 |
"Rolled back scheme %s for %s and %s (%s) as its no longer active in June", scheme.getName(),
|
624 |
genericRepository.delete(uwh);
|
| - |
|
625 |
}
|
| - |
|
626 |
}
|
| - |
|
627 |
} else {
|
| 625 |
purchase.getPurchaseReference(), itemRepository.selectById(ii.getItemId()).getItemDescription(),
|
628 |
List<ScanRecord> scanRecords = scanRecordRepository.selectByInventoryItemId(ii.getId());
|
| 626 |
ii.getSerialNumber());
|
629 |
int orderId = scanRecords.get(0).getOrderId();
|
| 627 |
System.out.println(rollbackDescription);
|
630 |
List<UserWalletHistory> historyList = userWalletHistoryRepository
|
| 628 |
walletService.rollbackAmountFromWallet(purchase.getFofoId(), sio.getAmount(), purchase.getId(),
|
631 |
.selectAllByreferenceIdandreferenceType(orderId, WalletReferenceType.SCHEME_OUT);
|
| - |
|
632 |
for (UserWalletHistory uwh : historyList) {
|
| 629 |
WalletReferenceType.SCHEME_IN, rollbackDescription);
|
633 |
if(uwh.getTimestamp().isAfter(startDate)) {
|
| 630 |
totalRollbackAmount += sio.getAmount();
|
634 |
genericRepository.delete(uwh);
|
| - |
|
635 |
}
|
| - |
|
636 |
}
|
| 631 |
}
|
637 |
}
|
| - |
|
638 |
|
| - |
|
639 |
// System.out.println("Total Amount Rolled Back is " + totalRollbackAmount);
|
| 632 |
}
|
640 |
}
|
| 633 |
System.out.println("Total Amount Rolled Back is " + totalRollbackAmount);
|
641 |
scheduledTasks.processScheme(startDate, startDate.plusDays(15));
|
| - |
|
642 |
|
| 634 |
//throw new Exception();
|
643 |
throw new Exception();
|
| 635 |
}
|
644 |
}
|
| 636 |
}
|
- |
|
| 637 |
|
645 |
}
|
| - |
|
646 |
|
| - |
|
647 |
//7015845171
|
| - |
|
648 |
|
| 638 |
|
649 |
|