Subversion Repositories SmartDukaan

Rev

Rev 8775 | Rev 8800 | 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();
8775 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());
8775 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));
8789 vikram.rag 215
					if(fulfillmentWarehouse.getStateId()!=0){
216
						fulfillmentWarehouse = inventoryClient.getWarehouse(7);
217
					}
8739 vikram.rag 218
				}
219
				t_order.setFulfilmentWarehouseId(fulfillmentWarehouse.getId());
220
				logger.info("Billing warehouse id for suborderid  " + order.getSuborderId() + " is " + fulfillmentWarehouse.getBillingWarehouseId());
221
				t_order.setWarehouse_id(fulfillmentWarehouse.getBillingWarehouseId());
222
				VendorItemPricing vendorItemPricing = inventoryClient.getItemPricing(lineItem.getItem_id(), fulfillmentWarehouse.getVendor().getId());
223
				t_order.getLineitems().get(0).setTransfer_price(vendorItemPricing.getTransferPrice());
224
				t_order.getLineitems().get(0).setNlc(vendorItemPricing.getNlc());
8616 vikram.rag 225
			} catch (InventoryServiceException e) {
8662 vikram.rag 226
				logger.error("Error connecting inventory service for suborderid  " + order.getSuborderId());
8775 vikram.rag 227
				sb.append(order.getSuborderId() + " Inventory Service Exception" + " " + "\n");
8739 vikram.rag 228
				continue;
8616 vikram.rag 229
			} catch (TTransportException e) {
8773 vikram.rag 230
				logger.error("Transport Exception with Inventory Service for suborderid  " + order.getSuborderId() , e);
8775 vikram.rag 231
				sb.append(order.getSuborderId() + " Transport Exception with Inventory Service" + " " + "\n");
8744 vikram.rag 232
				continue;
8616 vikram.rag 233
			} catch (TException e) {
8773 vikram.rag 234
				logger.error("Exception with Inventory Service for suborderid  " + order.getSuborderId() , e);
8775 vikram.rag 235
				sb.append(order.getSuborderId() + " Exception in Inventory Service" + " " + "\n");
8744 vikram.rag 236
				continue;
8657 vikram.rag 237
			}
8616 vikram.rag 238
			if(order.getCourier().equalsIgnoreCase(FIRSTFLIGHT)) {
239
				t_order.setLogistics_provider_id(12);
240
			} else if(order.getCourier().equalsIgnoreCase(DELHIVERY)) {
241
				t_order.setLogistics_provider_id(13);
242
			} else if(order.getCourier().equalsIgnoreCase(BLUEDART)) {
243
				t_order.setLogistics_provider_id(14);
8642 vikram.rag 244
			}else if(order.getCourier().equalsIgnoreCase(CHHOTU)) {
245
				t_order.setLogistics_provider_id(16);
8715 vikram.rag 246
			}
247
			else if(order.getCourier().equalsIgnoreCase(LAST_MILE)){
248
				t_order.setLogistics_provider_id(17);
249
			}
250
			else if(order.getCourier().equalsIgnoreCase(ECOMM_EXP)){
251
				t_order.setLogistics_provider_id(18);
252
			}
253
			else if(order.getCourier().equalsIgnoreCase(EWINGS)){
254
				t_order.setLogistics_provider_id(19);
255
			}
256
			else if(order.getCourier().equalsIgnoreCase(DTDC)){
257
				t_order.setLogistics_provider_id(20);
258
			}
259
			else if(order.getCourier().equalsIgnoreCase(WAREOLOG)){
260
				t_order.setLogistics_provider_id(21);
261
			}
262
			else if(order.getCourier().equalsIgnoreCase(MIRAKLE)){
263
				t_order.setLogistics_provider_id(22);
264
			}
265
			else if(order.getCourier().equalsIgnoreCase(RAJIV_TRANSPORT)){
266
				t_order.setLogistics_provider_id(23);
267
			}
268
			else if(order.getCourier().equalsIgnoreCase(BLUEDART_HIGH_VALUE)){
269
				t_order.setLogistics_provider_id(24);
270
			}
271
			else if(order.getCourier().equalsIgnoreCase(BLUEDART_SURFACE)){
272
				t_order.setLogistics_provider_id(25);
273
			}
274
			else if(order.getCourier().equalsIgnoreCase(BLUEDART_APEX)){
275
				t_order.setLogistics_provider_id(26);
276
			}
277
			else if(order.getCourier().equalsIgnoreCase(ARAMEX)){
278
				t_order.setLogistics_provider_id(27);
279
			}
280
			else if(order.getCourier().equalsIgnoreCase(GATI)){
281
				t_order.setLogistics_provider_id(28);
282
			}
283
			else if(order.getCourier().equalsIgnoreCase(INDIA_POST)){
284
				t_order.setLogistics_provider_id(29);
285
			}
286
			else if(order.getCourier().equalsIgnoreCase(FEDEX)){
287
				t_order.setLogistics_provider_id(30);
288
			}
289
			else if(order.getCourier().equalsIgnoreCase(IOT)){
290
				t_order.setLogistics_provider_id(31);
291
			}
292
			else if(order.getCourier().equalsIgnoreCase(RED_EXP)){
293
				t_order.setLogistics_provider_id(32);
294
			}
295
			else if(order.getCourier().equalsIgnoreCase(VDELIVER)){
296
				t_order.setLogistics_provider_id(33);
297
			}
298
			else if(order.getCourier().equalsIgnoreCase(GHARPAY)){
299
				t_order.setLogistics_provider_id(34);
300
			}
301
			else if(order.getCourier().equalsIgnoreCase(QUANTIUM)){
302
				t_order.setLogistics_provider_id(35);
303
			}
304
			else if(order.getCourier().equalsIgnoreCase(GATI_AIR)){
305
				t_order.setLogistics_provider_id(36);
306
			}
307
			else {
8652 vikram.rag 308
				logger.error("Error No Courier Match please add courier to our system for suborderid  " + order.getSuborderId() + "Courier Name " + order.getCourier());
8773 vikram.rag 309
				sb.append(order.getSuborderId() + " Error No Courier Match " + order.getCourier() +"\n");
8627 vikram.rag 310
				continue;
8616 vikram.rag 311
			}
8627 vikram.rag 312
 
8616 vikram.rag 313
			t_order.setAirwaybill_no(String.valueOf(order.getAWBNumber()));
314
			t_order.setTracking_id(String.valueOf(order.getAWBNumber()));
8739 vikram.rag 315
			t_order.setTotal_amount(SellingPrice);
8627 vikram.rag 316
			t_order.setOrderType(OrderType.B2C);
317
			t_order.setSource(SNAPDEAL_SOURCE_ID);
318
			t_order.setOrderType(OrderType.B2C);
319
			orderlist.add(t_order);
320
			txn.setOrders(orderlist);
8739 vikram.rag 321
			String referenceCode = order.getReferenceCode();
322
			String productName = order.getProduct();
323
			SimpleDateFormat istFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
324
			Date snapdealTxnDate = null;
325
			try {
326
				snapdealTxnDate = istFormatter.parse(order.getOrderPlacedDate());
327
			} catch (ParseException e) {
8773 vikram.rag 328
				logger.error(order.getSuborderId() + " Could not parse snapdeal order date from file " , e);
329
				sb.append(order.getSuborderId() + " Could not parse order date" +"\n");
8744 vikram.rag 330
				continue;
8739 vikram.rag 331
			}
332
			try {
333
				transactionId =  String.valueOf(transaction_client.createTransaction(txn));
334
			} catch (TransactionServiceException e) {
8773 vikram.rag 335
				logger.error(order.getSuborderId() + " Could not create transaction " , e);
336
				sb.append(order.getSuborderId() + " Could not create transaction" +"\n");
8744 vikram.rag 337
				continue;
8739 vikram.rag 338
			} catch (TException e) {
8773 vikram.rag 339
				logger.error("Problem with transaction service while creating transaction", e);
8775 vikram.rag 340
				sb.append(order.getSuborderId() + " Transaction Service Exception could not create transaction" +"\n");
8744 vikram.rag 341
				continue;
8739 vikram.rag 342
			}
343
			createPayment(user, (new Long(subOrderId)).toString(),lineItem.getTotal_price());
344
			Transaction transaction = null;
345
			try {
346
				transaction = transaction_client.getTransaction(Long.parseLong(transactionId));
347
			} catch (NumberFormatException e) {
348
				logger.error("Problem parsing transaction id " + transactionId);
8773 vikram.rag 349
				sb.append(order.getSuborderId() + " Problem parsing transaction id "+ transactionId +"\n");
8739 vikram.rag 350
				e.printStackTrace();
8744 vikram.rag 351
				continue;
8739 vikram.rag 352
			} catch (TransactionServiceException e) {
353
				logger.error("Problem getting transaction from service transaction id " + transactionId);
8773 vikram.rag 354
				sb.append(order.getSuborderId() + " Problem getting transaction id "+ transactionId +"\n");
8739 vikram.rag 355
				e.printStackTrace();
8744 vikram.rag 356
				continue;
8739 vikram.rag 357
			} catch (TException e) {
358
				logger.error("Problem with transaction service while getting transaction id " + transactionId);
8773 vikram.rag 359
				sb.append(order.getSuborderId() + " Problem with transaction service while getting transaction id "+ transactionId +"\n");
8739 vikram.rag 360
				e.printStackTrace();
8744 vikram.rag 361
				continue;
8739 vikram.rag 362
			}
363
			in.shop2020.model.v1.order.Order snapdealorder = transaction.getOrders().get(0);
8744 vikram.rag 364
			try {
365
				inventoryClient.reserveItemInWarehouse(lineItem.getItem_id(), fulfillmentWarehouse.getId(), 1, 
8773 vikram.rag 366
						snapdealorder.getId(), snapdealorder.getCreated_timestamp(), snapdealorder.getPromised_shipping_time(), snapdealorder.getLineitems().get(0).getQuantity());
8744 vikram.rag 367
			} catch (InventoryServiceException e1) {
368
				logger.error("Problem while reserving item in inventory service" + snapdealorder.getId());
8773 vikram.rag 369
				sb.append(order.getSuborderId() + " Could not reserve inventory for sku "+ order.getSKUCode() +"\n");
8744 vikram.rag 370
				continue;
371
			} catch (TException e1) {
372
				logger.error("Problem with inventory service" + snapdealorder.getId());
8773 vikram.rag 373
				sb.append(order.getSuborderId() + " Problem with inventory service while reserving inventory for sku "+ order.getSKUCode() +"\n");
8744 vikram.rag 374
				continue;
375
			}
8739 vikram.rag 376
			SnapdealOrder snapdealOrder = new SnapdealOrder();
377
			snapdealOrder.setOrderId(snapdealorder.getId());
378
			snapdealOrder.setSubOrderId(subOrderId);
379
			snapdealOrder.setReferenceCode(referenceCode);
380
			snapdealOrder.setProductName(productName);
381
			snapdealOrder.setSnapdealTxnDate(snapdealTxnDate.getTime());
382
			snapdealOrder.setListingPrice(order.getSellingPricePerItem());
383
			try {
384
				transaction_client.createSnapdealOrder(snapdealOrder);
385
			} catch (TException e) {
386
				logger.error("Could not create Snapdeal Order");
8773 vikram.rag 387
				sb.append(order.getSuborderId() + " Could not create snapdeal order"+"\n");
8739 vikram.rag 388
			}
8773 vikram.rag 389
			processed_orders++;
8789 vikram.rag 390
 
8773 vikram.rag 391
		}
392
		java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd-HH:mm:ss");
393
		Calendar cal=GregorianCalendar.getInstance();
394
		String emailFromAddress = "build@shop2020.in";
395
		String password = "cafe@nes";
396
		GmailUtils mailer = new GmailUtils();
397
		try {
8774 vikram.rag 398
			if(total_orders==processed_orders && total_orders > 0){
8773 vikram.rag 399
				String emailSubjectTxt = total_orders + " Snapdeal Orders Created Successfully "+sdf.format(cal.getTime());
400
				String text = "Order is now available for processing on Order Management Dashboard";
401
				String sendTo[] = new String[]{"vikram.raghav@shop2020.in"};
402
				//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"};
403
				mailer.sendSSLMessage(sendTo, emailSubjectTxt, text, emailFromAddress, password, new ArrayList<File>());
404
			}
8774 vikram.rag 405
			else if(total_orders > 0){
8773 vikram.rag 406
				int failed_orders = total_orders - processed_orders;
407
				String emailSubjectTxt = failed_orders + " Snapdeal Orders Failed while creation "+sdf.format(cal.getTime());
408
				String text = sb.toString();
409
				String sendTo[] = new String[]{"vikram.raghav@shop2020.in"};
410
				//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"};
411
				mailer.sendSSLMessage(sendTo, emailSubjectTxt, text, emailFromAddress, password, new ArrayList<File>());
412
			}
413
		}
414
		catch (Exception e) {
415
			e.printStackTrace();
416
		}
8627 vikram.rag 417
 
8616 vikram.rag 418
 
8773 vikram.rag 419
 
8616 vikram.rag 420
	}
421
 
8649 vikram.rag 422
	public static void createPayment(User user, String subOrderId, double amount) {
423
		in.shop2020.payments.PaymentService.Client client = null;
424
		try {
425
			client = new PaymentClient().getClient();
426
		} catch (TTransportException e) {
427
			logger.error("Could not connect to payment service ");
428
			e.printStackTrace();
429
		}
430
		long paymentId = 0;
431
		try {
432
			paymentId = client.createPayment(user.getUserId(), amount, SNAPDEAL_GATEWAY_ID, Long.valueOf(transactionId), false);
433
		} catch (NumberFormatException e) {
434
			logger.error("Could not create payment");
435
			e.printStackTrace();
436
		} catch (PaymentException e) {
437
			logger.error("Could not create payment payment exception");
438
			e.printStackTrace();
439
		} catch (TException e) {
440
			logger.error("Could not create payment thrift exception");
441
			e.printStackTrace();
442
		}
443
		try {
444
			client.updatePaymentDetails(paymentId, null, null, null, null, null, null, subOrderId, null, PaymentStatus.AUTHORIZED, null, null);
445
		} catch (PaymentException e) {
446
			logger.error("Could not update payment to order");
447
			e.printStackTrace();
448
		} catch (TException e) {
449
			logger.error("Could not update payment thrift exception");
450
			e.printStackTrace();
451
		}
8627 vikram.rag 452
	}   
453
 
8616 vikram.rag 454
	public static LineItem createLineItem(long itemId, double amount) throws CatalogServiceException, TException {
8627 vikram.rag 455
		LineItem lineItem = new LineItem();
456
		CatalogService.Client catalogClient = new CatalogClient().getClient();
457
		Item item = catalogClient.getItem(itemId);
8773 vikram.rag 458
		if(item.getId()==0){
459
			//in case item id is incorrect..
460
			return null;
461
		}
8616 vikram.rag 462
 
8627 vikram.rag 463
		lineItem.setProductGroup(item.getProductGroup());
464
		lineItem.setBrand(item.getBrand());
465
		lineItem.setModel_number(item.getModelNumber());
466
		lineItem.setModel_name(item.getModelName());
467
		lineItem.setExtra_info(item.getFeatureDescription());
468
		lineItem.setQuantity(1);
469
		lineItem.setItem_id(item.getId());
470
		lineItem.setUnit_weight(item.getWeight());
471
		lineItem.setTotal_weight(item.getWeight());
472
		lineItem.setUnit_price(amount);
473
		lineItem.setTotal_price(amount);
474
 
8739 vikram.rag 475
		if (item.getColor() == null || "NA".equals(item.getColor())) {
8627 vikram.rag 476
			lineItem.setColor("");
477
		} else {
478
			lineItem.setColor(item.getColor());
479
		}
480
		return lineItem;
8616 vikram.rag 481
	}
482
 
483
}