| Line 103... |
Line 103... |
| 103 |
|
103 |
|
| 104 |
private static final Font helvetica8 = FontFactory.getFont(FontFactory.HELVETICA, 8);
|
104 |
private static final Font helvetica8 = FontFactory.getFont(FontFactory.HELVETICA, 8);
|
| 105 |
private static final Font helvetica10 = FontFactory.getFont(FontFactory.HELVETICA, 10);
|
105 |
private static final Font helvetica10 = FontFactory.getFont(FontFactory.HELVETICA, 10);
|
| 106 |
private static final Font helvetica12 = FontFactory.getFont(FontFactory.HELVETICA, 12);
|
106 |
private static final Font helvetica12 = FontFactory.getFont(FontFactory.HELVETICA, 12);
|
| 107 |
private static final Font helvetica16 = FontFactory.getFont(FontFactory.HELVETICA, 16);
|
107 |
private static final Font helvetica16 = FontFactory.getFont(FontFactory.HELVETICA, 16);
|
| - |
|
108 |
private static final Font helvetica28 = FontFactory.getFont(FontFactory.HELVETICA, 28);
|
| 108 |
|
109 |
|
| 109 |
private static final Font helveticaBold8 = FontFactory.getFont(FontFactory.HELVETICA_BOLD, 8);
|
110 |
private static final Font helveticaBold8 = FontFactory.getFont(FontFactory.HELVETICA_BOLD, 8);
|
| 110 |
private static final Font helveticaBold12 = FontFactory.getFont(FontFactory.HELVETICA_BOLD, 12);
|
111 |
private static final Font helveticaBold12 = FontFactory.getFont(FontFactory.HELVETICA_BOLD, 12);
|
| 111 |
|
112 |
|
| 112 |
private static final Properties properties = readProperties();
|
113 |
private static final Properties properties = readProperties();
|
| Line 210... |
Line 211... |
| 210 |
Font barCodeFont = getBarCodeFont(provider, barcodeFontSize);
|
211 |
Font barCodeFont = getBarCodeFont(provider, barcodeFontSize);
|
| 211 |
|
212 |
|
| 212 |
PdfPTable table = new PdfPTable(1);
|
213 |
PdfPTable table = new PdfPTable(1);
|
| 213 |
table.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
214 |
table.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
| 214 |
|
215 |
|
| - |
|
216 |
PdfPTable logoTable = new PdfPTable(2);
|
| - |
|
217 |
logoTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
| - |
|
218 |
logoTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT);
|
| - |
|
219 |
logoTable.getDefaultCell().setVerticalAlignment(Element.ALIGN_BOTTOM);
|
| 215 |
PdfPCell logoCell = getLogoCell();
|
220 |
logoTable.addCell(getLogoCell());
|
| - |
|
221 |
if(order.isCod())
|
| - |
|
222 |
logoTable.addCell(new Phrase("COD ", helvetica28));
|
| - |
|
223 |
|
| 216 |
PdfPCell titleCell = getTitleCell();
|
224 |
PdfPCell titleCell = getTitleCell();
|
| 217 |
PdfPTable customerTable = getCustomerAddressTable(order, destCode, false, helvetica12);
|
225 |
PdfPTable customerTable = getCustomerAddressTable(order, destCode, false, helvetica12);
|
| 218 |
PdfPTable providerInfoTable = getProviderTable(order, provider, barCodeFont);
|
226 |
PdfPTable providerInfoTable = getProviderTable(order, provider, barCodeFont);
|
| 219 |
|
227 |
|
| 220 |
PdfPTable dispatchTable = new PdfPTable(new float[]{0.5f, 0.1f, 0.4f});
|
228 |
PdfPTable dispatchTable = new PdfPTable(new float[]{0.5f, 0.1f, 0.4f});
|
| Line 227... |
Line 235... |
| 227 |
PdfPTable invoiceTable = null;
|
235 |
PdfPTable invoiceTable = null;
|
| 228 |
if(withBill)
|
236 |
if(withBill)
|
| 229 |
invoiceTable = getTopInvoiceTable(order, tinNo);
|
237 |
invoiceTable = getTopInvoiceTable(order, tinNo);
|
| 230 |
else
|
238 |
else
|
| 231 |
invoiceTable = getTopInvoiceTable(order, warehouse.getTinNumber());
|
239 |
invoiceTable = getTopInvoiceTable(order, warehouse.getTinNumber());
|
| 232 |
|
240 |
|
| 233 |
PdfPCell addressCell = null;
|
241 |
PdfPCell addressCell = null;
|
| 234 |
if(withBill)
|
242 |
if(withBill)
|
| 235 |
addressCell = getAddressCell(ourAddress);
|
243 |
addressCell = getAddressCell(ourAddress);
|
| 236 |
else
|
244 |
else
|
| 237 |
addressCell = getAddressCell(warehouse.getLocation() + "\nPIN " + warehouse.getPincode() + "\n\n");
|
245 |
addressCell = getAddressCell(warehouse.getLocation() + "\nPIN " + warehouse.getPincode() + "\n\n");
|
| 238 |
|
246 |
|
| - |
|
247 |
PdfPTable chargesTable = new PdfPTable(1);
|
| - |
|
248 |
chargesTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
| - |
|
249 |
chargesTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
|
| - |
|
250 |
if(order.isCod()){
|
| - |
|
251 |
chargesTable.addCell(new Phrase("AMOUNT TO BE COLLECTED : Rs " + order.getTotal_amount(), helveticaBold12));
|
| - |
|
252 |
chargesTable.addCell(new Phrase("RTO ADDRESS:DEL/HSE-111118"));
|
| - |
|
253 |
} else {
|
| - |
|
254 |
chargesTable.addCell(new Phrase("Do not pay any extra charges to the Courier."));
|
| - |
|
255 |
}
|
| - |
|
256 |
|
| - |
|
257 |
PdfPTable addressAndNoteTable = new PdfPTable(new float[]{0.3f, 0.7f});
|
| - |
|
258 |
addressAndNoteTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
|
| - |
|
259 |
addressAndNoteTable.addCell(addressCell);
|
| - |
|
260 |
addressAndNoteTable.addCell(chargesTable);
|
| - |
|
261 |
|
| 239 |
table.addCell(logoCell);
|
262 |
table.addCell(logoTable);
|
| 240 |
table.addCell(titleCell);
|
263 |
table.addCell(titleCell);
|
| 241 |
table.addCell(dispatchTable);
|
264 |
table.addCell(dispatchTable);
|
| 242 |
table.addCell(invoiceTable);
|
265 |
table.addCell(invoiceTable);
|
| 243 |
table.addCell(new Phrase("If undelivered, return to:", helvetica10));
|
266 |
table.addCell(new Phrase("If undelivered, return to:", helvetica10));
|
| 244 |
table.addCell(addressCell);
|
267 |
table.addCell(addressAndNoteTable);
|
| 245 |
table.addCell(new Phrase("Do not pay any extra charges to the Courier."));
|
- |
|
| 246 |
return table;
|
268 |
return table;
|
| 247 |
}
|
269 |
}
|
| 248 |
|
270 |
|
| 249 |
private Font getBarCodeFont(Provider provider, float barcodeFontSize) {
|
271 |
private Font getBarCodeFont(Provider provider, float barcodeFontSize) {
|
| 250 |
String fontPath = InvoiceGenerationService.class.getResource("/" + provider.getName().toLowerCase() + "/barcode.TTF").getPath();
|
272 |
String fontPath = InvoiceGenerationService.class.getResource("/" + provider.getName().toLowerCase() + "/barcode.TTF").getPath();
|
| Line 287... |
Line 309... |
| 287 |
awbNumberCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
|
309 |
awbNumberCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
|
| 288 |
awbNumberCell.setBorder(Rectangle.NO_BORDER);
|
310 |
awbNumberCell.setBorder(Rectangle.NO_BORDER);
|
| 289 |
|
311 |
|
| 290 |
providerInfoTable.addCell(providerNameCell);
|
312 |
providerInfoTable.addCell(providerNameCell);
|
| 291 |
providerInfoTable.addCell(awbNumberCell);
|
313 |
providerInfoTable.addCell(awbNumberCell);
|
| - |
|
314 |
if(order.isCod())
|
| - |
|
315 |
providerInfoTable.addCell(new Phrase("Account No : " + provider.getDetails().get(DeliveryType.COD).getAccountNo(), helvetica8));
|
| - |
|
316 |
else
|
| 292 |
providerInfoTable.addCell(new Phrase("Account No : " + provider.getDetails().get(DeliveryType.PREPAID).getAccountNo(), helvetica8));
|
317 |
providerInfoTable.addCell(new Phrase("Account No : " + provider.getDetails().get(DeliveryType.PREPAID).getAccountNo(), helvetica8));
|
| 293 |
providerInfoTable.addCell(new Phrase("AWB Date : " + DateFormat.getDateInstance(DateFormat.MEDIUM).format(new Date()), helvetica8));
|
318 |
providerInfoTable.addCell(new Phrase("AWB Date : " + DateFormat.getDateInstance(DateFormat.MEDIUM).format(new Date()), helvetica8));
|
| 294 |
providerInfoTable.addCell(new Phrase("Weight : " + order.getTotal_weight() + " Kg", helvetica8));
|
319 |
providerInfoTable.addCell(new Phrase("Weight : " + order.getTotal_weight() + " Kg", helvetica8));
|
| 295 |
return providerInfoTable;
|
320 |
return providerInfoTable;
|
| 296 |
}
|
321 |
}
|
| 297 |
|
322 |
|
| Line 323... |
Line 348... |
| 323 |
|
348 |
|
| 324 |
private void populateTopInvoiceTable(Order order, PdfPTable invoiceTable) {
|
349 |
private void populateTopInvoiceTable(Order order, PdfPTable invoiceTable) {
|
| 325 |
List<LineItem> lineitems = order.getLineitems();
|
350 |
List<LineItem> lineitems = order.getLineitems();
|
| 326 |
for (LineItem lineitem : lineitems) {
|
351 |
for (LineItem lineitem : lineitems) {
|
| 327 |
invoiceTable.addCell(new Phrase(order.getId() + "", helvetica8));
|
352 |
invoiceTable.addCell(new Phrase(order.getId() + "", helvetica8));
|
| - |
|
353 |
if(order.isCod())
|
| - |
|
354 |
invoiceTable.addCell(new Phrase("COD", helvetica8));
|
| - |
|
355 |
else
|
| 328 |
invoiceTable.addCell(new Phrase("Prepaid", helvetica8));
|
356 |
invoiceTable.addCell(new Phrase("Prepaid", helvetica8));
|
| 329 |
|
357 |
|
| 330 |
invoiceTable.addCell(getProductNameCell(lineitem, false));
|
358 |
invoiceTable.addCell(getProductNameCell(lineitem, false));
|
| 331 |
|
359 |
|
| 332 |
invoiceTable.addCell(new Phrase(lineitem.getQuantity() + "", helvetica8));
|
360 |
invoiceTable.addCell(new Phrase(lineitem.getQuantity() + "", helvetica8));
|
| 333 |
|
361 |
|
| Line 619... |
Line 647... |
| 619 |
return eoeCell;
|
647 |
return eoeCell;
|
| 620 |
}
|
648 |
}
|
| 621 |
|
649 |
|
| 622 |
public static void main(String[] args) throws IOException {
|
650 |
public static void main(String[] args) throws IOException {
|
| 623 |
InvoiceGenerationService invoiceGenerationService = new InvoiceGenerationService();
|
651 |
InvoiceGenerationService invoiceGenerationService = new InvoiceGenerationService();
|
| 624 |
long orderId = 434;
|
652 |
long orderId = 542;
|
| 625 |
ByteArrayOutputStream baos = invoiceGenerationService.generateInvoice(orderId, true);
|
653 |
ByteArrayOutputStream baos = invoiceGenerationService.generateInvoice(orderId, false);
|
| 626 |
String userHome = System.getProperty("user.home");
|
654 |
String userHome = System.getProperty("user.home");
|
| 627 |
File f = new File(userHome + "/invoice-" + orderId + ".pdf");
|
655 |
File f = new File(userHome + "/invoice-" + orderId + ".pdf");
|
| 628 |
FileOutputStream fos = new FileOutputStream(f);
|
656 |
FileOutputStream fos = new FileOutputStream(f);
|
| 629 |
baos.writeTo(fos);
|
657 |
baos.writeTo(fos);
|
| 630 |
System.out.println("Invoice generated.");
|
658 |
System.out.println("Invoice generated.");
|