Subversion Repositories SmartDukaan

Rev

Rev 9242 | Rev 9568 | 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
 
3
import in.shop2020.model.v1.catalog.CatalogService.Client;
9242 kshitij.so 4
import in.shop2020.model.v1.catalog.CatalogServiceException;
5
import in.shop2020.model.v1.catalog.Item;
8739 vikram.rag 6
import in.shop2020.model.v1.catalog.SnapdealItem;
9242 kshitij.so 7
import in.shop2020.model.v1.catalog.SnapdealItemDetails;
8739 vikram.rag 8
import in.shop2020.model.v1.order.AmazonFbaSalesSnapshot;
8886 vikram.rag 9
import in.shop2020.model.v1.order.SnapdealOrder;
8739 vikram.rag 10
import in.shop2020.support.utils.ReportsUtils;
11
import in.shop2020.thrift.clients.CatalogClient;
9478 kshitij.so 12
import in.shop2020.thrift.clients.InventoryClient;
8739 vikram.rag 13
import in.shop2020.thrift.clients.TransactionClient;
14
 
15
import java.io.BufferedInputStream;
16
import java.io.File;
17
import java.io.FileInputStream;
18
import java.io.FileNotFoundException;
19
import java.io.FileOutputStream;
20
import java.io.FileWriter;
21
import java.io.IOException;
22
import java.io.InputStream;
9242 kshitij.so 23
import java.text.DecimalFormat;
8739 vikram.rag 24
import java.util.ArrayList;
9242 kshitij.so 25
import java.util.Arrays;
8739 vikram.rag 26
import java.util.HashMap;
27
import java.util.List;
28
import java.util.Map;
29
 
30
import javax.servlet.ServletContext;
31
import javax.servlet.ServletOutputStream;
32
import javax.servlet.http.HttpServletRequest;
33
import javax.servlet.http.HttpServletResponse;
34
import javax.servlet.http.HttpSession;
35
 
36
import org.apache.commons.io.FileUtils;
37
import org.apache.commons.lang.xwork.StringUtils;
38
import org.apache.poi.hssf.usermodel.HSSFRow;
39
import org.apache.poi.hssf.usermodel.HSSFSheet;
40
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
41
import org.apache.poi.ss.usermodel.Cell;
42
import org.apache.struts2.convention.annotation.InterceptorRef;
43
import org.apache.struts2.convention.annotation.InterceptorRefs;
44
import org.apache.struts2.interceptor.ServletRequestAware;
45
import org.apache.struts2.interceptor.ServletResponseAware;
46
import org.apache.struts2.util.ServletContextAware;
47
import org.apache.thrift.TException;
48
import org.apache.thrift.transport.TTransportException;
9242 kshitij.so 49
import org.json.JSONException;
50
import org.json.JSONObject;
8739 vikram.rag 51
import org.slf4j.Logger;
52
import org.slf4j.LoggerFactory;
53
 
54
import com.opensymphony.xwork2.ValidationAwareSupport;
55
 
9242 kshitij.so 56
@SuppressWarnings("unused")
57
 
58
@InterceptorRefs({
59
	@InterceptorRef("defaultStack"),
60
	@InterceptorRef("login")
61
})
62
 
8739 vikram.rag 63
public class SnapdealListController extends ValidationAwareSupport implements ServletRequestAware ,ServletResponseAware, ServletContextAware{
9242 kshitij.so 64
	/**
65
	 * 
66
	 */
67
	private static final long serialVersionUID = 1L;
68
 
69
 
8739 vikram.rag 70
	private static Logger logger = LoggerFactory.getLogger(SnapdealListController.class);
71
 
72
 
73
	private HttpServletRequest request;
74
	private HttpServletResponse response;
75
	private HttpSession session;
76
	private ServletContext context;
77
	private String url;
78
	private String itemId;
79
	private String isSnapdealListed;
80
	private String exceptionPrice;
81
	private String warehouseId;
82
	private File file;
83
	private String errMsg;
84
	private String next;
85
	private String id;
9242 kshitij.so 86
	private String searchText;
87
	private List<SnapdealItemDetails> snapdealItems;
88
	private long searchCount;
89
	private long totalCount;
90
	private String sellingPrice;
91
	private String transferPrice;
92
	private String webisteMrp;
93
	private String webisteSellingPrice;
94
	private String isListedOnSnapdeal;
95
	private String commission;
96
	private String serviceTax;
97
	private String courierCost;
98
	private JSONObject itemObj;
99
	private String isSuppressInventoryFeed;
100
	private String isSuppressPriceFeed;
9478 kshitij.so 101
	private String maxNlc;
102
	private String sdItemCode;
8739 vikram.rag 103
 
9242 kshitij.so 104
 
105
 
9478 kshitij.so 106
	public String getSdItemCode() {
107
		return sdItemCode;
108
	}
109
 
110
	public void setSdItemCode(String sdItemCode) {
111
		this.sdItemCode = sdItemCode;
112
	}
113
 
8739 vikram.rag 114
	public String index() {
115
		if (!ReportsUtils.canAccessReport((Long) session.getAttribute(ReportsUtils.ROLE),request.getServletPath())) {
116
			return "authfail";
117
		}
118
		return "index";
119
	}
120
 
9242 kshitij.so 121
	public String edit() {
122
		if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), request.getRequestURI().substring(request.getContextPath().length()).split("/")[1])) {
123
			return "authfail";
124
		}
125
		return "edit";
126
	}
127
 
128
	public String fetchItems() throws TException {
129
		Client CatalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
130
		if (searchText.length() == 0) {
131
			snapdealItems = CatalogClient.getSnapdealItems(Long.valueOf(next), 10);
132
			totalCount = CatalogClient.getCountForSnapdealItems();
133
			setSearchCount(totalCount);
134
		} else {
135
			List<String> subString = Arrays.asList(searchText.split(" "));
136
			snapdealItems = CatalogClient.searchSnapdealItems(subString,Long.valueOf(next), 10);
137
			totalCount = CatalogClient.getCountForSnapdealItems();
138
			searchCount = CatalogClient.getSnapdealSearchResultCount(subString);
139
		}
140
		return "snapdeal-item-table";
141
	}
142
 
143
	public SnapdealItemDetails fetchItemDetail() throws NumberFormatException, TException {
144
		Client CatalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
145
		return CatalogClient.getSnapdealItemDetails(Long.valueOf(id));
146
	}
147
 
8739 vikram.rag 148
	public String uploadBulkSheet(){
149
		if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0])) {
150
			logger.info(request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0]);
151
			return "authfail";
152
		}
153
		return "snapdeal-bulk-upload";
154
	}
9242 kshitij.so 155
 
156
	public String update() throws NumberFormatException, TException{
157
		Client catalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
158
		SnapdealItem snapdealItem = catalogClient.getSnapdealItem(Long.valueOf(itemId));
159
		boolean commit = false; 
160
		if (snapdealItem.getWarehouseId()!=Long.valueOf(warehouseId)){
161
			snapdealItem.setWarehouseId(Long.valueOf(warehouseId));
162
			commit = true;
163
		}
164
		if (snapdealItem.isIsListedOnSnapdeal()!=Boolean.valueOf(isListedOnSnapdeal)){
165
			snapdealItem.setIsListedOnSnapdeal(Boolean.valueOf(isListedOnSnapdeal));
166
			commit = true;
167
		}
168
		if (snapdealItem.isSuppressInventoryFeed()!=Boolean.valueOf(isSuppressInventoryFeed)){
169
			snapdealItem.setSuppressInventoryFeed(Boolean.valueOf(isSuppressInventoryFeed));
170
			commit = true;
171
		}
172
		if (snapdealItem.isSuppressPriceFeed()!=Boolean.valueOf(isSuppressPriceFeed)){
173
			snapdealItem.setSuppressPriceFeed(Boolean.valueOf(isSuppressPriceFeed));
174
			commit = true;
175
		}
176
		if (snapdealItem.getTransferPrice()!=Double.valueOf(transferPrice)){
177
			snapdealItem.setTransferPrice(Double.valueOf(transferPrice));
178
			commit = true;
179
		}
180
		if (snapdealItem.getExceptionPrice()!=Double.valueOf(exceptionPrice)){
181
			snapdealItem.setExceptionPrice(Double.valueOf(exceptionPrice));
182
			commit = true;
183
		}
184
		if (snapdealItem.getSellingPrice()!=Double.valueOf(sellingPrice)){
185
			snapdealItem.setSellingPrice(Double.valueOf(sellingPrice));
186
			commit = true;
187
		}
188
		if (snapdealItem.getCourierCost()!=Double.valueOf(courierCost)){
189
			snapdealItem.setCourierCost(Double.valueOf(courierCost));
190
			commit = true;
191
		}
192
		if (snapdealItem.getCommission()!=Double.valueOf(commission)){
193
			snapdealItem.setCommission(Double.valueOf(commission));
194
			commit = true;
195
		}
196
		if (snapdealItem.getServiceTax()!=Double.valueOf(serviceTax)){
197
			snapdealItem.setServiceTax(Double.valueOf(serviceTax));
198
			commit = true;
199
		}
9478 kshitij.so 200
		if (snapdealItem.getMaxNlc()!=Double.valueOf(maxNlc)){
201
			snapdealItem.setMaxNlc(Double.valueOf(maxNlc));
202
			commit = true;
203
		}
204
		if (!StringUtils.equalsIgnoreCase(snapdealItem.getSkuAtSnapdeal(), sdItemCode)){
205
			snapdealItem.setSkuAtSnapdeal(sdItemCode);
206
			commit=true;
207
		}
208
 
9242 kshitij.so 209
		if (commit){
210
			catalogClient.addOrUpdateSnapdealItem(snapdealItem);
211
		}
212
		return "index";
213
	}
214
 
215
	public String addNewItem() throws TException{
216
		SnapdealItem snapdealItem = new SnapdealItem();
217
		snapdealItem.setItem_id(Long.valueOf(itemId));
218
		snapdealItem.setWarehouseId(Long.valueOf(warehouseId));
219
		snapdealItem.setIsListedOnSnapdeal(Boolean.valueOf(isListedOnSnapdeal));
220
		snapdealItem.setSuppressInventoryFeed(Boolean.valueOf(isSuppressInventoryFeed));
221
		snapdealItem.setSuppressPriceFeed(Boolean.valueOf(isSuppressPriceFeed));
222
		snapdealItem.setTransferPrice(Double.valueOf(transferPrice));
223
		snapdealItem.setExceptionPrice(Double.valueOf(exceptionPrice));
224
		snapdealItem.setSellingPrice(Double.valueOf(sellingPrice));
225
		snapdealItem.setCourierCost(Double.valueOf(courierCost));
226
		snapdealItem.setCommission(Double.valueOf(commission));
227
		snapdealItem.setServiceTax(Double.valueOf(serviceTax));
9478 kshitij.so 228
		snapdealItem.setMaxNlc(Double.valueOf(maxNlc));
229
		snapdealItem.setSkuAtSnapdeal(sdItemCode);
9242 kshitij.so 230
		Client catalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
231
		catalogClient.addOrUpdateSnapdealItem(snapdealItem);
232
		return "index";
233
	}
234
 
235
	public String getAddNewItemForm(){
236
		return "snapdeal-add-item";
237
	}
238
 
239
	public String getItemDetailsInJson() throws NumberFormatException, CatalogServiceException, TException, JSONException{
240
		Client catalogClient =new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
241
		SnapdealItem snapdealItem = catalogClient.getSnapdealItem(Long.valueOf(itemId));
242
		if (snapdealItem.getItem_id()!=0){
243
			throw new CatalogServiceException();
244
		}
245
		Item item = catalogClient.getItem(Long.valueOf(itemId));
246
		if (item.getId()==0){
247
			throw new CatalogServiceException();
248
		}
9478 kshitij.so 249
		InventoryClient inventoryServiceClient = new InventoryClient();
250
		in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
251
		double maxNLC = inventoryClient.getNlcForWarehouse(Long.valueOf(warehouseId), Long.valueOf(itemId));
9242 kshitij.so 252
		itemObj = new JSONObject();
253
		itemObj.put("ItemId", item.getId());
254
		itemObj.put("Brand", item.getBrand());
255
		itemObj.put("ModelName", item.getModelName());
256
		itemObj.put("ModelNumber", item.getModelNumber());
257
		itemObj.put("Color", item.getColor());
258
		itemObj.put("Weight", item.getWeight());
259
		itemObj.put("Risky", item.isRisky());
260
		itemObj.put("Status", item.getItemStatus());
261
		itemObj.put("MRP", item.getMrp());
262
		itemObj.put("SellingPrice", item.getSellingPrice());
9478 kshitij.so 263
		itemObj.put("MaxNlc", maxNLC);
9242 kshitij.so 264
		return "item-details-json";
265
	}
266
 
9478 kshitij.so 267
	public String ke$ha() throws NumberFormatException, TException, JSONException{
268
		InventoryClient inventoryServiceClient = new InventoryClient();
269
		in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
270
		double maxNLC = inventoryClient.getNlcForWarehouse(Long.valueOf(warehouseId), Long.valueOf(itemId));
271
		itemObj = new JSONObject();
272
		itemObj.put("ItemId", itemId);
273
		itemObj.put("WarehouseId", warehouseId);
274
		itemObj.put("MaxNlc", maxNLC);
275
		return "item-details-json";
276
	}
277
 
8739 vikram.rag 278
	public void downloadSnapdealListings() throws IOException, TException{
279
		File file = new File("/tmp/snapdeal-bulk-upload-template.xls");
280
		HSSFWorkbook hwb=new HSSFWorkbook();
281
		HSSFSheet sheet =  hwb.createSheet("Snapdeal-Listings");
282
		HSSFRow rowhead=   sheet.createRow((short)0);
283
		rowhead.createCell((short) 0).setCellValue("ITEM-ID");
284
		rowhead.createCell((short) 1).setCellValue("WAREHOUSE-ID");
285
		rowhead.createCell((short) 2).setCellValue("EXCEPTIONAL-PRICE");
286
		rowhead.createCell((short) 3).setCellValue("SNAPDEAL-LISTED");
9242 kshitij.so 287
		rowhead.createCell((short) 4).setCellValue("TRANSFER-PRICE");
288
		rowhead.createCell((short) 5).setCellValue("SELLING-PRICE");
289
		rowhead.createCell((short) 6).setCellValue("COURIER-COST");
290
		rowhead.createCell((short) 7).setCellValue("COMMISION");
291
		rowhead.createCell((short) 8).setCellValue("SERVICE-TAX");
8739 vikram.rag 292
		CatalogClient catalogServiceClient = null;
9242 kshitij.so 293
		List<SnapdealItemDetails> snapdealItems = null;
8739 vikram.rag 294
		try {
9242 kshitij.so 295
			catalogServiceClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port");
8739 vikram.rag 296
			in.shop2020.model.v1.catalog.CatalogService.Client catalogClient= catalogServiceClient.getClient();
297
			snapdealItems = catalogClient.getAllSnapdealItems();
298
		} catch (Exception e) {
299
			e.printStackTrace();
300
		}
301
		int iterator=1;
9242 kshitij.so 302
		for(SnapdealItemDetails snapdealItem:snapdealItems){
8739 vikram.rag 303
			HSSFRow row = sheet.createRow((short)iterator);
304
			row.createCell((short) 0).setCellValue(snapdealItem.getItem_id());
305
			row.createCell((short) 1).setCellValue(snapdealItem.getWarehouseId());
306
			row.createCell((short) 2).setCellValue(snapdealItem.getExceptionPrice());
307
			if(snapdealItem.isIsListedOnSnapdeal()){
308
				row.createCell((short) 3).setCellValue(1);
309
			}
310
			else{
311
				row.createCell((short) 3).setCellValue(0);
312
			}
9242 kshitij.so 313
			row.createCell((short) 4).setCellValue(snapdealItem.getTransferPrice());
314
			row.createCell((short) 5).setCellValue(snapdealItem.getSellingPrice());
315
			rowhead.createCell((short) 6).setCellValue(snapdealItem.getCourierCost());
316
			rowhead.createCell((short) 7).setCellValue(snapdealItem.getCommission());
317
			rowhead.createCell((short) 8).setCellValue(snapdealItem.getServiceTax());
8739 vikram.rag 318
			iterator++;
319
		}
9242 kshitij.so 320
 
8739 vikram.rag 321
		FileOutputStream fileOut = null;
322
		try {
323
			fileOut = new FileOutputStream(file);
324
		} catch (FileNotFoundException e) {
325
			// TODO Auto-generated catch block
326
			e.printStackTrace();
327
		}
328
		try {
329
			hwb.write(fileOut);
330
		} catch (IOException e) {
331
			// TODO Auto-generated catch block
332
			e.printStackTrace();
333
		}
334
		try {
335
			fileOut.close();
336
		} catch (IOException e) {
337
			// TODO Auto-generated catch block
338
			e.printStackTrace();
339
		}
340
		byte[] buffer = new byte[(int)file.length()];
341
		InputStream input = null;
342
		try {
343
			int totalBytesRead = 0;
344
			input = new BufferedInputStream(new FileInputStream(file));
345
			while(totalBytesRead < buffer.length){
346
				int bytesRemaining = buffer.length - totalBytesRead;
347
				int bytesRead = input.read(buffer, totalBytesRead, bytesRemaining); 
348
				if (bytesRead > 0){
349
					totalBytesRead = totalBytesRead + bytesRead;
350
				}
351
			}
352
		}
353
		finally {
354
			input.close();
355
			file.delete();
356
		}
357
 
358
		response.setHeader("Content-Disposition", "attachment; filename=\"Snapdeal-Bulk-Listings.xls\"");
359
		response.setContentType("application/octet-stream");
360
		ServletOutputStream sos;
361
		try {
362
			sos = response.getOutputStream();
363
			sos.write(buffer);
364
			sos.flush();
365
		} catch (IOException e) {
366
			System.out.println("Unable to stream the manifest file");
367
		}   
368
 
9242 kshitij.so 369
 
8739 vikram.rag 370
	}
371
 
372
	public void uploadsnapdealBulkSheet() throws IOException, TException{
373
		File fileToCreate = new File("/tmp/", "Snapdeal-bulk-upload.xls");
374
		FileUtils.copyFile(this.file, fileToCreate);
375
		FileInputStream iFile = new FileInputStream(new File(file.getAbsolutePath()));
376
		HSSFWorkbook workbook = new HSSFWorkbook(iFile);
377
		HSSFSheet sheet = workbook.getSheetAt(0);
8887 vikram.rag 378
		Client catalogClient=null;
8739 vikram.rag 379
		StringBuilder sb = new StringBuilder();
380
		try {
9242 kshitij.so 381
			catalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
8739 vikram.rag 382
		} catch (TTransportException e) {
383
			e.printStackTrace();
384
		}
9478 kshitij.so 385
		InventoryClient inventoryServiceClient = new InventoryClient();
386
		in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
8739 vikram.rag 387
		for (int iterator=(sheet.getFirstRowNum()+1);iterator<=sheet.getLastRowNum();iterator++){
388
			SnapdealItem snapdealItem =null;
9242 kshitij.so 389
			Item item = null;
8739 vikram.rag 390
			Long sku;
391
			if (checkEmptyString(sheet.getRow(iterator).getCell(0))){
392
				continue;
393
			}
394
			else {
8791 kshitij.so 395
				sku=(long) sheet.getRow(iterator).getCell(0).getNumericCellValue();
8887 vikram.rag 396
				snapdealItem = catalogClient.getSnapdealItem(sku);
9242 kshitij.so 397
				try {
398
					item = catalogClient.getItem(sku);
399
					if (item.getId()==0){
400
						sb.append(sku + " Item not Present"+"\n");
401
						continue;
402
					}
403
				} catch (CatalogServiceException e) {
404
					sb.append(sku + " Item not Present"+"\n");
405
					continue;
406
				}
8886 vikram.rag 407
				if(snapdealItem.getItem_id()==0){
408
					snapdealItem = new SnapdealItem();
409
					snapdealItem.setItem_id(sku); 
410
				}
8739 vikram.rag 411
			}
412
			if (!checkEmptyString(sheet.getRow(iterator).getCell(1))){
413
				long warehouseId = (long) sheet.getRow(iterator).getCell(1).getNumericCellValue();
9478 kshitij.so 414
				double maxNLC = inventoryClient.getNlcForWarehouse(warehouseId, item.getId());
8739 vikram.rag 415
				snapdealItem.setWarehouseId(warehouseId);
9478 kshitij.so 416
				snapdealItem.setMaxNlc(maxNLC);
8739 vikram.rag 417
			}
418
 
419
			if (!checkEmptyString(sheet.getRow(iterator).getCell(2))){
420
				double exceptionPrice = sheet.getRow(iterator).getCell(2).getNumericCellValue();
421
				snapdealItem.setExceptionPrice(exceptionPrice);
422
			}
423
 
424
			if (!checkEmptyString(sheet.getRow(iterator).getCell(3))){
425
				if ((long)sheet.getRow(iterator).getCell(3).getNumericCellValue()==1){
426
					snapdealItem.setIsListedOnSnapdeal(true);
427
				}
428
				if ((long)sheet.getRow(iterator).getCell(3).getNumericCellValue()==0){
429
					snapdealItem.setIsListedOnSnapdeal(false);
430
				}
431
			}
9242 kshitij.so 432
			double transferPrice = 0,sellingPrice,commission,courierCost =45,serviceTax;
433
			if (checkEmptyString(sheet.getRow(iterator).getCell(4))){
434
				sb.append(sku + " Transfer Price cannot be empty"+"\n");
435
				continue;
436
			}
437
			if (!checkEmptyString(sheet.getRow(iterator).getCell(4))){
438
				transferPrice = sheet.getRow(iterator).getCell(4).getNumericCellValue();
439
				if(transferPrice==0){
440
					sb.append(sku + " Transfer Price cannot be zero"+"\n");
441
					continue;
442
				}
443
				snapdealItem.setTransferPrice(transferPrice);
444
			}
445
 
446
			if (!checkEmptyString(sheet.getRow(iterator).getCell(5))){
447
				if ((long)sheet.getRow(iterator).getCell(5).getNumericCellValue()==1){
448
					snapdealItem.setSuppressPriceFeed(true);
449
				}
450
				if ((long)sheet.getRow(iterator).getCell(5).getNumericCellValue()==0){
451
					snapdealItem.setSuppressPriceFeed(false);
452
				}
453
			}
454
 
455
			if (!checkEmptyString(sheet.getRow(iterator).getCell(6))){
456
				if ((long)sheet.getRow(iterator).getCell(6).getNumericCellValue()==1){
457
					snapdealItem.setSuppressInventoryFeed(true);
458
				}
459
				if ((long)sheet.getRow(iterator).getCell(6).getNumericCellValue()==0){
460
					snapdealItem.setSuppressInventoryFeed(false);
461
				}
462
			}
9478 kshitij.so 463
 
464
			if (!checkEmptyString(sheet.getRow(iterator).getCell(7))){
465
				String snapdealItemCode = sheet.getRow(iterator).getCell(7).getStringCellValue();
466
				snapdealItem.setSkuAtSnapdeal(snapdealItemCode);
467
			}
9242 kshitij.so 468
			double weight = item.getWeight();
469
 
470
			/*
471
			 *TODO Uncomment this for pricing feed. 
472
			 * if(weight==0){
473
				sb.append(sku + " Please add weight"+"\n");
474
				continue;
475
			}*/
476
			if (weight!=0){
477
				int slabs = (int) ((weight - .001)/(.5));
478
 
479
				for(int i=0;i<slabs;i++){
480
					courierCost = courierCost + 35;
481
				}
482
			}
483
 
484
			snapdealItem.setCourierCost(courierCost);
485
			sellingPrice = roundTwoDecimals(((transferPrice + courierCost*1.1236)/(100 - 3.59*1.1236))*100);
486
			snapdealItem.setSellingPrice(sellingPrice);
487
			double commision_value = roundTwoDecimals(.0359*sellingPrice + courierCost);
488
			commission = roundTwoDecimals(((.0359*sellingPrice + courierCost)/sellingPrice)*100);
489
			snapdealItem.setCommission(commission);
490
			serviceTax = roundTwoDecimals((commision_value * .1236)); 
491
			snapdealItem.setServiceTax(serviceTax);
8888 vikram.rag 492
			if(!catalogClient.addOrUpdateSnapdealItem(snapdealItem)){
8739 vikram.rag 493
				sb.append(sku + "\n");
494
			}	
495
		}
496
		//logger.info("Amazon Bulk Map "+amazonBulkUpdate.toString());
497
		File file = new File("/tmp/amazonbulk");
498
		FileWriter writer = new FileWriter(file);
499
		writer.append(sb.toString());
500
		writer.close();
501
		byte[] buffer = new byte[(int)file.length()];
502
		InputStream input = null;
503
		try {
504
			int totalBytesRead = 0;
505
			input = new BufferedInputStream(new FileInputStream(file));
506
			while(totalBytesRead < buffer.length){
507
				int bytesRemaining = buffer.length - totalBytesRead;
508
				int bytesRead = input.read(buffer, totalBytesRead, bytesRemaining); 
509
				if (bytesRead > 0){
510
					totalBytesRead = totalBytesRead + bytesRead;
511
				}
512
			}
513
		}
514
		finally {
515
			input.close();
516
			file.delete();
517
		}
518
 
519
		response.setHeader("Content-Type", "text/javascript");
520
 
521
		ServletOutputStream sos;
522
		try {
523
			sos = response.getOutputStream();
524
			sos.write(buffer);
525
			sos.flush();
526
		} catch (IOException e) {
527
			System.out.println("Unable to stream the manifest file");
528
		}   
529
	}
530
 
531
	public boolean checkEmptyString(Cell cell){
532
		if (cell==null){
533
			return true;
534
		}
535
		return false;
536
	}
537
 
9242 kshitij.so 538
	double roundTwoDecimals(double d) {
539
		DecimalFormat twoPlaces = new DecimalFormat("#.##");
540
		return Double.valueOf(twoPlaces.format(d));
541
	}
542
 
543
 
8739 vikram.rag 544
	public String show() {
545
		logger.info("Before fetching role");
546
		logger.info(request.getSession().toString());
547
		logger.info(ReportsUtils.ROLE);
548
		logger.info(session.getAttribute(ReportsUtils.ROLE).toString());
549
		logger.info(request.getRequestURI().substring(request.getContextPath().length()).split("/")[1]);
550
		if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), request.getRequestURI().substring(request.getContextPath().length()).split("/")[1])) {
551
			logger.info(request.getRequestURI().substring(request.getContextPath().length()).split("/")[1]);
552
			return "authfail";
553
		}
554
 
555
		if (StringUtils.equals(id, "snapdeal-options")){
556
			return "snapdeal-options";
557
		}
9242 kshitij.so 558
		if (StringUtils.equals(id, "item-table")){
559
			return "snapdeal-item-table";
560
		}
8739 vikram.rag 561
 
562
		return "id";
563
	}
564
 
565
	public void setId(String id) {
566
		this.id = id;
567
	}
568
 
569
	public HttpServletRequest getRequest() {
570
		logger.info("set request"+request.toString());
571
		return request;
572
	}
573
 
574
	public void setRequest(HttpServletRequest request) {
575
		this.request = request;
576
	}
577
 
578
	public HttpServletResponse getResponse() {
579
		return response;
580
	}
581
 
582
	public void setResponse(HttpServletResponse response) {
583
		this.response = response;
584
	}
585
 
586
	public HttpSession getSession() {
587
		return session;
588
	}
589
 
590
	public void setSession(HttpSession session) {
591
		logger.info("set session"+session.toString());
592
		this.session = session;
593
	}
594
 
595
	public ServletContext getContext() {
596
		return context;
597
	}
598
 
599
	public void setContext(ServletContext context) {
600
		this.context = context;
601
	}
602
 
603
	public String getUrl() {
604
		return url;
605
	}
606
 
607
	public void setUrl(String url) {
608
		this.url = url;
609
	}
610
 
611
	public String getItemId() {
612
		return itemId;
613
	}
614
 
615
	public void setItemId(String itemId) {
616
		this.itemId = itemId;
617
	}
618
 
619
	public String getIsSnapdealListed() {
620
		return isSnapdealListed;
621
	}
622
 
623
	public void setIsSnapdealListed(String isSnapdealListed) {
624
		this.isSnapdealListed = isSnapdealListed;
625
	}
626
 
627
	public String getExceptionPrice() {
628
		return exceptionPrice;
629
	}
630
 
631
	public void setExceptionPrice(String exceptionPrice) {
632
		this.exceptionPrice = exceptionPrice;
633
	}
634
 
635
	public String getWarehouseId() {
636
		return warehouseId;
637
	}
638
 
639
	public void setWarehouseId(String warehouseId) {
640
		this.warehouseId = warehouseId;
641
	}
642
 
643
	public File getFile() {
644
		return file;
645
	}
646
 
647
	public void setFile(File file) {
648
		this.file = file;
649
	}
650
 
651
	public String getErrMsg() {
652
		return errMsg;
653
	}
654
 
655
	public void setErrMsg(String errMsg) {
656
		this.errMsg = errMsg;
657
	}
658
 
659
	public String getNext() {
660
		return next;
661
	}
662
 
663
	public void setNext(String next) {
664
		this.next = next;
665
	}
666
 
667
	public String getId() {
668
		return id;
669
	}
670
 
671
	public void setServletRequest(HttpServletRequest req) {
672
		this.request = req;
673
		this.session = req.getSession();        
674
	}
675
 
676
	public void setServletContext(ServletContext arg0) {
677
		// TODO Auto-generated method stub
678
 
679
	}
680
 
681
	public void setServletResponse(HttpServletResponse response) {
682
		this.response = response;
683
	}
684
 
9242 kshitij.so 685
	public void setSearchText(String searchText) {
686
		this.searchText = searchText;
687
	}
688
 
689
	public String getSearchText() {
690
		return searchText;
691
	}
692
 
693
	public long getSearchCount() {
694
		return searchCount;
695
	}
696
 
697
	public long getTotalCount() {
698
		return totalCount;
699
	}
700
 
701
	public void setSearchCount(long count) {
702
		this.searchCount = count;
703
	}
704
 
705
	public List<SnapdealItemDetails> getSnapdealItems(){
706
		return snapdealItems;
707
	}
708
 
709
	public void setSellingPrice(String sellingPrice) {
710
		this.sellingPrice = sellingPrice;
711
	}
712
 
713
	public String getSellingPrice() {
714
		return sellingPrice;
715
	}
716
 
717
	public void setTransferPrice(String transferPrice) {
718
		this.transferPrice = transferPrice;
719
	}
720
 
721
	public String getTransferPrice() {
722
		return transferPrice;
723
	}
724
 
725
	public void setWebisteMrp(String webisteMrp) {
726
		this.webisteMrp = webisteMrp;
727
	}
728
 
729
	public String getWebisteMrp() {
730
		return webisteMrp;
731
	}
732
 
733
	public void setWebisteSellingPrice(String webisteSellingPrice) {
734
		this.webisteSellingPrice = webisteSellingPrice;
735
	}
736
 
737
	public String getWebisteSellingPrice() {
738
		return webisteSellingPrice;
739
	}
740
 
741
	public void setIsListedOnSnapdeal(String isListedOnSnapdeal) {
742
		this.isListedOnSnapdeal = isListedOnSnapdeal;
743
	}
744
 
745
	public String getIsSuppressInventoryFeed() {
746
		return isSuppressInventoryFeed;
747
	}
748
 
749
	public void setIsSuppressInventoryFeed(String isSuppressInventoryFeed) {
750
		this.isSuppressInventoryFeed = isSuppressInventoryFeed;
751
	}
752
 
753
	public String getIsSuppressPriceFeed() {
754
		return isSuppressPriceFeed;
755
	}
756
 
757
	public void setIsSuppressPriceFeed(String isSuppressPriceFeed) {
758
		this.isSuppressPriceFeed = isSuppressPriceFeed;
759
	}
760
 
761
	public String getIsListedOnSnapdeal() {
762
		return isListedOnSnapdeal;
763
	}
764
 
765
	public void setCommission(String commission) {
766
		this.commission = commission;
767
	}
768
 
769
	public String getCommission() {
770
		return commission;
771
	}
772
 
773
	public void setServiceTax(String serviceTax) {
774
		this.serviceTax = serviceTax;
775
	}
776
 
777
	public String getServiceTax() {
778
		return serviceTax;
779
	}
780
 
781
	public void setCourierCost(String courierCost) {
782
		this.courierCost = courierCost;
783
	}
784
 
785
	public String getCourierCost() {
786
		return courierCost;
787
	}
788
 
9478 kshitij.so 789
	public void setMaxNlc(String maxNlc) {
790
		this.maxNlc = maxNlc;
791
	}
792
 
793
	public String getMaxNlc() {
794
		return maxNlc;
795
	}
796
 
9242 kshitij.so 797
	public String getItemDetails(){
798
		return itemObj.toString();
799
	}
800
 
801
 
802
 
803
}