Subversion Repositories SmartDukaan

Rev

Rev 6467 | Rev 7672 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
4500 mandeep.dh 1
/**
2
 * 
3
 */
4
package in.shop2020.warehouse.domain;
5
 
5110 mandeep.dh 6
import in.shop2020.generic.ExceptionType;
4555 mandeep.dh 7
import in.shop2020.purchase.LineItem;
8
import in.shop2020.purchase.PurchaseOrder;
9
import in.shop2020.purchase.PurchaseService.Client;
10
import in.shop2020.thrift.clients.PurchaseClient;
5185 mandeep.dh 11
import in.shop2020.warehouse.ScanType;
7410 amar.kumar 12
import in.shop2020.warehouse.TransferLotStatus;
5110 mandeep.dh 13
import in.shop2020.warehouse.WarehouseServiceException;
4500 mandeep.dh 14
 
4555 mandeep.dh 15
import org.apache.commons.logging.Log;
16
import org.apache.commons.logging.LogFactory;
17
 
18
 
4500 mandeep.dh 19
/**
20
 * @author mandeep
21
 *
22
 */
23
public class InventoryItem {
4555 mandeep.dh 24
    private static Log logger = LogFactory.getLog(InventoryItem.class);
25
 
4500 mandeep.dh 26
    private long id;
27
    private long itemId;
28
    private String itemNumber;
29
    private String serialNumber;
30
    private long initialQuantity;
31
    private long currentQuantity;
32
    private long purchaseId;
6467 amar.kumar 33
    private long purchaseReturnId;
5185 mandeep.dh 34
    private long currentWarehouseId;
35
    private ScanType lastScanType;
7410 amar.kumar 36
    private long physicalWarehouseId;
37
    private TransferLotStatus transferStatus;
5185 mandeep.dh 38
 
4500 mandeep.dh 39
    public static InventoryItem create(in.shop2020.warehouse.InventoryItem thriftInventoryItem) {
40
        InventoryItem inventoryItem = new InventoryItem();
41
        inventoryItem.id = thriftInventoryItem.getId();
42
        inventoryItem.itemId = thriftInventoryItem.getItemId();
43
        inventoryItem.itemNumber = thriftInventoryItem.getItemNumber();
44
        inventoryItem.serialNumber = thriftInventoryItem.getSerialNumber();
45
        inventoryItem.initialQuantity = thriftInventoryItem.getInitialQuantity();
46
        inventoryItem.currentQuantity = thriftInventoryItem.getCurrentQuantity();
47
        inventoryItem.purchaseId = thriftInventoryItem.getPurchaseId();
6467 amar.kumar 48
        inventoryItem.purchaseReturnId = thriftInventoryItem.getPurchaseReturnId();
5185 mandeep.dh 49
        inventoryItem.currentWarehouseId = thriftInventoryItem.getCurrentWarehouseId();
50
        inventoryItem.lastScanType = thriftInventoryItem.getLastScanType();
7410 amar.kumar 51
        inventoryItem.physicalWarehouseId = thriftInventoryItem.getPhysicalWarehouseId();
52
        inventoryItem.transferStatus = thriftInventoryItem.getTransferStatus();
4500 mandeep.dh 53
 
54
        return inventoryItem;
55
    }
56
 
5110 mandeep.dh 57
    public in.shop2020.warehouse.InventoryItem convert() throws WarehouseServiceException {
4500 mandeep.dh 58
        in.shop2020.warehouse.InventoryItem inventoryItem = new in.shop2020.warehouse.InventoryItem();
59
        inventoryItem.setId(id);
60
        inventoryItem.setItemId(itemId);
61
        inventoryItem.setCurrentQuantity(currentQuantity);
62
        inventoryItem.setInitialQuantity(initialQuantity);
63
        inventoryItem.setItemNumber(itemNumber);
64
        inventoryItem.setPurchaseId(purchaseId);
6467 amar.kumar 65
        inventoryItem.setPurchaseReturnId(purchaseReturnId);
4500 mandeep.dh 66
        inventoryItem.setSerialNumber(serialNumber);
5185 mandeep.dh 67
        inventoryItem.setCurrentWarehouseId(currentWarehouseId);
68
        inventoryItem.setLastScanType(lastScanType);        
7410 amar.kumar 69
        inventoryItem.setTransferStatus(transferStatus);        
70
        inventoryItem.setPhysicalWarehouseId(physicalWarehouseId);        
4555 mandeep.dh 71
 
72
        // Setting derived fields
73
        try {
74
            Client client = new PurchaseClient().getClient();
75
            PurchaseOrder purchaseOrder = client.getPurchaseOrderForPurchase(purchaseId);
76
            inventoryItem.setSupplierId(purchaseOrder.getSupplierId());
77
            for (LineItem lineItem : purchaseOrder.getLineitems()) {
78
                if (lineItem.getItemId() == itemId) {
79
                    inventoryItem.setUnitPrice(lineItem.getUnitPrice());
80
                    break;
81
                }
82
            }
5110 mandeep.dh 83
        } catch (Exception e) {
4555 mandeep.dh 84
            logger.error("Could not fetch purchase order for purchase id: " + purchaseId, e);
5110 mandeep.dh 85
            throw new WarehouseServiceException(ExceptionType.DATABASE_ERROR, "Could not find item in PO.");
4555 mandeep.dh 86
        }
87
 
4500 mandeep.dh 88
        return inventoryItem;
4555 mandeep.dh 89
    }
4500 mandeep.dh 90
 
91
    public long getId() {
92
        return id;
93
    }
94
    public void setId(long id) {
95
        this.id = id;
96
    }
97
    public long getItemId() {
98
        return itemId;
99
    }
100
    public void setItemId(long itemId) {
101
        this.itemId = itemId;
102
    }
103
    public String getItemNumber() {
104
        return itemNumber;
105
    }
106
    public void setItemNumber(String itemNumber) {
107
        this.itemNumber = itemNumber;
108
    }
109
    public String getSerialNumber() {
110
        return serialNumber;
111
    }
112
    public void setSerialNumber(String serialNumber) {
113
        this.serialNumber = serialNumber;
114
    }
115
    public long getInitialQuantity() {
116
        return initialQuantity;
117
    }
118
    public void setInitialQuantity(long initialQuantity) {
119
        this.initialQuantity = initialQuantity;
120
    }
121
    public long getCurrentQuantity() {
122
        return currentQuantity;
123
    }
124
    public void setCurrentQuantity(long currentQuantity) {
125
        this.currentQuantity = currentQuantity;
126
    }
127
    public long getPurchaseId() {
128
        return purchaseId;
129
    }
130
    public void setPurchaseId(long purchaseId) {
131
        this.purchaseId = purchaseId;
132
    }
5185 mandeep.dh 133
 
6467 amar.kumar 134
    public long getPurchaseReturnId() {
135
		return purchaseReturnId;
136
	}
137
 
138
	public void setPurchaseReturnId(long purchaseReturnId) {
139
		this.purchaseReturnId = purchaseReturnId;
140
	}
141
 
142
	public long getCurrentWarehouseId() {
5185 mandeep.dh 143
        return currentWarehouseId;
144
    }
145
 
146
    public void setCurrentWarehouseId(long currentWarehouseId) {
147
        this.currentWarehouseId = currentWarehouseId;
148
    }
149
 
150
    public ScanType getLastScanType() {
151
        return lastScanType;
152
    }
153
 
154
    public void setLastScanType(ScanType lastScanType) {
155
        this.lastScanType = lastScanType;
156
    }
7410 amar.kumar 157
 
158
	public TransferLotStatus getTransferStatus() {
159
		return transferStatus;
160
	}
161
 
162
	public void setTransferStatus(TransferLotStatus transferStatus) {
163
		this.transferStatus = transferStatus;
164
	}
165
 
166
	public long getPhysicalWarehouseId() {
167
		return physicalWarehouseId;
168
	}
169
 
170
	public void setPhysicalWarehouseId(long physicalWarehouseId) {
171
		this.physicalWarehouseId = physicalWarehouseId;
172
	}
173
 
4500 mandeep.dh 174
}