| 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")
|
| 25112 |
amit.gupta |
43 |
@Results({
|
|
|
44 |
@Result(name = "redirect", type = "redirectAction", params = { "actionName", "warehouse" }),
|
|
|
45 |
@Result(name = "redirectPoShow", type = "redirectAction", params = { "actionName", "purchase-order/${poId}"})
|
|
|
46 |
})
|
| 4687 |
mandeep.dh |
47 |
public class PurchaseController extends BaseController {
|
| 25112 |
amit.gupta |
48 |
/**
|
|
|
49 |
*
|
|
|
50 |
*/
|
|
|
51 |
private static final int NUM_BULK__SCAN_ITEMS = 10;
|
|
|
52 |
private static Logger logger = LoggerFactory.getLogger(PurchaseController.class);
|
| 4687 |
mandeep.dh |
53 |
|
| 25112 |
amit.gupta |
54 |
public static enum ScanRecordType {
|
|
|
55 |
VALID, BLANK
|
|
|
56 |
};
|
| 4687 |
mandeep.dh |
57 |
|
| 25112 |
amit.gupta |
58 |
private static final long DUMMY_VENDOR_ID = 40;
|
| 4687 |
mandeep.dh |
59 |
|
| 25112 |
amit.gupta |
60 |
private ServletContext context;
|
|
|
61 |
private String id;
|
|
|
62 |
private Long transferLotId;
|
|
|
63 |
private String itemId;
|
|
|
64 |
private String itemNo;
|
|
|
65 |
private double invoicePrice;
|
| 5496 |
mandeep.dh |
66 |
|
| 25112 |
amit.gupta |
67 |
public double getInvoicePrice() {
|
|
|
68 |
return invoicePrice;
|
|
|
69 |
}
|
| 5496 |
mandeep.dh |
70 |
|
| 25112 |
amit.gupta |
71 |
public void setInvoicePrice(double invoicePrice) {
|
|
|
72 |
this.invoicePrice = invoicePrice;
|
|
|
73 |
}
|
| 4687 |
mandeep.dh |
74 |
|
| 25112 |
amit.gupta |
75 |
private String errorMsg = "";
|
|
|
76 |
private List<Item> items;
|
|
|
77 |
private List<LineItem> lineItems;
|
|
|
78 |
private List<Invoice> invoices;
|
| 5496 |
mandeep.dh |
79 |
|
| 25112 |
amit.gupta |
80 |
private String invoiceNumber;
|
|
|
81 |
private Double freightCharges;
|
|
|
82 |
private Long poId;
|
|
|
83 |
private String purchaseComments;
|
| 4687 |
mandeep.dh |
84 |
|
| 25112 |
amit.gupta |
85 |
private String purchaseOrderId;
|
|
|
86 |
private Long warehouseId;
|
|
|
87 |
private Long transferWarehouseId;
|
|
|
88 |
private Warehouse warehouse;
|
|
|
89 |
private Warehouse thirdPartyWarehouse;
|
| 4687 |
mandeep.dh |
90 |
|
| 25112 |
amit.gupta |
91 |
public String editNew() {
|
|
|
92 |
purchaseOrderId = request.getParameter("poId");
|
| 4687 |
mandeep.dh |
93 |
|
| 25112 |
amit.gupta |
94 |
try {
|
|
|
95 |
in.shop2020.purchase.PurchaseService.Client purchaseClient = new PurchaseClient().getClient();
|
|
|
96 |
// invoices = purchaseClient.getInvoices(getPreviousDay(getPreviousDay(new
|
|
|
97 |
// Date())).getTime());
|
|
|
98 |
PurchaseOrder po = purchaseClient.getPurchaseOrder(Long.parseLong(purchaseOrderId));
|
|
|
99 |
invoices = purchaseClient.getInvoicesForWarehouse(po.getWarehouseId(), po.getSupplierId(),
|
|
|
100 |
getPreviousDay(getPreviousDay(new Date())).getTime());
|
|
|
101 |
} catch (Exception e) {
|
|
|
102 |
logger.error("Error loading invoices", e);
|
|
|
103 |
}
|
| 5110 |
mandeep.dh |
104 |
|
| 25112 |
amit.gupta |
105 |
return "new";
|
|
|
106 |
}
|
| 5110 |
mandeep.dh |
107 |
|
| 25112 |
amit.gupta |
108 |
private Date getPreviousDay(Date date) {
|
|
|
109 |
Calendar calendar = Calendar.getInstance();
|
|
|
110 |
calendar.setTime(date);
|
|
|
111 |
calendar.add(Calendar.DAY_OF_MONTH, -1);
|
|
|
112 |
return calendar.getTime();
|
|
|
113 |
}
|
| 6630 |
amar.kumar |
114 |
|
| 25112 |
amit.gupta |
115 |
public String create() {
|
|
|
116 |
this.purchaseOrderId = request.getParameter("poId");
|
|
|
117 |
poId = Long.parseLong(purchaseOrderId);
|
|
|
118 |
invoiceNumber = request.getParameter("invoiceNo");
|
|
|
119 |
if (invoiceNumber.endsWith(",")) {
|
|
|
120 |
addActionError("Invoice Number should not end with Comma");
|
|
|
121 |
return "show";
|
|
|
122 |
}
|
|
|
123 |
String fc = request.getParameter("freightCharges").trim();
|
|
|
124 |
freightCharges = 0D;
|
|
|
125 |
id = "0";
|
|
|
126 |
if (fc != null && !fc.isEmpty())
|
|
|
127 |
freightCharges = Double.parseDouble(fc);
|
|
|
128 |
return show();
|
|
|
129 |
// return "create";
|
| 4687 |
mandeep.dh |
130 |
|
| 25112 |
amit.gupta |
131 |
}
|
| 5110 |
mandeep.dh |
132 |
|
| 25112 |
amit.gupta |
133 |
public String show() {
|
|
|
134 |
resetLineItems();
|
|
|
135 |
setItemsFromPO();
|
|
|
136 |
return SHOW;
|
|
|
137 |
}
|
| 5110 |
mandeep.dh |
138 |
|
| 25112 |
amit.gupta |
139 |
private void resetLineItems() {
|
|
|
140 |
lineItems = new ArrayList<LineItem>();
|
|
|
141 |
|
|
|
142 |
for (int i = 0; i < NUM_BULK__SCAN_ITEMS; i++) {
|
|
|
143 |
LineItem lineItem = new LineItem();
|
|
|
144 |
lineItem.setId(i);
|
|
|
145 |
lineItem.setExtra_info("");
|
|
|
146 |
lineItem.setSerial_number("");
|
|
|
147 |
lineItem.setItem_number("");
|
|
|
148 |
lineItem.setQuantity(1);
|
|
|
149 |
lineItem.setItem_id(-1);
|
|
|
150 |
lineItems.add(lineItem);
|
|
|
151 |
}
|
|
|
152 |
}
|
|
|
153 |
|
|
|
154 |
public boolean createPurchase() {
|
|
|
155 |
try {
|
|
|
156 |
logger.info("poId=" + poId + " invoiceNumber=" + invoiceNumber + " freightCharges=" + freightCharges
|
|
|
157 |
+ " purchaseComments= " + purchaseComments);
|
|
|
158 |
PurchaseClient purchaseClient = new PurchaseClient();
|
|
|
159 |
in.shop2020.purchase.PurchaseService.Client client = purchaseClient.getClient();
|
|
|
160 |
id = "" + client.startPurchase(poId, invoiceNumber, freightCharges, purchaseComments);
|
|
|
161 |
logger.info("id = " + id);
|
|
|
162 |
} catch (TTransportException e) {
|
|
|
163 |
errorMsg = "Error while establishing connection to the warehouse server";
|
|
|
164 |
logger.error(errorMsg, e);
|
|
|
165 |
} catch (TException e) {
|
|
|
166 |
errorMsg = "Error while scanning in the item";
|
|
|
167 |
logger.error(errorMsg, e);
|
|
|
168 |
} catch (PurchaseServiceException e) {
|
|
|
169 |
errorMsg = e.getMessage();
|
|
|
170 |
logger.error(errorMsg, e);
|
|
|
171 |
}
|
|
|
172 |
|
|
|
173 |
if (errorMsg.isEmpty())
|
|
|
174 |
return true;
|
|
|
175 |
else {
|
|
|
176 |
addActionError(errorMsg);
|
|
|
177 |
return false;
|
|
|
178 |
}
|
|
|
179 |
}
|
|
|
180 |
|
|
|
181 |
public String update() {
|
|
|
182 |
setItemsFromPO();
|
|
|
183 |
|
|
|
184 |
try {
|
|
|
185 |
if (!areValidScans()) {
|
|
|
186 |
return SHOW;
|
|
|
187 |
}
|
|
|
188 |
if (id == null || Long.parseLong(id) == 0) {
|
|
|
189 |
if (!createPurchase()) {
|
|
|
190 |
return "new";
|
| 11801 |
manish.sha |
191 |
}
|
| 25112 |
amit.gupta |
192 |
}
|
| 5110 |
mandeep.dh |
193 |
|
| 25112 |
amit.gupta |
194 |
WarehouseClient warehouseClient = new WarehouseClient();
|
|
|
195 |
Client client = warehouseClient.getClient();
|
|
|
196 |
in.shop2020.purchase.PurchaseService.Client purchaseClient = new PurchaseClient().getClient();
|
|
|
197 |
PurchaseOrder po = purchaseClient.getPurchaseOrder(poId);
|
|
|
198 |
InventoryService.Client inventoryClient = new InventoryClient().getClient();
|
|
|
199 |
if (transferLotId == null || transferLotId == 0) {
|
|
|
200 |
if (transferWarehouseId != null && transferWarehouseId != 0) {
|
|
|
201 |
Warehouse fulfilmentWarehouse = inventoryClient.getWarehouses(WarehouseType.OURS,
|
|
|
202 |
InventoryType.GOOD, po.getSupplierId(), po.getWarehouseId(), 0L).get(0);
|
|
|
203 |
transferLotId = client.createTransferLot(po.getWarehouseId(), transferWarehouseId);
|
|
|
204 |
}
|
|
|
205 |
}
|
|
|
206 |
boolean checkDirectScanWarehouse = false;
|
| 5110 |
mandeep.dh |
207 |
|
| 25112 |
amit.gupta |
208 |
if (thirdPartyWarehouse.getVendor().getId() == DUMMY_VENDOR_ID
|
|
|
209 |
&& thirdPartyWarehouse.getInventoryType() == InventoryType.GOOD
|
|
|
210 |
&& thirdPartyWarehouse.getWarehouseType() == WarehouseType.OURS_THIRDPARTY) {
|
|
|
211 |
checkDirectScanWarehouse = true;
|
|
|
212 |
}
|
| 4846 |
mandeep.dh |
213 |
|
| 25112 |
amit.gupta |
214 |
long currentWarehouseId = 0;
|
|
|
215 |
if (!checkDirectScanWarehouse) {
|
|
|
216 |
Warehouse fulfilmentWarehouse = inventoryClient.getWarehouses(WarehouseType.OURS, InventoryType.GOOD,
|
|
|
217 |
po.getSupplierId(), po.getWarehouseId(), 0).get(0);
|
|
|
218 |
currentWarehouseId = fulfilmentWarehouse.getId();
|
|
|
219 |
}
|
| 4687 |
mandeep.dh |
220 |
|
| 25112 |
amit.gupta |
221 |
for (LineItem lineItem : lineItems) {
|
|
|
222 |
if (ScanRecordType.BLANK.name().equals(lineItem.getExtra_info())) {
|
|
|
223 |
continue;
|
|
|
224 |
}
|
| 5110 |
mandeep.dh |
225 |
|
| 25112 |
amit.gupta |
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 |
}
|
| 5110 |
mandeep.dh |
244 |
|
| 25112 |
amit.gupta |
245 |
if (!client.isAlive()) {
|
|
|
246 |
client = warehouseClient.getClient();
|
|
|
247 |
}
|
|
|
248 |
client.scan(inventoryItem, ScanType.PURCHASE, new Double(lineItem.getQuantity()).longValue(),
|
|
|
249 |
warehouseId, (transferLotId != null) ? transferLotId : 0L);
|
|
|
250 |
}
|
| 5110 |
mandeep.dh |
251 |
|
| 25112 |
amit.gupta |
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);
|
|
|
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 |
}
|
| 5110 |
mandeep.dh |
266 |
|
| 25112 |
amit.gupta |
267 |
if (!errorMsg.isEmpty()) {
|
|
|
268 |
addActionError(errorMsg);
|
|
|
269 |
}
|
| 5110 |
mandeep.dh |
270 |
|
| 25112 |
amit.gupta |
271 |
return SHOW;
|
|
|
272 |
}
|
| 5110 |
mandeep.dh |
273 |
|
| 25112 |
amit.gupta |
274 |
/**
|
|
|
275 |
* @return
|
|
|
276 |
* @throws TException
|
|
|
277 |
* @throws NumberFormatException
|
|
|
278 |
* @throws PurchaseServiceException
|
|
|
279 |
*/
|
|
|
280 |
private boolean areValidScans() throws NumberFormatException, TException, PurchaseServiceException {
|
|
|
281 |
boolean areValidScans = true;
|
|
|
282 |
in.shop2020.purchase.PurchaseService.Client purchaseClient = new PurchaseClient().getClient();
|
|
|
283 |
// PurchaseOrder purchaseOrder =
|
|
|
284 |
// purchaseClient.getPurchaseOrderForPurchase(Long.parseLong(id));
|
|
|
285 |
PurchaseOrder purchaseOrder = purchaseClient.getPurchaseOrder(poId);
|
|
|
286 |
Map<Long, Long> itemsQuantityMapFromPO = new HashMap<Long, Long>();
|
|
|
287 |
for (in.shop2020.purchase.LineItem lineItem : purchaseOrder.getLineitems()) {
|
|
|
288 |
itemsQuantityMapFromPO.put(lineItem.getItemId(), (long) lineItem.getUnfulfilledQuantity());
|
|
|
289 |
}
|
| 5110 |
mandeep.dh |
290 |
|
| 25112 |
amit.gupta |
291 |
Client warehouseClient = new WarehouseClient().getClient();
|
|
|
292 |
for (LineItem lineItem : lineItems) {
|
|
|
293 |
if (lineItem.getItem_id() == -1 && lineItem.getItem_number().isEmpty()
|
|
|
294 |
&& lineItem.getSerial_number().isEmpty()) {
|
|
|
295 |
lineItem.setExtra_info(ScanRecordType.BLANK.name());
|
|
|
296 |
} else {
|
|
|
297 |
lineItem.setExtra_info(ScanRecordType.VALID.name());
|
|
|
298 |
if (StringUtils.isNotBlank(lineItem.getSerial_number())) {
|
|
|
299 |
try {
|
|
|
300 |
InventoryItem inventoryItem = warehouseClient.getInventoryItem(lineItem.getSerial_number());
|
|
|
301 |
if (inventoryItem.getLastScanType() != ScanType.PURCHASE_RETURN
|
|
|
302 |
&& inventoryItem.getLastScanType() != ScanType.DOA_REPLACED) {
|
|
|
303 |
lineItem.setExtra_info("Item scanned already.");
|
|
|
304 |
areValidScans = false;
|
|
|
305 |
continue;
|
|
|
306 |
}
|
|
|
307 |
} catch (Exception e) {
|
|
|
308 |
}
|
|
|
309 |
}
|
| 5110 |
mandeep.dh |
310 |
|
| 25112 |
amit.gupta |
311 |
if (lineItem.getItem_id() == -1 && (StringUtils.isBlank(lineItem.getItem_number())
|
|
|
312 |
|| StringUtils.isBlank(lineItem.getSerial_number()))) {
|
|
|
313 |
lineItem.setExtra_info("Item not selected/Item or serial number not present");
|
|
|
314 |
areValidScans = false;
|
|
|
315 |
continue;
|
|
|
316 |
}
|
| 5110 |
mandeep.dh |
317 |
|
| 25112 |
amit.gupta |
318 |
if (StringUtils.isBlank(lineItem.getItem_number())) {
|
|
|
319 |
lineItem.setExtra_info("Item number not entered");
|
|
|
320 |
areValidScans = false;
|
|
|
321 |
continue;
|
|
|
322 |
}
|
| 5361 |
mandeep.dh |
323 |
|
| 25112 |
amit.gupta |
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 |
}
|
| 5496 |
mandeep.dh |
331 |
|
| 25112 |
amit.gupta |
332 |
if (itemIds.size() > 0) {
|
|
|
333 |
int numItemsInPO = 0;
|
|
|
334 |
for (long itemId : itemIds) {
|
|
|
335 |
if (itemsQuantityMapFromPO.containsKey(itemId)) {
|
|
|
336 |
numItemsInPO++;
|
|
|
337 |
lineItem.setItem_id(itemId);
|
|
|
338 |
}
|
|
|
339 |
}
|
| 5110 |
mandeep.dh |
340 |
|
| 25112 |
amit.gupta |
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 |
}
|
| 4687 |
mandeep.dh |
349 |
|
| 25112 |
amit.gupta |
350 |
if (!itemsQuantityMapFromPO.containsKey(lineItem.getItem_id())) {
|
|
|
351 |
lineItem.setExtra_info("Item not present in PO.");
|
|
|
352 |
areValidScans = false;
|
|
|
353 |
continue;
|
|
|
354 |
}
|
| 4687 |
mandeep.dh |
355 |
|
| 25112 |
amit.gupta |
356 |
itemsQuantityMapFromPO.put(lineItem.getItem_id(), itemsQuantityMapFromPO.get(lineItem.getItem_id())
|
|
|
357 |
- new Double(lineItem.getQuantity()).longValue());
|
| 4687 |
mandeep.dh |
358 |
|
| 25112 |
amit.gupta |
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 |
}
|
| 4687 |
mandeep.dh |
366 |
|
| 25112 |
amit.gupta |
367 |
return areValidScans;
|
|
|
368 |
}
|
| 4687 |
mandeep.dh |
369 |
|
| 25112 |
amit.gupta |
370 |
private void setItemsFromPO() {
|
| 11801 |
manish.sha |
371 |
try {
|
| 25112 |
amit.gupta |
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();
|
| 11801 |
manish.sha |
377 |
in.shop2020.model.v1.catalog.CatalogService.Client catalogClient = new CatalogClient().getClient();
|
| 25112 |
amit.gupta |
378 |
|
|
|
379 |
for (in.shop2020.purchase.LineItem lineItem : purchaseOrder.getLineitems()) {
|
|
|
380 |
if(lineItem.getInvoicePrice() > 0) {
|
|
|
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) {
|
|
|
390 |
warehouse = thirdPartyWarehouse;
|
|
|
391 |
} else {
|
|
|
392 |
warehouse = inventoryClient.getWarehouses(WarehouseType.OURS, InventoryType.GOOD,
|
|
|
393 |
purchaseOrder.getSupplierId(), warehouseId, warehouseId).get(0);
|
|
|
394 |
}
|
| 11801 |
manish.sha |
395 |
} catch (Exception e) {
|
| 25112 |
amit.gupta |
396 |
logger.error("Could not find items in PO with purchase: " + id, e);
|
| 11801 |
manish.sha |
397 |
}
|
| 25112 |
amit.gupta |
398 |
}
|
|
|
399 |
|
|
|
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);
|
| 11801 |
manish.sha |
416 |
}
|
| 25112 |
amit.gupta |
417 |
return "redirect";
|
| 11801 |
manish.sha |
418 |
}
|
| 5110 |
mandeep.dh |
419 |
|
| 25112 |
amit.gupta |
420 |
public String createItemNumberMapping() throws Exception {
|
|
|
421 |
long itemIdLong = Long.parseLong(itemId);
|
| 4846 |
mandeep.dh |
422 |
|
| 25112 |
amit.gupta |
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 |
}
|
| 4687 |
mandeep.dh |
431 |
|
| 25112 |
amit.gupta |
432 |
return show();
|
|
|
433 |
}
|
| 4687 |
mandeep.dh |
434 |
|
| 25112 |
amit.gupta |
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");
|
|
|
440 |
return OUTPUT;
|
|
|
441 |
}
|
| 4687 |
mandeep.dh |
442 |
|
| 25112 |
amit.gupta |
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 |
*/
|
| 4687 |
mandeep.dh |
452 |
|
| 25112 |
amit.gupta |
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>();
|
|
|
467 |
}
|
|
|
468 |
}
|
| 4687 |
mandeep.dh |
469 |
|
| 25112 |
amit.gupta |
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; }
|
|
|
477 |
*/
|
|
|
478 |
public String itemNumberMappingEditNew() {
|
|
|
479 |
return "item-number-mapping";
|
|
|
480 |
}
|
| 4687 |
mandeep.dh |
481 |
|
| 25112 |
amit.gupta |
482 |
public String getName(Item item) {
|
|
|
483 |
return ModelUtils.extractProductNameFromItem(item);
|
|
|
484 |
}
|
| 4687 |
mandeep.dh |
485 |
|
| 25112 |
amit.gupta |
486 |
public void setId(String id) {
|
|
|
487 |
this.id = id;
|
|
|
488 |
}
|
| 4687 |
mandeep.dh |
489 |
|
| 25112 |
amit.gupta |
490 |
public String getId() {
|
|
|
491 |
return id;
|
|
|
492 |
}
|
| 4687 |
mandeep.dh |
493 |
|
| 25112 |
amit.gupta |
494 |
public String getErrorMessage() {
|
|
|
495 |
return errorMsg;
|
|
|
496 |
}
|
| 4846 |
mandeep.dh |
497 |
|
| 25112 |
amit.gupta |
498 |
public String getPurchaseOrderId() {
|
|
|
499 |
return purchaseOrderId;
|
|
|
500 |
}
|
| 4846 |
mandeep.dh |
501 |
|
| 25112 |
amit.gupta |
502 |
public String getServletContextPath() {
|
|
|
503 |
return context.getContextPath();
|
|
|
504 |
}
|
| 5110 |
mandeep.dh |
505 |
|
| 25112 |
amit.gupta |
506 |
public String getItemId() {
|
|
|
507 |
return itemId;
|
|
|
508 |
}
|
| 5110 |
mandeep.dh |
509 |
|
| 25112 |
amit.gupta |
510 |
public void setItemId(String itemId) {
|
|
|
511 |
this.itemId = itemId;
|
|
|
512 |
}
|
| 5496 |
mandeep.dh |
513 |
|
| 25112 |
amit.gupta |
514 |
public String getItemNo() {
|
|
|
515 |
return itemNo;
|
|
|
516 |
}
|
| 5496 |
mandeep.dh |
517 |
|
| 25112 |
amit.gupta |
518 |
public void setItemNo(String itemNo) {
|
|
|
519 |
this.itemNo = itemNo;
|
|
|
520 |
}
|
| 6630 |
amar.kumar |
521 |
|
| 25112 |
amit.gupta |
522 |
public List<Item> getItems() {
|
|
|
523 |
return items;
|
|
|
524 |
}
|
|
|
525 |
|
|
|
526 |
public void setItems(List<Item> items) {
|
|
|
527 |
this.items = items;
|
|
|
528 |
}
|
|
|
529 |
|
|
|
530 |
public List<LineItem> getLineItems() {
|
|
|
531 |
return lineItems;
|
|
|
532 |
}
|
|
|
533 |
|
|
|
534 |
public void setLineItems(List<LineItem> lineItems) {
|
|
|
535 |
this.lineItems = lineItems;
|
|
|
536 |
}
|
|
|
537 |
|
|
|
538 |
public Warehouse getWarehouse() {
|
|
|
539 |
return warehouse;
|
|
|
540 |
}
|
|
|
541 |
|
|
|
542 |
public List<Invoice> getInvoices() {
|
|
|
543 |
return invoices;
|
|
|
544 |
}
|
|
|
545 |
|
|
|
546 |
public void setInvoices(List<Invoice> invoices) {
|
|
|
547 |
this.invoices = invoices;
|
|
|
548 |
}
|
|
|
549 |
|
| 6630 |
amar.kumar |
550 |
public String getInvoiceNumber() {
|
|
|
551 |
return invoiceNumber;
|
|
|
552 |
}
|
|
|
553 |
|
|
|
554 |
public void setInvoiceNumber(String invoiceNumber) {
|
|
|
555 |
this.invoiceNumber = invoiceNumber;
|
|
|
556 |
}
|
|
|
557 |
|
|
|
558 |
public Double getFreightCharges() {
|
|
|
559 |
return freightCharges;
|
|
|
560 |
}
|
|
|
561 |
|
|
|
562 |
public void setFreightCharges(Double freightCharges) {
|
|
|
563 |
this.freightCharges = freightCharges;
|
|
|
564 |
}
|
|
|
565 |
|
|
|
566 |
public Long getPoId() {
|
|
|
567 |
return poId;
|
|
|
568 |
}
|
|
|
569 |
|
|
|
570 |
public void setPoId(Long poId) {
|
|
|
571 |
this.poId = poId;
|
|
|
572 |
}
|
| 7410 |
amar.kumar |
573 |
|
|
|
574 |
public Long getWarehouseId() {
|
|
|
575 |
return warehouseId;
|
|
|
576 |
}
|
|
|
577 |
|
|
|
578 |
public void setWarehouseId(Long warehouseId) {
|
|
|
579 |
this.warehouseId = warehouseId;
|
|
|
580 |
}
|
|
|
581 |
|
|
|
582 |
public Long getTransferWarehouseId() {
|
|
|
583 |
return transferWarehouseId;
|
|
|
584 |
}
|
|
|
585 |
|
|
|
586 |
public void setTransferWarehouseId(Long transferWarehouseId) {
|
|
|
587 |
this.transferWarehouseId = transferWarehouseId;
|
|
|
588 |
}
|
| 7441 |
amar.kumar |
589 |
|
|
|
590 |
public Long getTransferLotId() {
|
|
|
591 |
return transferLotId;
|
|
|
592 |
}
|
|
|
593 |
|
|
|
594 |
public void setTransferLotId(Long transferLotId) {
|
|
|
595 |
this.transferLotId = transferLotId;
|
|
|
596 |
}
|
| 11801 |
manish.sha |
597 |
|
|
|
598 |
public String getPurchaseComments() {
|
|
|
599 |
return purchaseComments;
|
|
|
600 |
}
|
|
|
601 |
|
|
|
602 |
public void setPurchaseComments(String purchaseComments) {
|
|
|
603 |
this.purchaseComments = purchaseComments;
|
|
|
604 |
}
|
|
|
605 |
|
|
|
606 |
public Warehouse getThirdPartyWarehouse() {
|
|
|
607 |
return thirdPartyWarehouse;
|
|
|
608 |
}
|
|
|
609 |
|
|
|
610 |
public void setThirdPartyWarehouse(Warehouse thirdPartyWarehouse) {
|
|
|
611 |
this.thirdPartyWarehouse = thirdPartyWarehouse;
|
|
|
612 |
}
|
| 25112 |
amit.gupta |
613 |
|
| 4687 |
mandeep.dh |
614 |
}
|