Subversion Repositories SmartDukaan

Rev

Rev 5235 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
5185 mandeep.dh 1
/**
2
 * 
3
 */
4
package in.shop2020.inventory.controllers;
5
 
6
import in.shop2020.model.v1.catalog.Warehouse;
7
import in.shop2020.thrift.clients.CatalogClient;
8
import in.shop2020.thrift.clients.PurchaseClient;
9
import in.shop2020.thrift.clients.WarehouseClient;
10
import in.shop2020.utils.ModelUtils;
11
import in.shop2020.warehouse.InventoryItem;
12
import in.shop2020.warehouse.ScanType;
13
import in.shop2020.warehouse.WarehouseService.Client;
14
 
15
import java.util.List;
16
 
17
import org.apache.commons.logging.Log;
18
import org.apache.commons.logging.LogFactory;
19
 
20
/**
21
 * @author mandeep
22
 *
23
 */
24
public class DoaOutController extends BaseController {
25
    private Log logger = LogFactory.getLog(DoaOutController.class);
26
    private String id;
27
    List<InventoryItem> inventoryItems;
28
 
29
    public String index() {
30
        try {
31
            Client warehouseClient = new WarehouseClient().getClient();
32
            inventoryItems = warehouseClient
33
                    .getInventoryItemsFromLastScanType(ScanType.DOA_OUT);
34
        } catch (Exception e) {
35
            logger.error("Could not fetch inventory items", e);
36
        }
37
 
38
        return INDEX;
39
    }
40
 
41
    public String update() {
42
        try {
43
            Client warehouseClient = new WarehouseClient().getClient();
44
            InventoryItem inventoryItem = warehouseClient.getInventoryItemFromId(Long.valueOf(id));
45
            in.shop2020.model.v1.catalog.InventoryService.Client catalogClient = new CatalogClient().getClient();
46
            Warehouse warehouse = catalogClient.getWarehouse(inventoryItem.getCurrentWarehouseId());
47
            warehouseClient.scanSerializedItem(inventoryItem, ScanType.DOA_REPLACED, warehouse.getBillingWarehouseId());
48
            in.shop2020.purchase.PurchaseService.Client purchaseClient = new PurchaseClient().getClient();
49
            purchaseClient.unFulfillPO(inventoryItem.getPurchaseId(), inventoryItem.getItemId(), 1);
50
        } catch (Exception e) {
51
            logger.error("Could not fetch inventory items", e);
52
        }
53
 
54
        return index();
55
    }
56
 
57
    public String getWarehouseDisplayName(long warehouseId) {
58
        try {
59
            in.shop2020.model.v1.catalog.InventoryService.Client catalogClient = new CatalogClient().getClient();
60
            return catalogClient.getWarehouse(warehouseId).getDisplayName();
61
        } catch (Exception e) {
62
            return "N/A";
63
        }
64
    }
65
 
66
    public String getModelName(long itemId) {
67
        try {
68
            in.shop2020.model.v1.catalog.InventoryService.Client catalogClient = new CatalogClient()
69
                    .getClient();
70
            return ModelUtils.extractProductNameFromItem(catalogClient
71
                    .getItem(itemId));
72
        } catch (Exception e) {
73
            return "N/A";
74
        }
75
    }
76
 
77
    public String getId() {
78
        return id;
79
    }
80
 
81
    public void setId(String id) {
82
        this.id = id;
83
    }
84
 
85
    public List<InventoryItem> getInventoryItems() {
86
        return inventoryItems;
87
    }
88
 
89
    public void setInventoryItems(List<InventoryItem> inventoryItems) {
90
        this.inventoryItems = inventoryItems;
91
    }
92
 
93
}