| 11349 |
manish.sha |
1 |
package in.shop2020.inventory.controllers;
|
|
|
2 |
|
|
|
3 |
import in.shop2020.model.v1.catalog.Item;
|
|
|
4 |
import in.shop2020.model.v1.catalog.ItemType;
|
|
|
5 |
import in.shop2020.model.v1.inventory.InventoryService;
|
|
|
6 |
import in.shop2020.model.v1.inventory.InventoryType;
|
|
|
7 |
import in.shop2020.model.v1.inventory.Warehouse;
|
|
|
8 |
import in.shop2020.model.v1.inventory.WarehouseType;
|
|
|
9 |
import in.shop2020.model.v1.order.LineItem;
|
|
|
10 |
import in.shop2020.purchase.Invoice;
|
|
|
11 |
import in.shop2020.purchase.PurchaseOrder;
|
|
|
12 |
import in.shop2020.purchase.PurchaseServiceException;
|
|
|
13 |
import in.shop2020.thrift.clients.CatalogClient;
|
|
|
14 |
import in.shop2020.thrift.clients.InventoryClient;
|
|
|
15 |
import in.shop2020.thrift.clients.PurchaseClient;
|
|
|
16 |
import in.shop2020.thrift.clients.WarehouseClient;
|
|
|
17 |
import in.shop2020.utils.ModelUtils;
|
|
|
18 |
import in.shop2020.warehouse.InventoryItem;
|
|
|
19 |
import in.shop2020.warehouse.ScanType;
|
|
|
20 |
import in.shop2020.warehouse.WarehouseService;
|
|
|
21 |
import in.shop2020.warehouse.WarehouseService.Client;
|
|
|
22 |
|
|
|
23 |
import java.io.BufferedInputStream;
|
|
|
24 |
import java.io.BufferedReader;
|
|
|
25 |
import java.io.BufferedWriter;
|
|
|
26 |
import java.io.File;
|
|
|
27 |
import java.io.FileInputStream;
|
|
|
28 |
import java.io.FileReader;
|
|
|
29 |
import java.io.FileWriter;
|
|
|
30 |
import java.io.IOException;
|
|
|
31 |
import java.io.InputStream;
|
|
|
32 |
import java.util.ArrayList;
|
|
|
33 |
import java.util.HashMap;
|
|
|
34 |
import java.util.List;
|
|
|
35 |
import java.util.Map;
|
|
|
36 |
|
|
|
37 |
import javax.servlet.ServletContext;
|
|
|
38 |
import javax.servlet.ServletOutputStream;
|
|
|
39 |
|
|
|
40 |
import org.apache.commons.io.FileUtils;
|
|
|
41 |
import org.apache.commons.lang.StringUtils;
|
|
|
42 |
import org.apache.struts2.convention.annotation.Result;
|
|
|
43 |
import org.apache.struts2.convention.annotation.Results;
|
|
|
44 |
import org.apache.thrift.TException;
|
|
|
45 |
import org.apache.thrift.transport.TTransportException;
|
|
|
46 |
import org.slf4j.Logger;
|
|
|
47 |
import org.slf4j.LoggerFactory;
|
|
|
48 |
|
|
|
49 |
@SuppressWarnings("serial")
|
|
|
50 |
@Results({ @Result(name = "redirect", type = "redirectAction", params = {
|
|
|
51 |
"actionName", "warehouse" }) })
|
|
|
52 |
public class BulkPurchaseController extends BaseController {
|
|
|
53 |
private static Logger logger = LoggerFactory.getLogger(BulkPurchaseController.class);
|
|
|
54 |
private List<String> exceptionList = new ArrayList<String>();
|
|
|
55 |
private static final int NUM_BULK__SCAN_ITEMS = 10;
|
| 11801 |
manish.sha |
56 |
private static final long DUMMY_VENDOR_ID = 40;
|
| 11349 |
manish.sha |
57 |
|
|
|
58 |
private ServletContext context;
|
|
|
59 |
private String id="";
|
|
|
60 |
private Long transferLotId;
|
|
|
61 |
private String itemId;
|
|
|
62 |
private String itemNo;
|
|
|
63 |
private String errorMsg = "";
|
|
|
64 |
private String successMsg = "";
|
|
|
65 |
private List<Item> items;
|
|
|
66 |
private List<LineItem> lineItems;
|
|
|
67 |
private String bulkScanUploadItem;
|
| 18668 |
manish.sha |
68 |
private String selectItemType;
|
| 11349 |
manish.sha |
69 |
private File scanDataFile;
|
|
|
70 |
|
|
|
71 |
private String invoiceNumber;
|
|
|
72 |
private Double freightCharges ;
|
| 11801 |
manish.sha |
73 |
private String purchaseComments;
|
| 11349 |
manish.sha |
74 |
private Long poId;
|
|
|
75 |
private String fileNameVal;
|
|
|
76 |
|
|
|
77 |
private String purchaseId;
|
|
|
78 |
private String purchaseOrderId;
|
|
|
79 |
private Long warehouseId;
|
|
|
80 |
private Long transferWarehouseId;
|
|
|
81 |
private Warehouse warehouse;
|
| 11801 |
manish.sha |
82 |
private Warehouse thirdPartyWarehouse;
|
| 11349 |
manish.sha |
83 |
|
|
|
84 |
private Map<Long, Double> unfulfilledMap = new HashMap<Long, Double>();
|
| 18668 |
manish.sha |
85 |
private Map<Long, Item> nonserializedMap = new HashMap<Long, Item>();
|
|
|
86 |
private Map<Long, Item> serializedMap = new HashMap<Long, Item>();
|
| 11349 |
manish.sha |
87 |
|
|
|
88 |
|
| 18668 |
manish.sha |
89 |
|
| 11349 |
manish.sha |
90 |
public String show() {
|
|
|
91 |
resetLineItems();
|
|
|
92 |
setItemsFromPO();
|
|
|
93 |
return SHOW;
|
|
|
94 |
}
|
|
|
95 |
|
|
|
96 |
private void resetLineItems() {
|
|
|
97 |
lineItems = new ArrayList<LineItem>();
|
|
|
98 |
|
|
|
99 |
for (int i = 0; i < NUM_BULK__SCAN_ITEMS; i++) {
|
|
|
100 |
LineItem lineItem = new LineItem();
|
|
|
101 |
lineItem.setId(i);
|
|
|
102 |
lineItem.setExtra_info("");
|
|
|
103 |
lineItem.setSerial_number("");
|
|
|
104 |
lineItem.setItem_number("");
|
|
|
105 |
lineItem.setQuantity(1);
|
|
|
106 |
lineItem.setItem_id(-1);
|
|
|
107 |
lineItems.add(lineItem);
|
|
|
108 |
}
|
|
|
109 |
}
|
|
|
110 |
|
|
|
111 |
public String create() {
|
|
|
112 |
this.purchaseOrderId = request.getParameter("poId");
|
|
|
113 |
poId = Long.parseLong(purchaseOrderId);
|
|
|
114 |
invoiceNumber = request.getParameter("invoiceNumber");
|
|
|
115 |
String fc = request.getParameter("freightCharges").trim();
|
|
|
116 |
freightCharges = 0D;
|
|
|
117 |
if(id == null ||StringUtils.isEmpty(id))
|
|
|
118 |
id = "0";
|
|
|
119 |
if (fc != null && !fc.isEmpty())
|
|
|
120 |
freightCharges = Double.parseDouble(fc);
|
|
|
121 |
return show();
|
|
|
122 |
//return "create";
|
|
|
123 |
|
|
|
124 |
}
|
|
|
125 |
|
|
|
126 |
public boolean createPurchase(){
|
|
|
127 |
try {
|
| 11801 |
manish.sha |
128 |
logger.info("poId="+poId+" invoiceNumber="+invoiceNumber+" freightCharges="+freightCharges+ " purchaseComments="+purchaseComments);
|
| 11349 |
manish.sha |
129 |
PurchaseClient purchaseClient = new PurchaseClient();
|
|
|
130 |
in.shop2020.purchase.PurchaseService.Client client = purchaseClient
|
|
|
131 |
.getClient();
|
| 11801 |
manish.sha |
132 |
id = "" + client.startPurchase(poId, invoiceNumber, freightCharges, purchaseComments);
|
| 11349 |
manish.sha |
133 |
logger.info("id = "+id);
|
|
|
134 |
} catch (TTransportException e) {
|
|
|
135 |
errorMsg = errorMsg + "<br> Error while establishing connection to the warehouse server";
|
|
|
136 |
exceptionList.add("Error while establishing connection to the warehouse server");
|
|
|
137 |
logger.error(errorMsg, e);
|
|
|
138 |
} catch (TException e) {
|
|
|
139 |
errorMsg = errorMsg+ "<br> Error while scanning in the item";
|
|
|
140 |
exceptionList.add("Error while strating purchase");
|
|
|
141 |
logger.error(errorMsg, e);
|
|
|
142 |
} catch (PurchaseServiceException e) {
|
|
|
143 |
errorMsg = errorMsg+ e.getMessage();
|
|
|
144 |
exceptionList.add(e.getMessage());
|
|
|
145 |
logger.error(errorMsg, e);
|
|
|
146 |
}
|
|
|
147 |
|
|
|
148 |
if (errorMsg.isEmpty())
|
|
|
149 |
return true;
|
|
|
150 |
else {
|
|
|
151 |
addActionError(errorMsg);
|
|
|
152 |
return false;
|
|
|
153 |
}
|
|
|
154 |
}
|
|
|
155 |
|
|
|
156 |
public File getScanFileToRead(){
|
|
|
157 |
File fileToCreate = null;
|
|
|
158 |
|
|
|
159 |
if(scanDataFile!=null & fileNameVal !=null && !fileNameVal.isEmpty()){
|
|
|
160 |
|
|
|
161 |
logger.info("File Name "+scanDataFile.getName());
|
|
|
162 |
System.out.println("File Name "+scanDataFile.getName());
|
|
|
163 |
|
|
|
164 |
logger.info("File Name Value "+fileNameVal);
|
|
|
165 |
System.out.println("File Name Value "+fileNameVal);
|
|
|
166 |
String fileName = fileNameVal;
|
|
|
167 |
try {
|
|
|
168 |
if(!fileName.substring(fileName.lastIndexOf(".")+1).equalsIgnoreCase("txt")){
|
|
|
169 |
throw new Exception("File is not in expected TXT Format");
|
|
|
170 |
}
|
|
|
171 |
fileToCreate = new File("/tmp/", fileName);
|
|
|
172 |
|
|
|
173 |
FileUtils.copyFile(this.scanDataFile, fileToCreate);
|
|
|
174 |
} catch (Exception e) {
|
|
|
175 |
logger.error("Error while writing file used to the local file system", e);
|
|
|
176 |
errorMsg = e.getMessage();
|
|
|
177 |
//addActionError(errorMsg);
|
|
|
178 |
return null;
|
|
|
179 |
}
|
|
|
180 |
} else {
|
|
|
181 |
errorMsg = errorMsg + "<br>Either No File Uploaded or file name is blank";
|
|
|
182 |
}
|
|
|
183 |
return fileToCreate;
|
|
|
184 |
}
|
|
|
185 |
|
|
|
186 |
public boolean transferLotCreate(PurchaseOrder po){
|
|
|
187 |
String errMsg = "";
|
|
|
188 |
try{
|
|
|
189 |
if(transferLotId==null || transferLotId==0) {
|
|
|
190 |
if(transferWarehouseId!=null && transferWarehouseId!=0) {
|
|
|
191 |
WarehouseClient warehouseClient = new WarehouseClient();
|
|
|
192 |
Client client = warehouseClient.getClient();
|
|
|
193 |
InventoryService.Client inventoryClient = new InventoryClient().getClient();
|
|
|
194 |
Warehouse fulfilmentWarehouse = inventoryClient.getWarehouses(WarehouseType.OURS, InventoryType.GOOD, po.getSupplierId(), po.getWarehouseId(), 0L).get(0);
|
|
|
195 |
transferLotId = client.createTransferLot(po.getWarehouseId(), transferWarehouseId);
|
|
|
196 |
}
|
|
|
197 |
}
|
|
|
198 |
} catch(Exception e){
|
|
|
199 |
errMsg = "<br> Error while creating Transfer Lot due to : "+ e.getMessage();
|
|
|
200 |
}
|
|
|
201 |
if (errMsg.isEmpty()){
|
|
|
202 |
return true;
|
|
|
203 |
}
|
|
|
204 |
else {
|
|
|
205 |
errorMsg = errMsg;
|
|
|
206 |
addActionError(errorMsg);
|
|
|
207 |
return false;
|
|
|
208 |
}
|
|
|
209 |
}
|
|
|
210 |
|
|
|
211 |
public File createErrorFile(List<String> errorList){
|
|
|
212 |
try{
|
|
|
213 |
String tmpDir = System.getProperty("java.io.tmpdir");
|
|
|
214 |
File file = new File(tmpDir + "/ScanRecordResult.xls");
|
|
|
215 |
BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(
|
|
|
216 |
file));
|
|
|
217 |
bufferedWriter.write(StringUtils.join(new String[] { "----Scan Response----"}, '\t'));
|
|
|
218 |
//bufferedWriter.newLine();
|
|
|
219 |
for(String record : errorList){
|
|
|
220 |
bufferedWriter.newLine();
|
|
|
221 |
bufferedWriter.write(StringUtils.join(new String[] { record }, '\t'));
|
|
|
222 |
}
|
|
|
223 |
bufferedWriter.close();
|
|
|
224 |
return file;
|
|
|
225 |
} catch (Exception e) {
|
|
|
226 |
logger.error("Could not create file for Scan Record Result", e);
|
|
|
227 |
return null;
|
|
|
228 |
}
|
|
|
229 |
}
|
|
|
230 |
|
|
|
231 |
public void setResponseErrorFile(File errorFile) throws IOException{
|
|
|
232 |
byte[] buffer = null;
|
|
|
233 |
buffer = new byte[(int) errorFile.length()];
|
|
|
234 |
InputStream input = null;
|
|
|
235 |
try {
|
|
|
236 |
int totalBytesRead = 0;
|
|
|
237 |
input = new BufferedInputStream(new FileInputStream(errorFile));
|
|
|
238 |
while (totalBytesRead < buffer.length) {
|
|
|
239 |
int bytesRemaining = buffer.length - totalBytesRead;
|
|
|
240 |
// input.read() returns -1, 0, or more :
|
|
|
241 |
int bytesRead = input.read(buffer, totalBytesRead,
|
|
|
242 |
bytesRemaining);
|
|
|
243 |
if (bytesRead > 0) {
|
|
|
244 |
totalBytesRead = totalBytesRead + bytesRead;
|
|
|
245 |
}
|
|
|
246 |
}
|
|
|
247 |
/*
|
|
|
248 |
* the above style is a bit tricky: it places bytes into the
|
|
|
249 |
* 'buffer' array; 'buffer' is an output parameter; the while
|
|
|
250 |
* loop usually has a single iteration only.
|
|
|
251 |
*/
|
|
|
252 |
} finally {
|
|
|
253 |
input.close();
|
|
|
254 |
}
|
|
|
255 |
|
|
|
256 |
response.setContentType("application/vnd.ms-excel");
|
|
|
257 |
response.setHeader("Content-disposition", "inline; filename="
|
|
|
258 |
+ errorFile.getName());
|
|
|
259 |
|
|
|
260 |
ServletOutputStream sos = response.getOutputStream();
|
|
|
261 |
sos.write(buffer);
|
|
|
262 |
sos.flush();
|
|
|
263 |
}
|
|
|
264 |
|
|
|
265 |
public boolean checkForException() throws IOException{
|
|
|
266 |
if(exceptionList!=null && exceptionList.size()>0){
|
|
|
267 |
File errorFile = createErrorFile(exceptionList);
|
|
|
268 |
if(errorFile.isFile()){
|
|
|
269 |
setResponseErrorFile(errorFile);
|
|
|
270 |
return false;
|
|
|
271 |
}
|
|
|
272 |
}
|
|
|
273 |
return true;
|
|
|
274 |
}
|
|
|
275 |
|
|
|
276 |
private void areValidSerializedItems() throws Exception {
|
|
|
277 |
Client warehouseClient = new WarehouseClient().getClient();
|
|
|
278 |
for (LineItem lineItem : lineItems) {
|
|
|
279 |
if (StringUtils.isNotBlank(lineItem.getSerial_number())) {
|
|
|
280 |
InventoryItem inventoryItem = new InventoryItem();
|
|
|
281 |
try{
|
|
|
282 |
inventoryItem = warehouseClient.getInventoryItem(lineItem.getSerial_number());
|
|
|
283 |
} catch(Exception e){
|
|
|
284 |
continue;
|
|
|
285 |
}
|
|
|
286 |
if(inventoryItem.getLastScanType()!=ScanType.PURCHASE_RETURN && inventoryItem.getLastScanType()!=ScanType.DOA_REPLACED) {
|
|
|
287 |
lineItem.setExtra_info("Item scanned already.");
|
|
|
288 |
exceptionList.add("Items Scanned already : "+ lineItem.getSerial_number());
|
|
|
289 |
continue;
|
|
|
290 |
}
|
|
|
291 |
}
|
|
|
292 |
}
|
|
|
293 |
}
|
|
|
294 |
|
|
|
295 |
private void setItemsFromPO() {
|
|
|
296 |
try {
|
|
|
297 |
items = new ArrayList<Item>();
|
|
|
298 |
in.shop2020.purchase.PurchaseService.Client purchaseClient = new PurchaseClient().getClient();
|
|
|
299 |
//PurchaseOrder purchaseOrder = purchaseClient.getPurchaseOrderForPurchase(id);
|
|
|
300 |
PurchaseOrder purchaseOrder = purchaseClient.getPurchaseOrder(poId);
|
|
|
301 |
warehouseId = purchaseOrder.getWarehouseId();
|
|
|
302 |
in.shop2020.model.v1.catalog.CatalogService.Client catalogClient = new CatalogClient().getClient();
|
|
|
303 |
|
|
|
304 |
for (in.shop2020.purchase.LineItem lineItem : purchaseOrder.getLineitems()) {
|
| 18668 |
manish.sha |
305 |
Item it = catalogClient.getItem(lineItem.getItemId());
|
|
|
306 |
if(it.getType()==ItemType.SERIALIZED){
|
|
|
307 |
serializedMap.put(it.getId(), it);
|
|
|
308 |
}else{
|
|
|
309 |
nonserializedMap.put(it.getId(), it);
|
|
|
310 |
}
|
|
|
311 |
items.add(it);
|
| 11349 |
manish.sha |
312 |
unfulfilledMap.put(lineItem.getItemId(), lineItem.getUnfulfilledQuantity());
|
|
|
313 |
}
|
|
|
314 |
|
|
|
315 |
in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = new InventoryClient().getClient();
|
| 11801 |
manish.sha |
316 |
thirdPartyWarehouse = inventoryClient.getWarehouse(warehouseId);
|
|
|
317 |
if(thirdPartyWarehouse.getVendor().getId()==DUMMY_VENDOR_ID && thirdPartyWarehouse.getInventoryType()==InventoryType.GOOD && thirdPartyWarehouse.getWarehouseType()==WarehouseType.OURS_THIRDPARTY){
|
|
|
318 |
warehouse = thirdPartyWarehouse;
|
|
|
319 |
} else {
|
|
|
320 |
warehouse = inventoryClient.getWarehouses(WarehouseType.OURS, InventoryType.GOOD, purchaseOrder.getSupplierId(), warehouseId, warehouseId).get(0);
|
|
|
321 |
}
|
| 11349 |
manish.sha |
322 |
} catch (Exception e) {
|
|
|
323 |
logger.error("Could not find items in PO with purchase: " + id, e);
|
|
|
324 |
}
|
|
|
325 |
}
|
|
|
326 |
|
|
|
327 |
public String update() {
|
| 18668 |
manish.sha |
328 |
if(selectItemType.equalsIgnoreCase("SERIALIZED")){
|
|
|
329 |
if(("-1").equalsIgnoreCase(bulkScanUploadItem)){
|
|
|
330 |
errorMsg = errorMsg +" <br> No Item Selected to Scan In";
|
|
|
331 |
return show();
|
|
|
332 |
}
|
| 11349 |
manish.sha |
333 |
}
|
|
|
334 |
|
|
|
335 |
File fileToCreate = getScanFileToRead();
|
|
|
336 |
Map<Long, String> correctRowsMap = new HashMap<Long, String>();
|
|
|
337 |
Map<Long, String> errorRowsMap = new HashMap<Long, String>();
|
|
|
338 |
|
|
|
339 |
if(fileToCreate==null){
|
|
|
340 |
errorMsg = errorMsg +" <br> No File to read";
|
|
|
341 |
return create();
|
|
|
342 |
}
|
|
|
343 |
|
|
|
344 |
ItemType itemType = ItemType.SERIALIZED;
|
|
|
345 |
setItemsFromPO();
|
|
|
346 |
lineItems = new ArrayList<LineItem>();
|
| 18668 |
manish.sha |
347 |
|
| 11349 |
manish.sha |
348 |
if(fileToCreate.isFile()){
|
| 18668 |
manish.sha |
349 |
|
|
|
350 |
try {
|
| 11349 |
manish.sha |
351 |
in.shop2020.purchase.PurchaseService.Client purchaseClient = new PurchaseClient().getClient();
|
|
|
352 |
PurchaseOrder po = purchaseClient.getPurchaseOrder(poId);
|
|
|
353 |
List<in.shop2020.purchase.LineItem> poLineItems = po.getLineitems();
|
|
|
354 |
in.shop2020.purchase.LineItem poLineItem = new in.shop2020.purchase.LineItem();
|
|
|
355 |
|
|
|
356 |
if(!transferLotCreate(po)){
|
|
|
357 |
return create();
|
|
|
358 |
}
|
| 18668 |
manish.sha |
359 |
|
|
|
360 |
if(selectItemType.equalsIgnoreCase("SERIALIZED")){
|
|
|
361 |
Item item = serializedMap.get(Long.parseLong(bulkScanUploadItem));
|
|
|
362 |
itemType = item.getType();
|
|
|
363 |
|
|
|
364 |
for(in.shop2020.purchase.LineItem pItem : poLineItems){
|
|
|
365 |
if(pItem.getItemId() == item.getId()){
|
|
|
366 |
poLineItem = pItem;
|
|
|
367 |
break;
|
| 11349 |
manish.sha |
368 |
}
|
|
|
369 |
}
|
| 18668 |
manish.sha |
370 |
|
|
|
371 |
BufferedReader br = new BufferedReader(new FileReader(fileToCreate));
|
|
|
372 |
long line = 1;
|
|
|
373 |
String strLine;
|
|
|
374 |
String[] values;
|
|
|
375 |
while((strLine = br.readLine())!=null){
|
| 18681 |
manish.sha |
376 |
if(strLine.trim().isEmpty()){
|
|
|
377 |
continue;
|
|
|
378 |
}
|
| 18668 |
manish.sha |
379 |
if(line==1){
|
|
|
380 |
values = strLine.split("\t");
|
|
|
381 |
if(values.length !=3){
|
|
|
382 |
errorMsg = errorMsg + "<br> File contains Inappropriate Content ";
|
|
|
383 |
addActionError(errorMsg);
|
|
|
384 |
return create();
|
| 11349 |
manish.sha |
385 |
}
|
| 18668 |
manish.sha |
386 |
line++;
|
|
|
387 |
continue;
|
|
|
388 |
}
|
|
|
389 |
values = strLine.split("\t");
|
|
|
390 |
for(String s : values){
|
|
|
391 |
logger.info("Row No "+line+" :"+s);
|
|
|
392 |
System.out.println("Row No "+line+" :"+s);
|
|
|
393 |
}
|
|
|
394 |
LineItem lineItem = new LineItem();
|
|
|
395 |
lineItem.setId(line);
|
|
|
396 |
lineItem.setItem_id(item.getId());
|
|
|
397 |
lineItem.setBrand(item.getBrand());
|
|
|
398 |
lineItem.setColor(item.getColor());
|
|
|
399 |
lineItem.setModel_name(item.getModelName());
|
|
|
400 |
lineItem.setModel_number(item.getModelNumber());
|
|
|
401 |
lineItem.setProductGroup(item.getProductGroup());
|
|
|
402 |
lineItem.setNlc(poLineItem.getNlc());
|
|
|
403 |
lineItem.setTransfer_price(poLineItem.getUnitPrice());
|
|
|
404 |
lineItem.setUnit_price(poLineItem.getUnitPrice());
|
|
|
405 |
if(itemType==ItemType.SERIALIZED){
|
|
|
406 |
if(StringUtils.isNotBlank(values[0]) && StringUtils.isNotEmpty(values[0])){
|
|
|
407 |
if(StringUtils.isNotBlank(values[1]) && StringUtils.isNotEmpty(values[1])){
|
|
|
408 |
lineItem.setItem_number(values[0].trim());
|
|
|
409 |
lineItem.setSerial_number(values[1].trim());
|
|
|
410 |
lineItem.setQuantity(1);
|
|
|
411 |
correctRowsMap.put(line, "Entries are correct in the row");
|
|
|
412 |
}
|
|
|
413 |
else{
|
|
|
414 |
errorRowsMap.put(line, "Error: Serial Number Missing ");
|
|
|
415 |
line++;
|
|
|
416 |
continue;
|
|
|
417 |
}
|
|
|
418 |
}
|
| 11349 |
manish.sha |
419 |
else{
|
| 18668 |
manish.sha |
420 |
errorRowsMap.put(line, "Error: Item Number Missing ");
|
| 11349 |
manish.sha |
421 |
line++;
|
|
|
422 |
continue;
|
|
|
423 |
}
|
|
|
424 |
}
|
| 18668 |
manish.sha |
425 |
|
|
|
426 |
if(correctRowsMap.containsKey(line) && !errorRowsMap.containsKey(line)){
|
|
|
427 |
lineItems.add(lineItem);
|
|
|
428 |
}
|
|
|
429 |
|
|
|
430 |
line++;
|
|
|
431 |
}
|
|
|
432 |
|
|
|
433 |
areValidSerializedItems();
|
|
|
434 |
|
|
|
435 |
}else{
|
|
|
436 |
|
|
|
437 |
BufferedReader br = new BufferedReader(new FileReader(fileToCreate));
|
|
|
438 |
long line = 1;
|
|
|
439 |
String strLine;
|
|
|
440 |
String[] values;
|
|
|
441 |
while((strLine = br.readLine())!=null){
|
| 18681 |
manish.sha |
442 |
if(strLine.trim().isEmpty()){
|
|
|
443 |
continue;
|
|
|
444 |
}
|
| 18668 |
manish.sha |
445 |
if(line==1){
|
|
|
446 |
values = strLine.split("\t");
|
|
|
447 |
if(values.length !=4){
|
|
|
448 |
errorMsg = errorMsg + "<br> File contains Inappropriate Content ";
|
|
|
449 |
addActionError(errorMsg);
|
|
|
450 |
return create();
|
|
|
451 |
}
|
| 11349 |
manish.sha |
452 |
line++;
|
|
|
453 |
continue;
|
|
|
454 |
}
|
| 18668 |
manish.sha |
455 |
values = strLine.split("\t");
|
|
|
456 |
for(String s : values){
|
|
|
457 |
logger.info("Row No "+line+" :"+s);
|
|
|
458 |
System.out.println("Row No "+line+" :"+s);
|
|
|
459 |
}
|
|
|
460 |
Item item = nonserializedMap.get(Long.parseLong(values[0]));
|
|
|
461 |
itemType = item.getType();
|
|
|
462 |
|
|
|
463 |
for(in.shop2020.purchase.LineItem pItem : poLineItems){
|
|
|
464 |
if(pItem.getItemId() == item.getId()){
|
|
|
465 |
poLineItem = pItem;
|
|
|
466 |
break;
|
|
|
467 |
}
|
|
|
468 |
}
|
|
|
469 |
LineItem lineItem = new LineItem();
|
|
|
470 |
lineItem.setId(line);
|
|
|
471 |
lineItem.setItem_id(item.getId());
|
|
|
472 |
lineItem.setBrand(item.getBrand());
|
|
|
473 |
lineItem.setColor(item.getColor());
|
|
|
474 |
lineItem.setModel_name(item.getModelName());
|
|
|
475 |
lineItem.setModel_number(item.getModelNumber());
|
|
|
476 |
lineItem.setProductGroup(item.getProductGroup());
|
|
|
477 |
lineItem.setNlc(poLineItem.getNlc());
|
|
|
478 |
lineItem.setTransfer_price(poLineItem.getUnitPrice());
|
|
|
479 |
lineItem.setUnit_price(poLineItem.getUnitPrice());
|
| 11349 |
manish.sha |
480 |
|
| 18668 |
manish.sha |
481 |
if(itemType==ItemType.NON_SERIALIZED){
|
|
|
482 |
if(StringUtils.isNotBlank(values[1]) && StringUtils.isNotEmpty(values[1])){
|
|
|
483 |
lineItem.setItem_number(values[1].trim());
|
|
|
484 |
lineItem.setSerial_number("");
|
|
|
485 |
if(StringUtils.isNotBlank(values[3]) && StringUtils.isNumeric(values[3]) && Double.parseDouble(values[3]) > 0){
|
|
|
486 |
lineItem.setQuantity(Double.parseDouble(values[3].trim()));
|
|
|
487 |
correctRowsMap.put(line, "Entries are correct in the row ");
|
|
|
488 |
}
|
|
|
489 |
else{
|
|
|
490 |
errorRowsMap.put(line, "Error: Invalid Item Quantity ");
|
|
|
491 |
line++;
|
|
|
492 |
continue;
|
|
|
493 |
}
|
|
|
494 |
} else{
|
|
|
495 |
errorRowsMap.put(line, "Error: Item Number Missing ");
|
| 11349 |
manish.sha |
496 |
line++;
|
|
|
497 |
continue;
|
|
|
498 |
}
|
| 18668 |
manish.sha |
499 |
|
| 11349 |
manish.sha |
500 |
}
|
|
|
501 |
|
| 18668 |
manish.sha |
502 |
if(correctRowsMap.containsKey(line) && !errorRowsMap.containsKey(line)){
|
|
|
503 |
lineItems.add(lineItem);
|
|
|
504 |
}
|
| 11349 |
manish.sha |
505 |
|
| 18668 |
manish.sha |
506 |
line++;
|
| 11349 |
manish.sha |
507 |
}
|
|
|
508 |
}
|
| 18668 |
manish.sha |
509 |
|
| 11349 |
manish.sha |
510 |
if(correctRowsMap!=null && correctRowsMap.size()>0){
|
|
|
511 |
if(errorRowsMap!=null && errorRowsMap.size()>0){
|
|
|
512 |
for(Long row : errorRowsMap.keySet()){
|
|
|
513 |
exceptionList.add("At Row "+ row +" "+ errorRowsMap.get(row));
|
|
|
514 |
}
|
|
|
515 |
}
|
|
|
516 |
}
|
|
|
517 |
else{
|
|
|
518 |
exceptionList.add("-- File Contains Zero Correct Records --");
|
|
|
519 |
if(errorRowsMap!=null && errorRowsMap.size()>0){
|
|
|
520 |
exceptionList.add("-- Data in uploaded sheet is Inappropriate --");
|
|
|
521 |
}
|
|
|
522 |
}
|
|
|
523 |
|
|
|
524 |
if(id == null || Long.parseLong(id)==0) {
|
|
|
525 |
if(!createPurchase()) {
|
|
|
526 |
if(!checkForException()){
|
|
|
527 |
return create();
|
|
|
528 |
}
|
|
|
529 |
}
|
| 18668 |
manish.sha |
530 |
}
|
|
|
531 |
|
| 11349 |
manish.sha |
532 |
WarehouseClient warehouseClient = new WarehouseClient();
|
|
|
533 |
Client client = warehouseClient.getClient();
|
| 16490 |
manish.sha |
534 |
InventoryService.Client inventoryClient = new InventoryClient().getClient();
|
| 11801 |
manish.sha |
535 |
boolean checkDirectScanWarehouse = false;
|
|
|
536 |
|
|
|
537 |
if(thirdPartyWarehouse.getVendor().getId()==DUMMY_VENDOR_ID && thirdPartyWarehouse.getInventoryType()==InventoryType.GOOD && thirdPartyWarehouse.getWarehouseType()==WarehouseType.OURS_THIRDPARTY){
|
|
|
538 |
checkDirectScanWarehouse = true;
|
|
|
539 |
}
|
| 16490 |
manish.sha |
540 |
|
|
|
541 |
long currentWarehouseId = 0;
|
|
|
542 |
if(!checkDirectScanWarehouse){
|
|
|
543 |
Warehouse fulfilmentWarehouse = inventoryClient.getWarehouses(WarehouseType.OURS, InventoryType.GOOD, po.getSupplierId(), po.getWarehouseId(), 0).get(0);
|
|
|
544 |
currentWarehouseId = fulfilmentWarehouse.getId();
|
|
|
545 |
}
|
| 11801 |
manish.sha |
546 |
|
| 11349 |
manish.sha |
547 |
for (LineItem lineItem : lineItems) {
|
|
|
548 |
|
|
|
549 |
InventoryItem inventoryItem = new InventoryItem();
|
|
|
550 |
inventoryItem.setItemId(lineItem.getItem_id());
|
|
|
551 |
inventoryItem.setPurchaseId(Long.parseLong(id));
|
|
|
552 |
inventoryItem.setCurrentQuantity(0);
|
|
|
553 |
inventoryItem.setItemNumber(lineItem.getItem_number());
|
|
|
554 |
inventoryItem.setSerialNumber(lineItem.getSerial_number());
|
|
|
555 |
inventoryItem.setInitialQuantity(new Double(lineItem.getQuantity()).longValue());
|
| 11801 |
manish.sha |
556 |
if(checkDirectScanWarehouse){
|
|
|
557 |
inventoryItem.setPhysicalWarehouseId(po.getWarehouseId());
|
|
|
558 |
inventoryItem.setCurrentWarehouseId(po.getWarehouseId());
|
|
|
559 |
}else{
|
|
|
560 |
inventoryItem.setPhysicalWarehouseId(po.getWarehouseId());
|
| 16490 |
manish.sha |
561 |
inventoryItem.setCurrentWarehouseId(currentWarehouseId);
|
| 11801 |
manish.sha |
562 |
}
|
| 11349 |
manish.sha |
563 |
if(!client.isAlive()){
|
|
|
564 |
client = warehouseClient.getClient();
|
|
|
565 |
}
|
|
|
566 |
try{
|
| 18668 |
manish.sha |
567 |
if(lineItem.getSerial_number()!=null && !lineItem.getSerial_number().isEmpty()){
|
| 13089 |
manish.sha |
568 |
if(lineItem.getExtra_info()!=null && "Item scanned already.".equalsIgnoreCase(lineItem.getExtra_info())){
|
|
|
569 |
continue;
|
|
|
570 |
}
|
|
|
571 |
}
|
| 11349 |
manish.sha |
572 |
client.scan(inventoryItem, ScanType.PURCHASE, new Double(lineItem.getQuantity()).longValue(), warehouseId, (transferLotId!=null)?transferLotId:0L);
|
|
|
573 |
if(lineItem.getSerial_number()!=null && !lineItem.getSerial_number().isEmpty()){
|
|
|
574 |
exceptionList.add("Item with Serial Number "+ lineItem.getSerial_number() + " Scanned Successfully");
|
|
|
575 |
}
|
|
|
576 |
else{
|
|
|
577 |
exceptionList.add("Item with Item Number "+ lineItem.getItem_number() + " with "+ lineItem.getQuantity() + " units Scanned Successfully");
|
|
|
578 |
}
|
|
|
579 |
}
|
|
|
580 |
catch(Exception e){
|
|
|
581 |
exceptionList.add("Error "+lineItem.getId()+" "+e.getMessage());
|
|
|
582 |
continue;
|
|
|
583 |
}
|
|
|
584 |
}
|
|
|
585 |
|
|
|
586 |
if(lineItems!= null && lineItems.size()!=exceptionList.size()){
|
|
|
587 |
if(!checkForException()){
|
|
|
588 |
return null;
|
|
|
589 |
}
|
|
|
590 |
}else{
|
|
|
591 |
successMsg = "Items scanned Successfully.<br>Check the unfulfilled Quantity for further details";
|
|
|
592 |
}
|
| 18668 |
manish.sha |
593 |
|
|
|
594 |
} catch (Exception e) {
|
| 11349 |
manish.sha |
595 |
errorMsg = errorMsg + " <br> Error while scanning items";
|
|
|
596 |
logger.error(errorMsg, e);
|
| 18668 |
manish.sha |
597 |
e.printStackTrace();
|
| 11349 |
manish.sha |
598 |
}
|
|
|
599 |
}
|
|
|
600 |
return create();
|
|
|
601 |
}
|
|
|
602 |
|
|
|
603 |
public String destroy() {
|
|
|
604 |
long id = Long.parseLong(this.id);
|
|
|
605 |
|
|
|
606 |
try {
|
|
|
607 |
PurchaseClient warehouseClient = new PurchaseClient();
|
|
|
608 |
in.shop2020.purchase.PurchaseService.Client client = warehouseClient
|
|
|
609 |
.getClient();
|
|
|
610 |
client.closePurchase(id);
|
|
|
611 |
} catch (TTransportException e) {
|
|
|
612 |
errorMsg = errorMsg + "<br> Error while establishing connection to the warehouse server";
|
|
|
613 |
logger.error(errorMsg, e);
|
|
|
614 |
} catch (TException e) {
|
|
|
615 |
errorMsg = errorMsg + "<br> Error while scanning in the item";
|
|
|
616 |
logger.error(errorMsg, e);
|
|
|
617 |
} catch (PurchaseServiceException e) {
|
|
|
618 |
errorMsg = errorMsg + e.getMessage();
|
|
|
619 |
logger.error(errorMsg, e);
|
|
|
620 |
}
|
|
|
621 |
return "redirect";
|
|
|
622 |
}
|
|
|
623 |
|
|
|
624 |
public List<Warehouse> getAllowedDestinationWarehousesForTransfer(long originWarehouseId){
|
|
|
625 |
try {
|
|
|
626 |
WarehouseService.Client warehouseClient = new WarehouseClient().getClient();
|
|
|
627 |
List<Long> allowedWarehouseIds = warehouseClient.getAllowedDestinationWarehousesForTransfer(originWarehouseId);
|
|
|
628 |
List<Warehouse> allowedWarehouses = new ArrayList<Warehouse>();
|
|
|
629 |
InventoryService.Client inventoryClient = new InventoryClient().getClient();
|
|
|
630 |
for(Long allowedWarehouseId : allowedWarehouseIds) {
|
|
|
631 |
allowedWarehouses.add(inventoryClient.getWarehouse(allowedWarehouseId));
|
|
|
632 |
}
|
|
|
633 |
return allowedWarehouses;
|
|
|
634 |
} catch(Exception e) {
|
|
|
635 |
logger.error("Error while getting all destination warehouses for warehouseId " + warehouseId, e);
|
|
|
636 |
return new ArrayList<Warehouse>();
|
|
|
637 |
}
|
|
|
638 |
}
|
|
|
639 |
|
|
|
640 |
public boolean isItemScannedIn(long id){
|
|
|
641 |
if(unfulfilledMap.get(id)> 0){
|
|
|
642 |
return true;
|
|
|
643 |
}
|
|
|
644 |
return false;
|
|
|
645 |
}
|
|
|
646 |
|
|
|
647 |
public String getName(Item item){
|
|
|
648 |
return ModelUtils.extractProductNameFromItem(item);
|
|
|
649 |
}
|
|
|
650 |
|
|
|
651 |
public void setId(String id) {
|
|
|
652 |
this.id = id;
|
|
|
653 |
}
|
|
|
654 |
|
|
|
655 |
public String getId() {
|
|
|
656 |
return id;
|
|
|
657 |
}
|
|
|
658 |
|
|
|
659 |
public String getErrorMessage() {
|
|
|
660 |
return errorMsg;
|
|
|
661 |
}
|
|
|
662 |
|
|
|
663 |
public String getPurchaseOrderId() {
|
|
|
664 |
return purchaseOrderId;
|
|
|
665 |
}
|
|
|
666 |
|
|
|
667 |
public String getServletContextPath() {
|
|
|
668 |
return context.getContextPath();
|
|
|
669 |
}
|
|
|
670 |
|
|
|
671 |
public String getItemId() {
|
|
|
672 |
return itemId;
|
|
|
673 |
}
|
|
|
674 |
|
|
|
675 |
public void setItemId(String itemId) {
|
|
|
676 |
this.itemId = itemId;
|
|
|
677 |
}
|
|
|
678 |
|
|
|
679 |
public String getItemNo() {
|
|
|
680 |
return itemNo;
|
|
|
681 |
}
|
|
|
682 |
|
|
|
683 |
public void setItemNo(String itemNo) {
|
|
|
684 |
this.itemNo = itemNo;
|
|
|
685 |
}
|
|
|
686 |
|
|
|
687 |
public List<Item> getItems() {
|
|
|
688 |
return items;
|
|
|
689 |
}
|
|
|
690 |
|
|
|
691 |
public void setItems(List<Item> items) {
|
|
|
692 |
this.items = items;
|
|
|
693 |
}
|
|
|
694 |
|
|
|
695 |
public List<LineItem> getLineItems() {
|
|
|
696 |
return lineItems;
|
|
|
697 |
}
|
|
|
698 |
|
|
|
699 |
public void setLineItems(List<LineItem> lineItems) {
|
|
|
700 |
this.lineItems = lineItems;
|
|
|
701 |
}
|
|
|
702 |
|
|
|
703 |
public Warehouse getWarehouse() {
|
|
|
704 |
return warehouse;
|
|
|
705 |
}
|
|
|
706 |
|
|
|
707 |
public String getInvoiceNumber() {
|
|
|
708 |
return invoiceNumber;
|
|
|
709 |
}
|
|
|
710 |
|
|
|
711 |
public void setInvoiceNumber(String invoiceNumber) {
|
|
|
712 |
this.invoiceNumber = invoiceNumber;
|
|
|
713 |
}
|
|
|
714 |
|
|
|
715 |
public Double getFreightCharges() {
|
|
|
716 |
return freightCharges;
|
|
|
717 |
}
|
|
|
718 |
|
|
|
719 |
public void setFreightCharges(Double freightCharges) {
|
|
|
720 |
this.freightCharges = freightCharges;
|
|
|
721 |
}
|
|
|
722 |
|
|
|
723 |
public Long getPoId() {
|
|
|
724 |
return poId;
|
|
|
725 |
}
|
|
|
726 |
|
|
|
727 |
public void setPoId(Long poId) {
|
|
|
728 |
this.poId = poId;
|
|
|
729 |
}
|
|
|
730 |
|
|
|
731 |
public Long getWarehouseId() {
|
|
|
732 |
return warehouseId;
|
|
|
733 |
}
|
|
|
734 |
|
|
|
735 |
public void setWarehouseId(Long warehouseId) {
|
|
|
736 |
this.warehouseId = warehouseId;
|
|
|
737 |
}
|
|
|
738 |
|
|
|
739 |
public Long getTransferWarehouseId() {
|
|
|
740 |
return transferWarehouseId;
|
|
|
741 |
}
|
|
|
742 |
|
|
|
743 |
public void setTransferWarehouseId(Long transferWarehouseId) {
|
|
|
744 |
this.transferWarehouseId = transferWarehouseId;
|
|
|
745 |
}
|
|
|
746 |
|
|
|
747 |
public Long getTransferLotId() {
|
|
|
748 |
return transferLotId;
|
|
|
749 |
}
|
|
|
750 |
|
|
|
751 |
public void setTransferLotId(Long transferLotId) {
|
|
|
752 |
this.transferLotId = transferLotId;
|
|
|
753 |
}
|
|
|
754 |
|
|
|
755 |
public String getBulkScanUploadItem() {
|
|
|
756 |
return bulkScanUploadItem;
|
|
|
757 |
}
|
|
|
758 |
|
|
|
759 |
public void setBulkScanUploadItem(String bulkScanUploadItem) {
|
|
|
760 |
this.bulkScanUploadItem = bulkScanUploadItem;
|
|
|
761 |
}
|
|
|
762 |
|
| 18679 |
manish.sha |
763 |
public String getSelectItemType() {
|
|
|
764 |
return selectItemType;
|
|
|
765 |
}
|
|
|
766 |
|
|
|
767 |
public void setSelectItemType(String selectItemType) {
|
|
|
768 |
this.selectItemType = selectItemType;
|
|
|
769 |
}
|
|
|
770 |
|
| 11349 |
manish.sha |
771 |
public File getScanDataFile() {
|
|
|
772 |
return scanDataFile;
|
|
|
773 |
}
|
|
|
774 |
|
|
|
775 |
public void setScanDataFile(File scanDataFile) {
|
|
|
776 |
this.scanDataFile = scanDataFile;
|
|
|
777 |
}
|
|
|
778 |
|
|
|
779 |
public String getPurchaseId() {
|
|
|
780 |
return purchaseId;
|
|
|
781 |
}
|
|
|
782 |
|
|
|
783 |
public void setPurchaseId(String purchaseId) {
|
|
|
784 |
this.purchaseId = purchaseId;
|
|
|
785 |
}
|
|
|
786 |
|
|
|
787 |
public String getFileNameVal() {
|
|
|
788 |
return fileNameVal;
|
|
|
789 |
}
|
|
|
790 |
|
|
|
791 |
public void setFileNameVal(String fileNameVal) {
|
|
|
792 |
this.fileNameVal = fileNameVal;
|
|
|
793 |
}
|
|
|
794 |
|
|
|
795 |
public String getSuccessMsg() {
|
|
|
796 |
return successMsg;
|
|
|
797 |
}
|
|
|
798 |
|
|
|
799 |
public void setSuccessMsg(String successMsg) {
|
|
|
800 |
this.successMsg = successMsg;
|
|
|
801 |
}
|
|
|
802 |
|
| 11801 |
manish.sha |
803 |
public String getPurchaseComments() {
|
|
|
804 |
return purchaseComments;
|
|
|
805 |
}
|
|
|
806 |
|
|
|
807 |
public void setPurchaseComments(String purchaseComments) {
|
|
|
808 |
this.purchaseComments = purchaseComments;
|
|
|
809 |
}
|
|
|
810 |
|
|
|
811 |
public Warehouse getThirdPartyWarehouse() {
|
|
|
812 |
return thirdPartyWarehouse;
|
|
|
813 |
}
|
|
|
814 |
|
|
|
815 |
public void setThirdPartyWarehouse(Warehouse thirdPartyWarehouse) {
|
|
|
816 |
this.thirdPartyWarehouse = thirdPartyWarehouse;
|
|
|
817 |
}
|
| 11349 |
manish.sha |
818 |
}
|