Subversion Repositories SmartDukaan

Rev

Rev 11095 | Rev 14780 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
8739 vikram.rag 1
package in.shop2020.support.controllers;
2
 
10287 kshitij.so 3
import in.shop2020.config.ConfigException;
8739 vikram.rag 4
import in.shop2020.model.v1.catalog.CatalogService.Client;
9242 kshitij.so 5
import in.shop2020.model.v1.catalog.CatalogServiceException;
6
import in.shop2020.model.v1.catalog.Item;
11015 kshitij.so 7
import in.shop2020.model.v1.catalog.MarketplaceHistory;
9725 kshitij.so 8
import in.shop2020.model.v1.catalog.MarketplaceItems;
9780 kshitij.so 9
import in.shop2020.model.v1.catalog.MarketplacePercentage;
8739 vikram.rag 10
import in.shop2020.model.v1.catalog.SnapdealItem;
9242 kshitij.so 11
import in.shop2020.model.v1.catalog.SnapdealItemDetails;
9725 kshitij.so 12
import in.shop2020.model.v1.inventory.InventoryServiceException;
13
import in.shop2020.model.v1.inventory.InventoryType;
14
import in.shop2020.model.v1.inventory.ItemInventory;
9923 kshitij.so 15
import in.shop2020.model.v1.inventory.OOSStatus;
9725 kshitij.so 16
import in.shop2020.model.v1.inventory.Warehouse;
17
import in.shop2020.model.v1.inventory.WarehouseType;
11015 kshitij.so 18
import in.shop2020.model.v1.order.OrderSource;
8886 vikram.rag 19
import in.shop2020.model.v1.order.SnapdealOrder;
8739 vikram.rag 20
import in.shop2020.support.utils.ReportsUtils;
10225 vikram.rag 21
import in.shop2020.support.utils.UpdateSDPricingUsingPanel;
8739 vikram.rag 22
import in.shop2020.thrift.clients.CatalogClient;
9478 kshitij.so 23
import in.shop2020.thrift.clients.InventoryClient;
8739 vikram.rag 24
import in.shop2020.thrift.clients.TransactionClient;
10287 kshitij.so 25
import in.shop2020.thrift.clients.config.ConfigClient;
9725 kshitij.so 26
import in.shop2020.utils.GmailUtils;
27
import javax.mail.MessagingException;
8739 vikram.rag 28
 
29
import java.io.BufferedInputStream;
30
import java.io.File;
31
import java.io.FileInputStream;
32
import java.io.FileNotFoundException;
33
import java.io.FileOutputStream;
34
import java.io.FileWriter;
35
import java.io.IOException;
36
import java.io.InputStream;
9242 kshitij.so 37
import java.text.DecimalFormat;
8739 vikram.rag 38
import java.util.ArrayList;
9242 kshitij.so 39
import java.util.Arrays;
8739 vikram.rag 40
import java.util.HashMap;
41
import java.util.List;
42
import java.util.Map;
43
 
44
import javax.servlet.ServletContext;
45
import javax.servlet.ServletOutputStream;
46
import javax.servlet.http.HttpServletRequest;
47
import javax.servlet.http.HttpServletResponse;
48
import javax.servlet.http.HttpSession;
49
 
50
import org.apache.commons.io.FileUtils;
51
import org.apache.commons.lang.xwork.StringUtils;
52
import org.apache.poi.hssf.usermodel.HSSFRow;
53
import org.apache.poi.hssf.usermodel.HSSFSheet;
54
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
55
import org.apache.poi.ss.usermodel.Cell;
56
import org.apache.struts2.convention.annotation.InterceptorRef;
57
import org.apache.struts2.convention.annotation.InterceptorRefs;
58
import org.apache.struts2.interceptor.ServletRequestAware;
59
import org.apache.struts2.interceptor.ServletResponseAware;
60
import org.apache.struts2.util.ServletContextAware;
61
import org.apache.thrift.TException;
62
import org.apache.thrift.transport.TTransportException;
9242 kshitij.so 63
import org.json.JSONException;
64
import org.json.JSONObject;
8739 vikram.rag 65
import org.slf4j.Logger;
66
import org.slf4j.LoggerFactory;
67
 
11015 kshitij.so 68
import com.google.gson.Gson;
8739 vikram.rag 69
import com.opensymphony.xwork2.ValidationAwareSupport;
70
 
9825 kshitij.so 71
@SuppressWarnings({"unused","deprecation"})
9242 kshitij.so 72
 
73
@InterceptorRefs({
12133 kshitij.so 74
    @InterceptorRef("defaultStack"),
75
    @InterceptorRef("login")
9242 kshitij.so 76
})
77
 
8739 vikram.rag 78
public class SnapdealListController extends ValidationAwareSupport implements ServletRequestAware ,ServletResponseAware, ServletContextAware{
12133 kshitij.so 79
    /**
80
     * 
81
     */
82
    private static final long serialVersionUID = 1L;
9242 kshitij.so 83
 
84
 
12133 kshitij.so 85
    private static Logger logger = LoggerFactory.getLogger(SnapdealListController.class);
8739 vikram.rag 86
 
87
 
12133 kshitij.so 88
    private HttpServletRequest request;
89
    private HttpServletResponse response;
90
    private HttpSession session;
91
    private ServletContext context;
92
    private String url;
93
    private String itemId;
94
    private String isSnapdealListed;
95
    private String exceptionPrice;
96
    private String warehouseId;
97
    private File file;
98
    private String errMsg;
99
    private String next;
100
    private String id;
101
    private String searchText;
102
    private List<SnapdealItemDetails> snapdealItems;
103
    private long searchCount;
104
    private long totalCount;
105
    private String sellingPrice;
106
    private String transferPrice;
107
    private String webisteMrp;
108
    private String webisteSellingPrice;
109
    private String isListedOnSnapdeal;
110
    private String commission;
111
    private String serviceTax;
112
    private String courierCost;
113
    private JSONObject itemObj;
114
    private String isSuppressInventoryFeed;
115
    private String isSuppressPriceFeed;
116
    private String maxNlc;
117
    private String sdItemCode;
118
    private String supc;
119
    private String held;
120
    private String lastUpdatedInventoryTimestamp;
121
    private String lastCheckedTimestamp;
122
    private String otherCost;
123
    private String isAutoIncrement;
124
    private String isAutoDecrement;
125
    private String isManualFavourite;
126
    private String isAutoFavourite;
127
    private String currentSp;
128
    private String currentTp;
129
    private String minPosSp;
130
    private String minPosTp;
131
    private String vat;
132
    private String comparsionResult;
133
    private String maxSp;
134
    private String nDaySale;
135
    private static String live;
11015 kshitij.so 136
    private List<MarketplaceHistory> compData;
137
    private String productName;
138
    private String startDate;
139
    private String endDate;
11095 kshitij.so 140
    private String courierCostMarketplace;
12133 kshitij.so 141
    private String packagingCost;
9923 kshitij.so 142
 
12133 kshitij.so 143
 
11095 kshitij.so 144
    public String courierCostMarketplace() {
145
        return courierCostMarketplace;
146
    }
147
 
148
    public void setCourierCostMarketplace(String courierCostMarketplace) {
149
        this.courierCostMarketplace = courierCostMarketplace;
150
    }
12133 kshitij.so 151
 
11015 kshitij.so 152
    public String getnDaySale() {
12133 kshitij.so 153
        return nDaySale;
154
    }
9923 kshitij.so 155
 
12133 kshitij.so 156
    public void setnDaySale(String nDaySale) {
157
        this.nDaySale = nDaySale;
158
    }
9923 kshitij.so 159
 
12133 kshitij.so 160
    private String avgSale;
9923 kshitij.so 161
 
12133 kshitij.so 162
    public String getAvgSale() {
163
        return avgSale;
164
    }
9923 kshitij.so 165
 
12133 kshitij.so 166
    public void setAvgSale(String avgSale) {
167
        this.avgSale = avgSale;
168
    }
9923 kshitij.so 169
 
12133 kshitij.so 170
    public String getMaxSp() {
171
        return maxSp;
172
    }
9923 kshitij.so 173
 
12133 kshitij.so 174
    public void setMaxSp(String maxSp) {
175
        this.maxSp = maxSp;
176
    }
9923 kshitij.so 177
 
12133 kshitij.so 178
    public String getComparsionResult() {
179
        return comparsionResult;
180
    }
8739 vikram.rag 181
 
12133 kshitij.so 182
    public void setComparsionResult(String comparsionResult) {
183
        this.comparsionResult = comparsionResult;
184
    }
9734 kshitij.so 185
 
12133 kshitij.so 186
    private Map<Integer, Long> holdInventoryMap;
9734 kshitij.so 187
 
12133 kshitij.so 188
    public String getVat() {
189
        return vat;
190
    }
9242 kshitij.so 191
 
12133 kshitij.so 192
    public void setStartDate(String startDate) {
193
        this.startDate = startDate;
194
    }
195
 
196
    public String getStartDate() {
11015 kshitij.so 197
        return startDate;
198
    }
12133 kshitij.so 199
 
200
    public void setEndDate(String endDate) {
11015 kshitij.so 201
        this.endDate = endDate;
202
    }
12133 kshitij.so 203
 
11015 kshitij.so 204
    public String getEndDate() {
205
        return endDate;
206
    }
9242 kshitij.so 207
 
11015 kshitij.so 208
    public void setVat(String vat) {
209
        this.vat = vat;
210
    }
211
 
12133 kshitij.so 212
    public String getOtherCost() {
213
        return otherCost;
214
    }
9725 kshitij.so 215
 
12133 kshitij.so 216
    public void setOtherCost(String otherCost) {
217
        this.otherCost = otherCost;
218
    }
9725 kshitij.so 219
 
220
 
12133 kshitij.so 221
    public String getCurrentSp() {
222
        return currentSp;
223
    }
9725 kshitij.so 224
 
12133 kshitij.so 225
    public void setCurrentSp(String currentSp) {
226
        this.currentSp = currentSp;
227
    }
9725 kshitij.so 228
 
12133 kshitij.so 229
    public String getCurrentTp() {
230
        return currentTp;
231
    }
9725 kshitij.so 232
 
12133 kshitij.so 233
    public void setCurrentTp(String currentTp) {
234
        this.currentTp = currentTp;
235
    }
9725 kshitij.so 236
 
237
 
12133 kshitij.so 238
    public String getLastCheckedTimestamp() {
239
        return lastCheckedTimestamp;
240
    }
9725 kshitij.so 241
 
12133 kshitij.so 242
    public String getLastUpdatedInventoryTimestamp() {
243
        return lastUpdatedInventoryTimestamp;
244
    }
9725 kshitij.so 245
 
12133 kshitij.so 246
    public void setLastUpdatedInventoryTimestamp(
247
            String lastUpdatedInventoryTimestamp) {
248
        this.lastUpdatedInventoryTimestamp = lastUpdatedInventoryTimestamp;
249
    }
9725 kshitij.so 250
 
12133 kshitij.so 251
    public void setLastCheckedTimestamp(
252
            String lastCheckedTimestamp) {
253
        this.lastCheckedTimestamp = lastCheckedTimestamp;
254
    }
9725 kshitij.so 255
 
12133 kshitij.so 256
    public String getIsAutoIncrement() {
257
        return isAutoIncrement;
258
    }
9725 kshitij.so 259
 
12133 kshitij.so 260
    public void setIsAutoIncrement(String isAutoIncrement) {
261
        this.isAutoIncrement = isAutoIncrement;
262
    }
9725 kshitij.so 263
 
12133 kshitij.so 264
    public String getIsAutoDecrement() {
265
        return isAutoDecrement;
266
    }
9725 kshitij.so 267
 
12133 kshitij.so 268
    public void setIsAutoDecrement(String isAutoDecrement) {
269
        this.isAutoDecrement = isAutoDecrement;
270
    }
9725 kshitij.so 271
 
12133 kshitij.so 272
    public String getIsManualFavourite() {
273
        return isManualFavourite;
274
    }
9725 kshitij.so 275
 
12133 kshitij.so 276
    public void setIsManualFavourite(String isManualFavourite) {
277
        this.isManualFavourite = isManualFavourite;
278
    }
9725 kshitij.so 279
 
12133 kshitij.so 280
    public String getIsAutoFavourite() {
281
        return isAutoFavourite;
282
    }
9725 kshitij.so 283
 
12133 kshitij.so 284
    public void setIsAutoFavourite(String isAutoFavourite) {
285
        this.isAutoFavourite = isAutoFavourite;
286
    }
9725 kshitij.so 287
 
12133 kshitij.so 288
    public String getMinPosSp() {
289
        return minPosSp;
290
    }
9725 kshitij.so 291
 
12133 kshitij.so 292
    public void setMinPosSp(String minPosSp) {
293
        this.minPosSp = minPosSp;
294
    }
9725 kshitij.so 295
 
12133 kshitij.so 296
    public String getMinPosTp() {
297
        return minPosTp;
298
    }
9725 kshitij.so 299
 
12133 kshitij.so 300
    public void setMinPosTp(String minPosTp) {
301
        this.minPosTp = minPosTp;
302
    }
9725 kshitij.so 303
 
12133 kshitij.so 304
    public String getHeld() {
305
        return held;
306
    }
9725 kshitij.so 307
 
12133 kshitij.so 308
    public void setHeld(String held) {
309
        this.held = held;
310
    }
9725 kshitij.so 311
 
12133 kshitij.so 312
    public String getSupc() {
313
        return supc;
314
    }
9568 kshitij.so 315
 
12133 kshitij.so 316
    public void setSupc(String supc) {
317
        this.supc = supc;
318
    }
9568 kshitij.so 319
 
12133 kshitij.so 320
    public String getSdItemCode() {
321
        return sdItemCode;
322
    }
9478 kshitij.so 323
 
12133 kshitij.so 324
    public void setSdItemCode(String sdItemCode) {
325
        this.sdItemCode = sdItemCode;
326
    }
9478 kshitij.so 327
 
8739 vikram.rag 328
 
12133 kshitij.so 329
    static{
330
        try {
331
            live = ConfigClient.getClient().get("sync_price_on_marketplace");
332
        } catch (ConfigException e) {
333
            logger.error("Unable to get parameter from the config service", e);
334
            live = "false";
335
        }
336
    }
9242 kshitij.so 337
 
12133 kshitij.so 338
    public String index() {
339
        if (!ReportsUtils.canAccessReport((Long) session.getAttribute(ReportsUtils.ROLE),request.getServletPath())) {
340
            return "authfail";
341
        }
342
        return "index";
343
    }
9242 kshitij.so 344
 
12133 kshitij.so 345
    public String edit() {
346
        if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), request.getRequestURI().substring(request.getContextPath().length()).split("/")[1])) {
347
            return "authfail";
348
        }
349
        return "edit";
350
    }
9242 kshitij.so 351
 
12133 kshitij.so 352
    public String fetchItems() throws TException {
353
        Client CatalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
354
        if (searchText.length() == 0) {
355
            snapdealItems = CatalogClient.getSnapdealItems(Long.valueOf(next), 10);
356
            totalCount = CatalogClient.getCountForSnapdealItems();
357
            setSearchCount(totalCount);
358
        } else {
359
            List<String> subString = Arrays.asList(searchText.split(" "));
360
            snapdealItems = CatalogClient.searchSnapdealItems(subString,Long.valueOf(next), 10);
361
            totalCount = CatalogClient.getCountForSnapdealItems();
362
            searchCount = CatalogClient.getSnapdealSearchResultCount(subString);
363
        }
364
        return "snapdeal-item-table";
365
    }
9725 kshitij.so 366
 
12133 kshitij.so 367
    public SnapdealItemDetails fetchItemDetail() throws NumberFormatException, TException {
368
        Client CatalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
369
        SnapdealItemDetails sdItemDetails = CatalogClient.getSnapdealItemDetails(Long.valueOf(id));
370
        lastUpdatedInventoryTimeStampForItem(sdItemDetails.getLastUpdatedInventoryTimestamp());
371
        return sdItemDetails;
372
    }
9725 kshitij.so 373
 
12133 kshitij.so 374
    public MarketplaceItems fetchMarketplaceDetail() throws NumberFormatException, TException {
375
        Client CatalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
376
        MarketplaceItems mpItemDetails = CatalogClient.getMarketplacedetailsForItem(Long.valueOf(id), 7);
377
        lastCheckedTimeStampForItem(mpItemDetails.getLastCheckedTimestamp());
378
        return mpItemDetails;
379
    }
9725 kshitij.so 380
 
12133 kshitij.so 381
    public String getDate(long timestamp){
382
        return new java.util.Date(timestamp).toLocaleString();
9242 kshitij.so 383
 
12133 kshitij.so 384
    }
385
 
386
    public void lastUpdatedInventoryTimeStampForItem(long timestamp){
387
        setLastUpdatedInventoryTimestamp(new java.util.Date(timestamp).toLocaleString());
388
    }
389
 
390
    public void lastCheckedTimeStampForItem(long timestamp){
391
        setLastCheckedTimestamp(new java.util.Date(timestamp).toLocaleString());
392
    }
393
 
394
    public String uploadBulkSheet(){
395
        if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0])) {
396
            logger.info(request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0]);
397
            return "authfail";
398
        }
399
        return "snapdeal-bulk-upload";
400
    }
401
 
402
    public String update() throws NumberFormatException, TException, InventoryServiceException, CatalogServiceException, JSONException{
403
        Client catalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
404
        //Client catalogClientProd = new CatalogClient().getClient();
405
        Long timestamp = System.currentTimeMillis();
406
        SnapdealItem snapdealItem = catalogClient.getSnapdealItem(Long.valueOf(itemId));
407
        boolean toUpdate = false;
408
        if (snapdealItem.getSellingPrice()!=Double.valueOf(sellingPrice) || snapdealItem.isIsListedOnSnapdeal()!=Boolean.valueOf(isListedOnSnapdeal) || snapdealItem.isSuppressPriceFeed()!=Boolean.valueOf(isSuppressPriceFeed)){
409
            toUpdate=true;
410
        }
411
        Item item = catalogClient.getItem(Long.valueOf(itemId));
412
        MarketplacePercentage mpCosting = catalogClient.getCostingForMarketplace(7, Long.valueOf(itemId));
413
        if (mpCosting.getSource()==0){
414
            throw new CatalogServiceException();
415
        }
416
        MarketplaceItems mpItem = catalogClient.getMarketplacedetailsForItem(Long.valueOf(itemId),7);
417
        mpItem.setEmiFee(mpCosting.getEmiFee());
418
        mpItem.setReturnProvision(mpCosting.getReturnProvision());
419
        mpItem.setClosingFee(mpCosting.getClosingFee());
420
        mpItem.setServiceTax(mpCosting.getServiceTax());
421
        mpItem.setCommission(mpCosting.getCommission());
422
        mpItem.setPgFee(mpCosting.getPgFee());
423
        InventoryClient inventoryServiceClient = new InventoryClient();
424
        in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
425
        Warehouse warehouse = inventoryClient.getWarehouse(Long.valueOf(warehouseId));
426
        /*if (!(warehouse.getWarehouseType()==WarehouseType.OURS && warehouse.getInventoryType() == InventoryType.GOOD)){
9725 kshitij.so 427
			throw new InventoryServiceException();
9780 kshitij.so 428
		}*/
12133 kshitij.so 429
        snapdealItem.setWarehouseId(Long.valueOf(warehouseId));
430
        snapdealItem.setIsListedOnSnapdeal(Boolean.valueOf(isListedOnSnapdeal));
431
        snapdealItem.setSuppressInventoryFeed(Boolean.valueOf(isSuppressInventoryFeed));
432
        snapdealItem.setSuppressPriceFeed(Boolean.valueOf(isSuppressPriceFeed));
433
        snapdealItem.setTransferPrice(Double.valueOf(transferPrice));
434
        snapdealItem.setExceptionPrice(Double.valueOf(exceptionPrice));
435
        snapdealItem.setSellingPrice(Double.valueOf(sellingPrice));
436
        snapdealItem.setCourierCost(Double.valueOf(courierCost));
437
        snapdealItem.setCommission(Double.valueOf(commission));
438
        snapdealItem.setServiceTax(Double.valueOf(serviceTax));
439
        snapdealItem.setMaxNlc(Double.valueOf(maxNlc));
440
        snapdealItem.setSkuAtSnapdeal(sdItemCode);
441
        snapdealItem.setSupc(supc);
442
        snapdealItem.setCourierCostMarketplace(Double.valueOf(courierCostMarketplace));
443
        MarketplaceItems t_mpItem = updateMarketplaceItemDetails(mpItem);
444
        //double vat = catalogClientProd.getVatPercentageForItem(Long.valueOf(itemId), warehouse.getStateId(), Double.valueOf(sellingPrice));
445
        //t_mpItem.setVat(vat);
446
        t_mpItem.setCourierCostMarketplace(Double.valueOf(courierCostMarketplace));
447
        snapdealItem.setUpdatedBy(getUserName());
448
        snapdealItem.setMarketplaceItems(t_mpItem);
9780 kshitij.so 449
 
12133 kshitij.so 450
        if(!compareParameters(t_mpItem,snapdealItem,warehouse,item.getWeight(),item.getCategory())){
451
            setComparsionResult("0");
452
            return "snapdeal-update-result";
453
        }
454
        else{
455
            setComparsionResult("1");
456
        }
9478 kshitij.so 457
 
12133 kshitij.so 458
        if(!catalogClient.addOrUpdateSnapdealItem(snapdealItem)){
459
            throw new CatalogServiceException();
460
        }
9780 kshitij.so 461
 
12133 kshitij.so 462
        if (t_mpItem.getCurrentSp()< t_mpItem.getMinimumPossibleSp()){
463
            sendAlert(t_mpItem.getItemId(),t_mpItem.getCurrentSp(),t_mpItem.getMinimumPossibleSp());
464
        }
465
        logger.info("\nUpdate Method Item Id "+itemId+"\nSelling Price "+sellingPrice+"\nWarehouse Id "+warehouseId+"\nMax Nlc "+maxNlc+"\nUpdated By: "+session.getAttribute(ReportsUtils.USER_NAME).toString());
466
        if(toUpdate && Boolean.valueOf(live) && (!snapdealItem.isSuppressPriceFeed()) && snapdealItem.isIsListedOnSnapdeal()){
467
            logger.info("Calling Method to update price at snapdeal");
468
            UpdateSDPricingUsingPanel updatePriceOnSnapdeal = new UpdateSDPricingUsingPanel(Float.valueOf(sellingPrice),supc,item,timestamp);
469
            logger.info("Calling Thread to update price at snapdeal");
470
            updatePriceOnSnapdeal.start();	
471
        }
472
        return "snapdeal-update-result";
473
    }
9242 kshitij.so 474
 
10287 kshitij.so 475
 
12133 kshitij.so 476
    public void updateForAutoPricing() throws NumberFormatException, CatalogServiceException, TException{
477
        logger.info("Calling Method to update price at snapdeal for auto pricing");
478
        Client catalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
479
        Item item = catalogClient.getItem(Long.valueOf(itemId));
480
        UpdateSDPricingUsingPanel updatePriceOnSnapdeal = new UpdateSDPricingUsingPanel(Float.valueOf(sellingPrice),supc,item,System.currentTimeMillis());
481
        logger.info("Calling Thread to update price at snapdeal for auto pricing");
482
        updatePriceOnSnapdeal.start();	
483
    }
9923 kshitij.so 484
 
485
 
12133 kshitij.so 486
    public boolean compareParameters(MarketplaceItems mpItem, SnapdealItem snapdealItem, Warehouse warehouse,double weight, Long categoryId) throws TException, JSONException, CatalogServiceException{
487
        double nlc =getNlcForWarehouse(snapdealItem.getWarehouseId(),snapdealItem.getItem_id());
488
        double vat = (snapdealItem.getSellingPrice()/(1+(mpItem.getVat()/100))-(nlc/(1+(mpItem.getVat()/100))))*(mpItem.getVat()/100);
489
        double inHouseCost = mpItem.getPackagingCost()+vat+(mpItem.getReturnProvision()/100)*snapdealItem.getSellingPrice()+mpItem.getOtherCost();
490
        double lowest_possible_tp = nlc+inHouseCost;
491
        double our_tp =  snapdealItem.getSellingPrice()- snapdealItem.getSellingPrice()*((mpItem.getCommission()/100)+mpItem.getEmiFee()/100)*(1+(mpItem.getServiceTax()/100))-(snapdealItem.getCourierCostMarketplace()+mpItem.getClosingFee())*(1+(mpItem.getServiceTax()/100))-(Math.max(20,(mpItem.getPgFee()/100)*snapdealItem.getSellingPrice())*(1+(mpItem.getServiceTax()/100)));
492
        double commission=0.0;
493
        if ((mpItem.getPgFee()/100)*snapdealItem.getSellingPrice()>=20){
494
            commission =  (((mpItem.getCommission()/100)+mpItem.getPgFee()/100)*snapdealItem.getSellingPrice());
495
        }
496
        else{
497
            commission =  ((mpItem.getCommission()/100)*snapdealItem.getSellingPrice()+20);
498
        }
499
        double service_tax = (mpItem.getServiceTax()/100)*(snapdealItem.getCommission()+snapdealItem.getCourierCostMarketplace());
500
        double lowest_possible_sp = 0.0;
501
        if ((mpItem.getPgFee()/100)*snapdealItem.getSellingPrice()>=20){
502
            lowest_possible_sp = (nlc+(snapdealItem.getCourierCostMarketplace()+mpItem.getClosingFee())*(1+(mpItem.getServiceTax()/100))*(1+(mpItem.getVat()/100))+(mpItem.getPackagingCost()+mpItem.getOtherCost())*(1+(mpItem.getVat())/100))/(1-((mpItem.getCommission()/100)+mpItem.getEmiFee()/100+mpItem.getPgFee()/100)*(1+(mpItem.getServiceTax()/100))*(1+(mpItem.getVat())/100)-(mpItem.getReturnProvision()/100)*(1+(mpItem.getVat())/100));
503
        }
504
        else{
505
            lowest_possible_sp = (nlc+(snapdealItem.getCourierCostMarketplace()+mpItem.getClosingFee()+20)*(1+(mpItem.getServiceTax()/100))*(1+(mpItem.getVat()/100))+(mpItem.getPackagingCost()+mpItem.getOtherCost())*(1+(mpItem.getVat())/100))/(1-((mpItem.getCommission()/100)+mpItem.getEmiFee()/100)*(1+(mpItem.getServiceTax()/100))*(1+(mpItem.getVat())/100)-(mpItem.getReturnProvision()/100)*(1+(mpItem.getVat())/100));
506
        }
507
        double vat_rate_prod = getVatRateForItem(warehouse,snapdealItem.getSellingPrice(),snapdealItem.getItem_id());
508
        JSONObject x = new JSONObject();
509
        x.put("NLC", nlc);
510
        x.put("VAT", vat);
511
        x.put("COURIER COST",getCourierCost(weight));
512
        x.put("LOWEST POS TP", lowest_possible_tp);
513
        x.put("TP", our_tp);
514
        x.put("COMMISSION", commission);
515
        x.put("SERVICE TAX", service_tax);
516
        x.put("LOWEST POS SP", lowest_possible_sp);
517
        x.put("VAT RATE",vat_rate_prod);
518
        logger.info("Snapdeal Backend validation "+x.toString());
519
        boolean compare_result=true;
9923 kshitij.so 520
 
12133 kshitij.so 521
        if(!(mpItem.getPackagingCost()==computePackagingCost(categoryId))){
522
            compare_result=false;
523
        }
9780 kshitij.so 524
 
12133 kshitij.so 525
        if(!(getCourierCost(weight)==snapdealItem.getCourierCost())){
526
            compare_result=false;
527
        }
9923 kshitij.so 528
 
12133 kshitij.so 529
        if(!(vat_rate_prod==mpItem.getVat())){
530
            compare_result=false;
531
        }
9780 kshitij.so 532
 
12133 kshitij.so 533
        if(!(nlc==snapdealItem.getMaxNlc())){
534
            compare_result=false;
535
        }
536
        if(!(lowest_possible_tp-mpItem.getMinimumPossibleTp()>-1 && lowest_possible_tp-mpItem.getMinimumPossibleTp()<1)){
537
            compare_result=false;
538
        }
539
        if(!(our_tp-snapdealItem.getTransferPrice()>-1 && our_tp-snapdealItem.getTransferPrice()<1)){
540
            compare_result=false;
541
        }
542
        if(!(commission-snapdealItem.getCommission()>-1 && commission-snapdealItem.getCommission()<1)){
543
            compare_result=false;
544
        }
545
        if(!(service_tax-snapdealItem.getServiceTax()>-1 && service_tax-snapdealItem.getServiceTax()<1)){
546
            compare_result=false;
547
        }
548
        if(!(lowest_possible_sp-mpItem.getMinimumPossibleSp()>-1 && lowest_possible_sp-mpItem.getMinimumPossibleSp()<1)){
549
            compare_result=false;
550
        }
551
        return compare_result;
9780 kshitij.so 552
 
12133 kshitij.so 553
    }
9734 kshitij.so 554
 
12133 kshitij.so 555
    private double computePackagingCost(Long categoryId) {
556
        double pc = 15.0;
557
        if (categoryId==10006 || categoryId==10010){
558
            pc =pc + 43.0;
559
        }
560
        return pc;
561
    }
9734 kshitij.so 562
 
12133 kshitij.so 563
    public double getVatRateForItem(Warehouse warehouse, double sellingPrice,long itemId) throws CatalogServiceException, TException{
564
        Client catalogClientProd = new CatalogClient().getClient();
565
        return catalogClientProd.getVatPercentageForItem(itemId, warehouse.getStateId(), sellingPrice);
566
    }
9923 kshitij.so 567
 
12133 kshitij.so 568
    public double getNlcForWarehouse(long warehouseId,long item_id) throws TException{
569
        InventoryClient inventoryServiceClient = new InventoryClient();
570
        in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
571
        return inventoryClient.getNlcForWarehouse(warehouseId, item_id);
572
    }
9923 kshitij.so 573
 
12133 kshitij.so 574
    public double getCourierCost(double weight){
575
        double cCost = 45.0;
576
        int slabs = (int) ((weight+.05 - .001)/(.5));
577
        for(int i=0;i<slabs;i++){
578
            cCost = cCost + 35;
579
        }
580
        return cCost;
581
    }
9725 kshitij.so 582
 
12133 kshitij.so 583
    public void getLastNDaySaleForItem(String itemId,String days) {
584
        try{
585
            InventoryClient inventoryServiceClient = new InventoryClient();
586
            in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
587
            List<OOSStatus> oosStatuses = inventoryClient.getOosStatusesForXDaysForItem(Long.valueOf(itemId), 7, Integer.valueOf(days));
588
            String lastNdaySale="";
589
            double avgSale = 0.0;
590
            long count = 0,sale = 0;
591
            for(OOSStatus oosStatus : oosStatuses){
592
                if(oosStatus.isIs_oos()){
593
                    lastNdaySale += "X-";
594
                }else{
595
                    lastNdaySale += oosStatus.getNum_orders() + "-";
596
                    sale = sale + oosStatus.getNum_orders();
597
                    count+=1;
598
                }
599
            }
600
            lastNdaySale = lastNdaySale.substring(0, lastNdaySale.length()-1);
601
            lastNdaySale += "\n";
602
            setnDaySale(lastNdaySale);
603
            if (count!=0){
604
                setAvgSale(String.valueOf(roundTwoDecimals(sale/(double)count)));
605
            }
606
            else{
607
                setAvgSale("0");
608
            }
609
        }
610
        catch (Exception e){
611
            setAvgSale("0");
612
            setnDaySale("Unable to fetch");
613
            logger.error("Unable to get last n day sale",e);
614
        }
9725 kshitij.so 615
 
12133 kshitij.so 616
    }
9923 kshitij.so 617
 
12133 kshitij.so 618
 
619
    private MarketplaceItems updateMarketplaceItemDetails(MarketplaceItems mpItem){
620
        mpItem.setItemId(Long.valueOf(itemId));
621
        mpItem.setSource(7);
622
        mpItem.setVat(Double.valueOf(vat));
623
        mpItem.setCourierCost(Double.valueOf(courierCost));
624
        mpItem.setOtherCost(Double.valueOf(otherCost));
625
        mpItem.setCurrentSp(Double.valueOf(sellingPrice));
626
        mpItem.setCurrentTp(Double.valueOf(transferPrice));
627
        mpItem.setAutoDecrement(Boolean.valueOf(isAutoDecrement));
628
        mpItem.setAutoIncrement(Boolean.valueOf(isAutoIncrement));
629
        mpItem.setManualFavourite(Boolean.valueOf(isManualFavourite));
630
        mpItem.setMinimumPossibleSp(Double.valueOf(minPosSp));
631
        mpItem.setMinimumPossibleTp(Double.valueOf(minPosTp));
632
        mpItem.setMaximumSellingPrice(Double.valueOf(maxSp));
633
        return mpItem;
634
    }
635
 
636
    private void sendAlert(long itemId,double sp,double minSp){
637
        Item item;
638
        try{
639
            Client catalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
640
            item= catalogClient.getItem(itemId);
641
        }
642
        catch(Exception e){
643
            e.printStackTrace();
644
            return;
645
        }
646
        String emailSubjectTxt="Snapdeal SP is set below Min Possible SP";
647
        String[] sendTo=new String[]{ "kshitij.sood@saholic.com","rajneesh.arora@saholic.com","rajveer.singh@saholic.com","vikram.raghav@saholic.com"};
648
        String text = "Item Details-\nItem Id: "+itemId+"\nProduct Name: "+item.getBrand()+" "+item.getModelName()+" "+item.getModelNumber()+" "+item.getColor()+"\nSellingPrice: "+sp+"\nMinPossibleSp: "+minSp+"\nUpdated By: "+session.getAttribute(ReportsUtils.USER_NAME).toString();
649
        logger.info(text);
650
        String emailFromAddress = "build@shop2020.in";
651
        String password = "cafe@nes";
652
        GmailUtils mailer = new GmailUtils();
653
        try {
654
            mailer.sendSSLMessage(sendTo, emailSubjectTxt, text, emailFromAddress, password, new ArrayList<File>());
655
        }
656
        catch (Exception e) {
657
            logger.info(e.toString());
658
        }
659
    }
660
 
661
    public String addNewItem() throws TException, NumberFormatException, InventoryServiceException, CatalogServiceException, JSONException{
662
        InventoryClient inventoryServiceClient = new InventoryClient();
663
        in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
664
        Client catalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
665
        Item item = catalogClient.getItem(Long.valueOf(itemId));
666
        //Client catalogClientProd = new CatalogClient().getClient();
667
        MarketplacePercentage mpCosting = catalogClient.getCostingForMarketplace(7, Long.valueOf(itemId));
668
 
669
        if (mpCosting.getSource()==0){
670
            throw new CatalogServiceException();
671
        }
672
        Warehouse warehouse = inventoryClient.getWarehouse(Long.valueOf(warehouseId));
673
        /*if (!(warehouse.getWarehouseType()==WarehouseType.OURS && warehouse.getInventoryType() == InventoryType.GOOD)){
9725 kshitij.so 674
			throw new InventoryServiceException();
9780 kshitij.so 675
		}*/
12133 kshitij.so 676
        SnapdealItem snapdealItem = new SnapdealItem();
677
        snapdealItem.setItem_id(Long.valueOf(itemId));
678
        snapdealItem.setWarehouseId(Long.valueOf(warehouseId));
679
        snapdealItem.setIsListedOnSnapdeal(Boolean.valueOf(isListedOnSnapdeal));
680
        snapdealItem.setSuppressInventoryFeed(Boolean.valueOf(isSuppressInventoryFeed));
681
        snapdealItem.setSuppressPriceFeed(Boolean.valueOf(isSuppressPriceFeed));
682
        snapdealItem.setTransferPrice(Double.valueOf(transferPrice));
683
        snapdealItem.setExceptionPrice(Double.valueOf(exceptionPrice));
684
        snapdealItem.setSellingPrice(Double.valueOf(sellingPrice));
685
        snapdealItem.setCourierCost(Double.valueOf(courierCost));
686
        snapdealItem.setCommission(Double.valueOf(commission));
687
        snapdealItem.setServiceTax(Double.valueOf(serviceTax));
688
        snapdealItem.setMaxNlc(Double.valueOf(maxNlc));
689
        snapdealItem.setSkuAtSnapdeal(sdItemCode);
690
        snapdealItem.setSupc(supc);
691
        snapdealItem.setUpdatedBy(getUserName());
692
        snapdealItem.setCourierCostMarketplace(Double.valueOf(courierCostMarketplace));
9734 kshitij.so 693
 
12133 kshitij.so 694
        MarketplaceItems mpItem = new MarketplaceItems();
695
        MarketplaceItems t_mpItem = updateMarketplaceItemDetails(mpItem);
696
        /*double vat = catalogClientProd.getVatPercentageForItem(Long.valueOf(itemId), warehouse.getStateId(), Double.valueOf(sellingPrice));
9825 kshitij.so 697
		t_mpItem.setVat(vat);*/
12133 kshitij.so 698
        t_mpItem.setCommission(mpCosting.getCommission());
699
        t_mpItem.setServiceTax(mpCosting.getServiceTax());
700
        t_mpItem.setReturnProvision(mpCosting.getReturnProvision());
701
        t_mpItem.setEmiFee(mpCosting.getEmiFee());
702
        t_mpItem.setClosingFee(mpCosting.getClosingFee());
703
        t_mpItem.setPgFee(mpCosting.getPgFee());
704
        t_mpItem.setCourierCostMarketplace(Double.valueOf(courierCostMarketplace));
705
        t_mpItem.setPackagingCost(Double.valueOf(packagingCost));
706
        if(!compareParameters(t_mpItem,snapdealItem,warehouse,item.getWeight(),item.getCategory())){
707
            setComparsionResult("0");
708
            return "snapdeal-update-result";
709
        }
710
        else{
711
            setComparsionResult("1");
712
        }
713
        snapdealItem.setMarketplaceItems(t_mpItem);
714
        Long timestamp = System.currentTimeMillis();
715
        boolean result = catalogClient.addOrUpdateSnapdealItem(snapdealItem);
716
        if(!result){
717
            throw new CatalogServiceException();
718
        }
719
        if (t_mpItem.getCurrentSp()< t_mpItem.getMinimumPossibleSp()){
720
            sendAlert(t_mpItem.getItemId(),t_mpItem.getCurrentSp(),t_mpItem.getMinimumPossibleSp());
721
        }
722
        if (Boolean.valueOf(live) && (!snapdealItem.isSuppressPriceFeed()) && snapdealItem.isIsListedOnSnapdeal()){
723
            logger.info("Calling Method to update new item price at snapdeal");
724
            UpdateSDPricingUsingPanel updatePriceOnSnapdeal = new UpdateSDPricingUsingPanel(Float.valueOf(sellingPrice),supc,item,timestamp);
725
            logger.info("Calling Thread to update new item price at snapdeal");
726
            updatePriceOnSnapdeal.start();
727
        }
728
        return "snapdeal-update-result";
729
    }
9242 kshitij.so 730
 
9780 kshitij.so 731
 
12133 kshitij.so 732
    public String getAddNewItemForm(){
733
        return "snapdeal-add-item";
734
    }
735
 
736
    /*public String getCompetitionAnalyis() throws NumberFormatException, TException{
11015 kshitij.so 737
	    Client cc = new CatalogClient().getClient();
738
	    compData = cc.getMarketplaceHistory(7, 0, Long.valueOf(itemId));
739
	    //Gson gson = new Gson();
740
	    //competitionJson = gson.toJson(compData);
741
	    return "competition-details";
12133 kshitij.so 742
 
11015 kshitij.so 743
	}*/
9242 kshitij.so 744
 
12133 kshitij.so 745
    public String getItemDetailsInJson() throws NumberFormatException, CatalogServiceException, TException, JSONException, InventoryServiceException{
746
        Client catalogClientProd = new CatalogClient().getClient();
747
        Client catalogClient =new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
748
        SnapdealItem snapdealItem = catalogClient.getSnapdealItem(Long.valueOf(itemId));
749
        MarketplacePercentage mpCosting = catalogClient.getCostingForMarketplace(7, Long.valueOf(itemId));
750
        if (snapdealItem.getItem_id()!=0){
751
            throw new CatalogServiceException();
752
        }
753
        Item item = catalogClient.getItem(Long.valueOf(itemId));
754
        if (item.getId()==0){
755
            throw new CatalogServiceException();
756
        }
757
        InventoryClient inventoryServiceClient = new InventoryClient();
758
        in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
759
        Warehouse warehouse = inventoryClient.getWarehouse(Long.valueOf(warehouseId));
760
        /*if (!(warehouse.getWarehouseType()==WarehouseType.OURS && warehouse.getInventoryType() == InventoryType.GOOD)){
9725 kshitij.so 761
			throw new InventoryServiceException();
9780 kshitij.so 762
		}*/
12133 kshitij.so 763
        double maxNLC = inventoryClient.getNlcForWarehouse(Long.valueOf(warehouseId), Long.valueOf(itemId));
764
        double vat = catalogClientProd.getVatPercentageForItem(Long.valueOf(itemId), warehouse.getStateId(), Double.valueOf(sellingPrice));
765
        if (maxNLC==0){
766
            throw new InventoryServiceException();
767
        }
768
        itemObj = new JSONObject();
769
        itemObj.put("ItemId", item.getId());
770
        itemObj.put("Brand", item.getBrand());
771
        itemObj.put("ModelName", item.getModelName());
772
        itemObj.put("ModelNumber", item.getModelNumber());
773
        itemObj.put("Color", item.getColor());
774
        itemObj.put("Weight", item.getWeight());
775
        itemObj.put("Risky", item.isRisky());
776
        itemObj.put("Status", item.getItemStatus());
777
        itemObj.put("MRP", item.getMrp());
778
        itemObj.put("SellingPrice", item.getSellingPrice());
779
        itemObj.put("MaxNlc", maxNLC);
780
        itemObj.put("VatRate", vat);
781
        itemObj.put("CommissionRate", mpCosting.getCommission());
782
        itemObj.put("ServiceTaxRate", mpCosting.getServiceTax());
783
        itemObj.put("ReturnProvision", mpCosting.getReturnProvision());
784
        itemObj.put("EmiFee", mpCosting.getEmiFee());
785
        itemObj.put("ClosingFee", mpCosting.getClosingFee());
786
        itemObj.put("PgFee", mpCosting.getPgFee());
787
        itemObj.put("PackagingCost", computePackagingCost(item.getCategory()));
788
        return "item-details-json";
789
    }
9242 kshitij.so 790
 
12133 kshitij.so 791
    public String ke$ha() throws NumberFormatException, TException, JSONException, InventoryServiceException, CatalogServiceException{
792
        Client catalogClientProd = new CatalogClient().getClient();
793
        InventoryClient inventoryServiceClient = new InventoryClient();
794
        in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
795
        Warehouse warehouse = inventoryClient.getWarehouse(Long.valueOf(warehouseId));
796
        //if (warehouse.getWarehouseType()==WarehouseType.OURS && warehouse.getInventoryType() == InventoryType.GOOD){
797
        double maxNLC = inventoryClient.getNlcForWarehouse(Long.valueOf(warehouseId), Long.valueOf(itemId));
798
        double vat = catalogClientProd.getVatPercentageForItem(Long.valueOf(itemId), warehouse.getStateId(), Double.valueOf(sellingPrice));
799
        itemObj = new JSONObject();
800
        itemObj.put("ItemId", itemId);
801
        itemObj.put("WarehouseId", warehouseId);
802
        itemObj.put("MaxNlc", maxNLC);
803
        itemObj.put("VatRate", vat);
804
        /*}
9725 kshitij.so 805
		else{
806
			itemObj = new JSONObject();
807
			throw new InventoryServiceException();
9780 kshitij.so 808
		}*/
12133 kshitij.so 809
        return "item-details-json";
810
    }
9478 kshitij.so 811
 
12133 kshitij.so 812
    public ItemInventory getItemInventory(String itemId) throws NumberFormatException, InventoryServiceException, TException{
813
        try{
814
            InventoryClient inventoryServiceClient = new InventoryClient();
815
            in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
816
            in.shop2020.model.v1.inventory.ItemInventory thriftItemInventory = inventoryClient.getItemInventoryByItemId(Long.valueOf(itemId));
817
            return thriftItemInventory;
818
        }
819
        catch(Exception e){
820
            logger.error("Unable to get inventory info for item",e);
821
            return null;
822
        }
823
    }
9725 kshitij.so 824
 
9734 kshitij.so 825
 
826
 
12133 kshitij.so 827
    public Warehouse getWarehouse(String warehouseId,String itemId) throws NumberFormatException, TException, InventoryServiceException { 
828
        InventoryClient inventoryServiceClient = new InventoryClient();
829
        holdInventoryMap =inventoryServiceClient.getClient().getHeldInventoryMapForItem(Long.valueOf(itemId), Long.valueOf(warehouseId));
830
        return inventoryServiceClient.getClient().getWarehouse(Long.valueOf(warehouseId));
831
    }
9725 kshitij.so 832
 
12133 kshitij.so 833
    public Map<Integer, Long> getHoldInventoryMapForItem(){
834
        return holdInventoryMap;
835
    }
9734 kshitij.so 836
 
12133 kshitij.so 837
    public void changeHeldForSource() throws NumberFormatException, TException, InventoryServiceException{
838
        InventoryClient inventoryServiceClient = new InventoryClient();
839
        Warehouse warehouse = inventoryServiceClient.getClient().getWarehouse(Long.valueOf(warehouseId));
840
        if (!(warehouse.getWarehouseType()==WarehouseType.OURS && warehouse.getInventoryType() == InventoryType.GOOD)){
841
            throw new InventoryServiceException();
842
        }
843
        inventoryServiceClient.getClient().addUpdateHoldInventory(Long.valueOf(itemId),Long.valueOf(warehouseId),Long.valueOf(held),7);
844
    }
9725 kshitij.so 845
 
12133 kshitij.so 846
    public void downloadSnapdealListings() throws IOException, TException{
847
        File file = new File("/tmp/snapdeal-bulk-upload-template.xls");
848
        HSSFWorkbook hwb=new HSSFWorkbook();
849
        HSSFSheet sheet =  hwb.createSheet("Snapdeal-Listings");
850
        HSSFRow rowhead=   sheet.createRow((short)0);
851
        rowhead.createCell((short) 0).setCellValue("ITEM-ID");
852
        rowhead.createCell((short) 1).setCellValue("PRODUCT");
853
        rowhead.createCell((short) 2).setCellValue("WAREHOUSE-ID");
854
        rowhead.createCell((short) 3).setCellValue("EXCEPTIONAL-PRICE");
855
        rowhead.createCell((short) 4).setCellValue("SNAPDEAL-LISTED");
856
        rowhead.createCell((short) 5).setCellValue("TRANSFER-PRICE");
857
        rowhead.createCell((short) 6).setCellValue("SELLING-PRICE");
858
        rowhead.createCell((short) 7).setCellValue("LOWEST POSSIBLE SP");
859
        rowhead.createCell((short) 8).setCellValue("LOWEST POSSIBLE TP");
860
        rowhead.createCell((short) 9).setCellValue("OTHER COST");
861
        rowhead.createCell((short) 10).setCellValue("COURIER-COST");
862
        rowhead.createCell((short) 11).setCellValue("COURIER-COST-Snapdeal");
863
        rowhead.createCell((short) 12).setCellValue("COMMISION");
864
        rowhead.createCell((short) 13).setCellValue("SERVICE-TAX");
865
        rowhead.createCell((short) 14).setCellValue("Suppress Inventory Feed");
866
        rowhead.createCell((short) 15).setCellValue("Suppress Price Feed");
867
        rowhead.createCell((short) 16).setCellValue("AUTO FAVOURITE");
868
        rowhead.createCell((short) 17).setCellValue("MANUAL FAVOURITE");
869
        rowhead.createCell((short) 18).setCellValue("AUTO INCREMENT");
870
        rowhead.createCell((short) 19).setCellValue("AUTO DECREMENT");
871
        rowhead.createCell((short) 20).setCellValue("Max NLC");
872
        rowhead.createCell((short) 21).setCellValue("SKU @ Snapdeal");
873
        rowhead.createCell((short) 22).setCellValue("SUPC");
874
        Client catalogClient = null;
875
        List<SnapdealItem> snapdealItems = null;
876
        try {
877
            catalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
878
            snapdealItems = catalogClient.getAllSnapdealMarketplaceItem();
879
        } catch (Exception e) {
880
            e.printStackTrace();
881
        }
882
        int iterator=1;
883
        Item item;
884
        MarketplaceItems marketplaceItem;
885
        for(SnapdealItem snapdealItem:snapdealItems){
886
            marketplaceItem = snapdealItem.getMarketplaceItems();
887
            item = snapdealItem.getItem();
888
            HSSFRow row = sheet.createRow((short)iterator);
889
            row.createCell((short) 0).setCellValue(snapdealItem.getItem_id());
890
            row.createCell((short) 1).setCellValue(getVaildName(item.getBrand())+" "+getVaildName(item.getModelName())+" "+getVaildName(item.getModelNumber())+" "+getVaildName(item.getColor()));
891
            row.createCell((short) 2).setCellValue(snapdealItem.getWarehouseId());
892
            row.createCell((short) 3).setCellValue(roundTwoDecimals(snapdealItem.getExceptionPrice()));
893
            if(snapdealItem.isIsListedOnSnapdeal()){
894
                row.createCell((short) 4).setCellValue(1);
895
            }
896
            else{
897
                row.createCell((short) 4).setCellValue(0);
898
            }
899
            row.createCell((short) 5).setCellValue(roundTwoDecimals(snapdealItem.getTransferPrice()));
900
            row.createCell((short) 6).setCellValue(roundTwoDecimals(snapdealItem.getSellingPrice()));
901
            row.createCell((short) 7).setCellValue(roundTwoDecimals(marketplaceItem.getMinimumPossibleSp()));
902
            row.createCell((short) 8).setCellValue(roundTwoDecimals(marketplaceItem.getMinimumPossibleTp()));
903
            row.createCell((short) 9).setCellValue(roundTwoDecimals(marketplaceItem.getOtherCost()));
904
            row.createCell((short) 10).setCellValue(snapdealItem.getCourierCost());
905
            row.createCell((short) 11).setCellValue(snapdealItem.getCourierCostMarketplace());
906
            row.createCell((short) 12).setCellValue(roundTwoDecimals(snapdealItem.getCommission()));
907
            row.createCell((short) 13).setCellValue(roundTwoDecimals(snapdealItem.getServiceTax()));
908
            if(snapdealItem.isSuppressInventoryFeed()){
909
                row.createCell((short) 14).setCellValue(1);
910
            }
911
            else{
912
                row.createCell((short) 14).setCellValue(0);
913
            }
914
            if(snapdealItem.isSuppressPriceFeed()){
915
                row.createCell((short) 15).setCellValue(1);
916
            }
917
            else{
918
                row.createCell((short) 15).setCellValue(0);
919
            }
920
            if(marketplaceItem.isAutoFavourite()){
921
                row.createCell((short) 16).setCellValue(1);
922
            }
923
            else{
924
                row.createCell((short) 16).setCellValue(0);
925
            }
926
            if(marketplaceItem.isManualFavourite()){
927
                row.createCell((short) 17).setCellValue(1);
928
            }
929
            else{
930
                row.createCell((short) 17).setCellValue(0);
931
            }
932
            if(marketplaceItem.isAutoIncrement()){
933
                row.createCell((short) 18).setCellValue(1);
934
            }
935
            else{
936
                row.createCell((short) 18).setCellValue(0);
937
            }
938
            if(marketplaceItem.isAutoDecrement()){
939
                row.createCell((short) 19).setCellValue(1);
940
            }
941
            else{
942
                row.createCell((short) 19).setCellValue(0);
943
            }
944
            row.createCell((short) 20).setCellValue(snapdealItem.getMaxNlc());
945
            row.createCell((short) 21).setCellValue(snapdealItem.getSkuAtSnapdeal());
946
            row.createCell((short) 22).setCellValue(snapdealItem.getSupc());
947
            iterator++;
948
        }
9242 kshitij.so 949
 
12133 kshitij.so 950
        FileOutputStream fileOut = null;
951
        try {
952
            fileOut = new FileOutputStream(file);
953
        } catch (FileNotFoundException e) {
954
            // TODO Auto-generated catch block
955
            e.printStackTrace();
956
        }
957
        try {
958
            hwb.write(fileOut);
959
        } catch (IOException e) {
960
            // TODO Auto-generated catch block
961
            e.printStackTrace();
962
        }
963
        try {
964
            fileOut.close();
965
        } catch (IOException e) {
966
            // TODO Auto-generated catch block
967
            e.printStackTrace();
968
        }
969
        byte[] buffer = new byte[(int)file.length()];
970
        InputStream input = null;
971
        try {
972
            int totalBytesRead = 0;
973
            input = new BufferedInputStream(new FileInputStream(file));
974
            while(totalBytesRead < buffer.length){
975
                int bytesRemaining = buffer.length - totalBytesRead;
976
                int bytesRead = input.read(buffer, totalBytesRead, bytesRemaining); 
977
                if (bytesRead > 0){
978
                    totalBytesRead = totalBytesRead + bytesRead;
979
                }
980
            }
981
        }
982
        finally {
983
            input.close();
984
            file.delete();
985
        }
8739 vikram.rag 986
 
12133 kshitij.so 987
        response.setHeader("Content-Disposition", "attachment; filename=\"Snapdeal-Bulk-Listings.xls\"");
988
        response.setContentType("application/octet-stream");
989
        ServletOutputStream sos;
990
        try {
991
            sos = response.getOutputStream();
992
            sos.write(buffer);
993
            sos.flush();
994
        } catch (IOException e) {
995
            System.out.println("Unable to stream the manifest file");
996
        }   
997
    }
8739 vikram.rag 998
 
9825 kshitij.so 999
 
12133 kshitij.so 1000
    public void uploadsnapdealBulkSheet() throws IOException, TException, NumberFormatException, InventoryServiceException, CatalogServiceException{
1001
        File fileToCreate = new File("/tmp/", "Snapdeal-bulk-upload.xls");
1002
        FileUtils.copyFile(this.file, fileToCreate);
1003
        FileInputStream iFile = new FileInputStream(new File(file.getAbsolutePath()));
1004
        HSSFWorkbook workbook = new HSSFWorkbook(iFile);
1005
        HSSFSheet sheet = workbook.getSheetAt(0);
1006
        String updatedBy = getUserName();
1007
        Client catalogClient=null;
1008
        Client catalogClientProd=null;
1009
        StringBuilder sb = new StringBuilder();
1010
        try {
1011
            catalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
1012
            catalogClientProd = new CatalogClient().getClient();
1013
        } catch (TTransportException e) {
1014
            e.printStackTrace();
1015
        }
1016
        InventoryClient inventoryServiceClient = new InventoryClient();
1017
        in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
9825 kshitij.so 1018
 
12133 kshitij.so 1019
        for (int iterator=(sheet.getFirstRowNum()+1);iterator<=sheet.getLastRowNum();iterator++){
1020
            if (sheet.getLastRowNum()-1>100){
1021
                sb.append("Number of items to update can't be greater than 100");
1022
                break;
1023
            }
1024
            SnapdealItem snapdealItem = null;
1025
            MarketplaceItems marketplaceItem = null;
1026
            MarketplacePercentage mpCosting = null;
1027
            Warehouse warehouse = null;
1028
            Item item = null;
1029
            Long sku;
1030
            boolean new_item = false;
1031
            if (checkEmptyString(sheet.getRow(iterator).getCell(0))){
1032
                continue;
1033
            }
1034
            else {
1035
                sku=(long) sheet.getRow(iterator).getCell(0).getNumericCellValue();
1036
                snapdealItem = catalogClient.getSnapdealItem(sku);
1037
                mpCosting = catalogClient.getCostingForMarketplace(7, sku);
1038
                marketplaceItem  = catalogClient.getMarketplacedetailsForItem(sku, 7);
1039
                marketplaceItem.setItemId(sku);
1040
                marketplaceItem.setSource(7);
1041
                marketplaceItem.setCommission(mpCosting.getCommission());
1042
                marketplaceItem.setServiceTax(mpCosting.getServiceTax());
1043
                marketplaceItem.setReturnProvision(mpCosting.getReturnProvision());
1044
                marketplaceItem.setEmiFee(mpCosting.getEmiFee());
1045
                marketplaceItem.setClosingFee(mpCosting.getClosingFee());
1046
                marketplaceItem.setPgFee(mpCosting.getPgFee());
9825 kshitij.so 1047
 
12133 kshitij.so 1048
                try {
1049
                    item = catalogClient.getItem(sku);
1050
                    marketplaceItem.setPackagingCost(computePackagingCost(item.getCategory()));
1051
                    if (item.getId()==0){
1052
                        sb.append(sku + " Item not valid"+"\n");
1053
                        continue;
1054
                    }
1055
                } catch (CatalogServiceException e) {
1056
                    sb.append(sku + " Item not valid"+"\n");
1057
                    continue;
1058
                }
1059
                if(snapdealItem.getItem_id()==0){
1060
                    new_item = true;
1061
                    snapdealItem = new SnapdealItem();
1062
                    snapdealItem.setItem_id(sku); 
1063
                }
1064
            }
9725 kshitij.so 1065
 
12133 kshitij.so 1066
            if (checkEmptyString(sheet.getRow(iterator).getCell(1)) && new_item){
1067
                sb.append(sku + " New Listing - Warehouse Id not Present"+"\n");
1068
                continue;
1069
            }
9725 kshitij.so 1070
 
12133 kshitij.so 1071
            if (!checkEmptyString(sheet.getRow(iterator).getCell(1))){
1072
                /*Warehouse warehouse = inventoryClient.getWarehouse(Long.valueOf(warehouseId));
9725 kshitij.so 1073
				if (!(warehouse.getWarehouseType()==WarehouseType.OURS && warehouse.getInventoryType() == InventoryType.GOOD)){
1074
					sb.append(sku + "Not acceptable warehouse"+"\n");
1075
					continue;
9780 kshitij.so 1076
				}*/
12133 kshitij.so 1077
                long warehouseId = (long) sheet.getRow(iterator).getCell(1).getNumericCellValue();
1078
                double maxNLC = inventoryClient.getNlcForWarehouse(warehouseId, item.getId());
1079
                if (maxNLC==0){
1080
                    sb.append(sku + "Max Nlc can't be 0"+"\n");
1081
                    continue;
1082
                }
1083
                snapdealItem.setWarehouseId(warehouseId);
1084
                snapdealItem.setMaxNlc(maxNLC);
1085
            }
8739 vikram.rag 1086
 
12133 kshitij.so 1087
            if (!checkEmptyString(sheet.getRow(iterator).getCell(2))){
1088
                double exceptionPrice = sheet.getRow(iterator).getCell(2).getNumericCellValue();
1089
                snapdealItem.setExceptionPrice(exceptionPrice);
1090
            }
8739 vikram.rag 1091
 
12133 kshitij.so 1092
            if (!checkEmptyString(sheet.getRow(iterator).getCell(3))){
1093
                if ((long)sheet.getRow(iterator).getCell(3).getNumericCellValue()==1){
1094
                    snapdealItem.setIsListedOnSnapdeal(true);
1095
                }
1096
                if ((long)sheet.getRow(iterator).getCell(3).getNumericCellValue()==0){
1097
                    snapdealItem.setIsListedOnSnapdeal(false);
1098
                }
1099
            }
9825 kshitij.so 1100
 
12133 kshitij.so 1101
            double transferPrice = 0,sellingPrice,commission,courierCost =45,serviceTax,otherCost;
1102
            if (checkEmptyString(sheet.getRow(iterator).getCell(4))&& new_item){
1103
                sb.append(sku + "New Item -  Selling Price cannot be empty"+"\n");
1104
                continue;
1105
            }
1106
            if (!checkEmptyString(sheet.getRow(iterator).getCell(4))){
1107
                sellingPrice = sheet.getRow(iterator).getCell(4).getNumericCellValue();
1108
                if(sellingPrice==0){
1109
                    sb.append(sku + " Selling Price cannot be zero"+"\n");
1110
                    continue;
1111
                }
1112
                snapdealItem.setSellingPrice(sellingPrice);
1113
                marketplaceItem.setCurrentSp(sellingPrice);
1114
            }
9825 kshitij.so 1115
 
12133 kshitij.so 1116
            if (!checkEmptyString(sheet.getRow(iterator).getCell(5))){
1117
                otherCost = sheet.getRow(iterator).getCell(5).getNumericCellValue();
1118
                marketplaceItem.setOtherCost(otherCost);
1119
            }
9242 kshitij.so 1120
 
9780 kshitij.so 1121
 
12133 kshitij.so 1122
            if (!checkEmptyString(sheet.getRow(iterator).getCell(6))){
1123
                if ((long)sheet.getRow(iterator).getCell(6).getNumericCellValue()==1){
1124
                    snapdealItem.setSuppressPriceFeed(true);
1125
                }
1126
                if ((long)sheet.getRow(iterator).getCell(6).getNumericCellValue()==0){
1127
                    snapdealItem.setSuppressPriceFeed(false);
1128
                }
1129
            }
9242 kshitij.so 1130
 
12133 kshitij.so 1131
            if (!checkEmptyString(sheet.getRow(iterator).getCell(7))){
1132
                if ((long)sheet.getRow(iterator).getCell(7).getNumericCellValue()==1){
1133
                    snapdealItem.setSuppressInventoryFeed(true);
1134
                }
1135
                if ((long)sheet.getRow(iterator).getCell(7).getNumericCellValue()==0){
1136
                    snapdealItem.setSuppressInventoryFeed(false);
1137
                }
1138
            }
9725 kshitij.so 1139
 
12133 kshitij.so 1140
            if (checkEmptyString(sheet.getRow(iterator).getCell(8)) && new_item){
1141
                sb.append(sku + " New Item -  SKU@Snapdeal cannot be empty"+"\n");
1142
                continue;
1143
            }
9725 kshitij.so 1144
 
12133 kshitij.so 1145
            if (!checkEmptyString(sheet.getRow(iterator).getCell(8))){
1146
                sheet.getRow(iterator).getCell(8).setCellType(Cell.CELL_TYPE_STRING);
1147
                String snapdealItemCode = sheet.getRow(iterator).getCell(8).getStringCellValue();
1148
                if (snapdealItemCode.length()==0 && new_item){
1149
                    sb.append(sku + " New Item -  SKU@Snapdeal cannot be empty"+"\n");
1150
                    continue;
1151
                }
1152
                snapdealItem.setSkuAtSnapdeal(snapdealItemCode);
1153
            }
9825 kshitij.so 1154
 
12133 kshitij.so 1155
            if (checkEmptyString(sheet.getRow(iterator).getCell(9)) && new_item){
1156
                sb.append(sku + " New Item -  SUPC code cannot be empty"+"\n");
1157
                continue;
1158
            }
9780 kshitij.so 1159
 
12133 kshitij.so 1160
            if (!checkEmptyString(sheet.getRow(iterator).getCell(9))){
1161
                sheet.getRow(iterator).getCell(9).setCellType(Cell.CELL_TYPE_STRING);
1162
                String supc = sheet.getRow(iterator).getCell(9).getStringCellValue();
1163
                if (supc.length()==0 && new_item){
1164
                    sb.append(sku + "  New Item -  SUPC code cannot be empty"+"\n");
1165
                    continue;
1166
                }
1167
                snapdealItem.setSupc(supc);
1168
            }
1169
            double weight = item.getWeight();
9242 kshitij.so 1170
 
9825 kshitij.so 1171
 
12133 kshitij.so 1172
            if(weight==0){
1173
                sb.append(sku + " Please add weight"+"\n");
1174
                continue;
1175
            }
1176
            if (weight!=0){
1177
                weight = weight+.05;
1178
                int slabs = (int) ((weight - .001)/(.5));
9242 kshitij.so 1179
 
12133 kshitij.so 1180
                for(int i=0;i<slabs;i++){
1181
                    courierCost = courierCost + 35;
1182
                }
1183
            }
10225 vikram.rag 1184
 
12133 kshitij.so 1185
            warehouse = inventoryClient.getWarehouse(snapdealItem.getWarehouseId());
1186
            snapdealItem.setCourierCost(courierCost);
1187
            marketplaceItem.setCourierCost(courierCost);
1188
            if (new_item){
1189
                snapdealItem.setCourierCostMarketplace(courierCost);
1190
                marketplaceItem.setCourierCostMarketplace(courierCost);
1191
            }
1192
            transferPrice = roundTwoDecimals(snapdealItem.getSellingPrice()- snapdealItem.getSellingPrice()*((marketplaceItem.getCommission()/100)+marketplaceItem.getEmiFee()/100)*(1+(marketplaceItem.getServiceTax()/100))-(snapdealItem.getCourierCostMarketplace()+marketplaceItem.getClosingFee())*(1+(marketplaceItem.getServiceTax()/100))-(Math.max(20,(marketplaceItem.getPgFee()/100)*snapdealItem.getSellingPrice())*(1+(marketplaceItem.getServiceTax()/100))));
1193
            snapdealItem.setTransferPrice(transferPrice);
1194
            marketplaceItem.setCurrentTp(transferPrice);
1195
            if ((marketplaceItem.getPgFee()/100)*snapdealItem.getSellingPrice()>=20){
1196
                commission =  (((marketplaceItem.getCommission()/100)+marketplaceItem.getPgFee()/100)*snapdealItem.getSellingPrice());
1197
            }
1198
            else{
1199
                commission =  ((marketplaceItem.getCommission()/100)*snapdealItem.getSellingPrice()+20);
1200
            }
1201
            commission = roundTwoDecimals(commission);
1202
            snapdealItem.setCommission(commission);
1203
            serviceTax = roundTwoDecimals((marketplaceItem.getServiceTax()/100)*(snapdealItem.getCommission()+snapdealItem.getCourierCostMarketplace())); 
1204
            snapdealItem.setServiceTax(serviceTax);
1205
            double vatRate = catalogClientProd.getVatPercentageForItem(snapdealItem.getItem_id(),warehouse.getStateId(),snapdealItem.getSellingPrice());
1206
            marketplaceItem.setVat(vatRate);
1207
            double vat = roundTwoDecimals((snapdealItem.getSellingPrice()/(1+(marketplaceItem.getVat()/100))-(snapdealItem.getMaxNlc()/(1+(marketplaceItem.getVat()/100))))*(marketplaceItem.getVat()/100));
1208
            double inHouseCost = roundTwoDecimals(marketplaceItem.getPackagingCost()+vat+(marketplaceItem.getReturnProvision()/100)*snapdealItem.getSellingPrice()+marketplaceItem.getOtherCost());
1209
            double lowest_possible_tp = roundTwoDecimals(snapdealItem.getMaxNlc()+inHouseCost);
1210
            marketplaceItem.setMinimumPossibleTp(lowest_possible_tp);
1211
            double lowest_possible_sp=0.0;
1212
            if ((marketplaceItem.getPgFee()/100)*snapdealItem.getSellingPrice()>=20){
1213
                lowest_possible_sp = roundTwoDecimals((snapdealItem.getMaxNlc()+(snapdealItem.getCourierCostMarketplace()+marketplaceItem.getClosingFee())*(1+marketplaceItem.getServiceTax()/100)*(1+(marketplaceItem.getVat()/100))+(marketplaceItem.getPackagingCost()+marketplaceItem.getOtherCost())*(1+(marketplaceItem.getVat())/100))/(1-((marketplaceItem.getCommission()/100)+marketplaceItem.getEmiFee()/100+marketplaceItem.getPgFee()/100)*(1+(marketplaceItem.getServiceTax()/100))*(1+(marketplaceItem.getVat())/100)-(marketplaceItem.getReturnProvision()/100)*(1+(marketplaceItem.getVat())/100)));
1214
            }
1215
            else{
1216
                lowest_possible_sp = roundTwoDecimals((snapdealItem.getMaxNlc()+(snapdealItem.getCourierCostMarketplace()+marketplaceItem.getClosingFee()+20)*(1+marketplaceItem.getServiceTax()/100)*(1+(marketplaceItem.getVat()/100))+(marketplaceItem.getPackagingCost()+marketplaceItem.getOtherCost())*(1+(marketplaceItem.getVat())/100))/(1-((marketplaceItem.getCommission()/100)+marketplaceItem.getEmiFee()/100)*(1+(marketplaceItem.getServiceTax()/100))*(1+(marketplaceItem.getVat())/100)-(marketplaceItem.getReturnProvision()/100)*(1+(marketplaceItem.getVat())/100)));
1217
            }
1218
            marketplaceItem.setMinimumPossibleSp(lowest_possible_sp);
1219
            snapdealItem.setUpdatedBy(updatedBy);
1220
            snapdealItem.setMarketplaceItems(marketplaceItem);
1221
            //logger.info(snapdealItem.toString());
1222
            if(!catalogClient.addOrUpdateSnapdealItem(snapdealItem)){
1223
                sb.append(sku + " Service Error\n");
1224
            }	
1225
        }
1226
        File file = new File("/tmp/snapdealbulk");
1227
        FileWriter writer = new FileWriter(file);
1228
        writer.append(sb.toString());
1229
        writer.close();
1230
        byte[] buffer = new byte[(int)file.length()];
1231
        InputStream input = null;
1232
        try {
1233
            int totalBytesRead = 0;
1234
            input = new BufferedInputStream(new FileInputStream(file));
1235
            while(totalBytesRead < buffer.length){
1236
                int bytesRemaining = buffer.length - totalBytesRead;
1237
                int bytesRead = input.read(buffer, totalBytesRead, bytesRemaining); 
1238
                if (bytesRead > 0){
1239
                    totalBytesRead = totalBytesRead + bytesRead;
1240
                }
1241
            }
1242
        }
1243
        finally {
1244
            input.close();
1245
            file.delete();
1246
        }
8739 vikram.rag 1247
 
12133 kshitij.so 1248
        response.setHeader("Content-Type", "text/javascript");
8739 vikram.rag 1249
 
12133 kshitij.so 1250
        ServletOutputStream sos;
1251
        try {
1252
            sos = response.getOutputStream();
1253
            sos.write(buffer);
1254
            sos.flush();
1255
        } catch (IOException e) {
1256
            System.out.println("Unable to stream the manifest file");
1257
        }   
1258
    }
8739 vikram.rag 1259
 
12133 kshitij.so 1260
    public boolean checkEmptyString(Cell cell){
1261
        if (cell==null || cell.getCellType() == Cell.CELL_TYPE_BLANK){
1262
            return true;
1263
        }
1264
        return false;
1265
    }
8739 vikram.rag 1266
 
12133 kshitij.so 1267
    double roundTwoDecimals(double d) {
1268
        DecimalFormat twoPlaces = new DecimalFormat("#.##");
1269
        return Double.valueOf(twoPlaces.format(d));
1270
    }
9242 kshitij.so 1271
 
12133 kshitij.so 1272
    /*String getLocation(String location){
9825 kshitij.so 1273
		logger.info("Inside trim"+location);
1274
		int loc = location.lastIndexOf(',');
1275
		logger.info("end result "+location.substring(loc+1));
1276
		return location.substring(loc+1);
1277
	}*/
9242 kshitij.so 1278
 
9825 kshitij.so 1279
 
12133 kshitij.so 1280
    public String show() {
1281
        if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), request.getRequestURI().substring(request.getContextPath().length()).split("/")[1])) {
1282
            return "authfail";
1283
        }
8739 vikram.rag 1284
 
12133 kshitij.so 1285
        if (StringUtils.equals(id, "snapdeal-options")){
1286
            return "snapdeal-options";
1287
        }
1288
 
1289
        if (StringUtils.equals(id, "competition-analysis")){
1290
            //setAnalysisData(Long.valueOf(itemId));
1291
 
11015 kshitij.so 1292
            return "competition-details";
1293
        }
8739 vikram.rag 1294
 
12133 kshitij.so 1295
        if (StringUtils.equals(id, "item-table")){
1296
            return "snapdeal-item-table";
1297
        }
1298
 
1299
        return "id";
1300
    }
1301
 
1302
    //	public void setAnalysisData(long itemId){
1303
    //        try {
1304
    //            Client cc = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
1305
    //            compData = cc.getMarketplaceHistory(7, 0, itemId);
1306
    //        } catch (Exception e) {
1307
    //            // TODO Auto-generated catch block
1308
    //            logger.error("Unable to set analysis data for itemId "+itemId +" "+e);
1309
    //        }
1310
    //        //Gson gson = new Gson();
1311
    //        //competitionJson = gson.toJson(compData);
1312
    //        
1313
    //	}
1314
 
1315
    public String getCountForCompetitionData(String itemId) throws TException, NumberFormatException, CatalogServiceException{
1316
        Client cc = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
1317
        Item item = cc.getItem(Long.valueOf(itemId));
1318
        setProductName(getVaildName(item.getBrand())+" "+getVaildName(item.getModelName())+" "+getVaildName(item.getModelNumber())+" "+getVaildName(item.getColor()));
1319
        return String.valueOf(cc.getCountForMarketplaceHistory(7, Long.valueOf(itemId)));
1320
    }
1321
 
1322
    public void setProductName(String productName){
1323
        this.productName = productName;
1324
    }
1325
 
1326
    public String getProductName(){
1327
        return productName;
1328
    }
1329
 
1330
 
1331
    public String fetchCompetitionData(){
1332
        try {
11015 kshitij.so 1333
            Client cc = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
1334
            compData = cc.getMarketplaceHistory(7, Long.valueOf(next), Long.valueOf(itemId));
1335
        } catch (Exception e) {
1336
            // TODO Auto-generated catch block
1337
            logger.error("Unable to set analysis data for itemId "+itemId +" "+e);
1338
        }
1339
        return "snapdeal-competition-table";
12133 kshitij.so 1340
 
1341
    }
1342
 
1343
    public String fetchCompetitionDataTest(){
11015 kshitij.so 1344
        try {
1345
            Client cc = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
1346
            compData = cc.getMarketplaceHistoryByDate(7, Long.valueOf(startDate), Long.valueOf(endDate),999999L,999999L,Long.valueOf(itemId));
1347
        } catch (Exception e) {
1348
            // TODO Auto-generated catch block
1349
            logger.error("Unable to set analysis data for itemId "+itemId +" "+e);
1350
        }
1351
        return "snapdeal-duplicate-records";
12133 kshitij.so 1352
 
11015 kshitij.so 1353
    }
12133 kshitij.so 1354
 
1355
 
1356
    public List<MarketplaceHistory> getAnalysisData() {
11015 kshitij.so 1357
        return compData;
1358
    }
8739 vikram.rag 1359
 
12133 kshitij.so 1360
    public void setId(String id) {
1361
        this.id = id;
1362
    }
8739 vikram.rag 1363
 
12133 kshitij.so 1364
    public String getUserName(){
1365
        return session.getAttribute(ReportsUtils.USER_NAME).toString();
1366
    }
9780 kshitij.so 1367
 
12133 kshitij.so 1368
    public HttpServletRequest getRequest() {
1369
        logger.info("set request"+request.toString());
1370
        return request;
1371
    }
8739 vikram.rag 1372
 
12133 kshitij.so 1373
    public void setRequest(HttpServletRequest request) {
1374
        this.request = request;
1375
    }
8739 vikram.rag 1376
 
12133 kshitij.so 1377
    public HttpServletResponse getResponse() {
1378
        return response;
1379
    }
8739 vikram.rag 1380
 
12133 kshitij.so 1381
    public void setResponse(HttpServletResponse response) {
1382
        this.response = response;
1383
    }
8739 vikram.rag 1384
 
12133 kshitij.so 1385
    public HttpSession getSession() {
1386
        return session;
1387
    }
8739 vikram.rag 1388
 
12133 kshitij.so 1389
    public void setSession(HttpSession session) {
1390
        this.session = session;
1391
    }
8739 vikram.rag 1392
 
12133 kshitij.so 1393
    public ServletContext getContext() {
1394
        return context;
1395
    }
8739 vikram.rag 1396
 
12133 kshitij.so 1397
    public void setContext(ServletContext context) {
1398
        this.context = context;
1399
    }
8739 vikram.rag 1400
 
12133 kshitij.so 1401
    public String getUrl() {
1402
        return url;
1403
    }
8739 vikram.rag 1404
 
12133 kshitij.so 1405
    public void setUrl(String url) {
1406
        this.url = url;
1407
    }
8739 vikram.rag 1408
 
12133 kshitij.so 1409
    public String getItemId() {
1410
        return itemId;
1411
    }
8739 vikram.rag 1412
 
12133 kshitij.so 1413
    public void setItemId(String itemId) {
1414
        this.itemId = itemId;
1415
    }
8739 vikram.rag 1416
 
12133 kshitij.so 1417
    public String getIsSnapdealListed() {
1418
        return isSnapdealListed;
1419
    }
8739 vikram.rag 1420
 
12133 kshitij.so 1421
    public void setIsSnapdealListed(String isSnapdealListed) {
1422
        this.isSnapdealListed = isSnapdealListed;
1423
    }
8739 vikram.rag 1424
 
12133 kshitij.so 1425
    public String getExceptionPrice() {
1426
        return exceptionPrice;
1427
    }
8739 vikram.rag 1428
 
12133 kshitij.so 1429
    public void setExceptionPrice(String exceptionPrice) {
1430
        this.exceptionPrice = exceptionPrice;
1431
    }
8739 vikram.rag 1432
 
12133 kshitij.so 1433
    public String getWarehouseId() {
1434
        return warehouseId;
1435
    }
8739 vikram.rag 1436
 
12133 kshitij.so 1437
    public void setWarehouseId(String warehouseId) {
1438
        this.warehouseId = warehouseId;
1439
    }
8739 vikram.rag 1440
 
12133 kshitij.so 1441
    public File getFile() {
1442
        return file;
1443
    }
8739 vikram.rag 1444
 
12133 kshitij.so 1445
    public void setFile(File file) {
1446
        this.file = file;
1447
    }
8739 vikram.rag 1448
 
12133 kshitij.so 1449
    public String getErrMsg() {
1450
        return errMsg;
1451
    }
8739 vikram.rag 1452
 
12133 kshitij.so 1453
    public void setErrMsg(String errMsg) {
1454
        this.errMsg = errMsg;
1455
    }
8739 vikram.rag 1456
 
12133 kshitij.so 1457
    public String getNext() {
1458
        return next;
1459
    }
8739 vikram.rag 1460
 
12133 kshitij.so 1461
    public void setNext(String next) {
1462
        this.next = next;
1463
    }
8739 vikram.rag 1464
 
12133 kshitij.so 1465
    public String getId() {
1466
        return id;
1467
    }
8739 vikram.rag 1468
 
12133 kshitij.so 1469
    public void setServletRequest(HttpServletRequest req) {
1470
        this.request = req;
1471
        this.session = req.getSession();        
1472
    }
8739 vikram.rag 1473
 
12133 kshitij.so 1474
    public void setServletContext(ServletContext arg0) {
1475
        // TODO Auto-generated method stub
8739 vikram.rag 1476
 
12133 kshitij.so 1477
    }
8739 vikram.rag 1478
 
12133 kshitij.so 1479
    public void setServletResponse(HttpServletResponse response) {
1480
        this.response = response;
1481
    }
8739 vikram.rag 1482
 
12133 kshitij.so 1483
    public void setSearchText(String searchText) {
1484
        this.searchText = searchText;
1485
    }
9242 kshitij.so 1486
 
12133 kshitij.so 1487
    public String getSearchText() {
1488
        return searchText;
1489
    }
9242 kshitij.so 1490
 
12133 kshitij.so 1491
    public long getSearchCount() {
1492
        return searchCount;
1493
    }
9242 kshitij.so 1494
 
12133 kshitij.so 1495
    public long getTotalCount() {
1496
        return totalCount;
1497
    }
9242 kshitij.so 1498
 
12133 kshitij.so 1499
    public void setSearchCount(long count) {
1500
        this.searchCount = count;
1501
    }
9242 kshitij.so 1502
 
12133 kshitij.so 1503
    public List<SnapdealItemDetails> getSnapdealItems(){
1504
        return snapdealItems;
1505
    }
9242 kshitij.so 1506
 
12133 kshitij.so 1507
    public void setSellingPrice(String sellingPrice) {
1508
        this.sellingPrice = sellingPrice;
1509
    }
9242 kshitij.so 1510
 
12133 kshitij.so 1511
    public String getSellingPrice() {
1512
        return sellingPrice;
1513
    }
9242 kshitij.so 1514
 
12133 kshitij.so 1515
    public void setTransferPrice(String transferPrice) {
1516
        this.transferPrice = transferPrice;
1517
    }
9242 kshitij.so 1518
 
12133 kshitij.so 1519
    public String getTransferPrice() {
1520
        return transferPrice;
1521
    }
9242 kshitij.so 1522
 
12133 kshitij.so 1523
    public void setWebisteMrp(String webisteMrp) {
1524
        this.webisteMrp = webisteMrp;
1525
    }
9242 kshitij.so 1526
 
12133 kshitij.so 1527
    public String getWebisteMrp() {
1528
        return webisteMrp;
1529
    }
9242 kshitij.so 1530
 
12133 kshitij.so 1531
    public void setWebisteSellingPrice(String webisteSellingPrice) {
1532
        this.webisteSellingPrice = webisteSellingPrice;
1533
    }
9242 kshitij.so 1534
 
12133 kshitij.so 1535
    public String getWebisteSellingPrice() {
1536
        return webisteSellingPrice;
1537
    }
9242 kshitij.so 1538
 
12133 kshitij.so 1539
    public void setIsListedOnSnapdeal(String isListedOnSnapdeal) {
1540
        this.isListedOnSnapdeal = isListedOnSnapdeal;
1541
    }
9242 kshitij.so 1542
 
12133 kshitij.so 1543
    public String getIsSuppressInventoryFeed() {
1544
        return isSuppressInventoryFeed;
1545
    }
9242 kshitij.so 1546
 
12133 kshitij.so 1547
    public void setIsSuppressInventoryFeed(String isSuppressInventoryFeed) {
1548
        this.isSuppressInventoryFeed = isSuppressInventoryFeed;
1549
    }
9242 kshitij.so 1550
 
12133 kshitij.so 1551
    public String getIsSuppressPriceFeed() {
1552
        return isSuppressPriceFeed;
1553
    }
9242 kshitij.so 1554
 
12133 kshitij.so 1555
    public void setIsSuppressPriceFeed(String isSuppressPriceFeed) {
1556
        this.isSuppressPriceFeed = isSuppressPriceFeed;
1557
    }
9242 kshitij.so 1558
 
12133 kshitij.so 1559
    public String getIsListedOnSnapdeal() {
1560
        return isListedOnSnapdeal;
1561
    }
9242 kshitij.so 1562
 
12133 kshitij.so 1563
    public void setCommission(String commission) {
1564
        this.commission = commission;
1565
    }
9242 kshitij.so 1566
 
12133 kshitij.so 1567
    public String getCommission() {
1568
        return commission;
1569
    }
9242 kshitij.so 1570
 
12133 kshitij.so 1571
    public void setServiceTax(String serviceTax) {
1572
        this.serviceTax = serviceTax;
1573
    }
9242 kshitij.so 1574
 
12133 kshitij.so 1575
    public String getServiceTax() {
1576
        return serviceTax;
1577
    }
9242 kshitij.so 1578
 
12133 kshitij.so 1579
    public void setCourierCost(String courierCost) {
1580
        this.courierCost = courierCost;
1581
    }
9242 kshitij.so 1582
 
12133 kshitij.so 1583
    public String getCourierCost() {
1584
        return courierCost;
1585
    }
9242 kshitij.so 1586
 
12133 kshitij.so 1587
    public void setMaxNlc(String maxNlc) {
1588
        this.maxNlc = maxNlc;
1589
    }
9478 kshitij.so 1590
 
12133 kshitij.so 1591
    public String getMaxNlc() {
1592
        return maxNlc;
1593
    }
9478 kshitij.so 1594
 
12133 kshitij.so 1595
    public String getItemDetails(){
1596
        return itemObj.toString();
1597
    }
9242 kshitij.so 1598
 
12133 kshitij.so 1599
    public double getRoundOfValue(String val){
1600
        return roundTwoDecimals(Double.valueOf(val));
1601
    }
9923 kshitij.so 1602
 
12133 kshitij.so 1603
    public String getVaildName(String name){
1604
        return name!=null?name:"";
1605
    }
9242 kshitij.so 1606
 
12133 kshitij.so 1607
    public String getPackagingCost() {
1608
        return packagingCost;
1609
    }
1610
 
1611
    public void setPackagingCost(String packagingCost) {
1612
        this.packagingCost = packagingCost;
1613
    }
1614
 
10287 kshitij.so 1615
}