Rev 7451 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
package in.shop2020.inventory.controllers;import in.shop2020.inventory.controllers.PurchaseController.ScanRecordType;import in.shop2020.model.v1.catalog.CatalogService;import in.shop2020.model.v1.catalog.CatalogServiceException;import in.shop2020.model.v1.catalog.Item;import in.shop2020.model.v1.catalog.ItemType;import in.shop2020.model.v1.inventory.InventoryServiceException;import in.shop2020.model.v1.inventory.Vendor;import in.shop2020.model.v1.inventory.InventoryService.Client;import in.shop2020.model.v1.inventory.Warehouse;import in.shop2020.model.v1.inventory.WarehouseType;import in.shop2020.model.v1.order.LineItem;import in.shop2020.purchase.PurchaseReturn;import in.shop2020.purchase.PurchaseServiceException;import in.shop2020.thrift.clients.CatalogClient;import in.shop2020.thrift.clients.InventoryClient;import in.shop2020.thrift.clients.PurchaseClient;import in.shop2020.thrift.clients.WarehouseClient;import in.shop2020.warehouse.InventoryItem;import in.shop2020.warehouse.Scan;import in.shop2020.warehouse.ScanType;import in.shop2020.warehouse.TransferLot;import in.shop2020.warehouse.WarehouseService;import in.shop2020.warehouse.WarehouseServiceException;import java.text.DateFormat;import java.text.ParseException;import java.text.SimpleDateFormat;import java.util.Calendar;import java.util.HashMap;import java.util.Hashtable;import java.util.List;import java.util.Map;import java.util.Map.Entry;import java.util.Set;import java.util.ArrayList;import org.apache.thrift.TException;import org.apache.thrift.transport.TTransportException;import org.slf4j.Logger;import org.slf4j.LoggerFactory;public class TransferLotController extends BaseController{/****/private static final long serialVersionUID = 3052114881399915348L;private Long id;private TransferLot transferLot;private List<TransferLot>transferLots;private String remoteTransferRefNumber;private String fromDate;private String toDate;private String errorMessage = "";private Calendar transferLotFromDate;private Calendar transferLotToDate;private Long originWarehouseId;private List<LineItem> lineItems;private Long destinationWarehouseId;private String output;private static Map<Long, Warehouse> warehouseMap;private static SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");private static Logger logger = LoggerFactory.getLogger(TransferLotController.class);static {warehouseMap = new HashMap<Long, Warehouse>();InventoryClient inventoryServiceClient;try {inventoryServiceClient = new InventoryClient();Client inventoryClient = inventoryServiceClient.getClient();List<Warehouse> warehouses;warehouses = inventoryClient.getAllWarehouses(true);for(Warehouse warehouse : warehouses){warehouseMap.put(warehouse.getId(), warehouse);}} catch (TTransportException e) {logger.error("Error in populating warehouse map", e);} catch (TException e) {logger.error("Error in populating warehouse map", e);} catch (InventoryServiceException isex) {logger.error("Error in populating warehouse map", isex);}}public String index(){if(warehouseMap==null||warehouseMap.size()<1){//TODO fetchWarehouseMap();}try{WarehouseService.Client warehouseClient = new WarehouseClient().getClient();transferLotFromDate = Calendar.getInstance();transferLotToDate = Calendar.getInstance();if(fromDate==null) {transferLotFromDate.add(Calendar.MONTH, -1);} else {transferLotFromDate.setTime(formatter.parse(fromDate));if(toDate!=null) {transferLotToDate.setTime(formatter.parse(toDate));}}transferLots = warehouseClient.getTransferLotsByDate(transferLotFromDate.getTimeInMillis(), transferLotToDate.getTimeInMillis());} catch(TException e){logger.error("Error in getting transfer lots", e);} catch(ParseException pex) {logger.error("Error in parsing time", pex);} catch(WarehouseServiceException wsex) {logger.error("Error in getting transfer lots", wsex);}return INDEX;}public String create() {originWarehouseId = Long.parseLong(request.getParameter("originWarehouseId"));destinationWarehouseId = Long.parseLong(request.getParameter("destinationWarehouseId"));try {WarehouseService.Client warehouseClient = new WarehouseClient().getClient();id = warehouseClient.createTransferLot(originWarehouseId, destinationWarehouseId);} catch (TException tex) {logger.error("Error in creating transferlot between warehouseId " + originWarehouseId + " and " + destinationWarehouseId, tex);errorMessage = "Error in creating transferlot between warehouseId " + originWarehouseId + " and " + destinationWarehouseId;} catch (WarehouseServiceException wex) {logger.error("Error in creating transferlot between warehouseId " + originWarehouseId + " and " + destinationWarehouseId, wex);errorMessage = "Error in creating transferlot between warehouseId " + originWarehouseId + " and " + destinationWarehouseId;}return show();}public String show(){resetLineItems();return SHOW;}public String update() {try {if(!areValidScans()){errorMessage = "Invalid Scans";return show();}if(id == null || id==0) {//if(!createPurchase()) {errorMessage = "No transferLot-Id selected for Transfer";return "new";//}}List<InventoryItem> inventoryItems = new ArrayList<InventoryItem>();CatalogService.Client catalogClient = new CatalogClient().getClient();for (LineItem lineItem : lineItems) {if (lineItem.getItem_id() == 0) {continue;}InventoryItem inventoryItem = new InventoryItem();inventoryItem.setItemId(lineItem.getItem_id());inventoryItem.setCurrentQuantity(new Double(lineItem.getQuantity()).longValue());inventoryItem.setItemNumber(lineItem.getItem_number());if(catalogClient.getItem(lineItem.getItem_id()).getType()==ItemType.SERIALIZED) {inventoryItem.setSerialNumber(lineItem.getSerial_number());}inventoryItems.add(inventoryItem);}WarehouseService.Client warehouseClient = new WarehouseClient().getClient();warehouseClient.scanForTransfer(inventoryItems, ScanType.WAREHOUSE_TRANSFER_OUT, id);} catch (TTransportException e) {errorMessage = "Error while establishing connection to the warehouse server";logger.error(errorMessage, e);} catch (WarehouseServiceException e) {errorMessage = e.getMessage();logger.error(errorMessage, e);} catch (TException e) {errorMessage = "Error while scanning in the item";logger.error(errorMessage, e);} catch (CatalogServiceException csex) {errorMessage = "Error while getting the serialized details of item";logger.error(errorMessage, csex);}return show();}public String editNew(){return "new";}private boolean areValidScans() throws NumberFormatException, TException {boolean areValidScans = true;return areValidScans;}private void resetLineItems() {lineItems = new ArrayList<LineItem>();for (int i = 0; i < 11; i++) {LineItem lineItem = new LineItem();lineItem.setId(i);lineItem.setExtra_info("");lineItem.setSerial_number("");lineItem.setItem_number("");lineItem.setQuantity(1);lineItem.setItem_id(-1);lineItems.add(lineItem);}}public String getTransferLotItems() {try {WarehouseService.Client warehouseClient = new WarehouseClient().getClient();Map<Long, Long> transferLotItems = warehouseClient.getItemsInTransferLot(id);CatalogService.Client catalogClient = new CatalogClient().getClient();String transferLotItemDiv = "<div id = 'transfer-lot-item-list-div' align='center'><table id = 'transfer-lot-item-list-table'><tr><th>Item</th><th>Quantity</th></tr>";for(Long itemId : transferLotItems.keySet()){Item item = catalogClient.getItem(itemId);transferLotItemDiv = transferLotItemDiv + "<tr><td>" + item.getBrand() + " " + item.getModelName() + " " + item.getModelNumber() + " " + item.getColor();transferLotItemDiv = transferLotItemDiv + "</td><td>" + transferLotItems.get(itemId) +"</td></tr>";}transferLotItemDiv = transferLotItemDiv + "</table></div>";setOutput(transferLotItemDiv);} catch (TException tex) {logger.error("Error in marking transfer lot as received",tex);} catch (CatalogServiceException csex) {logger.error("Error in marking transfer lot as received",csex);}return OUTPUT;}public String markTransferLotAsReceived() throws Exception {try{WarehouseService.Client warehouseClient = new WarehouseClient().getClient();warehouseClient.markItemsAsReceivedForTransferLot(id);warehouseClient.markTransferLotAsReceived(id, remoteTransferRefNumber);} catch(TException e){logger.error("Error in marking transfer lot as received",e);throw new Exception("Error in marking transfer lot as received");} catch(WarehouseServiceException wsex) {logger.error("Error in marking transfer lot as received",wsex);throw new Exception("Error in marking transfer lot as received");}return INDEX;}public String getWarehouseName(Long warehouseId){return warehouseMap.get(warehouseId).getDisplayName();}public boolean isTransferReceivable(TransferLot transferLot) {if(warehouseMap.get(transferLot.getDestinationWarehouseId()).getWarehouseType()==WarehouseType.OURS_THIRDPARTY||warehouseMap.get(transferLot.getDestinationWarehouseId()).getWarehouseType()==WarehouseType.THIRD_PARTY) {return false;} else {return true;}}public String getDateTime(long milliseconds) {Calendar cal = Calendar.getInstance();cal.setTimeInMillis(milliseconds);return formatter.format(cal.getTime());}public static void setWarehouseMap(Map<Long, Warehouse> warehouseMap) {TransferLotController.warehouseMap = warehouseMap;}public TransferLot getTransferLot() {return transferLot;}public void setTransferLot(TransferLot transferLot) {this.transferLot = transferLot;}public List<TransferLot> getTransferLots() {return transferLots;}public void setTransferLots(List<TransferLot> transferLots) {this.transferLots = transferLots;}public String getRemoteTransferRefNumber() {return remoteTransferRefNumber;}public void setRemoteTransferRefNumber(String remoteTransferRefNumber) {this.remoteTransferRefNumber = remoteTransferRefNumber;}public Long getId() {return id;}public void setId(Long id) {this.id = id;}public String getOutput() {return output;}public void setOutput(String output) {this.output = output;}public Long getOriginWarehouseId() {return originWarehouseId;}public void setOriginWarehouseId(Long originWarehouseId) {this.originWarehouseId = originWarehouseId;}public Long getDestinationWarehouseId() {return destinationWarehouseId;}public void setDestinationWarehouseId(Long destinationWarehouseId) {this.destinationWarehouseId = destinationWarehouseId;}public String getErrorMessage() {return errorMessage;}public void setErrorMsg(String errorMessage) {this.errorMessage = errorMessage;}public List<LineItem> getLineItems() {return lineItems;}public void setLineItems(List<LineItem> lineItems) {this.lineItems = lineItems;}}