Subversion Repositories SmartDukaan

Rev

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