| Line 1... |
Line 1... |
| 1 |
package in.shop2020.inventory.service;
|
1 |
package in.shop2020.inventory.service;
|
| 2 |
|
2 |
|
| 3 |
import in.shop2020.model.v1.catalog.CatalogServiceException;
|
- |
|
| 4 |
import in.shop2020.model.v1.catalog.GstRate;
|
- |
|
| 5 |
import in.shop2020.model.v1.catalog.StateGstRates;
|
- |
|
| 6 |
import in.shop2020.model.v1.inventory.StateInfo;
|
- |
|
| 7 |
import in.shop2020.model.v1.order.BuyerInfo;
|
- |
|
| 8 |
import in.shop2020.model.v1.order.WarehouseAddress;
|
- |
|
| 9 |
import in.shop2020.purchase.PurchaseOrder;
|
- |
|
| 10 |
import in.shop2020.purchase.Supplier;
|
- |
|
| 11 |
import in.shop2020.purchase.TaxType;
|
- |
|
| 12 |
import in.shop2020.thrift.clients.CatalogClient;
|
- |
|
| 13 |
import in.shop2020.thrift.clients.InventoryClient;
|
- |
|
| 14 |
import in.shop2020.thrift.clients.TransactionClient;
|
- |
|
| 15 |
|
- |
|
| 16 |
import java.io.ByteArrayOutputStream;
|
3 |
import java.io.ByteArrayOutputStream;
|
| 17 |
import java.io.File;
|
4 |
import java.io.File;
|
| 18 |
import java.io.FileOutputStream;
|
5 |
import java.io.FileOutputStream;
|
| 19 |
import java.io.IOException;
|
6 |
import java.io.IOException;
|
| 20 |
import java.text.DateFormat;
|
7 |
import java.text.DateFormat;
|
| 21 |
import java.text.MessageFormat;
|
8 |
import java.text.MessageFormat;
|
| 22 |
import java.util.Calendar;
|
9 |
import java.util.Calendar;
|
| 23 |
import java.util.Date;
|
10 |
import java.util.Date;
|
| - |
|
11 |
import java.util.List;
|
| 24 |
import java.util.Map;
|
12 |
import java.util.Map;
|
| 25 |
|
13 |
|
| 26 |
import org.apache.commons.lang.StringUtils;
|
14 |
import org.apache.commons.lang.StringUtils;
|
| 27 |
import org.apache.thrift.TException;
|
15 |
import org.apache.thrift.TException;
|
| 28 |
import org.slf4j.Logger;
|
16 |
import org.slf4j.Logger;
|
| Line 38... |
Line 26... |
| 38 |
import com.itextpdf.text.Rectangle;
|
26 |
import com.itextpdf.text.Rectangle;
|
| 39 |
import com.itextpdf.text.pdf.PdfPCell;
|
27 |
import com.itextpdf.text.pdf.PdfPCell;
|
| 40 |
import com.itextpdf.text.pdf.PdfPTable;
|
28 |
import com.itextpdf.text.pdf.PdfPTable;
|
| 41 |
import com.itextpdf.text.pdf.PdfWriter;
|
29 |
import com.itextpdf.text.pdf.PdfWriter;
|
| 42 |
|
30 |
|
| - |
|
31 |
import in.shop2020.model.v1.catalog.CatalogServiceException;
|
| - |
|
32 |
import in.shop2020.model.v1.inventory.InventoryService;
|
| - |
|
33 |
import in.shop2020.model.v1.inventory.StateInfo;
|
| - |
|
34 |
import in.shop2020.model.v1.inventory.VendorItemMapping;
|
| - |
|
35 |
import in.shop2020.model.v1.order.BuyerInfo;
|
| - |
|
36 |
import in.shop2020.model.v1.order.WarehouseAddress;
|
| - |
|
37 |
import in.shop2020.purchase.PurchaseOrder;
|
| - |
|
38 |
import in.shop2020.purchase.Supplier;
|
| - |
|
39 |
import in.shop2020.purchase.TaxType;
|
| - |
|
40 |
import in.shop2020.thrift.clients.CatalogClient;
|
| - |
|
41 |
import in.shop2020.thrift.clients.InventoryClient;
|
| - |
|
42 |
import in.shop2020.thrift.clients.TransactionClient;
|
| - |
|
43 |
|
| 43 |
public class PdfPoSheetGenerator {
|
44 |
public class PdfPoSheetGenerator {
|
| 44 |
|
45 |
|
| 45 |
private static Logger logger = LoggerFactory.getLogger(PdfPoSheetGenerator.class);
|
46 |
private static Logger logger = LoggerFactory.getLogger(PdfPoSheetGenerator.class);
|
| 46 |
|
47 |
|
| 47 |
private static final Font helvetica8 = FontFactory.getFont(FontFactory.HELVETICA, 8);
|
48 |
private static final Font helvetica8 = FontFactory.getFont(FontFactory.HELVETICA, 8);
|
| 48 |
|
49 |
|
| 49 |
private static final Font helveticaBold8 = FontFactory.getFont(FontFactory.HELVETICA_BOLD, 8);
|
50 |
private static final Font helveticaBold8 = FontFactory.getFont(FontFactory.HELVETICA_BOLD, 8);
|
| 50 |
private static final Font helveticaBold12 = FontFactory.getFont(FontFactory.HELVETICA_BOLD, 12);
|
51 |
private static final Font helveticaBold12 = FontFactory.getFont(FontFactory.HELVETICA_BOLD, 12);
|
| 51 |
|
52 |
|
| 52 |
public static Map<Long, StateInfo> stateIdMap = null;
|
53 |
public static Map<Long, StateInfo> stateIdMap = null;
|
| - |
|
54 |
public static InventoryService.Client inventoryClient = null;
|
| 53 |
|
55 |
|
| 54 |
static String CONTACT_FORMAT = "Mr. {0}, Contact No. +91 {1}";
|
56 |
static String CONTACT_FORMAT = "Mr. {0}, Contact No. +91 {1}";
|
| 55 |
|
57 |
|
| 56 |
static {
|
58 |
static {
|
| 57 |
try {
|
59 |
try {
|
| 58 |
in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = new InventoryClient().getClient();
|
60 |
inventoryClient = new InventoryClient().getClient();
|
| 59 |
stateIdMap = inventoryClient.getStateMaster();
|
61 |
stateIdMap = inventoryClient.getStateMaster();
|
| 60 |
|
62 |
|
| 61 |
} catch (Exception e) {
|
63 |
} catch (Exception e) {
|
| 62 |
logger.error("Unable to get State Info Map", e);
|
64 |
logger.error("Unable to get State Info Map", e);
|
| 63 |
}
|
65 |
}
|
| Line 287... |
Line 289... |
| 287 |
CatalogClient cClient = new CatalogClient();
|
289 |
CatalogClient cClient = new CatalogClient();
|
| 288 |
in.shop2020.model.v1.catalog.CatalogService.Client catalogClient = cClient.getClient();
|
290 |
in.shop2020.model.v1.catalog.CatalogService.Client catalogClient = cClient.getClient();
|
| 289 |
for (in.shop2020.purchase.LineItem lineitem : purchaseOrder.getLineitems()) {
|
291 |
for (in.shop2020.purchase.LineItem lineitem : purchaseOrder.getLineitems()) {
|
| 290 |
slNo++;
|
292 |
slNo++;
|
| 291 |
detailsTable.addCell(new Phrase(slNo + "", helvetica8));
|
293 |
detailsTable.addCell(new Phrase(slNo + "", helvetica8));
|
| 292 |
detailsTable.addCell(getProductNameCell(lineitem));
|
294 |
detailsTable.addCell(getProductNameCell(lineitem, purchaseOrder.getSupplierId()));
|
| 293 |
detailsTable.addCell(new Phrase(lineitem.getHsnCode(), helvetica8));
|
295 |
detailsTable.addCell(new Phrase(lineitem.getHsnCode(), helvetica8));
|
| 294 |
detailsTable.addCell(new Phrase(String.format("%d Units", (int)lineitem.getQuantity()), helvetica8));
|
296 |
detailsTable.addCell(new Phrase(String.format("%d Units", (int)lineitem.getQuantity()), helvetica8));
|
| 295 |
detailsTable.addCell(new Phrase(String.format("%.2f", lineitem.getUnitPrice()), helvetica8));
|
297 |
detailsTable.addCell(new Phrase(String.format("%.2f", lineitem.getUnitPrice()), helvetica8));
|
| 296 |
|
298 |
|
| 297 |
double totalAmount = lineitem.getUnitPrice()*lineitem.getQuantity();
|
299 |
double totalAmount = lineitem.getUnitPrice()*lineitem.getQuantity();
|
| Line 388... |
Line 390... |
| 388 |
}
|
390 |
}
|
| 389 |
|
391 |
|
| 390 |
return billToTable;
|
392 |
return billToTable;
|
| 391 |
}
|
393 |
}
|
| 392 |
|
394 |
|
| 393 |
private static PdfPCell getProductNameCell(in.shop2020.purchase.LineItem lineitem) {
|
395 |
private static PdfPCell getProductNameCell(in.shop2020.purchase.LineItem lineitem, long supplierId) {
|
| 394 |
String itemName = getItemDisplayName(lineitem);
|
396 |
String itemName = getItemDisplayName(lineitem, supplierId);
|
| 395 |
PdfPCell productNameCell = new PdfPCell(new Phrase(itemName, helvetica8));
|
397 |
PdfPCell productNameCell = new PdfPCell(new Phrase(itemName, helvetica8));
|
| 396 |
productNameCell.setHorizontalAlignment(Element.ALIGN_LEFT);
|
398 |
productNameCell.setHorizontalAlignment(Element.ALIGN_LEFT);
|
| 397 |
return productNameCell;
|
399 |
return productNameCell;
|
| 398 |
}
|
400 |
}
|
| 399 |
|
401 |
|
| 400 |
private static String getItemDisplayName(in.shop2020.purchase.LineItem lineitem) {
|
402 |
private static String getItemDisplayName(in.shop2020.purchase.LineItem lineitem, long supplierId) {
|
| 401 |
StringBuffer itemName = new StringBuffer();
|
403 |
StringBuffer itemName = new StringBuffer();
|
| 402 |
if (lineitem.getBrand() != null)
|
404 |
if (lineitem.getBrand() != null)
|
| 403 |
itemName.append(lineitem.getBrand() + " ");
|
405 |
itemName.append(lineitem.getBrand() + " ");
|
| 404 |
if (lineitem.getModelName() != null)
|
406 |
if (lineitem.getModelName() != null)
|
| 405 |
itemName.append(lineitem.getModelName() + " ");
|
407 |
itemName.append(lineitem.getModelName() + " ");
|
| 406 |
if (lineitem.getModelNumber() != null)
|
408 |
if (lineitem.getModelNumber() != null)
|
| 407 |
itemName.append(lineitem.getModelNumber() + " ");
|
409 |
itemName.append(lineitem.getModelNumber() + " ");
|
| 408 |
if (lineitem.getColor() != null && !lineitem.getColor().trim().equals("NA"))
|
410 |
if (lineitem.getColor() != null && !lineitem.getColor().trim().equals("NA"))
|
| 409 |
itemName.append("(" + lineitem.getColor() + ")");
|
411 |
itemName.append("-" + lineitem.getColor());
|
| - |
|
412 |
if(lineitem.getBrand()=="Samsung") {
|
| - |
|
413 |
List<VendorItemMapping> vims = getVendorItemMapping(lineitem.getItemId());
|
| - |
|
414 |
if(vims != null && vims.size() > 0) {
|
| - |
|
415 |
for(VendorItemMapping vim : vims) {
|
| - |
|
416 |
if(vim.getVendorId() == supplierId) {
|
| - |
|
417 |
itemName.append("(" + vim.getItemKey() + ")");
|
| - |
|
418 |
}
|
| - |
|
419 |
}
|
| - |
|
420 |
}
|
| 410 |
|
421 |
}
|
| 411 |
return itemName.toString();
|
422 |
return itemName.toString();
|
| 412 |
}
|
423 |
}
|
| - |
|
424 |
|
| - |
|
425 |
private static List<VendorItemMapping> getVendorItemMapping(long itemId) {
|
| - |
|
426 |
try {
|
| - |
|
427 |
|
| - |
|
428 |
return inventoryClient.getVendorItemMappings(itemId);
|
| - |
|
429 |
}catch (Exception e) {
|
| - |
|
430 |
try {
|
| - |
|
431 |
inventoryClient = new InventoryClient().getClient();
|
| - |
|
432 |
return inventoryClient.getVendorItemMappings(itemId);
|
| - |
|
433 |
} catch(Exception e1) {
|
| - |
|
434 |
e1.printStackTrace();
|
| - |
|
435 |
}
|
| - |
|
436 |
}
|
| - |
|
437 |
return null;
|
| - |
|
438 |
}
|
| 413 |
|
439 |
|
| 414 |
private static PdfPCell getTotalCell(int colspan) {
|
440 |
private static PdfPCell getTotalCell(int colspan) {
|
| 415 |
PdfPCell totalCell = new PdfPCell(new Phrase("Total", helveticaBold8));
|
441 |
PdfPCell totalCell = new PdfPCell(new Phrase("Total", helveticaBold8));
|
| 416 |
totalCell.setColspan(colspan);
|
442 |
totalCell.setColspan(colspan);
|
| 417 |
totalCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
|
443 |
totalCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
|