Subversion Repositories SmartDukaan

Rev

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