Subversion Repositories SmartDukaan

Rev

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

Rev 8217 Rev 11801
Line 1... Line 1...
1
package in.shop2020.inventory.controllers;
1
package in.shop2020.inventory.controllers;
2
 
2
 
3
import in.shop2020.model.v1.catalog.Item;
3
import in.shop2020.model.v1.catalog.Item;
4
import in.shop2020.model.v1.inventory.InventoryService;
4
import in.shop2020.model.v1.inventory.InventoryService;
-
 
5
import in.shop2020.model.v1.inventory.InventoryServiceException;
5
import in.shop2020.model.v1.inventory.InventoryType;
6
import in.shop2020.model.v1.inventory.InventoryType;
6
import in.shop2020.model.v1.inventory.Warehouse;
7
import in.shop2020.model.v1.inventory.Warehouse;
7
import in.shop2020.model.v1.inventory.WarehouseType;
8
import in.shop2020.model.v1.inventory.WarehouseType;
8
import in.shop2020.model.v1.order.LineItem;
9
import in.shop2020.model.v1.order.LineItem;
9
import in.shop2020.purchase.Invoice;
10
import in.shop2020.purchase.Invoice;
-
 
11
/*import in.shop2020.purchase.POStatus;*/
10
import in.shop2020.purchase.PurchaseOrder;
12
import in.shop2020.purchase.PurchaseOrder;
-
 
13
/*import in.shop2020.purchase.PurchaseService;*/
11
import in.shop2020.purchase.PurchaseServiceException;
14
import in.shop2020.purchase.PurchaseServiceException;
12
import in.shop2020.thrift.clients.CatalogClient;
15
import in.shop2020.thrift.clients.CatalogClient;
13
import in.shop2020.thrift.clients.HelperClient;
16
import in.shop2020.thrift.clients.HelperClient;
14
import in.shop2020.thrift.clients.InventoryClient;
17
import in.shop2020.thrift.clients.InventoryClient;
15
import in.shop2020.thrift.clients.PurchaseClient;
18
import in.shop2020.thrift.clients.PurchaseClient;
Line 47... Line 50...
47
     * 
50
     * 
48
     */
51
     */
49
    private static final int NUM_BULK__SCAN_ITEMS = 10;
52
    private static final int NUM_BULK__SCAN_ITEMS = 10;
50
    private static Logger logger = LoggerFactory.getLogger(PurchaseController.class);
53
    private static Logger logger = LoggerFactory.getLogger(PurchaseController.class);
51
    public static enum ScanRecordType { VALID, BLANK };
54
    public static enum ScanRecordType { VALID, BLANK };
-
 
55
    private static final long DUMMY_VENDOR_ID = 40;
52
 
56
 
53
    private ServletContext context;
57
    private ServletContext context;
54
    private String id;
58
    private String id;
55
    private Long transferLotId;
59
    private Long transferLotId;
56
    private String itemId;
60
    private String itemId;
Line 61... Line 65...
61
    private List<Invoice> invoices;
65
    private List<Invoice> invoices;
62
    
66
    
63
    private String invoiceNumber;
67
    private String invoiceNumber;
64
    private Double freightCharges ;
68
    private Double freightCharges ;
65
    private Long poId;
69
    private Long poId;
-
 
70
    private String purchaseComments;
66
 
71
 
67
    private String purchaseOrderId;
72
    private String purchaseOrderId;
68
    private Long warehouseId;
73
    private Long warehouseId;
69
    private Long transferWarehouseId;
74
    private Long transferWarehouseId;
70
    private Warehouse warehouse;
75
    private Warehouse warehouse;
-
 
76
    private Warehouse thirdPartyWarehouse;
71
 
77
 
72
    public String editNew() {
78
    public String editNew() {
73
        purchaseOrderId = request.getParameter("poId");
79
        purchaseOrderId = request.getParameter("poId");
74
 
80
 
75
        try {
81
        try {
Line 126... Line 132...
126
        }
132
        }
127
    }
133
    }
128
 
134
 
129
    public boolean createPurchase(){
135
    public boolean createPurchase(){
130
        try {
136
        try {
131
        	logger.info("poId="+poId+" invoiceNumber="+invoiceNumber+" freightCharges="+freightCharges);
137
        	logger.info("poId="+poId+" invoiceNumber="+invoiceNumber+" freightCharges="+freightCharges+ " purchaseComments= "+purchaseComments);
132
            PurchaseClient purchaseClient = new PurchaseClient();
138
            PurchaseClient purchaseClient = new PurchaseClient();
133
            in.shop2020.purchase.PurchaseService.Client client = purchaseClient
139
            in.shop2020.purchase.PurchaseService.Client client = purchaseClient
134
                    .getClient();
140
                    .getClient();
135
            id = "" + client.startPurchase(poId, invoiceNumber, freightCharges);
141
            id = "" + client.startPurchase(poId, invoiceNumber, freightCharges, purchaseComments);
136
            logger.info("id = "+id);
142
            logger.info("id = "+id);
137
        } catch (TTransportException e) {
143
        } catch (TTransportException e) {
138
            errorMsg = "Error while establishing connection to the warehouse server";
144
            errorMsg = "Error while establishing connection to the warehouse server";
139
            logger.error(errorMsg, e);
145
            logger.error(errorMsg, e);
140
        } catch (TException e) {
146
        } catch (TException e) {
Line 175... Line 181...
175
	            	InventoryService.Client inventoryClient = new InventoryClient().getClient();
181
	            	InventoryService.Client inventoryClient = new InventoryClient().getClient();
176
	                Warehouse fulfilmentWarehouse = inventoryClient.getWarehouses(WarehouseType.OURS, InventoryType.GOOD, po.getSupplierId(), po.getWarehouseId(), 0L).get(0);
182
	                Warehouse fulfilmentWarehouse = inventoryClient.getWarehouses(WarehouseType.OURS, InventoryType.GOOD, po.getSupplierId(), po.getWarehouseId(), 0L).get(0);
177
	            	transferLotId = client.createTransferLot(po.getWarehouseId(), transferWarehouseId);
183
	            	transferLotId = client.createTransferLot(po.getWarehouseId(), transferWarehouseId);
178
	            }
184
	            }
179
            }
185
            }
-
 
186
            boolean checkDirectScanWarehouse = false;
-
 
187
            
-
 
188
            if(thirdPartyWarehouse.getVendor().getId()==DUMMY_VENDOR_ID && thirdPartyWarehouse.getInventoryType()==InventoryType.GOOD && thirdPartyWarehouse.getWarehouseType()==WarehouseType.OURS_THIRDPARTY){
-
 
189
            	checkDirectScanWarehouse = true;
-
 
190
            }
-
 
191
            
180
            for (LineItem lineItem : lineItems) {
192
            for (LineItem lineItem : lineItems) {
181
                if (ScanRecordType.BLANK.name().equals(lineItem.getExtra_info())) {
193
                if (ScanRecordType.BLANK.name().equals(lineItem.getExtra_info())) {
182
                    continue;
194
                    continue;
183
                }
195
                }
184
 
196
 
Line 188... Line 200...
188
                inventoryItem.setCurrentQuantity(0);
200
                inventoryItem.setCurrentQuantity(0);
189
                inventoryItem.setItemNumber(lineItem.getItem_number());
201
                inventoryItem.setItemNumber(lineItem.getItem_number());
190
                inventoryItem.setSerialNumber(lineItem.getSerial_number());
202
                inventoryItem.setSerialNumber(lineItem.getSerial_number());
191
                inventoryItem.setInitialQuantity(new Double(lineItem.getQuantity()).longValue());
203
                inventoryItem.setInitialQuantity(new Double(lineItem.getQuantity()).longValue());
192
                inventoryItem.setPhysicalWarehouseId(po.getWarehouseId());
204
                inventoryItem.setPhysicalWarehouseId(po.getWarehouseId());
-
 
205
                logger.info("checkDirectScanWarehouse..... "+ checkDirectScanWarehouse);
-
 
206
                if(checkDirectScanWarehouse){
-
 
207
                	logger.info("Come into this loop.... where direct scan Warehouse Id exist");
-
 
208
                	inventoryItem.setPhysicalWarehouseId(po.getWarehouseId());
-
 
209
                	inventoryItem.setCurrentWarehouseId(po.getWarehouseId());
-
 
210
                }else{
-
 
211
                	logger.info("Come into this loop.... where direct scan Warehouse Id Not Exist");
-
 
212
                	inventoryItem.setPhysicalWarehouseId(po.getWarehouseId());
-
 
213
                }
-
 
214
                
-
 
215
                if(!client.isAlive()){
-
 
216
					client = warehouseClient.getClient();
-
 
217
				}
193
            	client.scan(inventoryItem, ScanType.PURCHASE, new Double(lineItem.getQuantity()).longValue(), warehouseId, (transferLotId!=null)?transferLotId:0L);
218
            	client.scan(inventoryItem, ScanType.PURCHASE, new Double(lineItem.getQuantity()).longValue(), warehouseId, (transferLotId!=null)?transferLotId:0L);
194
            }
219
            }
195
 
220
 
196
            resetLineItems();
221
            resetLineItems();
197
        } catch (TTransportException e) {
222
        } catch (TTransportException e) {
Line 322... Line 347...
322
            for (in.shop2020.purchase.LineItem lineItem : purchaseOrder.getLineitems()) {
347
            for (in.shop2020.purchase.LineItem lineItem : purchaseOrder.getLineitems()) {
323
                items.add(catalogClient.getItem(lineItem.getItemId()));
348
                items.add(catalogClient.getItem(lineItem.getItemId()));
324
            }
349
            }
325
 
350
 
326
            in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = new InventoryClient().getClient();
351
            in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = new InventoryClient().getClient();
-
 
352
            thirdPartyWarehouse = inventoryClient.getWarehouse(warehouseId);
-
 
353
            if(thirdPartyWarehouse.getVendor().getId()==DUMMY_VENDOR_ID && thirdPartyWarehouse.getInventoryType()==InventoryType.GOOD && thirdPartyWarehouse.getWarehouseType()==WarehouseType.OURS_THIRDPARTY){
-
 
354
            	warehouse = thirdPartyWarehouse;
-
 
355
            } else {
327
            warehouse = inventoryClient.getWarehouses(WarehouseType.OURS, InventoryType.GOOD, purchaseOrder.getSupplierId(), warehouseId, warehouseId).get(0);
356
            	warehouse = inventoryClient.getWarehouses(WarehouseType.OURS, InventoryType.GOOD, purchaseOrder.getSupplierId(), warehouseId, warehouseId).get(0);
-
 
357
            }
328
        } catch (Exception e) {
358
        } catch (Exception e) {
329
            logger.error("Could not find items in PO with purchase: " + id, e);
359
            logger.error("Could not find items in PO with purchase: " + id, e);
330
        }
360
        }
331
    }
361
    }
332
 
362
 
Line 393... Line 423...
393
    		logger.error("Error while getting all destination warehouses for warehouseId " + warehouseId, e);
423
    		logger.error("Error while getting all destination warehouses for warehouseId " + warehouseId, e);
394
    		return new ArrayList<Warehouse>();
424
    		return new ArrayList<Warehouse>();
395
    	}
425
    	}
396
    }
426
    }
397
 
427
 
-
 
428
/*	public boolean canItemCanBeScannedIn(long id) {
-
 
429
		double itemWeight = 0.0;
-
 
430
		try {
-
 
431
			in.shop2020.model.v1.catalog.CatalogService.Client catalogClient = new CatalogClient().getClient();
-
 
432
			Item item = catalogClient.getItem(id);
-
 
433
			itemWeight = item.getWeight();
-
 
434
		} catch (Exception e) {
-
 
435
			logger.error("Could not fetch item to get weight of it ", e);
-
 
436
		}
-
 
437
		if(itemWeight> 0.0){
-
 
438
			return true;
-
 
439
		}
-
 
440
		return false;
-
 
441
	}
-
 
442
*/
398
    public String itemNumberMappingEditNew() {
443
    public String itemNumberMappingEditNew() {
399
        return "item-number-mapping";
444
        return "item-number-mapping";
400
    }
445
    }
401
 
446
 
402
    public String getName(Item item){
447
    public String getName(Item item){
Line 512... Line 557...
512
	}
557
	}
513
 
558
 
514
	public void setTransferLotId(Long transferLotId) {
559
	public void setTransferLotId(Long transferLotId) {
515
		this.transferLotId = transferLotId;
560
		this.transferLotId = transferLotId;
516
	}
561
	}
-
 
562
 
-
 
563
	public String getPurchaseComments() {
-
 
564
		return purchaseComments;
-
 
565
	}
-
 
566
 
-
 
567
	public void setPurchaseComments(String purchaseComments) {
-
 
568
		this.purchaseComments = purchaseComments;
-
 
569
	}
-
 
570
 
-
 
571
	public Warehouse getThirdPartyWarehouse() {
-
 
572
		return thirdPartyWarehouse;
-
 
573
	}
-
 
574
 
-
 
575
	public void setThirdPartyWarehouse(Warehouse thirdPartyWarehouse) {
-
 
576
		this.thirdPartyWarehouse = thirdPartyWarehouse;
-
 
577
	}
517
	
578
	
518
}
579
}