Subversion Repositories SmartDukaan

Rev

Rev 8903 | Rev 9113 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 8903 Rev 9110
Line 1... Line 1...
1
package in.shop2020.support.controllers;
1
package in.shop2020.support.controllers;
2
 
2
 
3
import in.shop2020.model.v1.catalog.Amazonlisted;
3
import in.shop2020.model.v1.catalog.Amazonlisted;
4
import in.shop2020.model.v1.catalog.CatalogService.Client;
4
import in.shop2020.model.v1.catalog.CatalogService.Client;
-
 
5
import in.shop2020.model.v1.catalog.CatalogServiceException;
-
 
6
import in.shop2020.model.v1.catalog.Item;
5
import in.shop2020.model.v1.catalog.SnapdealItem;
7
import in.shop2020.model.v1.catalog.SnapdealItem;
-
 
8
import in.shop2020.model.v1.catalog.SnapdealItemDetails;
6
import in.shop2020.model.v1.order.AmazonFbaSalesSnapshot;
9
import in.shop2020.model.v1.order.AmazonFbaSalesSnapshot;
7
import in.shop2020.model.v1.order.SnapdealOrder;
10
import in.shop2020.model.v1.order.SnapdealOrder;
8
import in.shop2020.support.utils.ReportsUtils;
11
import in.shop2020.support.utils.ReportsUtils;
9
import in.shop2020.thrift.clients.CatalogClient;
12
import in.shop2020.thrift.clients.CatalogClient;
10
import in.shop2020.thrift.clients.TransactionClient;
13
import in.shop2020.thrift.clients.TransactionClient;
Line 16... Line 19...
16
import java.io.FileOutputStream;
19
import java.io.FileOutputStream;
17
import java.io.FileWriter;
20
import java.io.FileWriter;
18
import java.io.IOException;
21
import java.io.IOException;
19
import java.io.InputStream;
22
import java.io.InputStream;
20
import java.util.ArrayList;
23
import java.util.ArrayList;
-
 
24
import java.util.Arrays;
21
import java.util.HashMap;
25
import java.util.HashMap;
22
import java.util.List;
26
import java.util.List;
23
import java.util.Map;
27
import java.util.Map;
24
 
28
 
25
import javax.servlet.ServletContext;
29
import javax.servlet.ServletContext;
Line 61... Line 65...
61
	private String warehouseId;
65
	private String warehouseId;
62
	private File file;
66
	private File file;
63
	private String errMsg;
67
	private String errMsg;
64
	private String next;
68
	private String next;
65
	private String id;
69
	private String id;
-
 
70
	private String searchText;
-
 
71
	private List<SnapdealItemDetails> snapdealItems;
-
 
72
	private long searchCount;
-
 
73
	private long totalCount;
66
 
74
 
67
	public String index() {
75
	public String index() {
68
		if (!ReportsUtils.canAccessReport((Long) session.getAttribute(ReportsUtils.ROLE),request.getServletPath())) {
76
		if (!ReportsUtils.canAccessReport((Long) session.getAttribute(ReportsUtils.ROLE),request.getServletPath())) {
69
			return "authfail";
77
			return "authfail";
70
		}
78
		}
71
		return "index";
79
		return "index";
72
	}
80
	}
-
 
81
	
-
 
82
	public String fetchItems() throws TException {
-
 
83
		Client CatalogClient = new CatalogClient().getClient();
-
 
84
		if (searchText.length() == 0) {
-
 
85
			snapdealItems = CatalogClient.getSnapdealItems(Long.valueOf(next), 10);
-
 
86
			totalCount = CatalogClient.getCountForSnapdealItems();
-
 
87
			setSearchCount(totalCount);
-
 
88
		} else {
-
 
89
			List<String> subString = Arrays.asList(searchText.split(" "));
-
 
90
			snapdealItems = CatalogClient.searchSnapdealItems(subString,Long.valueOf(next), 10);
-
 
91
			totalCount = CatalogClient.getCountForSnapdealItems();
-
 
92
			searchCount = CatalogClient.getSnapdealSearchResultCount(subString);
-
 
93
		}
-
 
94
		return "snapdeal-item-table";
-
 
95
	}
73
 
96
 
74
	public String uploadBulkSheet(){
97
	public String uploadBulkSheet(){
75
		if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0])) {
98
		if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0])) {
76
			logger.info(request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0]);
99
			logger.info(request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0]);
77
			return "authfail";
100
			return "authfail";
78
		}
101
		}
79
		return "snapdeal-bulk-upload";
102
		return "snapdeal-bulk-upload";
80
	}
103
	}
81
	
104
 
82
	public void downloadSnapdealListings() throws IOException, TException{
105
	public void downloadSnapdealListings() throws IOException, TException{
83
		File file = new File("/tmp/snapdeal-bulk-upload-template.xls");
106
		File file = new File("/tmp/snapdeal-bulk-upload-template.xls");
84
		HSSFWorkbook hwb=new HSSFWorkbook();
107
		HSSFWorkbook hwb=new HSSFWorkbook();
85
		HSSFSheet sheet =  hwb.createSheet("Snapdeal-Listings");
108
		HSSFSheet sheet =  hwb.createSheet("Snapdeal-Listings");
86
		HSSFRow rowhead=   sheet.createRow((short)0);
109
		HSSFRow rowhead=   sheet.createRow((short)0);
87
		rowhead.createCell((short) 0).setCellValue("ITEM-ID");
110
		rowhead.createCell((short) 0).setCellValue("ITEM-ID");
88
		rowhead.createCell((short) 1).setCellValue("WAREHOUSE-ID");
111
		rowhead.createCell((short) 1).setCellValue("WAREHOUSE-ID");
89
		rowhead.createCell((short) 2).setCellValue("EXCEPTIONAL-PRICE");
112
		rowhead.createCell((short) 2).setCellValue("EXCEPTIONAL-PRICE");
90
		rowhead.createCell((short) 3).setCellValue("SNAPDEAL-LISTED");
113
		rowhead.createCell((short) 3).setCellValue("SNAPDEAL-LISTED");
-
 
114
		rowhead.createCell((short) 4).setCellValue("TRANSFER-PRICE");
-
 
115
		rowhead.createCell((short) 5).setCellValue("SELLING-PRICE");
-
 
116
		rowhead.createCell((short) 6).setCellValue("COURIER-COST");
-
 
117
		rowhead.createCell((short) 7).setCellValue("COMMISION");
-
 
118
		rowhead.createCell((short) 8).setCellValue("SERVICE-TAX");
91
		CatalogClient catalogServiceClient = null;
119
		CatalogClient catalogServiceClient = null;
92
		List<SnapdealItem> snapdealItems = null;
120
		List<SnapdealItemDetails> snapdealItems = null;
93
		try {
121
		try {
94
			//catalogServiceClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port");
-
 
95
			catalogServiceClient = new CatalogClient();
122
			catalogServiceClient = new CatalogClient();
96
			in.shop2020.model.v1.catalog.CatalogService.Client catalogClient= catalogServiceClient.getClient();
123
			in.shop2020.model.v1.catalog.CatalogService.Client catalogClient= catalogServiceClient.getClient();
97
			snapdealItems = catalogClient.getAllSnapdealItems();
124
			snapdealItems = catalogClient.getAllSnapdealItems();
98
		} catch (Exception e) {
125
		} catch (Exception e) {
99
			// TODO Auto-generated catch block
-
 
100
			e.printStackTrace();
126
			e.printStackTrace();
101
		}
127
		}
102
		int iterator=1;
128
		int iterator=1;
103
		for(SnapdealItem snapdealItem:snapdealItems){
129
		for(SnapdealItemDetails snapdealItem:snapdealItems){
104
			HSSFRow row = sheet.createRow((short)iterator);
130
			HSSFRow row = sheet.createRow((short)iterator);
105
			row.createCell((short) 0).setCellValue(snapdealItem.getItem_id());
131
			row.createCell((short) 0).setCellValue(snapdealItem.getItem_id());
106
			row.createCell((short) 1).setCellValue(snapdealItem.getWarehouseId());
132
			row.createCell((short) 1).setCellValue(snapdealItem.getWarehouseId());
107
			row.createCell((short) 2).setCellValue(snapdealItem.getExceptionPrice());
133
			row.createCell((short) 2).setCellValue(snapdealItem.getExceptionPrice());
108
			if(snapdealItem.isIsListedOnSnapdeal()){
134
			if(snapdealItem.isIsListedOnSnapdeal()){
109
				row.createCell((short) 3).setCellValue(1);
135
				row.createCell((short) 3).setCellValue(1);
110
			}
136
			}
111
			else{
137
			else{
112
				row.createCell((short) 3).setCellValue(0);
138
				row.createCell((short) 3).setCellValue(0);
113
			}
139
			}
-
 
140
			row.createCell((short) 4).setCellValue(snapdealItem.getTransferPrice());
-
 
141
			row.createCell((short) 5).setCellValue(snapdealItem.getSellingPrice());
-
 
142
			rowhead.createCell((short) 6).setCellValue(snapdealItem.getCourierCost());
-
 
143
			rowhead.createCell((short) 7).setCellValue(snapdealItem.getCommission());
-
 
144
			rowhead.createCell((short) 8).setCellValue(snapdealItem.getServiceTax());
114
			iterator++;
145
			iterator++;
115
		}
146
		}
116
		
147
 
117
		FileOutputStream fileOut = null;
148
		FileOutputStream fileOut = null;
118
		try {
149
		try {
119
			fileOut = new FileOutputStream(file);
150
			fileOut = new FileOutputStream(file);
120
		} catch (FileNotFoundException e) {
151
		} catch (FileNotFoundException e) {
121
			// TODO Auto-generated catch block
152
			// TODO Auto-generated catch block
Line 160... Line 191...
160
			sos.flush();
191
			sos.flush();
161
		} catch (IOException e) {
192
		} catch (IOException e) {
162
			System.out.println("Unable to stream the manifest file");
193
			System.out.println("Unable to stream the manifest file");
163
		}   
194
		}   
164
 
195
 
165
		
196
 
166
	}
197
	}
167
 
198
 
168
	public void uploadsnapdealBulkSheet() throws IOException, TException{
199
	public void uploadsnapdealBulkSheet() throws IOException, TException{
169
		File fileToCreate = new File("/tmp/", "Snapdeal-bulk-upload.xls");
200
		File fileToCreate = new File("/tmp/", "Snapdeal-bulk-upload.xls");
170
		FileUtils.copyFile(this.file, fileToCreate);
201
		FileUtils.copyFile(this.file, fileToCreate);
Line 172... Line 203...
172
		HSSFWorkbook workbook = new HSSFWorkbook(iFile);
203
		HSSFWorkbook workbook = new HSSFWorkbook(iFile);
173
		HSSFSheet sheet = workbook.getSheetAt(0);
204
		HSSFSheet sheet = workbook.getSheetAt(0);
174
		Client catalogClient=null;
205
		Client catalogClient=null;
175
		StringBuilder sb = new StringBuilder();
206
		StringBuilder sb = new StringBuilder();
176
		try {
207
		try {
177
			//catalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
-
 
178
			catalogClient = new CatalogClient().getClient();
208
			catalogClient = new CatalogClient().getClient();
179
		} catch (TTransportException e) {
209
		} catch (TTransportException e) {
180
			// TODO Auto-generated catch block
-
 
181
			e.printStackTrace();
210
			e.printStackTrace();
182
		}
211
		}
183
		for (int iterator=(sheet.getFirstRowNum()+1);iterator<=sheet.getLastRowNum();iterator++){
212
		for (int iterator=(sheet.getFirstRowNum()+1);iterator<=sheet.getLastRowNum();iterator++){
184
			SnapdealItem snapdealItem =null;
213
			SnapdealItem snapdealItem =null;
-
 
214
			Item item = null;
185
			Long sku;
215
			Long sku;
186
			if (checkEmptyString(sheet.getRow(iterator).getCell(0))){
216
			if (checkEmptyString(sheet.getRow(iterator).getCell(0))){
187
				continue;
217
				continue;
188
			}
218
			}
189
			else {
219
			else {
190
				sku=(long) sheet.getRow(iterator).getCell(0).getNumericCellValue();
220
				sku=(long) sheet.getRow(iterator).getCell(0).getNumericCellValue();
191
				snapdealItem = catalogClient.getSnapdealItem(sku);
221
				snapdealItem = catalogClient.getSnapdealItem(sku);
-
 
222
				try {
-
 
223
					item = catalogClient.getItem(sku);
-
 
224
				} catch (CatalogServiceException e) {
-
 
225
					sb.append(sku + " Item not Present"+"\n");
-
 
226
				}
192
				if(snapdealItem.getItem_id()==0){
227
				if(snapdealItem.getItem_id()==0){
193
					snapdealItem = new SnapdealItem();
228
					snapdealItem = new SnapdealItem();
194
					snapdealItem.setItem_id(sku); 
229
					snapdealItem.setItem_id(sku); 
195
				}
230
				}
196
			}
231
			}
197
			
-
 
198
			if (!checkEmptyString(sheet.getRow(iterator).getCell(1))){
232
			if (!checkEmptyString(sheet.getRow(iterator).getCell(1))){
199
				long warehouseId = (long) sheet.getRow(iterator).getCell(1).getNumericCellValue();
233
				long warehouseId = (long) sheet.getRow(iterator).getCell(1).getNumericCellValue();
200
				snapdealItem.setWarehouseId(warehouseId);
234
				snapdealItem.setWarehouseId(warehouseId);
201
			}
235
			}
202
 
236
 
Line 211... Line 245...
211
				}
245
				}
212
				if ((long)sheet.getRow(iterator).getCell(3).getNumericCellValue()==0){
246
				if ((long)sheet.getRow(iterator).getCell(3).getNumericCellValue()==0){
213
					snapdealItem.setIsListedOnSnapdeal(false);
247
					snapdealItem.setIsListedOnSnapdeal(false);
214
				}
248
				}
215
			}
249
			}
-
 
250
			double transferPrice = 0,sellingPrice,commission,courierCost =45,serviceTax;
-
 
251
			if (!checkEmptyString(sheet.getRow(iterator).getCell(4))){
-
 
252
				transferPrice = sheet.getRow(iterator).getCell(4).getNumericCellValue();
-
 
253
				if(transferPrice==0){
-
 
254
					sb.append(sku + " Transfer Price cannot be zero"+"\n");
-
 
255
					continue;
-
 
256
				}
-
 
257
				snapdealItem.setTransferPrice(transferPrice);
-
 
258
			}
-
 
259
			double weight = item.getWeight();
-
 
260
			if(weight==0){
-
 
261
				sb.append(sku + " Please add weight"+"\n");
-
 
262
				continue;
-
 
263
			}
-
 
264
			int slabs = (int) (weight/.5);
-
 
265
 
-
 
266
			for(int i=0;i<slabs;i++){
-
 
267
				courierCost = courierCost + 35;
-
 
268
			}
-
 
269
			snapdealItem.setCourierCost(courierCost);
-
 
270
			sellingPrice = ((transferPrice + courierCost*1.1236)/(100 - 3.59*1.1236))*100;
-
 
271
			snapdealItem.setSellingPrice(sellingPrice);
-
 
272
			double commision_value = .0359*sellingPrice + courierCost;
-
 
273
			commission = ((.0359*sellingPrice + courierCost)/sellingPrice)*100;
-
 
274
			snapdealItem.setCommission(commission);
-
 
275
			serviceTax = (commision_value * .1236); 
-
 
276
			snapdealItem.setServiceTax(serviceTax);
216
			if(!catalogClient.addOrUpdateSnapdealItem(snapdealItem)){
277
			if(!catalogClient.addOrUpdateSnapdealItem(snapdealItem)){
217
				sb.append(sku + "\n");
278
				sb.append(sku + "\n");
218
			}	
279
			}	
219
		}
280
		}
220
		//logger.info("Amazon Bulk Map "+amazonBulkUpdate.toString());
281
		//logger.info("Amazon Bulk Map "+amazonBulkUpdate.toString());
Line 271... Line 332...
271
		}
332
		}
272
 
333
 
273
		if (StringUtils.equals(id, "snapdeal-options")){
334
		if (StringUtils.equals(id, "snapdeal-options")){
274
			return "snapdeal-options";
335
			return "snapdeal-options";
275
		}
336
		}
-
 
337
		if (StringUtils.equals(id, "item-table")){
-
 
338
			return "snapdeal-item-table";
-
 
339
		}
276
 
340
 
277
		return "id";
341
		return "id";
278
	}
342
	}
279
 
343
 
280
	public void setId(String id) {
344
	public void setId(String id) {
Line 395... Line 459...
395
	}
459
	}
396
 
460
 
397
	public void setServletResponse(HttpServletResponse response) {
461
	public void setServletResponse(HttpServletResponse response) {
398
		this.response = response;
462
		this.response = response;
399
	}
463
	}
-
 
464
	
-
 
465
	public void setSearchText(String searchText) {
-
 
466
		this.searchText = searchText;
-
 
467
	}
-
 
468
 
-
 
469
	public String getSearchText() {
-
 
470
		return searchText;
-
 
471
	}
-
 
472
 
-
 
473
	public long getSearchCount() {
-
 
474
		return searchCount;
-
 
475
	}
-
 
476
 
-
 
477
	public long getTotalCount() {
-
 
478
		return totalCount;
-
 
479
	}
-
 
480
 
-
 
481
	public void setSearchCount(long count) {
-
 
482
		this.searchCount = count;
-
 
483
	}
-
 
484
 
-
 
485
	
400
 
486
 
401
}
487
}