| 21686 |
ashik.ali |
1 |
package com.spice.profitmandi.common.util;
|
|
|
2 |
|
|
|
3 |
import java.io.OutputStream;
|
| 23001 |
amit.gupta |
4 |
import java.util.List;
|
| 21915 |
ashik.ali |
5 |
import java.util.Locale;
|
| 21686 |
ashik.ali |
6 |
import java.util.Set;
|
|
|
7 |
|
|
|
8 |
import org.slf4j.Logger;
|
|
|
9 |
import org.slf4j.LoggerFactory;
|
| 22068 |
ashik.ali |
10 |
import org.springframework.util.StringUtils;
|
| 21686 |
ashik.ali |
11 |
|
| 21915 |
ashik.ali |
12 |
import com.ibm.icu.text.RuleBasedNumberFormat;
|
| 21686 |
ashik.ali |
13 |
import com.itextpdf.text.Chunk;
|
|
|
14 |
import com.itextpdf.text.Document;
|
|
|
15 |
import com.itextpdf.text.DocumentException;
|
|
|
16 |
import com.itextpdf.text.Element;
|
|
|
17 |
import com.itextpdf.text.Font;
|
|
|
18 |
import com.itextpdf.text.Paragraph;
|
|
|
19 |
import com.itextpdf.text.Rectangle;
|
|
|
20 |
import com.itextpdf.text.pdf.PdfPCell;
|
|
|
21 |
import com.itextpdf.text.pdf.PdfPTable;
|
|
|
22 |
import com.itextpdf.text.pdf.PdfWriter;
|
|
|
23 |
import com.spice.profitmandi.common.model.CustomCustomer;
|
| 23001 |
amit.gupta |
24 |
import com.spice.profitmandi.common.model.CustomInsurancePolicy;
|
| 22858 |
ashik.ali |
25 |
import com.spice.profitmandi.common.model.CustomOrderItem;
|
| 23558 |
amit.gupta |
26 |
import com.spice.profitmandi.common.model.CustomPaymentOption;
|
| 21686 |
ashik.ali |
27 |
import com.spice.profitmandi.common.model.CustomRetailer;
|
| 23509 |
amit.gupta |
28 |
import com.spice.profitmandi.common.model.DebitNotePdfModel;
|
| 21686 |
ashik.ali |
29 |
import com.spice.profitmandi.common.model.PdfModel;
|
|
|
30 |
|
|
|
31 |
public class PdfUtils {
|
| 23509 |
amit.gupta |
32 |
|
|
|
33 |
private static final Font FONT_TITLE = new Font(Font.FontFamily.HELVETICA, 18, Font.BOLD);
|
| 21965 |
ashik.ali |
34 |
private static Font FONT_NORMAL = new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL);
|
|
|
35 |
private static Font FONT_BOLD = new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.BOLD);
|
| 23509 |
amit.gupta |
36 |
// private static Font fontTableHeader = new
|
|
|
37 |
// Font(Font.FontFamily.TIMES_ROMAN, 14, Font.BOLD);
|
| 23374 |
amit.gupta |
38 |
private static final String INVOICE_TITLE = "TAX INVOICE";
|
| 23532 |
amit.gupta |
39 |
private static final String DEBIT_NOTE_TITLE = "DEBIT NOTE";
|
| 23509 |
amit.gupta |
40 |
|
| 23549 |
amit.gupta |
41 |
private static float[] igstWidthsWithDiscount = new float[] { .3f, 2.6f, 0.7f, .4f, 0.7f, 0.5f, .7f, .6f, 0.6f, 0.9f };
|
|
|
42 |
private static float[] stateWidthsWithDiscount = new float[] { .3f, 2.1f, 0.7f, .3f, 0.6f, 0.4f, .7f, .5f, .6f, .5f,
|
| 23509 |
amit.gupta |
43 |
.6f, .8f };
|
|
|
44 |
|
| 23542 |
amit.gupta |
45 |
private static float[] igstWidths = new float[] { .6f, 2.6f, 0.7f, .4f, 0.7f, .7f, .6f, 0.6f, 0.9f };
|
|
|
46 |
private static float[] stateWidths = new float[] { .6f, 2.1f, 0.7f, .3f, 0.6f, .7f, .5f, .6f, .5f, .6f, .8f };
|
| 23533 |
amit.gupta |
47 |
|
| 21915 |
ashik.ali |
48 |
private static final Locale indianLocale = Locale.getDefault();
|
| 23509 |
amit.gupta |
49 |
|
| 21686 |
ashik.ali |
50 |
private static final Logger LOGGER = LoggerFactory.getLogger(PdfUtils.class);
|
| 23509 |
amit.gupta |
51 |
|
|
|
52 |
public static void generateAndWrite(PdfModel pdfModel, OutputStream outputStream) {
|
| 21686 |
ashik.ali |
53 |
Document document = new Document();
|
| 21926 |
ashik.ali |
54 |
document.setMargins(0, 0, 25, 0);
|
| 23509 |
amit.gupta |
55 |
try {
|
|
|
56 |
CustomCustomer customer = pdfModel.getCustomer();
|
|
|
57 |
CustomRetailer retailer = pdfModel.getRetailer();
|
|
|
58 |
boolean stateGst = false;
|
|
|
59 |
String customerAddressStateCode = "", retailerAddressStateCode = "";
|
|
|
60 |
if (customer.getAddress().getState().equals(retailer.getAddress().getState())) {
|
|
|
61 |
stateGst = true;
|
|
|
62 |
customerAddressStateCode = Utils.getStateCode(customer.getAddress().getState());
|
|
|
63 |
} else {
|
|
|
64 |
customerAddressStateCode = Utils.getStateCode(customer.getAddress().getState());
|
|
|
65 |
retailerAddressStateCode = Utils.getStateCode(retailer.getAddress().getState());
|
|
|
66 |
}
|
|
|
67 |
Set<CustomOrderItem> orderItems = pdfModel.getOrderItems();
|
| 21686 |
ashik.ali |
68 |
|
| 23509 |
amit.gupta |
69 |
PdfWriter.getInstance(document, outputStream);
|
| 22687 |
amit.gupta |
70 |
|
| 23509 |
amit.gupta |
71 |
document.open();
|
|
|
72 |
document.addTitle(pdfModel.getTitle());
|
|
|
73 |
document.addAuthor(pdfModel.getAuther());
|
| 22889 |
amit.gupta |
74 |
|
| 23509 |
amit.gupta |
75 |
Paragraph paragraphTitle = new Paragraph(INVOICE_TITLE, FONT_TITLE);
|
|
|
76 |
paragraphTitle.setAlignment(Element.ALIGN_CENTER);
|
| 21686 |
ashik.ali |
77 |
|
| 23509 |
amit.gupta |
78 |
PdfPCell blankCell = new PdfPCell();
|
|
|
79 |
blankCell.setBorder(Rectangle.NO_BORDER);
|
|
|
80 |
PdfPTable tableCustomerRetailer = new PdfPTable(3);
|
|
|
81 |
tableCustomerRetailer.setWidthPercentage(90);
|
|
|
82 |
tableCustomerRetailer.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
|
|
83 |
PdfPCell columnCustomerInfo = new PdfPCell();
|
|
|
84 |
columnCustomerInfo.addElement(new Paragraph("Customer Details", FONT_BOLD));
|
|
|
85 |
columnCustomerInfo.addElement(new Paragraph(
|
|
|
86 |
StringUtils.capitalize(customer.getFirstName() + " " + customer.getLastName()), FONT_NORMAL));
|
|
|
87 |
columnCustomerInfo.addElement(new Paragraph(StringUtils.capitalize(customer.getAddress().getLine1()) + ", "
|
|
|
88 |
+ StringUtils.capitalize(customer.getAddress().getLine2()), FONT_NORMAL));
|
|
|
89 |
columnCustomerInfo.addElement(new Paragraph(StringUtils.capitalize(customer.getAddress().getCity()) + ", "
|
|
|
90 |
+ StringUtils.capitalize(customer.getAddress().getState()) + "(" + customerAddressStateCode + ")"
|
|
|
91 |
+ "\n" + customer.getAddress().getPinCode(), FONT_NORMAL));
|
|
|
92 |
columnCustomerInfo.addElement(new Paragraph("Mobile - " + customer.getMobileNumber(), FONT_NORMAL));
|
|
|
93 |
if (customer.getGstNumber() != null && !customer.getGstNumber().isEmpty()) {
|
|
|
94 |
columnCustomerInfo.addElement(new Paragraph("GST Number - " + customer.getGstNumber(), FONT_NORMAL));
|
|
|
95 |
}
|
|
|
96 |
columnCustomerInfo.setBorder(Rectangle.NO_BORDER);
|
|
|
97 |
PdfPCell columnRetailerInfo = new PdfPCell();
|
|
|
98 |
columnRetailerInfo
|
|
|
99 |
.addElement(new Paragraph(StringUtils.capitalize(retailer.getAddress().getName()), FONT_BOLD));
|
|
|
100 |
columnRetailerInfo.addElement(new Paragraph(StringUtils.capitalize(retailer.getAddress().getLine1()) + ", "
|
|
|
101 |
+ StringUtils.capitalize(retailer.getAddress().getLine2()) + ", "
|
|
|
102 |
+ StringUtils.capitalize(retailer.getAddress().getCity()) + "-" + retailer.getAddress().getPinCode()
|
|
|
103 |
+ ", " + retailer.getAddress().getState() + "("
|
|
|
104 |
+ (stateGst ? customerAddressStateCode : retailerAddressStateCode) + ")", FONT_BOLD));
|
|
|
105 |
columnRetailerInfo
|
|
|
106 |
.addElement(new Paragraph("Contact No.- " + retailer.getAddress().getPhoneNumber(), FONT_BOLD));
|
|
|
107 |
columnRetailerInfo.addElement(new Paragraph("GST NO. " + retailer.getGstNumber(), FONT_BOLD));
|
|
|
108 |
columnRetailerInfo.setBorder(Rectangle.NO_BORDER);
|
|
|
109 |
|
|
|
110 |
PdfPTable tableInvoiceDateRetailer = new PdfPTable(1);
|
|
|
111 |
tableInvoiceDateRetailer.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
|
|
112 |
|
|
|
113 |
PdfPTable tableInvoiceDate = new PdfPTable(2);
|
|
|
114 |
tableInvoiceDate.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
|
|
115 |
|
|
|
116 |
PdfPCell invoiceNumberKey = new PdfPCell(new Paragraph("Invoice No:", FONT_NORMAL));
|
|
|
117 |
invoiceNumberKey.setBorder(Rectangle.NO_BORDER);
|
|
|
118 |
|
|
|
119 |
PdfPCell invoiceNumberValue = new PdfPCell(new Paragraph(pdfModel.getInvoiceNumber(), FONT_NORMAL));
|
|
|
120 |
invoiceNumberValue.setBorder(Rectangle.NO_BORDER);
|
|
|
121 |
|
|
|
122 |
PdfPCell dateKey = new PdfPCell(new Paragraph("Date:", FONT_NORMAL));
|
|
|
123 |
dateKey.setBorder(Rectangle.NO_BORDER);
|
|
|
124 |
|
|
|
125 |
PdfPCell dateValue = new PdfPCell(new Paragraph(pdfModel.getInvoiceDate(), FONT_NORMAL));
|
|
|
126 |
dateValue.setBorder(Rectangle.NO_BORDER);
|
|
|
127 |
tableInvoiceDate.addCell(invoiceNumberKey);
|
|
|
128 |
// tableInvoiceDate.addCell(blankCell);
|
|
|
129 |
tableInvoiceDate.addCell(invoiceNumberValue);
|
|
|
130 |
tableInvoiceDate.addCell(dateKey);
|
|
|
131 |
// tableInvoiceDate.addCell(blankCell);
|
|
|
132 |
tableInvoiceDate.addCell(dateValue);
|
|
|
133 |
tableInvoiceDateRetailer.addCell(tableInvoiceDate);
|
|
|
134 |
tableInvoiceDateRetailer.addCell(columnRetailerInfo);
|
|
|
135 |
|
|
|
136 |
tableCustomerRetailer.addCell(columnCustomerInfo);
|
|
|
137 |
tableCustomerRetailer.addCell(blankCell);
|
|
|
138 |
tableCustomerRetailer.addCell(tableInvoiceDateRetailer);
|
|
|
139 |
|
|
|
140 |
PdfPTable orders = null;
|
|
|
141 |
if (stateGst) {
|
|
|
142 |
orders = new PdfPTable(stateWidthsWithDiscount.length);
|
|
|
143 |
orders.setWidths(stateWidthsWithDiscount);
|
|
|
144 |
} else {
|
|
|
145 |
orders = new PdfPTable(igstWidthsWithDiscount.length);
|
|
|
146 |
orders.setWidths(igstWidthsWithDiscount);
|
|
|
147 |
}
|
|
|
148 |
orders.setWidthPercentage(90);
|
|
|
149 |
orders.addCell(new Paragraph("Sl", FONT_BOLD));
|
|
|
150 |
orders.addCell(new Paragraph("Description", FONT_BOLD));
|
|
|
151 |
orders.addCell(new Paragraph("HSN", FONT_BOLD));
|
|
|
152 |
orders.addCell(new Paragraph("Qty", FONT_BOLD));
|
|
|
153 |
orders.addCell(new Paragraph("Rate\n(Per pc)", FONT_BOLD));
|
|
|
154 |
orders.addCell(new Paragraph("Disc.", FONT_BOLD));
|
|
|
155 |
orders.addCell(new Paragraph("Total\nTaxable", FONT_BOLD));
|
|
|
156 |
if (!stateGst) {
|
|
|
157 |
orders.addCell(new Paragraph("IGST\n%", FONT_BOLD));
|
|
|
158 |
orders.addCell(new Paragraph("IGST", FONT_BOLD));
|
|
|
159 |
// orders.setWidths(new float[]{1, 3, 1, 1, 1, 1, 1, 1});
|
|
|
160 |
// total 8f
|
|
|
161 |
} else {
|
|
|
162 |
orders.addCell(new Paragraph("CGST %", FONT_BOLD));
|
|
|
163 |
orders.addCell(new Paragraph("CGST", FONT_BOLD));
|
|
|
164 |
orders.addCell(new Paragraph("SGST %", FONT_BOLD));
|
|
|
165 |
orders.addCell(new Paragraph("SGST", FONT_BOLD));
|
|
|
166 |
// orders.setWidths(new float[]{1, 3, 1, 1, 1, 1, 1, 1, 1, 1});
|
|
|
167 |
// total 8f
|
|
|
168 |
}
|
|
|
169 |
orders.addCell(new Paragraph("Total", FONT_BOLD));
|
|
|
170 |
|
|
|
171 |
// orders.addCell(new Paragraph("Item Total (Rs)", FONT_BOLD));
|
|
|
172 |
|
|
|
173 |
orders.setHeaderRows(1);
|
|
|
174 |
// orders.setSkipFirstHeader(true);
|
|
|
175 |
|
|
|
176 |
float igstTotalAmount = 0, cgstTotalAmount = 0, sgstTotalAmount = 0;
|
|
|
177 |
int index = 1;
|
|
|
178 |
for (CustomOrderItem orderItem : orderItems) {
|
|
|
179 |
orders.addCell(new Paragraph(String.valueOf(index++), FONT_NORMAL));
|
|
|
180 |
orders.addCell(new Paragraph(orderItem.getDescription(), FONT_NORMAL));
|
|
|
181 |
orders.addCell(new Paragraph(orderItem.getHsnCode(), FONT_NORMAL));
|
|
|
182 |
orders.addCell(new Paragraph(String.valueOf(orderItem.getQuantity()), FONT_NORMAL));
|
|
|
183 |
orders.addCell(new Paragraph(String.format("%.2f", orderItem.getRate()), FONT_NORMAL));
|
|
|
184 |
orders.addCell(new Paragraph(String.format("%.2f", orderItem.getDiscount()), FONT_NORMAL));
|
|
|
185 |
orders.addCell(new Paragraph(String.format("%.2f", orderItem.getAmount()), FONT_NORMAL));
|
|
|
186 |
if (!stateGst) {
|
|
|
187 |
orders.addCell(new Paragraph(String.format("%.2f", orderItem.getIgstRate()), FONT_NORMAL));
|
|
|
188 |
orders.addCell(new Paragraph(String.format("%.2f", orderItem.getIgstAmount()), FONT_NORMAL));
|
|
|
189 |
igstTotalAmount = igstTotalAmount + orderItem.getIgstAmount();
|
|
|
190 |
} else {
|
|
|
191 |
orders.addCell(new Paragraph(String.format("%.2f", orderItem.getCgstRate()), FONT_NORMAL));
|
|
|
192 |
orders.addCell(new Paragraph(String.format("%.2f", orderItem.getCgstAmount()), FONT_NORMAL));
|
|
|
193 |
orders.addCell(new Paragraph(String.format("%.2f", orderItem.getSgstRate()), FONT_NORMAL));
|
|
|
194 |
orders.addCell(new Paragraph(String.format("%.2f", orderItem.getSgstAmount()), FONT_NORMAL));
|
|
|
195 |
cgstTotalAmount = cgstTotalAmount + orderItem.getCgstAmount();
|
|
|
196 |
sgstTotalAmount = sgstTotalAmount + orderItem.getSgstAmount();
|
|
|
197 |
}
|
|
|
198 |
orders.addCell(new Paragraph(String.format("%.0f", orderItem.getNetAmount()), FONT_NORMAL));
|
|
|
199 |
// orders.addCell(new Paragraph(String.format("%.2f",
|
|
|
200 |
// orderItem.getItemTotal()), FONT_NORMAL));
|
|
|
201 |
}
|
|
|
202 |
|
|
|
203 |
for (CustomInsurancePolicy insurancePolicy : pdfModel.getInsurancePolicies()) {
|
|
|
204 |
orders.addCell(new Paragraph(String.valueOf(index++), FONT_NORMAL));
|
|
|
205 |
orders.addCell(new Paragraph(insurancePolicy.getDescription(), FONT_NORMAL));
|
|
|
206 |
orders.addCell(new Paragraph(insurancePolicy.getHsnCode(), FONT_NORMAL));
|
|
|
207 |
orders.addCell(new Paragraph("1", FONT_NORMAL));
|
|
|
208 |
orders.addCell(new Paragraph(String.format("%.2f", insurancePolicy.getRate()), FONT_NORMAL));
|
|
|
209 |
orders.addCell(new Paragraph("-", FONT_NORMAL));
|
|
|
210 |
orders.addCell(new Paragraph(String.format("%.2f", insurancePolicy.getRate()), FONT_NORMAL));
|
|
|
211 |
if (!stateGst) {
|
|
|
212 |
orders.addCell(new Paragraph(String.format("%.2f", insurancePolicy.getIgstRate()), FONT_NORMAL));
|
|
|
213 |
orders.addCell(new Paragraph(String.format("%.2f", insurancePolicy.getIgstAmount()), FONT_NORMAL));
|
|
|
214 |
igstTotalAmount = igstTotalAmount + insurancePolicy.getIgstAmount();
|
|
|
215 |
} else {
|
|
|
216 |
orders.addCell(new Paragraph(String.format("%.2f", insurancePolicy.getCgstRate()), FONT_NORMAL));
|
|
|
217 |
orders.addCell(new Paragraph(String.format("%.2f", insurancePolicy.getCgstAmount()), FONT_NORMAL));
|
|
|
218 |
orders.addCell(new Paragraph(String.format("%.2f", insurancePolicy.getSgstRate()), FONT_NORMAL));
|
|
|
219 |
orders.addCell(new Paragraph(String.format("%.2f", insurancePolicy.getSgstAmount()), FONT_NORMAL));
|
|
|
220 |
cgstTotalAmount = cgstTotalAmount + insurancePolicy.getCgstAmount();
|
|
|
221 |
sgstTotalAmount = sgstTotalAmount + insurancePolicy.getSgstAmount();
|
|
|
222 |
}
|
|
|
223 |
orders.addCell(new Paragraph(String.format("%.0f", insurancePolicy.getNetAmount()), FONT_NORMAL));
|
|
|
224 |
}
|
|
|
225 |
|
|
|
226 |
document.add(paragraphTitle);
|
|
|
227 |
document.add(Chunk.NEWLINE);
|
|
|
228 |
document.add(Chunk.NEWLINE);
|
|
|
229 |
document.add(tableCustomerRetailer);
|
|
|
230 |
|
|
|
231 |
document.add(Chunk.NEWLINE);
|
|
|
232 |
document.add(orders);
|
|
|
233 |
|
|
|
234 |
PdfPTable grandTotalTable = new PdfPTable(3);
|
| 23552 |
amit.gupta |
235 |
PdfPTable paymentsTable = new PdfPTable(2);
|
|
|
236 |
paymentsTable.setWidthPercentage(95);
|
|
|
237 |
paymentsTable.setWidths(new float[] { 8f, 2f });
|
|
|
238 |
|
|
|
239 |
|
| 23509 |
amit.gupta |
240 |
if (stateGst) {
|
|
|
241 |
grandTotalTable.setWidths(new float[] { 6.6f, .6f, .8f });
|
|
|
242 |
} else {
|
|
|
243 |
grandTotalTable.setWidths(new float[] { 6.5f, .6f, .9f });
|
|
|
244 |
}
|
|
|
245 |
grandTotalTable.setWidthPercentage(90);
|
|
|
246 |
|
|
|
247 |
Paragraph grandTotalParagraph = new Paragraph("Grand total", FONT_BOLD);
|
|
|
248 |
grandTotalParagraph.setIndentationRight(20);
|
|
|
249 |
grandTotalTable.addCell(grandTotalParagraph);
|
|
|
250 |
Paragraph rsParagraph = new Paragraph("Rs.", FONT_BOLD);
|
|
|
251 |
grandTotalTable.addCell(rsParagraph);
|
|
|
252 |
Paragraph amountParagraph = new Paragraph(String.format("%.2f", pdfModel.getTotalAmount()), FONT_BOLD);
|
|
|
253 |
grandTotalTable.addCell(amountParagraph);
|
|
|
254 |
|
|
|
255 |
document.add(grandTotalTable);
|
|
|
256 |
|
|
|
257 |
PdfPTable amountInWordsTable = new PdfPTable(3);
|
| 23558 |
amit.gupta |
258 |
amountInWordsTable.setWidthPercentage(90);
|
|
|
259 |
amountInWordsTable.addCell(new Paragraph("Amount in Words:", FONT_BOLD));
|
| 23509 |
amit.gupta |
260 |
if (!stateGst) {
|
|
|
261 |
amountInWordsTable.setWidths(new float[] { 2, 5.1f, 0.9f });
|
|
|
262 |
} else {
|
|
|
263 |
amountInWordsTable.setWidths(new float[] { 2, 5.2f, 0.8f });
|
|
|
264 |
}
|
|
|
265 |
|
|
|
266 |
String amountInWords = toAmountInWords(pdfModel.getTotalAmount());
|
|
|
267 |
amountInWordsTable.addCell(new Paragraph(amountInWords.toString(), FONT_BOLD));
|
|
|
268 |
amountInWordsTable.addCell(new Paragraph("E & O.E", FONT_NORMAL));
|
|
|
269 |
document.add(amountInWordsTable);
|
| 23558 |
amit.gupta |
270 |
|
|
|
271 |
if(pdfModel.getPaymentOptions() != null) {
|
|
|
272 |
PdfPTable paidAmountTable = new PdfPTable(3);
|
|
|
273 |
paidAmountTable.setWidthPercentage(90);
|
|
|
274 |
paidAmountTable.setWidths(new float[] { 2, 5.2f, 0.8f });
|
|
|
275 |
if (!stateGst) {
|
|
|
276 |
paidAmountTable.setWidths(new float[] { 2, 5.1f, 0.9f });
|
|
|
277 |
} else {
|
|
|
278 |
paidAmountTable.setWidths(new float[] { 2, 5.2f, 0.8f });
|
|
|
279 |
}
|
|
|
280 |
Paragraph para = new Paragraph("Paid Through", FONT_BOLD);
|
|
|
281 |
paidAmountTable.addCell(para);
|
|
|
282 |
for(CustomPaymentOption paymentOption : pdfModel.getPaymentOptions()) {
|
|
|
283 |
PdfPCell cell = new PdfPCell(new Paragraph(10, paymentOption.getPaymentOption(), FONT_BOLD));
|
|
|
284 |
cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
|
|
|
285 |
cell.setPadding(5);
|
|
|
286 |
paidAmountTable.addCell(cell);
|
| 23509 |
amit.gupta |
287 |
|
| 23558 |
amit.gupta |
288 |
PdfPCell cell1 = new PdfPCell(new Paragraph(10, FormattingUtils.formatDecimalTwoDigits(paymentOption.getAmount()), FONT_BOLD));
|
|
|
289 |
cell1.setHorizontalAlignment(Element.ALIGN_RIGHT);
|
|
|
290 |
cell1.setPadding(5);
|
|
|
291 |
paidAmountTable.addCell(cell1);
|
|
|
292 |
|
|
|
293 |
}
|
|
|
294 |
document.add(paidAmountTable);
|
|
|
295 |
}
|
|
|
296 |
|
| 23509 |
amit.gupta |
297 |
StringBuffer sb = new StringBuffer();
|
|
|
298 |
List<String> tncs = pdfModel.getTncs();
|
|
|
299 |
for (String tnc : tncs) {
|
|
|
300 |
sb.append(tnc).append("\n");
|
|
|
301 |
}
|
|
|
302 |
|
|
|
303 |
Paragraph warningParagraph = new Paragraph(sb.toString(), FONT_NORMAL);
|
|
|
304 |
warningParagraph.setIndentationLeft(40);
|
|
|
305 |
document.add(Chunk.NEWLINE);
|
|
|
306 |
document.add(warningParagraph);
|
|
|
307 |
|
|
|
308 |
document.close(); // no need to close PDFwriter?
|
|
|
309 |
|
|
|
310 |
} catch (DocumentException e) {
|
|
|
311 |
LOGGER.error("Unable to write data to pdf file : ", e);
|
|
|
312 |
} catch (Exception e) {
|
| 21901 |
ashik.ali |
313 |
// TODO Auto-generated catch block
|
|
|
314 |
e.printStackTrace();
|
|
|
315 |
}
|
| 21686 |
ashik.ali |
316 |
}
|
| 23509 |
amit.gupta |
317 |
|
|
|
318 |
public static void generateAndWriteDebitNote(List<DebitNotePdfModel> debitNotePdfModels,
|
|
|
319 |
OutputStream outputStream) {
|
|
|
320 |
Document document = new Document();
|
|
|
321 |
document.setMargins(0, 0, 25, 0);
|
|
|
322 |
try {
|
|
|
323 |
for (DebitNotePdfModel debitNotePdfModel : debitNotePdfModels) {
|
|
|
324 |
|
|
|
325 |
PdfModel pdfModel = debitNotePdfModel.getPdfModel();
|
|
|
326 |
CustomCustomer customer = pdfModel.getCustomer();
|
|
|
327 |
CustomRetailer retailer = pdfModel.getRetailer();
|
|
|
328 |
boolean stateGst = false;
|
|
|
329 |
String customerAddressStateCode = "", retailerAddressStateCode = "";
|
|
|
330 |
if (customer.getAddress().getState().equals(retailer.getAddress().getState())) {
|
|
|
331 |
stateGst = true;
|
|
|
332 |
customerAddressStateCode = Utils.getStateCode(customer.getAddress().getState());
|
| 23549 |
amit.gupta |
333 |
retailerAddressStateCode = customerAddressStateCode;
|
| 23509 |
amit.gupta |
334 |
} else {
|
|
|
335 |
customerAddressStateCode = Utils.getStateCode(customer.getAddress().getState());
|
|
|
336 |
retailerAddressStateCode = Utils.getStateCode(retailer.getAddress().getState());
|
|
|
337 |
}
|
|
|
338 |
Set<CustomOrderItem> orderItems = pdfModel.getOrderItems();
|
|
|
339 |
|
|
|
340 |
PdfWriter.getInstance(document, outputStream);
|
|
|
341 |
|
|
|
342 |
document.open();
|
|
|
343 |
document.addTitle(pdfModel.getTitle());
|
|
|
344 |
document.addAuthor(pdfModel.getAuther());
|
|
|
345 |
|
| 23532 |
amit.gupta |
346 |
Paragraph paragraphTitle = new Paragraph(DEBIT_NOTE_TITLE, FONT_TITLE);
|
| 23509 |
amit.gupta |
347 |
paragraphTitle.setAlignment(Element.ALIGN_CENTER);
|
|
|
348 |
|
|
|
349 |
PdfPCell blankCell = new PdfPCell();
|
|
|
350 |
blankCell.setBorder(Rectangle.NO_BORDER);
|
|
|
351 |
PdfPTable tableCustomerRetailer = new PdfPTable(3);
|
| 23533 |
amit.gupta |
352 |
tableCustomerRetailer.setWidthPercentage(95);
|
| 23532 |
amit.gupta |
353 |
PdfPCell partnerInfo = new PdfPCell();
|
| 23549 |
amit.gupta |
354 |
partnerInfo.addElement(new Paragraph("From Party:", FONT_BOLD));
|
|
|
355 |
partnerInfo.addElement(new Paragraph(StringUtils.capitalize(customer.getAddress().getName()), FONT_NORMAL));
|
|
|
356 |
partnerInfo.addElement(new Paragraph(StringUtils.capitalize(customer.getAddress().getLine1()) + ", "
|
|
|
357 |
+ (customer.getAddress().getLine2() == null ? "" : StringUtils.capitalize(customer.getAddress().getLine2()))
|
|
|
358 |
+ ", " + customer.getAddress().getCity()
|
|
|
359 |
+ " - "+ customer.getAddress().getPinCode(), FONT_NORMAL));
|
| 23539 |
amit.gupta |
360 |
|
| 23549 |
amit.gupta |
361 |
partnerInfo.addElement(new Paragraph(StringUtils.capitalize(customer.getAddress().getState())
|
|
|
362 |
+ "("+ customerAddressStateCode + ")", FONT_NORMAL));
|
| 23532 |
amit.gupta |
363 |
partnerInfo.addElement(new Paragraph("Mobile - " + customer.getMobileNumber(), FONT_NORMAL));
|
| 23509 |
amit.gupta |
364 |
if (customer.getGstNumber() != null && !customer.getGstNumber().isEmpty()) {
|
| 23549 |
amit.gupta |
365 |
partnerInfo.addElement(new Paragraph("GST No - " + customer.getGstNumber(), FONT_BOLD));
|
| 23509 |
amit.gupta |
366 |
}
|
| 23533 |
amit.gupta |
367 |
|
| 23532 |
amit.gupta |
368 |
PdfPCell sellerParty = new PdfPCell();
|
| 23549 |
amit.gupta |
369 |
sellerParty.addElement(new Paragraph("To Party:", FONT_BOLD));
|
|
|
370 |
sellerParty.addElement(new Paragraph(StringUtils.capitalize(retailer.getAddress().getName()), FONT_NORMAL));
|
| 23532 |
amit.gupta |
371 |
sellerParty.addElement(new Paragraph(
|
| 23533 |
amit.gupta |
372 |
(retailer.getAddress().getLine1() == null ? ""
|
|
|
373 |
: StringUtils.capitalize(retailer.getAddress().getLine1()) + ", ")
|
|
|
374 |
+ (retailer.getAddress().getLine2() == null ? ""
|
|
|
375 |
: StringUtils.capitalize(retailer.getAddress().getLine2()) + ", ")
|
|
|
376 |
+ StringUtils.capitalize(retailer.getAddress().getCity()) + "-"
|
| 23549 |
amit.gupta |
377 |
+ retailer.getAddress().getPinCode() + ", ", FONT_NORMAL));
|
|
|
378 |
sellerParty.addElement(new Paragraph(retailer.getAddress().getState() + "(" + retailerAddressStateCode + ")", FONT_NORMAL));
|
|
|
379 |
sellerParty.addElement(new Paragraph("Mobile - " + retailer.getAddress().getPhoneNumber(), FONT_NORMAL));
|
|
|
380 |
sellerParty.addElement(new Paragraph("GST No - " + retailer.getGstNumber(), FONT_BOLD));
|
| 23509 |
amit.gupta |
381 |
|
|
|
382 |
PdfPTable tableInvoiceDateRetailer = new PdfPTable(1);
|
|
|
383 |
tableInvoiceDateRetailer.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
|
|
384 |
|
|
|
385 |
PdfPTable tableInvoiceDate = new PdfPTable(2);
|
|
|
386 |
tableInvoiceDate.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
| 23533 |
amit.gupta |
387 |
tableInvoiceDate.setWidthPercentage(90);
|
| 23509 |
amit.gupta |
388 |
|
| 23533 |
amit.gupta |
389 |
PdfPCell debitNoteDetails = new PdfPCell(new Paragraph("Debit Note Details", FONT_BOLD));
|
|
|
390 |
debitNoteDetails.setColspan(2);
|
|
|
391 |
debitNoteDetails.setBorder(Rectangle.NO_BORDER);
|
|
|
392 |
|
| 23532 |
amit.gupta |
393 |
PdfPCell debitNoteNumberKey = new PdfPCell(new Paragraph("Debit Note No:", FONT_NORMAL));
|
|
|
394 |
debitNoteNumberKey.setBorder(Rectangle.NO_BORDER);
|
|
|
395 |
PdfPCell debitNoteNumberValue = new PdfPCell(new Paragraph(debitNotePdfModel.getDebitNoteNumber(), FONT_NORMAL));
|
|
|
396 |
debitNoteNumberValue.setBorder(Rectangle.NO_BORDER);
|
|
|
397 |
|
|
|
398 |
PdfPCell debitNoteDateKey = new PdfPCell(new Paragraph("Debit Note Dt:", FONT_NORMAL));
|
|
|
399 |
debitNoteDateKey.setBorder(Rectangle.NO_BORDER);
|
| 23533 |
amit.gupta |
400 |
|
|
|
401 |
PdfPCell debitNoteDateValue = new PdfPCell(
|
|
|
402 |
new Paragraph(debitNotePdfModel.getDebitNoteDate(), FONT_NORMAL));
|
| 23532 |
amit.gupta |
403 |
debitNoteDateValue.setBorder(Rectangle.NO_BORDER);
|
|
|
404 |
|
| 23539 |
amit.gupta |
405 |
PdfPCell invoiceNumberKey = new PdfPCell(new Paragraph("Invoice Ref No:", FONT_NORMAL));
|
| 23509 |
amit.gupta |
406 |
invoiceNumberKey.setBorder(Rectangle.NO_BORDER);
|
|
|
407 |
PdfPCell invoiceNumberValue = new PdfPCell(new Paragraph(pdfModel.getInvoiceNumber(), FONT_NORMAL));
|
|
|
408 |
invoiceNumberValue.setBorder(Rectangle.NO_BORDER);
|
|
|
409 |
|
| 23532 |
amit.gupta |
410 |
PdfPCell dateKey = new PdfPCell(new Paragraph("Invoice Dt:", FONT_NORMAL));
|
| 23509 |
amit.gupta |
411 |
dateKey.setBorder(Rectangle.NO_BORDER);
|
| 23549 |
amit.gupta |
412 |
PdfPCell dateValue = new PdfPCell(new Paragraph(pdfModel.getInvoiceDate(), FONT_NORMAL));
|
| 23509 |
amit.gupta |
413 |
dateValue.setBorder(Rectangle.NO_BORDER);
|
| 23533 |
amit.gupta |
414 |
|
|
|
415 |
tableInvoiceDate.addCell(debitNoteDetails);
|
| 23532 |
amit.gupta |
416 |
tableInvoiceDate.addCell(debitNoteNumberKey);
|
|
|
417 |
tableInvoiceDate.addCell(debitNoteNumberValue);
|
|
|
418 |
tableInvoiceDate.addCell(debitNoteDateKey);
|
|
|
419 |
tableInvoiceDate.addCell(debitNoteDateValue);
|
| 23509 |
amit.gupta |
420 |
tableInvoiceDate.addCell(invoiceNumberKey);
|
|
|
421 |
tableInvoiceDate.addCell(invoiceNumberValue);
|
|
|
422 |
tableInvoiceDate.addCell(dateKey);
|
|
|
423 |
tableInvoiceDate.addCell(dateValue);
|
|
|
424 |
|
| 23532 |
amit.gupta |
425 |
tableCustomerRetailer.addCell(partnerInfo);
|
| 23533 |
amit.gupta |
426 |
tableCustomerRetailer.addCell(tableInvoiceDate);
|
|
|
427 |
tableCustomerRetailer.addCell(sellerParty);
|
| 23509 |
amit.gupta |
428 |
|
|
|
429 |
PdfPTable orders = null;
|
|
|
430 |
if (stateGst) {
|
| 23532 |
amit.gupta |
431 |
orders = new PdfPTable(stateWidths.length);
|
|
|
432 |
orders.setWidths(stateWidths);
|
| 23509 |
amit.gupta |
433 |
} else {
|
| 23532 |
amit.gupta |
434 |
orders = new PdfPTable(igstWidths.length);
|
|
|
435 |
orders.setWidths(igstWidths);
|
| 23509 |
amit.gupta |
436 |
}
|
| 23549 |
amit.gupta |
437 |
orders.setWidthPercentage(95);
|
| 23542 |
amit.gupta |
438 |
orders.addCell(new Paragraph("Order Id", FONT_BOLD));
|
| 23509 |
amit.gupta |
439 |
orders.addCell(new Paragraph("Description", FONT_BOLD));
|
|
|
440 |
orders.addCell(new Paragraph("HSN", FONT_BOLD));
|
|
|
441 |
orders.addCell(new Paragraph("Qty", FONT_BOLD));
|
|
|
442 |
orders.addCell(new Paragraph("Rate\n(Per pc)", FONT_BOLD));
|
|
|
443 |
orders.addCell(new Paragraph("Total\nTaxable", FONT_BOLD));
|
|
|
444 |
if (!stateGst) {
|
|
|
445 |
orders.addCell(new Paragraph("IGST\n%", FONT_BOLD));
|
|
|
446 |
orders.addCell(new Paragraph("IGST", FONT_BOLD));
|
|
|
447 |
// orders.setWidths(new float[]{1, 3, 1, 1, 1, 1, 1, 1});
|
|
|
448 |
// total 8f
|
|
|
449 |
} else {
|
|
|
450 |
orders.addCell(new Paragraph("CGST %", FONT_BOLD));
|
|
|
451 |
orders.addCell(new Paragraph("CGST", FONT_BOLD));
|
|
|
452 |
orders.addCell(new Paragraph("SGST %", FONT_BOLD));
|
|
|
453 |
orders.addCell(new Paragraph("SGST", FONT_BOLD));
|
|
|
454 |
// orders.setWidths(new float[]{1, 3, 1, 1, 1, 1, 1, 1, 1,
|
|
|
455 |
// 1});
|
|
|
456 |
// total 8f
|
|
|
457 |
}
|
|
|
458 |
orders.addCell(new Paragraph("Total", FONT_BOLD));
|
|
|
459 |
|
|
|
460 |
orders.setHeaderRows(1);
|
|
|
461 |
|
|
|
462 |
float igstTotalAmount = 0, cgstTotalAmount = 0, sgstTotalAmount = 0;
|
|
|
463 |
for (CustomOrderItem orderItem : orderItems) {
|
| 23542 |
amit.gupta |
464 |
orders.addCell(new Paragraph(String.valueOf(orderItem.getOrderId()), FONT_NORMAL));
|
| 23509 |
amit.gupta |
465 |
orders.addCell(new Paragraph(orderItem.getDescription(), FONT_NORMAL));
|
|
|
466 |
orders.addCell(new Paragraph(orderItem.getHsnCode(), FONT_NORMAL));
|
|
|
467 |
orders.addCell(new Paragraph(String.valueOf(orderItem.getQuantity()), FONT_NORMAL));
|
|
|
468 |
orders.addCell(new Paragraph(String.format("%.2f", orderItem.getRate()), FONT_NORMAL));
|
|
|
469 |
orders.addCell(new Paragraph(String.format("%.2f", orderItem.getAmount()), FONT_NORMAL));
|
|
|
470 |
if (!stateGst) {
|
|
|
471 |
orders.addCell(new Paragraph(String.format("%.2f", orderItem.getIgstRate()), FONT_NORMAL));
|
|
|
472 |
orders.addCell(new Paragraph(String.format("%.2f", orderItem.getIgstAmount()), FONT_NORMAL));
|
|
|
473 |
igstTotalAmount = igstTotalAmount + orderItem.getIgstAmount();
|
|
|
474 |
} else {
|
|
|
475 |
orders.addCell(new Paragraph(String.format("%.2f", orderItem.getCgstRate()), FONT_NORMAL));
|
|
|
476 |
orders.addCell(new Paragraph(String.format("%.2f", orderItem.getCgstAmount()), FONT_NORMAL));
|
|
|
477 |
orders.addCell(new Paragraph(String.format("%.2f", orderItem.getSgstRate()), FONT_NORMAL));
|
|
|
478 |
orders.addCell(new Paragraph(String.format("%.2f", orderItem.getSgstAmount()), FONT_NORMAL));
|
|
|
479 |
cgstTotalAmount = cgstTotalAmount + orderItem.getCgstAmount();
|
|
|
480 |
sgstTotalAmount = sgstTotalAmount + orderItem.getSgstAmount();
|
|
|
481 |
}
|
|
|
482 |
orders.addCell(new Paragraph(String.format("%.0f", orderItem.getNetAmount()), FONT_NORMAL));
|
| 23533 |
amit.gupta |
483 |
LOGGER.info("IN FOR LOOP");
|
| 23509 |
amit.gupta |
484 |
}
|
|
|
485 |
|
|
|
486 |
document.add(paragraphTitle);
|
| 23533 |
amit.gupta |
487 |
|
| 23509 |
amit.gupta |
488 |
document.add(Chunk.NEWLINE);
|
|
|
489 |
document.add(tableCustomerRetailer);
|
|
|
490 |
|
|
|
491 |
document.add(Chunk.NEWLINE);
|
|
|
492 |
document.add(orders);
|
|
|
493 |
|
|
|
494 |
PdfPTable grandTotalTable = new PdfPTable(3);
|
|
|
495 |
if (stateGst) {
|
|
|
496 |
grandTotalTable.setWidths(new float[] { 6.6f, .6f, .8f });
|
|
|
497 |
} else {
|
|
|
498 |
grandTotalTable.setWidths(new float[] { 6.5f, .6f, .9f });
|
|
|
499 |
}
|
| 23549 |
amit.gupta |
500 |
grandTotalTable.setWidthPercentage(95);
|
| 23509 |
amit.gupta |
501 |
|
|
|
502 |
Paragraph grandTotalParagraph = new Paragraph("Grand total", FONT_BOLD);
|
|
|
503 |
grandTotalParagraph.setIndentationRight(20);
|
|
|
504 |
grandTotalTable.addCell(grandTotalParagraph);
|
|
|
505 |
Paragraph rsParagraph = new Paragraph("Rs.", FONT_BOLD);
|
|
|
506 |
grandTotalTable.addCell(rsParagraph);
|
|
|
507 |
Paragraph amountParagraph = new Paragraph(String.format("%.2f", pdfModel.getTotalAmount()), FONT_BOLD);
|
|
|
508 |
grandTotalTable.addCell(amountParagraph);
|
|
|
509 |
|
|
|
510 |
document.add(grandTotalTable);
|
|
|
511 |
|
|
|
512 |
PdfPTable amountInWordsTable = new PdfPTable(3);
|
|
|
513 |
if (!stateGst) {
|
|
|
514 |
amountInWordsTable.setWidths(new float[] { 2, 5.1f, 0.9f });
|
|
|
515 |
} else {
|
|
|
516 |
amountInWordsTable.setWidths(new float[] { 2, 5.2f, 0.8f });
|
|
|
517 |
}
|
| 23549 |
amit.gupta |
518 |
amountInWordsTable.setWidthPercentage(95);
|
| 23509 |
amit.gupta |
519 |
amountInWordsTable.addCell(new Paragraph("Amount in Words:", FONT_BOLD));
|
|
|
520 |
|
|
|
521 |
String amountInWords = toAmountInWords(pdfModel.getTotalAmount());
|
|
|
522 |
amountInWordsTable.addCell(new Paragraph(amountInWords.toString(), FONT_BOLD));
|
|
|
523 |
amountInWordsTable.addCell(new Paragraph("E & O.E", FONT_NORMAL));
|
|
|
524 |
document.add(amountInWordsTable);
|
|
|
525 |
|
|
|
526 |
document.newPage();
|
|
|
527 |
}
|
|
|
528 |
document.close(); // no need to close PDFwriter?
|
|
|
529 |
} catch (DocumentException e) {
|
|
|
530 |
LOGGER.error("Unable to write data to pdf file : ", e);
|
|
|
531 |
} catch (Exception e) {
|
|
|
532 |
// TODO Auto-generated catch block
|
|
|
533 |
e.printStackTrace();
|
|
|
534 |
}
|
| 21915 |
ashik.ali |
535 |
}
|
| 23509 |
amit.gupta |
536 |
|
|
|
537 |
private static String toAmountInWords(float amount) {
|
|
|
538 |
RuleBasedNumberFormat amountInWordsFormat = new RuleBasedNumberFormat(indianLocale,
|
|
|
539 |
RuleBasedNumberFormat.SPELLOUT);
|
|
|
540 |
StringBuilder amountInWords = new StringBuilder("Rs. ");
|
|
|
541 |
amountInWords.append(StringUtils.capitalize(amountInWordsFormat.format((int) amount)));
|
|
|
542 |
amountInWords.append(" and ");
|
|
|
543 |
amountInWords.append(StringUtils.capitalize(amountInWordsFormat.format((int) (amount * 100) % 100)));
|
|
|
544 |
amountInWords.append(" paise");
|
|
|
545 |
return amountInWords.toString();
|
|
|
546 |
}
|
| 21686 |
ashik.ali |
547 |
}
|