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