Subversion Repositories SmartDukaan

Rev

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

Rev 7293 Rev 7323
Line 10... Line 10...
10
import org.apache.thrift.TException;
10
import org.apache.thrift.TException;
11
import org.apache.thrift.transport.TTransportException;
11
import org.apache.thrift.transport.TTransportException;
12
 
12
 
13
import in.shop2020.logistics.PickUpType;
13
import in.shop2020.logistics.PickUpType;
14
import in.shop2020.model.v1.catalog.Item;
14
import in.shop2020.model.v1.catalog.Item;
-
 
15
import in.shop2020.model.v1.catalog.StorePricing;
15
import in.shop2020.model.v1.order.LineItem;
16
import in.shop2020.model.v1.order.LineItem;
16
import in.shop2020.model.v1.order.Order;
17
import in.shop2020.model.v1.order.Order;
17
import in.shop2020.model.v1.order.OrderSource;
18
import in.shop2020.model.v1.order.OrderSource;
18
import in.shop2020.model.v1.order.OrderStatus;
19
import in.shop2020.model.v1.order.OrderStatus;
19
import in.shop2020.model.v1.order.OrderType;
20
import in.shop2020.model.v1.order.OrderType;
Line 54... Line 55...
54
    private String errorMsg = "";
55
    private String errorMsg = "";
55
    private double price;
56
    private double price;
56
    private List<Order> orders = new ArrayList<Order>();
57
    private List<Order> orders = new ArrayList<Order>();
57
    private Double advanceAmount;
58
    private Double advanceAmount;
58
    private String deliveryDate = "";
59
    private String deliveryDate = "";
-
 
60
    private String productName = "";
-
 
61
    private String bestDealText = "";
-
 
62
    private String CatalogItemId = "";
59
    
63
    
60
    private FormattingUtils formattingUtils = new FormattingUtils();
64
    private FormattingUtils formattingUtils = new FormattingUtils();
-
 
65
    private StorePricing sp;
61
    
66
    
62
    public String index() {
67
    public String index() {
63
        return INDEX;
68
        return INDEX;
64
    }
69
    }
65
    
70
    
Line 107... Line 112...
107
        txnObj.setTransactionStatus(TransactionStatus.INIT);
112
        txnObj.setTransactionStatus(TransactionStatus.INIT);
108
        txnObj.setStatusDescription("New Store Order");
113
        txnObj.setStatusDescription("New Store Order");
109
        txnObj.setCoupon_code("");
114
        txnObj.setCoupon_code("");
110
        txnObj.setEmiSchemeId(0);
115
        txnObj.setEmiSchemeId(0);
111
        
116
        
-
 
117
        Order order = createOrder(tempUserId);
-
 
118
        
112
        if(createOrder(tempUserId) ==  null) {
119
        if(order ==  null) {
113
            log.error("Unable to create transaction");
120
            log.error("Unable to create transaction");
114
            setErrorMsg("Unable to create order. Please try again.");
121
            setErrorMsg("Unable to create order. Please try again.");
115
            return "error-result";
122
            return "error-result";
116
        }
123
        }
117
        
124
        
118
        orders.add(createOrder(tempUserId));
125
        orders.add(order);
119
        txnObj.setOrders(orders);
126
        txnObj.setOrders(orders);
120
        TransactionClient tcl;
127
        TransactionClient tcl;
121
        long txnId = 0;
128
        long txnId = 0;
122
        try {
129
        try {
123
            tcl = new TransactionClient();
130
            tcl = new TransactionClient();
Line 140... Line 147...
140
            setErrorMsg("Unable to create order. Please try again.");
147
            setErrorMsg("Unable to create order. Please try again.");
141
            return "error-result";
148
            return "error-result";
142
        }
149
        }
143
        
150
        
144
        try {
151
        try {
-
 
152
            TransactionStatus txnStatus = TransactionStatus.COD_IN_PROCESS;
-
 
153
            if(advanceAmount >= price) {
-
 
154
                txnStatus = TransactionStatus.AUTHORIZED;
-
 
155
            }
-
 
156
            
145
            tcl = new TransactionClient();
157
            tcl = new TransactionClient();
146
            boolean status = tcl.getClient().changeTransactionStatus(txnId, TransactionStatus.COD_IN_PROCESS, "Payment authorized", PickUpType.COURIER.getValue(), OrderType.B2C, OrderSource.STORE);
158
            boolean status = tcl.getClient().changeTransactionStatus(txnId, txnStatus, "Payment authorized", PickUpType.COURIER.getValue(), OrderType.B2C, OrderSource.STORE);
147
            if(!status) {
159
            if(!status) {
148
                log.error("Unable to update transaction");
160
                log.error("Unable to update transaction");
149
                setErrorMsg("Unable to create order. Please try again.");
161
                setErrorMsg("Unable to create order. Please try again.");
150
                return "error-result";
162
                return "error-result";
151
            }
163
            }
Line 198... Line 210...
198
        order.setCreated_timestamp(Calendar.getInstance().getTimeInMillis());
210
        order.setCreated_timestamp(Calendar.getInstance().getTimeInMillis());
199
        order.setTotal_weight(lineObj.getTotal_weight());
211
        order.setTotal_weight(lineObj.getTotal_weight());
200
        
212
        
201
        order.setSource(2);
213
        order.setSource(2);
202
        order.setStoreId(1);
214
        order.setStoreId(1);
-
 
215
        
203
        order.setAdvanceAmount(advanceAmount);
216
        order.setAdvanceAmount(advanceAmount);
-
 
217
        order.setFreebieItemId(sp.getFreebieItemId());
204
        
218
        
205
        List<LineItem> lines = new ArrayList<LineItem>();
219
        List<LineItem> lines = new ArrayList<LineItem>();
206
        lines.add(lineObj);
220
        lines.add(lineObj);
207
        order.setLineitems(lines);
221
        order.setLineitems(lines);
208
        return order;
222
        return order;
Line 212... Line 226...
212
        LineItem lineitem = new LineItem();
226
        LineItem lineitem = new LineItem();
213
        Item item = null;
227
        Item item = null;
214
        try {
228
        try {
215
            CatalogClient ccl = new CatalogClient();
229
            CatalogClient ccl = new CatalogClient();
216
            item = ccl.getClient().getItem(product_id);
230
            item = ccl.getClient().getItem(product_id);
-
 
231
            sp = ccl.getClient().getStorePricing(product_id);
-
 
232
            lineitem.setDealText(sp.getBestDealText());
217
        } catch (Exception e) {
233
        } catch (Exception e) {
218
            log.error("Unable to get the item from catalog service, ItemId : " + product_id, e);
234
            log.error("Unable to get the item from catalog service, ItemId : " + product_id, e);
219
            setErrorMsg("Unable to create order. Please try again.");
235
            setErrorMsg("Unable to create order. Please try again.");
220
            return null;
236
            return null;
221
        }
237
        }
Line 411... Line 427...
411
    public String formatPrice(double price)    {
427
    public String formatPrice(double price)    {
412
        return formattingUtils.formatPrice(price);
428
        return formattingUtils.formatPrice(price);
413
    }
429
    }
414
    
430
    
415
    public static String formatDate(long timestamp){
431
    public static String formatDate(long timestamp){
416
        SimpleDateFormat dateformat = new SimpleDateFormat("h:m a, dd MMMM yyyy");
432
        SimpleDateFormat dateformat = new SimpleDateFormat("dd MMMM yyyy");
417
        return dateformat.format(new Date(timestamp));  
433
        return dateformat.format(new Date(timestamp));  
418
    }
434
    }
-
 
435
 
-
 
436
    public String getProductName() {
-
 
437
        return productName;
-
 
438
    }
-
 
439
 
-
 
440
    public void setProductName(String productName) {
-
 
441
        this.productName = productName;
-
 
442
    }
-
 
443
 
-
 
444
    public String getBestDealText() {
-
 
445
        return bestDealText;
-
 
446
    }
-
 
447
 
-
 
448
    public void setBestDealText(String bestDealText) {
-
 
449
        this.bestDealText = bestDealText;
-
 
450
    }
-
 
451
    
-
 
452
    
-
 
453
    public String getImageSource() {
-
 
454
        return "/storewebsite/images/website/" + getCatalogItemId() + "/default.jpg";
-
 
455
    }
-
 
456
 
-
 
457
    public String getCatalogItemId() {
-
 
458
        return CatalogItemId;
-
 
459
    }
-
 
460
 
-
 
461
    public void setCatalogItemId(String catalogItemId) {
-
 
462
        CatalogItemId = catalogItemId;
-
 
463
    }
419
}
464
}