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