Subversion Repositories SmartDukaan

Rev

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

Rev 24991 Rev 25112
Line 38... Line 38...
38
import in.shop2020.warehouse.WarehouseService;
38
import in.shop2020.warehouse.WarehouseService;
39
import in.shop2020.warehouse.WarehouseService.Client;
39
import in.shop2020.warehouse.WarehouseService.Client;
40
import in.shop2020.warehouse.WarehouseServiceException;
40
import in.shop2020.warehouse.WarehouseServiceException;
41
 
41
 
42
@SuppressWarnings("serial")
42
@SuppressWarnings("serial")
-
 
43
@Results({ 
43
@Results({ @Result(name = "redirect", type = "redirectAction", params = {
44
	@Result(name = "redirect", type = "redirectAction", params = { "actionName", "warehouse" }),
44
        "actionName", "warehouse" }) })
45
	@Result(name = "redirectPoShow", type = "redirectAction", params = { "actionName", "purchase-order/${poId}"})
-
 
46
})
45
public class PurchaseController extends BaseController {
47
public class PurchaseController extends BaseController {
46
    /**
48
	/**
47
     * 
49
	 * 
48
     */
50
	 */
49
    private static final int NUM_BULK__SCAN_ITEMS = 10;
51
	private static final int NUM_BULK__SCAN_ITEMS = 10;
50
    private static Logger logger = LoggerFactory.getLogger(PurchaseController.class);
52
	private static Logger logger = LoggerFactory.getLogger(PurchaseController.class);
51
    public static enum ScanRecordType { VALID, BLANK };
53
 
52
    private static final long DUMMY_VENDOR_ID = 40;
54
	public static enum ScanRecordType {
53
 
55
		VALID, BLANK
54
    private ServletContext context;
56
	};
55
    private String id;
57
 
56
    private Long transferLotId;
58
	private static final long DUMMY_VENDOR_ID = 40;
57
    private String itemId;
59
 
58
    private String itemNo;
60
	private ServletContext context;
59
    private String errorMsg = "";
61
	private String id;
60
    private List<Item> items;
62
	private Long transferLotId;
61
    private List<LineItem> lineItems;
63
	private String itemId;
62
    private List<Invoice> invoices;
64
	private String itemNo;
63
    
65
	private double invoicePrice;
64
    private String invoiceNumber;
66
 
65
    private Double freightCharges ;
67
	public double getInvoicePrice() {
66
    private Long poId;
68
		return invoicePrice;
67
    private String purchaseComments;
69
	}
68
 
70
 
69
    private String purchaseOrderId;
71
	public void setInvoicePrice(double invoicePrice) {
70
    private Long warehouseId;
72
		this.invoicePrice = invoicePrice;
71
    private Long transferWarehouseId;
73
	}
72
    private Warehouse warehouse;
74
 
73
    private Warehouse thirdPartyWarehouse;
75
	private String errorMsg = "";
74
 
76
	private List<Item> items;
75
    public String editNew() {
77
	private List<LineItem> lineItems;
76
        purchaseOrderId = request.getParameter("poId");
78
	private List<Invoice> invoices;
77
 
79
 
78
        try {
80
	private String invoiceNumber;
79
            in.shop2020.purchase.PurchaseService.Client purchaseClient = new PurchaseClient().getClient();
81
	private Double freightCharges;
80
            //invoices = purchaseClient.getInvoices(getPreviousDay(getPreviousDay(new Date())).getTime());
82
	private Long poId;
81
            PurchaseOrder po = purchaseClient.getPurchaseOrder(Long.parseLong(purchaseOrderId));
83
	private String purchaseComments;
82
            invoices = purchaseClient.getInvoicesForWarehouse(po.getWarehouseId(), po.getSupplierId(), getPreviousDay(getPreviousDay(new Date())).getTime());
84
 
83
        } catch (Exception e) {
85
	private String purchaseOrderId;
84
            logger.error("Error loading invoices", e);
86
	private Long warehouseId;
85
        }
87
	private Long transferWarehouseId;
86
 
88
	private Warehouse warehouse;
87
        return "new";
89
	private Warehouse thirdPartyWarehouse;
88
    }
90
 
89
 
91
	public String editNew() {
90
    private Date getPreviousDay(Date date) {
92
		purchaseOrderId = request.getParameter("poId");
91
        Calendar calendar = Calendar.getInstance();
93
 
92
        calendar.setTime(date);
94
		try {
93
        calendar.add(Calendar.DAY_OF_MONTH, -1);
95
			in.shop2020.purchase.PurchaseService.Client purchaseClient = new PurchaseClient().getClient();
94
        return calendar.getTime();
96
			// invoices = purchaseClient.getInvoices(getPreviousDay(getPreviousDay(new
95
    }
97
			// Date())).getTime());
96
 
98
			PurchaseOrder po = purchaseClient.getPurchaseOrder(Long.parseLong(purchaseOrderId));
97
    public String create() {
99
			invoices = purchaseClient.getInvoicesForWarehouse(po.getWarehouseId(), po.getSupplierId(),
98
    	this.purchaseOrderId = request.getParameter("poId");
100
					getPreviousDay(getPreviousDay(new Date())).getTime());
99
        poId = Long.parseLong(purchaseOrderId);
101
		} catch (Exception e) {
100
        invoiceNumber = request.getParameter("invoiceNo");
102
			logger.error("Error loading invoices", e);
101
        if(invoiceNumber.endsWith(",")) {
103
		}
102
        	addActionError("Invoice Number should not end with Comma");
104
 
103
        	return "show";
105
		return "new";
104
        }
106
	}
105
        String fc = request.getParameter("freightCharges").trim();
107
 
106
        freightCharges = 0D;
108
	private Date getPreviousDay(Date date) {
107
        id = "0";
109
		Calendar calendar = Calendar.getInstance();
108
        if (fc != null && !fc.isEmpty())
110
		calendar.setTime(date);
109
            freightCharges = Double.parseDouble(fc);
111
		calendar.add(Calendar.DAY_OF_MONTH, -1);
110
        return show();
112
		return calendar.getTime();
111
        //return "create";
113
	}
112
 
114
 
113
    }
115
	public String create() {
114
 
116
		this.purchaseOrderId = request.getParameter("poId");
115
    public String show() {
117
		poId = Long.parseLong(purchaseOrderId);
116
        resetLineItems();
118
		invoiceNumber = request.getParameter("invoiceNo");
117
        setItemsFromPO();
119
		if (invoiceNumber.endsWith(",")) {
118
        return SHOW;
120
			addActionError("Invoice Number should not end with Comma");
119
    }
121
			return "show";
120
 
122
		}
121
    private void resetLineItems() {
123
		String fc = request.getParameter("freightCharges").trim();
122
        lineItems = new ArrayList<LineItem>();
124
		freightCharges = 0D;
123
 
125
		id = "0";
124
        for (int i = 0; i < NUM_BULK__SCAN_ITEMS; i++) {
126
		if (fc != null && !fc.isEmpty())
125
            LineItem lineItem = new LineItem();
127
			freightCharges = Double.parseDouble(fc);
126
            lineItem.setId(i);
128
		return show();
127
            lineItem.setExtra_info("");
129
		// return "create";
128
            lineItem.setSerial_number("");
130
 
129
            lineItem.setItem_number("");
131
	}
130
            lineItem.setQuantity(1);
132
 
131
            lineItem.setItem_id(-1);
133
	public String show() {
132
            lineItems.add(lineItem);
134
		resetLineItems();
133
        }
135
		setItemsFromPO();
134
    }
136
		return SHOW;
135
 
137
	}
136
    public boolean createPurchase(){
138
 
137
        try {
139
	private void resetLineItems() {
138
        	logger.info("poId="+poId+" invoiceNumber="+invoiceNumber+" freightCharges="+freightCharges+ " purchaseComments= "+purchaseComments);
140
		lineItems = new ArrayList<LineItem>();
139
            PurchaseClient purchaseClient = new PurchaseClient();
141
 
140
            in.shop2020.purchase.PurchaseService.Client client = purchaseClient
142
		for (int i = 0; i < NUM_BULK__SCAN_ITEMS; i++) {
141
                    .getClient();
143
			LineItem lineItem = new LineItem();
142
            id = "" + client.startPurchase(poId, invoiceNumber, freightCharges, purchaseComments);
144
			lineItem.setId(i);
143
            logger.info("id = "+id);
145
			lineItem.setExtra_info("");
144
        } catch (TTransportException e) {
146
			lineItem.setSerial_number("");
145
            errorMsg = "Error while establishing connection to the warehouse server";
147
			lineItem.setItem_number("");
146
            logger.error(errorMsg, e);
148
			lineItem.setQuantity(1);
147
        } catch (TException e) {
149
			lineItem.setItem_id(-1);
148
            errorMsg = "Error while scanning in the item";
150
			lineItems.add(lineItem);
149
            logger.error(errorMsg, e);
151
		}
150
        } catch (PurchaseServiceException e) {
152
	}
151
            errorMsg = e.getMessage();
153
 
152
            logger.error(errorMsg, e);
154
	public boolean createPurchase() {
153
        }
155
		try {
154
 
156
			logger.info("poId=" + poId + " invoiceNumber=" + invoiceNumber + " freightCharges=" + freightCharges
155
        if (errorMsg.isEmpty())
157
					+ " purchaseComments= " + purchaseComments);
156
            return true;
158
			PurchaseClient purchaseClient = new PurchaseClient();
157
        else {
159
			in.shop2020.purchase.PurchaseService.Client client = purchaseClient.getClient();
158
            addActionError(errorMsg);
160
			id = "" + client.startPurchase(poId, invoiceNumber, freightCharges, purchaseComments);
159
            return false;
161
			logger.info("id = " + id);
160
        }
162
		} catch (TTransportException e) {
161
    }
163
			errorMsg = "Error while establishing connection to the warehouse server";
162
    
164
			logger.error(errorMsg, e);
163
    public String update() {
165
		} catch (TException e) {
164
        setItemsFromPO();
166
			errorMsg = "Error while scanning in the item";
165
 
167
			logger.error(errorMsg, e);
166
        try {
168
		} catch (PurchaseServiceException e) {
167
            if (!areValidScans()) {
169
			errorMsg = e.getMessage();
168
                return SHOW;
170
			logger.error(errorMsg, e);
169
            }
171
		}
170
            if(id == null || Long.parseLong(id)==0) {
172
 
171
	            if(!createPurchase()) {
173
		if (errorMsg.isEmpty())
172
	        		return "new";
174
			return true;
173
	        	}
175
		else {
174
            }
176
			addActionError(errorMsg);
175
 
177
			return false;
176
            WarehouseClient warehouseClient = new WarehouseClient();
178
		}
177
            Client client = warehouseClient.getClient();
179
	}
178
            in.shop2020.purchase.PurchaseService.Client purchaseClient = new PurchaseClient().getClient();
180
 
179
            PurchaseOrder po = purchaseClient.getPurchaseOrder(poId);
181
	public String update() {
180
            InventoryService.Client inventoryClient = new InventoryClient().getClient();
182
		setItemsFromPO();
181
            if(transferLotId==null || transferLotId==0) {
183
 
182
	            if(transferWarehouseId!=null && transferWarehouseId!=0) {
184
		try {
183
	                Warehouse fulfilmentWarehouse = inventoryClient.getWarehouses(WarehouseType.OURS, InventoryType.GOOD, po.getSupplierId(), po.getWarehouseId(), 0L).get(0);
185
			if (!areValidScans()) {
184
	            	transferLotId = client.createTransferLot(po.getWarehouseId(), transferWarehouseId);
186
				return SHOW;
185
	            }
187
			}
186
            }
188
			if (id == null || Long.parseLong(id) == 0) {
187
            boolean checkDirectScanWarehouse = false;
189
				if (!createPurchase()) {
188
            
190
					return "new";
189
            if(thirdPartyWarehouse.getVendor().getId()==DUMMY_VENDOR_ID && thirdPartyWarehouse.getInventoryType()==InventoryType.GOOD && thirdPartyWarehouse.getWarehouseType()==WarehouseType.OURS_THIRDPARTY){
191
				}
190
            	checkDirectScanWarehouse = true;
192
			}
191
            }
193
 
192
            
194
			WarehouseClient warehouseClient = new WarehouseClient();
193
            long currentWarehouseId = 0;
195
			Client client = warehouseClient.getClient();
194
            if(!checkDirectScanWarehouse){
196
			in.shop2020.purchase.PurchaseService.Client purchaseClient = new PurchaseClient().getClient();
195
            	Warehouse fulfilmentWarehouse = inventoryClient.getWarehouses(WarehouseType.OURS, InventoryType.GOOD, po.getSupplierId(), po.getWarehouseId(), 0).get(0);
197
			PurchaseOrder po = purchaseClient.getPurchaseOrder(poId);
196
            	currentWarehouseId = fulfilmentWarehouse.getId();
198
			InventoryService.Client inventoryClient = new InventoryClient().getClient();
197
            }
199
			if (transferLotId == null || transferLotId == 0) {
198
            
200
				if (transferWarehouseId != null && transferWarehouseId != 0) {
199
            for (LineItem lineItem : lineItems) {
201
					Warehouse fulfilmentWarehouse = inventoryClient.getWarehouses(WarehouseType.OURS,
200
                if (ScanRecordType.BLANK.name().equals(lineItem.getExtra_info())) {
202
							InventoryType.GOOD, po.getSupplierId(), po.getWarehouseId(), 0L).get(0);
201
                    continue;
203
					transferLotId = client.createTransferLot(po.getWarehouseId(), transferWarehouseId);
202
                }
204
				}
203
 
205
			}
204
                InventoryItem inventoryItem = new InventoryItem();
206
			boolean checkDirectScanWarehouse = false;
205
                inventoryItem.setItemId(lineItem.getItem_id());
207
 
206
                inventoryItem.setPurchaseId(Long.parseLong(id));
208
			if (thirdPartyWarehouse.getVendor().getId() == DUMMY_VENDOR_ID
207
                inventoryItem.setCurrentQuantity(0);
209
					&& thirdPartyWarehouse.getInventoryType() == InventoryType.GOOD
208
                inventoryItem.setItemNumber(lineItem.getItem_number());
210
					&& thirdPartyWarehouse.getWarehouseType() == WarehouseType.OURS_THIRDPARTY) {
209
                inventoryItem.setSerialNumber(lineItem.getSerial_number());
211
				checkDirectScanWarehouse = true;
210
                inventoryItem.setInitialQuantity(new Double(lineItem.getQuantity()).longValue());
212
			}
211
                inventoryItem.setPhysicalWarehouseId(po.getWarehouseId());
213
 
212
                logger.info("checkDirectScanWarehouse..... "+ checkDirectScanWarehouse);
214
			long currentWarehouseId = 0;
213
                if(checkDirectScanWarehouse){
215
			if (!checkDirectScanWarehouse) {
214
                	logger.info("Come into this loop.... where direct scan Warehouse Id exist");
216
				Warehouse fulfilmentWarehouse = inventoryClient.getWarehouses(WarehouseType.OURS, InventoryType.GOOD,
215
                	inventoryItem.setPhysicalWarehouseId(po.getWarehouseId());
217
						po.getSupplierId(), po.getWarehouseId(), 0).get(0);
216
                	inventoryItem.setCurrentWarehouseId(po.getWarehouseId());
218
				currentWarehouseId = fulfilmentWarehouse.getId();
217
                }else{
219
			}
218
                	logger.info("Come into this loop.... where direct scan Warehouse Id Not Exist");
220
 
219
                	inventoryItem.setPhysicalWarehouseId(po.getWarehouseId());
221
			for (LineItem lineItem : lineItems) {
220
                	inventoryItem.setCurrentWarehouseId(currentWarehouseId);
222
				if (ScanRecordType.BLANK.name().equals(lineItem.getExtra_info())) {
221
                }
223
					continue;
222
                
224
				}
223
                if(!client.isAlive()){
225
 
-
 
226
				InventoryItem inventoryItem = new InventoryItem();
-
 
227
				inventoryItem.setItemId(lineItem.getItem_id());
-
 
228
				inventoryItem.setPurchaseId(Long.parseLong(id));
-
 
229
				inventoryItem.setCurrentQuantity(0);
-
 
230
				inventoryItem.setItemNumber(lineItem.getItem_number());
-
 
231
				inventoryItem.setSerialNumber(lineItem.getSerial_number());
-
 
232
				inventoryItem.setInitialQuantity(new Double(lineItem.getQuantity()).longValue());
-
 
233
				inventoryItem.setPhysicalWarehouseId(po.getWarehouseId());
-
 
234
				logger.info("checkDirectScanWarehouse..... " + checkDirectScanWarehouse);
-
 
235
				if (checkDirectScanWarehouse) {
-
 
236
					logger.info("Come into this loop.... where direct scan Warehouse Id exist");
-
 
237
					inventoryItem.setPhysicalWarehouseId(po.getWarehouseId());
-
 
238
					inventoryItem.setCurrentWarehouseId(po.getWarehouseId());
-
 
239
				} else {
-
 
240
					logger.info("Come into this loop.... where direct scan Warehouse Id Not Exist");
-
 
241
					inventoryItem.setPhysicalWarehouseId(po.getWarehouseId());
-
 
242
					inventoryItem.setCurrentWarehouseId(currentWarehouseId);
-
 
243
				}
-
 
244
 
-
 
245
				if (!client.isAlive()) {
224
					client = warehouseClient.getClient();
246
					client = warehouseClient.getClient();
225
				}
247
				}
226
            	client.scan(inventoryItem, ScanType.PURCHASE, new Double(lineItem.getQuantity()).longValue(), warehouseId, (transferLotId!=null)?transferLotId:0L);
248
				client.scan(inventoryItem, ScanType.PURCHASE, new Double(lineItem.getQuantity()).longValue(),
-
 
249
						warehouseId, (transferLotId != null) ? transferLotId : 0L);
-
 
250
			}
-
 
251
 
-
 
252
			resetLineItems();
-
 
253
		} catch (TTransportException e) {
-
 
254
			errorMsg = "Issue while scanning:- " + e.getMessage();
-
 
255
			logger.error(errorMsg, e);
-
 
256
		} catch (WarehouseServiceException e) {
-
 
257
			errorMsg = e.getMessage();
-
 
258
			logger.error(errorMsg, e);
227
            }
259
		} catch (TException e) {
-
 
260
			errorMsg = "Error while scanning in the item";
-
 
261
			logger.error(errorMsg, e);
-
 
262
		} catch (PurchaseServiceException e) {
-
 
263
			errorMsg = "Error while creating the purchase";
-
 
264
			logger.error(errorMsg, e);
-
 
265
		}
228
 
266
 
229
            resetLineItems();
267
		if (!errorMsg.isEmpty()) {
230
        } catch (TTransportException e) {
268
			addActionError(errorMsg);
231
            errorMsg = "Issue while scanning:- "+e.getMessage();
269
		}
232
            logger.error(errorMsg, e);
270
 
233
        } catch (WarehouseServiceException e) {
271
		return SHOW;
234
            errorMsg = e.getMessage();
272
	}
235
            logger.error(errorMsg, e);
273
 
236
        } catch (TException e) {
274
	/**
237
            errorMsg = "Error while scanning in the item";
275
	 * @return
238
            logger.error(errorMsg, e);
276
	 * @throws TException
239
        } catch (PurchaseServiceException e) {
277
	 * @throws NumberFormatException
240
            errorMsg = "Error while creating the purchase";
278
	 * @throws PurchaseServiceException
241
            logger.error(errorMsg, e);
279
	 */
242
        }
280
	private boolean areValidScans() throws NumberFormatException, TException, PurchaseServiceException {
243
 
281
		boolean areValidScans = true;
244
        if (!errorMsg.isEmpty()) {
282
		in.shop2020.purchase.PurchaseService.Client purchaseClient = new PurchaseClient().getClient();
245
            addActionError(errorMsg);
283
		// PurchaseOrder purchaseOrder =
246
        }
284
		// purchaseClient.getPurchaseOrderForPurchase(Long.parseLong(id));
247
 
285
		PurchaseOrder purchaseOrder = purchaseClient.getPurchaseOrder(poId);
248
        return SHOW;
286
		Map<Long, Long> itemsQuantityMapFromPO = new HashMap<Long, Long>();
249
    }
287
		for (in.shop2020.purchase.LineItem lineItem : purchaseOrder.getLineitems()) {
250
 
288
			itemsQuantityMapFromPO.put(lineItem.getItemId(), (long) lineItem.getUnfulfilledQuantity());
251
    /**
289
		}
252
     * @return
290
 
253
     * @throws TException 
291
		Client warehouseClient = new WarehouseClient().getClient();
254
     * @throws NumberFormatException 
292
		for (LineItem lineItem : lineItems) {
255
     * @throws PurchaseServiceException 
293
			if (lineItem.getItem_id() == -1 && lineItem.getItem_number().isEmpty()
256
     */
294
					&& lineItem.getSerial_number().isEmpty()) {
257
    private boolean areValidScans() throws NumberFormatException, TException, PurchaseServiceException {
295
				lineItem.setExtra_info(ScanRecordType.BLANK.name());
258
        boolean areValidScans = true;
296
			} else {
259
        in.shop2020.purchase.PurchaseService.Client purchaseClient = new PurchaseClient().getClient();
297
				lineItem.setExtra_info(ScanRecordType.VALID.name());
260
        //PurchaseOrder purchaseOrder = purchaseClient.getPurchaseOrderForPurchase(Long.parseLong(id));
298
				if (StringUtils.isNotBlank(lineItem.getSerial_number())) {
261
        PurchaseOrder purchaseOrder = purchaseClient.getPurchaseOrder(poId);
299
					try {
262
        Map<Long, Long> itemsQuantityMapFromPO = new HashMap<Long, Long>();
300
						InventoryItem inventoryItem = warehouseClient.getInventoryItem(lineItem.getSerial_number());
263
        for (in.shop2020.purchase.LineItem lineItem : purchaseOrder.getLineitems()) {
301
						if (inventoryItem.getLastScanType() != ScanType.PURCHASE_RETURN
264
            itemsQuantityMapFromPO.put(lineItem.getItemId(), (long) lineItem.getUnfulfilledQuantity());
302
								&& inventoryItem.getLastScanType() != ScanType.DOA_REPLACED) {
265
        }
303
							lineItem.setExtra_info("Item scanned already.");
266
 
304
							areValidScans = false;
267
        Client warehouseClient = new WarehouseClient().getClient();
305
							continue;
268
        for (LineItem lineItem : lineItems) {
306
						}
269
            if (lineItem.getItem_id() == -1 && lineItem.getItem_number().isEmpty() && lineItem.getSerial_number().isEmpty()) {
307
					} catch (Exception e) {
270
                lineItem.setExtra_info(ScanRecordType.BLANK.name());
308
					}
271
            }
309
				}
272
            else {
310
 
273
                lineItem.setExtra_info(ScanRecordType.VALID.name());
311
				if (lineItem.getItem_id() == -1 && (StringUtils.isBlank(lineItem.getItem_number())
274
                if (StringUtils.isNotBlank(lineItem.getSerial_number())) {
312
						|| StringUtils.isBlank(lineItem.getSerial_number()))) {
275
                    try {
313
					lineItem.setExtra_info("Item not selected/Item or serial number not present");
276
                    	InventoryItem inventoryItem = warehouseClient.getInventoryItem(lineItem.getSerial_number());
314
					areValidScans = false;
277
                        if(inventoryItem.getLastScanType()!=ScanType.PURCHASE_RETURN && inventoryItem.getLastScanType()!=ScanType.DOA_REPLACED) {
315
					continue;
278
	                       lineItem.setExtra_info("Item scanned already.");
316
				}
279
	                       areValidScans = false;
-
 
280
	                       continue;
-
 
281
                        }
-
 
282
                    } catch (Exception e) {
-
 
283
                    }
-
 
284
                }
-
 
285
 
-
 
286
                if (lineItem.getItem_id() == -1 && 
-
 
287
                        (StringUtils.isBlank(lineItem.getItem_number()) || 
-
 
288
                         StringUtils.isBlank(lineItem.getSerial_number())))
-
 
289
                {
-
 
290
                    lineItem.setExtra_info("Item not selected/Item or serial number not present");
-
 
291
                    areValidScans = false;
-
 
292
                    continue;
-
 
293
                }
-
 
294
 
-
 
295
                if (StringUtils.isBlank(lineItem.getItem_number())) {
-
 
296
                	lineItem.setExtra_info("Item number not entered");
-
 
297
                	areValidScans = false;
-
 
298
                	continue;
-
 
299
                }
-
 
300
                
-
 
301
                if (lineItem.getItem_id() == -1) {
-
 
302
                    List<Long> itemIds = warehouseClient.getItemIds(lineItem.getItem_number());
-
 
303
                    if (itemIds.isEmpty()) {
-
 
304
                        lineItem.setExtra_info("Unknown item number");
-
 
305
                        areValidScans = false;
-
 
306
                        continue;
-
 
307
                    }
-
 
308
 
-
 
309
                    if (itemIds.size() > 0) {
-
 
310
                        int numItemsInPO = 0;
-
 
311
                        for (long itemId : itemIds) {
-
 
312
                            if (itemsQuantityMapFromPO.containsKey(itemId)) {
-
 
313
                                numItemsInPO++;
-
 
314
                                lineItem.setItem_id(itemId);
-
 
315
                            }
-
 
316
                        }
-
 
317
                        
-
 
318
                        if (numItemsInPO > 1) {
-
 
319
                            lineItem.setExtra_info("Multiple items found for given item Number. Choose item explicitly.");
-
 
320
                            areValidScans = false;
-
 
321
                            continue;
-
 
322
                        }
-
 
323
                    }
-
 
324
                }
-
 
325
 
-
 
326
                if (!itemsQuantityMapFromPO.containsKey(lineItem.getItem_id())) {
-
 
327
                    lineItem.setExtra_info("Item not present in PO.");
-
 
328
                    areValidScans = false;
-
 
329
                    continue;
-
 
330
                }
-
 
331
 
-
 
332
                itemsQuantityMapFromPO.put(lineItem.getItem_id(),
-
 
333
                        itemsQuantityMapFromPO.get(lineItem.getItem_id()) - new Double(lineItem.getQuantity()).longValue());
-
 
334
 
-
 
335
                if (itemsQuantityMapFromPO.get(lineItem.getItem_id()) < 0) {
-
 
336
                    lineItem.setExtra_info("Item already fulfilled in PO.");
-
 
337
                    areValidScans = false;
-
 
338
                    continue;
-
 
339
                }
-
 
340
            }
-
 
341
        }
-
 
342
 
-
 
343
        return areValidScans;
-
 
344
    }
-
 
345
 
-
 
346
    private void setItemsFromPO() {
-
 
347
        try {
-
 
348
            items = new ArrayList<Item>();
-
 
349
            in.shop2020.purchase.PurchaseService.Client purchaseClient = new PurchaseClient().getClient();
-
 
350
            //PurchaseOrder purchaseOrder = purchaseClient.getPurchaseOrderForPurchase(id);
-
 
351
            PurchaseOrder purchaseOrder = purchaseClient.getPurchaseOrder(poId);
-
 
352
            warehouseId = purchaseOrder.getWarehouseId();
-
 
353
            in.shop2020.model.v1.catalog.CatalogService.Client catalogClient = new CatalogClient().getClient();
-
 
354
 
-
 
355
            for (in.shop2020.purchase.LineItem lineItem : purchaseOrder.getLineitems()) {
-
 
356
                items.add(catalogClient.getItem(lineItem.getItemId()));
-
 
357
            }
-
 
358
 
-
 
359
            in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = new InventoryClient().getClient();
-
 
360
            thirdPartyWarehouse = inventoryClient.getWarehouse(warehouseId);
-
 
361
            if(thirdPartyWarehouse.getVendor().getId()==DUMMY_VENDOR_ID && thirdPartyWarehouse.getInventoryType()==InventoryType.GOOD && thirdPartyWarehouse.getWarehouseType()==WarehouseType.OURS_THIRDPARTY){
-
 
362
            	warehouse = thirdPartyWarehouse;
-
 
363
            } else {
-
 
364
            	warehouse = inventoryClient.getWarehouses(WarehouseType.OURS, InventoryType.GOOD, purchaseOrder.getSupplierId(), warehouseId, warehouseId).get(0);
-
 
365
            }
-
 
366
        } catch (Exception e) {
-
 
367
            logger.error("Could not find items in PO with purchase: " + id, e);
-
 
368
        }
-
 
369
    }
-
 
370
 
-
 
371
    public String destroy() {
-
 
372
        long id = Long.parseLong(this.id);
-
 
373
 
-
 
374
        try {
-
 
375
            PurchaseClient warehouseClient = new PurchaseClient();
-
 
376
            in.shop2020.purchase.PurchaseService.Client client = warehouseClient
-
 
377
                    .getClient();
-
 
378
            client.closePurchase(id);
-
 
379
        } catch (TTransportException e) {
-
 
380
            errorMsg = "Error while establishing connection to the warehouse server";
-
 
381
            logger.error(errorMsg, e);
-
 
382
        } catch (TException e) {
-
 
383
            errorMsg = "Error while scanning in the item";
-
 
384
            logger.error(errorMsg, e);
-
 
385
        } catch (PurchaseServiceException e) {
-
 
386
            errorMsg = e.getMessage();
-
 
387
            logger.error(errorMsg, e);
-
 
388
        }
-
 
389
        return "redirect";
-
 
390
    }
-
 
391
 
-
 
392
    public String createItemNumberMapping() {
-
 
393
        long itemIdLong = Long.parseLong(itemId);
-
 
394
 
-
 
395
        try {
-
 
396
            Client warehouseClient = new WarehouseClient().getClient();
-
 
397
            warehouseClient.createItemNumberMapping(itemNo, itemIdLong);
-
 
398
        } catch (TTransportException e) {
-
 
399
            logger.error("Could not create thrift client", e);
-
 
400
        } catch (TException e) {
-
 
401
            logger.error("Could not create item number mapping", e);
-
 
402
        }
-
 
403
 
-
 
404
        return show();
-
 
405
    }
-
 
406
    
-
 
407
    /*public String setTransferItemsOption() {
-
 
408
    	boolean isTransferAllowed = false;
-
 
409
    	try {
-
 
410
			Client warehouseClient = new WarehouseClient().getClient();
-
 
411
	        isTransferAllowed = warehouseClient.isItemTransferAllowed(warehouseId, transferWarehouseId);
-
 
412
    	} catch (TTransportException e) {
-
 
413
            logger.error("Could not create thrift client", e);
-
 
414
        } catch (TException e) {
-
 
415
            logger.error("Could not check if item transfer allowed between warehouses", e);
-
 
416
        }//TODO
-
 
417
    	return "";
-
 
418
    }*/
-
 
419
    
-
 
420
    public List<Warehouse> getAllowedDestinationWarehousesForTransfer(long originWarehouseId){
-
 
421
    	try {
-
 
422
    		WarehouseService.Client warehouseClient = new WarehouseClient().getClient();
-
 
423
    		List<Long> allowedWarehouseIds = warehouseClient.getAllowedDestinationWarehousesForTransfer(originWarehouseId);
-
 
424
    		List<Warehouse> allowedWarehouses = new ArrayList<Warehouse>();
-
 
425
    		InventoryService.Client inventoryClient = new InventoryClient().getClient();
-
 
426
    		for(Long allowedWarehouseId : allowedWarehouseIds) {
-
 
427
    			allowedWarehouses.add(inventoryClient.getWarehouse(allowedWarehouseId));
-
 
428
    		}
-
 
429
    		return allowedWarehouses;
-
 
430
    	} catch(Exception e) {
-
 
431
    		logger.error("Error while getting all destination warehouses for warehouseId " + warehouseId, e);
-
 
432
    		return new ArrayList<Warehouse>();
-
 
433
    	}
-
 
434
    }
-
 
435
 
317
 
-
 
318
				if (StringUtils.isBlank(lineItem.getItem_number())) {
-
 
319
					lineItem.setExtra_info("Item number not entered");
-
 
320
					areValidScans = false;
-
 
321
					continue;
-
 
322
				}
-
 
323
 
436
/*	public boolean canItemCanBeScannedIn(long id) {
324
				if (lineItem.getItem_id() == -1) {
-
 
325
					List<Long> itemIds = warehouseClient.getItemIds(lineItem.getItem_number());
-
 
326
					if (itemIds.isEmpty()) {
-
 
327
						lineItem.setExtra_info("Unknown item number");
-
 
328
						areValidScans = false;
-
 
329
						continue;
-
 
330
					}
-
 
331
 
-
 
332
					if (itemIds.size() > 0) {
437
		double itemWeight = 0.0;
333
						int numItemsInPO = 0;
-
 
334
						for (long itemId : itemIds) {
-
 
335
							if (itemsQuantityMapFromPO.containsKey(itemId)) {
-
 
336
								numItemsInPO++;
-
 
337
								lineItem.setItem_id(itemId);
-
 
338
							}
-
 
339
						}
-
 
340
 
-
 
341
						if (numItemsInPO > 1) {
-
 
342
							lineItem.setExtra_info(
-
 
343
									"Multiple items found for given item Number. Choose item explicitly.");
-
 
344
							areValidScans = false;
-
 
345
							continue;
-
 
346
						}
-
 
347
					}
-
 
348
				}
-
 
349
 
-
 
350
				if (!itemsQuantityMapFromPO.containsKey(lineItem.getItem_id())) {
-
 
351
					lineItem.setExtra_info("Item not present in PO.");
-
 
352
					areValidScans = false;
-
 
353
					continue;
-
 
354
				}
-
 
355
 
-
 
356
				itemsQuantityMapFromPO.put(lineItem.getItem_id(), itemsQuantityMapFromPO.get(lineItem.getItem_id())
-
 
357
						- new Double(lineItem.getQuantity()).longValue());
-
 
358
 
-
 
359
				if (itemsQuantityMapFromPO.get(lineItem.getItem_id()) < 0) {
-
 
360
					lineItem.setExtra_info("Item already fulfilled in PO.");
-
 
361
					areValidScans = false;
-
 
362
					continue;
-
 
363
				}
-
 
364
			}
-
 
365
		}
-
 
366
 
-
 
367
		return areValidScans;
-
 
368
	}
-
 
369
 
-
 
370
	private void setItemsFromPO() {
438
		try {
371
		try {
-
 
372
			items = new ArrayList<Item>();
-
 
373
			in.shop2020.purchase.PurchaseService.Client purchaseClient = new PurchaseClient().getClient();
-
 
374
			// PurchaseOrder purchaseOrder = purchaseClient.getPurchaseOrderForPurchase(id);
-
 
375
			PurchaseOrder purchaseOrder = purchaseClient.getPurchaseOrder(poId);
-
 
376
			warehouseId = purchaseOrder.getWarehouseId();
439
			in.shop2020.model.v1.catalog.CatalogService.Client catalogClient = new CatalogClient().getClient();
377
			in.shop2020.model.v1.catalog.CatalogService.Client catalogClient = new CatalogClient().getClient();
-
 
378
 
-
 
379
			for (in.shop2020.purchase.LineItem lineItem : purchaseOrder.getLineitems()) {
-
 
380
				if(lineItem.getInvoicePrice() > 0) {
440
			Item item = catalogClient.getItem(id);
381
					items.add(catalogClient.getItem(lineItem.getItemId()));
-
 
382
				}
-
 
383
			}
-
 
384
 
-
 
385
			in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = new InventoryClient().getClient();
-
 
386
			thirdPartyWarehouse = inventoryClient.getWarehouse(warehouseId);
-
 
387
			if (thirdPartyWarehouse.getVendor().getId() == DUMMY_VENDOR_ID
-
 
388
					&& thirdPartyWarehouse.getInventoryType() == InventoryType.GOOD
-
 
389
					&& thirdPartyWarehouse.getWarehouseType() == WarehouseType.OURS_THIRDPARTY) {
441
			itemWeight = item.getWeight();
390
				warehouse = thirdPartyWarehouse;
-
 
391
			} else {
-
 
392
				warehouse = inventoryClient.getWarehouses(WarehouseType.OURS, InventoryType.GOOD,
-
 
393
						purchaseOrder.getSupplierId(), warehouseId, warehouseId).get(0);
-
 
394
			}
442
		} catch (Exception e) {
395
		} catch (Exception e) {
443
			logger.error("Could not fetch item to get weight of it ", e);
396
			logger.error("Could not find items in PO with purchase: " + id, e);
444
		}
397
		}
-
 
398
	}
-
 
399
 
445
		if(itemWeight> 0.0){
400
	public String destroy() {
-
 
401
		long id = Long.parseLong(this.id);
-
 
402
 
-
 
403
		try {
-
 
404
			PurchaseClient warehouseClient = new PurchaseClient();
-
 
405
			in.shop2020.purchase.PurchaseService.Client client = warehouseClient.getClient();
-
 
406
			client.closePurchase(id);
-
 
407
		} catch (TTransportException e) {
-
 
408
			errorMsg = "Error while establishing connection to the warehouse server";
-
 
409
			logger.error(errorMsg, e);
-
 
410
		} catch (TException e) {
-
 
411
			errorMsg = "Error while scanning in the item";
-
 
412
			logger.error(errorMsg, e);
-
 
413
		} catch (PurchaseServiceException e) {
-
 
414
			errorMsg = e.getMessage();
-
 
415
			logger.error(errorMsg, e);
-
 
416
		}
-
 
417
		return "redirect";
-
 
418
	}
-
 
419
 
-
 
420
	public String createItemNumberMapping() throws Exception {
-
 
421
		long itemIdLong = Long.parseLong(itemId);
-
 
422
 
-
 
423
		try {
-
 
424
			Client warehouseClient = new WarehouseClient().getClient();
-
 
425
			warehouseClient.createItemNumberMapping(itemNo, itemIdLong);
-
 
426
		} catch (TTransportException e) {
-
 
427
			logger.error("Could not create thrift client", e);
-
 
428
		} catch (TException e) {
-
 
429
			logger.error("Could not create item number mapping", e);
-
 
430
		}
-
 
431
 
-
 
432
		return show();
-
 
433
	}
-
 
434
 
-
 
435
	public String updateItemInvoicePrice() throws Exception {
-
 
436
		long itemIdLong = Long.parseLong(itemId);
-
 
437
		in.shop2020.purchase.PurchaseService.Client purchaseClient = new PurchaseClient().getClient();
-
 
438
		purchaseClient.createPurchaseForOurExtBilling(String.valueOf(poId), invoicePrice, 0, itemIdLong);
-
 
439
		setOutput("true");
446
			return true;
440
		return OUTPUT;
-
 
441
	}
-
 
442
 
-
 
443
	/*
-
 
444
	 * public String setTransferItemsOption() { boolean isTransferAllowed = false;
-
 
445
	 * try { Client warehouseClient = new WarehouseClient().getClient();
-
 
446
	 * isTransferAllowed = warehouseClient.isItemTransferAllowed(warehouseId,
-
 
447
	 * transferWarehouseId); } catch (TTransportException e) {
-
 
448
	 * logger.error("Could not create thrift client", e); } catch (TException e) {
-
 
449
	 * logger.error("Could not check if item transfer allowed between warehouses",
-
 
450
	 * e); }//TODO return ""; }
-
 
451
	 */
-
 
452
 
-
 
453
	public List<Warehouse> getAllowedDestinationWarehousesForTransfer(long originWarehouseId) {
-
 
454
		try {
-
 
455
			WarehouseService.Client warehouseClient = new WarehouseClient().getClient();
-
 
456
			List<Long> allowedWarehouseIds = warehouseClient
-
 
457
					.getAllowedDestinationWarehousesForTransfer(originWarehouseId);
-
 
458
			List<Warehouse> allowedWarehouses = new ArrayList<Warehouse>();
-
 
459
			InventoryService.Client inventoryClient = new InventoryClient().getClient();
-
 
460
			for (Long allowedWarehouseId : allowedWarehouseIds) {
-
 
461
				allowedWarehouses.add(inventoryClient.getWarehouse(allowedWarehouseId));
-
 
462
			}
-
 
463
			return allowedWarehouses;
-
 
464
		} catch (Exception e) {
-
 
465
			logger.error("Error while getting all destination warehouses for warehouseId " + warehouseId, e);
-
 
466
			return new ArrayList<Warehouse>();
447
		}
467
		}
448
		return false;
-
 
449
	}
468
	}
-
 
469
 
-
 
470
	/*
-
 
471
	 * public boolean canItemCanBeScannedIn(long id) { double itemWeight = 0.0; try
-
 
472
	 * { in.shop2020.model.v1.catalog.CatalogService.Client catalogClient = new
-
 
473
	 * CatalogClient().getClient(); Item item = catalogClient.getItem(id);
-
 
474
	 * itemWeight = item.getWeight(); } catch (Exception e) {
-
 
475
	 * logger.error("Could not fetch item to get weight of it ", e); }
-
 
476
	 * if(itemWeight> 0.0){ return true; } return false; }
450
*/
477
	 */
451
    public String itemNumberMappingEditNew() {
478
	public String itemNumberMappingEditNew() {
452
        return "item-number-mapping";
479
		return "item-number-mapping";
453
    }
480
	}
454
 
481
 
455
    public String getName(Item item){
482
	public String getName(Item item) {
456
        return ModelUtils.extractProductNameFromItem(item);
483
		return ModelUtils.extractProductNameFromItem(item);
457
    }
484
	}
458
 
485
 
459
    public void setId(String id) {
486
	public void setId(String id) {
460
        this.id = id;
487
		this.id = id;
461
    }
488
	}
462
 
489
 
463
    public String getId() {
490
	public String getId() {
464
        return id;
491
		return id;
465
    }
492
	}
466
 
493
 
467
    public String getErrorMessage() {
494
	public String getErrorMessage() {
468
        return errorMsg;
495
		return errorMsg;
469
    }
496
	}
470
 
497
 
471
    public String getPurchaseOrderId() {
498
	public String getPurchaseOrderId() {
472
        return purchaseOrderId;
499
		return purchaseOrderId;
473
    }
500
	}
474
 
501
 
475
    public String getServletContextPath() {
502
	public String getServletContextPath() {
476
        return context.getContextPath();
503
		return context.getContextPath();
477
    }
504
	}
478
 
505
 
479
    public String getItemId() {
506
	public String getItemId() {
480
        return itemId;
507
		return itemId;
481
    }
508
	}
482
 
509
 
483
    public void setItemId(String itemId) {
510
	public void setItemId(String itemId) {
484
        this.itemId = itemId;
511
		this.itemId = itemId;
485
    }
512
	}
486
 
513
 
487
    public String getItemNo() {
514
	public String getItemNo() {
488
        return itemNo;
515
		return itemNo;
489
    }
516
	}
490
 
517
 
491
    public void setItemNo(String itemNo) {
518
	public void setItemNo(String itemNo) {
492
        this.itemNo = itemNo;
519
		this.itemNo = itemNo;
493
    }
520
	}
494
 
521
 
495
    public List<Item> getItems() {
522
	public List<Item> getItems() {
496
        return items;
523
		return items;
497
    }
524
	}
498
 
525
 
499
    public void setItems(List<Item> items) {
526
	public void setItems(List<Item> items) {
500
        this.items = items;
527
		this.items = items;
501
    }
528
	}
502
 
529
 
503
    public List<LineItem> getLineItems() {
530
	public List<LineItem> getLineItems() {
504
        return lineItems;
531
		return lineItems;
505
    }
532
	}
506
 
533
 
507
    public void setLineItems(List<LineItem> lineItems) {
534
	public void setLineItems(List<LineItem> lineItems) {
508
        this.lineItems = lineItems;
535
		this.lineItems = lineItems;
509
    }
536
	}
510
 
537
 
511
    public Warehouse getWarehouse() {
538
	public Warehouse getWarehouse() {
512
        return warehouse;
539
		return warehouse;
513
    }
540
	}
514
 
541
 
515
    public List<Invoice> getInvoices() {
542
	public List<Invoice> getInvoices() {
516
        return invoices;
543
		return invoices;
517
    }
544
	}
518
 
545
 
519
    public void setInvoices(List<Invoice> invoices) {
546
	public void setInvoices(List<Invoice> invoices) {
520
        this.invoices = invoices;
547
		this.invoices = invoices;
521
    }
548
	}
522
 
549
 
523
	public String getInvoiceNumber() {
550
	public String getInvoiceNumber() {
524
		return invoiceNumber;
551
		return invoiceNumber;
525
	}
552
	}
526
 
553
 
Line 581... Line 608...
581
	}
608
	}
582
 
609
 
583
	public void setThirdPartyWarehouse(Warehouse thirdPartyWarehouse) {
610
	public void setThirdPartyWarehouse(Warehouse thirdPartyWarehouse) {
584
		this.thirdPartyWarehouse = thirdPartyWarehouse;
611
		this.thirdPartyWarehouse = thirdPartyWarehouse;
585
	}
612
	}
586
	
613
 
587
}
614
}