Subversion Repositories SmartDukaan

Rev

Rev 8616 | Rev 8642 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 8616 Rev 8627
Line 44... Line 44...
44
import order.SaholicAPI;
44
import order.SaholicAPI;
45
import order.ObjectFactory;
45
import order.ObjectFactory;
46
import order.SaholicAPI.Order;
46
import order.SaholicAPI.Order;
47
 
47
 
48
public class ProcessSnapdealOrder {
48
public class ProcessSnapdealOrder {
-
 
49
	//private static final int SNAPDEAL_SOURCE_ID = 3;
49
	private static final int SNAPDEAL_SOURCE_ID = 7;
50
	private static final int SNAPDEAL_SOURCE_ID = 7;
50
	private static final String FIRSTFLIGHT = "First Flight";
51
	private static final String FIRSTFLIGHT = "First Flight";
51
    private static final String DELHIVERY = "DELHIVERY";
52
	private static final String DELHIVERY = "DELHIVERY";
52
    private static final String BLUEDART = "Bluedart";
53
	private static final String BLUEDART = "Bluedart";
53
    private static String transactionId;
54
	private static String transactionId;
54
    private static final int SNAPDEAL_GATEWAY_ID = 18;
55
	private static final int SNAPDEAL_GATEWAY_ID = 18;
55
    
56
 
56
	public static void processSnapdealOrders(File file) throws JAXBException{
57
	public static void processSnapdealOrders(File file) throws JAXBException{
57
		JAXBContext jc = JAXBContext.newInstance(SaholicAPI.class);
58
		JAXBContext jc = JAXBContext.newInstance(SaholicAPI.class);
58
		Unmarshaller unmarshaller = jc.createUnmarshaller();
59
		Unmarshaller unmarshaller = jc.createUnmarshaller();
59
		SaholicAPI orders = (SaholicAPI) unmarshaller.unmarshal(file);
60
		SaholicAPI orders = (SaholicAPI) unmarshaller.unmarshal(file);
60
		Marshaller marshaller = jc.createMarshaller();
61
		Marshaller marshaller = jc.createMarshaller();
61
		marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
62
		marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
62
		marshaller.marshal(orders, System.out);
63
		marshaller.marshal(orders, System.out);
63
 
-
 
64
		SourceDetail sourceDetail = null;
64
		SourceDetail sourceDetail = null;
65
		User user = null;
65
		User user = null;
66
		TransactionClient tsc = null;
66
		TransactionClient tsc = null;
67
		try {
67
		try {
68
			tsc = new TransactionClient();
68
			tsc = new TransactionClient();
Line 73... Line 73...
73
			in.shop2020.model.v1.user.UserContextService.Client userClient = new UserClient().getClient();
73
			in.shop2020.model.v1.user.UserContextService.Client userClient = new UserClient().getClient();
74
			user = userClient.getUserByEmail(sourceDetail.getEmail());
74
			user = userClient.getUserByEmail(sourceDetail.getEmail());
75
		} catch (Exception e) {
75
		} catch (Exception e) {
76
		}
76
		}
77
		for(Order order:orders.getOrder()){
77
		for(Order order:orders.getOrder()){
-
 
78
			long subOrderId = (long) order.getSuborderId();
-
 
79
			Client transaction_client = null;
-
 
80
			try {
-
 
81
				transaction_client = new TransactionClient().getClient();
-
 
82
				//transaction_client.snapdealOrderExists(subOrderId);
-
 
83
				System.out.println("Suborder id " + subOrderId);
-
 
84
				if(transaction_client.snapdealOrderExists(subOrderId)) {
-
 
85
					System.out.println("Suborder id exists");
-
 
86
					continue;
-
 
87
				}
-
 
88
 
-
 
89
			} catch (TTransportException e1) {
-
 
90
				// TODO Auto-generated catch block
-
 
91
				e1.printStackTrace();
-
 
92
			} catch (TException e) {
-
 
93
				// TODO Auto-generated catch block
-
 
94
				e.printStackTrace();
-
 
95
			}
-
 
96
			System.out.println("Inside Order Parsing");
78
			Transaction txn = new Transaction();
97
			Transaction txn = new Transaction();
-
 
98
			System.out.println("User details are " + user.getActiveCartId());
79
			txn.setShoppingCartid(user.getActiveCartId());
99
			txn.setShoppingCartid(user.getActiveCartId());
-
 
100
			System.out.println("transaction created");
80
			txn.setCustomer_id(user.getUserId());
101
			txn.setCustomer_id(user.getUserId());
-
 
102
			System.out.println("User Id is " + user.getUserId());
81
			txn.setCreatedOn(new Date().getTime());
103
			txn.setCreatedOn(new Date().getTime());
82
			txn.setTransactionStatus(TransactionStatus.INIT);
104
			txn.setTransactionStatus(TransactionStatus.INIT);
83
			txn.setStatusDescription("Order for Snapdeal ");
105
			txn.setStatusDescription("Order for Snapdeal ");
84
			List<in.shop2020.model.v1.order.Order> orderlist = new ArrayList<in.shop2020.model.v1.order.Order>();
106
			List<in.shop2020.model.v1.order.Order> orderlist = new ArrayList<in.shop2020.model.v1.order.Order>();
85
			LineItem lineItem = null;
107
			LineItem lineItem = null;
86
			try {
108
			try {
87
				lineItem = createLineItem(order.getSKUCode(),order.getSellingPricePerItem());
109
				lineItem = createLineItem(order.getSKUCode(),order.getSellingPricePerItem());
-
 
110
				System.out.println("Line item created");
88
			} catch (CatalogServiceException e) {
111
			} catch (CatalogServiceException e) {
89
				// TODO Auto-generated catch block
112
				// TODO Auto-generated catch block
90
				e.printStackTrace();
113
				e.printStackTrace();
91
			} catch (TException e) {
114
			} catch (TException e) {
92
				// TODO Auto-generated catch block
115
				// TODO Auto-generated catch block
93
				e.printStackTrace();
116
				e.printStackTrace();
94
			}
117
			}
95
			in.shop2020.model.v1.order.Order t_order = new in.shop2020.model.v1.order.Order();
118
			in.shop2020.model.v1.order.Order t_order = new in.shop2020.model.v1.order.Order();
96
            t_order.setCustomer_id(user.getUserId());
119
			t_order.setCustomer_id(user.getUserId());
97
            t_order.setCustomer_email(sourceDetail.getEmail());
120
			t_order.setCustomer_email(sourceDetail.getEmail());
98
        	t_order.setCustomer_name(order.getCustomerName());
121
			t_order.setCustomer_name(order.getCustomerName());
99
        	t_order.setCustomer_address1("");
122
			t_order.setCustomer_address1("");
100
        	t_order.setCustomer_address2("");
123
			t_order.setCustomer_address2("");
101
        	t_order.setCustomer_city(order.getCity());
124
			t_order.setCustomer_city(order.getCity());
102
        	t_order.setCustomer_state(order.getState());
125
			t_order.setCustomer_state(order.getState());
103
        	t_order.setCustomer_pincode(String.valueOf(order.getPINCode()));
126
			t_order.setCustomer_pincode(String.valueOf(order.getPINCode()));
104
            t_order.setTotal_amount(lineItem.getTotal_price());            
127
			t_order.setTotal_amount(lineItem.getTotal_price());            
105
            t_order.setTotal_weight(lineItem.getTotal_weight());
128
			t_order.setTotal_weight(lineItem.getTotal_weight());
106
            t_order.setLineitems(Collections.singletonList(lineItem));            
129
			t_order.setLineitems(Collections.singletonList(lineItem));            
107
            t_order.setStatus(OrderStatus.SUBMITTED_FOR_PROCESSING);
130
			t_order.setStatus(OrderStatus.SUBMITTED_FOR_PROCESSING);
108
            t_order.setStatusDescription("In Process");
131
			t_order.setStatusDescription("In Process");
109
            t_order.setCreated_timestamp(new Date().getTime());
132
			t_order.setCreated_timestamp(new Date().getTime());
110
            t_order.setOrderType(OrderType.B2C);
133
			t_order.setOrderType(OrderType.B2C);
111
            t_order.setCod(false);
134
			t_order.setCod(false);
-
 
135
			System.out.println("t order created");
112
            try {
136
			try {
113
            	Calendar time = Calendar.getInstance();
137
				Calendar time = Calendar.getInstance();
114
            	time.add(Calendar.DAY_OF_MONTH, 1);
138
				time.add(Calendar.DAY_OF_MONTH, 1);
115
            	t_order.setPromised_shipping_time(time.getTimeInMillis());
139
				t_order.setPromised_shipping_time(time.getTimeInMillis());
116
            	t_order.setExpected_shipping_time(time.getTimeInMillis());
140
				t_order.setExpected_shipping_time(time.getTimeInMillis());
117
            	time.add(Calendar.DAY_OF_MONTH, 3);
141
				time.add(Calendar.DAY_OF_MONTH, 3);
118
            	t_order.setPromised_delivery_time(time.getTimeInMillis());
142
				t_order.setPromised_delivery_time(time.getTimeInMillis());
119
            	t_order.setExpected_delivery_time(time.getTimeInMillis());
143
				t_order.setExpected_delivery_time(time.getTimeInMillis());
-
 
144
				System.out.println("Dates set in transaction");
120
            } catch(Exception e) {
145
			} catch(Exception e) {
121
            	continue;
146
				continue;
122
            }
147
			}
123
            InventoryService.Client inventoryClient = null;
148
			/*InventoryService.Client inventoryClient = null;
124
            Warehouse fulfillmentWarehouse= null; 
149
            //Warehouse fulfillmentWarehouse= null; 
125
            try {
150
            try {
126
            	inventoryClient = new InventoryClient().getClient();
151
            	//inventoryClient = new InventoryClient().getClient();
127
        		VendorItemPricing vendorItemPricing = inventoryClient.getItemPricing(lineItem.getItem_id(), fulfillmentWarehouse.getVendor().getId());
152
        		//VendorItemPricing vendorItemPricing = inventoryClient.getItemPricing(lineItem.getItem_id(), fulfillmentWarehouse.getVendor().getId());
128
        		t_order.getLineitems().get(0).setTransfer_price(vendorItemPricing.getTransferPrice());
153
        		//t_order.getLineitems().get(0).setTransfer_price(vendorItemPricing.getTransferPrice());
129
        		t_order.getLineitems().get(0).setNlc(vendorItemPricing.getNlc());
154
        		//t_order.getLineitems().get(0).setNlc(vendorItemPricing.getNlc());
130
			} catch (InventoryServiceException e) {
155
			} catch (InventoryServiceException e) {
131
            	continue;
156
            	continue;
132
			} catch (TTransportException e) {
157
			} catch (TTransportException e) {
133
				// TODO Auto-generated catch block
158
				// TODO Auto-generated catch block
134
				e.printStackTrace();
159
				e.printStackTrace();
135
			} catch (TException e) {
160
			} catch (TException e) {
136
				// TODO Auto-generated catch block
161
				// TODO Auto-generated catch block
137
				e.printStackTrace();
162
				e.printStackTrace();
138
			}
163
			}*/
139
			if(order.getCourier().equalsIgnoreCase(FIRSTFLIGHT)) {
164
			if(order.getCourier().equalsIgnoreCase(FIRSTFLIGHT)) {
140
				t_order.setLogistics_provider_id(12);
165
				t_order.setLogistics_provider_id(12);
141
			} else if(order.getCourier().equalsIgnoreCase(DELHIVERY)) {
166
			} else if(order.getCourier().equalsIgnoreCase(DELHIVERY)) {
142
				t_order.setLogistics_provider_id(13);
167
				t_order.setLogistics_provider_id(13);
143
			} else if(order.getCourier().equalsIgnoreCase(BLUEDART)) {
168
			} else if(order.getCourier().equalsIgnoreCase(BLUEDART)) {
144
				t_order.setLogistics_provider_id(14);
169
				t_order.setLogistics_provider_id(14);
145
			} else {
170
			} else {
-
 
171
				System.out.println("No Courier Match");
146
            	continue;
172
				continue;
147
			}
173
			}
148
			
174
 
149
			t_order.setAirwaybill_no(String.valueOf(order.getAWBNumber()));
175
			t_order.setAirwaybill_no(String.valueOf(order.getAWBNumber()));
150
			t_order.setTracking_id(String.valueOf(order.getAWBNumber()));
176
			t_order.setTracking_id(String.valueOf(order.getAWBNumber()));
151
            t_order.setTotal_amount(order.getSellingPricePerItem());
177
			t_order.setTotal_amount(order.getSellingPricePerItem());
152
            t_order.setOrderType(OrderType.B2C);
178
			t_order.setOrderType(OrderType.B2C);
153
            t_order.setSource(SNAPDEAL_SOURCE_ID);
179
			t_order.setSource(SNAPDEAL_SOURCE_ID);
154
            t_order.setOrderType(OrderType.B2C);
180
			t_order.setOrderType(OrderType.B2C);
155
            orderlist.add(t_order);
181
			orderlist.add(t_order);
156
            txn.setOrders(orderlist);
182
			txn.setOrders(orderlist);
157
            
-
 
158
            
-
 
159
            Client transaction_client = null;
-
 
160
			try {
183
			try {
161
				transaction_client = new TransactionClient().getClient();
-
 
162
			} catch (TTransportException e1) {
-
 
163
				// TODO Auto-generated catch block
-
 
164
				e1.printStackTrace();
-
 
165
			}
-
 
166
            try {
-
 
167
            	long subOrderId = order.getSuborderId();
-
 
168
            	String referenceCode = order.getReferenceCode();
184
				String referenceCode = order.getReferenceCode();
169
            	String productName = order.getProduct();
185
				String productName = order.getProduct();
-
 
186
				SimpleDateFormat istFormatter = new SimpleDateFormat("dd/mm/yyyy");
170
				SimpleDateFormat istFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
187
				//SimpleDateFormat istFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
171
				Date snapdealTxnDate = istFormatter.parse(order.getOrderPlacedDate());
188
				Date snapdealTxnDate = istFormatter.parse(order.getOrderPlacedDate());
172
            	if(transaction_client.snapdealOrderExists(subOrderId)) {
-
 
173
            		continue;
-
 
174
            	}
-
 
175
            	transactionId =  String.valueOf(transaction_client.createTransaction(txn));
189
				transactionId =  String.valueOf(transaction_client.createTransaction(txn));
176
            	createPayment(user, (new Long(subOrderId)).toString(), lineItem.getTotal_price());
190
				createPayment(user, (new Long(subOrderId)).toString(), lineItem.getTotal_price());
177
                
191
 
178
                Transaction transaction = transaction_client.getTransaction(Long.parseLong(transactionId));
192
				Transaction transaction = transaction_client.getTransaction(Long.parseLong(transactionId));
179
                in.shop2020.model.v1.order.Order snapdealorder = transaction.getOrders().get(0);
193
				in.shop2020.model.v1.order.Order snapdealorder = transaction.getOrders().get(0);
180
                
194
 
181
                inventoryClient.reserveItemInWarehouse(lineItem.getItem_id(), fulfillmentWarehouse.getId(), 1, 
195
				//inventoryClient.reserveItemInWarehouse(lineItem.getItem_id(), fulfillmentWarehouse.getId(), 1, 
182
                		snapdealorder.getId(), snapdealorder.getCreated_timestamp(), snapdealorder.getPromised_shipping_time(), snapdealorder.getLineitems().get(0).getQuantity());
196
				//		snapdealorder.getId(), snapdealorder.getCreated_timestamp(), snapdealorder.getPromised_shipping_time(), snapdealorder.getLineitems().get(0).getQuantity());
183
                
197
 
184
                
198
 
185
                SnapdealOrder snapdealOrder = new SnapdealOrder();
199
				SnapdealOrder snapdealOrder = new SnapdealOrder();
186
                snapdealOrder.setOrderId(snapdealorder.getId());
200
				snapdealOrder.setOrderId(snapdealorder.getId());
187
                snapdealOrder.setSubOrderId(subOrderId);
201
				snapdealOrder.setSubOrderId(subOrderId);
188
                snapdealOrder.setReferenceCode(referenceCode);
202
				snapdealOrder.setReferenceCode(referenceCode);
189
                snapdealOrder.setProductName(productName);
203
				snapdealOrder.setProductName(productName);
190
                snapdealOrder.setSnapdealTxnDate(snapdealTxnDate.getTime());
204
				snapdealOrder.setSnapdealTxnDate(snapdealTxnDate.getTime());
191
                snapdealOrder.setListingPrice(lineItem.getTotal_price());
205
				snapdealOrder.setListingPrice(lineItem.getTotal_price());
192
                transaction_client.createSnapdealOrder(snapdealOrder);
206
				transaction_client.createSnapdealOrder(snapdealOrder);
-
 
207
 
193
                
208
			} catch (Exception e) {
194
            } catch (Exception e) {
209
				System.out.println("Exception in finding suborderid");
195
                continue;
210
				continue;
196
    		}
211
			}
197
            
212
 
198
            
213
 
199
		}
214
		}
200
 
215
 
201
	}
216
	}
202
 
217
 
203
	public static void createPayment(User user, String subOrderId, double amount) throws NumberFormatException, PaymentException, TException {
218
	public static void createPayment(User user, String subOrderId, double amount) throws NumberFormatException, PaymentException, TException {
204
        in.shop2020.payments.PaymentService.Client client = new PaymentClient().getClient();
219
		in.shop2020.payments.PaymentService.Client client = new PaymentClient().getClient();
205
        long paymentId = client.createPayment(user.getUserId(), amount, SNAPDEAL_GATEWAY_ID, Long.valueOf(transactionId), false);
220
		long paymentId = client.createPayment(user.getUserId(), amount, SNAPDEAL_GATEWAY_ID, Long.valueOf(transactionId), false);
206
        client.updatePaymentDetails(paymentId, null, null, null, null, null, null, subOrderId, null, PaymentStatus.AUTHORIZED, null, null);
221
		client.updatePaymentDetails(paymentId, null, null, null, null, null, null, subOrderId, null, PaymentStatus.AUTHORIZED, null, null);
207
    }   
222
	}   
208
    	
223
 
209
	public static LineItem createLineItem(long itemId, double amount) throws CatalogServiceException, TException {
224
	public static LineItem createLineItem(long itemId, double amount) throws CatalogServiceException, TException {
210
    	LineItem lineItem = new LineItem();
225
		LineItem lineItem = new LineItem();
211
    	CatalogService.Client catalogClient = new CatalogClient().getClient();
226
		CatalogService.Client catalogClient = new CatalogClient().getClient();
212
    	Item item = catalogClient.getItem(itemId);
227
		Item item = catalogClient.getItem(itemId);
213
    	
228
 
214
    	lineItem.setProductGroup(item.getProductGroup());
229
		lineItem.setProductGroup(item.getProductGroup());
215
        lineItem.setBrand(item.getBrand());
230
		lineItem.setBrand(item.getBrand());
216
        lineItem.setModel_number(item.getModelNumber());
231
		lineItem.setModel_number(item.getModelNumber());
217
        lineItem.setModel_name(item.getModelName());
232
		lineItem.setModel_name(item.getModelName());
218
        lineItem.setExtra_info(item.getFeatureDescription());
233
		lineItem.setExtra_info(item.getFeatureDescription());
219
        lineItem.setQuantity(1);
234
		lineItem.setQuantity(1);
220
        lineItem.setItem_id(item.getId());
235
		lineItem.setItem_id(item.getId());
221
        lineItem.setUnit_weight(item.getWeight());
236
		lineItem.setUnit_weight(item.getWeight());
222
        lineItem.setTotal_weight(item.getWeight());
237
		lineItem.setTotal_weight(item.getWeight());
223
        lineItem.setUnit_price(amount);
238
		lineItem.setUnit_price(amount);
224
        lineItem.setTotal_price(amount);
239
		lineItem.setTotal_price(amount);
225
 
240
 
226
        if (item.getColor() == null || "NA".equals(item.getColor())) {
241
		if (item.getColor() == null || "NA".equals(item.getColor())) {
227
            lineItem.setColor("");
242
			lineItem.setColor("");
228
        } else {
243
		} else {
229
            lineItem.setColor(item.getColor());
244
			lineItem.setColor(item.getColor());
230
        }
245
		}
231
    	return lineItem;
246
		return lineItem;
232
	}
247
	}
233
 
248
 
234
}
249
}