| 8488 |
amar.kumar |
1 |
package in.shop2020.support.controllers;
|
|
|
2 |
|
|
|
3 |
import java.io.File;
|
|
|
4 |
import java.io.FileInputStream;
|
|
|
5 |
import java.text.SimpleDateFormat;
|
|
|
6 |
import java.util.ArrayList;
|
|
|
7 |
import java.util.Calendar;
|
|
|
8 |
import java.util.Collection;
|
|
|
9 |
import java.util.Collections;
|
|
|
10 |
import java.util.Date;
|
|
|
11 |
import java.util.List;
|
|
|
12 |
|
|
|
13 |
import in.shop2020.logistics.DeliveryType;
|
|
|
14 |
import in.shop2020.logistics.LogisticsInfo;
|
|
|
15 |
import in.shop2020.logistics.LogisticsService;
|
|
|
16 |
import in.shop2020.logistics.PickUpType;
|
|
|
17 |
import in.shop2020.model.v1.catalog.CatalogService;
|
|
|
18 |
import in.shop2020.model.v1.catalog.CatalogServiceException;
|
|
|
19 |
import in.shop2020.model.v1.catalog.EbayItem;
|
|
|
20 |
import in.shop2020.model.v1.catalog.Item;
|
| 9456 |
vikram.rag |
21 |
import in.shop2020.model.v1.catalog.SnapdealItem;
|
| 8488 |
amar.kumar |
22 |
import in.shop2020.model.v1.inventory.InventoryService;
|
|
|
23 |
import in.shop2020.model.v1.inventory.InventoryServiceException;
|
| 8892 |
amar.kumar |
24 |
import in.shop2020.model.v1.inventory.InventoryType;
|
| 8488 |
amar.kumar |
25 |
import in.shop2020.model.v1.inventory.VendorItemPricing;
|
|
|
26 |
import in.shop2020.model.v1.inventory.Warehouse;
|
| 8892 |
amar.kumar |
27 |
import in.shop2020.model.v1.inventory.WarehouseType;
|
| 8488 |
amar.kumar |
28 |
import in.shop2020.model.v1.order.LineItem;
|
|
|
29 |
import in.shop2020.model.v1.order.Order;
|
|
|
30 |
import in.shop2020.model.v1.order.OrderSource;
|
|
|
31 |
import in.shop2020.model.v1.order.OrderStatus;
|
|
|
32 |
import in.shop2020.model.v1.order.OrderType;
|
|
|
33 |
import in.shop2020.model.v1.order.SnapdealOrder;
|
|
|
34 |
import in.shop2020.model.v1.order.SourceDetail;
|
|
|
35 |
import in.shop2020.model.v1.order.Transaction;
|
|
|
36 |
import in.shop2020.model.v1.order.TransactionStatus;
|
|
|
37 |
import in.shop2020.model.v1.order.TransactionService.Client;
|
|
|
38 |
import in.shop2020.model.v1.user.Address;
|
|
|
39 |
import in.shop2020.model.v1.user.User;
|
|
|
40 |
import in.shop2020.payments.Attribute;
|
|
|
41 |
import in.shop2020.payments.PaymentException;
|
|
|
42 |
import in.shop2020.payments.PaymentStatus;
|
|
|
43 |
import in.shop2020.thrift.clients.CatalogClient;
|
|
|
44 |
import in.shop2020.thrift.clients.InventoryClient;
|
|
|
45 |
import in.shop2020.thrift.clients.LogisticsClient;
|
|
|
46 |
import in.shop2020.thrift.clients.PaymentClient;
|
|
|
47 |
import in.shop2020.thrift.clients.TransactionClient;
|
|
|
48 |
import in.shop2020.thrift.clients.UserClient;
|
|
|
49 |
import in.shop2020.support.utils.ReportsUtils;
|
|
|
50 |
|
|
|
51 |
import javax.servlet.http.HttpServletRequest;
|
|
|
52 |
import javax.servlet.http.HttpSession;
|
|
|
53 |
|
|
|
54 |
import org.apache.commons.io.FileUtils;
|
|
|
55 |
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
|
56 |
import org.apache.poi.ss.usermodel.Cell;
|
|
|
57 |
import org.apache.poi.ss.usermodel.Row;
|
|
|
58 |
import org.apache.poi.ss.usermodel.Sheet;
|
|
|
59 |
import org.apache.poi.ss.usermodel.Workbook;
|
|
|
60 |
import org.apache.struts2.convention.annotation.InterceptorRef;
|
|
|
61 |
import org.apache.struts2.convention.annotation.InterceptorRefs;
|
|
|
62 |
import org.apache.struts2.convention.annotation.Result;
|
|
|
63 |
import org.apache.struts2.convention.annotation.Results;
|
|
|
64 |
import org.apache.struts2.interceptor.ServletRequestAware;
|
|
|
65 |
import org.apache.thrift.TException;
|
|
|
66 |
import org.slf4j.Logger;
|
|
|
67 |
import org.slf4j.LoggerFactory;
|
|
|
68 |
|
|
|
69 |
import com.opensymphony.xwork2.ActionSupport;
|
|
|
70 |
|
|
|
71 |
@SuppressWarnings("serial")
|
|
|
72 |
@InterceptorRefs({
|
|
|
73 |
@InterceptorRef("defaultStack"),
|
|
|
74 |
@InterceptorRef("login")
|
|
|
75 |
})
|
|
|
76 |
@Results({
|
|
|
77 |
@Result(name="authfail", type="redirectAction", params = {"actionName" , "reports"})
|
|
|
78 |
})
|
|
|
79 |
public class SnapdealOrderCreatorController extends ActionSupport implements ServletRequestAware {
|
|
|
80 |
|
|
|
81 |
private static Logger logger = LoggerFactory.getLogger(SnapdealOrderCreatorController.class);
|
|
|
82 |
|
|
|
83 |
private HttpServletRequest request;
|
|
|
84 |
private HttpSession session;
|
|
|
85 |
|
|
|
86 |
private static final int SNAPDEAL_SOURCE_ID = 7;
|
|
|
87 |
|
|
|
88 |
private static final int COURIER_INDEX = 0;
|
|
|
89 |
private static final int PRODUCT_NAME_INDEX = 1;
|
|
|
90 |
private static final int REFERENCE_CODE_INDEX = 2;
|
|
|
91 |
private static final int SUBORDER_ID_INDEX = 3;
|
|
|
92 |
private static final int ITEMID_INDEX = 4;
|
|
|
93 |
private static final int AWB_INDEX = 5;
|
|
|
94 |
private static final int TRANSACTION_DATE_INDEX = 6;
|
| 10870 |
vikram.rag |
95 |
private static final int BUYER_NAME_INDEX = 7;
|
|
|
96 |
private static final int CITY_INDEX = 8;
|
|
|
97 |
private static final int STATE_INDEX = 9;
|
|
|
98 |
private static final int PINCODE_INDEX = 10;
|
|
|
99 |
private static final int AMOUNT_INDEX = 11;
|
|
|
100 |
private static final int WAREHOUSE_ID_INDEX = 13;
|
|
|
101 |
private static final int OVERRIDE_BILLING_PRICE_INDEX = 14;
|
| 8488 |
amar.kumar |
102 |
|
|
|
103 |
|
|
|
104 |
private static final int SNAPDEAL_GATEWAY_ID = 18;
|
|
|
105 |
|
|
|
106 |
private static final String FIRSTFLIGHT = "First Flight";
|
| 9110 |
vikram.rag |
107 |
private static final String DELHIVERY = "DELHIVERY";
|
|
|
108 |
private static final String BLUEDART = "Bluedart";
|
|
|
109 |
private static final String CHHOTU = "CHHOTU";
|
|
|
110 |
private static final String LAST_MILE = "LAST_MILE";
|
|
|
111 |
private static final String ECOM = "Ecom Express";
|
|
|
112 |
private static final String EWINGS = "EWINGS";
|
|
|
113 |
private static final String DTDC = "DTDC";
|
| 9188 |
vikram.rag |
114 |
private static final String WAREOLOG = "Wareolog";
|
| 9110 |
vikram.rag |
115 |
private static final String MIRAKLE = "MIRAKLE";
|
|
|
116 |
private static final String RAJIV_TRANSPORT = "RAJIV_TRANSPORT";
|
|
|
117 |
private static final String BLUEDART_HIGH_VALUE = "BLUEDART_HIGH_VALUE";
|
|
|
118 |
private static final String BLUEDART_SURFACE = "BLUEDART_SURFACE";
|
| 9188 |
vikram.rag |
119 |
private static final String BLUEDART_APEX = "BLUEDART APEX";
|
| 9110 |
vikram.rag |
120 |
private static final String ARAMEX = "ARAMEX";
|
|
|
121 |
private static final String GATI = "GATI";
|
|
|
122 |
private static final String INDIA_POST = "INDIA_POST";
|
|
|
123 |
private static final String FEDEX = "FEDEX";
|
|
|
124 |
private static final String IOT = "IOT";
|
| 9147 |
vikram.rag |
125 |
private static final String RED_EXP = "Red Express";
|
| 9110 |
vikram.rag |
126 |
private static final String GHARPAY = "GHARPAY";
|
| 9127 |
vikram.rag |
127 |
private static final String QUANTIUM = "Quantium Solutions";
|
| 9119 |
vikram.rag |
128 |
private static final String GATI_AIR = "GATI AIR";
|
| 9110 |
vikram.rag |
129 |
private static final String VDELIVER = "VDELIVER";
|
| 9136 |
vikram.rag |
130 |
private static final String OVERNITE_EXP = "Overnite Express";
|
| 10236 |
vikram.rag |
131 |
private static final String BIBHA_CARGO = "BIBHA CARGO AND COURIER PVT LTD";
|
| 9110 |
vikram.rag |
132 |
|
| 8488 |
amar.kumar |
133 |
private File orderDataFile;
|
|
|
134 |
private String orderDataFileName;
|
|
|
135 |
private String transactionId;
|
|
|
136 |
private String errorMsg = "";
|
|
|
137 |
private Long rowId = 0L;
|
| 9150 |
vikram.rag |
138 |
|
|
|
139 |
private long paymentId;
|
| 8488 |
amar.kumar |
140 |
|
|
|
141 |
public String create() throws TException {
|
|
|
142 |
File fileToCreate = null;
|
|
|
143 |
orderDataFileName = "OrderSheet_Snapdeal_"+(new Date().toString());
|
|
|
144 |
try {
|
|
|
145 |
fileToCreate = new File("/tmp/", this.orderDataFileName);
|
|
|
146 |
FileUtils.copyFile(this.orderDataFile, fileToCreate);
|
|
|
147 |
} catch (Exception e) {
|
|
|
148 |
logger.error("Error while writing order data file to the local file system for Snapdeal", e);
|
|
|
149 |
addActionError("Error while writing order data file to the local file system");
|
|
|
150 |
}
|
|
|
151 |
|
|
|
152 |
|
|
|
153 |
if(checkForErrors())
|
|
|
154 |
return "authsuccess";
|
|
|
155 |
|
|
|
156 |
//Parse the file and submit the data for update to the transaction service
|
|
|
157 |
Workbook wb = null;
|
|
|
158 |
try {
|
|
|
159 |
wb = new HSSFWorkbook(new FileInputStream(fileToCreate));
|
|
|
160 |
} catch (Exception e) {
|
|
|
161 |
logger.error("Unable to open the File for Order Creation for Snapdeal ", e);
|
|
|
162 |
setErrorMsg(getErrorMsg() + "Error in opening File for Order creation");
|
|
|
163 |
addActionError("Unable to open the File for Order creation");
|
|
|
164 |
}
|
|
|
165 |
if(checkForErrors())
|
|
|
166 |
return "authsuccess";
|
|
|
167 |
|
|
|
168 |
SourceDetail sourceDetail = null;
|
|
|
169 |
User user = null;
|
|
|
170 |
TransactionClient tsc = null;
|
|
|
171 |
try {
|
|
|
172 |
tsc = new TransactionClient();
|
|
|
173 |
sourceDetail = tsc.getClient().getSourceDetail(SNAPDEAL_SOURCE_ID);
|
|
|
174 |
} catch (Exception e) {
|
|
|
175 |
logger.error("Unable to establish connection to the transaction service while getting Snapdeal Source Detail", e);
|
|
|
176 |
setErrorMsg(getErrorMsg() + "Error in Order Service while getting Snapdeal Source Detail");
|
|
|
177 |
addActionError("Error in connecting to Order Service");
|
|
|
178 |
}
|
|
|
179 |
|
|
|
180 |
if(checkForErrors())
|
|
|
181 |
return "authsuccess";
|
|
|
182 |
|
|
|
183 |
try {
|
|
|
184 |
in.shop2020.model.v1.user.UserContextService.Client userClient = new UserClient().getClient();
|
|
|
185 |
user = userClient.getUserByEmail(sourceDetail.getEmail());
|
|
|
186 |
} catch (Exception e) {
|
|
|
187 |
logger.error("Unable to establish connection to the User service", e);
|
|
|
188 |
setErrorMsg(getErrorMsg() + "Unable to get Default Email for Snapdeal ");
|
|
|
189 |
addActionError("Unable to get Default Email for Snapdeal ");
|
|
|
190 |
}
|
|
|
191 |
|
|
|
192 |
if(checkForErrors())
|
|
|
193 |
return "authsuccess";
|
|
|
194 |
|
|
|
195 |
Sheet sheet = wb.getSheetAt(0);
|
|
|
196 |
Row firstRow = sheet.getRow(0);
|
| 9456 |
vikram.rag |
197 |
SnapdealItem snapdealItem;
|
|
|
198 |
in.shop2020.model.v1.catalog.CatalogService.Client catalogClient;
|
| 8488 |
amar.kumar |
199 |
for (Row row : sheet) {
|
|
|
200 |
long orderCountForRow = 0;
|
|
|
201 |
rowId++;
|
|
|
202 |
if(row.equals(firstRow))
|
|
|
203 |
continue;
|
|
|
204 |
try {
|
|
|
205 |
Transaction txn = new Transaction();
|
|
|
206 |
txn.setShoppingCartid(user.getActiveCartId());
|
|
|
207 |
txn.setCustomer_id(user.getUserId());
|
|
|
208 |
txn.setCreatedOn(new Date().getTime());
|
|
|
209 |
txn.setTransactionStatus(TransactionStatus.INIT);
|
|
|
210 |
txn.setStatusDescription("Order for Snapdeal ");
|
|
|
211 |
|
|
|
212 |
List<Order> orders = new ArrayList<Order>();
|
|
|
213 |
|
|
|
214 |
row.getCell(ITEMID_INDEX).setCellType(Cell.CELL_TYPE_STRING);
|
| 10852 |
vikram.rag |
215 |
String sku = row.getCell(ITEMID_INDEX).getStringCellValue();
|
|
|
216 |
Long itemId;
|
| 8488 |
amar.kumar |
217 |
double listingPrice = 0;
|
|
|
218 |
double overriddenPrice = 0;
|
|
|
219 |
double totalPrice = 0;
|
|
|
220 |
Cell overriddenPriceCell = row.getCell(OVERRIDE_BILLING_PRICE_INDEX);
|
|
|
221 |
if(overriddenPriceCell != null && overriddenPriceCell .getCellType() != Cell.CELL_TYPE_BLANK) {
|
|
|
222 |
overriddenPrice = row.getCell(OVERRIDE_BILLING_PRICE_INDEX).getNumericCellValue();
|
|
|
223 |
}
|
|
|
224 |
|
|
|
225 |
totalPrice = row.getCell(AMOUNT_INDEX).getNumericCellValue();
|
|
|
226 |
listingPrice = totalPrice;
|
|
|
227 |
if(overriddenPrice>=1) {
|
|
|
228 |
totalPrice = overriddenPrice;
|
|
|
229 |
}
|
|
|
230 |
LineItem lineItem = null;
|
|
|
231 |
try {
|
| 10852 |
vikram.rag |
232 |
catalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
|
|
|
233 |
snapdealItem = catalogClient.getSnapdealItembySkuAtSnapdeal(sku);
|
|
|
234 |
itemId = snapdealItem.getItem_id();
|
|
|
235 |
if(itemId == 0){
|
|
|
236 |
logger.error("Mapping not present for " + rowId + " "+ sku);
|
|
|
237 |
logger.error("Unable to create order for RowId " + rowId);
|
|
|
238 |
continue;
|
|
|
239 |
}
|
| 8488 |
amar.kumar |
240 |
lineItem = createLineItem(itemId, totalPrice);
|
| 8569 |
amar.kumar |
241 |
Double subOrderId = row.getCell(SUBORDER_ID_INDEX).getNumericCellValue();
|
|
|
242 |
String refCode = row.getCell(REFERENCE_CODE_INDEX).getStringCellValue();
|
|
|
243 |
lineItem.setExtra_info("SubOrderId = " + subOrderId + " ReferenceCode = " + refCode);
|
| 8488 |
amar.kumar |
244 |
} catch (Exception tex) {
|
|
|
245 |
logger.error("Unable to create order for RowId " + rowId, tex);
|
|
|
246 |
setErrorMsg(getErrorMsg() + "<br>Unable to create lineitem using catalog info for RowId " + rowId);
|
|
|
247 |
continue;
|
|
|
248 |
}
|
|
|
249 |
Order t_order = new Order();
|
|
|
250 |
t_order.setCustomer_id(user.getUserId());
|
|
|
251 |
t_order.setCustomer_email(sourceDetail.getEmail());
|
|
|
252 |
row.getCell(BUYER_NAME_INDEX).setCellType(Cell.CELL_TYPE_STRING);
|
|
|
253 |
t_order.setCustomer_name(row.getCell(BUYER_NAME_INDEX).getStringCellValue());
|
| 9215 |
vikram.rag |
254 |
t_order.setCustomer_mobilenumber("+91-9999999999");
|
| 8488 |
amar.kumar |
255 |
t_order.setCustomer_address1("");
|
|
|
256 |
t_order.setCustomer_address2("");
|
|
|
257 |
t_order.setCustomer_city(row.getCell(CITY_INDEX).getStringCellValue());
|
| 10848 |
vikram.rag |
258 |
row.getCell(STATE_INDEX).setCellType(Cell.CELL_TYPE_STRING);
|
| 8488 |
amar.kumar |
259 |
t_order.setCustomer_state(row.getCell(STATE_INDEX).getStringCellValue());
|
|
|
260 |
row.getCell(PINCODE_INDEX).setCellType(Cell.CELL_TYPE_STRING);
|
|
|
261 |
t_order.setCustomer_pincode(row.getCell(PINCODE_INDEX).getStringCellValue());
|
| 10852 |
vikram.rag |
262 |
t_order.setTotal_amount(lineItem.getTotal_price());
|
| 8488 |
amar.kumar |
263 |
t_order.setTotal_weight(lineItem.getTotal_weight());
|
|
|
264 |
t_order.setLineitems(Collections.singletonList(lineItem));
|
| 8761 |
vikram.rag |
265 |
t_order.setStatus(OrderStatus.PAYMENT_PENDING);
|
| 8488 |
amar.kumar |
266 |
t_order.setStatusDescription("In Process");
|
|
|
267 |
t_order.setCreated_timestamp(new Date().getTime());
|
|
|
268 |
t_order.setOrderType(OrderType.B2C);
|
|
|
269 |
t_order.setCod(false);
|
|
|
270 |
try {
|
|
|
271 |
Calendar time = Calendar.getInstance();
|
|
|
272 |
time.add(Calendar.DAY_OF_MONTH, 1);
|
| 9288 |
vikram.rag |
273 |
if(time.get(Calendar.DAY_OF_WEEK)!=1){
|
|
|
274 |
t_order.setPromised_shipping_time(time.getTimeInMillis());
|
|
|
275 |
t_order.setExpected_shipping_time(time.getTimeInMillis());
|
|
|
276 |
}
|
|
|
277 |
else{
|
|
|
278 |
t_order.setPromised_shipping_time(time.getTimeInMillis()+24*60*60*1000);
|
|
|
279 |
t_order.setExpected_shipping_time(time.getTimeInMillis()+24*60*60*1000);
|
|
|
280 |
}
|
| 8488 |
amar.kumar |
281 |
time.add(Calendar.DAY_OF_MONTH, 3);
|
|
|
282 |
t_order.setPromised_delivery_time(time.getTimeInMillis());
|
|
|
283 |
t_order.setExpected_delivery_time(time.getTimeInMillis());
|
|
|
284 |
} catch(Exception e) {
|
|
|
285 |
addActionError("Error in updating Shipping or Delivery Time for row number " + rowId);
|
|
|
286 |
logger.error("Error in updating Shipping or Delivery Time for row number " + rowId,e);
|
|
|
287 |
continue;
|
|
|
288 |
}
|
|
|
289 |
|
|
|
290 |
InventoryService.Client inventoryClient = null;
|
|
|
291 |
Warehouse fulfillmentWarehouse= null;
|
|
|
292 |
try {
|
|
|
293 |
inventoryClient = new InventoryClient().getClient();
|
|
|
294 |
Cell warehouseCell = row.getCell(WAREHOUSE_ID_INDEX);
|
|
|
295 |
if(warehouseCell != null && warehouseCell.getCellType() != Cell.CELL_TYPE_BLANK) {
|
|
|
296 |
fulfillmentWarehouse = inventoryClient.getWarehouse(new Double(row.getCell(WAREHOUSE_ID_INDEX).getNumericCellValue()).longValue());
|
|
|
297 |
} else {
|
|
|
298 |
List<Long> itemAvailability = inventoryClient.getItemAvailabilityAtLocation(itemId, 1);
|
|
|
299 |
fulfillmentWarehouse = inventoryClient.getWarehouse(itemAvailability.get(0));
|
|
|
300 |
}
|
|
|
301 |
t_order.setFulfilmentWarehouseId(fulfillmentWarehouse.getId());
|
| 8892 |
amar.kumar |
302 |
|
|
|
303 |
long billingWarehouseId = 0;
|
|
|
304 |
if(fulfillmentWarehouse.getBillingWarehouseId()== 0) {
|
|
|
305 |
inventoryClient = new InventoryClient().getClient();
|
|
|
306 |
List<Warehouse> warehouses = inventoryClient.getWarehouses(WarehouseType.OURS, InventoryType.GOOD, fulfillmentWarehouse.getVendor().getId(), 0, 0);
|
|
|
307 |
for(Warehouse warehouse : warehouses) {
|
|
|
308 |
if(warehouse.getBillingWarehouseId()!=0) {
|
|
|
309 |
billingWarehouseId = warehouse.getBillingWarehouseId();
|
|
|
310 |
break;
|
|
|
311 |
}
|
|
|
312 |
}
|
|
|
313 |
} else {
|
|
|
314 |
billingWarehouseId = fulfillmentWarehouse.getBillingWarehouseId();
|
|
|
315 |
}
|
|
|
316 |
|
|
|
317 |
t_order.setWarehouse_id(billingWarehouseId);
|
|
|
318 |
//t_order.setWarehouse_id(fulfillmentWarehouse.getBillingWarehouseId());
|
| 8488 |
amar.kumar |
319 |
VendorItemPricing vendorItemPricing = inventoryClient.getItemPricing(lineItem.getItem_id(), fulfillmentWarehouse.getVendor().getId());
|
|
|
320 |
t_order.getLineitems().get(0).setTransfer_price(vendorItemPricing.getTransferPrice());
|
|
|
321 |
t_order.getLineitems().get(0).setNlc(vendorItemPricing.getNlc());
|
|
|
322 |
} catch (InventoryServiceException e) {
|
|
|
323 |
addActionError("Error in updating WarehouseId for row number " + rowId);
|
|
|
324 |
setErrorMsg(getErrorMsg() + "<br>Error in updating WarehouseId for row number " + rowId);
|
|
|
325 |
logger.error("Error in updating WarehouseId for row number " + rowId,e);
|
|
|
326 |
continue;
|
|
|
327 |
}
|
|
|
328 |
|
|
|
329 |
String provider = row.getCell(COURIER_INDEX).getStringCellValue();
|
| 9110 |
vikram.rag |
330 |
if(provider.equalsIgnoreCase(FIRSTFLIGHT)) {
|
| 8488 |
amar.kumar |
331 |
t_order.setLogistics_provider_id(12);
|
| 9110 |
vikram.rag |
332 |
} else if(provider.equalsIgnoreCase(DELHIVERY)) {
|
| 8488 |
amar.kumar |
333 |
t_order.setLogistics_provider_id(13);
|
| 9110 |
vikram.rag |
334 |
} else if(provider.equalsIgnoreCase(BLUEDART)) {
|
| 8508 |
amar.kumar |
335 |
t_order.setLogistics_provider_id(14);
|
| 9110 |
vikram.rag |
336 |
} else if(provider.equalsIgnoreCase(ECOM)) {
|
| 8796 |
anupam.sin |
337 |
t_order.setLogistics_provider_id(18);
|
| 9110 |
vikram.rag |
338 |
}else if(provider.equalsIgnoreCase(EWINGS)){
|
|
|
339 |
t_order.setLogistics_provider_id(19);
|
|
|
340 |
}
|
|
|
341 |
else if(provider.equalsIgnoreCase(DTDC)){
|
|
|
342 |
t_order.setLogistics_provider_id(20);
|
|
|
343 |
}
|
|
|
344 |
else if(provider.equalsIgnoreCase(WAREOLOG)){
|
|
|
345 |
t_order.setLogistics_provider_id(21);
|
|
|
346 |
}
|
|
|
347 |
else if(provider.equalsIgnoreCase(MIRAKLE)){
|
|
|
348 |
t_order.setLogistics_provider_id(22);
|
|
|
349 |
}
|
|
|
350 |
else if(provider.equalsIgnoreCase(RAJIV_TRANSPORT)){
|
|
|
351 |
t_order.setLogistics_provider_id(23);
|
|
|
352 |
}
|
|
|
353 |
else if(provider.equalsIgnoreCase(BLUEDART_HIGH_VALUE)){
|
|
|
354 |
t_order.setLogistics_provider_id(24);
|
|
|
355 |
}
|
|
|
356 |
else if(provider.equalsIgnoreCase(BLUEDART_SURFACE)){
|
|
|
357 |
t_order.setLogistics_provider_id(25);
|
|
|
358 |
}
|
|
|
359 |
else if(provider.equalsIgnoreCase(BLUEDART_APEX)){
|
|
|
360 |
t_order.setLogistics_provider_id(26);
|
|
|
361 |
}
|
|
|
362 |
else if(provider.equalsIgnoreCase(ARAMEX)){
|
|
|
363 |
t_order.setLogistics_provider_id(27);
|
|
|
364 |
}
|
|
|
365 |
else if(provider.equalsIgnoreCase(GATI)){
|
|
|
366 |
t_order.setLogistics_provider_id(28);
|
|
|
367 |
}
|
|
|
368 |
else if(provider.equalsIgnoreCase(INDIA_POST)){
|
|
|
369 |
t_order.setLogistics_provider_id(29);
|
|
|
370 |
}
|
|
|
371 |
else if(provider.equalsIgnoreCase(FEDEX)){
|
|
|
372 |
t_order.setLogistics_provider_id(30);
|
|
|
373 |
}
|
|
|
374 |
else if(provider.equalsIgnoreCase(IOT)){
|
|
|
375 |
t_order.setLogistics_provider_id(31);
|
|
|
376 |
}
|
|
|
377 |
else if(provider.equalsIgnoreCase(RED_EXP)){
|
|
|
378 |
t_order.setLogistics_provider_id(32);
|
|
|
379 |
}
|
|
|
380 |
else if(provider.equalsIgnoreCase(VDELIVER)){
|
|
|
381 |
t_order.setLogistics_provider_id(33);
|
|
|
382 |
}
|
|
|
383 |
else if(provider.equalsIgnoreCase(GHARPAY)){
|
|
|
384 |
t_order.setLogistics_provider_id(34);
|
|
|
385 |
}
|
|
|
386 |
else if(provider.equalsIgnoreCase(QUANTIUM)){
|
|
|
387 |
t_order.setLogistics_provider_id(35);
|
|
|
388 |
}
|
|
|
389 |
else if(provider.equalsIgnoreCase(GATI_AIR)){
|
|
|
390 |
t_order.setLogistics_provider_id(36);
|
| 9136 |
vikram.rag |
391 |
}
|
| 9138 |
vikram.rag |
392 |
else if(provider.equalsIgnoreCase(OVERNITE_EXP)){
|
| 9136 |
vikram.rag |
393 |
t_order.setLogistics_provider_id(37);
|
|
|
394 |
}
|
| 10236 |
vikram.rag |
395 |
else if(provider.equalsIgnoreCase(BIBHA_CARGO)){
|
|
|
396 |
t_order.setLogistics_provider_id(38);
|
|
|
397 |
}
|
| 9136 |
vikram.rag |
398 |
else {
|
| 12815 |
manish.sha |
399 |
t_order.setLogistics_provider_id(44);
|
| 8488 |
amar.kumar |
400 |
}
|
|
|
401 |
|
|
|
402 |
row.getCell(AWB_INDEX).setCellType(Cell.CELL_TYPE_STRING);
|
|
|
403 |
t_order.setAirwaybill_no(row.getCell(AWB_INDEX).getStringCellValue());
|
|
|
404 |
t_order.setTracking_id(row.getCell(AWB_INDEX).getStringCellValue());
|
|
|
405 |
t_order.setTotal_amount(totalPrice);
|
|
|
406 |
t_order.setOrderType(OrderType.B2C);
|
|
|
407 |
t_order.setSource(SNAPDEAL_SOURCE_ID);
|
|
|
408 |
t_order.setOrderType(OrderType.B2C);
|
|
|
409 |
orders.add(t_order);
|
|
|
410 |
orderCountForRow++;
|
|
|
411 |
|
|
|
412 |
txn.setOrders(orders);
|
|
|
413 |
Client transaction_client = new TransactionClient().getClient();
|
|
|
414 |
try {
|
| 9819 |
vikram.rag |
415 |
row.getCell(SUBORDER_ID_INDEX).setCellType(Cell.CELL_TYPE_STRING);
|
|
|
416 |
long subOrderId = Long.parseLong(row.getCell(SUBORDER_ID_INDEX).getStringCellValue());
|
| 8488 |
amar.kumar |
417 |
String referenceCode = row.getCell(REFERENCE_CODE_INDEX).getStringCellValue();
|
|
|
418 |
String productName = row.getCell(PRODUCT_NAME_INDEX).getStringCellValue();
|
|
|
419 |
Date snapdealTxnDate = row.getCell(TRANSACTION_DATE_INDEX).getDateCellValue();
|
|
|
420 |
|
| 9818 |
vikram.rag |
421 |
if(transaction_client.snapdealOrderExists(String.valueOf(subOrderId), referenceCode)) {
|
| 8488 |
amar.kumar |
422 |
setErrorMsg(getErrorMsg() + "<br>Duplicate order for subOrderId " + subOrderId + " for row number " + rowId);
|
|
|
423 |
logger.error("Duplicate order for subOrderId " + subOrderId + " for row number " + rowId);
|
|
|
424 |
continue;
|
|
|
425 |
}
|
|
|
426 |
|
|
|
427 |
transactionId = String.valueOf(transaction_client.createTransaction(txn));
|
| 9150 |
vikram.rag |
428 |
paymentId = createPayment(user, (new Long(subOrderId)).toString(), totalPrice);
|
| 8488 |
amar.kumar |
429 |
|
|
|
430 |
logger.info("Successfully created transaction: " + transactionId + " for amount: " + totalPrice);
|
|
|
431 |
|
|
|
432 |
Transaction transaction = transaction_client.getTransaction(Long.parseLong(transactionId));
|
|
|
433 |
Order order = transaction.getOrders().get(0);
|
|
|
434 |
|
|
|
435 |
inventoryClient.reserveItemInWarehouse(itemId, fulfillmentWarehouse.getId(), 1,
|
|
|
436 |
order.getId(), order.getCreated_timestamp(), order.getPromised_shipping_time(), order.getLineitems().get(0).getQuantity());
|
|
|
437 |
|
|
|
438 |
|
|
|
439 |
SnapdealOrder snapdealOrder = new SnapdealOrder();
|
|
|
440 |
snapdealOrder.setOrderId(order.getId());
|
| 9818 |
vikram.rag |
441 |
snapdealOrder.setSubOrderId(String.valueOf(subOrderId));
|
| 8488 |
amar.kumar |
442 |
snapdealOrder.setReferenceCode(referenceCode);
|
|
|
443 |
snapdealOrder.setProductName(productName);
|
|
|
444 |
snapdealOrder.setSnapdealTxnDate(snapdealTxnDate.getTime());
|
|
|
445 |
snapdealOrder.setListingPrice(listingPrice);
|
| 9456 |
vikram.rag |
446 |
snapdealOrder.setMaxNlc(snapdealItem.getMaxNlc());
|
| 8488 |
amar.kumar |
447 |
transaction_client.createSnapdealOrder(snapdealOrder);
|
| 9818 |
vikram.rag |
448 |
new PaymentClient().getClient().updatePaymentDetails(paymentId, null, null, null, null, null, null, Long.toString(subOrderId), null, PaymentStatus.SUCCESS, null, null);
|
| 8488 |
amar.kumar |
449 |
|
|
|
450 |
} catch (Exception e) {
|
|
|
451 |
logger.error("Error while creating order for rowId " + rowId, e);
|
|
|
452 |
addActionError("Error while creating order for rowId " + rowId);
|
|
|
453 |
setErrorMsg(getErrorMsg() + "<br>Error while creating order for row number " + rowId);
|
|
|
454 |
continue;
|
|
|
455 |
}
|
|
|
456 |
} catch (Exception e) {
|
| 8748 |
amar.kumar |
457 |
logger.error("Error while creating order for row number " + rowId, e);
|
| 8488 |
amar.kumar |
458 |
setErrorMsg(getErrorMsg() + "<br>Error while creating order for row number " + rowId);
|
|
|
459 |
continue;
|
|
|
460 |
}
|
|
|
461 |
}
|
|
|
462 |
|
|
|
463 |
checkForErrors();
|
|
|
464 |
return "authsuccess";
|
|
|
465 |
}
|
|
|
466 |
|
|
|
467 |
private Date interchangeDateAndMonth(Date date) {
|
|
|
468 |
Date updatedDate = new Date(date.getTime());
|
|
|
469 |
updatedDate.setDate(date.getMonth() + 1);
|
|
|
470 |
updatedDate.setMonth(date.getDate() - 1);
|
|
|
471 |
return updatedDate;
|
|
|
472 |
}
|
|
|
473 |
|
|
|
474 |
private LineItem createLineItem(long itemId, double amount) throws CatalogServiceException, TException {
|
|
|
475 |
LineItem lineItem = new LineItem();
|
|
|
476 |
CatalogService.Client catalogClient = new CatalogClient().getClient();
|
|
|
477 |
Item item = catalogClient.getItem(itemId);
|
|
|
478 |
|
|
|
479 |
lineItem.setProductGroup(item.getProductGroup());
|
|
|
480 |
lineItem.setBrand(item.getBrand());
|
|
|
481 |
lineItem.setModel_number(item.getModelNumber());
|
|
|
482 |
lineItem.setModel_name(item.getModelName());
|
|
|
483 |
lineItem.setExtra_info(item.getFeatureDescription());
|
|
|
484 |
lineItem.setQuantity(1);
|
|
|
485 |
lineItem.setItem_id(item.getId());
|
|
|
486 |
lineItem.setUnit_weight(item.getWeight());
|
|
|
487 |
lineItem.setTotal_weight(item.getWeight());
|
|
|
488 |
lineItem.setUnit_price(amount);
|
|
|
489 |
lineItem.setTotal_price(amount);
|
|
|
490 |
|
|
|
491 |
if (item.getColor() == null || "NA".equals(item.getColor())) {
|
|
|
492 |
lineItem.setColor("");
|
|
|
493 |
} else {
|
|
|
494 |
lineItem.setColor(item.getColor());
|
|
|
495 |
}
|
|
|
496 |
return lineItem;
|
|
|
497 |
}
|
|
|
498 |
|
| 9150 |
vikram.rag |
499 |
private long createPayment(User user, String subOrderId, double amount) throws NumberFormatException, PaymentException, TException {
|
| 8488 |
amar.kumar |
500 |
in.shop2020.payments.PaymentService.Client client = new PaymentClient().getClient();
|
| 9150 |
vikram.rag |
501 |
return client.createPayment(user.getUserId(), amount, SNAPDEAL_GATEWAY_ID, Long.valueOf(transactionId), false);
|
| 8488 |
amar.kumar |
502 |
}
|
|
|
503 |
|
|
|
504 |
public String index() {
|
|
|
505 |
if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), "/ebay-dashboard"))
|
|
|
506 |
return "authfail";
|
|
|
507 |
checkForErrors();
|
|
|
508 |
return "authsuccess";
|
|
|
509 |
}
|
|
|
510 |
|
|
|
511 |
private boolean checkForErrors(){
|
|
|
512 |
Collection<String> actionErrors = getActionErrors();
|
|
|
513 |
if(actionErrors != null && !actionErrors.isEmpty()){
|
|
|
514 |
for (String str : actionErrors) {
|
|
|
515 |
errorMsg += "<BR/>" + str;
|
|
|
516 |
}
|
|
|
517 |
return true;
|
|
|
518 |
}
|
|
|
519 |
return false;
|
|
|
520 |
}
|
|
|
521 |
|
|
|
522 |
@Override
|
|
|
523 |
public void setServletRequest(HttpServletRequest request) {
|
|
|
524 |
this.request = request;
|
|
|
525 |
this.session = request.getSession();
|
|
|
526 |
}
|
|
|
527 |
|
|
|
528 |
public String getErrorMsg() {
|
|
|
529 |
return errorMsg;
|
|
|
530 |
}
|
|
|
531 |
|
|
|
532 |
public void setErrorMsg(String errorMsg) {
|
|
|
533 |
this.errorMsg = errorMsg;
|
|
|
534 |
}
|
|
|
535 |
|
|
|
536 |
public Long getRowId() {
|
|
|
537 |
return rowId;
|
|
|
538 |
}
|
|
|
539 |
|
|
|
540 |
public void setRowId(Long rowId) {
|
|
|
541 |
this.rowId = rowId;
|
|
|
542 |
}
|
|
|
543 |
|
|
|
544 |
public File getOrderDataFile() {
|
|
|
545 |
return orderDataFile;
|
|
|
546 |
}
|
|
|
547 |
|
|
|
548 |
public void setOrderDataFile(File orderDataFile) {
|
|
|
549 |
this.orderDataFile = orderDataFile;
|
|
|
550 |
}
|
|
|
551 |
|
|
|
552 |
}
|