| Line 11... |
Line 11... |
| 11 |
import java.util.ArrayList;
|
11 |
import java.util.ArrayList;
|
| 12 |
import java.util.HashMap;
|
12 |
import java.util.HashMap;
|
| 13 |
import java.util.List;
|
13 |
import java.util.List;
|
| 14 |
import java.util.Map;
|
14 |
import java.util.Map;
|
| 15 |
|
15 |
|
| 16 |
import in.shop2020.model.v1.catalog.CatalogServiceException;
|
- |
|
| 17 |
import in.shop2020.model.v1.catalog.Item;
|
- |
|
| 18 |
import in.shop2020.model.v1.catalog.ItemPricing;
|
- |
|
| 19 |
import in.shop2020.model.v1.catalog.CatalogService.Client;
|
- |
|
| 20 |
import in.shop2020.model.v1.dtr.BulkItems;
|
- |
|
| 21 |
import in.shop2020.model.v1.inventory.BulkAddInventory;
|
- |
|
| 22 |
import in.shop2020.model.v1.inventory.InventoryServiceException;
|
- |
|
| 23 |
import in.shop2020.model.v1.inventory.ItemInventory;
|
- |
|
| 24 |
import in.shop2020.model.v1.inventory.Vendor;
|
- |
|
| 25 |
import in.shop2020.model.v1.inventory.VendorItemPricing;
|
- |
|
| 26 |
import in.shop2020.model.v1.inventory.Warehouse;
|
- |
|
| 27 |
import in.shop2020.model.v1.order.AmazonOrder;
|
- |
|
| 28 |
import in.shop2020.support.utils.ReportsUtils;
|
- |
|
| 29 |
import in.shop2020.thrift.clients.CatalogClient;
|
- |
|
| 30 |
import in.shop2020.thrift.clients.DtrClient;
|
- |
|
| 31 |
import in.shop2020.thrift.clients.InventoryClient;
|
- |
|
| 32 |
import in.shop2020.thrift.clients.TransactionClient;
|
- |
|
| 33 |
|
- |
|
| 34 |
import org.apache.commons.io.FileUtils;
|
- |
|
| 35 |
import org.apache.commons.lang.xwork.StringUtils;
|
- |
|
| 36 |
|
- |
|
| 37 |
import javax.servlet.ServletContext;
|
16 |
import javax.servlet.ServletContext;
|
| 38 |
import javax.servlet.ServletOutputStream;
|
17 |
import javax.servlet.ServletOutputStream;
|
| 39 |
import javax.servlet.http.HttpServletRequest;
|
18 |
import javax.servlet.http.HttpServletRequest;
|
| 40 |
import javax.servlet.http.HttpServletResponse;
|
19 |
import javax.servlet.http.HttpServletResponse;
|
| 41 |
import javax.servlet.http.HttpSession;
|
20 |
import javax.servlet.http.HttpSession;
|
| 42 |
|
21 |
|
| - |
|
22 |
import org.apache.commons.io.FileUtils;
|
| - |
|
23 |
import org.apache.commons.lang.xwork.StringUtils;
|
| 43 |
import org.apache.poi.hssf.usermodel.HSSFRow;
|
24 |
import org.apache.poi.hssf.usermodel.HSSFRow;
|
| 44 |
import org.apache.poi.hssf.usermodel.HSSFSheet;
|
25 |
import org.apache.poi.hssf.usermodel.HSSFSheet;
|
| 45 |
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
26 |
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
| 46 |
import org.apache.poi.ss.usermodel.Cell;
|
27 |
import org.apache.poi.ss.usermodel.Cell;
|
| 47 |
import org.apache.struts2.convention.annotation.InterceptorRef;
|
28 |
import org.apache.struts2.convention.annotation.InterceptorRef;
|
| 48 |
import org.apache.struts2.convention.annotation.InterceptorRefs;
|
29 |
import org.apache.struts2.convention.annotation.InterceptorRefs;
|
| 49 |
import org.apache.struts2.interceptor.ServletRequestAware;
|
30 |
import org.apache.struts2.interceptor.ServletRequestAware;
|
| 50 |
import org.apache.struts2.interceptor.ServletResponseAware;
|
31 |
import org.apache.struts2.interceptor.ServletResponseAware;
|
| 51 |
import org.apache.struts2.util.ServletContextAware;
|
32 |
import org.apache.struts2.util.ServletContextAware;
|
| 52 |
import org.apache.thrift.TException;
|
33 |
import org.apache.thrift.TException;
|
| 53 |
import org.apache.thrift.transport.TTransportException;
|
- |
|
| 54 |
import org.slf4j.Logger;
|
34 |
import org.slf4j.Logger;
|
| 55 |
import org.slf4j.LoggerFactory;
|
35 |
import org.slf4j.LoggerFactory;
|
| 56 |
|
36 |
|
| 57 |
import com.opensymphony.xwork2.ValidationAwareSupport;
|
37 |
import com.opensymphony.xwork2.ValidationAwareSupport;
|
| 58 |
|
38 |
|
| - |
|
39 |
import in.shop2020.model.v1.catalog.CatalogService.Client;
|
| - |
|
40 |
import in.shop2020.model.v1.catalog.CatalogServiceException;
|
| - |
|
41 |
import in.shop2020.model.v1.catalog.GstRate;
|
| - |
|
42 |
import in.shop2020.model.v1.catalog.Item;
|
| - |
|
43 |
import in.shop2020.model.v1.catalog.ItemPricing;
|
| - |
|
44 |
import in.shop2020.model.v1.catalog.StateGstRate;
|
| - |
|
45 |
import in.shop2020.model.v1.dtr.BulkItems;
|
| - |
|
46 |
import in.shop2020.model.v1.inventory.BulkAddInventory;
|
| - |
|
47 |
import in.shop2020.model.v1.inventory.InventoryServiceException;
|
| - |
|
48 |
import in.shop2020.model.v1.inventory.ItemInventory;
|
| - |
|
49 |
import in.shop2020.model.v1.inventory.Vendor;
|
| - |
|
50 |
import in.shop2020.model.v1.inventory.VendorItemPricing;
|
| - |
|
51 |
import in.shop2020.model.v1.inventory.Warehouse;
|
| - |
|
52 |
import in.shop2020.support.utils.ReportsUtils;
|
| - |
|
53 |
import in.shop2020.thrift.clients.CatalogClient;
|
| - |
|
54 |
import in.shop2020.thrift.clients.DtrClient;
|
| - |
|
55 |
import in.shop2020.thrift.clients.InventoryClient;
|
| - |
|
56 |
|
| 59 |
@SuppressWarnings({"unused","deprecation"})
|
57 |
@SuppressWarnings({"unused","deprecation"})
|
| 60 |
|
58 |
|
| 61 |
@InterceptorRefs({
|
59 |
@InterceptorRefs({
|
| 62 |
@InterceptorRef("defaultStack"),
|
60 |
@InterceptorRef("defaultStack"),
|
| 63 |
@InterceptorRef("login")
|
61 |
@InterceptorRef("login")
|
| Line 146... |
Line 144... |
| 146 |
logger.info(request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0]);
|
144 |
logger.info(request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0]);
|
| 147 |
return "authfail";
|
145 |
return "authfail";
|
| 148 |
}
|
146 |
}
|
| 149 |
return "dtr-bulk-add";
|
147 |
return "dtr-bulk-add";
|
| 150 |
}
|
148 |
}
|
| - |
|
149 |
|
| - |
|
150 |
public String loadUploadTaxRateDiv(){
|
| - |
|
151 |
if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0])) {
|
| - |
|
152 |
logger.info(request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0]);
|
| - |
|
153 |
return "authfail";
|
| - |
|
154 |
}
|
| - |
|
155 |
return "upload-tax-rate";
|
| - |
|
156 |
}
|
| 151 |
|
157 |
|
| 152 |
public String loadDownloadVirtualDiv(){
|
158 |
public String loadDownloadVirtualDiv(){
|
| 153 |
if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0])) {
|
159 |
if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0])) {
|
| 154 |
logger.info(request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0]);
|
160 |
logger.info(request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0]);
|
| 155 |
return "authfail";
|
161 |
return "authfail";
|
| Line 254... |
Line 260... |
| 254 |
}else{
|
260 |
}else{
|
| 255 |
setResult("Items added successfully");
|
261 |
setResult("Items added successfully");
|
| 256 |
}
|
262 |
}
|
| 257 |
return "item-details-json";
|
263 |
return "item-details-json";
|
| 258 |
}
|
264 |
}
|
| - |
|
265 |
|
| - |
|
266 |
private static class ItemIdStateId{
|
| - |
|
267 |
private int itemId;
|
| - |
|
268 |
private int stateId;
|
| - |
|
269 |
public int getItemId() {
|
| - |
|
270 |
return itemId;
|
| - |
|
271 |
}
|
| - |
|
272 |
public void setItemId(int itemId) {
|
| - |
|
273 |
this.itemId = itemId;
|
| - |
|
274 |
}
|
| - |
|
275 |
public int getStateId() {
|
| - |
|
276 |
return stateId;
|
| - |
|
277 |
}
|
| - |
|
278 |
public void setStateId(int stateId) {
|
| - |
|
279 |
this.stateId = stateId;
|
| - |
|
280 |
}
|
| - |
|
281 |
}
|
| - |
|
282 |
|
| - |
|
283 |
public String uploadTaxRateSheet() throws IOException, CatalogServiceException, TException{
|
| - |
|
284 |
if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0])) {
|
| - |
|
285 |
logger.info(request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0]);
|
| - |
|
286 |
return "authfail";
|
| - |
|
287 |
}
|
| - |
|
288 |
File fileToCreate = new File("/tmp/", "tax-rate-sheet.xls");
|
| - |
|
289 |
FileUtils.copyFile(this.file, fileToCreate);
|
| - |
|
290 |
FileInputStream iFile = new FileInputStream(new File(file.getAbsolutePath()));
|
| - |
|
291 |
HSSFWorkbook workbook = new HSSFWorkbook(iFile);
|
| - |
|
292 |
HSSFSheet sheet = workbook.getSheetAt(0);
|
| - |
|
293 |
|
| - |
|
294 |
List<Long> itemIdsTaxRates = new ArrayList<Long>();
|
| - |
|
295 |
|
| - |
|
296 |
Map<Long, Double> itemIdIgstTaxRate = new HashMap<Long, Double>();
|
| - |
|
297 |
Map<ItemIdStateId, GstRate> itemIdStateIdStateRateMap = new HashMap<BulkAddController.ItemIdStateId, GstRate>();
|
| - |
|
298 |
|
| - |
|
299 |
for (int iterator = sheet.getFirstRowNum() + 1; iterator <= sheet.getLastRowNum(); iterator++){
|
| - |
|
300 |
long itemId = (long) sheet.getRow(iterator).getCell(0).getNumericCellValue();
|
| - |
|
301 |
long stateId = (long)sheet.getRow(iterator).getCell(1).getNumericCellValue();
|
| - |
|
302 |
double igstRate = sheet.getRow(iterator).getCell(2).getNumericCellValue();
|
| - |
|
303 |
if(stateId == -1){
|
| - |
|
304 |
|
| - |
|
305 |
itemIdIgstTaxRate.put(itemId, igstRate);
|
| - |
|
306 |
}else{
|
| - |
|
307 |
double cgstRate = sheet.getRow(iterator).getCell(3).getNumericCellValue();
|
| - |
|
308 |
double sgstRate = sheet.getRow(iterator).getCell(4).getNumericCellValue();
|
| - |
|
309 |
ItemIdStateId itemIdStateId = new ItemIdStateId();
|
| - |
|
310 |
itemIdStateId.setItemId(Long.valueOf(itemId).intValue());
|
| - |
|
311 |
itemIdStateId.setStateId(Long.valueOf(stateId).intValue());
|
| - |
|
312 |
GstRate gstRate = new GstRate();
|
| - |
|
313 |
gstRate.setCgstRate(cgstRate);
|
| - |
|
314 |
gstRate.setSgstRate(sgstRate);
|
| - |
|
315 |
itemIdStateIdStateRateMap.put(itemIdStateId, gstRate);
|
| - |
|
316 |
itemIdsTaxRates.add(itemId);
|
| - |
|
317 |
}
|
| - |
|
318 |
}
|
| - |
|
319 |
|
| - |
|
320 |
Client cc = new CatalogClient().getClient();
|
| - |
|
321 |
if(!itemIdIgstTaxRate.keySet().isEmpty()){
|
| - |
|
322 |
|
| - |
|
323 |
Map<Long, Item> itemMap = cc.getItems(new ArrayList<Long>(itemIdIgstTaxRate.keySet()));
|
| - |
|
324 |
StringBuilder sb = new StringBuilder();
|
| - |
|
325 |
|
| - |
|
326 |
for(Map.Entry<Long, Double> itemIdIgstTaxRateEntry : itemIdIgstTaxRate.entrySet()){
|
| - |
|
327 |
if(itemMap.get(itemIdIgstTaxRateEntry.getKey()) == null){
|
| - |
|
328 |
sb.append("Item is not valid "+itemIdIgstTaxRateEntry.getKey()+"\n");
|
| - |
|
329 |
}
|
| - |
|
330 |
}
|
| - |
|
331 |
if (sb.length()>0){
|
| - |
|
332 |
setResult("Please correct error \n"+sb.toString());
|
| - |
|
333 |
return "item-details-json";
|
| - |
|
334 |
}
|
| - |
|
335 |
}
|
| - |
|
336 |
|
| - |
|
337 |
if(!itemIdsTaxRates.isEmpty()){
|
| - |
|
338 |
Map<Long, Item> itemMap = cc.getItems(new ArrayList<Long>(itemIdsTaxRates));
|
| - |
|
339 |
StringBuilder sb = new StringBuilder();
|
| - |
|
340 |
for(long itemId : itemIdsTaxRates){
|
| - |
|
341 |
if(itemMap.get(itemId) == null){
|
| - |
|
342 |
sb.append("Item is not valid "+itemId+"\n");
|
| - |
|
343 |
}
|
| - |
|
344 |
}
|
| - |
|
345 |
if (sb.length()>0){
|
| - |
|
346 |
setResult("Please correct error \n"+sb.toString());
|
| - |
|
347 |
return "item-details-json";
|
| - |
|
348 |
}
|
| - |
|
349 |
}
|
| - |
|
350 |
|
| - |
|
351 |
for(Map.Entry<Long, Double> itemIdIgstTaxRateEntry : itemIdIgstTaxRate.entrySet()){
|
| - |
|
352 |
StateGstRate stateGstRate = new StateGstRate();
|
| - |
|
353 |
stateGstRate.setItemId(itemIdIgstTaxRateEntry.getKey());
|
| - |
|
354 |
stateGstRate.setStateId(-1);
|
| - |
|
355 |
stateGstRate.setIgstRate(itemIdIgstTaxRateEntry.getValue());
|
| - |
|
356 |
stateGstRate.setCgstRate(0);
|
| - |
|
357 |
stateGstRate.setSgstRate(0);
|
| - |
|
358 |
cc.persistStateGstRate(stateGstRate);
|
| - |
|
359 |
}
|
| - |
|
360 |
|
| - |
|
361 |
for(Map.Entry<ItemIdStateId, GstRate> itemIdStateIdStateRateEntry : itemIdStateIdStateRateMap.entrySet()){
|
| - |
|
362 |
StateGstRate stateGstRate = new StateGstRate();
|
| - |
|
363 |
stateGstRate.setItemId(itemIdStateIdStateRateEntry.getKey().getItemId());
|
| - |
|
364 |
stateGstRate.setStateId(itemIdStateIdStateRateEntry.getKey().getStateId());
|
| - |
|
365 |
stateGstRate.setIgstRate(0);
|
| - |
|
366 |
stateGstRate.setCgstRate(itemIdStateIdStateRateEntry.getValue().getCgstRate());
|
| - |
|
367 |
stateGstRate.setSgstRate(itemIdStateIdStateRateEntry.getValue().getSgstRate());
|
| - |
|
368 |
cc.persistStateGstRate(stateGstRate);
|
| - |
|
369 |
}
|
| - |
|
370 |
|
| - |
|
371 |
setResult("Sheet uploaded successfully");
|
| - |
|
372 |
return "item-details-json";
|
| - |
|
373 |
}
|
| 259 |
|
374 |
|
| 260 |
public String updateVirtualInventory() throws IOException, CatalogServiceException, TException, InventoryServiceException{
|
375 |
public String updateVirtualInventory() throws IOException, CatalogServiceException, TException, InventoryServiceException{
|
| 261 |
if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0])) {
|
376 |
if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0])) {
|
| 262 |
logger.info(request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0]);
|
377 |
logger.info(request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0]);
|
| 263 |
return "authfail";
|
378 |
return "authfail";
|