| 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);
|
|
|
27 |
// private static Font fontTableHeader = new
|
|
|
28 |
// Font(Font.FontFamily.TIMES_ROMAN, 14, Font.BOLD);
|
|
|
29 |
public static final String INVOICE_TITLE = "TAX INVOICE";
|
|
|
30 |
public static final String DEBIT_NOTE_TITLE = "DEBIT NOTE";
|
|
|
31 |
public static final String SECURITY_DEPOSIT = "SECURITY DEPOSIT RECEIPT";
|
| 23509 |
amit.gupta |
32 |
|
| 32275 |
tejbeer |
33 |
private static float[] igstWidthsWithDiscount = new float[]{.2f, 2.6f, 0.7f, .4f, 0.7f, 0.6f, .7f, .6f, 0.7f};
|
|
|
34 |
private static float[] stateWidthsWithDiscount = new float[]{.2f, 2.1f, 0.7f, .3f, 0.6f, 0.5f, .7f, .6f, .6f, .7f};
|
| 23509 |
amit.gupta |
35 |
|
| 32275 |
tejbeer |
36 |
private static float[] igstWidths = new float[]{.6f, 2.6f, 0.7f, .4f, 0.7f, .7f, .6f, 0.6f, 0.9f};
|
|
|
37 |
private static float[] stateWidths = new float[]{.6f, 2.1f, 0.7f, .3f, 0.6f, .7f, .5f, .6f, .5f, .6f, .8f};
|
| 23533 |
amit.gupta |
38 |
|
| 32275 |
tejbeer |
39 |
private static float[] igstWidthsCrNote = new float[]{2.6f, 0.7f, .4f, 0.7f, .7f, .6f, 0.6f, 0.9f};
|
|
|
40 |
private static float[] stateWidthsCrNote = new float[]{2.1f, 0.7f, .3f, 0.6f, .7f, .5f, .6f, .5f, .6f, .8f};
|
| 23654 |
amit.gupta |
41 |
|
| 32275 |
tejbeer |
42 |
private static final Locale indianLocale = Locale.getDefault();
|
| 23509 |
amit.gupta |
43 |
|
| 32275 |
tejbeer |
44 |
private static final Logger LOGGER = LogManager.getLogger(PdfUtils.class);
|
| 23509 |
amit.gupta |
45 |
|
| 32275 |
tejbeer |
46 |
private static final URL iconUrl = PdfUtils.class.getClassLoader().getResource("sdlogo.png");
|
|
|
47 |
private static Image iconImg = null;
|
| 30400 |
amit.gupta |
48 |
|
| 32275 |
tejbeer |
49 |
static {
|
|
|
50 |
try {
|
|
|
51 |
iconImg = Image.getInstance(iconUrl);
|
|
|
52 |
} catch (Exception e) {
|
|
|
53 |
e.printStackTrace();
|
|
|
54 |
}
|
|
|
55 |
}
|
| 30400 |
amit.gupta |
56 |
|
| 32275 |
tejbeer |
57 |
//Debit Note generation logic has been changed
|
|
|
58 |
//Debit Note considers price drops so amount in debit note is current price of item.
|
|
|
59 |
//From 16Nov 2019 onwards all debit notes will be as per actuall billing value, all pricedrops
|
|
|
60 |
//shall be rolledback or cancelled once the debit note is generated.
|
| 25463 |
amit.gupta |
61 |
|
| 35035 |
amit |
62 |
public static void generateAndWrite(List<InvoicePdfModel> pdfModels, PrinterType printerType, ByteArrayOutputStream outputStream) throws ProfitMandiBusinessException {
|
| 35024 |
amit |
63 |
if (PrinterType.A4.equals(printerType)) {
|
|
|
64 |
generateAndWrite(pdfModels, outputStream);
|
|
|
65 |
} else {
|
|
|
66 |
if (pdfModels.size() > 1) {
|
|
|
67 |
}
|
|
|
68 |
if (PrinterType.W80.equals(printerType)) {
|
|
|
69 |
InvoiceFormatter.getInvoice(pdfModels.get(0), outputStream, InvoiceFormatter.WIDTH_80MM);
|
|
|
70 |
} else if (PrinterType.W58.equals(printerType)) {
|
|
|
71 |
InvoiceFormatter.getInvoice(pdfModels.get(0), outputStream, InvoiceFormatter.WIDTH_58MM);
|
| 30400 |
amit.gupta |
72 |
|
| 35024 |
amit |
73 |
}
|
|
|
74 |
}
|
| 35035 |
amit |
75 |
}
|
| 35024 |
amit |
76 |
|
|
|
77 |
|
|
|
78 |
//Standard
|
| 32275 |
tejbeer |
79 |
public static void generateAndWrite(List<InvoicePdfModel> pdfModels, ByteArrayOutputStream outputStream) {
|
|
|
80 |
try {
|
| 32991 |
amit.gupta |
81 |
boolean cancelledPages = false;
|
| 32275 |
tejbeer |
82 |
List<Integer> caneclledPageList = new ArrayList<>();
|
|
|
83 |
Document document = new Document();
|
|
|
84 |
document.setMargins(0, 0, 25, 0);
|
| 33741 |
amit.gupta |
85 |
PdfWriter pdfWriter = PdfWriter.getInstance(document, outputStream);
|
| 32275 |
tejbeer |
86 |
document.open();
|
|
|
87 |
for (InvoicePdfModel pdfModel : pdfModels) {
|
|
|
88 |
CustomCustomer customer = pdfModel.getCustomer();
|
|
|
89 |
CustomRetailer retailer = pdfModel.getRetailer();
|
|
|
90 |
boolean stateGst = false;
|
|
|
91 |
if (customer.getAddress().getState().equals(retailer.getAddress().getState())) {
|
|
|
92 |
stateGst = true;
|
|
|
93 |
}
|
| 33298 |
amit.gupta |
94 |
List<CustomOrderItem> orderItems = pdfModel.getOrderItems();
|
| 32275 |
tejbeer |
95 |
if (pdfModel.isCancelled()) {
|
|
|
96 |
caneclledPageList.add(1);
|
| 32991 |
amit.gupta |
97 |
cancelledPages = true;
|
| 32275 |
tejbeer |
98 |
} else {
|
|
|
99 |
caneclledPageList.add(0);
|
|
|
100 |
}
|
|
|
101 |
document.addTitle(pdfModel.getTitle());
|
|
|
102 |
document.addAuthor(pdfModel.getAuther());
|
| 22889 |
amit.gupta |
103 |
|
| 32275 |
tejbeer |
104 |
Paragraph paragraphTitle = new Paragraph(INVOICE_TITLE, FONT_TITLE);
|
|
|
105 |
paragraphTitle.setAlignment(Element.ALIGN_CENTER);
|
| 21686 |
ashik.ali |
106 |
|
| 32980 |
amit.gupta |
107 |
document.add(paragraphTitle);
|
|
|
108 |
|
|
|
109 |
Rectangle rectangle = document.getPageSize();
|
|
|
110 |
|
|
|
111 |
/*Paragraph paragraphTitle = new Paragraph(INVOICE_TITLE, FONT_TITLE);
|
|
|
112 |
paragraphTitle.setAlignment(Element.ALIGN_CENTER);*/
|
|
|
113 |
/*pdfCell.addElement(paragraphTitle);
|
|
|
114 |
pdfCell.setBorder(Rectangle.NO_BORDER);*/
|
|
|
115 |
if (pdfModel.getIrnModel() != null) {
|
|
|
116 |
addIrnDetails(pdfModel.getIrnModel(), rectangle, document);
|
|
|
117 |
}
|
|
|
118 |
|
|
|
119 |
|
|
|
120 |
PdfPTable tableCustomerRetailer = new PdfPTable(2);
|
| 32275 |
tejbeer |
121 |
tableCustomerRetailer.setWidthPercentage(90);
|
|
|
122 |
tableCustomerRetailer.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
|
|
123 |
PdfPCell columnCustomerInfo = new PdfPCell();
|
|
|
124 |
columnCustomerInfo.addElement(new Paragraph("Customer Details", FONT_BOLD));
|
|
|
125 |
columnCustomerInfo.addElement(new Paragraph(
|
|
|
126 |
StringUtils.capitalize(customer.getAddress().getName() + (customer.getAddress().getLastName() == null ? "" : " " + customer.getAddress().getLastName())), FONT_NORMAL));
|
| 32627 |
ranu |
127 |
if (customer.getAddress() != null) {
|
|
|
128 |
if ((customer.getAddress().getLine1() != null && !customer.getAddress().getLine1().trim().isEmpty()) || (customer.getAddress().getLine2() != null && !customer.getAddress().getLine2().trim().isEmpty())) {
|
|
|
129 |
columnCustomerInfo.addElement(new Paragraph(StringUtils.capitalize(customer.getAddress().getLine1()) + ", " + StringUtils.capitalize(customer.getAddress().getLine2()), FONT_NORMAL));
|
|
|
130 |
}
|
|
|
131 |
if ((customer.getAddress().getCity() != null && !customer.getAddress().getCity().trim().isEmpty()) || (customer.getAddress().getState() != null && !customer.getAddress().getState().trim().isEmpty())) {
|
|
|
132 |
columnCustomerInfo.addElement(new Paragraph(StringUtils.capitalize(customer.getAddress().getCity()) + ", " + StringUtils.capitalize(customer.getAddress().getState()) + "(" + pdfModel.getCustomerAddressStateCode() + ")" + "\n" + customer.getAddress().getPinCode(), FONT_NORMAL));
|
|
|
133 |
}
|
|
|
134 |
}
|
|
|
135 |
|
| 32275 |
tejbeer |
136 |
columnCustomerInfo.addElement(new Paragraph("Mobile - " + customer.getAddress().getPhoneNumber(), FONT_NORMAL));
|
|
|
137 |
if (customer.getGstNumber() != null && !customer.getGstNumber().isEmpty()) {
|
|
|
138 |
columnCustomerInfo.addElement(new Paragraph("GST Number - " + customer.getGstNumber(), FONT_NORMAL));
|
|
|
139 |
}
|
|
|
140 |
columnCustomerInfo.setBorder(Rectangle.NO_BORDER);
|
|
|
141 |
PdfPCell columnRetailerInfo = new PdfPCell();
|
|
|
142 |
columnRetailerInfo.addElement(new Paragraph(StringUtils.capitalize(retailer.getAddress().getName()), FONT_BOLD));
|
|
|
143 |
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));
|
|
|
144 |
columnRetailerInfo.addElement(new Paragraph("Contact No.- " + retailer.getAddress().getPhoneNumber(), FONT_BOLD));
|
|
|
145 |
columnRetailerInfo.addElement(new Paragraph("GST NO. " + retailer.getGstNumber(), FONT_BOLD));
|
|
|
146 |
columnRetailerInfo.setBorder(Rectangle.NO_BORDER);
|
| 23509 |
amit.gupta |
147 |
|
| 32275 |
tejbeer |
148 |
PdfPTable tableInvoiceDateRetailer = new PdfPTable(1);
|
|
|
149 |
tableInvoiceDateRetailer.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
| 23509 |
amit.gupta |
150 |
|
| 32275 |
tejbeer |
151 |
PdfPTable tableInvoiceDate = new PdfPTable(2);
|
|
|
152 |
tableInvoiceDate.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
| 23509 |
amit.gupta |
153 |
|
| 32275 |
tejbeer |
154 |
PdfPCell invoiceNumberKey = new PdfPCell(new Paragraph("Invoice No:", FONT_NORMAL));
|
|
|
155 |
invoiceNumberKey.setBorder(Rectangle.NO_BORDER);
|
| 23509 |
amit.gupta |
156 |
|
| 32275 |
tejbeer |
157 |
PdfPCell invoiceNumberValue = new PdfPCell(new Paragraph(pdfModel.getInvoiceNumber(), FONT_NORMAL));
|
|
|
158 |
invoiceNumberValue.setBorder(Rectangle.NO_BORDER);
|
| 23509 |
amit.gupta |
159 |
|
| 32275 |
tejbeer |
160 |
PdfPCell dateKey = new PdfPCell(new Paragraph("Date:", FONT_NORMAL));
|
|
|
161 |
dateKey.setBorder(Rectangle.NO_BORDER);
|
| 23509 |
amit.gupta |
162 |
|
| 32275 |
tejbeer |
163 |
PdfPCell dateValue = new PdfPCell(new Paragraph(pdfModel.getInvoiceDate(), FONT_NORMAL));
|
|
|
164 |
dateValue.setBorder(Rectangle.NO_BORDER);
|
|
|
165 |
tableInvoiceDate.addCell(invoiceNumberKey);
|
|
|
166 |
// tableInvoiceDate.addCell(blankCell);
|
|
|
167 |
tableInvoiceDate.addCell(invoiceNumberValue);
|
|
|
168 |
tableInvoiceDate.addCell(dateKey);
|
|
|
169 |
// tableInvoiceDate.addCell(blankCell);
|
|
|
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 |
|
| 32275 |
tejbeer |
177 |
PdfPTable orders = null;
|
|
|
178 |
if (stateGst) {
|
|
|
179 |
orders = new PdfPTable(stateWidthsWithDiscount.length);
|
|
|
180 |
orders.setWidths(stateWidthsWithDiscount);
|
|
|
181 |
} else {
|
|
|
182 |
orders = new PdfPTable(igstWidthsWithDiscount.length);
|
|
|
183 |
orders.setWidths(igstWidthsWithDiscount);
|
|
|
184 |
}
|
|
|
185 |
orders.setWidthPercentage(90);
|
|
|
186 |
orders.addCell(new Paragraph("Sl", FONT_BOLD));
|
|
|
187 |
orders.addCell(new Paragraph("Description", FONT_BOLD));
|
|
|
188 |
orders.addCell(new Paragraph("HSN", FONT_BOLD));
|
|
|
189 |
orders.addCell(new Paragraph("Qty", FONT_BOLD));
|
|
|
190 |
orders.addCell(new Paragraph("Rate\n(Per pc)", FONT_BOLD));
|
|
|
191 |
orders.addCell(new Paragraph("Discount", FONT_BOLD));
|
|
|
192 |
orders.addCell(new Paragraph("Total\nTaxable", FONT_BOLD));
|
|
|
193 |
if (!stateGst) {
|
|
|
194 |
orders.addCell(new Paragraph("IGST", FONT_BOLD));
|
|
|
195 |
// orders.setWidths(new float[]{1, 3, 1, 1, 1, 1, 1, 1});
|
|
|
196 |
// total 8f
|
|
|
197 |
} else {
|
|
|
198 |
orders.addCell(new Paragraph("CGST", FONT_BOLD));
|
|
|
199 |
orders.addCell(new Paragraph("SGST", FONT_BOLD));
|
|
|
200 |
// orders.setWidths(new float[]{1, 3, 1, 1, 1, 1, 1, 1, 1, 1});
|
|
|
201 |
// total 8f
|
|
|
202 |
}
|
|
|
203 |
orders.addCell(new Paragraph("Total", FONT_BOLD));
|
| 23509 |
amit.gupta |
204 |
|
| 32275 |
tejbeer |
205 |
// orders.addCell(new Paragraph("Item Total (Rs)", FONT_BOLD));
|
| 23509 |
amit.gupta |
206 |
|
| 32275 |
tejbeer |
207 |
orders.setHeaderRows(1);
|
|
|
208 |
// orders.setSkipFirstHeader(true);
|
| 23509 |
amit.gupta |
209 |
|
| 32275 |
tejbeer |
210 |
float igstTotalAmount = 0, cgstTotalAmount = 0, sgstTotalAmount = 0;
|
|
|
211 |
int index = 1;
|
|
|
212 |
for (CustomOrderItem orderItem : orderItems) {
|
|
|
213 |
orders.addCell(new Paragraph(String.valueOf(index++), FONT_NORMAL));
|
|
|
214 |
orders.addCell(new Paragraph(orderItem.getDescription(), FONT_NORMAL));
|
|
|
215 |
orders.addCell(new Paragraph(orderItem.getHsnCode(), FONT_NORMAL));
|
|
|
216 |
orders.addCell(new Paragraph(String.valueOf(orderItem.getQuantity()), FONT_NORMAL));
|
|
|
217 |
orders.addCell(new Paragraph(String.format("%.2f", orderItem.getRate()), FONT_NORMAL));
|
|
|
218 |
orders.addCell(new Paragraph(String.format("%.2f", orderItem.getDiscount()), FONT_NORMAL));
|
|
|
219 |
orders.addCell(new Paragraph(String.format("%.2f", orderItem.getAmount()), FONT_NORMAL));
|
|
|
220 |
if (!stateGst) {
|
|
|
221 |
orders.addCell(new Paragraph(String.format("%.2f%n(@%.0f%%)", orderItem.getIgstAmount(), orderItem.getIgstRate()), FONT_NORMAL));
|
|
|
222 |
igstTotalAmount = igstTotalAmount + orderItem.getIgstAmount();
|
|
|
223 |
} else {
|
|
|
224 |
orders.addCell(new Paragraph(String.format("%.2f%n(@%.0f%%)", orderItem.getCgstAmount(), orderItem.getCgstRate()), FONT_NORMAL));
|
|
|
225 |
orders.addCell(new Paragraph(String.format("%.2f%n(@%.0f%%)", orderItem.getSgstAmount(), orderItem.getSgstRate()), FONT_NORMAL));
|
|
|
226 |
cgstTotalAmount = cgstTotalAmount + orderItem.getCgstAmount();
|
|
|
227 |
sgstTotalAmount = sgstTotalAmount + orderItem.getSgstAmount();
|
|
|
228 |
}
|
|
|
229 |
orders.addCell(new Paragraph(String.format("%.0f", orderItem.getNetAmount()), FONT_NORMAL));
|
|
|
230 |
// orders.addCell(new Paragraph(String.format("%.2f",
|
|
|
231 |
// orderItem.getItemTotal()), FONT_NORMAL));
|
|
|
232 |
}
|
|
|
233 |
if (pdfModel.getInsurancePolicies() != null) {
|
|
|
234 |
for (CustomInsurancePolicy insurancePolicy : pdfModel.getInsurancePolicies()) {
|
|
|
235 |
orders.addCell(new Paragraph(String.valueOf(index++), FONT_NORMAL));
|
|
|
236 |
orders.addCell(new Paragraph(insurancePolicy.getDescription(), FONT_NORMAL));
|
|
|
237 |
orders.addCell(new Paragraph(insurancePolicy.getHsnCode(), FONT_NORMAL));
|
|
|
238 |
orders.addCell(new Paragraph("1", FONT_NORMAL));
|
|
|
239 |
orders.addCell(new Paragraph(String.format("%.2f", insurancePolicy.getRate()), FONT_NORMAL));
|
|
|
240 |
orders.addCell(new Paragraph("-", FONT_NORMAL));
|
|
|
241 |
orders.addCell(new Paragraph(String.format("%.2f", insurancePolicy.getRate()), FONT_NORMAL));
|
|
|
242 |
if (!stateGst) {
|
|
|
243 |
orders.addCell(new Paragraph(String.format("%.2f%n(@%.0f%%)", insurancePolicy.getIgstAmount(), insurancePolicy.getIgstRate()), FONT_NORMAL));
|
|
|
244 |
igstTotalAmount = igstTotalAmount + insurancePolicy.getIgstAmount();
|
|
|
245 |
} else {
|
|
|
246 |
orders.addCell(new Paragraph(String.format("%.2f%n(@%.0f%%)", insurancePolicy.getCgstAmount(), insurancePolicy.getCgstRate()), FONT_NORMAL));
|
|
|
247 |
orders.addCell(new Paragraph(String.format("%.2f%n(@%.0f%%)", insurancePolicy.getSgstAmount(), insurancePolicy.getSgstRate()), FONT_NORMAL));
|
|
|
248 |
cgstTotalAmount = cgstTotalAmount + insurancePolicy.getCgstAmount();
|
|
|
249 |
sgstTotalAmount = sgstTotalAmount + insurancePolicy.getSgstAmount();
|
|
|
250 |
}
|
|
|
251 |
orders.addCell(new Paragraph(String.format("%.0f", insurancePolicy.getNetAmount()), FONT_NORMAL));
|
|
|
252 |
}
|
|
|
253 |
}
|
| 32980 |
amit.gupta |
254 |
|
| 32275 |
tejbeer |
255 |
iconImg.setAbsolutePosition(25, rectangle.getHeight() - 100);
|
|
|
256 |
iconImg.scalePercent(30);
|
| 30400 |
amit.gupta |
257 |
|
| 32275 |
tejbeer |
258 |
document.add(iconImg);
|
|
|
259 |
document.add(Chunk.NEWLINE);
|
|
|
260 |
document.add(Chunk.NEWLINE);
|
|
|
261 |
document.add(tableCustomerRetailer);
|
| 23509 |
amit.gupta |
262 |
|
| 32275 |
tejbeer |
263 |
document.add(Chunk.NEWLINE);
|
|
|
264 |
document.add(orders);
|
| 23509 |
amit.gupta |
265 |
|
| 32275 |
tejbeer |
266 |
PdfPTable grandTotalTable = new PdfPTable(3);
|
|
|
267 |
PdfPTable paymentsTable = new PdfPTable(2);
|
|
|
268 |
paymentsTable.setWidthPercentage(95);
|
|
|
269 |
paymentsTable.setWidths(new float[]{8f, 2f});
|
| 23509 |
amit.gupta |
270 |
|
| 32275 |
tejbeer |
271 |
if (stateGst) {
|
|
|
272 |
grandTotalTable.setWidths(new float[]{6.6f, .6f, .8f});
|
|
|
273 |
} else {
|
|
|
274 |
grandTotalTable.setWidths(new float[]{6.5f, .6f, .9f});
|
|
|
275 |
}
|
|
|
276 |
grandTotalTable.setWidthPercentage(90);
|
| 23654 |
amit.gupta |
277 |
|
| 32275 |
tejbeer |
278 |
Paragraph grandTotalParagraph = new Paragraph("Grand total", FONT_BOLD);
|
|
|
279 |
grandTotalParagraph.setIndentationRight(20);
|
|
|
280 |
grandTotalTable.addCell(grandTotalParagraph);
|
|
|
281 |
Paragraph rsParagraph = new Paragraph("Rs.", FONT_BOLD);
|
|
|
282 |
grandTotalTable.addCell(rsParagraph);
|
|
|
283 |
Paragraph amountParagraph = new Paragraph(String.format("%.2f", pdfModel.getTotalAmount()), FONT_BOLD);
|
|
|
284 |
grandTotalTable.addCell(amountParagraph);
|
| 24845 |
amit.gupta |
285 |
|
| 32275 |
tejbeer |
286 |
document.add(grandTotalTable);
|
| 24845 |
amit.gupta |
287 |
|
| 32275 |
tejbeer |
288 |
PdfPTable amountInWordsTable = new PdfPTable(3);
|
|
|
289 |
amountInWordsTable.setWidthPercentage(90);
|
|
|
290 |
amountInWordsTable.addCell(new Paragraph("Amount in Words:", FONT_BOLD));
|
|
|
291 |
if (!stateGst) {
|
|
|
292 |
amountInWordsTable.setWidths(new float[]{2, 5.1f, 0.9f});
|
|
|
293 |
} else {
|
|
|
294 |
amountInWordsTable.setWidths(new float[]{2, 5.2f, 0.8f});
|
|
|
295 |
}
|
| 23509 |
amit.gupta |
296 |
|
| 32275 |
tejbeer |
297 |
String amountInWords = toAmountInWords(pdfModel.getTotalAmount());
|
|
|
298 |
amountInWordsTable.addCell(new Paragraph(amountInWords.toString(), FONT_BOLD));
|
|
|
299 |
amountInWordsTable.addCell(new Paragraph("E & O.E", FONT_NORMAL));
|
|
|
300 |
document.add(amountInWordsTable);
|
| 23654 |
amit.gupta |
301 |
|
| 32275 |
tejbeer |
302 |
if (pdfModel.getPaymentOptions() != null) {
|
|
|
303 |
PdfPTable paidAmountTable = new PdfPTable(2);
|
|
|
304 |
paidAmountTable.setWidthPercentage(90);
|
|
|
305 |
if (!stateGst) {
|
|
|
306 |
paidAmountTable.setWidths(new float[]{7.1f, 0.9f});
|
|
|
307 |
} else {
|
|
|
308 |
paidAmountTable.setWidths(new float[]{7.2f, 0.8f});
|
|
|
309 |
}
|
|
|
310 |
float totalPaidValue = 0;
|
|
|
311 |
for (CustomPaymentOption paymentOption : pdfModel.getPaymentOptions()) {
|
| 33795 |
ranu |
312 |
LOGGER.info("paymentOption - {}", paymentOption);
|
|
|
313 |
if (!"CASH DISCOUNT".equals(paymentOption.getPaymentOption())) {
|
|
|
314 |
PdfPCell cell = new PdfPCell(
|
|
|
315 |
new Paragraph(10, "Paid Through " + paymentOption.getPaymentOption(), FONT_BOLD));
|
|
|
316 |
cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
|
|
|
317 |
cell.setPadding(5);
|
|
|
318 |
paidAmountTable.addCell(cell);
|
| 23654 |
amit.gupta |
319 |
|
| 33795 |
ranu |
320 |
PdfPCell cell1 = new PdfPCell(new Paragraph(10, FormattingUtils.formatDecimal(paymentOption.getAmount()), FONT_BOLD));
|
|
|
321 |
cell1.setPadding(5);
|
|
|
322 |
paidAmountTable.addCell(cell1);
|
|
|
323 |
totalPaidValue += paymentOption.getAmount();
|
|
|
324 |
}
|
| 32275 |
tejbeer |
325 |
}
|
|
|
326 |
PdfPCell totalPaidCell = new PdfPCell(new Paragraph(10, "Total Paid", FONT_BOLD));
|
|
|
327 |
totalPaidCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
|
|
|
328 |
totalPaidCell.setPadding(5);
|
|
|
329 |
paidAmountTable.addCell(totalPaidCell);
|
| 23558 |
amit.gupta |
330 |
|
| 32275 |
tejbeer |
331 |
PdfPCell totalPaidValueCell = new PdfPCell(
|
|
|
332 |
new Paragraph(10, FormattingUtils.formatDecimal(totalPaidValue), FONT_BOLD));
|
|
|
333 |
totalPaidValueCell.setPadding(5);
|
|
|
334 |
paidAmountTable.addCell(totalPaidValueCell);
|
| 23509 |
amit.gupta |
335 |
|
| 32275 |
tejbeer |
336 |
document.add(paidAmountTable);
|
|
|
337 |
}
|
| 32980 |
amit.gupta |
338 |
Paragraph autoGenerateParagraph = new Paragraph("Note - This is computer generated Invoice, no signature is required", FONT_NORMAL);
|
|
|
339 |
autoGenerateParagraph.setAlignment(Element.ALIGN_CENTER);
|
|
|
340 |
document.add(autoGenerateParagraph);
|
| 24845 |
amit.gupta |
341 |
|
| 35024 |
amit |
342 |
if(pdfModel.getCreditTerms()!=null) {
|
|
|
343 |
// Use monospaced Courier font to preserve spaces/indentation
|
|
|
344 |
|
|
|
345 |
// Title
|
| 35025 |
amit |
346 |
Paragraph title = new Paragraph("Credit terms :-\n", FONT_BOLD);
|
| 35024 |
amit |
347 |
title.setIndentationLeft(25);
|
|
|
348 |
title.setIndentationRight(25);
|
|
|
349 |
document.add(title);
|
|
|
350 |
|
|
|
351 |
// Exact text block (with spaces preserved)
|
|
|
352 |
StringBuffer termsBuffer = new StringBuffer();
|
|
|
353 |
int count = 0;
|
|
|
354 |
for (String creditTerm : pdfModel.getCreditTerms()) {
|
|
|
355 |
count++;
|
|
|
356 |
termsBuffer.append(count).append(". ").append(creditTerm).append(".\n");
|
|
|
357 |
}
|
|
|
358 |
|
|
|
359 |
|
| 35025 |
amit |
360 |
Paragraph body = new Paragraph(termsBuffer.toString(), FONT_NORMAL);
|
| 35024 |
amit |
361 |
body.setIndentationLeft(25);
|
|
|
362 |
body.setIndentationRight(25);
|
|
|
363 |
document.add(body);
|
|
|
364 |
|
|
|
365 |
}
|
| 32275 |
tejbeer |
366 |
if (pdfModel.getTncs() != null) {
|
|
|
367 |
StringBuffer sb = new StringBuffer();
|
|
|
368 |
for (String tnc : pdfModel.getTncs()) {
|
|
|
369 |
sb.append(tnc).append("\n");
|
|
|
370 |
}
|
|
|
371 |
Paragraph warningParagraph = new Paragraph(sb.toString(), FONT_NORMAL);
|
|
|
372 |
warningParagraph.setIndentationLeft(40);
|
|
|
373 |
document.add(Chunk.NEWLINE);
|
|
|
374 |
document.add(warningParagraph);
|
|
|
375 |
}
|
| 24845 |
amit.gupta |
376 |
|
| 32275 |
tejbeer |
377 |
document.newPage();
|
| 35024 |
amit |
378 |
if (pdfModel.geteWayBillPdfModel() != null) {
|
| 33741 |
amit.gupta |
379 |
|
|
|
380 |
EWayBillPDF.generateDocument(document, pdfWriter, pdfModel.geteWayBillPdfModel());
|
|
|
381 |
}
|
| 32275 |
tejbeer |
382 |
}
|
|
|
383 |
document.close(); // no need to close PDFwriter?
|
| 35024 |
amit |
384 |
if (cancelledPages) {
|
| 32991 |
amit.gupta |
385 |
stampCancelled(outputStream, caneclledPageList);
|
|
|
386 |
}
|
| 23509 |
amit.gupta |
387 |
|
| 32275 |
tejbeer |
388 |
} catch (DocumentException e) {
|
|
|
389 |
LOGGER.error("Unable to write data to pdf file : ", e);
|
|
|
390 |
} catch (Exception e) {
|
|
|
391 |
// TODO Auto-generated catch block
|
|
|
392 |
e.printStackTrace();
|
|
|
393 |
}
|
| 24506 |
amit.gupta |
394 |
|
| 32275 |
tejbeer |
395 |
}
|
| 23509 |
amit.gupta |
396 |
|
| 32980 |
amit.gupta |
397 |
private static void addIrnDetails(IrnModel irnModel, Rectangle rectangle, Document document) throws IOException, DocumentException {
|
|
|
398 |
PdfPTable taxTable = new PdfPTable(1);
|
|
|
399 |
taxTable.setWidthPercentage(45);
|
|
|
400 |
PdfPCell pdfCell = new PdfPCell();
|
|
|
401 |
pdfCell.setBorder(Rectangle.NO_BORDER);
|
|
|
402 |
Image img = Image.getInstance(irnModel.getQrCode().toURI().toURL());
|
|
|
403 |
img.setAbsolutePosition(450f, rectangle.getHeight() - 140);
|
|
|
404 |
document.add(img);
|
|
|
405 |
Paragraph irnParagraph = new Paragraph("IRN No - " + irnModel.getIrnNumber(), FONT_NORMAL);
|
|
|
406 |
irnParagraph.setAlignment(Element.ALIGN_LEFT);
|
|
|
407 |
pdfCell.addElement(irnParagraph);
|
|
|
408 |
|
| 35024 |
amit |
409 |
Paragraph ackParagraph = new Paragraph("Ack No - " + irnModel.getAcknowledgeNumber(), FONT_NORMAL);
|
| 32980 |
amit.gupta |
410 |
ackParagraph.setAlignment(Element.ALIGN_LEFT);
|
|
|
411 |
pdfCell.addElement(ackParagraph);
|
|
|
412 |
|
|
|
413 |
Paragraph ackDateParagraph = new Paragraph("Ack Date - " + FormattingUtils.format(irnModel.getAcknowledgeDate()), FONT_NORMAL);
|
|
|
414 |
ackDateParagraph.setAlignment(Element.ALIGN_LEFT);
|
|
|
415 |
pdfCell.addElement(ackDateParagraph);
|
|
|
416 |
taxTable.addCell(pdfCell);
|
|
|
417 |
document.add(taxTable);
|
|
|
418 |
}
|
|
|
419 |
|
| 32275 |
tejbeer |
420 |
private static void stampCancelled(ByteArrayOutputStream byteStream, List<Integer> cancelledPage) throws IOException, DocumentException {
|
|
|
421 |
ByteArrayInputStream bais = new ByteArrayInputStream(byteStream.toByteArray());
|
|
|
422 |
PdfReader pdfReader = new PdfReader(bais);
|
|
|
423 |
int n = pdfReader.getNumberOfPages();
|
|
|
424 |
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
|
|
425 |
PdfStamper pdfStamper = new PdfStamper(pdfReader, baos);
|
|
|
426 |
pdfStamper.setRotateContents(false);
|
|
|
427 |
// text watermark
|
|
|
428 |
Font f = new Font(FontFamily.HELVETICA, 30);
|
|
|
429 |
Phrase p = new Phrase("My watermark (text)", f);
|
|
|
430 |
URL cancelledImgUrl = PdfUtils.class.getClassLoader().getResource("cancelled.png");
|
|
|
431 |
URL waterMarkImgUrl = PdfUtils.class.getClassLoader().getResource("sd1.jpg");
|
|
|
432 |
Image imgCancelled = Image.getInstance(cancelledImgUrl);
|
|
|
433 |
Image imgWatermark = Image.getInstance(waterMarkImgUrl);
|
|
|
434 |
imgWatermark.scaleAbsolute(imgWatermark.getScaledWidth() * 2.5f, imgWatermark.getScaledHeight() * 2.5f);
|
|
|
435 |
float w = imgCancelled.getScaledWidth() / 2;
|
|
|
436 |
float h = imgCancelled.getScaledHeight() / 2;
|
|
|
437 |
float wWaterMark = imgWatermark.getScaledWidth() / 2;
|
|
|
438 |
float hWatermark = imgWatermark.getScaledHeight() / 2;
|
|
|
439 |
// transparency
|
|
|
440 |
PdfGState gs1 = new PdfGState();
|
| 32980 |
amit.gupta |
441 |
gs1.setFillOpacity(0.4f);
|
| 32275 |
tejbeer |
442 |
PdfGState gs2 = new PdfGState();
|
| 32980 |
amit.gupta |
443 |
gs2.setFillOpacity(0.05f);
|
| 32275 |
tejbeer |
444 |
// properties
|
|
|
445 |
PdfContentByte over;
|
|
|
446 |
Rectangle pagesize;
|
|
|
447 |
float x, y;
|
| 24506 |
amit.gupta |
448 |
|
| 32275 |
tejbeer |
449 |
// loop over every page
|
|
|
450 |
for (int i = 1; i <= n; i++) {
|
|
|
451 |
pagesize = pdfReader.getPageSize(i);
|
|
|
452 |
x = (pagesize.getLeft() + pagesize.getRight()) / 2;
|
|
|
453 |
y = (pagesize.getTop() + pagesize.getBottom()) / 2;
|
|
|
454 |
over = pdfStamper.getOverContent(i);
|
|
|
455 |
over.saveState();
|
|
|
456 |
if (cancelledPage.get(i - 1) == 1) {
|
|
|
457 |
over.setGState(gs1);
|
|
|
458 |
over.addImage(imgCancelled, w, 0, 0, h, x - (w / 2), y - (h / 2));
|
|
|
459 |
over.restoreState();
|
|
|
460 |
} else {
|
|
|
461 |
over.setGState(gs2);
|
|
|
462 |
over.addImage(imgWatermark, wWaterMark, 0, 0, hWatermark, x - (wWaterMark / 2), y - (hWatermark / 2));
|
|
|
463 |
over.restoreState();
|
|
|
464 |
}
|
|
|
465 |
}
|
|
|
466 |
pdfStamper.close();
|
|
|
467 |
pdfReader.close();
|
|
|
468 |
baos.writeTo(byteStream);
|
| 24845 |
amit.gupta |
469 |
|
| 32275 |
tejbeer |
470 |
}
|
| 24506 |
amit.gupta |
471 |
|
| 32275 |
tejbeer |
472 |
public static void generateAndWriteDebitNote(List<DebitNotePdfModel> debitNotePdfModels, OutputStream outputStream) {
|
|
|
473 |
Document document = new Document();
|
|
|
474 |
document.setMargins(0, 0, 25, 0);
|
|
|
475 |
try {
|
|
|
476 |
for (DebitNotePdfModel debitNotePdfModel : debitNotePdfModels) {
|
| 23509 |
amit.gupta |
477 |
|
| 32275 |
tejbeer |
478 |
InvoicePdfModel pdfModel = debitNotePdfModel.getPdfModel();
|
|
|
479 |
CustomCustomer customer = pdfModel.getCustomer();
|
|
|
480 |
CustomRetailer retailer = pdfModel.getRetailer();
|
|
|
481 |
boolean stateGst = false;
|
| 32290 |
tejbeer |
482 |
|
|
|
483 |
LOGGER.info("Customer - {}", customer.getAddress().getState());
|
|
|
484 |
LOGGER.info("retailer - {}", retailer.getAddress().getState());
|
|
|
485 |
|
|
|
486 |
|
| 32292 |
tejbeer |
487 |
if (customer.getAddress().getState().equals(retailer.getAddress().getState())) {
|
|
|
488 |
stateGst = true;
|
|
|
489 |
}
|
| 33298 |
amit.gupta |
490 |
List<CustomOrderItem> orderItems = pdfModel.getOrderItems();
|
| 23509 |
amit.gupta |
491 |
|
| 32275 |
tejbeer |
492 |
PdfWriter.getInstance(document, outputStream);
|
| 23509 |
amit.gupta |
493 |
|
| 32275 |
tejbeer |
494 |
document.open();
|
|
|
495 |
document.addTitle(pdfModel.getTitle());
|
|
|
496 |
document.addAuthor(pdfModel.getAuther());
|
| 23509 |
amit.gupta |
497 |
|
| 32275 |
tejbeer |
498 |
Paragraph paragraphTitle = new Paragraph(pdfModel.getTitle(), FONT_TITLE);
|
|
|
499 |
paragraphTitle.setAlignment(Element.ALIGN_CENTER);
|
| 23509 |
amit.gupta |
500 |
|
| 32275 |
tejbeer |
501 |
PdfPCell blankCell = new PdfPCell();
|
|
|
502 |
blankCell.setBorder(Rectangle.NO_BORDER);
|
|
|
503 |
PdfPTable tableCustomerRetailer = new PdfPTable(3);
|
|
|
504 |
tableCustomerRetailer.setWidthPercentage(95);
|
|
|
505 |
PdfPCell partnerInfo = new PdfPCell();
|
|
|
506 |
partnerInfo.addElement(new Paragraph("From Party:", FONT_BOLD));
|
|
|
507 |
partnerInfo.addElement(
|
|
|
508 |
new Paragraph(StringUtils.capitalize(customer.getAddress().getName()), FONT_NORMAL));
|
|
|
509 |
partnerInfo.addElement(new Paragraph(
|
| 32289 |
tejbeer |
510 |
(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 |
511 |
|
| 32275 |
tejbeer |
512 |
partnerInfo.addElement(new Paragraph(
|
|
|
513 |
StringUtils.capitalize(customer.getAddress().getState()) + "(" + pdfModel.getCustomerAddressStateCode() + ")", FONT_NORMAL));
|
|
|
514 |
partnerInfo.addElement(new Paragraph("Mobile - " + customer.getMobileNumber(), FONT_NORMAL));
|
|
|
515 |
if (customer.getGstNumber() != null && !customer.getGstNumber().isEmpty()) {
|
|
|
516 |
partnerInfo.addElement(new Paragraph("GST No - " + customer.getGstNumber(), FONT_BOLD));
|
|
|
517 |
}
|
| 23533 |
amit.gupta |
518 |
|
| 32275 |
tejbeer |
519 |
PdfPCell sellerParty = new PdfPCell();
|
|
|
520 |
sellerParty.addElement(new Paragraph("To Party:", FONT_BOLD));
|
|
|
521 |
sellerParty.addElement(
|
|
|
522 |
new Paragraph(StringUtils.capitalize(retailer.getAddress().getName()), FONT_NORMAL));
|
| 32289 |
tejbeer |
523 |
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 |
524 |
sellerParty.addElement(new Paragraph(
|
|
|
525 |
retailer.getAddress().getState() + "(" + pdfModel.getPartnerAddressStateCode() + ")", FONT_NORMAL));
|
|
|
526 |
sellerParty.addElement(new Paragraph("Mobile - " + retailer.getAddress().getPhoneNumber(), FONT_NORMAL));
|
|
|
527 |
sellerParty.addElement(new Paragraph("GST No - " + retailer.getGstNumber(), FONT_BOLD));
|
| 23509 |
amit.gupta |
528 |
|
| 32275 |
tejbeer |
529 |
PdfPTable tableInvoiceDateRetailer = new PdfPTable(1);
|
|
|
530 |
tableInvoiceDateRetailer.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
| 23509 |
amit.gupta |
531 |
|
| 32275 |
tejbeer |
532 |
PdfPTable tableInvoiceDate = new PdfPTable(2);
|
|
|
533 |
tableInvoiceDate.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
|
|
534 |
tableInvoiceDate.setWidthPercentage(90);
|
| 23509 |
amit.gupta |
535 |
|
| 32275 |
tejbeer |
536 |
PdfPCell debitNoteDetails = new PdfPCell(new Paragraph("Debit Note Details", FONT_BOLD));
|
|
|
537 |
debitNoteDetails.setColspan(2);
|
|
|
538 |
debitNoteDetails.setBorder(Rectangle.NO_BORDER);
|
| 23654 |
amit.gupta |
539 |
|
| 32275 |
tejbeer |
540 |
PdfPCell debitNoteNumberKey = new PdfPCell(new Paragraph("Debit Note No:", FONT_NORMAL));
|
|
|
541 |
debitNoteNumberKey.setBorder(Rectangle.NO_BORDER);
|
|
|
542 |
PdfPCell debitNoteNumberValue = new PdfPCell(
|
|
|
543 |
new Paragraph(debitNotePdfModel.getDebitNoteNumber(), FONT_NORMAL));
|
|
|
544 |
debitNoteNumberValue.setBorder(Rectangle.NO_BORDER);
|
| 23532 |
amit.gupta |
545 |
|
| 32275 |
tejbeer |
546 |
PdfPCell debitNoteDateKey = new PdfPCell(new Paragraph("Debit Note Dt:", FONT_NORMAL));
|
|
|
547 |
debitNoteDateKey.setBorder(Rectangle.NO_BORDER);
|
| 23533 |
amit.gupta |
548 |
|
| 32275 |
tejbeer |
549 |
PdfPCell debitNoteDateValue = new PdfPCell(
|
|
|
550 |
new Paragraph(debitNotePdfModel.getDebitNoteDate(), FONT_NORMAL));
|
|
|
551 |
debitNoteDateValue.setBorder(Rectangle.NO_BORDER);
|
| 23532 |
amit.gupta |
552 |
|
| 32275 |
tejbeer |
553 |
PdfPCell invoiceNumberKey = new PdfPCell(new Paragraph("Invoice Ref No:", FONT_NORMAL));
|
|
|
554 |
invoiceNumberKey.setBorder(Rectangle.NO_BORDER);
|
|
|
555 |
PdfPCell invoiceNumberValue = new PdfPCell(new Paragraph(pdfModel.getInvoiceNumber(), FONT_NORMAL));
|
|
|
556 |
invoiceNumberValue.setBorder(Rectangle.NO_BORDER);
|
| 23509 |
amit.gupta |
557 |
|
| 32275 |
tejbeer |
558 |
PdfPCell dateKey = new PdfPCell(new Paragraph("Invoice Dt:", FONT_NORMAL));
|
|
|
559 |
dateKey.setBorder(Rectangle.NO_BORDER);
|
|
|
560 |
PdfPCell dateValue = new PdfPCell(new Paragraph(pdfModel.getInvoiceDate(), FONT_NORMAL));
|
|
|
561 |
dateValue.setBorder(Rectangle.NO_BORDER);
|
| 23533 |
amit.gupta |
562 |
|
| 32275 |
tejbeer |
563 |
tableInvoiceDate.addCell(debitNoteDetails);
|
|
|
564 |
tableInvoiceDate.addCell(debitNoteNumberKey);
|
|
|
565 |
tableInvoiceDate.addCell(debitNoteNumberValue);
|
|
|
566 |
tableInvoiceDate.addCell(debitNoteDateKey);
|
|
|
567 |
tableInvoiceDate.addCell(debitNoteDateValue);
|
|
|
568 |
tableInvoiceDate.addCell(invoiceNumberKey);
|
|
|
569 |
tableInvoiceDate.addCell(invoiceNumberValue);
|
|
|
570 |
tableInvoiceDate.addCell(dateKey);
|
|
|
571 |
tableInvoiceDate.addCell(dateValue);
|
| 23509 |
amit.gupta |
572 |
|
| 32275 |
tejbeer |
573 |
tableCustomerRetailer.addCell(partnerInfo);
|
|
|
574 |
tableCustomerRetailer.addCell(tableInvoiceDate);
|
|
|
575 |
tableCustomerRetailer.addCell(sellerParty);
|
| 23509 |
amit.gupta |
576 |
|
| 32275 |
tejbeer |
577 |
PdfPTable orders = null;
|
|
|
578 |
if (stateGst) {
|
|
|
579 |
orders = new PdfPTable(stateWidths.length);
|
|
|
580 |
orders.setWidths(stateWidths);
|
|
|
581 |
} else {
|
|
|
582 |
orders = new PdfPTable(igstWidths.length);
|
|
|
583 |
orders.setWidths(igstWidths);
|
|
|
584 |
}
|
|
|
585 |
orders.setWidthPercentage(95);
|
|
|
586 |
orders.addCell(new Paragraph("Order Id", FONT_BOLD));
|
|
|
587 |
orders.addCell(new Paragraph("Description", FONT_BOLD));
|
|
|
588 |
orders.addCell(new Paragraph("HSN", FONT_BOLD));
|
|
|
589 |
orders.addCell(new Paragraph("Qty", FONT_BOLD));
|
|
|
590 |
orders.addCell(new Paragraph("Rate\n(Per pc)", FONT_BOLD));
|
|
|
591 |
orders.addCell(new Paragraph("Total\nTaxable", FONT_BOLD));
|
|
|
592 |
if (!stateGst) {
|
|
|
593 |
orders.addCell(new Paragraph("IGST\n%", FONT_BOLD));
|
|
|
594 |
orders.addCell(new Paragraph("IGST", FONT_BOLD));
|
|
|
595 |
// orders.setWidths(new float[]{1, 3, 1, 1, 1, 1, 1, 1});
|
|
|
596 |
// total 8f
|
|
|
597 |
} else {
|
|
|
598 |
orders.addCell(new Paragraph("CGST %", FONT_BOLD));
|
|
|
599 |
orders.addCell(new Paragraph("CGST", FONT_BOLD));
|
|
|
600 |
orders.addCell(new Paragraph("SGST %", FONT_BOLD));
|
|
|
601 |
orders.addCell(new Paragraph("SGST", FONT_BOLD));
|
|
|
602 |
// orders.setWidths(new float[]{1, 3, 1, 1, 1, 1, 1, 1, 1,
|
|
|
603 |
// 1});
|
|
|
604 |
// total 8f
|
|
|
605 |
}
|
|
|
606 |
orders.addCell(new Paragraph("Total", FONT_BOLD));
|
| 23509 |
amit.gupta |
607 |
|
| 32275 |
tejbeer |
608 |
orders.setHeaderRows(1);
|
| 23509 |
amit.gupta |
609 |
|
| 32275 |
tejbeer |
610 |
float igstTotalAmount = 0, cgstTotalAmount = 0, sgstTotalAmount = 0;
|
|
|
611 |
for (CustomOrderItem orderItem : orderItems) {
|
|
|
612 |
orders.addCell(new Paragraph(String.valueOf(orderItem.getOrderId()), FONT_NORMAL));
|
|
|
613 |
orders.addCell(new Paragraph(orderItem.getDescription(), FONT_NORMAL));
|
|
|
614 |
orders.addCell(new Paragraph(orderItem.getHsnCode(), FONT_NORMAL));
|
|
|
615 |
orders.addCell(new Paragraph(String.valueOf(orderItem.getQuantity()), FONT_NORMAL));
|
|
|
616 |
orders.addCell(new Paragraph(String.format("%.2f", orderItem.getRate()), FONT_NORMAL));
|
|
|
617 |
orders.addCell(new Paragraph(String.format("%.2f", orderItem.getAmount()), FONT_NORMAL));
|
|
|
618 |
if (!stateGst) {
|
|
|
619 |
orders.addCell(new Paragraph(String.format("%.2f", orderItem.getIgstRate()), FONT_NORMAL));
|
|
|
620 |
orders.addCell(new Paragraph(String.format("%.2f", orderItem.getIgstAmount()), FONT_NORMAL));
|
|
|
621 |
igstTotalAmount = igstTotalAmount + orderItem.getIgstAmount();
|
|
|
622 |
} else {
|
|
|
623 |
orders.addCell(new Paragraph(String.format("%.2f", orderItem.getCgstRate()), FONT_NORMAL));
|
|
|
624 |
orders.addCell(new Paragraph(String.format("%.2f", orderItem.getCgstAmount()), FONT_NORMAL));
|
|
|
625 |
orders.addCell(new Paragraph(String.format("%.2f", orderItem.getSgstRate()), FONT_NORMAL));
|
|
|
626 |
orders.addCell(new Paragraph(String.format("%.2f", orderItem.getSgstAmount()), FONT_NORMAL));
|
|
|
627 |
cgstTotalAmount = cgstTotalAmount + orderItem.getCgstAmount();
|
|
|
628 |
sgstTotalAmount = sgstTotalAmount + orderItem.getSgstAmount();
|
|
|
629 |
}
|
|
|
630 |
orders.addCell(new Paragraph(String.format("%.0f", orderItem.getNetAmount()), FONT_NORMAL));
|
|
|
631 |
LOGGER.info("IN FOR LOOP");
|
|
|
632 |
}
|
| 23509 |
amit.gupta |
633 |
|
| 32275 |
tejbeer |
634 |
document.add(paragraphTitle);
|
| 23533 |
amit.gupta |
635 |
|
| 32275 |
tejbeer |
636 |
document.add(Chunk.NEWLINE);
|
|
|
637 |
document.add(tableCustomerRetailer);
|
| 23509 |
amit.gupta |
638 |
|
| 32275 |
tejbeer |
639 |
document.add(Chunk.NEWLINE);
|
|
|
640 |
document.add(orders);
|
| 23509 |
amit.gupta |
641 |
|
| 32275 |
tejbeer |
642 |
PdfPTable grandTotalTable = new PdfPTable(3);
|
|
|
643 |
if (stateGst) {
|
|
|
644 |
grandTotalTable.setWidths(new float[]{6.6f, .6f, .8f});
|
|
|
645 |
} else {
|
|
|
646 |
grandTotalTable.setWidths(new float[]{6.5f, .6f, .9f});
|
|
|
647 |
}
|
|
|
648 |
grandTotalTable.setWidthPercentage(95);
|
| 23509 |
amit.gupta |
649 |
|
| 32275 |
tejbeer |
650 |
Paragraph grandTotalParagraph = new Paragraph("Grand total", FONT_BOLD);
|
|
|
651 |
grandTotalParagraph.setIndentationRight(20);
|
|
|
652 |
grandTotalTable.addCell(grandTotalParagraph);
|
|
|
653 |
Paragraph rsParagraph = new Paragraph("Rs.", FONT_BOLD);
|
|
|
654 |
grandTotalTable.addCell(rsParagraph);
|
|
|
655 |
Paragraph amountParagraph = new Paragraph(String.format("%.2f", pdfModel.getTotalAmount()), FONT_BOLD);
|
|
|
656 |
grandTotalTable.addCell(amountParagraph);
|
| 23509 |
amit.gupta |
657 |
|
| 32275 |
tejbeer |
658 |
document.add(grandTotalTable);
|
| 23509 |
amit.gupta |
659 |
|
| 32275 |
tejbeer |
660 |
PdfPTable amountInWordsTable = new PdfPTable(3);
|
|
|
661 |
if (!stateGst) {
|
|
|
662 |
amountInWordsTable.setWidths(new float[]{2, 5.1f, 0.9f});
|
|
|
663 |
} else {
|
|
|
664 |
amountInWordsTable.setWidths(new float[]{2, 5.2f, 0.8f});
|
|
|
665 |
}
|
|
|
666 |
amountInWordsTable.setWidthPercentage(95);
|
|
|
667 |
amountInWordsTable.addCell(new Paragraph("Amount in Words:", FONT_BOLD));
|
| 23509 |
amit.gupta |
668 |
|
| 32275 |
tejbeer |
669 |
String amountInWords = toAmountInWords(pdfModel.getTotalAmount());
|
|
|
670 |
amountInWordsTable.addCell(new Paragraph(amountInWords.toString(), FONT_BOLD));
|
|
|
671 |
amountInWordsTable.addCell(new Paragraph("E & O.E", FONT_NORMAL));
|
|
|
672 |
document.add(amountInWordsTable);
|
| 23509 |
amit.gupta |
673 |
|
| 32275 |
tejbeer |
674 |
document.newPage();
|
|
|
675 |
}
|
|
|
676 |
document.close(); // no need to close PDFwriter?
|
| 30539 |
amit.gupta |
677 |
|
| 32275 |
tejbeer |
678 |
} catch (DocumentException e) {
|
|
|
679 |
LOGGER.error("Unable to write data to pdf file : ", e);
|
|
|
680 |
} catch (Exception e) {
|
|
|
681 |
// TODO Auto-generated catch block
|
|
|
682 |
e.printStackTrace();
|
|
|
683 |
}
|
|
|
684 |
}
|
| 23509 |
amit.gupta |
685 |
|
| 32275 |
tejbeer |
686 |
private static String toAmountInWords(float amount) {
|
|
|
687 |
RuleBasedNumberFormat amountInWordsFormat = new RuleBasedNumberFormat(indianLocale, RuleBasedNumberFormat.SPELLOUT);
|
|
|
688 |
StringBuilder amountInWords = new StringBuilder("Rs. ");
|
|
|
689 |
amountInWords.append(StringUtils.capitalize(amountInWordsFormat.format((int) amount)));
|
|
|
690 |
amountInWords.append(" and ");
|
|
|
691 |
amountInWords.append(StringUtils.capitalize(amountInWordsFormat.format((int) (amount * 100) % 100)));
|
|
|
692 |
amountInWords.append(" paise");
|
|
|
693 |
return amountInWords.toString();
|
|
|
694 |
}
|
| 23654 |
amit.gupta |
695 |
|
| 32275 |
tejbeer |
696 |
public static void generateAndWriteCustomerCreditNotes(List<CreditNotePdfModel> creditNotes, OutputStream outputStream) {
|
|
|
697 |
Document document = new Document();
|
|
|
698 |
document.setMargins(0, 0, 25, 0);
|
|
|
699 |
try {
|
|
|
700 |
PdfWriter.getInstance(document, outputStream);
|
| 24506 |
amit.gupta |
701 |
|
| 32275 |
tejbeer |
702 |
document.open();
|
|
|
703 |
document.addTitle(creditNotes.get(0).getPdfModel().getTitle());
|
|
|
704 |
document.addAuthor(creditNotes.get(0).getPdfModel().getAuther());
|
|
|
705 |
for (CreditNotePdfModel creditNotePdfModel : creditNotes) {
|
|
|
706 |
InvoicePdfModel pdfModel = creditNotePdfModel.getPdfModel();
|
|
|
707 |
CustomCustomer customer = pdfModel.getCustomer();
|
|
|
708 |
CustomRetailer retailer = pdfModel.getRetailer();
|
|
|
709 |
boolean stateGst = false;
|
| 32290 |
tejbeer |
710 |
|
| 32275 |
tejbeer |
711 |
if (customer.getAddress().getState().equals(retailer.getAddress().getState())) {
|
|
|
712 |
stateGst = true;
|
|
|
713 |
}
|
| 33298 |
amit.gupta |
714 |
List<CustomOrderItem> orderItems = pdfModel.getOrderItems();
|
| 23654 |
amit.gupta |
715 |
|
| 32275 |
tejbeer |
716 |
Paragraph paragraphTitle = new Paragraph(pdfModel.getTitle(), FONT_TITLE);
|
|
|
717 |
paragraphTitle.setAlignment(Element.ALIGN_CENTER);
|
| 23654 |
amit.gupta |
718 |
|
| 32275 |
tejbeer |
719 |
PdfPCell blankCell = new PdfPCell();
|
|
|
720 |
blankCell.setBorder(Rectangle.NO_BORDER);
|
|
|
721 |
PdfPTable tableCustomerRetailer = new PdfPTable(3);
|
|
|
722 |
tableCustomerRetailer.setWidthPercentage(95);
|
|
|
723 |
PdfPCell partnerInfo = new PdfPCell();
|
|
|
724 |
partnerInfo.addElement(new Paragraph("To Party:", FONT_BOLD));
|
|
|
725 |
partnerInfo.addElement(
|
|
|
726 |
new Paragraph(StringUtils.capitalize(customer.getAddress().getName()), FONT_NORMAL));
|
|
|
727 |
partnerInfo.addElement(new Paragraph(
|
|
|
728 |
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 |
729 |
|
| 32275 |
tejbeer |
730 |
partnerInfo.addElement(new Paragraph(
|
|
|
731 |
StringUtils.capitalize(customer.getAddress().getState()) + "(" + pdfModel.getCustomerAddressStateCode() + ")", FONT_NORMAL));
|
|
|
732 |
partnerInfo.addElement(new Paragraph("Mobile - " + customer.getMobileNumber(), FONT_NORMAL));
|
|
|
733 |
if (customer.getGstNumber() != null && !customer.getGstNumber().isEmpty()) {
|
|
|
734 |
partnerInfo.addElement(new Paragraph("GST No - " + customer.getGstNumber(), FONT_BOLD));
|
|
|
735 |
}
|
| 23654 |
amit.gupta |
736 |
|
| 32275 |
tejbeer |
737 |
PdfPCell sellerParty = new PdfPCell();
|
|
|
738 |
sellerParty.addElement(new Paragraph("From Party:", FONT_BOLD));
|
|
|
739 |
sellerParty.addElement(
|
|
|
740 |
new Paragraph(StringUtils.capitalize(retailer.getAddress().getName()), FONT_NORMAL));
|
|
|
741 |
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));
|
|
|
742 |
sellerParty.addElement(new Paragraph(
|
|
|
743 |
retailer.getAddress().getState() + "(" + pdfModel.getPartnerAddressStateCode() + ")", FONT_NORMAL));
|
|
|
744 |
sellerParty.addElement(new Paragraph("Mobile - " + retailer.getAddress().getPhoneNumber(), FONT_NORMAL));
|
|
|
745 |
sellerParty.addElement(new Paragraph("GST No - " + retailer.getGstNumber(), FONT_BOLD));
|
| 23654 |
amit.gupta |
746 |
|
| 32275 |
tejbeer |
747 |
PdfPTable tableInvoiceDateRetailer = new PdfPTable(1);
|
|
|
748 |
tableInvoiceDateRetailer.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
| 23654 |
amit.gupta |
749 |
|
| 32275 |
tejbeer |
750 |
PdfPTable tableInvoiceDate = new PdfPTable(2);
|
|
|
751 |
tableInvoiceDate.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
|
|
752 |
tableInvoiceDate.setWidthPercentage(90);
|
| 23654 |
amit.gupta |
753 |
|
| 32275 |
tejbeer |
754 |
PdfPCell debitNoteDetails = new PdfPCell(new Paragraph("Credit Note Details", FONT_BOLD));
|
|
|
755 |
debitNoteDetails.setColspan(2);
|
|
|
756 |
debitNoteDetails.setBorder(Rectangle.NO_BORDER);
|
| 23654 |
amit.gupta |
757 |
|
| 32275 |
tejbeer |
758 |
PdfPCell debitNoteNumberKey = new PdfPCell(new Paragraph("Credit Note No:", FONT_NORMAL));
|
|
|
759 |
debitNoteNumberKey.setBorder(Rectangle.NO_BORDER);
|
|
|
760 |
PdfPCell debitNoteNumberValue = new PdfPCell(
|
|
|
761 |
new Paragraph(creditNotePdfModel.getCreditNoteNumber(), FONT_NORMAL));
|
|
|
762 |
debitNoteNumberValue.setBorder(Rectangle.NO_BORDER);
|
| 23654 |
amit.gupta |
763 |
|
| 32275 |
tejbeer |
764 |
PdfPCell debitNoteDateKey = new PdfPCell(new Paragraph("Credit Note Dt:", FONT_NORMAL));
|
|
|
765 |
debitNoteDateKey.setBorder(Rectangle.NO_BORDER);
|
| 23654 |
amit.gupta |
766 |
|
| 32275 |
tejbeer |
767 |
PdfPCell debitNoteDateValue = new PdfPCell(
|
|
|
768 |
new Paragraph(creditNotePdfModel.getCreditNoteDate(), FONT_NORMAL));
|
|
|
769 |
debitNoteDateValue.setBorder(Rectangle.NO_BORDER);
|
|
|
770 |
tableInvoiceDate.addCell(debitNoteDetails);
|
|
|
771 |
tableInvoiceDate.addCell(debitNoteNumberKey);
|
|
|
772 |
tableInvoiceDate.addCell(debitNoteNumberValue);
|
|
|
773 |
tableInvoiceDate.addCell(debitNoteDateKey);
|
|
|
774 |
tableInvoiceDate.addCell(debitNoteDateValue);
|
| 32980 |
amit.gupta |
775 |
if (pdfModel.getInvoiceNumber() != null) {
|
| 32275 |
tejbeer |
776 |
PdfPCell dateKey = new PdfPCell(new Paragraph("Invoice Dt:", FONT_NORMAL));
|
|
|
777 |
dateKey.setBorder(Rectangle.NO_BORDER);
|
|
|
778 |
PdfPCell dateValue = new PdfPCell(new Paragraph(pdfModel.getInvoiceDate(), FONT_NORMAL));
|
|
|
779 |
dateValue.setBorder(Rectangle.NO_BORDER);
|
| 23654 |
amit.gupta |
780 |
|
| 32275 |
tejbeer |
781 |
PdfPCell invoiceNumberKey = new PdfPCell(new Paragraph("Invoice Ref No:", FONT_NORMAL));
|
|
|
782 |
invoiceNumberKey.setBorder(Rectangle.NO_BORDER);
|
|
|
783 |
PdfPCell invoiceNumberValue = new PdfPCell(new Paragraph(pdfModel.getInvoiceNumber(), FONT_NORMAL));
|
|
|
784 |
invoiceNumberValue.setBorder(Rectangle.NO_BORDER);
|
|
|
785 |
tableInvoiceDate.addCell(invoiceNumberKey);
|
|
|
786 |
tableInvoiceDate.addCell(invoiceNumberValue);
|
|
|
787 |
tableInvoiceDate.addCell(dateKey);
|
|
|
788 |
tableInvoiceDate.addCell(dateValue);
|
|
|
789 |
}
|
| 31008 |
amit.gupta |
790 |
|
| 32275 |
tejbeer |
791 |
tableCustomerRetailer.addCell(partnerInfo);
|
|
|
792 |
tableCustomerRetailer.addCell(tableInvoiceDate);
|
|
|
793 |
tableCustomerRetailer.addCell(sellerParty);
|
| 23654 |
amit.gupta |
794 |
|
| 32275 |
tejbeer |
795 |
PdfPTable orders = null;
|
|
|
796 |
if (stateGst) {
|
|
|
797 |
orders = new PdfPTable(stateWidthsCrNote.length);
|
|
|
798 |
orders.setWidths(stateWidthsCrNote);
|
|
|
799 |
} else {
|
|
|
800 |
orders = new PdfPTable(igstWidthsCrNote.length);
|
|
|
801 |
orders.setWidths(igstWidthsCrNote);
|
|
|
802 |
}
|
|
|
803 |
orders.setWidthPercentage(95);
|
|
|
804 |
orders.addCell(new Paragraph("Description", FONT_BOLD));
|
|
|
805 |
orders.addCell(new Paragraph("HSN", FONT_BOLD));
|
|
|
806 |
orders.addCell(new Paragraph("Qty", FONT_BOLD));
|
|
|
807 |
orders.addCell(new Paragraph("Rate\n(Per pc)", FONT_BOLD));
|
|
|
808 |
orders.addCell(new Paragraph("Total\nTaxable", FONT_BOLD));
|
|
|
809 |
if (!stateGst) {
|
|
|
810 |
orders.addCell(new Paragraph("IGST%", FONT_BOLD));
|
|
|
811 |
orders.addCell(new Paragraph("IGST", FONT_BOLD));
|
|
|
812 |
// orders.setWidths(new float[]{1, 3, 1, 1, 1, 1, 1, 1});
|
|
|
813 |
// total 8f
|
|
|
814 |
} else {
|
|
|
815 |
orders.addCell(new Paragraph("CGST %", FONT_BOLD));
|
|
|
816 |
orders.addCell(new Paragraph("CGST", FONT_BOLD));
|
|
|
817 |
orders.addCell(new Paragraph("SGST %", FONT_BOLD));
|
|
|
818 |
orders.addCell(new Paragraph("SGST", FONT_BOLD));
|
|
|
819 |
// orders.setWidths(new float[]{1, 3, 1, 1, 1, 1, 1, 1, 1,
|
|
|
820 |
// 1});
|
|
|
821 |
// total 8f
|
|
|
822 |
}
|
|
|
823 |
orders.addCell(new Paragraph("Total", FONT_BOLD));
|
| 23654 |
amit.gupta |
824 |
|
| 32275 |
tejbeer |
825 |
orders.setHeaderRows(1);
|
| 23654 |
amit.gupta |
826 |
|
| 32275 |
tejbeer |
827 |
float igstTotalAmount = 0, cgstTotalAmount = 0, sgstTotalAmount = 0;
|
|
|
828 |
for (CustomOrderItem orderItem : orderItems) {
|
|
|
829 |
LOGGER.info("Custom Order Item - {}", orderItem);
|
|
|
830 |
orders.addCell(new Paragraph(orderItem.getDescription(), FONT_NORMAL));
|
|
|
831 |
orders.addCell(new Paragraph(orderItem.getHsnCode(), FONT_NORMAL));
|
|
|
832 |
orders.addCell(new Paragraph(String.valueOf(orderItem.getQuantity()), FONT_NORMAL));
|
|
|
833 |
orders.addCell(new Paragraph(String.format("%.2f", orderItem.getRate()), FONT_NORMAL));
|
|
|
834 |
orders.addCell(new Paragraph(String.format("%.2f", orderItem.getAmount()), FONT_NORMAL));
|
|
|
835 |
if (!stateGst) {
|
|
|
836 |
orders.addCell(new Paragraph(String.format("%.2f", orderItem.getIgstRate()), FONT_NORMAL));
|
|
|
837 |
orders.addCell(new Paragraph(String.format("%.2f", orderItem.getIgstAmount()), FONT_NORMAL));
|
|
|
838 |
igstTotalAmount = igstTotalAmount + orderItem.getIgstAmount();
|
|
|
839 |
} else {
|
|
|
840 |
orders.addCell(new Paragraph(String.format("%.2f", orderItem.getCgstRate()), FONT_NORMAL));
|
|
|
841 |
orders.addCell(new Paragraph(String.format("%.2f", orderItem.getCgstAmount()), FONT_NORMAL));
|
|
|
842 |
orders.addCell(new Paragraph(String.format("%.2f", orderItem.getSgstRate()), FONT_NORMAL));
|
|
|
843 |
orders.addCell(new Paragraph(String.format("%.2f", orderItem.getSgstAmount()), FONT_NORMAL));
|
|
|
844 |
cgstTotalAmount = cgstTotalAmount + orderItem.getCgstAmount();
|
|
|
845 |
sgstTotalAmount = sgstTotalAmount + orderItem.getSgstAmount();
|
|
|
846 |
}
|
|
|
847 |
orders.addCell(new Paragraph(String.format("%.0f", orderItem.getNetAmount()), FONT_NORMAL));
|
|
|
848 |
LOGGER.info("IN FOR LOOP");
|
|
|
849 |
}
|
| 23654 |
amit.gupta |
850 |
|
| 32275 |
tejbeer |
851 |
document.add(paragraphTitle);
|
| 23654 |
amit.gupta |
852 |
|
| 32275 |
tejbeer |
853 |
document.add(Chunk.NEWLINE);
|
|
|
854 |
document.add(tableCustomerRetailer);
|
| 23654 |
amit.gupta |
855 |
|
| 32275 |
tejbeer |
856 |
document.add(Chunk.NEWLINE);
|
|
|
857 |
document.add(orders);
|
| 23654 |
amit.gupta |
858 |
|
| 32275 |
tejbeer |
859 |
PdfPTable grandTotalTable = new PdfPTable(3);
|
|
|
860 |
if (stateGst) {
|
|
|
861 |
grandTotalTable.setWidths(new float[]{6.6f, .6f, .8f});
|
|
|
862 |
} else {
|
|
|
863 |
grandTotalTable.setWidths(new float[]{6.5f, .6f, .9f});
|
|
|
864 |
}
|
|
|
865 |
grandTotalTable.setWidthPercentage(95);
|
| 23654 |
amit.gupta |
866 |
|
| 32275 |
tejbeer |
867 |
Paragraph grandTotalParagraph = new Paragraph("Grand total", FONT_BOLD);
|
|
|
868 |
grandTotalParagraph.setIndentationRight(20);
|
|
|
869 |
grandTotalTable.addCell(grandTotalParagraph);
|
|
|
870 |
Paragraph rsParagraph = new Paragraph("Rs.", FONT_BOLD);
|
|
|
871 |
grandTotalTable.addCell(rsParagraph);
|
|
|
872 |
Paragraph amountParagraph = new Paragraph(String.format("%.2f", pdfModel.getTotalAmount()), FONT_BOLD);
|
|
|
873 |
grandTotalTable.addCell(amountParagraph);
|
| 23654 |
amit.gupta |
874 |
|
| 32275 |
tejbeer |
875 |
document.add(grandTotalTable);
|
| 23654 |
amit.gupta |
876 |
|
| 32275 |
tejbeer |
877 |
PdfPTable amountInWordsTable = new PdfPTable(3);
|
|
|
878 |
if (!stateGst) {
|
|
|
879 |
amountInWordsTable.setWidths(new float[]{2, 5.1f, 0.9f});
|
|
|
880 |
} else {
|
|
|
881 |
amountInWordsTable.setWidths(new float[]{2, 5.2f, 0.8f});
|
|
|
882 |
}
|
|
|
883 |
amountInWordsTable.setWidthPercentage(95);
|
|
|
884 |
amountInWordsTable.addCell(new Paragraph("Amount in Words:", FONT_BOLD));
|
| 23654 |
amit.gupta |
885 |
|
| 32275 |
tejbeer |
886 |
String amountInWords = toAmountInWords(pdfModel.getTotalAmount());
|
|
|
887 |
amountInWordsTable.addCell(new Paragraph(amountInWords.toString(), FONT_BOLD));
|
|
|
888 |
amountInWordsTable.addCell(new Paragraph("E & O.E", FONT_NORMAL));
|
|
|
889 |
document.add(amountInWordsTable);
|
| 23654 |
amit.gupta |
890 |
|
| 32275 |
tejbeer |
891 |
document.newPage();
|
|
|
892 |
}
|
|
|
893 |
document.close(); // no need to close PDFwriter?
|
|
|
894 |
} catch (DocumentException e) {
|
|
|
895 |
LOGGER.error("Unable to write data to pdf file : ", e);
|
|
|
896 |
} catch (Exception e) {
|
|
|
897 |
// TODO Auto-generated catch block
|
|
|
898 |
e.printStackTrace();
|
|
|
899 |
}
|
| 23654 |
amit.gupta |
900 |
|
| 32275 |
tejbeer |
901 |
}
|
| 34805 |
ranu |
902 |
|
|
|
903 |
public static byte[] mergePdfFiles(List<byte[]> pdfFiles) throws IOException, DocumentException {
|
|
|
904 |
ByteArrayOutputStream mergedOutputStream = new ByteArrayOutputStream();
|
|
|
905 |
Document document = new Document();
|
|
|
906 |
PdfCopy copy = new PdfCopy(document, mergedOutputStream);
|
|
|
907 |
document.open();
|
|
|
908 |
|
|
|
909 |
for (byte[] pdf : pdfFiles) {
|
|
|
910 |
PdfReader reader = new PdfReader(new ByteArrayInputStream(pdf));
|
|
|
911 |
int n = reader.getNumberOfPages();
|
|
|
912 |
for (int i = 1; i <= n; i++) {
|
|
|
913 |
copy.addPage(copy.getImportedPage(reader, i));
|
|
|
914 |
}
|
|
|
915 |
copy.freeReader(reader);
|
|
|
916 |
reader.close();
|
|
|
917 |
}
|
|
|
918 |
|
|
|
919 |
document.close();
|
|
|
920 |
return mergedOutputStream.toByteArray();
|
|
|
921 |
}
|
|
|
922 |
|
| 21686 |
ashik.ali |
923 |
}
|