Subversion Repositories SmartDukaan

Rev

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