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