Subversion Repositories SmartDukaan

Rev

Rev 37658 | Rev 37686 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 37658 Rev 37675
Line 1... Line 1...
1
package com.smartdukaan.cron.migrations;
1
package com.smartdukaan.cron.migrations;
2
 
2
 
3
import com.google.gson.Gson;
3
import com.google.gson.Gson;
4
import com.smartdukaan.cron.scheduled.SamsungIMEIActivationService;
-
 
5
import com.smartdukaan.cron.scheduled.ScheduledTasks;
4
import com.smartdukaan.cron.scheduled.ScheduledTasks;
6
import com.smartdukaan.cron.scheduled.amazon.shop.AmazonPurchaseService;
-
 
7
import com.smartdukaan.cron.scheduled.amazon.shop.OrderSummary;
-
 
8
import com.smartdukaan.cron.scheduled.amazon.shop.model.OrderRow;
-
 
9
import com.smartdukaan.cron.scheduled.ambreports.AbmReportSender;
5
import com.smartdukaan.cron.scheduled.ambreports.AbmReportSender;
10
import com.spice.profitmandi.common.enumuration.ItemType;
6
import com.spice.profitmandi.common.enumuration.ItemType;
11
import com.spice.profitmandi.common.enumuration.PurchaseReturnStatus;
7
import com.spice.profitmandi.common.enumuration.PurchaseReturnStatus;
12
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
8
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
13
import com.spice.profitmandi.common.model.CustomRetailer;
9
import com.spice.profitmandi.common.model.CustomRetailer;
Line 187... Line 183...
187
 
183
 
188
    @Autowired
184
    @Autowired
189
    private PaymentOptionTransactionRepository paymentOptionTransactionRepository;
185
    private PaymentOptionTransactionRepository paymentOptionTransactionRepository;
190
 
186
 
191
    @Autowired
187
    @Autowired
192
    private SamsungIMEIActivationService samsungIMEIActivationService;
-
 
193
 
-
 
194
    @Autowired
-
 
195
    private PrebookingOrderRepository prebookingOrderRepository;
188
    private PrebookingOrderRepository prebookingOrderRepository;
196
 
189
 
197
    @Autowired
190
    @Autowired
198
    private PartnerTargetRepository partnerTargetRepository;
191
    private PartnerTargetRepository partnerTargetRepository;
199
 
192
 
Line 343... Line 336...
343
            }
336
            }
344
        }
337
        }
345
 
338
 
346
    }
339
    }
347
 
340
 
348
    public void fetchImeiActivation(int ym) throws Exception {
-
 
349
        LocalDate startDate = null;
-
 
350
        LocalDate endDate = null;
-
 
351
        if (ym == 0) {
-
 
352
            startDate = LocalDate.now().minusDays(30);
-
 
353
            endDate = LocalDate.now();
-
 
354
        } else {
-
 
355
            startDate = LocalDate.now().minusMonths(ym);
-
 
356
            endDate = startDate.plusMonths(1);
-
 
357
        }
-
 
358
        samsungIMEIActivationService.getActivationsBetweenNew(startDate, endDate);
-
 
359
    }
-
 
360
 
-
 
361
    public void cancelOrder(List<String> invoiceNumbers) throws Exception {
341
    public void cancelOrder(List<String> invoiceNumbers) throws Exception {
362
        orderService.cancelOrder(invoiceNumbers);
342
        orderService.cancelOrder(invoiceNumbers);
363
    }
343
    }
364
 
344
 
365
    @Autowired
345
    @Autowired
Line 947... Line 927...
947
        } catch (Throwable t) {
927
        } catch (Throwable t) {
948
            t.printStackTrace();
928
            t.printStackTrace();
949
        }
929
        }
950
    }
930
    }
951
 
931
 
952
    @Autowired
-
 
953
    AmazonPurchaseService amazonPurchaseService;
-
 
954
 
-
 
955
    private static DataFormatter formatter = new DataFormatter();
932
    private static DataFormatter formatter = new DataFormatter();
956
 
933
 
957
    @Autowired
934
    @Autowired
958
    OfferTargetSlabRepository offerTargetSlabRepository;
935
    OfferTargetSlabRepository offerTargetSlabRepository;
959
 
936
 
960
    public void amazonPurchase() throws Exception {
-
 
961
        //Read file
-
 
962
        FileInputStream fis = new FileInputStream(new File("/Users/amit/Downloads/amazon.xlsx"));
-
 
963
        //creating workbook instance that refers to .xls file
-
 
964
        XSSFWorkbook wb = new XSSFWorkbook(fis);
-
 
965
        //creating a Sheet object to retrieve the object
-
 
966
        XSSFSheet sheet = wb.getSheetAt(0);
-
 
967
 
-
 
968
        OrderSummary orderSummary = this.getOrderSummary(sheet);
-
 
969
        List<OrderRow> orderRows = new ArrayList<>();
-
 
970
        int rows = sheet.getLastRowNum();
-
 
971
        for (int rowNum = 3; rowNum < rows; rowNum++) {
-
 
972
            try {
-
 
973
                OrderRow orderRow = parseRow(orderSummary, sheet.getRow(rowNum));
-
 
974
                orderRows.add(orderRow);
-
 
975
            } catch (RuntimeException re) {
-
 
976
                System.out.println("Could not parse rownum - " + rowNum);
-
 
977
            }
-
 
978
        }
-
 
979
        amazonPurchaseService.purchaseAmazon(orderSummary, orderRows);
-
 
980
    }
-
 
981
 
-
 
982
    private OrderSummary getOrderSummary(XSSFSheet sheet) {
-
 
983
        XSSFRow firstRow = sheet.getRow(0);
-
 
984
        String asin = firstRow.getCell(1).getStringCellValue();
-
 
985
        int purchasePrice = (int) firstRow.getCell(3).getNumericCellValue();
-
 
986
        int qtyPerOrder = (int) firstRow.getCell(5).getNumericCellValue();
-
 
987
        boolean gst = Boolean.parseBoolean(getCellString(firstRow.getCell(7)));
-
 
988
        XSSFRow secondRow = sheet.getRow(1);
-
 
989
        boolean prepaid = Boolean.parseBoolean(getCellString(secondRow.getCell(1)));
-
 
990
        boolean noCostEmi = Boolean.parseBoolean(getCellString(secondRow.getCell(3)));
-
 
991
        OrderSummary orderSummary = new OrderSummary();
-
 
992
        orderSummary.setAsin(asin);
-
 
993
        orderSummary.setGst(gst);
-
 
994
        orderSummary.setQtyPerOrder(qtyPerOrder);
-
 
995
        orderSummary.setPrepaid(prepaid);
-
 
996
        orderSummary.setNoCostEmi(noCostEmi);
-
 
997
        return orderSummary;
-
 
998
    }
-
 
999
 
-
 
1000
    private static String getCellString(XSSFCell xssfCell) {
-
 
1001
        xssfCell.setCellType(CellType.STRING);
-
 
1002
        return xssfCell.getStringCellValue();
-
 
1003
    }
-
 
1004
 
-
 
1005
    private OrderRow parseRow(OrderSummary orderSummary, XSSFRow row) {
-
 
1006
        int col = 0;
-
 
1007
        OrderRow orderRow = new OrderRow();
-
 
1008
        String userName = getCellString(row.getCell(col++));
-
 
1009
        String password = getCellString(row.getCell(col++));
-
 
1010
        orderRow.setUserName(userName);
-
 
1011
        orderRow.setPassword(password);
-
 
1012
 
-
 
1013
        if (orderSummary.isPrepaid()) {
-
 
1014
            String cardName = getCellString(row.getCell(col++));
-
 
1015
            String cardNumber = getCellString(row.getCell(col++));
-
 
1016
            String cardExpiryYr = getCellString(row.getCell(col++));
-
 
1017
            String cardExpiryMonth = getCellString(row.getCell(col++));
-
 
1018
            String cvv = getCellString(row.getCell(col++));
-
 
1019
            String verificationPin = getCellString(row.getCell(col++));
-
 
1020
            boolean orderPlaced = getCellString(row.getCell(col++)).equals("1") ? true : false;
-
 
1021
            orderRow.setCardNumber(cardNumber);
-
 
1022
            orderRow.setCvv(StringUtils.repeat("0", 3 - cvv.length()) + cvv);
-
 
1023
            orderRow.setCardName(cardName);
-
 
1024
            orderRow.setExpiryYr(cardExpiryYr);
-
 
1025
            orderRow.setExpiryMonth(cardExpiryMonth);
-
 
1026
            orderRow.setVerificationPin(verificationPin);
-
 
1027
            orderRow.setOrderPlaced(orderPlaced);
-
 
1028
        }
-
 
1029
        return orderRow;
-
 
1030
    }
-
 
1031
 
-
 
1032
    @Autowired
937
    @Autowired
1033
    ItemCriteriaRepository itemCriteriaRepository;
938
    ItemCriteriaRepository itemCriteriaRepository;
1034
 
939
 
1035
    public void createOfferCriteria() throws Exception {
940
    public void createOfferCriteria() throws Exception {
1036
        Offer offer = offerRepository.selectById(1099);
941
        Offer offer = offerRepository.selectById(1099);