Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
8616 vikram.rag 1
package in.shop2020;
2
 
3
import in.shop2020.model.v1.catalog.CatalogService;
8739 vikram.rag 4
import in.shop2020.model.v1.catalog.SnapdealItem;
8616 vikram.rag 5
import in.shop2020.model.v1.catalog.CatalogServiceException;
6
import in.shop2020.model.v1.catalog.Item;
7
import in.shop2020.model.v1.inventory.InventoryService;
8
import in.shop2020.model.v1.inventory.InventoryServiceException;
8759 vikram.rag 9
 
8616 vikram.rag 10
import in.shop2020.model.v1.inventory.VendorItemPricing;
11
import in.shop2020.model.v1.inventory.Warehouse;
12
import in.shop2020.model.v1.order.LineItem;
13
import in.shop2020.model.v1.order.OrderStatus;
14
import in.shop2020.model.v1.order.OrderType;
15
import in.shop2020.model.v1.order.SnapdealOrder;
16
import in.shop2020.model.v1.order.SourceDetail;
17
import in.shop2020.model.v1.order.Transaction;
8651 vikram.rag 18
import in.shop2020.model.v1.order.TransactionServiceException;
8616 vikram.rag 19
import in.shop2020.model.v1.order.TransactionStatus;
20
import in.shop2020.model.v1.order.TransactionService.Client;
21
import in.shop2020.model.v1.user.User;
22
import in.shop2020.payments.PaymentException;
23
import in.shop2020.payments.PaymentStatus;
24
import in.shop2020.thrift.clients.CatalogClient;
25
import in.shop2020.thrift.clients.InventoryClient;
26
import in.shop2020.thrift.clients.PaymentClient;
27
import in.shop2020.thrift.clients.TransactionClient;
28
import in.shop2020.thrift.clients.UserClient;
29
 
30
import java.io.File;
8651 vikram.rag 31
import java.text.ParseException;
8616 vikram.rag 32
import java.text.SimpleDateFormat;
33
import java.util.ArrayList;
34
import java.util.Calendar;
35
import java.util.Collections;
36
import java.util.Date;
8773 vikram.rag 37
import java.util.GregorianCalendar;
8616 vikram.rag 38
import java.util.List;
39
import javax.xml.bind.JAXBContext;
40
import javax.xml.bind.JAXBException;
41
import javax.xml.bind.Marshaller;
42
import javax.xml.bind.Unmarshaller;
8739 vikram.rag 43
 
8616 vikram.rag 44
import org.apache.thrift.TException;
45
import org.apache.thrift.transport.TTransportException;
8645 vikram.rag 46
import org.slf4j.Logger;
47
import org.slf4j.LoggerFactory;
8773 vikram.rag 48
import in.shop2020.utils.GmailUtils;
8616 vikram.rag 49
 
50
import order.SaholicAPI;
51
import order.SaholicAPI.Order;
52
 
53
public class ProcessSnapdealOrder {
54
	private static final int SNAPDEAL_SOURCE_ID = 7;
55
	private static final String FIRSTFLIGHT = "First Flight";
8627 vikram.rag 56
	private static final String DELHIVERY = "DELHIVERY";
57
	private static final String BLUEDART = "Bluedart";
8715 vikram.rag 58
	private static final String CHHOTU = "CHHOTU";	
59
	private static final String LAST_MILE = "LAST_MILE";
60
	private static final String  ECOMM_EXP = "ECOMM_EXP";
61
	private static final String  EWINGS = "EWINGS";
62
	private static final String DTDC = "DTDC";
63
	private static final String WAREOLOG = "DTDC";
64
	private static final String  MIRAKLE = "MIRAKLE";
65
	private static final String RAJIV_TRANSPORT = "RAJIV_TRANSPORT";
66
	private static final String BLUEDART_HIGH_VALUE = "BLUEDART_HIGH_VALUE";
67
	private static final String BLUEDART_SURFACE = "BLUEDART_SURFACE";
68
	private static final String BLUEDART_APEX = "BLUEDART_APEX";
69
	private static final String ARAMEX = "ARAMEX";
70
	private static final String GATI = "GATI";
71
	private static final String INDIA_POST = "INDIA_POST";
72
	private static final String FEDEX = "FEDEX";
73
	private static final String IOT = "IOT";
74
	private static final String RED_EXP = "RED_EXP";
75
	private static final String GHARPAY = "GHARPAY";
76
	private static final String QUANTIUM = "QUANTIUM";
77
	private static final String GATI_AIR = "GATI_AIR`";
78
	private static final String VDELIVER = "VDELIVER";
8627 vikram.rag 79
	private static String transactionId;
80
	private static final int SNAPDEAL_GATEWAY_ID = 18;
8646 vikram.rag 81
	private static Logger logger;
8627 vikram.rag 82
 
8616 vikram.rag 83
	public static void processSnapdealOrders(File file) throws JAXBException{
8646 vikram.rag 84
		logger = LoggerFactory.getLogger(ProcessSnapdealOrder.class);
8616 vikram.rag 85
		JAXBContext jc = JAXBContext.newInstance(SaholicAPI.class);
86
		Unmarshaller unmarshaller = jc.createUnmarshaller();
87
		SaholicAPI orders = (SaholicAPI) unmarshaller.unmarshal(file);
88
		Marshaller marshaller = jc.createMarshaller();
89
		marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
90
		marshaller.marshal(orders, System.out);
91
		SourceDetail sourceDetail = null;
92
		User user = null;
93
		TransactionClient tsc = null;
94
		try {
95
			tsc = new TransactionClient();
96
			sourceDetail = tsc.getClient().getSourceDetail(SNAPDEAL_SOURCE_ID);
97
		} catch (Exception e) {
8773 vikram.rag 98
			logger.error("Unable to establish connection to the transaction service while getting Snapdeal Source Detail ", e);
8616 vikram.rag 99
		}
100
		try {   
101
			in.shop2020.model.v1.user.UserContextService.Client userClient = new UserClient().getClient();
102
			user = userClient.getUserByEmail(sourceDetail.getEmail());
103
		} catch (Exception e) {
8773 vikram.rag 104
			logger.error("Unable to establish connection to the User service ", e);
8616 vikram.rag 105
		}
8773 vikram.rag 106
		int total_orders = 0;
107
		int processed_orders = 0;
108
		StringBuffer sb = new StringBuffer();
8616 vikram.rag 109
		for(Order order:orders.getOrder()){
8627 vikram.rag 110
			long subOrderId = (long) order.getSuborderId();
111
			Client transaction_client = null;
112
			try {
113
				transaction_client = new TransactionClient().getClient();
114
				if(transaction_client.snapdealOrderExists(subOrderId)) {
8739 vikram.rag 115
					logger.error("Snapdeal suborder id exists " + subOrderId);
8627 vikram.rag 116
					continue;
117
				}
118
 
119
			} catch (TTransportException e1) {
8773 vikram.rag 120
				logger.error("Problem with Transaction service " , e1);
8627 vikram.rag 121
				e1.printStackTrace();
122
			} catch (TException e) {
8773 vikram.rag 123
				logger.error("Problem.. thrift exception with Transaction service " , e);
8627 vikram.rag 124
				e.printStackTrace();
125
			}
8773 vikram.rag 126
			total_orders++;
8616 vikram.rag 127
			Transaction txn = new Transaction();
128
			txn.setShoppingCartid(user.getActiveCartId());
129
			txn.setCustomer_id(user.getUserId());
8627 vikram.rag 130
			System.out.println("User Id is " + user.getUserId());
8616 vikram.rag 131
			txn.setCreatedOn(new Date().getTime());
132
			txn.setTransactionStatus(TransactionStatus.INIT);
133
			txn.setStatusDescription("Order for Snapdeal ");
134
			List<in.shop2020.model.v1.order.Order> orderlist = new ArrayList<in.shop2020.model.v1.order.Order>();
135
			LineItem lineItem = null;
8739 vikram.rag 136
			CatalogService.Client catalogClient = null;
137
			SnapdealItem snapdealItem = null;
138
			double SellingPrice = 0;
8616 vikram.rag 139
			try {
8739 vikram.rag 140
				catalogClient =  new CatalogClient().getClient();
141
				snapdealItem = catalogClient.getSnapdealItem(order.getSKUCode());
8742 vikram.rag 142
				if(snapdealItem.getItem_id()!=0 && order.getSellingPricePerItem() <  snapdealItem.getExceptionPrice()){
8739 vikram.rag 143
					SellingPrice = snapdealItem.getExceptionPrice();
144
				}
145
				else{
146
					SellingPrice = order.getSellingPricePerItem();
147
				}
148
				lineItem = createLineItem(order.getSKUCode(),SellingPrice);
8773 vikram.rag 149
				if(lineItem == null){
150
					sb.append(order.getSuborderId() +" "+"SKU not found" + "\n");
151
					continue;
152
				}
8627 vikram.rag 153
				System.out.println("Line item created");
8616 vikram.rag 154
			} catch (CatalogServiceException e) {
8773 vikram.rag 155
				logger.error("Unable to create order for suborderid  " + order.getSuborderId() , e);
8616 vikram.rag 156
				e.printStackTrace();
8773 vikram.rag 157
				sb.append(order.getSuborderId() + " " + "Problem with catalog service" + "\n");
8744 vikram.rag 158
				continue;
8616 vikram.rag 159
			} catch (TException e) {
8773 vikram.rag 160
				logger.error("Unable to create order for suborderid  " + order.getSuborderId() , e);
8616 vikram.rag 161
				e.printStackTrace();
8773 vikram.rag 162
				sb.append(order.getSuborderId() + " " + "Thrift Exception in Catalog Service" + "\n");
8744 vikram.rag 163
				continue;
8616 vikram.rag 164
			}
165
			in.shop2020.model.v1.order.Order t_order = new in.shop2020.model.v1.order.Order();
8627 vikram.rag 166
			t_order.setCustomer_id(user.getUserId());
167
			t_order.setCustomer_email(sourceDetail.getEmail());
168
			t_order.setCustomer_name(order.getCustomerName());
169
			t_order.setCustomer_address1("");
170
			t_order.setCustomer_address2("");
171
			t_order.setCustomer_city(order.getCity());
172
			t_order.setCustomer_state(order.getState());
173
			t_order.setCustomer_pincode(String.valueOf(order.getPINCode()));
8742 vikram.rag 174
			t_order.setTotal_amount(SellingPrice);            
8627 vikram.rag 175
			t_order.setTotal_weight(lineItem.getTotal_weight());
176
			t_order.setLineitems(Collections.singletonList(lineItem));            
8759 vikram.rag 177
			t_order.setStatus(OrderStatus.PAYMENT_PENDING);
178
			t_order.setStatusDescription("Waiting for payment");
8627 vikram.rag 179
			t_order.setCreated_timestamp(new Date().getTime());
180
			t_order.setOrderType(OrderType.B2C);
181
			t_order.setCod(false);
182
			System.out.println("t order created");
183
			try {
8661 vikram.rag 184
				SimpleDateFormat istFormatter = new SimpleDateFormat("yyyy-MM-dd");
185
				Date shipDate = null;
186
				try {
187
					shipDate= istFormatter.parse(order.getShipByDate());
188
				} catch (ParseException e) {
8773 vikram.rag 189
					logger.error("Could not parse order ship date from file " , e);
8661 vikram.rag 190
					e.printStackTrace();
8773 vikram.rag 191
					sb.append(order.getSuborderId() + "Could not parse ship date" + " " + "\n");
8744 vikram.rag 192
					continue;
8661 vikram.rag 193
				}
8627 vikram.rag 194
				Calendar time = Calendar.getInstance();
8661 vikram.rag 195
				t_order.setPromised_shipping_time(shipDate.getTime());
196
				t_order.setExpected_shipping_time(shipDate.getTime());
8744 vikram.rag 197
				time.add(Calendar.DAY_OF_MONTH, 4);
8627 vikram.rag 198
				t_order.setPromised_delivery_time(time.getTimeInMillis());
199
				t_order.setExpected_delivery_time(time.getTimeInMillis());
200
				System.out.println("Dates set in transaction");
8697 vikram.rag 201
			} catch(Exception e) {	
8645 vikram.rag 202
				logger.error("Error in updating Shipping or Delivery Time for suborderid  " + order.getSuborderId());
8773 vikram.rag 203
				sb.append(order.getSuborderId() + "Could not update delivery time" + " " + "\n");
8627 vikram.rag 204
				continue;
205
			}
8657 vikram.rag 206
			InventoryService.Client inventoryClient = null;
8739 vikram.rag 207
			Warehouse fulfillmentWarehouse= null;
208
			try {
209
				inventoryClient = new InventoryClient().getClient();
210
				if(snapdealItem.getItem_id()!=0 && snapdealItem.getWarehouseId()!=0) {
211
					fulfillmentWarehouse = inventoryClient.getWarehouse(snapdealItem.getWarehouseId());
212
				} else {
213
					List<Long> itemAvailability = inventoryClient.getItemAvailabilityAtLocation(order.getSKUCode(), 1);
214
					fulfillmentWarehouse = inventoryClient.getWarehouse(itemAvailability.get(0));
215
				}
216
				logger.info("Fulfillment warehouse id for suborderid  " + order.getSuborderId() + " is " + fulfillmentWarehouse.getId());
217
				t_order.setFulfilmentWarehouseId(fulfillmentWarehouse.getId());
218
				logger.info("Billing warehouse id for suborderid  " + order.getSuborderId() + " is " + fulfillmentWarehouse.getBillingWarehouseId());
219
				t_order.setWarehouse_id(fulfillmentWarehouse.getBillingWarehouseId());
220
				VendorItemPricing vendorItemPricing = inventoryClient.getItemPricing(lineItem.getItem_id(), fulfillmentWarehouse.getVendor().getId());
221
				t_order.getLineitems().get(0).setTransfer_price(vendorItemPricing.getTransferPrice());
222
				t_order.getLineitems().get(0).setNlc(vendorItemPricing.getNlc());
8616 vikram.rag 223
			} catch (InventoryServiceException e) {
8662 vikram.rag 224
				logger.error("Error connecting inventory service for suborderid  " + order.getSuborderId());
8773 vikram.rag 225
				sb.append(order.getSuborderId() + "Inventory Service Exception" + " " + "\n");
8739 vikram.rag 226
				continue;
8616 vikram.rag 227
			} catch (TTransportException e) {
8773 vikram.rag 228
				logger.error("Transport Exception with Inventory Service for suborderid  " + order.getSuborderId() , e);
229
				sb.append(order.getSuborderId() + "Transport Exception with Inventory Service" + " " + "\n");
8744 vikram.rag 230
				continue;
8616 vikram.rag 231
			} catch (TException e) {
8773 vikram.rag 232
				logger.error("Exception with Inventory Service for suborderid  " + order.getSuborderId() , e);
233
				sb.append(order.getSuborderId() + "Exception in Inventory Service" + " " + "\n");
8744 vikram.rag 234
				continue;
8657 vikram.rag 235
			}
8616 vikram.rag 236
			if(order.getCourier().equalsIgnoreCase(FIRSTFLIGHT)) {
237
				t_order.setLogistics_provider_id(12);
238
			} else if(order.getCourier().equalsIgnoreCase(DELHIVERY)) {
239
				t_order.setLogistics_provider_id(13);
240
			} else if(order.getCourier().equalsIgnoreCase(BLUEDART)) {
241
				t_order.setLogistics_provider_id(14);
8642 vikram.rag 242
			}else if(order.getCourier().equalsIgnoreCase(CHHOTU)) {
243
				t_order.setLogistics_provider_id(16);
8715 vikram.rag 244
			}
245
			else if(order.getCourier().equalsIgnoreCase(LAST_MILE)){
246
				t_order.setLogistics_provider_id(17);
247
			}
248
			else if(order.getCourier().equalsIgnoreCase(ECOMM_EXP)){
249
				t_order.setLogistics_provider_id(18);
250
			}
251
			else if(order.getCourier().equalsIgnoreCase(EWINGS)){
252
				t_order.setLogistics_provider_id(19);
253
			}
254
			else if(order.getCourier().equalsIgnoreCase(DTDC)){
255
				t_order.setLogistics_provider_id(20);
256
			}
257
			else if(order.getCourier().equalsIgnoreCase(WAREOLOG)){
258
				t_order.setLogistics_provider_id(21);
259
			}
260
			else if(order.getCourier().equalsIgnoreCase(MIRAKLE)){
261
				t_order.setLogistics_provider_id(22);
262
			}
263
			else if(order.getCourier().equalsIgnoreCase(RAJIV_TRANSPORT)){
264
				t_order.setLogistics_provider_id(23);
265
			}
266
			else if(order.getCourier().equalsIgnoreCase(BLUEDART_HIGH_VALUE)){
267
				t_order.setLogistics_provider_id(24);
268
			}
269
			else if(order.getCourier().equalsIgnoreCase(BLUEDART_SURFACE)){
270
				t_order.setLogistics_provider_id(25);
271
			}
272
			else if(order.getCourier().equalsIgnoreCase(BLUEDART_APEX)){
273
				t_order.setLogistics_provider_id(26);
274
			}
275
			else if(order.getCourier().equalsIgnoreCase(ARAMEX)){
276
				t_order.setLogistics_provider_id(27);
277
			}
278
			else if(order.getCourier().equalsIgnoreCase(GATI)){
279
				t_order.setLogistics_provider_id(28);
280
			}
281
			else if(order.getCourier().equalsIgnoreCase(INDIA_POST)){
282
				t_order.setLogistics_provider_id(29);
283
			}
284
			else if(order.getCourier().equalsIgnoreCase(FEDEX)){
285
				t_order.setLogistics_provider_id(30);
286
			}
287
			else if(order.getCourier().equalsIgnoreCase(IOT)){
288
				t_order.setLogistics_provider_id(31);
289
			}
290
			else if(order.getCourier().equalsIgnoreCase(RED_EXP)){
291
				t_order.setLogistics_provider_id(32);
292
			}
293
			else if(order.getCourier().equalsIgnoreCase(VDELIVER)){
294
				t_order.setLogistics_provider_id(33);
295
			}
296
			else if(order.getCourier().equalsIgnoreCase(GHARPAY)){
297
				t_order.setLogistics_provider_id(34);
298
			}
299
			else if(order.getCourier().equalsIgnoreCase(QUANTIUM)){
300
				t_order.setLogistics_provider_id(35);
301
			}
302
			else if(order.getCourier().equalsIgnoreCase(GATI_AIR)){
303
				t_order.setLogistics_provider_id(36);
304
			}
305
			else {
8652 vikram.rag 306
				logger.error("Error No Courier Match please add courier to our system for suborderid  " + order.getSuborderId() + "Courier Name " + order.getCourier());
8773 vikram.rag 307
				sb.append(order.getSuborderId() + " Error No Courier Match " + order.getCourier() +"\n");
8627 vikram.rag 308
				continue;
8616 vikram.rag 309
			}
8627 vikram.rag 310
 
8616 vikram.rag 311
			t_order.setAirwaybill_no(String.valueOf(order.getAWBNumber()));
312
			t_order.setTracking_id(String.valueOf(order.getAWBNumber()));
8739 vikram.rag 313
			t_order.setTotal_amount(SellingPrice);
8627 vikram.rag 314
			t_order.setOrderType(OrderType.B2C);
315
			t_order.setSource(SNAPDEAL_SOURCE_ID);
316
			t_order.setOrderType(OrderType.B2C);
317
			orderlist.add(t_order);
318
			txn.setOrders(orderlist);
8739 vikram.rag 319
			String referenceCode = order.getReferenceCode();
320
			String productName = order.getProduct();
321
			SimpleDateFormat istFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
322
			Date snapdealTxnDate = null;
323
			try {
324
				snapdealTxnDate = istFormatter.parse(order.getOrderPlacedDate());
325
			} catch (ParseException e) {
8773 vikram.rag 326
				logger.error(order.getSuborderId() + " Could not parse snapdeal order date from file " , e);
327
				sb.append(order.getSuborderId() + " Could not parse order date" +"\n");
8744 vikram.rag 328
				continue;
8739 vikram.rag 329
			}
330
			try {
331
				transactionId =  String.valueOf(transaction_client.createTransaction(txn));
332
			} catch (TransactionServiceException e) {
8773 vikram.rag 333
				logger.error(order.getSuborderId() + " Could not create transaction " , e);
334
				sb.append(order.getSuborderId() + " Could not create transaction" +"\n");
8744 vikram.rag 335
				continue;
8739 vikram.rag 336
			} catch (TException e) {
8773 vikram.rag 337
				logger.error("Problem with transaction service while creating transaction", e);
338
				sb.append(order.getSuborderId() + "Transaction Service Exception could not create transaction" +"\n");
8744 vikram.rag 339
				continue;
8739 vikram.rag 340
			}
341
			createPayment(user, (new Long(subOrderId)).toString(),lineItem.getTotal_price());
342
			Transaction transaction = null;
343
			try {
344
				transaction = transaction_client.getTransaction(Long.parseLong(transactionId));
345
			} catch (NumberFormatException e) {
346
				logger.error("Problem parsing transaction id " + transactionId);
8773 vikram.rag 347
				sb.append(order.getSuborderId() + " Problem parsing transaction id "+ transactionId +"\n");
8739 vikram.rag 348
				e.printStackTrace();
8744 vikram.rag 349
				continue;
8739 vikram.rag 350
			} catch (TransactionServiceException e) {
351
				logger.error("Problem getting transaction from service transaction id " + transactionId);
8773 vikram.rag 352
				sb.append(order.getSuborderId() + " Problem getting transaction id "+ transactionId +"\n");
8739 vikram.rag 353
				e.printStackTrace();
8744 vikram.rag 354
				continue;
8739 vikram.rag 355
			} catch (TException e) {
356
				logger.error("Problem with transaction service while getting transaction id " + transactionId);
8773 vikram.rag 357
				sb.append(order.getSuborderId() + " Problem with transaction service while getting transaction id "+ transactionId +"\n");
8739 vikram.rag 358
				e.printStackTrace();
8744 vikram.rag 359
				continue;
8739 vikram.rag 360
			}
361
			in.shop2020.model.v1.order.Order snapdealorder = transaction.getOrders().get(0);
8744 vikram.rag 362
			try {
363
				inventoryClient.reserveItemInWarehouse(lineItem.getItem_id(), fulfillmentWarehouse.getId(), 1, 
8773 vikram.rag 364
						snapdealorder.getId(), snapdealorder.getCreated_timestamp(), snapdealorder.getPromised_shipping_time(), snapdealorder.getLineitems().get(0).getQuantity());
8744 vikram.rag 365
			} catch (InventoryServiceException e1) {
366
				logger.error("Problem while reserving item in inventory service" + snapdealorder.getId());
8773 vikram.rag 367
				sb.append(order.getSuborderId() + " Could not reserve inventory for sku "+ order.getSKUCode() +"\n");
8744 vikram.rag 368
				continue;
369
			} catch (TException e1) {
370
				logger.error("Problem with inventory service" + snapdealorder.getId());
8773 vikram.rag 371
				sb.append(order.getSuborderId() + " Problem with inventory service while reserving inventory for sku "+ order.getSKUCode() +"\n");
8744 vikram.rag 372
				continue;
373
			}
8739 vikram.rag 374
			SnapdealOrder snapdealOrder = new SnapdealOrder();
375
			snapdealOrder.setOrderId(snapdealorder.getId());
376
			snapdealOrder.setSubOrderId(subOrderId);
377
			snapdealOrder.setReferenceCode(referenceCode);
378
			snapdealOrder.setProductName(productName);
379
			snapdealOrder.setSnapdealTxnDate(snapdealTxnDate.getTime());
380
			snapdealOrder.setListingPrice(order.getSellingPricePerItem());
381
			try {
382
				transaction_client.createSnapdealOrder(snapdealOrder);
383
			} catch (TException e) {
384
				logger.error("Could not create Snapdeal Order");
8773 vikram.rag 385
				sb.append(order.getSuborderId() + " Could not create snapdeal order"+"\n");
8739 vikram.rag 386
			}
8773 vikram.rag 387
			processed_orders++;
388
 
389
		}
390
		java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd-HH:mm:ss");
391
		Calendar cal=GregorianCalendar.getInstance();
392
		String emailFromAddress = "build@shop2020.in";
393
		String password = "cafe@nes";
394
		GmailUtils mailer = new GmailUtils();
395
		try {
8774 vikram.rag 396
			if(total_orders==processed_orders && total_orders > 0){
8773 vikram.rag 397
				String emailSubjectTxt = total_orders + " Snapdeal Orders Created Successfully "+sdf.format(cal.getTime());
398
				String text = "Order is now available for processing on Order Management Dashboard";
399
				String sendTo[] = new String[]{"vikram.raghav@shop2020.in"};
400
				//String sendTo[] = new String[]{ "sandeep.sachdeva@shop2020.in", "vikram.raghav@shop2020.in", "rajneesh.arora@shop2020.in","khushal.bhatia@shop2020.in","rajveer.singh@saholic.com","manoj.kumar@saholic.com","chaitnaya.vats@saholic.com"};
401
				mailer.sendSSLMessage(sendTo, emailSubjectTxt, text, emailFromAddress, password, new ArrayList<File>());
402
			}
8774 vikram.rag 403
			else if(total_orders > 0){
8773 vikram.rag 404
				int failed_orders = total_orders - processed_orders;
405
				String emailSubjectTxt = failed_orders + " Snapdeal Orders Failed while creation "+sdf.format(cal.getTime());
406
				String text = sb.toString();
407
				String sendTo[] = new String[]{"vikram.raghav@shop2020.in"};
408
				//String sendTo[] = new String[]{ "sandeep.sachdeva@shop2020.in", "vikram.raghav@shop2020.in", "rajneesh.arora@shop2020.in","khushal.bhatia@shop2020.in","rajveer.singh@saholic.com","manoj.kumar@saholic.com","chaitnaya.vats@saholic.com"};
409
				mailer.sendSSLMessage(sendTo, emailSubjectTxt, text, emailFromAddress, password, new ArrayList<File>());
410
			}
411
		}
412
		catch (Exception e) {
413
			e.printStackTrace();
414
		}
8627 vikram.rag 415
 
8616 vikram.rag 416
 
8773 vikram.rag 417
 
8616 vikram.rag 418
	}
419
 
8649 vikram.rag 420
	public static void createPayment(User user, String subOrderId, double amount) {
421
		in.shop2020.payments.PaymentService.Client client = null;
422
		try {
423
			client = new PaymentClient().getClient();
424
		} catch (TTransportException e) {
425
			logger.error("Could not connect to payment service ");
426
			e.printStackTrace();
427
		}
428
		long paymentId = 0;
429
		try {
430
			paymentId = client.createPayment(user.getUserId(), amount, SNAPDEAL_GATEWAY_ID, Long.valueOf(transactionId), false);
431
		} catch (NumberFormatException e) {
432
			logger.error("Could not create payment");
433
			e.printStackTrace();
434
		} catch (PaymentException e) {
435
			logger.error("Could not create payment payment exception");
436
			e.printStackTrace();
437
		} catch (TException e) {
438
			logger.error("Could not create payment thrift exception");
439
			e.printStackTrace();
440
		}
441
		try {
442
			client.updatePaymentDetails(paymentId, null, null, null, null, null, null, subOrderId, null, PaymentStatus.AUTHORIZED, null, null);
443
		} catch (PaymentException e) {
444
			logger.error("Could not update payment to order");
445
			e.printStackTrace();
446
		} catch (TException e) {
447
			logger.error("Could not update payment thrift exception");
448
			e.printStackTrace();
449
		}
8627 vikram.rag 450
	}   
451
 
8616 vikram.rag 452
	public static LineItem createLineItem(long itemId, double amount) throws CatalogServiceException, TException {
8627 vikram.rag 453
		LineItem lineItem = new LineItem();
454
		CatalogService.Client catalogClient = new CatalogClient().getClient();
455
		Item item = catalogClient.getItem(itemId);
8773 vikram.rag 456
		if(item.getId()==0){
457
			//in case item id is incorrect..
458
			return null;
459
		}
8616 vikram.rag 460
 
8627 vikram.rag 461
		lineItem.setProductGroup(item.getProductGroup());
462
		lineItem.setBrand(item.getBrand());
463
		lineItem.setModel_number(item.getModelNumber());
464
		lineItem.setModel_name(item.getModelName());
465
		lineItem.setExtra_info(item.getFeatureDescription());
466
		lineItem.setQuantity(1);
467
		lineItem.setItem_id(item.getId());
468
		lineItem.setUnit_weight(item.getWeight());
469
		lineItem.setTotal_weight(item.getWeight());
470
		lineItem.setUnit_price(amount);
471
		lineItem.setTotal_price(amount);
472
 
8739 vikram.rag 473
		if (item.getColor() == null || "NA".equals(item.getColor())) {
8627 vikram.rag 474
			lineItem.setColor("");
475
		} else {
476
			lineItem.setColor(item.getColor());
477
		}
478
		return lineItem;
8616 vikram.rag 479
	}
480
 
481
}