| Line 39... |
Line 39... |
| 39 |
import javax.servlet.ServletOutputStream;
|
39 |
import javax.servlet.ServletOutputStream;
|
| 40 |
import javax.servlet.http.HttpServlet;
|
40 |
import javax.servlet.http.HttpServlet;
|
| 41 |
import javax.servlet.http.HttpServletRequest;
|
41 |
import javax.servlet.http.HttpServletRequest;
|
| 42 |
import javax.servlet.http.HttpServletResponse;
|
42 |
import javax.servlet.http.HttpServletResponse;
|
| 43 |
|
43 |
|
| - |
|
44 |
import org.apache.commons.lang.StringUtils;
|
| 44 |
import org.apache.commons.lang.WordUtils;
|
45 |
import org.apache.commons.lang.WordUtils;
|
| 45 |
import org.apache.thrift.TException;
|
46 |
import org.apache.thrift.TException;
|
| 46 |
import org.slf4j.Logger;
|
47 |
import org.slf4j.Logger;
|
| 47 |
import org.slf4j.LoggerFactory;
|
48 |
import org.slf4j.LoggerFactory;
|
| 48 |
|
49 |
|
| Line 64... |
Line 65... |
| 64 |
import com.itextpdf.text.pdf.PdfWriter;
|
65 |
import com.itextpdf.text.pdf.PdfWriter;
|
| 65 |
import com.itextpdf.text.pdf.draw.DottedLineSeparator;
|
66 |
import com.itextpdf.text.pdf.draw.DottedLineSeparator;
|
| 66 |
|
67 |
|
| 67 |
@SuppressWarnings("serial")
|
68 |
@SuppressWarnings("serial")
|
| 68 |
public class InvoiceServlet extends HttpServlet {
|
69 |
public class InvoiceServlet extends HttpServlet {
|
| 69 |
|
70 |
|
| 70 |
private static Logger logger = LoggerFactory.getLogger(InvoiceServlet.class);
|
71 |
private static Logger logger = LoggerFactory.getLogger(InvoiceServlet.class);
|
| 71 |
|
72 |
|
| 72 |
@Override
|
73 |
@Override
|
| 73 |
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
74 |
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
| 74 |
long orderId = Long.parseLong(request.getParameter("id"));
|
75 |
long orderId = Long.parseLong(request.getParameter("id"));
|
| 75 |
long warehouseId = Long.parseLong(request.getParameter("warehouse"));
|
76 |
long warehouseId = Long.parseLong(request.getParameter("warehouse"));
|
| 76 |
boolean withBill = false;
|
77 |
boolean withBill = false;
|
| 77 |
boolean printAll = false;
|
78 |
boolean printAll = false;
|
| 78 |
try {
|
79 |
try {
|
| 79 |
withBill = Boolean.parseBoolean(request.getParameter("withBill"));
|
80 |
withBill = Boolean.parseBoolean(request.getParameter("withBill"));
|
| 80 |
} catch(Exception e){
|
81 |
} catch(Exception e){
|
| 81 |
logger.warn("Couldn't infer whether bill should be printed. Not printing the bill.", e);
|
82 |
logger.warn("Couldn't infer whether bill should be printed. Not printing the bill.", e);
|
| 82 |
}
|
83 |
}
|
| 83 |
try {
|
84 |
try {
|
| 84 |
printAll = Boolean.parseBoolean(request.getParameter("printAll"));
|
85 |
printAll = Boolean.parseBoolean(request.getParameter("printAll"));
|
| 85 |
} catch(Exception e){
|
86 |
} catch(Exception e){
|
| 86 |
logger.warn("Couldn't infer whether bill should be printed. Not printing the bill.", e);
|
87 |
logger.warn("Couldn't infer whether bill should be printed. Not printing the bill.", e);
|
| 87 |
}
|
88 |
}
|
| 88 |
|
89 |
|
| 89 |
logger.info("Printing invoice for order id: " + orderId);
|
90 |
logger.info("Printing invoice for order id: " + orderId);
|
| 90 |
|
91 |
|
| 91 |
InvoiceGenerationService invoiceGenerationService = new InvoiceGenerationService();
|
92 |
InvoiceGenerationService invoiceGenerationService = new InvoiceGenerationService();
|
| 92 |
ByteArrayOutputStream baos = invoiceGenerationService.generateInvoice(orderId, withBill, printAll, warehouseId);
|
93 |
ByteArrayOutputStream baos = invoiceGenerationService.generateInvoice(orderId, withBill, printAll, warehouseId);
|
| 93 |
response.setContentType("application/pdf");
|
94 |
response.setContentType("application/pdf");
|
| 94 |
response.setHeader("Content-disposition", "inline; filename=invoice-"+orderId+".pdf" );
|
95 |
response.setHeader("Content-disposition", "inline; filename=invoice-"+orderId+".pdf" );
|
| 95 |
|
96 |
|
| 96 |
ServletOutputStream sos;
|
97 |
ServletOutputStream sos;
|
| 97 |
try {
|
98 |
try {
|
| 98 |
sos = response.getOutputStream();
|
99 |
sos = response.getOutputStream();
|
| 99 |
baos.writeTo(sos);
|
100 |
baos.writeTo(sos);
|
| 100 |
sos.flush();
|
101 |
sos.flush();
|
| 101 |
} catch (IOException e) {
|
102 |
} catch (IOException e) {
|
| 102 |
logger.error("Encountered error while sending invoice response: ", e);
|
103 |
logger.error("Encountered error while sending invoice response: ", e);
|
| 103 |
}
|
104 |
}
|
| 104 |
}
|
105 |
}
|
| 105 |
}
|
106 |
}
|
| 106 |
|
107 |
|
| 107 |
class InvoiceGenerationService {
|
108 |
class InvoiceGenerationService {
|
| 108 |
|
109 |
|
| 109 |
private static Logger logger = LoggerFactory.getLogger(InvoiceGenerationService.class);
|
110 |
private static Logger logger = LoggerFactory.getLogger(InvoiceGenerationService.class);
|
| 110 |
|
111 |
|
| 111 |
private TransactionClient tsc = null;
|
112 |
private TransactionClient tsc = null;
|
| 112 |
private InventoryClient csc = null;
|
113 |
private InventoryClient csc = null;
|
| 113 |
private LogisticsClient lsc = null;
|
114 |
private LogisticsClient lsc = null;
|
| 114 |
|
115 |
|
| 115 |
private static Locale indianLocale = new Locale("en", "IN");
|
116 |
private static Locale indianLocale = new Locale("en", "IN");
|
| 116 |
private DecimalFormat amountFormat = new DecimalFormat("#,##0.00");
|
117 |
private DecimalFormat amountFormat = new DecimalFormat("#,##0.00");
|
| 117 |
|
118 |
|
| 118 |
private static final Font helvetica8 = FontFactory.getFont(FontFactory.HELVETICA, 8);
|
119 |
private static final Font helvetica8 = FontFactory.getFont(FontFactory.HELVETICA, 8);
|
| 119 |
private static final Font helvetica10 = FontFactory.getFont(FontFactory.HELVETICA, 10);
|
120 |
private static final Font helvetica10 = FontFactory.getFont(FontFactory.HELVETICA, 10);
|
| 120 |
private static final Font helvetica12 = FontFactory.getFont(FontFactory.HELVETICA, 12);
|
121 |
private static final Font helvetica12 = FontFactory.getFont(FontFactory.HELVETICA, 12);
|
| 121 |
private static final Font helvetica16 = FontFactory.getFont(FontFactory.HELVETICA, 16);
|
122 |
private static final Font helvetica16 = FontFactory.getFont(FontFactory.HELVETICA, 16);
|
| 122 |
private static final Font helvetica28 = FontFactory.getFont(FontFactory.HELVETICA, 28);
|
123 |
private static final Font helvetica28 = FontFactory.getFont(FontFactory.HELVETICA, 28);
|
| 123 |
|
124 |
|
| 124 |
private static final Font helveticaBold8 = FontFactory.getFont(FontFactory.HELVETICA_BOLD, 8);
|
125 |
private static final Font helveticaBold8 = FontFactory.getFont(FontFactory.HELVETICA_BOLD, 8);
|
| 125 |
private static final Font helveticaBold12 = FontFactory.getFont(FontFactory.HELVETICA_BOLD, 12);
|
126 |
private static final Font helveticaBold12 = FontFactory.getFont(FontFactory.HELVETICA_BOLD, 12);
|
| 126 |
|
127 |
|
| 127 |
private static final Properties properties = readProperties();
|
128 |
private static final Properties properties = readProperties();
|
| 128 |
private static final String ourAddress = properties.getProperty("sales_tax_address",
|
129 |
private static final String ourAddress = properties.getProperty("sales_tax_address",
|
| 129 |
"Spice Online Retail Pvt. Ltd.\nKhasra No. 819, Block-K\nMahipalpur, New Delhi-110037\n");
|
130 |
"Spice Online Retail Pvt. Ltd.\nKhasra No. 819, Block-K\nMahipalpur, New Delhi-110037\n");
|
| 130 |
private static final String tinNo = properties.getProperty("sales_tax_tin", "07250399732");
|
131 |
private static final String tinNo = properties.getProperty("sales_tax_tin", "07250399732");
|
| 131 |
|
132 |
|
| 132 |
private static final String delhiPincodePrefix = "11";
|
133 |
private static final String delhiPincodePrefix = "11";
|
| 133 |
|
134 |
|
| 134 |
private static Properties readProperties(){
|
135 |
private static Properties readProperties(){
|
| 135 |
ResourceBundle resource = ResourceBundle.getBundle(InvoiceGenerationService.class.getName());
|
136 |
ResourceBundle resource = ResourceBundle.getBundle(InvoiceGenerationService.class.getName());
|
| 136 |
Properties props = new Properties();
|
137 |
Properties props = new Properties();
|
| 137 |
|
138 |
|
| 138 |
Enumeration<String> keys = resource.getKeys();
|
139 |
Enumeration<String> keys = resource.getKeys();
|
| 139 |
while (keys.hasMoreElements()) {
|
140 |
while (keys.hasMoreElements()) {
|
| 140 |
String key = keys.nextElement();
|
141 |
String key = keys.nextElement();
|
| 141 |
props.put(key, resource.getString(key));
|
142 |
props.put(key, resource.getString(key));
|
| 142 |
}
|
143 |
}
|
| 143 |
return props;
|
144 |
return props;
|
| 144 |
}
|
145 |
}
|
| 145 |
|
146 |
|
| 146 |
public InvoiceGenerationService() {
|
147 |
public InvoiceGenerationService() {
|
| 147 |
try {
|
148 |
try {
|
| 148 |
tsc = new TransactionClient();
|
149 |
tsc = new TransactionClient();
|
| 149 |
csc = new InventoryClient();
|
150 |
csc = new InventoryClient();
|
| 150 |
lsc = new LogisticsClient();
|
151 |
lsc = new LogisticsClient();
|
| 151 |
} catch (Exception e) {
|
152 |
} catch (Exception e) {
|
| 152 |
logger.error("Error while instantiating thrift clients.", e);
|
153 |
logger.error("Error while instantiating thrift clients.", e);
|
| 153 |
}
|
154 |
}
|
| 154 |
}
|
155 |
}
|
| 155 |
|
156 |
|
| 156 |
public ByteArrayOutputStream generateInvoice(long orderId, boolean withBill, boolean printAll, long warehouseId) {
|
157 |
public ByteArrayOutputStream generateInvoice(long orderId, boolean withBill, boolean printAll, long warehouseId) {
|
| 157 |
ByteArrayOutputStream baosPDF = null;
|
158 |
ByteArrayOutputStream baosPDF = null;
|
| 158 |
in.shop2020.model.v1.order.TransactionService.Client tclient = tsc.getClient();
|
159 |
in.shop2020.model.v1.order.TransactionService.Client tclient = tsc.getClient();
|
| 159 |
in.shop2020.model.v1.inventory.InventoryService.Client iclient = csc.getClient();
|
160 |
in.shop2020.model.v1.inventory.InventoryService.Client iclient = csc.getClient();
|
| 160 |
in.shop2020.logistics.LogisticsService.Client logisticsClient = lsc.getClient();
|
161 |
in.shop2020.logistics.LogisticsService.Client logisticsClient = lsc.getClient();
|
| 161 |
|
162 |
|
| 162 |
|
163 |
|
| 163 |
try {
|
164 |
try {
|
| 164 |
baosPDF = new ByteArrayOutputStream();
|
165 |
baosPDF = new ByteArrayOutputStream();
|
| 165 |
|
166 |
|
| 166 |
Document document = new Document();
|
167 |
Document document = new Document();
|
| 167 |
PdfWriter.getInstance(document, baosPDF);
|
168 |
PdfWriter.getInstance(document, baosPDF);
|
| 168 |
document.addAuthor("shop2020");
|
169 |
document.addAuthor("shop2020");
|
| 169 |
//document.addTitle("Invoice No: " + order.getInvoice_number());
|
170 |
//document.addTitle("Invoice No: " + order.getInvoice_number());
|
| 170 |
document.open();
|
171 |
document.open();
|
| 171 |
|
172 |
|
| 172 |
List<Order> orders = new ArrayList<Order>();
|
173 |
List<Order> orders = new ArrayList<Order>();
|
| 173 |
if(printAll){
|
174 |
if(printAll){
|
| 174 |
try {
|
175 |
try {
|
| 175 |
List<OrderStatus> statuses = new ArrayList<OrderStatus>();
|
176 |
List<OrderStatus> statuses = new ArrayList<OrderStatus>();
|
| 176 |
statuses.add(OrderStatus.ACCEPTED);
|
177 |
statuses.add(OrderStatus.ACCEPTED);
|
| 177 |
orders = tclient.getAllOrders(statuses, 0, 0, warehouseId);
|
178 |
orders = tclient.getAllOrders(statuses, 0, 0, warehouseId);
|
| 178 |
} catch (Exception e) {
|
179 |
} catch (Exception e) {
|
| 179 |
logger.error("Error while getting order information", e);
|
180 |
logger.error("Error while getting order information", e);
|
| 180 |
return baosPDF;
|
181 |
return baosPDF;
|
| 181 |
}
|
182 |
}
|
| 182 |
}else{
|
183 |
}else{
|
| 183 |
orders.add(tclient.getOrder(orderId));
|
184 |
orders.add(tclient.getOrder(orderId));
|
| 184 |
}
|
185 |
}
|
| 185 |
boolean isFirst = true;
|
186 |
boolean isFirst = true;
|
| 186 |
|
187 |
|
| 187 |
for(Order order: orders){
|
188 |
for(Order order: orders){
|
| 188 |
Warehouse warehouse = null;
|
189 |
Warehouse warehouse = null;
|
| 189 |
Provider provider = null;
|
190 |
Provider provider = null;
|
| 190 |
String destCode = null;
|
191 |
String destCode = null;
|
| 191 |
int barcodeFontSize = 0;
|
192 |
int barcodeFontSize = 0;
|
| 192 |
try {
|
193 |
try {
|
| 193 |
warehouse = iclient.getWarehouse(order.getWarehouse_id());
|
194 |
warehouse = iclient.getWarehouse(order.getWarehouse_id());
|
| 194 |
long providerId = order.getLogistics_provider_id();
|
195 |
long providerId = order.getLogistics_provider_id();
|
| 195 |
provider = logisticsClient.getProvider(providerId);
|
196 |
provider = logisticsClient.getProvider(providerId);
|
| 196 |
if(provider.getPickup().equals(PickUpType.SELF) || provider.getPickup().equals(PickUpType.RUNNER))
|
197 |
if(provider.getPickup().equals(PickUpType.SELF) || provider.getPickup().equals(PickUpType.RUNNER))
|
| 197 |
destCode = provider.getPickup().toString();
|
198 |
destCode = provider.getPickup().toString();
|
| 198 |
else
|
199 |
else
|
| 199 |
destCode = logisticsClient.getDestinationCode(providerId, order.getCustomer_pincode());
|
200 |
destCode = logisticsClient.getDestinationCode(providerId, order.getCustomer_pincode());
|
| 200 |
|
201 |
|
| 201 |
barcodeFontSize = Integer.parseInt(ConfigClient.getClient().get(provider.getName().toLowerCase() + "_barcode_fontsize"));
|
202 |
barcodeFontSize = Integer.parseInt(ConfigClient.getClient().get(provider.getName().toLowerCase() + "_barcode_fontsize"));
|
| 202 |
} catch (InventoryServiceException ise) {
|
203 |
} catch (InventoryServiceException ise) {
|
| 203 |
logger.error("Error while getting the warehouse information.", ise);
|
204 |
logger.error("Error while getting the warehouse information.", ise);
|
| 204 |
return baosPDF;
|
205 |
return baosPDF;
|
| 205 |
} catch (LogisticsServiceException lse) {
|
206 |
} catch (LogisticsServiceException lse) {
|
| 206 |
logger.error("Error while getting the provider information.", lse);
|
207 |
logger.error("Error while getting the provider information.", lse);
|
| 207 |
return baosPDF;
|
208 |
return baosPDF;
|
| 208 |
} catch (ConfigException ce) {
|
209 |
} catch (ConfigException ce) {
|
| 209 |
logger.error("Error while getting the fontsize for the given provider", ce);
|
210 |
logger.error("Error while getting the fontsize for the given provider", ce);
|
| 210 |
return baosPDF;
|
211 |
return baosPDF;
|
| 211 |
} catch (TException te) {
|
212 |
} catch (TException te) {
|
| 212 |
logger.error("Error while getting some essential information from the services", te);
|
213 |
logger.error("Error while getting some essential information from the services", te);
|
| 213 |
return baosPDF;
|
214 |
return baosPDF;
|
| 214 |
}
|
215 |
}
|
| 215 |
|
216 |
|
| 216 |
if(printAll && warehouse.getBillingType() == BillingType.OURS_EXTERNAL){
|
217 |
if(printAll && warehouse.getBillingType() == BillingType.OURS_EXTERNAL){
|
| 217 |
if(isFirst){
|
218 |
if(isFirst){
|
| 218 |
document.add(getFixedTextTable(16, "Spice Online Retail Pvt Ltd"));
|
219 |
document.add(getFixedTextTable(16, "Spice Online Retail Pvt Ltd"));
|
| 219 |
isFirst = false;
|
220 |
isFirst = false;
|
| 220 |
}
|
221 |
}
|
| 221 |
document.add(getExtraInfoTable(order, provider, 16, warehouse.getBillingType()));
|
222 |
document.add(getExtraInfoTable(order, provider, 16, warehouse.getBillingType()));
|
| 222 |
continue;
|
223 |
continue;
|
| 223 |
}
|
224 |
}
|
| 224 |
|
225 |
|
| 225 |
PdfPTable dispatchAdviceTable = getDispatchAdviceTable(order, warehouse, provider, barcodeFontSize, destCode, withBill);
|
226 |
PdfPTable dispatchAdviceTable = getDispatchAdviceTable(order, warehouse, provider, barcodeFontSize, destCode, withBill);
|
| 226 |
dispatchAdviceTable.setSpacingAfter(10.0f);
|
227 |
dispatchAdviceTable.setSpacingAfter(10.0f);
|
| 227 |
dispatchAdviceTable.setWidthPercentage(90.0f);
|
228 |
dispatchAdviceTable.setWidthPercentage(90.0f);
|
| 228 |
|
229 |
|
| 229 |
document.add(dispatchAdviceTable);
|
230 |
document.add(dispatchAdviceTable);
|
| 230 |
if(withBill){
|
231 |
if(withBill){
|
| 231 |
PdfPTable taxTable = getTaxCumRetailInvoiceTable(order, provider);
|
232 |
PdfPTable taxTable = getTaxCumRetailInvoiceTable(order, provider);
|
| 232 |
taxTable.setSpacingBefore(5.0f);
|
233 |
taxTable.setSpacingBefore(5.0f);
|
| 233 |
taxTable.setWidthPercentage(90.0f);
|
234 |
taxTable.setWidthPercentage(90.0f);
|
| 234 |
document.add(new DottedLineSeparator());
|
235 |
document.add(new DottedLineSeparator());
|
| 235 |
document.add(taxTable);
|
236 |
document.add(taxTable);
|
| 236 |
}else{
|
237 |
}else{
|
| 237 |
PdfPTable extraInfoTable = getExtraInfoTable(order, provider, 16, warehouse.getBillingType());
|
238 |
PdfPTable extraInfoTable = getExtraInfoTable(order, provider, 16, warehouse.getBillingType());
|
| 238 |
extraInfoTable.setSpacingBefore(5.0f);
|
239 |
extraInfoTable.setSpacingBefore(5.0f);
|
| 239 |
extraInfoTable.setWidthPercentage(90.0f);
|
240 |
extraInfoTable.setWidthPercentage(90.0f);
|
| 240 |
document.add(new DottedLineSeparator());
|
241 |
document.add(new DottedLineSeparator());
|
| 241 |
document.add(extraInfoTable);
|
242 |
document.add(extraInfoTable);
|
| 242 |
}
|
243 |
}
|
| 243 |
document.newPage();
|
244 |
document.newPage();
|
| 244 |
}
|
245 |
}
|
| 245 |
document.close();
|
246 |
document.close();
|
| 246 |
baosPDF.close();
|
247 |
baosPDF.close();
|
| 247 |
// Adding facility to store the bill on the local directory. This will happen for only for Mahipalpur warehouse.
|
248 |
// Adding facility to store the bill on the local directory. This will happen for only for Mahipalpur warehouse.
|
| 248 |
if(withBill && !printAll){
|
249 |
if(withBill && !printAll){
|
| 249 |
Calendar cal = new GregorianCalendar();
|
250 |
String strOrderId = StringUtils.repeat("0", 10-String.valueOf(orderId).length());
|
| 250 |
cal.setTimeInMillis(orders.get(0).getBilling_timestamp());
|
251 |
String dirPath = "/SaholicInvoices" + File.separator + strOrderId.substring(0, 2) + File.separator + strOrderId.substring(2, 4) + File.separator + strOrderId.substring(4, 6);
|
| 251 |
int year = cal.get(Calendar.YEAR);
|
252 |
String filename = dirPath + File.separator + orderId + ".pdf";
|
| 252 |
int month = cal.get(Calendar.MONTH);
|
253 |
File dirFile = new File(dirPath);
|
| 253 |
int day = cal.get(Calendar.DAY_OF_MONTH);
|
254 |
if(!dirFile.exists()){
|
| 254 |
String dirPath = "/SaholicInvoices" + File.separator + year + File.separator + month + File.separator + day;
|
255 |
dirFile.mkdirs();
|
| 255 |
File dirFile = new File(dirPath);
|
256 |
}
|
| 256 |
if(!dirFile.exists()){
|
257 |
File f = new File(filename);
|
| 257 |
dirFile.mkdirs();
|
258 |
FileOutputStream fos = new FileOutputStream(f);
|
| 258 |
}
|
259 |
baosPDF.writeTo(fos);
|
| 259 |
File f = new File( dirPath + File.separator + orderId + ".pdf");
|
260 |
}
|
| 260 |
FileOutputStream fos = new FileOutputStream(f);
|
261 |
} catch (Exception e) {
|
| 261 |
baosPDF.writeTo(fos);
|
262 |
logger.error("Error while generating Invoice: ", e);
|
| 262 |
}
|
263 |
}
|
| 263 |
} catch (Exception e) {
|
264 |
return baosPDF;
|
| 264 |
logger.error("Error while generating Invoice: ", e);
|
265 |
}
|
| 265 |
}
|
266 |
|
| 266 |
return baosPDF;
|
267 |
private PdfPTable getDispatchAdviceTable(Order order, Warehouse warehouse, Provider provider, float barcodeFontSize, String destCode, boolean withBill){
|
| 267 |
}
|
268 |
Font barCodeFont = getBarCodeFont(provider, barcodeFontSize);
|
| 268 |
|
269 |
|
| 269 |
private PdfPTable getDispatchAdviceTable(Order order, Warehouse warehouse, Provider provider, float barcodeFontSize, String destCode, boolean withBill){
|
270 |
PdfPTable table = new PdfPTable(1);
|
| 270 |
Font barCodeFont = getBarCodeFont(provider, barcodeFontSize);
|
271 |
table.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
| 271 |
|
272 |
|
| 272 |
PdfPTable table = new PdfPTable(1);
|
273 |
PdfPTable logoTable = new PdfPTable(2);
|
| 273 |
table.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
274 |
logoTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
| 274 |
|
275 |
logoTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT);
|
| 275 |
PdfPTable logoTable = new PdfPTable(2);
|
276 |
logoTable.getDefaultCell().setVerticalAlignment(Element.ALIGN_BOTTOM);
|
| 276 |
logoTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
277 |
logoTable.addCell(getLogoCell());
|
| 277 |
logoTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT);
|
278 |
if(order.isLogisticsCod())
|
| 278 |
logoTable.getDefaultCell().setVerticalAlignment(Element.ALIGN_BOTTOM);
|
279 |
logoTable.addCell(new Phrase("COD ", helvetica28));
|
| 279 |
logoTable.addCell(getLogoCell());
|
280 |
else
|
| 280 |
if(order.isLogisticsCod())
|
281 |
logoTable.addCell(new Phrase(" ", helvetica28));
|
| 281 |
logoTable.addCell(new Phrase("COD ", helvetica28));
|
282 |
PdfPCell titleCell = getTitleCell();
|
| 282 |
else
|
283 |
PdfPTable customerTable = getCustomerAddressTable(order, destCode, false, helvetica12, false);
|
| 283 |
logoTable.addCell(new Phrase(" ", helvetica28));
|
284 |
PdfPTable providerInfoTable = getProviderTable(order, provider, barCodeFont);
|
| 284 |
PdfPCell titleCell = getTitleCell();
|
285 |
|
| 285 |
PdfPTable customerTable = getCustomerAddressTable(order, destCode, false, helvetica12, false);
|
286 |
PdfPTable dispatchTable = new PdfPTable(new float[]{0.5f, 0.1f, 0.4f});
|
| 286 |
PdfPTable providerInfoTable = getProviderTable(order, provider, barCodeFont);
|
287 |
dispatchTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
| 287 |
|
288 |
dispatchTable.addCell(customerTable);
|
| 288 |
PdfPTable dispatchTable = new PdfPTable(new float[]{0.5f, 0.1f, 0.4f});
|
289 |
dispatchTable.addCell(new Phrase(" "));
|
| 289 |
dispatchTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
290 |
dispatchTable.addCell(providerInfoTable);
|
| 290 |
dispatchTable.addCell(customerTable);
|
291 |
|
| 291 |
dispatchTable.addCell(new Phrase(" "));
|
292 |
Warehouse shippingLocation = CatalogUtils.getWarehouse(warehouse.getShippingWarehouseId());
|
| 292 |
dispatchTable.addCell(providerInfoTable);
|
293 |
PdfPTable invoiceTable = getTopInvoiceTable(order, shippingLocation.getTinNumber());
|
| 293 |
|
294 |
PdfPCell addressCell = getAddressCell(shippingLocation.getLocation() +
|
| 294 |
Warehouse shippingLocation = CatalogUtils.getWarehouse(warehouse.getShippingWarehouseId());
|
295 |
"\nPIN " + warehouse.getPincode() + "\n\n");
|
| 295 |
PdfPTable invoiceTable = getTopInvoiceTable(order, shippingLocation.getTinNumber());
|
296 |
|
| 296 |
PdfPCell addressCell = getAddressCell(shippingLocation.getLocation() +
|
297 |
PdfPTable chargesTable = new PdfPTable(1);
|
| 297 |
"\nPIN " + warehouse.getPincode() + "\n\n");
|
298 |
chargesTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
| 298 |
|
299 |
chargesTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
|
| 299 |
PdfPTable chargesTable = new PdfPTable(1);
|
300 |
if(order.isLogisticsCod()){
|
| 300 |
chargesTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
301 |
chargesTable.addCell(new Phrase("AMOUNT TO BE COLLECTED : Rs " + (order.getTotal_amount()-order.getGvAmount()), helveticaBold12));
|
| 301 |
chargesTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
|
302 |
chargesTable.addCell(new Phrase("RTO ADDRESS:DEL/HPW/111116"));
|
| 302 |
if(order.isLogisticsCod()){
|
303 |
} else {
|
| 303 |
chargesTable.addCell(new Phrase("AMOUNT TO BE COLLECTED : Rs " + (order.getTotal_amount()-order.getGvAmount()), helveticaBold12));
|
304 |
chargesTable.addCell(new Phrase("Do not pay any extra charges to the Courier."));
|
| 304 |
chargesTable.addCell(new Phrase("RTO ADDRESS:DEL/HPW/111116"));
|
305 |
}
|
| 305 |
} else {
|
306 |
|
| 306 |
chargesTable.addCell(new Phrase("Do not pay any extra charges to the Courier."));
|
307 |
PdfPTable addressAndNoteTable = new PdfPTable(new float[]{0.3f, 0.7f});
|
| 307 |
}
|
308 |
addressAndNoteTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
| 308 |
|
309 |
addressAndNoteTable.addCell(addressCell);
|
| 309 |
PdfPTable addressAndNoteTable = new PdfPTable(new float[]{0.3f, 0.7f});
|
310 |
addressAndNoteTable.addCell(chargesTable);
|
| 310 |
addressAndNoteTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
311 |
|
| 311 |
addressAndNoteTable.addCell(addressCell);
|
312 |
table.addCell(logoTable);
|
| 312 |
addressAndNoteTable.addCell(chargesTable);
|
313 |
table.addCell(titleCell);
|
| 313 |
|
314 |
table.addCell(dispatchTable);
|
| 314 |
table.addCell(logoTable);
|
315 |
table.addCell(invoiceTable);
|
| 315 |
table.addCell(titleCell);
|
316 |
table.addCell(new Phrase("If undelivered, return to:", helvetica10));
|
| 316 |
table.addCell(dispatchTable);
|
317 |
table.addCell(addressAndNoteTable);
|
| 317 |
table.addCell(invoiceTable);
|
318 |
return table;
|
| 318 |
table.addCell(new Phrase("If undelivered, return to:", helvetica10));
|
319 |
}
|
| 319 |
table.addCell(addressAndNoteTable);
|
320 |
|
| 320 |
return table;
|
321 |
private Font getBarCodeFont(Provider provider, float barcodeFontSize) {
|
| 321 |
}
|
322 |
String fontPath = InvoiceGenerationService.class.getResource("/" + provider.getName().toLowerCase() + "/barcode.TTF").getPath();
|
| 322 |
|
323 |
FontFactoryImp ttfFontFactory = new FontFactoryImp();
|
| 323 |
private Font getBarCodeFont(Provider provider, float barcodeFontSize) {
|
324 |
ttfFontFactory.register(fontPath, "barcode");
|
| 324 |
String fontPath = InvoiceGenerationService.class.getResource("/" + provider.getName().toLowerCase() + "/barcode.TTF").getPath();
|
325 |
Font barCodeFont = ttfFontFactory.getFont("barcode", BaseFont.CP1252, true, barcodeFontSize);
|
| 325 |
FontFactoryImp ttfFontFactory = new FontFactoryImp();
|
326 |
return barCodeFont;
|
| 326 |
ttfFontFactory.register(fontPath, "barcode");
|
327 |
}
|
| 327 |
Font barCodeFont = ttfFontFactory.getFont("barcode", BaseFont.CP1252, true, barcodeFontSize);
|
328 |
|
| 328 |
return barCodeFont;
|
329 |
private PdfPCell getLogoCell() {
|
| 329 |
}
|
330 |
String logoPath = InvoiceGenerationService.class.getResource("/logo.jpg").getPath();
|
| 330 |
|
331 |
PdfPCell logoCell;
|
| 331 |
private PdfPCell getLogoCell() {
|
332 |
try {
|
| 332 |
String logoPath = InvoiceGenerationService.class.getResource("/logo.jpg").getPath();
|
333 |
logoCell = new PdfPCell(Image.getInstance(logoPath), false);
|
| 333 |
PdfPCell logoCell;
|
334 |
} catch (Exception e) {
|
| 334 |
try {
|
335 |
//Too Many exceptions to catch here: BadElementException, MalformedURLException and IOException
|
| 335 |
logoCell = new PdfPCell(Image.getInstance(logoPath), false);
|
336 |
logger.warn("Couldn't load the Saholic logo: ", e);
|
| 336 |
} catch (Exception e) {
|
337 |
logoCell = new PdfPCell(new Phrase("Saholic Logo"));
|
| 337 |
//Too Many exceptions to catch here: BadElementException, MalformedURLException and IOException
|
338 |
}
|
| 338 |
logger.warn("Couldn't load the Saholic logo: ", e);
|
339 |
logoCell.setBorder(Rectangle.NO_BORDER);
|
| 339 |
logoCell = new PdfPCell(new Phrase("Saholic Logo"));
|
340 |
return logoCell;
|
| 340 |
}
|
341 |
}
|
| 341 |
logoCell.setBorder(Rectangle.NO_BORDER);
|
342 |
|
| 342 |
return logoCell;
|
343 |
private PdfPCell getTitleCell() {
|
| 343 |
}
|
344 |
PdfPCell titleCell = new PdfPCell(new Phrase("Dispatch Advice", helveticaBold12));
|
| 344 |
|
345 |
titleCell.setHorizontalAlignment(Element.ALIGN_CENTER);
|
| 345 |
private PdfPCell getTitleCell() {
|
346 |
titleCell.setBorder(Rectangle.NO_BORDER);
|
| 346 |
PdfPCell titleCell = new PdfPCell(new Phrase("Dispatch Advice", helveticaBold12));
|
347 |
return titleCell;
|
| 347 |
titleCell.setHorizontalAlignment(Element.ALIGN_CENTER);
|
348 |
}
|
| 348 |
titleCell.setBorder(Rectangle.NO_BORDER);
|
349 |
|
| 349 |
return titleCell;
|
350 |
private PdfPTable getProviderTable(Order order, Provider provider, Font barCodeFont) {
|
| 350 |
}
|
351 |
PdfPTable providerInfoTable = new PdfPTable(1);
|
| 351 |
|
352 |
providerInfoTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
| 352 |
private PdfPTable getProviderTable(Order order, Provider provider, Font barCodeFont) {
|
353 |
PdfPCell providerNameCell = new PdfPCell(new Phrase(provider.getName(), helveticaBold12));
|
| 353 |
PdfPTable providerInfoTable = new PdfPTable(1);
|
354 |
providerNameCell.setHorizontalAlignment(Element.ALIGN_LEFT);
|
| 354 |
providerInfoTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
355 |
providerNameCell.setBorder(Rectangle.NO_BORDER);
|
| 355 |
PdfPCell providerNameCell = new PdfPCell(new Phrase(provider.getName(), helveticaBold12));
|
356 |
|
| 356 |
providerNameCell.setHorizontalAlignment(Element.ALIGN_LEFT);
|
357 |
PdfPCell awbNumberCell = new PdfPCell(new Paragraph("*" + order.getAirwaybill_no() + "*", barCodeFont));
|
| 357 |
providerNameCell.setBorder(Rectangle.NO_BORDER);
|
358 |
awbNumberCell.setPaddingTop(20.0f);
|
| 358 |
|
359 |
awbNumberCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
|
| 359 |
PdfPCell awbNumberCell = new PdfPCell(new Paragraph("*" + order.getAirwaybill_no() + "*", barCodeFont));
|
360 |
awbNumberCell.setBorder(Rectangle.NO_BORDER);
|
| 360 |
awbNumberCell.setPaddingTop(20.0f);
|
361 |
|
| 361 |
awbNumberCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
|
362 |
providerInfoTable.addCell(providerNameCell);
|
| 362 |
awbNumberCell.setBorder(Rectangle.NO_BORDER);
|
363 |
providerInfoTable.addCell(awbNumberCell);
|
| 363 |
|
364 |
if(order.isLogisticsCod())
|
| 364 |
providerInfoTable.addCell(providerNameCell);
|
365 |
providerInfoTable.addCell(new Phrase("Account No : " + provider.getDetails().get(DeliveryType.COD).getAccountNo(), helvetica8));
|
| 365 |
providerInfoTable.addCell(awbNumberCell);
|
366 |
else
|
| 366 |
if(order.isLogisticsCod())
|
367 |
providerInfoTable.addCell(new Phrase("Account No : " + provider.getDetails().get(DeliveryType.PREPAID).getAccountNo(), helvetica8));
|
| 367 |
providerInfoTable.addCell(new Phrase("Account No : " + provider.getDetails().get(DeliveryType.COD).getAccountNo(), helvetica8));
|
368 |
Date awbDate;
|
| 368 |
else
|
369 |
if(order.getBilling_timestamp() == 0){
|
| 369 |
providerInfoTable.addCell(new Phrase("Account No : " + provider.getDetails().get(DeliveryType.PREPAID).getAccountNo(), helvetica8));
|
370 |
awbDate = new Date();
|
| 370 |
Date awbDate;
|
371 |
}else{
|
| 371 |
if(order.getBilling_timestamp() == 0){
|
372 |
awbDate = new Date(order.getBilling_timestamp());
|
| 372 |
awbDate = new Date();
|
373 |
}
|
| 373 |
}else{
|
374 |
providerInfoTable.addCell(new Phrase("AWB Date : " + DateFormat.getDateInstance(DateFormat.MEDIUM).format(awbDate), helvetica8));
|
| 374 |
awbDate = new Date(order.getBilling_timestamp());
|
375 |
providerInfoTable.addCell(new Phrase("Weight : " + order.getTotal_weight() + " Kg", helvetica8));
|
| 375 |
}
|
376 |
return providerInfoTable;
|
| 376 |
providerInfoTable.addCell(new Phrase("AWB Date : " + DateFormat.getDateInstance(DateFormat.MEDIUM).format(awbDate), helvetica8));
|
377 |
}
|
| 377 |
providerInfoTable.addCell(new Phrase("Weight : " + order.getTotal_weight() + " Kg", helvetica8));
|
378 |
|
| 378 |
return providerInfoTable;
|
379 |
private PdfPTable getTopInvoiceTable(Order order, String tinNo){
|
| 379 |
}
|
380 |
PdfPTable invoiceTable = new PdfPTable(new float[]{0.2f, 0.2f, 0.3f, 0.1f, 0.1f, 0.1f});
|
| 380 |
|
381 |
invoiceTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
|
| 381 |
private PdfPTable getTopInvoiceTable(Order order, String tinNo){
|
382 |
|
| 382 |
PdfPTable invoiceTable = new PdfPTable(new float[]{0.2f, 0.2f, 0.3f, 0.1f, 0.1f, 0.1f});
|
383 |
invoiceTable.addCell(getInvoiceTableHeader(6));
|
| 383 |
invoiceTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
|
384 |
|
| 384 |
|
385 |
invoiceTable.addCell(new Phrase("Order No", helvetica8));
|
| 385 |
invoiceTable.addCell(getInvoiceTableHeader(6));
|
386 |
invoiceTable.addCell(new Phrase("Paymode", helvetica8));
|
| 386 |
|
387 |
invoiceTable.addCell(new Phrase("Product Name", helvetica8));
|
| 387 |
invoiceTable.addCell(new Phrase("Order No", helvetica8));
|
388 |
invoiceTable.addCell(new Phrase("Quantity", helvetica8));
|
| 388 |
invoiceTable.addCell(new Phrase("Paymode", helvetica8));
|
389 |
invoiceTable.addCell(new Phrase("Rate", helvetica8));
|
| 389 |
invoiceTable.addCell(new Phrase("Product Name", helvetica8));
|
390 |
invoiceTable.addCell(new Phrase("Amount", helvetica8));
|
| 390 |
invoiceTable.addCell(new Phrase("Quantity", helvetica8));
|
391 |
populateTopInvoiceTable(order, invoiceTable);
|
| 391 |
invoiceTable.addCell(new Phrase("Rate", helvetica8));
|
392 |
|
| 392 |
invoiceTable.addCell(new Phrase("Amount", helvetica8));
|
393 |
|
| 393 |
populateTopInvoiceTable(order, invoiceTable);
|
394 |
if(order.getInsurer() > 0) {
|
| 394 |
|
395 |
invoiceTable.addCell(getInsuranceCell(4));
|
| 395 |
|
396 |
invoiceTable.addCell(getPriceCell(order.getInsuranceAmount()));
|
| 396 |
if(order.getInsurer() > 0) {
|
397 |
invoiceTable.addCell(getPriceCell(order.getInsuranceAmount()));
|
| 397 |
invoiceTable.addCell(getInsuranceCell(4));
|
398 |
}
|
| 398 |
invoiceTable.addCell(getPriceCell(order.getInsuranceAmount()));
|
399 |
|
| 399 |
invoiceTable.addCell(getPriceCell(order.getInsuranceAmount()));
|
400 |
invoiceTable.addCell(getTotalCell(4));
|
| 400 |
}
|
401 |
invoiceTable.addCell(getRupeesCell());
|
| 401 |
|
402 |
invoiceTable.addCell(getTotalAmountCell(order.getTotal_amount()-order.getGvAmount()));
|
| 402 |
invoiceTable.addCell(getTotalCell(4));
|
403 |
|
| 403 |
invoiceTable.addCell(getRupeesCell());
|
404 |
PdfPCell tinCell = new PdfPCell(new Phrase("TIN NO. " + tinNo, helvetica8));
|
| 404 |
invoiceTable.addCell(getTotalAmountCell(order.getTotal_amount()-order.getGvAmount()));
|
405 |
tinCell.setColspan(6);
|
| 405 |
|
406 |
tinCell.setPadding(2);
|
| 406 |
PdfPCell tinCell = new PdfPCell(new Phrase("TIN NO. " + tinNo, helvetica8));
|
407 |
invoiceTable.addCell(tinCell);
|
| 407 |
tinCell.setColspan(6);
|
408 |
|
| 408 |
tinCell.setPadding(2);
|
409 |
return invoiceTable;
|
| 409 |
invoiceTable.addCell(tinCell);
|
410 |
}
|
| 410 |
|
411 |
|
| 411 |
return invoiceTable;
|
412 |
private void populateTopInvoiceTable(Order order, PdfPTable invoiceTable) {
|
| 412 |
}
|
413 |
List<LineItem> lineitems = order.getLineitems();
|
| 413 |
|
414 |
for (LineItem lineitem : lineitems) {
|
| 414 |
private void populateTopInvoiceTable(Order order, PdfPTable invoiceTable) {
|
415 |
invoiceTable.addCell(new Phrase(order.getId() + "", helvetica8));
|
| 415 |
List<LineItem> lineitems = order.getLineitems();
|
416 |
if(order.getPickupStoreId() > 0 && order.isCod() == true)
|
| 416 |
for (LineItem lineitem : lineitems) {
|
417 |
invoiceTable.addCell(new Phrase("In-Store", helvetica8));
|
| 417 |
invoiceTable.addCell(new Phrase(order.getId() + "", helvetica8));
|
418 |
else if (order.isCod())
|
| 418 |
if(order.getPickupStoreId() > 0 && order.isCod() == true)
|
419 |
invoiceTable.addCell(new Phrase("COD", helvetica8));
|
| 419 |
invoiceTable.addCell(new Phrase("In-Store", helvetica8));
|
420 |
else
|
| 420 |
else if (order.isCod())
|
421 |
invoiceTable.addCell(new Phrase("Prepaid", helvetica8));
|
| 421 |
invoiceTable.addCell(new Phrase("COD", helvetica8));
|
422 |
/*
|
| 422 |
else
|
- |
|
| 423 |
invoiceTable.addCell(new Phrase("Prepaid", helvetica8));
|
- |
|
| 424 |
/*
|
- |
|
| 425 |
if(order.isLogisticsCod())
|
423 |
if(order.isLogisticsCod())
|
| 426 |
invoiceTable.addCell(new Phrase("COD", helvetica8));
|
424 |
invoiceTable.addCell(new Phrase("COD", helvetica8));
|
| 427 |
else
|
425 |
else
|
| 428 |
invoiceTable.addCell(new Phrase("Prepaid", helvetica8));
|
426 |
invoiceTable.addCell(new Phrase("Prepaid", helvetica8));
|
| 429 |
*/
|
427 |
*/
|
| 430 |
invoiceTable.addCell(getProductNameCell(lineitem, false));
|
428 |
invoiceTable.addCell(getProductNameCell(lineitem, false));
|
| 431 |
|
429 |
|
| 432 |
invoiceTable.addCell(new Phrase(lineitem.getQuantity() + "", helvetica8));
|
430 |
invoiceTable.addCell(new Phrase(lineitem.getQuantity() + "", helvetica8));
|
| 433 |
|
431 |
|
| 434 |
invoiceTable.addCell(getPriceCell(lineitem.getUnit_price()-order.getGvAmount()));
|
432 |
invoiceTable.addCell(getPriceCell(lineitem.getUnit_price()-order.getGvAmount()));
|
| 435 |
|
433 |
|
| 436 |
invoiceTable.addCell(getPriceCell(lineitem.getTotal_price()-order.getGvAmount()));
|
434 |
invoiceTable.addCell(getPriceCell(lineitem.getTotal_price()-order.getGvAmount()));
|
| 437 |
}
|
435 |
}
|
| 438 |
}
|
436 |
}
|
| 439 |
|
437 |
|
| 440 |
private PdfPCell getAddressCell(String address) {
|
438 |
private PdfPCell getAddressCell(String address) {
|
| 441 |
Paragraph addressParagraph = new Paragraph(address, new Font(FontFamily.TIMES_ROMAN, 8f));
|
439 |
Paragraph addressParagraph = new Paragraph(address, new Font(FontFamily.TIMES_ROMAN, 8f));
|
| 442 |
PdfPCell addressCell = new PdfPCell();
|
440 |
PdfPCell addressCell = new PdfPCell();
|
| 443 |
addressCell.addElement(addressParagraph);
|
441 |
addressCell.addElement(addressParagraph);
|
| 444 |
addressCell.setHorizontalAlignment(Element.ALIGN_LEFT);
|
442 |
addressCell.setHorizontalAlignment(Element.ALIGN_LEFT);
|
| 445 |
addressCell.setBorder(Rectangle.NO_BORDER);
|
443 |
addressCell.setBorder(Rectangle.NO_BORDER);
|
| 446 |
return addressCell;
|
444 |
return addressCell;
|
| 447 |
}
|
445 |
}
|
| 448 |
|
446 |
|
| 449 |
private PdfPTable getTaxCumRetailInvoiceTable(Order order, Provider provider){
|
447 |
private PdfPTable getTaxCumRetailInvoiceTable(Order order, Provider provider){
|
| 450 |
PdfPTable taxTable = new PdfPTable(1);
|
448 |
PdfPTable taxTable = new PdfPTable(1);
|
| 451 |
Phrase phrase = null;
|
449 |
Phrase phrase = null;
|
| 452 |
taxTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
450 |
taxTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
| 453 |
taxTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
|
451 |
taxTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
|
| 454 |
|
452 |
|
| 455 |
if (order.getOrderType().equals(OrderType.B2B)) {
|
453 |
if (order.getOrderType().equals(OrderType.B2B)) {
|
| 456 |
phrase = new Phrase("TAX INVOICE", helveticaBold12);
|
454 |
phrase = new Phrase("TAX INVOICE", helveticaBold12);
|
| 457 |
} else {
|
455 |
} else {
|
| 458 |
phrase = new Phrase("RETAIL INVOICE", helveticaBold12);
|
456 |
phrase = new Phrase("RETAIL INVOICE", helveticaBold12);
|
| 459 |
}
|
457 |
}
|
| 460 |
PdfPCell retailInvoiceTitleCell = new PdfPCell(phrase);
|
458 |
PdfPCell retailInvoiceTitleCell = new PdfPCell(phrase);
|
| 461 |
retailInvoiceTitleCell.setHorizontalAlignment(Element.ALIGN_CENTER);
|
459 |
retailInvoiceTitleCell.setHorizontalAlignment(Element.ALIGN_CENTER);
|
| 462 |
retailInvoiceTitleCell.setBorder(Rectangle.NO_BORDER);
|
460 |
retailInvoiceTitleCell.setBorder(Rectangle.NO_BORDER);
|
| 463 |
|
461 |
|
| 464 |
Paragraph sorlAddress = new Paragraph(ourAddress + "TIN NO. " + tinNo, new Font(FontFamily.TIMES_ROMAN, 8f, Element.ALIGN_CENTER));
|
462 |
Paragraph sorlAddress = new Paragraph(ourAddress + "TIN NO. " + tinNo, new Font(FontFamily.TIMES_ROMAN, 8f, Element.ALIGN_CENTER));
|
| 465 |
PdfPCell sorlAddressCell = new PdfPCell(sorlAddress);
|
463 |
PdfPCell sorlAddressCell = new PdfPCell(sorlAddress);
|
| 466 |
sorlAddressCell.addElement(sorlAddress);
|
464 |
sorlAddressCell.addElement(sorlAddress);
|
| 467 |
sorlAddressCell.setHorizontalAlignment(Element.ALIGN_CENTER);
|
465 |
sorlAddressCell.setHorizontalAlignment(Element.ALIGN_CENTER);
|
| 468 |
|
466 |
|
| 469 |
PdfPTable customerAddress = getCustomerAddressTable(order, null, true, helvetica8, true);
|
467 |
PdfPTable customerAddress = getCustomerAddressTable(order, null, true, helvetica8, true);
|
| 470 |
PdfPTable orderDetails = getOrderDetails(order, provider);
|
468 |
PdfPTable orderDetails = getOrderDetails(order, provider);
|
| 471 |
|
469 |
|
| 472 |
PdfPTable addrAndOrderDetailsTable = new PdfPTable(new float[]{0.5f, 0.1f, 0.4f});
|
470 |
PdfPTable addrAndOrderDetailsTable = new PdfPTable(new float[]{0.5f, 0.1f, 0.4f});
|
| 473 |
addrAndOrderDetailsTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
471 |
addrAndOrderDetailsTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
| 474 |
addrAndOrderDetailsTable.addCell(customerAddress);
|
472 |
addrAndOrderDetailsTable.addCell(customerAddress);
|
| 475 |
addrAndOrderDetailsTable.addCell(new Phrase(" "));
|
473 |
addrAndOrderDetailsTable.addCell(new Phrase(" "));
|
| 476 |
addrAndOrderDetailsTable.addCell(orderDetails);
|
474 |
addrAndOrderDetailsTable.addCell(orderDetails);
|
| 477 |
|
475 |
|
| 478 |
boolean isVAT = order.getCustomer_pincode().startsWith(delhiPincodePrefix);
|
476 |
boolean isVAT = order.getCustomer_pincode().startsWith(delhiPincodePrefix);
|
| 479 |
PdfPTable invoiceTable = getBottomInvoiceTable(order, isVAT);
|
477 |
PdfPTable invoiceTable = getBottomInvoiceTable(order, isVAT);
|
| 480 |
|
478 |
|
| 481 |
PdfPCell disclaimerCell = new PdfPCell(new Phrase("Goods once sold will not be taken back.\nAll disputes subject to Delhi Jurisdiction.\nThis is a Computer generated Invoice.", helvetica8));
|
479 |
PdfPCell disclaimerCell = new PdfPCell(new Phrase("Goods once sold will not be taken back.\nAll disputes subject to Delhi Jurisdiction.\nThis is a Computer generated Invoice.", helvetica8));
|
| 482 |
disclaimerCell.setHorizontalAlignment(Element.ALIGN_LEFT);
|
480 |
disclaimerCell.setHorizontalAlignment(Element.ALIGN_LEFT);
|
| 483 |
disclaimerCell.setBorder(Rectangle.NO_BORDER);
|
481 |
disclaimerCell.setBorder(Rectangle.NO_BORDER);
|
| 484 |
|
482 |
|
| 485 |
taxTable.addCell(retailInvoiceTitleCell);
|
483 |
taxTable.addCell(retailInvoiceTitleCell);
|
| 486 |
taxTable.addCell(sorlAddress);
|
484 |
taxTable.addCell(sorlAddress);
|
| 487 |
taxTable.addCell(addrAndOrderDetailsTable);
|
485 |
taxTable.addCell(addrAndOrderDetailsTable);
|
| 488 |
taxTable.addCell(invoiceTable);
|
486 |
taxTable.addCell(invoiceTable);
|
| 489 |
taxTable.addCell(disclaimerCell);
|
487 |
taxTable.addCell(disclaimerCell);
|
| 490 |
|
488 |
|
| 491 |
return taxTable;
|
489 |
return taxTable;
|
| 492 |
}
|
490 |
}
|
| 493 |
|
491 |
|
| 494 |
private PdfPTable getCustomerAddressTable(Order order, String destCode, boolean showPaymentMode, Font font, boolean forInvoce){
|
492 |
private PdfPTable getCustomerAddressTable(Order order, String destCode, boolean showPaymentMode, Font font, boolean forInvoce){
|
| 495 |
PdfPTable customerTable = new PdfPTable(1);
|
493 |
PdfPTable customerTable = new PdfPTable(1);
|
| 496 |
customerTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
494 |
customerTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
| 497 |
if(forInvoce || order.getPickupStoreId() == 0){
|
495 |
if(forInvoce || order.getPickupStoreId() == 0){
|
| 498 |
customerTable.addCell(new Phrase(order.getCustomer_name(), font));
|
496 |
customerTable.addCell(new Phrase(order.getCustomer_name(), font));
|
| 499 |
customerTable.addCell(new Phrase(order.getCustomer_address1(), font));
|
497 |
customerTable.addCell(new Phrase(order.getCustomer_address1(), font));
|
| 500 |
customerTable.addCell(new Phrase(order.getCustomer_address2(), font));
|
498 |
customerTable.addCell(new Phrase(order.getCustomer_address2(), font));
|
| 501 |
customerTable.addCell(new Phrase(order.getCustomer_city() + "," + order.getCustomer_state(), font));
|
499 |
customerTable.addCell(new Phrase(order.getCustomer_city() + "," + order.getCustomer_state(), font));
|
| 502 |
if(destCode != null)
|
500 |
if(destCode != null)
|
| 503 |
customerTable.addCell(new Phrase(order.getCustomer_pincode() + " - " + destCode, helvetica16));
|
501 |
customerTable.addCell(new Phrase(order.getCustomer_pincode() + " - " + destCode, helvetica16));
|
| 504 |
else
|
502 |
else
|
| 505 |
customerTable.addCell(new Phrase(order.getCustomer_pincode(), font));
|
503 |
customerTable.addCell(new Phrase(order.getCustomer_pincode(), font));
|
| 506 |
customerTable.addCell(new Phrase("Phone :" + order.getCustomer_mobilenumber(), font));
|
504 |
customerTable.addCell(new Phrase("Phone :" + order.getCustomer_mobilenumber(), font));
|
| 507 |
}else{
|
505 |
}else{
|
| 508 |
try {
|
506 |
try {
|
| 509 |
in.shop2020.logistics.LogisticsService.Client lclient = (new LogisticsClient()).getClient();
|
507 |
in.shop2020.logistics.LogisticsService.Client lclient = (new LogisticsClient()).getClient();
|
| 510 |
PickupStore store = lclient.getPickupStore(order.getPickupStoreId());
|
508 |
PickupStore store = lclient.getPickupStore(order.getPickupStoreId());
|
| 511 |
customerTable.addCell(new Phrase(order.getCustomer_name() + " \nc/o " + store.getName(), font));
|
509 |
customerTable.addCell(new Phrase(order.getCustomer_name() + " \nc/o " + store.getName(), font));
|
| 512 |
customerTable.addCell(new Phrase(store.getLine1(), font));
|
510 |
customerTable.addCell(new Phrase(store.getLine1(), font));
|
| 513 |
customerTable.addCell(new Phrase(store.getLine2(), font));
|
511 |
customerTable.addCell(new Phrase(store.getLine2(), font));
|
| 514 |
customerTable.addCell(new Phrase(store.getCity() + "," + store.getState(), font));
|
512 |
customerTable.addCell(new Phrase(store.getCity() + "," + store.getState(), font));
|
| 515 |
if(destCode != null)
|
513 |
if(destCode != null)
|
| 516 |
customerTable.addCell(new Phrase(store.getPin() + " - " + destCode, helvetica16));
|
514 |
customerTable.addCell(new Phrase(store.getPin() + " - " + destCode, helvetica16));
|
| 517 |
else
|
515 |
else
|
| 518 |
customerTable.addCell(new Phrase(store.getPin(), font));
|
516 |
customerTable.addCell(new Phrase(store.getPin(), font));
|
| 519 |
customerTable.addCell(new Phrase("Phone :" + store.getPhone(), font));
|
517 |
customerTable.addCell(new Phrase("Phone :" + store.getPhone(), font));
|
| 520 |
} catch (TException e) {
|
518 |
} catch (TException e) {
|
| 521 |
// TODO Auto-generated catch block
|
519 |
// TODO Auto-generated catch block
|
| 522 |
e.printStackTrace();
|
520 |
e.printStackTrace();
|
| 523 |
}
|
521 |
}
|
| 524 |
|
522 |
|
| 525 |
}
|
523 |
}
|
| 526 |
|
524 |
|
| 527 |
if(order.getOrderType().equals(OrderType.B2B)) {
|
525 |
if(order.getOrderType().equals(OrderType.B2B)) {
|
| 528 |
String tin = null;
|
526 |
String tin = null;
|
| 529 |
in.shop2020.model.v1.order.TransactionService.Client tclient = tsc.getClient();
|
527 |
in.shop2020.model.v1.order.TransactionService.Client tclient = tsc.getClient();
|
| 530 |
List<Attribute> attributes;
|
528 |
List<Attribute> attributes;
|
| 531 |
try {
|
529 |
try {
|
| 532 |
attributes = tclient.getAllAttributesForOrderId(order.getId());
|
530 |
attributes = tclient.getAllAttributesForOrderId(order.getId());
|
| 533 |
|
531 |
|
| 534 |
for(Attribute attribute : attributes) {
|
532 |
for(Attribute attribute : attributes) {
|
| 535 |
if(attribute.getName().equals("tinNumber")) {
|
533 |
if(attribute.getName().equals("tinNumber")) {
|
| 536 |
tin = attribute.getValue();
|
534 |
tin = attribute.getValue();
|
| 537 |
}
|
535 |
}
|
| 538 |
}
|
536 |
}
|
| 539 |
if (tin != null) {
|
537 |
if (tin != null) {
|
| 540 |
customerTable.addCell(new Phrase("TIN :" + tin, font));
|
538 |
customerTable.addCell(new Phrase("TIN :" + tin, font));
|
| 541 |
}
|
539 |
}
|
| 542 |
|
540 |
|
| 543 |
} catch (Exception e) {
|
541 |
} catch (Exception e) {
|
| 544 |
logger.error("Error while getting order attributes", e);
|
542 |
logger.error("Error while getting order attributes", e);
|
| 545 |
}
|
543 |
}
|
| 546 |
}
|
544 |
}
|
| 547 |
/*
|
545 |
/*
|
| 548 |
if(showPaymentMode){
|
546 |
if(showPaymentMode){
|
| 549 |
customerTable.addCell(new Phrase(" ", font));
|
547 |
customerTable.addCell(new Phrase(" ", font));
|
| 550 |
customerTable.addCell(new Phrase("Payment Mode: Prepaid", font));
|
548 |
customerTable.addCell(new Phrase("Payment Mode: Prepaid", font));
|
| 551 |
}*/
|
549 |
}*/
|
| 552 |
return customerTable;
|
550 |
return customerTable;
|
| 553 |
}
|
551 |
}
|
| 554 |
|
552 |
|
| 555 |
private PdfPTable getOrderDetails(Order order, Provider provider){
|
553 |
private PdfPTable getOrderDetails(Order order, Provider provider){
|
| 556 |
PdfPTable orderTable = new PdfPTable(new float[]{0.4f, 0.6f});
|
554 |
PdfPTable orderTable = new PdfPTable(new float[]{0.4f, 0.6f});
|
| 557 |
orderTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
555 |
orderTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
| 558 |
|
556 |
|
| 559 |
orderTable.addCell(new Phrase("Invoice No:", helvetica8));
|
557 |
orderTable.addCell(new Phrase("Invoice No:", helvetica8));
|
| 560 |
orderTable.addCell(new Phrase(order.getInvoice_number(), helvetica8));
|
558 |
orderTable.addCell(new Phrase(order.getInvoice_number(), helvetica8));
|
| 561 |
|
559 |
|
| 562 |
orderTable.addCell(new Phrase("Date:", helvetica8));
|
560 |
orderTable.addCell(new Phrase("Date:", helvetica8));
|
| 563 |
orderTable.addCell(new Phrase(DateFormat.getDateInstance(DateFormat.MEDIUM).format(new Date(order.getBilling_timestamp())), helvetica8));
|
561 |
orderTable.addCell(new Phrase(DateFormat.getDateInstance(DateFormat.MEDIUM).format(new Date(order.getBilling_timestamp())), helvetica8));
|
| 564 |
|
562 |
|
| 565 |
orderTable.addCell(new Phrase(" "));
|
563 |
orderTable.addCell(new Phrase(" "));
|
| 566 |
orderTable.addCell(new Phrase(" "));
|
564 |
orderTable.addCell(new Phrase(" "));
|
| 567 |
|
565 |
|
| 568 |
orderTable.addCell(new Phrase("Order ID:", helvetica8));
|
566 |
orderTable.addCell(new Phrase("Order ID:", helvetica8));
|
| 569 |
orderTable.addCell(new Phrase("" + order.getId(), helvetica8));
|
567 |
orderTable.addCell(new Phrase("" + order.getId(), helvetica8));
|
| 570 |
|
568 |
|
| 571 |
orderTable.addCell(new Phrase("Order Date:", helvetica8));
|
569 |
orderTable.addCell(new Phrase("Order Date:", helvetica8));
|
| 572 |
orderTable.addCell(new Phrase(DateFormat.getDateInstance(DateFormat.MEDIUM).format(new Date(order.getCreated_timestamp())), helvetica8));
|
570 |
orderTable.addCell(new Phrase(DateFormat.getDateInstance(DateFormat.MEDIUM).format(new Date(order.getCreated_timestamp())), helvetica8));
|
| 573 |
|
571 |
|
| 574 |
orderTable.addCell(new Phrase("Courier:", helvetica8));
|
572 |
orderTable.addCell(new Phrase("Courier:", helvetica8));
|
| 575 |
orderTable.addCell(new Phrase(provider.getName(), helvetica8));
|
573 |
orderTable.addCell(new Phrase(provider.getName(), helvetica8));
|
| 576 |
|
574 |
|
| 577 |
orderTable.addCell(new Phrase("AWB No:", helvetica8));
|
575 |
orderTable.addCell(new Phrase("AWB No:", helvetica8));
|
| 578 |
orderTable.addCell(new Phrase(order.getAirwaybill_no(), helvetica8));
|
576 |
orderTable.addCell(new Phrase(order.getAirwaybill_no(), helvetica8));
|
| 579 |
|
577 |
|
| 580 |
orderTable.addCell(new Phrase("AWB Date:", helvetica8));
|
578 |
orderTable.addCell(new Phrase("AWB Date:", helvetica8));
|
| 581 |
orderTable.addCell(new Phrase(DateFormat.getDateInstance(DateFormat.MEDIUM).format(new Date(order.getBilling_timestamp())), helvetica8));
|
579 |
orderTable.addCell(new Phrase(DateFormat.getDateInstance(DateFormat.MEDIUM).format(new Date(order.getBilling_timestamp())), helvetica8));
|
| 582 |
|
580 |
|
| 583 |
return orderTable;
|
581 |
return orderTable;
|
| 584 |
}
|
582 |
}
|
| 585 |
|
583 |
|
| 586 |
private PdfPTable getBottomInvoiceTable(Order order, boolean isVAT){
|
584 |
private PdfPTable getBottomInvoiceTable(Order order, boolean isVAT){
|
| 587 |
PdfPTable invoiceTable = new PdfPTable(new float[]{0.2f, 0.5f, 0.1f, 0.1f, 0.1f});
|
585 |
PdfPTable invoiceTable = new PdfPTable(new float[]{0.2f, 0.5f, 0.1f, 0.1f, 0.1f});
|
| 588 |
invoiceTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
|
586 |
invoiceTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
|
| 589 |
|
587 |
|
| 590 |
invoiceTable.addCell(getInvoiceTableHeader(5));
|
588 |
invoiceTable.addCell(getInvoiceTableHeader(5));
|
| 591 |
|
589 |
|
| 592 |
invoiceTable.addCell(new Phrase("Sl. No.", helveticaBold8));
|
590 |
invoiceTable.addCell(new Phrase("Sl. No.", helveticaBold8));
|
| 593 |
invoiceTable.addCell(new Phrase("Description", helveticaBold8));
|
591 |
invoiceTable.addCell(new Phrase("Description", helveticaBold8));
|
| 594 |
invoiceTable.addCell(new Phrase("Quantity", helveticaBold8));
|
592 |
invoiceTable.addCell(new Phrase("Quantity", helveticaBold8));
|
| 595 |
invoiceTable.addCell(new Phrase("Rate (Rs)", helveticaBold8));
|
593 |
invoiceTable.addCell(new Phrase("Rate (Rs)", helveticaBold8));
|
| 596 |
invoiceTable.addCell(new Phrase("Amount (Rs)", helveticaBold8));
|
594 |
invoiceTable.addCell(new Phrase("Amount (Rs)", helveticaBold8));
|
| 597 |
LineItem lineItem = order.getLineitems().get(0);
|
595 |
LineItem lineItem = order.getLineitems().get(0);
|
| 598 |
double orderAmount = order.getTotal_amount();
|
596 |
double orderAmount = order.getTotal_amount();
|
| 599 |
double rate = lineItem.getVatRate();
|
597 |
double rate = lineItem.getVatRate();
|
| 600 |
double salesTax = (rate * orderAmount)/(100 + rate);
|
598 |
double salesTax = (rate * orderAmount)/(100 + rate);
|
| 601 |
|
599 |
|
| 602 |
populateBottomInvoiceTable(order, invoiceTable, rate);
|
600 |
populateBottomInvoiceTable(order, invoiceTable, rate);
|
| 603 |
|
601 |
|
| 604 |
PdfPCell salesTaxCell = getPriceCell(salesTax);
|
602 |
PdfPCell salesTaxCell = getPriceCell(salesTax);
|
| 605 |
|
603 |
|
| 606 |
invoiceTable.addCell(getVATLabelCell(isVAT));
|
604 |
invoiceTable.addCell(getVATLabelCell(isVAT));
|
| 607 |
invoiceTable.addCell(new Phrase(rate + "%", helvetica8));
|
605 |
invoiceTable.addCell(new Phrase(rate + "%", helvetica8));
|
| 608 |
invoiceTable.addCell(salesTaxCell);
|
606 |
invoiceTable.addCell(salesTaxCell);
|
| 609 |
|
607 |
|
| 610 |
if(order.getInsurer() > 0) {
|
608 |
if(order.getInsurer() > 0) {
|
| 611 |
invoiceTable.addCell(getInsuranceCell(3));
|
609 |
invoiceTable.addCell(getInsuranceCell(3));
|
| 612 |
invoiceTable.addCell(getPriceCell(order.getInsuranceAmount()));
|
610 |
invoiceTable.addCell(getPriceCell(order.getInsuranceAmount()));
|
| 613 |
invoiceTable.addCell(getPriceCell(order.getInsuranceAmount()));
|
611 |
invoiceTable.addCell(getPriceCell(order.getInsuranceAmount()));
|
| 614 |
}
|
612 |
}
|
| 615 |
|
613 |
|
| 616 |
invoiceTable.addCell(getEmptyCell(5));
|
614 |
invoiceTable.addCell(getEmptyCell(5));
|
| 617 |
|
615 |
|
| 618 |
invoiceTable.addCell(getTotalCell(3));
|
616 |
invoiceTable.addCell(getTotalCell(3));
|
| 619 |
invoiceTable.addCell(getRupeesCell());
|
617 |
invoiceTable.addCell(getRupeesCell());
|
| 620 |
invoiceTable.addCell(getTotalAmountCell(orderAmount));
|
618 |
invoiceTable.addCell(getTotalAmountCell(orderAmount));
|
| 621 |
|
619 |
|
| 622 |
invoiceTable.addCell(new Phrase("Amount in Words:", helvetica8));
|
620 |
invoiceTable.addCell(new Phrase("Amount in Words:", helvetica8));
|
| 623 |
invoiceTable.addCell(getAmountInWordsCell(orderAmount));
|
621 |
invoiceTable.addCell(getAmountInWordsCell(orderAmount));
|
| 624 |
|
622 |
|
| 625 |
invoiceTable.addCell(getEOECell(5));
|
623 |
invoiceTable.addCell(getEOECell(5));
|
| 626 |
|
624 |
|
| 627 |
return invoiceTable;
|
625 |
return invoiceTable;
|
| 628 |
}
|
626 |
}
|
| 629 |
|
627 |
|
| 630 |
private PdfPCell getInvoiceTableHeader(int colspan) {
|
628 |
private PdfPCell getInvoiceTableHeader(int colspan) {
|
| 631 |
PdfPCell invoiceTableHeader = new PdfPCell(new Phrase("Order Details:", helveticaBold12));
|
629 |
PdfPCell invoiceTableHeader = new PdfPCell(new Phrase("Order Details:", helveticaBold12));
|
| 632 |
invoiceTableHeader.setBorder(Rectangle.NO_BORDER);
|
630 |
invoiceTableHeader.setBorder(Rectangle.NO_BORDER);
|
| 633 |
invoiceTableHeader.setColspan(colspan);
|
631 |
invoiceTableHeader.setColspan(colspan);
|
| 634 |
invoiceTableHeader.setPaddingTop(10);
|
632 |
invoiceTableHeader.setPaddingTop(10);
|
| 635 |
return invoiceTableHeader;
|
633 |
return invoiceTableHeader;
|
| 636 |
}
|
634 |
}
|
| 637 |
|
635 |
|
| 638 |
private void populateBottomInvoiceTable(Order order, PdfPTable invoiceTable, double rate) {
|
636 |
private void populateBottomInvoiceTable(Order order, PdfPTable invoiceTable, double rate) {
|
| 639 |
for (LineItem lineitem : order.getLineitems()) {
|
637 |
for (LineItem lineitem : order.getLineitems()) {
|
| 640 |
invoiceTable.addCell(new Phrase("" + order.getId() , helvetica8));
|
638 |
invoiceTable.addCell(new Phrase("" + order.getId() , helvetica8));
|
| 641 |
|
639 |
|
| 642 |
invoiceTable.addCell(getProductNameCell(lineitem, true));
|
640 |
invoiceTable.addCell(getProductNameCell(lineitem, true));
|
| 643 |
|
641 |
|
| 644 |
invoiceTable.addCell(new Phrase("" + lineitem.getQuantity(), helvetica8));
|
642 |
invoiceTable.addCell(new Phrase("" + lineitem.getQuantity(), helvetica8));
|
| 645 |
|
643 |
|
| 646 |
double itemPrice = lineitem.getUnit_price();
|
644 |
double itemPrice = lineitem.getUnit_price();
|
| 647 |
double showPrice = (100 * itemPrice)/(100 + rate);
|
645 |
double showPrice = (100 * itemPrice)/(100 + rate);
|
| 648 |
invoiceTable.addCell(getPriceCell(showPrice)); //Unit Price Cell
|
646 |
invoiceTable.addCell(getPriceCell(showPrice)); //Unit Price Cell
|
| 649 |
|
647 |
|
| 650 |
double totalPrice = lineitem.getTotal_price();
|
648 |
double totalPrice = lineitem.getTotal_price();
|
| 651 |
showPrice = (100 * totalPrice)/(100 + rate);
|
649 |
showPrice = (100 * totalPrice)/(100 + rate);
|
| 652 |
invoiceTable.addCell(getPriceCell(showPrice)); //Total Price Cell
|
650 |
invoiceTable.addCell(getPriceCell(showPrice)); //Total Price Cell
|
| 653 |
}
|
651 |
}
|
| 654 |
}
|
652 |
}
|
| 655 |
|
653 |
|
| 656 |
private PdfPCell getProductNameCell(LineItem lineitem, boolean appendIMEI) {
|
654 |
private PdfPCell getProductNameCell(LineItem lineitem, boolean appendIMEI) {
|
| 657 |
String itemName = getItemDisplayName(lineitem, appendIMEI);
|
655 |
String itemName = getItemDisplayName(lineitem, appendIMEI);
|
| 658 |
PdfPCell productNameCell = new PdfPCell(new Phrase(itemName, helvetica8));
|
656 |
PdfPCell productNameCell = new PdfPCell(new Phrase(itemName, helvetica8));
|
| 659 |
productNameCell.setHorizontalAlignment(Element.ALIGN_LEFT);
|
657 |
productNameCell.setHorizontalAlignment(Element.ALIGN_LEFT);
|
| 660 |
return productNameCell;
|
658 |
return productNameCell;
|
| 661 |
}
|
659 |
}
|
| 662 |
|
660 |
|
| 663 |
private PdfPCell getPriceCell(double price) {
|
661 |
private PdfPCell getPriceCell(double price) {
|
| 664 |
PdfPCell totalPriceCell = new PdfPCell(new Phrase(amountFormat.format(price), helvetica8));
|
662 |
PdfPCell totalPriceCell = new PdfPCell(new Phrase(amountFormat.format(price), helvetica8));
|
| 665 |
totalPriceCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
|
663 |
totalPriceCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
|
| 666 |
return totalPriceCell;
|
664 |
return totalPriceCell;
|
| 667 |
}
|
665 |
}
|
| 668 |
|
666 |
|
| 669 |
private PdfPCell getVATLabelCell(boolean isVAT) {
|
667 |
private PdfPCell getVATLabelCell(boolean isVAT) {
|
| 670 |
PdfPCell vatCell = null;
|
668 |
PdfPCell vatCell = null;
|
| 671 |
if(isVAT){
|
669 |
if(isVAT){
|
| 672 |
vatCell = new PdfPCell(new Phrase("VAT", helveticaBold8));
|
670 |
vatCell = new PdfPCell(new Phrase("VAT", helveticaBold8));
|
| 673 |
} else {
|
671 |
} else {
|
| 674 |
vatCell = new PdfPCell(new Phrase("CST", helveticaBold8));
|
672 |
vatCell = new PdfPCell(new Phrase("CST", helveticaBold8));
|
| 675 |
}
|
673 |
}
|
| 676 |
vatCell.setColspan(3);
|
674 |
vatCell.setColspan(3);
|
| 677 |
vatCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
|
675 |
vatCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
|
| 678 |
return vatCell;
|
676 |
return vatCell;
|
| 679 |
}
|
677 |
}
|
| 680 |
|
678 |
|
| 681 |
private PdfPCell getInsuranceCell(int colspan) {
|
679 |
private PdfPCell getInsuranceCell(int colspan) {
|
| 682 |
PdfPCell insuranceCell = null;
|
680 |
PdfPCell insuranceCell = null;
|
| 683 |
insuranceCell = new PdfPCell(new Phrase("1 Year WorldWide Theft Insurance", helvetica8));
|
681 |
insuranceCell = new PdfPCell(new Phrase("1 Year WorldWide Theft Insurance", helvetica8));
|
| 684 |
insuranceCell.setColspan(colspan);
|
682 |
insuranceCell.setColspan(colspan);
|
| 685 |
insuranceCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
|
683 |
insuranceCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
|
| 686 |
return insuranceCell;
|
684 |
return insuranceCell;
|
| 687 |
}
|
685 |
}
|
| 688 |
|
686 |
|
| 689 |
private PdfPCell getEmptyCell(int colspan) {
|
687 |
private PdfPCell getEmptyCell(int colspan) {
|
| 690 |
PdfPCell emptyCell = new PdfPCell(new Phrase(" ", helvetica8));
|
688 |
PdfPCell emptyCell = new PdfPCell(new Phrase(" ", helvetica8));
|
| 691 |
emptyCell.setColspan(colspan);
|
689 |
emptyCell.setColspan(colspan);
|
| 692 |
return emptyCell;
|
690 |
return emptyCell;
|
| 693 |
}
|
691 |
}
|
| 694 |
|
692 |
|
| 695 |
private PdfPCell getTotalCell(int colspan) {
|
693 |
private PdfPCell getTotalCell(int colspan) {
|
| 696 |
PdfPCell totalCell = new PdfPCell(new Phrase("Total", helveticaBold8));
|
694 |
PdfPCell totalCell = new PdfPCell(new Phrase("Total", helveticaBold8));
|
| 697 |
totalCell.setColspan(colspan);
|
695 |
totalCell.setColspan(colspan);
|
| 698 |
totalCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
|
696 |
totalCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
|
| 699 |
return totalCell;
|
697 |
return totalCell;
|
| 700 |
}
|
698 |
}
|
| 701 |
|
699 |
|
| 702 |
private PdfPCell getRupeesCell() {
|
700 |
private PdfPCell getRupeesCell() {
|
| 703 |
PdfPCell rupeesCell = new PdfPCell(new Phrase("Rs.", helveticaBold8));
|
701 |
PdfPCell rupeesCell = new PdfPCell(new Phrase("Rs.", helveticaBold8));
|
| 704 |
rupeesCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
|
702 |
rupeesCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
|
| 705 |
return rupeesCell;
|
703 |
return rupeesCell;
|
| 706 |
}
|
704 |
}
|
| 707 |
|
705 |
|
| 708 |
private PdfPCell getTotalAmountCell(double orderAmount) {
|
706 |
private PdfPCell getTotalAmountCell(double orderAmount) {
|
| 709 |
PdfPCell totalAmountCell = new PdfPCell(new Phrase(amountFormat.format(orderAmount), helveticaBold8));
|
707 |
PdfPCell totalAmountCell = new PdfPCell(new Phrase(amountFormat.format(orderAmount), helveticaBold8));
|
| 710 |
totalAmountCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
|
708 |
totalAmountCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
|
| 711 |
return totalAmountCell;
|
709 |
return totalAmountCell;
|
| 712 |
}
|
710 |
}
|
| 713 |
|
711 |
|
| 714 |
/**
|
712 |
/**
|
| 715 |
* This method uses ICU4J libraries to convert the given amount into words
|
713 |
* This method uses ICU4J libraries to convert the given amount into words
|
| 716 |
* of Indian locale.
|
714 |
* of Indian locale.
|
| 717 |
*
|
715 |
*
|
| 718 |
* @param orderAmount
|
716 |
* @param orderAmount
|
| 719 |
* The amount to convert.
|
717 |
* The amount to convert.
|
| 720 |
* @return the string representation of the given amount.
|
718 |
* @return the string representation of the given amount.
|
| 721 |
*/
|
719 |
*/
|
| 722 |
private PdfPCell getAmountInWordsCell(double orderAmount) {
|
720 |
private PdfPCell getAmountInWordsCell(double orderAmount) {
|
| 723 |
RuleBasedNumberFormat amountInWordsFormat = new RuleBasedNumberFormat(indianLocale, RuleBasedNumberFormat.SPELLOUT);
|
721 |
RuleBasedNumberFormat amountInWordsFormat = new RuleBasedNumberFormat(indianLocale, RuleBasedNumberFormat.SPELLOUT);
|
| 724 |
StringBuilder amountInWords = new StringBuilder("Rs. ");
|
722 |
StringBuilder amountInWords = new StringBuilder("Rs. ");
|
| 725 |
amountInWords.append(WordUtils.capitalize(amountInWordsFormat.format((int)orderAmount)));
|
723 |
amountInWords.append(WordUtils.capitalize(amountInWordsFormat.format((int)orderAmount)));
|
| 726 |
amountInWords.append(" and ");
|
724 |
amountInWords.append(" and ");
|
| 727 |
amountInWords.append(WordUtils.capitalize(amountInWordsFormat.format((int)(orderAmount*100)%100)));
|
725 |
amountInWords.append(WordUtils.capitalize(amountInWordsFormat.format((int)(orderAmount*100)%100)));
|
| 728 |
amountInWords.append(" paise");
|
726 |
amountInWords.append(" paise");
|
| 729 |
|
727 |
|
| 730 |
PdfPCell amountInWordsCell= new PdfPCell(new Phrase(amountInWords.toString(), helveticaBold8));
|
728 |
PdfPCell amountInWordsCell= new PdfPCell(new Phrase(amountInWords.toString(), helveticaBold8));
|
| 731 |
amountInWordsCell.setColspan(4);
|
729 |
amountInWordsCell.setColspan(4);
|
| 732 |
return amountInWordsCell;
|
730 |
return amountInWordsCell;
|
| 733 |
}
|
731 |
}
|
| 734 |
|
732 |
|
| 735 |
/**
|
733 |
/**
|
| 736 |
* Returns the item name to be displayed in the invoice table.
|
734 |
* Returns the item name to be displayed in the invoice table.
|
| 737 |
*
|
735 |
*
|
| 738 |
* @param lineitem
|
736 |
* @param lineitem
|
| 739 |
* The line item whose name has to be displayed
|
737 |
* The line item whose name has to be displayed
|
| 740 |
* @param appendIMEI
|
738 |
* @param appendIMEI
|
| 741 |
* Whether to attach the IMEI No. to the item name
|
739 |
* Whether to attach the IMEI No. to the item name
|
| 742 |
* @return The name to be displayed for the given line item.
|
740 |
* @return The name to be displayed for the given line item.
|
| 743 |
*/
|
741 |
*/
|
| 744 |
private String getItemDisplayName(LineItem lineitem, boolean appendIMEI){
|
742 |
private String getItemDisplayName(LineItem lineitem, boolean appendIMEI){
|
| 745 |
StringBuffer itemName = new StringBuffer();
|
743 |
StringBuffer itemName = new StringBuffer();
|
| 746 |
if(lineitem.getBrand()!= null)
|
744 |
if(lineitem.getBrand()!= null)
|
| 747 |
itemName.append(lineitem.getBrand() + " ");
|
745 |
itemName.append(lineitem.getBrand() + " ");
|
| 748 |
if(lineitem.getModel_name() != null)
|
746 |
if(lineitem.getModel_name() != null)
|
| 749 |
itemName.append(lineitem.getModel_name() + " ");
|
747 |
itemName.append(lineitem.getModel_name() + " ");
|
| 750 |
if(lineitem.getModel_number() != null )
|
748 |
if(lineitem.getModel_number() != null )
|
| 751 |
itemName.append(lineitem.getModel_number() + " ");
|
749 |
itemName.append(lineitem.getModel_number() + " ");
|
| 752 |
if(lineitem.getColor() != null && !lineitem.getColor().trim().equals("NA"))
|
750 |
if(lineitem.getColor() != null && !lineitem.getColor().trim().equals("NA"))
|
| 753 |
itemName.append("("+lineitem.getColor()+")");
|
751 |
itemName.append("("+lineitem.getColor()+")");
|
| 754 |
if(appendIMEI && lineitem.isSetSerial_number()){
|
752 |
if(appendIMEI && lineitem.isSetSerial_number()){
|
| 755 |
itemName.append("\nIMEI No. " + lineitem.getSerial_number());
|
753 |
itemName.append("\nIMEI No. " + lineitem.getSerial_number());
|
| 756 |
}
|
754 |
}
|
| 757 |
|
755 |
|
| 758 |
return itemName.toString();
|
756 |
return itemName.toString();
|
| 759 |
}
|
757 |
}
|
| 760 |
|
758 |
|
| 761 |
/**
|
759 |
/**
|
| 762 |
*
|
760 |
*
|
| 763 |
* @param colspan
|
761 |
* @param colspan
|
| 764 |
* @return a PdfPCell containing the E&OE text and spanning the given
|
762 |
* @return a PdfPCell containing the E&OE text and spanning the given
|
| 765 |
* no. of columns
|
763 |
* no. of columns
|
| 766 |
*/
|
764 |
*/
|
| 767 |
private PdfPCell getEOECell(int colspan) {
|
765 |
private PdfPCell getEOECell(int colspan) {
|
| 768 |
PdfPCell eoeCell = new PdfPCell(new Phrase("E & O.E", helvetica8));
|
766 |
PdfPCell eoeCell = new PdfPCell(new Phrase("E & O.E", helvetica8));
|
| 769 |
eoeCell.setColspan(colspan);
|
767 |
eoeCell.setColspan(colspan);
|
| 770 |
eoeCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
|
768 |
eoeCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
|
| 771 |
return eoeCell;
|
769 |
return eoeCell;
|
| 772 |
}
|
770 |
}
|
| 773 |
|
771 |
|
| 774 |
private PdfPTable getExtraInfoTable(Order order, Provider provider, float barcodeFontSize, BillingType billingType){
|
772 |
private PdfPTable getExtraInfoTable(Order order, Provider provider, float barcodeFontSize, BillingType billingType){
|
| 775 |
PdfPTable extraInfoTable = new PdfPTable(1);
|
773 |
PdfPTable extraInfoTable = new PdfPTable(1);
|
| 776 |
extraInfoTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
774 |
extraInfoTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
| 777 |
extraInfoTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
|
775 |
extraInfoTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
|
| 778 |
|
776 |
|
| 779 |
String fontPath = InvoiceGenerationService.class.getResource("/saholic-wn.TTF").getPath();
|
777 |
String fontPath = InvoiceGenerationService.class.getResource("/saholic-wn.TTF").getPath();
|
| 780 |
FontFactoryImp ttfFontFactory = new FontFactoryImp();
|
778 |
FontFactoryImp ttfFontFactory = new FontFactoryImp();
|
| 781 |
ttfFontFactory.register(fontPath, "barcode");
|
779 |
ttfFontFactory.register(fontPath, "barcode");
|
| 782 |
Font barCodeFont = ttfFontFactory.getFont("barcode", BaseFont.CP1252, true, barcodeFontSize);
|
780 |
Font barCodeFont = ttfFontFactory.getFont("barcode", BaseFont.CP1252, true, barcodeFontSize);
|
| 783 |
|
781 |
|
| 784 |
PdfPCell extraInfoCell;
|
782 |
PdfPCell extraInfoCell;
|
| 785 |
if(billingType == BillingType.EXTERNAL){
|
783 |
if(billingType == BillingType.EXTERNAL){
|
| 786 |
extraInfoCell = new PdfPCell(new Paragraph( "*" + order.getId() + "* *" + order.getCustomer_name() + "* *" + order.getTotal_amount() + "*", barCodeFont));
|
784 |
extraInfoCell = new PdfPCell(new Paragraph( "*" + order.getId() + "* *" + order.getCustomer_name() + "* *" + order.getTotal_amount() + "*", barCodeFont));
|
| 787 |
}else{
|
785 |
}else{
|
| 788 |
extraInfoCell = new PdfPCell(new Paragraph( "*" + order.getId() + "* *" + order.getLineitems().get(0).getTransfer_price() + "*", barCodeFont));
|
786 |
extraInfoCell = new PdfPCell(new Paragraph( "*" + order.getId() + "* *" + order.getLineitems().get(0).getTransfer_price() + "*", barCodeFont));
|
| 789 |
}
|
787 |
}
|
| 790 |
|
788 |
|
| 791 |
extraInfoCell.setPaddingTop(20.0f);
|
789 |
extraInfoCell.setPaddingTop(20.0f);
|
| 792 |
extraInfoCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
|
790 |
extraInfoCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
|
| 793 |
extraInfoCell.setBorder(Rectangle.NO_BORDER);
|
791 |
extraInfoCell.setBorder(Rectangle.NO_BORDER);
|
| 794 |
|
792 |
|
| 795 |
extraInfoTable.addCell(extraInfoCell);
|
793 |
extraInfoTable.addCell(extraInfoCell);
|
| 796 |
|
794 |
|
| 797 |
|
795 |
|
| 798 |
return extraInfoTable;
|
796 |
return extraInfoTable;
|
| 799 |
}
|
797 |
}
|
| 800 |
|
798 |
|
| 801 |
private PdfPTable getFixedTextTable(float barcodeFontSize, String printText){
|
799 |
private PdfPTable getFixedTextTable(float barcodeFontSize, String printText){
|
| 802 |
PdfPTable extraInfoTable = new PdfPTable(1);
|
800 |
PdfPTable extraInfoTable = new PdfPTable(1);
|
| 803 |
extraInfoTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
801 |
extraInfoTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
| 804 |
extraInfoTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
|
802 |
extraInfoTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
|
| 805 |
|
803 |
|
| 806 |
String fontPath = InvoiceGenerationService.class.getResource("/saholic-wn.TTF").getPath();
|
804 |
String fontPath = InvoiceGenerationService.class.getResource("/saholic-wn.TTF").getPath();
|
| 807 |
FontFactoryImp ttfFontFactory = new FontFactoryImp();
|
805 |
FontFactoryImp ttfFontFactory = new FontFactoryImp();
|
| 808 |
ttfFontFactory.register(fontPath, "barcode");
|
806 |
ttfFontFactory.register(fontPath, "barcode");
|
| 809 |
Font barCodeFont = ttfFontFactory.getFont("barcode", BaseFont.CP1252, true, barcodeFontSize);
|
807 |
Font barCodeFont = ttfFontFactory.getFont("barcode", BaseFont.CP1252, true, barcodeFontSize);
|
| 810 |
|
808 |
|
| 811 |
PdfPCell extraInfoCell = new PdfPCell(new Paragraph( "*" + printText + "*", barCodeFont));
|
809 |
PdfPCell extraInfoCell = new PdfPCell(new Paragraph( "*" + printText + "*", barCodeFont));
|
| 812 |
|
810 |
|
| 813 |
extraInfoCell.setPaddingTop(20.0f);
|
811 |
extraInfoCell.setPaddingTop(20.0f);
|
| 814 |
extraInfoCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
|
812 |
extraInfoCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
|
| 815 |
extraInfoCell.setBorder(Rectangle.NO_BORDER);
|
813 |
extraInfoCell.setBorder(Rectangle.NO_BORDER);
|
| 816 |
|
814 |
|
| 817 |
extraInfoTable.addCell(extraInfoCell);
|
815 |
extraInfoTable.addCell(extraInfoCell);
|
| 818 |
|
816 |
|
| 819 |
return extraInfoTable;
|
817 |
return extraInfoTable;
|
| 820 |
}
|
818 |
}
|
| 821 |
|
819 |
|
| 822 |
public static void main(String[] args) throws IOException {
|
820 |
public static void main(String[] args) throws IOException {
|
| 823 |
InvoiceGenerationService invoiceGenerationService = new InvoiceGenerationService();
|
821 |
InvoiceGenerationService invoiceGenerationService = new InvoiceGenerationService();
|
| 824 |
long orderId = 148574;
|
822 |
long orderId = 148574;
|
| 825 |
ByteArrayOutputStream baos = invoiceGenerationService.generateInvoice(orderId, false, false, 1);
|
823 |
ByteArrayOutputStream baos = invoiceGenerationService.generateInvoice(orderId, false, false, 1);
|
| 826 |
String userHome = System.getProperty("user.home");
|
824 |
String userHome = System.getProperty("user.home");
|
| 827 |
File f = new File(userHome + "/invoice-" + orderId + ".pdf");
|
825 |
File f = new File(userHome + "/invoice-" + orderId + ".pdf");
|
| 828 |
FileOutputStream fos = new FileOutputStream(f);
|
826 |
FileOutputStream fos = new FileOutputStream(f);
|
| 829 |
baos.writeTo(fos);
|
827 |
baos.writeTo(fos);
|
| 830 |
System.out.println("Invoice generated.");
|
828 |
System.out.println("Invoice generated.");
|
| 831 |
}
|
829 |
}
|
| 832 |
}
|
830 |
}
|