Subversion Repositories SmartDukaan

Rev

Rev 9147 | Rev 9188 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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