| 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 |
|
| 36109 |
amit |
449 |
public static void generateMarginSchemeInvoice(List<InvoicePdfModel> pdfModels, ByteArrayOutputStream outputStream) {
|
|
|
450 |
try {
|
|
|
451 |
boolean cancelledPages = false;
|
|
|
452 |
List<Integer> cancelledPageList = new ArrayList<>();
|
|
|
453 |
Document document = new Document();
|
|
|
454 |
document.setMargins(0, 0, 25, 0);
|
|
|
455 |
PdfWriter pdfWriter = PdfWriter.getInstance(document, outputStream);
|
|
|
456 |
document.open();
|
|
|
457 |
|
| 36111 |
amit |
458 |
// 8 columns: S.No | Description | HSN | Qty | Gross Sale Value | Taxable Value (Margin) | Tax Rate | Tax Amount
|
|
|
459 |
float[] marginSchemeWidths = new float[]{0.3f, 2.4f, 0.6f, 0.3f, 0.9f, 0.9f, 0.9f, 0.7f};
|
| 36109 |
amit |
460 |
|
|
|
461 |
for (InvoicePdfModel pdfModel : pdfModels) {
|
|
|
462 |
CustomCustomer customer = pdfModel.getCustomer();
|
|
|
463 |
CustomRetailer retailer = pdfModel.getRetailer();
|
|
|
464 |
boolean stateGst = customer.getAddress().getState().equals(retailer.getAddress().getState());
|
|
|
465 |
|
|
|
466 |
List<CustomOrderItem> orderItems = pdfModel.getOrderItems();
|
|
|
467 |
if (pdfModel.isCancelled()) {
|
|
|
468 |
cancelledPageList.add(1);
|
|
|
469 |
cancelledPages = true;
|
|
|
470 |
} else {
|
|
|
471 |
cancelledPageList.add(0);
|
|
|
472 |
}
|
|
|
473 |
|
| 36111 |
amit |
474 |
document.addTitle("TAX INVOICE");
|
| 36109 |
amit |
475 |
document.addAuthor(pdfModel.getAuther());
|
|
|
476 |
|
| 36111 |
amit |
477 |
Paragraph paragraphTitle = new Paragraph("TAX INVOICE", FONT_TITLE);
|
| 36109 |
amit |
478 |
paragraphTitle.setAlignment(Element.ALIGN_CENTER);
|
|
|
479 |
document.add(paragraphTitle);
|
|
|
480 |
|
| 36111 |
amit |
481 |
Font subtitleFont = new Font(Font.FontFamily.HELVETICA, 9, Font.ITALIC);
|
|
|
482 |
Paragraph subtitle = new Paragraph("(GST Payable on Margin Scheme Basis \u2014 ITC not admissible to buyer)", subtitleFont);
|
|
|
483 |
subtitle.setAlignment(Element.ALIGN_CENTER);
|
|
|
484 |
document.add(subtitle);
|
|
|
485 |
|
| 36109 |
amit |
486 |
Rectangle rectangle = document.getPageSize();
|
|
|
487 |
|
|
|
488 |
if (pdfModel.getIrnModel() != null) {
|
|
|
489 |
addIrnDetails(pdfModel.getIrnModel(), rectangle, document);
|
|
|
490 |
}
|
|
|
491 |
|
| 36111 |
amit |
492 |
// Customer and Retailer details (same as regular invoice)
|
| 36109 |
amit |
493 |
PdfPTable tableCustomerRetailer = new PdfPTable(2);
|
|
|
494 |
tableCustomerRetailer.setWidthPercentage(90);
|
|
|
495 |
tableCustomerRetailer.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
|
|
496 |
|
|
|
497 |
PdfPCell columnCustomerInfo = new PdfPCell();
|
| 36111 |
amit |
498 |
columnCustomerInfo.addElement(new Paragraph("Buyer Details", FONT_BOLD));
|
| 36109 |
amit |
499 |
columnCustomerInfo.addElement(new Paragraph(
|
|
|
500 |
StringUtils.capitalize(customer.getAddress().getName() + (customer.getAddress().getLastName() == null ? "" : " " + customer.getAddress().getLastName())), FONT_NORMAL));
|
|
|
501 |
if (customer.getAddress() != null) {
|
|
|
502 |
if ((customer.getAddress().getLine1() != null && !customer.getAddress().getLine1().trim().isEmpty()) || (customer.getAddress().getLine2() != null && !customer.getAddress().getLine2().trim().isEmpty())) {
|
|
|
503 |
columnCustomerInfo.addElement(new Paragraph(StringUtils.capitalize(customer.getAddress().getLine1()) + ", " + StringUtils.capitalize(customer.getAddress().getLine2()), FONT_NORMAL));
|
|
|
504 |
}
|
|
|
505 |
if ((customer.getAddress().getCity() != null && !customer.getAddress().getCity().trim().isEmpty()) || (customer.getAddress().getState() != null && !customer.getAddress().getState().trim().isEmpty())) {
|
|
|
506 |
columnCustomerInfo.addElement(new Paragraph(StringUtils.capitalize(customer.getAddress().getCity()) + ", " + StringUtils.capitalize(customer.getAddress().getState()) + "(" + pdfModel.getCustomerAddressStateCode() + ")" + "\n" + customer.getAddress().getPinCode(), FONT_NORMAL));
|
|
|
507 |
}
|
|
|
508 |
}
|
|
|
509 |
columnCustomerInfo.addElement(new Paragraph("Mobile - " + customer.getAddress().getPhoneNumber(), FONT_NORMAL));
|
|
|
510 |
if (customer.getGstNumber() != null && !customer.getGstNumber().isEmpty()) {
|
|
|
511 |
columnCustomerInfo.addElement(new Paragraph("GST Number - " + customer.getGstNumber(), FONT_NORMAL));
|
|
|
512 |
}
|
|
|
513 |
columnCustomerInfo.setBorder(Rectangle.NO_BORDER);
|
|
|
514 |
|
|
|
515 |
PdfPCell columnRetailerInfo = new PdfPCell();
|
| 36111 |
amit |
516 |
columnRetailerInfo.addElement(new Paragraph("Supplier Details", FONT_BOLD));
|
| 36109 |
amit |
517 |
columnRetailerInfo.addElement(new Paragraph(StringUtils.capitalize(retailer.getAddress().getName()), FONT_BOLD));
|
|
|
518 |
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));
|
|
|
519 |
columnRetailerInfo.addElement(new Paragraph("Contact No.- " + retailer.getAddress().getPhoneNumber(), FONT_BOLD));
|
|
|
520 |
columnRetailerInfo.addElement(new Paragraph("GST NO. " + retailer.getGstNumber(), FONT_BOLD));
|
|
|
521 |
columnRetailerInfo.setBorder(Rectangle.NO_BORDER);
|
|
|
522 |
|
|
|
523 |
PdfPTable tableInvoiceDateRetailer = new PdfPTable(1);
|
|
|
524 |
tableInvoiceDateRetailer.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
|
|
525 |
|
|
|
526 |
PdfPTable tableInvoiceDate = new PdfPTable(2);
|
|
|
527 |
tableInvoiceDate.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
|
|
528 |
|
|
|
529 |
PdfPCell invoiceNumberKey = new PdfPCell(new Paragraph("Invoice No:", FONT_NORMAL));
|
|
|
530 |
invoiceNumberKey.setBorder(Rectangle.NO_BORDER);
|
|
|
531 |
PdfPCell invoiceNumberValue = new PdfPCell(new Paragraph(pdfModel.getInvoiceNumber(), FONT_NORMAL));
|
|
|
532 |
invoiceNumberValue.setBorder(Rectangle.NO_BORDER);
|
|
|
533 |
PdfPCell dateKey = new PdfPCell(new Paragraph("Date:", FONT_NORMAL));
|
|
|
534 |
dateKey.setBorder(Rectangle.NO_BORDER);
|
|
|
535 |
PdfPCell dateValue = new PdfPCell(new Paragraph(pdfModel.getInvoiceDate(), FONT_NORMAL));
|
|
|
536 |
dateValue.setBorder(Rectangle.NO_BORDER);
|
|
|
537 |
|
|
|
538 |
tableInvoiceDate.addCell(invoiceNumberKey);
|
|
|
539 |
tableInvoiceDate.addCell(invoiceNumberValue);
|
|
|
540 |
tableInvoiceDate.addCell(dateKey);
|
|
|
541 |
tableInvoiceDate.addCell(dateValue);
|
|
|
542 |
tableInvoiceDateRetailer.addCell(tableInvoiceDate);
|
|
|
543 |
tableInvoiceDateRetailer.addCell(columnRetailerInfo);
|
|
|
544 |
|
|
|
545 |
tableCustomerRetailer.addCell(columnCustomerInfo);
|
|
|
546 |
tableCustomerRetailer.addCell(tableInvoiceDateRetailer);
|
|
|
547 |
|
| 36111 |
amit |
548 |
// Item table — margin scheme columns (no purchase price disclosed)
|
| 36109 |
amit |
549 |
PdfPTable orders = new PdfPTable(marginSchemeWidths.length);
|
|
|
550 |
orders.setWidths(marginSchemeWidths);
|
|
|
551 |
orders.setWidthPercentage(90);
|
|
|
552 |
|
|
|
553 |
orders.addCell(new Paragraph("S.No", FONT_BOLD));
|
| 36111 |
amit |
554 |
orders.addCell(new Paragraph("Description of Goods", FONT_BOLD));
|
|
|
555 |
orders.addCell(new Paragraph("HSN\nCode", FONT_BOLD));
|
| 36109 |
amit |
556 |
orders.addCell(new Paragraph("Qty", FONT_BOLD));
|
| 36111 |
amit |
557 |
orders.addCell(new Paragraph("Gross Sale\nValue (Rs.)", FONT_BOLD));
|
|
|
558 |
orders.addCell(new Paragraph("Taxable Value\n- Margin (Rs.)", FONT_BOLD));
|
|
|
559 |
String taxRateHeader = stateGst ? "CGST+SGST\nRate" : "IGST\nRate";
|
|
|
560 |
orders.addCell(new Paragraph(taxRateHeader, FONT_BOLD));
|
|
|
561 |
orders.addCell(new Paragraph("Tax Amount\n(Rs.)", FONT_BOLD));
|
| 36109 |
amit |
562 |
orders.setHeaderRows(1);
|
|
|
563 |
|
| 36111 |
amit |
564 |
float totalGrossSale = 0, totalMargin = 0, totalTaxAmount = 0;
|
| 36109 |
amit |
565 |
int index = 1;
|
|
|
566 |
for (CustomOrderItem orderItem : orderItems) {
|
| 36111 |
amit |
567 |
float taxAmount = orderItem.getCgstAmount() + orderItem.getSgstAmount() + orderItem.getIgstAmount();
|
| 36109 |
amit |
568 |
|
|
|
569 |
orders.addCell(new Paragraph(String.valueOf(index++), FONT_NORMAL));
|
|
|
570 |
orders.addCell(new Paragraph(orderItem.getDescription(), FONT_NORMAL));
|
|
|
571 |
orders.addCell(new Paragraph(orderItem.getHsnCode(), FONT_NORMAL));
|
|
|
572 |
orders.addCell(new Paragraph(String.valueOf(orderItem.getQuantity()), FONT_NORMAL));
|
|
|
573 |
orders.addCell(new Paragraph(String.format("%.2f", orderItem.getNetAmount()), FONT_NORMAL));
|
| 36111 |
amit |
574 |
orders.addCell(new Paragraph(String.format("%.2f", orderItem.getAmount()), FONT_NORMAL));
|
| 36109 |
amit |
575 |
|
| 36111 |
amit |
576 |
String taxRateText;
|
|
|
577 |
if (stateGst) {
|
|
|
578 |
taxRateText = String.format("CGST %.1f%%\n+ SGST %.1f%%", orderItem.getCgstRate(), orderItem.getSgstRate());
|
|
|
579 |
} else {
|
|
|
580 |
taxRateText = String.format("IGST %.1f%%", orderItem.getIgstRate());
|
|
|
581 |
}
|
|
|
582 |
orders.addCell(new Paragraph(taxRateText, FONT_NORMAL));
|
|
|
583 |
orders.addCell(new Paragraph(String.format("%.2f", taxAmount), FONT_NORMAL));
|
|
|
584 |
|
|
|
585 |
totalGrossSale += orderItem.getNetAmount();
|
|
|
586 |
totalMargin += orderItem.getAmount();
|
|
|
587 |
totalTaxAmount += taxAmount;
|
| 36109 |
amit |
588 |
}
|
|
|
589 |
|
|
|
590 |
// Total row
|
| 36111 |
amit |
591 |
PdfPCell totalLabelCell = new PdfPCell(new Paragraph("Total", FONT_BOLD));
|
|
|
592 |
totalLabelCell.setColspan(4);
|
| 36109 |
amit |
593 |
orders.addCell(totalLabelCell);
|
| 36111 |
amit |
594 |
orders.addCell(new Paragraph(String.format("%.2f", totalGrossSale), FONT_BOLD));
|
| 36109 |
amit |
595 |
orders.addCell(new Paragraph(String.format("%.2f", totalMargin), FONT_BOLD));
|
| 36111 |
amit |
596 |
PdfPCell dashCell = new PdfPCell(new Paragraph("\u2014", FONT_BOLD));
|
|
|
597 |
dashCell.setHorizontalAlignment(Element.ALIGN_CENTER);
|
|
|
598 |
orders.addCell(dashCell);
|
|
|
599 |
orders.addCell(new Paragraph(String.format("%.2f", totalTaxAmount), FONT_BOLD));
|
| 36109 |
amit |
600 |
|
|
|
601 |
// Logo and layout
|
|
|
602 |
iconImg.setAbsolutePosition(25, rectangle.getHeight() - 100);
|
|
|
603 |
iconImg.scalePercent(30);
|
|
|
604 |
document.add(iconImg);
|
|
|
605 |
document.add(Chunk.NEWLINE);
|
|
|
606 |
document.add(Chunk.NEWLINE);
|
|
|
607 |
document.add(tableCustomerRetailer);
|
|
|
608 |
document.add(Chunk.NEWLINE);
|
|
|
609 |
document.add(orders);
|
|
|
610 |
|
| 36111 |
amit |
611 |
// Declaration box
|
|
|
612 |
document.add(Chunk.NEWLINE);
|
|
|
613 |
PdfPTable declarationTable = new PdfPTable(1);
|
|
|
614 |
declarationTable.setWidthPercentage(90);
|
|
|
615 |
Font declarationFont = new Font(Font.FontFamily.HELVETICA, 9, Font.BOLD);
|
|
|
616 |
PdfPCell declarationCell = new PdfPCell();
|
|
|
617 |
declarationCell.addElement(new Paragraph("Declaration", declarationFont));
|
|
|
618 |
Font declarationBodyFont = new Font(Font.FontFamily.TIMES_ROMAN, 9, Font.NORMAL);
|
|
|
619 |
declarationCell.addElement(new Paragraph(
|
|
|
620 |
"GST is payable on margin scheme basis under Section 2(27) read with Rule 32(5) of CGST Rules, 2017. " +
|
|
|
621 |
"The buyer is NOT eligible to claim Input Tax Credit on this invoice.", declarationBodyFont));
|
|
|
622 |
declarationCell.setPadding(8);
|
|
|
623 |
declarationCell.setBackgroundColor(new BaseColor(245, 245, 245));
|
|
|
624 |
declarationTable.addCell(declarationCell);
|
|
|
625 |
document.add(declarationTable);
|
| 36109 |
amit |
626 |
|
| 36111 |
amit |
627 |
// Summary table: Total Selling Price, GST on Margin, Total Invoice Value
|
|
|
628 |
document.add(Chunk.NEWLINE);
|
|
|
629 |
PdfPTable summaryTable = new PdfPTable(2);
|
|
|
630 |
summaryTable.setWidthPercentage(50);
|
|
|
631 |
summaryTable.setHorizontalAlignment(Element.ALIGN_RIGHT);
|
|
|
632 |
summaryTable.setWidths(new float[]{3f, 2f});
|
| 36109 |
amit |
633 |
|
| 36111 |
amit |
634 |
PdfPCell slCell = new PdfPCell(new Paragraph("Total Selling Price", FONT_BOLD));
|
|
|
635 |
slCell.setPadding(4);
|
|
|
636 |
summaryTable.addCell(slCell);
|
|
|
637 |
PdfPCell slValCell = new PdfPCell(new Paragraph(String.format("Rs. %.2f", totalGrossSale), FONT_NORMAL));
|
|
|
638 |
slValCell.setPadding(4);
|
|
|
639 |
summaryTable.addCell(slValCell);
|
|
|
640 |
|
|
|
641 |
PdfPCell gstCell = new PdfPCell(new Paragraph("GST on Margin", FONT_BOLD));
|
|
|
642 |
gstCell.setPadding(4);
|
|
|
643 |
summaryTable.addCell(gstCell);
|
|
|
644 |
PdfPCell gstValCell = new PdfPCell(new Paragraph(String.format("Rs. %.2f", totalTaxAmount), FONT_NORMAL));
|
|
|
645 |
gstValCell.setPadding(4);
|
|
|
646 |
summaryTable.addCell(gstValCell);
|
|
|
647 |
|
|
|
648 |
Font grandTotalFont = new Font(Font.FontFamily.HELVETICA, 11, Font.BOLD);
|
|
|
649 |
PdfPCell gtCell = new PdfPCell(new Paragraph("Total Invoice Value", grandTotalFont));
|
|
|
650 |
gtCell.setPadding(5);
|
|
|
651 |
gtCell.setBackgroundColor(new BaseColor(230, 230, 230));
|
|
|
652 |
summaryTable.addCell(gtCell);
|
|
|
653 |
PdfPCell gtValCell = new PdfPCell(new Paragraph(String.format("Rs. %.2f", pdfModel.getTotalAmount()), grandTotalFont));
|
|
|
654 |
gtValCell.setPadding(5);
|
|
|
655 |
gtValCell.setBackgroundColor(new BaseColor(230, 230, 230));
|
|
|
656 |
summaryTable.addCell(gtValCell);
|
|
|
657 |
|
|
|
658 |
document.add(summaryTable);
|
|
|
659 |
|
| 36109 |
amit |
660 |
// Amount in words
|
| 36111 |
amit |
661 |
PdfPTable amountInWordsTable = new PdfPTable(1);
|
| 36109 |
amit |
662 |
amountInWordsTable.setWidthPercentage(90);
|
|
|
663 |
String amountInWords = toAmountInWords(pdfModel.getTotalAmount());
|
| 36111 |
amit |
664 |
PdfPCell wordsCell = new PdfPCell(new Paragraph(amountInWords, FONT_BOLD));
|
|
|
665 |
wordsCell.setPadding(5);
|
|
|
666 |
amountInWordsTable.addCell(wordsCell);
|
| 36109 |
amit |
667 |
document.add(amountInWordsTable);
|
|
|
668 |
|
|
|
669 |
// Payment options
|
|
|
670 |
if (pdfModel.getPaymentOptions() != null) {
|
|
|
671 |
PdfPTable paidAmountTable = new PdfPTable(2);
|
|
|
672 |
paidAmountTable.setWidthPercentage(90);
|
|
|
673 |
paidAmountTable.setWidths(new float[]{7.1f, 0.9f});
|
|
|
674 |
float totalPaidValue = 0;
|
|
|
675 |
for (CustomPaymentOption paymentOption : pdfModel.getPaymentOptions()) {
|
|
|
676 |
if (!"CASH DISCOUNT".equals(paymentOption.getPaymentOption())) {
|
|
|
677 |
PdfPCell cell = new PdfPCell(new Paragraph(10, "Paid Through " + paymentOption.getPaymentOption(), FONT_BOLD));
|
|
|
678 |
cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
|
|
|
679 |
cell.setPadding(5);
|
|
|
680 |
paidAmountTable.addCell(cell);
|
|
|
681 |
|
|
|
682 |
PdfPCell cell1 = new PdfPCell(new Paragraph(10, FormattingUtils.formatDecimal(paymentOption.getAmount()), FONT_BOLD));
|
|
|
683 |
cell1.setPadding(5);
|
|
|
684 |
paidAmountTable.addCell(cell1);
|
|
|
685 |
totalPaidValue += paymentOption.getAmount();
|
|
|
686 |
}
|
|
|
687 |
}
|
|
|
688 |
PdfPCell totalPaidCell = new PdfPCell(new Paragraph(10, "Total Paid", FONT_BOLD));
|
|
|
689 |
totalPaidCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
|
|
|
690 |
totalPaidCell.setPadding(5);
|
|
|
691 |
paidAmountTable.addCell(totalPaidCell);
|
|
|
692 |
|
|
|
693 |
PdfPCell totalPaidValueCell = new PdfPCell(new Paragraph(10, FormattingUtils.formatDecimal(totalPaidValue), FONT_BOLD));
|
|
|
694 |
totalPaidValueCell.setPadding(5);
|
|
|
695 |
paidAmountTable.addCell(totalPaidValueCell);
|
|
|
696 |
document.add(paidAmountTable);
|
|
|
697 |
}
|
|
|
698 |
|
|
|
699 |
// Computer generated note
|
|
|
700 |
Paragraph autoGenerateParagraph = new Paragraph("Note - This is computer generated Invoice, no signature is required", FONT_NORMAL);
|
|
|
701 |
autoGenerateParagraph.setAlignment(Element.ALIGN_CENTER);
|
|
|
702 |
document.add(autoGenerateParagraph);
|
|
|
703 |
|
|
|
704 |
// Credit terms
|
|
|
705 |
if (pdfModel.getCreditTerms() != null) {
|
|
|
706 |
Paragraph title = new Paragraph("Credit terms :-\n", FONT_BOLD);
|
|
|
707 |
title.setIndentationLeft(25);
|
|
|
708 |
title.setIndentationRight(25);
|
|
|
709 |
document.add(title);
|
|
|
710 |
|
|
|
711 |
StringBuffer termsBuffer = new StringBuffer();
|
|
|
712 |
int count = 0;
|
|
|
713 |
for (String creditTerm : pdfModel.getCreditTerms()) {
|
|
|
714 |
count++;
|
|
|
715 |
termsBuffer.append(count).append(". ").append(creditTerm).append(".\n");
|
|
|
716 |
}
|
|
|
717 |
Paragraph body = new Paragraph(termsBuffer.toString(), FONT_NORMAL);
|
|
|
718 |
body.setIndentationLeft(25);
|
|
|
719 |
body.setIndentationRight(25);
|
|
|
720 |
document.add(body);
|
|
|
721 |
}
|
|
|
722 |
|
|
|
723 |
document.newPage();
|
|
|
724 |
|
|
|
725 |
// E-Way Bill support
|
|
|
726 |
if (pdfModel.geteWayBillPdfModel() != null) {
|
|
|
727 |
EWayBillPDF.generateDocument(document, pdfWriter, pdfModel.geteWayBillPdfModel());
|
|
|
728 |
}
|
|
|
729 |
}
|
|
|
730 |
|
|
|
731 |
document.close();
|
|
|
732 |
if (cancelledPages) {
|
|
|
733 |
stampCancelled(outputStream, cancelledPageList);
|
|
|
734 |
}
|
|
|
735 |
} catch (DocumentException e) {
|
|
|
736 |
LOGGER.error("Unable to write data to margin scheme pdf file : ", e);
|
|
|
737 |
} catch (Exception e) {
|
|
|
738 |
e.printStackTrace();
|
|
|
739 |
}
|
|
|
740 |
}
|
|
|
741 |
|
| 32275 |
tejbeer |
742 |
private static void stampCancelled(ByteArrayOutputStream byteStream, List<Integer> cancelledPage) throws IOException, DocumentException {
|
|
|
743 |
ByteArrayInputStream bais = new ByteArrayInputStream(byteStream.toByteArray());
|
|
|
744 |
PdfReader pdfReader = new PdfReader(bais);
|
|
|
745 |
int n = pdfReader.getNumberOfPages();
|
|
|
746 |
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
|
|
747 |
PdfStamper pdfStamper = new PdfStamper(pdfReader, baos);
|
|
|
748 |
pdfStamper.setRotateContents(false);
|
|
|
749 |
// text watermark
|
|
|
750 |
Font f = new Font(FontFamily.HELVETICA, 30);
|
|
|
751 |
Phrase p = new Phrase("My watermark (text)", f);
|
|
|
752 |
URL cancelledImgUrl = PdfUtils.class.getClassLoader().getResource("cancelled.png");
|
|
|
753 |
URL waterMarkImgUrl = PdfUtils.class.getClassLoader().getResource("sd1.jpg");
|
|
|
754 |
Image imgCancelled = Image.getInstance(cancelledImgUrl);
|
|
|
755 |
Image imgWatermark = Image.getInstance(waterMarkImgUrl);
|
|
|
756 |
imgWatermark.scaleAbsolute(imgWatermark.getScaledWidth() * 2.5f, imgWatermark.getScaledHeight() * 2.5f);
|
|
|
757 |
float w = imgCancelled.getScaledWidth() / 2;
|
|
|
758 |
float h = imgCancelled.getScaledHeight() / 2;
|
|
|
759 |
float wWaterMark = imgWatermark.getScaledWidth() / 2;
|
|
|
760 |
float hWatermark = imgWatermark.getScaledHeight() / 2;
|
|
|
761 |
// transparency
|
|
|
762 |
PdfGState gs1 = new PdfGState();
|
| 32980 |
amit.gupta |
763 |
gs1.setFillOpacity(0.4f);
|
| 32275 |
tejbeer |
764 |
PdfGState gs2 = new PdfGState();
|
| 32980 |
amit.gupta |
765 |
gs2.setFillOpacity(0.05f);
|
| 32275 |
tejbeer |
766 |
// properties
|
|
|
767 |
PdfContentByte over;
|
|
|
768 |
Rectangle pagesize;
|
|
|
769 |
float x, y;
|
| 24506 |
amit.gupta |
770 |
|
| 32275 |
tejbeer |
771 |
// loop over every page
|
|
|
772 |
for (int i = 1; i <= n; i++) {
|
|
|
773 |
pagesize = pdfReader.getPageSize(i);
|
|
|
774 |
x = (pagesize.getLeft() + pagesize.getRight()) / 2;
|
|
|
775 |
y = (pagesize.getTop() + pagesize.getBottom()) / 2;
|
|
|
776 |
over = pdfStamper.getOverContent(i);
|
|
|
777 |
over.saveState();
|
|
|
778 |
if (cancelledPage.get(i - 1) == 1) {
|
|
|
779 |
over.setGState(gs1);
|
|
|
780 |
over.addImage(imgCancelled, w, 0, 0, h, x - (w / 2), y - (h / 2));
|
|
|
781 |
over.restoreState();
|
|
|
782 |
} else {
|
|
|
783 |
over.setGState(gs2);
|
|
|
784 |
over.addImage(imgWatermark, wWaterMark, 0, 0, hWatermark, x - (wWaterMark / 2), y - (hWatermark / 2));
|
|
|
785 |
over.restoreState();
|
|
|
786 |
}
|
|
|
787 |
}
|
|
|
788 |
pdfStamper.close();
|
|
|
789 |
pdfReader.close();
|
|
|
790 |
baos.writeTo(byteStream);
|
| 24845 |
amit.gupta |
791 |
|
| 32275 |
tejbeer |
792 |
}
|
| 24506 |
amit.gupta |
793 |
|
| 32275 |
tejbeer |
794 |
public static void generateAndWriteDebitNote(List<DebitNotePdfModel> debitNotePdfModels, OutputStream outputStream) {
|
|
|
795 |
Document document = new Document();
|
|
|
796 |
document.setMargins(0, 0, 25, 0);
|
|
|
797 |
try {
|
|
|
798 |
for (DebitNotePdfModel debitNotePdfModel : debitNotePdfModels) {
|
| 23509 |
amit.gupta |
799 |
|
| 32275 |
tejbeer |
800 |
InvoicePdfModel pdfModel = debitNotePdfModel.getPdfModel();
|
|
|
801 |
CustomCustomer customer = pdfModel.getCustomer();
|
|
|
802 |
CustomRetailer retailer = pdfModel.getRetailer();
|
|
|
803 |
boolean stateGst = false;
|
| 32290 |
tejbeer |
804 |
|
|
|
805 |
LOGGER.info("Customer - {}", customer.getAddress().getState());
|
|
|
806 |
LOGGER.info("retailer - {}", retailer.getAddress().getState());
|
|
|
807 |
|
|
|
808 |
|
| 32292 |
tejbeer |
809 |
if (customer.getAddress().getState().equals(retailer.getAddress().getState())) {
|
|
|
810 |
stateGst = true;
|
|
|
811 |
}
|
| 33298 |
amit.gupta |
812 |
List<CustomOrderItem> orderItems = pdfModel.getOrderItems();
|
| 23509 |
amit.gupta |
813 |
|
| 32275 |
tejbeer |
814 |
PdfWriter.getInstance(document, outputStream);
|
| 23509 |
amit.gupta |
815 |
|
| 32275 |
tejbeer |
816 |
document.open();
|
|
|
817 |
document.addTitle(pdfModel.getTitle());
|
|
|
818 |
document.addAuthor(pdfModel.getAuther());
|
| 23509 |
amit.gupta |
819 |
|
| 32275 |
tejbeer |
820 |
Paragraph paragraphTitle = new Paragraph(pdfModel.getTitle(), FONT_TITLE);
|
|
|
821 |
paragraphTitle.setAlignment(Element.ALIGN_CENTER);
|
| 23509 |
amit.gupta |
822 |
|
| 32275 |
tejbeer |
823 |
PdfPCell blankCell = new PdfPCell();
|
|
|
824 |
blankCell.setBorder(Rectangle.NO_BORDER);
|
|
|
825 |
PdfPTable tableCustomerRetailer = new PdfPTable(3);
|
|
|
826 |
tableCustomerRetailer.setWidthPercentage(95);
|
|
|
827 |
PdfPCell partnerInfo = new PdfPCell();
|
|
|
828 |
partnerInfo.addElement(new Paragraph("From Party:", FONT_BOLD));
|
|
|
829 |
partnerInfo.addElement(
|
|
|
830 |
new Paragraph(StringUtils.capitalize(customer.getAddress().getName()), FONT_NORMAL));
|
|
|
831 |
partnerInfo.addElement(new Paragraph(
|
| 32289 |
tejbeer |
832 |
(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 |
833 |
|
| 32275 |
tejbeer |
834 |
partnerInfo.addElement(new Paragraph(
|
|
|
835 |
StringUtils.capitalize(customer.getAddress().getState()) + "(" + pdfModel.getCustomerAddressStateCode() + ")", FONT_NORMAL));
|
|
|
836 |
partnerInfo.addElement(new Paragraph("Mobile - " + customer.getMobileNumber(), FONT_NORMAL));
|
|
|
837 |
if (customer.getGstNumber() != null && !customer.getGstNumber().isEmpty()) {
|
|
|
838 |
partnerInfo.addElement(new Paragraph("GST No - " + customer.getGstNumber(), FONT_BOLD));
|
|
|
839 |
}
|
| 23533 |
amit.gupta |
840 |
|
| 32275 |
tejbeer |
841 |
PdfPCell sellerParty = new PdfPCell();
|
|
|
842 |
sellerParty.addElement(new Paragraph("To Party:", FONT_BOLD));
|
|
|
843 |
sellerParty.addElement(
|
|
|
844 |
new Paragraph(StringUtils.capitalize(retailer.getAddress().getName()), FONT_NORMAL));
|
| 32289 |
tejbeer |
845 |
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 |
846 |
sellerParty.addElement(new Paragraph(
|
|
|
847 |
retailer.getAddress().getState() + "(" + pdfModel.getPartnerAddressStateCode() + ")", FONT_NORMAL));
|
|
|
848 |
sellerParty.addElement(new Paragraph("Mobile - " + retailer.getAddress().getPhoneNumber(), FONT_NORMAL));
|
|
|
849 |
sellerParty.addElement(new Paragraph("GST No - " + retailer.getGstNumber(), FONT_BOLD));
|
| 23509 |
amit.gupta |
850 |
|
| 32275 |
tejbeer |
851 |
PdfPTable tableInvoiceDateRetailer = new PdfPTable(1);
|
|
|
852 |
tableInvoiceDateRetailer.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
| 23509 |
amit.gupta |
853 |
|
| 32275 |
tejbeer |
854 |
PdfPTable tableInvoiceDate = new PdfPTable(2);
|
|
|
855 |
tableInvoiceDate.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
|
|
856 |
tableInvoiceDate.setWidthPercentage(90);
|
| 23509 |
amit.gupta |
857 |
|
| 32275 |
tejbeer |
858 |
PdfPCell debitNoteDetails = new PdfPCell(new Paragraph("Debit Note Details", FONT_BOLD));
|
|
|
859 |
debitNoteDetails.setColspan(2);
|
|
|
860 |
debitNoteDetails.setBorder(Rectangle.NO_BORDER);
|
| 23654 |
amit.gupta |
861 |
|
| 32275 |
tejbeer |
862 |
PdfPCell debitNoteNumberKey = new PdfPCell(new Paragraph("Debit Note No:", FONT_NORMAL));
|
|
|
863 |
debitNoteNumberKey.setBorder(Rectangle.NO_BORDER);
|
|
|
864 |
PdfPCell debitNoteNumberValue = new PdfPCell(
|
|
|
865 |
new Paragraph(debitNotePdfModel.getDebitNoteNumber(), FONT_NORMAL));
|
|
|
866 |
debitNoteNumberValue.setBorder(Rectangle.NO_BORDER);
|
| 23532 |
amit.gupta |
867 |
|
| 32275 |
tejbeer |
868 |
PdfPCell debitNoteDateKey = new PdfPCell(new Paragraph("Debit Note Dt:", FONT_NORMAL));
|
|
|
869 |
debitNoteDateKey.setBorder(Rectangle.NO_BORDER);
|
| 23533 |
amit.gupta |
870 |
|
| 32275 |
tejbeer |
871 |
PdfPCell debitNoteDateValue = new PdfPCell(
|
|
|
872 |
new Paragraph(debitNotePdfModel.getDebitNoteDate(), FONT_NORMAL));
|
|
|
873 |
debitNoteDateValue.setBorder(Rectangle.NO_BORDER);
|
| 23532 |
amit.gupta |
874 |
|
| 32275 |
tejbeer |
875 |
PdfPCell invoiceNumberKey = new PdfPCell(new Paragraph("Invoice Ref No:", FONT_NORMAL));
|
|
|
876 |
invoiceNumberKey.setBorder(Rectangle.NO_BORDER);
|
|
|
877 |
PdfPCell invoiceNumberValue = new PdfPCell(new Paragraph(pdfModel.getInvoiceNumber(), FONT_NORMAL));
|
|
|
878 |
invoiceNumberValue.setBorder(Rectangle.NO_BORDER);
|
| 23509 |
amit.gupta |
879 |
|
| 32275 |
tejbeer |
880 |
PdfPCell dateKey = new PdfPCell(new Paragraph("Invoice Dt:", FONT_NORMAL));
|
|
|
881 |
dateKey.setBorder(Rectangle.NO_BORDER);
|
|
|
882 |
PdfPCell dateValue = new PdfPCell(new Paragraph(pdfModel.getInvoiceDate(), FONT_NORMAL));
|
|
|
883 |
dateValue.setBorder(Rectangle.NO_BORDER);
|
| 23533 |
amit.gupta |
884 |
|
| 32275 |
tejbeer |
885 |
tableInvoiceDate.addCell(debitNoteDetails);
|
|
|
886 |
tableInvoiceDate.addCell(debitNoteNumberKey);
|
|
|
887 |
tableInvoiceDate.addCell(debitNoteNumberValue);
|
|
|
888 |
tableInvoiceDate.addCell(debitNoteDateKey);
|
|
|
889 |
tableInvoiceDate.addCell(debitNoteDateValue);
|
|
|
890 |
tableInvoiceDate.addCell(invoiceNumberKey);
|
|
|
891 |
tableInvoiceDate.addCell(invoiceNumberValue);
|
|
|
892 |
tableInvoiceDate.addCell(dateKey);
|
|
|
893 |
tableInvoiceDate.addCell(dateValue);
|
| 23509 |
amit.gupta |
894 |
|
| 32275 |
tejbeer |
895 |
tableCustomerRetailer.addCell(partnerInfo);
|
|
|
896 |
tableCustomerRetailer.addCell(tableInvoiceDate);
|
|
|
897 |
tableCustomerRetailer.addCell(sellerParty);
|
| 23509 |
amit.gupta |
898 |
|
| 32275 |
tejbeer |
899 |
PdfPTable orders = null;
|
|
|
900 |
if (stateGst) {
|
|
|
901 |
orders = new PdfPTable(stateWidths.length);
|
|
|
902 |
orders.setWidths(stateWidths);
|
|
|
903 |
} else {
|
|
|
904 |
orders = new PdfPTable(igstWidths.length);
|
|
|
905 |
orders.setWidths(igstWidths);
|
|
|
906 |
}
|
|
|
907 |
orders.setWidthPercentage(95);
|
|
|
908 |
orders.addCell(new Paragraph("Order Id", FONT_BOLD));
|
|
|
909 |
orders.addCell(new Paragraph("Description", FONT_BOLD));
|
|
|
910 |
orders.addCell(new Paragraph("HSN", FONT_BOLD));
|
|
|
911 |
orders.addCell(new Paragraph("Qty", FONT_BOLD));
|
|
|
912 |
orders.addCell(new Paragraph("Rate\n(Per pc)", FONT_BOLD));
|
|
|
913 |
orders.addCell(new Paragraph("Total\nTaxable", FONT_BOLD));
|
|
|
914 |
if (!stateGst) {
|
|
|
915 |
orders.addCell(new Paragraph("IGST\n%", FONT_BOLD));
|
|
|
916 |
orders.addCell(new Paragraph("IGST", FONT_BOLD));
|
|
|
917 |
} else {
|
|
|
918 |
orders.addCell(new Paragraph("CGST %", FONT_BOLD));
|
|
|
919 |
orders.addCell(new Paragraph("CGST", FONT_BOLD));
|
|
|
920 |
orders.addCell(new Paragraph("SGST %", FONT_BOLD));
|
|
|
921 |
orders.addCell(new Paragraph("SGST", FONT_BOLD));
|
|
|
922 |
}
|
|
|
923 |
orders.addCell(new Paragraph("Total", FONT_BOLD));
|
| 23509 |
amit.gupta |
924 |
|
| 32275 |
tejbeer |
925 |
orders.setHeaderRows(1);
|
| 23509 |
amit.gupta |
926 |
|
| 32275 |
tejbeer |
927 |
float igstTotalAmount = 0, cgstTotalAmount = 0, sgstTotalAmount = 0;
|
| 35799 |
amit |
928 |
boolean marginSeparatorAdded = false;
|
| 32275 |
tejbeer |
929 |
for (CustomOrderItem orderItem : orderItems) {
|
| 35799 |
amit |
930 |
if (orderItem.isMarginScheme() && !marginSeparatorAdded) {
|
|
|
931 |
addMarginSchemeSeparator(orders, stateGst ? stateWidths.length : igstWidths.length);
|
|
|
932 |
marginSeparatorAdded = true;
|
|
|
933 |
}
|
|
|
934 |
|
| 32275 |
tejbeer |
935 |
orders.addCell(new Paragraph(String.valueOf(orderItem.getOrderId()), FONT_NORMAL));
|
|
|
936 |
orders.addCell(new Paragraph(orderItem.getDescription(), FONT_NORMAL));
|
|
|
937 |
orders.addCell(new Paragraph(orderItem.getHsnCode(), FONT_NORMAL));
|
|
|
938 |
orders.addCell(new Paragraph(String.valueOf(orderItem.getQuantity()), FONT_NORMAL));
|
|
|
939 |
orders.addCell(new Paragraph(String.format("%.2f", orderItem.getRate()), FONT_NORMAL));
|
|
|
940 |
orders.addCell(new Paragraph(String.format("%.2f", orderItem.getAmount()), FONT_NORMAL));
|
|
|
941 |
if (!stateGst) {
|
|
|
942 |
orders.addCell(new Paragraph(String.format("%.2f", orderItem.getIgstRate()), FONT_NORMAL));
|
|
|
943 |
orders.addCell(new Paragraph(String.format("%.2f", orderItem.getIgstAmount()), FONT_NORMAL));
|
|
|
944 |
igstTotalAmount = igstTotalAmount + orderItem.getIgstAmount();
|
|
|
945 |
} else {
|
|
|
946 |
orders.addCell(new Paragraph(String.format("%.2f", orderItem.getCgstRate()), FONT_NORMAL));
|
|
|
947 |
orders.addCell(new Paragraph(String.format("%.2f", orderItem.getCgstAmount()), FONT_NORMAL));
|
|
|
948 |
orders.addCell(new Paragraph(String.format("%.2f", orderItem.getSgstRate()), FONT_NORMAL));
|
|
|
949 |
orders.addCell(new Paragraph(String.format("%.2f", orderItem.getSgstAmount()), FONT_NORMAL));
|
|
|
950 |
cgstTotalAmount = cgstTotalAmount + orderItem.getCgstAmount();
|
|
|
951 |
sgstTotalAmount = sgstTotalAmount + orderItem.getSgstAmount();
|
|
|
952 |
}
|
|
|
953 |
orders.addCell(new Paragraph(String.format("%.0f", orderItem.getNetAmount()), FONT_NORMAL));
|
|
|
954 |
LOGGER.info("IN FOR LOOP");
|
|
|
955 |
}
|
| 23509 |
amit.gupta |
956 |
|
| 32275 |
tejbeer |
957 |
document.add(paragraphTitle);
|
| 23533 |
amit.gupta |
958 |
|
| 32275 |
tejbeer |
959 |
document.add(Chunk.NEWLINE);
|
|
|
960 |
document.add(tableCustomerRetailer);
|
| 23509 |
amit.gupta |
961 |
|
| 32275 |
tejbeer |
962 |
document.add(Chunk.NEWLINE);
|
|
|
963 |
document.add(orders);
|
| 23509 |
amit.gupta |
964 |
|
| 32275 |
tejbeer |
965 |
PdfPTable grandTotalTable = new PdfPTable(3);
|
|
|
966 |
if (stateGst) {
|
|
|
967 |
grandTotalTable.setWidths(new float[]{6.6f, .6f, .8f});
|
|
|
968 |
} else {
|
|
|
969 |
grandTotalTable.setWidths(new float[]{6.5f, .6f, .9f});
|
|
|
970 |
}
|
|
|
971 |
grandTotalTable.setWidthPercentage(95);
|
| 23509 |
amit.gupta |
972 |
|
| 32275 |
tejbeer |
973 |
Paragraph grandTotalParagraph = new Paragraph("Grand total", FONT_BOLD);
|
|
|
974 |
grandTotalParagraph.setIndentationRight(20);
|
|
|
975 |
grandTotalTable.addCell(grandTotalParagraph);
|
|
|
976 |
Paragraph rsParagraph = new Paragraph("Rs.", FONT_BOLD);
|
|
|
977 |
grandTotalTable.addCell(rsParagraph);
|
|
|
978 |
Paragraph amountParagraph = new Paragraph(String.format("%.2f", pdfModel.getTotalAmount()), FONT_BOLD);
|
|
|
979 |
grandTotalTable.addCell(amountParagraph);
|
| 23509 |
amit.gupta |
980 |
|
| 32275 |
tejbeer |
981 |
document.add(grandTotalTable);
|
| 23509 |
amit.gupta |
982 |
|
| 32275 |
tejbeer |
983 |
PdfPTable amountInWordsTable = new PdfPTable(3);
|
|
|
984 |
if (!stateGst) {
|
|
|
985 |
amountInWordsTable.setWidths(new float[]{2, 5.1f, 0.9f});
|
|
|
986 |
} else {
|
|
|
987 |
amountInWordsTable.setWidths(new float[]{2, 5.2f, 0.8f});
|
|
|
988 |
}
|
|
|
989 |
amountInWordsTable.setWidthPercentage(95);
|
|
|
990 |
amountInWordsTable.addCell(new Paragraph("Amount in Words:", FONT_BOLD));
|
| 23509 |
amit.gupta |
991 |
|
| 32275 |
tejbeer |
992 |
String amountInWords = toAmountInWords(pdfModel.getTotalAmount());
|
|
|
993 |
amountInWordsTable.addCell(new Paragraph(amountInWords.toString(), FONT_BOLD));
|
|
|
994 |
amountInWordsTable.addCell(new Paragraph("E & O.E", FONT_NORMAL));
|
|
|
995 |
document.add(amountInWordsTable);
|
| 23509 |
amit.gupta |
996 |
|
| 35799 |
amit |
997 |
// Margin scheme declaration for debit notes
|
|
|
998 |
addMarginSchemeDeclaration(document, pdfModel);
|
|
|
999 |
|
| 32275 |
tejbeer |
1000 |
document.newPage();
|
|
|
1001 |
}
|
|
|
1002 |
document.close(); // no need to close PDFwriter?
|
| 30539 |
amit.gupta |
1003 |
|
| 32275 |
tejbeer |
1004 |
} catch (DocumentException e) {
|
|
|
1005 |
LOGGER.error("Unable to write data to pdf file : ", e);
|
|
|
1006 |
} catch (Exception e) {
|
|
|
1007 |
// TODO Auto-generated catch block
|
|
|
1008 |
e.printStackTrace();
|
|
|
1009 |
}
|
|
|
1010 |
}
|
| 23509 |
amit.gupta |
1011 |
|
| 32275 |
tejbeer |
1012 |
private static String toAmountInWords(float amount) {
|
|
|
1013 |
RuleBasedNumberFormat amountInWordsFormat = new RuleBasedNumberFormat(indianLocale, RuleBasedNumberFormat.SPELLOUT);
|
|
|
1014 |
StringBuilder amountInWords = new StringBuilder("Rs. ");
|
|
|
1015 |
amountInWords.append(StringUtils.capitalize(amountInWordsFormat.format((int) amount)));
|
|
|
1016 |
amountInWords.append(" and ");
|
|
|
1017 |
amountInWords.append(StringUtils.capitalize(amountInWordsFormat.format((int) (amount * 100) % 100)));
|
|
|
1018 |
amountInWords.append(" paise");
|
|
|
1019 |
return amountInWords.toString();
|
|
|
1020 |
}
|
| 23654 |
amit.gupta |
1021 |
|
| 32275 |
tejbeer |
1022 |
public static void generateAndWriteCustomerCreditNotes(List<CreditNotePdfModel> creditNotes, OutputStream outputStream) {
|
|
|
1023 |
Document document = new Document();
|
|
|
1024 |
document.setMargins(0, 0, 25, 0);
|
|
|
1025 |
try {
|
|
|
1026 |
PdfWriter.getInstance(document, outputStream);
|
| 24506 |
amit.gupta |
1027 |
|
| 32275 |
tejbeer |
1028 |
document.open();
|
|
|
1029 |
document.addTitle(creditNotes.get(0).getPdfModel().getTitle());
|
|
|
1030 |
document.addAuthor(creditNotes.get(0).getPdfModel().getAuther());
|
|
|
1031 |
for (CreditNotePdfModel creditNotePdfModel : creditNotes) {
|
|
|
1032 |
InvoicePdfModel pdfModel = creditNotePdfModel.getPdfModel();
|
|
|
1033 |
CustomCustomer customer = pdfModel.getCustomer();
|
|
|
1034 |
CustomRetailer retailer = pdfModel.getRetailer();
|
|
|
1035 |
boolean stateGst = false;
|
| 32290 |
tejbeer |
1036 |
|
| 32275 |
tejbeer |
1037 |
if (customer.getAddress().getState().equals(retailer.getAddress().getState())) {
|
|
|
1038 |
stateGst = true;
|
|
|
1039 |
}
|
| 33298 |
amit.gupta |
1040 |
List<CustomOrderItem> orderItems = pdfModel.getOrderItems();
|
| 23654 |
amit.gupta |
1041 |
|
| 32275 |
tejbeer |
1042 |
Paragraph paragraphTitle = new Paragraph(pdfModel.getTitle(), FONT_TITLE);
|
|
|
1043 |
paragraphTitle.setAlignment(Element.ALIGN_CENTER);
|
| 23654 |
amit.gupta |
1044 |
|
| 32275 |
tejbeer |
1045 |
PdfPCell blankCell = new PdfPCell();
|
|
|
1046 |
blankCell.setBorder(Rectangle.NO_BORDER);
|
|
|
1047 |
PdfPTable tableCustomerRetailer = new PdfPTable(3);
|
|
|
1048 |
tableCustomerRetailer.setWidthPercentage(95);
|
|
|
1049 |
PdfPCell partnerInfo = new PdfPCell();
|
|
|
1050 |
partnerInfo.addElement(new Paragraph("To Party:", FONT_BOLD));
|
|
|
1051 |
partnerInfo.addElement(
|
|
|
1052 |
new Paragraph(StringUtils.capitalize(customer.getAddress().getName()), FONT_NORMAL));
|
|
|
1053 |
partnerInfo.addElement(new Paragraph(
|
|
|
1054 |
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 |
1055 |
|
| 32275 |
tejbeer |
1056 |
partnerInfo.addElement(new Paragraph(
|
|
|
1057 |
StringUtils.capitalize(customer.getAddress().getState()) + "(" + pdfModel.getCustomerAddressStateCode() + ")", FONT_NORMAL));
|
|
|
1058 |
partnerInfo.addElement(new Paragraph("Mobile - " + customer.getMobileNumber(), FONT_NORMAL));
|
|
|
1059 |
if (customer.getGstNumber() != null && !customer.getGstNumber().isEmpty()) {
|
|
|
1060 |
partnerInfo.addElement(new Paragraph("GST No - " + customer.getGstNumber(), FONT_BOLD));
|
|
|
1061 |
}
|
| 23654 |
amit.gupta |
1062 |
|
| 32275 |
tejbeer |
1063 |
PdfPCell sellerParty = new PdfPCell();
|
|
|
1064 |
sellerParty.addElement(new Paragraph("From Party:", FONT_BOLD));
|
|
|
1065 |
sellerParty.addElement(
|
|
|
1066 |
new Paragraph(StringUtils.capitalize(retailer.getAddress().getName()), FONT_NORMAL));
|
|
|
1067 |
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));
|
|
|
1068 |
sellerParty.addElement(new Paragraph(
|
|
|
1069 |
retailer.getAddress().getState() + "(" + pdfModel.getPartnerAddressStateCode() + ")", FONT_NORMAL));
|
|
|
1070 |
sellerParty.addElement(new Paragraph("Mobile - " + retailer.getAddress().getPhoneNumber(), FONT_NORMAL));
|
|
|
1071 |
sellerParty.addElement(new Paragraph("GST No - " + retailer.getGstNumber(), FONT_BOLD));
|
| 23654 |
amit.gupta |
1072 |
|
| 32275 |
tejbeer |
1073 |
PdfPTable tableInvoiceDateRetailer = new PdfPTable(1);
|
|
|
1074 |
tableInvoiceDateRetailer.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
| 23654 |
amit.gupta |
1075 |
|
| 32275 |
tejbeer |
1076 |
PdfPTable tableInvoiceDate = new PdfPTable(2);
|
|
|
1077 |
tableInvoiceDate.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
|
|
1078 |
tableInvoiceDate.setWidthPercentage(90);
|
| 23654 |
amit.gupta |
1079 |
|
| 32275 |
tejbeer |
1080 |
PdfPCell debitNoteDetails = new PdfPCell(new Paragraph("Credit Note Details", FONT_BOLD));
|
|
|
1081 |
debitNoteDetails.setColspan(2);
|
|
|
1082 |
debitNoteDetails.setBorder(Rectangle.NO_BORDER);
|
| 23654 |
amit.gupta |
1083 |
|
| 32275 |
tejbeer |
1084 |
PdfPCell debitNoteNumberKey = new PdfPCell(new Paragraph("Credit Note No:", FONT_NORMAL));
|
|
|
1085 |
debitNoteNumberKey.setBorder(Rectangle.NO_BORDER);
|
|
|
1086 |
PdfPCell debitNoteNumberValue = new PdfPCell(
|
|
|
1087 |
new Paragraph(creditNotePdfModel.getCreditNoteNumber(), FONT_NORMAL));
|
|
|
1088 |
debitNoteNumberValue.setBorder(Rectangle.NO_BORDER);
|
| 23654 |
amit.gupta |
1089 |
|
| 32275 |
tejbeer |
1090 |
PdfPCell debitNoteDateKey = new PdfPCell(new Paragraph("Credit Note Dt:", FONT_NORMAL));
|
|
|
1091 |
debitNoteDateKey.setBorder(Rectangle.NO_BORDER);
|
| 23654 |
amit.gupta |
1092 |
|
| 32275 |
tejbeer |
1093 |
PdfPCell debitNoteDateValue = new PdfPCell(
|
|
|
1094 |
new Paragraph(creditNotePdfModel.getCreditNoteDate(), FONT_NORMAL));
|
|
|
1095 |
debitNoteDateValue.setBorder(Rectangle.NO_BORDER);
|
|
|
1096 |
tableInvoiceDate.addCell(debitNoteDetails);
|
|
|
1097 |
tableInvoiceDate.addCell(debitNoteNumberKey);
|
|
|
1098 |
tableInvoiceDate.addCell(debitNoteNumberValue);
|
|
|
1099 |
tableInvoiceDate.addCell(debitNoteDateKey);
|
|
|
1100 |
tableInvoiceDate.addCell(debitNoteDateValue);
|
| 32980 |
amit.gupta |
1101 |
if (pdfModel.getInvoiceNumber() != null) {
|
| 32275 |
tejbeer |
1102 |
PdfPCell dateKey = new PdfPCell(new Paragraph("Invoice Dt:", FONT_NORMAL));
|
|
|
1103 |
dateKey.setBorder(Rectangle.NO_BORDER);
|
|
|
1104 |
PdfPCell dateValue = new PdfPCell(new Paragraph(pdfModel.getInvoiceDate(), FONT_NORMAL));
|
|
|
1105 |
dateValue.setBorder(Rectangle.NO_BORDER);
|
| 23654 |
amit.gupta |
1106 |
|
| 32275 |
tejbeer |
1107 |
PdfPCell invoiceNumberKey = new PdfPCell(new Paragraph("Invoice Ref No:", FONT_NORMAL));
|
|
|
1108 |
invoiceNumberKey.setBorder(Rectangle.NO_BORDER);
|
|
|
1109 |
PdfPCell invoiceNumberValue = new PdfPCell(new Paragraph(pdfModel.getInvoiceNumber(), FONT_NORMAL));
|
|
|
1110 |
invoiceNumberValue.setBorder(Rectangle.NO_BORDER);
|
|
|
1111 |
tableInvoiceDate.addCell(invoiceNumberKey);
|
|
|
1112 |
tableInvoiceDate.addCell(invoiceNumberValue);
|
|
|
1113 |
tableInvoiceDate.addCell(dateKey);
|
|
|
1114 |
tableInvoiceDate.addCell(dateValue);
|
|
|
1115 |
}
|
| 31008 |
amit.gupta |
1116 |
|
| 32275 |
tejbeer |
1117 |
tableCustomerRetailer.addCell(partnerInfo);
|
|
|
1118 |
tableCustomerRetailer.addCell(tableInvoiceDate);
|
|
|
1119 |
tableCustomerRetailer.addCell(sellerParty);
|
| 23654 |
amit.gupta |
1120 |
|
| 32275 |
tejbeer |
1121 |
PdfPTable orders = null;
|
|
|
1122 |
if (stateGst) {
|
|
|
1123 |
orders = new PdfPTable(stateWidthsCrNote.length);
|
|
|
1124 |
orders.setWidths(stateWidthsCrNote);
|
|
|
1125 |
} else {
|
|
|
1126 |
orders = new PdfPTable(igstWidthsCrNote.length);
|
|
|
1127 |
orders.setWidths(igstWidthsCrNote);
|
|
|
1128 |
}
|
|
|
1129 |
orders.setWidthPercentage(95);
|
|
|
1130 |
orders.addCell(new Paragraph("Description", FONT_BOLD));
|
|
|
1131 |
orders.addCell(new Paragraph("HSN", FONT_BOLD));
|
|
|
1132 |
orders.addCell(new Paragraph("Qty", FONT_BOLD));
|
|
|
1133 |
orders.addCell(new Paragraph("Rate\n(Per pc)", FONT_BOLD));
|
|
|
1134 |
orders.addCell(new Paragraph("Total\nTaxable", FONT_BOLD));
|
|
|
1135 |
if (!stateGst) {
|
|
|
1136 |
orders.addCell(new Paragraph("IGST%", FONT_BOLD));
|
|
|
1137 |
orders.addCell(new Paragraph("IGST", FONT_BOLD));
|
|
|
1138 |
} else {
|
|
|
1139 |
orders.addCell(new Paragraph("CGST %", FONT_BOLD));
|
|
|
1140 |
orders.addCell(new Paragraph("CGST", FONT_BOLD));
|
|
|
1141 |
orders.addCell(new Paragraph("SGST %", FONT_BOLD));
|
|
|
1142 |
orders.addCell(new Paragraph("SGST", FONT_BOLD));
|
|
|
1143 |
}
|
|
|
1144 |
orders.addCell(new Paragraph("Total", FONT_BOLD));
|
| 23654 |
amit.gupta |
1145 |
|
| 32275 |
tejbeer |
1146 |
orders.setHeaderRows(1);
|
| 23654 |
amit.gupta |
1147 |
|
| 32275 |
tejbeer |
1148 |
float igstTotalAmount = 0, cgstTotalAmount = 0, sgstTotalAmount = 0;
|
| 35799 |
amit |
1149 |
boolean marginSeparatorAdded = false;
|
| 32275 |
tejbeer |
1150 |
for (CustomOrderItem orderItem : orderItems) {
|
| 35799 |
amit |
1151 |
if (orderItem.isMarginScheme() && !marginSeparatorAdded) {
|
|
|
1152 |
addMarginSchemeSeparator(orders, stateGst ? stateWidthsCrNote.length : igstWidthsCrNote.length);
|
|
|
1153 |
marginSeparatorAdded = true;
|
|
|
1154 |
}
|
|
|
1155 |
|
| 32275 |
tejbeer |
1156 |
LOGGER.info("Custom Order Item - {}", orderItem);
|
|
|
1157 |
orders.addCell(new Paragraph(orderItem.getDescription(), FONT_NORMAL));
|
|
|
1158 |
orders.addCell(new Paragraph(orderItem.getHsnCode(), FONT_NORMAL));
|
|
|
1159 |
orders.addCell(new Paragraph(String.valueOf(orderItem.getQuantity()), FONT_NORMAL));
|
|
|
1160 |
orders.addCell(new Paragraph(String.format("%.2f", orderItem.getRate()), FONT_NORMAL));
|
|
|
1161 |
orders.addCell(new Paragraph(String.format("%.2f", orderItem.getAmount()), FONT_NORMAL));
|
|
|
1162 |
if (!stateGst) {
|
|
|
1163 |
orders.addCell(new Paragraph(String.format("%.2f", orderItem.getIgstRate()), FONT_NORMAL));
|
|
|
1164 |
orders.addCell(new Paragraph(String.format("%.2f", orderItem.getIgstAmount()), FONT_NORMAL));
|
|
|
1165 |
igstTotalAmount = igstTotalAmount + orderItem.getIgstAmount();
|
|
|
1166 |
} else {
|
|
|
1167 |
orders.addCell(new Paragraph(String.format("%.2f", orderItem.getCgstRate()), FONT_NORMAL));
|
|
|
1168 |
orders.addCell(new Paragraph(String.format("%.2f", orderItem.getCgstAmount()), FONT_NORMAL));
|
|
|
1169 |
orders.addCell(new Paragraph(String.format("%.2f", orderItem.getSgstRate()), FONT_NORMAL));
|
|
|
1170 |
orders.addCell(new Paragraph(String.format("%.2f", orderItem.getSgstAmount()), FONT_NORMAL));
|
|
|
1171 |
cgstTotalAmount = cgstTotalAmount + orderItem.getCgstAmount();
|
|
|
1172 |
sgstTotalAmount = sgstTotalAmount + orderItem.getSgstAmount();
|
|
|
1173 |
}
|
|
|
1174 |
orders.addCell(new Paragraph(String.format("%.0f", orderItem.getNetAmount()), FONT_NORMAL));
|
|
|
1175 |
LOGGER.info("IN FOR LOOP");
|
|
|
1176 |
}
|
| 23654 |
amit.gupta |
1177 |
|
| 32275 |
tejbeer |
1178 |
document.add(paragraphTitle);
|
| 23654 |
amit.gupta |
1179 |
|
| 32275 |
tejbeer |
1180 |
document.add(Chunk.NEWLINE);
|
|
|
1181 |
document.add(tableCustomerRetailer);
|
| 23654 |
amit.gupta |
1182 |
|
| 32275 |
tejbeer |
1183 |
document.add(Chunk.NEWLINE);
|
|
|
1184 |
document.add(orders);
|
| 23654 |
amit.gupta |
1185 |
|
| 32275 |
tejbeer |
1186 |
PdfPTable grandTotalTable = new PdfPTable(3);
|
|
|
1187 |
if (stateGst) {
|
|
|
1188 |
grandTotalTable.setWidths(new float[]{6.6f, .6f, .8f});
|
|
|
1189 |
} else {
|
|
|
1190 |
grandTotalTable.setWidths(new float[]{6.5f, .6f, .9f});
|
|
|
1191 |
}
|
|
|
1192 |
grandTotalTable.setWidthPercentage(95);
|
| 23654 |
amit.gupta |
1193 |
|
| 32275 |
tejbeer |
1194 |
Paragraph grandTotalParagraph = new Paragraph("Grand total", FONT_BOLD);
|
|
|
1195 |
grandTotalParagraph.setIndentationRight(20);
|
|
|
1196 |
grandTotalTable.addCell(grandTotalParagraph);
|
|
|
1197 |
Paragraph rsParagraph = new Paragraph("Rs.", FONT_BOLD);
|
|
|
1198 |
grandTotalTable.addCell(rsParagraph);
|
|
|
1199 |
Paragraph amountParagraph = new Paragraph(String.format("%.2f", pdfModel.getTotalAmount()), FONT_BOLD);
|
|
|
1200 |
grandTotalTable.addCell(amountParagraph);
|
| 23654 |
amit.gupta |
1201 |
|
| 32275 |
tejbeer |
1202 |
document.add(grandTotalTable);
|
| 23654 |
amit.gupta |
1203 |
|
| 32275 |
tejbeer |
1204 |
PdfPTable amountInWordsTable = new PdfPTable(3);
|
|
|
1205 |
if (!stateGst) {
|
|
|
1206 |
amountInWordsTable.setWidths(new float[]{2, 5.1f, 0.9f});
|
|
|
1207 |
} else {
|
|
|
1208 |
amountInWordsTable.setWidths(new float[]{2, 5.2f, 0.8f});
|
|
|
1209 |
}
|
|
|
1210 |
amountInWordsTable.setWidthPercentage(95);
|
|
|
1211 |
amountInWordsTable.addCell(new Paragraph("Amount in Words:", FONT_BOLD));
|
| 23654 |
amit.gupta |
1212 |
|
| 32275 |
tejbeer |
1213 |
String amountInWords = toAmountInWords(pdfModel.getTotalAmount());
|
|
|
1214 |
amountInWordsTable.addCell(new Paragraph(amountInWords.toString(), FONT_BOLD));
|
|
|
1215 |
amountInWordsTable.addCell(new Paragraph("E & O.E", FONT_NORMAL));
|
|
|
1216 |
document.add(amountInWordsTable);
|
| 23654 |
amit.gupta |
1217 |
|
| 35799 |
amit |
1218 |
// Margin scheme declaration for credit notes
|
|
|
1219 |
addMarginSchemeDeclaration(document, pdfModel);
|
|
|
1220 |
|
| 32275 |
tejbeer |
1221 |
document.newPage();
|
|
|
1222 |
}
|
|
|
1223 |
document.close(); // no need to close PDFwriter?
|
|
|
1224 |
} catch (DocumentException e) {
|
|
|
1225 |
LOGGER.error("Unable to write data to pdf file : ", e);
|
|
|
1226 |
} catch (Exception e) {
|
|
|
1227 |
// TODO Auto-generated catch block
|
|
|
1228 |
e.printStackTrace();
|
|
|
1229 |
}
|
| 23654 |
amit.gupta |
1230 |
|
| 32275 |
tejbeer |
1231 |
}
|
| 34805 |
ranu |
1232 |
|
|
|
1233 |
public static byte[] mergePdfFiles(List<byte[]> pdfFiles) throws IOException, DocumentException {
|
|
|
1234 |
ByteArrayOutputStream mergedOutputStream = new ByteArrayOutputStream();
|
|
|
1235 |
Document document = new Document();
|
|
|
1236 |
PdfCopy copy = new PdfCopy(document, mergedOutputStream);
|
|
|
1237 |
document.open();
|
|
|
1238 |
|
|
|
1239 |
for (byte[] pdf : pdfFiles) {
|
|
|
1240 |
PdfReader reader = new PdfReader(new ByteArrayInputStream(pdf));
|
|
|
1241 |
int n = reader.getNumberOfPages();
|
|
|
1242 |
for (int i = 1; i <= n; i++) {
|
|
|
1243 |
copy.addPage(copy.getImportedPage(reader, i));
|
|
|
1244 |
}
|
|
|
1245 |
copy.freeReader(reader);
|
|
|
1246 |
reader.close();
|
|
|
1247 |
}
|
|
|
1248 |
|
|
|
1249 |
document.close();
|
|
|
1250 |
return mergedOutputStream.toByteArray();
|
|
|
1251 |
}
|
|
|
1252 |
|
| 21686 |
ashik.ali |
1253 |
}
|