| 5300 |
mandeep.dh |
1 |
/**
|
|
|
2 |
*
|
|
|
3 |
*/
|
|
|
4 |
package in.shop2020.inventory.service;
|
|
|
5 |
|
|
|
6 |
import java.io.BufferedWriter;
|
|
|
7 |
import java.io.File;
|
|
|
8 |
import java.io.FileWriter;
|
| 24012 |
amit.gupta |
9 |
import java.util.List;
|
| 5300 |
mandeep.dh |
10 |
|
|
|
11 |
import org.apache.commons.lang.StringUtils;
|
|
|
12 |
|
| 24012 |
amit.gupta |
13 |
import in.shop2020.model.v1.inventory.InventoryService;
|
|
|
14 |
import in.shop2020.model.v1.inventory.VendorItemMapping;
|
|
|
15 |
import in.shop2020.purchase.LineItem;
|
|
|
16 |
import in.shop2020.purchase.PurchaseOrder;
|
|
|
17 |
import in.shop2020.thrift.clients.InventoryClient;
|
|
|
18 |
|
| 5300 |
mandeep.dh |
19 |
/**
|
|
|
20 |
* @author mandeep
|
|
|
21 |
*
|
|
|
22 |
*/
|
|
|
23 |
public class POExcelGenerator {
|
| 24012 |
amit.gupta |
24 |
public static InventoryService.Client inventoryClient = null;
|
|
|
25 |
static {
|
|
|
26 |
try {
|
|
|
27 |
inventoryClient = new InventoryClient().getClient();
|
|
|
28 |
} catch(Exception e) {
|
|
|
29 |
e.printStackTrace();
|
|
|
30 |
}
|
|
|
31 |
}
|
| 5300 |
mandeep.dh |
32 |
public static File generateExcelSheet(PurchaseOrder purchaseOrder) {
|
|
|
33 |
try {
|
| 6699 |
rajveer |
34 |
String tmpDir = System.getProperty("java.io.tmpdir");
|
| 24095 |
amit.gupta |
35 |
File file = new File(tmpDir + "/NSSPL-" + purchaseOrder.getId() + ".xls");
|
| 5300 |
mandeep.dh |
36 |
BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(file));
|
| 24012 |
amit.gupta |
37 |
bufferedWriter.write(StringUtils.join(new String[]{"Brand", "Model Name", "Model Number", "Color", "Vendor Key", "Quantity Required", "Actual Quantity Fulfilled", "Other colors available"}, '\t'));
|
| 5300 |
mandeep.dh |
38 |
|
|
|
39 |
for (LineItem lineitem : purchaseOrder.getLineitems()) {
|
| 24012 |
amit.gupta |
40 |
String vendorKey = "";
|
| 5300 |
mandeep.dh |
41 |
bufferedWriter.newLine();
|
| 24012 |
amit.gupta |
42 |
if(lineitem.getBrand()=="Samsung") {
|
|
|
43 |
List<VendorItemMapping> vims = getVendorItemMapping(lineitem.getItemId());
|
|
|
44 |
if(vims != null && vims.size() > 0) {
|
|
|
45 |
for(VendorItemMapping vim : vims) {
|
|
|
46 |
if(vim.getVendorId() == purchaseOrder.getSupplierId()) {
|
|
|
47 |
vendorKey = vim.getItemKey();
|
|
|
48 |
break;
|
|
|
49 |
}
|
|
|
50 |
}
|
|
|
51 |
}
|
|
|
52 |
}
|
|
|
53 |
bufferedWriter.write(StringUtils.join(new String[]{lineitem.getBrand(), lineitem.getModelName(), lineitem.getModelNumber(), lineitem.getColor(), vendorKey, String.valueOf(lineitem.getQuantity()), "0", ""}, '\t'));
|
| 5300 |
mandeep.dh |
54 |
}
|
|
|
55 |
|
|
|
56 |
bufferedWriter.close();
|
|
|
57 |
return file;
|
|
|
58 |
} catch (Exception e) {
|
|
|
59 |
return null;
|
|
|
60 |
}
|
|
|
61 |
}
|
| 24012 |
amit.gupta |
62 |
|
|
|
63 |
|
|
|
64 |
private static List<VendorItemMapping> getVendorItemMapping(long itemId) {
|
|
|
65 |
try {
|
|
|
66 |
|
|
|
67 |
return inventoryClient.getVendorItemMappings(itemId);
|
|
|
68 |
}catch (Exception e) {
|
|
|
69 |
try {
|
|
|
70 |
inventoryClient = new InventoryClient().getClient();
|
|
|
71 |
return inventoryClient.getVendorItemMappings(itemId);
|
|
|
72 |
} catch(Exception e1) {
|
|
|
73 |
e1.printStackTrace();
|
|
|
74 |
}
|
|
|
75 |
}
|
|
|
76 |
return null;
|
| 5300 |
mandeep.dh |
77 |
}
|
| 24012 |
amit.gupta |
78 |
}
|