| 8182 |
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;
|
|
|
21 |
import in.shop2020.model.v1.inventory.InventoryService;
|
|
|
22 |
import in.shop2020.model.v1.inventory.InventoryServiceException;
|
| 8892 |
amar.kumar |
23 |
import in.shop2020.model.v1.inventory.InventoryType;
|
| 8291 |
amar.kumar |
24 |
import in.shop2020.model.v1.inventory.VendorItemPricing;
|
| 8182 |
amar.kumar |
25 |
import in.shop2020.model.v1.inventory.Warehouse;
|
| 8892 |
amar.kumar |
26 |
import in.shop2020.model.v1.inventory.WarehouseType;
|
| 8182 |
amar.kumar |
27 |
import in.shop2020.model.v1.order.EbayOrder;
|
|
|
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.SourceDetail;
|
|
|
34 |
import in.shop2020.model.v1.order.Transaction;
|
|
|
35 |
import in.shop2020.model.v1.order.TransactionStatus;
|
|
|
36 |
import in.shop2020.model.v1.order.TransactionService.Client;
|
|
|
37 |
import in.shop2020.model.v1.user.Address;
|
|
|
38 |
import in.shop2020.model.v1.user.User;
|
|
|
39 |
import in.shop2020.payments.Attribute;
|
|
|
40 |
import in.shop2020.payments.PaymentException;
|
|
|
41 |
import in.shop2020.payments.PaymentStatus;
|
|
|
42 |
import in.shop2020.thrift.clients.CatalogClient;
|
|
|
43 |
import in.shop2020.thrift.clients.InventoryClient;
|
|
|
44 |
import in.shop2020.thrift.clients.LogisticsClient;
|
|
|
45 |
import in.shop2020.thrift.clients.PaymentClient;
|
|
|
46 |
import in.shop2020.thrift.clients.TransactionClient;
|
|
|
47 |
import in.shop2020.thrift.clients.UserClient;
|
|
|
48 |
import in.shop2020.support.utils.ReportsUtils;
|
|
|
49 |
|
|
|
50 |
import javax.servlet.http.HttpServletRequest;
|
|
|
51 |
import javax.servlet.http.HttpSession;
|
|
|
52 |
|
|
|
53 |
import org.apache.commons.io.FileUtils;
|
|
|
54 |
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
|
55 |
import org.apache.poi.ss.usermodel.Cell;
|
|
|
56 |
import org.apache.poi.ss.usermodel.Row;
|
|
|
57 |
import org.apache.poi.ss.usermodel.Sheet;
|
|
|
58 |
import org.apache.poi.ss.usermodel.Workbook;
|
|
|
59 |
import org.apache.struts2.convention.annotation.InterceptorRef;
|
|
|
60 |
import org.apache.struts2.convention.annotation.InterceptorRefs;
|
|
|
61 |
import org.apache.struts2.convention.annotation.Result;
|
|
|
62 |
import org.apache.struts2.convention.annotation.Results;
|
|
|
63 |
import org.apache.struts2.interceptor.ServletRequestAware;
|
|
|
64 |
import org.apache.thrift.TException;
|
|
|
65 |
import org.slf4j.Logger;
|
|
|
66 |
import org.slf4j.LoggerFactory;
|
|
|
67 |
|
|
|
68 |
import com.opensymphony.xwork2.ActionSupport;
|
|
|
69 |
|
|
|
70 |
@SuppressWarnings("serial")
|
|
|
71 |
@InterceptorRefs({
|
|
|
72 |
@InterceptorRef("defaultStack"),
|
|
|
73 |
@InterceptorRef("login")
|
|
|
74 |
})
|
|
|
75 |
@Results({
|
|
|
76 |
@Result(name="authfail", type="redirectAction", params = {"actionName" , "reports"})
|
|
|
77 |
})
|
|
|
78 |
public class EbayNormalOrderCreatorController extends ActionSupport implements ServletRequestAware {
|
|
|
79 |
|
|
|
80 |
private static Logger logger = LoggerFactory.getLogger(EbayNormalOrderCreatorController.class);
|
|
|
81 |
|
|
|
82 |
private HttpServletRequest request;
|
|
|
83 |
private HttpSession session;
|
|
|
84 |
|
|
|
85 |
private static final int EBAY_SOURCE_ID = 6;
|
|
|
86 |
|
|
|
87 |
private static final int SALES_RECORD_NUM_INDEX = 0;
|
|
|
88 |
private static final int BUYER_NAME_INDEX = 2;
|
|
|
89 |
private static final int CUST_MOBILE_INDEX = 3;
|
|
|
90 |
private static final int EMAIL_INDEX = 4;
|
|
|
91 |
private static final int ADDR1_INDEX = 5;
|
|
|
92 |
private static final int ADDR2_INDEX = 6;
|
|
|
93 |
private static final int CITY_INDEX = 7;
|
|
|
94 |
private static final int STATE_INDEX = 8;
|
|
|
95 |
private static final int PINCODE_INDEX = 9;
|
|
|
96 |
private static final int EBAY_LISTINGID_INDEX = 11;
|
|
|
97 |
private static final int QUANTITY_INDEX = 14;
|
|
|
98 |
private static final int AMOUNT_INDEX = 15;
|
|
|
99 |
private static final int TRANSACTION_DATE_INDEX = 21;
|
|
|
100 |
private static final int PAISAPAY_ID_INDEX = 28;
|
|
|
101 |
private static final int TRANSACTION_ID_INDEX = 31;
|
|
|
102 |
|
|
|
103 |
private static final int SHIP_DATE_INDEX = 24;
|
|
|
104 |
private static final int WAREHOUSE_ID_INDEX = 34;
|
| 8488 |
amar.kumar |
105 |
private static final int OVERRIDE_BILLING_PRICE_INDEX = 35;
|
| 8182 |
amar.kumar |
106 |
|
| 8196 |
amar.kumar |
107 |
private static final int EBAY_GATEWAY_ID = 16;
|
| 8182 |
amar.kumar |
108 |
|
|
|
109 |
private SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yy");
|
|
|
110 |
private SimpleDateFormat sdf2 = new SimpleDateFormat("dd-MMM-yyyy");
|
|
|
111 |
|
|
|
112 |
private File orderDataFile;
|
|
|
113 |
private String orderDataFileName;
|
|
|
114 |
private String transactionId;
|
|
|
115 |
private String errorMsg = "";
|
|
|
116 |
private Long rowId = 0L;
|
|
|
117 |
|
|
|
118 |
public String create() throws TException {
|
|
|
119 |
File fileToCreate = null;
|
|
|
120 |
orderDataFileName = "OrderSheet_"+EBAY_SOURCE_ID+"_"+(new Date().toString());
|
|
|
121 |
try {
|
|
|
122 |
fileToCreate = new File("/tmp/", this.orderDataFileName);
|
|
|
123 |
FileUtils.copyFile(this.orderDataFile, fileToCreate);
|
|
|
124 |
} catch (Exception e) {
|
|
|
125 |
logger.error("Error while writing order data file to the local file system for Ebay", e);
|
|
|
126 |
addActionError("Error while writing order data file to the local file system");
|
|
|
127 |
}
|
|
|
128 |
|
|
|
129 |
|
|
|
130 |
if(checkForErrors())
|
|
|
131 |
return "authsuccess";
|
|
|
132 |
|
|
|
133 |
//Parse the file and submit the data for update to the transaction service
|
|
|
134 |
Workbook wb = null;
|
|
|
135 |
try {
|
|
|
136 |
wb = new HSSFWorkbook(new FileInputStream(fileToCreate));
|
|
|
137 |
} catch (Exception e) {
|
|
|
138 |
logger.error("Unable to open the File for Order Creation for Ebay ", e);
|
|
|
139 |
addActionError("Unable to open the File for Order creation");
|
|
|
140 |
}
|
|
|
141 |
if(checkForErrors())
|
|
|
142 |
return "authsuccess";
|
|
|
143 |
|
|
|
144 |
SourceDetail sourceDetail = null;
|
|
|
145 |
User user = null;
|
|
|
146 |
TransactionClient tsc = null;
|
|
|
147 |
try {
|
|
|
148 |
tsc = new TransactionClient();
|
|
|
149 |
sourceDetail = tsc.getClient().getSourceDetail(EBAY_SOURCE_ID);
|
|
|
150 |
} catch (Exception e) {
|
|
|
151 |
logger.error("Unable to establish connection to the transaction service", e);
|
|
|
152 |
addActionError("Unable to establish connection to the transaction service");
|
|
|
153 |
}
|
|
|
154 |
|
|
|
155 |
if(checkForErrors())
|
|
|
156 |
return "authsuccess";
|
|
|
157 |
|
|
|
158 |
in.shop2020.model.v1.user.UserContextService.Client userClient = null;
|
|
|
159 |
try {
|
|
|
160 |
userClient = new UserClient().getClient();
|
|
|
161 |
} catch (Exception e) {
|
|
|
162 |
logger.error("Unable to establish connection to the User service", e);
|
|
|
163 |
addActionError("Unable to establish connection to the User service");
|
|
|
164 |
}
|
|
|
165 |
|
|
|
166 |
if(checkForErrors())
|
|
|
167 |
return "authsuccess";
|
|
|
168 |
|
|
|
169 |
Sheet sheet = wb.getSheetAt(0);
|
|
|
170 |
Row firstRow = sheet.getRow(0);
|
|
|
171 |
logger.info("Last row number is:" + sheet.getLastRowNum());
|
|
|
172 |
for (Row row : sheet) {
|
| 8656 |
amar.kumar |
173 |
rowId++;
|
| 8182 |
amar.kumar |
174 |
long orderCountForRow = 0;
|
|
|
175 |
if(row.equals(firstRow))
|
|
|
176 |
continue;
|
| 8656 |
amar.kumar |
177 |
|
| 8182 |
amar.kumar |
178 |
try {
|
|
|
179 |
//TODO Get this user from a different method
|
|
|
180 |
if (userClient.userExists(row.getCell(EMAIL_INDEX).getStringCellValue())) {
|
|
|
181 |
user = userClient.getUserByEmail(row.getCell(EMAIL_INDEX).getStringCellValue());
|
|
|
182 |
} else {
|
|
|
183 |
user = new User();
|
|
|
184 |
user.setName(row.getCell(BUYER_NAME_INDEX).getStringCellValue());
|
|
|
185 |
user.setEmail(row.getCell(EMAIL_INDEX).getStringCellValue());
|
| 8723 |
amar.kumar |
186 |
user.setSourceId(EBAY_SOURCE_ID);
|
| 8182 |
amar.kumar |
187 |
//TODO set mobileNumber for customer
|
|
|
188 |
//TODO set password for user;
|
|
|
189 |
user.setIsAnonymous(false);
|
|
|
190 |
user = userClient.createUser(user);
|
|
|
191 |
}
|
|
|
192 |
} catch(Exception e) {
|
|
|
193 |
logger.error("Unable to establish connection to the User service for row number " + (rowId + 1), e);
|
| 8925 |
amar.kumar |
194 |
addActionError("Unable to establish connection to the User service for row number " + (rowId + 1));
|
| 8182 |
amar.kumar |
195 |
return "authsuccess";
|
|
|
196 |
}
|
|
|
197 |
Transaction txn = new Transaction();
|
|
|
198 |
txn.setShoppingCartid(user.getActiveCartId());
|
|
|
199 |
txn.setCustomer_id(user.getUserId());
|
|
|
200 |
txn.setCreatedOn(new Date().getTime());
|
|
|
201 |
txn.setTransactionStatus(TransactionStatus.INIT);
|
|
|
202 |
txn.setStatusDescription("Order for Ebay ");
|
|
|
203 |
|
|
|
204 |
List<Order> orders = new ArrayList<Order>();
|
|
|
205 |
|
| 8241 |
amar.kumar |
206 |
double listingPrice = 0;
|
|
|
207 |
double overriddenPrice = 0;
|
|
|
208 |
double totalPrice = 0;
|
|
|
209 |
|
| 8182 |
amar.kumar |
210 |
row.getCell(EBAY_LISTINGID_INDEX).setCellType(Cell.CELL_TYPE_STRING);
|
|
|
211 |
String ebayListingId = row.getCell(EBAY_LISTINGID_INDEX).getStringCellValue();
|
|
|
212 |
CatalogService.Client catalogClient = new CatalogClient().getClient();
|
|
|
213 |
EbayItem ebayItem = catalogClient.getEbayItem(ebayListingId);
|
|
|
214 |
long quantity = new Double(row.getCell(QUANTITY_INDEX).getNumericCellValue()).longValue();
|
| 8488 |
amar.kumar |
215 |
Cell overriddenPriceCell = row.getCell(OVERRIDE_BILLING_PRICE_INDEX);
|
| 8241 |
amar.kumar |
216 |
if(overriddenPriceCell != null && overriddenPriceCell .getCellType() != Cell.CELL_TYPE_BLANK) {
|
| 8488 |
amar.kumar |
217 |
overriddenPrice = row.getCell(OVERRIDE_BILLING_PRICE_INDEX).getNumericCellValue();
|
| 8241 |
amar.kumar |
218 |
}
|
| 8182 |
amar.kumar |
219 |
String totalPriceString = row.getCell(AMOUNT_INDEX).getStringCellValue();
|
| 8241 |
amar.kumar |
220 |
if(overriddenPrice>=1) {
|
|
|
221 |
totalPrice = overriddenPrice*quantity;
|
|
|
222 |
listingPrice = (Double.parseDouble(totalPriceString.substring(3).replace(",","")))/quantity;
|
|
|
223 |
} else {
|
|
|
224 |
totalPrice = Double.parseDouble(totalPriceString.substring(3).replace(",",""));
|
|
|
225 |
listingPrice = totalPrice/quantity;
|
|
|
226 |
}
|
| 8182 |
amar.kumar |
227 |
LineItem lineItem = null;
|
|
|
228 |
try {
|
|
|
229 |
lineItem = createLineItem(ebayItem.getItemId(), quantity, totalPrice);
|
| 8656 |
amar.kumar |
230 |
Double salesRecordNumber = row.getCell(SALES_RECORD_NUM_INDEX).getNumericCellValue();
|
|
|
231 |
row.getCell(PAISAPAY_ID_INDEX).setCellType(Cell.CELL_TYPE_STRING);
|
|
|
232 |
String paisaPayId = row.getCell(PAISAPAY_ID_INDEX).getStringCellValue();
|
|
|
233 |
lineItem.setExtra_info("PaisaPayId = " + paisaPayId + " SalesRecordNumber = " + salesRecordNumber);
|
| 8182 |
amar.kumar |
234 |
} catch (Exception tex) {
|
|
|
235 |
logger.error("Unable to establish connection to the Catalog service", tex);
|
|
|
236 |
addActionError("Unable to establish connection to the Catalog service");
|
|
|
237 |
return "authsuccess";
|
|
|
238 |
}
|
|
|
239 |
Order order = new Order();
|
|
|
240 |
order.setCustomer_id(user.getUserId());
|
|
|
241 |
order.setCustomer_email(user.getEmail());
|
|
|
242 |
order.setCustomer_name(user.getName());
|
|
|
243 |
try {
|
|
|
244 |
order.setCustomer_mobilenumber(new Double(row.getCell(CUST_MOBILE_INDEX).getNumericCellValue()).toString());
|
|
|
245 |
} catch (Exception e) {
|
|
|
246 |
addActionError("Error in reading mobile Number for rowNumber " + row.getRowNum());
|
|
|
247 |
logger.error("Error in reading mobile Number for rowNumber " + row.getRowNum());
|
|
|
248 |
}
|
|
|
249 |
order.setCustomer_address1(row.getCell(ADDR1_INDEX).getStringCellValue());
|
| 8569 |
amar.kumar |
250 |
Cell address2Cell = row.getCell(ADDR2_INDEX);
|
|
|
251 |
if(address2Cell != null && address2Cell.getCellType() != Cell.CELL_TYPE_BLANK) {
|
|
|
252 |
order.setCustomer_address2(row.getCell(ADDR2_INDEX).getStringCellValue());
|
|
|
253 |
}
|
|
|
254 |
// order.setCustomer_address2(row.getCell(ADDR2_INDEX).getStringCellValue());
|
| 8182 |
amar.kumar |
255 |
order.setCustomer_city(row.getCell(CITY_INDEX).getStringCellValue());
|
|
|
256 |
order.setCustomer_state(row.getCell(STATE_INDEX).getStringCellValue());
|
|
|
257 |
row.getCell(PINCODE_INDEX).setCellType(Cell.CELL_TYPE_STRING);
|
|
|
258 |
order.setCustomer_pincode(row.getCell(PINCODE_INDEX).getStringCellValue());
|
|
|
259 |
order.setTotal_amount(totalPrice);
|
|
|
260 |
order.setTotal_weight(lineItem.getTotal_weight());
|
|
|
261 |
order.setLineitems(Collections.singletonList(lineItem));
|
|
|
262 |
order.setStatus(OrderStatus.SUBMITTED_FOR_PROCESSING);
|
|
|
263 |
order.setStatusDescription("In Process");
|
|
|
264 |
order.setCreated_timestamp(new Date().getTime());
|
| 8303 |
amar.kumar |
265 |
order.setCod(false);
|
| 8182 |
amar.kumar |
266 |
try {
|
| 8925 |
amar.kumar |
267 |
//Date shippingDate = interchangeDateAndMonth(row.getCell(SHIP_DATE_INDEX).getDateCellValue());
|
|
|
268 |
Date shippingDate = row.getCell(SHIP_DATE_INDEX).getDateCellValue();
|
| 8281 |
amar.kumar |
269 |
order.setPromised_shipping_time(shippingDate.getTime());
|
|
|
270 |
order.setExpected_shipping_time(shippingDate.getTime());
|
| 8254 |
amar.kumar |
271 |
//order.setPromised_shipping_time(sdf.parse(row.getCell(SHIP_DATE_INDEX).getStringCellValue()).getTime());
|
|
|
272 |
//order.setExpected_shipping_time(sdf.parse(row.getCell(SHIP_DATE_INDEX).getStringCellValue()).getTime());
|
| 8182 |
amar.kumar |
273 |
Calendar time = Calendar.getInstance();
|
|
|
274 |
time.setTimeInMillis(order.getExpected_shipping_time());
|
|
|
275 |
time.add(Calendar.DAY_OF_MONTH, 3);
|
|
|
276 |
order.setPromised_delivery_time(time.getTimeInMillis());
|
|
|
277 |
order.setExpected_delivery_time(time.getTimeInMillis());
|
|
|
278 |
} catch(Exception e) {
|
| 8254 |
amar.kumar |
279 |
addActionError("Error in updating Shipping Time for row number " + (rowId + 1));
|
| 8182 |
amar.kumar |
280 |
logger.error("Error in updating Shipping Time for row number " + (rowId + 1),e);
|
| 8343 |
amar.kumar |
281 |
continue;
|
| 8182 |
amar.kumar |
282 |
}
|
|
|
283 |
|
|
|
284 |
//TODO Delivery time
|
|
|
285 |
InventoryService.Client inventoryClient = null;
|
|
|
286 |
Warehouse fulfillmentWarehouse= null;
|
|
|
287 |
try {
|
|
|
288 |
inventoryClient = new InventoryClient().getClient();
|
|
|
289 |
Cell warehouseCell = row.getCell(WAREHOUSE_ID_INDEX);
|
|
|
290 |
if(warehouseCell != null && warehouseCell.getCellType() != Cell.CELL_TYPE_BLANK) {
|
|
|
291 |
fulfillmentWarehouse = inventoryClient.getWarehouse(new Double(row.getCell(WAREHOUSE_ID_INDEX).getNumericCellValue()).longValue());
|
|
|
292 |
|
|
|
293 |
} else if (ebayItem.getDefaultWarehouseId()!=0 ){
|
|
|
294 |
fulfillmentWarehouse = inventoryClient.getWarehouse(ebayItem.getDefaultWarehouseId());
|
|
|
295 |
} else {
|
|
|
296 |
List<Long> itemAvailability = inventoryClient.getItemAvailabilityAtLocation(ebayItem.getItemId(), 1);
|
|
|
297 |
fulfillmentWarehouse = inventoryClient.getWarehouse(itemAvailability.get(0));
|
|
|
298 |
}
|
|
|
299 |
order.setFulfilmentWarehouseId(fulfillmentWarehouse.getId());
|
| 8892 |
amar.kumar |
300 |
|
|
|
301 |
long billingWarehouseId = 0;
|
|
|
302 |
if(fulfillmentWarehouse.getBillingWarehouseId()== 0) {
|
|
|
303 |
inventoryClient = new InventoryClient().getClient();
|
|
|
304 |
List<Warehouse> warehouses = inventoryClient.getWarehouses(WarehouseType.OURS, InventoryType.GOOD, fulfillmentWarehouse.getVendor().getId(), 0, 0);
|
|
|
305 |
for(Warehouse warehouse : warehouses) {
|
|
|
306 |
if(warehouse.getBillingWarehouseId()!=0) {
|
|
|
307 |
billingWarehouseId = warehouse.getBillingWarehouseId();
|
|
|
308 |
break;
|
|
|
309 |
}
|
|
|
310 |
}
|
|
|
311 |
}else {
|
|
|
312 |
billingWarehouseId = fulfillmentWarehouse.getBillingWarehouseId();
|
|
|
313 |
}
|
|
|
314 |
|
|
|
315 |
order.setWarehouse_id(billingWarehouseId);
|
|
|
316 |
//order.setWarehouse_id(fulfillmentWarehouse.getBillingWarehouseId());
|
| 8291 |
amar.kumar |
317 |
VendorItemPricing vendorItemPricing = inventoryClient.getItemPricing(lineItem.getItem_id(), fulfillmentWarehouse.getVendor().getId());
|
|
|
318 |
order.getLineitems().get(0).setTransfer_price(vendorItemPricing.getTransferPrice());
|
|
|
319 |
order.getLineitems().get(0).setNlc(vendorItemPricing.getNlc());
|
| 8182 |
amar.kumar |
320 |
} catch (InventoryServiceException e) {
|
|
|
321 |
addActionError("Error in updating WarehouseId for row number " + rowId + 1);
|
|
|
322 |
logger.error("Error in updating WarehouseId for row number " + (rowId + 1),e);
|
| 8488 |
amar.kumar |
323 |
continue;
|
| 8182 |
amar.kumar |
324 |
}
|
|
|
325 |
|
|
|
326 |
order.setTotal_amount(totalPrice);
|
|
|
327 |
order.setSource(EBAY_SOURCE_ID);
|
|
|
328 |
orders.add(order);
|
|
|
329 |
orderCountForRow++;
|
|
|
330 |
|
|
|
331 |
txn.setOrders(orders);
|
|
|
332 |
Client transaction_client = new TransactionClient().getClient();
|
|
|
333 |
try {
|
|
|
334 |
long salesRecNumber = new Double(row.getCell(SALES_RECORD_NUM_INDEX).getNumericCellValue()).longValue();
|
|
|
335 |
if(transaction_client.ebayOrderExists(salesRecNumber, ebayItem.getEbayListingId())) {
|
| 8342 |
amar.kumar |
336 |
setErrorMsg(getErrorMsg() + "<br>Duplicate order for salesRecNumber " + salesRecNumber + " and listingId " + ebayItem.getEbayListingId() + " for row number " + rowId);
|
|
|
337 |
logger.error("Duplicate order for salesRecNumber " + salesRecNumber + " and listingId " + ebayItem.getEbayListingId());
|
|
|
338 |
continue;
|
| 8182 |
amar.kumar |
339 |
}
|
| 8350 |
amar.kumar |
340 |
try {
|
|
|
341 |
LogisticsService.Client logisticsClient = new LogisticsClient().getClient();
|
|
|
342 |
LogisticsInfo logisticsInfo = logisticsClient.getLogisticsInfo(order.getCustomer_pincode(),
|
| 8779 |
amar.kumar |
343 |
new Double(order.getLineitems().get(0).getItem_id()).longValue(), DeliveryType.PREPAID, PickUpType.COURIER);
|
| 8925 |
amar.kumar |
344 |
if(logisticsInfo.getProviderId()<7) {
|
|
|
345 |
String airwaybillNo= logisticsClient.getEmptyAWB(logisticsInfo.getProviderId(), DeliveryType.PREPAID);
|
|
|
346 |
order.setAirwaybill_no(airwaybillNo);
|
|
|
347 |
order.setTracking_id(airwaybillNo);
|
|
|
348 |
}
|
| 8350 |
amar.kumar |
349 |
order.setLogistics_provider_id(logisticsInfo.getProviderId());
|
|
|
350 |
} catch (Exception e) {
|
|
|
351 |
logger.error("Error while setting logistics provider for order for rowId " + rowId, e);
|
|
|
352 |
addActionError("Error while setting logistics provider for order for rowId " + rowId);
|
|
|
353 |
setErrorMsg(getErrorMsg() + "<br>Error while setting logistics provider for order for rowId " + rowId);
|
|
|
354 |
continue;
|
|
|
355 |
}
|
| 8182 |
amar.kumar |
356 |
transactionId = String.valueOf(transaction_client.createTransaction(txn));
|
|
|
357 |
row.getCell(PAISAPAY_ID_INDEX).setCellType(Cell.CELL_TYPE_STRING);
|
|
|
358 |
String paisaPayId = row.getCell(PAISAPAY_ID_INDEX).getStringCellValue();
|
| 10943 |
vikram.rag |
359 |
long paymentId = createPayment(user, paisaPayId, totalPrice);
|
| 8182 |
amar.kumar |
360 |
|
|
|
361 |
//TODO
|
|
|
362 |
/*in.shop2020.model.v1.order.Attribute orderAttribute = new in.shop2020.model.v1.order.Attribute();
|
|
|
363 |
orderAttribute.setName("tinNumber");
|
|
|
364 |
orderAttribute.setValue(sourceDetail.getTinNumber());
|
|
|
365 |
|
|
|
366 |
if(!sourceDetail.getTinNumber().equals("") && !(sourceDetail.getTinNumber() == null)) {
|
|
|
367 |
transaction_client.setOrderAttributeForTransaction(Long.parseLong(transactionId), orderAttribute);
|
|
|
368 |
}*/
|
|
|
369 |
//source
|
|
|
370 |
//transaction_client.changeTransactionStatus(Long.valueOf(transactionId), TransactionStatus.AUTHORIZED, "Ebay Order", 0L, OrderType.B2C, OrderSource.EBAY);
|
|
|
371 |
//transaction_client.changeTransactionStatus(Long.valueOf(transactionId), TransactionStatus.IN_PROCESS, "Ebay Order", 0L, OrderType.B2C, OrderSource.EBAY);
|
|
|
372 |
logger.info("Successfully created transaction: " + transactionId + " for amount: " + totalPrice);
|
|
|
373 |
|
|
|
374 |
Transaction transaction = transaction_client.getTransaction(Long.parseLong(transactionId));
|
| 8209 |
amar.kumar |
375 |
order = transaction.getOrders().get(0);
|
| 8182 |
amar.kumar |
376 |
inventoryClient.reserveItemInWarehouse(ebayItem.getItemId(), fulfillmentWarehouse.getId(), 1,
|
|
|
377 |
order.getId(), order.getCreated_timestamp(), order.getPromised_shipping_time(), order.getLineitems().get(0).getQuantity());
|
|
|
378 |
transaction_client.updateOrderForEbay(order);
|
|
|
379 |
EbayOrder ebayOrder = new EbayOrder();
|
|
|
380 |
ebayOrder.setEbayListingId(ebayItem.getEbayListingId());
|
|
|
381 |
ebayOrder.setSalesRecordNumber(new Double(row.getCell(SALES_RECORD_NUM_INDEX).getNumericCellValue()).longValue());
|
|
|
382 |
row.getCell(TRANSACTION_ID_INDEX).setCellType(Cell.CELL_TYPE_STRING);
|
|
|
383 |
ebayOrder.setTransactionId(row.getCell(TRANSACTION_ID_INDEX).getStringCellValue());
|
|
|
384 |
try {
|
| 8925 |
amar.kumar |
385 |
//Date ebayTransactionDate = interchangeDateAndMonth(row.getCell(TRANSACTION_DATE_INDEX).getDateCellValue());
|
|
|
386 |
Date ebayTransactionDate = row.getCell(TRANSACTION_DATE_INDEX).getDateCellValue();
|
| 8281 |
amar.kumar |
387 |
ebayOrder.setEbayTxnDate(ebayTransactionDate.getTime());
|
| 8182 |
amar.kumar |
388 |
//ebayOrder.setEbayTxnDate(sdf2.parse(row.getCell(TRANSACTION_DATE_INDEX).getStringCellValue()).getTime());
|
| 8254 |
amar.kumar |
389 |
//ebayOrder.setEbayTxnDate(sdf.parse(row.getCell(TRANSACTION_DATE_INDEX).getStringCellValue()).getTime());
|
| 8182 |
amar.kumar |
390 |
} catch (Exception e) {
|
|
|
391 |
logger.error("Error in setting transaction date for Ebay Order with OrderId : " + order.getId());
|
|
|
392 |
}
|
|
|
393 |
ebayOrder.setOrderId(transaction.getOrders().get(0).getId());
|
|
|
394 |
ebayOrder.setPaisaPayId(paisaPayId);
|
|
|
395 |
ebayOrder.setSubsidyAmount(ebayItem.getSubsidy()*quantity);
|
|
|
396 |
ebayOrder.setListingName(ebayItem.getListingName());
|
| 8241 |
amar.kumar |
397 |
ebayOrder.setListingPrice(listingPrice);
|
| 8182 |
amar.kumar |
398 |
transaction_client.createEbayOrder(ebayOrder);
|
| 10943 |
vikram.rag |
399 |
in.shop2020.payments.PaymentService.Client client = new PaymentClient().getClient();
|
|
|
400 |
client.updatePaymentDetails(paymentId, null, null, null, null, null, null, paisaPayId, null, PaymentStatus.SUCCESS, null, null);
|
| 8182 |
amar.kumar |
401 |
} catch (Exception e) {
|
| 8350 |
amar.kumar |
402 |
logger.error("Error while creating order for rowId " + rowId, e);
|
|
|
403 |
addActionError("Error while creating order for rowId " + rowId);
|
|
|
404 |
setErrorMsg(getErrorMsg() + "<br>Error while creating order for row number " + rowId);
|
|
|
405 |
continue;
|
| 8182 |
amar.kumar |
406 |
}
|
|
|
407 |
}
|
|
|
408 |
|
|
|
409 |
checkForErrors();
|
|
|
410 |
return "authsuccess";
|
|
|
411 |
}
|
|
|
412 |
|
| 8925 |
amar.kumar |
413 |
/*private Date interchangeDateAndMonth(Date date) {
|
| 8281 |
amar.kumar |
414 |
Date updatedDate = new Date(date.getTime());
|
| 8286 |
amar.kumar |
415 |
updatedDate.setDate(date.getMonth() + 1);
|
|
|
416 |
updatedDate.setMonth(date.getDate() - 1);
|
| 8281 |
amar.kumar |
417 |
return updatedDate;
|
| 8925 |
amar.kumar |
418 |
}*/
|
| 8281 |
amar.kumar |
419 |
|
| 8182 |
amar.kumar |
420 |
private LineItem createLineItem(long itemId, long quantity, double amount) throws CatalogServiceException, TException {
|
|
|
421 |
LineItem lineItem = new LineItem();
|
|
|
422 |
CatalogService.Client catalogClient = new CatalogClient().getClient();
|
|
|
423 |
Item item = catalogClient.getItem(itemId);
|
|
|
424 |
|
|
|
425 |
lineItem.setProductGroup(item.getProductGroup());
|
|
|
426 |
lineItem.setBrand(item.getBrand());
|
|
|
427 |
lineItem.setModel_number(item.getModelNumber());
|
|
|
428 |
lineItem.setModel_name(item.getModelName());
|
|
|
429 |
lineItem.setExtra_info(item.getFeatureDescription());
|
|
|
430 |
lineItem.setQuantity(quantity);
|
|
|
431 |
lineItem.setItem_id(item.getId());
|
|
|
432 |
lineItem.setUnit_weight(item.getWeight());
|
| 8241 |
amar.kumar |
433 |
lineItem.setTotal_weight(item.getWeight()*quantity);
|
| 8182 |
amar.kumar |
434 |
lineItem.setUnit_price(amount/quantity);
|
|
|
435 |
lineItem.setTotal_price(amount);
|
|
|
436 |
|
|
|
437 |
if (item.getColor() == null || "NA".equals(item.getColor())) {
|
|
|
438 |
lineItem.setColor("");
|
|
|
439 |
} else {
|
|
|
440 |
lineItem.setColor(item.getColor());
|
|
|
441 |
}
|
|
|
442 |
return lineItem;
|
|
|
443 |
}
|
|
|
444 |
|
| 10943 |
vikram.rag |
445 |
private long createPayment(User user, String paisaPayId, double amount) throws NumberFormatException, PaymentException, TException {
|
| 8182 |
amar.kumar |
446 |
in.shop2020.payments.PaymentService.Client client = new PaymentClient().getClient();
|
| 10943 |
vikram.rag |
447 |
return client.createPayment(user.getUserId(), amount, EBAY_GATEWAY_ID, Long.valueOf(transactionId), false);
|
| 8182 |
amar.kumar |
448 |
}
|
|
|
449 |
|
|
|
450 |
public String index() {
|
|
|
451 |
if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), "/ebay-dashboard"))
|
|
|
452 |
return "authfail";
|
|
|
453 |
checkForErrors();
|
|
|
454 |
return "authsuccess";
|
|
|
455 |
}
|
|
|
456 |
|
|
|
457 |
private boolean checkForErrors(){
|
|
|
458 |
Collection<String> actionErrors = getActionErrors();
|
|
|
459 |
if(actionErrors != null && !actionErrors.isEmpty()){
|
|
|
460 |
for (String str : actionErrors) {
|
|
|
461 |
errorMsg += "<BR/>" + str;
|
|
|
462 |
}
|
|
|
463 |
return true;
|
|
|
464 |
}
|
|
|
465 |
return false;
|
|
|
466 |
}
|
|
|
467 |
|
|
|
468 |
@Override
|
|
|
469 |
public void setServletRequest(HttpServletRequest request) {
|
|
|
470 |
this.request = request;
|
|
|
471 |
this.session = request.getSession();
|
|
|
472 |
}
|
|
|
473 |
|
|
|
474 |
public String getErrorMsg() {
|
|
|
475 |
return errorMsg;
|
|
|
476 |
}
|
|
|
477 |
|
|
|
478 |
public void setErrorMsg(String errorMsg) {
|
|
|
479 |
this.errorMsg = errorMsg;
|
|
|
480 |
}
|
|
|
481 |
|
|
|
482 |
public Long getRowId() {
|
|
|
483 |
return rowId;
|
|
|
484 |
}
|
|
|
485 |
|
|
|
486 |
public void setRowId(Long rowId) {
|
|
|
487 |
this.rowId = rowId;
|
|
|
488 |
}
|
|
|
489 |
|
|
|
490 |
public File getOrderDataFile() {
|
|
|
491 |
return orderDataFile;
|
|
|
492 |
}
|
|
|
493 |
|
|
|
494 |
public void setOrderDataFile(File orderDataFile) {
|
|
|
495 |
this.orderDataFile = orderDataFile;
|
|
|
496 |
}
|
|
|
497 |
|
|
|
498 |
}
|