Subversion Repositories SmartDukaan

Rev

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

Rev 9110 Rev 9113
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;
-
 
7
import in.shop2020.model.v1.catalog.SnapdealItem;
5
import in.shop2020.model.v1.catalog.SnapdealItem;
8
import in.shop2020.model.v1.catalog.SnapdealItemDetails;
-
 
9
import in.shop2020.model.v1.order.AmazonFbaSalesSnapshot;
6
import in.shop2020.model.v1.order.AmazonFbaSalesSnapshot;
10
import in.shop2020.model.v1.order.SnapdealOrder;
7
import in.shop2020.model.v1.order.SnapdealOrder;
11
import in.shop2020.support.utils.ReportsUtils;
8
import in.shop2020.support.utils.ReportsUtils;
12
import in.shop2020.thrift.clients.CatalogClient;
9
import in.shop2020.thrift.clients.CatalogClient;
13
import in.shop2020.thrift.clients.TransactionClient;
10
import in.shop2020.thrift.clients.TransactionClient;
Line 19... Line 16...
19
import java.io.FileOutputStream;
16
import java.io.FileOutputStream;
20
import java.io.FileWriter;
17
import java.io.FileWriter;
21
import java.io.IOException;
18
import java.io.IOException;
22
import java.io.InputStream;
19
import java.io.InputStream;
23
import java.util.ArrayList;
20
import java.util.ArrayList;
24
import java.util.Arrays;
-
 
25
import java.util.HashMap;
21
import java.util.HashMap;
26
import java.util.List;
22
import java.util.List;
27
import java.util.Map;
23
import java.util.Map;
28
 
24
 
29
import javax.servlet.ServletContext;
25
import javax.servlet.ServletContext;
Line 65... Line 61...
65
	private String warehouseId;
61
	private String warehouseId;
66
	private File file;
62
	private File file;
67
	private String errMsg;
63
	private String errMsg;
68
	private String next;
64
	private String next;
69
	private String id;
65
	private String id;
70
	private String searchText;
-
 
71
	private List<SnapdealItemDetails> snapdealItems;
-
 
72
	private long searchCount;
-
 
73
	private long totalCount;
-
 
74
 
66
 
75
	public String index() {
67
	public String index() {
76
		if (!ReportsUtils.canAccessReport((Long) session.getAttribute(ReportsUtils.ROLE),request.getServletPath())) {
68
		if (!ReportsUtils.canAccessReport((Long) session.getAttribute(ReportsUtils.ROLE),request.getServletPath())) {
77
			return "authfail";
69
			return "authfail";
78
		}
70
		}
79
		return "index";
71
		return "index";
80
	}
72
	}
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
	}
-
 
96
 
73
 
97
	public String uploadBulkSheet(){
74
	public String uploadBulkSheet(){
98
		if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0])) {
75
		if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0])) {
99
			logger.info(request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0]);
76
			logger.info(request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0]);
100
			return "authfail";
77
			return "authfail";
101
		}
78
		}
102
		return "snapdeal-bulk-upload";
79
		return "snapdeal-bulk-upload";
103
	}
80
	}
104
 
81
	
105
	public void downloadSnapdealListings() throws IOException, TException{
82
	public void downloadSnapdealListings() throws IOException, TException{
106
		File file = new File("/tmp/snapdeal-bulk-upload-template.xls");
83
		File file = new File("/tmp/snapdeal-bulk-upload-template.xls");
107
		HSSFWorkbook hwb=new HSSFWorkbook();
84
		HSSFWorkbook hwb=new HSSFWorkbook();
108
		HSSFSheet sheet =  hwb.createSheet("Snapdeal-Listings");
85
		HSSFSheet sheet =  hwb.createSheet("Snapdeal-Listings");
109
		HSSFRow rowhead=   sheet.createRow((short)0);
86
		HSSFRow rowhead=   sheet.createRow((short)0);
110
		rowhead.createCell((short) 0).setCellValue("ITEM-ID");
87
		rowhead.createCell((short) 0).setCellValue("ITEM-ID");
111
		rowhead.createCell((short) 1).setCellValue("WAREHOUSE-ID");
88
		rowhead.createCell((short) 1).setCellValue("WAREHOUSE-ID");
112
		rowhead.createCell((short) 2).setCellValue("EXCEPTIONAL-PRICE");
89
		rowhead.createCell((short) 2).setCellValue("EXCEPTIONAL-PRICE");
113
		rowhead.createCell((short) 3).setCellValue("SNAPDEAL-LISTED");
90
		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");
-
 
119
		CatalogClient catalogServiceClient = null;
91
		CatalogClient catalogServiceClient = null;
120
		List<SnapdealItemDetails> snapdealItems = null;
92
		List<SnapdealItem> snapdealItems = null;
121
		try {
93
		try {
-
 
94
			//catalogServiceClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port");
122
			catalogServiceClient = new CatalogClient();
95
			catalogServiceClient = new CatalogClient();
123
			in.shop2020.model.v1.catalog.CatalogService.Client catalogClient= catalogServiceClient.getClient();
96
			in.shop2020.model.v1.catalog.CatalogService.Client catalogClient= catalogServiceClient.getClient();
124
			snapdealItems = catalogClient.getAllSnapdealItems();
97
			snapdealItems = catalogClient.getAllSnapdealItems();
125
		} catch (Exception e) {
98
		} catch (Exception e) {
-
 
99
			// TODO Auto-generated catch block
126
			e.printStackTrace();
100
			e.printStackTrace();
127
		}
101
		}
128
		int iterator=1;
102
		int iterator=1;
129
		for(SnapdealItemDetails snapdealItem:snapdealItems){
103
		for(SnapdealItem snapdealItem:snapdealItems){
130
			HSSFRow row = sheet.createRow((short)iterator);
104
			HSSFRow row = sheet.createRow((short)iterator);
131
			row.createCell((short) 0).setCellValue(snapdealItem.getItem_id());
105
			row.createCell((short) 0).setCellValue(snapdealItem.getItem_id());
132
			row.createCell((short) 1).setCellValue(snapdealItem.getWarehouseId());
106
			row.createCell((short) 1).setCellValue(snapdealItem.getWarehouseId());
133
			row.createCell((short) 2).setCellValue(snapdealItem.getExceptionPrice());
107
			row.createCell((short) 2).setCellValue(snapdealItem.getExceptionPrice());
134
			if(snapdealItem.isIsListedOnSnapdeal()){
108
			if(snapdealItem.isIsListedOnSnapdeal()){
135
				row.createCell((short) 3).setCellValue(1);
109
				row.createCell((short) 3).setCellValue(1);
136
			}
110
			}
137
			else{
111
			else{
138
				row.createCell((short) 3).setCellValue(0);
112
				row.createCell((short) 3).setCellValue(0);
139
			}
113
			}
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());
-
 
145
			iterator++;
114
			iterator++;
146
		}
115
		}
147
 
116
		
148
		FileOutputStream fileOut = null;
117
		FileOutputStream fileOut = null;
149
		try {
118
		try {
150
			fileOut = new FileOutputStream(file);
119
			fileOut = new FileOutputStream(file);
151
		} catch (FileNotFoundException e) {
120
		} catch (FileNotFoundException e) {
152
			// TODO Auto-generated catch block
121
			// TODO Auto-generated catch block
Line 191... Line 160...
191
			sos.flush();
160
			sos.flush();
192
		} catch (IOException e) {
161
		} catch (IOException e) {
193
			System.out.println("Unable to stream the manifest file");
162
			System.out.println("Unable to stream the manifest file");
194
		}   
163
		}   
195
 
164
 
196
 
165
		
197
	}
166
	}
198
 
167
 
199
	public void uploadsnapdealBulkSheet() throws IOException, TException{
168
	public void uploadsnapdealBulkSheet() throws IOException, TException{
200
		File fileToCreate = new File("/tmp/", "Snapdeal-bulk-upload.xls");
169
		File fileToCreate = new File("/tmp/", "Snapdeal-bulk-upload.xls");
201
		FileUtils.copyFile(this.file, fileToCreate);
170
		FileUtils.copyFile(this.file, fileToCreate);
Line 203... Line 172...
203
		HSSFWorkbook workbook = new HSSFWorkbook(iFile);
172
		HSSFWorkbook workbook = new HSSFWorkbook(iFile);
204
		HSSFSheet sheet = workbook.getSheetAt(0);
173
		HSSFSheet sheet = workbook.getSheetAt(0);
205
		Client catalogClient=null;
174
		Client catalogClient=null;
206
		StringBuilder sb = new StringBuilder();
175
		StringBuilder sb = new StringBuilder();
207
		try {
176
		try {
-
 
177
			//catalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
208
			catalogClient = new CatalogClient().getClient();
178
			catalogClient = new CatalogClient().getClient();
209
		} catch (TTransportException e) {
179
		} catch (TTransportException e) {
-
 
180
			// TODO Auto-generated catch block
210
			e.printStackTrace();
181
			e.printStackTrace();
211
		}
182
		}
212
		for (int iterator=(sheet.getFirstRowNum()+1);iterator<=sheet.getLastRowNum();iterator++){
183
		for (int iterator=(sheet.getFirstRowNum()+1);iterator<=sheet.getLastRowNum();iterator++){
213
			SnapdealItem snapdealItem =null;
184
			SnapdealItem snapdealItem =null;
214
			Item item = null;
-
 
215
			Long sku;
185
			Long sku;
216
			if (checkEmptyString(sheet.getRow(iterator).getCell(0))){
186
			if (checkEmptyString(sheet.getRow(iterator).getCell(0))){
217
				continue;
187
				continue;
218
			}
188
			}
219
			else {
189
			else {
220
				sku=(long) sheet.getRow(iterator).getCell(0).getNumericCellValue();
190
				sku=(long) sheet.getRow(iterator).getCell(0).getNumericCellValue();
221
				snapdealItem = catalogClient.getSnapdealItem(sku);
191
				snapdealItem = catalogClient.getSnapdealItem(sku);
222
				try {
-
 
223
					item = catalogClient.getItem(sku);
-
 
224
				} catch (CatalogServiceException e) {
-
 
225
					sb.append(sku + " Item not Present"+"\n");
-
 
226
				}
-
 
227
				if(snapdealItem.getItem_id()==0){
192
				if(snapdealItem.getItem_id()==0){
228
					snapdealItem = new SnapdealItem();
193
					snapdealItem = new SnapdealItem();
229
					snapdealItem.setItem_id(sku); 
194
					snapdealItem.setItem_id(sku); 
230
				}
195
				}
231
			}
196
			}
-
 
197
			
232
			if (!checkEmptyString(sheet.getRow(iterator).getCell(1))){
198
			if (!checkEmptyString(sheet.getRow(iterator).getCell(1))){
233
				long warehouseId = (long) sheet.getRow(iterator).getCell(1).getNumericCellValue();
199
				long warehouseId = (long) sheet.getRow(iterator).getCell(1).getNumericCellValue();
234
				snapdealItem.setWarehouseId(warehouseId);
200
				snapdealItem.setWarehouseId(warehouseId);
235
			}
201
			}
236
 
202
 
Line 245... Line 211...
245
				}
211
				}
246
				if ((long)sheet.getRow(iterator).getCell(3).getNumericCellValue()==0){
212
				if ((long)sheet.getRow(iterator).getCell(3).getNumericCellValue()==0){
247
					snapdealItem.setIsListedOnSnapdeal(false);
213
					snapdealItem.setIsListedOnSnapdeal(false);
248
				}
214
				}
249
			}
215
			}
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);
-
 
277
			if(!catalogClient.addOrUpdateSnapdealItem(snapdealItem)){
216
			if(!catalogClient.addOrUpdateSnapdealItem(snapdealItem)){
278
				sb.append(sku + "\n");
217
				sb.append(sku + "\n");
279
			}	
218
			}	
280
		}
219
		}
281
		//logger.info("Amazon Bulk Map "+amazonBulkUpdate.toString());
220
		//logger.info("Amazon Bulk Map "+amazonBulkUpdate.toString());
Line 332... Line 271...
332
		}
271
		}
333
 
272
 
334
		if (StringUtils.equals(id, "snapdeal-options")){
273
		if (StringUtils.equals(id, "snapdeal-options")){
335
			return "snapdeal-options";
274
			return "snapdeal-options";
336
		}
275
		}
337
		if (StringUtils.equals(id, "item-table")){
-
 
338
			return "snapdeal-item-table";
-
 
339
		}
-
 
340
 
276
 
341
		return "id";
277
		return "id";
342
	}
278
	}
343
 
279
 
344
	public void setId(String id) {
280
	public void setId(String id) {
Line 459... Line 395...
459
	}
395
	}
460
 
396
 
461
	public void setServletResponse(HttpServletResponse response) {
397
	public void setServletResponse(HttpServletResponse response) {
462
		this.response = response;
398
		this.response = response;
463
	}
399
	}
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
	
-
 
486
 
400
 
487
}
401
}