| 4687 |
mandeep.dh |
1 |
package in.shop2020.inventory.controllers;
|
|
|
2 |
|
| 24991 |
amit.gupta |
3 |
import java.util.ArrayList;
|
|
|
4 |
import java.util.Calendar;
|
|
|
5 |
import java.util.Date;
|
|
|
6 |
import java.util.HashMap;
|
|
|
7 |
import java.util.List;
|
|
|
8 |
import java.util.Map;
|
|
|
9 |
|
|
|
10 |
import javax.servlet.ServletContext;
|
|
|
11 |
|
|
|
12 |
import org.apache.commons.lang.StringUtils;
|
|
|
13 |
import org.apache.struts2.convention.annotation.Result;
|
|
|
14 |
import org.apache.struts2.convention.annotation.Results;
|
|
|
15 |
import org.apache.thrift.TException;
|
|
|
16 |
import org.apache.thrift.transport.TTransportException;
|
|
|
17 |
import org.slf4j.Logger;
|
|
|
18 |
import org.slf4j.LoggerFactory;
|
|
|
19 |
|
| 4846 |
mandeep.dh |
20 |
import in.shop2020.model.v1.catalog.Item;
|
| 7410 |
amar.kumar |
21 |
import in.shop2020.model.v1.inventory.InventoryService;
|
| 5945 |
mandeep.dh |
22 |
import in.shop2020.model.v1.inventory.InventoryType;
|
|
|
23 |
import in.shop2020.model.v1.inventory.Warehouse;
|
|
|
24 |
import in.shop2020.model.v1.inventory.WarehouseType;
|
| 5110 |
mandeep.dh |
25 |
import in.shop2020.model.v1.order.LineItem;
|
| 5496 |
mandeep.dh |
26 |
import in.shop2020.purchase.Invoice;
|
| 11801 |
manish.sha |
27 |
/*import in.shop2020.purchase.POStatus;*/
|
| 5110 |
mandeep.dh |
28 |
import in.shop2020.purchase.PurchaseOrder;
|
| 11801 |
manish.sha |
29 |
/*import in.shop2020.purchase.PurchaseService;*/
|
| 4687 |
mandeep.dh |
30 |
import in.shop2020.purchase.PurchaseServiceException;
|
|
|
31 |
import in.shop2020.thrift.clients.CatalogClient;
|
| 5945 |
mandeep.dh |
32 |
import in.shop2020.thrift.clients.InventoryClient;
|
| 4687 |
mandeep.dh |
33 |
import in.shop2020.thrift.clients.PurchaseClient;
|
|
|
34 |
import in.shop2020.thrift.clients.WarehouseClient;
|
| 4846 |
mandeep.dh |
35 |
import in.shop2020.utils.ModelUtils;
|
| 4687 |
mandeep.dh |
36 |
import in.shop2020.warehouse.InventoryItem;
|
|
|
37 |
import in.shop2020.warehouse.ScanType;
|
| 7410 |
amar.kumar |
38 |
import in.shop2020.warehouse.WarehouseService;
|
| 4687 |
mandeep.dh |
39 |
import in.shop2020.warehouse.WarehouseService.Client;
|
|
|
40 |
import in.shop2020.warehouse.WarehouseServiceException;
|
|
|
41 |
|
|
|
42 |
@SuppressWarnings("serial")
|
|
|
43 |
@Results({ @Result(name = "redirect", type = "redirectAction", params = {
|
|
|
44 |
"actionName", "warehouse" }) })
|
|
|
45 |
public class PurchaseController extends BaseController {
|
| 5110 |
mandeep.dh |
46 |
/**
|
|
|
47 |
*
|
|
|
48 |
*/
|
|
|
49 |
private static final int NUM_BULK__SCAN_ITEMS = 10;
|
|
|
50 |
private static Logger logger = LoggerFactory.getLogger(PurchaseController.class);
|
| 7410 |
amar.kumar |
51 |
public static enum ScanRecordType { VALID, BLANK };
|
| 11801 |
manish.sha |
52 |
private static final long DUMMY_VENDOR_ID = 40;
|
| 4687 |
mandeep.dh |
53 |
|
|
|
54 |
private ServletContext context;
|
|
|
55 |
private String id;
|
| 7410 |
amar.kumar |
56 |
private Long transferLotId;
|
| 4687 |
mandeep.dh |
57 |
private String itemId;
|
|
|
58 |
private String itemNo;
|
|
|
59 |
private String errorMsg = "";
|
| 4846 |
mandeep.dh |
60 |
private List<Item> items;
|
| 5110 |
mandeep.dh |
61 |
private List<LineItem> lineItems;
|
| 5496 |
mandeep.dh |
62 |
private List<Invoice> invoices;
|
| 6630 |
amar.kumar |
63 |
|
|
|
64 |
private String invoiceNumber;
|
|
|
65 |
private Double freightCharges ;
|
|
|
66 |
private Long poId;
|
| 11801 |
manish.sha |
67 |
private String purchaseComments;
|
| 4687 |
mandeep.dh |
68 |
|
|
|
69 |
private String purchaseOrderId;
|
| 7410 |
amar.kumar |
70 |
private Long warehouseId;
|
|
|
71 |
private Long transferWarehouseId;
|
| 5110 |
mandeep.dh |
72 |
private Warehouse warehouse;
|
| 11801 |
manish.sha |
73 |
private Warehouse thirdPartyWarehouse;
|
| 4687 |
mandeep.dh |
74 |
|
|
|
75 |
public String editNew() {
|
|
|
76 |
purchaseOrderId = request.getParameter("poId");
|
| 5496 |
mandeep.dh |
77 |
|
|
|
78 |
try {
|
|
|
79 |
in.shop2020.purchase.PurchaseService.Client purchaseClient = new PurchaseClient().getClient();
|
| 7410 |
amar.kumar |
80 |
//invoices = purchaseClient.getInvoices(getPreviousDay(getPreviousDay(new Date())).getTime());
|
|
|
81 |
PurchaseOrder po = purchaseClient.getPurchaseOrder(Long.parseLong(purchaseOrderId));
|
|
|
82 |
invoices = purchaseClient.getInvoicesForWarehouse(po.getWarehouseId(), po.getSupplierId(), getPreviousDay(getPreviousDay(new Date())).getTime());
|
| 5496 |
mandeep.dh |
83 |
} catch (Exception e) {
|
|
|
84 |
logger.error("Error loading invoices", e);
|
|
|
85 |
}
|
|
|
86 |
|
| 4687 |
mandeep.dh |
87 |
return "new";
|
|
|
88 |
}
|
|
|
89 |
|
| 5496 |
mandeep.dh |
90 |
private Date getPreviousDay(Date date) {
|
|
|
91 |
Calendar calendar = Calendar.getInstance();
|
|
|
92 |
calendar.setTime(date);
|
|
|
93 |
calendar.add(Calendar.DAY_OF_MONTH, -1);
|
|
|
94 |
return calendar.getTime();
|
|
|
95 |
}
|
|
|
96 |
|
| 4687 |
mandeep.dh |
97 |
public String create() {
|
| 6630 |
amar.kumar |
98 |
this.purchaseOrderId = request.getParameter("poId");
|
|
|
99 |
poId = Long.parseLong(purchaseOrderId);
|
|
|
100 |
invoiceNumber = request.getParameter("invoiceNo");
|
| 24332 |
amit.gupta |
101 |
if(invoiceNumber.endsWith(",")) {
|
|
|
102 |
addActionError("Invoice Number should not end with Comma");
|
|
|
103 |
return "show";
|
|
|
104 |
}
|
| 4687 |
mandeep.dh |
105 |
String fc = request.getParameter("freightCharges").trim();
|
| 6630 |
amar.kumar |
106 |
freightCharges = 0D;
|
|
|
107 |
id = "0";
|
| 4687 |
mandeep.dh |
108 |
if (fc != null && !fc.isEmpty())
|
|
|
109 |
freightCharges = Double.parseDouble(fc);
|
| 6630 |
amar.kumar |
110 |
return show();
|
|
|
111 |
//return "create";
|
| 4687 |
mandeep.dh |
112 |
|
|
|
113 |
}
|
|
|
114 |
|
|
|
115 |
public String show() {
|
| 5110 |
mandeep.dh |
116 |
resetLineItems();
|
| 6630 |
amar.kumar |
117 |
setItemsFromPO();
|
| 5110 |
mandeep.dh |
118 |
return SHOW;
|
| 4687 |
mandeep.dh |
119 |
}
|
|
|
120 |
|
| 5110 |
mandeep.dh |
121 |
private void resetLineItems() {
|
|
|
122 |
lineItems = new ArrayList<LineItem>();
|
|
|
123 |
|
|
|
124 |
for (int i = 0; i < NUM_BULK__SCAN_ITEMS; i++) {
|
|
|
125 |
LineItem lineItem = new LineItem();
|
|
|
126 |
lineItem.setId(i);
|
|
|
127 |
lineItem.setExtra_info("");
|
|
|
128 |
lineItem.setSerial_number("");
|
|
|
129 |
lineItem.setItem_number("");
|
| 5361 |
mandeep.dh |
130 |
lineItem.setQuantity(1);
|
| 5110 |
mandeep.dh |
131 |
lineItem.setItem_id(-1);
|
|
|
132 |
lineItems.add(lineItem);
|
|
|
133 |
}
|
|
|
134 |
}
|
|
|
135 |
|
| 6630 |
amar.kumar |
136 |
public boolean createPurchase(){
|
|
|
137 |
try {
|
| 11801 |
manish.sha |
138 |
logger.info("poId="+poId+" invoiceNumber="+invoiceNumber+" freightCharges="+freightCharges+ " purchaseComments= "+purchaseComments);
|
| 6630 |
amar.kumar |
139 |
PurchaseClient purchaseClient = new PurchaseClient();
|
|
|
140 |
in.shop2020.purchase.PurchaseService.Client client = purchaseClient
|
|
|
141 |
.getClient();
|
| 11801 |
manish.sha |
142 |
id = "" + client.startPurchase(poId, invoiceNumber, freightCharges, purchaseComments);
|
| 6630 |
amar.kumar |
143 |
logger.info("id = "+id);
|
|
|
144 |
} catch (TTransportException e) {
|
|
|
145 |
errorMsg = "Error while establishing connection to the warehouse server";
|
|
|
146 |
logger.error(errorMsg, e);
|
|
|
147 |
} catch (TException e) {
|
|
|
148 |
errorMsg = "Error while scanning in the item";
|
|
|
149 |
logger.error(errorMsg, e);
|
|
|
150 |
} catch (PurchaseServiceException e) {
|
|
|
151 |
errorMsg = e.getMessage();
|
|
|
152 |
logger.error(errorMsg, e);
|
|
|
153 |
}
|
|
|
154 |
|
|
|
155 |
if (errorMsg.isEmpty())
|
|
|
156 |
return true;
|
|
|
157 |
else {
|
|
|
158 |
addActionError(errorMsg);
|
|
|
159 |
return false;
|
|
|
160 |
}
|
|
|
161 |
}
|
|
|
162 |
|
| 4687 |
mandeep.dh |
163 |
public String update() {
|
| 6630 |
amar.kumar |
164 |
setItemsFromPO();
|
| 4687 |
mandeep.dh |
165 |
|
|
|
166 |
try {
|
| 5110 |
mandeep.dh |
167 |
if (!areValidScans()) {
|
|
|
168 |
return SHOW;
|
|
|
169 |
}
|
| 6641 |
amar.kumar |
170 |
if(id == null || Long.parseLong(id)==0) {
|
|
|
171 |
if(!createPurchase()) {
|
|
|
172 |
return "new";
|
|
|
173 |
}
|
|
|
174 |
}
|
| 5110 |
mandeep.dh |
175 |
|
| 4687 |
mandeep.dh |
176 |
WarehouseClient warehouseClient = new WarehouseClient();
|
|
|
177 |
Client client = warehouseClient.getClient();
|
| 7410 |
amar.kumar |
178 |
in.shop2020.purchase.PurchaseService.Client purchaseClient = new PurchaseClient().getClient();
|
|
|
179 |
PurchaseOrder po = purchaseClient.getPurchaseOrder(poId);
|
| 16264 |
manish.sha |
180 |
InventoryService.Client inventoryClient = new InventoryClient().getClient();
|
| 7410 |
amar.kumar |
181 |
if(transferLotId==null || transferLotId==0) {
|
|
|
182 |
if(transferWarehouseId!=null && transferWarehouseId!=0) {
|
|
|
183 |
Warehouse fulfilmentWarehouse = inventoryClient.getWarehouses(WarehouseType.OURS, InventoryType.GOOD, po.getSupplierId(), po.getWarehouseId(), 0L).get(0);
|
|
|
184 |
transferLotId = client.createTransferLot(po.getWarehouseId(), transferWarehouseId);
|
|
|
185 |
}
|
|
|
186 |
}
|
| 11801 |
manish.sha |
187 |
boolean checkDirectScanWarehouse = false;
|
|
|
188 |
|
|
|
189 |
if(thirdPartyWarehouse.getVendor().getId()==DUMMY_VENDOR_ID && thirdPartyWarehouse.getInventoryType()==InventoryType.GOOD && thirdPartyWarehouse.getWarehouseType()==WarehouseType.OURS_THIRDPARTY){
|
|
|
190 |
checkDirectScanWarehouse = true;
|
|
|
191 |
}
|
|
|
192 |
|
| 16264 |
manish.sha |
193 |
long currentWarehouseId = 0;
|
|
|
194 |
if(!checkDirectScanWarehouse){
|
|
|
195 |
Warehouse fulfilmentWarehouse = inventoryClient.getWarehouses(WarehouseType.OURS, InventoryType.GOOD, po.getSupplierId(), po.getWarehouseId(), 0).get(0);
|
|
|
196 |
currentWarehouseId = fulfilmentWarehouse.getId();
|
|
|
197 |
}
|
|
|
198 |
|
| 5110 |
mandeep.dh |
199 |
for (LineItem lineItem : lineItems) {
|
|
|
200 |
if (ScanRecordType.BLANK.name().equals(lineItem.getExtra_info())) {
|
|
|
201 |
continue;
|
|
|
202 |
}
|
|
|
203 |
|
| 5437 |
mandeep.dh |
204 |
InventoryItem inventoryItem = new InventoryItem();
|
|
|
205 |
inventoryItem.setItemId(lineItem.getItem_id());
|
| 6641 |
amar.kumar |
206 |
inventoryItem.setPurchaseId(Long.parseLong(id));
|
| 7441 |
amar.kumar |
207 |
inventoryItem.setCurrentQuantity(0);
|
| 5437 |
mandeep.dh |
208 |
inventoryItem.setItemNumber(lineItem.getItem_number());
|
|
|
209 |
inventoryItem.setSerialNumber(lineItem.getSerial_number());
|
| 5530 |
mandeep.dh |
210 |
inventoryItem.setInitialQuantity(new Double(lineItem.getQuantity()).longValue());
|
| 7410 |
amar.kumar |
211 |
inventoryItem.setPhysicalWarehouseId(po.getWarehouseId());
|
| 11801 |
manish.sha |
212 |
logger.info("checkDirectScanWarehouse..... "+ checkDirectScanWarehouse);
|
|
|
213 |
if(checkDirectScanWarehouse){
|
|
|
214 |
logger.info("Come into this loop.... where direct scan Warehouse Id exist");
|
|
|
215 |
inventoryItem.setPhysicalWarehouseId(po.getWarehouseId());
|
|
|
216 |
inventoryItem.setCurrentWarehouseId(po.getWarehouseId());
|
|
|
217 |
}else{
|
|
|
218 |
logger.info("Come into this loop.... where direct scan Warehouse Id Not Exist");
|
|
|
219 |
inventoryItem.setPhysicalWarehouseId(po.getWarehouseId());
|
| 16264 |
manish.sha |
220 |
inventoryItem.setCurrentWarehouseId(currentWarehouseId);
|
| 11801 |
manish.sha |
221 |
}
|
|
|
222 |
|
|
|
223 |
if(!client.isAlive()){
|
|
|
224 |
client = warehouseClient.getClient();
|
|
|
225 |
}
|
| 7410 |
amar.kumar |
226 |
client.scan(inventoryItem, ScanType.PURCHASE, new Double(lineItem.getQuantity()).longValue(), warehouseId, (transferLotId!=null)?transferLotId:0L);
|
| 5361 |
mandeep.dh |
227 |
}
|
| 5110 |
mandeep.dh |
228 |
|
|
|
229 |
resetLineItems();
|
| 4687 |
mandeep.dh |
230 |
} catch (TTransportException e) {
|
| 16264 |
manish.sha |
231 |
errorMsg = "Issue while scanning:- "+e.getMessage();
|
| 4687 |
mandeep.dh |
232 |
logger.error(errorMsg, e);
|
|
|
233 |
} catch (WarehouseServiceException e) {
|
|
|
234 |
errorMsg = e.getMessage();
|
|
|
235 |
logger.error(errorMsg, e);
|
|
|
236 |
} catch (TException e) {
|
|
|
237 |
errorMsg = "Error while scanning in the item";
|
|
|
238 |
logger.error(errorMsg, e);
|
| 6630 |
amar.kumar |
239 |
} catch (PurchaseServiceException e) {
|
|
|
240 |
errorMsg = "Error while creating the purchase";
|
|
|
241 |
logger.error(errorMsg, e);
|
| 4687 |
mandeep.dh |
242 |
}
|
| 5110 |
mandeep.dh |
243 |
|
| 4687 |
mandeep.dh |
244 |
if (!errorMsg.isEmpty()) {
|
|
|
245 |
addActionError(errorMsg);
|
|
|
246 |
}
|
| 4846 |
mandeep.dh |
247 |
|
| 5110 |
mandeep.dh |
248 |
return SHOW;
|
| 4687 |
mandeep.dh |
249 |
}
|
|
|
250 |
|
| 5110 |
mandeep.dh |
251 |
/**
|
|
|
252 |
* @return
|
|
|
253 |
* @throws TException
|
|
|
254 |
* @throws NumberFormatException
|
| 6630 |
amar.kumar |
255 |
* @throws PurchaseServiceException
|
| 5110 |
mandeep.dh |
256 |
*/
|
| 6630 |
amar.kumar |
257 |
private boolean areValidScans() throws NumberFormatException, TException, PurchaseServiceException {
|
| 5110 |
mandeep.dh |
258 |
boolean areValidScans = true;
|
|
|
259 |
in.shop2020.purchase.PurchaseService.Client purchaseClient = new PurchaseClient().getClient();
|
| 6630 |
amar.kumar |
260 |
//PurchaseOrder purchaseOrder = purchaseClient.getPurchaseOrderForPurchase(Long.parseLong(id));
|
|
|
261 |
PurchaseOrder purchaseOrder = purchaseClient.getPurchaseOrder(poId);
|
| 5110 |
mandeep.dh |
262 |
Map<Long, Long> itemsQuantityMapFromPO = new HashMap<Long, Long>();
|
|
|
263 |
for (in.shop2020.purchase.LineItem lineItem : purchaseOrder.getLineitems()) {
|
|
|
264 |
itemsQuantityMapFromPO.put(lineItem.getItemId(), (long) lineItem.getUnfulfilledQuantity());
|
|
|
265 |
}
|
|
|
266 |
|
|
|
267 |
Client warehouseClient = new WarehouseClient().getClient();
|
|
|
268 |
for (LineItem lineItem : lineItems) {
|
|
|
269 |
if (lineItem.getItem_id() == -1 && lineItem.getItem_number().isEmpty() && lineItem.getSerial_number().isEmpty()) {
|
|
|
270 |
lineItem.setExtra_info(ScanRecordType.BLANK.name());
|
|
|
271 |
}
|
|
|
272 |
else {
|
|
|
273 |
lineItem.setExtra_info(ScanRecordType.VALID.name());
|
| 5496 |
mandeep.dh |
274 |
if (StringUtils.isNotBlank(lineItem.getSerial_number())) {
|
| 5361 |
mandeep.dh |
275 |
try {
|
| 7321 |
amit.gupta |
276 |
InventoryItem inventoryItem = warehouseClient.getInventoryItem(lineItem.getSerial_number());
|
| 8217 |
amar.kumar |
277 |
if(inventoryItem.getLastScanType()!=ScanType.PURCHASE_RETURN && inventoryItem.getLastScanType()!=ScanType.DOA_REPLACED) {
|
| 7321 |
amit.gupta |
278 |
lineItem.setExtra_info("Item scanned already.");
|
|
|
279 |
areValidScans = false;
|
|
|
280 |
continue;
|
|
|
281 |
}
|
| 5496 |
mandeep.dh |
282 |
} catch (Exception e) {
|
| 5361 |
mandeep.dh |
283 |
}
|
| 5110 |
mandeep.dh |
284 |
}
|
|
|
285 |
|
| 5496 |
mandeep.dh |
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");
|
| 5110 |
mandeep.dh |
291 |
areValidScans = false;
|
|
|
292 |
continue;
|
|
|
293 |
}
|
|
|
294 |
|
| 6630 |
amar.kumar |
295 |
if (StringUtils.isBlank(lineItem.getItem_number())) {
|
|
|
296 |
lineItem.setExtra_info("Item number not entered");
|
|
|
297 |
areValidScans = false;
|
|
|
298 |
continue;
|
|
|
299 |
}
|
|
|
300 |
|
| 5110 |
mandeep.dh |
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;
|
| 5361 |
mandeep.dh |
321 |
continue;
|
| 5110 |
mandeep.dh |
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 |
|
| 5361 |
mandeep.dh |
332 |
itemsQuantityMapFromPO.put(lineItem.getItem_id(),
|
|
|
333 |
itemsQuantityMapFromPO.get(lineItem.getItem_id()) - new Double(lineItem.getQuantity()).longValue());
|
| 5110 |
mandeep.dh |
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 |
|
| 6630 |
amar.kumar |
346 |
private void setItemsFromPO() {
|
| 5110 |
mandeep.dh |
347 |
try {
|
|
|
348 |
items = new ArrayList<Item>();
|
|
|
349 |
in.shop2020.purchase.PurchaseService.Client purchaseClient = new PurchaseClient().getClient();
|
| 6630 |
amar.kumar |
350 |
//PurchaseOrder purchaseOrder = purchaseClient.getPurchaseOrderForPurchase(id);
|
|
|
351 |
PurchaseOrder purchaseOrder = purchaseClient.getPurchaseOrder(poId);
|
| 7410 |
amar.kumar |
352 |
warehouseId = purchaseOrder.getWarehouseId();
|
| 5945 |
mandeep.dh |
353 |
in.shop2020.model.v1.catalog.CatalogService.Client catalogClient = new CatalogClient().getClient();
|
| 5361 |
mandeep.dh |
354 |
|
| 5110 |
mandeep.dh |
355 |
for (in.shop2020.purchase.LineItem lineItem : purchaseOrder.getLineitems()) {
|
| 5496 |
mandeep.dh |
356 |
items.add(catalogClient.getItem(lineItem.getItemId()));
|
| 5110 |
mandeep.dh |
357 |
}
|
| 5496 |
mandeep.dh |
358 |
|
| 5945 |
mandeep.dh |
359 |
in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = new InventoryClient().getClient();
|
| 11801 |
manish.sha |
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 |
}
|
| 5110 |
mandeep.dh |
366 |
} catch (Exception e) {
|
|
|
367 |
logger.error("Could not find items in PO with purchase: " + id, e);
|
|
|
368 |
}
|
|
|
369 |
}
|
|
|
370 |
|
| 4687 |
mandeep.dh |
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 |
}
|
| 7410 |
amar.kumar |
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 |
}
|
| 4687 |
mandeep.dh |
435 |
|
| 11801 |
manish.sha |
436 |
/* public boolean canItemCanBeScannedIn(long id) {
|
|
|
437 |
double itemWeight = 0.0;
|
|
|
438 |
try {
|
|
|
439 |
in.shop2020.model.v1.catalog.CatalogService.Client catalogClient = new CatalogClient().getClient();
|
|
|
440 |
Item item = catalogClient.getItem(id);
|
|
|
441 |
itemWeight = item.getWeight();
|
|
|
442 |
} catch (Exception e) {
|
|
|
443 |
logger.error("Could not fetch item to get weight of it ", e);
|
|
|
444 |
}
|
|
|
445 |
if(itemWeight> 0.0){
|
|
|
446 |
return true;
|
|
|
447 |
}
|
|
|
448 |
return false;
|
|
|
449 |
}
|
|
|
450 |
*/
|
| 5110 |
mandeep.dh |
451 |
public String itemNumberMappingEditNew() {
|
|
|
452 |
return "item-number-mapping";
|
|
|
453 |
}
|
|
|
454 |
|
| 4846 |
mandeep.dh |
455 |
public String getName(Item item){
|
|
|
456 |
return ModelUtils.extractProductNameFromItem(item);
|
|
|
457 |
}
|
|
|
458 |
|
| 4687 |
mandeep.dh |
459 |
public void setId(String id) {
|
|
|
460 |
this.id = id;
|
|
|
461 |
}
|
|
|
462 |
|
|
|
463 |
public String getId() {
|
|
|
464 |
return id;
|
|
|
465 |
}
|
|
|
466 |
|
|
|
467 |
public String getErrorMessage() {
|
|
|
468 |
return errorMsg;
|
|
|
469 |
}
|
|
|
470 |
|
|
|
471 |
public String getPurchaseOrderId() {
|
|
|
472 |
return purchaseOrderId;
|
|
|
473 |
}
|
|
|
474 |
|
|
|
475 |
public String getServletContextPath() {
|
|
|
476 |
return context.getContextPath();
|
|
|
477 |
}
|
|
|
478 |
|
|
|
479 |
public String getItemId() {
|
|
|
480 |
return itemId;
|
|
|
481 |
}
|
|
|
482 |
|
|
|
483 |
public void setItemId(String itemId) {
|
|
|
484 |
this.itemId = itemId;
|
|
|
485 |
}
|
|
|
486 |
|
|
|
487 |
public String getItemNo() {
|
|
|
488 |
return itemNo;
|
|
|
489 |
}
|
|
|
490 |
|
|
|
491 |
public void setItemNo(String itemNo) {
|
|
|
492 |
this.itemNo = itemNo;
|
|
|
493 |
}
|
|
|
494 |
|
| 4846 |
mandeep.dh |
495 |
public List<Item> getItems() {
|
|
|
496 |
return items;
|
|
|
497 |
}
|
|
|
498 |
|
|
|
499 |
public void setItems(List<Item> items) {
|
|
|
500 |
this.items = items;
|
|
|
501 |
}
|
|
|
502 |
|
| 5110 |
mandeep.dh |
503 |
public List<LineItem> getLineItems() {
|
|
|
504 |
return lineItems;
|
|
|
505 |
}
|
|
|
506 |
|
|
|
507 |
public void setLineItems(List<LineItem> lineItems) {
|
|
|
508 |
this.lineItems = lineItems;
|
|
|
509 |
}
|
|
|
510 |
|
|
|
511 |
public Warehouse getWarehouse() {
|
|
|
512 |
return warehouse;
|
|
|
513 |
}
|
| 5496 |
mandeep.dh |
514 |
|
|
|
515 |
public List<Invoice> getInvoices() {
|
|
|
516 |
return invoices;
|
|
|
517 |
}
|
|
|
518 |
|
|
|
519 |
public void setInvoices(List<Invoice> invoices) {
|
|
|
520 |
this.invoices = invoices;
|
|
|
521 |
}
|
| 6630 |
amar.kumar |
522 |
|
|
|
523 |
public String getInvoiceNumber() {
|
|
|
524 |
return invoiceNumber;
|
|
|
525 |
}
|
|
|
526 |
|
|
|
527 |
public void setInvoiceNumber(String invoiceNumber) {
|
|
|
528 |
this.invoiceNumber = invoiceNumber;
|
|
|
529 |
}
|
|
|
530 |
|
|
|
531 |
public Double getFreightCharges() {
|
|
|
532 |
return freightCharges;
|
|
|
533 |
}
|
|
|
534 |
|
|
|
535 |
public void setFreightCharges(Double freightCharges) {
|
|
|
536 |
this.freightCharges = freightCharges;
|
|
|
537 |
}
|
|
|
538 |
|
|
|
539 |
public Long getPoId() {
|
|
|
540 |
return poId;
|
|
|
541 |
}
|
|
|
542 |
|
|
|
543 |
public void setPoId(Long poId) {
|
|
|
544 |
this.poId = poId;
|
|
|
545 |
}
|
| 7410 |
amar.kumar |
546 |
|
|
|
547 |
public Long getWarehouseId() {
|
|
|
548 |
return warehouseId;
|
|
|
549 |
}
|
|
|
550 |
|
|
|
551 |
public void setWarehouseId(Long warehouseId) {
|
|
|
552 |
this.warehouseId = warehouseId;
|
|
|
553 |
}
|
|
|
554 |
|
|
|
555 |
public Long getTransferWarehouseId() {
|
|
|
556 |
return transferWarehouseId;
|
|
|
557 |
}
|
|
|
558 |
|
|
|
559 |
public void setTransferWarehouseId(Long transferWarehouseId) {
|
|
|
560 |
this.transferWarehouseId = transferWarehouseId;
|
|
|
561 |
}
|
| 7441 |
amar.kumar |
562 |
|
|
|
563 |
public Long getTransferLotId() {
|
|
|
564 |
return transferLotId;
|
|
|
565 |
}
|
|
|
566 |
|
|
|
567 |
public void setTransferLotId(Long transferLotId) {
|
|
|
568 |
this.transferLotId = transferLotId;
|
|
|
569 |
}
|
| 11801 |
manish.sha |
570 |
|
|
|
571 |
public String getPurchaseComments() {
|
|
|
572 |
return purchaseComments;
|
|
|
573 |
}
|
|
|
574 |
|
|
|
575 |
public void setPurchaseComments(String purchaseComments) {
|
|
|
576 |
this.purchaseComments = purchaseComments;
|
|
|
577 |
}
|
|
|
578 |
|
|
|
579 |
public Warehouse getThirdPartyWarehouse() {
|
|
|
580 |
return thirdPartyWarehouse;
|
|
|
581 |
}
|
|
|
582 |
|
|
|
583 |
public void setThirdPartyWarehouse(Warehouse thirdPartyWarehouse) {
|
|
|
584 |
this.thirdPartyWarehouse = thirdPartyWarehouse;
|
|
|
585 |
}
|
| 7441 |
amar.kumar |
586 |
|
| 4687 |
mandeep.dh |
587 |
}
|