| Line 4... |
Line 4... |
| 4 |
import in.shop2020.logistics.PickUpType;
|
4 |
import in.shop2020.logistics.PickUpType;
|
| 5 |
import in.shop2020.logistics.PickupStore;
|
5 |
import in.shop2020.logistics.PickupStore;
|
| 6 |
import in.shop2020.logistics.Provider;
|
6 |
import in.shop2020.logistics.Provider;
|
| 7 |
import in.shop2020.model.v1.inventory.InventoryServiceException;
|
7 |
import in.shop2020.model.v1.inventory.InventoryServiceException;
|
| 8 |
import in.shop2020.model.v1.inventory.Warehouse;
|
8 |
import in.shop2020.model.v1.inventory.Warehouse;
|
| - |
|
9 |
import in.shop2020.model.v1.order.BuyerInfo;
|
| 9 |
import in.shop2020.model.v1.order.EbayOrder;
|
10 |
import in.shop2020.model.v1.order.EbayOrder;
|
| 10 |
import in.shop2020.model.v1.order.LineItem;
|
11 |
import in.shop2020.model.v1.order.LineItem;
|
| 11 |
import in.shop2020.model.v1.order.Order;
|
12 |
import in.shop2020.model.v1.order.Order;
|
| 12 |
import in.shop2020.model.v1.order.OrderStatus;
|
13 |
import in.shop2020.model.v1.order.OrderStatus;
|
| 13 |
import in.shop2020.model.v1.order.TransactionServiceException;
|
14 |
import in.shop2020.model.v1.order.TransactionServiceException;
|
| - |
|
15 |
import in.shop2020.model.v1.order.WarehouseAddress;
|
| 14 |
import in.shop2020.thrift.clients.InventoryClient;
|
16 |
import in.shop2020.thrift.clients.InventoryClient;
|
| 15 |
import in.shop2020.thrift.clients.LogisticsClient;
|
17 |
import in.shop2020.thrift.clients.LogisticsClient;
|
| 16 |
import in.shop2020.thrift.clients.TransactionClient;
|
18 |
import in.shop2020.thrift.clients.TransactionClient;
|
| 17 |
|
19 |
|
| 18 |
import java.io.ByteArrayOutputStream;
|
20 |
import java.io.ByteArrayOutputStream;
|
| Line 20... |
Line 22... |
| 20 |
import java.io.FileOutputStream;
|
22 |
import java.io.FileOutputStream;
|
| 21 |
import java.io.IOException;
|
23 |
import java.io.IOException;
|
| 22 |
import java.net.MalformedURLException;
|
24 |
import java.net.MalformedURLException;
|
| 23 |
import java.text.DateFormat;
|
25 |
import java.text.DateFormat;
|
| 24 |
import java.text.DecimalFormat;
|
26 |
import java.text.DecimalFormat;
|
| - |
|
27 |
import java.text.SimpleDateFormat;
|
| 25 |
import java.util.ArrayList;
|
28 |
import java.util.ArrayList;
|
| 26 |
import java.util.Date;
|
29 |
import java.util.Date;
|
| 27 |
import java.util.HashMap;
|
30 |
import java.util.HashMap;
|
| 28 |
import java.util.List;
|
31 |
import java.util.List;
|
| 29 |
import java.util.Map;
|
32 |
import java.util.Map;
|
| Line 36... |
Line 39... |
| 36 |
import com.itextpdf.text.DocumentException;
|
39 |
import com.itextpdf.text.DocumentException;
|
| 37 |
import com.itextpdf.text.Element;
|
40 |
import com.itextpdf.text.Element;
|
| 38 |
import com.itextpdf.text.Font;
|
41 |
import com.itextpdf.text.Font;
|
| 39 |
import com.itextpdf.text.Font.FontFamily;
|
42 |
import com.itextpdf.text.Font.FontFamily;
|
| 40 |
import com.itextpdf.text.FontFactory;
|
43 |
import com.itextpdf.text.FontFactory;
|
| 41 |
import com.itextpdf.text.Image;
|
- |
|
| 42 |
import com.itextpdf.text.Paragraph;
|
44 |
import com.itextpdf.text.Paragraph;
|
| 43 |
import com.itextpdf.text.Phrase;
|
45 |
import com.itextpdf.text.Phrase;
|
| 44 |
import com.itextpdf.text.Rectangle;
|
46 |
import com.itextpdf.text.Rectangle;
|
| 45 |
import com.itextpdf.text.pdf.PdfPCell;
|
47 |
import com.itextpdf.text.pdf.PdfPCell;
|
| 46 |
import com.itextpdf.text.pdf.PdfPTable;
|
48 |
import com.itextpdf.text.pdf.PdfPTable;
|
| Line 52... |
Line 54... |
| 52 |
|
54 |
|
| 53 |
private TransactionClient tsc = null;
|
55 |
private TransactionClient tsc = null;
|
| 54 |
private InventoryClient csc = null;
|
56 |
private InventoryClient csc = null;
|
| 55 |
private LogisticsClient lsc = null;
|
57 |
private LogisticsClient lsc = null;
|
| 56 |
private DecimalFormat weightFormat = new DecimalFormat("0.000");
|
58 |
private DecimalFormat weightFormat = new DecimalFormat("0.000");
|
| - |
|
59 |
private static DateFormat df = new SimpleDateFormat("MMddyyyy");
|
| 57 |
public ManifestGenerator() {
|
60 |
public ManifestGenerator() {
|
| 58 |
try {
|
61 |
try {
|
| 59 |
tsc = new TransactionClient();
|
62 |
tsc = new TransactionClient();
|
| 60 |
csc = new InventoryClient();
|
63 |
csc = new InventoryClient();
|
| 61 |
lsc = new LogisticsClient();
|
64 |
lsc = new LogisticsClient();
|
| Line 65... |
Line 68... |
| 65 |
}
|
68 |
}
|
| 66 |
|
69 |
|
| 67 |
public ByteArrayOutputStream generateManifestFile(long warehouseId, long providerId, boolean isCod, List<Long> orderIds, String runner) {
|
70 |
public ByteArrayOutputStream generateManifestFile(long warehouseId, long providerId, boolean isCod, List<Long> orderIds, String runner) {
|
| 68 |
ByteArrayOutputStream baosPDF = null;
|
71 |
ByteArrayOutputStream baosPDF = null;
|
| 69 |
in.shop2020.model.v1.order.TransactionService.Client txnClient = tsc.getClient();
|
72 |
in.shop2020.model.v1.order.TransactionService.Client txnClient = tsc.getClient();
|
| 70 |
in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = csc.getClient();
|
- |
|
| 71 |
in.shop2020.logistics.LogisticsService.Client logisticsClient = lsc.getClient();
|
73 |
in.shop2020.logistics.LogisticsService.Client logisticsClient = lsc.getClient();
|
| 72 |
|
74 |
|
| 73 |
List<OrderStatus> statuses = new ArrayList<OrderStatus>();
|
75 |
List<OrderStatus> statuses = new ArrayList<OrderStatus>();
|
| 74 |
statuses.add(OrderStatus.BILLED);
|
76 |
statuses.add(OrderStatus.BILLED);
|
| 75 |
|
77 |
|
| 76 |
List<Order> orders = null;
|
78 |
List<Order> orders = null;
|
| 77 |
Warehouse warehouse = null;
|
- |
|
| 78 |
Provider provider = null;
|
79 |
Provider provider = null;
|
| 79 |
List<PickupStore> stores = null;
|
80 |
List<PickupStore> stores = null;
|
| - |
|
81 |
BuyerInfo buyerInfo = null;
|
| 80 |
try {
|
82 |
try {
|
| 81 |
orders = txnClient.getOrdersInBatch(statuses, 0, 0, warehouseId, 0);
|
83 |
orders = txnClient.getOrdersInBatch(statuses, 0, 0, warehouseId, 0);
|
| 82 |
warehouse = inventoryClient.getWarehouse(warehouseId);
|
84 |
buyerInfo = txnClient.getBuyerByWarehouse(warehouseId);
|
| 83 |
provider = logisticsClient.getProvider(providerId);
|
85 |
provider = logisticsClient.getProvider(providerId);
|
| 84 |
stores = logisticsClient.getAllPickupStores();
|
86 |
stores = logisticsClient.getAllPickupStores();
|
| 85 |
} catch (TException e) {
|
87 |
} catch (TException e) {
|
| 86 |
logger.error("Error getting information from one of the Thrift Services: ", e);
|
88 |
logger.error("Error getting information from one of the Thrift Services: ", e);
|
| 87 |
return baosPDF;
|
89 |
return baosPDF;
|
| 88 |
} catch (InventoryServiceException e) {
|
- |
|
| 89 |
logger.error("Error getting warehouse info from the catalog service: ", e);
|
- |
|
| 90 |
return baosPDF;
|
- |
|
| 91 |
} catch (LogisticsServiceException e) {
|
90 |
} catch (LogisticsServiceException e) {
|
| 92 |
logger.error("Error getting provider info from the logistics service: ", e);
|
91 |
logger.error("Error getting provider info from the logistics service: ", e);
|
| 93 |
return baosPDF;
|
92 |
return baosPDF;
|
| 94 |
} catch (TransactionServiceException e) {
|
93 |
} catch (TransactionServiceException e) {
|
| 95 |
logger.error("Error getting orders from the transaction service: ", e);
|
94 |
logger.error("Error getting orders from the transaction service: ", e);
|
| 96 |
return baosPDF;
|
95 |
return baosPDF;
|
| 97 |
}
|
96 |
}
|
| 98 |
|
97 |
|
| 99 |
try {
|
98 |
try {
|
| - |
|
99 |
WarehouseAddress wha = buyerInfo.getBuyerAddress();
|
| 100 |
baosPDF = new ByteArrayOutputStream();
|
100 |
baosPDF = new ByteArrayOutputStream();
|
| 101 |
Font helvetica8 = FontFactory.getFont(FontFactory.HELVETICA, 8);
|
101 |
Font helvetica8 = FontFactory.getFont(FontFactory.HELVETICA, 8);
|
| 102 |
Document document = new Document();
|
102 |
Document document = new Document();
|
| 103 |
PdfWriter.getInstance(document, baosPDF);
|
103 |
PdfWriter.getInstance(document, baosPDF);
|
| 104 |
document.addAuthor("shop2020");
|
104 |
document.addAuthor("shop2020");
|
| 105 |
document.addTitle("Manifest for warehouse " + warehouseId + " provider " + providerId);
|
105 |
document.addTitle("Manifest for warehouse " + warehouseId + " provider " + providerId);
|
| 106 |
document.open();
|
106 |
document.open();
|
| 107 |
PdfPTable table = new PdfPTable(1);
|
107 |
PdfPTable table = new PdfPTable(2);
|
| 108 |
table.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
108 |
table.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
| 109 |
table.getDefaultCell().setPaddingBottom(10.0f);
|
109 |
table.getDefaultCell().setPaddingBottom(10.0f);
|
| 110 |
|
110 |
|
| 111 |
String logoPath = ManifestGenerator.class.getResource("/logo.jpg").getPath();
|
111 |
Paragraph companyPara = new Paragraph(buyerInfo.getOrganisationName() + " Manifest Report", new Font(FontFamily.TIMES_ROMAN,16f));
|
| 112 |
PdfPCell logoCell = new PdfPCell(Image.getInstance(logoPath), false);
|
112 |
PdfPCell companyCell = new PdfPCell();
|
| - |
|
113 |
companyCell.addElement(companyPara);
|
| - |
|
114 |
companyCell.setHorizontalAlignment(Element.ALIGN_LEFT);
|
| 113 |
logoCell.setBorder(Rectangle.NO_BORDER);
|
115 |
companyCell.setBorder(Rectangle.NO_BORDER);
|
| - |
|
116 |
|
| 114 |
|
117 |
|
| 115 |
String addressString = warehouse.getLocation() + "\nPIN " + warehouse.getPincode()+ "\n\n";
|
118 |
String addressString = wha.getAddress() + "\nPIN " + wha.getPin()+ "\n\n";
|
| 116 |
Paragraph addressParagraph = new Paragraph(addressString, new Font(FontFamily.TIMES_ROMAN,8f));
|
119 |
Paragraph addressParagraph = new Paragraph(addressString, new Font(FontFamily.TIMES_ROMAN,8f));
|
| 117 |
PdfPCell addressCell = new PdfPCell();
|
120 |
PdfPCell addressCell = new PdfPCell();
|
| 118 |
addressCell.addElement(addressParagraph);
|
121 |
addressCell.addElement(addressParagraph);
|
| 119 |
addressCell.setHorizontalAlignment(Element.ALIGN_LEFT);
|
122 |
addressCell.setHorizontalAlignment(Element.ALIGN_LEFT);
|
| 120 |
addressCell.setBorder(Rectangle.NO_BORDER);
|
123 |
addressCell.setBorder(Rectangle.NO_BORDER);
|
| Line 230... |
Line 233... |
| 230 |
ordersTable.addCell(new Phrase(store.getCity(), helvetica8));
|
233 |
ordersTable.addCell(new Phrase(store.getCity(), helvetica8));
|
| 231 |
ordersTable.addCell(new Phrase(store.getPhone(), helvetica8));
|
234 |
ordersTable.addCell(new Phrase(store.getPhone(), helvetica8));
|
| 232 |
}
|
235 |
}
|
| 233 |
|
236 |
|
| 234 |
}
|
237 |
}
|
| 235 |
/*for(int i=0; i < orders.size();i++){
|
- |
|
| 236 |
Order order = orders.get(i);
|
- |
|
| 237 |
if(!orderIds.contains(order.getId()))
|
- |
|
| 238 |
continue;
|
- |
|
| 239 |
if(order.getLogistics_provider_id()!=providerId)
|
- |
|
| 240 |
continue;
|
- |
|
| 241 |
if(order.isLogisticsCod() != isCod)
|
- |
|
| 242 |
continue;
|
- |
|
| 243 |
//TODO: These are exactly the orders which will be shipped now. Shouldn't we change their status to be SHIPPED?
|
- |
|
| 244 |
serialNo++;
|
- |
|
| 245 |
List<LineItem> lineItems = order.getLineitems();
|
- |
|
| 246 |
double weight = 0;
|
- |
|
| 247 |
for(LineItem lineItem: lineItems)
|
- |
|
| 248 |
weight += lineItem.getTotal_weight();
|
- |
|
| 249 |
|
- |
|
| 250 |
ordersTable.addCell(new Phrase(serialNo + "", helvetica8));
|
- |
|
| 251 |
if(provider.isGroupShipmentAllowed()){
|
- |
|
| 252 |
ordersTable.addCell(new Phrase(order.getLogisticsTransactionId(), helvetica8));
|
- |
|
| 253 |
}
|
- |
|
| 254 |
ordersTable.addCell(new Phrase(order.getId() + "", helvetica8));
|
- |
|
| 255 |
ordersTable.addCell(new Phrase(order.getAirwaybill_no(), helvetica8));
|
- |
|
| 256 |
ordersTable.addCell(new Phrase(weightFormat.format(weight), helvetica8));
|
- |
|
| 257 |
|
- |
|
| 258 |
//if Logistics is Ebay Power Ship add extra fields like Sales Record Number and PaisaPayId
|
- |
|
| 259 |
if(providerId > 7 && providerId <12) {
|
- |
|
| 260 |
try {
|
- |
|
| 261 |
EbayOrder ebayOrder = txnClient.getEbayOrderByOrderId(order.getId());
|
- |
|
| 262 |
ordersTable.addCell(new Phrase(ebayOrder.getPaisaPayId(), helvetica8));
|
- |
|
| 263 |
ordersTable.addCell(new Phrase(new Long(ebayOrder.getSalesRecordNumber()).toString(), helvetica8));
|
- |
|
| 264 |
} catch (Exception e) {
|
- |
|
| 265 |
logger.error("Error getting Ebay Order for OrderId : " + order.getId(), e);
|
- |
|
| 266 |
return baosPDF;
|
- |
|
| 267 |
}
|
- |
|
| 268 |
}
|
- |
|
| 269 |
|
- |
|
| 270 |
if(runner == null){
|
- |
|
| 271 |
ordersTable.addCell(new Phrase(order.getCustomer_name(), helvetica8));
|
- |
|
| 272 |
ordersTable.addCell(new Phrase(order.getCustomer_city(), helvetica8));
|
- |
|
| 273 |
ordersTable.addCell(new Phrase(order.getCustomer_pincode(), helvetica8));
|
- |
|
| 274 |
ordersTable.addCell(new Phrase(order.getCustomer_state(), helvetica8));
|
- |
|
| 275 |
}else{
|
- |
|
| 276 |
PickupStore store = getStoreFromId(stores, order.getPickupStoreId());
|
- |
|
| 277 |
ordersTable.addCell(new Phrase(store.getHotspotId(), helvetica8));
|
- |
|
| 278 |
ordersTable.addCell(new Phrase(store.getLine1() + ((store.getLine2() == null)? "": "\n" + store.getLine2()), helvetica8));
|
- |
|
| 279 |
ordersTable.addCell(new Phrase(store.getCity(), helvetica8));
|
- |
|
| 280 |
ordersTable.addCell(new Phrase(store.getPhone(), helvetica8));
|
- |
|
| 281 |
}
|
- |
|
| 282 |
}*/
|
- |
|
| 283 |
|
- |
|
| 284 |
table.addCell(logoCell);
|
238 |
table.addCell(companyCell);
|
| 285 |
table.addCell(addressCell);
|
239 |
table.addCell(addressCell);
|
| 286 |
if(isCod)
|
240 |
if(isCod) {
|
| - |
|
241 |
table.addCell(new Phrase("Manifest ID: COD" + df.format(new Date())) + String.format("%032", warehouseId) + String.format("%032", providerId));
|
| 287 |
table.addCell(new Phrase("PAYMODE: COD", helvetica8));
|
242 |
table.addCell(new Phrase("PAYMODE: COD", helvetica8));
|
| - |
|
243 |
}
|
| 288 |
else
|
244 |
else {
|
| - |
|
245 |
table.addCell(new Phrase("Manifest ID: PRE" + df.format(new Date())) + String.format("%032", warehouseId) + String.format("%032", providerId));
|
| 289 |
table.addCell(new Phrase("PAYMODE: Prepaid", helvetica8));
|
246 |
table.addCell(new Phrase("PAYMODE: Prepaid", helvetica8));
|
| - |
|
247 |
}
|
| 290 |
if(provider.getPickup() == PickUpType.RUNNER){
|
248 |
if(provider.getPickup() == PickUpType.RUNNER){
|
| 291 |
table.addCell(new Phrase("Runner Name: " + runner, helvetica8));
|
249 |
table.addCell(new Phrase("Runner Name: " + runner, helvetica8));
|
| - |
|
250 |
table.addCell(new Phrase("Manifest Type: Runner Manifest", helvetica8));
|
| 292 |
}else{
|
251 |
}else{
|
| 293 |
table.addCell(new Phrase("Courier Name: " + provider.getName(), helvetica8));
|
252 |
table.addCell(new Phrase("Courier Name: " + provider.getName(), helvetica8));
|
| - |
|
253 |
table.addCell(new Phrase("Manifest Type: Courier Manifest", helvetica8));
|
| 294 |
}
|
254 |
}
|
| 295 |
|
255 |
|
| 296 |
table.addCell(new Phrase("Pick up Date: " + DateFormat.getDateInstance(DateFormat.MEDIUM).format(new Date()), helvetica8));
|
256 |
table.addCell(new Phrase("Dispatch Date: " + DateFormat.getDateInstance(DateFormat.MEDIUM).format(new Date()), helvetica8));
|
| - |
|
257 |
table.addCell(new Phrase("No. of Shipments: " + airwayBillNoMap.size(), helvetica8));
|
| 297 |
table.addCell(ordersTable);
|
258 |
table.addCell(ordersTable);
|
| 298 |
table.setWidthPercentage(90.0f);
|
259 |
table.setWidthPercentage(90.0f);
|
| 299 |
|
260 |
|
| 300 |
document.add(table);
|
261 |
document.add(table);
|
| 301 |
document.close();
|
262 |
document.close();
|