| 21686 |
ashik.ali |
1 |
package com.spice.profitmandi.common.util;
|
|
|
2 |
|
| 29930 |
amit.gupta |
3 |
import com.ibm.icu.text.RuleBasedNumberFormat;
|
|
|
4 |
import com.itextpdf.text.*;
|
|
|
5 |
import com.itextpdf.text.Font.FontFamily;
|
|
|
6 |
import com.itextpdf.text.pdf.*;
|
| 35024 |
amit |
7 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 29930 |
amit.gupta |
8 |
import com.spice.profitmandi.common.model.*;
|
|
|
9 |
import org.apache.logging.log4j.LogManager;
|
|
|
10 |
import org.apache.logging.log4j.Logger;
|
|
|
11 |
import org.springframework.util.StringUtils;
|
|
|
12 |
|
| 24506 |
amit.gupta |
13 |
import java.io.ByteArrayInputStream;
|
|
|
14 |
import java.io.ByteArrayOutputStream;
|
|
|
15 |
import java.io.IOException;
|
| 21686 |
ashik.ali |
16 |
import java.io.OutputStream;
|
| 24506 |
amit.gupta |
17 |
import java.net.URL;
|
| 24854 |
amit.gupta |
18 |
import java.util.ArrayList;
|
| 23001 |
amit.gupta |
19 |
import java.util.List;
|
| 21915 |
ashik.ali |
20 |
import java.util.Locale;
|
| 21686 |
ashik.ali |
21 |
|
|
|
22 |
public class PdfUtils {
|
| 23509 |
amit.gupta |
23 |
|
| 32275 |
tejbeer |
24 |
private static final Font FONT_TITLE = new Font(Font.FontFamily.HELVETICA, 18, Font.BOLD);
|
|
|
25 |
private static Font FONT_NORMAL = new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL);
|
|
|
26 |
private static Font FONT_BOLD = new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.BOLD);
|
| 35799 |
amit |
27 |
private static Font FONT_MARGIN_HEADER = new Font(Font.FontFamily.HELVETICA, 9, Font.BOLDITALIC);
|
| 32275 |
tejbeer |
28 |
public static final String INVOICE_TITLE = "TAX INVOICE";
|
|
|
29 |
public static final String DEBIT_NOTE_TITLE = "DEBIT NOTE";
|
|
|
30 |
public static final String SECURITY_DEPOSIT = "SECURITY DEPOSIT RECEIPT";
|
| 23509 |
amit.gupta |
31 |
|
| 32275 |
tejbeer |
32 |
private static float[] igstWidthsWithDiscount = new float[]{.2f, 2.6f, 0.7f, .4f, 0.7f, 0.6f, .7f, .6f, 0.7f};
|
|
|
33 |
private static float[] stateWidthsWithDiscount = new float[]{.2f, 2.1f, 0.7f, .3f, 0.6f, 0.5f, .7f, .6f, .6f, .7f};
|
| 23509 |
amit.gupta |
34 |
|
| 35799 |
amit |
35 |
// Column widths without discount column (for Transaction.Order invoices)
|
|
|
36 |
private static float[] igstWidthsNoDiscount = new float[]{.2f, 2.8f, 0.7f, .4f, 0.8f, .7f, .6f, 0.8f};
|
|
|
37 |
private static float[] stateWidthsNoDiscount = new float[]{.2f, 2.3f, 0.7f, .4f, 0.7f, .7f, .6f, .6f, .8f};
|
|
|
38 |
|
| 32275 |
tejbeer |
39 |
private static float[] igstWidths = new float[]{.6f, 2.6f, 0.7f, .4f, 0.7f, .7f, .6f, 0.6f, 0.9f};
|
|
|
40 |
private static float[] stateWidths = new float[]{.6f, 2.1f, 0.7f, .3f, 0.6f, .7f, .5f, .6f, .5f, .6f, .8f};
|
| 23533 |
amit.gupta |
41 |
|
| 32275 |
tejbeer |
42 |
private static float[] igstWidthsCrNote = new float[]{2.6f, 0.7f, .4f, 0.7f, .7f, .6f, 0.6f, 0.9f};
|
|
|
43 |
private static float[] stateWidthsCrNote = new float[]{2.1f, 0.7f, .3f, 0.6f, .7f, .5f, .6f, .5f, .6f, .8f};
|
| 23654 |
amit.gupta |
44 |
|
| 36137 |
amit |
45 |
private static final Locale indianLocale = new Locale("en", "IN");
|
|
|
46 |
private static final java.text.NumberFormat indianCurrencyFormat = java.text.NumberFormat.getCurrencyInstance(new Locale("en", "IN"));
|
| 23509 |
amit.gupta |
47 |
|
| 32275 |
tejbeer |
48 |
private static final Logger LOGGER = LogManager.getLogger(PdfUtils.class);
|
| 23509 |
amit.gupta |
49 |
|
| 32275 |
tejbeer |
50 |
private static final URL iconUrl = PdfUtils.class.getClassLoader().getResource("sdlogo.png");
|
|
|
51 |
private static Image iconImg = null;
|
| 30400 |
amit.gupta |
52 |
|
| 32275 |
tejbeer |
53 |
static {
|
|
|
54 |
try {
|
|
|
55 |
iconImg = Image.getInstance(iconUrl);
|
|
|
56 |
} catch (Exception e) {
|
|
|
57 |
e.printStackTrace();
|
|
|
58 |
}
|
|
|
59 |
}
|
| 30400 |
amit.gupta |
60 |
|
| 32275 |
tejbeer |
61 |
//Debit Note generation logic has been changed
|
|
|
62 |
//Debit Note considers price drops so amount in debit note is current price of item.
|
|
|
63 |
//From 16Nov 2019 onwards all debit notes will be as per actuall billing value, all pricedrops
|
|
|
64 |
//shall be rolledback or cancelled once the debit note is generated.
|
| 25463 |
amit.gupta |
65 |
|
| 35035 |
amit |
66 |
public static void generateAndWrite(List<InvoicePdfModel> pdfModels, PrinterType printerType, ByteArrayOutputStream outputStream) throws ProfitMandiBusinessException {
|
| 35024 |
amit |
67 |
if (PrinterType.A4.equals(printerType)) {
|
|
|
68 |
generateAndWrite(pdfModels, outputStream);
|
|
|
69 |
} else {
|
|
|
70 |
if (pdfModels.size() > 1) {
|
|
|
71 |
}
|
|
|
72 |
if (PrinterType.W80.equals(printerType)) {
|
|
|
73 |
InvoiceFormatter.getInvoice(pdfModels.get(0), outputStream, InvoiceFormatter.WIDTH_80MM);
|
|
|
74 |
} else if (PrinterType.W58.equals(printerType)) {
|
|
|
75 |
InvoiceFormatter.getInvoice(pdfModels.get(0), outputStream, InvoiceFormatter.WIDTH_58MM);
|
| 30400 |
amit.gupta |
76 |
|
| 35024 |
amit |
77 |
}
|
|
|
78 |
}
|
| 35035 |
amit |
79 |
}
|
| 35024 |
amit |
80 |
|
|
|
81 |
|
|
|
82 |
//Standard
|
| 32275 |
tejbeer |
83 |
public static void generateAndWrite(List<InvoicePdfModel> pdfModels, ByteArrayOutputStream outputStream) {
|
|
|
84 |
try {
|
| 32991 |
amit.gupta |
85 |
boolean cancelledPages = false;
|
| 32275 |
tejbeer |
86 |
List<Integer> caneclledPageList = new ArrayList<>();
|
|
|
87 |
Document document = new Document();
|
|
|
88 |
document.setMargins(0, 0, 25, 0);
|
| 33741 |
amit.gupta |
89 |
PdfWriter pdfWriter = PdfWriter.getInstance(document, outputStream);
|
| 32275 |
tejbeer |
90 |
document.open();
|
|
|
91 |
for (InvoicePdfModel pdfModel : pdfModels) {
|
|
|
92 |
CustomCustomer customer = pdfModel.getCustomer();
|
|
|
93 |
CustomRetailer retailer = pdfModel.getRetailer();
|
|
|
94 |
boolean stateGst = false;
|
|
|
95 |
if (customer.getAddress().getState().equals(retailer.getAddress().getState())) {
|
|
|
96 |
stateGst = true;
|
|
|
97 |
}
|
| 33298 |
amit.gupta |
98 |
List<CustomOrderItem> orderItems = pdfModel.getOrderItems();
|
| 32275 |
tejbeer |
99 |
if (pdfModel.isCancelled()) {
|
|
|
100 |
caneclledPageList.add(1);
|
| 32991 |
amit.gupta |
101 |
cancelledPages = true;
|
| 32275 |
tejbeer |
102 |
} else {
|
|
|
103 |
caneclledPageList.add(0);
|
|
|
104 |
}
|
|
|
105 |
document.addTitle(pdfModel.getTitle());
|
|
|
106 |
document.addAuthor(pdfModel.getAuther());
|
| 22889 |
amit.gupta |
107 |
|
| 36044 |
amit |
108 |
String titleText = pdfModel.getTitle() != null ? pdfModel.getTitle().toUpperCase() : INVOICE_TITLE;
|
|
|
109 |
Paragraph paragraphTitle = new Paragraph(titleText, FONT_TITLE);
|
| 32275 |
tejbeer |
110 |
paragraphTitle.setAlignment(Element.ALIGN_CENTER);
|
| 21686 |
ashik.ali |
111 |
|
| 32980 |
amit.gupta |
112 |
document.add(paragraphTitle);
|
|
|
113 |
|
|
|
114 |
Rectangle rectangle = document.getPageSize();
|
|
|
115 |
|
|
|
116 |
if (pdfModel.getIrnModel() != null) {
|
|
|
117 |
addIrnDetails(pdfModel.getIrnModel(), rectangle, document);
|
|
|
118 |
}
|
|
|
119 |
|
|
|
120 |
|
|
|
121 |
PdfPTable tableCustomerRetailer = new PdfPTable(2);
|
| 32275 |
tejbeer |
122 |
tableCustomerRetailer.setWidthPercentage(90);
|
|
|
123 |
tableCustomerRetailer.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
|
|
124 |
PdfPCell columnCustomerInfo = new PdfPCell();
|
|
|
125 |
columnCustomerInfo.addElement(new Paragraph("Customer Details", FONT_BOLD));
|
|
|
126 |
columnCustomerInfo.addElement(new Paragraph(
|
|
|
127 |
StringUtils.capitalize(customer.getAddress().getName() + (customer.getAddress().getLastName() == null ? "" : " " + customer.getAddress().getLastName())), FONT_NORMAL));
|
| 32627 |
ranu |
128 |
if (customer.getAddress() != null) {
|
|
|
129 |
if ((customer.getAddress().getLine1() != null && !customer.getAddress().getLine1().trim().isEmpty()) || (customer.getAddress().getLine2() != null && !customer.getAddress().getLine2().trim().isEmpty())) {
|
|
|
130 |
columnCustomerInfo.addElement(new Paragraph(StringUtils.capitalize(customer.getAddress().getLine1()) + ", " + StringUtils.capitalize(customer.getAddress().getLine2()), FONT_NORMAL));
|
|
|
131 |
}
|
|
|
132 |
if ((customer.getAddress().getCity() != null && !customer.getAddress().getCity().trim().isEmpty()) || (customer.getAddress().getState() != null && !customer.getAddress().getState().trim().isEmpty())) {
|
|
|
133 |
columnCustomerInfo.addElement(new Paragraph(StringUtils.capitalize(customer.getAddress().getCity()) + ", " + StringUtils.capitalize(customer.getAddress().getState()) + "(" + pdfModel.getCustomerAddressStateCode() + ")" + "\n" + customer.getAddress().getPinCode(), FONT_NORMAL));
|
|
|
134 |
}
|
|
|
135 |
}
|
|
|
136 |
|
| 32275 |
tejbeer |
137 |
columnCustomerInfo.addElement(new Paragraph("Mobile - " + customer.getAddress().getPhoneNumber(), FONT_NORMAL));
|
|
|
138 |
if (customer.getGstNumber() != null && !customer.getGstNumber().isEmpty()) {
|
|
|
139 |
columnCustomerInfo.addElement(new Paragraph("GST Number - " + customer.getGstNumber(), FONT_NORMAL));
|
|
|
140 |
}
|
|
|
141 |
columnCustomerInfo.setBorder(Rectangle.NO_BORDER);
|
|
|
142 |
PdfPCell columnRetailerInfo = new PdfPCell();
|
|
|
143 |
columnRetailerInfo.addElement(new Paragraph(StringUtils.capitalize(retailer.getAddress().getName()), FONT_BOLD));
|
|
|
144 |
columnRetailerInfo.addElement(new Paragraph(StringUtils.capitalize(retailer.getAddress().getLine1()) + ", " + StringUtils.capitalize(retailer.getAddress().getLine2()) + ", " + StringUtils.capitalize(retailer.getAddress().getCity()) + "-" + retailer.getAddress().getPinCode() + ", " + retailer.getAddress().getState() + "(" + (stateGst ? pdfModel.getCustomerAddressStateCode() : pdfModel.getPartnerAddressStateCode()) + ")", FONT_BOLD));
|
|
|
145 |
columnRetailerInfo.addElement(new Paragraph("Contact No.- " + retailer.getAddress().getPhoneNumber(), FONT_BOLD));
|
|
|
146 |
columnRetailerInfo.addElement(new Paragraph("GST NO. " + retailer.getGstNumber(), FONT_BOLD));
|
|
|
147 |
columnRetailerInfo.setBorder(Rectangle.NO_BORDER);
|
| 23509 |
amit.gupta |
148 |
|
| 32275 |
tejbeer |
149 |
PdfPTable tableInvoiceDateRetailer = new PdfPTable(1);
|
|
|
150 |
tableInvoiceDateRetailer.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
| 23509 |
amit.gupta |
151 |
|
| 32275 |
tejbeer |
152 |
PdfPTable tableInvoiceDate = new PdfPTable(2);
|
|
|
153 |
tableInvoiceDate.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
| 23509 |
amit.gupta |
154 |
|
| 36037 |
amit |
155 |
String invoiceLabel = pdfModel.getTitle() != null && pdfModel.getTitle().toLowerCase().contains("challan") ? "DC No:" : "Invoice No:";
|
|
|
156 |
PdfPCell invoiceNumberKey = new PdfPCell(new Paragraph(invoiceLabel, FONT_NORMAL));
|
| 32275 |
tejbeer |
157 |
invoiceNumberKey.setBorder(Rectangle.NO_BORDER);
|
| 23509 |
amit.gupta |
158 |
|
| 32275 |
tejbeer |
159 |
PdfPCell invoiceNumberValue = new PdfPCell(new Paragraph(pdfModel.getInvoiceNumber(), FONT_NORMAL));
|
|
|
160 |
invoiceNumberValue.setBorder(Rectangle.NO_BORDER);
|
| 23509 |
amit.gupta |
161 |
|
| 32275 |
tejbeer |
162 |
PdfPCell dateKey = new PdfPCell(new Paragraph("Date:", FONT_NORMAL));
|
|
|
163 |
dateKey.setBorder(Rectangle.NO_BORDER);
|
| 23509 |
amit.gupta |
164 |
|
| 32275 |
tejbeer |
165 |
PdfPCell dateValue = new PdfPCell(new Paragraph(pdfModel.getInvoiceDate(), FONT_NORMAL));
|
|
|
166 |
dateValue.setBorder(Rectangle.NO_BORDER);
|
|
|
167 |
tableInvoiceDate.addCell(invoiceNumberKey);
|
|
|
168 |
tableInvoiceDate.addCell(invoiceNumberValue);
|
|
|
169 |
tableInvoiceDate.addCell(dateKey);
|
|
|
170 |
tableInvoiceDate.addCell(dateValue);
|
|
|
171 |
tableInvoiceDateRetailer.addCell(tableInvoiceDate);
|
|
|
172 |
tableInvoiceDateRetailer.addCell(columnRetailerInfo);
|
| 23509 |
amit.gupta |
173 |
|
| 32275 |
tejbeer |
174 |
tableCustomerRetailer.addCell(columnCustomerInfo);
|
|
|
175 |
tableCustomerRetailer.addCell(tableInvoiceDateRetailer);
|
| 23509 |
amit.gupta |
176 |
|
| 35799 |
amit |
177 |
boolean showDiscount = pdfModel.isShowDiscountColumn();
|
| 32275 |
tejbeer |
178 |
PdfPTable orders = null;
|
|
|
179 |
if (stateGst) {
|
| 35799 |
amit |
180 |
if (showDiscount) {
|
|
|
181 |
orders = new PdfPTable(stateWidthsWithDiscount.length);
|
|
|
182 |
orders.setWidths(stateWidthsWithDiscount);
|
|
|
183 |
} else {
|
|
|
184 |
orders = new PdfPTable(stateWidthsNoDiscount.length);
|
|
|
185 |
orders.setWidths(stateWidthsNoDiscount);
|
|
|
186 |
}
|
| 32275 |
tejbeer |
187 |
} else {
|
| 35799 |
amit |
188 |
if (showDiscount) {
|
|
|
189 |
orders = new PdfPTable(igstWidthsWithDiscount.length);
|
|
|
190 |
orders.setWidths(igstWidthsWithDiscount);
|
|
|
191 |
} else {
|
|
|
192 |
orders = new PdfPTable(igstWidthsNoDiscount.length);
|
|
|
193 |
orders.setWidths(igstWidthsNoDiscount);
|
|
|
194 |
}
|
| 32275 |
tejbeer |
195 |
}
|
|
|
196 |
orders.setWidthPercentage(90);
|
|
|
197 |
orders.addCell(new Paragraph("Sl", FONT_BOLD));
|
|
|
198 |
orders.addCell(new Paragraph("Description", FONT_BOLD));
|
|
|
199 |
orders.addCell(new Paragraph("HSN", FONT_BOLD));
|
|
|
200 |
orders.addCell(new Paragraph("Qty", FONT_BOLD));
|
|
|
201 |
orders.addCell(new Paragraph("Rate\n(Per pc)", FONT_BOLD));
|
| 35799 |
amit |
202 |
if (showDiscount) {
|
|
|
203 |
orders.addCell(new Paragraph("Discount", FONT_BOLD));
|
|
|
204 |
}
|
| 32275 |
tejbeer |
205 |
orders.addCell(new Paragraph("Total\nTaxable", FONT_BOLD));
|
|
|
206 |
if (!stateGst) {
|
|
|
207 |
orders.addCell(new Paragraph("IGST", FONT_BOLD));
|
|
|
208 |
} else {
|
|
|
209 |
orders.addCell(new Paragraph("CGST", FONT_BOLD));
|
|
|
210 |
orders.addCell(new Paragraph("SGST", FONT_BOLD));
|
|
|
211 |
}
|
|
|
212 |
orders.addCell(new Paragraph("Total", FONT_BOLD));
|
| 23509 |
amit.gupta |
213 |
|
| 32275 |
tejbeer |
214 |
orders.setHeaderRows(1);
|
| 23509 |
amit.gupta |
215 |
|
| 32275 |
tejbeer |
216 |
float igstTotalAmount = 0, cgstTotalAmount = 0, sgstTotalAmount = 0;
|
|
|
217 |
int index = 1;
|
|
|
218 |
for (CustomOrderItem orderItem : orderItems) {
|
|
|
219 |
orders.addCell(new Paragraph(String.valueOf(index++), FONT_NORMAL));
|
|
|
220 |
orders.addCell(new Paragraph(orderItem.getDescription(), FONT_NORMAL));
|
|
|
221 |
orders.addCell(new Paragraph(orderItem.getHsnCode(), FONT_NORMAL));
|
|
|
222 |
orders.addCell(new Paragraph(String.valueOf(orderItem.getQuantity()), FONT_NORMAL));
|
| 35799 |
amit |
223 |
|
| 36109 |
amit |
224 |
orders.addCell(new Paragraph(String.format("%.2f", orderItem.getRate()), FONT_NORMAL));
|
|
|
225 |
if (showDiscount) {
|
|
|
226 |
String discountText = orderItem.getDiscount() == 0 ? "-" : String.format("%.2f", orderItem.getDiscount());
|
|
|
227 |
orders.addCell(new Paragraph(discountText, FONT_NORMAL));
|
| 35799 |
amit |
228 |
}
|
| 32275 |
tejbeer |
229 |
orders.addCell(new Paragraph(String.format("%.2f", orderItem.getAmount()), FONT_NORMAL));
|
|
|
230 |
if (!stateGst) {
|
|
|
231 |
orders.addCell(new Paragraph(String.format("%.2f%n(@%.0f%%)", orderItem.getIgstAmount(), orderItem.getIgstRate()), FONT_NORMAL));
|
|
|
232 |
igstTotalAmount = igstTotalAmount + orderItem.getIgstAmount();
|
|
|
233 |
} else {
|
|
|
234 |
orders.addCell(new Paragraph(String.format("%.2f%n(@%.0f%%)", orderItem.getCgstAmount(), orderItem.getCgstRate()), FONT_NORMAL));
|
|
|
235 |
orders.addCell(new Paragraph(String.format("%.2f%n(@%.0f%%)", orderItem.getSgstAmount(), orderItem.getSgstRate()), FONT_NORMAL));
|
|
|
236 |
cgstTotalAmount = cgstTotalAmount + orderItem.getCgstAmount();
|
|
|
237 |
sgstTotalAmount = sgstTotalAmount + orderItem.getSgstAmount();
|
|
|
238 |
}
|
|
|
239 |
orders.addCell(new Paragraph(String.format("%.0f", orderItem.getNetAmount()), FONT_NORMAL));
|
|
|
240 |
}
|
|
|
241 |
if (pdfModel.getInsurancePolicies() != null) {
|
|
|
242 |
for (CustomInsurancePolicy insurancePolicy : pdfModel.getInsurancePolicies()) {
|
|
|
243 |
orders.addCell(new Paragraph(String.valueOf(index++), FONT_NORMAL));
|
|
|
244 |
orders.addCell(new Paragraph(insurancePolicy.getDescription(), FONT_NORMAL));
|
|
|
245 |
orders.addCell(new Paragraph(insurancePolicy.getHsnCode(), FONT_NORMAL));
|
|
|
246 |
orders.addCell(new Paragraph("1", FONT_NORMAL));
|
|
|
247 |
orders.addCell(new Paragraph(String.format("%.2f", insurancePolicy.getRate()), FONT_NORMAL));
|
| 35799 |
amit |
248 |
if (showDiscount) {
|
|
|
249 |
orders.addCell(new Paragraph("-", FONT_NORMAL));
|
|
|
250 |
}
|
| 32275 |
tejbeer |
251 |
orders.addCell(new Paragraph(String.format("%.2f", insurancePolicy.getRate()), FONT_NORMAL));
|
|
|
252 |
if (!stateGst) {
|
|
|
253 |
orders.addCell(new Paragraph(String.format("%.2f%n(@%.0f%%)", insurancePolicy.getIgstAmount(), insurancePolicy.getIgstRate()), FONT_NORMAL));
|
|
|
254 |
igstTotalAmount = igstTotalAmount + insurancePolicy.getIgstAmount();
|
|
|
255 |
} else {
|
|
|
256 |
orders.addCell(new Paragraph(String.format("%.2f%n(@%.0f%%)", insurancePolicy.getCgstAmount(), insurancePolicy.getCgstRate()), FONT_NORMAL));
|
|
|
257 |
orders.addCell(new Paragraph(String.format("%.2f%n(@%.0f%%)", insurancePolicy.getSgstAmount(), insurancePolicy.getSgstRate()), FONT_NORMAL));
|
|
|
258 |
cgstTotalAmount = cgstTotalAmount + insurancePolicy.getCgstAmount();
|
|
|
259 |
sgstTotalAmount = sgstTotalAmount + insurancePolicy.getSgstAmount();
|
|
|
260 |
}
|
|
|
261 |
orders.addCell(new Paragraph(String.format("%.0f", insurancePolicy.getNetAmount()), FONT_NORMAL));
|
|
|
262 |
}
|
|
|
263 |
}
|
| 32980 |
amit.gupta |
264 |
|
| 32275 |
tejbeer |
265 |
iconImg.setAbsolutePosition(25, rectangle.getHeight() - 100);
|
|
|
266 |
iconImg.scalePercent(30);
|
| 30400 |
amit.gupta |
267 |
|
| 32275 |
tejbeer |
268 |
document.add(iconImg);
|
|
|
269 |
document.add(Chunk.NEWLINE);
|
|
|
270 |
document.add(Chunk.NEWLINE);
|
|
|
271 |
document.add(tableCustomerRetailer);
|
| 23509 |
amit.gupta |
272 |
|
| 32275 |
tejbeer |
273 |
document.add(Chunk.NEWLINE);
|
|
|
274 |
document.add(orders);
|
| 23509 |
amit.gupta |
275 |
|
| 32275 |
tejbeer |
276 |
PdfPTable grandTotalTable = new PdfPTable(3);
|
|
|
277 |
PdfPTable paymentsTable = new PdfPTable(2);
|
|
|
278 |
paymentsTable.setWidthPercentage(95);
|
|
|
279 |
paymentsTable.setWidths(new float[]{8f, 2f});
|
| 23509 |
amit.gupta |
280 |
|
| 32275 |
tejbeer |
281 |
if (stateGst) {
|
|
|
282 |
grandTotalTable.setWidths(new float[]{6.6f, .6f, .8f});
|
|
|
283 |
} else {
|
|
|
284 |
grandTotalTable.setWidths(new float[]{6.5f, .6f, .9f});
|
|
|
285 |
}
|
|
|
286 |
grandTotalTable.setWidthPercentage(90);
|
| 23654 |
amit.gupta |
287 |
|
| 32275 |
tejbeer |
288 |
Paragraph grandTotalParagraph = new Paragraph("Grand total", FONT_BOLD);
|
|
|
289 |
grandTotalParagraph.setIndentationRight(20);
|
|
|
290 |
grandTotalTable.addCell(grandTotalParagraph);
|
|
|
291 |
Paragraph rsParagraph = new Paragraph("Rs.", FONT_BOLD);
|
|
|
292 |
grandTotalTable.addCell(rsParagraph);
|
|
|
293 |
Paragraph amountParagraph = new Paragraph(String.format("%.2f", pdfModel.getTotalAmount()), FONT_BOLD);
|
|
|
294 |
grandTotalTable.addCell(amountParagraph);
|
| 24845 |
amit.gupta |
295 |
|
| 32275 |
tejbeer |
296 |
document.add(grandTotalTable);
|
| 24845 |
amit.gupta |
297 |
|
| 32275 |
tejbeer |
298 |
PdfPTable amountInWordsTable = new PdfPTable(3);
|
|
|
299 |
amountInWordsTable.setWidthPercentage(90);
|
|
|
300 |
amountInWordsTable.addCell(new Paragraph("Amount in Words:", FONT_BOLD));
|
|
|
301 |
if (!stateGst) {
|
|
|
302 |
amountInWordsTable.setWidths(new float[]{2, 5.1f, 0.9f});
|
|
|
303 |
} else {
|
|
|
304 |
amountInWordsTable.setWidths(new float[]{2, 5.2f, 0.8f});
|
|
|
305 |
}
|
| 23509 |
amit.gupta |
306 |
|
| 32275 |
tejbeer |
307 |
String amountInWords = toAmountInWords(pdfModel.getTotalAmount());
|
|
|
308 |
amountInWordsTable.addCell(new Paragraph(amountInWords.toString(), FONT_BOLD));
|
|
|
309 |
amountInWordsTable.addCell(new Paragraph("E & O.E", FONT_NORMAL));
|
|
|
310 |
document.add(amountInWordsTable);
|
| 23654 |
amit.gupta |
311 |
|
| 32275 |
tejbeer |
312 |
if (pdfModel.getPaymentOptions() != null) {
|
|
|
313 |
PdfPTable paidAmountTable = new PdfPTable(2);
|
|
|
314 |
paidAmountTable.setWidthPercentage(90);
|
|
|
315 |
if (!stateGst) {
|
|
|
316 |
paidAmountTable.setWidths(new float[]{7.1f, 0.9f});
|
|
|
317 |
} else {
|
|
|
318 |
paidAmountTable.setWidths(new float[]{7.2f, 0.8f});
|
|
|
319 |
}
|
|
|
320 |
float totalPaidValue = 0;
|
|
|
321 |
for (CustomPaymentOption paymentOption : pdfModel.getPaymentOptions()) {
|
| 33795 |
ranu |
322 |
LOGGER.info("paymentOption - {}", paymentOption);
|
|
|
323 |
if (!"CASH DISCOUNT".equals(paymentOption.getPaymentOption())) {
|
|
|
324 |
PdfPCell cell = new PdfPCell(
|
|
|
325 |
new Paragraph(10, "Paid Through " + paymentOption.getPaymentOption(), FONT_BOLD));
|
|
|
326 |
cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
|
|
|
327 |
cell.setPadding(5);
|
|
|
328 |
paidAmountTable.addCell(cell);
|
| 23654 |
amit.gupta |
329 |
|
| 33795 |
ranu |
330 |
PdfPCell cell1 = new PdfPCell(new Paragraph(10, FormattingUtils.formatDecimal(paymentOption.getAmount()), FONT_BOLD));
|
|
|
331 |
cell1.setPadding(5);
|
|
|
332 |
paidAmountTable.addCell(cell1);
|
|
|
333 |
totalPaidValue += paymentOption.getAmount();
|
|
|
334 |
}
|
| 32275 |
tejbeer |
335 |
}
|
|
|
336 |
PdfPCell totalPaidCell = new PdfPCell(new Paragraph(10, "Total Paid", FONT_BOLD));
|
|
|
337 |
totalPaidCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
|
|
|
338 |
totalPaidCell.setPadding(5);
|
|
|
339 |
paidAmountTable.addCell(totalPaidCell);
|
| 23558 |
amit.gupta |
340 |
|
| 32275 |
tejbeer |
341 |
PdfPCell totalPaidValueCell = new PdfPCell(
|
|
|
342 |
new Paragraph(10, FormattingUtils.formatDecimal(totalPaidValue), FONT_BOLD));
|
|
|
343 |
totalPaidValueCell.setPadding(5);
|
|
|
344 |
paidAmountTable.addCell(totalPaidValueCell);
|
| 23509 |
amit.gupta |
345 |
|
| 32275 |
tejbeer |
346 |
document.add(paidAmountTable);
|
|
|
347 |
}
|
| 36045 |
amit |
348 |
String docType = pdfModel.getTitle() != null && pdfModel.getTitle().toLowerCase().contains("challan") ? "Delivery Challan" : "Invoice";
|
|
|
349 |
Paragraph autoGenerateParagraph = new Paragraph("Note - This is computer generated " + docType + ", no signature is required", FONT_NORMAL);
|
| 32980 |
amit.gupta |
350 |
autoGenerateParagraph.setAlignment(Element.ALIGN_CENTER);
|
|
|
351 |
document.add(autoGenerateParagraph);
|
| 24845 |
amit.gupta |
352 |
|
| 35024 |
amit |
353 |
if(pdfModel.getCreditTerms()!=null) {
|
| 35025 |
amit |
354 |
Paragraph title = new Paragraph("Credit terms :-\n", FONT_BOLD);
|
| 35024 |
amit |
355 |
title.setIndentationLeft(25);
|
|
|
356 |
title.setIndentationRight(25);
|
|
|
357 |
document.add(title);
|
|
|
358 |
|
|
|
359 |
StringBuffer termsBuffer = new StringBuffer();
|
|
|
360 |
int count = 0;
|
|
|
361 |
for (String creditTerm : pdfModel.getCreditTerms()) {
|
|
|
362 |
count++;
|
|
|
363 |
termsBuffer.append(count).append(". ").append(creditTerm).append(".\n");
|
|
|
364 |
}
|
|
|
365 |
|
| 35025 |
amit |
366 |
Paragraph body = new Paragraph(termsBuffer.toString(), FONT_NORMAL);
|
| 35024 |
amit |
367 |
body.setIndentationLeft(25);
|
|
|
368 |
body.setIndentationRight(25);
|
|
|
369 |
document.add(body);
|
|
|
370 |
|
|
|
371 |
}
|
| 35799 |
amit |
372 |
|
| 32275 |
tejbeer |
373 |
if (pdfModel.getTncs() != null) {
|
|
|
374 |
StringBuffer sb = new StringBuffer();
|
|
|
375 |
for (String tnc : pdfModel.getTncs()) {
|
|
|
376 |
sb.append(tnc).append("\n");
|
|
|
377 |
}
|
|
|
378 |
Paragraph warningParagraph = new Paragraph(sb.toString(), FONT_NORMAL);
|
|
|
379 |
warningParagraph.setIndentationLeft(40);
|
|
|
380 |
document.add(Chunk.NEWLINE);
|
|
|
381 |
document.add(warningParagraph);
|
|
|
382 |
}
|
| 24845 |
amit.gupta |
383 |
|
| 32275 |
tejbeer |
384 |
document.newPage();
|
| 35024 |
amit |
385 |
if (pdfModel.geteWayBillPdfModel() != null) {
|
| 33741 |
amit.gupta |
386 |
|
|
|
387 |
EWayBillPDF.generateDocument(document, pdfWriter, pdfModel.geteWayBillPdfModel());
|
|
|
388 |
}
|
| 32275 |
tejbeer |
389 |
}
|
|
|
390 |
document.close(); // no need to close PDFwriter?
|
| 35024 |
amit |
391 |
if (cancelledPages) {
|
| 32991 |
amit.gupta |
392 |
stampCancelled(outputStream, caneclledPageList);
|
|
|
393 |
}
|
| 23509 |
amit.gupta |
394 |
|
| 32275 |
tejbeer |
395 |
} catch (DocumentException e) {
|
|
|
396 |
LOGGER.error("Unable to write data to pdf file : ", e);
|
|
|
397 |
} catch (Exception e) {
|
|
|
398 |
// TODO Auto-generated catch block
|
|
|
399 |
e.printStackTrace();
|
|
|
400 |
}
|
| 24506 |
amit.gupta |
401 |
|
| 32275 |
tejbeer |
402 |
}
|
| 23509 |
amit.gupta |
403 |
|
| 32980 |
amit.gupta |
404 |
private static void addIrnDetails(IrnModel irnModel, Rectangle rectangle, Document document) throws IOException, DocumentException {
|
|
|
405 |
PdfPTable taxTable = new PdfPTable(1);
|
|
|
406 |
taxTable.setWidthPercentage(45);
|
|
|
407 |
PdfPCell pdfCell = new PdfPCell();
|
|
|
408 |
pdfCell.setBorder(Rectangle.NO_BORDER);
|
|
|
409 |
Image img = Image.getInstance(irnModel.getQrCode().toURI().toURL());
|
|
|
410 |
img.setAbsolutePosition(450f, rectangle.getHeight() - 140);
|
|
|
411 |
document.add(img);
|
|
|
412 |
Paragraph irnParagraph = new Paragraph("IRN No - " + irnModel.getIrnNumber(), FONT_NORMAL);
|
|
|
413 |
irnParagraph.setAlignment(Element.ALIGN_LEFT);
|
|
|
414 |
pdfCell.addElement(irnParagraph);
|
|
|
415 |
|
| 35024 |
amit |
416 |
Paragraph ackParagraph = new Paragraph("Ack No - " + irnModel.getAcknowledgeNumber(), FONT_NORMAL);
|
| 32980 |
amit.gupta |
417 |
ackParagraph.setAlignment(Element.ALIGN_LEFT);
|
|
|
418 |
pdfCell.addElement(ackParagraph);
|
|
|
419 |
|
|
|
420 |
Paragraph ackDateParagraph = new Paragraph("Ack Date - " + FormattingUtils.format(irnModel.getAcknowledgeDate()), FONT_NORMAL);
|
|
|
421 |
ackDateParagraph.setAlignment(Element.ALIGN_LEFT);
|
|
|
422 |
pdfCell.addElement(ackDateParagraph);
|
|
|
423 |
taxTable.addCell(pdfCell);
|
|
|
424 |
document.add(taxTable);
|
|
|
425 |
}
|
|
|
426 |
|
| 35799 |
amit |
427 |
private static void addMarginSchemeSeparator(PdfPTable table, int numColumns) {
|
|
|
428 |
PdfPCell separatorCell = new PdfPCell(new Paragraph("Items under Margin Scheme \u2013 Rule 32(5) of CGST Rules, 2017", FONT_MARGIN_HEADER));
|
|
|
429 |
separatorCell.setColspan(numColumns);
|
|
|
430 |
separatorCell.setBackgroundColor(new BaseColor(240, 240, 240));
|
|
|
431 |
separatorCell.setPadding(5);
|
|
|
432 |
separatorCell.setHorizontalAlignment(Element.ALIGN_CENTER);
|
|
|
433 |
table.addCell(separatorCell);
|
|
|
434 |
}
|
|
|
435 |
|
|
|
436 |
private static void addMarginSchemeDeclaration(Document document, InvoicePdfModel pdfModel) throws DocumentException {
|
|
|
437 |
if (pdfModel.getMarginSchemeDeclarations() != null && !pdfModel.getMarginSchemeDeclarations().isEmpty()) {
|
|
|
438 |
document.add(Chunk.NEWLINE);
|
|
|
439 |
Paragraph declarationTitle = new Paragraph("Margin Scheme Declaration:", FONT_BOLD);
|
|
|
440 |
declarationTitle.setIndentationLeft(25);
|
|
|
441 |
document.add(declarationTitle);
|
|
|
442 |
for (String declaration : pdfModel.getMarginSchemeDeclarations()) {
|
|
|
443 |
Paragraph declarationParagraph = new Paragraph("- " + declaration, FONT_NORMAL);
|
|
|
444 |
declarationParagraph.setIndentationLeft(30);
|
|
|
445 |
document.add(declarationParagraph);
|
|
|
446 |
}
|
|
|
447 |
}
|
|
|
448 |
}
|
|
|
449 |
|
| 36116 |
amit |
450 |
// ── Margin Scheme Invoice Helpers ──────────────────────────────────────
|
|
|
451 |
private static final BaseColor MS_BORDER = new BaseColor(204, 204, 204);
|
|
|
452 |
private static final BaseColor MS_HEADER_BG = new BaseColor(242, 242, 242);
|
|
|
453 |
private static final BaseColor MS_TOTAL_BG = new BaseColor(249, 249, 249);
|
|
|
454 |
private static final BaseColor MS_SUMM_BG = new BaseColor(242, 242, 242);
|
|
|
455 |
|
|
|
456 |
private static final Font MS_TITLE = new Font(Font.FontFamily.HELVETICA, 13, Font.BOLD);
|
|
|
457 |
private static final Font MS_SUBTITLE = new Font(Font.FontFamily.HELVETICA, 7.5f, Font.ITALIC, new BaseColor(51, 51, 51));
|
|
|
458 |
private static final Font MS_SECTION = new Font(Font.FontFamily.HELVETICA, 6.5f, Font.BOLD, new BaseColor(85, 85, 85));
|
|
|
459 |
private static final Font MS_NORMAL = new Font(Font.FontFamily.HELVETICA, 8, Font.NORMAL);
|
|
|
460 |
private static final Font MS_BOLD = new Font(Font.FontFamily.HELVETICA, 8, Font.BOLD);
|
|
|
461 |
private static final Font MS_SMALL = new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL, new BaseColor(68, 68, 68));
|
|
|
462 |
private static final Font MS_SMALL_BOLD = new Font(Font.FontFamily.HELVETICA, 7, Font.BOLD);
|
|
|
463 |
private static final Font MS_ITALIC = new Font(Font.FontFamily.HELVETICA, 7.5f, Font.ITALIC);
|
|
|
464 |
private static final Font MS_TBL_HDR = new Font(Font.FontFamily.HELVETICA, 7, Font.BOLD);
|
|
|
465 |
|
|
|
466 |
private static Paragraph msSpacer(float spacing) {
|
|
|
467 |
Paragraph p = new Paragraph(" ");
|
|
|
468 |
p.setSpacingAfter(spacing);
|
|
|
469 |
p.setLeading(0f);
|
|
|
470 |
return p;
|
|
|
471 |
}
|
|
|
472 |
|
|
|
473 |
private static Paragraph msRightPara(String text, Font font) {
|
|
|
474 |
Paragraph p = new Paragraph(text, font);
|
|
|
475 |
p.setAlignment(Element.ALIGN_RIGHT);
|
|
|
476 |
return p;
|
|
|
477 |
}
|
|
|
478 |
|
|
|
479 |
private static void msAddHeader(PdfPTable table, String text, int align) {
|
|
|
480 |
PdfPCell cell = new PdfPCell(new Phrase(text, MS_TBL_HDR));
|
|
|
481 |
cell.setHorizontalAlignment(align);
|
|
|
482 |
cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
|
|
|
483 |
cell.setBackgroundColor(MS_HEADER_BG);
|
|
|
484 |
cell.setBorderColor(MS_BORDER);
|
|
|
485 |
cell.setPadding(4f);
|
|
|
486 |
table.addCell(cell);
|
|
|
487 |
}
|
|
|
488 |
|
|
|
489 |
private static void msAddDataCell(PdfPTable table, String text, int align, boolean bold, boolean totalRow) {
|
|
|
490 |
Font font = bold ? MS_BOLD : MS_NORMAL;
|
|
|
491 |
PdfPCell cell = new PdfPCell();
|
|
|
492 |
cell.setHorizontalAlignment(align);
|
|
|
493 |
cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
|
|
|
494 |
cell.setBorderColor(MS_BORDER);
|
|
|
495 |
if (totalRow) cell.setBackgroundColor(MS_TOTAL_BG);
|
|
|
496 |
cell.setPadding(4f);
|
|
|
497 |
String[] lines = text.split("\n");
|
|
|
498 |
for (String line : lines) {
|
|
|
499 |
Paragraph p = new Paragraph(line, font);
|
|
|
500 |
p.setAlignment(align);
|
|
|
501 |
p.setLeading(11f);
|
|
|
502 |
cell.addElement(p);
|
|
|
503 |
}
|
|
|
504 |
table.addCell(cell);
|
|
|
505 |
}
|
|
|
506 |
|
|
|
507 |
private static void msAddSummaryRow(PdfPTable table, String label, String value, boolean highlight) {
|
|
|
508 |
Font lf = highlight ? MS_BOLD : MS_NORMAL;
|
|
|
509 |
Font vf = highlight ? MS_BOLD : MS_NORMAL;
|
|
|
510 |
BaseColor bg = highlight ? MS_SUMM_BG : BaseColor.WHITE;
|
|
|
511 |
PdfPCell lc = new PdfPCell(new Phrase(label, lf));
|
|
|
512 |
lc.setBorderColor(MS_BORDER);
|
|
|
513 |
lc.setPadding(5f);
|
|
|
514 |
lc.setBackgroundColor(bg);
|
|
|
515 |
table.addCell(lc);
|
|
|
516 |
PdfPCell vc = new PdfPCell(new Phrase(value, vf));
|
|
|
517 |
vc.setHorizontalAlignment(Element.ALIGN_RIGHT);
|
|
|
518 |
vc.setBorderColor(MS_BORDER);
|
|
|
519 |
vc.setPadding(5f);
|
|
|
520 |
vc.setBackgroundColor(bg);
|
|
|
521 |
table.addCell(vc);
|
|
|
522 |
}
|
|
|
523 |
|
| 36109 |
amit |
524 |
public static void generateMarginSchemeInvoice(List<InvoicePdfModel> pdfModels, ByteArrayOutputStream outputStream) {
|
| 36116 |
amit |
525 |
generateInvoiceV2(pdfModels, outputStream);
|
|
|
526 |
}
|
|
|
527 |
|
|
|
528 |
public static void generateInvoiceV2(List<InvoicePdfModel> pdfModels, ByteArrayOutputStream outputStream) {
|
| 36109 |
amit |
529 |
try {
|
|
|
530 |
boolean cancelledPages = false;
|
|
|
531 |
List<Integer> cancelledPageList = new ArrayList<>();
|
| 36116 |
amit |
532 |
Document document = new Document(PageSize.A4, 28, 28, 34, 34);
|
| 36109 |
amit |
533 |
PdfWriter pdfWriter = PdfWriter.getInstance(document, outputStream);
|
|
|
534 |
document.open();
|
|
|
535 |
|
|
|
536 |
for (InvoicePdfModel pdfModel : pdfModels) {
|
|
|
537 |
CustomCustomer customer = pdfModel.getCustomer();
|
|
|
538 |
CustomRetailer retailer = pdfModel.getRetailer();
|
|
|
539 |
boolean stateGst = customer.getAddress().getState().equals(retailer.getAddress().getState());
|
| 36116 |
amit |
540 |
String stateCode = stateGst ? pdfModel.getCustomerAddressStateCode() : pdfModel.getPartnerAddressStateCode();
|
|
|
541 |
List<CustomOrderItem> orderItems = pdfModel.getOrderItems();
|
|
|
542 |
boolean isMargin = pdfModel.isHasMarginSchemeItems();
|
| 36109 |
amit |
543 |
|
|
|
544 |
if (pdfModel.isCancelled()) {
|
|
|
545 |
cancelledPageList.add(1);
|
|
|
546 |
cancelledPages = true;
|
|
|
547 |
} else {
|
|
|
548 |
cancelledPageList.add(0);
|
|
|
549 |
}
|
|
|
550 |
|
| 36116 |
amit |
551 |
// ── Header: Logo (left) + Title (center) + QR (right) ─────
|
|
|
552 |
Rectangle rectangle = document.getPageSize();
|
|
|
553 |
String titleText = pdfModel.getTitle() != null ? pdfModel.getTitle().toUpperCase() : "TAX INVOICE";
|
| 36109 |
amit |
554 |
|
| 36116 |
amit |
555 |
PdfPTable headerBanner = new PdfPTable(3);
|
|
|
556 |
headerBanner.setWidthPercentage(100);
|
|
|
557 |
headerBanner.setWidths(new float[]{1.2f, 4f, 1.2f});
|
|
|
558 |
headerBanner.setSpacingAfter(4f);
|
| 36109 |
amit |
559 |
|
| 36116 |
amit |
560 |
// Left: Logo
|
|
|
561 |
PdfPCell logoCell = new PdfPCell();
|
|
|
562 |
logoCell.setBorder(Rectangle.NO_BORDER);
|
|
|
563 |
logoCell.setPadding(4f);
|
|
|
564 |
logoCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
|
|
|
565 |
Image logoImg = Image.getInstance(iconImg);
|
|
|
566 |
logoImg.scalePercent(25);
|
|
|
567 |
logoCell.addElement(logoImg);
|
|
|
568 |
headerBanner.addCell(logoCell);
|
| 36111 |
amit |
569 |
|
| 36116 |
amit |
570 |
// Center: Title + subtitle
|
|
|
571 |
PdfPCell titleCell = new PdfPCell();
|
|
|
572 |
titleCell.setBorder(Rectangle.NO_BORDER);
|
|
|
573 |
titleCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
|
|
|
574 |
titleCell.setHorizontalAlignment(Element.ALIGN_CENTER);
|
|
|
575 |
Paragraph title = new Paragraph(titleText, MS_TITLE);
|
|
|
576 |
title.setAlignment(Element.ALIGN_CENTER);
|
|
|
577 |
titleCell.addElement(title);
|
|
|
578 |
if (isMargin) {
|
|
|
579 |
Paragraph subtitle = new Paragraph(
|
|
|
580 |
"(GST Payable on Margin Scheme Basis \u2014 ITC not admissible to buyer)", MS_SUBTITLE);
|
|
|
581 |
subtitle.setAlignment(Element.ALIGN_CENTER);
|
|
|
582 |
titleCell.addElement(subtitle);
|
|
|
583 |
}
|
|
|
584 |
headerBanner.addCell(titleCell);
|
| 36109 |
amit |
585 |
|
| 36116 |
amit |
586 |
// Right: QR code (or empty)
|
|
|
587 |
PdfPCell qrCell = new PdfPCell();
|
|
|
588 |
qrCell.setBorder(Rectangle.NO_BORDER);
|
|
|
589 |
qrCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
|
|
|
590 |
qrCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
|
|
|
591 |
if (pdfModel.getIrnModel() != null && pdfModel.getIrnModel().getQrCode() != null) {
|
|
|
592 |
Image qrImg = Image.getInstance(pdfModel.getIrnModel().getQrCode().toURI().toURL());
|
|
|
593 |
qrImg.scaleAbsolute(80, 80);
|
|
|
594 |
qrCell.addElement(qrImg);
|
| 36109 |
amit |
595 |
}
|
| 36116 |
amit |
596 |
headerBanner.addCell(qrCell);
|
| 36109 |
amit |
597 |
|
| 36116 |
amit |
598 |
document.add(headerBanner);
|
| 36109 |
amit |
599 |
|
| 36116 |
amit |
600 |
// ── IRN Details (full width below header) ──────────────────
|
|
|
601 |
if (pdfModel.getIrnModel() != null) {
|
|
|
602 |
PdfPTable irnTable = new PdfPTable(1);
|
|
|
603 |
irnTable.setWidthPercentage(100);
|
|
|
604 |
irnTable.setSpacingAfter(8f);
|
|
|
605 |
|
|
|
606 |
PdfPCell irnCell = new PdfPCell();
|
|
|
607 |
irnCell.setBorder(Rectangle.BOTTOM);
|
|
|
608 |
irnCell.setBorderColor(MS_BORDER);
|
|
|
609 |
irnCell.setPadding(3f);
|
|
|
610 |
irnCell.addElement(new Paragraph("IRN: " + pdfModel.getIrnModel().getIrnNumber(), MS_SMALL));
|
|
|
611 |
irnCell.addElement(new Paragraph("Ack No: " + pdfModel.getIrnModel().getAcknowledgeNumber(), MS_SMALL));
|
|
|
612 |
irnCell.addElement(new Paragraph("Ack Date: " + FormattingUtils.format(pdfModel.getIrnModel().getAcknowledgeDate()), MS_SMALL));
|
|
|
613 |
irnTable.addCell(irnCell);
|
|
|
614 |
|
|
|
615 |
document.add(irnTable);
|
| 36109 |
amit |
616 |
}
|
|
|
617 |
|
| 36116 |
amit |
618 |
// ── Supplier (left) + Invoice Details (right) ──────────────
|
|
|
619 |
PdfPTable headerTable = new PdfPTable(2);
|
|
|
620 |
headerTable.setWidthPercentage(100);
|
|
|
621 |
headerTable.setWidths(new float[]{1f, 1f});
|
|
|
622 |
headerTable.setSpacingAfter(8f);
|
| 36109 |
amit |
623 |
|
| 36116 |
amit |
624 |
PdfPCell supplierCell = new PdfPCell();
|
|
|
625 |
supplierCell.setBorder(Rectangle.NO_BORDER);
|
|
|
626 |
supplierCell.setPadding(4f);
|
|
|
627 |
supplierCell.setPaddingLeft(0f);
|
|
|
628 |
supplierCell.addElement(new Paragraph("SUPPLIER DETAILS", MS_SECTION));
|
|
|
629 |
supplierCell.addElement(msSpacer(2f));
|
|
|
630 |
supplierCell.addElement(new Paragraph(StringUtils.capitalize(retailer.getAddress().getName()), MS_BOLD));
|
|
|
631 |
supplierCell.addElement(new Paragraph(
|
|
|
632 |
StringUtils.capitalize(retailer.getAddress().getLine1()) + ", "
|
|
|
633 |
+ StringUtils.capitalize(retailer.getAddress().getLine2()) + ", "
|
|
|
634 |
+ StringUtils.capitalize(retailer.getAddress().getCity()) + " - "
|
|
|
635 |
+ retailer.getAddress().getPinCode(), MS_NORMAL));
|
|
|
636 |
supplierCell.addElement(new Paragraph("GSTIN: " + retailer.getGstNumber(), MS_NORMAL));
|
|
|
637 |
supplierCell.addElement(new Paragraph("State: " + retailer.getAddress().getState()
|
|
|
638 |
+ " | Code: " + stateCode, MS_NORMAL));
|
|
|
639 |
headerTable.addCell(supplierCell);
|
| 36109 |
amit |
640 |
|
| 36138 |
amit |
641 |
boolean isChallan = titleText.contains("CHALLAN");
|
| 36145 |
amit |
642 |
boolean isCreditNote = titleText.contains("CREDIT");
|
|
|
643 |
String docLabel = isCreditNote ? "CN No:" : (isChallan ? "Challan No:" : "Invoice No:");
|
|
|
644 |
String sectionLabel = isCreditNote ? "CREDIT NOTE DETAILS" : (isChallan ? "CHALLAN DETAILS" : "INVOICE DETAILS");
|
| 36116 |
amit |
645 |
PdfPCell invoiceCell = new PdfPCell();
|
|
|
646 |
invoiceCell.setBorder(Rectangle.NO_BORDER);
|
|
|
647 |
invoiceCell.setPadding(4f);
|
|
|
648 |
invoiceCell.setPaddingRight(0f);
|
| 36138 |
amit |
649 |
invoiceCell.addElement(msRightPara(sectionLabel, MS_SECTION));
|
| 36116 |
amit |
650 |
invoiceCell.addElement(msSpacer(2f));
|
| 36138 |
amit |
651 |
invoiceCell.addElement(msRightPara(docLabel + " " + pdfModel.getInvoiceNumber(), MS_BOLD));
|
| 36116 |
amit |
652 |
invoiceCell.addElement(msRightPara("Date: " + pdfModel.getInvoiceDate(), MS_NORMAL));
|
|
|
653 |
String supplyType = stateGst ? "Intra-state" : "Inter-state";
|
|
|
654 |
invoiceCell.addElement(msRightPara("Place of supply: " + customer.getAddress().getState()
|
|
|
655 |
+ " (" + pdfModel.getCustomerAddressStateCode() + ")", MS_NORMAL));
|
|
|
656 |
invoiceCell.addElement(msRightPara("Supply type: " + supplyType, MS_NORMAL));
|
|
|
657 |
headerTable.addCell(invoiceCell);
|
| 36109 |
amit |
658 |
|
| 36116 |
amit |
659 |
document.add(headerTable);
|
| 36109 |
amit |
660 |
|
| 36116 |
amit |
661 |
// ── Buyer Details ──────────────────────────────────────────
|
|
|
662 |
PdfPTable buyerTable = new PdfPTable(1);
|
|
|
663 |
buyerTable.setWidthPercentage(100);
|
|
|
664 |
buyerTable.setSpacingAfter(8f);
|
| 36109 |
amit |
665 |
|
| 36116 |
amit |
666 |
PdfPCell buyerCell = new PdfPCell();
|
|
|
667 |
buyerCell.setBorder(Rectangle.BOX);
|
|
|
668 |
buyerCell.setBorderColor(MS_BORDER);
|
|
|
669 |
buyerCell.setPadding(5f);
|
|
|
670 |
buyerCell.addElement(new Paragraph("BUYER DETAILS", MS_SECTION));
|
|
|
671 |
buyerCell.addElement(msSpacer(2f));
|
|
|
672 |
String buyerName = StringUtils.capitalize(customer.getAddress().getName()
|
|
|
673 |
+ (customer.getAddress().getLastName() == null ? "" : " " + customer.getAddress().getLastName()));
|
|
|
674 |
buyerCell.addElement(new Paragraph(buyerName, MS_BOLD));
|
|
|
675 |
if (customer.getAddress().getLine1() != null || customer.getAddress().getLine2() != null) {
|
|
|
676 |
String addr = "";
|
|
|
677 |
if (customer.getAddress().getLine1() != null) addr += StringUtils.capitalize(customer.getAddress().getLine1());
|
|
|
678 |
if (customer.getAddress().getLine2() != null) addr += ", " + StringUtils.capitalize(customer.getAddress().getLine2());
|
|
|
679 |
buyerCell.addElement(new Paragraph(addr, MS_NORMAL));
|
|
|
680 |
}
|
|
|
681 |
String buyerLocation = StringUtils.capitalize(customer.getAddress().getCity()) + ", "
|
|
|
682 |
+ customer.getAddress().getState() + " - " + customer.getAddress().getPinCode();
|
|
|
683 |
buyerCell.addElement(new Paragraph(buyerLocation, MS_NORMAL));
|
|
|
684 |
String buyerGstLine = "";
|
|
|
685 |
if (customer.getGstNumber() != null && !customer.getGstNumber().isEmpty()) {
|
|
|
686 |
buyerGstLine += "GSTIN: " + customer.getGstNumber() + " | ";
|
|
|
687 |
}
|
|
|
688 |
buyerGstLine += "State: " + customer.getAddress().getState()
|
|
|
689 |
+ " (Code: " + pdfModel.getCustomerAddressStateCode() + ")";
|
|
|
690 |
buyerCell.addElement(new Paragraph(buyerGstLine, MS_NORMAL));
|
|
|
691 |
if (customer.getAddress().getPhoneNumber() != null) {
|
|
|
692 |
buyerCell.addElement(new Paragraph("Mobile: " + customer.getAddress().getPhoneNumber(), MS_NORMAL));
|
|
|
693 |
}
|
|
|
694 |
buyerTable.addCell(buyerCell);
|
|
|
695 |
document.add(buyerTable);
|
| 36109 |
amit |
696 |
|
| 36116 |
amit |
697 |
// ── Item Table ─────────────────────────────────────────────
|
|
|
698 |
PdfPTable itemTable;
|
|
|
699 |
// 10 columns for both margin and regular
|
|
|
700 |
itemTable = new PdfPTable(10);
|
| 36120 |
amit |
701 |
itemTable.setWidths(new float[]{0.7f, 1.4f, 3.5f, 1.2f, 0.6f, 1.8f, 1.8f, 2.4f, 1.6f, 1.6f});
|
| 36116 |
amit |
702 |
itemTable.setWidthPercentage(100);
|
|
|
703 |
itemTable.setSpacingAfter(0f);
|
|
|
704 |
itemTable.setHeaderRows(1);
|
| 36109 |
amit |
705 |
|
| 36116 |
amit |
706 |
msAddHeader(itemTable, "S.No.", Element.ALIGN_CENTER);
|
|
|
707 |
msAddHeader(itemTable, "Order Id", Element.ALIGN_CENTER);
|
|
|
708 |
msAddHeader(itemTable, "Description of Goods", Element.ALIGN_LEFT);
|
|
|
709 |
msAddHeader(itemTable, "HSN\nCode", Element.ALIGN_CENTER);
|
|
|
710 |
msAddHeader(itemTable, "Qty", Element.ALIGN_CENTER);
|
| 36109 |
amit |
711 |
|
| 36116 |
amit |
712 |
msAddHeader(itemTable, "Rate\n(Rs.)", Element.ALIGN_RIGHT);
|
|
|
713 |
msAddHeader(itemTable, isMargin ? "Taxable Value\n- Margin (Rs.)" : "Taxable\nValue (Rs.)", Element.ALIGN_RIGHT);
|
|
|
714 |
msAddHeader(itemTable, "Tax\nRate", Element.ALIGN_CENTER);
|
|
|
715 |
msAddHeader(itemTable, "Tax\n(Rs.)", Element.ALIGN_RIGHT);
|
|
|
716 |
msAddHeader(itemTable, "Total\n(Rs.)", Element.ALIGN_RIGHT);
|
|
|
717 |
|
|
|
718 |
float totalGrossSale = 0, totalTaxable = 0, totalTaxAmount = 0, totalNetAmount = 0;
|
|
|
719 |
float totalCgst = 0, totalSgst = 0, totalIgst = 0;
|
| 36109 |
amit |
720 |
int index = 1;
|
|
|
721 |
for (CustomOrderItem orderItem : orderItems) {
|
| 36111 |
amit |
722 |
float taxAmount = orderItem.getCgstAmount() + orderItem.getSgstAmount() + orderItem.getIgstAmount();
|
| 36109 |
amit |
723 |
|
| 36116 |
amit |
724 |
msAddDataCell(itemTable, String.valueOf(index++), Element.ALIGN_CENTER, false, false);
|
|
|
725 |
msAddDataCell(itemTable, String.valueOf(orderItem.getOrderId()), Element.ALIGN_CENTER, false, false);
|
|
|
726 |
msAddDataCell(itemTable, orderItem.getDescription(), Element.ALIGN_LEFT, false, false);
|
|
|
727 |
msAddDataCell(itemTable, orderItem.getHsnCode(), Element.ALIGN_CENTER, false, false);
|
|
|
728 |
msAddDataCell(itemTable, String.valueOf(orderItem.getQuantity()), Element.ALIGN_CENTER, false, false);
|
| 36109 |
amit |
729 |
|
| 36116 |
amit |
730 |
if (isMargin) {
|
| 36119 |
amit |
731 |
float grossSaleTotal = orderItem.getNetAmount() - taxAmount;
|
|
|
732 |
float grossSalePerUnit = grossSaleTotal / orderItem.getQuantity();
|
| 36137 |
amit |
733 |
msAddDataCell(itemTable, formatIndianCurrency(grossSalePerUnit), Element.ALIGN_RIGHT, false, false);
|
| 36119 |
amit |
734 |
totalGrossSale += grossSaleTotal;
|
| 36116 |
amit |
735 |
} else {
|
| 36137 |
amit |
736 |
msAddDataCell(itemTable, formatIndianCurrency(orderItem.getRate()), Element.ALIGN_RIGHT, false, false);
|
| 36116 |
amit |
737 |
}
|
|
|
738 |
totalNetAmount += orderItem.getNetAmount();
|
| 36137 |
amit |
739 |
msAddDataCell(itemTable, formatIndianCurrency(orderItem.getAmount()), Element.ALIGN_RIGHT, false, false);
|
| 36116 |
amit |
740 |
String rateText;
|
| 36111 |
amit |
741 |
if (stateGst) {
|
| 36116 |
amit |
742 |
rateText = String.format("CGST %.1f%%\n+ SGST %.1f%%", orderItem.getCgstRate(), orderItem.getSgstRate());
|
| 36111 |
amit |
743 |
} else {
|
| 36116 |
amit |
744 |
rateText = String.format("IGST %.1f%%", orderItem.getIgstRate());
|
| 36111 |
amit |
745 |
}
|
| 36116 |
amit |
746 |
msAddDataCell(itemTable, rateText, Element.ALIGN_CENTER, false, false);
|
| 36137 |
amit |
747 |
msAddDataCell(itemTable, formatIndianCurrency(taxAmount), Element.ALIGN_RIGHT, false, false);
|
|
|
748 |
msAddDataCell(itemTable, formatIndianCurrency(orderItem.getNetAmount()), Element.ALIGN_RIGHT, false, false);
|
| 36111 |
amit |
749 |
|
| 36116 |
amit |
750 |
totalTaxable += orderItem.getAmount();
|
| 36111 |
amit |
751 |
totalTaxAmount += taxAmount;
|
| 36116 |
amit |
752 |
totalCgst += orderItem.getCgstAmount();
|
|
|
753 |
totalSgst += orderItem.getSgstAmount();
|
|
|
754 |
totalIgst += orderItem.getIgstAmount();
|
| 36109 |
amit |
755 |
}
|
|
|
756 |
|
|
|
757 |
// Total row
|
| 36116 |
amit |
758 |
int totalPcs = 0;
|
|
|
759 |
for (CustomOrderItem oi : orderItems) totalPcs += oi.getQuantity();
|
|
|
760 |
int totalColSpan = 5;
|
|
|
761 |
PdfPCell totalSpan = new PdfPCell(new Phrase("Total " + totalPcs + " pc(s)", MS_BOLD));
|
|
|
762 |
totalSpan.setColspan(totalColSpan);
|
|
|
763 |
totalSpan.setHorizontalAlignment(Element.ALIGN_RIGHT);
|
|
|
764 |
totalSpan.setBorderColor(MS_BORDER);
|
|
|
765 |
totalSpan.setBackgroundColor(MS_TOTAL_BG);
|
|
|
766 |
totalSpan.setPadding(4f);
|
|
|
767 |
itemTable.addCell(totalSpan);
|
| 36109 |
amit |
768 |
|
| 36137 |
amit |
769 |
msAddDataCell(itemTable, isMargin ? formatIndianCurrency(totalGrossSale) : "", Element.ALIGN_RIGHT, true, true);
|
|
|
770 |
msAddDataCell(itemTable, formatIndianCurrency(totalTaxable), Element.ALIGN_RIGHT, true, true);
|
| 36116 |
amit |
771 |
msAddDataCell(itemTable, "\u2014", Element.ALIGN_CENTER, false, true);
|
| 36137 |
amit |
772 |
msAddDataCell(itemTable, formatIndianCurrency(totalTaxAmount), Element.ALIGN_RIGHT, true, true);
|
|
|
773 |
msAddDataCell(itemTable, formatIndianCurrency(totalNetAmount), Element.ALIGN_RIGHT, true, true);
|
| 36109 |
amit |
774 |
|
| 36116 |
amit |
775 |
document.add(itemTable);
|
| 36109 |
amit |
776 |
|
| 36116 |
amit |
777 |
// ── Bottom: Info (left) + Summary (right) + Amount in words ──
|
|
|
778 |
float totalInvoiceValue = isMargin ? (totalGrossSale + totalTaxAmount) : totalNetAmount;
|
| 36109 |
amit |
779 |
|
| 36116 |
amit |
780 |
PdfPTable bottomTable = new PdfPTable(2);
|
|
|
781 |
bottomTable.setWidthPercentage(100);
|
|
|
782 |
bottomTable.setWidths(new float[]{1.15f, 1f});
|
|
|
783 |
bottomTable.setSpacingBefore(0f);
|
|
|
784 |
bottomTable.setSpacingAfter(0f);
|
| 36111 |
amit |
785 |
|
| 36116 |
amit |
786 |
// Left: Declaration (margin) or Tax Summary (regular)
|
|
|
787 |
PdfPCell leftCell = new PdfPCell();
|
|
|
788 |
leftCell.setBorder(Rectangle.BOX);
|
|
|
789 |
leftCell.setBorderColor(MS_BORDER);
|
|
|
790 |
leftCell.setPadding(6f);
|
|
|
791 |
leftCell.setPaddingRight(8f);
|
| 36111 |
amit |
792 |
|
| 36116 |
amit |
793 |
if (isMargin) {
|
|
|
794 |
leftCell.addElement(new Paragraph("Declaration", MS_SMALL_BOLD));
|
|
|
795 |
leftCell.addElement(msSpacer(3f));
|
|
|
796 |
leftCell.addElement(new Paragraph(
|
|
|
797 |
"GST is payable on margin scheme basis under Section 2(27) read with "
|
|
|
798 |
+ "Rule 32(5) of CGST Rules, 2017.", MS_SMALL));
|
|
|
799 |
leftCell.addElement(msSpacer(4f));
|
|
|
800 |
leftCell.addElement(new Paragraph(
|
|
|
801 |
"The buyer is NOT eligible to claim Input Tax Credit on this invoice.", MS_SMALL_BOLD));
|
|
|
802 |
}
|
|
|
803 |
bottomTable.addCell(leftCell);
|
| 36111 |
amit |
804 |
|
| 36116 |
amit |
805 |
// Right: Summary totals
|
|
|
806 |
PdfPCell summaryCell = new PdfPCell();
|
|
|
807 |
summaryCell.setBorder(Rectangle.BOX);
|
|
|
808 |
summaryCell.setBorderColor(MS_BORDER);
|
|
|
809 |
summaryCell.setPadding(0f);
|
|
|
810 |
PdfPTable sumTable = new PdfPTable(2);
|
|
|
811 |
sumTable.setWidthPercentage(100);
|
|
|
812 |
sumTable.setWidths(new float[]{1.4f, 1f});
|
| 36111 |
amit |
813 |
|
| 36116 |
amit |
814 |
if (isMargin) {
|
| 36137 |
amit |
815 |
msAddSummaryRow(sumTable, "Total Selling Price", "Rs. " + formatIndianCurrency(totalGrossSale), false);
|
|
|
816 |
msAddSummaryRow(sumTable, "GST on Margin", "Rs. " + formatIndianCurrency(totalTaxAmount), false);
|
| 36116 |
amit |
817 |
} else {
|
| 36137 |
amit |
818 |
msAddSummaryRow(sumTable, "Total Taxable Value", "Rs. " + formatIndianCurrency(totalTaxable), false);
|
|
|
819 |
msAddSummaryRow(sumTable, "Total GST", "Rs. " + formatIndianCurrency(totalTaxAmount), false);
|
| 36116 |
amit |
820 |
}
|
| 36137 |
amit |
821 |
msAddSummaryRow(sumTable, "Total Invoice Value", "Rs. " + formatIndianCurrency(totalInvoiceValue), true);
|
| 36116 |
amit |
822 |
summaryCell.addElement(sumTable);
|
|
|
823 |
bottomTable.addCell(summaryCell);
|
| 36109 |
amit |
824 |
|
| 36119 |
amit |
825 |
// Row 2: empty (left) + Amount in words (right) — no gap
|
| 36116 |
amit |
826 |
PdfPCell emptyLeft = new PdfPCell(new Phrase("", MS_NORMAL));
|
|
|
827 |
emptyLeft.setBorder(Rectangle.NO_BORDER);
|
| 36119 |
amit |
828 |
emptyLeft.setPadding(0f);
|
|
|
829 |
emptyLeft.setFixedHeight(0.1f);
|
| 36116 |
amit |
830 |
bottomTable.addCell(emptyLeft);
|
|
|
831 |
PdfPCell wordsCell = new PdfPCell(new Phrase(toAmountInWords(totalInvoiceValue), MS_ITALIC));
|
|
|
832 |
wordsCell.setBorder(Rectangle.BOX);
|
|
|
833 |
wordsCell.setBorderColor(MS_BORDER);
|
| 36119 |
amit |
834 |
wordsCell.setPadding(4f);
|
| 36116 |
amit |
835 |
wordsCell.setBackgroundColor(MS_TOTAL_BG);
|
|
|
836 |
bottomTable.addCell(wordsCell);
|
|
|
837 |
|
|
|
838 |
document.add(bottomTable);
|
|
|
839 |
|
|
|
840 |
// ── Payment Options ────────────────────────────────────────
|
| 36109 |
amit |
841 |
if (pdfModel.getPaymentOptions() != null) {
|
| 36116 |
amit |
842 |
PdfPTable paidTable = new PdfPTable(2);
|
|
|
843 |
paidTable.setWidthPercentage(100);
|
|
|
844 |
paidTable.setWidths(new float[]{7f, 1f});
|
| 36109 |
amit |
845 |
float totalPaidValue = 0;
|
| 36116 |
amit |
846 |
for (CustomPaymentOption po : pdfModel.getPaymentOptions()) {
|
|
|
847 |
if (!"CASH DISCOUNT".equals(po.getPaymentOption())) {
|
|
|
848 |
PdfPCell lbl = new PdfPCell(new Phrase("Paid Through " + po.getPaymentOption(), MS_BOLD));
|
|
|
849 |
lbl.setHorizontalAlignment(Element.ALIGN_RIGHT);
|
|
|
850 |
lbl.setBorderColor(MS_BORDER);
|
|
|
851 |
lbl.setPadding(4f);
|
|
|
852 |
paidTable.addCell(lbl);
|
|
|
853 |
PdfPCell val = new PdfPCell(new Phrase(FormattingUtils.formatDecimal(po.getAmount()), MS_BOLD));
|
|
|
854 |
val.setHorizontalAlignment(Element.ALIGN_RIGHT);
|
|
|
855 |
val.setBorderColor(MS_BORDER);
|
|
|
856 |
val.setPadding(4f);
|
|
|
857 |
paidTable.addCell(val);
|
|
|
858 |
totalPaidValue += po.getAmount();
|
| 36109 |
amit |
859 |
}
|
|
|
860 |
}
|
| 36116 |
amit |
861 |
PdfPCell tpLbl = new PdfPCell(new Phrase("Total Paid", MS_BOLD));
|
|
|
862 |
tpLbl.setHorizontalAlignment(Element.ALIGN_RIGHT);
|
|
|
863 |
tpLbl.setBorderColor(MS_BORDER);
|
|
|
864 |
tpLbl.setPadding(4f);
|
|
|
865 |
paidTable.addCell(tpLbl);
|
|
|
866 |
PdfPCell tpVal = new PdfPCell(new Phrase(FormattingUtils.formatDecimal(totalPaidValue), MS_BOLD));
|
|
|
867 |
tpVal.setHorizontalAlignment(Element.ALIGN_RIGHT);
|
|
|
868 |
tpVal.setBorderColor(MS_BORDER);
|
|
|
869 |
tpVal.setPadding(4f);
|
|
|
870 |
paidTable.addCell(tpVal);
|
|
|
871 |
document.add(paidTable);
|
| 36109 |
amit |
872 |
}
|
|
|
873 |
|
| 36116 |
amit |
874 |
// ── Note + Credit Terms ────────────────────────────────────
|
|
|
875 |
Paragraph note = new Paragraph("This is a computer-generated invoice and does not require a physical signature.", MS_SMALL);
|
|
|
876 |
note.setAlignment(Element.ALIGN_CENTER);
|
|
|
877 |
note.setSpacingBefore(8f);
|
|
|
878 |
note.setSpacingAfter(4f);
|
|
|
879 |
document.add(note);
|
| 36109 |
amit |
880 |
|
|
|
881 |
if (pdfModel.getCreditTerms() != null) {
|
| 36116 |
amit |
882 |
Paragraph ctTitle = new Paragraph("Credit terms:", MS_SMALL_BOLD);
|
|
|
883 |
ctTitle.setIndentationLeft(25);
|
|
|
884 |
document.add(ctTitle);
|
| 36109 |
amit |
885 |
int count = 0;
|
| 36116 |
amit |
886 |
for (String ct : pdfModel.getCreditTerms()) {
|
| 36109 |
amit |
887 |
count++;
|
| 36116 |
amit |
888 |
Paragraph line = new Paragraph(count + ". " + ct + ".", MS_SMALL);
|
|
|
889 |
line.setIndentationLeft(25);
|
|
|
890 |
line.setIndentationRight(25);
|
|
|
891 |
document.add(line);
|
| 36109 |
amit |
892 |
}
|
|
|
893 |
}
|
|
|
894 |
|
|
|
895 |
document.newPage();
|
|
|
896 |
|
| 36116 |
amit |
897 |
// ── E-Way Bill ─────────────────────────────────────────────
|
| 36109 |
amit |
898 |
if (pdfModel.geteWayBillPdfModel() != null) {
|
|
|
899 |
EWayBillPDF.generateDocument(document, pdfWriter, pdfModel.geteWayBillPdfModel());
|
|
|
900 |
}
|
|
|
901 |
}
|
|
|
902 |
|
|
|
903 |
document.close();
|
|
|
904 |
if (cancelledPages) {
|
|
|
905 |
stampCancelled(outputStream, cancelledPageList);
|
|
|
906 |
}
|
|
|
907 |
} catch (DocumentException e) {
|
| 36116 |
amit |
908 |
LOGGER.error("Unable to write data to pdf file : ", e);
|
| 36109 |
amit |
909 |
} catch (Exception e) {
|
|
|
910 |
e.printStackTrace();
|
|
|
911 |
}
|
|
|
912 |
}
|
|
|
913 |
|
| 32275 |
tejbeer |
914 |
private static void stampCancelled(ByteArrayOutputStream byteStream, List<Integer> cancelledPage) throws IOException, DocumentException {
|
|
|
915 |
ByteArrayInputStream bais = new ByteArrayInputStream(byteStream.toByteArray());
|
|
|
916 |
PdfReader pdfReader = new PdfReader(bais);
|
|
|
917 |
int n = pdfReader.getNumberOfPages();
|
|
|
918 |
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
|
|
919 |
PdfStamper pdfStamper = new PdfStamper(pdfReader, baos);
|
|
|
920 |
pdfStamper.setRotateContents(false);
|
|
|
921 |
// text watermark
|
|
|
922 |
Font f = new Font(FontFamily.HELVETICA, 30);
|
|
|
923 |
Phrase p = new Phrase("My watermark (text)", f);
|
|
|
924 |
URL cancelledImgUrl = PdfUtils.class.getClassLoader().getResource("cancelled.png");
|
|
|
925 |
URL waterMarkImgUrl = PdfUtils.class.getClassLoader().getResource("sd1.jpg");
|
|
|
926 |
Image imgCancelled = Image.getInstance(cancelledImgUrl);
|
|
|
927 |
Image imgWatermark = Image.getInstance(waterMarkImgUrl);
|
|
|
928 |
imgWatermark.scaleAbsolute(imgWatermark.getScaledWidth() * 2.5f, imgWatermark.getScaledHeight() * 2.5f);
|
|
|
929 |
float w = imgCancelled.getScaledWidth() / 2;
|
|
|
930 |
float h = imgCancelled.getScaledHeight() / 2;
|
|
|
931 |
float wWaterMark = imgWatermark.getScaledWidth() / 2;
|
|
|
932 |
float hWatermark = imgWatermark.getScaledHeight() / 2;
|
|
|
933 |
// transparency
|
|
|
934 |
PdfGState gs1 = new PdfGState();
|
| 32980 |
amit.gupta |
935 |
gs1.setFillOpacity(0.4f);
|
| 32275 |
tejbeer |
936 |
PdfGState gs2 = new PdfGState();
|
| 32980 |
amit.gupta |
937 |
gs2.setFillOpacity(0.05f);
|
| 32275 |
tejbeer |
938 |
// properties
|
|
|
939 |
PdfContentByte over;
|
|
|
940 |
Rectangle pagesize;
|
|
|
941 |
float x, y;
|
| 24506 |
amit.gupta |
942 |
|
| 32275 |
tejbeer |
943 |
// loop over every page
|
|
|
944 |
for (int i = 1; i <= n; i++) {
|
|
|
945 |
pagesize = pdfReader.getPageSize(i);
|
|
|
946 |
x = (pagesize.getLeft() + pagesize.getRight()) / 2;
|
|
|
947 |
y = (pagesize.getTop() + pagesize.getBottom()) / 2;
|
|
|
948 |
over = pdfStamper.getOverContent(i);
|
|
|
949 |
over.saveState();
|
|
|
950 |
if (cancelledPage.get(i - 1) == 1) {
|
|
|
951 |
over.setGState(gs1);
|
|
|
952 |
over.addImage(imgCancelled, w, 0, 0, h, x - (w / 2), y - (h / 2));
|
|
|
953 |
over.restoreState();
|
|
|
954 |
} else {
|
|
|
955 |
over.setGState(gs2);
|
|
|
956 |
over.addImage(imgWatermark, wWaterMark, 0, 0, hWatermark, x - (wWaterMark / 2), y - (hWatermark / 2));
|
|
|
957 |
over.restoreState();
|
|
|
958 |
}
|
|
|
959 |
}
|
|
|
960 |
pdfStamper.close();
|
|
|
961 |
pdfReader.close();
|
|
|
962 |
baos.writeTo(byteStream);
|
| 24845 |
amit.gupta |
963 |
|
| 32275 |
tejbeer |
964 |
}
|
| 24506 |
amit.gupta |
965 |
|
| 32275 |
tejbeer |
966 |
public static void generateAndWriteDebitNote(List<DebitNotePdfModel> debitNotePdfModels, OutputStream outputStream) {
|
|
|
967 |
Document document = new Document();
|
|
|
968 |
document.setMargins(0, 0, 25, 0);
|
|
|
969 |
try {
|
|
|
970 |
for (DebitNotePdfModel debitNotePdfModel : debitNotePdfModels) {
|
| 23509 |
amit.gupta |
971 |
|
| 32275 |
tejbeer |
972 |
InvoicePdfModel pdfModel = debitNotePdfModel.getPdfModel();
|
|
|
973 |
CustomCustomer customer = pdfModel.getCustomer();
|
|
|
974 |
CustomRetailer retailer = pdfModel.getRetailer();
|
|
|
975 |
boolean stateGst = false;
|
| 32290 |
tejbeer |
976 |
|
|
|
977 |
LOGGER.info("Customer - {}", customer.getAddress().getState());
|
|
|
978 |
LOGGER.info("retailer - {}", retailer.getAddress().getState());
|
|
|
979 |
|
|
|
980 |
|
| 32292 |
tejbeer |
981 |
if (customer.getAddress().getState().equals(retailer.getAddress().getState())) {
|
|
|
982 |
stateGst = true;
|
|
|
983 |
}
|
| 33298 |
amit.gupta |
984 |
List<CustomOrderItem> orderItems = pdfModel.getOrderItems();
|
| 23509 |
amit.gupta |
985 |
|
| 32275 |
tejbeer |
986 |
PdfWriter.getInstance(document, outputStream);
|
| 23509 |
amit.gupta |
987 |
|
| 32275 |
tejbeer |
988 |
document.open();
|
|
|
989 |
document.addTitle(pdfModel.getTitle());
|
|
|
990 |
document.addAuthor(pdfModel.getAuther());
|
| 23509 |
amit.gupta |
991 |
|
| 32275 |
tejbeer |
992 |
Paragraph paragraphTitle = new Paragraph(pdfModel.getTitle(), FONT_TITLE);
|
|
|
993 |
paragraphTitle.setAlignment(Element.ALIGN_CENTER);
|
| 23509 |
amit.gupta |
994 |
|
| 32275 |
tejbeer |
995 |
PdfPCell blankCell = new PdfPCell();
|
|
|
996 |
blankCell.setBorder(Rectangle.NO_BORDER);
|
|
|
997 |
PdfPTable tableCustomerRetailer = new PdfPTable(3);
|
|
|
998 |
tableCustomerRetailer.setWidthPercentage(95);
|
|
|
999 |
PdfPCell partnerInfo = new PdfPCell();
|
|
|
1000 |
partnerInfo.addElement(new Paragraph("From Party:", FONT_BOLD));
|
|
|
1001 |
partnerInfo.addElement(
|
|
|
1002 |
new Paragraph(StringUtils.capitalize(customer.getAddress().getName()), FONT_NORMAL));
|
|
|
1003 |
partnerInfo.addElement(new Paragraph(
|
| 32289 |
tejbeer |
1004 |
(customer.getAddress().getLine1() == null ? "" : StringUtils.capitalize(customer.getAddress().getLine1()) + ", ") + (customer.getAddress().getLine2() == null ? "" : StringUtils.capitalize(customer.getAddress().getLine2()) + ", ") + (customer.getAddress().getCity() == null ? "" : StringUtils.capitalize(customer.getAddress().getCity()) + " - ") + (customer.getAddress().getPinCode() == null ? "" : StringUtils.capitalize(customer.getAddress().getPinCode())), FONT_NORMAL));
|
| 23654 |
amit.gupta |
1005 |
|
| 32275 |
tejbeer |
1006 |
partnerInfo.addElement(new Paragraph(
|
|
|
1007 |
StringUtils.capitalize(customer.getAddress().getState()) + "(" + pdfModel.getCustomerAddressStateCode() + ")", FONT_NORMAL));
|
|
|
1008 |
partnerInfo.addElement(new Paragraph("Mobile - " + customer.getMobileNumber(), FONT_NORMAL));
|
|
|
1009 |
if (customer.getGstNumber() != null && !customer.getGstNumber().isEmpty()) {
|
|
|
1010 |
partnerInfo.addElement(new Paragraph("GST No - " + customer.getGstNumber(), FONT_BOLD));
|
|
|
1011 |
}
|
| 23533 |
amit.gupta |
1012 |
|
| 32275 |
tejbeer |
1013 |
PdfPCell sellerParty = new PdfPCell();
|
|
|
1014 |
sellerParty.addElement(new Paragraph("To Party:", FONT_BOLD));
|
|
|
1015 |
sellerParty.addElement(
|
|
|
1016 |
new Paragraph(StringUtils.capitalize(retailer.getAddress().getName()), FONT_NORMAL));
|
| 32289 |
tejbeer |
1017 |
sellerParty.addElement(new Paragraph((retailer.getAddress().getLine1() == null ? "" : StringUtils.capitalize(retailer.getAddress().getLine1()) + ", ") + (retailer.getAddress().getLine2() == null ? "" : StringUtils.capitalize(retailer.getAddress().getLine2()) + ", ") + (retailer.getAddress().getCity() == null ? "" : StringUtils.capitalize(retailer.getAddress().getCity()) + "-") + (retailer.getAddress().getPinCode() == null ? "" : StringUtils.capitalize(retailer.getAddress().getPinCode())), FONT_NORMAL));
|
| 32275 |
tejbeer |
1018 |
sellerParty.addElement(new Paragraph(
|
|
|
1019 |
retailer.getAddress().getState() + "(" + pdfModel.getPartnerAddressStateCode() + ")", FONT_NORMAL));
|
|
|
1020 |
sellerParty.addElement(new Paragraph("Mobile - " + retailer.getAddress().getPhoneNumber(), FONT_NORMAL));
|
|
|
1021 |
sellerParty.addElement(new Paragraph("GST No - " + retailer.getGstNumber(), FONT_BOLD));
|
| 23509 |
amit.gupta |
1022 |
|
| 32275 |
tejbeer |
1023 |
PdfPTable tableInvoiceDateRetailer = new PdfPTable(1);
|
|
|
1024 |
tableInvoiceDateRetailer.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
| 23509 |
amit.gupta |
1025 |
|
| 32275 |
tejbeer |
1026 |
PdfPTable tableInvoiceDate = new PdfPTable(2);
|
|
|
1027 |
tableInvoiceDate.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
|
|
1028 |
tableInvoiceDate.setWidthPercentage(90);
|
| 23509 |
amit.gupta |
1029 |
|
| 32275 |
tejbeer |
1030 |
PdfPCell debitNoteDetails = new PdfPCell(new Paragraph("Debit Note Details", FONT_BOLD));
|
|
|
1031 |
debitNoteDetails.setColspan(2);
|
|
|
1032 |
debitNoteDetails.setBorder(Rectangle.NO_BORDER);
|
| 23654 |
amit.gupta |
1033 |
|
| 32275 |
tejbeer |
1034 |
PdfPCell debitNoteNumberKey = new PdfPCell(new Paragraph("Debit Note No:", FONT_NORMAL));
|
|
|
1035 |
debitNoteNumberKey.setBorder(Rectangle.NO_BORDER);
|
|
|
1036 |
PdfPCell debitNoteNumberValue = new PdfPCell(
|
|
|
1037 |
new Paragraph(debitNotePdfModel.getDebitNoteNumber(), FONT_NORMAL));
|
|
|
1038 |
debitNoteNumberValue.setBorder(Rectangle.NO_BORDER);
|
| 23532 |
amit.gupta |
1039 |
|
| 32275 |
tejbeer |
1040 |
PdfPCell debitNoteDateKey = new PdfPCell(new Paragraph("Debit Note Dt:", FONT_NORMAL));
|
|
|
1041 |
debitNoteDateKey.setBorder(Rectangle.NO_BORDER);
|
| 23533 |
amit.gupta |
1042 |
|
| 32275 |
tejbeer |
1043 |
PdfPCell debitNoteDateValue = new PdfPCell(
|
|
|
1044 |
new Paragraph(debitNotePdfModel.getDebitNoteDate(), FONT_NORMAL));
|
|
|
1045 |
debitNoteDateValue.setBorder(Rectangle.NO_BORDER);
|
| 23532 |
amit.gupta |
1046 |
|
| 32275 |
tejbeer |
1047 |
PdfPCell invoiceNumberKey = new PdfPCell(new Paragraph("Invoice Ref No:", FONT_NORMAL));
|
|
|
1048 |
invoiceNumberKey.setBorder(Rectangle.NO_BORDER);
|
|
|
1049 |
PdfPCell invoiceNumberValue = new PdfPCell(new Paragraph(pdfModel.getInvoiceNumber(), FONT_NORMAL));
|
|
|
1050 |
invoiceNumberValue.setBorder(Rectangle.NO_BORDER);
|
| 23509 |
amit.gupta |
1051 |
|
| 32275 |
tejbeer |
1052 |
PdfPCell dateKey = new PdfPCell(new Paragraph("Invoice Dt:", FONT_NORMAL));
|
|
|
1053 |
dateKey.setBorder(Rectangle.NO_BORDER);
|
|
|
1054 |
PdfPCell dateValue = new PdfPCell(new Paragraph(pdfModel.getInvoiceDate(), FONT_NORMAL));
|
|
|
1055 |
dateValue.setBorder(Rectangle.NO_BORDER);
|
| 23533 |
amit.gupta |
1056 |
|
| 32275 |
tejbeer |
1057 |
tableInvoiceDate.addCell(debitNoteDetails);
|
|
|
1058 |
tableInvoiceDate.addCell(debitNoteNumberKey);
|
|
|
1059 |
tableInvoiceDate.addCell(debitNoteNumberValue);
|
|
|
1060 |
tableInvoiceDate.addCell(debitNoteDateKey);
|
|
|
1061 |
tableInvoiceDate.addCell(debitNoteDateValue);
|
|
|
1062 |
tableInvoiceDate.addCell(invoiceNumberKey);
|
|
|
1063 |
tableInvoiceDate.addCell(invoiceNumberValue);
|
|
|
1064 |
tableInvoiceDate.addCell(dateKey);
|
|
|
1065 |
tableInvoiceDate.addCell(dateValue);
|
| 23509 |
amit.gupta |
1066 |
|
| 32275 |
tejbeer |
1067 |
tableCustomerRetailer.addCell(partnerInfo);
|
|
|
1068 |
tableCustomerRetailer.addCell(tableInvoiceDate);
|
|
|
1069 |
tableCustomerRetailer.addCell(sellerParty);
|
| 23509 |
amit.gupta |
1070 |
|
| 32275 |
tejbeer |
1071 |
PdfPTable orders = null;
|
|
|
1072 |
if (stateGst) {
|
|
|
1073 |
orders = new PdfPTable(stateWidths.length);
|
|
|
1074 |
orders.setWidths(stateWidths);
|
|
|
1075 |
} else {
|
|
|
1076 |
orders = new PdfPTable(igstWidths.length);
|
|
|
1077 |
orders.setWidths(igstWidths);
|
|
|
1078 |
}
|
|
|
1079 |
orders.setWidthPercentage(95);
|
|
|
1080 |
orders.addCell(new Paragraph("Order Id", FONT_BOLD));
|
|
|
1081 |
orders.addCell(new Paragraph("Description", FONT_BOLD));
|
|
|
1082 |
orders.addCell(new Paragraph("HSN", FONT_BOLD));
|
|
|
1083 |
orders.addCell(new Paragraph("Qty", FONT_BOLD));
|
|
|
1084 |
orders.addCell(new Paragraph("Rate\n(Per pc)", FONT_BOLD));
|
|
|
1085 |
orders.addCell(new Paragraph("Total\nTaxable", FONT_BOLD));
|
|
|
1086 |
if (!stateGst) {
|
|
|
1087 |
orders.addCell(new Paragraph("IGST\n%", FONT_BOLD));
|
|
|
1088 |
orders.addCell(new Paragraph("IGST", FONT_BOLD));
|
|
|
1089 |
} else {
|
|
|
1090 |
orders.addCell(new Paragraph("CGST %", FONT_BOLD));
|
|
|
1091 |
orders.addCell(new Paragraph("CGST", FONT_BOLD));
|
|
|
1092 |
orders.addCell(new Paragraph("SGST %", FONT_BOLD));
|
|
|
1093 |
orders.addCell(new Paragraph("SGST", FONT_BOLD));
|
|
|
1094 |
}
|
|
|
1095 |
orders.addCell(new Paragraph("Total", FONT_BOLD));
|
| 23509 |
amit.gupta |
1096 |
|
| 32275 |
tejbeer |
1097 |
orders.setHeaderRows(1);
|
| 23509 |
amit.gupta |
1098 |
|
| 32275 |
tejbeer |
1099 |
float igstTotalAmount = 0, cgstTotalAmount = 0, sgstTotalAmount = 0;
|
| 35799 |
amit |
1100 |
boolean marginSeparatorAdded = false;
|
| 32275 |
tejbeer |
1101 |
for (CustomOrderItem orderItem : orderItems) {
|
| 35799 |
amit |
1102 |
if (orderItem.isMarginScheme() && !marginSeparatorAdded) {
|
|
|
1103 |
addMarginSchemeSeparator(orders, stateGst ? stateWidths.length : igstWidths.length);
|
|
|
1104 |
marginSeparatorAdded = true;
|
|
|
1105 |
}
|
|
|
1106 |
|
| 32275 |
tejbeer |
1107 |
orders.addCell(new Paragraph(String.valueOf(orderItem.getOrderId()), FONT_NORMAL));
|
|
|
1108 |
orders.addCell(new Paragraph(orderItem.getDescription(), FONT_NORMAL));
|
|
|
1109 |
orders.addCell(new Paragraph(orderItem.getHsnCode(), FONT_NORMAL));
|
|
|
1110 |
orders.addCell(new Paragraph(String.valueOf(orderItem.getQuantity()), FONT_NORMAL));
|
|
|
1111 |
orders.addCell(new Paragraph(String.format("%.2f", orderItem.getRate()), FONT_NORMAL));
|
|
|
1112 |
orders.addCell(new Paragraph(String.format("%.2f", orderItem.getAmount()), FONT_NORMAL));
|
|
|
1113 |
if (!stateGst) {
|
|
|
1114 |
orders.addCell(new Paragraph(String.format("%.2f", orderItem.getIgstRate()), FONT_NORMAL));
|
|
|
1115 |
orders.addCell(new Paragraph(String.format("%.2f", orderItem.getIgstAmount()), FONT_NORMAL));
|
|
|
1116 |
igstTotalAmount = igstTotalAmount + orderItem.getIgstAmount();
|
|
|
1117 |
} else {
|
|
|
1118 |
orders.addCell(new Paragraph(String.format("%.2f", orderItem.getCgstRate()), FONT_NORMAL));
|
|
|
1119 |
orders.addCell(new Paragraph(String.format("%.2f", orderItem.getCgstAmount()), FONT_NORMAL));
|
|
|
1120 |
orders.addCell(new Paragraph(String.format("%.2f", orderItem.getSgstRate()), FONT_NORMAL));
|
|
|
1121 |
orders.addCell(new Paragraph(String.format("%.2f", orderItem.getSgstAmount()), FONT_NORMAL));
|
|
|
1122 |
cgstTotalAmount = cgstTotalAmount + orderItem.getCgstAmount();
|
|
|
1123 |
sgstTotalAmount = sgstTotalAmount + orderItem.getSgstAmount();
|
|
|
1124 |
}
|
|
|
1125 |
orders.addCell(new Paragraph(String.format("%.0f", orderItem.getNetAmount()), FONT_NORMAL));
|
|
|
1126 |
LOGGER.info("IN FOR LOOP");
|
|
|
1127 |
}
|
| 23509 |
amit.gupta |
1128 |
|
| 32275 |
tejbeer |
1129 |
document.add(paragraphTitle);
|
| 23533 |
amit.gupta |
1130 |
|
| 32275 |
tejbeer |
1131 |
document.add(Chunk.NEWLINE);
|
|
|
1132 |
document.add(tableCustomerRetailer);
|
| 23509 |
amit.gupta |
1133 |
|
| 32275 |
tejbeer |
1134 |
document.add(Chunk.NEWLINE);
|
|
|
1135 |
document.add(orders);
|
| 23509 |
amit.gupta |
1136 |
|
| 32275 |
tejbeer |
1137 |
PdfPTable grandTotalTable = new PdfPTable(3);
|
|
|
1138 |
if (stateGst) {
|
|
|
1139 |
grandTotalTable.setWidths(new float[]{6.6f, .6f, .8f});
|
|
|
1140 |
} else {
|
|
|
1141 |
grandTotalTable.setWidths(new float[]{6.5f, .6f, .9f});
|
|
|
1142 |
}
|
|
|
1143 |
grandTotalTable.setWidthPercentage(95);
|
| 23509 |
amit.gupta |
1144 |
|
| 32275 |
tejbeer |
1145 |
Paragraph grandTotalParagraph = new Paragraph("Grand total", FONT_BOLD);
|
|
|
1146 |
grandTotalParagraph.setIndentationRight(20);
|
|
|
1147 |
grandTotalTable.addCell(grandTotalParagraph);
|
|
|
1148 |
Paragraph rsParagraph = new Paragraph("Rs.", FONT_BOLD);
|
|
|
1149 |
grandTotalTable.addCell(rsParagraph);
|
|
|
1150 |
Paragraph amountParagraph = new Paragraph(String.format("%.2f", pdfModel.getTotalAmount()), FONT_BOLD);
|
|
|
1151 |
grandTotalTable.addCell(amountParagraph);
|
| 23509 |
amit.gupta |
1152 |
|
| 32275 |
tejbeer |
1153 |
document.add(grandTotalTable);
|
| 23509 |
amit.gupta |
1154 |
|
| 32275 |
tejbeer |
1155 |
PdfPTable amountInWordsTable = new PdfPTable(3);
|
|
|
1156 |
if (!stateGst) {
|
|
|
1157 |
amountInWordsTable.setWidths(new float[]{2, 5.1f, 0.9f});
|
|
|
1158 |
} else {
|
|
|
1159 |
amountInWordsTable.setWidths(new float[]{2, 5.2f, 0.8f});
|
|
|
1160 |
}
|
|
|
1161 |
amountInWordsTable.setWidthPercentage(95);
|
|
|
1162 |
amountInWordsTable.addCell(new Paragraph("Amount in Words:", FONT_BOLD));
|
| 23509 |
amit.gupta |
1163 |
|
| 32275 |
tejbeer |
1164 |
String amountInWords = toAmountInWords(pdfModel.getTotalAmount());
|
|
|
1165 |
amountInWordsTable.addCell(new Paragraph(amountInWords.toString(), FONT_BOLD));
|
|
|
1166 |
amountInWordsTable.addCell(new Paragraph("E & O.E", FONT_NORMAL));
|
|
|
1167 |
document.add(amountInWordsTable);
|
| 23509 |
amit.gupta |
1168 |
|
| 35799 |
amit |
1169 |
// Margin scheme declaration for debit notes
|
|
|
1170 |
addMarginSchemeDeclaration(document, pdfModel);
|
|
|
1171 |
|
| 32275 |
tejbeer |
1172 |
document.newPage();
|
|
|
1173 |
}
|
|
|
1174 |
document.close(); // no need to close PDFwriter?
|
| 30539 |
amit.gupta |
1175 |
|
| 32275 |
tejbeer |
1176 |
} catch (DocumentException e) {
|
|
|
1177 |
LOGGER.error("Unable to write data to pdf file : ", e);
|
|
|
1178 |
} catch (Exception e) {
|
|
|
1179 |
// TODO Auto-generated catch block
|
|
|
1180 |
e.printStackTrace();
|
|
|
1181 |
}
|
|
|
1182 |
}
|
| 23509 |
amit.gupta |
1183 |
|
| 32275 |
tejbeer |
1184 |
private static String toAmountInWords(float amount) {
|
| 36137 |
amit |
1185 |
int rupees = (int) amount;
|
|
|
1186 |
int paise = Math.round((amount - rupees) * 100);
|
|
|
1187 |
StringBuilder sb = new StringBuilder("Rs. ");
|
|
|
1188 |
sb.append(StringUtils.capitalize(indianNumberToWords(rupees)));
|
|
|
1189 |
if (paise > 0) {
|
|
|
1190 |
sb.append(" and ");
|
|
|
1191 |
RuleBasedNumberFormat fmt = new RuleBasedNumberFormat(indianLocale, RuleBasedNumberFormat.SPELLOUT);
|
|
|
1192 |
sb.append(StringUtils.capitalize(fmt.format(paise)));
|
|
|
1193 |
sb.append(" Paise");
|
|
|
1194 |
} else {
|
|
|
1195 |
sb.append(" Only");
|
|
|
1196 |
}
|
|
|
1197 |
return sb.toString();
|
| 32275 |
tejbeer |
1198 |
}
|
| 23654 |
amit.gupta |
1199 |
|
| 36137 |
amit |
1200 |
/**
|
|
|
1201 |
* Convert number to Indian English words (lakh, crore system).
|
|
|
1202 |
*/
|
|
|
1203 |
private static String indianNumberToWords(int number) {
|
|
|
1204 |
if (number == 0) return "zero";
|
|
|
1205 |
String[] ones = {"", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine",
|
|
|
1206 |
"ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen",
|
|
|
1207 |
"eighteen", "nineteen"};
|
|
|
1208 |
String[] tens = {"", "", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"};
|
|
|
1209 |
|
|
|
1210 |
if (number < 0) return "minus " + indianNumberToWords(-number);
|
|
|
1211 |
|
|
|
1212 |
StringBuilder words = new StringBuilder();
|
|
|
1213 |
if (number / 10000000 > 0) {
|
|
|
1214 |
words.append(indianNumberToWords(number / 10000000)).append(" crore ");
|
|
|
1215 |
number %= 10000000;
|
|
|
1216 |
}
|
|
|
1217 |
if (number / 100000 > 0) {
|
|
|
1218 |
words.append(indianNumberToWords(number / 100000)).append(" lakh ");
|
|
|
1219 |
number %= 100000;
|
|
|
1220 |
}
|
|
|
1221 |
if (number / 1000 > 0) {
|
|
|
1222 |
words.append(indianNumberToWords(number / 1000)).append(" thousand ");
|
|
|
1223 |
number %= 1000;
|
|
|
1224 |
}
|
|
|
1225 |
if (number / 100 > 0) {
|
|
|
1226 |
words.append(ones[number / 100]).append(" hundred ");
|
|
|
1227 |
number %= 100;
|
|
|
1228 |
}
|
|
|
1229 |
if (number > 0) {
|
|
|
1230 |
if (words.length() > 0) words.append("and ");
|
|
|
1231 |
if (number < 20) {
|
|
|
1232 |
words.append(ones[number]);
|
|
|
1233 |
} else {
|
|
|
1234 |
words.append(tens[number / 10]);
|
|
|
1235 |
if (number % 10 > 0) words.append("-").append(ones[number % 10]);
|
|
|
1236 |
}
|
|
|
1237 |
}
|
|
|
1238 |
return words.toString().trim();
|
|
|
1239 |
}
|
|
|
1240 |
|
|
|
1241 |
/**
|
|
|
1242 |
* Format amount in Indian comma style: 1,25,129.00
|
|
|
1243 |
*/
|
|
|
1244 |
static String formatIndianCurrency(double amount) {
|
|
|
1245 |
String formatted = indianCurrencyFormat.format(amount);
|
| 36175 |
amit |
1246 |
// Remove currency symbol prefix (e.g. "₹", "Rs.", "INR ") keeping only the numeric part
|
|
|
1247 |
String symbol = indianCurrencyFormat.getCurrency().getSymbol(indianLocale);
|
|
|
1248 |
formatted = formatted.replace(symbol, "").trim();
|
|
|
1249 |
// Fallback: strip any remaining non-numeric prefix characters
|
|
|
1250 |
formatted = formatted.replaceFirst("^[^0-9-]+", "");
|
|
|
1251 |
return formatted;
|
| 36137 |
amit |
1252 |
}
|
|
|
1253 |
|
| 32275 |
tejbeer |
1254 |
public static void generateAndWriteCustomerCreditNotes(List<CreditNotePdfModel> creditNotes, OutputStream outputStream) {
|
|
|
1255 |
Document document = new Document();
|
|
|
1256 |
document.setMargins(0, 0, 25, 0);
|
|
|
1257 |
try {
|
|
|
1258 |
PdfWriter.getInstance(document, outputStream);
|
| 24506 |
amit.gupta |
1259 |
|
| 32275 |
tejbeer |
1260 |
document.open();
|
|
|
1261 |
document.addTitle(creditNotes.get(0).getPdfModel().getTitle());
|
|
|
1262 |
document.addAuthor(creditNotes.get(0).getPdfModel().getAuther());
|
|
|
1263 |
for (CreditNotePdfModel creditNotePdfModel : creditNotes) {
|
|
|
1264 |
InvoicePdfModel pdfModel = creditNotePdfModel.getPdfModel();
|
|
|
1265 |
CustomCustomer customer = pdfModel.getCustomer();
|
|
|
1266 |
CustomRetailer retailer = pdfModel.getRetailer();
|
|
|
1267 |
boolean stateGst = false;
|
| 32290 |
tejbeer |
1268 |
|
| 32275 |
tejbeer |
1269 |
if (customer.getAddress().getState().equals(retailer.getAddress().getState())) {
|
|
|
1270 |
stateGst = true;
|
|
|
1271 |
}
|
| 33298 |
amit.gupta |
1272 |
List<CustomOrderItem> orderItems = pdfModel.getOrderItems();
|
| 23654 |
amit.gupta |
1273 |
|
| 32275 |
tejbeer |
1274 |
Paragraph paragraphTitle = new Paragraph(pdfModel.getTitle(), FONT_TITLE);
|
|
|
1275 |
paragraphTitle.setAlignment(Element.ALIGN_CENTER);
|
| 23654 |
amit.gupta |
1276 |
|
| 32275 |
tejbeer |
1277 |
PdfPCell blankCell = new PdfPCell();
|
|
|
1278 |
blankCell.setBorder(Rectangle.NO_BORDER);
|
|
|
1279 |
PdfPTable tableCustomerRetailer = new PdfPTable(3);
|
|
|
1280 |
tableCustomerRetailer.setWidthPercentage(95);
|
|
|
1281 |
PdfPCell partnerInfo = new PdfPCell();
|
|
|
1282 |
partnerInfo.addElement(new Paragraph("To Party:", FONT_BOLD));
|
|
|
1283 |
partnerInfo.addElement(
|
|
|
1284 |
new Paragraph(StringUtils.capitalize(customer.getAddress().getName()), FONT_NORMAL));
|
|
|
1285 |
partnerInfo.addElement(new Paragraph(
|
|
|
1286 |
StringUtils.capitalize(customer.getAddress().getLine1()) + ", " + (customer.getAddress().getLine2() == null ? "" : StringUtils.capitalize(customer.getAddress().getLine2())) + ", " + customer.getAddress().getCity() + " - " + customer.getAddress().getPinCode(), FONT_NORMAL));
|
| 23654 |
amit.gupta |
1287 |
|
| 32275 |
tejbeer |
1288 |
partnerInfo.addElement(new Paragraph(
|
|
|
1289 |
StringUtils.capitalize(customer.getAddress().getState()) + "(" + pdfModel.getCustomerAddressStateCode() + ")", FONT_NORMAL));
|
|
|
1290 |
partnerInfo.addElement(new Paragraph("Mobile - " + customer.getMobileNumber(), FONT_NORMAL));
|
|
|
1291 |
if (customer.getGstNumber() != null && !customer.getGstNumber().isEmpty()) {
|
|
|
1292 |
partnerInfo.addElement(new Paragraph("GST No - " + customer.getGstNumber(), FONT_BOLD));
|
|
|
1293 |
}
|
| 23654 |
amit.gupta |
1294 |
|
| 32275 |
tejbeer |
1295 |
PdfPCell sellerParty = new PdfPCell();
|
|
|
1296 |
sellerParty.addElement(new Paragraph("From Party:", FONT_BOLD));
|
|
|
1297 |
sellerParty.addElement(
|
|
|
1298 |
new Paragraph(StringUtils.capitalize(retailer.getAddress().getName()), FONT_NORMAL));
|
|
|
1299 |
sellerParty.addElement(new Paragraph((retailer.getAddress().getLine1() == null ? "" : StringUtils.capitalize(retailer.getAddress().getLine1()) + ", ") + (retailer.getAddress().getLine2() == null ? "" : StringUtils.capitalize(retailer.getAddress().getLine2()) + ", ") + StringUtils.capitalize(retailer.getAddress().getCity()) + "-" + retailer.getAddress().getPinCode() + ", ", FONT_NORMAL));
|
|
|
1300 |
sellerParty.addElement(new Paragraph(
|
|
|
1301 |
retailer.getAddress().getState() + "(" + pdfModel.getPartnerAddressStateCode() + ")", FONT_NORMAL));
|
|
|
1302 |
sellerParty.addElement(new Paragraph("Mobile - " + retailer.getAddress().getPhoneNumber(), FONT_NORMAL));
|
|
|
1303 |
sellerParty.addElement(new Paragraph("GST No - " + retailer.getGstNumber(), FONT_BOLD));
|
| 23654 |
amit.gupta |
1304 |
|
| 32275 |
tejbeer |
1305 |
PdfPTable tableInvoiceDateRetailer = new PdfPTable(1);
|
|
|
1306 |
tableInvoiceDateRetailer.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
| 23654 |
amit.gupta |
1307 |
|
| 32275 |
tejbeer |
1308 |
PdfPTable tableInvoiceDate = new PdfPTable(2);
|
|
|
1309 |
tableInvoiceDate.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
|
|
1310 |
tableInvoiceDate.setWidthPercentage(90);
|
| 23654 |
amit.gupta |
1311 |
|
| 32275 |
tejbeer |
1312 |
PdfPCell debitNoteDetails = new PdfPCell(new Paragraph("Credit Note Details", FONT_BOLD));
|
|
|
1313 |
debitNoteDetails.setColspan(2);
|
|
|
1314 |
debitNoteDetails.setBorder(Rectangle.NO_BORDER);
|
| 23654 |
amit.gupta |
1315 |
|
| 32275 |
tejbeer |
1316 |
PdfPCell debitNoteNumberKey = new PdfPCell(new Paragraph("Credit Note No:", FONT_NORMAL));
|
|
|
1317 |
debitNoteNumberKey.setBorder(Rectangle.NO_BORDER);
|
|
|
1318 |
PdfPCell debitNoteNumberValue = new PdfPCell(
|
|
|
1319 |
new Paragraph(creditNotePdfModel.getCreditNoteNumber(), FONT_NORMAL));
|
|
|
1320 |
debitNoteNumberValue.setBorder(Rectangle.NO_BORDER);
|
| 23654 |
amit.gupta |
1321 |
|
| 32275 |
tejbeer |
1322 |
PdfPCell debitNoteDateKey = new PdfPCell(new Paragraph("Credit Note Dt:", FONT_NORMAL));
|
|
|
1323 |
debitNoteDateKey.setBorder(Rectangle.NO_BORDER);
|
| 23654 |
amit.gupta |
1324 |
|
| 32275 |
tejbeer |
1325 |
PdfPCell debitNoteDateValue = new PdfPCell(
|
|
|
1326 |
new Paragraph(creditNotePdfModel.getCreditNoteDate(), FONT_NORMAL));
|
|
|
1327 |
debitNoteDateValue.setBorder(Rectangle.NO_BORDER);
|
|
|
1328 |
tableInvoiceDate.addCell(debitNoteDetails);
|
|
|
1329 |
tableInvoiceDate.addCell(debitNoteNumberKey);
|
|
|
1330 |
tableInvoiceDate.addCell(debitNoteNumberValue);
|
|
|
1331 |
tableInvoiceDate.addCell(debitNoteDateKey);
|
|
|
1332 |
tableInvoiceDate.addCell(debitNoteDateValue);
|
| 32980 |
amit.gupta |
1333 |
if (pdfModel.getInvoiceNumber() != null) {
|
| 32275 |
tejbeer |
1334 |
PdfPCell dateKey = new PdfPCell(new Paragraph("Invoice Dt:", FONT_NORMAL));
|
|
|
1335 |
dateKey.setBorder(Rectangle.NO_BORDER);
|
|
|
1336 |
PdfPCell dateValue = new PdfPCell(new Paragraph(pdfModel.getInvoiceDate(), FONT_NORMAL));
|
|
|
1337 |
dateValue.setBorder(Rectangle.NO_BORDER);
|
| 23654 |
amit.gupta |
1338 |
|
| 32275 |
tejbeer |
1339 |
PdfPCell invoiceNumberKey = new PdfPCell(new Paragraph("Invoice Ref No:", FONT_NORMAL));
|
|
|
1340 |
invoiceNumberKey.setBorder(Rectangle.NO_BORDER);
|
|
|
1341 |
PdfPCell invoiceNumberValue = new PdfPCell(new Paragraph(pdfModel.getInvoiceNumber(), FONT_NORMAL));
|
|
|
1342 |
invoiceNumberValue.setBorder(Rectangle.NO_BORDER);
|
|
|
1343 |
tableInvoiceDate.addCell(invoiceNumberKey);
|
|
|
1344 |
tableInvoiceDate.addCell(invoiceNumberValue);
|
|
|
1345 |
tableInvoiceDate.addCell(dateKey);
|
|
|
1346 |
tableInvoiceDate.addCell(dateValue);
|
|
|
1347 |
}
|
| 31008 |
amit.gupta |
1348 |
|
| 32275 |
tejbeer |
1349 |
tableCustomerRetailer.addCell(partnerInfo);
|
|
|
1350 |
tableCustomerRetailer.addCell(tableInvoiceDate);
|
|
|
1351 |
tableCustomerRetailer.addCell(sellerParty);
|
| 23654 |
amit.gupta |
1352 |
|
| 32275 |
tejbeer |
1353 |
PdfPTable orders = null;
|
|
|
1354 |
if (stateGst) {
|
|
|
1355 |
orders = new PdfPTable(stateWidthsCrNote.length);
|
|
|
1356 |
orders.setWidths(stateWidthsCrNote);
|
|
|
1357 |
} else {
|
|
|
1358 |
orders = new PdfPTable(igstWidthsCrNote.length);
|
|
|
1359 |
orders.setWidths(igstWidthsCrNote);
|
|
|
1360 |
}
|
|
|
1361 |
orders.setWidthPercentage(95);
|
|
|
1362 |
orders.addCell(new Paragraph("Description", FONT_BOLD));
|
|
|
1363 |
orders.addCell(new Paragraph("HSN", FONT_BOLD));
|
|
|
1364 |
orders.addCell(new Paragraph("Qty", FONT_BOLD));
|
|
|
1365 |
orders.addCell(new Paragraph("Rate\n(Per pc)", FONT_BOLD));
|
|
|
1366 |
orders.addCell(new Paragraph("Total\nTaxable", FONT_BOLD));
|
|
|
1367 |
if (!stateGst) {
|
|
|
1368 |
orders.addCell(new Paragraph("IGST%", FONT_BOLD));
|
|
|
1369 |
orders.addCell(new Paragraph("IGST", FONT_BOLD));
|
|
|
1370 |
} else {
|
|
|
1371 |
orders.addCell(new Paragraph("CGST %", FONT_BOLD));
|
|
|
1372 |
orders.addCell(new Paragraph("CGST", FONT_BOLD));
|
|
|
1373 |
orders.addCell(new Paragraph("SGST %", FONT_BOLD));
|
|
|
1374 |
orders.addCell(new Paragraph("SGST", FONT_BOLD));
|
|
|
1375 |
}
|
|
|
1376 |
orders.addCell(new Paragraph("Total", FONT_BOLD));
|
| 23654 |
amit.gupta |
1377 |
|
| 32275 |
tejbeer |
1378 |
orders.setHeaderRows(1);
|
| 23654 |
amit.gupta |
1379 |
|
| 32275 |
tejbeer |
1380 |
float igstTotalAmount = 0, cgstTotalAmount = 0, sgstTotalAmount = 0;
|
| 35799 |
amit |
1381 |
boolean marginSeparatorAdded = false;
|
| 32275 |
tejbeer |
1382 |
for (CustomOrderItem orderItem : orderItems) {
|
| 35799 |
amit |
1383 |
if (orderItem.isMarginScheme() && !marginSeparatorAdded) {
|
|
|
1384 |
addMarginSchemeSeparator(orders, stateGst ? stateWidthsCrNote.length : igstWidthsCrNote.length);
|
|
|
1385 |
marginSeparatorAdded = true;
|
|
|
1386 |
}
|
|
|
1387 |
|
| 32275 |
tejbeer |
1388 |
LOGGER.info("Custom Order Item - {}", orderItem);
|
|
|
1389 |
orders.addCell(new Paragraph(orderItem.getDescription(), FONT_NORMAL));
|
|
|
1390 |
orders.addCell(new Paragraph(orderItem.getHsnCode(), FONT_NORMAL));
|
|
|
1391 |
orders.addCell(new Paragraph(String.valueOf(orderItem.getQuantity()), FONT_NORMAL));
|
|
|
1392 |
orders.addCell(new Paragraph(String.format("%.2f", orderItem.getRate()), FONT_NORMAL));
|
|
|
1393 |
orders.addCell(new Paragraph(String.format("%.2f", orderItem.getAmount()), FONT_NORMAL));
|
|
|
1394 |
if (!stateGst) {
|
|
|
1395 |
orders.addCell(new Paragraph(String.format("%.2f", orderItem.getIgstRate()), FONT_NORMAL));
|
|
|
1396 |
orders.addCell(new Paragraph(String.format("%.2f", orderItem.getIgstAmount()), FONT_NORMAL));
|
|
|
1397 |
igstTotalAmount = igstTotalAmount + orderItem.getIgstAmount();
|
|
|
1398 |
} else {
|
|
|
1399 |
orders.addCell(new Paragraph(String.format("%.2f", orderItem.getCgstRate()), FONT_NORMAL));
|
|
|
1400 |
orders.addCell(new Paragraph(String.format("%.2f", orderItem.getCgstAmount()), FONT_NORMAL));
|
|
|
1401 |
orders.addCell(new Paragraph(String.format("%.2f", orderItem.getSgstRate()), FONT_NORMAL));
|
|
|
1402 |
orders.addCell(new Paragraph(String.format("%.2f", orderItem.getSgstAmount()), FONT_NORMAL));
|
|
|
1403 |
cgstTotalAmount = cgstTotalAmount + orderItem.getCgstAmount();
|
|
|
1404 |
sgstTotalAmount = sgstTotalAmount + orderItem.getSgstAmount();
|
|
|
1405 |
}
|
|
|
1406 |
orders.addCell(new Paragraph(String.format("%.0f", orderItem.getNetAmount()), FONT_NORMAL));
|
|
|
1407 |
LOGGER.info("IN FOR LOOP");
|
|
|
1408 |
}
|
| 23654 |
amit.gupta |
1409 |
|
| 32275 |
tejbeer |
1410 |
document.add(paragraphTitle);
|
| 23654 |
amit.gupta |
1411 |
|
| 32275 |
tejbeer |
1412 |
document.add(Chunk.NEWLINE);
|
|
|
1413 |
document.add(tableCustomerRetailer);
|
| 23654 |
amit.gupta |
1414 |
|
| 32275 |
tejbeer |
1415 |
document.add(Chunk.NEWLINE);
|
|
|
1416 |
document.add(orders);
|
| 23654 |
amit.gupta |
1417 |
|
| 32275 |
tejbeer |
1418 |
PdfPTable grandTotalTable = new PdfPTable(3);
|
|
|
1419 |
if (stateGst) {
|
|
|
1420 |
grandTotalTable.setWidths(new float[]{6.6f, .6f, .8f});
|
|
|
1421 |
} else {
|
|
|
1422 |
grandTotalTable.setWidths(new float[]{6.5f, .6f, .9f});
|
|
|
1423 |
}
|
|
|
1424 |
grandTotalTable.setWidthPercentage(95);
|
| 23654 |
amit.gupta |
1425 |
|
| 32275 |
tejbeer |
1426 |
Paragraph grandTotalParagraph = new Paragraph("Grand total", FONT_BOLD);
|
|
|
1427 |
grandTotalParagraph.setIndentationRight(20);
|
|
|
1428 |
grandTotalTable.addCell(grandTotalParagraph);
|
|
|
1429 |
Paragraph rsParagraph = new Paragraph("Rs.", FONT_BOLD);
|
|
|
1430 |
grandTotalTable.addCell(rsParagraph);
|
|
|
1431 |
Paragraph amountParagraph = new Paragraph(String.format("%.2f", pdfModel.getTotalAmount()), FONT_BOLD);
|
|
|
1432 |
grandTotalTable.addCell(amountParagraph);
|
| 23654 |
amit.gupta |
1433 |
|
| 32275 |
tejbeer |
1434 |
document.add(grandTotalTable);
|
| 23654 |
amit.gupta |
1435 |
|
| 32275 |
tejbeer |
1436 |
PdfPTable amountInWordsTable = new PdfPTable(3);
|
|
|
1437 |
if (!stateGst) {
|
|
|
1438 |
amountInWordsTable.setWidths(new float[]{2, 5.1f, 0.9f});
|
|
|
1439 |
} else {
|
|
|
1440 |
amountInWordsTable.setWidths(new float[]{2, 5.2f, 0.8f});
|
|
|
1441 |
}
|
|
|
1442 |
amountInWordsTable.setWidthPercentage(95);
|
|
|
1443 |
amountInWordsTable.addCell(new Paragraph("Amount in Words:", FONT_BOLD));
|
| 23654 |
amit.gupta |
1444 |
|
| 32275 |
tejbeer |
1445 |
String amountInWords = toAmountInWords(pdfModel.getTotalAmount());
|
|
|
1446 |
amountInWordsTable.addCell(new Paragraph(amountInWords.toString(), FONT_BOLD));
|
|
|
1447 |
amountInWordsTable.addCell(new Paragraph("E & O.E", FONT_NORMAL));
|
|
|
1448 |
document.add(amountInWordsTable);
|
| 23654 |
amit.gupta |
1449 |
|
| 35799 |
amit |
1450 |
// Margin scheme declaration for credit notes
|
|
|
1451 |
addMarginSchemeDeclaration(document, pdfModel);
|
|
|
1452 |
|
| 32275 |
tejbeer |
1453 |
document.newPage();
|
|
|
1454 |
}
|
|
|
1455 |
document.close(); // no need to close PDFwriter?
|
|
|
1456 |
} catch (DocumentException e) {
|
|
|
1457 |
LOGGER.error("Unable to write data to pdf file : ", e);
|
|
|
1458 |
} catch (Exception e) {
|
|
|
1459 |
// TODO Auto-generated catch block
|
|
|
1460 |
e.printStackTrace();
|
|
|
1461 |
}
|
| 23654 |
amit.gupta |
1462 |
|
| 32275 |
tejbeer |
1463 |
}
|
| 34805 |
ranu |
1464 |
|
|
|
1465 |
public static byte[] mergePdfFiles(List<byte[]> pdfFiles) throws IOException, DocumentException {
|
|
|
1466 |
ByteArrayOutputStream mergedOutputStream = new ByteArrayOutputStream();
|
|
|
1467 |
Document document = new Document();
|
|
|
1468 |
PdfCopy copy = new PdfCopy(document, mergedOutputStream);
|
|
|
1469 |
document.open();
|
|
|
1470 |
|
|
|
1471 |
for (byte[] pdf : pdfFiles) {
|
|
|
1472 |
PdfReader reader = new PdfReader(new ByteArrayInputStream(pdf));
|
|
|
1473 |
int n = reader.getNumberOfPages();
|
|
|
1474 |
for (int i = 1; i <= n; i++) {
|
|
|
1475 |
copy.addPage(copy.getImportedPage(reader, i));
|
|
|
1476 |
}
|
|
|
1477 |
copy.freeReader(reader);
|
|
|
1478 |
reader.close();
|
|
|
1479 |
}
|
|
|
1480 |
|
|
|
1481 |
document.close();
|
|
|
1482 |
return mergedOutputStream.toByteArray();
|
|
|
1483 |
}
|
|
|
1484 |
|
| 21686 |
ashik.ali |
1485 |
}
|