Subversion Repositories SmartDukaan

Rev

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

Rev 7360 Rev 7386
Line 1... Line 1...
1
package in.shop2020.serving.controllers;
1
package in.shop2020.serving.controllers;
2
 
2
 
3
import java.text.SimpleDateFormat;
3
import java.text.SimpleDateFormat;
4
import java.util.ArrayList;
4
import java.util.ArrayList;
-
 
5
import java.util.Arrays;
5
import java.util.Calendar;
6
import java.util.Calendar;
6
import java.util.Date;
7
import java.util.Date;
7
import java.util.List;
8
import java.util.List;
8
import java.util.Random;
9
import java.util.Random;
9
 
10
 
Line 13... Line 14...
13
import org.apache.thrift.transport.TTransportException;
14
import org.apache.thrift.transport.TTransportException;
14
 
15
 
15
import in.shop2020.logistics.PickUpType;
16
import in.shop2020.logistics.PickUpType;
16
import in.shop2020.model.v1.catalog.Item;
17
import in.shop2020.model.v1.catalog.Item;
17
import in.shop2020.model.v1.catalog.StorePricing;
18
import in.shop2020.model.v1.catalog.StorePricing;
-
 
19
import in.shop2020.model.v1.order.HotspotStore;
18
import in.shop2020.model.v1.order.LineItem;
20
import in.shop2020.model.v1.order.LineItem;
19
import in.shop2020.model.v1.order.Order;
21
import in.shop2020.model.v1.order.Order;
20
import in.shop2020.model.v1.order.OrderSource;
22
import in.shop2020.model.v1.order.OrderSource;
21
import in.shop2020.model.v1.order.OrderStatus;
23
import in.shop2020.model.v1.order.OrderStatus;
22
import in.shop2020.model.v1.order.OrderType;
24
import in.shop2020.model.v1.order.OrderType;
23
import in.shop2020.model.v1.order.SourceDetail;
25
import in.shop2020.model.v1.order.SourceDetail;
-
 
26
import in.shop2020.model.v1.order.StoreOrderDetail;
-
 
27
import in.shop2020.model.v1.order.StorePaymentStatus;
24
import in.shop2020.model.v1.order.Transaction;
28
import in.shop2020.model.v1.order.Transaction;
25
import in.shop2020.model.v1.order.TransactionStatus;
29
import in.shop2020.model.v1.order.TransactionStatus;
26
import in.shop2020.model.v1.user.User;
30
import in.shop2020.model.v1.user.User;
27
import in.shop2020.model.v1.user.UserContextException;
31
import in.shop2020.model.v1.user.UserContextException;
28
import in.shop2020.payments.PaymentStatus;
32
import in.shop2020.payments.PaymentStatus;
Line 69... Line 73...
69
    private long paymentId;
73
    private long paymentId;
70
    private long userId;
74
    private long userId;
71
    
75
    
72
    
76
    
73
    private StorePricing sp;
77
    private StorePricing sp;
-
 
78
    private double cardAmount;
-
 
79
    private double cashAmount;
74
    
80
    
75
    public String index() {
81
    public String index() {
-
 
82
        String loginStatus = (String) request.getSession().getAttribute("LOGGED_IN");
-
 
83
        if(loginStatus == null || !loginStatus.equals("TRUE")){
-
 
84
            return "authfail";
-
 
85
        }
-
 
86
        storeId = Long.parseLong((String) request.getSession().getAttribute("STORE_ID"));
-
 
87
        if(!hotspotStores.containsKey(storeId)){
-
 
88
            try{
-
 
89
                HotspotStore hotSpotStore = (new TransactionClient()).getClient().getHotspotStore(storeId, "");
-
 
90
                hotspotStores.put(storeId, hotSpotStore);
-
 
91
            } catch (Exception e) {
-
 
92
                log.error("Unable to get store", e);
-
 
93
            }
-
 
94
        }
-
 
95
        
76
        return INDEX;
96
        return INDEX;
77
    }
97
    }
78
    
98
    
79
    public String create(){
99
    public String create(){
80
        return index();
100
        return index();
81
    }
101
    }
82
    
102
    
83
    public String persistTransaction() {
103
    public String persistTransaction() {
84
        Transaction txnObj = new Transaction();
104
        Transaction txnObj = new Transaction();
-
 
105
        StoreOrderDetail storeOrderDetail = new StoreOrderDetail();
85
        
106
        
86
        if(email != null && !email.isEmpty()) {
107
        if(email != null && !email.isEmpty()) {
87
            userId = createUserAndSendMail(email);
108
            userId = createUserAndSendMail(email);
88
        } else {
109
        } else {
89
            try {
110
            try {
Line 119... Line 140...
119
            return "error-result";
140
            return "error-result";
120
        }
141
        }
121
        
142
        
122
        orders.add(order);
143
        orders.add(order);
123
        txnObj.setOrders(orders);
144
        txnObj.setOrders(orders);
-
 
145
        
124
        TransactionClient tcl;
146
        TransactionClient tcl;
125
        long txnId = 0;
147
        long txnId = 0;
126
        try {
148
        try {
127
            tcl = new TransactionClient();
149
            tcl = new TransactionClient();
128
            txnId = tcl.getClient().createTransaction(txnObj);
150
            txnId = tcl.getClient().createTransaction(txnObj);
-
 
151
            
-
 
152
            storeOrderDetail.setAdvanceAmount(advanceAmount);
-
 
153
            storeOrderDetail.setCardAmount(cardAmount);
-
 
154
            storeOrderDetail.setCashAmount(cashAmount);
-
 
155
            storeOrderDetail.setOrderId(txnId);
-
 
156
            storeOrderDetail.setStoreId(1);
-
 
157
            if(advanceAmount == price) {
-
 
158
                storeOrderDetail.setPayStatus(StorePaymentStatus.FULL_PAY_RECEIVED);
-
 
159
            } else {
-
 
160
                storeOrderDetail.setPayStatus(StorePaymentStatus.ADV_RECEIVED);
-
 
161
            }
-
 
162
            
-
 
163
            boolean saveSuccess = tcl.getClient().saveStoreOrderDetail(storeOrderDetail);
-
 
164
            if(!saveSuccess) {
-
 
165
                setErrorMsg("Unable to create order. Please try again.");
-
 
166
                return "error-result";
-
 
167
            }
-
 
168
            
129
        } catch (Exception e) {
169
        } catch (Exception e) {
130
            log.error("Unable to create transaction", e);
170
            log.error("Unable to create transaction", e);
131
            setErrorMsg("Unable to create order. Please try again.");
171
            setErrorMsg("Unable to create order. Please try again.");
132
            return "error-result";
172
            return "error-result";
133
        }
173
        }
Line 296... Line 336...
296
            log.error("Unexpected error while mailing the new password");
336
            log.error("Unexpected error while mailing the new password");
297
            return -1;
337
            return -1;
298
        }
338
        }
299
        return user.getUserId();
339
        return user.getUserId();
300
    }
340
    }
-
 
341
    
-
 
342
    public List<String> getAllEdcBanks() {
-
 
343
        List<String> banks = new ArrayList<String>(); 
-
 
344
        try {
-
 
345
            TransactionClient tcl = new TransactionClient();
-
 
346
            banks = tcl.getClient().getAllEdcBanks();
-
 
347
        } catch (Exception e) {
-
 
348
            log.error("Unable to get banks for EDC", e);
-
 
349
        }
-
 
350
        return banks;
-
 
351
    }
301
 
352
 
302
    public String getLine1() {
353
    public String getLine1() {
303
        return line1;
354
        return line1;
304
    }
355
    }
305
 
356
 
Line 453... Line 504...
453
    }
504
    }
454
 
505
 
455
    public void setUserId(long userId) {
506
    public void setUserId(long userId) {
456
        this.userId = userId;
507
        this.userId = userId;
457
    }
508
    }
-
 
509
 
-
 
510
    public double getCashAmount() {
-
 
511
        return cashAmount;
-
 
512
    }
-
 
513
 
-
 
514
    public void setCashAmount(double cashAmount) {
-
 
515
        this.cashAmount = cashAmount;
-
 
516
    }
-
 
517
 
-
 
518
    public double getCardAmount() {
-
 
519
        return cardAmount;
-
 
520
    }
-
 
521
 
-
 
522
    public void setCardAmount(double cardAmount) {
-
 
523
        this.cardAmount = cardAmount;
-
 
524
    }
458
}
525
}