| 33741 |
amit.gupta |
1 |
package com.spice.profitmandi.common.util;
|
|
|
2 |
|
|
|
3 |
import com.itextpdf.text.*;
|
|
|
4 |
import com.itextpdf.text.pdf.*;
|
|
|
5 |
import com.spice.profitmandi.common.model.EWBPartAModel;
|
|
|
6 |
import com.spice.profitmandi.common.model.EWBPartBModel;
|
|
|
7 |
import com.spice.profitmandi.common.model.EWayBillPdfModel;
|
|
|
8 |
|
|
|
9 |
import java.io.FileOutputStream;
|
|
|
10 |
|
|
|
11 |
|
|
|
12 |
public class EWayBillPDF {
|
|
|
13 |
|
|
|
14 |
public static void main(String[] args) {
|
|
|
15 |
EWayBillPDF eWayBillPDF = new EWayBillPDF();
|
|
|
16 |
EWayBillPdfModel eWayBillPdfModel = new EWayBillPdfModel();
|
|
|
17 |
EWBPartAModel partAModel = new EWBPartAModel();
|
|
|
18 |
eWayBillPdfModel.setEwbPartAModel(partAModel);
|
|
|
19 |
eWayBillPDF.generateDocument(eWayBillPdfModel);
|
|
|
20 |
|
|
|
21 |
}
|
|
|
22 |
|
|
|
23 |
public static void generateDocument(EWayBillPdfModel eWayBillPdfModel) {
|
|
|
24 |
Document document = new Document();
|
|
|
25 |
try {
|
|
|
26 |
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("EWayBill.pdf"));
|
|
|
27 |
document.open();
|
|
|
28 |
EWayBillPDF.generateDocument(document, writer, eWayBillPdfModel);
|
|
|
29 |
document.close();
|
|
|
30 |
} catch (Exception e) {
|
|
|
31 |
e.printStackTrace();
|
|
|
32 |
}
|
|
|
33 |
}
|
| 36120 |
amit |
34 |
// Compact fonts matching invoice style
|
|
|
35 |
private static final BaseColor EWB_BORDER = new BaseColor(204, 204, 204);
|
|
|
36 |
private static final BaseColor EWB_HEADER_BG = new BaseColor(242, 242, 242);
|
|
|
37 |
private static final Font EWB_TITLE = new Font(Font.FontFamily.HELVETICA, 10, Font.BOLD);
|
|
|
38 |
private static final Font EWB_SECTION = new Font(Font.FontFamily.HELVETICA, 8, Font.BOLD);
|
|
|
39 |
private static final Font EWB_NORMAL = new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL);
|
|
|
40 |
private static final Font EWB_BOLD = new Font(Font.FontFamily.HELVETICA, 7, Font.BOLD);
|
|
|
41 |
|
| 33741 |
amit.gupta |
42 |
public static void generateDocument(Document document, PdfWriter writer, EWayBillPdfModel eWayBillPdfModel) {
|
|
|
43 |
try {
|
|
|
44 |
// Title
|
| 36120 |
amit |
45 |
Paragraph titleParagraph = new Paragraph("E-Way Bill System", EWB_TITLE);
|
| 33741 |
amit.gupta |
46 |
titleParagraph.setAlignment(Element.ALIGN_CENTER);
|
| 36120 |
amit |
47 |
titleParagraph.setSpacingAfter(6f);
|
| 33741 |
amit.gupta |
48 |
document.add(titleParagraph);
|
|
|
49 |
|
|
|
50 |
// E-Way Bill Info
|
|
|
51 |
PdfPTable table = new PdfPTable(2);
|
| 36120 |
amit |
52 |
table.setWidths(new float[]{1.2f, 2.8f});
|
|
|
53 |
table.setWidthPercentage(80);
|
|
|
54 |
table.setSpacingAfter(6f);
|
| 33741 |
amit.gupta |
55 |
|
| 36120 |
amit |
56 |
ewbRow(table, "E-Way Bill No:", eWayBillPdfModel.getEwbNumber());
|
|
|
57 |
ewbRow(table, "E-Way Bill Date:", eWayBillPdfModel.getEwbDate());
|
|
|
58 |
ewbRow(table, "Generated By:", eWayBillPdfModel.getGeneratedBy());
|
|
|
59 |
ewbRow(table, "Valid From:", eWayBillPdfModel.getValidFrom());
|
|
|
60 |
ewbRow(table, "Valid Until:", eWayBillPdfModel.getValidUntil());
|
| 33741 |
amit.gupta |
61 |
|
|
|
62 |
document.add(table);
|
|
|
63 |
|
|
|
64 |
// Part A
|
| 36120 |
amit |
65 |
EWBPartAModel partAModel = eWayBillPdfModel.getEwbPartAModel();
|
| 33741 |
amit.gupta |
66 |
PdfPTable partATable = new PdfPTable(2);
|
| 36120 |
amit |
67 |
partATable.setWidths(new float[]{1.2f, 2.8f});
|
|
|
68 |
partATable.setWidthPercentage(80);
|
|
|
69 |
partATable.setSpacingAfter(6f);
|
| 33741 |
amit.gupta |
70 |
|
| 36120 |
amit |
71 |
PdfPCell partAHeader = new PdfPCell(new Phrase("Part A", EWB_SECTION));
|
|
|
72 |
partAHeader.setColspan(2);
|
|
|
73 |
partAHeader.setHorizontalAlignment(Element.ALIGN_CENTER);
|
|
|
74 |
partAHeader.setBackgroundColor(EWB_HEADER_BG);
|
|
|
75 |
partAHeader.setBorderColor(EWB_BORDER);
|
|
|
76 |
partAHeader.setPadding(3f);
|
|
|
77 |
partATable.addCell(partAHeader);
|
| 33741 |
amit.gupta |
78 |
|
| 36120 |
amit |
79 |
ewbRow(partATable, "GSTIN of Supplier:", partAModel.getSupplierGstin());
|
|
|
80 |
ewbRow(partATable, "Place of Dispatch:", partAModel.getPlaceOfDispatch());
|
|
|
81 |
ewbRow(partATable, "GSTIN of Recipient:", partAModel.getRecipientGstin());
|
|
|
82 |
ewbRow(partATable, "Place of Delivery:", partAModel.getPlaceOfDelivery());
|
|
|
83 |
ewbRow(partATable, "Document No:", partAModel.getDocumentNumber());
|
|
|
84 |
ewbRow(partATable, "Document Date:", partAModel.getDocumentDate());
|
|
|
85 |
ewbRow(partATable, "Transaction Type:", partAModel.getTransactType());
|
|
|
86 |
ewbRow(partATable, "Value of Goods:", partAModel.getValueOfGoods());
|
|
|
87 |
ewbRow(partATable, "HSN Code(s):", partAModel.getHsnCode());
|
|
|
88 |
ewbRow(partATable, "Reason for Transportation:", partAModel.getReasonForTransportation());
|
|
|
89 |
if (partAModel.getTransporter() != null) {
|
|
|
90 |
ewbRow(partATable, "Transporter:", partAModel.getTransporter());
|
| 33742 |
amit.gupta |
91 |
}
|
|
|
92 |
|
| 33741 |
amit.gupta |
93 |
document.add(partATable);
|
|
|
94 |
|
|
|
95 |
// Part B
|
|
|
96 |
if (eWayBillPdfModel.getEwbPartBModel() != null) {
|
| 36120 |
amit |
97 |
PdfPTable partBTable = new PdfPTable(7);
|
| 33741 |
amit.gupta |
98 |
partBTable.setWidths(new float[]{2, 3, 3, 4, 4, 2, 2});
|
| 36120 |
amit |
99 |
partBTable.setWidthPercentage(80);
|
|
|
100 |
partBTable.setSpacingAfter(6f);
|
| 33741 |
amit.gupta |
101 |
|
| 36120 |
amit |
102 |
PdfPCell partBHeader = new PdfPCell(new Phrase("Part B", EWB_SECTION));
|
|
|
103 |
partBHeader.setColspan(7);
|
|
|
104 |
partBHeader.setHorizontalAlignment(Element.ALIGN_CENTER);
|
|
|
105 |
partBHeader.setBackgroundColor(EWB_HEADER_BG);
|
|
|
106 |
partBHeader.setBorderColor(EWB_BORDER);
|
|
|
107 |
partBHeader.setPadding(3f);
|
|
|
108 |
partBTable.addCell(partBHeader);
|
| 33741 |
amit.gupta |
109 |
|
| 36120 |
amit |
110 |
String[] headers = {"Mode", "Vehicle No.", "From", "Entered Date", "Entered By", "CEWB No.", "Multi Veh."};
|
|
|
111 |
for (String h : headers) {
|
|
|
112 |
PdfPCell hc = new PdfPCell(new Phrase(h, EWB_BOLD));
|
|
|
113 |
hc.setHorizontalAlignment(Element.ALIGN_CENTER);
|
|
|
114 |
hc.setBorderColor(EWB_BORDER);
|
|
|
115 |
hc.setBackgroundColor(EWB_HEADER_BG);
|
|
|
116 |
hc.setPadding(2f);
|
|
|
117 |
partBTable.addCell(hc);
|
|
|
118 |
}
|
|
|
119 |
|
| 33741 |
amit.gupta |
120 |
EWBPartBModel partBModel = eWayBillPdfModel.getEwbPartBModel();
|
| 36120 |
amit |
121 |
String[] data = {partBModel.getMode(), partBModel.getVehicleNumber(), partBModel.getFrom(),
|
|
|
122 |
partBModel.getEnteredDate(), partBModel.getEnteredBy(), "-", "-"};
|
|
|
123 |
for (String d : data) {
|
|
|
124 |
PdfPCell dc = new PdfPCell(new Phrase(d != null ? d : "-", EWB_NORMAL));
|
|
|
125 |
dc.setHorizontalAlignment(Element.ALIGN_CENTER);
|
|
|
126 |
dc.setBorderColor(EWB_BORDER);
|
|
|
127 |
dc.setPadding(2f);
|
|
|
128 |
partBTable.addCell(dc);
|
|
|
129 |
}
|
| 33741 |
amit.gupta |
130 |
|
|
|
131 |
document.add(partBTable);
|
|
|
132 |
}
|
|
|
133 |
|
| 36120 |
amit |
134 |
// Barcode
|
| 33741 |
amit.gupta |
135 |
Barcode128 barcode = new Barcode128();
|
|
|
136 |
barcode.setCode(eWayBillPdfModel.getEwbNumber());
|
|
|
137 |
barcode.setCodeType(Barcode.CODE128);
|
|
|
138 |
Image barcodeImage = barcode.createImageWithBarcode(writer.getDirectContent(), BaseColor.BLACK, BaseColor.BLACK);
|
|
|
139 |
barcodeImage.setAlignment(Element.ALIGN_CENTER);
|
| 36120 |
amit |
140 |
barcodeImage.scalePercent(120);
|
| 33741 |
amit.gupta |
141 |
document.add(barcodeImage);
|
|
|
142 |
|
|
|
143 |
} catch (Exception e) {
|
|
|
144 |
e.printStackTrace();
|
|
|
145 |
}
|
|
|
146 |
}
|
|
|
147 |
|
| 36120 |
amit |
148 |
private static void ewbRow(PdfPTable table, String label, String value) {
|
|
|
149 |
PdfPCell lc = new PdfPCell(new Phrase(label, EWB_BOLD));
|
|
|
150 |
lc.setHorizontalAlignment(Element.ALIGN_RIGHT);
|
|
|
151 |
lc.setBorderColor(EWB_BORDER);
|
|
|
152 |
lc.setPadding(3f);
|
|
|
153 |
table.addCell(lc);
|
|
|
154 |
PdfPCell vc = new PdfPCell(new Phrase(value != null ? value : "", EWB_NORMAL));
|
|
|
155 |
vc.setBorderColor(EWB_BORDER);
|
|
|
156 |
vc.setPadding(3f);
|
|
|
157 |
table.addCell(vc);
|
|
|
158 |
}
|
|
|
159 |
|
| 33741 |
amit.gupta |
160 |
private static PdfPCell getCell(String text, Font font) {
|
|
|
161 |
PdfPCell cell = new PdfPCell(new Phrase(text, font));
|
|
|
162 |
cell.setPadding(5);
|
|
|
163 |
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
|
|
|
164 |
cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
|
|
|
165 |
cell.setBorder(PdfPCell.BOX);
|
|
|
166 |
return cell;
|
|
|
167 |
}
|
|
|
168 |
}
|
|
|
169 |
|
|
|
170 |
|