Subversion Repositories SmartDukaan

Rev

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

Rev 8606 Rev 8824
Line 54... Line 54...
54
import java.io.FileWriter;
54
import java.io.FileWriter;
55
import java.io.IOException;
55
import java.io.IOException;
56
import java.io.InputStream;
56
import java.io.InputStream;
57
import java.text.SimpleDateFormat;
57
import java.text.SimpleDateFormat;
58
import java.util.ArrayList;
58
import java.util.ArrayList;
-
 
59
import java.util.Arrays;
59
import java.util.Calendar;
60
import java.util.Calendar;
60
import java.util.Collections;
61
import java.util.Collections;
61
import java.util.Date;
62
import java.util.Date;
62
import java.util.HashMap;
63
import java.util.HashMap;
63
import java.util.HashSet;
64
import java.util.HashSet;
Line 72... Line 73...
72
 
73
 
73
import net.htmlparser.jericho.Source;
74
import net.htmlparser.jericho.Source;
74
 
75
 
75
import org.apache.commons.lang.StringUtils;
76
import org.apache.commons.lang.StringUtils;
76
import org.apache.log4j.Logger;
77
import org.apache.log4j.Logger;
-
 
78
import org.apache.shiro.SecurityUtils;
-
 
79
import org.apache.struts2.convention.annotation.Result;
-
 
80
import org.apache.struts2.convention.annotation.Results;
77
import org.apache.thrift.TException;
81
import org.apache.thrift.TException;
78
import org.apache.thrift.transport.TTransportException;
82
import org.apache.thrift.transport.TTransportException;
79
 
83
 
80
import com.ShipWebServiceClient;
84
import com.ShipWebServiceClient;
81
import com.fedex.ship.stub.CompletedPackageDetail;
85
import com.fedex.ship.stub.CompletedPackageDetail;
Line 103... Line 107...
103
	private List<Payment>        payments;
107
	private List<Payment>        payments;
104
	private List<ShipmentUpdate> shipmentUpdates = new ArrayList<ShipmentUpdate>();
108
	private List<ShipmentUpdate> shipmentUpdates = new ArrayList<ShipmentUpdate>();
105
	private Long                 codTicketId;
109
	private Long                 codTicketId;
106
	private List<Address>        addresses;
110
	private List<Address>        addresses;
107
	private Set<OrderStatus>     setOfcancellableStates;
111
	private Set<OrderStatus>     setOfcancellableStates;
-
 
112
	//Start:- Added by Manish Sharma for Physical Refunds 
-
 
113
	private Set<OrderStatus>	 setOfrefundableStates;
-
 
114
	//End:- Added by Manish Sharma for Physical Refunds
108
	private String               cancellationInitiator;
115
	private String               cancellationInitiator;
109
	private String               cancelReason;
116
	private String               cancelReason;
110
	private String               body;
117
	private String               body;
111
	private String               line1;
118
	private String               line1;
112
	private String               line2;
119
	private String               line2;
Line 123... Line 130...
123
    //Start:- Added by Manish Sharma for Displaying Logistics Provider Id and Amazon Order Id on 25-Jul-2013
130
    //Start:- Added by Manish Sharma for Displaying Logistics Provider Id and Amazon Order Id on 25-Jul-2013
124
    private AmazonOrder          amazonOrder = null;
131
    private AmazonOrder          amazonOrder = null;
125
    private String               providerName = "N/A";
132
    private String               providerName = "N/A";
126
    //End:- Added by Manish Sharma for Displaying Logistics Provider Id and Amazon Order Id on 25-Jul-2013
133
    //End:- Added by Manish Sharma for Displaying Logistics Provider Id and Amazon Order Id on 25-Jul-2013
127
    private long				 gvAmount;
134
    private long				 gvAmount;
-
 
135
    //Start:- Added by Manish Sharma for Physical Refunds 
-
 
136
    private String               rfdRadio;
-
 
137
    private String         	     couponDetails;
-
 
138
    private String               refundAmountCoupon;
-
 
139
    private String               chequeDetails;
-
 
140
    private String               refundAmountCheque;
-
 
141
    private String 			     refundAmountGateway;
-
 
142
    private String			     comments;
-
 
143
    
-
 
144
    private String 				 errorMsg = "";
-
 
145
	private String 				 successmsg = "";
-
 
146
	//End:- Added by Manish Sharma for Physical Refunds 
128
 
147
 
129
	public UserOrderInfoController() {
148
	public UserOrderInfoController() {
130
		super();
149
		super();
131
		setOfcancellableStates = new HashSet<OrderStatus>();
150
		setOfcancellableStates = new HashSet<OrderStatus>();
132
		setOfcancellableStates.add(OrderStatus.SUBMITTED_FOR_PROCESSING);
151
		setOfcancellableStates.add(OrderStatus.SUBMITTED_FOR_PROCESSING);
Line 134... Line 153...
134
		setOfcancellableStates.add(OrderStatus.LOW_INV_PO_RAISED);
153
		setOfcancellableStates.add(OrderStatus.LOW_INV_PO_RAISED);
135
		setOfcancellableStates.add(OrderStatus.LOW_INV_REVERSAL_IN_PROCESS);
154
		setOfcancellableStates.add(OrderStatus.LOW_INV_REVERSAL_IN_PROCESS);
136
		setOfcancellableStates.add(OrderStatus.LOW_INV_NOT_AVAILABLE_AT_HOTSPOT);
155
		setOfcancellableStates.add(OrderStatus.LOW_INV_NOT_AVAILABLE_AT_HOTSPOT);
137
		setOfcancellableStates.add(OrderStatus.ACCEPTED);
156
		setOfcancellableStates.add(OrderStatus.ACCEPTED);
138
		setOfcancellableStates.add(OrderStatus.BILLED);
157
		setOfcancellableStates.add(OrderStatus.BILLED);
-
 
158
		
-
 
159
		//Start:- Added by Manish Sharma for Physical Refunds 
-
 
160
		setOfrefundableStates = new HashSet<OrderStatus>();
-
 
161
		setOfrefundableStates.add(OrderStatus.RTO_REFUNDED);
-
 
162
		setOfrefundableStates.add(OrderStatus.DOA_VALID_REFUNDED);
-
 
163
		setOfrefundableStates.add(OrderStatus.DOA_INVALID_REFUNDED);
-
 
164
		setOfrefundableStates.add(OrderStatus.DOA_REFUNDED_RCVD_DAMAGED);
-
 
165
		setOfrefundableStates.add(OrderStatus.DOA_REFUNDED_LOST_IN_TRANSIT);
-
 
166
		setOfrefundableStates.add(OrderStatus.RTO_DAMAGED_REFUNDED);
-
 
167
		setOfrefundableStates.add(OrderStatus.RTO_LOST_IN_TRANSIT_REFUNDED);
-
 
168
		setOfrefundableStates.add(OrderStatus.RET_PRODUCT_USABLE_REFUNDED);
-
 
169
		setOfrefundableStates.add(OrderStatus.RET_PRODUCT_UNUSABLE_REFUNDED);
-
 
170
		setOfrefundableStates.add(OrderStatus.RET_REFUNDED_RCVD_DAMAGED);
-
 
171
		setOfrefundableStates.add(OrderStatus.RET_REFUNDED_LOST_IN_TRANSIT);
-
 
172
		setOfrefundableStates.add(OrderStatus.LOST_IN_TRANSIT_REFUNDED);
-
 
173
		//End:- Added by Manish Sharma for Physical Refunds 
-
 
174
		
-
 
175
		
139
	}
176
	}
140
	
177
	
141
	public static final Map<Long, String> providerNameMap = new HashMap<Long, String>() {
178
	public static final Map<Long, String> providerNameMap = new HashMap<Long, String>() {
142
        {
179
        {
143
            put(1l, "BlueDart");
180
            put(1l, "BlueDart");
Line 154... Line 191...
154
		try {
191
		try {
155
			PaymentClient paymentServiceClient = new PaymentClient();
192
			PaymentClient paymentServiceClient = new PaymentClient();
156
			TransactionClient transactionServiceClient = new TransactionClient();
193
			TransactionClient transactionServiceClient = new TransactionClient();
157
			LogisticsClient logisticsServiceClient = new LogisticsClient();
194
			LogisticsClient logisticsServiceClient = new LogisticsClient();
158
			
195
			
-
 
196
			/*List<Provider> providerList = logisticsServiceClient.getClient().getAllProviders();
-
 
197
			Map<Long, String> providerNameMap = new HashMap<Long, String>();
-
 
198
			for(Provider provider : providerList){
-
 
199
				providerNameMap.put(provider.getId(), provider.getName());
-
 
200
			}*/
159
			order = transactionServiceClient.getClient().getOrder(orderId);
201
			order = transactionServiceClient.getClient().getOrder(orderId);
160
			//Start:- Added by Manish Sharma for Displaying Logistics Provider Id and Amazon Order Id on 25-Jul-2013
202
			//Start:- Added by Manish Sharma for Displaying Logistics Provider Id and Amazon Order Id on 25-Jul-2013
161
			try {
203
			try {
162
			    amazonOrder = transactionServiceClient.getClient().getAmazonOrder(orderId);
204
			    amazonOrder = transactionServiceClient.getClient().getAmazonOrder(orderId);
163
			} catch (Exception e) {
205
			} catch (Exception e) {
Line 255... Line 297...
255
			log.error("Thread was interrupted", e);
297
			log.error("Thread was interrupted", e);
256
		} catch (UserContextException e) {
298
		} catch (UserContextException e) {
257
			log.error("Unable to get addresses for user : " + order.getCustomer_id(), e);
299
			log.error("Unable to get addresses for user : " + order.getCustomer_id(), e);
258
		} catch(CatalogServiceException csex) {
300
		} catch(CatalogServiceException csex) {
259
			log.error("Unable to get item details for itemId: " + order.getFreebieItemId(), csex);
301
			log.error("Unable to get item details for itemId: " + order.getFreebieItemId(), csex);
-
 
302
		} /*catch (LogisticsServiceException lsex) {
-
 
303
			log.error("Unable to get providers infromation: " , lsex);
260
		}
304
		}*/
261
		return INDEX;
305
		return INDEX;
262
	}
306
	}
263
 
307
 
264
	private boolean canEditOrderAddress() {
308
	private boolean canEditOrderAddress() {
265
		return false;
309
		return false;
Line 611... Line 655...
611
				break;
655
				break;
612
			}
656
			}
613
		}
657
		}
614
		return paymentMethod != null ? paymentMethod : "N/A";
658
		return paymentMethod != null ? paymentMethod : "N/A";
615
	}
659
	}
-
 
660
	//Start:- Added by Manish Sharma for Physical Refunds 
-
 
661
	public String refundOrderPayment(){
-
 
662
		try{
-
 
663
			TransactionClient transactionServiceClient = new TransactionClient();
-
 
664
			in.shop2020.model.v1.order.TransactionService.Client transactionClient
-
 
665
		    = transactionServiceClient.getClient();
-
 
666
			
-
 
667
			in.shop2020.model.v1.order.Order t_order = transactionClient.getOrder(orderId);
-
 
668
			List<in.shop2020.model.v1.order.Attribute> attrList = new ArrayList<in.shop2020.model.v1.order.Attribute>();
-
 
669
			in.shop2020.model.v1.order.Attribute attr1 = new in.shop2020.model.v1.order.Attribute();
-
 
670
			attr1.setName("Refund_Option");
-
 
671
			in.shop2020.model.v1.order.Attribute attr2 = new in.shop2020.model.v1.order.Attribute();
-
 
672
			attr2.setName("Refund_Amount");
-
 
673
			PaymentClient paymentServiceClient = new PaymentClient();
-
 
674
			List<Payment> orderPayments =null; 
-
 
675
			if(!t_order.isCod()){
-
 
676
				orderPayments =paymentServiceClient.getClient()
-
 
677
					.getPaymentForTxnId(t_order.getTransactionId());
-
 
678
			}
-
 
679
			
-
 
680
			if(rfdRadio.equalsIgnoreCase("rfdCoupon")){
-
 
681
				if((couponDetails!=null && !("").equalsIgnoreCase(couponDetails)) || (refundAmountCoupon!=null &&!("").equalsIgnoreCase(refundAmountCoupon))){
-
 
682
					if(Double.parseDouble(refundAmountCoupon) <= t_order.getTotal_amount()){
-
 
683
						log.info(Double.parseDouble(refundAmountCoupon));
-
 
684
						log.info(t_order.getTotal_amount());
-
 
685
						attr1.setValue("Refund By Coupon: "+couponDetails);
-
 
686
						attrList.add(attr1);
-
 
687
						attr2.setValue(refundAmountCoupon);
-
 
688
						attrList.add(attr2);
-
 
689
						transactionClient.setOrderAttributes(t_order.getId(), attrList);
-
 
690
						successmsg = "Refund Marked Successful: Through Coupon";
-
 
691
						return "physical-refund-result";
-
 
692
					}
-
 
693
				}
-
 
694
				else{
-
 
695
					errorMsg ="Refund Unsuccessful: Due to either coupon details or refund amount is blank ";
-
 
696
					return "physical-refund-result";
-
 
697
				}
-
 
698
				errorMsg ="Refund Unsuccessful: Due to coupon amount greater than order total amount ";
-
 
699
			}
-
 
700
			if(rfdRadio.equalsIgnoreCase("rfdCheque")){
-
 
701
				if((chequeDetails!=null && !("").equalsIgnoreCase(chequeDetails)) || (refundAmountCheque!=null &&!("").equalsIgnoreCase(refundAmountCheque))){
-
 
702
					if(Double.parseDouble(refundAmountCheque) <= t_order.getTotal_amount()){
-
 
703
						attr1.setValue("Refund By Cheque: "+chequeDetails);
-
 
704
						attrList.add(attr1);
-
 
705
						attr2.setValue(refundAmountCheque);
-
 
706
						attrList.add(attr2);
-
 
707
						transactionClient.setOrderAttributes(t_order.getId(), attrList);
-
 
708
						successmsg = "Refund Marked Successful: Through Cheque";
-
 
709
						return "physical-refund-result";
-
 
710
					}
-
 
711
				}
-
 
712
				else{
-
 
713
					errorMsg ="Refund Unsuccessful: Due to either cheque details or refund amount is blank ";
-
 
714
					return "physical-refund-result";
-
 
715
				}
-
 
716
				errorMsg ="Refund Unsuccessful: Due to cheque amount greater than order total amount ";
-
 
717
			}
-
 
718
			if(rfdRadio.equalsIgnoreCase("rfdGateway")){
-
 
719
				if((comments!=null && !("").equalsIgnoreCase(comments)) || (refundAmountGateway!=null &&!("").equalsIgnoreCase(refundAmountGateway))){
-
 
720
					if(Double.parseDouble(refundAmountGateway) <= t_order.getTotal_amount()){
-
 
721
						boolean refundResult = paymentServiceClient.getClient().refundPayment(t_order.getTransactionId(), Double.parseDouble(refundAmountGateway), false);
-
 
722
						if(refundResult){
-
 
723
							attr1.setValue("Refund By Payment Gatway: "+comments);
-
 
724
							attrList.add(attr1);
-
 
725
							attr2.setValue(refundAmountGateway);
-
 
726
							attrList.add(attr2);
-
 
727
							transactionClient.setOrderAttributes(t_order.getId(), attrList);
-
 
728
							successmsg = "Refund Marked Successful: Through Gateway";
-
 
729
							return "physical-refund-result";
-
 
730
						}
-
 
731
						else{
-
 
732
							if(orderPayments !=null && !orderPayments.isEmpty()){
-
 
733
								Payment payment = orderPayments.get(0);
-
 
734
								if(payment.getGatewayId()==13L){
-
 
735
									attr1.setValue("Refund By Innoviti Gatway: "+comments);
-
 
736
									attrList.add(attr1);
-
 
737
									attr2.setValue(refundAmountGateway);
-
 
738
									attrList.add(attr2);
-
 
739
									transactionClient.setOrderAttributes(t_order.getId(), attrList);
-
 
740
									successmsg = "Refund Marked Successful: Through Innoviti Payment Gateway.";
-
 
741
									return "physical-refund-result";
-
 
742
								}
-
 
743
							}
-
 
744
							errorMsg ="Refund Unsuccessful: at Payment Gateway ";
-
 
745
							return "physical-refund-result";
-
 
746
						}
-
 
747
						
-
 
748
					}
-
 
749
				}
-
 
750
				else{
-
 
751
					errorMsg ="Refund Unsuccessful: Due to either comments or refund amount is blank ";
-
 
752
					return "physical-refund-result";
-
 
753
				}
-
 
754
				errorMsg ="Refund Unsuccessful: Due to refund amount greater than order total amount ";
-
 
755
			}
-
 
756
			
-
 
757
		}
-
 
758
		catch(Exception e){
-
 
759
			log.error(e);
-
 
760
		}
-
 
761
		return "physical-refund-result";
-
 
762
	}
-
 
763
	
-
 
764
	public int getRefundEnabledStatus(){
-
 
765
		try{
-
 
766
			TransactionClient transactionServiceClient = new TransactionClient();
-
 
767
			in.shop2020.model.v1.order.TransactionService.Client transactionClient
-
 
768
		    = transactionServiceClient.getClient();
-
 
769
			in.shop2020.model.v1.order.Order t_order = transactionClient.getOrder(orderId);
-
 
770
			String refundOption=transactionClient.getOrderAttributeValue(orderId, "Refund_Option");
-
 
771
			String refundAmount=transactionClient.getOrderAttributeValue(orderId, "Refund_Amount");
-
 
772
			if((refundOption!=null && refundAmount!=null) && (!("").equalsIgnoreCase(refundOption)) && !("").equalsIgnoreCase(refundAmount) && SecurityUtils.getSubject().hasRole("TeamLead")){
-
 
773
				System.out.println("Into the Refund Condition");
-
 
774
				return 0;
-
 
775
			}
-
 
776
			else if(setOfrefundableStates.contains(t_order.getStatus()) && SecurityUtils.getSubject().hasRole("TeamLead")){
-
 
777
				System.out.println("Into the Status Condition");
-
 
778
				return 2;
-
 
779
			}
-
 
780
		}
-
 
781
		catch(Exception e){
-
 
782
			log.error(e);
-
 
783
		}
-
 
784
		return 1;
-
 
785
	}
-
 
786
	//End:- Added by Manish Sharma for Physical Refunds 	
616
 
787
 
617
	public void setOrderId(String orderId) {
788
	public void setOrderId(String orderId) {
618
		try {
789
		try {
619
			this.orderId = Long.parseLong(orderId);
790
			this.orderId = Long.parseLong(orderId);
620
		} catch (NumberFormatException e) {
791
		} catch (NumberFormatException e) {
Line 814... Line 985...
814
    public String getProviderName() {
985
    public String getProviderName() {
815
        return providerName;
986
        return providerName;
816
    }
987
    }
817
    
988
    
818
    public static void main(String[] args) {
989
    public static void main(String[] args) {
819
        System.out.println(providerNameMap.get(5l));
990
    	
820
        System.out.println(providerNameMap.get(10l));
-
 
821
    }
991
    }
822
 
992
 
823
	public void setGvAmount(long gvAmount) {
993
	public void setGvAmount(long gvAmount) {
824
		this.gvAmount = gvAmount;
994
		this.gvAmount = gvAmount;
825
	}
995
	}
826
 
996
 
827
	public long getGvAmount() {
997
	public long getGvAmount() {
828
		return gvAmount;
998
		return gvAmount;
829
	}
999
	}
-
 
1000
	//Start:- Added by Manish Sharma for Physical Refunds 
-
 
1001
	public String getRfdRadio() {
-
 
1002
		return rfdRadio;
-
 
1003
	}
-
 
1004
 
830
 
1005
 
-
 
1006
	public void setRfdRadio(String rfdRadio) {
-
 
1007
		this.rfdRadio = rfdRadio;
-
 
1008
	}
-
 
1009
 
-
 
1010
 
-
 
1011
	public String getCouponDetails() {
-
 
1012
		return couponDetails;
-
 
1013
	}
-
 
1014
 
-
 
1015
 
-
 
1016
	public void setCouponDetails(String couponDetails) {
-
 
1017
		this.couponDetails = couponDetails;
-
 
1018
	}
-
 
1019
 
-
 
1020
 
-
 
1021
	public String getRefundAmountCoupon() {
-
 
1022
		return refundAmountCoupon;
-
 
1023
	}
-
 
1024
 
-
 
1025
 
-
 
1026
	public void setRefundAmountCoupon(String refundAmountCoupon) {
-
 
1027
		this.refundAmountCoupon = refundAmountCoupon;
-
 
1028
	}
-
 
1029
 
-
 
1030
 
-
 
1031
	public String getChequeDetails() {
-
 
1032
		return chequeDetails;
-
 
1033
	}
-
 
1034
 
-
 
1035
 
-
 
1036
	public void setChequeDetails(String chequeDetails) {
-
 
1037
		this.chequeDetails = chequeDetails;
-
 
1038
	}
-
 
1039
 
-
 
1040
 
-
 
1041
	public String getRefundAmountCheque() {
-
 
1042
		return refundAmountCheque;
-
 
1043
	}
-
 
1044
 
-
 
1045
 
-
 
1046
	public void setRefundAmountCheque(String refundAmountCheque) {
-
 
1047
		this.refundAmountCheque = refundAmountCheque;
-
 
1048
	}
-
 
1049
 
-
 
1050
 
-
 
1051
	public String getRefundAmountGateway() {
-
 
1052
		return refundAmountGateway;
-
 
1053
	}
-
 
1054
 
-
 
1055
 
-
 
1056
	public void setRefundAmountGateway(String refundAmountGateway) {
-
 
1057
		this.refundAmountGateway = refundAmountGateway;
-
 
1058
	}
-
 
1059
 
-
 
1060
 
-
 
1061
	public String getComments() {
-
 
1062
		return comments;
-
 
1063
	}
-
 
1064
 
-
 
1065
 
-
 
1066
	public void setComments(String comments) {
-
 
1067
		this.comments = comments;
-
 
1068
	}
-
 
1069
	
-
 
1070
	public String getErrorMsg(){
-
 
1071
        return this.errorMsg;
-
 
1072
    }
-
 
1073
	
-
 
1074
	public String getSuccessMessage(){
-
 
1075
		return this.successmsg ;
-
 
1076
	}
-
 
1077
	//End:- Added by Manish Sharma for Physical Refunds 
831
}
1078
}
832
1079