Subversion Repositories SmartDukaan

Rev

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