Subversion Repositories SmartDukaan

Rev

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

Rev 7321 Rev 7410
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.InventoryType;
5
import in.shop2020.model.v1.inventory.InventoryType;
5
import in.shop2020.model.v1.inventory.Warehouse;
6
import in.shop2020.model.v1.inventory.Warehouse;
6
import in.shop2020.model.v1.inventory.WarehouseType;
7
import in.shop2020.model.v1.inventory.WarehouseType;
7
import in.shop2020.model.v1.order.LineItem;
8
import in.shop2020.model.v1.order.LineItem;
8
import in.shop2020.purchase.Invoice;
9
import in.shop2020.purchase.Invoice;
9
import in.shop2020.purchase.PurchaseOrder;
10
import in.shop2020.purchase.PurchaseOrder;
10
import in.shop2020.purchase.PurchaseServiceException;
11
import in.shop2020.purchase.PurchaseServiceException;
11
import in.shop2020.thrift.clients.CatalogClient;
12
import in.shop2020.thrift.clients.CatalogClient;
-
 
13
import in.shop2020.thrift.clients.HelperClient;
12
import in.shop2020.thrift.clients.InventoryClient;
14
import in.shop2020.thrift.clients.InventoryClient;
13
import in.shop2020.thrift.clients.PurchaseClient;
15
import in.shop2020.thrift.clients.PurchaseClient;
14
import in.shop2020.thrift.clients.WarehouseClient;
16
import in.shop2020.thrift.clients.WarehouseClient;
-
 
17
import in.shop2020.utils.HelperService;
15
import in.shop2020.utils.ModelUtils;
18
import in.shop2020.utils.ModelUtils;
16
import in.shop2020.warehouse.InventoryItem;
19
import in.shop2020.warehouse.InventoryItem;
17
import in.shop2020.warehouse.ScanType;
20
import in.shop2020.warehouse.ScanType;
-
 
21
import in.shop2020.warehouse.WarehouseService;
18
import in.shop2020.warehouse.WarehouseService.Client;
22
import in.shop2020.warehouse.WarehouseService.Client;
19
import in.shop2020.warehouse.WarehouseServiceException;
23
import in.shop2020.warehouse.WarehouseServiceException;
20
 
24
 
21
import java.util.ArrayList;
25
import java.util.ArrayList;
22
import java.util.Calendar;
26
import java.util.Calendar;
Line 42... Line 46...
42
    /**
46
    /**
43
     * 
47
     * 
44
     */
48
     */
45
    private static final int NUM_BULK__SCAN_ITEMS = 10;
49
    private static final int NUM_BULK__SCAN_ITEMS = 10;
46
    private static Logger logger = LoggerFactory.getLogger(PurchaseController.class);
50
    private static Logger logger = LoggerFactory.getLogger(PurchaseController.class);
47
    private static enum ScanRecordType { VALID, BLANK };
51
    public static enum ScanRecordType { VALID, BLANK };
48
 
52
 
49
    private ServletContext context;
53
    private ServletContext context;
50
    private String id;
54
    private String id;
-
 
55
    private Long transferLotId;
51
    private String itemId;
56
    private String itemId;
52
    private String itemNo;
57
    private String itemNo;
53
    private String errorMsg = "";
58
    private String errorMsg = "";
54
    private List<Item> items;
59
    private List<Item> items;
55
    private List<LineItem> lineItems;
60
    private List<LineItem> lineItems;
Line 58... Line 63...
58
    private String invoiceNumber;
63
    private String invoiceNumber;
59
    private Double freightCharges ;
64
    private Double freightCharges ;
60
    private Long poId;
65
    private Long poId;
61
 
66
 
62
    private String purchaseOrderId;
67
    private String purchaseOrderId;
-
 
68
    private Long warehouseId;
-
 
69
    private Long transferWarehouseId;
63
    private Warehouse warehouse;
70
    private Warehouse warehouse;
64
 
71
 
65
    public String editNew() {
72
    public String editNew() {
66
        purchaseOrderId = request.getParameter("poId");
73
        purchaseOrderId = request.getParameter("poId");
67
 
74
 
68
        try {
75
        try {
69
            in.shop2020.purchase.PurchaseService.Client purchaseClient = new PurchaseClient().getClient();
76
            in.shop2020.purchase.PurchaseService.Client purchaseClient = new PurchaseClient().getClient();
70
            invoices = purchaseClient.getInvoices(getPreviousDay(getPreviousDay(new Date())).getTime());
77
            //invoices = purchaseClient.getInvoices(getPreviousDay(getPreviousDay(new Date())).getTime());
-
 
78
            PurchaseOrder po = purchaseClient.getPurchaseOrder(Long.parseLong(purchaseOrderId));
-
 
79
            invoices = purchaseClient.getInvoicesForWarehouse(po.getWarehouseId(), po.getSupplierId(), getPreviousDay(getPreviousDay(new Date())).getTime());
71
        } catch (Exception e) {
80
        } catch (Exception e) {
72
            logger.error("Error loading invoices", e);
81
            logger.error("Error loading invoices", e);
73
        }
82
        }
74
 
83
 
75
        return "new";
84
        return "new";
Line 157... Line 166...
157
	        	}
166
	        	}
158
            }
167
            }
159
 
168
 
160
            WarehouseClient warehouseClient = new WarehouseClient();
169
            WarehouseClient warehouseClient = new WarehouseClient();
161
            Client client = warehouseClient.getClient();
170
            Client client = warehouseClient.getClient();
-
 
171
            in.shop2020.purchase.PurchaseService.Client purchaseClient = new PurchaseClient().getClient();
-
 
172
            PurchaseOrder po = purchaseClient.getPurchaseOrder(poId);
-
 
173
            if(transferLotId==null || transferLotId==0) {
-
 
174
	            if(transferWarehouseId!=null && transferWarehouseId!=0) {
-
 
175
	            	InventoryService.Client inventoryClient = new InventoryClient().getClient();
-
 
176
	                Warehouse fulfilmentWarehouse = inventoryClient.getWarehouses(WarehouseType.OURS, InventoryType.GOOD, po.getSupplierId(), po.getWarehouseId(), 0L).get(0);
-
 
177
	            	transferLotId = client.createTransferLot(po.getWarehouseId(), transferWarehouseId);
-
 
178
	            }
162
 
179
            }
163
            for (LineItem lineItem : lineItems) {
180
            for (LineItem lineItem : lineItems) {
164
                if (ScanRecordType.BLANK.name().equals(lineItem.getExtra_info())) {
181
                if (ScanRecordType.BLANK.name().equals(lineItem.getExtra_info())) {
165
                    continue;
182
                    continue;
166
                }
183
                }
167
 
184
 
168
                InventoryItem inventoryItem = new InventoryItem();
185
                InventoryItem inventoryItem = new InventoryItem();
169
                inventoryItem.setItemId(lineItem.getItem_id());
186
                inventoryItem.setItemId(lineItem.getItem_id());
170
                inventoryItem.setPurchaseId(Long.parseLong(id));
187
                inventoryItem.setPurchaseId(Long.parseLong(id));
171
                inventoryItem.setCurrentQuantity(0);
188
                inventoryItem.setCurrentQuantity(new Double(lineItem.getQuantity()).longValue());
172
                inventoryItem.setItemNumber(lineItem.getItem_number());
189
                inventoryItem.setItemNumber(lineItem.getItem_number());
173
                inventoryItem.setSerialNumber(lineItem.getSerial_number());
190
                inventoryItem.setSerialNumber(lineItem.getSerial_number());
174
                inventoryItem.setInitialQuantity(new Double(lineItem.getQuantity()).longValue());
191
                inventoryItem.setInitialQuantity(new Double(lineItem.getQuantity()).longValue());
-
 
192
                inventoryItem.setPhysicalWarehouseId(po.getWarehouseId());
175
                client.scan(inventoryItem, ScanType.PURCHASE, new Double(lineItem.getQuantity()).longValue(), PurchaseOrderController.WAREHOUSE_ID);
193
            	client.scan(inventoryItem, ScanType.PURCHASE, new Double(lineItem.getQuantity()).longValue(), warehouseId, (transferLotId!=null)?transferLotId:0L);
176
            }
194
            }
177
 
195
 
178
            resetLineItems();
196
            resetLineItems();
179
        } catch (TTransportException e) {
197
        } catch (TTransportException e) {
180
            errorMsg = "Error while establishing connection to the warehouse server";
198
            errorMsg = "Error while establishing connection to the warehouse server";
Line 296... Line 314...
296
        try {
314
        try {
297
            items = new ArrayList<Item>();
315
            items = new ArrayList<Item>();
298
            in.shop2020.purchase.PurchaseService.Client purchaseClient = new PurchaseClient().getClient();
316
            in.shop2020.purchase.PurchaseService.Client purchaseClient = new PurchaseClient().getClient();
299
            //PurchaseOrder purchaseOrder = purchaseClient.getPurchaseOrderForPurchase(id);
317
            //PurchaseOrder purchaseOrder = purchaseClient.getPurchaseOrderForPurchase(id);
300
            PurchaseOrder purchaseOrder = purchaseClient.getPurchaseOrder(poId);
318
            PurchaseOrder purchaseOrder = purchaseClient.getPurchaseOrder(poId);
-
 
319
            warehouseId = purchaseOrder.getWarehouseId();
301
            in.shop2020.model.v1.catalog.CatalogService.Client catalogClient = new CatalogClient().getClient();
320
            in.shop2020.model.v1.catalog.CatalogService.Client catalogClient = new CatalogClient().getClient();
302
 
321
 
303
            for (in.shop2020.purchase.LineItem lineItem : purchaseOrder.getLineitems()) {
322
            for (in.shop2020.purchase.LineItem lineItem : purchaseOrder.getLineitems()) {
304
                items.add(catalogClient.getItem(lineItem.getItemId()));
323
                items.add(catalogClient.getItem(lineItem.getItemId()));
305
            }
324
            }
306
 
325
 
307
            in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = new InventoryClient().getClient();
326
            in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = new InventoryClient().getClient();
308
            warehouse = inventoryClient.getWarehouses(WarehouseType.OURS, InventoryType.GOOD, purchaseOrder.getSupplierId(), PurchaseOrderController.WAREHOUSE_ID, PurchaseOrderController.WAREHOUSE_ID).get(0);
327
            warehouse = inventoryClient.getWarehouses(WarehouseType.OURS, InventoryType.GOOD, purchaseOrder.getSupplierId(), warehouseId, warehouseId).get(0);
309
        } catch (Exception e) {
328
        } catch (Exception e) {
310
            logger.error("Could not find items in PO with purchase: " + id, e);
329
            logger.error("Could not find items in PO with purchase: " + id, e);
311
        }
330
        }
312
    }
331
    }
313
 
332
 
Line 344... Line 363...
344
            logger.error("Could not create item number mapping", e);
363
            logger.error("Could not create item number mapping", e);
345
        }
364
        }
346
 
365
 
347
        return show();
366
        return show();
348
    }
367
    }
-
 
368
    
-
 
369
    /*public String setTransferItemsOption() {
-
 
370
    	boolean isTransferAllowed = false;
-
 
371
    	try {
-
 
372
			Client warehouseClient = new WarehouseClient().getClient();
-
 
373
	        isTransferAllowed = warehouseClient.isItemTransferAllowed(warehouseId, transferWarehouseId);
-
 
374
    	} catch (TTransportException e) {
-
 
375
            logger.error("Could not create thrift client", e);
-
 
376
        } catch (TException e) {
-
 
377
            logger.error("Could not check if item transfer allowed between warehouses", e);
-
 
378
        }//TODO
-
 
379
    	return "";
-
 
380
    }*/
-
 
381
    
-
 
382
    public List<Warehouse> getAllowedDestinationWarehousesForTransfer(long originWarehouseId){
-
 
383
    	try {
-
 
384
    		WarehouseService.Client warehouseClient = new WarehouseClient().getClient();
-
 
385
    		List<Long> allowedWarehouseIds = warehouseClient.getAllowedDestinationWarehousesForTransfer(originWarehouseId);
-
 
386
    		List<Warehouse> allowedWarehouses = new ArrayList<Warehouse>();
-
 
387
    		InventoryService.Client inventoryClient = new InventoryClient().getClient();
-
 
388
    		for(Long allowedWarehouseId : allowedWarehouseIds) {
-
 
389
    			allowedWarehouses.add(inventoryClient.getWarehouse(allowedWarehouseId));
-
 
390
    		}
-
 
391
    		return allowedWarehouses;
-
 
392
    	} catch(Exception e) {
-
 
393
    		logger.error("Error while getting all destination warehouses for warehouseId " + warehouseId, e);
-
 
394
    		return new ArrayList<Warehouse>();
-
 
395
    	}
-
 
396
    }
349
 
397
 
350
    public String itemNumberMappingEditNew() {
398
    public String itemNumberMappingEditNew() {
351
        return "item-number-mapping";
399
        return "item-number-mapping";
352
    }
400
    }
353
 
401
 
Line 440... Line 488...
440
	}
488
	}
441
 
489
 
442
	public void setPoId(Long poId) {
490
	public void setPoId(Long poId) {
443
		this.poId = poId;
491
		this.poId = poId;
444
	}
492
	}
-
 
493
 
-
 
494
	public Long getWarehouseId() {
-
 
495
		return warehouseId;
445
    
496
	}
-
 
497
 
-
 
498
	public void setWarehouseId(Long warehouseId) {
-
 
499
		this.warehouseId = warehouseId;
-
 
500
	}
-
 
501
 
-
 
502
	public Long getTransferWarehouseId() {
-
 
503
		return transferWarehouseId;
-
 
504
	}
-
 
505
 
-
 
506
	public void setTransferWarehouseId(Long transferWarehouseId) {
-
 
507
		this.transferWarehouseId = transferWarehouseId;
446
    
508
	}
447
}
509
}