| Line 23... |
Line 23... |
| 23 |
import com.itextpdf.text.Font.FontFamily;
|
23 |
import com.itextpdf.text.Font.FontFamily;
|
| 24 |
import com.itextpdf.text.pdf.PdfPCell;
|
24 |
import com.itextpdf.text.pdf.PdfPCell;
|
| 25 |
import com.itextpdf.text.pdf.PdfPTable;
|
25 |
import com.itextpdf.text.pdf.PdfPTable;
|
| 26 |
import com.itextpdf.text.pdf.PdfWriter;
|
26 |
import com.itextpdf.text.pdf.PdfWriter;
|
| 27 |
|
27 |
|
| 28 |
import in.shop2020.model.v1.catalog.Warehouse;
|
- |
|
| 29 |
import in.shop2020.thrift.clients.CatalogServiceClient;
|
- |
|
| 30 |
import in.shop2020.thrift.clients.WarehouseServiceClient;
|
28 |
import in.shop2020.thrift.clients.WarehouseServiceClient;
|
| 31 |
import in.shop2020.warehouse.LineItem;
|
29 |
import in.shop2020.warehouse.LineItem;
|
| 32 |
import in.shop2020.warehouse.PurchaseOrder;
|
30 |
import in.shop2020.warehouse.PurchaseOrder;
|
| - |
|
31 |
import in.shop2020.warehouse.Supplier;
|
| 33 |
import in.shop2020.warehouse.WarehouseService.Client;
|
32 |
import in.shop2020.warehouse.WarehouseService.Client;
|
| 34 |
|
33 |
|
| 35 |
public class PoSheetGenerator {
|
34 |
public class PoSheetGenerator {
|
| 36 |
|
35 |
|
| 37 |
private static Logger logger = LoggerFactory.getLogger(PoSheetGenerator.class);
|
36 |
private static Logger logger = LoggerFactory.getLogger(PoSheetGenerator.class);
|
| 38 |
|
37 |
|
| 39 |
private static final Properties properties = readProperties();
|
38 |
private static final Properties properties = readProperties();
|
| 40 |
private static final String ourAddress = properties.getProperty("sales_tax_address",
|
39 |
private static final String ourAddress = properties.getProperty("sales_tax_address",
|
| 41 |
"Spice Online Retail Pvt. Ltd.\nKhasra No. 819, Block-K\nMahipalpur, New Delhi-110037\n");
|
40 |
"Spice Online Retail Pvt. Ltd.\nKhasra No. 819, Block-K\nMahipalpur, New Delhi-110037\n");
|
| - |
|
41 |
private static final String tinNo = properties.getProperty("sales_tax_tin", "07250399732");
|
| 42 |
|
42 |
|
| 43 |
private static final Font helvetica8 = FontFactory.getFont(FontFactory.HELVETICA, 8);
|
43 |
private static final Font helvetica8 = FontFactory.getFont(FontFactory.HELVETICA, 8);
|
| 44 |
private static final Font helvetica10 = FontFactory.getFont(FontFactory.HELVETICA, 10);
|
- |
|
| 45 |
private static final Font helvetica12 = FontFactory.getFont(FontFactory.HELVETICA, 12);
|
- |
|
| 46 |
private static final Font helvetica16 = FontFactory.getFont(FontFactory.HELVETICA, 16);
|
- |
|
| 47 |
|
44 |
|
| 48 |
private static final Font helveticaBold8 = FontFactory.getFont(FontFactory.HELVETICA_BOLD, 8);
|
45 |
private static final Font helveticaBold8 = FontFactory.getFont(FontFactory.HELVETICA_BOLD, 8);
|
| 49 |
private static final Font helveticaBold12 = FontFactory.getFont(FontFactory.HELVETICA_BOLD, 12);
|
46 |
private static final Font helveticaBold12 = FontFactory.getFont(FontFactory.HELVETICA_BOLD, 12);
|
| 50 |
|
47 |
|
| 51 |
private static Properties readProperties(){
|
48 |
private static Properties readProperties(){
|
| Line 58... |
Line 55... |
| 58 |
props.put(key, resource.getString(key));
|
55 |
props.put(key, resource.getString(key));
|
| 59 |
}
|
56 |
}
|
| 60 |
return props;
|
57 |
return props;
|
| 61 |
}
|
58 |
}
|
| 62 |
|
59 |
|
| 63 |
public static String generatePdfSheet(PurchaseOrder purchaseOrder) throws IOException{
|
60 |
public static String generatePdfSheet(PurchaseOrder purchaseOrder, Supplier supplier) throws IOException{
|
| 64 |
ByteArrayOutputStream baosPDF = null;
|
61 |
ByteArrayOutputStream baosPDF = null;
|
| 65 |
try {
|
62 |
try {
|
| 66 |
baosPDF = new ByteArrayOutputStream();
|
63 |
baosPDF = new ByteArrayOutputStream();
|
| 67 |
|
64 |
|
| 68 |
Document document = new Document();
|
65 |
Document document = new Document();
|
| 69 |
PdfWriter.getInstance(document, baosPDF);
|
66 |
PdfWriter.getInstance(document, baosPDF);
|
| 70 |
document.addAuthor("shop2020");
|
67 |
document.addAuthor("shop2020");
|
| 71 |
document.addTitle("Purchase Order No: " + purchaseOrder.getPoNumber());
|
68 |
document.addTitle("Purchase Order No: " + purchaseOrder.getPoNumber());
|
| 72 |
document.open();
|
69 |
document.open();
|
| 73 |
|
70 |
|
| 74 |
PdfPTable poTable = getPoTable(purchaseOrder);
|
71 |
PdfPTable poTable = getPoTable(purchaseOrder, supplier);
|
| 75 |
poTable.setSpacingAfter(10.0f);
|
72 |
poTable.setSpacingAfter(10.0f);
|
| 76 |
poTable.setWidthPercentage(90.0f);
|
73 |
poTable.setWidthPercentage(90.0f);
|
| 77 |
|
74 |
|
| 78 |
document.add(poTable);
|
75 |
document.add(poTable);
|
| 79 |
document.close();
|
76 |
document.close();
|
| Line 88... |
Line 85... |
| 88 |
FileOutputStream fos = new FileOutputStream(f);
|
85 |
FileOutputStream fos = new FileOutputStream(f);
|
| 89 |
baosPDF.writeTo(fos);
|
86 |
baosPDF.writeTo(fos);
|
| 90 |
return filename;
|
87 |
return filename;
|
| 91 |
}
|
88 |
}
|
| 92 |
|
89 |
|
| 93 |
private static PdfPTable getPoTable(PurchaseOrder purchaseOrder) throws Exception{
|
90 |
private static PdfPTable getPoTable(PurchaseOrder purchaseOrder, Supplier supplier) throws Exception{
|
| 94 |
PdfPTable poTable = new PdfPTable(1);
|
91 |
PdfPTable poTable = new PdfPTable(1);
|
| 95 |
poTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
92 |
poTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
| 96 |
poTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
|
93 |
poTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
|
| 97 |
|
94 |
|
| 98 |
PdfPCell poTitleCell = new PdfPCell(new Phrase("Purchase Order", helveticaBold12));
|
95 |
PdfPCell poTitleCell = new PdfPCell(new Phrase("Purchase Order", helveticaBold12));
|
| Line 106... |
Line 103... |
| 106 |
poSummaryTable.setSpacingBefore(10.0f);
|
103 |
poSummaryTable.setSpacingBefore(10.0f);
|
| 107 |
|
104 |
|
| 108 |
poTable.addCell(poTitleCell);
|
105 |
poTable.addCell(poTitleCell);
|
| 109 |
poTable.addCell(getAddressCell());
|
106 |
poTable.addCell(getAddressCell());
|
| 110 |
poTable.addCell(poSummaryTable);
|
107 |
poTable.addCell(poSummaryTable);
|
| 111 |
poTable.addCell(getSalutationTable(purchaseOrder.getSupplierId()));
|
108 |
poTable.addCell(getSalutationTable(supplier));
|
| 112 |
poTable.addCell(getPoDetailsTable(purchaseOrder));
|
109 |
poTable.addCell(getPoDetailsTable(purchaseOrder));
|
| 113 |
poTable.addCell(getBillToTable());
|
110 |
poTable.addCell(getBillToTable());
|
| 114 |
|
111 |
|
| 115 |
return poTable;
|
112 |
return poTable;
|
| 116 |
}
|
113 |
}
|
| 117 |
|
114 |
|
| 118 |
private static PdfPCell getAddressCell() {
|
115 |
private static PdfPCell getAddressCell() {
|
| 119 |
Paragraph addressParagraph = new Paragraph(ourAddress, new Font(FontFamily.TIMES_ROMAN, 8f));
|
116 |
Paragraph addressParagraph = new Paragraph(ourAddress + "\nTIN NO. " + tinNo, new Font(FontFamily.TIMES_ROMAN, 8f));
|
| 120 |
PdfPCell addressCell = new PdfPCell();
|
117 |
PdfPCell addressCell = new PdfPCell();
|
| 121 |
addressCell.addElement(addressParagraph);
|
118 |
addressCell.addElement(addressParagraph);
|
| 122 |
addressCell.setHorizontalAlignment(Element.ALIGN_CENTER);
|
119 |
addressCell.setHorizontalAlignment(Element.ALIGN_CENTER);
|
| 123 |
addressCell.setBorder(Rectangle.NO_BORDER);
|
120 |
addressCell.setBorder(Rectangle.NO_BORDER);
|
| 124 |
return addressCell;
|
121 |
return addressCell;
|
| 125 |
}
|
122 |
}
|
| 126 |
|
123 |
|
| 127 |
private static PdfPTable getSalutationTable(long supplierId) throws Exception{
|
124 |
private static PdfPTable getSalutationTable(Supplier supplier) throws Exception{
|
| 128 |
|
- |
|
| 129 |
CatalogServiceClient catalogServiceClient = new CatalogServiceClient();
|
- |
|
| 130 |
in.shop2020.model.v1.catalog.InventoryService.Client client = catalogServiceClient.getClient();
|
- |
|
| 131 |
Warehouse warehouse = client.getWarehouse(supplierId);
|
- |
|
| 132 |
|
- |
|
| 133 |
PdfPTable salutationTable = new PdfPTable(1);
|
125 |
PdfPTable salutationTable = new PdfPTable(1);
|
| 134 |
salutationTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
|
126 |
salutationTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
|
| 135 |
salutationTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
127 |
salutationTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
| 136 |
salutationTable.addCell(new Phrase("To", helvetica8));
|
128 |
salutationTable.addCell(new Phrase("To", helvetica8));
|
| 137 |
salutationTable.addCell(new Paragraph(warehouse.getLocation(), helvetica8));
|
129 |
salutationTable.addCell(new Paragraph(supplier.getCommunicationAddress(), helvetica8));
|
| 138 |
salutationTable.addCell(new Phrase("Dear Sir/Madam", helveticaBold8));
|
130 |
salutationTable.addCell(new Phrase("Dear Sir/Madam", helveticaBold8));
|
| 139 |
salutationTable.addCell(new Phrase("Please supply the following stocks as per the details given below:", helvetica8));
|
131 |
salutationTable.addCell(new Phrase("Please supply the following stocks as per the details given below:", helvetica8));
|
| 140 |
salutationTable.addCell(new Phrase(" "));
|
132 |
salutationTable.addCell(new Phrase(" "));
|
| 141 |
return salutationTable;
|
133 |
return salutationTable;
|
| 142 |
}
|
134 |
}
|
| Line 169... |
Line 161... |
| 169 |
private static PdfPTable getBillToTable(){
|
161 |
private static PdfPTable getBillToTable(){
|
| 170 |
PdfPTable billToTable = new PdfPTable(new float[]{0.2f, 0.8f});
|
162 |
PdfPTable billToTable = new PdfPTable(new float[]{0.2f, 0.8f});
|
| 171 |
billToTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
|
163 |
billToTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
|
| 172 |
|
164 |
|
| 173 |
billToTable.addCell(new Phrase("Bill To and Ship To:", helvetica8));
|
165 |
billToTable.addCell(new Phrase("Bill To and Ship To:", helvetica8));
|
| 174 |
billToTable.addCell(new PdfPCell(new Paragraph(ourAddress, helvetica8)));
|
166 |
billToTable.addCell(new PdfPCell(new Paragraph(ourAddress + "\nTIN NO. " + tinNo, helvetica8)));
|
| 175 |
|
167 |
|
| 176 |
billToTable.addCell(new Phrase("Contact Person:", helvetica8));
|
168 |
billToTable.addCell(new Phrase("Contact Person:", helvetica8));
|
| 177 |
billToTable.addCell(new Phrase("Mr. Pramod Kumar, Contact No. +91 9971573026", helvetica8));
|
169 |
billToTable.addCell(new Phrase("Mr. Pramod Kumar, Contact No. +91 9971573026", helvetica8));
|
| 178 |
|
170 |
|
| 179 |
billToTable.addCell(new Phrase("Taxes:", helvetica8));
|
171 |
billToTable.addCell(new Phrase("Taxes:", helvetica8));
|
| Line 213... |
Line 205... |
| 213 |
public static void main(String[] args) throws Exception {
|
205 |
public static void main(String[] args) throws Exception {
|
| 214 |
long purchaseOrderId = 10;
|
206 |
long purchaseOrderId = 10;
|
| 215 |
WarehouseServiceClient warehouseServiceClient = new WarehouseServiceClient();
|
207 |
WarehouseServiceClient warehouseServiceClient = new WarehouseServiceClient();
|
| 216 |
Client client = warehouseServiceClient.getClient();
|
208 |
Client client = warehouseServiceClient.getClient();
|
| 217 |
in.shop2020.warehouse.PurchaseOrder purchaseOrder = client.getPurchaseOrder(purchaseOrderId);
|
209 |
in.shop2020.warehouse.PurchaseOrder purchaseOrder = client.getPurchaseOrder(purchaseOrderId);
|
| - |
|
210 |
Supplier supplier = client.getSupplier(purchaseOrder.getSupplierId());
|
| 218 |
String filename = generatePdfSheet(purchaseOrder);
|
211 |
String filename = generatePdfSheet(purchaseOrder, supplier);
|
| 219 |
System.out.println("PO generated.");
|
212 |
System.out.println("PO generated in: " + filename);
|
| 220 |
}
|
213 |
}
|
| 221 |
}
|
214 |
}
|