Subversion Repositories SmartDukaan

Rev

Rev 7448 | Rev 7452 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 7448 Rev 7451
Line 1... Line 1...
1
package in.shop2020.inventory.controllers;
1
package in.shop2020.inventory.controllers;
2
 
2
 
3
import in.shop2020.inventory.controllers.PurchaseController.ScanRecordType;
-
 
4
import in.shop2020.model.v1.catalog.CatalogService;
3
import in.shop2020.model.v1.catalog.CatalogService;
5
import in.shop2020.model.v1.catalog.CatalogServiceException;
4
import in.shop2020.model.v1.catalog.CatalogServiceException;
6
import in.shop2020.model.v1.catalog.Item;
5
import in.shop2020.model.v1.catalog.Item;
7
import in.shop2020.model.v1.catalog.ItemType;
6
import in.shop2020.model.v1.catalog.ItemType;
8
import in.shop2020.model.v1.inventory.InventoryServiceException;
-
 
9
import in.shop2020.model.v1.inventory.Vendor;
-
 
10
import in.shop2020.model.v1.inventory.InventoryService.Client;
7
import in.shop2020.model.v1.inventory.InventoryService.Client;
-
 
8
import in.shop2020.model.v1.inventory.InventoryServiceException;
11
import in.shop2020.model.v1.inventory.Warehouse;
9
import in.shop2020.model.v1.inventory.Warehouse;
12
import in.shop2020.model.v1.inventory.WarehouseType;
10
import in.shop2020.model.v1.inventory.WarehouseType;
13
import in.shop2020.model.v1.order.LineItem;
11
import in.shop2020.model.v1.order.LineItem;
14
import in.shop2020.purchase.PurchaseReturn;
-
 
15
import in.shop2020.purchase.PurchaseServiceException;
-
 
16
import in.shop2020.thrift.clients.CatalogClient;
12
import in.shop2020.thrift.clients.CatalogClient;
17
import in.shop2020.thrift.clients.InventoryClient;
13
import in.shop2020.thrift.clients.InventoryClient;
18
import in.shop2020.thrift.clients.PurchaseClient;
-
 
19
import in.shop2020.thrift.clients.WarehouseClient;
14
import in.shop2020.thrift.clients.WarehouseClient;
20
import in.shop2020.warehouse.InventoryItem;
15
import in.shop2020.warehouse.InventoryItem;
21
import in.shop2020.warehouse.Scan;
-
 
22
import in.shop2020.warehouse.ScanType;
16
import in.shop2020.warehouse.ScanType;
23
import in.shop2020.warehouse.TransferLot;
17
import in.shop2020.warehouse.TransferLot;
24
import in.shop2020.warehouse.WarehouseService;
18
import in.shop2020.warehouse.WarehouseService;
25
import in.shop2020.warehouse.WarehouseServiceException;
19
import in.shop2020.warehouse.WarehouseServiceException;
26
 
20
 
-
 
21
import java.io.BufferedInputStream;
-
 
22
import java.io.ByteArrayOutputStream;
-
 
23
import java.io.File;
-
 
24
import java.io.FileInputStream;
-
 
25
import java.io.FileNotFoundException;
-
 
26
import java.io.FileOutputStream;
-
 
27
import java.io.IOException;
27
import java.text.DateFormat;
28
import java.io.InputStream;
28
import java.text.ParseException;
29
import java.text.ParseException;
29
import java.text.SimpleDateFormat;
30
import java.text.SimpleDateFormat;
-
 
31
import java.util.ArrayList;
30
import java.util.Calendar;
32
import java.util.Calendar;
-
 
33
import java.util.Date;
31
import java.util.HashMap;
34
import java.util.HashMap;
32
import java.util.Hashtable;
-
 
33
import java.util.List;
35
import java.util.List;
34
import java.util.Map;
36
import java.util.Map;
35
import java.util.Map.Entry;
37
import java.util.Map.Entry;
36
import java.util.Set;
-
 
37
import java.util.ArrayList;
-
 
38
 
38
 
-
 
39
import javax.servlet.ServletOutputStream;
-
 
40
 
-
 
41
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
-
 
42
import org.apache.poi.ss.usermodel.Row;
-
 
43
import org.apache.poi.ss.usermodel.Sheet;
-
 
44
import org.apache.poi.ss.usermodel.Workbook;
39
import org.apache.thrift.TException;
45
import org.apache.thrift.TException;
40
import org.apache.thrift.transport.TTransportException;
46
import org.apache.thrift.transport.TTransportException;
41
import org.slf4j.Logger;
47
import org.slf4j.Logger;
42
import org.slf4j.LoggerFactory;
48
import org.slf4j.LoggerFactory;
43
 
49
 
Line 234... Line 240...
234
				transferLotItemDiv = transferLotItemDiv  + "</td><td>" + transferLotItems.get(itemId) +"</td></tr>";
240
				transferLotItemDiv = transferLotItemDiv  + "</td><td>" + transferLotItems.get(itemId) +"</td></tr>";
235
			}
241
			}
236
			transferLotItemDiv = transferLotItemDiv + "</table></div>";
242
			transferLotItemDiv = transferLotItemDiv + "</table></div>";
237
			setOutput(transferLotItemDiv);
243
			setOutput(transferLotItemDiv);
238
		} catch (TException tex) {
244
		} catch (TException tex) {
239
			logger.error("Error in marking transfer lot as received",tex);
245
			logger.error("Error in getting transfer lot items",tex);
240
		} catch (CatalogServiceException csex) {
246
		} catch (CatalogServiceException csex) {
241
			logger.error("Error in marking transfer lot as received",csex);
247
			logger.error("Error in getting transfer lot items",csex);
242
		}
248
		}
243
		return OUTPUT;
249
		return OUTPUT;
244
	}
250
	}
245
 
251
 
246
	public String markTransferLotAsReceived() throws Exception {
252
	public String markTransferLotAsReceived() throws Exception {
Line 256... Line 262...
256
			throw new Exception("Error in marking transfer lot as received");
262
			throw new Exception("Error in marking transfer lot as received");
257
		}
263
		}
258
		return INDEX;
264
		return INDEX;
259
	}
265
	}
260
	
266
	
-
 
267
	public void downloadFBASheet() {
-
 
268
		try {
-
 
269
			WarehouseService.Client warehouseClient = new WarehouseClient().getClient();
-
 
270
			Map<Long, Long> transferLotItems = warehouseClient.getItemsInTransferLot(id);
-
 
271
			
-
 
272
			File fbaSheetFile = new File("transfer-lot-id-sheet"+new Date());
-
 
273
			FileOutputStream fStream = null;
-
 
274
			try {
-
 
275
				fStream = new FileOutputStream(fbaSheetFile);
-
 
276
			} catch (FileNotFoundException e1) {
-
 
277
				logger.error(e1.getMessage());
-
 
278
			}
-
 
279
	    	ByteArrayOutputStream baosXLS = new ByteArrayOutputStream();
-
 
280
		    Workbook wb = new HSSFWorkbook();
-
 
281
		    Sheet fbaSheet = wb.createSheet("FBA Sheet");
-
 
282
		    
-
 
283
		    Row merchantShipmentName = fbaSheet.createRow((short)0);
-
 
284
		    merchantShipmentName.createCell(0).setCellValue("MerchantShipmentName");
-
 
285
		    Row labelPrepPreference = fbaSheet.createRow((short)1);
-
 
286
		    labelPrepPreference.createCell(0).setCellValue("LabelPrepPreference");
-
 
287
		    Row addressName = fbaSheet.createRow((short)2);
-
 
288
		    addressName.createCell(0).setCellValue("AddressName");
-
 
289
		    Row addressFieldOne = fbaSheet.createRow((short)3);
-
 
290
		    addressFieldOne.createCell(0).setCellValue("AddressFieldOne");
-
 
291
		    Row addressFieldTwo = fbaSheet.createRow((short)4);
-
 
292
		    addressFieldTwo.createCell(0).setCellValue("AddressFieldTwo");
-
 
293
		    Row addressCity = fbaSheet.createRow((short)5);
-
 
294
		    addressCity.createCell(0).setCellValue("AddressCity");
-
 
295
		    Row addressCountryCode = fbaSheet.createRow((short)6);
-
 
296
		    addressCountryCode.createCell(0).setCellValue("AddressCountryCode");
-
 
297
		    Row addressStateOrRegion = fbaSheet.createRow((short)7);
-
 
298
		    addressStateOrRegion.createCell(0).setCellValue("AddressStateOrRegion");
-
 
299
		    Row addressPostalCode = fbaSheet.createRow((short)8);
-
 
300
		    addressPostalCode.createCell(0).setCellValue("AddressPostalCode");
-
 
301
		    Row addressDistrict = fbaSheet.createRow((short)9);
-
 
302
		    addressDistrict.createCell(0).setCellValue("AddressDistrict");
-
 
303
		    
-
 
304
		    Row blankRow = fbaSheet.createRow((short)10);
-
 
305
		    //blankRow.createCell(0).setCellValue("AddressPostalCode");
-
 
306
		    
-
 
307
		    Row skuHeaders = fbaSheet.createRow((short)11);
-
 
308
		    skuHeaders.createCell(0).setCellValue("MerchantSKU");
-
 
309
		    skuHeaders.createCell(1).setCellValue("Quantity");
-
 
310
		    
-
 
311
		    int rowCount = 12;
-
 
312
		    for(Entry<Long, Long> itemQuantity : transferLotItems.entrySet()) {
-
 
313
		    	Row newRow = fbaSheet.createRow((short)rowCount);
-
 
314
		    	newRow.createCell(0).setCellValue("FBA"+itemQuantity.getKey());
-
 
315
			    newRow.createCell(1).setCellValue(itemQuantity.getValue());
-
 
316
			    rowCount++;
-
 
317
		    }
-
 
318
		    
-
 
319
		    try {
-
 
320
			    wb.write(baosXLS);
-
 
321
			    baosXLS.close();
-
 
322
			    baosXLS.writeTo(fStream);
-
 
323
			    fStream.flush();
-
 
324
				fStream.close();
-
 
325
		    } catch(IOException e) {
-
 
326
		    	//TODO
-
 
327
		    }
-
 
328
		    byte[] buffer = null;
-
 
329
            buffer = new byte[(int) fbaSheetFile.length()];
-
 
330
            InputStream input = null;
-
 
331
            try {
-
 
332
                int totalBytesRead = 0;
-
 
333
                input = new BufferedInputStream(new FileInputStream(fbaSheetFile));
-
 
334
                while (totalBytesRead < buffer.length) {
-
 
335
                    int bytesRemaining = buffer.length - totalBytesRead;
-
 
336
                    // input.read() returns -1, 0, or more :
-
 
337
                    int bytesRead = input.read(buffer, totalBytesRead,
-
 
338
                            bytesRemaining);
-
 
339
                    if (bytesRead > 0) {
-
 
340
                        totalBytesRead = totalBytesRead + bytesRead;
-
 
341
                    }
-
 
342
                }
-
 
343
                
-
 
344
                 /* the above style is a bit tricky: it places bytes into the
-
 
345
                 * 'buffer' array; 'buffer' is an output parameter; the while
-
 
346
                 * loop usually has a single iteration only.*/
-
 
347
                 
-
 
348
            } finally {
-
 
349
                input.close();
-
 
350
            }
-
 
351
 
-
 
352
            response.setContentType("application/vnd.ms-excel");
-
 
353
            response.setHeader("Content-disposition", "inline; filename="
-
 
354
                    + fbaSheetFile.getName());
-
 
355
 
-
 
356
            ServletOutputStream sos = response.getOutputStream();
-
 
357
            sos.write(buffer);
-
 
358
            sos.flush();
-
 
359
		    
-
 
360
		} catch (TException tex) {
-
 
361
			logger.error("Error in generating fba sheet for transfer Lot Id " + id,tex);
-
 
362
		}  catch (FileNotFoundException fnfex) {
-
 
363
			logger.error("Error in generating fba sheet for transfer Lot Id " + id,fnfex);
-
 
364
		} catch (IOException ioex) {
-
 
365
			logger.error("Error in generating fba sheet for transfer Lot Id " + id,ioex);
-
 
366
		}
-
 
367
		
-
 
368
	}
-
 
369
	
261
	public String getWarehouseName(Long warehouseId){
370
	public String getWarehouseName(Long warehouseId){
262
		return warehouseMap.get(warehouseId).getDisplayName();
371
		return warehouseMap.get(warehouseId).getDisplayName();
263
	}
372
	}
264
	
373
	
265
	public boolean isTransferReceivable(TransferLot transferLot) {
374
	public boolean isTransferReceivable(TransferLot transferLot) {