Subversion Repositories SmartDukaan

Rev

Rev 5235 | Rev 5945 | Go to most recent revision | Details | Compare with Previous | 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;
5235 mandeep.dh 19
import org.apache.thrift.TException;
20
import org.apache.thrift.transport.TTransportException;
5185 mandeep.dh 21
 
22
/**
23
 * @author mandeep
24
 *
25
 */
26
public class DoaOutController extends BaseController {
27
    private Log logger = LogFactory.getLog(DoaOutController.class);
28
    private String id;
29
    List<InventoryItem> inventoryItems;
30
 
31
    public String index() {
32
        try {
33
            Client warehouseClient = new WarehouseClient().getClient();
34
            inventoryItems = warehouseClient
35
                    .getInventoryItemsFromLastScanType(ScanType.DOA_OUT);
36
        } catch (Exception e) {
37
            logger.error("Could not fetch inventory items", e);
38
        }
39
 
40
        return INDEX;
41
    }
42
 
43
    public String update() {
44
        try {
45
            Client warehouseClient = new WarehouseClient().getClient();
46
            InventoryItem inventoryItem = warehouseClient.getInventoryItemFromId(Long.valueOf(id));
47
            in.shop2020.model.v1.catalog.InventoryService.Client catalogClient = new CatalogClient().getClient();
48
            Warehouse warehouse = catalogClient.getWarehouse(inventoryItem.getCurrentWarehouseId());
5533 mandeep.dh 49
            warehouseClient.scan(inventoryItem, ScanType.DOA_REPLACED, inventoryItem.getInitialQuantity(), warehouse.getBillingWarehouseId());
5185 mandeep.dh 50
            in.shop2020.purchase.PurchaseService.Client purchaseClient = new PurchaseClient().getClient();
51
            purchaseClient.unFulfillPO(inventoryItem.getPurchaseId(), inventoryItem.getItemId(), 1);
52
        } catch (Exception e) {
53
            logger.error("Could not fetch inventory items", e);
54
        }
55
 
56
        return index();
57
    }
5235 mandeep.dh 58
 
59
    public String getPONumber(long purchaseId) {
60
        try {
61
            in.shop2020.purchase.PurchaseService.Client purchaseClient = new PurchaseClient().getClient();
62
            return purchaseClient.getPurchaseOrderForPurchase(purchaseId).getPoNumber();
63
        } catch (Exception e) {
64
            return "N/A";
65
        }
66
    }
67
 
5185 mandeep.dh 68
    public String getWarehouseDisplayName(long warehouseId) {
69
        try {
70
            in.shop2020.model.v1.catalog.InventoryService.Client catalogClient = new CatalogClient().getClient();
71
            return catalogClient.getWarehouse(warehouseId).getDisplayName();
72
        } catch (Exception e) {
73
            return "N/A";
74
        }
75
    }
76
 
77
    public String getModelName(long itemId) {
78
        try {
79
            in.shop2020.model.v1.catalog.InventoryService.Client catalogClient = new CatalogClient()
80
                    .getClient();
81
            return ModelUtils.extractProductNameFromItem(catalogClient
82
                    .getItem(itemId));
83
        } catch (Exception e) {
84
            return "N/A";
85
        }
86
    }
87
 
88
    public String getId() {
89
        return id;
90
    }
91
 
92
    public void setId(String id) {
93
        this.id = id;
94
    }
95
 
96
    public List<InventoryItem> getInventoryItems() {
97
        return inventoryItems;
98
    }
99
 
100
    public void setInventoryItems(List<InventoryItem> inventoryItems) {
101
        this.inventoryItems = inventoryItems;
102
    }
103
 
104
}