| Line 2... |
Line 2... |
| 2 |
|
2 |
|
| 3 |
import com.ibm.icu.text.RuleBasedNumberFormat;
|
3 |
import com.ibm.icu.text.RuleBasedNumberFormat;
|
| 4 |
import com.itextpdf.text.*;
|
4 |
import com.itextpdf.text.*;
|
| 5 |
import com.itextpdf.text.Font.FontFamily;
|
5 |
import com.itextpdf.text.Font.FontFamily;
|
| 6 |
import com.itextpdf.text.pdf.*;
|
6 |
import com.itextpdf.text.pdf.*;
|
| - |
|
7 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 7 |
import com.spice.profitmandi.common.model.*;
|
8 |
import com.spice.profitmandi.common.model.*;
|
| 8 |
import org.apache.logging.log4j.LogManager;
|
9 |
import org.apache.logging.log4j.LogManager;
|
| 9 |
import org.apache.logging.log4j.Logger;
|
10 |
import org.apache.logging.log4j.Logger;
|
| 10 |
import org.springframework.util.StringUtils;
|
11 |
import org.springframework.util.StringUtils;
|
| 11 |
|
12 |
|
| Line 56... |
Line 57... |
| 56 |
//Debit Note generation logic has been changed
|
57 |
//Debit Note generation logic has been changed
|
| 57 |
//Debit Note considers price drops so amount in debit note is current price of item.
|
58 |
//Debit Note considers price drops so amount in debit note is current price of item.
|
| 58 |
//From 16Nov 2019 onwards all debit notes will be as per actuall billing value, all pricedrops
|
59 |
//From 16Nov 2019 onwards all debit notes will be as per actuall billing value, all pricedrops
|
| 59 |
//shall be rolledback or cancelled once the debit note is generated.
|
60 |
//shall be rolledback or cancelled once the debit note is generated.
|
| 60 |
|
61 |
|
| - |
|
62 |
public static void generateAndWrite(List<InvoicePdfModel> pdfModels, PrinterType printerType, ByteArrayOutputStream outputStream) throws ProfitMandiBusinessException {
|
| - |
|
63 |
if (PrinterType.A4.equals(printerType)) {
|
| - |
|
64 |
generateAndWrite(pdfModels, outputStream);
|
| - |
|
65 |
} else {
|
| - |
|
66 |
if (pdfModels.size() > 1) {
|
| - |
|
67 |
}
|
| - |
|
68 |
if (PrinterType.W80.equals(printerType)) {
|
| - |
|
69 |
InvoiceFormatter.getInvoice(pdfModels.get(0), outputStream, InvoiceFormatter.WIDTH_80MM);
|
| - |
|
70 |
} else if (PrinterType.W58.equals(printerType)) {
|
| - |
|
71 |
InvoiceFormatter.getInvoice(pdfModels.get(0), outputStream, InvoiceFormatter.WIDTH_58MM);
|
| - |
|
72 |
|
| - |
|
73 |
}
|
| - |
|
74 |
}
|
| - |
|
75 |
}
|
| - |
|
76 |
|
| 61 |
|
77 |
|
| - |
|
78 |
//Standard
|
| 62 |
public static void generateAndWrite(List<InvoicePdfModel> pdfModels, ByteArrayOutputStream outputStream) {
|
79 |
public static void generateAndWrite(List<InvoicePdfModel> pdfModels, ByteArrayOutputStream outputStream) {
|
| 63 |
try {
|
80 |
try {
|
| 64 |
boolean cancelledPages = false;
|
81 |
boolean cancelledPages = false;
|
| 65 |
List<Integer> caneclledPageList = new ArrayList<>();
|
82 |
List<Integer> caneclledPageList = new ArrayList<>();
|
| 66 |
Document document = new Document();
|
83 |
Document document = new Document();
|
| Line 303... |
Line 320... |
| 303 |
PdfPCell cell1 = new PdfPCell(new Paragraph(10, FormattingUtils.formatDecimal(paymentOption.getAmount()), FONT_BOLD));
|
320 |
PdfPCell cell1 = new PdfPCell(new Paragraph(10, FormattingUtils.formatDecimal(paymentOption.getAmount()), FONT_BOLD));
|
| 304 |
cell1.setPadding(5);
|
321 |
cell1.setPadding(5);
|
| 305 |
paidAmountTable.addCell(cell1);
|
322 |
paidAmountTable.addCell(cell1);
|
| 306 |
totalPaidValue += paymentOption.getAmount();
|
323 |
totalPaidValue += paymentOption.getAmount();
|
| 307 |
}
|
324 |
}
|
| 308 |
|
- |
|
| 309 |
|
- |
|
| 310 |
|
- |
|
| 311 |
|
- |
|
| 312 |
}
|
325 |
}
|
| 313 |
PdfPCell totalPaidCell = new PdfPCell(new Paragraph(10, "Total Paid", FONT_BOLD));
|
326 |
PdfPCell totalPaidCell = new PdfPCell(new Paragraph(10, "Total Paid", FONT_BOLD));
|
| 314 |
totalPaidCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
|
327 |
totalPaidCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
|
| 315 |
totalPaidCell.setPadding(5);
|
328 |
totalPaidCell.setPadding(5);
|
| 316 |
paidAmountTable.addCell(totalPaidCell);
|
329 |
paidAmountTable.addCell(totalPaidCell);
|
| Line 324... |
Line 337... |
| 324 |
}
|
337 |
}
|
| 325 |
Paragraph autoGenerateParagraph = new Paragraph("Note - This is computer generated Invoice, no signature is required", FONT_NORMAL);
|
338 |
Paragraph autoGenerateParagraph = new Paragraph("Note - This is computer generated Invoice, no signature is required", FONT_NORMAL);
|
| 326 |
autoGenerateParagraph.setAlignment(Element.ALIGN_CENTER);
|
339 |
autoGenerateParagraph.setAlignment(Element.ALIGN_CENTER);
|
| 327 |
document.add(autoGenerateParagraph);
|
340 |
document.add(autoGenerateParagraph);
|
| 328 |
|
341 |
|
| - |
|
342 |
if(pdfModel.getCreditTerms()!=null) {
|
| - |
|
343 |
// Use monospaced Courier font to preserve spaces/indentation
|
| - |
|
344 |
Font font = FontFactory.getFont(FontFactory.COURIER, 10, Font.NORMAL);
|
| - |
|
345 |
|
| - |
|
346 |
// Title
|
| - |
|
347 |
Font boldFont = new Font(FontFactory.getFont(FontFactory.COURIER, 12, Font.BOLD));
|
| - |
|
348 |
Paragraph title = new Paragraph("Credit terms :-\n", boldFont);
|
| - |
|
349 |
title.setIndentationLeft(25);
|
| - |
|
350 |
title.setIndentationRight(25);
|
| - |
|
351 |
document.add(title);
|
| - |
|
352 |
|
| - |
|
353 |
// Exact text block (with spaces preserved)
|
| - |
|
354 |
StringBuffer termsBuffer = new StringBuffer();
|
| - |
|
355 |
int count = 0;
|
| - |
|
356 |
for (String creditTerm : pdfModel.getCreditTerms()) {
|
| - |
|
357 |
count++;
|
| - |
|
358 |
termsBuffer.append(count).append(". ").append(creditTerm).append(".\n");
|
| - |
|
359 |
}
|
| - |
|
360 |
|
| - |
|
361 |
|
| - |
|
362 |
Paragraph body = new Paragraph(termsBuffer.toString(), font);
|
| - |
|
363 |
body.setIndentationLeft(25);
|
| - |
|
364 |
body.setIndentationRight(25);
|
| - |
|
365 |
document.add(body);
|
| - |
|
366 |
|
| - |
|
367 |
}
|
| 329 |
if (pdfModel.getTncs() != null) {
|
368 |
if (pdfModel.getTncs() != null) {
|
| 330 |
StringBuffer sb = new StringBuffer();
|
369 |
StringBuffer sb = new StringBuffer();
|
| 331 |
for (String tnc : pdfModel.getTncs()) {
|
370 |
for (String tnc : pdfModel.getTncs()) {
|
| 332 |
sb.append(tnc).append("\n");
|
371 |
sb.append(tnc).append("\n");
|
| 333 |
}
|
372 |
}
|
| Line 336... |
Line 375... |
| 336 |
document.add(Chunk.NEWLINE);
|
375 |
document.add(Chunk.NEWLINE);
|
| 337 |
document.add(warningParagraph);
|
376 |
document.add(warningParagraph);
|
| 338 |
}
|
377 |
}
|
| 339 |
|
378 |
|
| 340 |
document.newPage();
|
379 |
document.newPage();
|
| 341 |
if(pdfModel.geteWayBillPdfModel()!=null) {
|
380 |
if (pdfModel.geteWayBillPdfModel() != null) {
|
| 342 |
|
381 |
|
| 343 |
EWayBillPDF.generateDocument(document, pdfWriter, pdfModel.geteWayBillPdfModel());
|
382 |
EWayBillPDF.generateDocument(document, pdfWriter, pdfModel.geteWayBillPdfModel());
|
| 344 |
}
|
383 |
}
|
| 345 |
}
|
384 |
}
|
| 346 |
document.close(); // no need to close PDFwriter?
|
385 |
document.close(); // no need to close PDFwriter?
|
| 347 |
if(cancelledPages) {
|
386 |
if (cancelledPages) {
|
| 348 |
stampCancelled(outputStream, caneclledPageList);
|
387 |
stampCancelled(outputStream, caneclledPageList);
|
| 349 |
}
|
388 |
}
|
| 350 |
|
389 |
|
| 351 |
} catch (DocumentException e) {
|
390 |
} catch (DocumentException e) {
|
| 352 |
LOGGER.error("Unable to write data to pdf file : ", e);
|
391 |
LOGGER.error("Unable to write data to pdf file : ", e);
|
| Line 367... |
Line 406... |
| 367 |
document.add(img);
|
406 |
document.add(img);
|
| 368 |
Paragraph irnParagraph = new Paragraph("IRN No - " + irnModel.getIrnNumber(), FONT_NORMAL);
|
407 |
Paragraph irnParagraph = new Paragraph("IRN No - " + irnModel.getIrnNumber(), FONT_NORMAL);
|
| 369 |
irnParagraph.setAlignment(Element.ALIGN_LEFT);
|
408 |
irnParagraph.setAlignment(Element.ALIGN_LEFT);
|
| 370 |
pdfCell.addElement(irnParagraph);
|
409 |
pdfCell.addElement(irnParagraph);
|
| 371 |
|
410 |
|
| 372 |
Paragraph ackParagraph = new Paragraph("Ack No - " + irnModel.getAcknowledgeNumber(), FONT_NORMAL);
|
411 |
Paragraph ackParagraph = new Paragraph("Ack No - " + irnModel.getAcknowledgeNumber(), FONT_NORMAL);
|
| 373 |
ackParagraph.setAlignment(Element.ALIGN_LEFT);
|
412 |
ackParagraph.setAlignment(Element.ALIGN_LEFT);
|
| 374 |
pdfCell.addElement(ackParagraph);
|
413 |
pdfCell.addElement(ackParagraph);
|
| 375 |
|
414 |
|
| 376 |
Paragraph ackDateParagraph = new Paragraph("Ack Date - " + FormattingUtils.format(irnModel.getAcknowledgeDate()), FONT_NORMAL);
|
415 |
Paragraph ackDateParagraph = new Paragraph("Ack Date - " + FormattingUtils.format(irnModel.getAcknowledgeDate()), FONT_NORMAL);
|
| 377 |
ackDateParagraph.setAlignment(Element.ALIGN_LEFT);
|
416 |
ackDateParagraph.setAlignment(Element.ALIGN_LEFT);
|