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