| 7410 |
amar.kumar |
1 |
package in.shop2020.inventory.controllers;
|
|
|
2 |
|
| 7452 |
amar.kumar |
3 |
import in.shop2020.inventory.controllers.PurchaseController.ScanRecordType;
|
| 7410 |
amar.kumar |
4 |
import in.shop2020.model.v1.catalog.CatalogService;
|
|
|
5 |
import in.shop2020.model.v1.catalog.CatalogServiceException;
|
|
|
6 |
import in.shop2020.model.v1.catalog.Item;
|
|
|
7 |
import in.shop2020.model.v1.catalog.ItemType;
|
| 7452 |
amar.kumar |
8 |
import in.shop2020.model.v1.inventory.InventoryServiceException;
|
|
|
9 |
import in.shop2020.model.v1.inventory.Vendor;
|
| 7451 |
amar.kumar |
10 |
import in.shop2020.model.v1.inventory.InventoryService.Client;
|
| 7410 |
amar.kumar |
11 |
import in.shop2020.model.v1.inventory.Warehouse;
|
|
|
12 |
import in.shop2020.model.v1.inventory.WarehouseType;
|
|
|
13 |
import in.shop2020.model.v1.order.LineItem;
|
| 7452 |
amar.kumar |
14 |
import in.shop2020.purchase.PurchaseReturn;
|
|
|
15 |
import in.shop2020.purchase.PurchaseServiceException;
|
| 7410 |
amar.kumar |
16 |
import in.shop2020.thrift.clients.CatalogClient;
|
|
|
17 |
import in.shop2020.thrift.clients.InventoryClient;
|
| 7452 |
amar.kumar |
18 |
import in.shop2020.thrift.clients.PurchaseClient;
|
| 7410 |
amar.kumar |
19 |
import in.shop2020.thrift.clients.WarehouseClient;
|
|
|
20 |
import in.shop2020.warehouse.InventoryItem;
|
| 7452 |
amar.kumar |
21 |
import in.shop2020.warehouse.Scan;
|
| 7410 |
amar.kumar |
22 |
import in.shop2020.warehouse.ScanType;
|
|
|
23 |
import in.shop2020.warehouse.TransferLot;
|
| 10121 |
manish.sha |
24 |
import in.shop2020.warehouse.TransferLotStatus;
|
| 7410 |
amar.kumar |
25 |
import in.shop2020.warehouse.WarehouseService;
|
|
|
26 |
import in.shop2020.warehouse.WarehouseServiceException;
|
|
|
27 |
|
| 7451 |
amar.kumar |
28 |
import java.io.BufferedInputStream;
|
|
|
29 |
import java.io.ByteArrayOutputStream;
|
|
|
30 |
import java.io.File;
|
|
|
31 |
import java.io.FileInputStream;
|
|
|
32 |
import java.io.FileNotFoundException;
|
|
|
33 |
import java.io.FileOutputStream;
|
|
|
34 |
import java.io.IOException;
|
|
|
35 |
import java.io.InputStream;
|
| 7452 |
amar.kumar |
36 |
import java.text.DateFormat;
|
| 7410 |
amar.kumar |
37 |
import java.text.ParseException;
|
|
|
38 |
import java.text.SimpleDateFormat;
|
|
|
39 |
import java.util.Calendar;
|
| 7451 |
amar.kumar |
40 |
import java.util.Date;
|
| 7410 |
amar.kumar |
41 |
import java.util.HashMap;
|
| 10121 |
manish.sha |
42 |
import java.util.HashSet;
|
| 7452 |
amar.kumar |
43 |
import java.util.Hashtable;
|
| 7410 |
amar.kumar |
44 |
import java.util.List;
|
|
|
45 |
import java.util.Map;
|
|
|
46 |
import java.util.Map.Entry;
|
| 7452 |
amar.kumar |
47 |
import java.util.Set;
|
|
|
48 |
import java.util.ArrayList;
|
| 7410 |
amar.kumar |
49 |
|
| 7451 |
amar.kumar |
50 |
import javax.servlet.ServletOutputStream;
|
|
|
51 |
|
|
|
52 |
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
|
53 |
import org.apache.poi.ss.usermodel.Row;
|
|
|
54 |
import org.apache.poi.ss.usermodel.Sheet;
|
|
|
55 |
import org.apache.poi.ss.usermodel.Workbook;
|
| 7410 |
amar.kumar |
56 |
import org.apache.thrift.TException;
|
|
|
57 |
import org.apache.thrift.transport.TTransportException;
|
| 10121 |
manish.sha |
58 |
import org.json.JSONObject;
|
| 7410 |
amar.kumar |
59 |
import org.slf4j.Logger;
|
|
|
60 |
import org.slf4j.LoggerFactory;
|
|
|
61 |
|
|
|
62 |
public class TransferLotController extends BaseController{
|
|
|
63 |
|
|
|
64 |
/**
|
|
|
65 |
*
|
|
|
66 |
*/
|
|
|
67 |
private static final long serialVersionUID = 3052114881399915348L;
|
|
|
68 |
|
|
|
69 |
private Long id;
|
|
|
70 |
private TransferLot transferLot;
|
|
|
71 |
private List<TransferLot>transferLots;
|
|
|
72 |
private String remoteTransferRefNumber;
|
|
|
73 |
private String fromDate;
|
|
|
74 |
private String toDate;
|
|
|
75 |
private String errorMessage = "";
|
|
|
76 |
private Calendar transferLotFromDate;
|
|
|
77 |
private Calendar transferLotToDate;
|
|
|
78 |
private Long originWarehouseId;
|
|
|
79 |
private List<LineItem> lineItems;
|
|
|
80 |
private Long destinationWarehouseId;
|
| 10121 |
manish.sha |
81 |
private String inventoryItemsString;
|
|
|
82 |
private JSONObject jsonTransferLotItemData = null;
|
|
|
83 |
private String inventoryItemsLength;
|
|
|
84 |
private String transferLotReceiveType;
|
| 7410 |
amar.kumar |
85 |
|
|
|
86 |
private String output;
|
|
|
87 |
private static Map<Long, Warehouse> warehouseMap;
|
|
|
88 |
|
|
|
89 |
private static SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
90 |
|
| 10121 |
manish.sha |
91 |
private static long totalItemsSizeInTransferLot;
|
|
|
92 |
private static boolean isCompleteTransferAvailable = false;
|
| 7410 |
amar.kumar |
93 |
private static Logger logger = LoggerFactory.getLogger(TransferLotController.class);
|
|
|
94 |
|
|
|
95 |
static {
|
|
|
96 |
warehouseMap = new HashMap<Long, Warehouse>();
|
|
|
97 |
InventoryClient inventoryServiceClient;
|
|
|
98 |
try {
|
|
|
99 |
inventoryServiceClient = new InventoryClient();
|
|
|
100 |
Client inventoryClient = inventoryServiceClient.getClient();
|
|
|
101 |
List<Warehouse> warehouses;
|
|
|
102 |
warehouses = inventoryClient.getAllWarehouses(true);
|
|
|
103 |
for(Warehouse warehouse : warehouses){
|
|
|
104 |
warehouseMap.put(warehouse.getId(), warehouse);
|
|
|
105 |
}
|
|
|
106 |
} catch (TTransportException e) {
|
|
|
107 |
logger.error("Error in populating warehouse map", e);
|
|
|
108 |
} catch (TException e) {
|
|
|
109 |
logger.error("Error in populating warehouse map", e);
|
|
|
110 |
} catch (InventoryServiceException isex) {
|
|
|
111 |
logger.error("Error in populating warehouse map", isex);
|
|
|
112 |
}
|
|
|
113 |
}
|
|
|
114 |
|
|
|
115 |
public String index(){
|
|
|
116 |
if(warehouseMap==null||warehouseMap.size()<1){
|
| 7448 |
amar.kumar |
117 |
fetchWarehouseMap();
|
| 7410 |
amar.kumar |
118 |
}
|
|
|
119 |
try{
|
|
|
120 |
WarehouseService.Client warehouseClient = new WarehouseClient().getClient();
|
|
|
121 |
transferLotFromDate = Calendar.getInstance();
|
|
|
122 |
transferLotToDate = Calendar.getInstance();
|
|
|
123 |
if(fromDate==null) {
|
| 11769 |
manish.sha |
124 |
transferLotFromDate.add(Calendar.MONTH, -12);
|
| 7410 |
amar.kumar |
125 |
} else {
|
|
|
126 |
transferLotFromDate.setTime(formatter.parse(fromDate));
|
|
|
127 |
if(toDate!=null) {
|
|
|
128 |
transferLotToDate.setTime(formatter.parse(toDate));
|
|
|
129 |
}
|
|
|
130 |
}
|
| 13940 |
manish.sha |
131 |
List<TransferLot> allTransferLots = warehouseClient.getTransferLotsByDate(transferLotFromDate.getTimeInMillis(), transferLotToDate.getTimeInMillis());
|
| 13957 |
manish.sha |
132 |
transferLots = new ArrayList<TransferLot>();
|
| 13940 |
manish.sha |
133 |
for(TransferLot transferLot: allTransferLots){
|
|
|
134 |
if(transferLot.getStatus()!=TransferLotStatus.TRANSFER_COMPLETE){
|
|
|
135 |
transferLots.add(transferLot);
|
|
|
136 |
}
|
|
|
137 |
}
|
|
|
138 |
//transferLots = warehouseClient.getTransferLotsByDate(transferLotFromDate.getTimeInMillis(), transferLotToDate.getTimeInMillis());
|
| 7410 |
amar.kumar |
139 |
} catch(TException e){
|
|
|
140 |
logger.error("Error in getting transfer lots", e);
|
|
|
141 |
} catch(ParseException pex) {
|
|
|
142 |
logger.error("Error in parsing time", pex);
|
|
|
143 |
} catch(WarehouseServiceException wsex) {
|
|
|
144 |
logger.error("Error in getting transfer lots", wsex);
|
|
|
145 |
}
|
|
|
146 |
return INDEX;
|
|
|
147 |
}
|
|
|
148 |
|
| 7448 |
amar.kumar |
149 |
private void fetchWarehouseMap() {
|
|
|
150 |
warehouseMap = new HashMap<Long, Warehouse>();
|
|
|
151 |
InventoryClient inventoryServiceClient;
|
|
|
152 |
try {
|
|
|
153 |
inventoryServiceClient = new InventoryClient();
|
|
|
154 |
Client inventoryClient = inventoryServiceClient.getClient();
|
|
|
155 |
List<Warehouse> warehouses;
|
|
|
156 |
warehouses = inventoryClient.getAllWarehouses(true);
|
|
|
157 |
for(Warehouse warehouse : warehouses){
|
|
|
158 |
warehouseMap.put(warehouse.getId(), warehouse);
|
|
|
159 |
}
|
|
|
160 |
} catch (TTransportException e) {
|
|
|
161 |
logger.error("Error in populating warehouse map", e);
|
|
|
162 |
} catch (TException e) {
|
|
|
163 |
logger.error("Error in populating warehouse map", e);
|
|
|
164 |
} catch (InventoryServiceException isex) {
|
|
|
165 |
logger.error("Error in populating warehouse map", isex);
|
|
|
166 |
}
|
|
|
167 |
}
|
|
|
168 |
|
|
|
169 |
public String create() {
|
| 7410 |
amar.kumar |
170 |
originWarehouseId = Long.parseLong(request.getParameter("originWarehouseId"));
|
|
|
171 |
destinationWarehouseId = Long.parseLong(request.getParameter("destinationWarehouseId"));
|
|
|
172 |
try {
|
|
|
173 |
WarehouseService.Client warehouseClient = new WarehouseClient().getClient();
|
|
|
174 |
id = warehouseClient.createTransferLot(originWarehouseId, destinationWarehouseId);
|
|
|
175 |
} catch (TException tex) {
|
|
|
176 |
logger.error("Error in creating transferlot between warehouseId " + originWarehouseId + " and " + destinationWarehouseId, tex);
|
|
|
177 |
errorMessage = "Error in creating transferlot between warehouseId " + originWarehouseId + " and " + destinationWarehouseId;
|
|
|
178 |
} catch (WarehouseServiceException wex) {
|
|
|
179 |
logger.error("Error in creating transferlot between warehouseId " + originWarehouseId + " and " + destinationWarehouseId, wex);
|
|
|
180 |
errorMessage = "Error in creating transferlot between warehouseId " + originWarehouseId + " and " + destinationWarehouseId;
|
|
|
181 |
}
|
|
|
182 |
return show();
|
|
|
183 |
}
|
|
|
184 |
|
|
|
185 |
public String show(){
|
|
|
186 |
resetLineItems();
|
|
|
187 |
return SHOW;
|
|
|
188 |
}
|
|
|
189 |
public String update() {
|
|
|
190 |
try {
|
|
|
191 |
if(!areValidScans()){
|
|
|
192 |
errorMessage = "Invalid Scans";
|
|
|
193 |
return show();
|
|
|
194 |
}
|
|
|
195 |
if(id == null || id==0) {
|
|
|
196 |
errorMessage = "No transferLot-Id selected for Transfer";
|
|
|
197 |
return "new";
|
|
|
198 |
}
|
|
|
199 |
List<InventoryItem> inventoryItems = new ArrayList<InventoryItem>();
|
|
|
200 |
CatalogService.Client catalogClient = new CatalogClient().getClient();
|
|
|
201 |
for (LineItem lineItem : lineItems) {
|
|
|
202 |
if (lineItem.getItem_id() == 0) {
|
|
|
203 |
continue;
|
|
|
204 |
}
|
|
|
205 |
InventoryItem inventoryItem = new InventoryItem();
|
|
|
206 |
inventoryItem.setItemId(lineItem.getItem_id());
|
|
|
207 |
inventoryItem.setCurrentQuantity(new Double(lineItem.getQuantity()).longValue());
|
|
|
208 |
inventoryItem.setItemNumber(lineItem.getItem_number());
|
|
|
209 |
if(catalogClient.getItem(lineItem.getItem_id()).getType()==ItemType.SERIALIZED) {
|
|
|
210 |
inventoryItem.setSerialNumber(lineItem.getSerial_number());
|
|
|
211 |
}
|
|
|
212 |
inventoryItems.add(inventoryItem);
|
|
|
213 |
}
|
|
|
214 |
WarehouseService.Client warehouseClient = new WarehouseClient().getClient();
|
| 7448 |
amar.kumar |
215 |
warehouseClient.scanForTransferOut(inventoryItems, ScanType.WAREHOUSE_TRANSFER_OUT, id);
|
| 7410 |
amar.kumar |
216 |
} catch (TTransportException e) {
|
|
|
217 |
errorMessage = "Error while establishing connection to the warehouse server";
|
|
|
218 |
logger.error(errorMessage, e);
|
|
|
219 |
} catch (WarehouseServiceException e) {
|
|
|
220 |
errorMessage = e.getMessage();
|
|
|
221 |
logger.error(errorMessage, e);
|
|
|
222 |
} catch (TException e) {
|
|
|
223 |
errorMessage = "Error while scanning in the item";
|
|
|
224 |
logger.error(errorMessage, e);
|
|
|
225 |
} catch (CatalogServiceException csex) {
|
|
|
226 |
errorMessage = "Error while getting the serialized details of item";
|
|
|
227 |
logger.error(errorMessage, csex);
|
|
|
228 |
}
|
|
|
229 |
return show();
|
|
|
230 |
}
|
|
|
231 |
|
|
|
232 |
public String editNew(){
|
|
|
233 |
return "new";
|
|
|
234 |
}
|
|
|
235 |
|
|
|
236 |
private boolean areValidScans() throws NumberFormatException, TException {
|
|
|
237 |
boolean areValidScans = true;
|
|
|
238 |
return areValidScans;
|
|
|
239 |
}
|
|
|
240 |
|
|
|
241 |
private void resetLineItems() {
|
|
|
242 |
lineItems = new ArrayList<LineItem>();
|
|
|
243 |
|
|
|
244 |
for (int i = 0; i < 11; i++) {
|
|
|
245 |
LineItem lineItem = new LineItem();
|
|
|
246 |
lineItem.setId(i);
|
|
|
247 |
lineItem.setExtra_info("");
|
|
|
248 |
lineItem.setSerial_number("");
|
|
|
249 |
lineItem.setItem_number("");
|
|
|
250 |
lineItem.setQuantity(1);
|
|
|
251 |
lineItem.setItem_id(-1);
|
|
|
252 |
lineItems.add(lineItem);
|
|
|
253 |
}
|
|
|
254 |
}
|
|
|
255 |
|
|
|
256 |
public String getTransferLotItems() {
|
|
|
257 |
try {
|
|
|
258 |
WarehouseService.Client warehouseClient = new WarehouseClient().getClient();
|
|
|
259 |
Map<Long, Long> transferLotItems = warehouseClient.getItemsInTransferLot(id);
|
|
|
260 |
CatalogService.Client catalogClient = new CatalogClient().getClient();
|
|
|
261 |
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>";
|
|
|
262 |
for(Long itemId : transferLotItems.keySet()){
|
|
|
263 |
Item item = catalogClient.getItem(itemId);
|
|
|
264 |
transferLotItemDiv = transferLotItemDiv + "<tr><td>" + item.getBrand() + " " + item.getModelName() + " " + item.getModelNumber() + " " + item.getColor();
|
|
|
265 |
transferLotItemDiv = transferLotItemDiv + "</td><td>" + transferLotItems.get(itemId) +"</td></tr>";
|
|
|
266 |
}
|
|
|
267 |
transferLotItemDiv = transferLotItemDiv + "</table></div>";
|
|
|
268 |
setOutput(transferLotItemDiv);
|
|
|
269 |
} catch (TException tex) {
|
| 7451 |
amar.kumar |
270 |
logger.error("Error in getting transfer lot items",tex);
|
| 7410 |
amar.kumar |
271 |
} catch (CatalogServiceException csex) {
|
| 7451 |
amar.kumar |
272 |
logger.error("Error in getting transfer lot items",csex);
|
| 7410 |
amar.kumar |
273 |
}
|
|
|
274 |
return OUTPUT;
|
|
|
275 |
}
|
| 10121 |
manish.sha |
276 |
|
|
|
277 |
public String getTransferLotItemsForMarkReceive(){
|
|
|
278 |
try{
|
|
|
279 |
WarehouseService.Client warehouseClient = new WarehouseClient().getClient();
|
|
|
280 |
List<InventoryItem> inventoryItems = warehouseClient.getTransferLotItemsForMarkReceive(id, ScanType.WAREHOUSE_TRANSFER_OUT);
|
|
|
281 |
CatalogService.Client catalogClient = new CatalogClient().getClient();
|
|
|
282 |
Set<Long> itemIdSet = new HashSet<Long>();
|
|
|
283 |
Map<Long,Map<String,String>> itemDataMap = new HashMap<Long,Map<String,String>>();
|
|
|
284 |
Map<String,List<Map<String,String>>> jsonDataMap = new HashMap<String,List<Map<String,String>>>();
|
|
|
285 |
List<Map<String,String>> jsonDataList = new ArrayList<Map<String,String>>();
|
|
|
286 |
//long quantity = 0;
|
|
|
287 |
for(InventoryItem item : inventoryItems){
|
|
|
288 |
itemIdSet.add(item.getItemId());
|
|
|
289 |
}
|
|
|
290 |
for(Long id : itemIdSet){
|
|
|
291 |
Item catalogItem = catalogClient.getItem(id);
|
|
|
292 |
Map<String,String> itemdetailsMap = new HashMap<String,String>();
|
|
|
293 |
itemdetailsMap.put("Name", catalogItem.getBrand() + " " + catalogItem.getModelName() + " " + catalogItem.getModelNumber() + " " + catalogItem.getColor());
|
|
|
294 |
itemdetailsMap.put("Type", catalogItem.getType().name());
|
|
|
295 |
itemDataMap.put(id,itemdetailsMap);
|
|
|
296 |
}
|
|
|
297 |
for(InventoryItem item : inventoryItems){
|
|
|
298 |
Map<String,String> dataMap = new HashMap<String,String>();
|
|
|
299 |
ItemType type = ItemType.valueOf(itemDataMap.get(item.getItemId()).get("Type"));
|
|
|
300 |
dataMap.put("ItemId",item.getId()+"");
|
|
|
301 |
if(ItemType.SERIALIZED == type){
|
|
|
302 |
dataMap.put("ItemDetail",itemDataMap.get(item.getItemId()).get("Name") +"-"+ item.getSerialNumber()+"-Units("+item.getInitialQuantity()+")");
|
|
|
303 |
}
|
|
|
304 |
else{
|
| 12932 |
manish.sha |
305 |
dataMap.put("ItemDetail",itemDataMap.get(item.getItemId()).get("Name") +"-"+ item.getItemNumber()+"-Units("+item.getCurrentQuantity()+")");
|
| 10121 |
manish.sha |
306 |
}
|
|
|
307 |
TransferLotStatus transferLotStatus = item.getTransferStatus();
|
|
|
308 |
if(TransferLotStatus.IN_TRANSIT == transferLotStatus){
|
|
|
309 |
dataMap.put("ItemStatus","Enabled");
|
|
|
310 |
}
|
|
|
311 |
else{
|
|
|
312 |
dataMap.put("ItemStatus","Disabled");
|
|
|
313 |
}
|
|
|
314 |
//quantity = quantity + item.getInitialQuantity();
|
|
|
315 |
jsonDataList.add(dataMap);
|
|
|
316 |
|
|
|
317 |
}
|
|
|
318 |
totalItemsSizeInTransferLot= inventoryItems.size();
|
|
|
319 |
jsonDataMap.put("TransferLotItemData", jsonDataList);
|
|
|
320 |
|
|
|
321 |
setJsonTransferLotItemData(new JSONObject(jsonDataMap));
|
|
|
322 |
|
|
|
323 |
} catch(Exception e){
|
|
|
324 |
logger.error("Error While getting Transfer Lot Items for Mark Receive",e);
|
|
|
325 |
}
|
|
|
326 |
return OUTPUT;
|
|
|
327 |
}
|
| 7410 |
amar.kumar |
328 |
|
|
|
329 |
public String markTransferLotAsReceived() throws Exception {
|
|
|
330 |
try{
|
|
|
331 |
WarehouseService.Client warehouseClient = new WarehouseClient().getClient();
|
|
|
332 |
warehouseClient.markItemsAsReceivedForTransferLot(id);
|
|
|
333 |
warehouseClient.markTransferLotAsReceived(id, remoteTransferRefNumber);
|
|
|
334 |
} catch(TException e){
|
|
|
335 |
logger.error("Error in marking transfer lot as received",e);
|
|
|
336 |
throw new Exception("Error in marking transfer lot as received");
|
|
|
337 |
} catch(WarehouseServiceException wsex) {
|
|
|
338 |
logger.error("Error in marking transfer lot as received",wsex);
|
|
|
339 |
throw new Exception("Error in marking transfer lot as received");
|
|
|
340 |
}
|
|
|
341 |
return INDEX;
|
|
|
342 |
}
|
|
|
343 |
|
| 10121 |
manish.sha |
344 |
public String markTransferLotAsReceivedPartial() throws Exception {
|
|
|
345 |
try{
|
|
|
346 |
WarehouseService.Client warehouseClient = new WarehouseClient().getClient();
|
|
|
347 |
TransferLot transferLot = warehouseClient.getTransferLot(id);
|
|
|
348 |
if(transferLot.getTransitCompletionReferenceNumber()!=null && !("").equalsIgnoreCase(transferLot.getTransitCompletionReferenceNumber())){
|
|
|
349 |
remoteTransferRefNumber = transferLot.getTransitCompletionReferenceNumber()+":"+remoteTransferRefNumber;
|
|
|
350 |
}
|
|
|
351 |
if("complete".equalsIgnoreCase(transferLotReceiveType)){
|
|
|
352 |
|
|
|
353 |
System.out.println("In Transfer Complete Block");
|
|
|
354 |
|
|
|
355 |
if (TransferLotStatus.IN_TRANSIT.equals(transferLot.getStatus())){
|
|
|
356 |
if(!warehouseClient.isAlive()){
|
|
|
357 |
warehouseClient = new WarehouseClient().getClient();
|
|
|
358 |
}
|
|
|
359 |
warehouseClient.markItemsAsReceivedForTransferLot(id);
|
|
|
360 |
warehouseClient.markTransferLotAsReceived(id, remoteTransferRefNumber);
|
|
|
361 |
}
|
|
|
362 |
if (TransferLotStatus.PARTIAL_TRANSFER.equals(transferLot.getStatus())){
|
|
|
363 |
String[] inventoryItemsArr = inventoryItemsString.split(",");
|
|
|
364 |
//System.out.println("inventoryItemsArr Length... "+inventoryItemsArr.length);
|
|
|
365 |
|
|
|
366 |
List<InventoryItem> inventoryItemList = new ArrayList<InventoryItem>();
|
|
|
367 |
for(String inventItemStr : inventoryItemsArr){
|
|
|
368 |
if(!warehouseClient.isAlive()){
|
|
|
369 |
warehouseClient = new WarehouseClient().getClient();
|
|
|
370 |
}
|
|
|
371 |
InventoryItem item = warehouseClient.getInventoryItemFromId(Long.parseLong(inventItemStr));
|
|
|
372 |
inventoryItemList.add(item);
|
|
|
373 |
}
|
|
|
374 |
if(!warehouseClient.isAlive()){
|
|
|
375 |
warehouseClient = new WarehouseClient().getClient();
|
|
|
376 |
}
|
|
|
377 |
warehouseClient.markItemsAsReceivedForTransferLotPartial(inventoryItemList,id);
|
|
|
378 |
warehouseClient.markTransferLotAsReceived(id, remoteTransferRefNumber);
|
|
|
379 |
}
|
|
|
380 |
}
|
|
|
381 |
else{
|
|
|
382 |
List<InventoryItem> inventoryItemsScannedIn = warehouseClient.getTransferLotItemsForMarkReceive(id,ScanType.WAREHOUSE_TRANSFER_IN);
|
|
|
383 |
System.out.println("totalItemsSizeInTransferLot....."+totalItemsSizeInTransferLot);
|
|
|
384 |
int totalItemsSizeScannedIn = inventoryItemsScannedIn.size();
|
|
|
385 |
int totalItemsSizeToBeScanIn = Integer.parseInt(inventoryItemsLength);
|
|
|
386 |
System.out.println("totalItemsSizeScannedIn....."+totalItemsSizeScannedIn);
|
|
|
387 |
System.out.println("totalItemsSizeToBeScanIn....."+totalItemsSizeToBeScanIn);
|
|
|
388 |
|
|
|
389 |
String[] inventoryItemsArr = inventoryItemsString.split(",");
|
|
|
390 |
System.out.println("inventoryItemsArr Length... "+inventoryItemsArr.length);
|
|
|
391 |
|
|
|
392 |
List<InventoryItem> inventoryItemList = new ArrayList<InventoryItem>();
|
|
|
393 |
for(String inventItemStr : inventoryItemsArr){
|
|
|
394 |
if(!warehouseClient.isAlive()){
|
|
|
395 |
warehouseClient = new WarehouseClient().getClient();
|
|
|
396 |
}
|
|
|
397 |
InventoryItem item = warehouseClient.getInventoryItemFromId(Long.parseLong(inventItemStr));
|
|
|
398 |
inventoryItemList.add(item);
|
|
|
399 |
}
|
|
|
400 |
if(totalItemsSizeToBeScanIn==totalItemsSizeInTransferLot){
|
|
|
401 |
System.out.println("Transfer Complete");
|
|
|
402 |
if(!warehouseClient.isAlive()){
|
|
|
403 |
warehouseClient = new WarehouseClient().getClient();
|
|
|
404 |
}
|
|
|
405 |
warehouseClient.markItemsAsReceivedForTransferLot(id);
|
|
|
406 |
warehouseClient.markTransferLotAsReceived(id, remoteTransferRefNumber);
|
|
|
407 |
}
|
|
|
408 |
if(totalItemsSizeInTransferLot== (totalItemsSizeScannedIn + totalItemsSizeToBeScanIn)){
|
|
|
409 |
System.out.println("Transfer Complete.... from Partial");
|
|
|
410 |
if(!warehouseClient.isAlive()){
|
|
|
411 |
warehouseClient = new WarehouseClient().getClient();
|
|
|
412 |
}
|
|
|
413 |
warehouseClient.markItemsAsReceivedForTransferLotPartial(inventoryItemList,id);
|
|
|
414 |
warehouseClient.markTransferLotAsReceived(id, remoteTransferRefNumber);
|
|
|
415 |
}
|
|
|
416 |
if(totalItemsSizeToBeScanIn<totalItemsSizeInTransferLot){
|
|
|
417 |
System.out.println("Items and Transfer Lot Partial");
|
|
|
418 |
if(!warehouseClient.isAlive()){
|
|
|
419 |
warehouseClient = new WarehouseClient().getClient();
|
|
|
420 |
}
|
|
|
421 |
warehouseClient.markItemsAsReceivedForTransferLotPartial(inventoryItemList,id);
|
|
|
422 |
warehouseClient.markTransferLotAsReceivedPartial(id, remoteTransferRefNumber);
|
|
|
423 |
}
|
|
|
424 |
}
|
|
|
425 |
|
|
|
426 |
} catch(Exception e){
|
|
|
427 |
logger.error("Error in marking transfer lot as received",e);
|
|
|
428 |
throw new Exception("Error in marking transfer lot as received");
|
|
|
429 |
}
|
|
|
430 |
return INDEX;
|
|
|
431 |
}
|
|
|
432 |
|
| 7451 |
amar.kumar |
433 |
public void downloadFBASheet() {
|
|
|
434 |
try {
|
|
|
435 |
WarehouseService.Client warehouseClient = new WarehouseClient().getClient();
|
|
|
436 |
Map<Long, Long> transferLotItems = warehouseClient.getItemsInTransferLot(id);
|
|
|
437 |
|
| 7588 |
amar.kumar |
438 |
File fbaSheetFile = new File("transfer-lot-"+id+"-sheet_"+new Date() + ".xls");
|
| 7451 |
amar.kumar |
439 |
FileOutputStream fStream = null;
|
|
|
440 |
try {
|
|
|
441 |
fStream = new FileOutputStream(fbaSheetFile);
|
|
|
442 |
} catch (FileNotFoundException e1) {
|
|
|
443 |
logger.error(e1.getMessage());
|
|
|
444 |
}
|
|
|
445 |
ByteArrayOutputStream baosXLS = new ByteArrayOutputStream();
|
|
|
446 |
Workbook wb = new HSSFWorkbook();
|
|
|
447 |
Sheet fbaSheet = wb.createSheet("FBA Sheet");
|
|
|
448 |
|
|
|
449 |
Row merchantShipmentName = fbaSheet.createRow((short)0);
|
|
|
450 |
merchantShipmentName.createCell(0).setCellValue("MerchantShipmentName");
|
|
|
451 |
Row labelPrepPreference = fbaSheet.createRow((short)1);
|
|
|
452 |
labelPrepPreference.createCell(0).setCellValue("LabelPrepPreference");
|
|
|
453 |
Row addressName = fbaSheet.createRow((short)2);
|
|
|
454 |
addressName.createCell(0).setCellValue("AddressName");
|
|
|
455 |
Row addressFieldOne = fbaSheet.createRow((short)3);
|
|
|
456 |
addressFieldOne.createCell(0).setCellValue("AddressFieldOne");
|
|
|
457 |
Row addressFieldTwo = fbaSheet.createRow((short)4);
|
|
|
458 |
addressFieldTwo.createCell(0).setCellValue("AddressFieldTwo");
|
|
|
459 |
Row addressCity = fbaSheet.createRow((short)5);
|
|
|
460 |
addressCity.createCell(0).setCellValue("AddressCity");
|
|
|
461 |
Row addressCountryCode = fbaSheet.createRow((short)6);
|
|
|
462 |
addressCountryCode.createCell(0).setCellValue("AddressCountryCode");
|
|
|
463 |
Row addressStateOrRegion = fbaSheet.createRow((short)7);
|
|
|
464 |
addressStateOrRegion.createCell(0).setCellValue("AddressStateOrRegion");
|
|
|
465 |
Row addressPostalCode = fbaSheet.createRow((short)8);
|
|
|
466 |
addressPostalCode.createCell(0).setCellValue("AddressPostalCode");
|
|
|
467 |
Row addressDistrict = fbaSheet.createRow((short)9);
|
|
|
468 |
addressDistrict.createCell(0).setCellValue("AddressDistrict");
|
|
|
469 |
|
|
|
470 |
Row blankRow = fbaSheet.createRow((short)10);
|
|
|
471 |
//blankRow.createCell(0).setCellValue("AddressPostalCode");
|
|
|
472 |
|
|
|
473 |
Row skuHeaders = fbaSheet.createRow((short)11);
|
|
|
474 |
skuHeaders.createCell(0).setCellValue("MerchantSKU");
|
|
|
475 |
skuHeaders.createCell(1).setCellValue("Quantity");
|
|
|
476 |
|
|
|
477 |
int rowCount = 12;
|
|
|
478 |
for(Entry<Long, Long> itemQuantity : transferLotItems.entrySet()) {
|
|
|
479 |
Row newRow = fbaSheet.createRow((short)rowCount);
|
|
|
480 |
newRow.createCell(0).setCellValue("FBA"+itemQuantity.getKey());
|
|
|
481 |
newRow.createCell(1).setCellValue(itemQuantity.getValue());
|
|
|
482 |
rowCount++;
|
|
|
483 |
}
|
|
|
484 |
|
|
|
485 |
try {
|
|
|
486 |
wb.write(baosXLS);
|
|
|
487 |
baosXLS.close();
|
|
|
488 |
baosXLS.writeTo(fStream);
|
|
|
489 |
fStream.flush();
|
|
|
490 |
fStream.close();
|
|
|
491 |
} catch(IOException e) {
|
|
|
492 |
//TODO
|
|
|
493 |
}
|
|
|
494 |
byte[] buffer = null;
|
|
|
495 |
buffer = new byte[(int) fbaSheetFile.length()];
|
|
|
496 |
InputStream input = null;
|
|
|
497 |
try {
|
|
|
498 |
int totalBytesRead = 0;
|
|
|
499 |
input = new BufferedInputStream(new FileInputStream(fbaSheetFile));
|
|
|
500 |
while (totalBytesRead < buffer.length) {
|
|
|
501 |
int bytesRemaining = buffer.length - totalBytesRead;
|
|
|
502 |
// input.read() returns -1, 0, or more :
|
|
|
503 |
int bytesRead = input.read(buffer, totalBytesRead,
|
|
|
504 |
bytesRemaining);
|
|
|
505 |
if (bytesRead > 0) {
|
|
|
506 |
totalBytesRead = totalBytesRead + bytesRead;
|
|
|
507 |
}
|
|
|
508 |
}
|
|
|
509 |
|
|
|
510 |
/* the above style is a bit tricky: it places bytes into the
|
|
|
511 |
* 'buffer' array; 'buffer' is an output parameter; the while
|
|
|
512 |
* loop usually has a single iteration only.*/
|
|
|
513 |
|
|
|
514 |
} finally {
|
|
|
515 |
input.close();
|
|
|
516 |
}
|
|
|
517 |
|
|
|
518 |
response.setContentType("application/vnd.ms-excel");
|
| 7588 |
amar.kumar |
519 |
response.setHeader("Content-disposition", "attachment; filename="
|
| 7451 |
amar.kumar |
520 |
+ fbaSheetFile.getName());
|
|
|
521 |
|
|
|
522 |
ServletOutputStream sos = response.getOutputStream();
|
|
|
523 |
sos.write(buffer);
|
|
|
524 |
sos.flush();
|
|
|
525 |
|
|
|
526 |
} catch (TException tex) {
|
|
|
527 |
logger.error("Error in generating fba sheet for transfer Lot Id " + id,tex);
|
|
|
528 |
} catch (FileNotFoundException fnfex) {
|
|
|
529 |
logger.error("Error in generating fba sheet for transfer Lot Id " + id,fnfex);
|
|
|
530 |
} catch (IOException ioex) {
|
|
|
531 |
logger.error("Error in generating fba sheet for transfer Lot Id " + id,ioex);
|
|
|
532 |
}
|
|
|
533 |
|
|
|
534 |
}
|
|
|
535 |
|
| 7410 |
amar.kumar |
536 |
public String getWarehouseName(Long warehouseId){
|
|
|
537 |
return warehouseMap.get(warehouseId).getDisplayName();
|
|
|
538 |
}
|
|
|
539 |
|
|
|
540 |
public boolean isTransferReceivable(TransferLot transferLot) {
|
|
|
541 |
if(warehouseMap.get(transferLot.getDestinationWarehouseId()).getWarehouseType()==WarehouseType.OURS_THIRDPARTY||
|
|
|
542 |
warehouseMap.get(transferLot.getDestinationWarehouseId()).getWarehouseType()==WarehouseType.THIRD_PARTY) {
|
|
|
543 |
return false;
|
|
|
544 |
} else {
|
|
|
545 |
return true;
|
|
|
546 |
}
|
|
|
547 |
}
|
|
|
548 |
|
|
|
549 |
|
|
|
550 |
|
|
|
551 |
|
|
|
552 |
public String getDateTime(long milliseconds) {
|
|
|
553 |
Calendar cal = Calendar.getInstance();
|
|
|
554 |
cal.setTimeInMillis(milliseconds);
|
|
|
555 |
return formatter.format(cal.getTime());
|
|
|
556 |
}
|
|
|
557 |
|
|
|
558 |
public static void setWarehouseMap(Map<Long, Warehouse> warehouseMap) {
|
|
|
559 |
TransferLotController.warehouseMap = warehouseMap;
|
|
|
560 |
}
|
|
|
561 |
|
|
|
562 |
public TransferLot getTransferLot() {
|
|
|
563 |
return transferLot;
|
|
|
564 |
}
|
|
|
565 |
|
|
|
566 |
public void setTransferLot(TransferLot transferLot) {
|
|
|
567 |
this.transferLot = transferLot;
|
|
|
568 |
}
|
|
|
569 |
|
|
|
570 |
public List<TransferLot> getTransferLots() {
|
|
|
571 |
return transferLots;
|
|
|
572 |
}
|
|
|
573 |
|
|
|
574 |
public void setTransferLots(List<TransferLot> transferLots) {
|
|
|
575 |
this.transferLots = transferLots;
|
|
|
576 |
}
|
|
|
577 |
|
|
|
578 |
public String getRemoteTransferRefNumber() {
|
|
|
579 |
return remoteTransferRefNumber;
|
|
|
580 |
}
|
|
|
581 |
|
|
|
582 |
public void setRemoteTransferRefNumber(String remoteTransferRefNumber) {
|
|
|
583 |
this.remoteTransferRefNumber = remoteTransferRefNumber;
|
|
|
584 |
}
|
|
|
585 |
|
|
|
586 |
public Long getId() {
|
|
|
587 |
return id;
|
|
|
588 |
}
|
|
|
589 |
|
|
|
590 |
public void setId(Long id) {
|
|
|
591 |
this.id = id;
|
|
|
592 |
}
|
|
|
593 |
|
|
|
594 |
public String getOutput() {
|
|
|
595 |
return output;
|
|
|
596 |
}
|
|
|
597 |
|
|
|
598 |
public void setOutput(String output) {
|
|
|
599 |
this.output = output;
|
|
|
600 |
}
|
|
|
601 |
|
|
|
602 |
public Long getOriginWarehouseId() {
|
|
|
603 |
return originWarehouseId;
|
|
|
604 |
}
|
|
|
605 |
|
|
|
606 |
public void setOriginWarehouseId(Long originWarehouseId) {
|
|
|
607 |
this.originWarehouseId = originWarehouseId;
|
|
|
608 |
}
|
|
|
609 |
|
|
|
610 |
public Long getDestinationWarehouseId() {
|
|
|
611 |
return destinationWarehouseId;
|
|
|
612 |
}
|
|
|
613 |
|
|
|
614 |
public void setDestinationWarehouseId(Long destinationWarehouseId) {
|
|
|
615 |
this.destinationWarehouseId = destinationWarehouseId;
|
|
|
616 |
}
|
|
|
617 |
|
|
|
618 |
public String getErrorMessage() {
|
|
|
619 |
return errorMessage;
|
|
|
620 |
}
|
|
|
621 |
|
|
|
622 |
public void setErrorMsg(String errorMessage) {
|
|
|
623 |
this.errorMessage = errorMessage;
|
|
|
624 |
}
|
|
|
625 |
|
|
|
626 |
public List<LineItem> getLineItems() {
|
|
|
627 |
return lineItems;
|
|
|
628 |
}
|
|
|
629 |
|
|
|
630 |
public void setLineItems(List<LineItem> lineItems) {
|
|
|
631 |
this.lineItems = lineItems;
|
|
|
632 |
}
|
| 10121 |
manish.sha |
633 |
|
|
|
634 |
public JSONObject getJsonTransferLotItemData() {
|
|
|
635 |
return jsonTransferLotItemData;
|
|
|
636 |
}
|
|
|
637 |
|
|
|
638 |
public void setJsonTransferLotItemData(JSONObject jsonTransferLotItemData) {
|
|
|
639 |
this.jsonTransferLotItemData = jsonTransferLotItemData;
|
|
|
640 |
}
|
|
|
641 |
|
|
|
642 |
public String getInventoryItemsString() {
|
|
|
643 |
return inventoryItemsString;
|
|
|
644 |
}
|
|
|
645 |
|
|
|
646 |
public void setInventoryItemsString(String inventoryItemsString) {
|
|
|
647 |
this.inventoryItemsString = inventoryItemsString;
|
|
|
648 |
}
|
|
|
649 |
|
|
|
650 |
public String getInventoryItemsLength() {
|
|
|
651 |
return inventoryItemsLength;
|
|
|
652 |
}
|
|
|
653 |
|
|
|
654 |
public void setInventoryItemsLength(String inventoryItemsLength) {
|
|
|
655 |
this.inventoryItemsLength = inventoryItemsLength;
|
|
|
656 |
}
|
|
|
657 |
|
|
|
658 |
public String getTransferLotReceiveType() {
|
|
|
659 |
return transferLotReceiveType;
|
|
|
660 |
}
|
|
|
661 |
|
|
|
662 |
public void setTransferLotReceiveType(String transferLotReceiveType) {
|
|
|
663 |
this.transferLotReceiveType = transferLotReceiveType;
|
|
|
664 |
}
|
|
|
665 |
|
| 7410 |
amar.kumar |
666 |
}
|