| Line 45... |
Line 45... |
| 45 |
import com.spice.profitmandi.common.model.GstRate;
|
45 |
import com.spice.profitmandi.common.model.GstRate;
|
| 46 |
import com.spice.profitmandi.common.model.RechargeCredential;
|
46 |
import com.spice.profitmandi.common.model.RechargeCredential;
|
| 47 |
import com.spice.profitmandi.common.util.FileUtil;
|
47 |
import com.spice.profitmandi.common.util.FileUtil;
|
| 48 |
import com.spice.profitmandi.common.util.FormattingUtils;
|
48 |
import com.spice.profitmandi.common.util.FormattingUtils;
|
| 49 |
import com.spice.profitmandi.common.util.Utils;
|
49 |
import com.spice.profitmandi.common.util.Utils;
|
| - |
|
50 |
import com.spice.profitmandi.common.util.Utils.Attachment;
|
| 50 |
import com.spice.profitmandi.dao.entity.catalog.Scheme;
|
51 |
import com.spice.profitmandi.dao.entity.catalog.Scheme;
|
| 51 |
import com.spice.profitmandi.dao.entity.cs.Ticket;
|
52 |
import com.spice.profitmandi.dao.entity.cs.Ticket;
|
| 52 |
import com.spice.profitmandi.dao.entity.cs.TicketAssigned;
|
53 |
import com.spice.profitmandi.dao.entity.cs.TicketAssigned;
|
| 53 |
import com.spice.profitmandi.dao.entity.dtr.DailyRecharge;
|
54 |
import com.spice.profitmandi.dao.entity.dtr.DailyRecharge;
|
| 54 |
import com.spice.profitmandi.dao.entity.dtr.RechargeProvider;
|
55 |
import com.spice.profitmandi.dao.entity.dtr.RechargeProvider;
|
| Line 415... |
Line 416... |
| 415 |
// Temporary Method
|
416 |
// Temporary Method
|
| 416 |
public void evaluateExcessSchemeOut() throws Exception {
|
417 |
public void evaluateExcessSchemeOut() throws Exception {
|
| 417 |
Map<Integer, String> userNameMap = retailerService.getAllFofoRetailerIdNameMap();
|
418 |
Map<Integer, String> userNameMap = retailerService.getAllFofoRetailerIdNameMap();
|
| 418 |
Map<Integer, Float> userAmountMap = new HashMap<>();
|
419 |
Map<Integer, Float> userAmountMap = new HashMap<>();
|
| 419 |
|
420 |
|
| 420 |
List<List<Object>> rows = new ArrayList<>();
|
421 |
List<List<?>> rows = new ArrayList<>();
|
| 421 |
List<String> headers = Arrays.asList("Scheme", "Item", "Partner", "Amount", "Credited On", "Invoice Number",
|
422 |
List<String> headers = Arrays.asList("Scheme", "Item", "Partner", "Amount", "Credited On", "Invoice Number",
|
| 422 |
"Sale On", "Scheme Start", "Scheme End", "Active On", "Expired On");
|
423 |
"Sale On", "Scheme Start", "Scheme End", "Active On", "Expired On");
|
| 423 |
schemeRepository.selectAll().stream().forEach(x -> {
|
424 |
schemeRepository.selectAll().stream().forEach(x -> {
|
| 424 |
if (x.getType().equals(SchemeType.OUT)) {
|
425 |
if (x.getType().equals(SchemeType.OUT)) {
|
| 425 |
List<SchemeInOut> sioList = schemeInOutRepository
|
426 |
List<SchemeInOut> sioList = schemeInOutRepository
|
| Line 542... |
Line 543... |
| 542 |
.getFofoRetailers(fofoStores.stream().map(x -> x.getId()).collect(Collectors.toList()));
|
543 |
.getFofoRetailers(fofoStores.stream().map(x -> x.getId()).collect(Collectors.toList()));
|
| 543 |
|
544 |
|
| 544 |
List<String> headers = Arrays.asList("Code", "StoreName", "Email", "Mobile", "Wallet Amount",
|
545 |
List<String> headers = Arrays.asList("Code", "StoreName", "Email", "Mobile", "Wallet Amount",
|
| 545 |
"Yesterday's Sale", "In Stock Amount", "Return In Transit Stock", "Unbilled Amount",
|
546 |
"Yesterday's Sale", "In Stock Amount", "Return In Transit Stock", "Unbilled Amount",
|
| 546 |
"Grn Pending Amount", "Min Investment", "Investment Amount", "Investment Short");
|
547 |
"Grn Pending Amount", "Min Investment", "Investment Amount", "Investment Short");
|
| 547 |
List<List<Object>> rows = new ArrayList<>();
|
548 |
List<List<?>> rows = new ArrayList<>();
|
| 548 |
for (FofoStore fofoStore : fofoStores) {
|
549 |
for (FofoStore fofoStore : fofoStores) {
|
| 549 |
CustomRetailer retailer = customRetailerMap.get(fofoStore.getId());
|
550 |
CustomRetailer retailer = customRetailerMap.get(fofoStore.getId());
|
| 550 |
if (retailer == null) {
|
551 |
if (retailer == null) {
|
| 551 |
LOGGER.info("Could not find retailer with retailer Id {}", fofoStore.getId());
|
552 |
LOGGER.info("Could not find retailer with retailer Id {}", fofoStore.getId());
|
| 552 |
continue;
|
553 |
continue;
|
| Line 876... |
Line 877... |
| 876 |
}
|
877 |
}
|
| 877 |
}
|
878 |
}
|
| 878 |
|
879 |
|
| 879 |
}
|
880 |
}
|
| 880 |
|
881 |
|
| 881 |
public void dryRunSchemeReco() {
|
882 |
public void dryRunSchemeReco() throws Exception {
|
| - |
|
883 |
List<UserWalletHistory> userWalletHistory = new ArrayList<>();
|
| - |
|
884 |
List<SchemeInOut> rolledbackSios = new ArrayList<>();
|
| - |
|
885 |
Map<Integer, Integer> userWalletMap = userWalletRepository
|
| - |
|
886 |
.selectByRetailerIds(
|
| - |
|
887 |
fofoStoreRepository.selectAll().stream().map(x -> x.getId()).collect(Collectors.toSet()))
|
| - |
|
888 |
.stream().collect(Collectors.toMap(UserWallet::getUserId, UserWallet::getId));
|
| 882 |
Map<Integer, SchemeType> schemeTypeMap = schemeRepository.selectAll().stream()
|
889 |
Map<Integer, SchemeType> schemeTypeMap = schemeRepository.selectAll().stream()
|
| 883 |
.collect(Collectors.toMap(Scheme::getId, Scheme::getType));
|
890 |
.collect(Collectors.toMap(Scheme::getId, Scheme::getType));
|
| 884 |
LocalDateTime startDate = LocalDate.of(2018, 9, 4).atStartOfDay();
|
891 |
LocalDateTime startDate = LocalDate.of(2018, 9, 4).atStartOfDay();
|
| 885 |
LocalDateTime endDate = startDate.plusDays(1);
|
892 |
LocalDateTime endDate = startDate.plusDays(4);
|
| 886 |
List<FofoOrder> allOrders = fofoOrderRepository.selectBetweenSaleDate(startDate, endDate);
|
893 |
List<FofoOrder> allOrders = fofoOrderRepository.selectBetweenSaleDate(startDate, endDate);
|
| 887 |
allOrders.stream().forEach(fofoOrder -> {
|
894 |
allOrders.stream().forEach(fofoOrder -> {
|
| - |
|
895 |
String description = "Adjustment of Duplicate Scheme for Sale Invoice " + fofoOrder.getInvoiceNumber();
|
| 888 |
List<Integer> inventoryItemIds = new ArrayList<>();
|
896 |
List<Integer> inventoryItemIds = new ArrayList<>();
|
| - |
|
897 |
float amountToRollback = 0;
|
| 889 |
List<FofoOrderItem> orderItems = fofoOrderItemRepository.selectByOrderId(fofoOrder.getId());
|
898 |
List<FofoOrderItem> orderItems = fofoOrderItemRepository.selectByOrderId(fofoOrder.getId());
|
| 890 |
orderItems.forEach(x -> {
|
899 |
orderItems.forEach(x -> {
|
| 891 |
inventoryItemIds.addAll(x.getFofoLineItems().stream().map(FofoLineItem::getInventoryItemId)
|
900 |
inventoryItemIds.addAll(x.getFofoLineItems().stream().map(FofoLineItem::getInventoryItemId)
|
| 892 |
.collect(Collectors.toSet()));
|
901 |
.collect(Collectors.toSet()));
|
| 893 |
});
|
902 |
});
|
| 894 |
List<SchemeType> sios = schemeInOutRepository.selectAllDuplicate(inventoryItemIds).stream()
|
903 |
List<SchemeInOut> sios = schemeInOutRepository.selectAllDuplicate(inventoryItemIds).stream()
|
| 895 |
.map(x -> schemeTypeMap.get(x.getSchemeId()))
|
904 |
.filter(x -> schemeTypeMap.get(x.getSchemeId()).equals(SchemeType.OUT))
|
| 896 |
.filter(schemeType -> schemeType.equals(SchemeType.OUT)).collect(Collectors.toList());
|
905 |
.collect(Collectors.toList());
|
| 897 |
if (sios.size() > 0) {
|
906 |
if (sios.size() > 0) {
|
| 898 |
LOGGER.info("Found {} duplicate scheme outs for Orderid {}", sios.size(), fofoOrder.getId());
|
907 |
LOGGER.info("Found {} duplicate schemeouts for Orderid {}", sios.size(), fofoOrder.getId());
|
| - |
|
908 |
UserWalletHistory uwh = new UserWalletHistory();
|
| - |
|
909 |
for (SchemeInOut sio : sios) {
|
| - |
|
910 |
|
| - |
|
911 |
List<SchemeInOut> souts = schemeInOutRepository.selectByScheme(sio.getSchemeId(),
|
| - |
|
912 |
sio.getInventoryItemId());
|
| - |
|
913 |
if (souts.size() > 2) {
|
| - |
|
914 |
LOGGER.info("Ignoring Scheme outs for Scheme {}, InventoryItem {} as Qty is {}",
|
| - |
|
915 |
sio.getSchemeId(), sio.getInventoryItemId(), souts.size());
|
| - |
|
916 |
} else {
|
| - |
|
917 |
String serialNumber = inventoryItemRepository.selectById(sio.getInventoryItemId())
|
| - |
|
918 |
.getSerialNumber();
|
| - |
|
919 |
souts.get(0).setRolledBackTimestamp(LocalDateTime.now());
|
| - |
|
920 |
amountToRollback += souts.get(0).getAmount();
|
| - |
|
921 |
souts.get(0).setSchemeType(SchemeType.OUT);
|
| - |
|
922 |
souts.get(0).setSerialNumber(serialNumber);
|
| - |
|
923 |
souts.get(0).setStoreCode(fofoOrder.getInvoiceNumber().split("/")[0]);
|
| - |
|
924 |
rolledbackSios.add(souts.get(0));
|
| - |
|
925 |
}
|
| - |
|
926 |
}
|
| - |
|
927 |
uwh.setAmount(Math.round(amountToRollback));
|
| - |
|
928 |
uwh.setDescription(description);
|
| - |
|
929 |
uwh.setTimestamp(LocalDateTime.now());
|
| - |
|
930 |
uwh.setReferenceType(WalletReferenceType.SCHEME_OUT);
|
| - |
|
931 |
uwh.setReference(fofoOrder.getId());
|
| - |
|
932 |
uwh.setWalletId(userWalletMap.get(fofoOrder.getFofoId()));
|
| - |
|
933 |
uwh.setFofoId(fofoOrder.getFofoId());
|
| - |
|
934 |
uwh.setStoreCode(fofoOrder.getInvoiceNumber().split("/")[0]);
|
| - |
|
935 |
userWalletHistory.add(uwh);
|
| 899 |
}
|
936 |
}
|
| 900 |
});
|
937 |
});
|
| - |
|
938 |
ByteArrayOutputStream baos = FileUtil.getCSVByteStream(
|
| - |
|
939 |
Arrays.asList("User Id", "Reference Type", "Reference", "Amount", "Description", "Timestamp"),
|
| - |
|
940 |
userWalletHistory.stream().map(x -> Arrays.asList(x.getWalletId(), x.getReferenceType(),
|
| - |
|
941 |
x.getReference(), x.getAmount(), x.getDescription(), x.getTimestamp()))
|
| - |
|
942 |
.collect(Collectors.toList()));
|
| - |
|
943 |
|
| - |
|
944 |
ByteArrayOutputStream baosOuts = FileUtil.getCSVByteStream(
|
| - |
|
945 |
Arrays.asList("Scheme ID", "SchemeType", "Store Code", "Serial Number", "Amount", "Created",
|
| - |
|
946 |
"Rolledback"),
|
| - |
|
947 |
rolledbackSios.stream()
|
| - |
|
948 |
.map(x -> Arrays.asList(x.getSchemeId(), x.getSchemeType(), x.getStoreCode(),
|
| - |
|
949 |
x.getSerialNumber(), x.getAmount(), x.getCreateTimestamp(), x.getRolledBackTimestamp()))
|
| - |
|
950 |
.collect(Collectors.toList()));
|
| - |
|
951 |
|
| - |
|
952 |
Utils.sendMailWithAttachments(googleMailSender, new String[] { "amit.gupta@shop2020.in" }, null,
|
| - |
|
953 |
"Partner Excess Amount", "PFA",new Attachment[] {
|
| - |
|
954 |
new Attachment("WalletSummary.csv", new ByteArrayResource(baos.toByteArray())),
|
| - |
|
955 |
new Attachment("SchemeOutRolledback.csv", new ByteArrayResource(baosOuts.toByteArray())) }
|
| - |
|
956 |
);
|
| 901 |
}
|
957 |
}
|
| 902 |
}
|
958 |
}
|
| 903 |
|
959 |
|
| 904 |
/*
|
960 |
/*
|
| 905 |
* public void processSchemeForModel(String string) { pricingService
|
961 |
* public void processSchemeForModel(String string) { pricingService
|