Subversion Repositories SmartDukaan

Rev

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