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