Subversion Repositories SmartDukaan

Rev

Rev 9568 | Rev 9595 | 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;
415
			if (checkEmptyString(sheet.getRow(iterator).getCell(0))){
416
				continue;
417
			}
418
			else {
8791 kshitij.so 419
				sku=(long) sheet.getRow(iterator).getCell(0).getNumericCellValue();
8887 vikram.rag 420
				snapdealItem = catalogClient.getSnapdealItem(sku);
9242 kshitij.so 421
				try {
422
					item = catalogClient.getItem(sku);
423
					if (item.getId()==0){
424
						sb.append(sku + " Item not Present"+"\n");
425
						continue;
426
					}
427
				} catch (CatalogServiceException e) {
428
					sb.append(sku + " Item not Present"+"\n");
429
					continue;
430
				}
8886 vikram.rag 431
				if(snapdealItem.getItem_id()==0){
432
					snapdealItem = new SnapdealItem();
433
					snapdealItem.setItem_id(sku); 
434
				}
8739 vikram.rag 435
			}
436
			if (!checkEmptyString(sheet.getRow(iterator).getCell(1))){
437
				long warehouseId = (long) sheet.getRow(iterator).getCell(1).getNumericCellValue();
9478 kshitij.so 438
				double maxNLC = inventoryClient.getNlcForWarehouse(warehouseId, item.getId());
8739 vikram.rag 439
				snapdealItem.setWarehouseId(warehouseId);
9478 kshitij.so 440
				snapdealItem.setMaxNlc(maxNLC);
8739 vikram.rag 441
			}
442
 
443
			if (!checkEmptyString(sheet.getRow(iterator).getCell(2))){
444
				double exceptionPrice = sheet.getRow(iterator).getCell(2).getNumericCellValue();
445
				snapdealItem.setExceptionPrice(exceptionPrice);
446
			}
447
 
448
			if (!checkEmptyString(sheet.getRow(iterator).getCell(3))){
449
				if ((long)sheet.getRow(iterator).getCell(3).getNumericCellValue()==1){
450
					snapdealItem.setIsListedOnSnapdeal(true);
451
				}
452
				if ((long)sheet.getRow(iterator).getCell(3).getNumericCellValue()==0){
453
					snapdealItem.setIsListedOnSnapdeal(false);
454
				}
455
			}
9242 kshitij.so 456
			double transferPrice = 0,sellingPrice,commission,courierCost =45,serviceTax;
457
			if (checkEmptyString(sheet.getRow(iterator).getCell(4))){
458
				sb.append(sku + " Transfer Price cannot be empty"+"\n");
459
				continue;
460
			}
461
			if (!checkEmptyString(sheet.getRow(iterator).getCell(4))){
462
				transferPrice = sheet.getRow(iterator).getCell(4).getNumericCellValue();
463
				if(transferPrice==0){
464
					sb.append(sku + " Transfer Price cannot be zero"+"\n");
465
					continue;
466
				}
467
				snapdealItem.setTransferPrice(transferPrice);
468
			}
469
 
470
			if (!checkEmptyString(sheet.getRow(iterator).getCell(5))){
471
				if ((long)sheet.getRow(iterator).getCell(5).getNumericCellValue()==1){
472
					snapdealItem.setSuppressPriceFeed(true);
473
				}
474
				if ((long)sheet.getRow(iterator).getCell(5).getNumericCellValue()==0){
475
					snapdealItem.setSuppressPriceFeed(false);
476
				}
477
			}
478
 
479
			if (!checkEmptyString(sheet.getRow(iterator).getCell(6))){
480
				if ((long)sheet.getRow(iterator).getCell(6).getNumericCellValue()==1){
481
					snapdealItem.setSuppressInventoryFeed(true);
482
				}
483
				if ((long)sheet.getRow(iterator).getCell(6).getNumericCellValue()==0){
484
					snapdealItem.setSuppressInventoryFeed(false);
485
				}
486
			}
9478 kshitij.so 487
 
488
			if (!checkEmptyString(sheet.getRow(iterator).getCell(7))){
489
				String snapdealItemCode = sheet.getRow(iterator).getCell(7).getStringCellValue();
490
				snapdealItem.setSkuAtSnapdeal(snapdealItemCode);
491
			}
9568 kshitij.so 492
 
493
			if (!checkEmptyString(sheet.getRow(iterator).getCell(8))){
494
				String supc = sheet.getRow(iterator).getCell(8).getStringCellValue();
495
				snapdealItem.setSupc(supc);
496
			}
9242 kshitij.so 497
			double weight = item.getWeight();
498
 
499
			/*
500
			 *TODO Uncomment this for pricing feed. 
501
			 * if(weight==0){
502
				sb.append(sku + " Please add weight"+"\n");
503
				continue;
504
			}*/
505
			if (weight!=0){
506
				int slabs = (int) ((weight - .001)/(.5));
507
 
508
				for(int i=0;i<slabs;i++){
509
					courierCost = courierCost + 35;
510
				}
511
			}
512
 
513
			snapdealItem.setCourierCost(courierCost);
514
			sellingPrice = roundTwoDecimals(((transferPrice + courierCost*1.1236)/(100 - 3.59*1.1236))*100);
515
			snapdealItem.setSellingPrice(sellingPrice);
516
			double commision_value = roundTwoDecimals(.0359*sellingPrice + courierCost);
517
			commission = roundTwoDecimals(((.0359*sellingPrice + courierCost)/sellingPrice)*100);
518
			snapdealItem.setCommission(commission);
519
			serviceTax = roundTwoDecimals((commision_value * .1236)); 
520
			snapdealItem.setServiceTax(serviceTax);
8888 vikram.rag 521
			if(!catalogClient.addOrUpdateSnapdealItem(snapdealItem)){
8739 vikram.rag 522
				sb.append(sku + "\n");
523
			}	
524
		}
525
		//logger.info("Amazon Bulk Map "+amazonBulkUpdate.toString());
526
		File file = new File("/tmp/amazonbulk");
527
		FileWriter writer = new FileWriter(file);
528
		writer.append(sb.toString());
529
		writer.close();
530
		byte[] buffer = new byte[(int)file.length()];
531
		InputStream input = null;
532
		try {
533
			int totalBytesRead = 0;
534
			input = new BufferedInputStream(new FileInputStream(file));
535
			while(totalBytesRead < buffer.length){
536
				int bytesRemaining = buffer.length - totalBytesRead;
537
				int bytesRead = input.read(buffer, totalBytesRead, bytesRemaining); 
538
				if (bytesRead > 0){
539
					totalBytesRead = totalBytesRead + bytesRead;
540
				}
541
			}
542
		}
543
		finally {
544
			input.close();
545
			file.delete();
546
		}
547
 
548
		response.setHeader("Content-Type", "text/javascript");
549
 
550
		ServletOutputStream sos;
551
		try {
552
			sos = response.getOutputStream();
553
			sos.write(buffer);
554
			sos.flush();
555
		} catch (IOException e) {
556
			System.out.println("Unable to stream the manifest file");
557
		}   
558
	}
559
 
560
	public boolean checkEmptyString(Cell cell){
561
		if (cell==null){
562
			return true;
563
		}
564
		return false;
565
	}
566
 
9242 kshitij.so 567
	double roundTwoDecimals(double d) {
568
		DecimalFormat twoPlaces = new DecimalFormat("#.##");
569
		return Double.valueOf(twoPlaces.format(d));
570
	}
571
 
572
 
8739 vikram.rag 573
	public String show() {
574
		logger.info("Before fetching role");
575
		logger.info(request.getSession().toString());
576
		logger.info(ReportsUtils.ROLE);
577
		logger.info(session.getAttribute(ReportsUtils.ROLE).toString());
578
		logger.info(request.getRequestURI().substring(request.getContextPath().length()).split("/")[1]);
579
		if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), request.getRequestURI().substring(request.getContextPath().length()).split("/")[1])) {
580
			logger.info(request.getRequestURI().substring(request.getContextPath().length()).split("/")[1]);
581
			return "authfail";
582
		}
583
 
584
		if (StringUtils.equals(id, "snapdeal-options")){
585
			return "snapdeal-options";
586
		}
9242 kshitij.so 587
		if (StringUtils.equals(id, "item-table")){
588
			return "snapdeal-item-table";
589
		}
8739 vikram.rag 590
 
591
		return "id";
592
	}
593
 
594
	public void setId(String id) {
595
		this.id = id;
596
	}
597
 
598
	public HttpServletRequest getRequest() {
599
		logger.info("set request"+request.toString());
600
		return request;
601
	}
602
 
603
	public void setRequest(HttpServletRequest request) {
604
		this.request = request;
605
	}
606
 
607
	public HttpServletResponse getResponse() {
608
		return response;
609
	}
610
 
611
	public void setResponse(HttpServletResponse response) {
612
		this.response = response;
613
	}
614
 
615
	public HttpSession getSession() {
616
		return session;
617
	}
618
 
619
	public void setSession(HttpSession session) {
620
		logger.info("set session"+session.toString());
621
		this.session = session;
622
	}
623
 
624
	public ServletContext getContext() {
625
		return context;
626
	}
627
 
628
	public void setContext(ServletContext context) {
629
		this.context = context;
630
	}
631
 
632
	public String getUrl() {
633
		return url;
634
	}
635
 
636
	public void setUrl(String url) {
637
		this.url = url;
638
	}
639
 
640
	public String getItemId() {
641
		return itemId;
642
	}
643
 
644
	public void setItemId(String itemId) {
645
		this.itemId = itemId;
646
	}
647
 
648
	public String getIsSnapdealListed() {
649
		return isSnapdealListed;
650
	}
651
 
652
	public void setIsSnapdealListed(String isSnapdealListed) {
653
		this.isSnapdealListed = isSnapdealListed;
654
	}
655
 
656
	public String getExceptionPrice() {
657
		return exceptionPrice;
658
	}
659
 
660
	public void setExceptionPrice(String exceptionPrice) {
661
		this.exceptionPrice = exceptionPrice;
662
	}
663
 
664
	public String getWarehouseId() {
665
		return warehouseId;
666
	}
667
 
668
	public void setWarehouseId(String warehouseId) {
669
		this.warehouseId = warehouseId;
670
	}
671
 
672
	public File getFile() {
673
		return file;
674
	}
675
 
676
	public void setFile(File file) {
677
		this.file = file;
678
	}
679
 
680
	public String getErrMsg() {
681
		return errMsg;
682
	}
683
 
684
	public void setErrMsg(String errMsg) {
685
		this.errMsg = errMsg;
686
	}
687
 
688
	public String getNext() {
689
		return next;
690
	}
691
 
692
	public void setNext(String next) {
693
		this.next = next;
694
	}
695
 
696
	public String getId() {
697
		return id;
698
	}
699
 
700
	public void setServletRequest(HttpServletRequest req) {
701
		this.request = req;
702
		this.session = req.getSession();        
703
	}
704
 
705
	public void setServletContext(ServletContext arg0) {
706
		// TODO Auto-generated method stub
707
 
708
	}
709
 
710
	public void setServletResponse(HttpServletResponse response) {
711
		this.response = response;
712
	}
713
 
9242 kshitij.so 714
	public void setSearchText(String searchText) {
715
		this.searchText = searchText;
716
	}
717
 
718
	public String getSearchText() {
719
		return searchText;
720
	}
721
 
722
	public long getSearchCount() {
723
		return searchCount;
724
	}
725
 
726
	public long getTotalCount() {
727
		return totalCount;
728
	}
729
 
730
	public void setSearchCount(long count) {
731
		this.searchCount = count;
732
	}
733
 
734
	public List<SnapdealItemDetails> getSnapdealItems(){
735
		return snapdealItems;
736
	}
737
 
738
	public void setSellingPrice(String sellingPrice) {
739
		this.sellingPrice = sellingPrice;
740
	}
741
 
742
	public String getSellingPrice() {
743
		return sellingPrice;
744
	}
745
 
746
	public void setTransferPrice(String transferPrice) {
747
		this.transferPrice = transferPrice;
748
	}
749
 
750
	public String getTransferPrice() {
751
		return transferPrice;
752
	}
753
 
754
	public void setWebisteMrp(String webisteMrp) {
755
		this.webisteMrp = webisteMrp;
756
	}
757
 
758
	public String getWebisteMrp() {
759
		return webisteMrp;
760
	}
761
 
762
	public void setWebisteSellingPrice(String webisteSellingPrice) {
763
		this.webisteSellingPrice = webisteSellingPrice;
764
	}
765
 
766
	public String getWebisteSellingPrice() {
767
		return webisteSellingPrice;
768
	}
769
 
770
	public void setIsListedOnSnapdeal(String isListedOnSnapdeal) {
771
		this.isListedOnSnapdeal = isListedOnSnapdeal;
772
	}
773
 
774
	public String getIsSuppressInventoryFeed() {
775
		return isSuppressInventoryFeed;
776
	}
777
 
778
	public void setIsSuppressInventoryFeed(String isSuppressInventoryFeed) {
779
		this.isSuppressInventoryFeed = isSuppressInventoryFeed;
780
	}
781
 
782
	public String getIsSuppressPriceFeed() {
783
		return isSuppressPriceFeed;
784
	}
785
 
786
	public void setIsSuppressPriceFeed(String isSuppressPriceFeed) {
787
		this.isSuppressPriceFeed = isSuppressPriceFeed;
788
	}
789
 
790
	public String getIsListedOnSnapdeal() {
791
		return isListedOnSnapdeal;
792
	}
793
 
794
	public void setCommission(String commission) {
795
		this.commission = commission;
796
	}
797
 
798
	public String getCommission() {
799
		return commission;
800
	}
801
 
802
	public void setServiceTax(String serviceTax) {
803
		this.serviceTax = serviceTax;
804
	}
805
 
806
	public String getServiceTax() {
807
		return serviceTax;
808
	}
809
 
810
	public void setCourierCost(String courierCost) {
811
		this.courierCost = courierCost;
812
	}
813
 
814
	public String getCourierCost() {
815
		return courierCost;
816
	}
817
 
9478 kshitij.so 818
	public void setMaxNlc(String maxNlc) {
819
		this.maxNlc = maxNlc;
820
	}
821
 
822
	public String getMaxNlc() {
823
		return maxNlc;
824
	}
825
 
9242 kshitij.so 826
	public String getItemDetails(){
827
		return itemObj.toString();
828
	}
829
 
830
 
831
 
832
}