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