Rev 7672 | Blame | Compare with Previous | Last modification | View Log | RSS feed
/****/package in.shop2020.warehouse.domain;import in.shop2020.generic.ExceptionType;import in.shop2020.purchase.LineItem;import in.shop2020.purchase.PurchaseOrder;import in.shop2020.purchase.PurchaseService.Client;import in.shop2020.thrift.clients.PurchaseClient;import in.shop2020.warehouse.ScanType;import in.shop2020.warehouse.TransferLotStatus;import in.shop2020.warehouse.WarehouseServiceException;import java.util.Date;import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;/*** @author mandeep**/public class InventoryItem {private static Log logger = LogFactory.getLog(InventoryItem.class);private long id;private long itemId;private String itemNumber;private String serialNumber;private long initialQuantity;private long currentQuantity;private long purchaseId;private long purchaseReturnId;private long currentWarehouseId;private ScanType lastScanType;private Date activated;private Date created;private long physicalWarehouseId;private TransferLotStatus transferStatus;public static InventoryItem create(in.shop2020.warehouse.InventoryItem thriftInventoryItem) {InventoryItem inventoryItem = new InventoryItem();inventoryItem.id = thriftInventoryItem.getId();inventoryItem.itemId = thriftInventoryItem.getItemId();inventoryItem.itemNumber = thriftInventoryItem.getItemNumber();inventoryItem.serialNumber = thriftInventoryItem.getSerialNumber();inventoryItem.initialQuantity = thriftInventoryItem.getInitialQuantity();inventoryItem.currentQuantity = thriftInventoryItem.getCurrentQuantity();inventoryItem.purchaseId = thriftInventoryItem.getPurchaseId();inventoryItem.purchaseReturnId = thriftInventoryItem.getPurchaseReturnId();inventoryItem.currentWarehouseId = thriftInventoryItem.getCurrentWarehouseId();inventoryItem.lastScanType = thriftInventoryItem.getLastScanType();inventoryItem.physicalWarehouseId = thriftInventoryItem.getPhysicalWarehouseId();inventoryItem.transferStatus = thriftInventoryItem.getTransferStatus();inventoryItem.created = new Date();return inventoryItem;}public in.shop2020.warehouse.InventoryItem convert() throws WarehouseServiceException {in.shop2020.warehouse.InventoryItem inventoryItem = new in.shop2020.warehouse.InventoryItem();inventoryItem.setId(id);inventoryItem.setItemId(itemId);inventoryItem.setCurrentQuantity(currentQuantity);inventoryItem.setInitialQuantity(initialQuantity);inventoryItem.setItemNumber(itemNumber);inventoryItem.setPurchaseId(purchaseId);inventoryItem.setPurchaseReturnId(purchaseReturnId);inventoryItem.setSerialNumber(serialNumber);inventoryItem.setCurrentWarehouseId(currentWarehouseId);inventoryItem.setLastScanType(lastScanType);inventoryItem.setTransferStatus(transferStatus);inventoryItem.setPhysicalWarehouseId(physicalWarehouseId);if(this.activated!=null) {inventoryItem.setActivated(this.activated.getTime());}if(this.created != null) {inventoryItem.setCreated(this.created.getTime());}// Setting derived fieldstry {Client client = new PurchaseClient().getClient();PurchaseOrder purchaseOrder = client.getPurchaseOrderForPurchase(purchaseId);inventoryItem.setSupplierId(purchaseOrder.getSupplierId());for (LineItem lineItem : purchaseOrder.getLineitems()) {if (lineItem.getItemId() == itemId) {inventoryItem.setUnitPrice(lineItem.getUnitPrice());inventoryItem.setNlc(lineItem.getNlc());break;}}} catch (Exception e) {logger.error("Could not fetch purchase order for purchase id: " + purchaseId, e);throw new WarehouseServiceException(ExceptionType.DATABASE_ERROR, "Could not find item in PO.");}return inventoryItem;}public in.shop2020.warehouse.InventoryItem convert(boolean derived) throws WarehouseServiceException {in.shop2020.warehouse.InventoryItem inventoryItem = new in.shop2020.warehouse.InventoryItem();inventoryItem.setId(id);inventoryItem.setItemId(itemId);inventoryItem.setCurrentQuantity(currentQuantity);inventoryItem.setInitialQuantity(initialQuantity);inventoryItem.setItemNumber(itemNumber);inventoryItem.setPurchaseId(purchaseId);inventoryItem.setPurchaseReturnId(purchaseReturnId);inventoryItem.setSerialNumber(serialNumber);inventoryItem.setCurrentWarehouseId(currentWarehouseId);inventoryItem.setLastScanType(lastScanType);inventoryItem.setTransferStatus(transferStatus);inventoryItem.setPhysicalWarehouseId(physicalWarehouseId);if(this.activated!=null) {inventoryItem.setActivated(this.activated.getTime());}if(this.created != null) {inventoryItem.setCreated(this.created.getTime());}// Setting derived fieldsif(derived) {try {Client client = new PurchaseClient().getClient();PurchaseOrder purchaseOrder = client.getPurchaseOrderForPurchase(purchaseId);inventoryItem.setSupplierId(purchaseOrder.getSupplierId());for (LineItem lineItem : purchaseOrder.getLineitems()) {if (lineItem.getItemId() == itemId) {inventoryItem.setUnitPrice(lineItem.getUnitPrice());inventoryItem.setNlc(lineItem.getNlc());break;}}} catch (Exception e) {logger.error("Could not fetch purchase order for purchase id: " + purchaseId, e);throw new WarehouseServiceException(ExceptionType.DATABASE_ERROR, "Could not find item in PO.");}}return inventoryItem;}public long getId() {return id;}public void setId(long id) {this.id = id;}public long getItemId() {return itemId;}public void setItemId(long itemId) {this.itemId = itemId;}public String getItemNumber() {return itemNumber;}public void setItemNumber(String itemNumber) {this.itemNumber = itemNumber;}public String getSerialNumber() {return serialNumber;}public void setSerialNumber(String serialNumber) {this.serialNumber = serialNumber;}public long getInitialQuantity() {return initialQuantity;}public void setInitialQuantity(long initialQuantity) {this.initialQuantity = initialQuantity;}public long getCurrentQuantity() {return currentQuantity;}public void setCurrentQuantity(long currentQuantity) {this.currentQuantity = currentQuantity;}public long getPurchaseId() {return purchaseId;}public void setPurchaseId(long purchaseId) {this.purchaseId = purchaseId;}public long getPurchaseReturnId() {return purchaseReturnId;}public void setPurchaseReturnId(long purchaseReturnId) {this.purchaseReturnId = purchaseReturnId;}public long getCurrentWarehouseId() {return currentWarehouseId;}public void setCurrentWarehouseId(long currentWarehouseId) {this.currentWarehouseId = currentWarehouseId;}public ScanType getLastScanType() {return lastScanType;}public void setLastScanType(ScanType lastScanType) {this.lastScanType = lastScanType;}public TransferLotStatus getTransferStatus() {return transferStatus;}public void setTransferStatus(TransferLotStatus transferStatus) {this.transferStatus = transferStatus;}public long getPhysicalWarehouseId() {return physicalWarehouseId;}public void setPhysicalWarehouseId(long physicalWarehouseId) {this.physicalWarehouseId = physicalWarehouseId;}public Date getActivated() {return activated;}public void setActivated(Date activated) {this.activated = activated;}public Date getCreated() {return created;}public void setCreated(Date created) {this.created = created;}}