| Line 1... |
Line 1... |
| 1 |
package com.spice.profitmandi.common.util;
|
1 |
package com.spice.profitmandi.common.util;
|
| 2 |
|
2 |
|
| 3 |
|
3 |
|
| 4 |
import java.io.OutputStream;
|
4 |
import java.io.OutputStream;
|
| - |
|
5 |
|
| 5 |
import java.time.LocalDateTime;
|
6 |
import java.time.LocalDateTime;
|
| - |
|
7 |
import java.util.Locale;
|
| 6 |
import java.util.Set;
|
8 |
import java.util.Set;
|
| 7 |
|
9 |
|
| 8 |
import org.slf4j.Logger;
|
10 |
import org.slf4j.Logger;
|
| 9 |
import org.slf4j.LoggerFactory;
|
11 |
import org.slf4j.LoggerFactory;
|
| 10 |
|
12 |
|
| - |
|
13 |
import com.ibm.icu.text.RuleBasedNumberFormat;
|
| 11 |
import com.itextpdf.text.Chunk;
|
14 |
import com.itextpdf.text.Chunk;
|
| 12 |
import com.itextpdf.text.Document;
|
15 |
import com.itextpdf.text.Document;
|
| 13 |
import com.itextpdf.text.DocumentException;
|
16 |
import com.itextpdf.text.DocumentException;
|
| 14 |
import com.itextpdf.text.Element;
|
17 |
import com.itextpdf.text.Element;
|
| 15 |
import com.itextpdf.text.Font;
|
18 |
import com.itextpdf.text.Font;
|
| Line 20... |
Line 23... |
| 20 |
import com.itextpdf.text.pdf.PdfWriter;
|
23 |
import com.itextpdf.text.pdf.PdfWriter;
|
| 21 |
import com.spice.profitmandi.common.model.CustomCustomer;
|
24 |
import com.spice.profitmandi.common.model.CustomCustomer;
|
| 22 |
import com.spice.profitmandi.common.model.CustomFofoOrderItem;
|
25 |
import com.spice.profitmandi.common.model.CustomFofoOrderItem;
|
| 23 |
import com.spice.profitmandi.common.model.CustomRetailer;
|
26 |
import com.spice.profitmandi.common.model.CustomRetailer;
|
| 24 |
import com.spice.profitmandi.common.model.PdfModel;
|
27 |
import com.spice.profitmandi.common.model.PdfModel;
|
| 25 |
|
- |
|
| - |
|
28 |
import org.apache.commons.lang3.text.*;
|
| 26 |
|
29 |
|
| 27 |
public class PdfUtils {
|
30 |
public class PdfUtils {
|
| 28 |
|
31 |
|
| 29 |
private static final Font FONT_TITLE = new Font(Font.FontFamily.HELVETICA , 18, Font.BOLD);
|
32 |
private static final Font FONT_TITLE = new Font(Font.FontFamily.HELVETICA , 18, Font.BOLD);
|
| 30 |
private static Font FONT_NORMAL = new Font(Font.FontFamily.TIMES_ROMAN, 8, Font.NORMAL);
|
33 |
private static Font FONT_NORMAL = new Font(Font.FontFamily.TIMES_ROMAN, 8, Font.NORMAL);
|
| 31 |
private static Font FONT_BOLD = new Font(Font.FontFamily.TIMES_ROMAN, 8, Font.BOLD);
|
34 |
private static Font FONT_BOLD = new Font(Font.FontFamily.TIMES_ROMAN, 8, Font.BOLD);
|
| 32 |
//private static Font fontTableHeader = new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.BOLD);
|
35 |
//private static Font fontTableHeader = new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.BOLD);
|
| 33 |
private static final String INVOICE_TITLE = "RETAILER_INVOICE";
|
36 |
private static final String INVOICE_TITLE = "RETAILER_INVOICE";
|
| 34 |
|
37 |
|
| - |
|
38 |
private static final Locale indianLocale = Locale.getDefault();
|
| - |
|
39 |
|
| 35 |
private static final Logger LOGGER = LoggerFactory.getLogger(PdfUtils.class);
|
40 |
private static final Logger LOGGER = LoggerFactory.getLogger(PdfUtils.class);
|
| 36 |
|
41 |
|
| 37 |
public static void generateAndWrite(PdfModel pdfModel, OutputStream outputStream){
|
42 |
public static void generateAndWrite(PdfModel pdfModel, OutputStream outputStream){
|
| 38 |
Document document = new Document();
|
43 |
Document document = new Document();
|
| 39 |
|
44 |
|
| Line 72... |
Line 77... |
| 72 |
columnCustomerInfo.setBorder(Rectangle.NO_BORDER);
|
77 |
columnCustomerInfo.setBorder(Rectangle.NO_BORDER);
|
| 73 |
PdfPCell columnRetailerInfo = new PdfPCell();
|
78 |
PdfPCell columnRetailerInfo = new PdfPCell();
|
| 74 |
//columnRetailerInfo.addElement(new Paragraph("Invoice No:"));
|
79 |
//columnRetailerInfo.addElement(new Paragraph("Invoice No:"));
|
| 75 |
columnRetailerInfo.addElement(new Paragraph(retailer.getBusinessName(), FONT_BOLD));
|
80 |
columnRetailerInfo.addElement(new Paragraph(retailer.getBusinessName(), FONT_BOLD));
|
| 76 |
// columnRetailerInfo.addElement(new Paragraph("Plot No. 485, Udyog Vihar Phase V, Gurgoan-122016", FONT_BOLD));
|
81 |
// columnRetailerInfo.addElement(new Paragraph("Plot No. 485, Udyog Vihar Phase V, Gurgoan-122016", FONT_BOLD));
|
| 77 |
columnRetailerInfo.addElement(new Paragraph(retailer.getAddress().getLine1() + ", " + retailer.getAddress().getLine2() + ", " + retailer.getAddress().getCity() + "-" + retailer.getAddress().getPinCode() + ", " + retailer.getAddress().getState() + "(" + retailerAddressStateCode + ")", FONT_BOLD));
|
82 |
columnRetailerInfo.addElement(new Paragraph(retailer.getAddress().getLine1() + ", " + retailer.getAddress().getLine2() + ", " + retailer.getAddress().getCity() + "-" + retailer.getAddress().getPinCode() + ", " + retailer.getAddress().getState() + "(" + (gstWithInState? customerAddressStateCode : retailerAddressStateCode) + ")", FONT_BOLD));
|
| 78 |
columnRetailerInfo.addElement(new Paragraph("Contact No.- "+retailer.getMobileNumber(), FONT_BOLD));
|
83 |
columnRetailerInfo.addElement(new Paragraph("Contact No.- "+retailer.getMobileNumber(), FONT_BOLD));
|
| 79 |
columnRetailerInfo.addElement(new Paragraph("TIN NO. " + retailer.getTinNumber(), FONT_BOLD));
|
84 |
columnRetailerInfo.addElement(new Paragraph("TIN NO. " + retailer.getTinNumber(), FONT_BOLD));
|
| 80 |
columnRetailerInfo.setBorder(Rectangle.NO_BORDER);
|
85 |
columnRetailerInfo.setBorder(Rectangle.NO_BORDER);
|
| 81 |
PdfPTable tableInvoiceDateRetailer = new PdfPTable(1);
|
86 |
PdfPTable tableInvoiceDateRetailer = new PdfPTable(1);
|
| 82 |
tableInvoiceDateRetailer.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
87 |
tableInvoiceDateRetailer.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
| Line 105... |
Line 110... |
| 105 |
tableCustomerRetailer.addCell(blankCell);
|
110 |
tableCustomerRetailer.addCell(blankCell);
|
| 106 |
tableCustomerRetailer.addCell(tableInvoiceDateRetailer);
|
111 |
tableCustomerRetailer.addCell(tableInvoiceDateRetailer);
|
| 107 |
|
112 |
|
| 108 |
PdfPTable orders = null;
|
113 |
PdfPTable orders = null;
|
| 109 |
if(gstWithInState){
|
114 |
if(gstWithInState){
|
| 110 |
orders = new PdfPTable(9);
|
115 |
orders = new PdfPTable(8);
|
| 111 |
}else{
|
116 |
}else{
|
| 112 |
orders = new PdfPTable(11);
|
117 |
orders = new PdfPTable(10);
|
| 113 |
}
|
118 |
}
|
| 114 |
//PdfPCell orderDetail = new PdfPCell(new Paragraph("Order Details:"));
|
119 |
//PdfPCell orderDetail = new PdfPCell(new Paragraph("Order Details:"));
|
| 115 |
/*PdfPTable ordersTable = new PdfPTable(8);
|
120 |
/*PdfPTable ordersTable = new PdfPTable(8);
|
| 116 |
PdfPCell srNo = new PdfPCell(new Paragraph("Sr No"));
|
121 |
PdfPCell srNo = new PdfPCell(new Paragraph("Sr No"));
|
| 117 |
PdfPCell description = new PdfPCell(new Paragraph("Description"));
|
122 |
PdfPCell description = new PdfPCell(new Paragraph("Description"));
|
| Line 136... |
Line 141... |
| 136 |
orders.addCell(new Paragraph("Rate (Rs)", FONT_BOLD));
|
141 |
orders.addCell(new Paragraph("Rate (Rs)", FONT_BOLD));
|
| 137 |
orders.addCell(new Paragraph("Amount (Rs)", FONT_BOLD));
|
142 |
orders.addCell(new Paragraph("Amount (Rs)", FONT_BOLD));
|
| 138 |
if(gstWithInState){
|
143 |
if(gstWithInState){
|
| 139 |
orders.addCell(new Paragraph("IGST Rate%", FONT_BOLD));
|
144 |
orders.addCell(new Paragraph("IGST Rate%", FONT_BOLD));
|
| 140 |
orders.addCell(new Paragraph("IGST Amount", FONT_BOLD));
|
145 |
orders.addCell(new Paragraph("IGST Amount", FONT_BOLD));
|
| 141 |
orders.setWidths(new int[]{1, 3, 1, 1, 1, 1, 1, 1, 1});
|
146 |
orders.setWidths(new int[]{1, 3, 1, 1, 1, 1, 1, 1});
|
| 142 |
}else{
|
147 |
}else{
|
| 143 |
orders.addCell(new Paragraph("CGST Rate%", FONT_BOLD));
|
148 |
orders.addCell(new Paragraph("CGST Rate%", FONT_BOLD));
|
| 144 |
orders.addCell(new Paragraph("CGST Amount", FONT_BOLD));
|
149 |
orders.addCell(new Paragraph("CGST Amount", FONT_BOLD));
|
| 145 |
orders.addCell(new Paragraph("SGST Rate%", FONT_BOLD));
|
150 |
orders.addCell(new Paragraph("SGST Rate%", FONT_BOLD));
|
| 146 |
orders.addCell(new Paragraph("SGST Amount", FONT_BOLD));
|
151 |
orders.addCell(new Paragraph("SGST Amount", FONT_BOLD));
|
| 147 |
orders.setWidths(new int[]{1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1});
|
152 |
orders.setWidths(new int[]{1, 3, 1, 1, 1, 1, 1, 1, 1, 1});
|
| 148 |
}
|
153 |
}
|
| 149 |
|
154 |
|
| 150 |
//orders.addCell(new Paragraph("Item Total (Rs)", FONT_BOLD));
|
155 |
//orders.addCell(new Paragraph("Item Total (Rs)", FONT_BOLD));
|
| 151 |
|
156 |
|
| 152 |
orders.setHeaderRows(1);
|
157 |
orders.setHeaderRows(1);
|
| Line 158... |
Line 163... |
| 158 |
orders.addCell(new Paragraph(orderItem.getDescription(), FONT_NORMAL));
|
163 |
orders.addCell(new Paragraph(orderItem.getDescription(), FONT_NORMAL));
|
| 159 |
orders.addCell(new Paragraph(orderItem.getHsnCode(), FONT_NORMAL));
|
164 |
orders.addCell(new Paragraph(orderItem.getHsnCode(), FONT_NORMAL));
|
| 160 |
orders.addCell(new Paragraph(String.valueOf(orderItem.getQuantity()), FONT_NORMAL));
|
165 |
orders.addCell(new Paragraph(String.valueOf(orderItem.getQuantity()), FONT_NORMAL));
|
| 161 |
orders.addCell(new Paragraph(String.valueOf(orderItem.getRate()), FONT_NORMAL));
|
166 |
orders.addCell(new Paragraph(String.valueOf(orderItem.getRate()), FONT_NORMAL));
|
| 162 |
orders.addCell(new Paragraph(String.valueOf(orderItem.getAmount()), FONT_NORMAL));
|
167 |
orders.addCell(new Paragraph(String.valueOf(orderItem.getAmount()), FONT_NORMAL));
|
| 163 |
float totalTaxRate = orderItem.getIgstRate() + orderItem.getSgstRate() + orderItem.getCgstRate();
|
- |
|
| 164 |
float taxableAmount = pdfModel.getTotalAmount() / (1 + (totalTaxRate / 100));
|
- |
|
| 165 |
if(gstWithInState){
|
168 |
if(gstWithInState){
|
| 166 |
float igstAmount = (taxableAmount * orderItem.getIgstRate()) / 100;
|
- |
|
| 167 |
orders.addCell(new Paragraph(String.valueOf(orderItem.getIgstRate()), FONT_NORMAL));
|
169 |
orders.addCell(new Paragraph(String.valueOf(orderItem.getIgstRate()), FONT_NORMAL));
|
| 168 |
orders.addCell(new Paragraph(String.valueOf(igstAmount), FONT_NORMAL));
|
170 |
orders.addCell(new Paragraph(String.valueOf(orderItem.getIgstAmount()), FONT_NORMAL));
|
| 169 |
}else{
|
171 |
}else{
|
| 170 |
float cgstAmount = (taxableAmount * orderItem.getCgstRate()) / 100;
|
- |
|
| 171 |
float sgstAmount = (taxableAmount * orderItem.getSgstRate()) / 100;
|
- |
|
| 172 |
orders.addCell(new Paragraph(String.valueOf(orderItem.getCgstRate()), FONT_NORMAL));
|
172 |
orders.addCell(new Paragraph(String.valueOf(orderItem.getCgstRate()), FONT_NORMAL));
|
| 173 |
orders.addCell(new Paragraph(String.valueOf(cgstAmount), FONT_NORMAL));
|
173 |
orders.addCell(new Paragraph(String.valueOf(orderItem.getCgstAmount()), FONT_NORMAL));
|
| 174 |
orders.addCell(new Paragraph(String.valueOf(orderItem.getSgstRate()), FONT_NORMAL));
|
174 |
orders.addCell(new Paragraph(String.valueOf(orderItem.getSgstRate()), FONT_NORMAL));
|
| 175 |
orders.addCell(new Paragraph(String.valueOf(sgstAmount), FONT_NORMAL));
|
175 |
orders.addCell(new Paragraph(String.valueOf(orderItem.getSgstAmount()), FONT_NORMAL));
|
| 176 |
}
|
176 |
}
|
| 177 |
orders.addCell(new Paragraph(String.valueOf(orderItem.getItemTotal()), FONT_NORMAL));
|
177 |
orders.addCell(new Paragraph(String.valueOf(orderItem.getItemTotal()), FONT_NORMAL));
|
| 178 |
}
|
178 |
}
|
| 179 |
//orders.addCell("1");
|
179 |
//orders.addCell("1");
|
| 180 |
//orders.addCell("Sansui X71Activ Ta2s");
|
180 |
//orders.addCell("Sansui X71Activ Ta2s");
|
| Line 218... |
Line 218... |
| 218 |
document.add(grandTotalTable);
|
218 |
document.add(grandTotalTable);
|
| 219 |
|
219 |
|
| 220 |
PdfPTable amountInWordsTable = new PdfPTable(3);
|
220 |
PdfPTable amountInWordsTable = new PdfPTable(3);
|
| 221 |
amountInWordsTable.setWidths(new int[]{1, 6, 3});
|
221 |
amountInWordsTable.setWidths(new int[]{1, 6, 3});
|
| 222 |
amountInWordsTable.addCell(new Paragraph("Amount in Words:", FONT_BOLD));
|
222 |
amountInWordsTable.addCell(new Paragraph("Amount in Words:", FONT_BOLD));
|
| - |
|
223 |
|
| - |
|
224 |
String amountInWords = toAmountInWords(pdfModel.getTotalAmount());
|
| 223 |
amountInWordsTable.addCell(new Paragraph("Rs. Four Thousand Nine Hundred Sixty-five and Zero paise", FONT_BOLD));
|
225 |
amountInWordsTable.addCell(new Paragraph(amountInWords.toString(), FONT_BOLD));
|
| 224 |
amountInWordsTable.addCell(new Paragraph("E & O.E", FONT_NORMAL));
|
226 |
amountInWordsTable.addCell(new Paragraph("E & O.E", FONT_NORMAL));
|
| 225 |
document.add(amountInWordsTable);
|
227 |
document.add(amountInWordsTable);
|
| 226 |
|
228 |
|
| 227 |
Paragraph warningParagraph = new Paragraph("Goods once sold will not be taken back.\nAll Disputes subject to "+pdfModel.getRetailer().getAddress().getState()+" Jurisdiction.\nThis is a Computer Generated Invoice.", FONT_NORMAL);
|
229 |
Paragraph warningParagraph = new Paragraph("Goods once sold will not be taken back.\nAll Disputes subject to "+pdfModel.getRetailer().getAddress().getState()+" Jurisdiction.\nThis is a Computer Generated Invoice.", FONT_NORMAL);
|
| 228 |
warningParagraph.setIndentationLeft(50);
|
230 |
warningParagraph.setIndentationLeft(50);
|
| 229 |
document.add(Chunk.NEWLINE);
|
231 |
document.add(Chunk.NEWLINE);
|
| 230 |
document.add(warningParagraph);
|
232 |
document.add(warningParagraph);
|
| Line 249... |
Line 251... |
| 249 |
} catch (Exception e) {
|
251 |
} catch (Exception e) {
|
| 250 |
// TODO Auto-generated catch block
|
252 |
// TODO Auto-generated catch block
|
| 251 |
e.printStackTrace();
|
253 |
e.printStackTrace();
|
| 252 |
}
|
254 |
}
|
| 253 |
}
|
255 |
}
|
| - |
|
256 |
|
| - |
|
257 |
@SuppressWarnings("deprecation")
|
| - |
|
258 |
private static String toAmountInWords(float amount){
|
| - |
|
259 |
RuleBasedNumberFormat amountInWordsFormat = new RuleBasedNumberFormat(indianLocale, RuleBasedNumberFormat.SPELLOUT);
|
| - |
|
260 |
StringBuilder amountInWords = new StringBuilder("Rs. ");
|
| - |
|
261 |
amountInWords.append(WordUtils.capitalize(amountInWordsFormat.format((int)amount)));
|
| - |
|
262 |
amountInWords.append(" and ");
|
| - |
|
263 |
amountInWords.append(WordUtils.capitalize(amountInWordsFormat.format((int)(amount*100)%100)));
|
| - |
|
264 |
amountInWords.append(" paise");
|
| - |
|
265 |
return amountInWords.toString();
|
| - |
|
266 |
}
|
| 254 |
}
|
267 |
}
|